1 |
/* |
/* |
2 |
* Copyright (C) 2007-2013 Andreas Persson |
* Copyright (C) 2007-2015 Andreas Persson |
3 |
* |
* |
4 |
* This program is free software; you can redistribute it and/or |
* This program is free software; you can redistribute it and/or |
5 |
* modify it under the terms of the GNU General Public License as |
* modify it under the terms of the GNU General Public License as |
17 |
* 02110-1301 USA. |
* 02110-1301 USA. |
18 |
*/ |
*/ |
19 |
|
|
20 |
|
#include <glibmmconfig.h> |
21 |
|
// threads.h must be included first to be able to build with |
22 |
|
// G_DISABLE_DEPRECATED |
23 |
|
#if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \ |
24 |
|
(GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2 |
25 |
|
#include <glibmm/threads.h> |
26 |
|
#endif |
27 |
|
|
28 |
#include "gigedit.h" |
#include "gigedit.h" |
29 |
|
|
30 |
#include <glibmm/dispatcher.h> |
#include <glibmm/dispatcher.h> |
47 |
#endif |
#endif |
48 |
|
|
49 |
//TODO: (hopefully) just a temporary nasty hack for launching gigedit on the main thread on Mac (see comments below in this file for details) |
//TODO: (hopefully) just a temporary nasty hack for launching gigedit on the main thread on Mac (see comments below in this file for details) |
50 |
#if defined(__APPLE__) // the following global external variables are defined in LinuxSampler's global_private.cpp ... |
#if defined(__APPLE__) && HAVE_LINUXSAMPLER // the following global external variables are defined in LinuxSampler's global_private.cpp ... |
51 |
extern bool g_mainThreadCallbackSupported; |
extern bool g_mainThreadCallbackSupported; |
52 |
extern void (*g_mainThreadCallback)(void* info); |
extern void (*g_mainThreadCallback)(void* info); |
53 |
extern void* g_mainThreadCallbackInfo; |
extern void* g_mainThreadCallbackInfo; |
66 |
// |
// |
67 |
class GigEditState : public sigc::trackable { |
class GigEditState : public sigc::trackable { |
68 |
public: |
public: |
69 |
GigEditState(GigEdit* parent) : parent(parent) { } |
GigEditState(GigEdit* parent) : |
70 |
|
window(0), parent(parent), instrument(0) { } |
71 |
void run(gig::Instrument* pInstrument); |
void run(gig::Instrument* pInstrument); |
72 |
|
|
73 |
MainWindow* window; |
MainWindow* window; |
244 |
mainwindow->signal_keyboard_key_released().connect( |
mainwindow->signal_keyboard_key_released().connect( |
245 |
gigedit->signal_keyboard_key_released().make_slot() |
gigedit->signal_keyboard_key_released().make_slot() |
246 |
); |
); |
247 |
|
mainwindow->signal_switch_sampler_instrument().connect( |
248 |
|
gigedit->signal_switch_sampler_instrument().make_slot() |
249 |
|
); |
250 |
} |
} |
251 |
|
|
252 |
} // namespace |
} // namespace |
289 |
|
|
290 |
void GigEdit::on_note_on_event(int key, int velocity) { |
void GigEdit::on_note_on_event(int key, int velocity) { |
291 |
if (!this->state) return; |
if (!this->state) return; |
292 |
GigEditState* state = (GigEditState*) this->state; |
GigEditState* state = static_cast<GigEditState*>(this->state); |
293 |
state->window->signal_note_on().emit(key, velocity); |
state->window->signal_note_on().emit(key, velocity); |
294 |
} |
} |
295 |
|
|
296 |
void GigEdit::on_note_off_event(int key, int velocity) { |
void GigEdit::on_note_off_event(int key, int velocity) { |
297 |
if (!this->state) return; |
if (!this->state) return; |
298 |
GigEditState* state = (GigEditState*) this->state; |
GigEditState* state = static_cast<GigEditState*>(this->state); |
299 |
state->window->signal_note_off().emit(key, velocity); |
state->window->signal_note_off().emit(key, velocity); |
300 |
} |
} |
301 |
|
|
347 |
return keyboard_key_released_signal; |
return keyboard_key_released_signal; |
348 |
} |
} |
349 |
|
|
350 |
|
sigc::signal<void, gig::Instrument*>& GigEdit::signal_switch_sampler_instrument() { |
351 |
|
return switch_sampler_instrument_signal; |
352 |
|
} |
353 |
|
|
354 |
#ifdef OLD_THREADS |
#ifdef OLD_THREADS |
355 |
Glib::StaticMutex GigEditState::mutex = GLIBMM_STATIC_MUTEX_INIT; |
Glib::StaticMutex GigEditState::mutex = GLIBMM_STATIC_MUTEX_INIT; |
356 |
#else |
#else |
417 |
mutex.lock(); // lock access to static variables |
mutex.lock(); // lock access to static variables |
418 |
|
|
419 |
static bool main_loop_started = false; |
static bool main_loop_started = false; |
420 |
|
instrument = pInstrument; |
421 |
if (!main_loop_started) { |
if (!main_loop_started) { |
422 |
#if defined(__APPLE__) |
#if defined(__APPLE__) && HAVE_LINUXSAMPLER |
423 |
// spawn GUI on main thread : |
// spawn GUI on main thread : |
424 |
// On OS X the Gtk GUI can only be launched on a process's "main" |
// On OS X the Gtk GUI can only be launched on a process's "main" |
425 |
// thread. When trying to launch the Gtk GUI on any other thread, |
// thread. When trying to launch the Gtk GUI on any other thread, |
483 |
printf("GUI is now initialized. Everything done.\n"); fflush(stdout); |
printf("GUI is now initialized. Everything done.\n"); fflush(stdout); |
484 |
main_loop_started = true; |
main_loop_started = true; |
485 |
} |
} |
|
instrument = pInstrument; |
|
486 |
current = this; |
current = this; |
487 |
dispatcher->emit(); |
dispatcher->emit(); |
488 |
open.wait(); // wait until the GUI thread has read current |
open.wait(); // wait until the GUI thread has read current |