feat(tracker): add numeric up down to adjust number of voices per track

This commit is contained in:
vsariola 2021-02-12 08:43:27 +02:00
parent 10f53bdbf7
commit d01657ab83
2 changed files with 38 additions and 1 deletions

View File

@ -104,7 +104,19 @@ func (t *Tracker) layoutTracker(gtx layout.Context) layout.Dimensions {
gtx.Constraints.Min.X = gtx.Px(unit.Dp(70))
return in.Layout(gtx, numStyle.Layout)
}
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
n := t.song.Tracks[t.Cursor.Track].NumVoices
maxRemain := t.song.Patch.TotalVoices() - t.song.TotalTrackVoices() + n
if maxRemain < 1 {
maxRemain = 1
}
t.TrackVoices.Value = n
voiceUpDown := func(gtx C) D {
numStyle := NumericUpDown(t.Theme, t.TrackVoices, 1, maxRemain)
gtx.Constraints.Min.Y = gtx.Px(unit.Dp(20))
gtx.Constraints.Min.X = gtx.Px(unit.Dp(70))
return in.Layout(gtx, numStyle.Layout)
}
dims := layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
layout.Rigid(Label("OCT:", white)),
layout.Rigid(octave),
layout.Rigid(Label(" PITCH:", white)),
@ -112,8 +124,12 @@ func (t *Tracker) layoutTracker(gtx layout.Context) layout.Dimensions {
layout.Rigid(subtractSemitoneBtnStyle.Layout),
layout.Rigid(addOctaveBtnStyle.Layout),
layout.Rigid(subtractOctaveBtnStyle.Layout),
layout.Rigid(Label("Voices:", white)),
layout.Rigid(voiceUpDown),
layout.Flexed(1, func(gtx C) D { return layout.Dimensions{Size: gtx.Constraints.Min} }),
layout.Rigid(newTrackBtnStyle.Layout))
t.SetTrackVoices(t.TrackVoices.Value)
return dims
}
return layout.Flex{Axis: layout.Vertical}.Layout(gtx,

View File

@ -47,6 +47,7 @@ type Tracker struct {
RowsPerPattern *NumberInput
RowsPerBeat *NumberInput
InstrumentVoices *NumberInput
TrackVoices *NumberInput
InstrumentNameEditor *widget.Editor
NewTrackBtn *widget.Clickable
NewInstrumentBtn *widget.Clickable
@ -220,6 +221,25 @@ func (t *Tracker) AddTrack() {
}
}
func (t *Tracker) SetTrackVoices(value int) bool {
if value < 1 {
value = 1
}
maxRemain := t.song.Patch.TotalVoices() - t.song.TotalTrackVoices() + t.song.Tracks[t.Cursor.Track].NumVoices
if maxRemain < 1 {
maxRemain = 1
}
if value > maxRemain {
value = maxRemain
}
if value != int(t.song.Tracks[t.Cursor.Track].NumVoices) {
t.SaveUndo()
t.song.Tracks[t.Cursor.Track].NumVoices = value
return true
}
return false
}
func (t *Tracker) AddInstrument() {
if t.song.Patch.TotalVoices() >= 32 {
return
@ -519,6 +539,7 @@ func New(audioContext sointu.AudioContext, synthService sointu.SynthService) *Tr
RowsPerPattern: new(NumberInput),
RowsPerBeat: new(NumberInput),
InstrumentVoices: new(NumberInput),
TrackVoices: new(NumberInput),
InstrumentNameEditor: &widget.Editor{SingleLine: true, Submit: true, Alignment: text.Middle},
NewTrackBtn: new(widget.Clickable),
NewInstrumentBtn: new(widget.Clickable),