Add API to write raw data to child processes.
[ardour.git] / gtk2_ardour / editor_cursors.cc
index edd300c67c5cef045f2ae3b2264b1ca39fff30f4..3df7761007a09c46da17b799932c64c2403d58e8 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000 Paul Davis 
+    Copyright (C) 2000 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #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 sigc;
 using namespace ARDOUR;
+using namespace PBD;
 using namespace Gtk;
 
-Editor::Cursor::Cursor (Editor& ed, const string& color, GtkSignalFunc callbck)
-       : editor (ed), callback (callbck), length(1.0)
+EditorCursor::EditorCursor (Editor& ed, bool (Editor::*callbck)(GdkEvent*,ArdourCanvas::Item*))
+       : _editor (ed)
+       , _track_canvas_item (new ArdourCanvas::Arrow (_editor.get_cursor_scroll_group()))
 {
-       GnomeCanvasGroup *group;
-       points = gnome_canvas_points_new (2);
-       
-       /* "randomly" initialize coords */
-
-       points->coords[0] = -9383839.0;
-       points->coords[1] = 0.0;
-       points->coords[2] = 1.0;
-       points->coords[3] = 0.0;
-
-       group = GNOME_CANVAS_GROUP (editor.cursor_group);
-
-       // cerr << "set cursor points, nc = " << points->num_points << endl;
-       canvas_item = gnome_canvas_item_new (group,
-                                          gnome_canvas_line_get_type(),
-                                          "points", points,
-                                          "fill_color", color.c_str(),
-                                          "width_pixels", 1,
-                                          "first_arrowhead", (gboolean) TRUE,
-                                          "last_arrowhead", (gboolean) TRUE,
-                                          "arrow_shape_a", 11.0,
-                                          "arrow_shape_b", 0.0,
-                                          "arrow_shape_c", 9.0,
-                                          NULL);
-
-       // cerr << "cursor line @ " << canvas_item << endl;
-
-       gtk_object_set_data (GTK_OBJECT(canvas_item), "cursor", this);
-       gtk_signal_connect (GTK_OBJECT(canvas_item), "event", callback, &editor);
-
-       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 */
 }
 
-Editor::Cursor::~Cursor ()
+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 ()
 {
-       gtk_object_destroy (GTK_OBJECT(canvas_item));
-       gnome_canvas_points_unref (points);
+       delete _track_canvas_item;
 }
 
 void
-Editor::Cursor::set_position (jack_nframes_t frame)
+EditorCursor::set_position (samplepos_t sample)
 {
-       double new_pos =  editor.frame_to_unit (frame);
+       if (_current_sample != sample) { PositionChanged (sample); }
 
-       if (editor.session == 0) {
-               gnome_canvas_item_hide (canvas_item);
-       } else {
-               gnome_canvas_item_show (canvas_item);
-       }
-
-       current_frame = frame;
+       double const new_pos = _editor.sample_to_pixel_unrounded (sample);
 
-       if (new_pos == points->coords[0]) {
+       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
+       }
 
-               /* change in position is not visible, so just raise it */
-               
-               gnome_canvas_item_raise_to_top (canvas_item);
-               return;
-       } 
+       _current_sample = sample;
+}
 
-       points->coords[0] = new_pos;
-       points->coords[2] = new_pos;
+void
+EditorCursor::show ()
+{
+       _track_canvas_item->show ();
+}
 
-       // cerr << "set cursor2 al points, nc = " << points->num_points << endl;
-       gnome_canvas_item_set (canvas_item, "points", points, NULL);
-       gnome_canvas_item_raise_to_top (canvas_item);
+void
+EditorCursor::hide ()
+{
+       _track_canvas_item->hide ();
 }
 
 void
-Editor::Cursor::set_length (double units)
+EditorCursor::set_color (Gtkmm2ext::Color color)
 {
-       length = units; 
-       points->coords[3] = points->coords[1] + length;
-       // cerr << "set cursor3 al points, nc = " << points->num_points << endl;
-       gnome_canvas_item_set (canvas_item, "points", points, NULL);
+       _track_canvas_item->set_color (color);
 }
 
-void 
-Editor::Cursor::set_y_axis (double position)
+void
+EditorCursor::set_sensitive (bool yn)
 {
-       points->coords[1] = position;
-       points->coords[3] = position + length;
-       // cerr << "set cursor4 al points, nc = " << points->num_points << endl;
-       gnome_canvas_item_set (canvas_item, "points", points, NULL);
+       _track_canvas_item->set_ignore_events (!yn);
 }