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{}
)
func (m NullMIDIContext) ListInputDevices() func(yield func(tracker.MIDIDevice) bool) {
return func(yield func(tracker.MIDIDevice) bool) {}
}
func (m NullMIDIContext) InputDevices(yield func(tracker.MIDIDevice) bool) {}
func (m NullMIDIContext) Close() {}

View File

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

View File

@ -339,7 +339,7 @@ func (ie *InstrumentEditor) layoutUnitList(gtx C, t *Tracker) D {
addUnitBtnStyle.IconButtonStyle.Inset = layout.UniformInset(unit.Dp(4))
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 {
break
}

View File

@ -36,7 +36,7 @@ func (a *PopupAlert) Layout(gtx C) D {
a.prevUpdate = now
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
switch alert.Priority {
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.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{
IconBytes: icons.ImageControlPoint,
Text: input.String(),

View File

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

View File

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

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
}
func (v *Units) Iterate() func(yield UnitYieldFunc) {
return func(yield UnitYieldFunc) {
func (v *Units) Iterate(yield UnitYieldFunc) {
if v.d.InstrIndex < 0 || v.d.InstrIndex >= len(v.d.Song.Patch) {
return
}
@ -344,7 +343,6 @@ func (v *Units) Iterate() func(yield UnitYieldFunc) {
stackBefore = stackAfter
}
}
}
func (v *Units) Selected() int {
return intMax(intMin(v.d.UnitIndex, v.Count()-1), 0)
@ -745,8 +743,7 @@ func (v *SearchResults) List() List {
return List{v}
}
func (l *SearchResults) Iterate() func(yield UnitSearchYieldFunc) {
return func(yield UnitSearchYieldFunc) {
func (l *SearchResults) Iterate(yield UnitSearchYieldFunc) {
index := 0
for _, name := range sointu.UnitNames {
if !strings.HasPrefix(name, l.d.UnitSearchString) {
@ -758,7 +755,6 @@ func (l *SearchResults) Iterate() func(yield UnitSearchYieldFunc) {
index++
}
}
}
func (l *SearchResults) Selected() int {
return intMax(intMin(l.d.UnitSearchIndex, l.Count()-1), 0)

View File

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

View File

@ -21,9 +21,7 @@ func (NullContext) BPM() (bpm float64, ok bool) {
return 0, false
}
func (NullContext) ListInputDevices() func(yield func(tracker.MIDIDevice) bool) {
return func(yield func(tracker.MIDIDevice) bool) {}
}
func (NullContext) InputDevices(yield func(tracker.MIDIDevice) bool) {}
func (NullContext) Close() {}
@ -292,7 +290,7 @@ func FuzzModel(f *testing.F) {
index--
return index > 0
}, seed)
for _, a := range model.Alerts().Iterate() {
for _, a := range model.Alerts().Iterate {
if a.Name == "IDCollision" {
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 {
count := 0
for range pl.Iterate() {
for range pl.Iterate {
count++
}
return count
@ -85,7 +85,7 @@ func (pl *Params) Count() int {
func (pl *Params) SelectedItem() (ret Parameter) {
index := pl.Selected()
for param := range pl.Iterate() {
for param := range pl.Iterate {
if index == 0 {
ret = param
}
@ -94,8 +94,7 @@ func (pl *Params) SelectedItem() (ret Parameter) {
return
}
func (pl *Params) Iterate() func(yield ParamYieldFunc) {
return func(yield ParamYieldFunc) {
func (pl *Params) Iterate(yield ParamYieldFunc) {
if pl.d.InstrIndex < 0 || pl.d.InstrIndex >= len(pl.d.Song.Patch) {
return
}
@ -144,7 +143,6 @@ func (pl *Params) Iterate() func(yield ParamYieldFunc) {
}
}
}
}
// NamedParameter