1 |
/* |
/* |
2 |
* Copyright (C) 2007 Andreas Persson |
* Copyright (C) 2007, 2008 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 |
20 |
#include "gigedit.h" |
#include "gigedit.h" |
21 |
|
|
22 |
#include <gtkmm/main.h> |
#include <gtkmm/main.h> |
23 |
|
#include <glibmm/main.h> |
24 |
#include "mainwindow.h" |
#include "mainwindow.h" |
25 |
|
|
26 |
#include "global.h" |
#include "global.h" |
27 |
|
|
28 |
|
GigEditJob::GigEditJob() { |
29 |
|
_msecs = 100; // 100ms by default |
30 |
|
} |
31 |
|
|
32 |
|
int GigEditJob::msecs() { |
33 |
|
return _msecs; |
34 |
|
} |
35 |
|
|
36 |
namespace { |
namespace { |
37 |
|
|
38 |
// State for a gigedit thread. |
// State for a gigedit thread. |
48 |
GigEditState(GigEdit* parent) : parent(parent) { } |
GigEditState(GigEdit* parent) : parent(parent) { } |
49 |
void run(gig::Instrument* pInstrument); |
void run(gig::Instrument* pInstrument); |
50 |
|
|
51 |
|
static std::vector< GigEditJob* > timeoutJobs; |
52 |
|
MainWindow* window; |
53 |
|
|
54 |
private: |
private: |
55 |
|
|
56 |
// simple condition variable abstraction |
// simple condition variable abstraction |
83 |
Cond open; |
Cond open; |
84 |
Cond close; |
Cond close; |
85 |
gig::Instrument* instrument; |
gig::Instrument* instrument; |
|
MainWindow* window; |
|
86 |
|
|
87 |
void open_window(); |
void open_window(); |
88 |
void close_window(); |
void close_window(); |
141 |
); |
); |
142 |
} |
} |
143 |
|
|
144 |
} |
} // namespace |
145 |
|
|
146 |
|
GigEdit::GigEdit() { |
147 |
|
state = NULL; |
148 |
|
} |
149 |
|
|
150 |
int GigEdit::run(int argc, char* argv[]) { |
int GigEdit::run(int argc, char* argv[]) { |
151 |
init_app(); |
init_app(); |
162 |
init_app(); |
init_app(); |
163 |
|
|
164 |
GigEditState state(this); |
GigEditState state(this); |
165 |
|
this->state = &state; |
166 |
state.run(pInstrument); |
state.run(pInstrument); |
167 |
|
this->state = NULL; |
168 |
return 0; |
return 0; |
169 |
} |
} |
170 |
|
|
171 |
|
void GigEdit::add_timeout_job(GigEditJob* job) { |
172 |
|
GigEditState::timeoutJobs.push_back(job); |
173 |
|
} |
174 |
|
|
175 |
|
void GigEdit::on_note_on_event(int key, int velocity) { |
176 |
|
if (!this->state) return; |
177 |
|
GigEditState* state = (GigEditState*) this->state; |
178 |
|
state->window->signal_note_on().emit(key, velocity); |
179 |
|
} |
180 |
|
|
181 |
|
void GigEdit::on_note_off_event(int key, int velocity) { |
182 |
|
if (!this->state) return; |
183 |
|
GigEditState* state = (GigEditState*) this->state; |
184 |
|
state->window->signal_note_off().emit(key, velocity); |
185 |
|
} |
186 |
|
|
187 |
sigc::signal<void, gig::File*>& GigEdit::signal_file_structure_to_be_changed() { |
sigc::signal<void, gig::File*>& GigEdit::signal_file_structure_to_be_changed() { |
188 |
return file_structure_to_be_changed_signal; |
return file_structure_to_be_changed_signal; |
189 |
} |
} |
224 |
Glib::StaticMutex GigEditState::mutex = GLIBMM_STATIC_MUTEX_INIT; |
Glib::StaticMutex GigEditState::mutex = GLIBMM_STATIC_MUTEX_INIT; |
225 |
Glib::Dispatcher* GigEditState::dispatcher = 0; |
Glib::Dispatcher* GigEditState::dispatcher = 0; |
226 |
GigEditState* GigEditState::current = 0; |
GigEditState* GigEditState::current = 0; |
227 |
|
std::vector<GigEditJob*> GigEditState::timeoutJobs; |
228 |
|
|
229 |
void GigEditState::open_window_static() { |
void GigEditState::open_window_static() { |
230 |
GigEditState* c = GigEditState::current; |
GigEditState* c = GigEditState::current; |
258 |
dispatcher->connect(sigc::ptr_fun(&GigEditState::open_window_static)); |
dispatcher->connect(sigc::ptr_fun(&GigEditState::open_window_static)); |
259 |
initialized->signal(); |
initialized->signal(); |
260 |
|
|
261 |
|
for (int i = 0; i < GigEditState::timeoutJobs.size(); i++) { |
262 |
|
GigEditJob* job = timeoutJobs[i]; |
263 |
|
const Glib::RefPtr<Glib::TimeoutSource> timeout_source = |
264 |
|
Glib::TimeoutSource::create(job->msecs()); |
265 |
|
timeout_source->connect( |
266 |
|
sigc::mem_fun(*job, &GigEditJob::runGigEditJob) |
267 |
|
); |
268 |
|
timeout_source->attach(Glib::MainContext::get_default()); |
269 |
|
} |
270 |
|
|
271 |
main_loop.run(); |
main_loop.run(); |
272 |
} |
} |
273 |
|
|