summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lv2/lv2_gui.cc31
-rw-r--r--plugingui/plugingui.cc87
-rw-r--r--plugingui/plugingui.h6
3 files changed, 57 insertions, 67 deletions
diff --git a/lv2/lv2_gui.cc b/lv2/lv2_gui.cc
index afd47a2..0242dcf 100644
--- a/lv2/lv2_gui.cc
+++ b/lv2/lv2_gui.cc
@@ -120,47 +120,32 @@ struct DG_GUI {
static void ui_run(struct lv2_external_ui * _this_)
{
- printf("run() called\n");
struct DG_GUI *dggui = (struct DG_GUI *)_this_;
dggui->gui->processEvents();
}
static void ui_show(struct lv2_external_ui * _this_)
{
- printf("show() called\n");
struct DG_GUI *dggui = (struct DG_GUI *)_this_;
dggui->gui->show();
}
static void ui_hide(struct lv2_external_ui * _this_)
{
- printf("hide() called\n");
struct DG_GUI *dggui = (struct DG_GUI *)_this_;
dggui->gui->hide();
}
static void closeHandler(void *ptr)
{
- printf("> closeHandler\n");
struct DG_GUI *gui = (struct DG_GUI *)ptr;
- if(gui->ui_host_ptr && gui->ui_host_ptr->ui_closed)
- gui->ui_host_ptr->ui_closed(gui->controller);
- gui->gui->hide();
- printf("< closeHandler\n");
-}
-static void midimapHandler(void *ptr, const char* file)
-{
- /*
- printf("> midimapHandler %s\n", file);
- struct DG_GUI *gui = (struct DG_GUI *)ptr;
- gui->instance->midimapfile = file;
-
- DGLV2 *dglv2 = (DGLV2 *)gui->instance_handle;
- dglv2->in->loadMidiMap(file);
+ if(gui->ui_host_ptr && gui->ui_host_ptr->ui_closed) {
+ gui->ui_host_ptr->ui_closed(gui->controller);
+ }
- printf("< midimapHandler\n");
- */
+ delete gui->gui;
+ gui->gui = NULL;
}
static LV2UI_Handle ui_instantiate(const struct _LV2UI_Descriptor * descriptor,
@@ -207,8 +192,6 @@ static LV2UI_Handle ui_instantiate(const struct _LV2UI_Descriptor * descriptor,
pt->virt.hide = ui_hide;
pt->gui = new PluginGUI(pt->instance);
pt->gui->setWindowClosedCallback(closeHandler, pt);
- pt->gui->setChangeMidimapCallback(midimapHandler, pt);
- // pt->gui->show();
*widget = (LV2UI_Widget)pt;
@@ -217,7 +200,6 @@ static LV2UI_Handle ui_instantiate(const struct _LV2UI_Descriptor * descriptor,
static void ui_cleanup(LV2UI_Handle ui)
{
- printf("ui_cleanup\n");
struct DG_GUI* pt = (struct DG_GUI*)ui;
delete pt->gui;
delete pt;
@@ -229,7 +211,6 @@ static void ui_port_event(LV2UI_Handle ui,
uint32_t format,
const void * buffer)
{
- printf("ui_cport_event\n");
}
#ifdef __cplusplus
@@ -246,8 +227,6 @@ static LV2UI_Descriptor descriptor = {
const LV2UI_Descriptor *lv2ui_descriptor(uint32_t index)
{
- printf("lv2ui_descriptor\n");
-
if(index == 0) return &descriptor;
return NULL;
}
diff --git a/plugingui/plugingui.cc b/plugingui/plugingui.cc
index 8e886ee..13b11d8 100644
--- a/plugingui/plugingui.cc
+++ b/plugingui/plugingui.cc
@@ -189,6 +189,7 @@ PluginGUI::PluginGUI(DrumGizmo *drumgizmo)
eventhandler = NULL;
running = true;
+ closing = false;
#ifdef USE_THREAD
run();
@@ -201,14 +202,15 @@ PluginGUI::PluginGUI(DrumGizmo *drumgizmo)
PluginGUI::~PluginGUI()
{
- DEBUG(plugingui, "~PluginGUI()\n");
-
- running = false;
- wait_stop();
+ stopThread();
+}
- if(window) delete window;
- if(eventhandler) delete eventhandler;
- if(gctx) delete gctx;
+void PluginGUI::stopThread()
+{
+ if(running) {
+ running = false;
+ wait_stop();
+ }
}
void PluginGUI::thread_main()
@@ -220,15 +222,19 @@ void PluginGUI::thread_main()
drumgizmo->sendEngineMessage(msg);
}
- while(running) {
- eventhandler->processEvents(window);
+ while(1) {
#ifdef WIN32
- SleepEx(50, FALSE);
+ SleepEx(50000, FALSE);
#else
- usleep(50);
+ usleep(50000);
#endif/*WIN32*/
+
+ if(!running) break;
+
+ eventhandler->processEvents(window);
+
Message *msg;
- while((msg = drumgizmo->receiveGUIMessage()) != NULL) {
+ if((msg = drumgizmo->receiveGUIMessage()) != NULL) {
switch(msg->type()) {
case Message::LoadStatus:
{
@@ -239,10 +245,6 @@ void PluginGUI::thread_main()
msg = drumgizmo->receiveGUIMessage();
}
LoadStatusMessage *ls = (LoadStatusMessage*)msg;
- DEBUG(gui, "%d of %d (%s)\n",
- ls->numer_of_files_loaded,
- ls->number_of_files,
- ls->current_file.c_str());
progress->setProgress((float)ls->numer_of_files_loaded /
(float)ls->number_of_files);
if(ls->numer_of_files_loaded == ls->number_of_files) {
@@ -253,8 +255,6 @@ void PluginGUI::thread_main()
case Message::LoadStatusMidimap:
{
LoadStatusMessageMidimap *ls = (LoadStatusMessageMidimap*)msg;
- DEBUG(gui, "Midimap status (%d)\n",
- ls->success);
progress2->setProgress(1);
if(ls->success) {
progress2->setState(GUI::ProgressBar::green);
@@ -267,6 +267,13 @@ void PluginGUI::thread_main()
{
EngineSettingsMessage *settings = (EngineSettingsMessage *)msg;
lineedit->setText(settings->drumkitfile);
+ if(settings->drumkit_loaded) {
+ progress->setProgress(1);
+ progress->setState(GUI::ProgressBar::green);
+ } else {
+ progress->setProgress(0);
+ progress->setState(GUI::ProgressBar::blue);
+ }
lineedit2->setText(settings->midimapfile);
if(settings->midimap_loaded) {
progress2->setProgress(1);
@@ -287,6 +294,21 @@ void PluginGUI::thread_main()
delete msg;
}
}
+
+ deinit();
+}
+
+void PluginGUI::deinit()
+{
+ if(window) delete window;
+ if(eventhandler) delete eventhandler;
+ if(gctx) delete gctx;
+}
+
+void closeEventHandler(void *ptr)
+{
+ volatile bool *closing = (volatile bool*)ptr;
+ *closing = true;
}
void PluginGUI::init()
@@ -294,7 +316,8 @@ void PluginGUI::init()
DEBUG(gui, "init");
gctx = new GUI::GlobalContext();
eventhandler = new GUI::EventHandler(gctx);
- // printf("%p\n", eventhandler);
+ eventhandler->registerCloseHandler(closeEventHandler, (void*)&closing);
+
window = new GUI::Window(gctx);
window->resize(370, 330);
window->setCaption("DrumGizmo v"VERSION);
@@ -445,29 +468,26 @@ void PluginGUI::init()
sem.post();
}
-static bool shown = false;
void PluginGUI::show()
{
if(!gctx) init();
- // printf("PluginGUI::show()\n");
- if(!shown && window) {
- shown = true;
- //window->show();
- }
+ window->show();
}
void PluginGUI::hide()
{
- // printf("PluginGUI::hide()\n");
if(window) window->hide();
}
void PluginGUI::processEvents()
{
-#ifdef USE_THREAD
-#else
- printf("PluginGUI::processEvents()\n");
+ if(closing) {
+ if(windowClosedHandler) windowClosedHandler(windowClosedPtr);
+ closing = false;
+ }
+
+#ifndef USE_THREAD
eventhandler->processEvents(window);
#endif/*USE_THREAD*/
}
@@ -476,15 +496,6 @@ void PluginGUI::setWindowClosedCallback(void (*handler)(void *), void *ptr)
{
windowClosedHandler = handler;
windowClosedPtr = ptr;
- eventhandler->registerCloseHandler(handler, ptr);
-}
-
-
-void PluginGUI::setChangeMidimapCallback(void (*handler)(void *, const char *),
- void *ptr)
-{
- changeMidimapHandler = handler;
- changeMidimapPtr = ptr;
}
#ifdef STANDALONE
diff --git a/plugingui/plugingui.h b/plugingui/plugingui.h
index 1f0bf57..ac0023b 100644
--- a/plugingui/plugingui.h
+++ b/plugingui/plugingui.h
@@ -51,17 +51,16 @@ public:
~PluginGUI();
void thread_main();
+ void stopThread();
void init();
+ void deinit();
void show();
void hide();
void processEvents();
void setWindowClosedCallback(void (*handler)(void *), void *ptr);
- void setChangeMidimapCallback(void (*handler)(void *, const char *),
- void *ptr);
-
//private:
GUI::GlobalContext *gctx;
GUI::Window *window;
@@ -91,6 +90,7 @@ public:
private:
volatile bool running;
+ volatile bool closing;
Semaphore sem;
};