1 |
/* |
/* |
2 |
* Copyright (C) 2007, 2008 Andreas Persson |
* Copyright (C) 2007-2009 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 |
25 |
|
|
26 |
#include "global.h" |
#include "global.h" |
27 |
|
|
|
GigEditJob::GigEditJob() { |
|
|
_msecs = 100; // 100ms by default |
|
|
} |
|
|
|
|
|
int GigEditJob::msecs() { |
|
|
return _msecs; |
|
|
} |
|
|
|
|
28 |
namespace { |
namespace { |
29 |
|
|
30 |
// State for a gigedit thread. |
// State for a gigedit thread. |
40 |
GigEditState(GigEdit* parent) : parent(parent) { } |
GigEditState(GigEdit* parent) : parent(parent) { } |
41 |
void run(gig::Instrument* pInstrument); |
void run(gig::Instrument* pInstrument); |
42 |
|
|
|
static std::vector< GigEditJob* > timeoutJobs; |
|
43 |
MainWindow* window; |
MainWindow* window; |
44 |
|
|
45 |
private: |
private: |
79 |
void close_window(); |
void close_window(); |
80 |
}; |
}; |
81 |
|
|
82 |
|
#ifdef WIN32 |
83 |
|
HINSTANCE gigedit_dll_handle = 0; |
84 |
|
#endif |
85 |
|
|
86 |
void init_app() { |
void init_app() { |
87 |
static bool process_initialized = false; |
static bool process_initialized = false; |
88 |
if (!process_initialized) { |
if (!process_initialized) { |
91 |
setlocale(LC_ALL, ""); |
setlocale(LC_ALL, ""); |
92 |
|
|
93 |
#if HAVE_GETTEXT |
#if HAVE_GETTEXT |
94 |
|
|
95 |
|
#ifdef WIN32 |
96 |
|
#if GLIB_CHECK_VERSION(2, 16, 0) |
97 |
|
gchar* root = |
98 |
|
g_win32_get_package_installation_directory_of_module(gigedit_dll_handle); |
99 |
|
#else |
100 |
|
gchar* root = |
101 |
|
g_win32_get_package_installation_directory(NULL, NULL); |
102 |
|
#endif |
103 |
|
gchar* temp = g_build_filename(root, "/share/locale", NULL); |
104 |
|
g_free(root); |
105 |
|
gchar* localedir = g_win32_locale_filename_from_utf8(temp); |
106 |
|
g_free(temp); |
107 |
|
bindtextdomain(GETTEXT_PACKAGE, localedir); |
108 |
|
g_free(localedir); |
109 |
|
#else |
110 |
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); |
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); |
111 |
|
#endif |
112 |
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); |
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); |
113 |
textdomain(GETTEXT_PACKAGE); |
textdomain(GETTEXT_PACKAGE); |
114 |
#endif // HAVE_GETTEXT |
#endif // HAVE_GETTEXT |
148 |
mainwindow->signal_dimreg_changed().connect( |
mainwindow->signal_dimreg_changed().connect( |
149 |
gigedit->signal_dimreg_changed().make_slot() |
gigedit->signal_dimreg_changed().make_slot() |
150 |
); |
); |
151 |
|
mainwindow->signal_sample_changed().connect( |
152 |
|
gigedit->signal_sample_changed().make_slot() |
153 |
|
); |
154 |
mainwindow->signal_sample_ref_changed().connect( |
mainwindow->signal_sample_ref_changed().connect( |
155 |
gigedit->signal_sample_ref_changed().make_slot() |
gigedit->signal_sample_ref_changed().make_slot() |
156 |
); |
); |
157 |
|
mainwindow->signal_keyboard_key_hit().connect( |
158 |
|
gigedit->signal_keyboard_key_hit().make_slot() |
159 |
|
); |
160 |
|
mainwindow->signal_keyboard_key_released().connect( |
161 |
|
gigedit->signal_keyboard_key_released().make_slot() |
162 |
|
); |
163 |
} |
} |
164 |
|
|
165 |
} // namespace |
} // namespace |
189 |
return 0; |
return 0; |
190 |
} |
} |
191 |
|
|
|
void GigEdit::add_timeout_job(GigEditJob* job) { |
|
|
GigEditState::timeoutJobs.push_back(job); |
|
|
} |
|
|
|
|
192 |
void GigEdit::on_note_on_event(int key, int velocity) { |
void GigEdit::on_note_on_event(int key, int velocity) { |
193 |
if (!this->state) return; |
if (!this->state) return; |
194 |
GigEditState* state = (GigEditState*) this->state; |
GigEditState* state = (GigEditState*) this->state; |
233 |
return dimreg_changed_signal; |
return dimreg_changed_signal; |
234 |
} |
} |
235 |
|
|
236 |
|
sigc::signal<void, gig::Sample*>& GigEdit::signal_sample_changed() { |
237 |
|
return sample_changed_signal; |
238 |
|
} |
239 |
|
|
240 |
sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& GigEdit::signal_sample_ref_changed() { |
sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& GigEdit::signal_sample_ref_changed() { |
241 |
return sample_ref_changed_signal; |
return sample_ref_changed_signal; |
242 |
} |
} |
243 |
|
|
244 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& GigEdit::signal_keyboard_key_hit() { |
245 |
|
return keyboard_key_hit_signal; |
246 |
|
} |
247 |
|
|
248 |
|
sigc::signal<void, int/*key*/, int/*velocity*/>& GigEdit::signal_keyboard_key_released() { |
249 |
|
return keyboard_key_released_signal; |
250 |
|
} |
251 |
|
|
252 |
Glib::StaticMutex GigEditState::mutex = GLIBMM_STATIC_MUTEX_INIT; |
Glib::StaticMutex GigEditState::mutex = GLIBMM_STATIC_MUTEX_INIT; |
253 |
Glib::Dispatcher* GigEditState::dispatcher = 0; |
Glib::Dispatcher* GigEditState::dispatcher = 0; |
254 |
GigEditState* GigEditState::current = 0; |
GigEditState* GigEditState::current = 0; |
|
std::vector<GigEditJob*> GigEditState::timeoutJobs; |
|
255 |
|
|
256 |
void GigEditState::open_window_static() { |
void GigEditState::open_window_static() { |
257 |
GigEditState* c = GigEditState::current; |
GigEditState* c = GigEditState::current; |
285 |
dispatcher->connect(sigc::ptr_fun(&GigEditState::open_window_static)); |
dispatcher->connect(sigc::ptr_fun(&GigEditState::open_window_static)); |
286 |
initialized->signal(); |
initialized->signal(); |
287 |
|
|
|
for (int i = 0; i < GigEditState::timeoutJobs.size(); i++) { |
|
|
GigEditJob* job = timeoutJobs[i]; |
|
|
const Glib::RefPtr<Glib::TimeoutSource> timeout_source = |
|
|
Glib::TimeoutSource::create(job->msecs()); |
|
|
timeout_source->connect( |
|
|
sigc::mem_fun(*job, &GigEditJob::runGigEditJob) |
|
|
); |
|
|
timeout_source->attach(Glib::MainContext::get_default()); |
|
|
} |
|
|
|
|
288 |
main_loop.run(); |
main_loop.run(); |
289 |
} |
} |
290 |
|
|
308 |
mutex.unlock(); |
mutex.unlock(); |
309 |
close.wait(); // sleep until window is closed |
close.wait(); // sleep until window is closed |
310 |
} |
} |
311 |
|
|
312 |
|
#if defined(WIN32) |
313 |
|
extern "C" { |
314 |
|
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) |
315 |
|
{ |
316 |
|
switch (reason) { |
317 |
|
case DLL_PROCESS_ATTACH: |
318 |
|
gigedit_dll_handle = instance; |
319 |
|
break; |
320 |
|
} |
321 |
|
return TRUE; |
322 |
|
} |
323 |
|
} |
324 |
|
#endif |