refactor(tracker): change Iterate() func(yield):s to Iterate(yield)

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2024-10-15 09:09:17 +03:00
parent 3986bbede7
commit b494a69a76
11 changed files with 90 additions and 104 deletions

View File

@ -27,9 +27,7 @@ type (
NullMIDIContext struct{} NullMIDIContext struct{}
) )
func (m NullMIDIContext) ListInputDevices() func(yield func(tracker.MIDIDevice) bool) { func (m NullMIDIContext) InputDevices(yield func(tracker.MIDIDevice) bool) {}
return func(yield func(tracker.MIDIDevice) bool) {}
}
func (m NullMIDIContext) Close() {} func (m NullMIDIContext) Close() {}

View File

@ -35,14 +35,12 @@ func (m *Model) Alerts() *Alerts { return (*Alerts)(m) }
// Alerts methods // Alerts methods
func (m *Alerts) Iterate() func(yield func(index int, alert Alert) bool) { func (m *Alerts) Iterate(yield func(index int, alert Alert) bool) {
return func(yield func(index int, alert Alert) bool) {
for i, a := range m.alerts { for i, a := range m.alerts {
if !yield(i, a) { if !yield(i, a) {
break break
} }
} }
}
} }
func (m *Alerts) Update(d time.Duration) (animating bool) { func (m *Alerts) Update(d time.Duration) (animating bool) {

View File

@ -339,7 +339,7 @@ func (ie *InstrumentEditor) layoutUnitList(gtx C, t *Tracker) D {
addUnitBtnStyle.IconButtonStyle.Inset = layout.UniformInset(unit.Dp(4)) addUnitBtnStyle.IconButtonStyle.Inset = layout.UniformInset(unit.Dp(4))
var units [256]tracker.UnitListItem var units [256]tracker.UnitListItem
for i, item := range (*tracker.Units)(t.Model).Iterate() { for i, item := range (*tracker.Units)(t.Model).Iterate {
if i >= 256 { if i >= 256 {
break break
} }

View File

@ -36,7 +36,7 @@ func (a *PopupAlert) Layout(gtx C) D {
a.prevUpdate = now a.prevUpdate = now
var totalY float64 = float64(gtx.Dp(38)) var totalY float64 = float64(gtx.Dp(38))
for _, alert := range a.alerts.Iterate() { for _, alert := range a.alerts.Iterate {
var color, textColor, shadeColor color.NRGBA var color, textColor, shadeColor color.NRGBA
switch alert.Priority { switch alert.Priority {
case tracker.Warning: case tracker.Warning:

View File

@ -84,7 +84,7 @@ func NewSongPanel(model *tracker.Model) *SongPanel {
{IconBytes: icons.ContentRedo, Text: "Redo", ShortcutText: keyActionMap["Redo"], Doer: model.Redo()}, {IconBytes: icons.ContentRedo, Text: "Redo", ShortcutText: keyActionMap["Redo"], Doer: model.Redo()},
{IconBytes: icons.ImageCrop, Text: "Remove unused data", ShortcutText: keyActionMap["RemoveUnused"], Doer: model.RemoveUnused()}, {IconBytes: icons.ImageCrop, Text: "Remove unused data", ShortcutText: keyActionMap["RemoveUnused"], Doer: model.RemoveUnused()},
} }
for input := range model.MIDI.ListInputDevices() { for input := range model.MIDI.InputDevices {
ret.midiMenuItems = append(ret.midiMenuItems, MenuItem{ ret.midiMenuItems = append(ret.midiMenuItems, MenuItem{
IconBytes: icons.ImageControlPoint, IconBytes: icons.ImageControlPoint,
Text: input.String(), Text: input.String(),

View File

@ -102,7 +102,7 @@ func (pe *UnitEditor) layoutSliders(gtx C, t *Tracker) D {
} }
index := 0 index := 0
for param := range t.Model.Params().Iterate() { for param := range t.Model.Params().Iterate {
pe.Parameters[index].Parameter = param pe.Parameters[index].Parameter = param
index++ index++
} }
@ -176,7 +176,7 @@ func (pe *UnitEditor) layoutFooter(gtx C, t *Tracker) D {
func (pe *UnitEditor) layoutUnitTypeChooser(gtx C, t *Tracker) D { func (pe *UnitEditor) layoutUnitTypeChooser(gtx C, t *Tracker) D {
var names [256]string var names [256]string
for i, item := range t.Model.SearchResults().Iterate() { for i, item := range t.Model.SearchResults().Iterate {
if i >= 256 { if i >= 256 {
break break
} }

View File

@ -23,8 +23,7 @@ type (
} }
) )
func (m *RTMIDIContext) ListInputDevices() func(yield func(tracker.MIDIDevice) bool) { func (m *RTMIDIContext) InputDevices(yield func(tracker.MIDIDevice) bool) {
return func(yield func(tracker.MIDIDevice) bool) {
if m.driver == nil { if m.driver == nil {
return return
} }
@ -38,7 +37,6 @@ func (m *RTMIDIContext) ListInputDevices() func(yield func(tracker.MIDIDevice) b
break break
} }
} }
}
} }
// Open the driver. // Open the driver.

View File

@ -323,8 +323,7 @@ func (m *Units) SetSelectedType(t string) {
m.d.Song.Patch[m.d.InstrIndex].Units[m.d.UnitIndex].ID = oldUnit.ID // keep the ID of the replaced unit m.d.Song.Patch[m.d.InstrIndex].Units[m.d.UnitIndex].ID = oldUnit.ID // keep the ID of the replaced unit
} }
func (v *Units) Iterate() func(yield UnitYieldFunc) { func (v *Units) Iterate(yield UnitYieldFunc) {
return func(yield UnitYieldFunc) {
if v.d.InstrIndex < 0 || v.d.InstrIndex >= len(v.d.Song.Patch) { if v.d.InstrIndex < 0 || v.d.InstrIndex >= len(v.d.Song.Patch) {
return return
} }
@ -343,7 +342,6 @@ func (v *Units) Iterate() func(yield UnitYieldFunc) {
} }
stackBefore = stackAfter stackBefore = stackAfter
} }
}
} }
func (v *Units) Selected() int { func (v *Units) Selected() int {
@ -745,8 +743,7 @@ func (v *SearchResults) List() List {
return List{v} return List{v}
} }
func (l *SearchResults) Iterate() func(yield UnitSearchYieldFunc) { func (l *SearchResults) Iterate(yield UnitSearchYieldFunc) {
return func(yield UnitSearchYieldFunc) {
index := 0 index := 0
for _, name := range sointu.UnitNames { for _, name := range sointu.UnitNames {
if !strings.HasPrefix(name, l.d.UnitSearchString) { if !strings.HasPrefix(name, l.d.UnitSearchString) {
@ -757,7 +754,6 @@ func (l *SearchResults) Iterate() func(yield UnitSearchYieldFunc) {
} }
index++ index++
} }
}
} }
func (l *SearchResults) Selected() int { func (l *SearchResults) Selected() int {

View File

@ -124,7 +124,7 @@ type (
Dialog int Dialog int
MIDIContext interface { MIDIContext interface {
ListInputDevices() func(yield func(MIDIDevice) bool) InputDevices(yield func(MIDIDevice) bool)
Close() Close()
} }

View File

@ -21,9 +21,7 @@ func (NullContext) BPM() (bpm float64, ok bool) {
return 0, false return 0, false
} }
func (NullContext) ListInputDevices() func(yield func(tracker.MIDIDevice) bool) { func (NullContext) InputDevices(yield func(tracker.MIDIDevice) bool) {}
return func(yield func(tracker.MIDIDevice) bool) {}
}
func (NullContext) Close() {} func (NullContext) Close() {}
@ -292,7 +290,7 @@ func FuzzModel(f *testing.F) {
index-- index--
return index > 0 return index > 0
}, seed) }, seed)
for _, a := range model.Alerts().Iterate() { for _, a := range model.Alerts().Iterate {
if a.Name == "IDCollision" { if a.Name == "IDCollision" {
t.Errorf("Path: %s Model has ID collisions", totalPath) t.Errorf("Path: %s Model has ID collisions", totalPath)
} }

View File

@ -77,7 +77,7 @@ func (pl *Params) change(n string, severity ChangeSeverity) func() {
func (pl *Params) Count() int { func (pl *Params) Count() int {
count := 0 count := 0
for range pl.Iterate() { for range pl.Iterate {
count++ count++
} }
return count return count
@ -85,7 +85,7 @@ func (pl *Params) Count() int {
func (pl *Params) SelectedItem() (ret Parameter) { func (pl *Params) SelectedItem() (ret Parameter) {
index := pl.Selected() index := pl.Selected()
for param := range pl.Iterate() { for param := range pl.Iterate {
if index == 0 { if index == 0 {
ret = param ret = param
} }
@ -94,8 +94,7 @@ func (pl *Params) SelectedItem() (ret Parameter) {
return return
} }
func (pl *Params) Iterate() func(yield ParamYieldFunc) { func (pl *Params) Iterate(yield ParamYieldFunc) {
return func(yield ParamYieldFunc) {
if pl.d.InstrIndex < 0 || pl.d.InstrIndex >= len(pl.d.Song.Patch) { if pl.d.InstrIndex < 0 || pl.d.InstrIndex >= len(pl.d.Song.Patch) {
return return
} }
@ -143,7 +142,6 @@ func (pl *Params) Iterate() func(yield ParamYieldFunc) {
} }
} }
} }
}
} }
// NamedParameter // NamedParameter