Beispiel #1
0
func NewBeatsKey(idx int) Key {
	osc := snd.NewOscil(sawsine, notes[idx], snd.NewOscil(triangle, 4, nil))
	dmp := snd.NewDamp(bpm.Dur(), osc)
	d := snd.BPM(float64(bpm) * 1.25).Dur()
	dmp1 := snd.NewDamp(d, osc)
	drv := snd.NewDrive(d, osc)
	mix := snd.NewMixer(dmp, dmp1, drv)

	frz := snd.NewFreeze(bpm.Dur()*4, mix)

	adsr := snd.NewADSR(250*ms, 500*ms, 300*ms, 400*ms, 0.85, 1.0, frz)
	key := &BeatsKey{snd.NewInstrument(adsr), adsr}
	key.Off()
	return key
}
Beispiel #2
0
func onStart(ctx gl.Context) {
	ctx.Enable(gl.BLEND)
	ctx.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	if err := al.OpenDevice(buffers); err != nil {
		log.Fatal(err)
	}

	var err error

	keymix = snd.NewMixer()
	go makekeys()
	lowpass = snd.NewLowPass(773, keymix)
	keygain = snd.NewGain(snd.Decibel(-3).Amp(), lowpass)

	dly := snd.NewDelay(29*time.Millisecond, keygain)
	tap0 := snd.NewTap(19*time.Millisecond, dly)
	tap1 := snd.NewTap(13*time.Millisecond, dly)
	tap2 := snd.NewTap(7*time.Millisecond, dly)
	cmb := snd.NewComb(snd.Decibel(-3).Amp(), 11*time.Millisecond, snd.NewMixer(dly, tap0, tap1, tap2))
	reverb = snd.NewLowPass(2000, cmb)
	dlymix := snd.NewMixer(reverb, keygain)

	loop = snd.NewLoopFrames(loopdur, dlymix)
	loop.SetBPM(bpm)
	loopmix := snd.NewMixer(dlymix, loop)

	master = snd.NewMixer(loopmix)
	mastergain = snd.NewGain(snd.Decibel(-6).Amp(), master)
	mixwf, err = snd.NewWaveform(ctx, 2, mastergain)
	if err != nil {
		log.Fatal(err)
	}
	pan := snd.NewPan(0, mixwf)

	mtrosc := snd.NewOscil(sine, 440, nil)
	mtrdmp := snd.NewDamp(bpm.Dur(), mtrosc)
	metronome = snd.NewMixer(mtrdmp)
	metronome.Off()
	master.Append(metronome)

	piano = NewPiano()
	pianowf, err = snd.NewWaveform(ctx, 1, piano)
	if err != nil {
		log.Fatal(err)
	}

	al.AddSource(pan)

	yoff := float32(-0) //.12)

	btnreverb = snd.NewButton(ctx, -0.98, 0.96+yoff, 0.2, -0.2)
	btnreverb.SetActiveColor(0, 1, 0, 0.5)
	btnreverb.SetActive(true)

	btnlowpass = snd.NewButton(ctx, -0.76, 0.96+yoff, 0.2, -0.2)
	btnlowpass.SetActiveColor(0, 1, 1, 0.5)
	btnlowpass.SetActive(true)

	btnmetronome = snd.NewButton(ctx, -0.54, 0.96+yoff, 0.2, -0.2)
	btnmetronome.SetActiveColor(0, 0, 1, 0.5)

	btnloop = snd.NewLoopButton(snd.NewButton(ctx, -0.32, 0.96+yoff, 0.2, -0.2), loop)
	btnloop.SetActiveColor(1, 0, 0, 0.5)

	btnsndbank = snd.NewButton(ctx, 0.78, 0.96+yoff, 0.2, -0.2)
	btnsndbank.SetActive(true)
	btnsndbank.SetActiveColor(sndbankcolor())
}