mirror of
https://github.com/vsariola/sointu.git
synced 2025-06-04 01:28:45 -04:00
feat(sointu, tracker): find the send targets ports easily and use this to figure slider maximums dynamically
There is a new helper function in Sointu to find the target of a send. In future, compiler and others should be refactored to use this function to find send targets. Closes #31
This commit is contained in:
parent
0f136d544c
commit
83d6277ae6
54
sointu.go
54
sointu.go
@ -268,6 +268,20 @@ var UnitTypes = map[string]([]UnitParameter){
|
|||||||
{Name: "channel", MinValue: 0, MaxValue: 6, CanSet: true, CanModulate: false}},
|
{Name: "channel", MinValue: 0, MaxValue: 6, CanSet: true, CanModulate: false}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var Ports = make(map[string]([]string))
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
for name, unitType := range UnitTypes {
|
||||||
|
unitPorts := make([]string, 0)
|
||||||
|
for _, param := range unitType {
|
||||||
|
if param.CanModulate {
|
||||||
|
unitPorts = append(unitPorts, param.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ports[name] = unitPorts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Song struct {
|
type Song struct {
|
||||||
BPM int
|
BPM int
|
||||||
RowsPerPattern int
|
RowsPerPattern int
|
||||||
@ -358,6 +372,46 @@ func (s *Song) Validate() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Patch) FindSendTarget(i, u int) (int, int, int, error) {
|
||||||
|
if i < 0 || i >= len(p.Instruments) {
|
||||||
|
return -1, -1, -1, errors.New("instrument index out of range")
|
||||||
|
}
|
||||||
|
instr := p.Instruments[i]
|
||||||
|
if u < 0 || u >= len(instr.Units) {
|
||||||
|
return -1, -1, -1, errors.New("unit index out of range")
|
||||||
|
}
|
||||||
|
unit := instr.Units[u]
|
||||||
|
var targetInstrIndex int
|
||||||
|
if unit.Parameters["voice"] == 0 {
|
||||||
|
targetInstrIndex = i
|
||||||
|
} else {
|
||||||
|
var err error
|
||||||
|
targetInstrIndex, err = p.InstrumentForVoice(unit.Parameters["voice"] - 1)
|
||||||
|
if err != nil {
|
||||||
|
return -1, -1, -1, errors.New("the target voice was out of range")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
targetInstr := p.Instruments[targetInstrIndex]
|
||||||
|
targetUnitIndex := unit.Parameters["unit"]
|
||||||
|
if targetUnitIndex < 0 || targetUnitIndex >= len(targetInstr.Units) {
|
||||||
|
return targetInstrIndex, -1, -1, errors.New("the target unit was out of range")
|
||||||
|
}
|
||||||
|
targetUnit := targetInstr.Units[targetUnitIndex]
|
||||||
|
port := unit.Parameters["port"]
|
||||||
|
if port < 0 {
|
||||||
|
return targetInstrIndex, targetUnitIndex, -1, errors.New("the target port was out of range")
|
||||||
|
}
|
||||||
|
for k, param := range UnitTypes[targetUnit.Type] {
|
||||||
|
if param.CanModulate {
|
||||||
|
port--
|
||||||
|
if port < 0 {
|
||||||
|
return targetInstrIndex, targetUnitIndex, k, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return targetInstrIndex, targetUnitIndex, -1, errors.New("the target port was out of range")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Song) ParamHintString(instrIndex, unitIndex int, param string) string {
|
func (s *Song) ParamHintString(instrIndex, unitIndex int, param string) string {
|
||||||
if instrIndex < 0 || instrIndex >= len(s.Patch.Instruments) {
|
if instrIndex < 0 || instrIndex >= len(s.Patch.Instruments) {
|
||||||
return ""
|
return ""
|
||||||
|
@ -67,6 +67,19 @@ func (t *Tracker) layoutUnitSliders(gtx C) D {
|
|||||||
}
|
}
|
||||||
value = params[name]
|
value = params[name]
|
||||||
min, max = ut[index].MinValue, ut[index].MaxValue
|
min, max = ut[index].MinValue, ut[index].MaxValue
|
||||||
|
if u.Type == "send" && name == "voice" {
|
||||||
|
max = t.song.Patch.TotalVoices()
|
||||||
|
} else if u.Type == "send" && name == "unit" { // set the maximum values depending on the send target
|
||||||
|
instrIndex, _, _, _ := t.song.Patch.FindSendTarget(t.CurrentInstrument, t.CurrentUnit)
|
||||||
|
if instrIndex != -1 {
|
||||||
|
max = len(t.song.Patch.Instruments[instrIndex].Units) - 1
|
||||||
|
}
|
||||||
|
} else if u.Type == "send" && name == "port" { // set the maximum values depending on the send target
|
||||||
|
instrIndex, unitIndex, _, _ := t.song.Patch.FindSendTarget(t.CurrentInstrument, t.CurrentUnit)
|
||||||
|
if instrIndex != -1 && unitIndex != -1 {
|
||||||
|
max = len(sointu.Ports[t.song.Patch.Instruments[instrIndex].Units[unitIndex].Type]) - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
hint := t.song.ParamHintString(t.CurrentInstrument, t.CurrentUnit, name)
|
hint := t.song.ParamHintString(t.CurrentInstrument, t.CurrentUnit, name)
|
||||||
if hint != "" {
|
if hint != "" {
|
||||||
valueText = fmt.Sprintf("%v / %v", value, hint)
|
valueText = fmt.Sprintf("%v / %v", value, hint)
|
||||||
@ -77,6 +90,9 @@ func (t *Tracker) layoutUnitSliders(gtx C) D {
|
|||||||
if !t.ParameterSliders[index].Dragging() {
|
if !t.ParameterSliders[index].Dragging() {
|
||||||
t.ParameterSliders[index].Value = float32(value)
|
t.ParameterSliders[index].Value = float32(value)
|
||||||
}
|
}
|
||||||
|
if max < min {
|
||||||
|
max = min
|
||||||
|
}
|
||||||
sliderStyle := material.Slider(t.Theme, t.ParameterSliders[index], float32(min), float32(max))
|
sliderStyle := material.Slider(t.Theme, t.ParameterSliders[index], float32(min), float32(max))
|
||||||
sliderStyle.Color = t.Theme.Fg
|
sliderStyle.Color = t.Theme.Fg
|
||||||
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
|
return layout.Flex{Axis: layout.Horizontal, Alignment: layout.Middle}.Layout(gtx,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user