Browse Source

Rework AudioMidiSyncHelper class in a way that actually works

master
falkTX 5 years ago
parent
commit
8e5dfcd69e
3 changed files with 59 additions and 22 deletions
  1. +1
    -1
      dpf
  2. +56
    -19
      plugins/Kars/DistrhoPluginKars.cpp
  3. +2
    -2
      plugins/Kars/DistrhoPluginKars.hpp

+ 1
- 1
dpf

@@ -1 +1 @@
Subproject commit ea7545a13ab9793b5608b13a82f1ad9cf9ec5e98
Subproject commit 7a056bbcf84f9437d7a00a5659be5bb6008bfe1d

+ 56
- 19
plugins/Kars/DistrhoPluginKars.cpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Kars Plugin, based on karplong by Chris Cannam.
* Copyright (C) 2015 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2015-2019 Filipe Coelho <falktx@falktx.com>
*
* 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
@@ -158,7 +158,8 @@ public:
midiEvents(m),
midiEventCount(0),
remainingFrames(f),
remainingMidiEventCount(mc) {}
remainingMidiEventCount(mc),
totalFramesUsed(0) {}
/**
Process a batch of events untill no more are available.
@@ -166,41 +167,76 @@ public:
*/
bool nextEvent()
{
if (remainingMidiEventCount == 0)
// nothing else to do
if (remainingFrames == 0)
return false;
// initial setup, need to find first MIDI event
if (totalFramesUsed == 0)
{
if (remainingFrames == 0)
return false;
// no MIDI events at all in this process cycle
if (remainingMidiEventCount == 0)
{
frames = remainingFrames;
remainingFrames = 0;
totalFramesUsed += frames;
return true;
}
// render audio until first midi event, if needed
if (const uint32_t firstEventFrame = midiEvents[0].frame)
{
frames = midiEvents[0].frame;
remainingFrames -= frames;
totalFramesUsed += frames;
return true;
}
}
else
{
for (uint32_t i=0; i<DISTRHO_PLUGIN_NUM_OUTPUTS; ++i)
outputs[i] += frames;
}
if (midiEventCount != 0)
midiEvents += midiEventCount;
// no more MIDI events available
if (remainingMidiEventCount == 0)
{
frames = remainingFrames;
midiEvents = nullptr;
midiEventCount = 0;
remainingFrames = 0;
totalFramesUsed += frames;
return true;
}
const uint32_t eventFrame = midiEvents[0].frame;
DISTRHO_SAFE_ASSERT_RETURN(eventFrame < remainingFrames, false);
// if there were midi events before, increment pointer
if (midiEventCount != 0)
midiEvents += midiEventCount;
midiEventCount = 1;
const uint32_t firstEventFrame = midiEvents[0].frame;
DISTRHO_SAFE_ASSERT_RETURN((firstEventFrame - frames) < remainingFrames, false);
for (uint32_t i=1; i<remainingMidiEventCount; ++i)
midiEventCount = 1;
while (midiEventCount < remainingMidiEventCount)
{
if (midiEvents[i].frame != eventFrame)
{
midiEventCount = i;
if (midiEvents[midiEventCount].frame == firstEventFrame)
++midiEventCount;
else
break;
}
}
frames = remainingFrames - eventFrame;
if (totalFramesUsed != 0)
{
// need to modify timestamp of midi events
MidiEvent* const rwEvents = const_cast<MidiEvent*>(midiEvents);
for (uint32_t i=0; i < midiEventCount; ++i)
rwEvents[i].frame -= totalFramesUsed;
}
frames = remainingFrames - firstEventFrame;
remainingFrames -= frames;
remainingMidiEventCount -= midiEventCount;
totalFramesUsed += frames;
return true;
}
@@ -208,6 +244,7 @@ private:
/** @internal */
uint32_t remainingFrames;
uint32_t remainingMidiEventCount;
uint32_t totalFramesUsed;
};
void DistrhoPluginKars::run(const float**, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount)
@@ -254,9 +291,9 @@ void DistrhoPluginKars::run(const float**, float** outputs, uint32_t frames, con
if (fNotes[i].on != kNoteNull)
addSamples(out, i, amsh.frames);
}
}
fBlockStart += frames;
fBlockStart += amsh.frames;
}
}
void DistrhoPluginKars::addSamples(float* out, int voice, uint32_t frames)


+ 2
- 2
plugins/Kars/DistrhoPluginKars.hpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Kars Plugin, based on karplong by Chris Cannam.
* Copyright (C) 2015 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2015-2019 Filipe Coelho <falktx@falktx.com>
*
* 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
@@ -70,7 +70,7 @@ protected:
uint32_t getVersion() const noexcept override
{
return d_version(1, 0, 0);
return d_version(1, 1, 0);
}
int64_t getUniqueId() const noexcept override


Loading…
Cancel
Save