update drobilla's fascistic dir-locals.el to force emacs users into whitespace submis...
[ardour.git] / gtk2_ardour / editor.cc
index 931196115f16bd4f109df5ef2f1fb13a063db67f..050f9b6a1e97108aed50012a494a6f1899e9d473 100644 (file)
 #include <gdkmm/color.h>
 #include <gdkmm/bitmap.h>
 
-#include <gtkmm2ext/grouped_buttons.h>
-#include <gtkmm2ext/gtk_ui.h>
-#include <gtkmm2ext/tearoff.h>
-#include <gtkmm2ext/utils.h>
-#include <gtkmm2ext/window_title.h>
-#include <gtkmm2ext/choice.h>
-#include <gtkmm2ext/cell_renderer_pixbuf_toggle.h>
+#include "gtkmm2ext/bindings.h"
+#include "gtkmm2ext/grouped_buttons.h"
+#include "gtkmm2ext/gtk_ui.h"
+#include "gtkmm2ext/tearoff.h"
+#include "gtkmm2ext/utils.h"
+#include "gtkmm2ext/window_title.h"
+#include "gtkmm2ext/choice.h"
+#include "gtkmm2ext/cell_renderer_pixbuf_toggle.h"
 
 #include "ardour/audio_diskstream.h"
 #include "ardour/audio_track.h"
@@ -77,6 +78,7 @@
 #include "control_protocol/control_protocol.h"
 
 #include "editor.h"
+#include "debug.h"
 #include "keyboard.h"
 #include "marker.h"
 #include "playlist_selector.h"
@@ -485,7 +487,6 @@ Editor::Editor ()
 
        controls_layout.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
        controls_layout.signal_button_release_event().connect (sigc::mem_fun(*this, &Editor::edit_controls_button_release));
-       controls_layout_size_request_connection = controls_layout.signal_size_request().connect (sigc::mem_fun (*this, &Editor::controls_layout_size_request));
 
        _cursors = new MouseCursors;
 
@@ -566,31 +567,31 @@ Editor::Editor ()
 
        Button* summary_arrows_left_left = manage (new Button);
        summary_arrows_left_left->add (*manage (new Arrow (ARROW_LEFT, SHADOW_NONE)));
-       summary_arrows_left_left->signal_pressed().connect (sigc::hide_return (sigc::mem_fun (*this, &Editor::horizontal_scroll_left_press)));
-       summary_arrows_left_left->signal_released().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left_release));
+       summary_arrows_left_left->signal_pressed().connect (sigc::hide_return (sigc::bind (sigc::mem_fun (*this, &Editor::scroll_press), LEFT)));
+       summary_arrows_left_left->signal_released().connect (sigc::mem_fun (*this, &Editor::scroll_release));
        
        Button* summary_arrows_left_right = manage (new Button);
        summary_arrows_left_right->add (*manage (new Arrow (ARROW_RIGHT, SHADOW_NONE)));
-       summary_arrows_left_right->signal_pressed().connect (sigc::hide_return (sigc::mem_fun (*this, &Editor::horizontal_scroll_right_press)));
-       summary_arrows_left_right->signal_released().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right_release));
+       summary_arrows_left_right->signal_pressed().connect (sigc::hide_return (sigc::bind (sigc::mem_fun (*this, &Editor::scroll_press), RIGHT)));
+       summary_arrows_left_right->signal_released().connect (sigc::mem_fun (*this, &Editor::scroll_release));
        
        VBox* summary_arrows_left = manage (new VBox);
        summary_arrows_left->pack_start (*summary_arrows_left_left);
        summary_arrows_left->pack_start (*summary_arrows_left_right);
 
-       Button* summary_arrows_right_left = manage (new Button);
-       summary_arrows_right_left->add (*manage (new Arrow (ARROW_LEFT, SHADOW_NONE)));
-       summary_arrows_right_left->signal_pressed().connect (sigc::hide_return (sigc::mem_fun (*this, &Editor::horizontal_scroll_left_press)));
-       summary_arrows_right_left->signal_released().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left_release));
+       Button* summary_arrows_right_up = manage (new Button);
+       summary_arrows_right_up->add (*manage (new Arrow (ARROW_UP, SHADOW_NONE)));
+       summary_arrows_right_up->signal_pressed().connect (sigc::hide_return (sigc::bind (sigc::mem_fun (*this, &Editor::scroll_press), UP)));
+       summary_arrows_right_up->signal_released().connect (sigc::mem_fun (*this, &Editor::scroll_release));
        
-       Button* summary_arrows_right_right = manage (new Button);
-       summary_arrows_right_right->add (*manage (new Arrow (ARROW_RIGHT, SHADOW_NONE)));
-       summary_arrows_right_right->signal_pressed().connect (sigc::hide_return (sigc::mem_fun (*this, &Editor::horizontal_scroll_right_press)));
-       summary_arrows_right_right->signal_released().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right_release));
+       Button* summary_arrows_right_down = manage (new Button);
+       summary_arrows_right_down->add (*manage (new Arrow (ARROW_DOWN, SHADOW_NONE)));
+       summary_arrows_right_down->signal_pressed().connect (sigc::hide_return (sigc::bind (sigc::mem_fun (*this, &Editor::scroll_press), DOWN)));
+       summary_arrows_right_down->signal_released().connect (sigc::mem_fun (*this, &Editor::scroll_release));
        
        VBox* summary_arrows_right = manage (new VBox);
-       summary_arrows_right->pack_start (*summary_arrows_right_left);
-       summary_arrows_right->pack_start (*summary_arrows_right_right);
+       summary_arrows_right->pack_start (*summary_arrows_right_up);
+       summary_arrows_right->pack_start (*summary_arrows_right_down);
 
        Frame* summary_frame = manage (new Frame);
        summary_frame->set_shadow_type (Gtk::SHADOW_ETCHED_IN);
@@ -646,6 +647,7 @@ Editor::Editor ()
        _snap_mode = SnapOff;
        set_snap_mode (_snap_mode);
        set_mouse_mode (MouseObject, true);
+        pre_internal_mouse_mode = MouseObject;
        set_edit_point_preference (EditAtMouse, true);
 
        _playlist_selector = new PlaylistSelector();
@@ -681,7 +683,7 @@ Editor::Editor ()
                window_icons.push_back (icon);
        }
        if (!window_icons.empty()) {
-               set_icon_list (window_icons);
+               // set_icon_list (window_icons);
                set_default_icon_list (window_icons);
        }
 
@@ -719,6 +721,17 @@ Editor::Editor ()
        _show_marker_lines = false;
        _over_region_trim_target = false;
 
+        /* Button bindings */
+
+        button_bindings = new Bindings;
+
+       XMLNode* node = button_settings();
+        if (node) {
+                for (XMLNodeList::const_iterator i = node->children().begin(); i != node->children().end(); ++i) {
+                        button_bindings->load (**i);
+                }
+        }
+
        constructed = true;
        instant_save ();
 
@@ -738,13 +751,28 @@ Editor::~Editor()
                image_socket_listener = 0 ;
        }
 #endif
-        
+
+        delete button_bindings;
        delete _routes;
        delete _route_groups;
        delete track_canvas;
        delete _drags;
 }
 
+XMLNode*
+Editor::button_settings () const
+{
+       XMLNode* settings = ARDOUR_UI::instance()->editor_settings();
+       XMLNode* node = find_named_node (*settings, X_("Buttons"));
+
+       if (!node) {
+                cerr << "new empty Button node\n";
+               node = new XMLNode (X_("Buttons"));
+       }
+
+       return node;
+}
+
 void
 Editor::add_toplevel_controls (Container& cont)
 {
@@ -817,10 +845,15 @@ Editor::show_window ()
        if (!is_visible ()) {
                show_all ();
 
+               /* XXX: this is a bit unfortunate; it would probably
+                  be nicer if we could just call show () above rather
+                  than needing the show_all ()
+               */
+
                /* re-hide stuff if necessary */
                editor_list_button_toggled ();
                parameter_changed ("show-summary");
-               parameter_changed ("show-edit-group-tabs");
+               parameter_changed ("show-group-tabs");
                parameter_changed ("show-zoom-tools");
 
                /* now reset all audio_time_axis heights, because widgets might need
@@ -833,6 +866,10 @@ Editor::show_window ()
                        tv = (static_cast<TimeAxisView*>(*i));
                        tv->reset_height ();
                }
+
+               if (current_mixer_strip) {
+                       current_mixer_strip->hide_things ();
+               }
        }
 
        present ();
@@ -1524,19 +1561,19 @@ Editor::build_track_region_context_menu ()
        region_edit_menu_split_item = 0;
        region_edit_menu_split_multichannel_item = 0;
 
+       /* we might try to use items that are currently attached to a crossfade menu,
+          so clear that, too.
+       */
+       track_crossfade_context_menu.items().clear ();
+
        RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (clicked_axisview);
 
        if (rtv) {
                boost::shared_ptr<Track> tr;
                boost::shared_ptr<Playlist> pl;
 
-               /* Don't offer a region submenu if we are in internal edit mode, as we don't select regions in this
-                  mode and so offering region context is somewhat confusing.
-               */
-               if ((tr = rtv->track()) && ((pl = tr->playlist())) && !internal_editing()) {
-                       framepos_t const framepos = (framepos_t) floor ((double) get_preferred_edit_position() * tr->speed());
-                       uint32_t regions_at = pl->count_regions_at (framepos);
-                       add_region_context_items (edit_items, regions_at > 1);
+               if ((tr = rtv->track())) {
+                       add_region_context_items (edit_items, tr);
                }
        }
 
@@ -1552,6 +1589,11 @@ Editor::build_track_crossfade_context_menu ()
        MenuList& edit_items  = track_crossfade_context_menu.items();
        edit_items.clear ();
 
+       /* we might try to use items that are currently attached to a crossfade menu,
+          so clear that, too.
+       */
+       track_region_context_menu.items().clear ();
+
        AudioTimeAxisView* atv = dynamic_cast<AudioTimeAxisView*> (clicked_axisview);
 
        if (atv) {
@@ -1562,18 +1604,24 @@ Editor::build_track_crossfade_context_menu ()
                if ((tr = atv->track()) && ((pl = tr->playlist()) != 0) && ((apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl)) != 0)) {
 
                        AudioPlaylist::Crossfades xfades;
+                       framepos_t where;
+                       bool ignored;
 
-                       apl->crossfades_at (get_preferred_edit_position (), xfades);
+                       /* The xfade menu is a bit of a special case, as we always use the mouse position
+                          to decide whether or not to display it (rather than the edit point).  No particularly
+                          strong reasons for this, other than it is a bit surprising to right-click on a xfade
+                          and not get a menu.
+                       */
+                       mouse_frame (where, ignored);
+                       apl->crossfades_at (where, xfades);
 
-                       bool many = xfades.size() > 1;
+                       bool const many = xfades.size() > 1;
 
                        for (AudioPlaylist::Crossfades::iterator i = xfades.begin(); i != xfades.end(); ++i) {
                                add_crossfade_context_items (atv->audio_view(), (*i), edit_items, many);
                        }
 
-                       framepos_t framepos = (framepos_t) floor ((double) get_preferred_edit_position() * tr->speed());
-                       uint32_t regions_at = pl->count_regions_at (framepos);
-                       add_region_context_items (edit_items, regions_at > 1);
+                       add_region_context_items (edit_items, tr);
                }
        }
 
@@ -1693,7 +1741,7 @@ Editor::xfade_edit_right_region ()
 }
 
 void
-Editor::add_region_context_items (Menu_Helpers::MenuList& edit_items, bool multiple_regions_at_position)
+Editor::add_region_context_items (Menu_Helpers::MenuList& edit_items, boost::shared_ptr<Track> track)
 {
        using namespace Menu_Helpers;
        
@@ -1701,15 +1749,15 @@ Editor::add_region_context_items (Menu_Helpers::MenuList& edit_items, bool multi
           the standard items.
        */
 
-       /* we have to hack up the region name because "_" has a special
-          meaning for menu titles.
-       */
-
        RegionSelection rs = get_regions_from_selection_and_entered ();
        
        string::size_type pos = 0;
        string menu_item_name = (rs.size() == 1) ? rs.front()->region()->name() : _("Selected Regions");
 
+       /* we have to hack up the region name because "_" has a special
+          meaning for menu titles.
+       */
+
        while ((pos = menu_item_name.find ("_", pos)) != string::npos) {
                menu_item_name.replace (pos, 1, "__");
                pos += 2;
@@ -1723,8 +1771,17 @@ Editor::add_region_context_items (Menu_Helpers::MenuList& edit_items, bool multi
                _popup_region_menu_item->set_label (menu_item_name);
        }
 
+       /* Use the mouse position rather than the edit point to decide whether to show the `choose top region'
+          dialogue.  If we use the edit point it gets a bit messy because the user still has to click over
+          *some* region in order to get the region context menu stuff to be displayed at all.
+       */
+       
+       framepos_t mouse;
+       bool ignored;
+       mouse_frame (mouse, ignored);
+
        edit_items.push_back (*_popup_region_menu_item);
-       if (multiple_regions_at_position && (layering_order_editor == 0 || !layering_order_editor->is_visible ())) {
+       if (track->playlist()->count_regions_at (mouse) > 1 && (layering_order_editor == 0 || !layering_order_editor->is_visible ())) {
                edit_items.push_back (*manage (_region_actions->get_action ("choose-top-region")->create_menu_item ()));
        }
        edit_items.push_back (SeparatorElem());
@@ -2109,7 +2166,7 @@ Editor::set_state (const XMLNode& node, int /*version*/)
 
        set_default_size (g.base_width, g.base_height);
        move (x, y);
-
+        
        if (_session && (prop = node.property ("playhead"))) {
                framepos_t pos;
                sscanf (prop->value().c_str(), "%" PRIi64, &pos);
@@ -2360,6 +2417,12 @@ Editor::get_state ()
        snprintf (buf, sizeof (buf), "%d", _the_notebook.get_current_page ());
        node->add_property (X_("editor-list-page"), buf);
 
+        if (button_bindings) {
+                XMLNode* bb = new XMLNode (X_("Buttons"));
+                button_bindings->save (*bb);
+                node->add_child_nocopy (*bb);
+        } 
+
        node->add_property (X_("show-marker-lines"), _show_marker_lines ? "yes" : "no");
 
        node->add_child_nocopy (selection->get_state ());
@@ -2755,15 +2818,15 @@ Editor::setup_toolbar ()
        _zoom_box.set_border_width (0);
 
        zoom_in_button.set_name ("EditorTimeButton");
-       zoom_in_button.set_image (*(manage (new Image (Stock::ZOOM_IN, Gtk::ICON_SIZE_MENU))));
+       zoom_in_button.set_image (*(manage (new Image (::get_icon ("zoom_in")))));
        zoom_in_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), false));
 
        zoom_out_button.set_name ("EditorTimeButton");
-       zoom_out_button.set_image (*(manage (new Image (Stock::ZOOM_OUT, Gtk::ICON_SIZE_MENU))));
+       zoom_out_button.set_image (*(manage (new Image (::get_icon ("zoom_out")))));
        zoom_out_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), true));
 
        zoom_out_full_button.set_name ("EditorTimeButton");
-       zoom_out_full_button.set_image (*(manage (new Image (Stock::ZOOM_100, Gtk::ICON_SIZE_MENU))));
+       zoom_out_full_button.set_image (*(manage (new Image (::get_icon ("zoom_full")))));
        zoom_out_full_button.signal_clicked().connect (sigc::mem_fun(*this, &Editor::temporal_zoom_session));
 
        zoom_focus_selector.set_name ("ZoomFocusSelector");
@@ -2778,14 +2841,16 @@ Editor::setup_toolbar ()
        
        /* Track zoom buttons */
        tav_expand_button.set_name ("TrackHeightButton");
-       tav_expand_button.set_size_request(-1,20);
-       tav_expand_button.add (*(manage (new Image (::get_icon("tav_exp")))));
-       tav_expand_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::tav_zoom_step), true));
+       tav_expand_button.set_size_request (-1, 20);
+       tav_expand_button.add (*(manage (new Image (::get_icon ("tav_exp")))));
+       RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("expand-tracks"));
+       act->connect_proxy (tav_expand_button);
 
        tav_shrink_button.set_name ("TrackHeightButton");
-       tav_shrink_button.set_size_request(-1,20);
-       tav_shrink_button.add (*(manage (new Image (::get_icon("tav_shrink")))));
-       tav_shrink_button.signal_clicked().connect (sigc::bind (sigc::mem_fun(*this, &Editor::tav_zoom_step), false));
+       tav_shrink_button.set_size_request (-1, 20);
+       tav_shrink_button.add (*(manage (new Image (::get_icon ("tav_shrink")))));
+       act = ActionManager::get_action (X_("Editor"), X_("shrink-tracks"));
+       act->connect_proxy (tav_shrink_button);
 
        _zoom_box.pack_start (tav_shrink_button);
        _zoom_box.pack_start (tav_expand_button);
@@ -2864,7 +2929,11 @@ Editor::setup_toolbar ()
        toolbar_hbox.pack_start (*_tools_tearoff, false, false);
 
        hbox->pack_start (snap_box, false, false);
-       hbox->pack_start (*nudge_box, false, false);
+        if (!Profile->get_small_screen()) {
+                hbox->pack_start (*nudge_box, false, false);
+        } else {
+                ARDOUR_UI::instance()->editor_transport_box().pack_start (*nudge_box, false, false);
+        }
        hbox->pack_start (panic_box, false, false);
 
        hbox->show_all ();
@@ -4387,6 +4456,7 @@ Editor::get_preferred_edit_position (bool ignore_playhead)
        EditPoint ep = _edit_point;
 
        if (entered_marker) {
+                DEBUG_TRACE (DEBUG::CutNPaste, string_compose ("GPEP: use entered marker @ %1\n", entered_marker->position()));
                return entered_marker->position();
        }
 
@@ -4397,6 +4467,7 @@ Editor::get_preferred_edit_position (bool ignore_playhead)
        switch (ep) {
        case EditAtPlayhead:
                where = _session->audible_frame();
+                DEBUG_TRACE (DEBUG::CutNPaste, string_compose ("GPEP: use playhead @ %1\n", where));
                break;
 
        case EditAtSelectedMarker:
@@ -4409,6 +4480,7 @@ Editor::get_preferred_edit_position (bool ignore_playhead)
                                } else {
                                        where = loc->end();
                                }
+                                DEBUG_TRACE (DEBUG::CutNPaste, string_compose ("GPEP: use selected marker @ %1\n", where));
                                break;
                        }
                }
@@ -4421,6 +4493,7 @@ Editor::get_preferred_edit_position (bool ignore_playhead)
                        return 0;
                }
                snap_to (where);
+                DEBUG_TRACE (DEBUG::CutNPaste, string_compose ("GPEP: use mouse @ %1\n", where));
                break;
        }
 
@@ -4809,6 +4882,12 @@ Editor::region_view_added (RegionView *)
        _summary->set_dirty ();
 }
 
+void
+Editor::region_view_removed ()
+{
+       _summary->set_dirty ();
+}
+
 TimeAxisView*
 Editor::axis_view_from_route (boost::shared_ptr<Route> r) const
 {
@@ -4871,7 +4950,14 @@ Editor::handle_new_route (RouteList& routes)
 
                rtv->effective_gain_display ();
 
+                if (internal_editing()) {
+                        rtv->enter_internal_edit_mode ();
+                } else {
+                        rtv->leave_internal_edit_mode ();
+                }
+
                rtv->view()->RegionViewAdded.connect (sigc::mem_fun (*this, &Editor::region_view_added));
+               rtv->view()->RegionViewRemoved.connect (sigc::mem_fun (*this, &Editor::region_view_removed));
        }
 
        _routes->routes_added (new_views);
@@ -4951,16 +5037,28 @@ Editor::timeaxisview_deleted (TimeAxisView *tv)
 }
 
 void
-Editor::hide_track_in_display (TimeAxisView* tv, bool /*temponly*/)
+Editor::hide_track_in_display (TimeAxisView* tv, bool apply_to_selection)
 {
-       RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
+       if (apply_to_selection) {
+               for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ) {
 
-       if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
-               // this will hide the mixer strip
-               set_selected_mixer_strip (*tv);
+                       TrackSelection::iterator j = i;
+                       ++j;
+                       
+                       hide_track_in_display (*i, false);
+                       
+                       i = j;
+               }
+       } else {
+               RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*> (tv);
+               
+               if (rtv && current_mixer_strip && (rtv->route() == current_mixer_strip->route())) {
+                       // this will hide the mixer strip
+                       set_selected_mixer_strip (*tv);
+               }
+               
+               _routes->hide_track_in_display (*tv);
        }
-
-       _routes->hide_track_in_display (*tv);
 }
 
 bool
@@ -5094,7 +5192,7 @@ Editor::check_step_edit ()
 }
 
 bool
-Editor::horizontal_scroll_left_press ()
+Editor::scroll_press (Direction dir)
 {
        ++_scroll_callbacks;
        
@@ -5102,44 +5200,32 @@ Editor::horizontal_scroll_left_press ()
                /* delay the first auto-repeat */
                return true;
        }
-               
-       double x = leftmost_position() - current_page_frames() / 5;
-       if (x < 0) {
-               x = 0;
-       }
-       
-       reset_x_origin (x);
 
-       /* do hacky auto-repeat */
-       if (!_scroll_connection.connected ()) {
-               _scroll_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_left_press), 100);
-               _scroll_callbacks = 0;
-       }
+       switch (dir) {
+       case LEFT:
+               scroll_backward (1);
+               break;
 
-       return true;
-}
+       case RIGHT:
+               scroll_forward (1);
+               break;
 
-void
-Editor::horizontal_scroll_left_release ()
-{
-       _scroll_connection.disconnect ();
-}
+       case UP:
+               scroll_tracks_up_line ();
+               break;
 
-bool
-Editor::horizontal_scroll_right_press ()
-{
-       ++_scroll_callbacks;
-       
-       if (_scroll_connection.connected() && _scroll_callbacks < 5) {
-               /* delay the first auto-repeat */
-               return true;
+       case DOWN:
+               scroll_tracks_down_line ();
+               break;
        }
 
-       reset_x_origin (leftmost_position() + current_page_frames() / 5);
-
        /* do hacky auto-repeat */
        if (!_scroll_connection.connected ()) {
-               _scroll_connection = Glib::signal_timeout().connect (sigc::mem_fun (*this, &Editor::horizontal_scroll_right_press), 100);
+
+               _scroll_connection = Glib::signal_timeout().connect (
+                       sigc::bind (sigc::mem_fun (*this, &Editor::scroll_press), dir), 100
+                       );
+               
                _scroll_callbacks = 0;
        }
 
@@ -5147,7 +5233,7 @@ Editor::horizontal_scroll_right_press ()
 }
 
 void
-Editor::horizontal_scroll_right_release ()
+Editor::scroll_release ()
 {
        _scroll_connection.disconnect ();
 }
@@ -5473,3 +5559,4 @@ Editor::notebook_tab_clicked (GdkEventButton* ev, Gtk::Widget* page)
 
        return true;
 }
+