mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-28 03:10:24 -04:00
refactor: rename FindSendTarget to FindUnit
This commit is contained in:
parent
43707e5fd6
commit
64270eaf68
20
patch.go
20
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)
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ func (p ParameterStyle) Layout(gtx C) D {
|
||||
var unitItems []MenuItem
|
||||
instrName := "<instr>"
|
||||
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 {
|
||||
targetInstrument := p.tracker.Song().Patch[targetI]
|
||||
instrName = targetInstrument.Name
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user