feat: keeping instruments and tracks linked & splitting them

Also includes a refactoring of the List: all methods that accepted
or returned a [from, to] range now return a Range, which is
non-inclusive i.e. [start,end).

Also the assignUnitIds was slightly refactored & a new function
called assignUnitIdsForPatch was added, to assign all unit IDs for
an patch at once.

Closes #157, #163.
This commit is contained in:
5684185+vsariola@users.noreply.github.com
2024-10-20 11:30:52 +03:00
parent 025f8832d9
commit 216cde2365
14 changed files with 675 additions and 284 deletions

View File

@ -356,6 +356,15 @@ func (instr *Instrument) Copy() Instrument {
return Instrument{Name: instr.Name, Comment: instr.Comment, NumVoices: instr.NumVoices, Units: units, Mute: instr.Mute}
}
// Implement the counter interface
func (i *Instrument) GetNumVoices() int {
return i.NumVoices
}
func (i *Instrument) SetNumVoices(count int) {
i.NumVoices = count
}
// Copy makes a deep copy of a Patch.
func (p Patch) Copy() Patch {
instruments := make([]Instrument, len(p))
@ -409,11 +418,11 @@ func (p Patch) NumSyncs() int {
// FirstVoiceForInstrument(1) returns 1 and FirstVoiceForInstrument(2) returns
// 4. Essentially computes just the cumulative sum.
func (p Patch) FirstVoiceForInstrument(instrIndex int) int {
ret := 0
for _, t := range p[:instrIndex] {
ret += t.NumVoices
if instrIndex < 0 {
return 0
}
return ret
instrIndex = min(instrIndex, len(p))
return TotalVoices(p[:instrIndex])
}
// InstrumentForVoice returns the instrument number for the given voice index.