Skip to content

Commit

Permalink
feat: add a way to specify a midi device
Browse files Browse the repository at this point in the history
Signed-off-by: Manfred Touron <94029+moul@users.noreply.github.com>
  • Loading branch information
moul committed Jul 5, 2021
1 parent 771d117 commit 722fa74
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions driver/midi.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"runtime"
"strconv"
"strings"
"sync"

"gitlab.com/gomidi/midi"
Expand All @@ -22,8 +24,22 @@ func NewMidiInput(opts Opts) (Input, error) {
return nil, fmt.Errorf("portmididrv.New: %w", err)
}

d.portNum = 0 // FIXME: parse args
d.portName = "" // FIXME: parse args
args := strings.Split(opts.Args, ",")
for _, arg := range args {
parts := strings.SplitN(arg, "=", 2)
if len(parts) != 2 {
continue
}
switch parts[0] {
case "id":
d.portNum, err = strconv.Atoi(parts[1])
if err != nil {
return nil, fmt.Errorf("invalid ID: %q: %w", parts[1], err)
}
case "name":
d.portName = parts[1]
}
}

return d, nil
}
Expand Down

0 comments on commit 722fa74

Please sign in to comment.