Browse Source

Idle timer for external UI (macOS)

pull/360/head
Luciano Iam 4 years ago
parent
commit
a076131303
2 changed files with 57 additions and 2 deletions
  1. +7
    -0
      distrho/DistrhoUIMain.cpp
  2. +50
    -2
      distrho/src/DistrhoUIVST3.cpp

+ 7
- 0
distrho/DistrhoUIMain.cpp View File

@@ -14,6 +14,13 @@
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include "src/DistrhoDefines.h"
#if defined(DISTRHO_OS_MAC)
// Allow referencing CoreFoundation from DistrhoUIVST3.cpp. Include must appear
// before DGL headers otherwise compiler fails on ambiguous 'Point' definition.
# include <CoreFoundation/CoreFoundation.h>
#endif

#include "src/DistrhoUI.cpp"

#if defined(DISTRHO_PLUGIN_TARGET_CARLA)


+ 50
- 2
distrho/src/DistrhoUIVST3.cpp View File

@@ -142,8 +142,12 @@ public:

~UIVst3()
{
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI && (defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS))
#if defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS)
# if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
nativeIdleTimerDestroy();
# else
fUI.removeIdleCallbackForVST3(this);
# endif
#endif
if (fConnection != nullptr)
disconnect();
@@ -168,8 +172,12 @@ public:
if (fConnection != nullptr)
connect(fConnection);

#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI && (defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS))
#if defined(DISTRHO_OS_MAC) || defined(DISTRHO_OS_WINDOWS)
# if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
nativeIdleTimerCreate(DPF_VST3_TIMER_INTERVAL);
# else
fUI.addIdleCallbackForVST3(this, DPF_VST3_TIMER_INTERVAL);
# endif
#endif
}

@@ -541,6 +549,11 @@ private:
// Plugin UI (after VST3 stuff so the UI can call into us during its constructor)
UIExporter fUI;

// Native timer support
#if defined(DISTRHO_OS_MAC)
CFRunLoopTimerRef fTimer;
#endif

// ----------------------------------------------------------------------------------------------------------------
// helper functions called during message passing

@@ -712,6 +725,41 @@ private:
((UIVst3*)ptr)->setState(key, value);
}
#endif

#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI
# if defined(DISTRHO_OS_MAC)
void nativeIdleTimerCreate(const uint timerFrequencyInMs)
{
const CFTimeInterval t = static_cast<double>(timerFrequencyInMs) / 1000.0;
CFRunLoopTimerContext ctx = {};
ctx.info = this;
fTimer = CFRunLoopTimerCreate(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + t, t, 0, 0,
UIVst3::nativeIdleTimerCallback, &ctx);
CFRunLoopAddTimer(CFRunLoopGetMain(), fTimer, kCFRunLoopCommonModes);
}

void nativeIdleTimerDestroy()
{
CFRunLoopRemoveTimer(CFRunLoopGetMain(), fTimer, kCFRunLoopCommonModes);
CFRelease(fTimer);
}

static void nativeIdleTimerCallback(CFRunLoopTimerRef timer, void *info)
{
reinterpret_cast<UIVst3*>(info)->onTimer();
}
# elif defined(DISTRHO_OS_WINDOWS)
void nativeIdleTimerCreate(const uint timerFrequencyInMs)
{
// TODO
}

void nativeIdleTimerDestroy()
{
// TODO
}
# endif
#endif
};

// --------------------------------------------------------------------------------------------------------------------


Loading…
Cancel
Save