func ExampleLaunchpad() { devices, _ := midi.GetDevices() launchpad := NewLaunchpad(devices["Launchpad"], map[int]int{}) launchpad.Open() launchpad.Reset() time.Sleep(2 * time.Second) launchpad.DrumMode() for i := 0; i < 3; i++ { launchpad.AllLightsOn(Green) time.Sleep(1 * time.Second) launchpad.AllLightsOn(Red) time.Sleep(1 * time.Second) launchpad.AllLightsOn(Amber) time.Sleep(1 * time.Second) } for i := 0; i < 8; i++ { for j := 0; j < 8; j++ { launchpad.LightOnXY(i, j, Red) time.Sleep(125 * time.Millisecond) } } time.Sleep(5 * time.Second) launchpad.Close() }
func ExamplLaunchpad2() { devices, _ := midi.GetDevices() nanopad := devices["nanoPAD2 PAD"] // A nanopad does its own transposition. launchpad := NewLaunchpad(devices["Launchpad"], map[int]int{ 96: 37, 97: 39, 98: 41, 99: 43, 100: 45, 101: 47, 102: 49, 103: 51, 112: 36, 113: 38, 114: 40, 115: 42, 116: 44, 117: 46, 118: 48, 119: 50}, nanopad) iac1 := devices["IAC Driver Bus 1"] pipe, _ := midi.NewPipe(launchpad, iac1) go pipe.Run() c := make(chan bool, 1) <-c }
func main() { devices, err := midi.GetDevices() check(err) launchpad := controller.NewLaunchpad(devices["Launchpad"], map[int]int{}) launchpad.ButtonPressColor = controller.RedLow launchpad.MomentaryButtons = false launchpad.Open() go launchpad.Run() sampler, err := audio.NewLoadedSampler("config/launchpad_sequencer.json") sampler.Run() time.Sleep(1 * time.Second) activeButtons := make(map[int]bool) for i := 0; i < 8; i++ { for j := i * 16; j < (i*16 + 8); j++ { activeButtons[j] = false } } go func() { for { select { case note := <-launchpad.OutPort().NoteOns(): activeButtons[note.Key] = !activeButtons[note.Key] // toggle state launchpad.ToggleLightColor(note.Key, controller.RedLow, controller.Black) case <-launchpad.OutPort().NoteOffs(): continue case <-launchpad.OutPort().ControlChanges(): continue } } }() for { for i := 0; i < 8; i++ { startButton := i endButton := startButton + (8 * 16) for j := startButton; j < endButton; j += 16 { if activeButtons[j] { launchpad.LightOn(j, controller.Red) // On color column, _ := launchpad.XY(j) sampler.Play(column, 0.7) } else { launchpad.LightOn(j, controller.Green) // Off color } } time.Sleep(250 * time.Millisecond) for j := startButton; j < endButton; j += 16 { if activeButtons[j] { launchpad.LightOn(j, controller.RedLow) } else { launchpad.LightOff(j) } } } } }
func main() { devices, _ := midi.GetDevices() launchpad := controller.NewLaunchpad(devices["Launchpad"], make(map[int]int)) launchpad.Open() go launchpad.Run() fmt.Println("Here.") time.Sleep(1 * time.Second) launchpad.AllGridLightsOn(controller.Green) wait := make(chan bool, 1) <-wait }
func ExampleMonome() { devices, err := midi.GetDevices() if err != nil { fmt.Println("Error: ", err) } iac1 := devices["IAC Driver Bus 1"] monome, err := NewMonome() fmt.Println(monome, err) monome.Open() go monome.Run() pipe, _ := midi.NewPipe(monome, iac1) go pipe.Run() c := make(chan bool, 1) <-c }
func main() { devices, _ := midi.GetDevices() launchpad := controller.NewLaunchpad(devices["Launchpad"], make(map[int]int)) launchpad.Open() go launchpad.Run() nextBoards := make(chan Board, 1) nextBoards <- glider() quit := make(chan bool, 1) go handleButtons(&launchpad, nextBoards, quit) go loop(&launchpad, nextBoards, quit) wait := make(chan bool) <-wait // wait forever }
func main() { // Split out a sample, set up the sampler. beat, err := audio.NewClipFromWave("samples/loops/beat.wav") check(err) numDivisions := 8 sleepLen := (beat.LenMilliseconds() / int64(numDivisions)) sampler, err := audio.NewSampler(2) check(err) clips, err := beat.Split(numDivisions) check(err) for i, clip := range clips { sampler.AddClip(clip, i) } sampler.Run() // Set up the launchpad. devices, err := midi.GetDevices() check(err) launchpad := controller.NewLaunchpad(devices["Launchpad"], map[int]int{}) launchpad.ButtonPressColor = controller.Red launchpad.Open() go launchpad.Run() // Throw out MIDI data that is not needed. go func() { for { select { case note := <-launchpad.OutPort().NoteOffs(): launchpad.LightOff(note.Key) case <-launchpad.OutPort().ControlChanges(): continue } } }() i := 0 var volume float32 = 0.5 play := make(chan bool, 1) pause := make(chan bool, 1) paused := true for { select { case note := <-launchpad.OutPort().NoteOns(): if note.Key == 8 { pause <- true } if note.Key > numDivisions { continue } last := i - 1 if last < 0 { last = numDivisions - 1 } launchpad.LightOff(last) i = note.Key case <-play: last := i - 1 if last < 0 { last = numDivisions - 1 } launchpad.LightOff(last) go sampler.Play(i, volume) launchpad.LightOn(i, controller.Green) go sleep(sleepLen, play) i++ if i >= numDivisions { i = 0 } case <-pause: timeout := make(chan bool, 1) go sleep(sleepLen, timeout) select { case <-play: case <-timeout: } if paused { play <- true paused = false } else { paused = true } } } }