Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,22 @@ docker run -d --name bblfshd --privileged -p 9432:9432 -v /var/lib/bblfshd:/var/
```
apt-get install libportmidi-dev
# or
sudo pacman -S portmidi
# or
brew install portmidi
```

* Midi synthesizer

- for macOS we recommend [SimpleSynth](http://notahat.com/simplesynth/)
- for Linux, [FluidSynth](http://www.fluidsynth.org/). Documentation abouut how to install it can be found [here](https://wiki.archlinux.org/index.php/FluidSynth). Once installed and configured, the output of `aplaymidi -l` should look alike:

```
Port Client name Port name
128:0 FLUID Synth (32076) Synth input port (32076:0)
```




## Running it
Expand Down Expand Up @@ -98,4 +108,3 @@ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md

* Kuba Podgórski - project idea
* Alvin Lin - [post about Markov chains and music](https://hackernoon.com/generating-music-using-markov-chains-40c3f3f46405)

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