Exemplo n.º 1
0
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)
				}
			}
		}
	}
}
Exemplo n.º 2
0
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
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
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
			}
		}
	}
}