Make internal plugin context use const; Fix host time
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
ec2f455826
commit
1a2c64309b
8 changed files with 63 additions and 39 deletions
|
@ -76,7 +76,7 @@ struct CarlaModule : Module {
|
||||||
NUM_LIGHTS
|
NUM_LIGHTS
|
||||||
};
|
};
|
||||||
|
|
||||||
CardinalPluginContext* const pcontext;
|
const CardinalPluginContext* const pcontext;
|
||||||
|
|
||||||
const NativePluginDescriptor* fCarlaPluginDescriptor = nullptr;
|
const NativePluginDescriptor* fCarlaPluginDescriptor = nullptr;
|
||||||
NativePluginHandle fCarlaPluginHandle = nullptr;
|
NativePluginHandle fCarlaPluginHandle = nullptr;
|
||||||
|
@ -398,7 +398,7 @@ static uint32_t host_get_buffer_size(const NativeHostHandle handle)
|
||||||
|
|
||||||
static double host_get_sample_rate(const NativeHostHandle handle)
|
static double host_get_sample_rate(const NativeHostHandle handle)
|
||||||
{
|
{
|
||||||
CardinalPluginContext* const pcontext = static_cast<CarlaModule*>(handle)->pcontext;
|
const CardinalPluginContext* const pcontext = static_cast<CarlaModule*>(handle)->pcontext;
|
||||||
DISTRHO_SAFE_ASSERT_RETURN(pcontext != nullptr, 48000.0);
|
DISTRHO_SAFE_ASSERT_RETURN(pcontext != nullptr, 48000.0);
|
||||||
return pcontext->sampleRate;
|
return pcontext->sampleRate;
|
||||||
}
|
}
|
||||||
|
@ -516,7 +516,7 @@ struct CarlaModuleWidget : ModuleWidget, IdleCallback {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const CarlaHostHandle handle = module->fCarlaHostHandle;
|
const CarlaHostHandle handle = module->fCarlaHostHandle;
|
||||||
CardinalPluginContext* const pcontext = module->pcontext;
|
const CardinalPluginContext* const pcontext = module->pcontext;
|
||||||
|
|
||||||
char winIdStr[24];
|
char winIdStr[24];
|
||||||
std::snprintf(winIdStr, sizeof(winIdStr), "%llx", (ulonglong)pcontext->nativeWindowId);
|
std::snprintf(winIdStr, sizeof(winIdStr), "%llx", (ulonglong)pcontext->nativeWindowId);
|
||||||
|
@ -539,7 +539,7 @@ struct CarlaModuleWidget : ModuleWidget, IdleCallback {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const CarlaHostHandle handle = module->fCarlaHostHandle;
|
const CarlaHostHandle handle = module->fCarlaHostHandle;
|
||||||
CardinalPluginContext* const pcontext = module->pcontext;
|
const CardinalPluginContext* const pcontext = module->pcontext;
|
||||||
|
|
||||||
module->fUI = nullptr;
|
module->fUI = nullptr;
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct HostParameters : Module {
|
||||||
{
|
{
|
||||||
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
|
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
|
||||||
|
|
||||||
CardinalPluginContext* const pcontext = static_cast<CardinalPluginContext*>(APP);
|
const CardinalPluginContext* const pcontext = static_cast<CardinalPluginContext*>(APP);
|
||||||
|
|
||||||
if (pcontext == nullptr)
|
if (pcontext == nullptr)
|
||||||
throw rack::Exception("Plugin context is null.");
|
throw rack::Exception("Plugin context is null.");
|
||||||
|
@ -57,7 +57,7 @@ struct HostParameters : Module {
|
||||||
|
|
||||||
void process(const ProcessArgs&) override
|
void process(const ProcessArgs&) override
|
||||||
{
|
{
|
||||||
if (CardinalPluginContext* const pcontext = static_cast<CardinalPluginContext*>(APP))
|
if (const CardinalPluginContext* const pcontext = static_cast<CardinalPluginContext*>(APP))
|
||||||
{
|
{
|
||||||
for (uint32_t i=0; i<kModuleParameters; ++i)
|
for (uint32_t i=0; i<kModuleParameters; ++i)
|
||||||
outputs[i].setVoltage(parameters[i].process(sampleTime, pcontext->parameters[i]));
|
outputs[i].setVoltage(parameters[i].process(sampleTime, pcontext->parameters[i]));
|
||||||
|
@ -66,7 +66,7 @@ struct HostParameters : Module {
|
||||||
|
|
||||||
void onSampleRateChange(const SampleRateChangeEvent& e) override
|
void onSampleRateChange(const SampleRateChangeEvent& e) override
|
||||||
{
|
{
|
||||||
if (CardinalPluginContext* const pcontext = static_cast<CardinalPluginContext*>(APP))
|
if (const CardinalPluginContext* const pcontext = static_cast<CardinalPluginContext*>(APP))
|
||||||
{
|
{
|
||||||
const double fall = 1.0 / (double(pcontext->bufferSize) / e.sampleRate);
|
const double fall = 1.0 / (double(pcontext->bufferSize) / e.sampleRate);
|
||||||
|
|
||||||
|
@ -84,12 +84,12 @@ struct HostParameters : Module {
|
||||||
#ifndef HEADLESS
|
#ifndef HEADLESS
|
||||||
struct CardinalParameterPJ301MPort : PJ301MPort {
|
struct CardinalParameterPJ301MPort : PJ301MPort {
|
||||||
void onDragStart(const DragStartEvent& e) override {
|
void onDragStart(const DragStartEvent& e) override {
|
||||||
if (CardinalPluginContext* const pcontext = static_cast<CardinalPluginContext*>(APP))
|
if (const CardinalPluginContext* const pcontext = static_cast<CardinalPluginContext*>(APP))
|
||||||
handleHostParameterDrag(pcontext, portId, true);
|
handleHostParameterDrag(pcontext, portId, true);
|
||||||
PJ301MPort::onDragStart(e);
|
PJ301MPort::onDragStart(e);
|
||||||
}
|
}
|
||||||
void onDragEnd(const DragEndEvent& e) override {
|
void onDragEnd(const DragEndEvent& e) override {
|
||||||
if (CardinalPluginContext* const pcontext = static_cast<CardinalPluginContext*>(APP))
|
if (const CardinalPluginContext* const pcontext = static_cast<CardinalPluginContext*>(APP))
|
||||||
handleHostParameterDrag(pcontext, portId, false);
|
handleHostParameterDrag(pcontext, portId, false);
|
||||||
PJ301MPort::onDragEnd(e);
|
PJ301MPort::onDragEnd(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,12 +37,21 @@ struct HostTime : Module {
|
||||||
|
|
||||||
rack::dsp::PulseGenerator pulseReset, pulseBar, pulseBeat, pulseClock;
|
rack::dsp::PulseGenerator pulseReset, pulseBar, pulseBeat, pulseClock;
|
||||||
float sampleTime = 0.0f;
|
float sampleTime = 0.0f;
|
||||||
|
int64_t lastBlockFrame = -1;
|
||||||
|
// cached time values
|
||||||
|
struct {
|
||||||
|
bool reset = true;
|
||||||
|
int32_t bar = 0;
|
||||||
|
int32_t beat = 0;
|
||||||
|
double tick = 0.0;
|
||||||
|
double tickClock = 0.0;
|
||||||
|
} timeInfo;
|
||||||
|
|
||||||
HostTime()
|
HostTime()
|
||||||
{
|
{
|
||||||
config(NUM_PARAMS, NUM_INPUTS, kHostTimeCount, kHostTimeCount);
|
config(NUM_PARAMS, NUM_INPUTS, kHostTimeCount, kHostTimeCount);
|
||||||
|
|
||||||
CardinalPluginContext* const pcontext = static_cast<CardinalPluginContext*>(APP);
|
const CardinalPluginContext* const pcontext = static_cast<CardinalPluginContext*>(APP);
|
||||||
|
|
||||||
if (pcontext == nullptr)
|
if (pcontext == nullptr)
|
||||||
throw rack::Exception("Plugin context is null.");
|
throw rack::Exception("Plugin context is null.");
|
||||||
|
@ -50,44 +59,57 @@ struct HostTime : Module {
|
||||||
|
|
||||||
void process(const ProcessArgs& args) override
|
void process(const ProcessArgs& args) override
|
||||||
{
|
{
|
||||||
if (CardinalPluginContext* const pcontext = static_cast<CardinalPluginContext*>(APP))
|
if (const CardinalPluginContext* const pcontext = static_cast<CardinalPluginContext*>(APP))
|
||||||
{
|
{
|
||||||
|
const int64_t blockFrame = pcontext->engine->getBlockFrame();
|
||||||
|
|
||||||
|
// Update time position if running a new audio block
|
||||||
|
if (lastBlockFrame != blockFrame)
|
||||||
|
{
|
||||||
|
lastBlockFrame = blockFrame;
|
||||||
|
timeInfo.reset = pcontext->reset;
|
||||||
|
timeInfo.bar = pcontext->bar;
|
||||||
|
timeInfo.beat = pcontext->beat;
|
||||||
|
timeInfo.tick = pcontext->tick;
|
||||||
|
timeInfo.tickClock = pcontext->tickClock;
|
||||||
|
}
|
||||||
|
|
||||||
const bool playing = pcontext->playing;
|
const bool playing = pcontext->playing;
|
||||||
const bool playingWithBBT = playing && pcontext->bbtValid;
|
const bool playingWithBBT = playing && pcontext->bbtValid;
|
||||||
|
|
||||||
if (playingWithBBT)
|
if (playingWithBBT)
|
||||||
{
|
{
|
||||||
if (pcontext->tick == 0.0)
|
if (timeInfo.tick == 0.0)
|
||||||
{
|
{
|
||||||
pulseReset.trigger();
|
pulseReset.trigger();
|
||||||
pulseClock.trigger();
|
pulseClock.trigger();
|
||||||
pulseBeat.trigger();
|
pulseBeat.trigger();
|
||||||
if (pcontext->beat == 1)
|
if (timeInfo.beat == 1)
|
||||||
pulseBar.trigger();
|
pulseBar.trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pcontext->reset)
|
if (timeInfo.reset)
|
||||||
{
|
{
|
||||||
pcontext->reset = false;
|
timeInfo.reset = false;
|
||||||
pulseReset.trigger();
|
pulseReset.trigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pcontext->tick += pcontext->ticksPerFrame) >= pcontext->ticksPerBeat)
|
if ((timeInfo.tick += pcontext->ticksPerFrame) >= pcontext->ticksPerBeat)
|
||||||
{
|
{
|
||||||
pcontext->tick -= pcontext->ticksPerBeat;
|
timeInfo.tick -= pcontext->ticksPerBeat;
|
||||||
pulseBeat.trigger();
|
pulseBeat.trigger();
|
||||||
|
|
||||||
if (++pcontext->beat > pcontext->beatsPerBar)
|
if (++timeInfo.beat > pcontext->beatsPerBar)
|
||||||
{
|
{
|
||||||
pcontext->beat = 1;
|
timeInfo.beat = 1;
|
||||||
++pcontext->bar;
|
++timeInfo.bar;
|
||||||
pulseBar.trigger();
|
pulseBar.trigger();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pcontext->tickClock += pcontext->ticksPerFrame) >= pcontext->ticksPerClock)
|
if ((timeInfo.tickClock += pcontext->ticksPerFrame) >= pcontext->ticksPerClock)
|
||||||
{
|
{
|
||||||
pcontext->tickClock -= pcontext->ticksPerClock;
|
timeInfo.tickClock -= pcontext->ticksPerClock;
|
||||||
pulseClock.trigger();
|
pulseClock.trigger();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,10 +119,10 @@ struct HostTime : Module {
|
||||||
const bool hasBeat = pulseBeat.process(args.sampleTime);
|
const bool hasBeat = pulseBeat.process(args.sampleTime);
|
||||||
const bool hasClock = pulseClock.process(args.sampleTime);
|
const bool hasClock = pulseClock.process(args.sampleTime);
|
||||||
const float beatPhase = playingWithBBT && pcontext->ticksPerBeat > 0.0
|
const float beatPhase = playingWithBBT && pcontext->ticksPerBeat > 0.0
|
||||||
? pcontext->tick / pcontext->ticksPerBeat
|
? timeInfo.tick / pcontext->ticksPerBeat
|
||||||
: 0.0f;
|
: 0.0f;
|
||||||
const float barPhase = playingWithBBT && pcontext->beatsPerBar > 0
|
const float barPhase = playingWithBBT && pcontext->beatsPerBar > 0
|
||||||
? ((float) (pcontext->beat - 1) + beatPhase) / pcontext->beatsPerBar
|
? ((float) (timeInfo.beat - 1) + beatPhase) / pcontext->beatsPerBar
|
||||||
: 0.0f;
|
: 0.0f;
|
||||||
|
|
||||||
lights[kHostTimeRolling].setBrightness(playing ? 1.0f : 0.0f);
|
lights[kHostTimeRolling].setBrightness(playing ? 1.0f : 0.0f);
|
||||||
|
|
|
@ -248,7 +248,7 @@ struct IldaeilModule : Module {
|
||||||
SharedResourcePointer<JuceInitializer> juceInitializer;
|
SharedResourcePointer<JuceInitializer> juceInitializer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CardinalPluginContext* const pcontext;
|
const CardinalPluginContext* const pcontext;
|
||||||
|
|
||||||
const NativePluginDescriptor* fCarlaPluginDescriptor = nullptr;
|
const NativePluginDescriptor* fCarlaPluginDescriptor = nullptr;
|
||||||
NativePluginHandle fCarlaPluginHandle = nullptr;
|
NativePluginHandle fCarlaPluginHandle = nullptr;
|
||||||
|
@ -588,7 +588,7 @@ static uint32_t host_get_buffer_size(const NativeHostHandle handle)
|
||||||
|
|
||||||
static double host_get_sample_rate(const NativeHostHandle handle)
|
static double host_get_sample_rate(const NativeHostHandle handle)
|
||||||
{
|
{
|
||||||
CardinalPluginContext* const pcontext = static_cast<IldaeilModule*>(handle)->pcontext;
|
const CardinalPluginContext* const pcontext = static_cast<IldaeilModule*>(handle)->pcontext;
|
||||||
DISTRHO_SAFE_ASSERT_RETURN(pcontext != nullptr, 48000.0);
|
DISTRHO_SAFE_ASSERT_RETURN(pcontext != nullptr, 48000.0);
|
||||||
return pcontext->sampleRate;
|
return pcontext->sampleRate;
|
||||||
}
|
}
|
||||||
|
@ -837,7 +837,7 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread {
|
||||||
DISTRHO_SAFE_ASSERT_RETURN(idleCallbackActive,);
|
DISTRHO_SAFE_ASSERT_RETURN(idleCallbackActive,);
|
||||||
DISTRHO_SAFE_ASSERT_RETURN(fPluginType == PLUGIN_INTERNAL || fPluginType == PLUGIN_LV2,);
|
DISTRHO_SAFE_ASSERT_RETURN(fPluginType == PLUGIN_INTERNAL || fPluginType == PLUGIN_LV2,);
|
||||||
|
|
||||||
CardinalPluginContext* const pcontext = module->pcontext;
|
const CardinalPluginContext* const pcontext = module->pcontext;
|
||||||
|
|
||||||
// FIXME isEmbed
|
// FIXME isEmbed
|
||||||
FileBrowserOptions opts;
|
FileBrowserOptions opts;
|
||||||
|
@ -1004,7 +1004,7 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread {
|
||||||
{
|
{
|
||||||
if (const CarlaHostHandle handle = module->fCarlaHostHandle)
|
if (const CarlaHostHandle handle = module->fCarlaHostHandle)
|
||||||
{
|
{
|
||||||
CardinalPluginContext* const pcontext = module->pcontext;
|
const CardinalPluginContext* const pcontext = module->pcontext;
|
||||||
|
|
||||||
char winIdStr[24];
|
char winIdStr[24];
|
||||||
std::snprintf(winIdStr, sizeof(winIdStr), "%llx", (ulonglong)pcontext->nativeWindowId);
|
std::snprintf(winIdStr, sizeof(winIdStr), "%llx", (ulonglong)pcontext->nativeWindowId);
|
||||||
|
@ -1026,7 +1026,7 @@ struct IldaeilWidget : ImGuiWidget, IdleCallback, Thread {
|
||||||
{
|
{
|
||||||
if (const CarlaHostHandle handle = module->fCarlaHostHandle)
|
if (const CarlaHostHandle handle = module->fCarlaHostHandle)
|
||||||
{
|
{
|
||||||
CardinalPluginContext* const pcontext = module->pcontext;
|
const CardinalPluginContext* const pcontext = module->pcontext;
|
||||||
|
|
||||||
module->fCarlaHostDescriptor.uiParentId = 0;
|
module->fCarlaHostDescriptor.uiParentId = 0;
|
||||||
carla_set_engine_option(handle, ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0");
|
carla_set_engine_option(handle, ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0");
|
||||||
|
|
|
@ -55,13 +55,13 @@ struct CardinalPluginContext : rack::Context {
|
||||||
#endif
|
#endif
|
||||||
CardinalPluginContext(Plugin* const p);
|
CardinalPluginContext(Plugin* const p);
|
||||||
#ifndef HEADLESS
|
#ifndef HEADLESS
|
||||||
bool addIdleCallback(IdleCallback* cb);
|
bool addIdleCallback(IdleCallback* cb) const;
|
||||||
void removeIdleCallback(IdleCallback* cb);
|
void removeIdleCallback(IdleCallback* cb) const;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef HEADLESS
|
#ifndef HEADLESS
|
||||||
void handleHostParameterDrag(CardinalPluginContext* pcontext, uint index, bool started);
|
void handleHostParameterDrag(const CardinalPluginContext* pcontext, uint index, bool started);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
END_NAMESPACE_DISTRHO
|
END_NAMESPACE_DISTRHO
|
||||||
|
|
|
@ -930,12 +930,13 @@ protected:
|
||||||
{
|
{
|
||||||
const TimePosition& timePos(getTimePosition());
|
const TimePosition& timePos(getTimePosition());
|
||||||
|
|
||||||
|
bool reset = false;
|
||||||
MidiEvent singleTimeMidiEvent = { 0, 1, { 0, 0, 0, 0 }, nullptr };
|
MidiEvent singleTimeMidiEvent = { 0, 1, { 0, 0, 0, 0 }, nullptr };
|
||||||
|
|
||||||
if (timePos.playing)
|
if (timePos.playing)
|
||||||
{
|
{
|
||||||
if (timePos.frame == 0 || fPreviousFrame + frames != timePos.frame)
|
if (timePos.frame == 0 || fPreviousFrame + frames != timePos.frame)
|
||||||
context->reset = true;
|
reset = true;
|
||||||
|
|
||||||
if (! context->playing)
|
if (! context->playing)
|
||||||
{
|
{
|
||||||
|
@ -977,6 +978,7 @@ protected:
|
||||||
context->tickClock = std::fmod(timePos.bbt.tick, context->ticksPerClock);
|
context->tickClock = std::fmod(timePos.bbt.tick, context->ticksPerClock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context->reset = reset;
|
||||||
fPreviousFrame = timePos.frame;
|
fPreviousFrame = timePos.frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ START_NAMESPACE_DISTRHO
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
bool CardinalPluginContext::addIdleCallback(IdleCallback* const cb)
|
bool CardinalPluginContext::addIdleCallback(IdleCallback* const cb) const
|
||||||
{
|
{
|
||||||
if (ui == nullptr)
|
if (ui == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
@ -202,7 +202,7 @@ bool CardinalPluginContext::addIdleCallback(IdleCallback* const cb)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardinalPluginContext::removeIdleCallback(IdleCallback* const cb)
|
void CardinalPluginContext::removeIdleCallback(IdleCallback* const cb) const
|
||||||
{
|
{
|
||||||
if (ui == nullptr)
|
if (ui == nullptr)
|
||||||
return;
|
return;
|
||||||
|
@ -210,7 +210,7 @@ void CardinalPluginContext::removeIdleCallback(IdleCallback* const cb)
|
||||||
ui->removeIdleCallback(cb);
|
ui->removeIdleCallback(cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleHostParameterDrag(CardinalPluginContext* pcontext, uint index, bool started)
|
void handleHostParameterDrag(const CardinalPluginContext* pcontext, uint index, bool started)
|
||||||
{
|
{
|
||||||
DISTRHO_SAFE_ASSERT_RETURN(pcontext->ui != nullptr,);
|
DISTRHO_SAFE_ASSERT_RETURN(pcontext->ui != nullptr,);
|
||||||
|
|
||||||
|
|
|
@ -91,13 +91,13 @@ struct CardinalPluginContext : rack::Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HEADLESS
|
#ifndef HEADLESS
|
||||||
bool addIdleCallback(IdleCallback* cb);
|
bool addIdleCallback(IdleCallback* cb) const;
|
||||||
void removeIdleCallback(IdleCallback* cb);
|
void removeIdleCallback(IdleCallback* cb) const;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef HEADLESS
|
#ifndef HEADLESS
|
||||||
void handleHostParameterDrag(CardinalPluginContext* pcontext, uint index, bool started);
|
void handleHostParameterDrag(const CardinalPluginContext* pcontext, uint index, bool started);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue