Skip to content

Commit b774ceb

Browse files
committed
Updates to actually play system MIDI devices.
1 parent de9bd37 commit b774ceb

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

cmd/midiserver/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
func main() {
1616
app.SetupLogging()
17-
log.Info("Starting up Go Port example ...")
17+
log.Info("Starting up Go midiserver ...")
1818
log.Infof("Running version: %s", app.VersionedBuildString())
1919
app.SetupRandom()
2020
ctx, cancel := app.SignalWithContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ require (
77
github.com/okeuday/erlang_go/v2 v2.0.2
88
github.com/sirupsen/logrus v1.8.1
99
gitlab.com/gomidi/midi v1.23.7
10+
gitlab.com/gomidi/rtmididrv v0.14.0
1011
)

go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic
2020
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
2121
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
2222
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
23+
gitlab.com/gomidi/midi v1.21.0/go.mod h1:3ohtNOhqoSakkuLG/Li1OI6I3J1c2LErnJF5o/VBq1c=
2324
gitlab.com/gomidi/midi v1.23.7 h1:I6qKoIk9s9dcX+pNf0jC+tziCzJFn82bMpuntRkLeik=
2425
gitlab.com/gomidi/midi v1.23.7/go.mod h1:3ohtNOhqoSakkuLG/Li1OI6I3J1c2LErnJF5o/VBq1c=
26+
gitlab.com/gomidi/rtmididrv v0.14.0 h1:IBkDsqXs1RuFoRWgQbyYEpwe0hoXZ17FLTZaJuyXWx0=
27+
gitlab.com/gomidi/rtmididrv v0.14.0/go.mod h1:p/6IL1LGgj7utcv3wXudsDWiD9spgAdn0O8LDsGIPG0=
2528
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
2629
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
2730
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

pkg/midiserver/rw.go

+48-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"io"
66
"time"
77

8+
log "github.com/sirupsen/logrus"
9+
driver "gitlab.com/gomidi/rtmididrv"
810
"gitlab.com/gomidi/midi/reader"
911
"gitlab.com/gomidi/midi/writer"
1012
)
@@ -23,6 +25,44 @@ func Example() {
2325

2426
var p printer
2527

28+
drv, err := driver.New()
29+
if err != nil {
30+
log.Panic(err)
31+
}
32+
defer drv.Close()
33+
34+
ins, err := drv.Ins()
35+
if err != nil {
36+
log.Panic(err)
37+
}
38+
39+
outs, err := drv.Outs()
40+
if err != nil {
41+
log.Panic(err)
42+
}
43+
44+
log.Debug("MIDI IN Ports")
45+
for _, port := range ins {
46+
log.Debugf("[%v] %s\n", port.Number(), port.String())
47+
}
48+
49+
log.Debug("MIDI OUT Ports")
50+
for _, port := range outs {
51+
log.Debugf("[%v] %s\n", port.Number(), port.String())
52+
}
53+
54+
in, out := ins[0], outs[0]
55+
56+
err = in.Open()
57+
if err != nil {
58+
log.Panic(err)
59+
}
60+
61+
err = out.Open()
62+
if err != nil {
63+
log.Panic(err)
64+
}
65+
2666
// to disable logging, pass mid.NoLogger() as option
2767
rd := reader.New(reader.NoLogger(),
2868
// set the callbacks for the messages you are interested in
@@ -35,11 +75,15 @@ func Example() {
3575
piperd, pipewr := io.Pipe()
3676

3777
go func() {
38-
wr := writer.New(pipewr)
39-
wr.SetChannel(1) // sets the channel for the next messages
40-
writer.NoteOn(wr, 120, 100)
78+
// wr := writer.New(pipewr)
79+
wr := writer.New(out)
80+
wr.SetChannel(0) // sets the channel for the next messages
81+
err := writer.NoteOn(wr, 60, 100)
82+
if err != nil {
83+
log.Panic(err)
84+
}
4185
time.Sleep(5 * time.Second)
42-
writer.NoteOff(wr, 120) // let the note ring for 5 sec
86+
writer.NoteOff(wr, 60) // let the note ring for 5 sec
4387
pipewr.Close() // finishes the writing
4488
}()
4589

pkg/port/port.go

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func ProcessMessages(ctx context.Context, fn CommandProcessor) {
2323
log.Info("Processing messages sent to Go language server ...")
2424
go func() {
2525
for {
26+
// XXX Let's make these switchable with a CLI flag
2627
cmd := ProcessExecMessage()
2728
// cmd := ProcessPortMessage()
2829
if cmd == "continue" {

0 commit comments

Comments
 (0)