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 NewAudioGenerator(filepath string) (*AudioGenerator, error) { a := AudioGenerator{} if s, err := audio.NewLoadedSampler(filepath); err != nil { return &AudioGenerator{}, err } else { a.Sampler = s } return &a, nil }
func main() { nanopad, _ := midi.GetDevice("nanoPAD PAD") sampler, _ := audio.NewLoadedSampler(configPath) for { msg := <-nanopad.OutPort() if msg.(type) == midi.NoteOn { go sampler.Play(msg.Key, volume) } } }
func main() { configPath := "/home/tasm/ir/src/tracker/cmd/config/waves.json" sampler, err := audio.NewLoadedSampler(configPath) g := tracker.MockGenerator{} p := tracker.PatternTable{ tracker.Pattern{ tracker.NewTrack(g, 127, []int{64, 60, 67}), tracker.NewTrack(g, 127, []int{52, 48, 55}), tracker.NewTrack(g, 127, []int{40, 36, 42}), }, } t := tracker.Tracker{BPM: 120, PatternTable: p} t.Play() }
func main() { devices, err := midi.GetDevices() check(err) launchpad := midi.NewLaunchpad(devices["Launchpad"], make(map[int]int)) launchpad.Open() go launchpad.Run() sampler, err := audio.NewLoadedSampler("instruments/config/launchpad_drums.json") sampler.Run() check(err) for { select { case note := <-launchpad.OutPort().NoteOns(): go sampler.Play(note.Key, 0.3) case <-launchpad.OutPort().NoteOffs(): continue case <-launchpad.OutPort().ControlChanges(): continue } } launchpad.Close() sampler.Stop() sampler.Close() }