diff options
author | David Robillard <d@drobilla.net> | 2007-06-06 02:51:08 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-06-06 02:51:08 +0000 |
commit | 5a2358e39602607757fedd08a7355bede3cb8739 (patch) | |
tree | 97e7c12667966a8bbc4e9d29a8eceb52fca18fb2 | |
parent | a62edb3f48133352c085e58c970cd77790d47df2 (diff) | |
download | patchage-5a2358e39602607757fedd08a7355bede3cb8739.tar.gz patchage-5a2358e39602607757fedd08a7355bede3cb8739.tar.bz2 patchage-5a2358e39602607757fedd08a7355bede3cb8739.zip |
Nicer Flowcanvas naming.
git-svn-id: http://svn.drobilla.net/lad/patchage@529 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | src/AlsaDriver.cpp | 5 | ||||
-rw-r--r-- | src/JackDriver.cpp | 100 | ||||
-rw-r--r-- | src/JackDriver.h | 7 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/Patchage.cpp | 6 | ||||
-rw-r--r-- | src/Patchage.h | 6 | ||||
-rw-r--r-- | src/PatchageCanvas.cpp (renamed from src/PatchageFlowCanvas.cpp) | 20 | ||||
-rw-r--r-- | src/PatchageCanvas.h (renamed from src/PatchageFlowCanvas.h) | 14 | ||||
-rw-r--r-- | src/PatchageEvent.cpp | 2 | ||||
-rw-r--r-- | src/PatchageModule.h | 10 | ||||
-rw-r--r-- | src/PatchagePort.h | 4 |
11 files changed, 98 insertions, 80 deletions
diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index b583917..87ef6d3 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -18,7 +18,7 @@ #include <string> #include <iostream> #include <cassert> -#include "PatchageFlowCanvas.h" +#include "PatchageCanvas.h" #include "AlsaDriver.h" #include "Patchage.h" #include "PatchageModule.h" @@ -27,8 +27,7 @@ using std::cerr; using std::string; - -using namespace LibFlowCanvas; +using namespace FlowCanvas; AlsaDriver::AlsaDriver(Patchage* app) : _app(app), diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index afb3ffb..5489905 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -24,7 +24,7 @@ #include <jack/statistics.h> #include <jack/thread.h> #include <raul/SharedPtr.h> -#include "PatchageFlowCanvas.h" +#include "PatchageCanvas.h" #include "PatchageEvent.h" #include "JackDriver.h" #include "Patchage.h" @@ -33,7 +33,7 @@ using std::cerr; using std::endl; using std::string; -using namespace LibFlowCanvas; +using namespace FlowCanvas; JackDriver::JackDriver(Patchage* app) @@ -72,17 +72,19 @@ JackDriver::attach(bool launch_daemon) _app->status_message("[JACK] Unable to create client"); _is_activated = false; } else { + jack_client_t* const client = _client; + jack_set_error_function(error_cb); - jack_on_shutdown(_client, jack_shutdown_cb, this); - jack_set_port_registration_callback(_client, jack_port_registration_cb, this); - jack_set_graph_order_callback(_client, jack_graph_order_cb, this); - jack_set_buffer_size_callback(_client, jack_buffer_size_cb, this); - jack_set_xrun_callback(_client, jack_xrun_cb, this); + jack_on_shutdown(client, jack_shutdown_cb, this); + jack_set_port_registration_callback(client, jack_port_registration_cb, this); + jack_set_graph_order_callback(client, jack_graph_order_cb, this); + jack_set_buffer_size_callback(client, jack_buffer_size_cb, this); + jack_set_xrun_callback(client, jack_xrun_cb, this); _is_dirty = true; - _buffer_size = jack_get_buffer_size(_client); + _buffer_size = jack_get_buffer_size(client); - if (!jack_activate(_client)) { + if (!jack_activate(client)) { _is_activated = true; signal_attached.emit(); _app->status_message("[JACK] Attached"); @@ -97,6 +99,8 @@ JackDriver::attach(bool launch_daemon) void JackDriver::detach() { + _mutex.lock(); + if (_client) { jack_deactivate(_client); jack_client_close(_client); @@ -106,6 +110,8 @@ JackDriver::detach() signal_detached.emit(); _app->status_message("[JACK] Detached"); } + + _mutex.unlock(); } @@ -161,29 +167,38 @@ JackDriver::create_port(boost::shared_ptr<PatchageModule> parent, jack_port_t* p } +void +JackDriver::shutdown() +{ + destroy_all_ports(); + signal_detached.emit(); + _is_dirty = false; +} + + /** Refresh all Jack audio ports/connections. * To be called from GTK thread only. */ void JackDriver::refresh() { - //m_mutex.lock(); + const char** ports; + jack_port_t* port; + // Jack can take _client away from us at any time throughout here :/ + // Shortest locks possible is the best solution I can figure out + + _mutex.lock(); + if (_client == NULL) { - // Shutdown - if (_is_dirty) { - destroy_all_ports(); - signal_detached.emit(); - } - _is_dirty = false; - //m_mutex.unlock(); + _mutex.unlock(); + shutdown(); return; } - const char** ports; - jack_port_t* port; - ports = jack_get_ports(_client, NULL, NULL, 0); // get all existing ports + + _mutex.unlock(); string client1_name; string port1_name; @@ -193,7 +208,15 @@ JackDriver::refresh() // Add all ports if (ports) for (int i=0; ports[i]; ++i) { + _mutex.lock(); + if (!_client) { + _mutex.unlock(); + shutdown(); + return; + } port = jack_port_by_name(_client, ports[i]); + _mutex.unlock(); + client1_name = ports[i]; client1_name = client1_name.substr(0, client1_name.find(":")); @@ -256,8 +279,17 @@ JackDriver::refresh() // Add all connections if (ports) for (int i=0; ports[i]; ++i) { + _mutex.lock(); + if (!_client) { + _mutex.unlock(); + shutdown(); + return; + } + port = jack_port_by_name(_client, ports[i]); const char** connected_ports = jack_port_get_all_connections(_client, port); + + _mutex.unlock(); if (connected_ports) { for (int j=0; connected_ports[j]; ++j) { @@ -274,6 +306,9 @@ JackDriver::refresh() boost::shared_ptr<Port> port2 = _app->canvas()->get_port(client2_name, port2_name); + if (!port1 || !port2) + continue; + boost::shared_ptr<Port> src; boost::shared_ptr<Port> dst; @@ -303,8 +338,6 @@ JackDriver::refresh() free(ports); undirty(); - - //m_mutex.unlock(); } @@ -447,10 +480,10 @@ JackDriver::jack_shutdown_cb(void* jack_driver) jack_reset_max_delayed_usecs(me->_client); - //(me->_mutex).lock(); - me->_client = NULL; + me->_mutex.lock(); me->_is_dirty = true; - //(me->_mutex).unlock(); + me->_client = NULL; + me->_mutex.unlock(); } @@ -499,20 +532,3 @@ JackDriver::set_buffer_size(jack_nframes_t size) } } -void -JackDriver::set_realtime(bool /*realtime*/, int /*priority*/) -{ - /* need a jack_set_realtime, this doesn't make sense - pthread_t jack_thread = jack_client_thread_id(_client); - - if (realtime) - if (jack_acquire_real_time_scheduling(jack_thread, priority)) - _app->status_message("[JACK] ERROR: Unable to set real-time priority"); - else - if (jack_drop_real_time_scheduling(jack_thread)) - _app->status_message("[JACK] ERROR: Unable to drop real-time priority"); - - cerr << "Set Jack realtime: " << realtime << endl; - */ -} - diff --git a/src/JackDriver.h b/src/JackDriver.h index f621071..816d7d5 100644 --- a/src/JackDriver.h +++ b/src/JackDriver.h @@ -24,6 +24,8 @@ #include <jack/jack.h> #include <jack/statistics.h> #include <raul/SRSWQueue.h> +#include <raul/Mutex.h> +#include <raul/AtomicPtr.h> #include "Driver.h" class Patchage; class PatchageEvent; @@ -81,8 +83,6 @@ public: inline float sample_rate() { return jack_get_sample_rate(_client); } - void set_realtime(bool realtime, int priority=80); - inline size_t xruns() { return _xruns; } inline float max_delay() { return jack_get_max_delayed_usecs(_client); } @@ -95,6 +95,7 @@ private: static void error_cb(const char* msg); void destroy_all_ports(); + void shutdown(); void update_time(); @@ -109,6 +110,8 @@ private: Raul::SRSWQueue<PatchageEvent> _events; + Raul::Mutex _mutex; + bool _is_activated; jack_position_t _last_pos; jack_nframes_t _buffer_size; diff --git a/src/Makefile.am b/src/Makefile.am index 485686c..04e30c6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -24,8 +24,8 @@ patchage_SOURCES = \ PatchageEvent.cpp \ JackDriver.h \ JackDriver.cpp \ - PatchageFlowCanvas.h \ - PatchageFlowCanvas.cpp + PatchageCanvas.h \ + PatchageCanvas.cpp if WITH_LASH patchage_SOURCES += LashDriver.h LashDriver.cpp diff --git a/src/Patchage.cpp b/src/Patchage.cpp index 2b5a85a..603f306 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -25,7 +25,7 @@ #include <fstream> #include <pthread.h> #include "StateManager.h" -#include "PatchageFlowCanvas.h" +#include "PatchageCanvas.h" #include <jack/statistics.h> #include "JackDriver.h" #include "JackSettingsDialog.h" @@ -91,7 +91,7 @@ Patchage::Patchage(int argc, char** argv) _settings_filename += "/.patchagerc"; _state_manager = new StateManager(); - _canvas = boost::shared_ptr<PatchageFlowCanvas>(new PatchageFlowCanvas(this, 1600*2, 1200*2)); + _canvas = boost::shared_ptr<PatchageCanvas>(new PatchageCanvas(this, 1600*2, 1200*2)); _jack_driver = new JackDriver(this); _jack_driver->signal_detached.connect(sigc::mem_fun(this, &Patchage::queue_refresh)); @@ -195,7 +195,7 @@ Patchage::Patchage(int argc, char** argv) _zoom_normal_button->signal_clicked().connect(sigc::bind( sigc::mem_fun(this, &Patchage::zoom), 1.0)); - _zoom_full_button->signal_clicked().connect(sigc::mem_fun(_canvas.get(), &PatchageFlowCanvas::zoom_full)); + _zoom_full_button->signal_clicked().connect(sigc::mem_fun(_canvas.get(), &PatchageCanvas::zoom_full)); _menu_jack_settings->signal_activate().connect( sigc::hide_return(sigc::mem_fun(_jack_settings_dialog, &JackSettingsDialog::run))); diff --git a/src/Patchage.h b/src/Patchage.h index a647c1c..288c8ee 100644 --- a/src/Patchage.h +++ b/src/Patchage.h @@ -25,7 +25,7 @@ using namespace std; -class PatchageFlowCanvas; +class PatchageCanvas; class JackDriver; class AlsaDriver; class LashDriver; @@ -39,7 +39,7 @@ public: Patchage(int argc, char** argv); ~Patchage(); - boost::shared_ptr<PatchageFlowCanvas> canvas() { return _canvas; } + boost::shared_ptr<PatchageCanvas> canvas() { return _canvas; } StateManager* state_manager() { return _state_manager; } Gtk::Window* window() { return _main_window; } @@ -120,7 +120,7 @@ protected: void menu_alsa_disconnect(); #endif - boost::shared_ptr<PatchageFlowCanvas> _canvas; + boost::shared_ptr<PatchageCanvas> _canvas; JackDriver* _jack_driver; StateManager* _state_manager; diff --git a/src/PatchageFlowCanvas.cpp b/src/PatchageCanvas.cpp index 986265b..97e31bf 100644 --- a/src/PatchageFlowCanvas.cpp +++ b/src/PatchageCanvas.cpp @@ -17,7 +17,7 @@ #include <raul/SharedPtr.h> #include "config.h" -#include "PatchageFlowCanvas.h" +#include "PatchageCanvas.h" #include "Patchage.h" #include "JackDriver.h" #include "PatchageModule.h" @@ -26,15 +26,15 @@ #include "AlsaDriver.h" #endif -PatchageFlowCanvas::PatchageFlowCanvas(Patchage* app, int width, int height) -: FlowCanvas(width, height), +PatchageCanvas::PatchageCanvas(Patchage* app, int width, int height) +: FlowCanvas::Canvas(width, height), _app(app) { } boost::shared_ptr<Item> -PatchageFlowCanvas::get_item(const string& name) +PatchageCanvas::get_item(const string& name) { ItemList::iterator m = _items.begin(); @@ -47,7 +47,7 @@ PatchageFlowCanvas::get_item(const string& name) boost::shared_ptr<PatchageModule> -PatchageFlowCanvas::find_module(const string& name, ModuleType type) +PatchageCanvas::find_module(const string& name, ModuleType type) { for (ItemList::iterator m = _items.begin(); m != _items.end(); ++m) { boost::shared_ptr<PatchageModule> pm = boost::dynamic_pointer_cast<PatchageModule>(*m); @@ -62,7 +62,7 @@ PatchageFlowCanvas::find_module(const string& name, ModuleType type) #ifdef HAVE_ALSA boost::shared_ptr<PatchagePort> -PatchageFlowCanvas::find_port(const snd_seq_addr_t* alsa_addr) +PatchageCanvas::find_port(const snd_seq_addr_t* alsa_addr) { boost::shared_ptr<PatchagePort> pp; for (ItemList::iterator m = _items.begin(); m != _items.end(); ++m) { @@ -83,7 +83,7 @@ PatchageFlowCanvas::find_port(const snd_seq_addr_t* alsa_addr) #endif void -PatchageFlowCanvas::connect(boost::shared_ptr<Connectable> port1, boost::shared_ptr<Connectable> port2) +PatchageCanvas::connect(boost::shared_ptr<Connectable> port1, boost::shared_ptr<Connectable> port2) { boost::shared_ptr<PatchagePort> p1 = boost::dynamic_pointer_cast<PatchagePort>(port1); boost::shared_ptr<PatchagePort> p2 = boost::dynamic_pointer_cast<PatchagePort>(port2); @@ -103,7 +103,7 @@ PatchageFlowCanvas::connect(boost::shared_ptr<Connectable> port1, boost::shared_ void -PatchageFlowCanvas::disconnect(boost::shared_ptr<Connectable> port1, boost::shared_ptr<Connectable> port2) +PatchageCanvas::disconnect(boost::shared_ptr<Connectable> port1, boost::shared_ptr<Connectable> port2) { boost::shared_ptr<PatchagePort> input = boost::dynamic_pointer_cast<PatchagePort>(port1); @@ -138,14 +138,14 @@ PatchageFlowCanvas::disconnect(boost::shared_ptr<Connectable> port1, boost::shar void -PatchageFlowCanvas::status_message(const string& msg) +PatchageCanvas::status_message(const string& msg) { _app->status_message(string("[Canvas] ").append(msg)); } boost::shared_ptr<Port> -PatchageFlowCanvas::get_port(const string& node_name, const string& port_name) +PatchageCanvas::get_port(const string& node_name, const string& port_name) { for (ItemList::iterator i = _items.begin(); i != _items.end(); ++i) { const boost::shared_ptr<Item> item = *i; diff --git a/src/PatchageFlowCanvas.h b/src/PatchageCanvas.h index d395af2..ab9b92e 100644 --- a/src/PatchageFlowCanvas.h +++ b/src/PatchageCanvas.h @@ -15,14 +15,14 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef PATCHAGEPATCHBAYAREA_H -#define PATCHAGEPATCHBAYAREA_H +#ifndef PATCHAGECANVAS_H +#define PATCHAGECANVAS_H #include <string> #ifdef HAVE_ALSA #include <alsa/asoundlib.h> #endif -#include <flowcanvas/FlowCanvas.h> +#include <flowcanvas/Canvas.h> #include "StateManager.h" class Patchage; @@ -30,12 +30,12 @@ class PatchageModule; class PatchagePort; using std::string; -using namespace LibFlowCanvas; +using namespace FlowCanvas; -class PatchageFlowCanvas : public FlowCanvas +class PatchageCanvas : public Canvas { public: - PatchageFlowCanvas(Patchage* _app, int width, int height); + PatchageCanvas(Patchage* _app, int width, int height); boost::shared_ptr<PatchageModule> find_module(const string& name, ModuleType type); #ifdef HAVE_ALSA @@ -55,4 +55,4 @@ private: }; -#endif // PATCHAGEPATCHBAYAREA_H +#endif // PATCHAGECANVAS_H diff --git a/src/PatchageEvent.cpp b/src/PatchageEvent.cpp index 7141ac1..70d1c43 100644 --- a/src/PatchageEvent.cpp +++ b/src/PatchageEvent.cpp @@ -17,7 +17,7 @@ #include "raul/SharedPtr.h" #include "Patchage.h" -#include "PatchageFlowCanvas.h" +#include "PatchageCanvas.h" #include "PatchageModule.h" #include "PatchageEvent.h" #include "JackDriver.h" diff --git a/src/PatchageModule.h b/src/PatchageModule.h index 3dee3c6..131c86a 100644 --- a/src/PatchageModule.h +++ b/src/PatchageModule.h @@ -23,15 +23,15 @@ #ifdef HAVE_ALSA #include <alsa/asoundlib.h> #endif -#include <flowcanvas/FlowCanvas.h> +#include <flowcanvas/Canvas.h> #include <flowcanvas/Module.h> -#include "PatchageFlowCanvas.h" +#include "PatchageCanvas.h" #include "StateManager.h" #include "PatchagePort.h" using std::string; using std::list; -using namespace LibFlowCanvas; +using namespace FlowCanvas; class PatchageModule : public Module { @@ -76,7 +76,7 @@ public: virtual void load_location() { - boost::shared_ptr<FlowCanvas> canvas = _canvas.lock(); + boost::shared_ptr<Canvas> canvas = _canvas.lock(); if (!canvas) return; @@ -113,7 +113,7 @@ public: virtual void on_click(GdkEventButton* ev) { if (ev->button == 3) _menu.popup(ev->button, ev->time); - LibFlowCanvas::Item::on_click(ev); + FlowCanvas::Item::on_click(ev); } virtual void menu_disconnect_all() { diff --git a/src/PatchagePort.h b/src/PatchagePort.h index e4f4c28..6109fba 100644 --- a/src/PatchagePort.h +++ b/src/PatchagePort.h @@ -29,7 +29,7 @@ #include <alsa/asoundlib.h> #endif -using namespace LibFlowCanvas; +using namespace FlowCanvas; using std::string; using std::list; enum PortType { JACK_AUDIO, JACK_MIDI, ALSA_MIDI }; @@ -39,7 +39,7 @@ enum PortType { JACK_AUDIO, JACK_MIDI, ALSA_MIDI }; * * \ingroup OmGtk */ -class PatchagePort : public LibFlowCanvas::Port +class PatchagePort : public FlowCanvas::Port { public: PatchagePort(boost::shared_ptr<Module> module, PortType type, const string& name, bool is_input, int color) |