mirror of
https://github.com/vsariola/sointu.git
synced 2025-07-18 04:54:27 -04:00
feat(sointu): add instrument name field and use it to name more sensible defaults
This commit is contained in:
@ -33,6 +33,7 @@ const (
|
|||||||
|
|
||||||
// Instrument includes a list of units consisting of the instrument, and the number of polyphonic voices for this instrument
|
// Instrument includes a list of units consisting of the instrument, and the number of polyphonic voices for this instrument
|
||||||
type Instrument struct {
|
type Instrument struct {
|
||||||
|
Name string
|
||||||
NumVoices int
|
NumVoices int
|
||||||
Units []Unit
|
Units []Unit
|
||||||
}
|
}
|
||||||
@ -42,7 +43,7 @@ func (instr *Instrument) Copy() Instrument {
|
|||||||
for i, u := range instr.Units {
|
for i, u := range instr.Units {
|
||||||
units[i] = u.Copy()
|
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
|
// Patch is simply a list of instruments used in a song
|
||||||
|
@ -33,9 +33,7 @@ var defaultUnits = map[string]sointu.Unit{
|
|||||||
"aux": {Type: "aux", Parameters: map[string]int{"stereo": 1, "gain": 64, "channel": 2}},
|
"aux": {Type: "aux", Parameters: map[string]int{"stereo": 1, "gain": 64, "channel": 2}},
|
||||||
"delay": {Type: "delay",
|
"delay": {Type: "delay",
|
||||||
Parameters: map[string]int{"damp": 0, "dry": 128, "feedback": 96, "notetracking": 0, "pregain": 40, "stereo": 0},
|
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,
|
VarArgs: []int{6615 * 2}},
|
||||||
1140, 1212, 1300, 1380, 1446, 1516, 1580, 1642,
|
|
||||||
}},
|
|
||||||
"in": {Type: "in", Parameters: map[string]int{"stereo": 1, "channel": 2}},
|
"in": {Type: "in", Parameters: map[string]int{"stereo": 1, "channel": 2}},
|
||||||
"speed": {Type: "speed", Parameters: map[string]int{}},
|
"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}},
|
"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{
|
var defaultInstrument = sointu.Instrument{
|
||||||
|
Name: "Instr",
|
||||||
NumVoices: 1,
|
NumVoices: 1,
|
||||||
Units: []sointu.Unit{
|
Units: []sointu.Unit{
|
||||||
defaultUnits["envelope"],
|
defaultUnits["envelope"],
|
||||||
@ -59,7 +58,7 @@ var defaultInstrument = sointu.Instrument{
|
|||||||
defaultUnits["mulp"],
|
defaultUnits["mulp"],
|
||||||
defaultUnits["delay"],
|
defaultUnits["delay"],
|
||||||
defaultUnits["pan"],
|
defaultUnits["pan"],
|
||||||
defaultUnits["out"],
|
defaultUnits["outaux"],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,8 +67,17 @@ var defaultSong = sointu.Song{
|
|||||||
RowsPerPattern: 16,
|
RowsPerPattern: 16,
|
||||||
RowsPerBeat: 4,
|
RowsPerBeat: 4,
|
||||||
Tracks: []sointu.Track{
|
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: 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}}},
|
||||||
{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}}},
|
|
||||||
},
|
},
|
||||||
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"],
|
||||||
|
}}}},
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,11 @@ func (t *Tracker) layoutInstrumentNames(gtx C) D {
|
|||||||
|
|
||||||
element := func(gtx C, i int) D {
|
element := func(gtx C, i int) D {
|
||||||
gtx.Constraints.Min.Y = gtx.Px(unit.Dp(36))
|
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.Inset{Left: unit.Dp(10), Right: unit.Dp(10)}.Layout(gtx, func(gtx C) D {
|
||||||
return layout.Center.Layout(gtx, labelStyle.Layout)
|
return layout.Center.Layout(gtx, labelStyle.Layout)
|
||||||
})
|
})
|
||||||
|
@ -210,21 +210,16 @@ func (t *Tracker) AddTrack() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tracker) AddInstrument() {
|
func (t *Tracker) AddInstrument() {
|
||||||
|
if t.song.Patch.TotalVoices() >= 32 {
|
||||||
|
return
|
||||||
|
}
|
||||||
t.SaveUndo()
|
t.SaveUndo()
|
||||||
if t.song.Patch.TotalVoices() < 32 {
|
instr := make([]sointu.Instrument, len(t.song.Patch.Instruments)+1)
|
||||||
units := make([]sointu.Unit, len(defaultInstrument.Units))
|
copy(instr, t.song.Patch.Instruments[:t.CurrentInstrument+1])
|
||||||
for i, defUnit := range defaultInstrument.Units {
|
instr[t.CurrentInstrument+1] = defaultInstrument.Copy()
|
||||||
units[i].Type = defUnit.Type
|
copy(instr[t.CurrentInstrument+2:], t.song.Patch.Instruments[t.CurrentInstrument+1:])
|
||||||
units[i].Parameters = make(map[string]int)
|
t.song.Patch.Instruments = instr
|
||||||
for k, v := range defUnit.Parameters {
|
t.CurrentInstrument++
|
||||||
units[i].Parameters[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
t.song.Patch.Instruments = append(t.song.Patch.Instruments, sointu.Instrument{
|
|
||||||
NumVoices: defaultInstrument.NumVoices,
|
|
||||||
Units: units,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
t.sequencer.SetPatch(t.song.Patch)
|
t.sequencer.SetPatch(t.song.Patch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user