Added gain slider

This commit is contained in:
Sasha Koshka 2023-02-11 01:46:12 -05:00
parent a74f9809af
commit d7a6193c04
2 changed files with 9 additions and 3 deletions

View File

@ -131,6 +131,7 @@ func (element *Slider) valueFor (x, y int) (value float64) {
value =
float64(y - element.track.Min.Y - element.bar.Dy() / 2) /
float64(element.track.Dy() - element.bar.Dy())
value = 1 - value
} else {
value =
float64(x - element.track.Min.X - element.bar.Dx() / 2) /
@ -139,7 +140,6 @@ func (element *Slider) valueFor (x, y int) (value float64) {
if value < 0 { value = 0 }
if value > 1 { value = 1 }
value = 1 - value
return
}

View File

@ -22,7 +22,8 @@ var adsr = ADSR {
Decay: 400 * time.Millisecond,
Sustain: 0.7,
Release: 500 * time.Millisecond,
}
}
var gain = 0.3
func main () {
speaker.Init(sampleRate, bufferSize)
@ -52,6 +53,7 @@ func run () {
decaySlider := basicElements.NewLerpSlider(0, 3 * time.Second, adsr.Decay, true)
sustainSlider := basicElements.NewSlider(adsr.Sustain, true)
releaseSlider := basicElements.NewLerpSlider(0, 3 * time.Second, adsr.Release, true)
gainSlider := basicElements.NewSlider(math.Sqrt(gain), false)
attackSlider.OnRelease (func () {
adsr.Attack = attackSlider.Value()
@ -65,6 +67,9 @@ func run () {
releaseSlider.OnRelease (func () {
adsr.Release = releaseSlider.Value()
})
gainSlider.OnRelease (func () {
gain = math.Pow(gainSlider.Value(), 2)
})
patchColumn := basicElements.NewContainer(basicLayouts.Vertical { true, false })
patch := func (w int, a, d time.Duration, s float64, r time.Duration) func () {
@ -133,6 +138,7 @@ func run () {
adsrGroup.Adopt(sustainSlider, false)
adsrGroup.Adopt(releaseSlider, false)
adsrColumn.Adopt(adsrGroup, true)
adsrColumn.Adopt(gainSlider, false)
controlBar.Adopt(adsrColumn, false)
container.Adopt(controlBar, true)
@ -162,7 +168,7 @@ func playNote (note music.Note) {
sampleRate,
int(tuning.Tune(note)),
waveform,
0.3,
gain,
adsr)
stopNote(note)