Skip to content

Instantly share code, notes, and snippets.

@moul
Created February 21, 2017 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moul/fd8ca0e917b1b16bda6f0fca987b3081 to your computer and use it in GitHub Desktop.
Save moul/fd8ca0e917b1b16bda6f0fca987b3081 to your computer and use it in GitHub Desktop.
synth roulette
package main
import (
"fmt"
"log"
"time"
"github.com/rakyll/portmidi"
)
func main() {
portmidi.Initialize()
defer portmidi.Terminate()
fmt.Println(portmidi.CountDevices())
out, err := portmidi.NewOutputStream(portmidi.DefaultOutputDeviceID(), 1024, 0)
if err != nil {
log.Fatal(err)
}
// note on events to play C major chord
out.WriteShort(0x90, 60, 100)
out.WriteShort(0x90, 64, 100)
out.WriteShort(0x90, 67, 100)
// notes will be sustained for 2 seconds
time.Sleep(2 * time.Second)
// note off events
out.WriteShort(0x80, 60, 100)
out.WriteShort(0x80, 64, 100)
out.WriteShort(0x80, 67, 100)
out.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment