diff options
-rw-r--r-- | src/events_ds.cc | 19 | ||||
-rw-r--r-- | src/events_ds.h | 3 | ||||
-rw-r--r-- | src/memory_heap.h | 8 |
3 files changed, 30 insertions, 0 deletions
diff --git a/src/events_ds.cc b/src/events_ds.cc index ee21f93..0195a89 100644 --- a/src/events_ds.cc +++ b/src/events_ds.cc @@ -99,6 +99,25 @@ void EventsDS::startAddingNewGroup(InstrumentID instrument_id) } } +void EventsDS::clear() +{ + // *this = EventsDS(); + + id_to_info.clear(); + id_to_group_data.clear(); + for (auto& channel_data: channel_data_array) + { + channel_data.sample_events.clear(); + } + for (auto& event_group_ids: instruments_sample_event_group_ids) + { + event_group_ids.clear(); + } + + current_group_id.invalidate(); + current_groups_instrument_id.invalidate(); +} + void EventsDS::removeGroup(EventGroupID group_id, InstrumentID instrument_id) { // if we remove the current group, then invalidate it diff --git a/src/events_ds.h b/src/events_ds.h index 5855711..fdab881 100644 --- a/src/events_ds.h +++ b/src/events_ds.h @@ -96,6 +96,9 @@ public: //! when startAddingNewGroup is again called. void startAddingNewGroup(InstrumentID instrument_id = InstrumentID()); + //! Clears the whole data structure to make it ready for a new drum kit. + void clear(); + private: struct ChannelData { diff --git a/src/memory_heap.h b/src/memory_heap.h index 3f0105a..658598c 100644 --- a/src/memory_heap.h +++ b/src/memory_heap.h @@ -61,6 +61,7 @@ public: T& get(Index index); const T& get(Index index) const; void remove(Index index); + void clear(); private: std::vector<T> memory; @@ -119,3 +120,10 @@ void MemoryHeap<T>::remove(Index index) { free_indices.push_back(index); } + +template <typename T> +void MemoryHeap<T>::clear() +{ + memory.clear(); + free_indices.clear(); +} |