In music production software, efficient management of various elements such as MIDI notes, clips, and tracks is crucial. The Tracktion Engine offers a sophisticated tool called the SelectionManager
to simplify these tasks within the song editor view or the piano roll editor. Let’s dive into how you can leverage the SelectionManager
to enhance your application.
1. Manipulating Selections
Adding to Your Selection
The SelectionManager
allows for both replacing and adding to your current selections:
- Select Only One: Replace the existing selection with a new note.
evs.m_selectionManager.selectOnly(note);
- Add to Existing Selection: Keep the existing selections and add new ones.
evs.m_selectionManager.addToSelection(note);
- Batch Additions: Conveniently add multiple notes.
for (auto note : notesToAdd) {
evs.m_selectionManager.addToSelection(note);
}
Removing from Your Selection
Removing items is just as straightforward:
- Deselect a Single Note:
evs.m_selectionManager.deselect(note);
- Batch Removals:
for (auto note : notesToRemove) {
evs.m_selectionManager.deselect(note);
}
- Clear Entire Selection:
evs.m_selectionManager.deselectAll();
2. Querying Selection Status
Understanding what is selected is key to manipulating data effectively:
- Check Selection Status of a Note:
bool isSelected = evs.m_selectionManager.isSelected(note);
- Count of Selected Items:
int numSelected = evs.m_selectionManager.getNumObjectsSelected();
- Count of Selected MIDI Notes Specifically:
int numNotesSelected = evs.m_selectionManager.getItemsOfType<te::MidiNote>().size();
3. Iterating Through Selections
Iterate through selected notes to modify properties such as velocity or start time:
auto selectedNotes = evs.m_selectionManager.getItemsOfType<te::MidiNote>();
for (auto note : selectedNotes) {
note->setVelocity(newVelocity, &evs.m_edit.getUndoManager());
note->setStartBeat(newStartBeat, &evs.m_edit.getUndoManager());
}
4. Handling Multiple Item Types
Tracktion Engine’s versatility extends to selecting and managing different types of edit items:
auto selectedObjects = evs.m_selectionManager.getSelectedObjects();
for (auto object : selectedObjects) {
if (auto note = dynamic_cast<te::MidiNote*>(object)) {
// Process the MIDI note
} else if (auto clip = dynamic_cast<te::Clip*>(object)) {
// Process the clip
} // Continue for other types
}
5. Custom Selectable Objects
Extend the functionality to custom objects by inheriting from te::Selectable
:
- Implement methods like
getSelectableDescription()
. - Use
select()
,deselect()
, andisSelected()
to manage these objects within your UI.
Conclusion
The SelectionManager
in the Tracktion Engine is a powerful component that simplifies the selection and manipulation of various objects within a digital audio workstation environment. By integrating this system, developers can provide users with a robust tool for editing audio efficiently and intuitively, ensuring that every change is manageable through undo/redo functionality.
Stay tuned for more tutorials on harnessing the power of the Tracktion Engine to build professional audio software!
Leave a Reply