diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/drumgizmo.cc | 25 | ||||
-rw-r--r-- | src/drumgizmo.h | 2 | ||||
-rw-r--r-- | src/events_ds.cc | 19 | ||||
-rw-r--r-- | src/events_ds.h | 3 | ||||
-rw-r--r-- | src/inputprocessor.cc | 2 | ||||
-rw-r--r-- | src/memory_heap.h | 8 | ||||
-rw-r--r-- | src/sample_selection.cc | 2 | ||||
-rw-r--r-- | src/translation.h | 2 |
8 files changed, 54 insertions, 9 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index ca91c12..d3665c2 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -119,6 +119,12 @@ void DrumGizmo::setRandomSeed(unsigned int seed) bool DrumGizmo::run(size_t pos, sample_t *samples, size_t nsamples) { + if(settings_getter.drumkit_file.hasChanged()) + { + // New kit loaded/loading - old events no longer makes sense. + events_ds.clear(); + } + if(settings_getter.enable_resampling.hasChanged()) { enable_resampling = settings_getter.enable_resampling.getValue(); @@ -346,8 +352,9 @@ void DrumGizmo::getSamples(int ch, int pos, sample_t* s, size_t sz) if(!af.isLoaded() || !af.isValid() || (s == nullptr)) { - removeevent = true; - break; + // This event cannot be played - schedule for deletion and continue. + to_remove.push_back(sample_event.id); + continue; } if(sample_event.offset > (pos + sz)) @@ -431,7 +438,7 @@ float DrumGizmo::samplerate() void DrumGizmo::setSamplerate(float samplerate, float resampling_quality) { - DEBUG(dgeditor, "%s samplerate: %f\n", __PRETTY_FUNCTION__, samplerate); + DEBUG(engine, "%s samplerate: %f\n", __PRETTY_FUNCTION__, samplerate); settings.samplerate.store(samplerate); // Notify input engine of the samplerate change. @@ -463,10 +470,14 @@ void DrumGizmo::setSamplerate(float samplerate, float resampling_quality) zita[c].set_inp_data(nullptr); zita[c].set_inp_count(null_size); - constexpr auto sz = 4096 * 16; - sample_t s[sz]; - zita[c].set_out_data(s); - zita[c].set_out_count(sz); + std::size_t scratch_buffer_size = (null_size / ratio); + + if(scratch_buffer.size() < scratch_buffer_size) + { + scratch_buffer.resize(scratch_buffer_size); + } + zita[c].set_out_data(scratch_buffer.data()); + zita[c].set_out_count(scratch_buffer_size); zita[c].process(); } diff --git a/src/drumgizmo.h b/src/drumgizmo.h index f08c9f7..89c2960 100644 --- a/src/drumgizmo.h +++ b/src/drumgizmo.h @@ -107,5 +107,5 @@ protected: std::array<ZRWrapper, NUM_CHANNELS> zita; std::array<std::unique_ptr<sample_t>, NUM_CHANNELS> resampler_input_buffer; double ratio = 1.0; - + std::vector<sample_t> scratch_buffer; }; 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/inputprocessor.cc b/src/inputprocessor.cc index 2283ab7..d8a7ff9 100644 --- a/src/inputprocessor.cc +++ b/src/inputprocessor.cc @@ -359,7 +359,7 @@ bool InputProcessor::processChoke(event_t& event, event_sample.rampdown_count == -1) // Only if not already ramping. { // Fixed group rampdown time of 68ms, independent of samplerate - applyChoke(settings, event_sample, 68, event_sample.offset); + applyChoke(settings, event_sample, 68, event.offset); } } } 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(); +} diff --git a/src/sample_selection.cc b/src/sample_selection.cc index 06e97c9..eb13e55 100644 --- a/src/sample_selection.cc +++ b/src/sample_selection.cc @@ -108,6 +108,8 @@ const Sample* SampleSelection::get(level_t level, float position, std::size_t po { DEBUG(rand, "%d %d", (int)up_index, (int)down_index); + assert(down_index <= up_index); + std::size_t current_index; if (up_value_lb < down_value_lb) { diff --git a/src/translation.h b/src/translation.h index 7f506a6..d8a6072 100644 --- a/src/translation.h +++ b/src/translation.h @@ -26,6 +26,8 @@ */ #pragma once +#include <cstdint> + #include <config.h> #ifdef WITH_NLS |