+void
+MackieControlProtocol::notify_subview_stripable_deleted ()
+{
+ /* return to global/mixer view */
+ _subview_stripable.reset ();
+ set_view_mode (Mixer);
+}
+
+bool
+MackieControlProtocol::subview_mode_would_be_ok (SubViewMode mode, boost::shared_ptr<Stripable> r)
+{
+ switch (mode) {
+ case None:
+ return true;
+ break;
+
+ case Sends:
+ if (r && r->send_level_controllable (0)) {
+ return true;
+ }
+ break;
+
+ case EQ:
+ if (r && r->eq_band_cnt() > 0) {
+ return true;
+ }
+ break;
+
+ case Dynamics:
+ if (r && r->comp_enable_controllable()) {
+ return true;
+ }
+ break;
+
+ case TrackView:
+ if (r) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+bool
+MackieControlProtocol::redisplay_subview_mode ()
+{
+ Surfaces copy; /* can't hold surfaces lock while calling Strip::subview_mode_changed */
+
+ {
+ Glib::Threads::Mutex::Lock lm (surfaces_lock);
+ copy = surfaces;
+ }
+
+ for (Surfaces::iterator s = copy.begin(); s != copy.end(); ++s) {
+ (*s)->subview_mode_changed ();
+ }
+
+ /* don't call this again from a timeout */
+ return false;
+}
+
+int
+MackieControlProtocol::set_subview_mode (SubViewMode sm, boost::shared_ptr<Stripable> r)
+{
+ if (_flip_mode != Normal) {
+ set_flip_mode (Normal);
+ }
+
+ if (!subview_mode_would_be_ok (sm, r)) {
+
+ if (r) {
+
+ Glib::Threads::Mutex::Lock lm (surfaces_lock);
+
+ if (!surfaces.empty()) {
+
+ string msg;
+
+ switch (sm) {
+ case Sends:
+ msg = _("no sends for selected track/bus");
+ break;
+ case EQ:
+ msg = _("no EQ in the track/bus");
+ break;
+ case Dynamics:
+ msg = _("no dynamics in selected track/bus");
+ break;
+ case TrackView:
+ msg = _("no track view possible");
+ default:
+ break;
+ }
+ if (!msg.empty()) {
+ surfaces.front()->display_message_for (msg, 1000);
+ if (_subview_mode != None) {
+ /* redisplay current subview mode after
+ that message goes away.
+ */
+ Glib::RefPtr<Glib::TimeoutSource> redisplay_timeout = Glib::TimeoutSource::create (1000); // milliseconds
+ redisplay_timeout->connect (sigc::mem_fun (*this, &MackieControlProtocol::redisplay_subview_mode));
+ redisplay_timeout->attach (main_loop()->get_context());
+ }
+ }
+ }
+ }
+
+ return -1;
+ }
+
+ boost::shared_ptr<Stripable> old_stripable = _subview_stripable;
+
+ _subview_mode = sm;
+ _subview_stripable = r;
+
+ if (_subview_route != old_stripable) {
+ subview_route_connections.drop_connections ();
+
+ /* Catch the current subview stripable going away */
+ if (_subview_stripable) {
+ _subview_stripable->DropReferences.connect (subview_stripable_connections, MISSING_INVALIDATOR,
+ boost::bind (&MackieControlProtocol::notify_subview_stripable_deleted, this),
+ this);
+ }
+ }
+
+ redisplay_subview_mode ();
+
+ /* turn buttons related to vpot mode on or off as required */
+
+ switch (_subview_mode) {
+ case MackieControlProtocol::None:
+ update_global_button (Button::Send, off);
+ update_global_button (Button::Plugin, off);
+ update_global_button (Button::Eq, off);
+ update_global_button (Button::Dyn, off);
+ update_global_button (Button::Track, off);
+ update_global_button (Button::Pan, on);
+ break;
+ case MackieControlProtocol::EQ:
+ update_global_button (Button::Send, off);
+ update_global_button (Button::Plugin, off);
+ update_global_button (Button::Eq, on);
+ update_global_button (Button::Dyn, off);
+ update_global_button (Button::Track, off);
+ update_global_button (Button::Pan, off);
+ break;
+ case MackieControlProtocol::Dynamics:
+ update_global_button (Button::Send, off);
+ update_global_button (Button::Plugin, off);
+ update_global_button (Button::Eq, off);
+ update_global_button (Button::Dyn, on);
+ update_global_button (Button::Track, off);
+ update_global_button (Button::Pan, off);
+ break;
+ case MackieControlProtocol::Sends:
+ update_global_button (Button::Send, on);
+ update_global_button (Button::Plugin, off);
+ update_global_button (Button::Eq, off);
+ update_global_button (Button::Dyn, off);
+ update_global_button (Button::Track, off);
+ update_global_button (Button::Pan, off);
+ break;
+ case MackieControlProtocol::TrackView:
+ update_global_button (Button::Send, off);
+ update_global_button (Button::Plugin, off);
+ update_global_button (Button::Eq, off);
+ update_global_button (Button::Dyn, off);
+ update_global_button (Button::Track, on);
+ update_global_button (Button::Pan, off);
+ break;
+ }
+
+ return 0;
+}
+