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 <gtkmmconfig.h> |
31 |
|
#if GTKMM_MAJOR_VERSION < 3 |
32 |
|
#include <gdkmm/region.h> |
33 |
|
#endif |
34 |
#include <glibmm/dispatcher.h> |
#include <glibmm/dispatcher.h> |
35 |
#include <glibmm/main.h> |
#include <glibmm/main.h> |
36 |
#include <gtkmm/main.h> |
#include <gtkmm/main.h> |
51 |
#endif |
#endif |
52 |
|
|
53 |
//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) |
54 |
#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 ... |
55 |
extern bool g_mainThreadCallbackSupported; |
extern bool g_mainThreadCallbackSupported; |
56 |
extern void (*g_mainThreadCallback)(void* info); |
extern void (*g_mainThreadCallback)(void* info); |
57 |
extern void* g_mainThreadCallbackInfo; |
extern void* g_mainThreadCallbackInfo; |
70 |
// |
// |
71 |
class GigEditState : public sigc::trackable { |
class GigEditState : public sigc::trackable { |
72 |
public: |
public: |
73 |
GigEditState(GigEdit* parent) : parent(parent) { } |
GigEditState(GigEdit* parent) : |
74 |
|
window(0), parent(parent), instrument(0) { } |
75 |
void run(gig::Instrument* pInstrument); |
void run(gig::Instrument* pInstrument); |
76 |
|
|
77 |
MainWindow* window; |
MainWindow* window; |
248 |
mainwindow->signal_keyboard_key_released().connect( |
mainwindow->signal_keyboard_key_released().connect( |
249 |
gigedit->signal_keyboard_key_released().make_slot() |
gigedit->signal_keyboard_key_released().make_slot() |
250 |
); |
); |
251 |
|
mainwindow->signal_switch_sampler_instrument().connect( |
252 |
|
gigedit->signal_switch_sampler_instrument().make_slot() |
253 |
|
); |
254 |
|
mainwindow->signal_script_to_be_changed.connect( |
255 |
|
gigedit->signal_script_to_be_changed.make_slot() |
256 |
|
); |
257 |
|
mainwindow->signal_script_changed.connect( |
258 |
|
gigedit->signal_script_changed.make_slot() |
259 |
|
); |
260 |
} |
} |
261 |
|
|
262 |
} // namespace |
} // namespace |
299 |
|
|
300 |
void GigEdit::on_note_on_event(int key, int velocity) { |
void GigEdit::on_note_on_event(int key, int velocity) { |
301 |
if (!this->state) return; |
if (!this->state) return; |
302 |
GigEditState* state = (GigEditState*) this->state; |
GigEditState* state = static_cast<GigEditState*>(this->state); |
303 |
state->window->signal_note_on().emit(key, velocity); |
state->window->signal_note_on().emit(key, velocity); |
304 |
} |
} |
305 |
|
|
306 |
void GigEdit::on_note_off_event(int key, int velocity) { |
void GigEdit::on_note_off_event(int key, int velocity) { |
307 |
if (!this->state) return; |
if (!this->state) return; |
308 |
GigEditState* state = (GigEditState*) this->state; |
GigEditState* state = static_cast<GigEditState*>(this->state); |
309 |
state->window->signal_note_off().emit(key, velocity); |
state->window->signal_note_off().emit(key, velocity); |
310 |
} |
} |
311 |
|
|
357 |
return keyboard_key_released_signal; |
return keyboard_key_released_signal; |
358 |
} |
} |
359 |
|
|
360 |
|
sigc::signal<void, gig::Instrument*>& GigEdit::signal_switch_sampler_instrument() { |
361 |
|
return switch_sampler_instrument_signal; |
362 |
|
} |
363 |
|
|
364 |
#ifdef OLD_THREADS |
#ifdef OLD_THREADS |
365 |
Glib::StaticMutex GigEditState::mutex = GLIBMM_STATIC_MUTEX_INIT; |
Glib::StaticMutex GigEditState::mutex = GLIBMM_STATIC_MUTEX_INIT; |
366 |
#else |
#else |
391 |
close.signal(); |
close.signal(); |
392 |
} |
} |
393 |
|
|
394 |
|
#if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) |
395 |
|
// make sure stack is 16-byte aligned for SSE instructions |
396 |
|
__attribute__((force_align_arg_pointer)) |
397 |
|
#endif |
398 |
void GigEditState::main_loop_run(Cond* initialized) { |
void GigEditState::main_loop_run(Cond* initialized) { |
399 |
int argc = 1; |
int argc = 1; |
400 |
const char* argv_c[] = { "gigedit" }; |
const char* argv_c[] = { "gigedit" }; |
431 |
mutex.lock(); // lock access to static variables |
mutex.lock(); // lock access to static variables |
432 |
|
|
433 |
static bool main_loop_started = false; |
static bool main_loop_started = false; |
434 |
|
instrument = pInstrument; |
435 |
if (!main_loop_started) { |
if (!main_loop_started) { |
436 |
#if defined(__APPLE__) |
#if defined(__APPLE__) && HAVE_LINUXSAMPLER |
437 |
// spawn GUI on main thread : |
// spawn GUI on main thread : |
438 |
// 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" |
439 |
// thread. When trying to launch the Gtk GUI on any other thread, |
// thread. When trying to launch the Gtk GUI on any other thread, |
497 |
printf("GUI is now initialized. Everything done.\n"); fflush(stdout); |
printf("GUI is now initialized. Everything done.\n"); fflush(stdout); |
498 |
main_loop_started = true; |
main_loop_started = true; |
499 |
} |
} |
|
instrument = pInstrument; |
|
500 |
current = this; |
current = this; |
501 |
dispatcher->emit(); |
dispatcher->emit(); |
502 |
open.wait(); // wait until the GUI thread has read current |
open.wait(); // wait until the GUI thread has read current |