2 Copyright (C) 2002 Paul Davis
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.
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.
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.
23 #include <ardour/session.h>
26 using namespace ARDOUR;
29 Editor::hscroll_slider_allocate (Gtk::Allocation &alloc)
31 //edit_hscroll_slider_width = alloc->width;
32 //edit_hscroll_slider_height = alloc->height ;
35 track_canvas_scroller.get_hadjustment()->set_upper (session->current_end_frame() / frames_per_unit);
41 Editor::hscroll_slider_expose (GdkEventExpose *ev)
43 GdkRectangle draw_rect;
44 GdkRectangle bar_rect;
45 gint bar_max = edit_hscroll_slider_width - 2;
48 bar_rect.height = edit_hscroll_slider_height - 2;
51 bar_rect.width = (gint) floor (bar_max * ((canvas_width * frames_per_unit) / session->current_end_frame()));
53 if (bar_rect.width > bar_max) {
55 bar_rect.width = bar_max;
57 bar_rect.x = 1 + (gint) floor (bar_max * ((double) leftmost_frame / session->current_end_frame()));
62 bar_rect.width = bar_max;
65 /* make sure we can see the bar at all times, and have enough to do zoom-trim on */
67 bar_rect.width = max ((guint16) (edit_hscroll_edge_width+5), (guint16) bar_rect.width);
69 gdk_rectangle_intersect (&ev->area, &bar_rect, &draw_rect);
71 gtk_paint_box (edit_hscroll_slider.get_style()->gobj(),
72 edit_hscroll_slider.get_window()->gobj(),
76 GTK_WIDGET(edit_hscroll_slider.gobj()),
80 gtk_paint_box (edit_hscroll_slider.get_style()->gobj(),
81 edit_hscroll_slider.get_window()->gobj(),
85 GTK_WIDGET(edit_hscroll_slider.gobj()),
87 bar_rect.x, bar_rect.y, bar_rect.width, bar_rect.height);
94 Editor::hscroll_slider_button_press (GdkEventButton *ev)
100 edit_hscroll_dragging = true;
101 //cerr << "PRESS" << endl;
110 start = (gint) floor (edit_hscroll_slider_width * ((double) leftmost_frame / session->current_end_frame()));
111 width = (gint) floor (edit_hscroll_slider_width * ((canvas_width * frames_per_unit) / session->current_end_frame()));
113 end = start + width - 1;
114 x = (gint) max (0.0, ev->x);
116 if (x >= start && x <= end) {
118 edit_hscroll_drag_last = x;
119 edit_hscroll_dragging = true;
120 edit_hscroll_slider.add_modal_grab();
127 Editor::hscroll_slider_button_release (GdkEventButton *ev)
137 gint bar_max = edit_hscroll_slider_width - 2;
138 jack_nframes_t new_leftmost = 0;
140 //cerr << "RELESAE" << endl;
142 if (edit_hscroll_dragging) {
143 // lets do a tempo redisplay now only, because it is dog slow
144 tempo_map_changed (Change (0));
145 edit_hscroll_dragging = false;
151 start = (gint) floor (bar_max * ((double) leftmost_frame / session->current_end_frame()));
152 width = (gint) floor (bar_max * ((canvas_width * frames_per_unit) / session->current_end_frame()));
154 end = start + width - 1;
155 x = (gint) max (0.0, ev->x);
157 if (!edit_hscroll_dragging) {
159 new_leftmost = (jack_nframes_t) floor (((double) x/bar_max) * session->current_end_frame());
160 reposition_x_origin (new_leftmost);
163 if (edit_hscroll_dragging) {
164 // lets do a tempo redisplay now only, because it is dog slow
165 tempo_map_changed (Change (0));
166 edit_hscroll_dragging = false;
167 edit_hscroll_slider.remove_modal_grab();
174 Editor::hscroll_slider_motion (GdkEventMotion *ev)
177 Gdk::ModifierType state;
178 gint bar_max = edit_hscroll_slider_width - 2;
180 if (!session || !edit_hscroll_dragging) {
184 edit_hscroll_slider.get_window()->get_pointer (x, y, state);
186 jack_nframes_t new_frame;
187 jack_nframes_t frames;
191 distance = x - edit_hscroll_drag_last;
192 fract = fabs (distance) / bar_max;
193 frames = (jack_nframes_t) floor (session->current_end_frame() * fract);
196 if (leftmost_frame < frames) {
199 new_frame = leftmost_frame - frames;
202 if (leftmost_frame > max_frames - frames) {
203 new_frame = max_frames;
205 new_frame = leftmost_frame + frames;
209 if (new_frame != leftmost_frame) {
210 reposition_x_origin (new_frame);
213 edit_hscroll_drag_last = x;
219 Editor::update_hscroller ()
221 //edit_hscroll_slider.queue_draw ();
223 // track_canvas_scroller.get_hadjustment()->set_upper (session->current_end_frame() / frames_per_unit);
224 // track_canvas_scroller.get_hadjustment()->set_value (leftmost_frame/frames_per_unit);
229 Editor::hscroll_left_arrow_button_press (GdkEventButton *ev)
235 start_canvas_autoscroll (-1);
240 Editor::hscroll_right_arrow_button_press (GdkEventButton *ev)
246 start_canvas_autoscroll (1);
251 Editor::hscroll_left_arrow_button_release (GdkEventButton *ev)
257 stop_canvas_autoscroll ();
262 Editor::hscroll_right_arrow_button_release (GdkEventButton *ev)
268 stop_canvas_autoscroll ();