diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 5 | ||||
-rw-r--r-- | src/audioinputengine.h | 2 | ||||
-rw-r--r-- | src/drumgizmo.cc | 3 | ||||
-rw-r--r-- | src/engineevent.h (renamed from src/event.h) | 2 | ||||
-rw-r--r-- | src/events.h | 3 | ||||
-rw-r--r-- | src/inputfilter.h | 2 | ||||
-rw-r--r-- | src/inputprocessor.cc | 47 | ||||
-rw-r--r-- | src/inputprocessor.h | 17 | ||||
-rw-r--r-- | src/instrument.cc | 18 | ||||
-rw-r--r-- | src/instrument.h | 11 | ||||
-rw-r--r-- | src/powerlist.cc | 1 | ||||
-rw-r--r-- | src/powerlist.h | 10 | ||||
-rw-r--r-- | src/sample_selection.cc | 4 |
13 files changed, 68 insertions, 57 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index cecb49b..770c436 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -33,7 +33,8 @@ libdg_la_CPPFLAGS = \ $(DEBUG_FLAGS) \ -I$(top_srcdir)/hugin -I$(top_srcdir)/pugixml/src \ $(SSEFLAGS) -I$(top_srcdir)/zita-resampler/libs \ - $(SNDFILE_CFLAGS) $(PTHREAD_CFLAGS) + $(SNDFILE_CFLAGS) $(PTHREAD_CFLAGS) \ + -Wno-deprecated-declarations libdg_la_LIBADD = \ $(SNDFILE_LIBS) $(PTHREAD_LIBS) libzr.la libpugi.la @@ -107,7 +108,7 @@ EXTRA_DIST = \ drumgizmoconf.h \ drumkit.h \ drumkitloader.h \ - event.h \ + engineevent.h \ events.h \ events_ds.h \ grid.h \ diff --git a/src/audioinputengine.h b/src/audioinputengine.h index 71a86c2..55a06ae 100644 --- a/src/audioinputengine.h +++ b/src/audioinputengine.h @@ -29,7 +29,7 @@ #include <string> #include <vector> -#include <event.h> +#include "engineevent.h" #include "instrument.h" diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index abe57be..b67e91a 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -32,7 +32,6 @@ #include <cstring> #include <mutex> -#include <event.h> #include <audiotypes.h> #include <config.h> @@ -312,7 +311,7 @@ repeat: assert(t >= 0); assert(t < evt.buffer_size - evt.buffer_ptr); - if(evt.rampdownInProgress() && evt.rampdown_offset < (evt.t + t) && + if(evt.hasRampdown() && evt.rampdown_offset < (pos + t) && evt.rampdown_count > 0) { if(evt.ramp_length > 0) diff --git a/src/event.h b/src/engineevent.h index 5780cc9..bf2b712 100644 --- a/src/event.h +++ b/src/engineevent.h @@ -1,6 +1,6 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /*************************************************************************** - * event.h + * engineevent.h * * Fri Jun 3 12:10:50 CEST 2011 * Copyright 2011 Bent Bisballe Nyeng diff --git a/src/events.h b/src/events.h index 9e3cae1..538127b 100644 --- a/src/events.h +++ b/src/events.h @@ -84,11 +84,12 @@ public: { } - bool rampdownInProgress() const + bool hasRampdown() const { return rampdown_count != -1; } + cacheid_t cache_id; sample_t* buffer; std::size_t buffer_size; diff --git a/src/inputfilter.h b/src/inputfilter.h index 45dd01e..128dfb0 100644 --- a/src/inputfilter.h +++ b/src/inputfilter.h @@ -26,7 +26,7 @@ */ #pragma once -#include <event.h> +#include "engineevent.h" //! An abstract filter component for the InputProcessor class filter chain. class InputFilter diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc index 00374d4..7679e82 100644 --- a/src/inputprocessor.cc +++ b/src/inputprocessor.cc @@ -141,20 +141,18 @@ std::size_t InputProcessor::getLatency() const return latency; } -//! Applies choke with rampdown time in ms to event starting at offset. -static void applyChoke(Settings& settings, SampleEvent& event, - double length_ms, timepos_t offset) +void InputProcessor::applyChoke(Settings& settings, SampleEvent& event, + double length_ms, timepos_t offset, std::size_t pos) { std::size_t ramp_length = (length_ms / 1000.) * settings.samplerate.load(); event.rampdown_count = ramp_length; - event.rampdown_offset = offset; + event.rampdown_offset = offset + pos; event.ramp_length = ramp_length; } -//! Applies choke group actions to active events based on the input event -static void applyChokeGroup(Settings& settings, DrumKit& kit, - Instrument& instr, event_t& event, - EventsDS& events_ds) +void InputProcessor::applyChokeGroup(Settings& settings, DrumKit& kit, + Instrument& instr, event_t& event, + EventsDS& events_ds, std::size_t pos) { std::size_t instrument_id = event.instrument; if(instr.getGroup() == "") @@ -177,16 +175,15 @@ static void applyChokeGroup(Settings& settings, DrumKit& kit, 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.offset); + applyChoke(settings, event_sample, 68, event.offset, pos); } } } } -//! Applies directed choke actions to active events based on the input event -static void applyDirectedChoke(Settings& settings, DrumKit& kit, - Instrument& instr, event_t& event, - EventsDS& events_ds) +void InputProcessor::applyDirectedChoke(Settings& settings, DrumKit& kit, + Instrument& instr, event_t& event, + EventsDS& events_ds, std::size_t pos) { for(const auto& choke : instr.getChokes()) { @@ -204,7 +201,7 @@ static void applyDirectedChoke(Settings& settings, DrumKit& kit, event_sample.rampdown_count == -1) // Only if not already ramping. { // choke.choketime is in ms - applyChoke(settings, event_sample, choke.choketime, event.offset); + applyChoke(settings, event_sample, choke.choketime, event.offset, pos); } } } @@ -247,15 +244,14 @@ bool InputProcessor::processOnset(event_t& event, std::size_t pos, } // Mute other instruments in the same instrument/choke group - applyChokeGroup(settings, kit, *instr, event, events_ds); + applyChokeGroup(settings, kit, *instr, event, events_ds, pos); // Apply directed chokes to mute other instruments if needed - applyDirectedChoke(settings, kit, *instr, event, events_ds); + applyDirectedChoke(settings, kit, *instr, event, events_ds, pos); - auto const power_max = instr->getMaxPower(); - auto const power_min = instr->getMinPower(); - float const power_span = power_max - power_min; - float const instrument_level = power_min + event.velocity*power_span; + auto power = instr->getPowers(event.position); + const float power_span = power.max - power.min; + const float instrument_level = power.min + event.velocity * power_span; // FIXME: bad variable naming of parameters const auto sample = instr->sample(instrument_level, event.position, event.offset + pos); @@ -269,7 +265,7 @@ bool InputProcessor::processOnset(event_t& event, std::size_t pos, { limitVoices(instrument_id, settings.voice_limit_max.load(), - settings.voice_limit_rampdown.load()); + settings.voice_limit_rampdown.load(), pos); } //Given that audio files could be invalid, maybe we must add the new @@ -359,7 +355,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, 450, event.offset); + applyChoke(settings, event_sample, 450, event.offset, pos); } } } @@ -400,7 +396,7 @@ bool InputProcessor::processStop(event_t& event) void InputProcessor::limitVoices(std::size_t instrument_id, std::size_t max_voices, - float rampdown_time) + float rampdown_time, std::size_t pos) { const auto& group_ids=events_ds.getSampleEventGroupIDsOf(instrument_id); @@ -421,7 +417,7 @@ void InputProcessor::limitVoices(std::size_t instrument_id, } const auto& sample=events_ds.get<SampleEvent>(event_ids[0]); - return !sample.rampdownInProgress(); + return !sample.hasRampdown(); }; EventGroupIDs non_ramping; @@ -435,7 +431,6 @@ void InputProcessor::limitVoices(std::size_t instrument_id, } //Let us get the eldest... - //TODO: where is the playhead? Should we add it to the offset? auto compare_event_offsets = [this](EventGroupID a, EventGroupID b) { @@ -459,6 +454,6 @@ void InputProcessor::limitVoices(std::size_t instrument_id, for(const auto& event_id : event_ids) { auto& sample=events_ds.get<SampleEvent>(event_id); - applyChoke(settings, sample, rampdown_time, sample.offset); + applyChoke(settings, sample, rampdown_time, sample.offset, pos); } } diff --git a/src/inputprocessor.h b/src/inputprocessor.h index 971cc85..a8dc45b 100644 --- a/src/inputprocessor.h +++ b/src/inputprocessor.h @@ -30,13 +30,13 @@ #include <list> #include <memory> -#include <event.h> #include "drumkit.h" #include "events.h" #include "events_ds.h" #include "id.h" #include "inputfilter.h" +#include "engineevent.h" struct Settings; class Random; @@ -64,10 +64,23 @@ private: bool processChoke(event_t& event, std::size_t pos, double resample_ratio); bool processStop(event_t& event); + //! Applies choke with rampdown time in ms to event starting at offset. + void applyChoke(Settings& settings, SampleEvent& event, + double length_ms, timepos_t offset, std::size_t pos); + + //! Applies choke group actions to active events based on the input event + void applyChokeGroup(Settings& settings, DrumKit& kit, + Instrument& instr, event_t& event, + EventsDS& events_ds, std::size_t pos); + //! Applies directed choke actions to active events based on the input event + void applyDirectedChoke(Settings& settings, DrumKit& kit, + Instrument& instr, event_t& event, + EventsDS& events_ds, std::size_t pos); + //! Ramps down samples from events_ds is there are more groups playing than //! max_voices for a given instrument. void limitVoices(std::size_t instrument_id, std::size_t max_voices, - float rampdown_time); + float rampdown_time, std::size_t pos); std::vector<std::unique_ptr<InputFilter>> filters; diff --git a/src/instrument.cc b/src/instrument.cc index ac6aa28..30f3423 100644 --- a/src/instrument.cc +++ b/src/instrument.cc @@ -130,27 +130,15 @@ std::size_t Instrument::getNumberOfFiles() const return audiofiles.size(); } -float Instrument::getMaxPower() const +Instrument::PowerRange Instrument::getPowers(float position) const { if(version >= VersionStr("2.0")) { - return powerlist.getMaxPower(); + return { powerlist.getMaxPower(), powerlist.getMaxPower() }; } else { - return 1.0f; - } -} - -float Instrument::getMinPower() const -{ - if(version >= VersionStr("2.0")) - { - return powerlist.getMinPower(); - } - else - { - return 0.0f; + return { 0.0f, 1.0f }; } } diff --git a/src/instrument.h b/src/instrument.h index 89918de..49a9a74 100644 --- a/src/instrument.h +++ b/src/instrument.h @@ -68,8 +68,15 @@ public: //! Get the number of audio files (as in single channel) in this instrument. std::size_t getNumberOfFiles() const; - float getMaxPower() const; - float getMinPower() const; + struct PowerRange + { + float min; + float max; + }; + PowerRange getPowers(float position) const; + + //float getMaxPower() const; + //float getMinPower() const; const std::vector<Choke>& getChokes(); diff --git a/src/powerlist.cc b/src/powerlist.cc index 23d9795..8dd0b24 100644 --- a/src/powerlist.cc +++ b/src/powerlist.cc @@ -84,6 +84,7 @@ const Channel* PowerList::getMasterChannel() af->load(nullptr, LOAD_SIZE); float silence{0.f}; + (void)silence; std::size_t silence_length{4u}; for (auto s = af->size; s > 0 && s > af->size - silence_length; --s) { diff --git a/src/powerlist.h b/src/powerlist.h index ffbd6ba..b1fd1fd 100644 --- a/src/powerlist.h +++ b/src/powerlist.h @@ -44,7 +44,13 @@ struct PowerListItem return this->power < power; } }; -using PowerListItems = std::vector<PowerListItem>; +class PowerListItems + : public std::vector<PowerListItem> +{ +public: + float getMaxPower() const; + float getMinPower() const; +}; class PowerList { @@ -54,7 +60,7 @@ public: void add(Sample* s); void finalise(); ///< Call this when no more samples will be added. - const PowerListItems& getPowerListItems() const; + const PowerListItems& getPowerListItems(float position) const; float getMaxPower() const; float getMinPower() const; diff --git a/src/sample_selection.cc b/src/sample_selection.cc index eb13e55..c6d8eea 100644 --- a/src/sample_selection.cc +++ b/src/sample_selection.cc @@ -58,7 +58,7 @@ void SampleSelection::finalise() // FIXME: bad variable naming const Sample* SampleSelection::get(level_t level, float position, std::size_t pos) { - const auto& samples = powerlist.getPowerListItems(); + const auto& samples = powerlist.getPowerListItems(position); if(!samples.size()) { return nullptr; // No samples to choose from. @@ -80,7 +80,7 @@ const Sample* SampleSelection::get(level_t level, float position, std::size_t po const float f_diverse = (1./2.)*settings.sample_selection_f_diverse.load(); const float f_random = (1./3.)*settings.sample_selection_f_random.load(); - float power_range = powerlist.getMaxPower() - powerlist.getMinPower(); + float power_range = samples.getMaxPower() - samples.getMinPower(); // If all power values are the same then power_range is invalid but we want // to avoid division by zero. if (power_range == 0.) { power_range = 1.0; } |