From 64270eaf6890d018b964bd5a78ca0154e4b49b07 Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Thu, 19 Oct 2023 13:31:34 +0300 Subject: [PATCH] refactor: rename FindSendTarget to FindUnit --- patch.go | 20 ++++++++++---------- tracker/gioui/parameter.go | 2 +- tracker/model.go | 2 +- vm/bytecode.go | 2 +- vm/featureset.go | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/patch.go b/patch.go index c11c0b5..8817c2b 100644 --- a/patch.go +++ b/patch.go @@ -330,14 +330,14 @@ func (p Patch) InstrumentForVoice(voice int) (int, error) { return 0, errors.New("voice number is beyond the total voices of an instrument") } -// FindSendTarget searches the instrument number and unit index for a unit with -// the given id. Two units should never have the same id, but if they do, then -// the first match is returned. Id 0 is interpreted as "no id", thus searching -// for id 0 returns an error. Error is also returned if the searched id is not +// FindUnit searches the instrument index and unit index for a unit with the +// given id. Two units should never have the same id, but if they do, then the +// first match is returned. Id 0 is interpreted as "no id", thus searching for +// id 0 returns an error. Error is also returned if the searched id is not // found. -func (p Patch) FindSendTarget(id int) (int, int, error) { +func (p Patch) FindUnit(id int) (instrIndex int, unitIndex int, err error) { if id == 0 { - return 0, 0, errors.New("send targets unit id 0") + return 0, 0, errors.New("FindUnit called with id 0") } for i, instr := range p { for u, unit := range instr.Units { @@ -346,7 +346,7 @@ func (p Patch) FindSendTarget(id int) (int, int, error) { } } } - return 0, 0, fmt.Errorf("send targets an unit with id %v, could not find a unit with such an ID in the patch", id) + return 0, 0, fmt.Errorf("could not find a unit with id %v", id) } // ParamHintString returns a human readable string representing the current @@ -421,7 +421,7 @@ func (p Patch) ParamHintString(instrIndex, unitIndex int, param string) string { return fmt.Sprintf("%.2f", float32(value)/64-1) case "voice": if value == 0 { - targetIndex, _, err := p.FindSendTarget(unit.Parameters["target"]) + targetIndex, _, err := p.FindUnit(unit.Parameters["target"]) if err == nil && targetIndex != instrIndex { return "all" } @@ -429,7 +429,7 @@ func (p Patch) ParamHintString(instrIndex, unitIndex int, param string) string { } return fmt.Sprintf("%v", value) case "target": - instrIndex, unitIndex, err := p.FindSendTarget(unit.Parameters["target"]) + instrIndex, unitIndex, err := p.FindUnit(unit.Parameters["target"]) if err != nil { return "invalid target" } @@ -437,7 +437,7 @@ func (p Patch) ParamHintString(instrIndex, unitIndex int, param string) string { unit := instr.Units[unitIndex] return fmt.Sprintf("%v / %v%v", instr.Name, unit.Type, unitIndex) case "port": - instrIndex, unitIndex, err := p.FindSendTarget(unit.Parameters["target"]) + instrIndex, unitIndex, err := p.FindUnit(unit.Parameters["target"]) if err != nil { return fmt.Sprintf("%v ???", value) } diff --git a/tracker/gioui/parameter.go b/tracker/gioui/parameter.go index 99af94d..1548187 100644 --- a/tracker/gioui/parameter.go +++ b/tracker/gioui/parameter.go @@ -125,7 +125,7 @@ func (p ParameterStyle) Layout(gtx C) D { var unitItems []MenuItem instrName := "" unitName := "" - targetI, targetU, err := p.tracker.Song().Patch.FindSendTarget(p.Parameter.Value) + targetI, targetU, err := p.tracker.Song().Patch.FindUnit(p.Parameter.Value) if err == nil { targetInstrument := p.tracker.Song().Patch[targetI] instrName = targetInstrument.Name diff --git a/tracker/model.go b/tracker/model.go index 23ff78c..79e7e87 100644 --- a/tracker/model.go +++ b/tracker/model.go @@ -1195,7 +1195,7 @@ func (m *Model) Param(index int) (Parameter, error) { min, max := t.MinValue, t.MaxValue if unit.Type == "send" { if t.Name == "voice" { - i, _, err := m.d.Song.Patch.FindSendTarget(unit.Parameters["target"]) + i, _, err := m.d.Song.Patch.FindUnit(unit.Parameters["target"]) if err == nil { max = m.d.Song.Patch[i].NumVoices } diff --git a/vm/bytecode.go b/vm/bytecode.go index 32c08a5..de1af53 100644 --- a/vm/bytecode.go +++ b/vm/bytecode.go @@ -155,7 +155,7 @@ func NewBytecode(patch sointu.Patch, featureSet FeatureSet, bpm int) (*Bytecode, b.operand(flags) case "send": targetID := unit.Parameters["target"] - targetInstrIndex, _, err := patch.FindSendTarget(targetID) + targetInstrIndex, _, err := patch.FindUnit(targetID) targetVoice := unit.Parameters["voice"] addr := unit.Parameters["port"] & 7 if err == nil { diff --git a/vm/featureset.go b/vm/featureset.go index 5e997c1..c94724b 100644 --- a/vm/featureset.go +++ b/vm/featureset.go @@ -134,7 +134,7 @@ func NecessaryFeaturesFor(patch sointu.Patch) NecessaryFeatures { features.supportsParamValue[key][v] = true } if unit.Type == "send" { - targetInstrIndex, targetUnitIndex, err := patch.FindSendTarget(unit.Parameters["target"]) + targetInstrIndex, targetUnitIndex, err := patch.FindUnit(unit.Parameters["target"]) if err != nil { continue }