示例#1
0
文件: main.go 项目: dskinner/material
func onStart(ctx gl.Context) {
	env.SetPalette(material.Palette{
		Primary: material.BlueGrey500,
		Dark:    material.BlueGrey700,
		Light:   material.BlueGrey100,
		Accent:  material.DeepOrangeA200,
	})

	quits = []chan struct{}{}

	sig = make(snd.Discrete, len(material.ExpSig))
	copy(sig, material.ExpSig)
	rsig := make(snd.Discrete, len(material.ExpSig))
	copy(rsig, material.ExpSig)
	rsig.UnitInverse()
	sig = append(sig, rsig...)
	sig.NormalizeRange(0, 1)

	ctx.Enable(gl.BLEND)
	ctx.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	ctx.Enable(gl.CULL_FACE)
	ctx.CullFace(gl.BACK)

	env.Load(ctx)

	for i := range boxes {
		boxes[i] = env.NewMaterial(ctx)
		boxes[i].SetColor(material.BlueGrey200)
	}
}
示例#2
0
文件: window.go 项目: morero/exp
func useOp(glctx gl.Context, op draw.Op) {
	if op == draw.Over {
		glctx.Enable(gl.BLEND)
		glctx.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)
	} else {
		glctx.Disable(gl.BLEND)
	}
}
示例#3
0
func main() {
	app.Main(func(a app.App) {
		var glctx gl.Context
		var sz size.Event
		for e := range a.Events() {
			switch e := a.Filter(e).(type) {
			case lifecycle.Event:
				switch e.Crosses(lifecycle.StageVisible) {
				case lifecycle.CrossOn:
					glctx, _ = e.DrawContext.(gl.Context)
					// transparency of png
					glctx.Enable(gl.BLEND)
					glctx.BlendEquation(gl.FUNC_ADD)
					glctx.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
					onStart(glctx)
					a.Send(paint.Event{})
				case lifecycle.CrossOff:
					onStop()
					glctx = nil
				}
			case size.Event:
				sz = e
			case paint.Event:
				if glctx == nil || e.External {
					continue
				}

				switch sceneId {
				case 0:
					Title.Apply()
				case 1:
					Gopher.Apply()
					Ball.MoveWithReflection()
					Ball.Apply()
				}

				onPaint(glctx, sz)
				a.Publish()
				a.Send(paint.Event{}) // keep animating
			case touch.Event:
				switch sceneId {
				case 1:
					Gopher.Move(e.X, e.Y)
					Gopher.Rotate(Gopher.radian + 5)
					//Gopher.Size(Gopher.width, Gopher.height)
				}
				if e.Type == touch.TypeEnd {
					sceneId = 1
					loadScene(sceneId)
				}
			}
		}
	})
}
示例#4
0
文件: main.go 项目: dskinner/material
func onStart(ctx gl.Context) {
	ctx.Enable(gl.BLEND)
	ctx.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	ctx.Enable(gl.CULL_FACE)
	ctx.CullFace(gl.BACK)

	env.Load(ctx)
	env.LoadGlyphs(ctx)

	t112 = env.NewButton(ctx)
	t112.SetTextColor(material.White)
	t112.SetText("AAAH`e_llo |jJ go 112px")
	t112.BehaviorFlags = material.DescriptorFlat

	t56 = env.NewButton(ctx)
	t56.SetTextColor(material.White)
	t56.SetText("Hello go 56px")
	t56.BehaviorFlags = material.DescriptorFlat

	t45 = env.NewButton(ctx)
	t45.SetTextColor(material.White)
	t45.SetText("Hello go 45px")
	t45.BehaviorFlags = material.DescriptorFlat

	t34 = env.NewButton(ctx)
	t34.SetTextColor(material.White)
	t34.SetText("Hello go 34px")
	t34.BehaviorFlags = material.DescriptorFlat

	t24 = env.NewButton(ctx)
	t24.SetTextColor(material.White)
	t24.SetText("Hello go 24px")
	t24.BehaviorFlags = material.DescriptorFlat

	t20 = env.NewButton(ctx)
	t20.SetTextColor(material.White)
	t20.SetText("Hello go 20px")
	t20.BehaviorFlags = material.DescriptorFlat

	t16 = env.NewButton(ctx)
	t16.SetTextColor(material.White)
	t16.SetText("Hello go 16px")
	t16.BehaviorFlags = material.DescriptorFlat

	t14 = env.NewButton(ctx)
	t14.SetTextColor(material.White)
	t14.SetText("Hello go 14px")
	t14.BehaviorFlags = material.DescriptorFlat

	t12 = env.NewButton(ctx)
	t12.SetTextColor(material.White)
	t12.SetText("Hello go 12px")
	t12.BehaviorFlags = material.DescriptorFlat
}
示例#5
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())
}
示例#6
0
文件: main.go 项目: dskinner/snd
func onStart(ctx gl.Context) {
	ctx.Enable(gl.BLEND)
	ctx.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	ctx.Enable(gl.CULL_FACE)
	ctx.CullFace(gl.BACK)

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

	env.Load(ctx)
	env.LoadIcons(ctx)
	env.LoadGlyphs(ctx)

	toolbar = env.NewToolbar(ctx)
	toolbar.Title.SetText("piano")
	toolbar.Title.SetTextColor(material.White)
	toolbar.Nav.SetIconColor(material.White)

	btnLoop := env.NewButton(ctx)
	toolbar.AddAction(btnLoop)
	btnLoop.SetIcon(icon.AvFiberSmartRecord)
	btnLoop.SetIconColor(material.White)
	btnLoop.OnPress = func() {
		if loop.Recording() {
			btnLoop.SetIconColor(material.White)
			loop.Stop()
		} else {
			btnLoop.SetIconColor(env.Palette().Accent)
			loop.Record()
		}
	}

	btnMetronome := env.NewButton(ctx)
	toolbar.AddAction(btnMetronome)
	btnMetronome.SetIcon(icon.AvSlowMotionVideo)
	btnMetronome.SetIconColor(material.White)
	btnMetronome.OnPress = func() {
		if metronome.IsOff() {
			metronome.On()
			btnMetronome.SetIconColor(env.Palette().Accent)
		} else {
			metronome.Off()
			btnMetronome.SetIconColor(material.White)
		}
	}

	btnLowpass := env.NewButton(ctx)
	toolbar.AddAction(btnLowpass)
	btnLowpass.SetIcon(icon.AvSubtitles)
	btnLowpass.SetIconColor(env.Palette().Accent)
	btnLowpass.OnPress = func() {
		lowpass.SetPassthrough(!lowpass.Passthrough())
		if lowpass.Passthrough() {
			btnLowpass.SetIconColor(material.White)
		} else {
			btnLowpass.SetIconColor(env.Palette().Accent)
		}
	}

	btnReverb := env.NewButton(ctx)
	toolbar.AddAction(btnReverb)
	btnReverb.SetIcon(icon.AvSurroundSound)
	btnReverb.SetIconColor(env.Palette().Accent)
	btnReverb.OnPress = func() {
		if reverb.IsOff() {
			reverb.On()
			keygain.SetAmp(snd.Decibel(-3).Amp())
			btnReverb.SetIconColor(env.Palette().Accent)
		} else {
			reverb.Off()
			keygain.SetAmp(snd.Decibel(3).Amp())
			btnReverb.SetIconColor(material.White)
		}
	}

	btnNext = env.NewFloatingActionButton(ctx)
	btnNext.Mini = true
	btnNext.SetColor(env.Palette().Accent)
	btnNext.SetIcon(icon.AvSkipNext)
	btnNext.OnPress = func() {
		sndbankpos = (sndbankpos + 1) % len(sndbank)
		go makekeys()
	}

	decor = env.NewMaterial(ctx)
	decor.SetColor(material.BlueGrey900)

	tseq := make(map[touch.Sequence]int)
	for i := range btnkeys {
		btnkeys[i] = env.NewButton(ctx)
		j := i
		btnkeys[i].OnTouch = func(ev touch.Event) {
			switch ev.Type {
			case touch.TypeBegin:
				keys[j].Press()
				tseq[ev.Sequence] = j
			case touch.TypeMove:
				// TODO drag finger off piano and it still plays, should stop
				if last, ok := tseq[ev.Sequence]; ok {
					if j != last {
						keys[last].Release()
						keys[j].Press()
						tseq[ev.Sequence] = j
					}
				}
			case touch.TypeEnd:
				keys[j].Release()
				delete(tseq, ev.Sequence)
			}
		}
	}

	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 = NewWaveform(ctx, 2, mastergain)
	mixwf.SetColor(material.BlueGrey700)
	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)

	al.AddSource(pan)
}