3 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "bcsignals.h"
23 #include "timelinepane.h"
24 #include "localsession.h"
25 #include "maincursor.h"
28 #include "mwindowgui.h"
30 #include "samplescroll.h"
34 #include "trackcanvas.h"
35 #include "trackscroll.h"
38 // coordinates are relative to the main window
39 TimelinePane::TimelinePane(MWindow *mwindow,
46 // printf("TimelinePane::TimelinePane %d number=%d %d %d %d %d\n",
53 this->mwindow = mwindow;
54 this->number = number;
66 TimelinePane::~TimelinePane()
76 void TimelinePane::create_objects()
78 this->gui = mwindow->gui;
79 mwindow->theme->get_pane_sizes(gui,
89 cursor = new MainCursor(mwindow, this);
90 cursor->create_objects();
91 // printf("TimelinePane::create_objects %d number=%d x=%d y=%d w=%d h=%d view_x=%d view_w=%d\n",
102 gui->add_subwindow(canvas = new TrackCanvas(mwindow,
108 canvas->create_objects();
110 if(number == TOP_LEFT_PANE ||
111 number == BOTTOM_LEFT_PANE)
116 if(number == TOP_LEFT_PANE)
118 patchbay_y += mwindow->theme->mtimebar_h;
119 patchbay_h -= mwindow->theme->mtimebar_h;
122 gui->add_subwindow(patchbay = new PatchBay(mwindow,
126 mwindow->theme->patchbay_w,
128 patchbay->create_objects();
131 if(number == TOP_LEFT_PANE ||
132 number == TOP_RIGHT_PANE)
134 int timebar_w = view_w;
135 // Overlap right scrollbar
136 if(gui->total_panes() == 1 ||
137 number == TOP_RIGHT_PANE)
138 timebar_w += BC_ScrollBar::get_span(SCROLL_VERT);
140 gui->add_subwindow(timebar = new MTimeBar(mwindow,
145 mwindow->theme->mtimebar_h));
146 timebar->create_objects();
149 create_sample_scroll(view_x, view_y, view_w, view_h);
151 create_track_scroll(view_x, view_y, view_w, view_h);
156 void TimelinePane::resize_event(int x, int y, int w, int h)
162 mwindow->theme->get_pane_sizes(
173 // printf("TimelinePane::resize_event %d number=%d x=%d y=%d w=%d h=%d view_x=%d view_y=%d view_w=%d view_h=%d\n",
187 int timebar_w = view_w;
188 // Overlap right scrollbar
189 if(gui->total_panes() == 1 ||
190 (gui->total_panes() == 2 &&
191 (number == TOP_LEFT_PANE ||
192 number == BOTTOM_LEFT_PANE)) ||
193 number == TOP_RIGHT_PANE ||
194 number == BOTTOM_RIGHT_PANE)
195 timebar_w += BC_ScrollBar::get_span(SCROLL_VERT);
196 timebar->resize_event(view_x,
199 mwindow->theme->mtimebar_h);
207 if(number == TOP_LEFT_PANE)
209 patchbay_y += mwindow->theme->mtimebar_h;
210 patchbay_h -= mwindow->theme->mtimebar_h;
216 patchbay->resize_event(x,
218 mwindow->theme->patchbay_w,
224 if(gui->pane[TOP_LEFT_PANE] &&
225 gui->pane[BOTTOM_LEFT_PANE] &&
226 (number == TOP_LEFT_PANE ||
227 number == TOP_RIGHT_PANE))
234 samplescroll->resize_event(view_x,
237 samplescroll->set_position();
241 create_sample_scroll(view_x, view_y, view_w, view_h);
245 if(gui->pane[TOP_LEFT_PANE] &&
246 gui->pane[TOP_RIGHT_PANE] &&
247 (number == TOP_LEFT_PANE ||
248 number == BOTTOM_LEFT_PANE))
255 trackscroll->resize_event(view_x + view_w,
258 trackscroll->set_position();
262 create_track_scroll(view_x, view_y, view_w, view_h);
264 canvas->reposition_window(view_x, view_y, view_w, view_h);
265 canvas->resize_event();
268 void TimelinePane::create_sample_scroll(int view_x, int view_y, int view_w, int view_h)
270 //printf("TimelinePane::create_sample_scroll %d %d\n", __LINE__, number);
271 if(number == BOTTOM_LEFT_PANE ||
272 number == BOTTOM_RIGHT_PANE ||
273 (gui->total_panes() == 2 &&
274 gui->pane[TOP_LEFT_PANE] &&
275 gui->pane[TOP_RIGHT_PANE]) ||
276 gui->total_panes() == 1)
278 //printf("TimelinePane::create_sample_scroll %d %d %d\n", __LINE__, y, h);
279 gui->add_subwindow(samplescroll = new SampleScroll(mwindow,
282 y + h - BC_ScrollBar::get_span(SCROLL_VERT),
284 samplescroll->set_position();
288 void TimelinePane::create_track_scroll(int view_x, int view_y, int view_w, int view_h)
290 if(number == TOP_RIGHT_PANE ||
291 number == BOTTOM_RIGHT_PANE ||
292 gui->vertical_panes() ||
293 gui->total_panes() == 1)
295 gui->add_subwindow(trackscroll = new TrackScroll(mwindow,
300 trackscroll->set_position();
305 void TimelinePane::update(int scrollbars,
310 if(timebar && this->timebar) this->timebar->update(0);
312 if(samplescroll && this->samplescroll) samplescroll->set_position();
313 if(trackscroll && this->trackscroll) trackscroll->set_position();
315 if(patchbay && this->patchbay) this->patchbay->update();
317 if( do_canvas != NO_DRAW ) {
318 this->canvas->draw(do_canvas, 1);
319 this->cursor->show();
320 this->canvas->flash(0);
321 // Activate causes the menubar to deactivate. Don't want this for
323 // if(do_canvas != IGNORE_THREAD) this->canvas->activate();
327 void TimelinePane::activate()
330 gui->focused_pane = number;
333 Track *TimelinePane::over_track()
335 int canvas_x = canvas->get_relative_cursor_x();
336 if( canvas_x < 0 || canvas_x >= canvas->get_w() ) return 0;
337 int canvas_y = canvas->get_relative_cursor_y();
338 if( canvas_y < 0 || canvas_y >= canvas->get_h() ) return 0;
339 int pane_y = canvas_y + mwindow->edl->local_session->track_start[number];
340 for( Track *track=mwindow->edl->tracks->first; track; track=track->next ) {
341 int track_y = track->y_pixel;
342 if( pane_y < track_y ) continue;
343 track_y += track->vertical_span(mwindow->theme);
344 if( pane_y < track_y )
351 Track *TimelinePane::over_patchbay()
353 if( !patchbay ) return 0;
354 int patch_x = patchbay->get_relative_cursor_x() ;
355 if( patch_x < 0 || patch_x >= patchbay->get_w() ) return 0;
356 int patch_y = patchbay->get_relative_cursor_y();
357 if( patch_y < 0 || patch_y >= patchbay->get_h() ) return 0;
358 // int canvas_x = patch_x + patchbay->get_x() - canvas->get_x();
359 int canvas_y = patch_y + patchbay->get_y() - canvas->get_y();
360 int pane_y = canvas_y + mwindow->edl->local_session->track_start[number];
361 for( Track *track=mwindow->edl->tracks->first; track; track=track->next ) {
362 int track_y = track->y_pixel;
363 if( pane_y < track_y ) continue;
364 track_y += track->vertical_span(mwindow->theme);
365 if( pane_y < track_y )