do not change Session::_transport_frame is a locate is pending
[ardour.git] / gtk2_ardour / processor_box.cc
index 876165e5d30d00f5e53bd3d5e365153d3a5d3360..ca1e448b587e4176ba5ab95dac348632d4ec544f 100644 (file)
 
 #include <sigc++/bind.h>
 
-#include "canvas/utils.h"
-
 #include <glibmm/miscutils.h>
 #include <glibmm/fileutils.h>
 
 #include <gtkmm/messagedialog.h>
 
-#include <gtkmm2ext/gtk_ui.h>
+#include "gtkmm2ext/colors.h"
+#include "gtkmm2ext/gtk_ui.h"
 #include "gtkmm2ext/menu_elems.h"
-#include <gtkmm2ext/utils.h>
-#include <gtkmm2ext/choice.h>
-#include <gtkmm2ext/utils.h>
-#include <gtkmm2ext/doi.h>
-#include <gtkmm2ext/rgb_macros.h>
+#include "gtkmm2ext/utils.h"
+#include "gtkmm2ext/doi.h"
+#include "gtkmm2ext/rgb_macros.h"
+
+#include "widgets/choice.h"
+#include "widgets/prompter.h"
+#include "widgets/tooltips.h"
 
 #include "ardour/amp.h"
 #include "ardour/audio_track.h"
@@ -84,7 +85,6 @@
 #include "script_selector.h"
 #include "send_ui.h"
 #include "timers.h"
-#include "tooltips.h"
 #include "new_plugin_preset_dialog.h"
 
 #include "pbd/i18n.h"
@@ -103,6 +103,7 @@ using namespace PBD;
 using namespace Gtk;
 using namespace Glib;
 using namespace Gtkmm2ext;
+using namespace ArdourWidgets;
 
 ProcessorBox*  ProcessorBox::_current_processor_box = 0;
 RefPtr<Action> ProcessorBox::paste_action;
@@ -183,7 +184,7 @@ ProcessorEntry::ProcessorEntry (ProcessorBox* parent, boost::shared_ptr<Processo
                boost::shared_ptr<PluginInsert> pi = boost::dynamic_pointer_cast<PluginInsert> (_processor);
                if (pi && pi->plugin() && pi->plugin()->has_inline_display()) {
                        if (pi->plugin()->get_info()->type != ARDOUR::Lua) {
-                               _plugin_display = new PluginDisplay (*this, pi->plugin(),
+                               _plugin_display = new PluginInlineDisplay (*this, pi->plugin(),
                                                std::max (60.f, rintf(112.f * UIConfiguration::instance().get_ui_scale())));
                        } else {
                                assert (boost::dynamic_pointer_cast<LuaProc>(pi->plugin()));
@@ -516,10 +517,10 @@ ProcessorEntry::setup_tooltip ()
                        }
 
                        if (pi->plugin()->has_editor()) {
-                               ARDOUR_UI_UTILS::set_tooltip (_button,
+                               set_tooltip (_button,
                                                string_compose (_("<b>%1</b>\nDouble-click to show GUI.\n%2+double-click to show generic GUI.%3"), name (Wide), Keyboard::secondary_modifier_name (), postfix));
                        } else {
-                               ARDOUR_UI_UTILS::set_tooltip (_button,
+                               set_tooltip (_button,
                                                string_compose (_("<b>%1</b>\nDouble-click to show generic GUI.%2"), name (Wide), postfix));
                        }
                        return;
@@ -533,14 +534,14 @@ ProcessorEntry::setup_tooltip ()
                if ((send = boost::dynamic_pointer_cast<Send> (_processor)) != 0 &&
                                !boost::dynamic_pointer_cast<InternalSend>(_processor)) {
                        if (send->remove_on_disconnect ()) {
-                               ARDOUR_UI_UTILS::set_tooltip (_button, string_compose ("<b>&gt; %1</b>\nThis (sidechain) send will be removed when disconnected.", _processor->name()));
+                               set_tooltip (_button, string_compose ("<b>&gt; %1</b>\nThis (sidechain) send will be removed when disconnected.", _processor->name()));
                        } else {
-                               ARDOUR_UI_UTILS::set_tooltip (_button, string_compose ("<b>&gt; %1</b>", _processor->name()));
+                               set_tooltip (_button, string_compose ("<b>&gt; %1</b>", _processor->name()));
                        }
                        return;
                }
        }
-       ARDOUR_UI_UTILS::set_tooltip (_button, string_compose ("<b>%1</b>", name (Wide)));
+       set_tooltip (_button, string_compose ("<b>%1</b>", name (Wide)));
 }
 
 string
@@ -850,6 +851,9 @@ ProcessorEntry::Control::Control (boost::shared_ptr<AutomationControl> c, string
                _adjustment.set_page_increment (largestep);
                _slider.set_default_value (normal);
 
+               _slider.StartGesture.connect(sigc::mem_fun(*this, &Control::start_touch));
+               _slider.StopGesture.connect(sigc::mem_fun(*this, &Control::end_touch));
+
                _adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &Control::slider_adjusted));
                c->Changed.connect (_connections, invalidator (*this), boost::bind (&Control::control_changed, this), gui_context ());
                if (c->alist ()) {
@@ -880,7 +884,7 @@ ProcessorEntry::Control::set_tooltip ()
        std::string tt = _name + ": " + ARDOUR::value_as_string (c->desc(), c->get_value ());
        string sm = Gtkmm2ext::markup_escape_text (tt);
        _slider_persistant_tooltip.set_tip (sm);
-       ARDOUR_UI_UTILS::set_tooltip (_button, sm);
+       ArdourWidgets::set_tooltip (_button, Gtkmm2ext::markup_escape_text (sm));
 }
 
 void
@@ -900,6 +904,26 @@ ProcessorEntry::Control::slider_adjusted ()
        set_tooltip ();
 }
 
+void
+ProcessorEntry::Control::start_touch ()
+{
+       boost::shared_ptr<AutomationControl> c = _control.lock ();
+       if (!c) {
+               return;
+       }
+       c->start_touch (c->session().transport_frame());
+}
+
+void
+ProcessorEntry::Control::end_touch ()
+{
+       boost::shared_ptr<AutomationControl> c = _control.lock ();
+       if (!c) {
+               return;
+       }
+       c->stop_touch (c->session().transport_frame());
+}
+
 void
 ProcessorEntry::Control::button_clicked ()
 {
@@ -1539,40 +1563,25 @@ ProcessorEntry::RoutingIcon::expose_output_map (cairo_t* cr, const double width,
        }
 }
 
-ProcessorEntry::PluginDisplay::PluginDisplay (ProcessorEntry& e, boost::shared_ptr<ARDOUR::Plugin> p, uint32_t max_height)
-       : _entry (e)
-       , _plug (p)
-       , _surf (0)
-       , _max_height (max_height)
-       , _cur_height (1)
+ProcessorEntry::PluginInlineDisplay::PluginInlineDisplay (ProcessorEntry& e, boost::shared_ptr<ARDOUR::Plugin> p, uint32_t max_height)
+       : PluginDisplay (p, max_height)
+       , _entry (e)
        , _scroll (false)
 {
-       set_name ("processor prefader");
-       add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
-       _plug->DropReferences.connect (_death_connection, invalidator (*this), boost::bind (&PluginDisplay::plugin_going_away, this), gui_context());
-       _plug->QueueDraw.connect (_qdraw_connection, invalidator (*this),
-                       boost::bind (&Gtk::Widget::queue_draw, this), gui_context ());
-
        std::string postfix = string_compose(_("\n%1+double-click to toggle inline-display"), Keyboard::tertiary_modifier_name ());
 
        if (_plug->has_editor()) {
-               ARDOUR_UI_UTILS::set_tooltip (*this,
+               set_tooltip (*this,
                                string_compose (_("<b>%1</b>\nDouble-click to show GUI.\n%2+double-click to show generic GUI.%3"), e.name (Wide), Keyboard::primary_modifier_name (), postfix));
        } else {
-               ARDOUR_UI_UTILS::set_tooltip (*this,
+               set_tooltip (*this,
                                string_compose (_("<b>%1</b>\nDouble-click to show generic GUI.%2"), e.name (Wide), postfix));
        }
 }
 
-ProcessorEntry::PluginDisplay::~PluginDisplay ()
-{
-       if (_surf) {
-               cairo_surface_destroy (_surf);
-       }
-}
 
 bool
-ProcessorEntry::PluginDisplay::on_button_press_event (GdkEventButton *ev)
+ProcessorEntry::PluginInlineDisplay::on_button_press_event (GdkEventButton *ev)
 {
        assert (_entry.processor ());
 
@@ -1599,14 +1608,8 @@ ProcessorEntry::PluginDisplay::on_button_press_event (GdkEventButton *ev)
        return false;
 }
 
-bool
-ProcessorEntry::PluginDisplay::on_button_release_event (GdkEventButton *ev)
-{
-       return false;
-}
-
 void
-ProcessorEntry::PluginDisplay::on_size_request (Requisition* req)
+ProcessorEntry::PluginInlineDisplay::on_size_request (Requisition* req)
 {
        req->width = 56;
        req->height = _cur_height;
@@ -1614,7 +1617,7 @@ ProcessorEntry::PluginDisplay::on_size_request (Requisition* req)
 
 
 void
-ProcessorEntry::PluginDisplay::update_height_alloc (uint32_t inline_height)
+ProcessorEntry::PluginInlineDisplay::update_height_alloc (uint32_t inline_height)
 {
        /* work-around scroll-bar + aspect ratio
         * show inline-view -> height changes -> scrollbar gets added
@@ -1643,105 +1646,14 @@ ProcessorEntry::PluginDisplay::update_height_alloc (uint32_t inline_height)
        _scroll = sc;
 }
 
-uint32_t
-ProcessorEntry::PluginDisplay::render_inline (cairo_t* cr, uint32_t width)
-{
-       Plugin::Display_Image_Surface* dis = _plug->render_inline_display (width, _max_height);
-       if (!dis) {
-               return 0;
-       }
-
-       /* allocate a local image-surface,
-        * We cannot re-use the data via cairo_image_surface_create_for_data(),
-        * since pixman keeps a reference to it.
-        * we'd need to hand over the data and ha cairo_surface_destroy to free it.
-        * it might be possible to work around via cairo_surface_set_user_data().
-        */
-       if (!_surf
-                       || dis->width !=  cairo_image_surface_get_width (_surf)
-                       || dis->height !=  cairo_image_surface_get_height (_surf)
-                ) {
-               if (_surf) {
-                       cairo_surface_destroy (_surf);
-               }
-               _surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, dis->width, dis->height);
-       }
-
-       if (cairo_image_surface_get_stride (_surf) == dis->stride) {
-               memcpy (cairo_image_surface_get_data (_surf), dis->data, dis->stride * dis->height);
-       } else {
-               unsigned char *src = dis->data;
-               unsigned char *dst = cairo_image_surface_get_data (_surf);
-               const int dst_stride =  cairo_image_surface_get_stride (_surf);
-               for (int y = 0; y < dis->height; ++y) {
-                       memcpy (dst, src, dis->width * 4 /*ARGB32*/);
-                       src += dis->stride;
-                       dst += dst_stride;
-               }
-       }
-
-       cairo_surface_flush(_surf);
-       cairo_surface_mark_dirty(_surf);
-       const double xc = floor ((width - dis->width) * .5);
-       cairo_set_source_surface(cr, _surf, xc, 0);
-       cairo_paint (cr);
-
-       return dis->height;
-}
-
-bool
-ProcessorEntry::PluginDisplay::on_expose_event (GdkEventExpose* ev)
+void
+ProcessorEntry::PluginInlineDisplay::display_frame (cairo_t* cr, double w, double h)
 {
-       Gtk::Allocation a = get_allocation();
-       double const width = a.get_width();
-       double const height = a.get_height();
-
-       cairo_t* cr = gdk_cairo_create (get_window()->gobj());
-       cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height);
-       cairo_clip (cr);
-
-       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);
-
-       cairo_save (cr);
-       cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
-       Gtkmm2ext::rounded_rectangle (cr, .5, -1.5, width - 1, height + 1, 7);
-       cairo_clip (cr);
-       cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
-
-       uint32_t ht = render_inline (cr, width);
-       cairo_restore (cr);
-
-       if (ht == 0) {
-               hide ();
-               if (_cur_height != 1) {
-                       _cur_height = 1;
-                       queue_resize ();
-               }
-               cairo_destroy (cr);
-               return true;
-       } else {
-               update_height_alloc (ht);
-       }
-
-       bool failed = false;
-       std::string name = get_name();
-       ArdourCanvas::Color fill_color = UIConfiguration::instance().color (string_compose ("%1: fill active", name), &failed);
-
-       Gtkmm2ext::rounded_rectangle (cr, .5, -1.5, width - 1, height + 1, 7);
-       cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
-       cairo_set_line_width(cr, 1.0);
-       ArdourCanvas::set_source_rgb_a (cr, fill_color, 1.0);
-       cairo_stroke (cr);
-
-       cairo_destroy(cr);
-       return true;
+       Gtkmm2ext::rounded_rectangle (cr, .5, -1.5, w - 1, h + 1, 7);
 }
 
 ProcessorEntry::LuaPluginDisplay::LuaPluginDisplay (ProcessorEntry& e, boost::shared_ptr<ARDOUR::LuaProc> p, uint32_t max_height)
-       : PluginDisplay (e, p, max_height)
+       : PluginInlineDisplay (e, p, max_height)
        , _luaproc (p)
        , _lua_render_inline (0)
 {
@@ -1774,7 +1686,7 @@ ProcessorEntry::LuaPluginDisplay::render_inline (cairo_t *cr, uint32_t width)
 #ifndef NDEBUG
                cerr << "LuaException:" << e.what () << endl;
 #endif
-       }
+       } catch (...) { }
        return 0;
 }
 
@@ -1856,7 +1768,7 @@ ProcessorBox::ProcessorBox (ARDOUR::Session* sess, boost::function<PluginSelecto
                        );
        }
 
-       ARDOUR_UI_UTILS::set_tooltip (processor_display, _("Right-click to add/remove/edit\nplugins,inserts,sends and more"));
+       set_tooltip (processor_display, _("Right-click to add/remove/edit\nplugins,inserts,sends and more"));
 }
 
 ProcessorBox::~ProcessorBox ()
@@ -2032,7 +1944,7 @@ ProcessorBox::object_drop (DnDVBox<ProcessorEntry>* source, ProcessorEntry* posi
                 * otherwise we'll end up with duplicate ports-names.
                 * (this needs a better solution which retains connections)
                 */
-               state.remove_nodes ("Processor");
+               state.remove_nodes_and_delete ("Processor");
                proc->set_state (state, Stateful::loading_state_version);
                boost::dynamic_pointer_cast<PluginInsert>(proc)->update_id (id);
                return;
@@ -3221,7 +3133,7 @@ ProcessorBox::idle_delete_processor (boost::weak_ptr<Processor> weak_processor)
 void
 ProcessorBox::rename_processor (boost::shared_ptr<Processor> processor)
 {
-       ArdourPrompter name_prompter (true);
+       Prompter name_prompter (true);
        string result;
        name_prompter.set_title (_("Rename Processor"));
        name_prompter.set_prompt (_("New name:"));
@@ -3395,7 +3307,7 @@ ProcessorBox::paste_processor_state (const XMLNodeList& nlist, boost::shared_ptr
                                 * We really would want Stateful::ForceIDRegeneration here :(
                                 */
                                XMLNode state (**niter);
-                               state.remove_nodes ("Processor");
+                               state.remove_nodes_and_delete ("Processor");
 
                                p->set_state (state, Stateful::current_state_version);
                                boost::dynamic_pointer_cast<PluginInsert>(p)->update_id (id);
@@ -3468,7 +3380,7 @@ ProcessorBox::clear_processors ()
        choices.push_back (_("Cancel"));
        choices.push_back (_("Yes, remove them all"));
 
-       Gtkmm2ext::Choice prompter (_("Remove processors"), prompt, choices);
+       ArdourWidgets::Choice prompter (_("Remove processors"), prompt, choices);
 
        if (prompter.run () == 1) {
                _route->clear_processors (PreFader);
@@ -3493,7 +3405,7 @@ ProcessorBox::clear_processors (Placement p)
        choices.push_back (_("Cancel"));
        choices.push_back (_("Yes, remove them all"));
 
-       Gtkmm2ext::Choice prompter (_("Remove processors"), prompt, choices);
+       ArdourWidgets::Choice prompter (_("Remove processors"), prompt, choices);
 
        if (prompter.run () == 1) {
                _route->clear_processors (p);