add 10 pixels of track height to facilitate easier grabbing of the track headers...
[ardour.git] / gtk2_ardour / time_axis_view.cc
index 0902d213f5cbcd0777a7996d083cc082c2babb7f..6f3d0c17bdc3a2e30e74b8b19dd1514041560a28 100644 (file)
 #include <gtkmm2ext/utils.h>
 #include <gtkmm2ext/selector.h>
 
-#include "ardour/session.h"
-#include "ardour/utils.h"
-#include "ardour/ladspa_plugin.h"
-#include "ardour/processor.h"
-#include "ardour/location.h"
-
 #include "ardour_ui.h"
 #include "global_signals.h"
 #include "gui_thread.h"
@@ -54,6 +48,7 @@
 #include "utils.h"
 #include "streamview.h"
 #include "editor_drag.h"
+#include "editor.h"
 
 #include "i18n.h"
 
@@ -67,8 +62,8 @@ using namespace ArdourCanvas;
 using Gtkmm2ext::Keyboard;
 
 const double trim_handle_size = 6.0; /* pixels */
-uint32_t TimeAxisView::extra_height;
-uint32_t TimeAxisView::small_height;
+uint32_t TimeAxisView::button_height = 0;
+uint32_t TimeAxisView::extra_height = 0;
 int const TimeAxisView::_max_order = 512;
 PBD::Signal1<void,TimeAxisView*> TimeAxisView::CatchDeletion;
 
@@ -136,8 +131,9 @@ TimeAxisView::TimeAxisView (ARDOUR::Session* sess, PublicEditor& ed, TimeAxisVie
        name_hbox.show ();
 
        controls_table.set_size_request (200);
-       controls_table.set_row_spacings (0);
-       controls_table.set_col_spacings (0);
+       controls_table.set_row_spacings (2);
+       controls_table.set_col_spacings (2);
+       controls_table.set_border_width (2);
        controls_table.set_homogeneous (true);
 
        controls_table.attach (name_hbox, 0, 5, 0, 1,  Gtk::FILL|Gtk::EXPAND,  Gtk::FILL|Gtk::EXPAND, 3, 0);
@@ -159,6 +155,7 @@ TimeAxisView::TimeAxisView (ARDOUR::Session* sess, PublicEditor& ed, TimeAxisVie
                                  Gdk::SCROLL_MASK);
        controls_ebox.set_flags (CAN_FOCUS);
 
+       /* note that this handler connects *before* the default handler */
        controls_ebox.signal_scroll_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_scroll), true);
        controls_ebox.signal_button_press_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_button_press));
        controls_ebox.signal_button_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_button_release));
@@ -175,7 +172,7 @@ TimeAxisView::TimeAxisView (ARDOUR::Session* sess, PublicEditor& ed, TimeAxisVie
 
        ColorsChanged.connect (sigc::mem_fun (*this, &TimeAxisView::color_handler));
 
-       GhostRegion::CatchDeletion.connect (*this, invalidator (*this), ui_bind (&TimeAxisView::erase_ghost, this, _1), gui_context());
+       GhostRegion::CatchDeletion.connect (*this, invalidator (*this), boost::bind (&TimeAxisView::erase_ghost, this, _1), gui_context());
 }
 
 TimeAxisView::~TimeAxisView()
@@ -318,14 +315,15 @@ TimeAxisView::clip_to_viewport ()
 bool
 TimeAxisView::controls_ebox_scroll (GdkEventScroll* ev)
 {
-       if (Keyboard::some_magic_widget_has_focus()) {
-               return false;
-       }
-
        switch (ev->direction) {
        case GDK_SCROLL_UP:
                if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
-                       step_height (false);
+                       /* See Editor::_stepping_axis_view for notes on this hack */
+                       Editor& e = dynamic_cast<Editor&> (_editor);
+                       if (!e.stepping_axis_view ()) {
+                               e.set_stepping_axis_view (this);
+                       }
+                       e.stepping_axis_view()->step_height (false);
                        return true;
                } else if (Keyboard::no_modifiers_active (ev->state)) {
                        _editor.scroll_tracks_up_line();
@@ -335,7 +333,12 @@ TimeAxisView::controls_ebox_scroll (GdkEventScroll* ev)
 
        case GDK_SCROLL_DOWN:
                if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
-                       step_height (true);
+                       /* See Editor::_stepping_axis_view for notes on this hack */
+                       Editor& e = dynamic_cast<Editor&> (_editor);
+                       if (!e.stepping_axis_view ()) {
+                               e.set_stepping_axis_view (this);
+                       }
+                       e.stepping_axis_view()->step_height (true);
                        return true;
                } else if (Keyboard::no_modifiers_active (ev->state)) {
                        _editor.scroll_tracks_down_line();
@@ -382,7 +385,7 @@ TimeAxisView::controls_ebox_motion (GdkEventMotion* ev)
                controls_ebox.translate_coordinates (*control_parent, ev->x, ev->y, tx, ty);
                ev->y = ty - _editor.get_trackview_group_vertical_offset();
                _editor.drags()->motion_handler ((GdkEvent *) ev, false);
-               _editor.maybe_autoscroll (false, true);
+               _editor.maybe_autoscroll (false, true, false, ev->y_root < _resize_drag_start);
 
                /* now do the actual TAV resize */
                 int32_t const delta = (int32_t) floor (ev->y_root - _resize_drag_start);
@@ -397,7 +400,7 @@ TimeAxisView::controls_ebox_motion (GdkEventMotion* ev)
 }
 
 bool
-TimeAxisView::controls_ebox_leave (GdkEventCrossing* ev)
+TimeAxisView::controls_ebox_leave (GdkEventCrossing*)
 {
        if (_have_preresize_cursor) {
                gdk_window_set_cursor (controls_ebox.get_window()->gobj(), _preresize_cursor);
@@ -497,16 +500,6 @@ TimeAxisView::step_height (bool coarser)
        }
 }
 
-void
-TimeAxisView::set_heights (uint32_t h)
-{
-       TrackSelection& ts (_editor.get_selection().tracks);
-
-       for (TrackSelection::iterator i = ts.begin(); i != ts.end(); ++i) {
-               (*i)->set_height (h);
-       }
-}
-
 void
 TimeAxisView::set_height_enum (Height h, bool apply_to_selection)
 {
@@ -650,7 +643,7 @@ bool
 TimeAxisView::name_entry_focus_in (GdkEventFocus*)
 {
        name_entry.select_region (0, -1);
-       name_entry.set_name ("EditorActiveTrackNameDisplay");
+       name_entry.set_state (STATE_SELECTED);
        return false;
 }
 
@@ -661,8 +654,8 @@ TimeAxisView::name_entry_focus_out (GdkEventFocus*)
 
        last_name_entry_key_press_event = 0;
        name_entry_key_timeout.disconnect ();
-       name_entry.set_name ("EditorTrackNameDisplay");
        name_entry.select_region (0,0);
+       name_entry.set_state (STATE_NORMAL);
 
        /* do the real stuff */
 
@@ -782,10 +775,10 @@ TimeAxisView::set_samples_per_unit (double spu)
 }
 
 void
-TimeAxisView::show_timestretch (framepos_t start, framepos_t end)
+TimeAxisView::show_timestretch (framepos_t start, framepos_t end, int layers, int layer)
 {
        for (Children::iterator i = children.begin(); i != children.end(); ++i) {
-               (*i)->show_timestretch (start, end);
+               (*i)->show_timestretch (start, end, layers, layer);
        }
 }
 
@@ -1092,7 +1085,8 @@ TimeAxisView::compute_heights ()
        Button* buttons[5];
        const int border_width = 2;
 
-       extra_height = (2 * border_width);
+       const int separator_height = 2;
+       extra_height = (2 * border_width) + separator_height;
 
        window.add (one_row_table);
 
@@ -1117,8 +1111,7 @@ TimeAxisView::compute_heights ()
        Gtk::Requisition req(one_row_table.size_request ());
 
        // height required to show 1 row of buttons
-
-       small_height = req.height + (2 * border_width);
+       button_height = req.height;
 }
 
 void
@@ -1197,10 +1190,10 @@ TimeAxisView::color_handler ()
  * TimeAxisView is non-0 if this object covers y, or one of its children does.
  * If the covering object is a child axis, then the child is returned.
  * TimeAxisView is 0 otherwise.
- * Layer index is the layer number if the TimeAxisView is valid and is in stacked
- * region display mode, otherwise 0.
+ * Layer index is the layer number (possibly fractional) if the TimeAxisView is valid
+ * and is in stacked or expanded * region display mode, otherwise 0.
  */
-std::pair<TimeAxisView*, layer_t>
+std::pair<TimeAxisView*, double>
 TimeAxisView::covers_y_position (double y)
 {
        if (hidden()) {
@@ -1210,15 +1203,30 @@ TimeAxisView::covers_y_position (double y)
        if (_y_position <= y && y < (_y_position + height)) {
 
                /* work out the layer index if appropriate */
-               layer_t l = 0;
-               if (layer_display () == Stacked && view ()) {
-                       /* compute layer */
-                       l = layer_t ((_y_position + height - y) / (view()->child_height ()));
-                       /* clamp to max layers to be on the safe side; sometimes the above calculation
-                         returns a too-high value */
-                       if (l >= view()->layers ()) {
-                               l = view()->layers() - 1;
+               double l = 0;
+               switch (layer_display ()) {
+               case Overlaid:
+                       break;
+               case Stacked:
+                       if (view ()) {
+                               /* compute layer */
+                               l = layer_t ((_y_position + height - y) / (view()->child_height ()));
+                               /* clamp to max layers to be on the safe side; sometimes the above calculation
+                                  returns a too-high value */
+                               if (l >= view()->layers ()) {
+                                       l = view()->layers() - 1;
+                               }
+                       }
+                       break;
+               case Expanded:
+                       if (view ()) {
+                               int const n = floor ((_y_position + height - y) / (view()->child_height ()));
+                               l = n * 0.5 - 0.5;
+                               if (l >= (view()->layers() - 0.5)) {
+                                       l = view()->layers() - 0.5;
+                               }
                        }
+                       break;
                }
 
                return std::make_pair (this, l);
@@ -1241,15 +1249,15 @@ TimeAxisView::preset_height (Height h)
 {
        switch (h) {
        case HeightLargest:
-               return extra_height + 48 + 250;
+               return (button_height * 2) + extra_height + 260;
        case HeightLarger:
-               return extra_height + 48 + 150;
+               return (button_height * 2) + extra_height + 160;
        case HeightLarge:
-               return extra_height + 48 + 50;
+               return (button_height * 2) + extra_height + 60;
        case HeightNormal:
-               return extra_height + 48;
+               return (button_height * 2) + extra_height + 10;
        case HeightSmall:
-               return small_height;
+               return button_height + extra_height;
        }
 
        /* NOTREACHED */
@@ -1299,10 +1307,37 @@ TimeAxisView::reset_visual_state ()
        /* this method is not required to trigger a global redraw */
 
        string str = gui_property ("height");
-
+       
        if (!str.empty()) {
                set_height (atoi (str));
        } else {
                set_height (preset_height (HeightNormal));
        }
 }
+
+TrackViewList
+TrackViewList::filter_to_unique_playlists ()
+{
+       std::set<boost::shared_ptr<ARDOUR::Playlist> > playlists;
+       TrackViewList ts;
+
+       for (iterator i = begin(); i != end(); ++i) {
+               RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*i);
+               if (!rtav) {
+                       /* not a route: include it anyway */
+                       ts.push_back (*i);
+               } else {
+                       boost::shared_ptr<ARDOUR::Track> t = rtav->track();
+                       if (t) {
+                               if (playlists.insert (t->playlist()).second) {
+                                       /* playlist not seen yet */
+                                       ts.push_back (*i);
+                               }
+                       } else {
+                               /* not a track: include it anyway */
+                               ts.push_back (*i);
+                       }
+               }
+       }
+       return ts;
+}