feat(sointu): add instrument name field and use it to name more sensible defaults

This commit is contained in:
vsariola 2021-02-06 19:10:37 +02:00
parent b34161b173
commit ef59c4a61a
4 changed files with 31 additions and 23 deletions

View File

@ -33,6 +33,7 @@ const (
// Instrument includes a list of units consisting of the instrument, and the number of polyphonic voices for this instrument
type Instrument struct {
Name string
NumVoices int
Units []Unit
}
@ -42,7 +43,7 @@ func (instr *Instrument) Copy() Instrument {
for i, u := range instr.Units {
units[i] = u.Copy()
}
return Instrument{NumVoices: instr.NumVoices, Units: units}
return Instrument{Name: instr.Name, NumVoices: instr.NumVoices, Units: units}
}
// Patch is simply a list of instruments used in a song

View File

@ -33,9 +33,7 @@ var defaultUnits = map[string]sointu.Unit{
"aux": {Type: "aux", Parameters: map[string]int{"stereo": 1, "gain": 64, "channel": 2}},
"delay": {Type: "delay",
Parameters: map[string]int{"damp": 0, "dry": 128, "feedback": 96, "notetracking": 0, "pregain": 40, "stereo": 0},
VarArgs: []int{1116, 1188, 1276, 1356, 1422, 1492, 1556, 1618,
1140, 1212, 1300, 1380, 1446, 1516, 1580, 1642,
}},
VarArgs: []int{6615 * 2}},
"in": {Type: "in", Parameters: map[string]int{"stereo": 1, "channel": 2}},
"speed": {Type: "speed", Parameters: map[string]int{}},
"compressor": {Type: "compressor", Parameters: map[string]int{"stereo": 0, "attack": 64, "release": 64, "invgain": 64, "threshold": 64, "ratio": 64}},
@ -52,6 +50,7 @@ func init() {
}
var defaultInstrument = sointu.Instrument{
Name: "Instr",
NumVoices: 1,
Units: []sointu.Unit{
defaultUnits["envelope"],
@ -59,7 +58,7 @@ var defaultInstrument = sointu.Instrument{
defaultUnits["mulp"],
defaultUnits["delay"],
defaultUnits["pan"],
defaultUnits["out"],
defaultUnits["outaux"],
},
}
@ -68,8 +67,17 @@ var defaultSong = sointu.Song{
RowsPerPattern: 16,
RowsPerBeat: 4,
Tracks: []sointu.Track{
{NumVoices: 2, Sequence: []byte{0, 0, 0, 1}, Patterns: [][]byte{{64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0, 0, 0}, {64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 75, 0, 75, 0, 80, 0}}},
{NumVoices: 2, Sequence: []byte{0, 0, 0, 1}, Patterns: [][]byte{{0, 0, 64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0}, {32, 0, 64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 68, 0, 68, 0}}},
{NumVoices: 1, Sequence: []byte{0, 0, 0, 1}, Patterns: [][]byte{{64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 78, 0, 0, 0, 0, 0}, {64, 0, 68, 0, 32, 0, 0, 0, 75, 0, 75, 0, 75, 0, 80, 0}}},
},
Patch: sointu.Patch{Instruments: []sointu.Instrument{{NumVoices: 4, Units: defaultInstrument.Units}}},
Patch: sointu.Patch{Instruments: []sointu.Instrument{
defaultInstrument,
{Name: "Global", NumVoices: 1, Units: []sointu.Unit{
defaultUnits["in"],
{Type: "delay",
Parameters: map[string]int{"damp": 0, "dry": 128, "feedback": 96, "notetracking": 0, "pregain": 40, "stereo": 1},
VarArgs: []int{1116, 1188, 1276, 1356, 1422, 1492, 1556, 1618,
1140, 1212, 1300, 1380, 1446, 1516, 1580, 1642,
}},
defaultUnits["out"],
}}}},
}

View File

@ -93,7 +93,11 @@ func (t *Tracker) layoutInstrumentNames(gtx C) D {
element := func(gtx C, i int) D {
gtx.Constraints.Min.Y = gtx.Px(unit.Dp(36))
labelStyle := LabelStyle{Text: fmt.Sprintf("%v", i), ShadeColor: black, Color: white, Font: labelDefaultFont, FontSize: unit.Sp(12)}
text := t.song.Patch.Instruments[i].Name
if text == "" {
text = fmt.Sprintf("%v", i)
}
labelStyle := LabelStyle{Text: text, ShadeColor: black, Color: white, Font: labelDefaultFont, FontSize: unit.Sp(12)}
return layout.Inset{Left: unit.Dp(10), Right: unit.Dp(10)}.Layout(gtx, func(gtx C) D {
return layout.Center.Layout(gtx, labelStyle.Layout)
})

View File

@ -210,21 +210,16 @@ func (t *Tracker) AddTrack() {
}
func (t *Tracker) AddInstrument() {
t.SaveUndo()
if t.song.Patch.TotalVoices() < 32 {
units := make([]sointu.Unit, len(defaultInstrument.Units))
for i, defUnit := range defaultInstrument.Units {
units[i].Type = defUnit.Type
units[i].Parameters = make(map[string]int)
for k, v := range defUnit.Parameters {
units[i].Parameters[k] = v
}
}
t.song.Patch.Instruments = append(t.song.Patch.Instruments, sointu.Instrument{
NumVoices: defaultInstrument.NumVoices,
Units: units,
})
if t.song.Patch.TotalVoices() >= 32 {
return
}
t.SaveUndo()
instr := make([]sointu.Instrument, len(t.song.Patch.Instruments)+1)
copy(instr, t.song.Patch.Instruments[:t.CurrentInstrument+1])
instr[t.CurrentInstrument+1] = defaultInstrument.Copy()
copy(instr[t.CurrentInstrument+2:], t.song.Patch.Instruments[t.CurrentInstrument+1:])
t.song.Patch.Instruments = instr
t.CurrentInstrument++
t.sequencer.SetPatch(t.song.Patch)
}