--- gigedit/trunk/src/gigedit/gigedit.cpp 2007/10/21 15:32:36 1456 +++ gigedit/trunk/src/gigedit/gigedit.cpp 2008/01/30 02:20:48 1654 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007 Andreas Persson + * Copyright (C) 2007, 2008 Andreas Persson * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -20,10 +20,19 @@ #include "gigedit.h" #include +#include #include "mainwindow.h" #include "global.h" +GigEditJob::GigEditJob() { + _msecs = 100; // 100ms by default +} + +int GigEditJob::msecs() { + return _msecs; +} + namespace { // State for a gigedit thread. @@ -39,6 +48,9 @@ GigEditState(GigEdit* parent) : parent(parent) { } void run(gig::Instrument* pInstrument); + static std::vector< GigEditJob* > timeoutJobs; + MainWindow* window; + private: // simple condition variable abstraction @@ -71,7 +83,6 @@ Cond open; Cond close; gig::Instrument* instrument; - MainWindow* window; void open_window(); void close_window(); @@ -130,8 +141,11 @@ ); } -} +} // namespace +GigEdit::GigEdit() { + state = NULL; +} int GigEdit::run(int argc, char* argv[]) { init_app(); @@ -148,10 +162,28 @@ init_app(); GigEditState state(this); + this->state = &state; state.run(pInstrument); + this->state = NULL; return 0; } +void GigEdit::add_timeout_job(GigEditJob* job) { + GigEditState::timeoutJobs.push_back(job); +} + +void GigEdit::on_note_on_event(int key, int velocity) { + if (!this->state) return; + GigEditState* state = (GigEditState*) this->state; + state->window->signal_note_on().emit(key, velocity); +} + +void GigEdit::on_note_off_event(int key, int velocity) { + if (!this->state) return; + GigEditState* state = (GigEditState*) this->state; + state->window->signal_note_off().emit(key, velocity); +} + sigc::signal& GigEdit::signal_file_structure_to_be_changed() { return file_structure_to_be_changed_signal; } @@ -192,6 +224,7 @@ Glib::StaticMutex GigEditState::mutex = GLIBMM_STATIC_MUTEX_INIT; Glib::Dispatcher* GigEditState::dispatcher = 0; GigEditState* GigEditState::current = 0; +std::vector GigEditState::timeoutJobs; void GigEditState::open_window_static() { GigEditState* c = GigEditState::current; @@ -225,6 +258,16 @@ dispatcher->connect(sigc::ptr_fun(&GigEditState::open_window_static)); initialized->signal(); + for (int i = 0; i < GigEditState::timeoutJobs.size(); i++) { + GigEditJob* job = timeoutJobs[i]; + const Glib::RefPtr timeout_source = + Glib::TimeoutSource::create(job->msecs()); + timeout_source->connect( + sigc::mem_fun(*job, &GigEditJob::runGigEditJob) + ); + timeout_source->attach(Glib::MainContext::get_default()); + } + main_loop.run(); }