summaryrefslogtreecommitdiff
path: root/plugingui
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2013-04-28 20:30:05 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2013-04-28 20:30:05 +0200
commitcdbb903edbbe71d3e7a8db61728164b88e8e9c45 (patch)
tree468caa16babdb10134f442181feb876ed2b3ae1b /plugingui
parent3eeba619215dadb15a5fd992cba03bf760c23d3a (diff)
Fix gui crash on window close. Make drumkit and midimap file and status reshow in the gui.
Diffstat (limited to 'plugingui')
-rw-r--r--plugingui/plugingui.cc87
-rw-r--r--plugingui/plugingui.h6
2 files changed, 52 insertions, 41 deletions
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;
};