Skip to content

Commit

Permalink
be able to program latency
Browse files Browse the repository at this point in the history
  • Loading branch information
schollz committed Sep 10, 2020
1 parent 79e1aeb commit 4f19c33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import (
"fmt"

"github.com/schollz/miti/src/log"
"github.com/schollz/miti/src/midi"
"github.com/schollz/miti/src/play"
"github.com/schollz/miti/src/record"
)

var flagDebug, flagTrace, flagVersion, flagList bool
var flagFile, flagRecord string
var flagLatency int64

// Version specifies the version
var Version string
Expand All @@ -25,6 +27,7 @@ func init() {
flag.BoolVar(&flagTrace, "trace", false, "trace")
flag.BoolVar(&flagList, "list", false, "list midi devices")
flag.BoolVar(&flagVersion, "version", false, "show version")
flag.Int64Var(&flagLatency, "latency", 2000, "latency for midi output")
flag.StringVar(&flagRecord, "record", "", "record input to miti file")
flag.StringVar(&flagFile, "play", "", "play sequence from miti file")
if Version == "" {
Expand All @@ -45,6 +48,7 @@ func main() {
if flagVersion {
return
}
midi.Latency = flagLatency
play.Version = Version
var err error
if flagRecord != "" {
Expand Down
4 changes: 3 additions & 1 deletion src/midi/midi.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var outputChannels []chan music.Chord
var channelLock sync.Mutex
var inited bool

var Latency = int64(2000) // milliseconds

func Init() (devices []string, err error) {
defer func() {
if err == nil {
Expand Down Expand Up @@ -53,7 +55,7 @@ func Init() (devices []string, err error) {
log.Debug("recovered panic")
}
}()
outputStream, err := portmidi.NewOutputStream(portmidi.DeviceID(deviceID), 4096, 2000)
outputStream, err := portmidi.NewOutputStream(portmidi.DeviceID(deviceID), 4096, Latency)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 4f19c33

Please sign in to comment.