X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=libs%2Fsurfaces%2Fcontrol_protocol%2Fcontrol_protocol.cc;h=8c2a1217790063cd4650d6debddda2a54149f41e;hb=0e5ac13a045c41e6451b92da0a5e588dddb84e62;hp=ff6de6b274ee9d8251e91b7e002afd7eb4f624ec;hpb=f450df300c9c057141a4caf79ff6dbfbf58492d9;p=ardour.git diff --git a/libs/surfaces/control_protocol/control_protocol.cc b/libs/surfaces/control_protocol/control_protocol.cc index ff6de6b274..8c2a121779 100644 --- a/libs/surfaces/control_protocol/control_protocol.cc +++ b/libs/surfaces/control_protocol/control_protocol.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2006 Paul Davis + Copyright (C) 2006 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser @@ -20,7 +20,9 @@ #include "pbd/error.h" +#include "ardour/gain_control.h" #include "ardour/session.h" +#include "ardour/record_enable_control.h" #include "ardour/route.h" #include "ardour/audio_track.h" #include "ardour/meter.h" @@ -35,115 +37,73 @@ Signal0 ControlProtocol::ZoomToSession; Signal0 ControlProtocol::ZoomOut; Signal0 ControlProtocol::ZoomIn; Signal0 ControlProtocol::Enter; +Signal0 ControlProtocol::Undo; +Signal0 ControlProtocol::Redo; Signal1 ControlProtocol::ScrollTimeline; - -ControlProtocol::ControlProtocol (Session& s, string str, EventLoop* evloop) - : BasicUI (s), - _name (str) +Signal1 ControlProtocol::GotoView; +Signal0 ControlProtocol::CloseDialog; +PBD::Signal0 ControlProtocol::VerticalZoomInAll; +PBD::Signal0 ControlProtocol::VerticalZoomOutAll; +PBD::Signal0 ControlProtocol::VerticalZoomInSelected; +PBD::Signal0 ControlProtocol::VerticalZoomOutSelected; +PBD::Signal0 ControlProtocol::StepTracksDown; +PBD::Signal0 ControlProtocol::StepTracksUp; + +PBD::Signal1 > ControlProtocol::AddStripableToSelection; +PBD::Signal1 > ControlProtocol::SetStripableSelection; +PBD::Signal1 > ControlProtocol::ToggleStripableSelection; +PBD::Signal1 > ControlProtocol::RemoveStripableFromSelection; +PBD::Signal0 ControlProtocol::ClearStripableSelection; + +PBD::Signal1 ControlProtocol::StripableSelectionChanged; + +Glib::Threads::Mutex ControlProtocol::first_selected_mutex; +boost::weak_ptr ControlProtocol::_first_selected_stripable; +StripableNotificationList ControlProtocol::_last_selected; +bool ControlProtocol::selection_connected = false; +PBD::ScopedConnection ControlProtocol::selection_connection; + +const std::string ControlProtocol::state_node_name ("Protocol"); + +ControlProtocol::ControlProtocol (Session& s, string str) + : BasicUI (s) + , _name (str) + , _active (false) { - if (evloop) { - _own_event_loop = false; - _event_loop = evloop; - } else { - _own_event_loop = true; - fatal << "programming error: cannot create control protocols without an existing event loop (yet)" << endmsg; - /*NOTREACHED*/ - } + if (!selection_connected) { + /* this is all static, connect it only once (and early), for all ControlProtocols */ - _active = false; - - session->RouteAdded.connect (*this, boost::protect (boost::bind (&ControlProtocol::add_strip, this, _1)), _event_loop); + StripableSelectionChanged.connect_same_thread (selection_connection, boost::bind (&ControlProtocol::stripable_selection_changed, _1)); + selection_connected = true; + } } ControlProtocol::~ControlProtocol () { } -void -ControlProtocol::add_strip (ARDOUR::RouteList&) +int +ControlProtocol::set_active (bool yn) { - route_list_changed(); + _active = yn; + return 0; } - + void ControlProtocol::next_track (uint32_t initial_id) { - uint32_t limit = session->nroutes(); - boost::shared_ptr cr = route_table[0]; - uint32_t id; - - if (cr) { - id = cr->remote_control_id (); - } else { - id = 0; - } - - if (id == limit) { - id = 0; - } else { - id++; - } - - while (id <= limit) { - if ((cr = session->route_by_remote_id (id)) != 0) { - break; - } - id++; - } - - if (id >= limit) { - id = 0; - while (id != initial_id) { - if ((cr = session->route_by_remote_id (id)) != 0) { - break; - } - id++; - } - } - - route_table[0] = cr; + // STRIPABLE route_table[0] = _session->get_nth_stripable (++initial_id, RemoteControlID::Route); } void ControlProtocol::prev_track (uint32_t initial_id) { - uint32_t limit = session->nroutes(); - boost::shared_ptr cr = route_table[0]; - int32_t id; - - if (cr) { - id = cr->remote_control_id (); - } else { - id = 0; - } - - if (id == 0) { - id = limit; - } else { - id--; - } - - while (id >= 0) { - if ((cr = session->route_by_remote_id (id)) != 0) { - break; - } - id--; - } - - if (id < 0) { - uint32_t i = limit; - while (i > initial_id) { - if ((cr = session->route_by_remote_id (i)) != 0) { - break; - } - i--; - } + if (!initial_id) { + return; } - - route_table[0] = cr; + // STRIPABLE route_table[0] = _session->get_nth_stripable (--initial_id, RemoteControlID::Route); } - void ControlProtocol::set_route_table_size (uint32_t size) { @@ -158,7 +118,7 @@ ControlProtocol::set_route_table (uint32_t table_index, boost::shared_ptr= route_table.size()) { return; } - + route_table[table_index] = r; // XXX SHAREDPTR need to handle r->GoingAway @@ -167,6 +127,7 @@ ControlProtocol::set_route_table (uint32_t table_index, boost::shared_ptr r = session->route_by_remote_id (remote_control_id); if (!r) { @@ -174,7 +135,7 @@ ControlProtocol::set_route_table (uint32_t table_index, uint32_t remote_control_ } set_route_table (table_index, r); - +#endif return true; } @@ -190,7 +151,7 @@ ControlProtocol::route_set_rec_enable (uint32_t table_index, bool yn) boost::shared_ptr at = boost::dynamic_pointer_cast(r); if (at) { - at->set_record_enable (yn, this); + at->rec_enable_control()->set_value (1.0, Controllable::UseGroup); } } @@ -206,7 +167,7 @@ ControlProtocol::route_get_rec_enable (uint32_t table_index) boost::shared_ptr at = boost::dynamic_pointer_cast(r); if (at) { - return at->record_enabled (); + return at->rec_enable_control()->get_value(); } return false; @@ -226,7 +187,7 @@ ControlProtocol::route_get_gain (uint32_t table_index) return 0.0f; } - return r->amp()->gain (); + return r->gain_control()->get_value(); } void @@ -237,9 +198,9 @@ ControlProtocol::route_set_gain (uint32_t table_index, float gain) } boost::shared_ptr r = route_table[table_index]; - + if (r != 0) { - r->set_gain (gain, this); + r->gain_control()->set_value (gain, Controllable::UseGroup); } } @@ -273,10 +234,9 @@ ControlProtocol::route_get_peak_input_power (uint32_t table_index, uint32_t whic return 0.0f; } - return r->peak_meter().peak_power (which_input); + return r->peak_meter()->meter_level (which_input, MeterPeak); } - bool ControlProtocol::route_get_muted (uint32_t table_index) { @@ -290,7 +250,7 @@ ControlProtocol::route_get_muted (uint32_t table_index) return false; } - return r->muted (); + return r->mute_control()->muted (); } void @@ -303,7 +263,7 @@ ControlProtocol::route_set_muted (uint32_t table_index, bool yn) boost::shared_ptr r = route_table[table_index]; if (r != 0) { - r->set_mute (yn, this); + r->mute_control()->set_value (yn ? 1.0 : 0.0, Controllable::UseGroup); } } @@ -334,7 +294,7 @@ ControlProtocol::route_set_soloed (uint32_t table_index, bool yn) boost::shared_ptr r = route_table[table_index]; if (r != 0) { - r->set_solo (yn, this); + r->solo_control()->set_value (yn ? 1.0 : 0.0, Controllable::UseGroup); } } @@ -354,3 +314,65 @@ ControlProtocol:: route_get_name (uint32_t table_index) return r->name(); } +list > +ControlProtocol::bundles () +{ + return list > (); +} + +XMLNode& +ControlProtocol::get_state () +{ + XMLNode* node = new XMLNode (state_node_name); + + node->add_property ("name", _name); + node->add_property ("feedback", get_feedback() ? "yes" : "no"); + + return *node; +} + +int +ControlProtocol::set_state (XMLNode const & node, int /* version */) +{ + const XMLProperty* prop; + + if ((prop = node.property ("feedback")) != 0) { + set_feedback (string_is_affirmative (prop->value())); + } + + return 0; +} + +boost::shared_ptr +ControlProtocol::first_selected_stripable () +{ + Glib::Threads::Mutex::Lock lm (first_selected_mutex); + return _first_selected_stripable.lock(); +} + +void +ControlProtocol::set_first_selected_stripable (boost::shared_ptr s) +{ + Glib::Threads::Mutex::Lock lm (first_selected_mutex); + _first_selected_stripable = s; +} + +void +ControlProtocol::stripable_selection_changed (StripableNotificationListPtr sp) +{ + bool had_selection = !_last_selected.empty(); + + _last_selected = *sp; + + { + Glib::Threads::Mutex::Lock lm (first_selected_mutex); + + if (!_last_selected.empty()) { + if (!had_selection) { + _first_selected_stripable = _last_selected.front().lock(); + } + } else { + _first_selected_stripable = boost::weak_ptr(); + } + } +}