Standardize drawing of PixFader and BarController; implement flat_buttons and prelight.
[ardour.git] / gtk2_ardour / processor_box.cc
index 605fbbc25fb3587c99d2c96ed2e52e24e0afa39c..f095896f407ac86ef00f0c093f1045e7552fefc2 100644 (file)
 #include "gtk2ardour-config.h"
 #endif
 
+#ifdef COMPILER_MSVC
+#define rintf(x) round((x) + 0.5)
+#endif
+
 #include <cmath>
 #include <iostream>
 #include <set>
@@ -45,7 +49,9 @@
 #include "ardour/audioengine.h"
 #include "ardour/internal_return.h"
 #include "ardour/internal_send.h"
+#include "ardour/panner_shell.h"
 #include "ardour/plugin_insert.h"
+#include "ardour/pannable.h"
 #include "ardour/port_insert.h"
 #include "ardour/profile.h"
 #include "ardour/return.h"
@@ -70,7 +76,6 @@
 #include "return_ui.h"
 #include "route_processor_selection.h"
 #include "send_ui.h"
-#include "utils.h"
 
 #include "i18n.h"
 
@@ -98,6 +103,7 @@ static const uint32_t midi_port_color = 0x960909FF; //Red
 ProcessorEntry::ProcessorEntry (ProcessorBox* parent, boost::shared_ptr<Processor> p, Width w)
        : _button (ArdourButton::led_default_elements)
        , _position (PreFader)
+       , _selectable(true)
        , _parent (parent)
        , _processor (p)
        , _width (w)
@@ -455,6 +461,34 @@ ProcessorEntry::toggle_control_visibility (Control* c)
        _parent->update_gui_object_state (this);
 }
 
+Menu *
+ProcessorEntry::build_send_options_menu ()
+{
+       using namespace Menu_Helpers;
+       Menu* menu = manage (new Menu);
+       MenuList& items = menu->items ();
+
+       boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (_processor);
+       if (send) {
+
+               items.push_back (CheckMenuElem (_("Link panner controls")));
+               Gtk::CheckMenuItem* c = dynamic_cast<Gtk::CheckMenuItem*> (&items.back ());
+               c->set_active (send->panner_shell()->is_linked_to_route());
+               c->signal_toggled().connect (sigc::mem_fun (*this, &ProcessorEntry::toggle_panner_link));
+
+       }
+       return menu;
+}
+
+void
+ProcessorEntry::toggle_panner_link ()
+{
+       boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (_processor);
+       if (send) {
+               send->panner_shell()->set_linked_to_route(!send->panner_shell()->is_linked_to_route());
+       }
+}
+
 ProcessorEntry::Control::Control (boost::shared_ptr<AutomationControl> c, string const & n)
        : _control (c)
        , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain()), 0, 1, 0.01, 0.1)
@@ -815,6 +849,13 @@ ProcessorEntry::RoutingIcon::on_expose_event (GdkEventExpose* ev)
                cairo_move_to (cr, si_x, height);
                cairo_line_to (cr, si_x, 0);
                cairo_stroke (cr);
+       } else if (midi_sources == 1 && midi_sinks == 1) {
+               /* unusual cases -- removed synth, midi-track w/audio plugins */
+               const float si_x  = rintf(width * (sinks   > 1 ? .2f : .5f)) + .5f;
+               const float si_x0 = rintf(width * (sources > 1 ? .2f : .5f)) + .5f;
+               cairo_move_to (cr, si_x, height);
+               cairo_curve_to (cr, si_x, 0, si_x0, height, si_x0, 0);
+               cairo_stroke (cr);
        }
 
        /* AUDIO */
@@ -826,8 +867,10 @@ ProcessorEntry::RoutingIcon::on_expose_event (GdkEventExpose* ev)
                        UINT_RGBA_B_FLT(audio_port_color));
 
        if (_splitting) {
+               assert(audio_sources < 2);
                assert(audio_sinks > 1);
-               const float si_x0 = rintf(width * .5f) + .5f;
+               /* assume there is only ever one MIDI port */
+               const float si_x0 = rintf(width * (midi_sources > 0 ? .8f : .5f)) + .5f;
                for (uint32_t i = midi_sinks; i < sinks; ++i) {
                        const float si_x = rintf(width * (.2f + .6f * i / (sinks - 1.f))) + .5f;
                        cairo_move_to (cr, si_x, height);
@@ -1091,6 +1134,20 @@ ProcessorBox::show_processor_menu (int arg)
                }
        }
 
+       Gtk::MenuItem* send_menu_item = dynamic_cast<Gtk::MenuItem*>(ActionManager::get_widget("/ProcessorMenu/send_options"));
+       if (send_menu_item) {
+               if (single_selection) {
+                       Menu* m = single_selection->build_send_options_menu ();
+                       if (m && !m->items().empty()) {
+                               send_menu_item->set_submenu (*m);
+                               send_menu_item->set_sensitive (true);
+                       } else {
+                               gtk_menu_item_set_submenu (send_menu_item->gobj(), 0);
+                               send_menu_item->set_sensitive (false);
+                       }
+               }
+       }
+
        /* Sensitise actions as approprioate */
 
         cut_action->set_sensitive (can_cut());
@@ -1139,14 +1196,14 @@ ProcessorBox::leave_notify (GdkEventCrossing*)
        return false;
 }
 
-void
+bool
 ProcessorBox::processor_operation (ProcessorOperation op) 
 {
        ProcSelection targets;
 
        get_selected_processors (targets);
 
-       if (targets.empty()) {
+/*     if (targets.empty()) {
 
                int x, y;
                processor_display.get_pointer (x, y);
@@ -1157,12 +1214,20 @@ ProcessorBox::processor_operation (ProcessorOperation op)
                        targets.push_back (pointer.first->processor ());
                }
        }
+*/
 
+       if ( (op == ProcessorsDelete) && targets.empty() )
+               return false;  //nothing to delete.  return false so the editor-mixer, because the user was probably intending to delete something in the editor
+       
        switch (op) {
        case ProcessorsSelectAll:
                processor_display.select_all ();
                break;
 
+       case ProcessorsSelectNone:
+               processor_display.select_none ();
+               break;
+
        case ProcessorsCopy:
                copy_processors (targets);
                break;
@@ -1200,6 +1265,8 @@ ProcessorBox::processor_operation (ProcessorOperation op)
        default:
                break;
        }
+       
+       return true;
 }
 
 ProcessorWindowProxy* 
@@ -1402,7 +1469,8 @@ ProcessorBox::choose_insert ()
 void
 ProcessorBox::choose_send ()
 {
-       boost::shared_ptr<Send> send (new Send (*_session, _route->pannable(), _route->mute_master()));
+       boost::shared_ptr<Pannable> sendpan(new Pannable (*_session));
+       boost::shared_ptr<Send> send (new Send (*_session, sendpan, _route->mute_master()));
 
        /* make an educated guess at the initial number of outputs for the send */
        ChanCount outs = (_session->master_out())
@@ -1686,6 +1754,7 @@ ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
        }
 
        boost::shared_ptr<PluginInsert> plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor);
+       
        ProcessorEntry* e = 0;
        if (plugin_insert) {
                e = new PluginInsertProcessorEntry (this, plugin_insert, _width);
@@ -1693,6 +1762,13 @@ ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
                e = new ProcessorEntry (this, processor, _width);
        }
 
+       boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
+       boost::shared_ptr<PortInsert> ext = boost::dynamic_pointer_cast<PortInsert> (processor);
+       
+       //faders and meters are not deletable, copy/paste-able, so they shouldn't be selectable
+       if (!send && !plugin_insert && !ext)
+               e->set_selectable(false);
+
        /* Set up this entry's state from the GUIObjectState */
        XMLNode* proc = entry_gui_object_state (e);
        if (proc) {
@@ -2051,9 +2127,10 @@ ProcessorBox::paste_processor_state (const XMLNodeList& nlist, boost::shared_ptr
                                        continue;
                                }
 
+                               boost::shared_ptr<Pannable> sendpan(new Pannable (*_session));
                                XMLNode n (**niter);
-                                InternalSend* s = new InternalSend (*_session, _route->pannable(), _route->mute_master(),
-                                                                   boost::shared_ptr<Route>(), Delivery::Aux); 
+                               InternalSend* s = new InternalSend (*_session, sendpan, _route->mute_master(),
+                                               _route, boost::shared_ptr<Route>(), Delivery::Aux);
 
                                IOProcessor::prepare_for_reset (n, s->name());
 
@@ -2066,8 +2143,10 @@ ProcessorBox::paste_processor_state (const XMLNodeList& nlist, boost::shared_ptr
 
                        } else if (type->value() == "send") {
 
+                               boost::shared_ptr<Pannable> sendpan(new Pannable (*_session));
                                XMLNode n (**niter);
-                                Send* s = new Send (*_session, _route->pannable(), _route->mute_master());
+
+                               Send* s = new Send (*_session, _route->pannable(), _route->mute_master());
 
                                IOProcessor::prepare_for_reset (n, s->name());
                                
@@ -2400,6 +2479,7 @@ ProcessorBox::register_actions ()
        ActionManager::register_action (popup_act_grp, X_("newaux"), _("New Aux Send ..."));
 
        ActionManager::register_action (popup_act_grp, X_("controls"), _("Controls"));
+       ActionManager::register_action (popup_act_grp, X_("send_options"), _("Send Options"));
 
        ActionManager::register_action (popup_act_grp, X_("clear"), _("Clear (all)"),
                        sigc::ptr_fun (ProcessorBox::rb_clear));