feat(tracker): add reverb presets for delay unit

The options are stereo, left and right. Similar to oscillator sample settings, if you tamper with these, it starts to show "custom". Used some of the generic features of go1.18, so had to update go.mod to require go1.18.
This commit is contained in:
5684185+vsariola@users.noreply.github.com 2023-10-14 14:58:38 +03:00
parent 94589eb2eb
commit b455ef0f3c
4 changed files with 52 additions and 4 deletions

View File

@ -11,6 +11,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Instrument presets. The presets are embedded in the executable and - Instrument presets. The presets are embedded in the executable and
there's a button to open a menu to load one of the presets. there's a button to open a menu to load one of the presets.
- Frequency modulation target for oscillator, as it was in 4klang - Frequency modulation target for oscillator, as it was in 4klang
- Reverb preset settings for a delay unit, with stereo, left and right
options
### Fixed ### Fixed
- The sointu-vsti-native plugin has different plugin ID and plugin name - The sointu-vsti-native plugin has different plugin ID and plugin name

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/vsariola/sointu module github.com/vsariola/sointu
go 1.17 go 1.18
require ( require (
gioui.org v0.3.0 gioui.org v0.3.0

View File

@ -78,6 +78,20 @@ var defaultSong = sointu.Song{
}}}, }}},
} }
type delayPreset struct {
name string
stereo int
varArgs []int
}
var reverbs = []delayPreset{
{"stereo", 1, []int{1116, 1188, 1276, 1356, 1422, 1492, 1556, 1618,
1140, 1212, 1300, 1380, 1446, 1516, 1580, 1642,
}},
{"left", 0, []int{1116, 1188, 1276, 1356, 1422, 1492, 1556, 1618}},
{"right", 0, []int{1140, 1212, 1300, 1380, 1446, 1516, 1580, 1642}},
}
func init() { func init() {
UnitTypeNames = make([]string, 0, len(sointu.UnitTypes)) UnitTypeNames = make([]string, 0, len(sointu.UnitTypes))
for k := range sointu.UnitTypes { for k := range sointu.UnitTypes {

View File

@ -11,6 +11,7 @@ import (
"github.com/vsariola/sointu" "github.com/vsariola/sointu"
"github.com/vsariola/sointu/vm" "github.com/vsariola/sointu/vm"
"golang.org/x/exp/slices"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
@ -863,6 +864,23 @@ func (m *Model) setGmDlsEntry(index int) {
m.notifyPatchChange() m.notifyPatchChange()
} }
func (m *Model) setReverb(index int) {
if index < 0 || index >= len(reverbs) {
return
}
entry := reverbs[index]
unit := &m.d.Song.Patch[m.d.InstrIndex].Units[m.d.UnitIndex]
if unit.Type != "delay" {
return
}
m.saveUndo("setReverb", 20)
unit.Parameters["stereo"] = entry.stereo
unit.Parameters["notetracking"] = 0
unit.VarArgs = make([]int, len(entry.varArgs))
copy(unit.VarArgs, entry.varArgs)
m.notifyPatchChange()
}
func (m *Model) SwapUnits(i, j int) { func (m *Model) SwapUnits(i, j int) {
units := m.Instrument().Units units := m.Instrument().Units
if i < 0 || j < 0 || i >= len(units) || j >= len(units) || i == j { if i < 0 || j < 0 || i >= len(units) || j >= len(units) || i == j {
@ -1121,7 +1139,7 @@ func (m *Model) NumParams() int {
numSettableParams = 1 numSettableParams = 1
} }
if unit.Type == "delay" { if unit.Type == "delay" {
numSettableParams += 1 + len(unit.VarArgs) numSettableParams += 2 + len(unit.VarArgs)
if len(unit.VarArgs)%2 == 1 && unit.Parameters["stereo"] == 1 { if len(unit.VarArgs)%2 == 1 && unit.Parameters["stereo"] == 1 {
numSettableParams++ numSettableParams++
} }
@ -1181,13 +1199,23 @@ func (m *Model) Param(index int) (Parameter, error) {
} }
if unit.Type == "delay" { if unit.Type == "delay" {
if index == 0 { if index == 0 {
i := slices.IndexFunc(reverbs, func(p delayPreset) bool {
return p.stereo == unit.Parameters["stereo"] && unit.Parameters["notetracking"] == 0 && slices.Equal(p.varArgs, unit.VarArgs)
})
hint := "0 / custom"
if i >= 0 {
hint = fmt.Sprintf("%v / %v", i+1, reverbs[i].name)
}
return Parameter{Type: IntegerParameter, Min: 0, Max: len(reverbs), Name: "reverb", Hint: hint, Value: i + 1}, nil
}
if index == 1 {
l := len(unit.VarArgs) l := len(unit.VarArgs)
if unit.Parameters["stereo"] == 1 { if unit.Parameters["stereo"] == 1 {
l = (l + 1) / 2 l = (l + 1) / 2
} }
return Parameter{Type: IntegerParameter, Min: 1, Max: 32, Name: "delaylines", Hint: strconv.Itoa(l), Value: l}, nil return Parameter{Type: IntegerParameter, Min: 1, Max: 32, Name: "delaylines", Hint: strconv.Itoa(l), Value: l}, nil
} }
index-- index -= 2
if index < len(unit.VarArgs) { if index < len(unit.VarArgs) {
val := unit.VarArgs[index] val := unit.VarArgs[index]
var text string var text string
@ -1305,6 +1333,10 @@ func (m *Model) SetParam(value int) {
m.setGmDlsEntry(value - 1) m.setGmDlsEntry(value - 1)
return return
} }
if p.Name == "reverb" {
m.setReverb(value - 1)
return
}
unit := m.Unit() unit := m.Unit()
if p.Name == "delaylines" { if p.Name == "delaylines" {
m.saveUndo("SetParam", 20) m.saveUndo("SetParam", 20)
@ -1318,7 +1350,7 @@ func (m *Model) SetParam(value int) {
m.Instrument().Units[m.d.UnitIndex].VarArgs = m.Instrument().Units[m.d.UnitIndex].VarArgs[:targetLines] m.Instrument().Units[m.d.UnitIndex].VarArgs = m.Instrument().Units[m.d.UnitIndex].VarArgs[:targetLines]
} else if p.Name == "delaytime" { } else if p.Name == "delaytime" {
m.saveUndo("SetParam", 20) m.saveUndo("SetParam", 20)
index := m.d.ParamIndex - 7 index := m.d.ParamIndex - 8
for len(m.Instrument().Units[m.d.UnitIndex].VarArgs) <= index { for len(m.Instrument().Units[m.d.UnitIndex].VarArgs) <= index {
m.Instrument().Units[m.d.UnitIndex].VarArgs = append(m.Instrument().Units[m.d.UnitIndex].VarArgs, 1) m.Instrument().Units[m.d.UnitIndex].VarArgs = append(m.Instrument().Units[m.d.UnitIndex].VarArgs, 1)
} }