rework set default transtion, nested proxy edl fixes, doubleclick proxy media fix...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / timelinepane.C
1 #include "bcsignals.h"
2 #include "edl.h"
3 #include "timelinepane.h"
4 #include "localsession.h"
5 #include "maincursor.h"
6 #include "mtimebar.h"
7 #include "mwindow.h"
8 #include "mwindowgui.h"
9 #include "patchbay.h"
10 #include "samplescroll.h"
11 #include "theme.h"
12 #include "track.h"
13 #include "tracks.h"
14 #include "trackcanvas.h"
15 #include "trackscroll.h"
16
17
18 // coordinates are relative to the main window
19 TimelinePane::TimelinePane(MWindow *mwindow,
20         int number,
21         int x,
22         int y,
23         int w,
24         int h)
25 {
26 // printf("TimelinePane::TimelinePane %d number=%d %d %d %d %d\n",
27 // __LINE__,
28 // number,
29 // x,
30 // y,
31 // w,
32 // h);
33         this->mwindow = mwindow;
34         this->number = number;
35         this->x = x;
36         this->y = y;
37         this->w = w;
38         this->h = h;
39         patchbay = 0;
40         timebar = 0;
41         samplescroll = 0;
42         trackscroll = 0;
43         cursor = 0;
44 }
45
46 TimelinePane::~TimelinePane()
47 {
48         delete canvas;
49         delete cursor;
50         delete patchbay;
51         delete timebar;
52         delete samplescroll;
53         delete trackscroll;
54 }
55
56 void TimelinePane::create_objects()
57 {
58         this->gui = mwindow->gui;
59         mwindow->theme->get_pane_sizes(gui,
60                 &view_x,
61                 &view_y,
62                 &view_w,
63                 &view_h,
64                 number,
65                 x,
66                 y,
67                 w,
68                 h);
69         cursor = new MainCursor(mwindow, this);
70         cursor->create_objects();
71 // printf("TimelinePane::create_objects %d number=%d x=%d y=%d w=%d h=%d view_x=%d view_w=%d\n",
72 // __LINE__,
73 // number,
74 // x,
75 // y,
76 // w,
77 // h,
78 // view_x,
79 // view_w);
80
81
82         gui->add_subwindow(canvas = new TrackCanvas(mwindow,
83                 this,
84                 view_x,
85                 view_y,
86                 view_w,
87                 view_h));
88         canvas->create_objects();
89
90         if(number == TOP_LEFT_PANE ||
91                 number == BOTTOM_LEFT_PANE)
92         {
93                 int patchbay_y = y;
94                 int patchbay_h = h;
95
96                 if(number == TOP_LEFT_PANE)
97                 {
98                         patchbay_y += mwindow->theme->mtimebar_h;
99                         patchbay_h -= mwindow->theme->mtimebar_h;
100                 }
101
102                 gui->add_subwindow(patchbay = new PatchBay(mwindow,
103                         this,
104                         x,
105                         patchbay_y,
106                         mwindow->theme->patchbay_w,
107                         patchbay_h));
108                 patchbay->create_objects();
109         }
110
111         if(number == TOP_LEFT_PANE ||
112                 number == TOP_RIGHT_PANE)
113         {
114                 int timebar_w = view_w;
115 // Overlap right scrollbar
116                 if(gui->total_panes() == 1 ||
117                         number == TOP_RIGHT_PANE)
118                         timebar_w += BC_ScrollBar::get_span(SCROLL_VERT);
119
120                 gui->add_subwindow(timebar = new MTimeBar(mwindow,
121                         this,
122                         view_x,
123                         y,
124                         timebar_w,
125                         mwindow->theme->mtimebar_h));
126                 timebar->create_objects();
127         }
128
129         create_sample_scroll(view_x, view_y, view_w, view_h);
130
131         create_track_scroll(view_x, view_y, view_w, view_h);
132 }
133
134
135
136 void TimelinePane::resize_event(int x, int y, int w, int h)
137 {
138         this->x = x;
139         this->y = y;
140         this->w = w;
141         this->h = h;
142         mwindow->theme->get_pane_sizes(
143                 gui,
144                 &view_x,
145                 &view_y,
146                 &view_w,
147                 &view_h,
148                 number,
149                 x,
150                 y,
151                 w,
152                 h);
153 // 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",
154 // __LINE__,
155 // number,
156 // x,
157 // y,
158 // w,
159 // h,
160 // view_x,
161 // view_y,
162 // view_w,
163 // view_h);
164
165         if(timebar)
166         {
167                 int timebar_w = view_w;
168 // Overlap right scrollbar
169                 if(gui->total_panes() == 1 ||
170                         (gui->total_panes() == 2 &&
171                         (number == TOP_LEFT_PANE ||
172                         number == BOTTOM_LEFT_PANE)) ||
173                         number == TOP_RIGHT_PANE ||
174                         number == BOTTOM_RIGHT_PANE)
175                         timebar_w += BC_ScrollBar::get_span(SCROLL_VERT);
176                 timebar->resize_event(view_x,
177                         y,
178                         timebar_w,
179                         mwindow->theme->mtimebar_h);
180         }
181
182         if(patchbay)
183         {
184                 int patchbay_y = y;
185                 int patchbay_h = h;
186
187                 if(number == TOP_LEFT_PANE)
188                 {
189                         patchbay_y += mwindow->theme->mtimebar_h;
190                         patchbay_h -= mwindow->theme->mtimebar_h;
191                 }
192                 else
193                 {
194                 }
195
196                 patchbay->resize_event(x,
197                         patchbay_y,
198                         mwindow->theme->patchbay_w,
199                         patchbay_h);
200         }
201
202         if(samplescroll)
203         {
204                 if(gui->pane[TOP_LEFT_PANE] &&
205                         gui->pane[BOTTOM_LEFT_PANE] &&
206                         (number == TOP_LEFT_PANE ||
207                                 number == TOP_RIGHT_PANE))
208                 {
209                         delete samplescroll;
210                         samplescroll = 0;
211                 }
212                 else
213                 {
214                         samplescroll->resize_event(view_x,
215                                 view_y + view_h,
216                                 view_w);
217                         samplescroll->set_position();
218                 }
219         }
220         else
221                 create_sample_scroll(view_x, view_y, view_w, view_h);
222
223         if(trackscroll)
224         {
225                 if(gui->pane[TOP_LEFT_PANE] &&
226                         gui->pane[TOP_RIGHT_PANE] &&
227                         (number == TOP_LEFT_PANE ||
228                         number == BOTTOM_LEFT_PANE))
229                 {
230                         delete trackscroll;
231                         trackscroll = 0;
232                 }
233                 else
234                 {
235                         trackscroll->resize_event(view_x + view_w,
236                                 view_y,
237                                 view_h);
238                         trackscroll->set_position();
239                 }
240         }
241         else
242                 create_track_scroll(view_x, view_y, view_w, view_h);
243
244         canvas->reposition_window(view_x, view_y, view_w, view_h);
245         canvas->resize_event();
246 }
247
248 void TimelinePane::create_sample_scroll(int view_x, int view_y, int view_w, int view_h)
249 {
250 //printf("TimelinePane::create_sample_scroll %d %d\n", __LINE__, number);
251         if(number == BOTTOM_LEFT_PANE ||
252                 number == BOTTOM_RIGHT_PANE ||
253                 (gui->total_panes() == 2 &&
254                         gui->pane[TOP_LEFT_PANE] &&
255                         gui->pane[TOP_RIGHT_PANE]) ||
256                 gui->total_panes() == 1)
257         {
258 //printf("TimelinePane::create_sample_scroll %d %d %d\n", __LINE__, y, h);
259                 gui->add_subwindow(samplescroll = new SampleScroll(mwindow,
260                         this,
261                         view_x,
262                         y + h - BC_ScrollBar::get_span(SCROLL_VERT),
263                         view_w));
264                 samplescroll->set_position();
265         }
266 }
267
268 void TimelinePane::create_track_scroll(int view_x, int view_y, int view_w, int view_h)
269 {
270         if(number == TOP_RIGHT_PANE ||
271                 number == BOTTOM_RIGHT_PANE ||
272                 gui->vertical_panes() ||
273                 gui->total_panes() == 1)
274         {
275                 gui->add_subwindow(trackscroll = new TrackScroll(mwindow,
276                         this,
277                         view_x + view_w,
278                         view_y,
279                         view_h));
280                 trackscroll->set_position();
281         }
282 }
283
284
285 void TimelinePane::update(int scrollbars,
286         int do_canvas,
287         int timebar,
288         int patchbay)
289 {
290         if(timebar && this->timebar) this->timebar->update(0);
291         if(scrollbars)
292         {
293                 if(samplescroll && this->samplescroll) samplescroll->set_position();
294                 if(trackscroll && this->trackscroll) trackscroll->set_position();
295         }
296         if(patchbay && this->patchbay) this->patchbay->update();
297
298         if(do_canvas)
299         {
300                 this->canvas->draw(do_canvas, 1);
301                 this->cursor->show();
302                 this->canvas->flash(0);
303 // Activate causes the menubar to deactivate.  Don't want this for
304 // picon thread.
305 //              if(do_canvas != IGNORE_THREAD) this->canvas->activate();
306         }
307 }
308
309 void TimelinePane::activate()
310 {
311         canvas->activate();
312         gui->focused_pane = number;
313 }
314
315 Track *TimelinePane::over_track()
316 {
317         int canvas_x = canvas->get_relative_cursor_x();
318         if( canvas_x < 0 || canvas_x >= canvas->get_w() ) return 0;
319         int canvas_y = canvas->get_relative_cursor_y();
320         if( canvas_y < 0 || canvas_y >= canvas->get_h() ) return 0;
321         int pane_y = canvas_y + mwindow->edl->local_session->track_start[number];
322         for( Track *track=mwindow->edl->tracks->first; track; track=track->next ) {
323                 int track_y = track->y_pixel;
324                 if( pane_y < track_y ) continue;
325                 track_y += track->vertical_span(mwindow->theme);
326                 if( pane_y < track_y )
327                         return track;
328         }
329
330         return 0;
331 }
332
333 Track *TimelinePane::over_patchbay()
334 {
335         if( !patchbay ) return 0;
336         int patch_x = patchbay->get_relative_cursor_x() ;
337         if( patch_x < 0 || patch_x >= patchbay->get_w() ) return 0;
338         int patch_y = patchbay->get_relative_cursor_y();
339         if( patch_y < 0 || patch_y >= patchbay->get_h() ) return 0;
340 //      int canvas_x = patch_x + patchbay->get_x() - canvas->get_x();
341         int canvas_y = patch_y + patchbay->get_y() - canvas->get_y();
342         int pane_y = canvas_y + mwindow->edl->local_session->track_start[number];
343         for( Track *track=mwindow->edl->tracks->first; track; track=track->next ) {
344                 int track_y = track->y_pixel;
345                 if( pane_y < track_y ) continue;
346                 track_y += track->vertical_span(mwindow->theme);
347                 if( pane_y < track_y )
348                         return track;
349         }
350
351         return 0;
352 }
353