changes to help strp silence
[ardour.git] / gtk2_ardour / editor_cursors.cc
1 /*
2     Copyright (C) 2000 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <cstdlib>
21 #include <cmath>
22
23 #include <libgnomecanvas/libgnomecanvas.h>
24
25 #include "utils.h"
26 #include "editor.h"
27
28 using namespace ARDOUR;
29 using namespace PBD;
30 using namespace Gtk;
31
32 EditorCursor::EditorCursor (Editor& ed, bool (Editor::*callbck)(GdkEvent*,ArdourCanvas::Item*))
33         : editor (ed),
34           canvas_item (*editor.cursor_group),
35           length(1.0)
36 {
37         points.push_back(Gnome::Art::Point(-1.0, 0.0)); // first x-coord needs to be a non-normal value
38         points.push_back(Gnome::Art::Point(1.0, 1.0));
39
40         canvas_item.property_points() = points;
41         canvas_item.property_width_pixels() = 1;
42         canvas_item.property_first_arrowhead() = TRUE;
43         canvas_item.property_last_arrowhead() = TRUE;
44         canvas_item.property_arrow_shape_a() = 11.0;
45         canvas_item.property_arrow_shape_b() = 0.0;
46         canvas_item.property_arrow_shape_c() = 9.0;
47
48         canvas_item.set_data ("cursor", this);
49         canvas_item.signal_event().connect (sigc::bind (sigc::mem_fun (ed, callbck), &canvas_item));
50         current_frame = 1; /* force redraw at 0 */
51 }
52
53 EditorCursor::~EditorCursor ()
54
55 {
56 }
57
58 void
59 EditorCursor::set_position (nframes64_t frame)
60 {
61         PositionChanged (frame);
62
63         double new_pos =  editor.frame_to_unit (frame);
64
65         if (new_pos != points.front().get_x()) {
66
67                 points.front().set_x (new_pos);
68                 points.back().set_x (new_pos);
69
70                 canvas_item.property_points() = points;
71         }
72         current_frame = frame;
73 }
74
75 void
76 EditorCursor::set_length (double units)
77 {
78         length = units;
79         points.back().set_y (points.front().get_y() + length);
80         canvas_item.property_points() = points;
81 }
82
83 void
84 EditorCursor::set_y_axis (double position)
85 {
86         points.front().set_y (position);
87         points.back().set_y (position + length);
88         canvas_item.property_points() = points;
89 }