Skip to content

Commit

Permalink
Ports rakyll/portmidi to gomidi/portmididrv
Browse files Browse the repository at this point in the history
Signed-off-by: ncordon <[email protected]>
  • Loading branch information
ncordon committed Oct 7, 2019
1 parent c0e335b commit a841d90
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 46 deletions.
8 changes: 4 additions & 4 deletions analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"

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

type Analyzer struct {
DataClient *lookout.DataClient
DeviceID portmidi.DeviceID
OutMidi mid.Out
}

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

deletedSeq := sound.NewSequence("prophet", ConvertMarkov(m2, deleted))
deletedSeq.Play(a.DeviceID)
deletedSeq.Play(a.OutMidi)

addedSeq := sound.NewSequence("prophet", ConvertMarkov(m2, added))
addedSeq.Play(a.DeviceID)
addedSeq.Play(a.OutMidi)

total += len(deleted) + len(added) + len(changed)
}
Expand Down
17 changes: 8 additions & 9 deletions cmd/sonic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (

"github.com/mloncode/sonic"
"github.com/kelseyhightower/envconfig"
"github.com/rakyll/portmidi"
"github.com/src-d/lookout"
"gopkg.in/src-d/lookout-sdk.v0/pb"
"github.com/src-d/lookout/util/grpchelper"
"google.golang.org/grpc"
driver "gitlab.com/gomidi/portmididrv"
log "gopkg.in/src-d/go-log.v1"
)

Expand Down Expand Up @@ -42,20 +42,19 @@ func main() {
return
}

if err := portmidi.Initialize(); err != nil {
log.Errorf(err, "can't initializer portmidi")
drv, err := driver.New()
defer drv.Close()
if err != nil {
log.Errorf(err, "can't initialize the midi driver")
return
}
defer portmidi.Terminate()

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

analyzer := &sonic.Analyzer{
DataClient: lookout.NewDataClient(conn),
DeviceID: portmidi.DefaultOutputDeviceID(),
OutMidi: out,
}

server := grpchelper.NewServer()
Expand Down
18 changes: 6 additions & 12 deletions cmd/test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ package main

import (
"log"

"github.com/mloncode/sonic"
"github.com/mloncode/sonic/src/sound"
"github.com/rakyll/portmidi"
)

func main() {
if err := portmidi.Initialize(); err != nil {
log.Fatal("can't initializer portmidi", err)
}
defer portmidi.Terminate()
out, err := sound.MidiOut()

if portmidi.CountDevices() == 0 {
log.Fatal("no midi devices")
if err != nil {
log.Fatal(err)
return
}

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

deviceID := portmidi.DefaultOutputDeviceID()

oldChanges.Play(deviceID)
newChanges.Play(deviceID)
oldChanges.Play(out)
newChanges.Play(out)
}
21 changes: 18 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,40 @@ go 1.12

require (
github.com/antchfx/xpath v1.0.0 // indirect
github.com/gogo/protobuf v1.3.0 // indirect
github.com/google/go-github v17.0.0+incompatible // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0 // indirect
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/kelseyhightower/envconfig v1.4.0
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.9 // indirect
github.com/mcuadros/go-lookup v0.0.0-20171110082742-5650f26be767 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mwitkow/grpc-proxy v0.0.0-20181017164139-0f1106ef9c76 // indirect
github.com/rakyll/portmidi v0.0.0-20170716032345-1246dd47c560
github.com/onsi/ginkgo v1.10.2 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/rakyll/portmidi v0.0.0-20170716032345-1246dd47c560 // indirect
github.com/src-d/envconfig v1.0.0 // indirect
github.com/src-d/lookout v0.11.0
github.com/src-d/lookout-test-fixtures v0.0.0-20190402142344-11bd37726868 // indirect
github.com/x-cray/logrus-prefixed-formatter v0.5.2 // indirect
gitlab.com/gomidi/midi v1.13.1
gitlab.com/gomidi/portmididrv v0.3.0
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc // indirect
golang.org/x/net v0.0.0-20191003171128-d98b1b443823 // indirect
golang.org/x/sys v0.0.0-20191007092633-5f54ce542709 // indirect
google.golang.org/appengine v1.4.0 // indirect
google.golang.org/grpc v1.23.1
google.golang.org/genproto v0.0.0-20191002211648-c459b9ce5143 // indirect
google.golang.org/grpc v1.24.0
gopkg.in/bblfsh/client-go.v2 v2.8.9
gopkg.in/bblfsh/sdk.v1 v1.17.0
gopkg.in/bblfsh/sdk.v2 v2.16.4 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/src-d/go-errors.v1 v1.0.0 // indirect
gopkg.in/src-d/go-git.v4 v4.13.1 // indirect
gopkg.in/src-d/go-log.v1 v1.0.2
gopkg.in/src-d/lookout-sdk.v0 v0.6.3
gopkg.in/yaml.v2 v2.2.4 // indirect
)
Loading

0 comments on commit a841d90

Please sign in to comment.