From 4f2c28de47d2acc9a6292d809d4fd6f1613976cf Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 13 Aug 2019 12:37:45 +0100 Subject: [PATCH] Add new file --- dpf/distrho/DistrhoPluginUtils.hpp | 155 +++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 dpf/distrho/DistrhoPluginUtils.hpp diff --git a/dpf/distrho/DistrhoPluginUtils.hpp b/dpf/distrho/DistrhoPluginUtils.hpp new file mode 100644 index 0000000..7c34303 --- /dev/null +++ b/dpf/distrho/DistrhoPluginUtils.hpp @@ -0,0 +1,155 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2019 Filipe Coelho + * + * Permission to use, copy, modify, and/or distribute this software for any purpose with + * or without fee is hereby granted, provided that the above copyright notice and this + * permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef DISTRHO_PLUGIN_UTILS_HPP_INCLUDED +#define DISTRHO_PLUGIN_UTILS_HPP_INCLUDED + +#include "DistrhoPlugin.hpp" + +START_NAMESPACE_DISTRHO + +// ----------------------------------------------------------------------------------------------------------- + +/** + Handy class to help keep audio buffer in sync with incoming MIDI events. + To use it, create a local variable (on the stack) and call nextEvent() until it returns false. + @code + for (AudioMidiSyncHelper amsh(outputs, frames, midiEvents, midiEventCount); amsh.nextEvent();) + { + float* const outL = amsh.outputs[0]; + float* const outR = amsh.outputs[1]; + + for (uint32_t i=0; i= totalFramesUsed, + firstEventFrame, totalFramesUsed, false); + + midiEventCount = 1; + while (midiEventCount < remainingMidiEventCount) + { + if (midiEvents[midiEventCount].frame == firstEventFrame) + ++midiEventCount; + else + break; + } + + frames = firstEventFrame - totalFramesUsed; + remainingFrames -= frames; + remainingMidiEventCount -= midiEventCount; + totalFramesUsed += frames; + return true; + } + +private: + /** @internal */ + uint32_t remainingFrames; + uint32_t remainingMidiEventCount; + uint32_t totalFramesUsed; +}; + +// ----------------------------------------------------------------------------------------------------------- + +END_NAMESPACE_DISTRHO + +#endif // DISTRHO_PLUGIN_UTILS_HPP_INCLUDED