diff options
author | Volker Fischer <corrados@users.noreply.github.com> | 2021-07-28 19:02:13 +0200 |
---|---|---|
committer | Volker Fischer <corrados@users.noreply.github.com> | 2021-07-28 19:02:13 +0200 |
commit | 61630a321ac59da01240a4b359c591e567aa84ed (patch) | |
tree | 0e4eeed42dabe4c46f06153f9e3914177a6b7967 | |
parent | 78c4c6abba8b02e3181c09ce9671cf454553c730 (diff) | |
parent | 62f7f2b2b004162b06af844dbc1a3cda696cfd9e (diff) |
Merge remote-tracking branch 'origin/develop' into edrumulus
-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 | ||||
-rw-r--r-- | test/eventsdstest.cc | 57 |
9 files changed, 97 insertions, 23 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 diff --git a/test/eventsdstest.cc b/test/eventsdstest.cc index 3c0af68..822cf14 100644 --- a/test/eventsdstest.cc +++ b/test/eventsdstest.cc @@ -34,7 +34,8 @@ class EventsDSTest public: EventsDSTest() { - uUNIT_TEST(EventsDSTest::test_all); + uTEST(EventsDSTest::test_all); + uTEST(EventsDSTest::test_clear); } public: @@ -48,27 +49,27 @@ public: events_ds.emplace<SampleEvent>(13, 13, 1.0, nullptr, "b", 42); events_ds.emplace<SampleEvent>(13, 13, 1.0, nullptr, "c", 42); - uUNIT_ASSERT(events_ds.getSampleEventGroupIDsOf(13).empty()); - uUNIT_ASSERT(events_ds.getSampleEventGroupIDsOf(42).size() == 1); + uASSERT(events_ds.getSampleEventGroupIDsOf(13).empty()); + uASSERT(events_ds.getSampleEventGroupIDsOf(42).size() == 1); auto group_id = events_ds.getSampleEventGroupIDsOf(42).back(); const auto& event_ids = events_ds.getEventIDsOf(group_id); - uUNIT_ASSERT(event_ids.size() == 3); + uASSERT(event_ids.size() == 3); // group 2 events_ds.startAddingNewGroup(42); events_ds.emplace<SampleEvent>(13, 13, 1.0, nullptr, "d", 42); - uUNIT_ASSERT(events_ds.getSampleEventGroupIDsOf(42).size() == 2); + uASSERT(events_ds.getSampleEventGroupIDsOf(42).size() == 2); // group 3 events_ds.startAddingNewGroup(23); events_ds.emplace<SampleEvent>(7, 7, 1.0, nullptr, "foo", 23); events_ds.emplace<SampleEvent>(7, 7, 1.0, nullptr, "bar", 23); - uUNIT_ASSERT(events_ds.getSampleEventGroupIDsOf(42).size() == 2); - uUNIT_ASSERT(events_ds.numberOfEvents(13) == 4); - uUNIT_ASSERT(events_ds.numberOfEvents(7) == 2); + uASSERT(events_ds.getSampleEventGroupIDsOf(42).size() == 2); + uASSERT(events_ds.numberOfEvents(13) == 4); + uASSERT(events_ds.numberOfEvents(7) == 2); // iterate over std::string group_concat = ""; @@ -76,27 +77,55 @@ public: { group_concat.append(sample_event.group); } - uUNIT_ASSERT(group_concat == "abcd"); + uASSERT(group_concat == "abcd"); // get and getType for (const auto& sample_event: events_ds.iterateOver<SampleEvent>(13)) { - uUNIT_ASSERT(events_ds.get<SampleEvent>(sample_event.id).channel == 13); - uUNIT_ASSERT(events_ds.getType(sample_event.id) == Event::Type::SampleEvent); + uASSERT(events_ds.get<SampleEvent>(sample_event.id).channel == 13); + uASSERT(events_ds.getType(sample_event.id) == Event::Type::SampleEvent); } // remove auto event_id = events_ds.getEventIDsOf(events_ds.getSampleEventGroupIDsOf(42).back()).back(); events_ds.remove(event_id); - uUNIT_ASSERT(events_ds.getSampleEventGroupIDsOf(42).size() == 1); + uASSERT(events_ds.getSampleEventGroupIDsOf(42).size() == 1); event_id = events_ds.getEventIDsOf(events_ds.getSampleEventGroupIDsOf(23).back()).back(); events_ds.remove(event_id); - uUNIT_ASSERT(!events_ds.getSampleEventGroupIDsOf(23).empty()); + uASSERT(!events_ds.getSampleEventGroupIDsOf(23).empty()); event_id = events_ds.getEventIDsOf(events_ds.getSampleEventGroupIDsOf(23).back()).back(); events_ds.remove(event_id); - uUNIT_ASSERT(events_ds.getSampleEventGroupIDsOf(23).empty()); + uASSERT(events_ds.getSampleEventGroupIDsOf(23).empty()); } + + void test_clear() + { + EventsDS events_ds; + + uASSERT_EQUAL(0u, events_ds.getSampleEventGroupIDsOf(42).size()); + uASSERT_EQUAL(0u, events_ds.getSampleEventGroupIDsOf(43).size()); + + // group 1 + events_ds.startAddingNewGroup(42); + events_ds.emplace<SampleEvent>(13, 13, 1.0, nullptr, "a", 42); + events_ds.emplace<SampleEvent>(13, 13, 1.0, nullptr, "b", 42); + events_ds.emplace<SampleEvent>(13, 13, 1.0, nullptr, "c", 42); + + // group 2 + events_ds.startAddingNewGroup(43); + events_ds.emplace<SampleEvent>(13, 13, 1.0, nullptr, "a", 43); + events_ds.emplace<SampleEvent>(13, 13, 1.0, nullptr, "b", 43); + events_ds.emplace<SampleEvent>(13, 13, 1.0, nullptr, "c", 43); + + uASSERT_EQUAL(1u, events_ds.getSampleEventGroupIDsOf(42).size() == 1); + uASSERT_EQUAL(1u, events_ds.getSampleEventGroupIDsOf(43).size() == 1); + + events_ds.clear(); + + uASSERT_EQUAL(0u, events_ds.getSampleEventGroupIDsOf(42).size()); + uASSERT_EQUAL(0u, events_ds.getSampleEventGroupIDsOf(43).size()); +} }; // Registers the fixture into the 'registry' |