feat(tracker): add ability to copy, cut and paste units

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2023-07-18 17:17:37 +03:00
parent 338529012a
commit 5a2e87982e
4 changed files with 56 additions and 1 deletions

View File

@ -641,6 +641,24 @@ func (m *Model) SetUnitType(t string) {
m.notifyPatchChange()
}
func (m *Model) PasteUnit(unit sointu.Unit) {
m.saveUndo("PasteUnit", 0)
newUnits := make([]sointu.Unit, len(m.Instrument().Units)+1)
m.unitIndex++
copy(newUnits, m.Instrument().Units[:m.unitIndex])
copy(newUnits[m.unitIndex+1:], m.Instrument().Units[m.unitIndex:])
if _, ok := m.usedIDs[unit.ID]; ok {
m.maxID++
unit.ID = m.maxID
}
m.usedIDs[unit.ID] = true
newUnits[m.unitIndex] = unit
m.song.Patch[m.instrIndex].Units = newUnits
m.paramIndex = 0
m.clampPositions()
m.notifyPatchChange()
}
func (m *Model) SetUnitIndex(value int) {
m.unitIndex = value
m.paramIndex = 0