+
+boost::shared_ptr<Surface>
+MackieControlProtocol::get_surface_by_raw_pointer (void* ptr) const
+{
+ Glib::Threads::Mutex::Lock lm (surfaces_lock);
+
+ for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
+ if ((*s).get() == (Surface*) ptr) {
+ return *s;
+ }
+ }
+
+ return boost::shared_ptr<Surface> ();
+}
+
+boost::shared_ptr<Surface>
+MackieControlProtocol::nth_surface (uint32_t n) const
+{
+ Glib::Threads::Mutex::Lock lm (surfaces_lock);
+
+ for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s, --n) {
+ if (n == 0) {
+ return *s;
+ }
+ }
+
+ return boost::shared_ptr<Surface> ();
+}
+
+void
+MackieControlProtocol::connection_handler (boost::weak_ptr<ARDOUR::Port> wp1, std::string name1, boost::weak_ptr<ARDOUR::Port> wp2, std::string name2, bool yn)
+{
+ Surfaces scopy;
+ {
+ Glib::Threads::Mutex::Lock lm (surfaces_lock);
+ scopy = surfaces;
+ }
+
+ for (Surfaces::const_iterator s = scopy.begin(); s != scopy.end(); ++s) {
+ if ((*s)->connection_handler (wp1, name1, wp2, name2, yn)) {
+ ConnectionChange (*s);
+ break;
+ }
+ }
+}
+
+bool
+MackieControlProtocol::is_track (boost::shared_ptr<Route> r) const
+{
+ return boost::dynamic_pointer_cast<Track>(r) != 0;
+}
+
+bool
+MackieControlProtocol::is_audio_track (boost::shared_ptr<Route> r) const
+{
+ return boost::dynamic_pointer_cast<AudioTrack>(r) != 0;
+}
+
+bool
+MackieControlProtocol::is_midi_track (boost::shared_ptr<Route> r) const
+{
+ return boost::dynamic_pointer_cast<MidiTrack>(r) != 0;
+}
+
+bool
+MackieControlProtocol::selected (boost::shared_ptr<Route> r) const
+{
+ const RouteNotificationList* rl = &_last_selected_routes;
+
+ for (ARDOUR::RouteNotificationList::const_iterator i = rl->begin(); i != rl->end(); ++i) {
+ boost::shared_ptr<ARDOUR::Route> rt = (*i).lock();
+ if (rt == r) {
+ return true;
+ }
+ }
+ return false;
+}
+
+boost::shared_ptr<Route>
+MackieControlProtocol::first_selected_route () const
+{
+ if (_last_selected_routes.empty()) {
+ return boost::shared_ptr<Route>();
+ }
+
+ boost::shared_ptr<Route> r = _last_selected_routes.front().lock();
+
+ return r; /* may be null */
+}
+
+boost::shared_ptr<Route>
+MackieControlProtocol::subview_route () const
+{
+ return _subview_route;
+}
+
+uint32_t
+MackieControlProtocol::global_index (Strip& strip)
+{
+ Glib::Threads::Mutex::Lock lm (surfaces_lock);
+ uint32_t global = 0;
+
+ for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
+ if ((*s).get() == strip.surface()) {
+ return global + strip.index();
+ }
+ global += (*s)->n_strips ();
+ }
+
+ return global;
+}
+
+void*
+MackieControlProtocol::request_factory (uint32_t num_requests)
+{
+ /* AbstractUI<T>::request_buffer_factory() is a template method only
+ instantiated in this source module. To provide something visible for
+ use in the interface/descriptor, we have this static method that is
+ template-free.
+ */
+ return request_buffer_factory (num_requests);
+}