Added support for exporting mp4 chapter marks
[ardour.git] / gtk2_ardour / marker.cc
index 0242ab98b71689c9a21557a90a071f48d0f72f36..5ef7549a9fcc35eeb9413a4f6a87ca5a7e683184 100644 (file)
 #include "ardour/tempo.h"
 
 #include "canvas/rectangle.h"
-#include "canvas/group.h"
+#include "canvas/container.h"
 #include "canvas/line.h"
 #include "canvas/polygon.h"
 #include "canvas/text.h"
 #include "canvas/canvas.h"
+#include "canvas/scroll_group.h"
 #include "canvas/debug.h"
 
 #include "ardour_ui.h"
 
 using namespace std;
 using namespace ARDOUR;
+using namespace ARDOUR_UI_UTILS;
 using namespace Gtkmm2ext;
 
 PBD::Signal1<void,Marker*> Marker::CatchDeletion;
 
-static const double marker_height = 13.0;
+static double marker_height = 13.0;
 
-Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, const string& annotation,
+void Marker::setup_sizes(const double timebar_height)
+{
+       marker_height = floor (timebar_height) - 2;
+}
+
+Marker::Marker (PublicEditor& ed, ArdourCanvas::Container& parent, guint32 rgba, const string& annotation,
                Type type, framepos_t frame, bool handle_events)
 
        : editor (ed)
        , _parent (&parent)
-       , _time_bars_line (0)
        , _track_canvas_line (0)
        , _type (type)
        , _selected (false)
@@ -69,73 +75,78 @@ Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, con
        , _label_offset (0)
 
 {
-       /* Shapes we use:
-
-         Mark:
-
-          (0,0) -> (6,0)
-            ^        |
-            |        V
-           (0,5)    (6,5)
-              \    /
-               (3,marker_height)
-
-
-          TempoMark:
-          MeterMark:
-
-               (3,0)
-              /      \
-          (0,5) -> (6,5)
-            ^        |
-            |        V
-           (0,10)<-(6,10)
-
 
-           Start:
-
-          0,0\
-                   |  \
-            |   \ 6,6
-           |   /
-            |  /
-           0,12
-
-          End:
-
-              /12,0
-             /     |
-             /      |
-          6,6      |
-             \      |
-              \     |
-               \    |
-              12,12
-
-             PunchIn:
-
-            0,0 ------> marker_height,0
-             |       /
-             |      /
-             |     /
-             |    /
-             |   /
-             |  /
-            0,marker_height
-
-            PunchOut
-
-          0,0 -->-marker_height,0
-           \       |
-            \      |
-             \     |
-              \    |
-               \   |
-                \  |
-                marker_height,marker_height
-
-
-       */
+       const double MH = marker_height - 1;
+       /* Shapes we use:
+        *
+        * Mark:
+        *
+        *  (0,0)   ->  (6,0)
+        *    ^           |
+        *    |           V
+        * (0,MH*.4)  (6,MH*.4)
+        *     \         /
+        *        (3,MH)
+        *
+        *
+        * TempoMark:
+        * MeterMark:
+        *
+        *        (3,0)
+        *     /         \
+        * (0,MH*.6)  (6,MH.*.6)
+        *    ^           |
+        *    |           V
+        * (0,MH)   <-  (6,MH)
+        *
+        *
+        * SessionStart:
+        * RangeStart:
+        *
+        *       0,0\
+        *        |  \
+        *        |   \ 6,MH/2
+        *        |   /
+        *        |  /
+        *       0,MH
+        *
+        *
+        * SessionEnd:
+        * RangeEnd:
+        *
+        *         /12,0
+        *        /   |
+        * 6,MH/2/    |
+        *       \    |
+        *        \   |
+        *         \12,MH
+        *
+        *
+        * PunchIn:
+        *
+        *   0,0 ------> marker_height,0
+        *    |       /
+        *    |      /
+        *    |     /
+        *    |    /
+        *    |   /
+        *    |  /
+        *   0,marker_height
+        *
+        *
+        *   PunchOut
+        *
+        *   0,0 ------> marker_height,0
+        *    \        |
+        *     \       |
+        *      \      |
+        *       \     |
+        *        \    |
+        *         \   |
+        *          \  |
+        *   marker_height,marker_height
+        *
+        */
 
        switch (type) {
        case Mark:
@@ -143,24 +154,23 @@ Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, con
 
                points->push_back (ArdourCanvas::Duple (0.0, 0.0));
                points->push_back (ArdourCanvas::Duple (6.0, 0.0));
-               points->push_back (ArdourCanvas::Duple (6.0, 5.0));
-               points->push_back (ArdourCanvas::Duple (3.0, marker_height));
-               points->push_back (ArdourCanvas::Duple (0.0, 5.0));
+               points->push_back (ArdourCanvas::Duple (6.0, MH * .4));
+               points->push_back (ArdourCanvas::Duple (3.0, MH));
+               points->push_back (ArdourCanvas::Duple (0.0, MH * .4));
                points->push_back (ArdourCanvas::Duple (0.0, 0.0));
 
                _shift = 3;
-               _label_offset = 8.0;
+               _label_offset = 10.0;
                break;
 
        case Tempo:
        case Meter:
-
                points = new ArdourCanvas::Points ();
                points->push_back (ArdourCanvas::Duple (3.0, 0.0));
-               points->push_back (ArdourCanvas::Duple (6.0, 5.0));
-               points->push_back (ArdourCanvas::Duple (6.0, 10.0));
-               points->push_back (ArdourCanvas::Duple (0.0, 10.0));
-               points->push_back (ArdourCanvas::Duple (0.0, 5.0));
+               points->push_back (ArdourCanvas::Duple (6.0, MH * .6));
+               points->push_back (ArdourCanvas::Duple (6.0, MH));
+               points->push_back (ArdourCanvas::Duple (0.0, MH));
+               points->push_back (ArdourCanvas::Duple (0.0, MH * .6));
                points->push_back (ArdourCanvas::Duple (3.0, 0.0));
 
                _shift = 3;
@@ -169,27 +179,26 @@ Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, con
 
        case SessionStart:
        case RangeStart:
-
-               points = new ArdourCanvas::Points ();
+               points = new ArdourCanvas::Points ();
                points->push_back (ArdourCanvas::Duple (0.0, 0.0));
-               points->push_back (ArdourCanvas::Duple (6.5, 6.5));
-               points->push_back (ArdourCanvas::Duple (0.0, marker_height));
+               points->push_back (ArdourCanvas::Duple (6.5, MH * .5));
+               points->push_back (ArdourCanvas::Duple (0.0, MH));
                points->push_back (ArdourCanvas::Duple (0.0, 0.0));
 
                _shift = 0;
-               _label_offset = marker_height;
+               _label_offset = 8.0;
                break;
 
        case SessionEnd:
        case RangeEnd:
                points = new ArdourCanvas::Points ();
-               points->push_back (ArdourCanvas::Duple (6.5, 6.5));
-               points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
-               points->push_back (ArdourCanvas::Duple (marker_height, marker_height));
-               points->push_back (ArdourCanvas::Duple (6.5, 6.5));
+               points->push_back (ArdourCanvas::Duple (6.0, 0.0));
+               points->push_back (ArdourCanvas::Duple (6.0, MH));
+               points->push_back (ArdourCanvas::Duple (0.0, MH * .5));
+               points->push_back (ArdourCanvas::Duple (6.0, 0.0));
 
-               _shift = marker_height;
-               _label_offset = 6.0;
+               _shift = 6.0;
+               _label_offset = 0.0;
                break;
 
        case LoopStart:
@@ -200,7 +209,7 @@ Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, con
                points->push_back (ArdourCanvas::Duple (0.0, 0.0));
 
                _shift = 0;
-               _label_offset = 12.0;
+               _label_offset = marker_height;
                break;
 
        case LoopEnd:
@@ -214,7 +223,7 @@ Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, con
                _label_offset = 0.0;
                break;
 
-       case  PunchIn:
+       case PunchIn:
                points = new ArdourCanvas::Points ();
                points->push_back (ArdourCanvas::Duple (0.0, 0.0));
                points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
@@ -225,11 +234,11 @@ Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, con
                _label_offset = marker_height;
                break;
 
-       case  PunchOut:
+       case PunchOut:
                points = new ArdourCanvas::Points ();
                points->push_back (ArdourCanvas::Duple (0.0, 0.0));
-               points->push_back (ArdourCanvas::Duple (12.0, 0.0));
-               points->push_back (ArdourCanvas::Duple (12.0, 12.0));
+               points->push_back (ArdourCanvas::Duple (marker_height, 0.0));
+               points->push_back (ArdourCanvas::Duple (marker_height, marker_height));
                points->push_back (ArdourCanvas::Duple (0.0, 0.0));
 
                _shift = marker_height;
@@ -242,7 +251,7 @@ Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, con
        unit_position = editor.sample_to_pixel (frame);
        unit_position -= _shift;
 
-       group = new ArdourCanvas::Group (&parent, ArdourCanvas::Duple (unit_position, 0));
+       group = new ArdourCanvas::Container (&parent, ArdourCanvas::Duple (unit_position, 0));
 #ifdef CANVAS_DEBUG
        group->name = string_compose ("Marker::group for %1", annotation);
 #endif 
@@ -275,7 +284,7 @@ Marker::Marker (PublicEditor& ed, ArdourCanvas::Group& parent, guint32 rgba, con
        CANVAS_DEBUG_NAME (_name_item, string_compose ("Marker::_name_item for %1", annotation));
        _name_item->set_font_description (name_font);
        _name_item->set_color (RGBA_TO_UINT (0,0,0,255));
-       _name_item->set_position (ArdourCanvas::Duple (_label_offset, (marker_height / 2.0) - (name_height / 2.0) - 2.0));
+       _name_item->set_position (ArdourCanvas::Duple (_label_offset, (marker_height - name_height - 1) * .5 ));
 
        set_name (annotation.c_str());
 
@@ -299,11 +308,10 @@ Marker::~Marker ()
 
        /* destroying the parent group destroys its contents, namely any polygons etc. that we added */
        delete group;
-       delete _time_bars_line;
        delete _track_canvas_line;
 }
 
-void Marker::reparent(ArdourCanvas::Group & parent)
+void Marker::reparent(ArdourCanvas::Container & parent)
 {
        group->reparent (&parent);
        _parent = &parent;
@@ -328,40 +336,26 @@ Marker::setup_line ()
 {
        if (_shown && (_selected || _line_shown)) {
 
-               if (_time_bars_line == 0) {
+               if (_track_canvas_line == 0) {
 
-                       _time_bars_line = new ArdourCanvas::Line (editor.get_time_bars_group());
-                       _time_bars_line->set_outline_color (ARDOUR_UI::config()->get_canvasvar_EditPoint());
-                       _time_bars_line->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
-                       
-                       _track_canvas_line = new ArdourCanvas::Line (editor.get_track_canvas_group());
-                       _track_canvas_line->set_outline_color (ARDOUR_UI::config()->get_canvasvar_EditPoint());
+                       _track_canvas_line = new ArdourCanvas::Line (editor.get_hscroll_group());
+                       _track_canvas_line->set_outline_color (ARDOUR_UI::config()->color ("edit point"));
                        _track_canvas_line->Event.connect (sigc::bind (sigc::mem_fun (editor, &PublicEditor::canvas_marker_event), group, this));
                }
 
-               ArdourCanvas::Duple g = group->item_to_canvas (ArdourCanvas::Duple (0, 0));
-               ArdourCanvas::Duple d = _time_bars_line->canvas_to_item (ArdourCanvas::Duple (g.x + _shift, 0));
-
-                _time_bars_line->set_x0 (d.x);
-                _time_bars_line->set_x1 (d.x);
-               _time_bars_line->set_y0 (d.y);
-               _time_bars_line->set_y1 (ArdourCanvas::COORD_MAX);
-               _time_bars_line->set_outline_color (_selected ? ARDOUR_UI::config()->get_canvasvar_EditPoint() : _color);
-               _time_bars_line->raise_to_top ();
-               _time_bars_line->show ();
+               ArdourCanvas::Duple g = group->canvas_origin();
+               ArdourCanvas::Duple d = _track_canvas_line->canvas_to_item (ArdourCanvas::Duple (g.x + _shift, 0));
 
-                d = _track_canvas_line->canvas_to_item (ArdourCanvas::Duple (g.x + _shift, 0));
                _track_canvas_line->set_x0 (d.x);
                _track_canvas_line->set_x1 (d.x);
                _track_canvas_line->set_y0 (d.y);
                _track_canvas_line->set_y1 (ArdourCanvas::COORD_MAX);
-               _track_canvas_line->set_outline_color (_selected ? ARDOUR_UI::config()->get_canvasvar_EditPoint() : _color);
+               _track_canvas_line->set_outline_color (_selected ? ARDOUR_UI::config()->color ("edit point") : _color);
                _track_canvas_line->raise_to_top ();
                _track_canvas_line->show ();
 
        } else {
-               if (_time_bars_line) {
-                       _time_bars_line->hide ();
+               if (_track_canvas_line) {
                        _track_canvas_line->hide ();
                }
        }
@@ -422,11 +416,14 @@ Marker::setup_name_display ()
                _name_item->set (_name);
                
                if (label_on_left ()) {
+                       /* adjust right edge of background to fit text */
                        _name_background->set_x0 (_name_item->position().x - 2);
                        _name_background->set_x1 (_name_item->position().x + name_width + _shift);
                } else {
-                       _name_background->set_x0 (_name_item->position().x - _label_offset + 2);
-                       _name_background->set_x1 (_name_item->position().x + name_width);
+                       /* right edge remains at zero (group-relative). Add
+                        * arbitrary 2 pixels of extra padding at the end
+                        */
+                       _name_background->set_x1 (_name_item->position().x + name_width + 2.0);
                }
        }
 
@@ -475,8 +472,7 @@ Marker::set_color_rgba (uint32_t c)
        mark->set_fill_color (_color);
        mark->set_outline_color (_color);
 
-       if (_time_bars_line && !_selected) {
-               _time_bars_line->set_outline_color (_color);
+       if (_track_canvas_line && !_selected) {
                _track_canvas_line->set_outline_color (_color);
        }
 
@@ -517,7 +513,7 @@ Marker::set_right_label_limit (double p)
 
 /***********************************************************************/
 
-TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text,
+TempoMarker::TempoMarker (PublicEditor& editor, ArdourCanvas::Container& parent, guint32 rgba, const string& text,
                          ARDOUR::TempoSection& temp)
        : Marker (editor, parent, rgba, text, Tempo, 0, false),
          _tempo (temp)
@@ -532,7 +528,7 @@ TempoMarker::~TempoMarker ()
 
 /***********************************************************************/
 
-MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Group& parent, guint32 rgba, const string& text,
+MeterMarker::MeterMarker (PublicEditor& editor, ArdourCanvas::Container& parent, guint32 rgba, const string& text,
                          ARDOUR::MeterSection& m)
        : Marker (editor, parent, rgba, text, Meter, 0, false),
          _meter (m)