commit e1aee0ec9f4693d1ad9e45a141d12bad81633c71
parent 8e5bb75a862e1ee43927dc26a1fb252aab938fe0
Author: falkTX <falktx@falktx.com>
Date: Sun, 19 Apr 2020 23:35:46 +0100
Port Application to new pugl style
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
3 files changed, 69 insertions(+), 43 deletions(-)
diff --git a/dgl/Application.hpp b/dgl/Application.hpp
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
+ * Copyright (C) 2012-2020 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
@@ -44,7 +44,8 @@ public:
/**
Constructor.
*/
- Application();
+ // NOTE: the default value is not yet passed, so we catch where we use this
+ Application(bool isStandalone /* = true */);
/**
Destructor.
@@ -62,7 +63,7 @@ public:
idle() is called at regular intervals.
@note This function is meant for standalones only, *never* call this from plugins.
*/
- void exec(int idleTime = 10);
+ void exec(uint idleTime = 10);
/**
Quit the application.
diff --git a/dgl/src/Application.cpp b/dgl/src/Application.cpp
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
+ * Copyright (C) 2012-2020 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
@@ -15,14 +15,13 @@
*/
#include "ApplicationPrivateData.hpp"
-#include "../Window.hpp"
START_NAMESPACE_DGL
// -----------------------------------------------------------------------
-Application::Application()
- : pData(new PrivateData()) {}
+Application::Application(const bool isStandalone)
+ : pData(new PrivateData(isStandalone)) {}
Application::~Application()
{
@@ -31,42 +30,23 @@ Application::~Application()
void Application::idle()
{
- for (std::list<Window*>::iterator it = pData->windows.begin(), ite = pData->windows.end(); it != ite; ++it)
- {
- Window* const window(*it);
- window->_idle();
- }
-
- for (std::list<IdleCallback*>::iterator it = pData->idleCallbacks.begin(), ite = pData->idleCallbacks.end(); it != ite; ++it)
- {
- IdleCallback* const idleCallback(*it);
- idleCallback->idleCallback();
- }
+ pData->idle(0);
}
-void Application::exec(int idleTime)
+void Application::exec(const uint idleTime)
{
- for (; pData->doLoop;)
- {
- idle();
- d_msleep(idleTime);
- }
+ while (!pData->isQuitting)
+ pData->idle(idleTime);
}
void Application::quit()
{
- pData->doLoop = false;
-
- for (std::list<Window*>::reverse_iterator rit = pData->windows.rbegin(), rite = pData->windows.rend(); rit != rite; ++rit)
- {
- Window* const window(*rit);
- window->close();
- }
+ pData->quit();
}
bool Application::isQuiting() const noexcept
{
- return !pData->doLoop;
+ return pData->isQuitting;
}
// -----------------------------------------------------------------------
diff --git a/dgl/src/ApplicationPrivateData.hpp b/dgl/src/ApplicationPrivateData.hpp
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
+ * Copyright (C) 2012-2020 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
@@ -18,7 +18,9 @@
#define DGL_APP_PRIVATE_DATA_HPP_INCLUDED
#include "../Application.hpp"
-#include "../../distrho/extra/Sleep.hpp"
+#include "../Window.hpp"
+
+#include "pugl-upstream/pugl/pugl.h"
#include <list>
@@ -27,38 +29,81 @@ START_NAMESPACE_DGL
// -----------------------------------------------------------------------
struct Application::PrivateData {
- bool doLoop;
+ bool isQuitting;
+ bool isStandalone;
uint visibleWindows;
std::list<Window*> windows;
std::list<IdleCallback*> idleCallbacks;
+ PuglWorld* const world;
- PrivateData()
- : doLoop(true),
+ PrivateData(const bool standalone)
+ : isQuitting(false),
+ isStandalone(standalone),
visibleWindows(0),
windows(),
- idleCallbacks() {}
+ idleCallbacks(),
+ world(puglNewWorld(isStandalone ? PUGL_PROGRAM : PUGL_MODULE,
+ isStandalone ? PUGL_WORLD_THREADS : 0x0))
+ {
+ puglSetWorldHandle(world, this);
+
+ // TODO puglSetClassName
+ }
~PrivateData()
{
- DISTRHO_SAFE_ASSERT(! doLoop);
+ DISTRHO_SAFE_ASSERT(isQuitting);
DISTRHO_SAFE_ASSERT(visibleWindows == 0);
windows.clear();
idleCallbacks.clear();
+
+ puglFreeWorld(world);
}
- void oneShown() noexcept
+ void oneWindowShown() noexcept
{
+ DISTRHO_SAFE_ASSERT_RETURN(isStandalone,);
+
if (++visibleWindows == 1)
- doLoop = true;
+ isQuitting = false;
}
- void oneHidden() noexcept
+ void oneWindowHidden() noexcept
{
+ DISTRHO_SAFE_ASSERT_RETURN(isStandalone,);
DISTRHO_SAFE_ASSERT_RETURN(visibleWindows > 0,);
if (--visibleWindows == 0)
- doLoop = false;
+ isQuitting = true;
+ }
+
+ void idle(const uint timeout)
+ {
+ puglUpdate(world, timeout == 0 ? 0.0 : (1.0 / static_cast<double>(timeout)));
+
+ for (std::list<Window*>::iterator it = windows.begin(), ite = windows.end(); it != ite; ++it)
+ {
+ Window* const window(*it);
+ window->_idle();
+ }
+
+ for (std::list<IdleCallback*>::iterator it = idleCallbacks.begin(), ite = idleCallbacks.end(); it != ite; ++it)
+ {
+ IdleCallback* const idleCallback(*it);
+ idleCallback->idleCallback();
+ }
+ }
+
+ void quit()
+ {
+ isQuitting = true;
+
+ for (std::list<Window*>::reverse_iterator rit = windows.rbegin(), rite = windows.rend(); rit != rite; ++rit)
+ {
+ Window* const window(*rit);
+ window->close();
+ }
}
DISTRHO_DECLARE_NON_COPY_STRUCT(PrivateData)