Add OSX configuration script.
[ardour.git] / libs / surfaces / faderport8 / actions.cc
index 65a647bb0bc8dee1cde0372e3e6e562352e16c96..a710540b71dcbe3f96635dc7e7012acd39174222 100644 (file)
@@ -96,13 +96,13 @@ FaderPort8::setup_actions ()
 
 
        BindMethod (BtnBypass, button_bypass);
-       BindAction (BtnBypassAll, "Mixer", "ab-plugins"); // XXX
+       BindAction (BtnBypassAll, "Mixer", "ab-plugins");
 
-       BindAction (BtnMacro, "Mixer", "show-editor");
-       BindAction (BtnLink, "Window", "show-mixer");
+       BindAction (BtnMacro, "Common", "toggle-editor-and-mixer");
+       BindMethod (BtnOpen, button_open);
 
-       BindAction (BtnOpen, "Common", "addExistingAudioFiles");
-       BindAction (BtnLock, "Editor", "lock");
+       BindMethod (BtnLink, button_link);
+       BindMethod (BtnLock, button_lock);
 
        // user-specific
        for (FP8Controls::UserButtonMap::const_iterator i = _ctrls.user_buttons ().begin ();
@@ -168,6 +168,48 @@ FaderPort8::button_bypass ()
        }
 }
 
+void
+FaderPort8::button_open ()
+{
+       boost::shared_ptr<PluginInsert> pi = _plugin_insert.lock();
+       if (pi) {
+               pi->ToggleUI (); /* EMIT SIGNAL */
+       } else {
+               AccessAction ("Common", "addExistingAudioFiles");
+       }
+}
+void
+FaderPort8::button_lock ()
+{
+       if (!_link_enabled) {
+               AccessAction ("Editor", "lock");
+               return;
+       }
+       if (_link_locked) {
+               unlock_link ();
+       } else if (!_link_control.expired ()) {
+               lock_link ();
+       }
+}
+
+void
+FaderPort8::button_link ()
+{
+       switch (_ctrls.fader_mode()) {
+               case ModeTrack:
+               case ModePan:
+                       if (_link_enabled) {
+                               stop_link ();
+                       } else {
+                               start_link ();
+                       }
+                       break;
+               default:
+                       //AccessAction ("Window", "show-mixer");
+                       break;
+       }
+}
+
 void
 FaderPort8::button_automation (ARDOUR::AutoState as)
 {
@@ -197,6 +239,8 @@ FaderPort8::button_automation (ARDOUR::AutoState as)
                        break;
        }
 
+       // TODO link/lock control automation?
+
        // apply to all selected tracks
        StripableList all;
        session->get_stripables (all);
@@ -263,6 +307,9 @@ void
 FaderPort8::button_solo_clear ()
 {
        bool soloing = session->soloing() || session->listening();
+#ifdef MIXBUS
+       soloing |= session->mixbus_soloed();
+#endif
        if (soloing) {
                StripableList all;
                session->get_stripables (all);
@@ -270,9 +317,9 @@ FaderPort8::button_solo_clear ()
                        if ((*i)->is_master() || (*i)->is_auditioner() || (*i)->is_monitor()) {
                                continue;
                        }
-                       boost::shared_ptr<AutomationControl> ac = (*i)->solo_control();
-                       if (ac && ac->get_value () > 0) {
-                               _solo_state.push_back (boost::weak_ptr<AutomationControl>(ac));
+                       boost::shared_ptr<SoloControl> sc = (*i)->solo_control();
+                       if (sc && sc->self_soloed ()) {
+                               _solo_state.push_back (boost::weak_ptr<AutomationControl>(sc));
                        }
                }
                AccessAction ("Main", "cancel-solo");
@@ -284,9 +331,7 @@ FaderPort8::button_solo_clear ()
                        if (!ac) {
                                continue;
                        }
-                       if (ac->automation_state() == Touch && !ac->touching ()) {
-                               ac->start_touch (ac->session().transport_frame());
-                       }
+                       ac->start_touch (ac->session().transport_frame());
                        cl->push_back (ac);
                }
                if (!cl->empty()) {
@@ -311,9 +356,7 @@ FaderPort8::button_mute_clear ()
                                continue;
                        }
                        cl->push_back (ac);
-                       if (ac->automation_state() == Touch && !ac->touching ()) {
-                               ac->start_touch (ac->session().transport_frame());
-                       }
+                       ac->start_touch (ac->session().transport_frame());
                }
                if (!cl->empty()) {
                        session->set_controls (cl, 1.0, PBD::Controllable::NoGroup);
@@ -337,6 +380,67 @@ FaderPort8::button_action (const std::string& group, const std::string& item)
        AccessAction (group, item);
 }
 
+/* ****************************************************************************
+ * Control Interaction (encoder)
+ */
+
+void
+FaderPort8::handle_encoder_pan (int steps)
+{
+       boost::shared_ptr<Stripable> s = first_selected_stripable();
+       if (s) {
+               boost::shared_ptr<AutomationControl> ac;
+               if (shift_mod () || _ctrls.fader_mode() == ModePan) {
+                       ac = s->pan_width_control ();
+               } else {
+                       ac = s->pan_azimuth_control ();
+               }
+               if (ac) {
+                       ac->start_touch (ac->session().transport_frame());
+                       if (steps == 0) {
+                               ac->set_value (ac->normal(), PBD::Controllable::UseGroup);
+                       } else {
+                               double v = ac->internal_to_interface (ac->get_value());
+                               v = std::max (0.0, std::min (1.0, v + steps * .01));
+                               ac->set_value (ac->interface_to_internal(v), PBD::Controllable::UseGroup);
+                       }
+               }
+       }
+}
+
+void
+FaderPort8::handle_encoder_link (int steps)
+{
+       if (_link_control.expired ()) {
+               return;
+       }
+       boost::shared_ptr<AutomationControl> ac = boost::dynamic_pointer_cast<AutomationControl> (_link_control.lock ());
+       if (!ac) {
+               return;
+       }
+
+       double v = ac->internal_to_interface (ac->get_value());
+       ac->start_touch (ac->session().transport_frame());
+
+       if (steps == 0) {
+               ac->set_value (ac->normal(), PBD::Controllable::UseGroup);
+               return;
+       }
+
+       if (ac->desc().toggled) {
+               v = v > 0 ? 0. : 1.;
+       } else if (ac->desc().integer_step) {
+               v += steps / (1.f + ac->desc().upper - ac->desc().lower);
+       } else if (ac->desc().enumeration) {
+               ac->set_value (ac->desc().step_enum (ac->get_value(), steps < 0), PBD::Controllable::UseGroup);
+               return;
+       } else {
+               v = std::max (0.0, std::min (1.0, v + steps * .01));
+       }
+       ac->set_value (ac->interface_to_internal(v), PBD::Controllable::UseGroup);
+}
+
+
 /* ****************************************************************************
  * Mode specific and internal callbacks
  */
@@ -423,9 +527,7 @@ FaderPort8::button_encoder ()
                                        ac = session->master_out()->gain_control ();
                                }
                                if (ac) {
-                                       if (ac->automation_state() == Touch && !ac->touching ()) {
-                                               ac->start_touch (ac->session().transport_frame());
-                                       }
+                                       ac->start_touch (ac->session().transport_frame());
                                        ac->set_value (ac->normal(), PBD::Controllable::NoGroup);
                                }
                        }
@@ -505,9 +607,7 @@ FaderPort8::encoder_navigate (bool neg, int steps)
                                if (ac) {
                                        double v = ac->internal_to_interface (ac->get_value());
                                        v = std::max (0.0, std::min (1.0, v + steps * (neg ? -.01 : .01)));
-                                       if (ac->automation_state() == Touch && !ac->touching ()) {
-                                               ac->start_touch (ac->session().transport_frame());
-                                       }
+                                       ac->start_touch (ac->session().transport_frame());
                                        ac->set_value (ac->interface_to_internal(v), PBD::Controllable::NoGroup);
                                }
                        }
@@ -529,25 +629,14 @@ FaderPort8::button_parameter ()
        switch (_ctrls.fader_mode()) {
                case ModeTrack:
                case ModePan:
-                       {
-                               boost::shared_ptr<Stripable> s = first_selected_stripable();
-                               if (s) {
-                                       boost::shared_ptr<AutomationControl> ac;
-                                       if (shift_mod () || _ctrls.fader_mode() == ModePan) {
-                                               ac = s->pan_width_control ();
-                                       } else {
-                                               ac = s->pan_azimuth_control ();
-                                       }
-                                       if (ac) {
-                                               if (ac->automation_state() == Touch && !ac->touching ()) {
-                                                       ac->start_touch (ac->session().transport_frame());
-                                               }
-                                               ac->set_value (ac->normal(), PBD::Controllable::UseGroup);
-                                       }
-                               }
+                       if (_link_enabled || _link_locked) {
+                               handle_encoder_link (0);
+                       } else {
+                               handle_encoder_pan (0);
                        }
                        break;
                case ModePlugins:
+                       toggle_preset_param_mode ();
                        break;
                case ModeSend:
                        break;
@@ -561,30 +650,18 @@ FaderPort8::encoder_parameter (bool neg, int steps)
        switch (_ctrls.fader_mode()) {
                case ModeTrack:
                case ModePan:
-                       {
-                               boost::shared_ptr<Stripable> s = first_selected_stripable();
-                               if (s) {
-                                       boost::shared_ptr<AutomationControl> ac;
-                                       if (shift_mod () || _ctrls.fader_mode() == ModePan) {
-                                               ac = s->pan_width_control ();
-                                       } else {
-                                               ac = s->pan_azimuth_control ();
-                                       }
-                                       if (ac) {
-                                               double v = ac->internal_to_interface (ac->get_value());
-                                               v = std::max (0.0, std::min (1.0, v + steps * (neg ? -.01 : .01)));
-                                               if (ac->automation_state() == Touch && !ac->touching ()) {
-                                                       ac->start_touch (ac->session().transport_frame());
-                                               }
-                                               ac->set_value (ac->interface_to_internal(v), PBD::Controllable::UseGroup);
-                                       }
+                       if (steps != 0) {
+                               if (_link_enabled || _link_locked) {
+                                       handle_encoder_link (neg ? -steps : steps);
+                               } else {
+                                       handle_encoder_pan (neg ? -steps : steps);
                                }
                        }
                        break;
                case ModePlugins:
                case ModeSend:
                        while (steps > 0) {
-                               bank_param (neg, false);
+                               bank_param (neg, shift_mod());
                                --steps;
                        }
                        break;