mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-28 03:10:24 -04:00
feat(tracker): add numeric updown to choose number of voices for instrument
This commit is contained in:
parent
e25015a60b
commit
21b620c824
@ -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))
|
||||
}
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user