Skip to content

Commit a841d90

Browse files
committed
Ports rakyll/portmidi to gomidi/portmididrv
Signed-off-by: ncordon <nacho.cordon.castillo@gmail.com>
1 parent c0e335b commit a841d90

File tree

7 files changed

+135
-46
lines changed

7 files changed

+135
-46
lines changed

analyzer.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"fmt"
77

88
"github.com/mloncode/sonic/src/sound"
9-
"github.com/rakyll/portmidi"
9+
"gitlab.com/gomidi/midi/mid"
1010
"gopkg.in/src-d/lookout-sdk.v0/pb"
1111
"github.com/src-d/lookout"
1212
"gopkg.in/bblfsh/client-go.v2/tools"
@@ -16,7 +16,7 @@ import (
1616

1717
type Analyzer struct {
1818
DataClient *lookout.DataClient
19-
DeviceID portmidi.DeviceID
19+
OutMidi mid.Out
2020
}
2121

2222
var _ lookout.AnalyzerServer = &Analyzer{}
@@ -62,10 +62,10 @@ func (a *Analyzer) NotifyReviewEvent(ctx context.Context, e *pb.ReviewEvent) (*p
6262
printNodes("changed:", changed)
6363

6464
deletedSeq := sound.NewSequence("prophet", ConvertMarkov(m2, deleted))
65-
deletedSeq.Play(a.DeviceID)
65+
deletedSeq.Play(a.OutMidi)
6666

6767
addedSeq := sound.NewSequence("prophet", ConvertMarkov(m2, added))
68-
addedSeq.Play(a.DeviceID)
68+
addedSeq.Play(a.OutMidi)
6969

7070
total += len(deleted) + len(added) + len(changed)
7171
}

cmd/sonic/main.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66

77
"github.com/mloncode/sonic"
88
"github.com/kelseyhightower/envconfig"
9-
"github.com/rakyll/portmidi"
109
"github.com/src-d/lookout"
1110
"gopkg.in/src-d/lookout-sdk.v0/pb"
1211
"github.com/src-d/lookout/util/grpchelper"
1312
"google.golang.org/grpc"
13+
driver "gitlab.com/gomidi/portmididrv"
1414
log "gopkg.in/src-d/go-log.v1"
1515
)
1616

@@ -42,20 +42,19 @@ func main() {
4242
return
4343
}
4444

45-
if err := portmidi.Initialize(); err != nil {
46-
log.Errorf(err, "can't initializer portmidi")
45+
drv, err := driver.New()
46+
defer drv.Close()
47+
if err != nil {
48+
log.Errorf(err, "can't initialize the midi driver")
4749
return
4850
}
49-
defer portmidi.Terminate()
5051

51-
if portmidi.CountDevices() == 0 {
52-
log.Errorf(nil, "no midi devices")
53-
return
54-
}
52+
outs, _ := drv.Outs()
53+
out := outs[1]
5554

5655
analyzer := &sonic.Analyzer{
5756
DataClient: lookout.NewDataClient(conn),
58-
DeviceID: portmidi.DefaultOutputDeviceID(),
57+
OutMidi: out,
5958
}
6059

6160
server := grpchelper.NewServer()

cmd/test/main.go

+6-12
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,16 @@ package main
22

33
import (
44
"log"
5-
65
"github.com/mloncode/sonic"
76
"github.com/mloncode/sonic/src/sound"
8-
"github.com/rakyll/portmidi"
97
)
108

119
func main() {
12-
if err := portmidi.Initialize(); err != nil {
13-
log.Fatal("can't initializer portmidi", err)
14-
}
15-
defer portmidi.Terminate()
10+
out, err := sound.MidiOut()
1611

17-
if portmidi.CountDevices() == 0 {
18-
log.Fatal("no midi devices")
12+
if err != nil {
13+
log.Fatal(err)
14+
return
1915
}
2016

2117
m1 := sound.NewMarkov("song1.midi")
@@ -24,8 +20,6 @@ func main() {
2420
oldChanges := sound.NewSequence("prophet", sonic.ConvertMarkov(m1, sonic.File1.Old))
2521
newChanges := sound.NewSequence("prophet", sonic.ConvertMarkov(m2, sonic.File1.New))
2622

27-
deviceID := portmidi.DefaultOutputDeviceID()
28-
29-
oldChanges.Play(deviceID)
30-
newChanges.Play(deviceID)
23+
oldChanges.Play(out)
24+
newChanges.Play(out)
3125
}

go.mod

+18-3
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,40 @@ go 1.12
44

55
require (
66
github.com/antchfx/xpath v1.0.0 // indirect
7+
github.com/gogo/protobuf v1.3.0 // indirect
8+
github.com/google/go-github v17.0.0+incompatible // indirect
9+
github.com/google/go-querystring v1.0.0 // indirect
710
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect
811
github.com/hashicorp/golang-lru v0.5.3 // indirect
912
github.com/kelseyhightower/envconfig v1.4.0
10-
github.com/mattn/go-colorable v0.1.2 // indirect
13+
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
14+
github.com/mattn/go-colorable v0.1.4 // indirect
15+
github.com/mattn/go-isatty v0.0.9 // indirect
1116
github.com/mcuadros/go-lookup v0.0.0-20171110082742-5650f26be767 // indirect
1217
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
1318
github.com/mwitkow/grpc-proxy v0.0.0-20181017164139-0f1106ef9c76 // indirect
14-
github.com/rakyll/portmidi v0.0.0-20170716032345-1246dd47c560
19+
github.com/onsi/ginkgo v1.10.2 // indirect
20+
github.com/onsi/gomega v1.7.0 // indirect
21+
github.com/rakyll/portmidi v0.0.0-20170716032345-1246dd47c560 // indirect
1522
github.com/src-d/envconfig v1.0.0 // indirect
1623
github.com/src-d/lookout v0.11.0
24+
github.com/src-d/lookout-test-fixtures v0.0.0-20190402142344-11bd37726868 // indirect
1725
github.com/x-cray/logrus-prefixed-formatter v0.5.2 // indirect
1826
gitlab.com/gomidi/midi v1.13.1
27+
gitlab.com/gomidi/portmididrv v0.3.0
28+
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc // indirect
29+
golang.org/x/net v0.0.0-20191003171128-d98b1b443823 // indirect
30+
golang.org/x/sys v0.0.0-20191007092633-5f54ce542709 // indirect
1931
google.golang.org/appengine v1.4.0 // indirect
20-
google.golang.org/grpc v1.23.1
32+
google.golang.org/genproto v0.0.0-20191002211648-c459b9ce5143 // indirect
33+
google.golang.org/grpc v1.24.0
2134
gopkg.in/bblfsh/client-go.v2 v2.8.9
2235
gopkg.in/bblfsh/sdk.v1 v1.17.0
2336
gopkg.in/bblfsh/sdk.v2 v2.16.4 // indirect
37+
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
2438
gopkg.in/src-d/go-errors.v1 v1.0.0 // indirect
2539
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
2640
gopkg.in/src-d/go-log.v1 v1.0.2
2741
gopkg.in/src-d/lookout-sdk.v0 v0.6.3
42+
gopkg.in/yaml.v2 v2.2.4 // indirect
2843
)

0 commit comments

Comments
 (0)