Browse Source

Store entire time info in context; More ImGui/Ildaeil fixups

Signed-off-by: falkTX <falktx@falktx.com>
tags/22.02
falkTX 3 years ago
parent
commit
af80d41aef
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
5 changed files with 68 additions and 30 deletions
  1. +22
    -20
      plugins/Cardinal/src/Ildaeil.cpp
  2. +25
    -3
      plugins/Cardinal/src/ImGuiWidget.cpp
  3. +4
    -2
      plugins/Cardinal/src/plugincontext.hpp
  4. +5
    -0
      src/CardinalPlugin.cpp
  5. +12
    -5
      src/PluginContext.hpp

+ 22
- 20
plugins/Cardinal/src/Ildaeil.cpp View File

@@ -89,6 +89,8 @@ struct IldaeilModule : Module {
NUM_LIGHTS
};

CardinalPluginContext* const pcontext;

const NativePluginDescriptor* fCarlaPluginDescriptor = nullptr;
NativePluginHandle fCarlaPluginHandle = nullptr;

@@ -107,6 +109,7 @@ struct IldaeilModule : Module {
unsigned audioDataFill = 0;

IldaeilModule()
: pcontext(reinterpret_cast<CardinalPluginContext*>(APP))
{
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);

@@ -172,19 +175,19 @@ struct IldaeilModule : Module {

const NativeTimeInfo* hostGetTimeInfo() const noexcept
{
if (CardinalPluginContext* const pcontext = reinterpret_cast<CardinalPluginContext*>(APP))
if (pcontext != nullptr)
{
fCarlaTimeInfo.playing = pcontext->playing;
// fCarlaTimeInfo.frame = timePos.frame;
// fCarlaTimeInfo.bbt.valid = timePos.bbt.valid;
fCarlaTimeInfo.frame = pcontext->frame;
fCarlaTimeInfo.bbt.valid = pcontext->bbtValid;
fCarlaTimeInfo.bbt.bar = pcontext->bar;
fCarlaTimeInfo.bbt.beat = pcontext->beat;
fCarlaTimeInfo.bbt.tick = pcontext->tick;
// fCarlaTimeInfo.bbt.barStartTick = timePos.bbt.barStartTick;
fCarlaTimeInfo.bbt.barStartTick = pcontext->barStartTick;
fCarlaTimeInfo.bbt.beatsPerBar = pcontext->beatsPerBar;
// fCarlaTimeInfo.bbt.beatType = timePos.bbt.beatType;
fCarlaTimeInfo.bbt.beatType = pcontext->beatType;
fCarlaTimeInfo.bbt.ticksPerBeat = pcontext->ticksPerBeat;
// fCarlaTimeInfo.bbt.beatsPerMinute = timePos.bbt.beatsPerMinute;
fCarlaTimeInfo.bbt.beatsPerMinute = pcontext->beatsPerMinute;
}

return &fCarlaTimeInfo;
@@ -405,7 +408,7 @@ struct IldaeilWidget : ImGuiWidget, Thread {

IldaeilModule* const module;

IldaeilWidget(IldaeilModule* const m, const uintptr_t nativeWindowId)
IldaeilWidget(IldaeilModule* const m)
: ImGuiWidget(),
module(m)
{
@@ -424,7 +427,7 @@ struct IldaeilWidget : ImGuiWidget, Thread {
const CarlaHostHandle handle = module->fCarlaHostHandle;

char winIdStr[24];
std::snprintf(winIdStr, sizeof(winIdStr), "%lx", (ulong)nativeWindowId);
std::snprintf(winIdStr, sizeof(winIdStr), "%lx", (ulong)module->pcontext->nativeWindowId);
carla_set_engine_option(handle, ENGINE_OPTION_FRONTEND_WIN_ID, 0, winIdStr);
/*
carla_set_engine_option(handle, ENGINE_OPTION_FRONTEND_UI_SCALE, getScaleFactor()*1000, nullptr);
@@ -626,21 +629,18 @@ struct IldaeilWidget : ImGuiWidget, Thread {
{
ImGuiWidget::onContextCreate(e);

/*
if (module == nullptr || module->fCarlaHostHandle == nullptr)
if (module == nullptr || module->pcontext == nullptr || module->fCarlaHostHandle == nullptr)
return;
*/

const uintptr_t nativeWindowId = reinterpret_cast<CardinalPluginContext*>(APP)->nativeWindowId;

char winIdStr[24];
std::snprintf(winIdStr, sizeof(winIdStr), "%lx", (ulong)nativeWindowId);
std::snprintf(winIdStr, sizeof(winIdStr), "%lx", (ulong)module->pcontext->nativeWindowId);
carla_set_engine_option(module->fCarlaHostHandle, ENGINE_OPTION_FRONTEND_WIN_ID, 0, winIdStr);
}

void onContextDestroy(const ContextDestroyEvent& e) override
{
carla_set_engine_option(module->fCarlaHostHandle, ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0");
if (module != nullptr && module->fCarlaHostHandle != nullptr)
carla_set_engine_option(module->fCarlaHostHandle, ENGINE_OPTION_FRONTEND_WIN_ID, 0, "0");

ImGuiWidget::onContextDestroy(e);
}
@@ -1122,11 +1122,13 @@ struct IldaeilModuleWidget : ModuleWidget {
setModule(module);
setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/glBars.svg")));

ildaeilWidget = new IldaeilWidget(static_cast<IldaeilModule*>(module),
reinterpret_cast<CardinalPluginContext*>(APP)->nativeWindowId);
ildaeilWidget->box.pos = Vec(2 * RACK_GRID_WIDTH, 0);
ildaeilWidget->box.size = Vec(box.size.x - 2 * RACK_GRID_WIDTH, box.size.y);
addChild(ildaeilWidget);
if (module != nullptr && module->pcontext != nullptr)
{
ildaeilWidget = new IldaeilWidget(module);
ildaeilWidget->box.pos = Vec(2 * RACK_GRID_WIDTH, 0);
ildaeilWidget->box.size = Vec(box.size.x - 2 * RACK_GRID_WIDTH, box.size.y);
addChild(ildaeilWidget);
}

addChild(createWidget<ScrewSilver>(Vec(0, 0)));
addChild(createWidget<ScrewSilver>(Vec(0, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));


+ 25
- 3
plugins/Cardinal/src/ImGuiWidget.cpp View File

@@ -16,6 +16,7 @@
*/

#include "ImGuiWidget.hpp"
#include "DistrhoUtils.hpp"

#ifndef DGL_NO_SHARED_RESOURCES
# include "../../../dpf/dgl/src/Resources.hpp"
@@ -24,12 +25,14 @@
#include "DearImGui/imgui_impl_opengl2.h"

struct ImGuiWidget::PrivateData {
ImGuiContext* context;
ImGuiContext* context = nullptr;
bool created = false;

PrivateData(const double scaleFactor = 1.0)
{
IMGUI_CHECKVERSION();
context = ImGui::CreateContext();
ImGui::SetCurrentContext(context);

ImGuiIO& io(ImGui::GetIO());
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
@@ -77,6 +80,13 @@ struct ImGuiWidget::PrivateData {

~PrivateData()
{
// this should not happen
if (created)
{
ImGui::SetCurrentContext(context);
ImGui_ImplOpenGL2_Shutdown();
}

ImGui::DestroyContext(context);
}
};
@@ -92,15 +102,21 @@ ImGuiWidget::~ImGuiWidget()
void ImGuiWidget::onContextCreate(const ContextCreateEvent& e)
{
OpenGlWidget::onContextCreate(e);
DISTRHO_SAFE_ASSERT_RETURN(!imData->created,);

ImGui::SetCurrentContext(imData->context);
ImGui_ImplOpenGL2_Init();
imData->created = true;
}

void ImGuiWidget::onContextDestroy(const ContextDestroyEvent& e)
{
ImGui::SetCurrentContext(imData->context);
ImGui_ImplOpenGL2_Shutdown();
if (imData->created)
{
ImGui::SetCurrentContext(imData->context);
ImGui_ImplOpenGL2_Shutdown();
imData->created = false;
}

OpenGlWidget::onContextDestroy(e);
}
@@ -115,6 +131,12 @@ void ImGuiWidget::drawFramebuffer()
io.DisplayFramebufferScale = ImVec2(fbSize.x / box.size.x, fbSize.y / box.size.y);
io.DisplaySize = ImVec2(box.size.x, box.size.y);

if (!imData->created)
{
ImGui_ImplOpenGL2_Init();
imData->created = true;
}

// TODO io.DeltaTime

ImGui_ImplOpenGL2_NewFrame();


+ 4
- 2
plugins/Cardinal/src/plugincontext.hpp View File

@@ -33,8 +33,10 @@ struct CardinalPluginContext : rack::Context {
uint32_t bufferSize;
double sampleRate;
float parameters[kModuleParameters];
bool playing, reset;
int32_t bar, beat, beatsPerBar;
bool playing, reset, bbtValid;
int32_t bar, beat, beatsPerBar, beatType;
uint64_t frame;
double barStartTick, beatsPerMinute;
double tick, tickClock, ticksPerBeat, ticksPerClock, ticksPerFrame;
uintptr_t nativeWindowId;
Plugin* const plugin;


+ 5
- 0
src/CardinalPlugin.cpp View File

@@ -818,6 +818,8 @@ protected:
{
const TimePosition& timePos(getTimePosition());
context->playing = timePos.playing;
context->bbtValid = timePos.bbt.valid;
context->frame = timePos.frame;
if (timePos.bbt.valid)
{
@@ -827,6 +829,9 @@ protected:
context->bar = timePos.bbt.bar;
context->beat = timePos.bbt.beat;
context->beatsPerBar = timePos.bbt.beatsPerBar;
context->beatType = timePos.bbt.beatType;
context->barStartTick = timePos.bbt.barStartTick;
context->beatsPerMinute = timePos.bbt.beatsPerMinute;
context->tick = timePos.bbt.tick;
context->ticksPerBeat = timePos.bbt.ticksPerBeat;
context->ticksPerClock = timePos.bbt.ticksPerBeat / timePos.bbt.beatType;


+ 12
- 5
src/PluginContext.hpp View File

@@ -40,8 +40,10 @@ struct CardinalPluginContext : rack::Context {
uint32_t bufferSize;
double sampleRate;
float parameters[kModuleParameters];
bool playing, reset;
int32_t bar, beat, beatsPerBar;
bool playing, reset, bbtValid;
int32_t bar, beat, beatsPerBar, beatType;
uint64_t frame;
double barStartTick, beatsPerMinute;
double tick, tickClock, ticksPerBeat, ticksPerClock, ticksPerFrame;
uintptr_t nativeWindowId;
Plugin* const plugin;
@@ -51,9 +53,14 @@ struct CardinalPluginContext : rack::Context {
sampleRate(p->getSampleRate()),
playing(false),
reset(false),
bar(0),
beat(0),
beatsPerBar(0),
bbtValid(false),
bar(1),
beat(1),
beatsPerBar(4),
beatType(4),
frame(0),
barStartTick(0.0),
beatsPerMinute(120.0),
tick(0.0),
tickClock(0.0),
ticksPerBeat(0.0),


Loading…
Cancel
Save