diff --git a/tracker/instruments.go b/tracker/instruments.go index ef1f9f6..61eee1a 100644 --- a/tracker/instruments.go +++ b/tracker/instruments.go @@ -67,6 +67,20 @@ func (t *Tracker) layoutInstrumentHeader() layout.Widget { deleteInstrumentBtnStyle.Color = disabledTextColor } return layout.Flex{Axis: layout.Horizontal}.Layout(gtx, + layout.Rigid(Label("Voices:", white)), + layout.Rigid(func(gtx layout.Context) layout.Dimensions { + maxRemain := 32 - t.song.Patch.TotalVoices() + t.song.Patch.Instruments[t.CurrentInstrument].NumVoices + if maxRemain < 0 { + maxRemain = 0 + } + t.InstrumentVoices.Value = t.song.Patch.Instruments[t.CurrentInstrument].NumVoices + numStyle := NumericUpDown(t.Theme, t.InstrumentVoices, 0, maxRemain) + gtx.Constraints.Min.Y = gtx.Px(unit.Dp(20)) + gtx.Constraints.Min.X = gtx.Px(unit.Dp(70)) + dims := numStyle.Layout(gtx) + t.SetInstrumentVoices(t.InstrumentVoices.Value) + return dims + }), layout.Flexed(1, func(gtx C) D { return layout.Dimensions{Size: gtx.Constraints.Min} }), layout.Rigid(deleteInstrumentBtnStyle.Layout)) } diff --git a/tracker/tracker.go b/tracker/tracker.go index c53b85e..8f6ec74 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -31,6 +31,7 @@ type Tracker struct { BPM *NumberInput RowsPerPattern *NumberInput RowsPerBeat *NumberInput + InstrumentVoices *NumberInput NewTrackBtn *widget.Clickable NewInstrumentBtn *widget.Clickable DeleteInstrumentBtn *widget.Clickable @@ -166,6 +167,26 @@ func (t *Tracker) ChangeOctave(delta int) bool { return false } +func (t *Tracker) SetInstrumentVoices(value int) bool { + if value < 1 { + value = 1 + } + maxRemain := 32 - t.song.Patch.TotalVoices() + t.song.Patch.Instruments[t.CurrentInstrument].NumVoices + if maxRemain < 1 { + maxRemain = 1 + } + if value > maxRemain { + value = maxRemain + } + if value != int(t.song.Patch.Instruments[t.CurrentInstrument].NumVoices) { + t.SaveUndo() + t.song.Patch.Instruments[t.CurrentInstrument].NumVoices = value + t.sequencer.SetPatch(t.song.Patch) + return true + } + return false +} + func (t *Tracker) SetBPM(value int) bool { if value < 1 { value = 1 @@ -383,6 +404,7 @@ func New(audioContext sointu.AudioContext) *Tracker { SongLength: new(NumberInput), RowsPerPattern: new(NumberInput), RowsPerBeat: new(NumberInput), + InstrumentVoices: new(NumberInput), NewTrackBtn: new(widget.Clickable), NewInstrumentBtn: new(widget.Clickable), DeleteInstrumentBtn: new(widget.Clickable),