further drafting

This commit is contained in:
5684185+vsariola@users.noreply.github.com 2024-09-21 21:06:22 +03:00
parent bd20440661
commit 964b2adbab
5 changed files with 33 additions and 27 deletions

View File

@ -28,8 +28,8 @@ func (NullContext) BPM() (bpm float64, ok bool) {
return 0, false
}
func (NullContext) Params() (ret tracker.ExtParamArray, ok bool) {
return tracker.ExtParamArray{}, false
func (NullContext) Params() (ret tracker.ExtValueArray, ok bool) {
return tracker.ExtValueArray{}, false
}
func (NullContext) SetParams(params tracker.ExtParamArray) bool {

View File

@ -53,19 +53,27 @@ func (c *VSTIProcessContext) BPM() (bpm float64, ok bool) {
return timeInfo.Tempo, true
}
func (c *VSTIProcessContext) Params() (ret tracker.ExtParamArray, ok bool) {
func (c *VSTIProcessContext) Params() (ret tracker.ExtValueArray, ok bool) {
for i, p := range c.parameters {
ret[i] = p.Value
}
return ret, true
}
func (c *VSTIProcessContext) SetParams(val tracker.ExtParamArray) bool {
func (c *VSTIProcessContext) SetParams(a tracker.ExtParamArray) bool {
changed := false
for i, p := range c.parameters {
if p.Value != val[i] {
p.Value = val[i]
p.Name = fmt.Sprintf("P%f", val[i])
i := i
name := a[i].Param.Name
if name == "" {
name = "---"
}
if p.Value != a[i].Val || p.Name != name {
p.Value = a[i].Val
p.Name = name
p.GetValueFunc = func(value float32) float32 {
return float32(a[i].Param.MinValue) + value*float32(a[i].Param.MaxValue-a[i].Param.MinValue)
}
changed = true
}
}
@ -101,15 +109,8 @@ func init() {
for i := 0; i < tracker.ExtParamCount; i++ {
parameters = append(parameters,
&vst2.Parameter{
Name: fmt.Sprintf("P%d", i),
Name: "---",
NotAutomated: true,
Unit: "foobar",
GetValueFunc: func(value float32) float32 {
return float32(int(value*128 + 1))
},
GetValueLabelFunc: func(value float32) string {
return fmt.Sprintf("%d", int(value))
},
})
}
context := VSTIProcessContext{host: h, parameters: parameters}

View File

@ -118,7 +118,11 @@ type (
ParamName string
}
ExtParamArray [ExtParamCount]float32
ExtValueArray [ExtParamCount]float32
ExtParamArray [ExtParamCount]struct {
Val float32
Param sointu.UnitParameter
}
IsPlayingMsg struct{ bool }
StartPlayMsg struct{ sointu.SongPos }
@ -374,8 +378,8 @@ func (m *Model) ProcessPlayerMessage(msg PlayerMsg) {
m.Alerts().AddAlert(e)
case IsPlayingMsg:
m.playing = e.bool
case ExtParamArray:
m.SetExtParams(e)
case ExtValueArray:
m.SetExtValues(e)
default:
}
}
@ -410,7 +414,7 @@ func (m *Model) Instrument(index int) sointu.Instrument {
return m.d.Song.Patch[index].Copy()
}
func (m *Model) ExtParams() (ret ExtParamArray) {
func (m *Model) ExtParams() (params ExtParamArray) {
for i, l := range m.d.ExtParamLinks {
instrIndex, unitIndex, err := m.d.Song.Patch.FindUnit(l.UnitID)
if err != nil {
@ -420,7 +424,8 @@ func (m *Model) ExtParams() (ret ExtParamArray) {
if up, ok := sointu.UnitTypes[unit.Type]; ok {
for _, p := range up {
if p.Name == l.ParamName && p.CanSet && p.MaxValue > p.MinValue {
ret[i] = float32(unit.Parameters[l.ParamName]-p.MinValue) / float32(p.MaxValue-p.MinValue)
params[i].Val = float32(unit.Parameters[l.ParamName]-p.MinValue) / float32(p.MaxValue-p.MinValue)
params[i].Param = p
}
}
}
@ -428,8 +433,8 @@ func (m *Model) ExtParams() (ret ExtParamArray) {
return
}
func (m *Model) SetExtParams(params ExtParamArray) {
defer m.change("SetParamValue", PatchChange, MinorChange)()
func (m *Model) SetExtValues(vals ExtValueArray) {
defer m.change("SetExtValues", PatchChange, MinorChange)()
changed := false
for i, l := range m.d.ExtParamLinks {
instrIndex, unitIndex, err := m.d.Song.Patch.FindUnit(l.UnitID)
@ -440,7 +445,7 @@ func (m *Model) SetExtParams(params ExtParamArray) {
if up, ok := sointu.UnitTypes[unit.Type]; ok {
for _, p := range up {
if p.Name == l.ParamName && p.CanSet && p.MaxValue > p.MinValue {
newVal := int(math.Round(float64(params[i])*float64(p.MaxValue-p.MinValue))) + p.MinValue
newVal := int(math.Round(float64(vals[i])*float64(p.MaxValue-p.MinValue))) + p.MinValue
if unit.Parameters[l.ParamName] != newVal {
unit.Parameters[l.ParamName] = newVal
changed = true

View File

@ -21,8 +21,8 @@ func (NullContext) BPM() (bpm float64, ok bool) {
return 0, false
}
func (NullContext) Params() (params tracker.ExtParamArray, ok bool) {
return tracker.ExtParamArray{}, false
func (NullContext) Params() (params tracker.ExtValueArray, ok bool) {
return tracker.ExtValueArray{}, false
}
func (NullContext) SetParams(params tracker.ExtParamArray) bool {

View File

@ -25,7 +25,7 @@ type (
voiceLevels [vm.MAX_VOICES]float32 // a level that can be used to visualize the volume of each voice
voices [vm.MAX_VOICES]voice
loop Loop
extParamValues ExtParamArray
extParamValues ExtValueArray
recState recState // is the recording off; are we waiting for a note; or are we recording
recording Recording // the recorded MIDI events and BPM
@ -40,7 +40,7 @@ type (
PlayerProcessContext interface {
NextEvent() (event MIDINoteEvent, ok bool)
BPM() (bpm float64, ok bool)
Params() (params ExtParamArray, ok bool)
Params() (params ExtValueArray, ok bool)
SetParams(params ExtParamArray) bool
}