From d01657ab830eeacb32a8817b29872b7ef8028aab Mon Sep 17 00:00:00 2001 From: vsariola <5684185+vsariola@users.noreply.github.com> Date: Fri, 12 Feb 2021 08:43:27 +0200 Subject: [PATCH] feat(tracker): add numeric up down to adjust number of voices per track --- tracker/track.go | 18 +++++++++++++++++- tracker/tracker.go | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/tracker/track.go b/tracker/track.go index b5c2c2d..f004301 100644 --- a/tracker/track.go +++ b/tracker/track.go @@ -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, diff --git a/tracker/tracker.go b/tracker/tracker.go index 92cfd1d..1d3ec58 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -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),