feat: input midi velocity into a separate track (includes many structural changes)

This commit is contained in:
qm210
2024-11-22 02:38:57 +01:00
parent ad690c7697
commit 49a259cf83
14 changed files with 348 additions and 142 deletions

View File

@ -2,9 +2,10 @@ package tracker
import (
"fmt"
"github.com/vsariola/sointu"
"iter"
"slices"
"github.com/vsariola/sointu"
)
/*
@ -115,17 +116,17 @@ func (m *Model) PatternUnique(t, p int) bool {
// public getters with further model information
func (m *Model) TracksWithSameInstrumentAsCurrent() []int {
currentTrack := m.d.Cursor.Track
if currentTrack > len(m.derived.forTrack) {
d, ok := m.currentDerivedForTrack()
if !ok {
return nil
}
return m.derived.forTrack[currentTrack].tracksWithSameInstrument
return d.tracksWithSameInstrument
}
func (m *Model) CountNextTracksForCurrentInstrument() int {
currentTrack := m.d.Cursor.Track
count := 0
for t := range m.TracksWithSameInstrumentAsCurrent() {
for _, t := range m.TracksWithSameInstrumentAsCurrent() {
if t > currentTrack {
count++
}
@ -133,6 +134,32 @@ func (m *Model) CountNextTracksForCurrentInstrument() int {
return count
}
func (m *Model) CanUseTrackForMidiVelInput(trackIndex int) bool {
// makes no sense to record velocity into tracks where notes get recorded
tracksForMidiNoteInput := m.TracksWithSameInstrumentAsCurrent()
return !slices.Contains(tracksForMidiNoteInput, trackIndex)
}
func (m *Model) CurrentPlayerConstraints() PlayerProcessConstraints {
d, ok := m.currentDerivedForTrack()
if !ok {
return PlayerProcessConstraints{IsConstrained: false}
}
return PlayerProcessConstraints{
IsConstrained: m.trackMidiIn,
MaxPolyphony: len(d.tracksWithSameInstrument),
InstrumentIndex: d.instrumentRange[0],
}
}
func (m *Model) currentDerivedForTrack() (derivedForTrack, bool) {
currentTrack := m.d.Cursor.Track
if currentTrack > len(m.derived.forTrack) {
return derivedForTrack{}, false
}
return m.derived.forTrack[currentTrack], true
}
// init / update methods
func (m *Model) initDerivedData() {
@ -165,6 +192,7 @@ func (m *Model) updateDerivedScoreData() {
},
)
}
m.updatePlayerConstraints()
}
func (m *Model) updateDerivedPatchData() {
@ -194,6 +222,13 @@ func (m *Model) updateDerivedParameterData(unit sointu.Unit) {
}
}
// updatePlayerConstraints() is different from the other derived methods,
// it needs to be called after any model change that could affect the player.
// for this, it reads derivedForTrack, which is why it lives here for now.
func (m *Model) updatePlayerConstraints() {
m.MIDI.SetPlayerConstraints(m.CurrentPlayerConstraints())
}
// internals...
func (m *Model) collectSendSources(unit sointu.Unit, paramName string) iter.Seq[sendSourceData] {