+void
+PluginInsertProcessorEntry::plugin_insert_splitting_changed ()
+{
+ if (_plugin_insert->splitting ()) {
+ _splitting_icon.show ();
+ } else {
+ _splitting_icon.hide ();
+ }
+}
+
+void
+PluginInsertProcessorEntry::hide_things ()
+{
+ ProcessorEntry::hide_things ();
+ plugin_insert_splitting_changed ();
+}
+
+void
+PluginInsertProcessorEntry::setup_visuals ()
+{
+ switch (_position) {
+ case PreFader:
+ _splitting_icon.set_name ("ProcessorPreFader");
+ break;
+
+ case Fader:
+ _splitting_icon.set_name ("ProcessorFader");
+ break;
+
+ case PostFader:
+ _splitting_icon.set_name ("ProcessorPostFader");
+ break;
+ }
+
+ ProcessorEntry::setup_visuals ();
+}
+
+bool
+PluginInsertProcessorEntry::SplittingIcon::on_expose_event (GdkEventExpose* ev)
+{
+ cairo_t* cr = gdk_cairo_create (get_window()->gobj());
+
+ cairo_set_line_width (cr, 1);
+
+ double const width = ev->area.width;
+ double const height = ev->area.height;
+
+ Gdk::Color const bg = get_style()->get_bg (STATE_NORMAL);
+ cairo_set_source_rgb (cr, bg.get_red_p (), bg.get_green_p (), bg.get_blue_p ());
+
+ cairo_rectangle (cr, 0, 0, width, height);
+ cairo_fill (cr);
+
+ Gdk::Color const fg = get_style()->get_fg (STATE_NORMAL);
+ cairo_set_source_rgb (cr, fg.get_red_p (), fg.get_green_p (), fg.get_blue_p ());
+
+ cairo_move_to (cr, width * 0.3, height);
+ cairo_line_to (cr, width * 0.3, height * 0.5);
+ cairo_line_to (cr, width * 0.7, height * 0.5);
+ cairo_line_to (cr, width * 0.7, height);
+ cairo_move_to (cr, width * 0.5, height * 0.5);
+ cairo_line_to (cr, width * 0.5, 0);
+ cairo_stroke (cr);
+
+ return true;
+}
+
+ProcessorBox::ProcessorBox (ARDOUR::Session* sess, boost::function<PluginSelector*()> get_plugin_selector,
+ 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;
+ no_processor_redisplay = false;
+
+ processor_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
+ processor_scroller.add (processor_display);
+ pack_start (processor_scroller, true, true);
+
+ processor_display.set_flags (CAN_FOCUS);
+ processor_display.set_name ("ProcessorList");
+ processor_display.set_size_request (48, -1);
+ processor_display.set_data ("processorbox", this);
+ processor_display.set_spacing (2);
+
+ 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.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_scroller.show ();
+ processor_display.show ();
+
+ if (parent) {
+ parent->DeliveryChanged.connect (
+ _mixer_strip_connections, invalidator (*this), boost::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
+ProcessorBox::set_route (boost::shared_ptr<Route> r)
+{
+ if (_route == r) {
+ return;
+ }
+
+ _route_connections.drop_connections();
+
+ /* new route: any existing block on processor redisplay must be meaningless */
+ no_processor_redisplay = false;
+ _route = r;
+
+ _route->processors_changed.connect (
+ _route_connections, invalidator (*this), boost::bind (&ProcessorBox::route_processors_changed, this, _1), gui_context()
+ );
+
+ _route->DropReferences.connect (
+ _route_connections, invalidator (*this), boost::bind (&ProcessorBox::route_going_away, this), gui_context()
+ );
+
+ _route->PropertyChanged.connect (
+ _route_connections, invalidator (*this), boost::bind (&ProcessorBox::route_property_changed, this, _1), gui_context()
+ );
+
+ redisplay_processors ();
+}
+
+void
+ProcessorBox::route_going_away ()
+{
+ /* don't keep updating display as processors are deleted */
+ no_processor_redisplay = true;
+ _route.reset ();
+}
+
+void
+ProcessorBox::object_drop(DnDVBox<ProcessorEntry>* source, ProcessorEntry* position, Glib::RefPtr<Gdk::DragContext> const & context)
+{
+ boost::shared_ptr<Processor> p;
+ if (position) {
+ p = position->processor ();
+ if (!p) {
+ /* dropped on the blank entry (which will be before the
+ fader), so use the first non-blank child as our
+ `dropped on' processor */
+ list<ProcessorEntry*> c = processor_display.children ();
+ list<ProcessorEntry*>::iterator i = c.begin ();
+ while (dynamic_cast<BlankProcessorEntry*> (*i)) {
+ assert (i != c.end ());
+ ++i;
+ }
+
+ assert (i != c.end ());
+ p = (*i)->processor ();
+ assert (p);
+ }
+ }
+
+ list<ProcessorEntry*> children = source->selection ();
+ list<boost::shared_ptr<Processor> > procs;
+ for (list<ProcessorEntry*>::const_iterator i = children.begin(); i != children.end(); ++i) {
+ if ((*i)->processor ()) {
+ procs.push_back ((*i)->processor ());
+ }
+ }
+
+ for (list<boost::shared_ptr<Processor> >::const_iterator i = procs.begin(); i != procs.end(); ++i) {
+ XMLNode& state = (*i)->get_state ();
+ XMLNodeList nlist;
+ nlist.push_back (&state);
+ paste_processor_state (nlist, p);
+ delete &state;
+ }
+
+ /* since the dndvbox doesn't take care of this properly, we have to delete the originals
+ ourselves.
+ */
+
+ if ((context->get_suggested_action() == Gdk::ACTION_MOVE) && source) {
+ ProcessorBox* other = reinterpret_cast<ProcessorBox*> (source->get_data ("processorbox"));
+ if (other) {
+ other->delete_dragged_processors (procs);
+ }
+ }
+}
+
+void
+ProcessorBox::set_width (Width w)
+{
+ if (_width == w) {
+ return;
+ }
+
+ _width = w;
+
+ list<ProcessorEntry*> children = processor_display.children ();
+ for (list<ProcessorEntry*>::iterator i = children.begin(); i != children.end(); ++i) {
+ (*i)->set_enum_width (w);
+ }
+
+ redisplay_processors ();
+}
+
+Gtk::Menu*
+ProcessorBox::build_possible_aux_menu ()
+{
+ boost::shared_ptr<RouteList> rl = _session->get_routes_with_internal_returns();
+
+ if (rl->empty()) {
+ /* No aux sends if there are no busses */
+ return 0;
+ }
+
+ using namespace Menu_Helpers;
+ Menu* menu = manage (new Menu);
+ MenuList& items = menu->items();
+
+ for (RouteList::iterator r = rl->begin(); r != rl->end(); ++r) {
+ if (!_route->internal_send_for (*r) && *r != _route) {
+ items.push_back (MenuElem ((*r)->name(), sigc::bind (sigc::ptr_fun (ProcessorBox::rb_choose_aux), boost::weak_ptr<Route>(*r))));
+ }
+ }
+
+ return menu;
+}
+
+void
+ProcessorBox::show_processor_menu (int arg)
+{
+ if (processor_menu == 0) {
+ processor_menu = build_processor_menu ();
+ 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) {
+ Menu* m = build_possible_aux_menu();
+ if (m && !m->items().empty()) {
+ aux_menu_item->set_submenu (*m);
+ aux_menu_item->set_sensitive (true);
+ } else {
+ /* stupid gtkmm: we need to pass a null reference here */
+ gtk_menu_item_set_submenu (aux_menu_item->gobj(), 0);
+ aux_menu_item->set_sensitive (false);
+ }
+ }
+
+ ProcessorEntry* single_selection = 0;
+ if (processor_display.selection().size() == 1) {
+ single_selection = processor_display.selection().front();
+ }
+
+ /* And the controls submenu */
+
+ Gtk::MenuItem* controls_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/ProcessorMenu/controls"));
+
+ if (controls_menu_item) {
+ if (single_selection) {
+ Menu* m = single_selection->build_controls_menu ();
+ if (m && !m->items().empty()) {
+ controls_menu_item->set_submenu (*m);
+ controls_menu_item->set_sensitive (true);
+ } else {
+ gtk_menu_item_set_submenu (controls_menu_item->gobj(), 0);
+ controls_menu_item->set_sensitive (false);
+ }
+ }
+ }
+
+ /* 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<PluginInsert> pi;
+ if (single_selection) {
+ pi = boost::dynamic_pointer_cast<PluginInsert> (single_selection->processor ());
+ }
+
+ /* allow editing with an Ardour-generated UI for plugin inserts with editors */
+ edit_generic_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 ()));
+
+ processor_menu->popup (1, arg);
+
+ /* Add a placeholder gap to the processor list to indicate where a processor would be
+ inserted were one chosen from the menu.
+ */
+ int x, y;
+ processor_display.get_pointer (x, y);
+ _placement = processor_display.add_placeholder (y);
+
+ if (_visible_prefader_processors == 0 && _placement > 0) {
+ --_placement;
+ }
+}
+
+bool
+ProcessorBox::enter_notify (GdkEventCrossing*)
+{
+ _current_processor_box = this;
+ return false;
+}
+
+bool
+ProcessorBox::leave_notify (GdkEventCrossing*)
+{
+ return false;
+}
+
+void
+ProcessorBox::processor_operation (ProcessorOperation op)
+{
+ ProcSelection targets;
+
+ get_selected_processors (targets);
+
+ if (targets.empty()) {
+
+ int x, y;
+ processor_display.get_pointer (x, y);
+
+ pair<ProcessorEntry *, double> const pointer = processor_display.get_child_at_position (y);
+
+ if (pointer.first && pointer.first->processor()) {
+ targets.push_back (pointer.first->processor ());
+ }
+ }
+
+ switch (op) {
+ case ProcessorsSelectAll:
+ processor_display.select_all ();
+ break;
+
+ case ProcessorsCopy:
+ copy_processors (targets);
+ break;
+
+ case ProcessorsCut:
+ cut_processors (targets);
+ break;
+
+ case ProcessorsPaste:
+ if (targets.empty()) {
+ paste_processors ();
+ } else {
+ paste_processors (targets.front());
+ }
+ break;
+
+ case ProcessorsDelete:
+ delete_processors (targets);
+ break;
+
+ case ProcessorsToggleActive:
+ for (ProcSelection::iterator i = targets.begin(); i != targets.end(); ++i) {
+ if ((*i)->active()) {
+ (*i)->deactivate ();
+ } else {
+ (*i)->activate ();
+ }
+ }
+ break;
+
+ case ProcessorsAB:
+ ab_plugins ();
+ break;
+
+ default:
+ break;
+ }
+}
+
+bool
+ProcessorBox::processor_button_press_event (GdkEventButton *ev, ProcessorEntry* child)
+{
+ boost::shared_ptr<Processor> processor;
+ if (child) {
+ processor = child->processor ();
+ }
+
+ int ret = false;
+ bool selected = processor_display.selected (child);
+
+ if (processor && (Keyboard::is_edit_event (ev) || (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS))) {
+
+ if (_session->engine().connected()) {
+ /* XXX giving an error message here is hard, because we may be in the midst of a button press */
+ if (Config->get_use_plugin_own_gui ()) {
+ toggle_edit_processor (processor);
+ } else {
+ toggle_edit_generic_processor (processor);
+ }
+ }
+ ret = true;
+
+ } else if (processor && ev->button == 1 && selected) {
+
+ // this is purely informational but necessary for route params UI
+ ProcessorSelected (processor); // emit
+
+ } else if (!processor && ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) {
+
+ choose_plugin ();
+ _get_plugin_selector()->show_manager ();
+ }
+
+ return ret;
+}
+
+bool
+ProcessorBox::processor_button_release_event (GdkEventButton *ev, ProcessorEntry* child)
+{
+ boost::shared_ptr<Processor> processor;
+ if (child) {
+ processor = child->processor ();
+ }
+
+ if (processor && Keyboard::is_delete_event (ev)) {
+
+ Glib::signal_idle().connect (sigc::bind (
+ sigc::mem_fun(*this, &ProcessorBox::idle_delete_processor),
+ boost::weak_ptr<Processor>(processor)));
+
+ } else if (Keyboard::is_context_menu_event (ev)) {
+
+ show_processor_menu (ev->time);
+
+ } else if (processor && Keyboard::is_button2_event (ev)
+#ifndef GTKOSX
+ && (Keyboard::no_modifier_keys_pressed (ev) && ((ev->state & Gdk::BUTTON2_MASK) == Gdk::BUTTON2_MASK))
+#endif
+ ) {
+
+ /* button2-click with no/appropriate modifiers */
+
+ if (processor->active()) {
+ processor->deactivate ();
+ } else {
+ processor->activate ();
+ }
+ }
+
+ return false;
+}
+
+Menu *
+ProcessorBox::build_processor_menu ()
+{
+ processor_menu = dynamic_cast<Gtk::Menu*>(ActionManager::get_widget("/ProcessorMenu") );
+ processor_menu->set_name ("ArdourContextMenu");
+ return processor_menu;
+}
+
+void
+ProcessorBox::select_all_processors ()
+{
+ processor_display.select_all ();
+}
+
+void
+ProcessorBox::deselect_all_processors ()
+{
+ processor_display.select_none ();
+}
+
+void
+ProcessorBox::choose_plugin ()
+{
+ _get_plugin_selector()->set_interested_object (*this);
+}
+
+/** @return true if an error occurred, otherwise false */
+bool
+ProcessorBox::use_plugins (const SelectedPlugins& plugins)
+{
+ for (SelectedPlugins::const_iterator p = plugins.begin(); p != plugins.end(); ++p) {
+
+ boost::shared_ptr<Processor> processor (new PluginInsert (*_session, *p));
+
+ Route::ProcessorStreams err_streams;
+
+ if (_route->add_processor_by_index (processor, _placement, &err_streams, Config->get_new_plugins_active ())) {
+ weird_plugin_dialog (**p, err_streams);
+ return true;
+ // XXX SHAREDPTR delete plugin here .. do we even need to care?
+ } else {
+
+ if (Profile->get_sae()) {
+ processor->activate ();
+ }
+ }
+ }
+
+ return false;
+}
+
+void
+ProcessorBox::weird_plugin_dialog (Plugin& p, Route::ProcessorStreams streams)
+{
+ ArdourDialog dialog (_("Plugin Incompatibility"));
+ Label label;
+
+ string text = string_compose(_("You attempted to add the plugin \"%1\" in slot %2.\n"),
+ p.name(), streams.index);
+
+ bool has_midi = streams.count.n_midi() > 0 || p.get_info()->n_inputs.n_midi() > 0;
+ bool has_audio = streams.count.n_audio() > 0 || p.get_info()->n_inputs.n_audio() > 0;
+
+ text += _("\nThis plugin has:\n");
+ if (has_midi) {
+ uint32_t const n = p.get_info()->n_inputs.n_midi ();
+ text += string_compose (ngettext ("\t%1 MIDI input\n", "\t%1 MIDI inputs\n", n), n);
+ }
+ if (has_audio) {
+ uint32_t const n = p.get_info()->n_inputs.n_audio ();
+ text += string_compose (ngettext ("\t%1 audio input\n", "\t%1 audio inputs\n", n), n);
+ }
+
+ text += _("\nbut at the insertion point, there are:\n");
+ if (has_midi) {
+ uint32_t const n = streams.count.n_midi ();
+ text += string_compose (ngettext ("\t%1 MIDI channel\n", "\t%1 MIDI channels\n", n), n);
+ }
+ if (has_audio) {
+ uint32_t const n = streams.count.n_audio ();
+ text += string_compose (ngettext ("\t%1 audio channel\n", "\t%1 audio channels\n", n), n);
+ }
+
+ text += string_compose (_("\n%1 is unable to insert this plugin here.\n"), PROGRAM_NAME);
+ label.set_text(text);
+
+ dialog.get_vbox()->pack_start (label);
+ dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
+
+ dialog.set_name (X_("PluginIODialog"));
+ dialog.set_position (Gtk::WIN_POS_MOUSE);
+ dialog.set_modal (true);
+ dialog.show_all ();
+
+ dialog.run ();
+}
+
+void
+ProcessorBox::choose_insert ()
+{
+ boost::shared_ptr<Processor> processor (new PortInsert (*_session, _route->pannable(), _route->mute_master()));
+ _route->add_processor_by_index (processor, _placement);
+}
+
+/* Caller must not hold process lock */
+void
+ProcessorBox::choose_send ()
+{
+ boost::shared_ptr<Send> send (new Send (*_session, _route->pannable(), _route->mute_master()));
+
+ /* make an educated guess at the initial number of outputs for the send */
+ ChanCount outs = (_session->master_out())
+ ? _session->master_out()->n_outputs()
+ : _route->n_outputs();
+
+ /* XXX need processor lock on route */
+ try {
+ Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock());
+ send->output()->ensure_io (outs, false, this);
+ } catch (AudioEngine::PortRegistrationFailure& err) {
+ error << string_compose (_("Cannot set up new send: %1"), err.what()) << endmsg;
+ return;
+ }
+
+ /* let the user adjust the IO setup before creation.
+
+ Note: this dialog is NOT modal - we just leave it to run and it will
+ return when its Finished signal is emitted - typically when the window
+ is closed.
+ */
+
+ IOSelectorWindow *ios = new IOSelectorWindow (_session, send->output(), true);
+ ios->show ();
+
+ /* keep a reference to the send so it doesn't get deleted while
+ the IOSelectorWindow is doing its stuff
+ */
+ _processor_being_created = send;
+
+ ios->selector().Finished.connect (sigc::bind (
+ sigc::mem_fun(*this, &ProcessorBox::send_io_finished),
+ boost::weak_ptr<Processor>(send), ios));
+
+}
+
+void
+ProcessorBox::send_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
+{
+ boost::shared_ptr<Processor> processor (weak_processor.lock());
+
+ /* drop our temporary reference to the new send */
+ _processor_being_created.reset ();
+
+ if (!processor) {
+ return;
+ }
+
+ switch (r) {
+ case IOSelector::Cancelled:
+ // processor will go away when all shared_ptrs to it vanish
+ break;
+
+ case IOSelector::Accepted:
+ _route->add_processor_by_index (processor, _placement);
+ if (Profile->get_sae()) {
+ processor->activate ();
+ }
+ break;
+ }
+
+ delete_when_idle (ios);