refactor: rename FindSendTarget to FindUnit

This commit is contained in:
5684185+vsariola@users.noreply.github.com 2023-10-19 13:31:34 +03:00
parent 43707e5fd6
commit 64270eaf68
5 changed files with 14 additions and 14 deletions

View File

@ -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") 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 // FindUnit searches the instrument index and unit index for a unit with the
// the given id. Two units should never have the same id, but if they do, then // given id. Two units should never have the same id, but if they do, then the
// the first match is returned. Id 0 is interpreted as "no id", thus searching // first match is returned. Id 0 is interpreted as "no id", thus searching for
// for id 0 returns an error. Error is also returned if the searched id is not // id 0 returns an error. Error is also returned if the searched id is not
// found. // 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 { 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 i, instr := range p {
for u, unit := range instr.Units { 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 // 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) return fmt.Sprintf("%.2f", float32(value)/64-1)
case "voice": case "voice":
if value == 0 { if value == 0 {
targetIndex, _, err := p.FindSendTarget(unit.Parameters["target"]) targetIndex, _, err := p.FindUnit(unit.Parameters["target"])
if err == nil && targetIndex != instrIndex { if err == nil && targetIndex != instrIndex {
return "all" return "all"
} }
@ -429,7 +429,7 @@ func (p Patch) ParamHintString(instrIndex, unitIndex int, param string) string {
} }
return fmt.Sprintf("%v", value) return fmt.Sprintf("%v", value)
case "target": case "target":
instrIndex, unitIndex, err := p.FindSendTarget(unit.Parameters["target"]) instrIndex, unitIndex, err := p.FindUnit(unit.Parameters["target"])
if err != nil { if err != nil {
return "invalid target" return "invalid target"
} }
@ -437,7 +437,7 @@ func (p Patch) ParamHintString(instrIndex, unitIndex int, param string) string {
unit := instr.Units[unitIndex] unit := instr.Units[unitIndex]
return fmt.Sprintf("%v / %v%v", instr.Name, unit.Type, unitIndex) return fmt.Sprintf("%v / %v%v", instr.Name, unit.Type, unitIndex)
case "port": case "port":
instrIndex, unitIndex, err := p.FindSendTarget(unit.Parameters["target"]) instrIndex, unitIndex, err := p.FindUnit(unit.Parameters["target"])
if err != nil { if err != nil {
return fmt.Sprintf("%v ???", value) return fmt.Sprintf("%v ???", value)
} }

View File

@ -125,7 +125,7 @@ func (p ParameterStyle) Layout(gtx C) D {
var unitItems []MenuItem var unitItems []MenuItem
instrName := "<instr>" instrName := "<instr>"
unitName := "<unit>" unitName := "<unit>"
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 { if err == nil {
targetInstrument := p.tracker.Song().Patch[targetI] targetInstrument := p.tracker.Song().Patch[targetI]
instrName = targetInstrument.Name instrName = targetInstrument.Name

View File

@ -1195,7 +1195,7 @@ func (m *Model) Param(index int) (Parameter, error) {
min, max := t.MinValue, t.MaxValue min, max := t.MinValue, t.MaxValue
if unit.Type == "send" { if unit.Type == "send" {
if t.Name == "voice" { 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 { if err == nil {
max = m.d.Song.Patch[i].NumVoices max = m.d.Song.Patch[i].NumVoices
} }

View File

@ -155,7 +155,7 @@ func NewBytecode(patch sointu.Patch, featureSet FeatureSet, bpm int) (*Bytecode,
b.operand(flags) b.operand(flags)
case "send": case "send":
targetID := unit.Parameters["target"] targetID := unit.Parameters["target"]
targetInstrIndex, _, err := patch.FindSendTarget(targetID) targetInstrIndex, _, err := patch.FindUnit(targetID)
targetVoice := unit.Parameters["voice"] targetVoice := unit.Parameters["voice"]
addr := unit.Parameters["port"] & 7 addr := unit.Parameters["port"] & 7
if err == nil { if err == nil {

View File

@ -134,7 +134,7 @@ func NecessaryFeaturesFor(patch sointu.Patch) NecessaryFeatures {
features.supportsParamValue[key][v] = true features.supportsParamValue[key][v] = true
} }
if unit.Type == "send" { if unit.Type == "send" {
targetInstrIndex, targetUnitIndex, err := patch.FindSendTarget(unit.Parameters["target"]) targetInstrIndex, targetUnitIndex, err := patch.FindUnit(unit.Parameters["target"])
if err != nil { if err != nil {
continue continue
} }