refactor(tracker): make Bool have separate BoolValue and Enabler

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2025-05-26 13:58:45 +03:00
parent 036cb1f34d
commit fb3a0da3ed
10 changed files with 125 additions and 133 deletions

View File

@ -70,17 +70,17 @@ type (
func NewInstrumentEditor(model *tracker.Model) *InstrumentEditor {
ret := &InstrumentEditor{
newInstrumentBtn: NewActionClickable(model.AddInstrument()),
enlargeBtn: NewBoolClickable(model.InstrEnlarged().Bool()),
enlargeBtn: NewBoolClickable(model.InstrEnlarged()),
deleteInstrumentBtn: NewActionClickable(model.DeleteInstrument()),
linkInstrTrackBtn: NewBoolClickable(model.LinkInstrTrack().Bool()),
linkInstrTrackBtn: NewBoolClickable(model.LinkInstrTrack()),
splitInstrumentBtn: NewActionClickable(model.SplitInstrument()),
copyInstrumentBtn: new(TipClickable),
saveInstrumentBtn: new(TipClickable),
loadInstrumentBtn: new(TipClickable),
commentExpandBtn: NewBoolClickable(model.CommentExpanded().Bool()),
commentExpandBtn: NewBoolClickable(model.CommentExpanded()),
presetMenuBtn: new(TipClickable),
soloBtn: NewBoolClickable(model.Solo().Bool()),
muteBtn: NewBoolClickable(model.Mute().Bool()),
soloBtn: NewBoolClickable(model.Solo()),
muteBtn: NewBoolClickable(model.Mute()),
commentEditor: NewEditor(widget.Editor{}),
nameEditor: NewEditor(widget.Editor{SingleLine: true, Submit: true, Alignment: text.Middle}),
searchEditor: NewEditor(widget.Editor{SingleLine: true, Submit: true, Alignment: text.Start}),
@ -429,11 +429,11 @@ func (ie *InstrumentEditor) layoutUnitList(gtx C, t *Tracker) D {
}
}
}
t.UnitSearching().Bool().Set(false)
t.UnitSearching().SetValue(false)
ie.searchEditor.SetText(str.Value())
}
for ie.searchEditor.Cancelled(gtx) {
t.UnitSearching().Bool().Set(false)
t.UnitSearching().SetValue(false)
ie.searchEditor.SetText(str.Value())
ie.unitDragList.Focus()
}
@ -485,11 +485,11 @@ func (ie *InstrumentEditor) layoutUnitList(gtx C, t *Tracker) D {
ie.unitEditor.sliderList.Focus()
case key.NameDeleteBackward:
t.Units().SetSelectedType("")
t.UnitSearching().Bool().Set(true)
t.UnitSearching().SetValue(true)
gtx.Execute(key.FocusCmd{Tag: &ie.searchEditor.Editor})
case key.NameEnter, key.NameReturn:
t.Model.AddUnit(e.Modifiers.Contain(key.ModCtrl)).Do()
t.UnitSearching().Bool().Set(true)
t.UnitSearching().SetValue(true)
gtx.Execute(key.FocusCmd{Tag: &ie.searchEditor.Editor})
}
}

View File

@ -129,28 +129,28 @@ func (t *Tracker) KeyEvent(e key.Event, gtx C) {
case "RemoveUnused":
t.RemoveUnused().Do()
case "PlayCurrentPosFollow":
t.Follow().Bool().Set(true)
t.Follow().SetValue(true)
t.PlayCurrentPos().Do()
case "PlayCurrentPosUnfollow":
t.Follow().Bool().Set(false)
t.Follow().SetValue(false)
t.PlayCurrentPos().Do()
case "PlaySongStartFollow":
t.Follow().Bool().Set(true)
t.Follow().SetValue(true)
t.PlaySongStart().Do()
case "PlaySongStartUnfollow":
t.Follow().Bool().Set(false)
t.Follow().SetValue(false)
t.PlaySongStart().Do()
case "PlaySelectedFollow":
t.Follow().Bool().Set(true)
t.Follow().SetValue(true)
t.PlaySelected().Do()
case "PlaySelectedUnfollow":
t.Follow().Bool().Set(false)
t.Follow().SetValue(false)
t.PlaySelected().Do()
case "PlayLoopFollow":
t.Follow().Bool().Set(true)
t.Follow().SetValue(true)
t.PlayFromLoopStart().Do()
case "PlayLoopUnfollow":
t.Follow().Bool().Set(false)
t.Follow().SetValue(false)
t.PlayFromLoopStart().Do()
case "StopPlaying":
t.StopPlaying().Do()
@ -186,33 +186,33 @@ func (t *Tracker) KeyEvent(e key.Event, gtx C) {
t.SplitInstrument().Do()
// Booleans
case "PanicToggle":
t.Panic().Bool().Toggle()
t.Panic().Toggle()
case "RecordingToggle":
t.IsRecording().Bool().Toggle()
t.IsRecording().Toggle()
case "PlayingToggleFollow":
t.Follow().Bool().Set(true)
t.Playing().Bool().Toggle()
t.Follow().SetValue(true)
t.Playing().Toggle()
case "PlayingToggleUnfollow":
t.Follow().Bool().Set(false)
t.Playing().Bool().Toggle()
t.Follow().SetValue(false)
t.Playing().Toggle()
case "InstrEnlargedToggle":
t.InstrEnlarged().Bool().Toggle()
t.InstrEnlarged().Toggle()
case "LinkInstrTrackToggle":
t.LinkInstrTrack().Bool().Toggle()
t.LinkInstrTrack().Toggle()
case "CommentExpandedToggle":
t.CommentExpanded().Bool().Toggle()
t.CommentExpanded().Toggle()
case "FollowToggle":
t.Follow().Bool().Toggle()
t.Follow().Toggle()
case "UnitDisabledToggle":
t.UnitDisabled().Bool().Toggle()
t.UnitDisabled().Toggle()
case "LoopToggle":
t.LoopToggle().Bool().Toggle()
t.LoopToggle().Toggle()
case "UniquePatternsToggle":
t.UniquePatterns().Bool().Toggle()
t.UniquePatterns().Toggle()
case "MuteToggle":
t.Mute().Bool().Toggle()
t.Mute().Toggle()
case "SoloToggle":
t.Solo().Bool().Toggle()
t.Solo().Toggle()
// Integers
case "InstrumentVoicesAdd":
t.Model.InstrumentVoices().Int().Add(1)

View File

@ -85,9 +85,9 @@ func NewNoteEditor(model *tracker.Model) *NoteEditor {
AddOctaveBtn: NewActionClickable(model.AddOctave()),
SubtractOctaveBtn: NewActionClickable(model.SubtractOctave()),
NoteOffBtn: NewActionClickable(model.EditNoteOff()),
EffectBtn: NewBoolClickable(model.Effect().Bool()),
UniqueBtn: NewBoolClickable(model.UniquePatterns().Bool()),
TrackMidiInBtn: NewBoolClickable(model.TrackMidiIn().Bool()),
EffectBtn: NewBoolClickable(model.Effect()),
UniqueBtn: NewBoolClickable(model.UniquePatterns()),
TrackMidiInBtn: NewBoolClickable(model.TrackMidiIn()),
scrollTable: NewScrollTable(
model.Notes().Table(),
model.Tracks().List(),

View File

@ -45,8 +45,8 @@ type (
func NewOscilloscope(model *tracker.Model) *OscilloscopeState {
return &OscilloscopeState{
onceBtn: NewBoolClickable(model.SignalAnalyzer().Once().Bool()),
wrapBtn: NewBoolClickable(model.SignalAnalyzer().Wrap().Bool()),
onceBtn: NewBoolClickable(model.SignalAnalyzer().Once()),
wrapBtn: NewBoolClickable(model.SignalAnalyzer().Wrap()),
lengthInBeatsNumber: NewNumberInput(model.SignalAnalyzer().LengthInBeats().Int()),
triggerChannelNumber: NewNumberInput(model.SignalAnalyzer().TriggerChannel().Int()),
}

View File

@ -64,7 +64,7 @@ func (s *SongPanel) Update(gtx C, t *Tracker) {
t.Model.DetectorWeighting().Int().Set((t.DetectorWeighting().Value() + 1) % int(tracker.NumWeightingTypes))
}
for s.OversamplingBtn.Clicked(gtx) {
t.Model.Oversampling().Bool().Set(!t.Oversampling().Value())
t.Model.Oversampling().SetValue(!t.Oversampling().Value())
}
}
@ -301,7 +301,7 @@ func NewMenuBar(model *tracker.Model) *MenuBar {
ret := &MenuBar{
Clickables: make([]Clickable, 3),
Menus: make([]Menu, 3),
PanicBtn: NewBoolClickable(model.Panic().Bool()),
PanicBtn: NewBoolClickable(model.Panic()),
panicHint: makeHint("Panic", " (%s)", "PanicToggle"),
}
ret.fileMenuItems = []MenuItem{
@ -369,10 +369,10 @@ type PlayBar struct {
func NewPlayBar(model *tracker.Model) *PlayBar {
ret := &PlayBar{
LoopBtn: NewBoolClickable(model.LoopToggle().Bool()),
RecordBtn: NewBoolClickable(model.IsRecording().Bool()),
FollowBtn: NewBoolClickable(model.Follow().Bool()),
PlayingBtn: NewBoolClickable(model.Playing().Bool()),
LoopBtn: NewBoolClickable(model.LoopToggle()),
RecordBtn: NewBoolClickable(model.IsRecording()),
FollowBtn: NewBoolClickable(model.Follow()),
PlayingBtn: NewBoolClickable(model.Playing()),
RewindBtn: NewActionClickable(model.PlaySongStart()),
}
ret.rewindHint = makeHint("Rewind", "\n(%s)", "PlaySongStartUnfollow")

View File

@ -46,7 +46,7 @@ func NewUnitEditor(m *tracker.Model) *UnitEditor {
ret := &UnitEditor{
DeleteUnitBtn: NewActionClickable(m.DeleteUnit()),
ClearUnitBtn: NewActionClickable(m.ClearUnit()),
DisableUnitBtn: NewBoolClickable(m.UnitDisabled().Bool()),
DisableUnitBtn: NewBoolClickable(m.UnitDisabled()),
CopyUnitBtn: new(TipClickable),
SelectTypeBtn: new(Clickable),
commentEditor: NewEditor(widget.Editor{SingleLine: true, Submit: true}),