add an empty ProcessorEntry before the fader if there are no pre-fader processors...
[ardour.git] / gtk2_ardour / processor_box.cc
index 2cdf1030341d91f1c3dd49c54410ac34870ea90b..5aaf48a7193c94bf356a810357f236e45ffbea9c 100644 (file)
@@ -102,24 +102,31 @@ ProcessorEntry::ProcessorEntry (boost::shared_ptr<Processor> p, Width w)
        , _width (w)
        , _visual_state (Gtk::STATE_NORMAL)
 {
-       _vbox.pack_start (_button, true, true);
        _vbox.show ();
        
-       if (_processor->active()) {
-               _button.set_active_state (Gtkmm2ext::Active);
-       }
        _button.set_diameter (3);
        _button.set_distinct_led_click (true);
        _button.set_led_left (true);
        _button.signal_led_clicked.connect (sigc::mem_fun (*this, &ProcessorEntry::led_clicked));
        _button.set_text (name (_width));
-       _button.show ();
 
-       _processor->ActiveChanged.connect (active_connection, invalidator (*this), boost::bind (&ProcessorEntry::processor_active_changed, this), gui_context());
-       _processor->PropertyChanged.connect (name_connection, invalidator (*this), ui_bind (&ProcessorEntry::processor_property_changed, this, _1), gui_context());
+       if (_processor) {
+               _vbox.pack_start (_button, true, true);
 
-       setup_tooltip ();
-       setup_visuals ();
+               if (_processor->active()) {
+                       _button.set_active_state (Gtkmm2ext::Active);
+               }
+               
+               _button.show ();
+               
+               _processor->ActiveChanged.connect (active_connection, invalidator (*this), boost::bind (&ProcessorEntry::processor_active_changed, this), gui_context());
+               _processor->PropertyChanged.connect (name_connection, invalidator (*this), ui_bind (&ProcessorEntry::processor_property_changed, this, _1), gui_context());
+
+               setup_tooltip ();
+               setup_visuals ();
+       } else {
+               _vbox.set_size_request (-1, _button.size_request().height);
+       }
 }
 
 EventBox&
@@ -191,20 +198,24 @@ ProcessorEntry::set_enum_width (Width w)
 void
 ProcessorEntry::led_clicked()
 {
-       if (_button.active_state() == Gtkmm2ext::Active) {
-               _processor->deactivate ();
-       } else {
-               _processor->activate ();
+       if (_processor) {
+               if (_button.active_state() == Gtkmm2ext::Active) {
+                       _processor->deactivate ();
+               } else {
+                       _processor->activate ();
+               }
        }
 }
 
 void
 ProcessorEntry::processor_active_changed ()
 {
-       if (_processor->active()) {
-               _button.set_active_state (Gtkmm2ext::Active);
-       } else {
-               _button.unset_active_state ();
+       if (_processor) {
+               if (_processor->active()) {
+                       _button.set_active_state (Gtkmm2ext::Active);
+               } else {
+                       _button.unset_active_state ();
+               }
        }
 }
 
@@ -229,6 +240,10 @@ ProcessorEntry::name (Width w) const
        boost::shared_ptr<Send> send;
        string name_display;
 
+       if (!_processor) {
+               return string();
+       }
+
        if ((send = boost::dynamic_pointer_cast<Send> (_processor)) != 0 &&
            !boost::dynamic_pointer_cast<InternalSend>(_processor)) {
 
@@ -265,6 +280,11 @@ ProcessorEntry::name (Width w) const
        return name_display;
 }
 
+BlankProcessorEntry::BlankProcessorEntry (Width w)
+       : ProcessorEntry (boost::shared_ptr<Processor>(), w)
+{
+}
+
 SendProcessorEntry::SendProcessorEntry (boost::shared_ptr<Send> s, Width w)
        : ProcessorEntry (s, w)
        , _send (s)
@@ -460,19 +480,19 @@ PluginInsertProcessorEntry::SplittingIcon::on_expose_event (GdkEventExpose* ev)
 }
 
 ProcessorBox::ProcessorBox (ARDOUR::Session* sess, boost::function<PluginSelector*()> get_plugin_selector,
-                           RouteRedirectSelection& rsel, MixerStrip* parent, bool owner_is_mixer)
+                           RouteProcessorSelection& rsel, MixerStrip* parent, bool owner_is_mixer)
        : _parent_strip (parent)
        , _owner_is_mixer (owner_is_mixer)
        , ab_direction (true)
        , _get_plugin_selector (get_plugin_selector)
        , _placement (-1)
+       , _visible_prefader_processors (0)
        , _rr_selection(rsel)
 {
        set_session (sess);
 
        _width = Wide;
        processor_menu = 0;
-       send_action_menu = 0;
        no_processor_redisplay = false;
 
        processor_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
@@ -488,15 +508,11 @@ ProcessorBox::ProcessorBox (ARDOUR::Session* sess, boost::function<PluginSelecto
        processor_display.signal_enter_notify_event().connect (sigc::mem_fun(*this, &ProcessorBox::enter_notify), false);
        processor_display.signal_leave_notify_event().connect (sigc::mem_fun(*this, &ProcessorBox::leave_notify), false);
 
-       processor_display.signal_key_press_event().connect (sigc::mem_fun(*this, &ProcessorBox::processor_key_press_event));
-       processor_display.signal_key_release_event().connect (sigc::mem_fun(*this, &ProcessorBox::processor_key_release_event));
-
        processor_display.ButtonPress.connect (sigc::mem_fun (*this, &ProcessorBox::processor_button_press_event));
        processor_display.ButtonRelease.connect (sigc::mem_fun (*this, &ProcessorBox::processor_button_release_event));
 
        processor_display.Reordered.connect (sigc::mem_fun (*this, &ProcessorBox::reordered));
        processor_display.DropFromAnotherBox.connect (sigc::mem_fun (*this, &ProcessorBox::object_drop));
-       processor_display.SelectionChanged.connect (sigc::mem_fun (*this, &ProcessorBox::selection_changed));
 
        processor_scroller.show ();
        processor_display.show ();
@@ -506,10 +522,21 @@ ProcessorBox::ProcessorBox (ARDOUR::Session* sess, boost::function<PluginSelecto
                        _mixer_strip_connections, invalidator (*this), ui_bind (&ProcessorBox::mixer_strip_delivery_changed, this, _1), gui_context ()
                        );
        }
+
+       ARDOUR_UI::instance()->set_tip (processor_display, _("Right-click to add/remove/edit\nplugins,inserts,sends and more"));
 }
 
 ProcessorBox::~ProcessorBox ()
 {
+       /* it may appear as if we should delete processor_menu but that is a
+        * pointer to a widget owned by the UI Manager, and has potentially
+        * be returned to many other ProcessorBoxes. GTK doesn't really make
+        * clear the ownership of this widget, which is a menu and thus is
+        * never packed into any container other than an implict GtkWindow.
+        *
+        * For now, until or if we ever get clarification over the ownership
+        * story just let it continue to exist. At worst, its a small memory leak.
+        */
 }
 
 void
@@ -577,7 +604,6 @@ ProcessorBox::object_drop(DnDVBox<ProcessorEntry>* source, ProcessorEntry* posit
        if ((context->get_suggested_action() == Gdk::ACTION_MOVE) && source) {
                ProcessorBox* other = reinterpret_cast<ProcessorBox*> (source->get_data ("processorbox"));
                if (other) {
-                       cerr << "source was another processor box, delete the selected items\n";
                        other->delete_dragged_processors (procs);
                }
        }
@@ -606,19 +632,6 @@ ProcessorBox::set_width (Width w)
        redisplay_processors ();
 }
 
-void
-ProcessorBox::build_send_action_menu ()
-{
-       using namespace Menu_Helpers;
-
-       send_action_menu = new Menu;
-       send_action_menu->set_name ("ArdourContextMenu");
-       MenuList& items = send_action_menu->items();
-
-       items.push_back (MenuElem (_("New send"), sigc::mem_fun(*this, &ProcessorBox::new_send)));
-       items.push_back (MenuElem (_("Show send controls"), sigc::mem_fun(*this, &ProcessorBox::show_send_controls)));
-}
-
 Gtk::Menu*
 ProcessorBox::build_possible_aux_menu ()
 {
@@ -659,12 +672,16 @@ ProcessorBox::show_processor_menu (int arg)
                processor_menu->signal_unmap().connect (sigc::mem_fun (*this, &ProcessorBox::processor_menu_unmapped));
        }
 
+       /* Sort out the plugin submenu */
+
        Gtk::MenuItem* plugin_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/ProcessorMenu/newplugin"));
 
        if (plugin_menu_item) {
                plugin_menu_item->set_submenu (*_get_plugin_selector()->plugin_menu());
        }
 
+       /* And the aux submenu */
+
        Gtk::MenuItem* aux_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/ProcessorMenu/newaux"));
 
        if (aux_menu_item) {
@@ -679,9 +696,31 @@ ProcessorBox::show_processor_menu (int arg)
                }
        }
 
+       /* Sensitise actions as approprioate */
+
         cut_action->set_sensitive (can_cut());
        paste_action->set_sensitive (!_rr_selection.processors.empty());
 
+       const bool sensitive = !processor_display.selection().empty();
+       ActionManager::set_sensitive (ActionManager::plugin_selection_sensitive_actions, sensitive);
+       edit_action->set_sensitive (one_processor_can_be_edited ());
+
+       boost::shared_ptr<Processor> single_selection;
+       if (processor_display.selection().size() == 1) {
+               single_selection = processor_display.selection().front()->processor ();
+       }
+
+       boost::shared_ptr<PluginInsert> pi;
+       if (single_selection) {
+               pi = boost::dynamic_pointer_cast<PluginInsert> (single_selection);
+       }
+
+       /* enable gui for plugin inserts with editors */
+       controls_action->set_sensitive(pi && pi->plugin()->has_editor());
+
+       /* disallow rename for multiple selections, for plugin inserts and for the fader */
+       rename_action->set_sensitive (single_selection && !pi && !boost::dynamic_pointer_cast<Amp> (single_selection));
+
        processor_menu->popup (1, arg);
 
        /* Add a placeholder gap to the processor list to indicate where a processor would be
@@ -690,56 +729,30 @@ ProcessorBox::show_processor_menu (int arg)
        int x, y;
        processor_display.get_pointer (x, y);
        _placement = processor_display.add_placeholder (y);
+
+       if (_visible_prefader_processors == 0) {
+               if (_placement == 1) {
+                       _placement = 0;
+               }
+       }
 }
 
 bool
 ProcessorBox::enter_notify (GdkEventCrossing*)
 {
        _current_processor_box = this;
-       Keyboard::magic_widget_grab_focus ();
-       processor_display.grab_focus ();
-
        return false;
 }
 
 bool
 ProcessorBox::leave_notify (GdkEventCrossing* ev)
 {
-       switch (ev->detail) {
-       case GDK_NOTIFY_INFERIOR:
-               break;
-       default:
-               Keyboard::magic_widget_drop_focus ();
-       }
-
        return false;
 }
 
-bool
-ProcessorBox::processor_key_press_event (GdkEventKey *ev)
-{
-       switch (ev->keyval) {
-       case GDK_a:
-       case GDK_c:
-       case GDK_x:
-       case GDK_v:
-       case GDK_Up:
-       case GDK_Down:
-       case GDK_Delete:
-       case GDK_BackSpace:
-       case GDK_Return:
-       case GDK_slash:
-               /* do real stuff on key release */
-               return true;
-       }
-       
-       return false;
-}
-
-bool
-ProcessorBox::processor_key_release_event (GdkEventKey *ev)
+void
+ProcessorBox::processor_operation (ProcessorOperation op) 
 {
-       bool ret = false;
        ProcSelection targets;
 
        get_selected_processors (targets);
@@ -751,62 +764,37 @@ ProcessorBox::processor_key_release_event (GdkEventKey *ev)
 
                pair<ProcessorEntry *, double> const pointer = processor_display.get_child_at_position (y);
 
-               if (pointer.first) {
+               if (pointer.first && pointer.first->processor()) {
                        targets.push_back (pointer.first->processor ());
                }
        }
 
-
-       switch (ev->keyval) {
-       case GDK_a:
-               if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
-                       processor_display.select_all ();
-                       ret = true;
-               }
+       switch (op) {
+       case ProcessorsSelectAll:
+               processor_display.select_all ();
                break;
 
-       case GDK_c:
-               if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
-                       copy_processors (targets);
-                       ret = true;
-               }
+       case ProcessorsCopy:
+               copy_processors (targets);
                break;
 
-       case GDK_x:
-               if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
-                       cut_processors (targets);
-                       ret = true;
-               }
+       case ProcessorsCut:
+               cut_processors (targets);
                break;
 
-       case GDK_v:
-               if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
-                       if (targets.empty()) {
-                               paste_processors ();
-                       } else {
-                               paste_processors (targets.front());
-                       }
-                       ret = true;
+       case ProcessorsPaste:
+               if (targets.empty()) {
+                       paste_processors ();
+               } else {
+                       paste_processors (targets.front());
                }
                break;
 
-       case GDK_Up:
-               processors_down ();
-               ret = true;
-               break;
-
-       case GDK_Down:
-               processors_up ();
-               ret = true;
-               break;
-
-       case GDK_Delete:
-       case GDK_BackSpace:
+       case ProcessorsDelete:
                delete_processors (targets);
-               ret = true;
                break;
 
-       case GDK_Return:
+       case ProcessorsToggleActive:
                for (ProcSelection::iterator i = targets.begin(); i != targets.end(); ++i) {
                        if ((*i)->active()) {
                                (*i)->deactivate ();
@@ -814,19 +802,15 @@ ProcessorBox::processor_key_release_event (GdkEventKey *ev)
                                (*i)->activate ();
                        }
                }
-               ret = true;
                break;
 
-       case GDK_slash:
+       case ProcessorsAB:
                ab_plugins ();
-               ret = true;
                break;
 
        default:
                break;
        }
-
-       return ret;
 }
 
 bool
@@ -906,29 +890,6 @@ ProcessorBox::build_processor_menu ()
        return processor_menu;
 }
 
-void
-ProcessorBox::selection_changed ()
-{
-       const bool sensitive = !processor_display.selection().empty();
-       ActionManager::set_sensitive(ActionManager::plugin_selection_sensitive_actions,
-                                    sensitive);
-       edit_action->set_sensitive(one_processor_can_be_edited());
-
-       const bool single_selection = (processor_display.selection().size() == 1);
-
-       boost::shared_ptr<PluginInsert> pi;
-       if (single_selection) {
-               pi = boost::dynamic_pointer_cast<PluginInsert>(
-                       processor_display.selection().front()->processor());
-       }
-
-       /* enable gui for plugin inserts with editors */
-       controls_action->set_sensitive(pi && pi->plugin()->has_editor());
-
-       /* disallow rename for multiple selections and for plugin inserts */
-       rename_action->set_sensitive(single_selection && pi);
-}
-
 void
 ProcessorBox::select_all_processors ()
 {
@@ -1155,7 +1116,8 @@ ProcessorBox::route_processors_changed (RouteProcessorChange c)
 void
 ProcessorBox::redisplay_processors ()
 {
-       ENSURE_GUI_THREAD (*this, &ProcessorBox::redisplay_processors)
+       ENSURE_GUI_THREAD (*this, &ProcessorBox::redisplay_processors);
+       bool     fader_seen;
 
        if (no_processor_redisplay) {
                return;
@@ -1163,6 +1125,18 @@ ProcessorBox::redisplay_processors ()
 
        processor_display.clear ();
 
+       _visible_prefader_processors = 0;
+       fader_seen = false;
+
+       _route->foreach_processor (sigc::bind (sigc::mem_fun (*this, &ProcessorBox::help_count_visible_prefader_processors), 
+                                              &_visible_prefader_processors, &fader_seen));
+
+       if (_visible_prefader_processors == 0) { // fader only
+               BlankProcessorEntry* bpe = new BlankProcessorEntry (_width);
+               bpe->set_pixel_width (get_allocation().get_width());
+               processor_display.add_child (bpe);
+       }
+
        _route->foreach_processor (sigc::mem_fun (*this, &ProcessorBox::add_processor_to_display));
 
        for (list<ProcessorWindowProxy*>::iterator i = _processor_window_proxies.begin(); i != _processor_window_proxies.end(); ++i) {
@@ -1250,6 +1224,23 @@ ProcessorBox::maybe_add_processor_to_ui_list (boost::weak_ptr<Processor> w)
        ARDOUR_UI::instance()->add_window_proxy (wp);
 }
 
+void
+ProcessorBox::help_count_visible_prefader_processors (boost::weak_ptr<Processor> p, uint32_t* cnt, bool* amp_seen)
+{
+       boost::shared_ptr<Processor> processor (p.lock ());
+
+       if (processor && processor->display_to_user()) {
+
+               if (boost::dynamic_pointer_cast<Amp>(processor)) {
+                       *amp_seen = true;
+               } else {
+                       if (!*amp_seen) {
+                               (*cnt)++;
+                       }
+               }
+       }
+}
+
 void
 ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
 {
@@ -1259,6 +1250,7 @@ ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
                return;
        }
 
+
        boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
        boost::shared_ptr<PluginInsert> plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor);
        ProcessorEntry* e = 0;
@@ -1402,14 +1394,6 @@ ProcessorBox::can_cut () const
         return false;
 }
 
-void
-ProcessorBox::cut_processors ()
-{
-       ProcSelection to_be_removed;
-
-       get_selected_processors (to_be_removed);
-}
-
 void
 ProcessorBox::cut_processors (const ProcSelection& to_be_removed)
 {
@@ -1451,14 +1435,6 @@ ProcessorBox::cut_processors (const ProcSelection& to_be_removed)
        redisplay_processors ();
 }
 
-void
-ProcessorBox::copy_processors ()
-{
-       ProcSelection to_be_copied;
-       get_selected_processors (to_be_copied);
-       copy_processors (to_be_copied);
-}
-
 void
 ProcessorBox::copy_processors (const ProcSelection& to_be_copied)
 {
@@ -1493,14 +1469,6 @@ ProcessorBox::processors_down ()
 }
        
 
-void
-ProcessorBox::delete_processors ()
-{
-       ProcSelection to_be_deleted;
-       get_selected_processors (to_be_deleted);
-       delete_processors (to_be_deleted);
-}
-
 void
 ProcessorBox::delete_processors (const ProcSelection& targets)
 {
@@ -1752,10 +1720,9 @@ ProcessorBox::for_selected_processors (void (ProcessorBox::*method)(boost::share
 }
 
 void
-ProcessorBox::all_processors_active (bool state)
+ProcessorBox::all_visible_processors_active (bool state)
 {
-       _route->all_processors_active (PreFader, state);
-       _route->all_processors_active (PostFader, state);
+       _route->all_visible_processors_active (state);
 }
 
 void
@@ -1871,8 +1838,10 @@ ProcessorBox::toggle_edit_processor (boost::shared_ptr<Processor> processor)
                        return;
                }
 
-               SendUIWindow* w = new SendUIWindow (send, _session);
-               w->show ();
+               if (boost::dynamic_pointer_cast<InternalSend> (processor) == 0) {
+                       SendUIWindow* w = new SendUIWindow (send, _session);
+                       w->show ();
+               }
 
        } else if ((retrn = boost::dynamic_pointer_cast<Return> (processor)) != 0) {
 
@@ -1994,7 +1963,7 @@ ProcessorBox::register_actions ()
        act = ActionManager::register_action (popup_act_grp, X_("newinsert"), _("New Insert"),
                        sigc::ptr_fun (ProcessorBox::rb_choose_insert));
        ActionManager::jack_sensitive_actions.push_back (act);
-       act = ActionManager::register_action (popup_act_grp, X_("newsend"), _("New Send ..."),
+       act = ActionManager::register_action (popup_act_grp, X_("newsend"), _("New External Send ..."),
                        sigc::ptr_fun (ProcessorBox::rb_choose_send));
        ActionManager::jack_sensitive_actions.push_back (act);
 
@@ -2030,9 +1999,9 @@ ProcessorBox::register_actions ()
 
        /* activation etc. */
 
-       ActionManager::register_action (popup_act_grp, X_("activate_all"), _("Activate all"),
+       ActionManager::register_action (popup_act_grp, X_("activate_all"), _("Activate All"),
                        sigc::ptr_fun (ProcessorBox::rb_activate_all));
-       ActionManager::register_action (popup_act_grp, X_("deactivate_all"), _("Deactivate all"),
+       ActionManager::register_action (popup_act_grp, X_("deactivate_all"), _("Deactivate All"),
                        sigc::ptr_fun (ProcessorBox::rb_deactivate_all));
        ActionManager::register_action (popup_act_grp, X_("ab_plugins"), _("A/B Plugins"),
                        sigc::ptr_fun (ProcessorBox::rb_ab_plugins));
@@ -2136,7 +2105,7 @@ ProcessorBox::rb_cut ()
                return;
        }
 
-       _current_processor_box->cut_processors ();
+       _current_processor_box->processor_operation (ProcessorsCut);
 }
 
 void
@@ -2146,7 +2115,7 @@ ProcessorBox::rb_delete ()
                return;
        }
 
-       _current_processor_box->delete_processors ();
+       _current_processor_box->processor_operation (ProcessorsDelete);
 }
 
 void
@@ -2155,7 +2124,7 @@ ProcessorBox::rb_copy ()
        if (_current_processor_box == 0) {
                return;
        }
-       _current_processor_box->copy_processors ();
+       _current_processor_box->processor_operation (ProcessorsCopy);
 }
 
 void
@@ -2165,7 +2134,7 @@ ProcessorBox::rb_paste ()
                return;
        }
 
-       _current_processor_box->paste_processors ();
+       _current_processor_box->processor_operation (ProcessorsPaste);
 }
 
 void
@@ -2184,7 +2153,7 @@ ProcessorBox::rb_select_all ()
                return;
        }
 
-       _current_processor_box->select_all_processors ();
+       _current_processor_box->processor_operation (ProcessorsSelectAll);
 }
 
 void
@@ -2204,7 +2173,7 @@ ProcessorBox::rb_activate_all ()
                return;
        }
 
-       _current_processor_box->all_processors_active (true);
+       _current_processor_box->all_visible_processors_active (true);
 }
 
 void
@@ -2213,7 +2182,7 @@ ProcessorBox::rb_deactivate_all ()
        if (_current_processor_box == 0) {
                return;
        }
-       _current_processor_box->all_processors_active (false);
+       _current_processor_box->all_visible_processors_active (false);
 }
 
 void