Add API to write raw data to child processes.
[ardour.git] / gtk2_ardour / editor_cursors.cc
index 89d2fcbaa1aa2b4949797d122f9b0bfcf75cdb00..3df7761007a09c46da17b799932c64c2403d58e8 100644 (file)
 #include <cstdlib>
 #include <cmath>
 
-#include <libgnomecanvas/libgnomecanvas.h>
+#include "canvas/canvas.h"
+#include "canvas/debug.h"
+#include "canvas/scroll_group.h"
 
-#include "utils.h"
+#include "editor_cursors.h"
 #include "editor.h"
 
 using namespace ARDOUR;
@@ -30,60 +32,82 @@ using namespace PBD;
 using namespace Gtk;
 
 EditorCursor::EditorCursor (Editor& ed, bool (Editor::*callbck)(GdkEvent*,ArdourCanvas::Item*))
-       : editor (ed),
-         canvas_item (*editor.cursor_group),
-         length(1.0)
+       : _editor (ed)
+       , _track_canvas_item (new ArdourCanvas::Arrow (_editor.get_cursor_scroll_group()))
 {
-       points.push_back(Gnome::Art::Point(-1.0, 0.0)); // first x-coord needs to be a non-normal value
-       points.push_back(Gnome::Art::Point(1.0, 1.0));
-
-       canvas_item.property_points() = points;
-       canvas_item.property_width_pixels() = 1;
-       canvas_item.property_first_arrowhead() = TRUE;
-       canvas_item.property_last_arrowhead() = TRUE;
-       canvas_item.property_arrow_shape_a() = 11.0;
-       canvas_item.property_arrow_shape_b() = 0.0;
-       canvas_item.property_arrow_shape_c() = 9.0;
-
-       canvas_item.set_data ("cursor", this);
-       canvas_item.signal_event().connect (sigc::bind (sigc::mem_fun (ed, callbck), &canvas_item));
-       current_frame = 1; /* force redraw at 0 */
+       CANVAS_DEBUG_NAME (_track_canvas_item, "track canvas editor cursor");
+
+       _track_canvas_item->set_show_head (0, true);
+       _track_canvas_item->set_head_height (0, 9);
+       _track_canvas_item->set_head_width (0, 16);
+       _track_canvas_item->set_head_outward (0, false);
+       _track_canvas_item->set_show_head (1, false); // head only
+       _track_canvas_item->set_data ("cursor", this);
+
+       _track_canvas_item->Event.connect (sigc::bind (sigc::mem_fun (ed, callbck), _track_canvas_item));
+
+       _track_canvas_item->set_y1 (ArdourCanvas::COORD_MAX);
+
+       _track_canvas_item->set_x (0);
+
+       _current_sample = 1; /* force redraw at 0 */
 }
 
-EditorCursor::~EditorCursor ()
+EditorCursor::EditorCursor (Editor& ed)
+       : _editor (ed)
+       , _track_canvas_item (new ArdourCanvas::Arrow (_editor.get_hscroll_group()))
+{
+       CANVAS_DEBUG_NAME (_track_canvas_item, "track canvas cursor");
+
+       _track_canvas_item->set_show_head (0, false);
+       _track_canvas_item->set_show_head (1, false);
+       _track_canvas_item->set_y1 (ArdourCanvas::COORD_MAX);
+       _track_canvas_item->set_ignore_events (true);
+
+       _track_canvas_item->set_x (0);
+
+       _current_sample = 1; /* force redraw at 0 */
+}
 
+EditorCursor::~EditorCursor ()
 {
+       delete _track_canvas_item;
 }
 
 void
-EditorCursor::set_position (nframes64_t frame)
+EditorCursor::set_position (samplepos_t sample)
 {
-       PositionChanged (frame);
+       if (_current_sample != sample) { PositionChanged (sample); }
 
-       double new_pos =  editor.frame_to_unit (frame);
+       double const new_pos = _editor.sample_to_pixel_unrounded (sample);
 
-       if (new_pos != points.front().get_x()) {
+       if (rint(new_pos) != rint(_track_canvas_item->x ())) {
+               _track_canvas_item->set_x (new_pos-0.5);  //accommodate the 1/2 pixel "line" offset in cairo
+       }
 
-               points.front().set_x (new_pos);
-               points.back().set_x (new_pos);
+       _current_sample = sample;
+}
 
-               canvas_item.property_points() = points;
-       }
-       current_frame = frame;
+void
+EditorCursor::show ()
+{
+       _track_canvas_item->show ();
+}
+
+void
+EditorCursor::hide ()
+{
+       _track_canvas_item->hide ();
 }
 
 void
-EditorCursor::set_length (double units)
+EditorCursor::set_color (Gtkmm2ext::Color color)
 {
-       length = units;
-       points.back().set_y (points.front().get_y() + length);
-       canvas_item.property_points() = points;
+       _track_canvas_item->set_color (color);
 }
 
 void
-EditorCursor::set_y_axis (double position)
+EditorCursor::set_sensitive (bool yn)
 {
-        points.front().set_y (position);
-       points.back().set_y (position + length);
-       canvas_item.property_points() = points;
+       _track_canvas_item->set_ignore_events (!yn);
 }