fix ruler, cwdw info popup updates, reset camera/projector shortcuts, findobj tweak...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / mwindowgui.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "androidcontrol.h"
23 #include "awindowgui.h"
24 #include "awindow.h"
25 #include "bcdisplayinfo.h"
26 #include "bchash.h"
27 #include "bcsignals.h"
28 #include "clip.h"
29 #include "cwindowgui.h"
30 #include "cwindow.h"
31 #include "channelinfo.h"
32 #include "dbwindow.h"
33 #include "edit.h"
34 #include "editpopup.h"
35 #include "edits.h"
36 #include "edl.h"
37 #include "edlsession.h"
38 #include "filesystem.h"
39 #include "keyframepopup.h"
40 #include "keys.h"
41 #include "language.h"
42 #include "localsession.h"
43 #include "mainclock.h"
44 #include "maincursor.h"
45 #include "mainmenu.h"
46 #include "mainsession.h"
47 #include "mainundo.h"
48 #include "mbuttons.h"
49 #include "mtimebar.h"
50 #include "mwindowgui.h"
51 #include "mwindow.h"
52 #include "panedividers.h"
53 #include "patchbay.h"
54 #include "plugin.h"
55 #include "pluginpopup.h"
56 #include "pluginset.h"
57 #include "preferences.h"
58 #include "record.h"
59 #include "recordgui.h"
60 #include "renderengine.h"
61 #include "resourcethread.h"
62 #include "samplescroll.h"
63 #include "shbtnprefs.h"
64 #include "statusbar.h"
65 #include "swindow.h"
66 #include "theme.h"
67 #include "trackcanvas.h"
68 #include "trackscroll.h"
69 #include "tracks.h"
70 #include "transitionpopup.h"
71 #include "vwindowgui.h"
72 #include "vwindow.h"
73 #include "zoombar.h"
74
75 #define PANE_DRAG_MARGIN MAX(mwindow->theme->pane_w, mwindow->theme->pane_h)
76
77
78 // the main window uses its own private colormap for video
79 MWindowGUI::MWindowGUI(MWindow *mwindow)
80  : BC_Window(_(PROGRAM_NAME ": Program"),
81                 mwindow->session->mwindow_x,
82                 mwindow->session->mwindow_y,
83                 mwindow->session->mwindow_w,
84                 mwindow->session->mwindow_h,
85                 100,
86                 100,
87                 1,
88                 1,
89                 1)
90 {
91         this->mwindow = mwindow;
92 //      samplescroll = 0;
93 //      trackscroll = 0;
94 //      cursor = 0;
95 //      patchbay = 0;
96 //      timebar = 0;
97 //      canvas = 0;
98         focused_pane = TOP_LEFT_PANE;
99         x_divider = 0;
100         y_divider = 0;
101         x_pane_drag = 0;
102         y_pane_drag = 0;
103         dragging_pane = 0;
104         drag_popup = 0;
105
106         render_engine = 0;
107         for(int i = 0; i < TOTAL_PANES; i++)
108                 pane[i] = 0;
109
110         record = 0;
111         channel_info = 0;
112         swindow = 0;
113         db_window = 0;
114 // subwindows
115         mbuttons = 0;
116         statusbar = 0;
117         zoombar = 0;
118         mainclock = 0;
119         edit_menu = 0;
120         plugin_menu = 0;
121         keyframe_menu = 0;
122         keyframe_hide = 0;
123         keyvalue_popup = 0;
124         transition_menu = 0;
125         remote_control = 0;
126         cwindow_remote_handler = 0;
127         record_remote_handler = 0;
128         android_control = 0;
129 }
130
131
132 MWindowGUI::~MWindowGUI()
133 {
134         delete android_control;
135         delete cwindow_remote_handler;
136         delete record_remote_handler;
137         delete remote_control;
138         delete keyvalue_popup;
139 //      delete samplescroll;
140 //      delete trackscroll;
141         for(int i = 0; i < TOTAL_PANES; i++)
142                 if(pane[i]) delete pane[i];
143 //      delete cursor;
144         delete render_engine;
145         delete resource_thread;
146         resource_pixmaps.remove_all_objects();
147         delete swindow;
148 #ifdef HAVE_DVB
149         delete channel_info;
150 #endif
151         delete db_window;
152         delete x_divider;
153         delete y_divider;
154 }
155
156 #if 0
157 void MWindowGUI::get_scrollbars(int flush)
158 {
159         //int64_t h_needed = mwindow->edl->get_tracks_height(mwindow->theme);
160         //int64_t w_needed = mwindow->edl->get_tracks_width();
161         int need_xscroll = 0;
162         int need_yscroll = 0;
163         view_w = mwindow->theme->mcanvas_w;
164         view_h = mwindow->theme->mcanvas_h;
165
166 // Scrollbars are constitutive
167         need_xscroll = need_yscroll = 1;
168         view_h = mwindow->theme->mcanvas_h;
169         view_w = mwindow->theme->mcanvas_w;
170
171 //      for(int i = 0; i < 2; i++)
172 //      {
173 //              if(w_needed > view_w)
174 //              {
175 //                      need_xscroll = 1;
176 //                      view_h = mwindow->theme->mcanvas_h - SCROLL_SPAN;
177 //              }
178 //              else
179 //                      need_xscroll = 0;
180 //
181 //              if(h_needed > view_h)
182 //              {
183 //                      need_yscroll = 1;
184 //                      view_w = mwindow->theme->mcanvas_w - SCROLL_SPAN;
185 //              }
186 //              else
187 //                      need_yscroll = 0;
188 //      }
189 //printf("MWindowGUI::get_scrollbars 1\n");
190
191         if(canvas && (view_w != canvas->get_w() || view_h != canvas->get_h()))
192         {
193                 canvas->reposition_window(mwindow->theme->mcanvas_x,
194                         mwindow->theme->mcanvas_y,
195                         view_w,
196                         view_h);
197         }
198
199         if(need_xscroll)
200         {
201                 if(!samplescroll)
202                         add_subwindow(samplescroll = new SampleScroll(mwindow,
203                                 this,
204                                 mwindow->theme->mhscroll_x,
205                                 mwindow->theme->mhscroll_y,
206                                 mwindow->theme->mhscroll_w));
207                 else
208                         samplescroll->resize_event();
209
210                 samplescroll->set_position(0);
211         }
212         else
213         {
214                 if(samplescroll) delete samplescroll;
215                 samplescroll = 0;
216                 mwindow->edl->local_session->view_start = 0;
217         }
218
219
220         if(need_yscroll)
221         {
222 //printf("MWindowGUI::get_scrollbars 1.1 %p %p\n", this, canvas);
223                 if(!trackscroll)
224                         add_subwindow(trackscroll = new TrackScroll(mwindow,
225                                 this,
226                                 mwindow->theme->mvscroll_x,
227                                 mwindow->theme->mvscroll_y,
228                                 mwindow->theme->mvscroll_h));
229                 else
230                         trackscroll->resize_event();
231
232
233 //printf("MWindowGUI::get_scrollbars 1.2\n");
234                 trackscroll->update_length(mwindow->edl->get_tracks_height(mwindow->theme),
235                         mwindow->edl->local_session->track_start,
236                         view_h,
237                         0);
238 //printf("MWindowGUI::get_scrollbars 1.3\n");
239         }
240         else
241         {
242                 if(trackscroll) delete trackscroll;
243                 trackscroll = 0;
244                 mwindow->edl->local_session->track_start = 0;
245         }
246
247         if(flush) this->flush();
248
249 }
250 #endif // 0
251
252 void MWindowGUI::create_objects()
253 {
254         const int debug = 0;
255
256         resource_thread = new ResourceThread(mwindow, this);
257         resource_thread->create_objects();
258
259
260         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
261         set_icon(mwindow->theme->get_image("mwindow_icon"));
262         remote_control = new RemoteControl(this);
263         cwindow_remote_handler = new CWindowRemoteHandler(remote_control);
264         record_remote_handler = new RecordRemoteHandler(remote_control);
265         mwindow->reset_android_remote();
266
267         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
268
269         int x = get_w() - MainShBtns::calculate_w(0);
270         add_subwindow(mainmenu = new MainMenu(mwindow, this, x));
271         mainmenu->create_objects();
272         add_subwindow(mainshbtns = new MainShBtns(mwindow, x, -1));
273         mainshbtns->load(mwindow->preferences);
274         mwindow->theme->get_mwindow_sizes(this, get_w(), get_h());
275         mwindow->theme->draw_mwindow_bg(this);
276         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
277
278         add_subwindow(mbuttons = new MButtons(mwindow, this));
279         mbuttons->create_objects();
280         add_subwindow(ffmpeg_toggle = new FFMpegToggle(mwindow, mbuttons, menu_w(), menu_h()+2));
281
282         pane[TOP_LEFT_PANE] = new TimelinePane(mwindow,
283                 TOP_LEFT_PANE,
284                 mwindow->theme->mcanvas_x,
285                 mwindow->theme->mcanvas_y,
286                 mwindow->theme->mcanvas_w,
287                 mwindow->theme->mcanvas_h);
288         pane[TOP_LEFT_PANE]->create_objects();
289
290 //      add_subwindow(timebar = new MTimeBar(mwindow,
291 //              this,
292 //              mwindow->theme->mtimebar_x,
293 //              mwindow->theme->mtimebar_y,
294 //              mwindow->theme->mtimebar_w,
295 //              mwindow->theme->mtimebar_h));
296 //      timebar->create_objects();
297
298 //      if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
299 //      add_subwindow(patchbay = new PatchBay(mwindow, this));
300 //      patchbay->create_objects();
301
302 //      if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
303 //      get_scrollbars(0);
304
305 //      if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
306 //      mwindow->gui->add_subwindow(canvas = new TrackCanvas(mwindow, this));
307 //      canvas->create_objects();
308
309
310         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
311         add_subwindow(zoombar = new ZoomBar(mwindow, this));
312         zoombar->create_objects();
313
314
315         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
316         add_subwindow(statusbar = new StatusBar(mwindow, this));
317         statusbar->create_objects();
318
319
320
321         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
322         add_subwindow(mainclock = new MainClock(mwindow,
323                 mwindow->theme->mclock_x, mwindow->theme->mclock_y,
324                 mwindow->theme->mclock_w));
325         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
326         mainclock->update(0);
327
328
329
330 //      if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
331 //      cursor = new MainCursor(mwindow, this);
332 //      cursor->create_objects();
333
334
335         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
336         add_subwindow(edit_menu = new EditPopup(mwindow, this));
337         edit_menu->create_objects();
338
339
340         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
341         add_subwindow(plugin_menu = new PluginPopup(mwindow, this));
342         plugin_menu->create_objects();
343
344
345         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
346         add_subwindow(keyframe_menu = new KeyframePopup(mwindow, this));
347         keyframe_menu->create_objects();
348         add_subwindow(keyframe_hide = new KeyframeHidePopup(mwindow, this));
349         keyframe_hide->create_objects();
350
351
352         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
353         add_subwindow(transition_menu = new TransitionPopup(mwindow, this));
354         transition_menu->create_objects();
355
356 #ifdef HAVE_DVB
357         channel_info = new ChannelInfo(mwindow);
358 #endif
359         db_window = new DbWindow(mwindow);
360         swindow = new SWindow(mwindow);
361
362         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
363
364         add_subwindow(pane_button = new PaneButton(mwindow,
365                 get_w() - mwindow->theme->get_image_set("pane")[0]->get_w(),
366                 mwindow->theme->mzoom_y + 1 - mwindow->theme->get_image_set("pane")[0]->get_h()));
367
368         pane[TOP_LEFT_PANE]->canvas->activate();
369
370         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
371 }
372
373 void MWindowGUI::redraw_time_dependancies()
374 {
375         zoombar->redraw_time_dependancies();
376         for(int i = 0; i < TOTAL_PANES; i++)
377                 if(pane[i] && pane[i]->timebar) pane[i]->timebar->update(0);
378         mainclock->update(mwindow->edl->local_session->get_selectionstart(1));
379 }
380
381 int MWindowGUI::focus_in_event()
382 {
383         for(int i = 0; i < TOTAL_PANES; i++)
384                 if(pane[i]) pane[i]->cursor->focus_in_event();
385         return 1;
386 }
387
388 int MWindowGUI::focus_out_event()
389 {
390         for(int i = 0; i < TOTAL_PANES; i++)
391                 if(pane[i]) pane[i]->cursor->focus_out_event();
392         return 1;
393 }
394
395
396 int MWindowGUI::resize_event(int w, int h)
397 {
398 //printf("MWindowGUI::resize_event %d\n", __LINE__);
399         mwindow->session->mwindow_w = w;
400         mwindow->session->mwindow_h = h;
401         int x = w - MainShBtns::calculate_w(0);
402         mainmenu->resize_event(x, mainmenu->get_h());
403         mainshbtns->reposition_window(x, -1);
404         ffmpeg_toggle->reposition_window(menu_w(), menu_h()+2);
405         mwindow->theme->get_mwindow_sizes(this, w, h);
406         mwindow->theme->draw_mwindow_bg(this);
407         mbuttons->resize_event();
408         statusbar->resize_event();
409         zoombar->resize_event();
410
411         resource_thread->stop_draw(1);
412
413         if(total_panes() > 1)
414         {
415                 if(horizontal_panes())
416                 {
417 //                      printf("MWindowGUI::resize_event %d %d %d\n",
418 //                              __LINE__,
419 //                              pane[TOP_RIGHT_PANE]->x,
420 //                              mwindow->theme->mcanvas_w -
421 //                                      BC_ScrollBar::get_span(SCROLL_VERT) -
422 //                                      PANE_DRAG_MARGIN);
423                         if(pane[TOP_RIGHT_PANE]->x >= mwindow->theme->mcanvas_w -
424                                 BC_ScrollBar::get_span(SCROLL_VERT) -
425                                 PANE_DRAG_MARGIN)
426                         {
427                                 delete_x_pane(pane[TOP_RIGHT_PANE]->x);
428                                 mwindow->edl->local_session->x_pane = -1;
429                         }
430                 }
431                 else
432                 if(vertical_panes())
433                 {
434                         if(pane[BOTTOM_LEFT_PANE]->y >= mwindow->theme->mzoom_y -
435                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
436                                 PANE_DRAG_MARGIN)
437                         {
438                                 delete_y_pane(pane[BOTTOM_LEFT_PANE]->y);
439                                 mwindow->edl->local_session->y_pane = -1;
440                         }
441                 }
442                 else
443                 {
444                         if(pane[TOP_RIGHT_PANE]->x >= mwindow->theme->mcanvas_w -
445                                         BC_ScrollBar::get_span(SCROLL_VERT) -
446                                         PANE_DRAG_MARGIN)
447                         {
448                                 delete_x_pane(pane[TOP_RIGHT_PANE]->x);
449                                 mwindow->edl->local_session->x_pane = -1;
450                         }
451
452                         if(pane[BOTTOM_LEFT_PANE]->y >= mwindow->theme->mzoom_y -
453                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
454                                 PANE_DRAG_MARGIN)
455                         {
456                                 delete_y_pane(pane[BOTTOM_LEFT_PANE]->y);
457                                 mwindow->edl->local_session->y_pane = -1;
458                         }
459                 }
460         }
461
462         if(total_panes() == 1)
463         {
464                 pane[TOP_LEFT_PANE]->resize_event(
465                         mwindow->theme->mcanvas_x,
466                         mwindow->theme->mcanvas_y,
467                         mwindow->theme->mcanvas_w,
468                         mwindow->theme->mcanvas_h);
469         }
470         else
471         if(horizontal_panes())
472         {
473                 pane[TOP_LEFT_PANE]->resize_event(
474                         pane[TOP_LEFT_PANE]->x,
475                         pane[TOP_LEFT_PANE]->y,
476                         pane[TOP_LEFT_PANE]->w,
477                         mwindow->theme->mcanvas_h);
478                 pane[TOP_RIGHT_PANE]->resize_event(
479                         pane[TOP_RIGHT_PANE]->x,
480                         pane[TOP_RIGHT_PANE]->y,
481                         mwindow->theme->mcanvas_w - pane[TOP_RIGHT_PANE]->x,
482                         mwindow->theme->mcanvas_h);
483         }
484         else
485         if(vertical_panes())
486         {
487                 pane[TOP_LEFT_PANE]->resize_event(
488                         pane[TOP_LEFT_PANE]->x,
489                         pane[TOP_LEFT_PANE]->y,
490                         mwindow->theme->mcanvas_w,
491                         pane[TOP_LEFT_PANE]->h);
492                 pane[BOTTOM_LEFT_PANE]->resize_event(
493                         pane[BOTTOM_LEFT_PANE]->x,
494                         pane[BOTTOM_LEFT_PANE]->y,
495                         mwindow->theme->mcanvas_w,
496                         mwindow->theme->mcanvas_y +
497                                 mwindow->theme->mcanvas_h -
498                                 pane[BOTTOM_LEFT_PANE]->y);
499         }
500         else
501         {
502                 pane[TOP_LEFT_PANE]->resize_event(
503                         pane[TOP_LEFT_PANE]->x,
504                         pane[TOP_LEFT_PANE]->y,
505                         pane[TOP_LEFT_PANE]->w,
506                         pane[TOP_LEFT_PANE]->h);
507                 pane[TOP_RIGHT_PANE]->resize_event(
508                         pane[TOP_RIGHT_PANE]->x,
509                         pane[TOP_RIGHT_PANE]->y,
510                         mwindow->theme->mcanvas_w - pane[TOP_RIGHT_PANE]->x,
511                         pane[TOP_RIGHT_PANE]->h);
512                 pane[BOTTOM_LEFT_PANE]->resize_event(
513                         pane[BOTTOM_LEFT_PANE]->x,
514                         pane[BOTTOM_LEFT_PANE]->y,
515                         pane[BOTTOM_LEFT_PANE]->w,
516                         mwindow->theme->mcanvas_y +
517                                 mwindow->theme->mcanvas_h -
518                                 pane[BOTTOM_LEFT_PANE]->y);
519                 pane[BOTTOM_RIGHT_PANE]->resize_event(
520                         pane[BOTTOM_RIGHT_PANE]->x,
521                         pane[BOTTOM_RIGHT_PANE]->y,
522                         mwindow->theme->mcanvas_w -
523                                 pane[BOTTOM_RIGHT_PANE]->x,
524                         mwindow->theme->mcanvas_y +
525                                 mwindow->theme->mcanvas_h -
526                                 pane[BOTTOM_RIGHT_PANE]->y);
527         }
528
529         update_pane_dividers();
530         pane_button->reposition_window(w - mwindow->theme->get_image_set("pane")[0]->get_w(),
531                 mwindow->theme->mzoom_y + 1 - mwindow->theme->get_image_set("pane")[0]->get_h());
532         resource_thread->start_draw();
533
534         flash(1);
535         return 0;
536 }
537
538 int MWindowGUI::total_panes()
539 {
540         int total = 0;
541         for(int i = 0; i < TOTAL_PANES; i++)
542                 if(pane[i]) total++;
543         return total;
544 }
545
546 int MWindowGUI::vertical_panes()
547 {
548         return total_panes() == 2 &&
549                 pane[TOP_LEFT_PANE] &&
550                 pane[BOTTOM_LEFT_PANE];
551 }
552
553 int MWindowGUI::horizontal_panes()
554 {
555         return total_panes() == 2 &&
556                 pane[TOP_LEFT_PANE] &&
557                 pane[TOP_RIGHT_PANE];
558 }
559
560 TimelinePane* MWindowGUI::get_focused_pane()
561 {
562         if(pane[focused_pane]) return pane[focused_pane];
563         for(int i = 0; i < TOTAL_PANES; i++)
564         {
565                 if(pane[i]) return pane[i];
566         }
567         return 0;
568 }
569
570 void MWindowGUI::activate_timeline()
571 {
572         if(pane[focused_pane])
573         {
574                 pane[focused_pane]->activate();
575         }
576         else
577         {
578                 for(int i = 0; i < TOTAL_PANES; i++)
579                 {
580                         if(pane[i])
581                         {
582                                 pane[i]->activate();
583                                 return;
584                         }
585                 }
586         }
587 }
588
589 void MWindowGUI::deactivate_timeline()
590 {
591         for(int i = 0; i < TOTAL_PANES; i++)
592         {
593                 if(pane[i])
594                 {
595                         pane[i]->canvas->deactivate();
596                 }
597         }
598 }
599
600 void MWindowGUI::update_title(char *path)
601 {
602         FileSystem fs;
603         char filename[BCTEXTLEN], string[BCTEXTLEN];
604         fs.extract_name(filename, path);
605         sprintf(string, _(PROGRAM_NAME ": %s"), filename);
606         set_title(string);
607 //printf("MWindowGUI::update_title %s\n", string);
608         flush();
609 }
610
611 void MWindowGUI::draw_overlays(int flash_it)
612 {
613         for(int i = 0; i < TOTAL_PANES; i++)
614         {
615                 if(pane[i])
616                 {
617                         pane[i]->canvas->draw_overlays();
618                         if(flash_it) pane[i]->canvas->flash();
619                 }
620         }
621 }
622
623 void MWindowGUI::update_timebar(int flush_it)
624 {
625         for(int i = 0; i < TOTAL_PANES; i++)
626         {
627                 if(pane[i] && pane[i]->timebar)
628                 {
629                         pane[i]->timebar->update(flush_it);
630                 }
631         }
632 }
633
634 void MWindowGUI::update_timebar_highlights()
635 {
636         for(int i = 0; i < TOTAL_PANES; i++)
637         {
638                 if(pane[i] && pane[i]->timebar)
639                 {
640                         pane[i]->timebar->update_highlights();
641                 }
642         }
643 }
644
645
646 void MWindowGUI::update_patchbay()
647 {
648         for(int i = 0; i < TOTAL_PANES; i++)
649         {
650                 if(pane[i] && pane[i]->patchbay)
651                 {
652                         pane[i]->patchbay->update();
653                 }
654         }
655 }
656
657 void MWindowGUI::draw_indexes(Indexable *indexable)
658 {
659         for(int i = 0; i < TOTAL_PANES; i++)
660         {
661                 if(pane[i])
662                 {
663                         pane[i]->canvas->draw_indexes(indexable);
664                 }
665         }
666 }
667
668 void MWindowGUI::draw_canvas(int mode /* = 0 */, int hide_cursor /* = 1 */)
669 {
670         if(mode != IGNORE_THREAD)
671         {
672                 resource_thread->stop_draw(1);
673         }
674
675
676         for(int i = 0; i < TOTAL_PANES; i++)
677         {
678                 if(pane[i])
679                 {
680                         pane[i]->canvas->draw(mode, hide_cursor);
681                 }
682         }
683
684
685         if(mode != IGNORE_THREAD)
686         {
687                 resource_thread->start_draw();
688         }
689
690 }
691
692 void MWindowGUI::flash_canvas(int flush)
693 {
694         for(int i = 0; i < TOTAL_PANES; i++)
695         {
696                 if(pane[i])
697                 {
698                         pane[i]->canvas->flash(flush);
699                 }
700         }
701 }
702
703 void MWindowGUI::draw_cursor(int do_plugintoggles)
704 {
705         for(int i = 0; i < TOTAL_PANES; i++)
706         {
707                 if(pane[i])
708                 {
709                         pane[i]->cursor->draw(do_plugintoggles);
710                 }
711         }
712 }
713
714 void MWindowGUI::show_cursor(int do_plugintoggles)
715 {
716         for(int i = 0; i < TOTAL_PANES; i++)
717         {
718                 if(pane[i])
719                 {
720                         pane[i]->cursor->show(do_plugintoggles);
721                 }
722         }
723 }
724
725 void MWindowGUI::hide_cursor(int do_plugintoggles)
726 {
727         for(int i = 0; i < TOTAL_PANES; i++)
728         {
729                 if(pane[i])
730                 {
731                         pane[i]->cursor->hide(do_plugintoggles);
732                 }
733         }
734 }
735
736 void MWindowGUI::update_cursor()
737 {
738         for(int i = 0; i < TOTAL_PANES; i++)
739         {
740                 if(pane[i])
741                 {
742                         pane[i]->cursor->update();
743                 }
744         }
745 }
746
747 void MWindowGUI::set_playing_back(int value)
748 {
749         for(int i = 0; i < TOTAL_PANES; i++)
750         {
751                 if(pane[i])
752                 {
753                         pane[i]->cursor->playing_back = value;
754                 }
755         }
756 }
757
758 void MWindowGUI::update_plugintoggles()
759 {
760         for(int i = 0; i < TOTAL_PANES; i++)
761         {
762                 if(pane[i])
763                 {
764                         pane[i]->canvas->refresh_plugintoggles();
765                 }
766         }
767
768 }
769
770 void MWindowGUI::update_scrollbars(int flush)
771 {
772         for(int i = 0; i < TOTAL_PANES; i++)
773         {
774                 if(pane[i])
775                 {
776                         pane[i]->update(1, 0, 0, 0);
777                 }
778         }
779         if(flush) this->flush();
780 }
781
782 void MWindowGUI::reset_meters()
783 {
784         for(int i = 0; i < TOTAL_PANES; i++)
785         {
786                 if(pane[i] && pane[i]->patchbay)
787                 {
788                         pane[i]->patchbay->reset_meters();
789                 }
790         }
791 }
792
793 void MWindowGUI::stop_meters()
794 {
795         for(int i = 0; i < TOTAL_PANES; i++)
796         {
797                 if(pane[i] && pane[i]->patchbay)
798                 {
799                         pane[i]->patchbay->stop_meters();
800                 }
801         }
802 }
803
804 void MWindowGUI::update_meters(ArrayList<double> *module_levels)
805 {
806         for(int i = 0; i < TOTAL_PANES; i++)
807         {
808                 if(pane[i] && pane[i]->patchbay)
809                 {
810                         pane[i]->patchbay->update_meters(module_levels);
811                 }
812         }
813 }
814
815 void MWindowGUI::set_editing_mode(int flush)
816 {
817         for(int i = 0; i < TOTAL_PANES; i++)
818         {
819                 if(pane[i])
820                 {
821                         pane[i]->canvas->update_cursor(flush);
822                 }
823         }
824 }
825
826 void MWindowGUI::set_meter_format(int mode, int min, int max)
827 {
828         for(int i = 0; i < TOTAL_PANES; i++)
829         {
830                 if(pane[i] && pane[i]->patchbay)
831                 {
832                         pane[i]->patchbay->set_meter_format(mode, min, max);
833                 }
834         }
835 }
836
837 void MWindowGUI::update(int scrollbars,
838         int do_canvas,
839         int timebar,
840         int zoombar,
841         int patchbay,
842         int clock,
843         int buttonbar)
844 {
845         const int debug = 0;
846         if(debug) PRINT_TRACE
847
848
849
850         mwindow->edl->tracks->update_y_pixels(mwindow->theme);
851
852         if(do_canvas && do_canvas != IGNORE_THREAD)
853         {
854                 resource_thread->stop_draw(1);
855         }
856
857         for(int i = 0; i < TOTAL_PANES; i++)
858         {
859                 if(pane[i]) pane[i]->update(scrollbars,
860                         do_canvas,
861                         timebar,
862                         patchbay);
863         }
864
865         if(do_canvas && do_canvas != IGNORE_THREAD)
866         {
867                 resource_thread->start_draw();
868         }
869
870 //      if(scrollbars) this->get_scrollbars(0);
871 //      if(timebar) this->timebar->update(0);
872         if(zoombar) this->zoombar->update();
873 //      if(patchbay) this->patchbay->update();
874         if(clock) this->mainclock->update(
875                 mwindow->edl->local_session->get_selectionstart(1));
876         if(debug) PRINT_TRACE
877
878
879
880 //      if(do_canvas)
881 //      {
882 //              this->canvas->draw(do_canvas);
883 //              this->cursor->show();
884 //              this->canvas->flash(0);
885 // Activate causes the menubar to deactivate.  Don't want this for
886 // picon thread.
887 //              if(canvas != IGNORE_THREAD) this->canvas->activate();
888 //      }
889         if(debug) PRINT_TRACE
890
891
892
893         if(buttonbar) mbuttons->update();
894         if(debug) PRINT_TRACE
895
896 // Can't age if the cache called this to draw missing picons
897 // or the GUI is updating the status of the draw toggle.
898         if(do_canvas != FORCE_REDRAW && do_canvas != IGNORE_THREAD)
899         {
900                 unlock_window();
901                 mwindow->age_caches();
902                 lock_window("MWindowGUI::update");
903         }
904
905         flush();
906         if(debug) PRINT_TRACE
907 }
908
909 int MWindowGUI::visible(int64_t x1, int64_t x2, int64_t view_x1, int64_t view_x2)
910 {
911         return (x1 >= view_x1 && x1 < view_x2) ||
912                 (x2 > view_x1 && x2 <= view_x2) ||
913                 (x1 <= view_x1 && x2 >= view_x2);
914 }
915
916
917 void MWindowGUI::show_message(const char *message, int color)
918 {
919         statusbar->show_message(message, color);
920 }
921
922 void MWindowGUI::update_default_message()
923 {
924         statusbar->update_default_message();
925 }
926
927 void MWindowGUI::reset_default_message()
928 {
929         statusbar->reset_default_message();
930 }
931
932 void MWindowGUI::default_message()
933 {
934         statusbar->default_message();
935 }
936
937 // Drag motion called from other window
938 int MWindowGUI::drag_motion()
939 {
940         if(get_hidden()) return 0;
941
942         Track *over_track = 0;
943         Edit *over_edit = 0;
944         PluginSet *over_pluginset = 0;
945         Plugin *over_plugin = 0;
946         int redraw = 0;
947
948         if(drag_popup)
949         {
950                 drag_popup->cursor_motion_event();
951         }
952
953
954 // there's no point in drawing highlights has until drag operation has been set
955         if (!mwindow->session->current_operation)
956                 return 0;
957
958         for(int i = 0; i < TOTAL_PANES; i++)
959         {
960                 if(pane[i]) pane[i]->canvas->drag_motion(
961                         &over_track,
962                         &over_edit,
963                         &over_pluginset,
964                         &over_plugin);
965         }
966
967         if(mwindow->session->track_highlighted != over_track)
968         {
969                 mwindow->session->track_highlighted = over_track;
970                 redraw = 1;
971         }
972
973         if(mwindow->session->edit_highlighted != over_edit)
974         {
975                 mwindow->session->edit_highlighted = over_edit;
976                 redraw = 1;
977         }
978
979         if(mwindow->session->pluginset_highlighted != over_pluginset)
980         {
981                 mwindow->session->pluginset_highlighted = over_pluginset;
982                 redraw = 1;
983         }
984
985         if(mwindow->session->plugin_highlighted != over_plugin)
986         {
987                 mwindow->session->plugin_highlighted = over_plugin;
988                 redraw = 1;
989         }
990
991         if( mwindow->session->current_operation == DRAG_ASSET ||
992             mwindow->session->current_operation == DRAG_EDIT ||
993             mwindow->session->current_operation == DRAG_AEFFECT_COPY ||
994             mwindow->session->current_operation == DRAG_VEFFECT_COPY )
995         {
996                 redraw = 1;
997         }
998
999
1000 // printf("drag_motion %d %d over_track=%p over_edit=%p\n",
1001 // __LINE__,
1002 // redraw,
1003 // over_track,
1004 // over_edit);
1005         if(redraw)
1006         {
1007                 lock_window("MWindowGUI::drag_motion");
1008                 draw_overlays(1);
1009                 unlock_window();
1010         }
1011         return 0;
1012 }
1013
1014 int MWindowGUI::drag_stop()
1015 {
1016         if(get_hidden()) return 0;
1017         int result = 0, redraw = 0;
1018
1019         for(int i = 0; i < TOTAL_PANES; i++)
1020         {
1021                 if(pane[i]) result |= pane[i]->canvas->drag_stop(
1022                         &redraw);
1023         }
1024         mwindow->edl->optimize();
1025
1026 // since we don't have subwindows we have to terminate any drag operation
1027         if(result)
1028         {
1029                 if (mwindow->session->track_highlighted
1030                         || mwindow->session->edit_highlighted
1031                         || mwindow->session->plugin_highlighted
1032                         || mwindow->session->pluginset_highlighted)
1033                         redraw = 1;
1034                 mwindow->session->track_highlighted = 0;
1035                 mwindow->session->edit_highlighted = 0;
1036                 mwindow->session->plugin_highlighted = 0;
1037                 mwindow->session->pluginset_highlighted = 0;
1038                 mwindow->session->current_operation = NO_OPERATION;
1039         }
1040
1041
1042 //printf("MWindowGUI::drag_stop %d %d\n", redraw, mwindow->session->current_operation);
1043         if(redraw)
1044         {
1045                 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
1046                 update_scrollbars(0);
1047                 update_patchbay();
1048                 draw_canvas(1, 1);
1049                 update_cursor();
1050                 flash_canvas(1);
1051         }
1052
1053         if(drag_popup)
1054         {
1055                 delete drag_popup;
1056                 drag_popup = 0;
1057         }
1058         return result;
1059 }
1060
1061 void MWindowGUI::default_positions()
1062 {
1063 //printf("MWindowGUI::default_positions 1\n");
1064         VWindow *vwindow = mwindow->vwindows.size() > DEFAULT_VWINDOW ?
1065                 mwindow->vwindows.get(DEFAULT_VWINDOW) : 0;
1066         if( vwindow && !vwindow->is_running() ) vwindow = 0;
1067         if( vwindow ) vwindow->gui->lock_window("MWindowGUI::default_positions");
1068         mwindow->cwindow->gui->lock_window("MWindowGUI::default_positions");
1069         mwindow->awindow->gui->lock_window("MWindowGUI::default_positions");
1070
1071 // printf("MWindowGUI::default_positions 1 %d %d %d %d\n", mwindow->session->vwindow_x,
1072 // mwindow->session->vwindow_y,
1073 // mwindow->session->vwindow_w,
1074 // mwindow->session->vwindow_h);
1075         reposition_window(mwindow->session->mwindow_x,
1076                 mwindow->session->mwindow_y,
1077                 mwindow->session->mwindow_w,
1078                 mwindow->session->mwindow_h);
1079         if( vwindow ) vwindow->gui->reposition_window(mwindow->session->vwindow_x,
1080                 mwindow->session->vwindow_y,
1081                 mwindow->session->vwindow_w,
1082                 mwindow->session->vwindow_h);
1083         mwindow->cwindow->gui->reposition_window(mwindow->session->cwindow_x,
1084                 mwindow->session->cwindow_y,
1085                 mwindow->session->cwindow_w,
1086                 mwindow->session->cwindow_h);
1087         mwindow->awindow->gui->reposition_window(mwindow->session->awindow_x,
1088                 mwindow->session->awindow_y,
1089                 mwindow->session->awindow_w,
1090                 mwindow->session->awindow_h);
1091 //printf("MWindowGUI::default_positions 1\n");
1092
1093         resize_event(mwindow->session->mwindow_w,
1094                 mwindow->session->mwindow_h);
1095 //printf("MWindowGUI::default_positions 1\n");
1096         if( vwindow ) vwindow->gui->resize_event(mwindow->session->vwindow_w,
1097                 mwindow->session->vwindow_h);
1098 //printf("MWindowGUI::default_positions 1\n");
1099         mwindow->cwindow->gui->resize_event(mwindow->session->cwindow_w,
1100                 mwindow->session->cwindow_h);
1101 //printf("MWindowGUI::default_positions 1\n");
1102         mwindow->awindow->gui->resize_event(mwindow->session->awindow_w,
1103                 mwindow->session->awindow_h);
1104
1105 //printf("MWindowGUI::default_positions 1\n");
1106
1107         flush();
1108         if( vwindow ) vwindow->gui->flush();
1109         mwindow->cwindow->gui->flush();
1110         mwindow->awindow->gui->flush();
1111
1112         if( vwindow ) vwindow->gui->unlock_window();
1113         mwindow->cwindow->gui->unlock_window();
1114         mwindow->awindow->gui->unlock_window();
1115 //printf("MWindowGUI::default_positions 2\n");
1116 }
1117
1118
1119 int MWindowGUI::button_release_event()
1120 {
1121         if( keyvalue_popup ) {
1122                 delete keyvalue_popup;  keyvalue_popup = 0;
1123         }
1124         return 0;
1125 }
1126
1127
1128 int MWindowGUI::repeat_event(int64_t duration)
1129 {
1130 // if(duration == 100)
1131 // mwindow->sync_parameters(CHANGE_ALL);
1132         int result = 0;
1133         for(int i = 0; i < TOTAL_PANES; i++)
1134         {
1135                 if(pane[i]) result = pane[i]->cursor->repeat_event(duration);
1136         }
1137         return result;
1138 }
1139
1140
1141 int MWindowGUI::translation_event()
1142 {
1143 //printf("MWindowGUI::translation_event 1 %d %d\n", get_x(), get_y());
1144         mwindow->session->mwindow_x = get_x();
1145         mwindow->session->mwindow_y = get_y();
1146         return 0;
1147 }
1148
1149
1150 int MWindowGUI::save_defaults(BC_Hash *defaults)
1151 {
1152         defaults->update("MWINDOWWIDTH", get_w());
1153         defaults->update("MWINDOWHEIGHT", get_h());
1154         mainmenu->save_defaults(defaults);
1155         BC_WindowBase::save_defaults(defaults);
1156         return 0;
1157 }
1158
1159 int MWindowGUI::keypress_event()
1160 {
1161 //printf("MWindowGUI::keypress_event 1 %d\n", get_keypress());
1162         int result = mbuttons->keypress_event();
1163         if( result ) return result;
1164
1165         Track *this_track = 0;
1166
1167         switch(get_keypress()) {
1168         case 'e':
1169                 mwindow->toggle_editing_mode();
1170                 result = 1;
1171                 break;
1172
1173         case 'k': case 'K':
1174                 if( alt_down() ) break;
1175                 stop_transport("MWindowGUI::keypress_event 1");
1176                 mwindow->nearest_plugin_keyframe(shift_down(),
1177                         !ctrl_down() ? PLAY_FORWARD : PLAY_REVERSE);
1178                 result = 1;
1179                 break;
1180
1181         case '1': case '2': case '3': case '4':
1182         case '5': case '6': case '7': case '8':
1183                 if( !alt_down() || shift_down() ) break;
1184                 if( !mwindow->select_asset(get_keypress()-'1',1) )
1185                         result = 1;
1186                 break;
1187
1188         case LEFT:
1189                 if( !ctrl_down() ) {
1190                         if( alt_down() ) {
1191                                 stop_transport("MWindowGUI::keypress_event 1");
1192                                 mwindow->prev_edit_handle(shift_down());
1193                         }
1194                         else
1195                                 mwindow->move_left();
1196                         result = 1;
1197                 }
1198                 break;
1199
1200         case ',':
1201                 if( !ctrl_down() && !alt_down() ) {
1202                         mwindow->move_left();
1203                         result = 1;
1204                 }
1205                 break;
1206
1207         case RIGHT:
1208                 if( !ctrl_down() ) {
1209                         if( alt_down() ) {
1210                                 stop_transport("MWindowGUI::keypress_event 2");
1211                                 mwindow->next_edit_handle(shift_down());
1212                         }
1213                         else
1214                                 mwindow->move_right();
1215                         result = 1;
1216                 }
1217                 break;
1218
1219         case '.':
1220                 if( !ctrl_down() && !alt_down() ) {
1221                         mwindow->move_right();
1222                         result = 1;
1223                 }
1224                 break;
1225
1226         case UP:
1227                 if( ctrl_down() && !alt_down() )
1228                         mwindow->expand_y();
1229                 else if( !ctrl_down() && alt_down() )
1230                         mwindow->expand_autos(0,1,1);
1231                 else if( ctrl_down() && alt_down() )
1232                         mwindow->expand_autos(1,1,1);
1233                 else
1234                         mwindow->expand_sample();
1235                 result = 1;
1236                 break;
1237
1238         case DOWN:
1239                 if( ctrl_down() && !alt_down() )
1240                         mwindow->zoom_in_y();
1241                 else if( !ctrl_down() && alt_down() )
1242                         mwindow->shrink_autos(0,1,1);
1243                 else if( ctrl_down() && alt_down() )
1244                         mwindow->shrink_autos(1,1,1);
1245                 else
1246                         mwindow->zoom_in_sample();
1247                 result = 1;
1248                 break;
1249
1250         case PGUP:
1251                 if( !ctrl_down() )
1252                         mwindow->move_up();
1253                 else
1254                         mwindow->expand_t();
1255                 result = 1;
1256                 break;
1257
1258         case PGDN:
1259                 if( !ctrl_down() )
1260                         mwindow->move_down();
1261                 else
1262                         mwindow->zoom_in_t();
1263                 result = 1;
1264                 break;
1265
1266         case TAB:
1267         case LEFTTAB:
1268                 for( int i=0; i<TOTAL_PANES; ++i ) {
1269                         if( !pane[i] ) continue;
1270                         if( (this_track = pane[i]->over_track()) != 0 ) break;
1271                         if( (this_track = pane[i]->over_patchbay()) != 0 ) break;
1272                 }
1273
1274                 if( get_keypress() == TAB ) { // Switch the record button
1275                         if( this_track )
1276                                 this_track->record = !this_track->record ? 1 : 0;
1277                 }
1278                 else {
1279                         int total_selected = mwindow->edl->tracks->total_of(Tracks::RECORD);
1280                         // all selected if nothing previously selected or
1281                         // if this patch was previously the only one selected and armed
1282                         int selected = !total_selected || (total_selected == 1 &&
1283                                 this_track && this_track->record ) ? 1 : 0;
1284                         mwindow->edl->tracks->select_all(Tracks::RECORD, selected);
1285                         if( !selected && this_track ) this_track->record = 1;
1286                 }
1287
1288                 update(0, 1, 0, 0, 1, 0, 1);
1289                 unlock_window();
1290                 mwindow->cwindow->update(0, 1, 1);
1291                 lock_window("MWindowGUI::keypress_event 3");
1292
1293                 result = 1;
1294                 break;
1295
1296         case KEY_F1:
1297         case KEY_F2:
1298         case KEY_F3:
1299         case KEY_F4:
1300         case KEY_F5:
1301         case KEY_F6:
1302         case KEY_F7:
1303         case KEY_F8:
1304         case KEY_F9:
1305         case KEY_F10:
1306         case KEY_F11:
1307         case KEY_F12:
1308                 resend_event(mwindow->cwindow->gui);
1309                 return 1;
1310         }
1311
1312 // since things under cursor have changed...
1313         if(result)
1314                 cursor_motion_event();
1315
1316         return result;
1317 }
1318
1319 int MWindowGUI::keyboard_listener(BC_WindowBase *wp)
1320 {
1321         return key_listener(wp->get_keypress());
1322 }
1323
1324 int MWindowGUI::key_listener(int key)
1325 {
1326         int result = 1;
1327         switch( key ) {
1328         case KPTV:
1329                 if( !record->running() )
1330                         record->start();
1331                 else
1332                         record->record_gui->interrupt_thread->start(0);
1333                 break;
1334         case KPHAND:
1335                 mwindow->quit();
1336                 break;
1337 #ifdef HAVE_DVB
1338         case KPBOOK:
1339                 channel_info->toggle_scan();
1340                 break;
1341 #endif
1342         case KPMENU:
1343                 if( !remote_control->deactivate() )
1344                         remote_control->activate();
1345                 break;
1346         default:
1347                 result = 0;
1348                 break;
1349         }
1350         return result;
1351 }
1352
1353
1354 void MWindowGUI::use_android_remote(int on)
1355 {
1356         if( !on ) {
1357                 delete android_control;
1358                 android_control = 0;
1359                 return;
1360         }
1361         if( android_control ) return;
1362         android_control = new AndroidControl(this);
1363 }
1364
1365 int MWindowGUI::close_event()
1366 {
1367         mainmenu->quit();
1368         return 0;
1369 }
1370
1371 void MWindowGUI::stop_drawing()
1372 {
1373         resource_thread->stop_draw(1);
1374 }
1375
1376 int MWindowGUI::menu_w()
1377 {
1378         return mainmenu->get_w();
1379 }
1380
1381 int MWindowGUI::menu_h()
1382 {
1383         return mainmenu->get_h();
1384 }
1385
1386 void MWindowGUI::start_x_pane_drag()
1387 {
1388         if(!x_pane_drag)
1389         {
1390                 x_pane_drag = new BC_Popup(this,
1391                         get_abs_cursor_x(0) - mwindow->theme->pane_w,
1392                         BC_DisplayInfo::get_top_border() +
1393                                 get_y() +
1394                                 mwindow->theme->mcanvas_y,
1395                         mwindow->theme->pane_w,
1396                         mwindow->theme->mcanvas_h,
1397                         mwindow->theme->drag_pane_color);
1398                 x_pane_drag->draw_3segmentv(0,
1399                         0,
1400                         x_pane_drag->get_h(),
1401                         mwindow->theme->get_image_set("xpane")[BUTTON_DOWNHI]);
1402                 x_pane_drag->flash(1);
1403         }
1404         dragging_pane = 1;
1405 }
1406
1407 void MWindowGUI::start_y_pane_drag()
1408 {
1409         if(!y_pane_drag)
1410         {
1411 //printf("MWindowGUI::start_y_pane_drag %d %d %d\n", __LINE__, get_x(), get_y());
1412                 y_pane_drag = new BC_Popup(this,
1413                         BC_DisplayInfo::get_left_border() +
1414                                 get_x() +
1415                                 mwindow->theme->mcanvas_x,
1416                         get_abs_cursor_y(0) - mwindow->theme->pane_h,
1417                         mwindow->theme->mcanvas_w,
1418                         mwindow->theme->pane_h,
1419                         mwindow->theme->drag_pane_color);
1420                 y_pane_drag->draw_3segmenth(0,
1421                         0,
1422                         y_pane_drag->get_w(),
1423                         mwindow->theme->get_image_set("ypane")[BUTTON_DOWNHI]);
1424                 y_pane_drag->flash(1);
1425         }
1426         dragging_pane = 1;
1427 }
1428
1429 void MWindowGUI::handle_pane_drag()
1430 {
1431         if(dragging_pane)
1432         {
1433                 if(x_pane_drag)
1434                 {
1435                         x_pane_drag->reposition_window(
1436                                 get_abs_cursor_x(0) - mwindow->theme->pane_w,
1437                                 x_pane_drag->get_y());
1438                 }
1439
1440                 if(y_pane_drag)
1441                 {
1442                         y_pane_drag->reposition_window(
1443                                 y_pane_drag->get_x(),
1444                                 get_abs_cursor_y(0) - mwindow->theme->pane_h);
1445                 }
1446         }
1447 }
1448
1449
1450 void MWindowGUI::create_x_pane(int cursor_x)
1451 {
1452         if(total_panes() == 1)
1453         {
1454 // create a horizontal pane
1455 // do this 1st so the resize_event knows there are 2 panes
1456                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] =
1457                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] +
1458                         cursor_x -
1459                         mwindow->theme->patchbay_w;
1460                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1461                         TOP_RIGHT_PANE,
1462                         mwindow->theme->mcanvas_x +
1463                                 cursor_x,
1464                         mwindow->theme->mcanvas_y,
1465                         mwindow->theme->mcanvas_x +
1466                                 mwindow->theme->mcanvas_w -
1467                                 cursor_x,
1468                         mwindow->theme->mcanvas_h);
1469                 pane[TOP_LEFT_PANE]->resize_event(
1470                         mwindow->theme->mcanvas_x,
1471                         mwindow->theme->mcanvas_y,
1472                         cursor_x - mwindow->theme->pane_w,
1473                         mwindow->theme->mcanvas_h);
1474                 pane[TOP_RIGHT_PANE]->create_objects();
1475         }
1476         else
1477         if(vertical_panes())
1478         {
1479 // create 2 horizontal panes
1480                 mwindow->edl->local_session->track_start[TOP_RIGHT_PANE] =
1481                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE];
1482                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1483                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE];
1484                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] =
1485                         mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1486                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] +
1487                         cursor_x -
1488                         mwindow->theme->patchbay_w;
1489                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1490                         TOP_RIGHT_PANE,
1491                         mwindow->theme->mcanvas_x +
1492                                 cursor_x,
1493                         pane[TOP_LEFT_PANE]->y,
1494                         mwindow->theme->mcanvas_x +
1495                                 mwindow->theme->mcanvas_w -
1496                                 cursor_x,
1497                         pane[TOP_LEFT_PANE]->h);
1498                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1499                         BOTTOM_RIGHT_PANE,
1500                         mwindow->theme->mcanvas_x +
1501                                 cursor_x,
1502                         pane[BOTTOM_LEFT_PANE]->y,
1503                         mwindow->theme->mcanvas_x +
1504                                 mwindow->theme->mcanvas_w -
1505                                 cursor_x,
1506                         pane[BOTTOM_LEFT_PANE]->h);
1507                 pane[TOP_LEFT_PANE]->resize_event(
1508                         pane[TOP_LEFT_PANE]->x,
1509                         pane[TOP_LEFT_PANE]->y,
1510                         cursor_x - mwindow->theme->pane_w,
1511                         pane[TOP_LEFT_PANE]->h);
1512                 pane[BOTTOM_LEFT_PANE]->resize_event(
1513                         pane[BOTTOM_LEFT_PANE]->x,
1514                         pane[BOTTOM_LEFT_PANE]->y,
1515                         cursor_x - mwindow->theme->pane_w,
1516                         pane[BOTTOM_LEFT_PANE]->h);
1517                 pane[TOP_RIGHT_PANE]->create_objects();
1518                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1519         }
1520         else
1521         if(horizontal_panes())
1522         {
1523 // resize a horizontal pane
1524                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] +=
1525                         cursor_x -
1526                         pane[TOP_RIGHT_PANE]->x;
1527                 if(mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] < 0)
1528                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] = 0;
1529                 pane[TOP_LEFT_PANE]->resize_event(
1530                         mwindow->theme->mcanvas_x,
1531                         mwindow->theme->mcanvas_y,
1532                         cursor_x - mwindow->theme->pane_w,
1533                         mwindow->theme->mcanvas_h);
1534                 pane[TOP_RIGHT_PANE]->resize_event(
1535                         mwindow->theme->mcanvas_x +
1536                                 cursor_x,
1537                         pane[TOP_RIGHT_PANE]->y,
1538                         mwindow->theme->mcanvas_x +
1539                                 mwindow->theme->mcanvas_w -
1540                                 cursor_x,
1541                         mwindow->theme->mcanvas_h);
1542         }
1543         else
1544         {
1545 // resize 2 horizontal panes
1546                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] +=
1547                         cursor_x -
1548                         pane[TOP_RIGHT_PANE]->x;
1549                 if(mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] < 0)
1550                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] = 0;
1551                 mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1552                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE];
1553
1554                 pane[TOP_LEFT_PANE]->resize_event(
1555                         mwindow->theme->mcanvas_x,
1556                         pane[TOP_LEFT_PANE]->y,
1557                         cursor_x - mwindow->theme->pane_w,
1558                         pane[TOP_LEFT_PANE]->h);
1559                 pane[TOP_RIGHT_PANE]->resize_event(
1560                         mwindow->theme->mcanvas_x +
1561                                 cursor_x,
1562                         pane[TOP_RIGHT_PANE]->y,
1563                         mwindow->theme->mcanvas_x +
1564                                 mwindow->theme->mcanvas_w -
1565                                 cursor_x,
1566                         pane[TOP_RIGHT_PANE]->h);
1567                 pane[BOTTOM_LEFT_PANE]->resize_event(
1568                         mwindow->theme->mcanvas_x,
1569                         pane[BOTTOM_LEFT_PANE]->y,
1570                         cursor_x - mwindow->theme->pane_w,
1571                         pane[BOTTOM_LEFT_PANE]->h);
1572                 pane[BOTTOM_RIGHT_PANE]->resize_event(
1573                         mwindow->theme->mcanvas_x +
1574                                 cursor_x,
1575                         pane[BOTTOM_RIGHT_PANE]->y,
1576                         mwindow->theme->mcanvas_x +
1577                                 mwindow->theme->mcanvas_w -
1578                                 cursor_x,
1579                         pane[BOTTOM_RIGHT_PANE]->h);
1580
1581         }
1582 }
1583
1584
1585 void MWindowGUI::delete_x_pane(int cursor_x)
1586 {
1587 // give left panes coordinates of right pane
1588         if(cursor_x < mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1589                 pane[TOP_RIGHT_PANE])
1590         {
1591                 mwindow->edl->local_session->view_start[TOP_LEFT_PANE] =
1592                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] -
1593                         pane[TOP_RIGHT_PANE]->x + mwindow->theme->patchbay_w;
1594                 if(mwindow->edl->local_session->view_start[TOP_LEFT_PANE] < 0)
1595                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] = 0;
1596                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1597                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1598         }
1599
1600         switch(total_panes())
1601         {
1602                 case 2:
1603                         if(pane[TOP_LEFT_PANE] && pane[TOP_RIGHT_PANE])
1604                         {
1605 // delete right pane
1606                                 delete pane[TOP_RIGHT_PANE];
1607                                 pane[TOP_RIGHT_PANE] = 0;
1608                                 pane[TOP_LEFT_PANE]->resize_event(
1609                                         mwindow->theme->mcanvas_x,
1610                                         mwindow->theme->mcanvas_y,
1611                                         mwindow->theme->mcanvas_w,
1612                                         mwindow->theme->mcanvas_h);
1613
1614                         }
1615                         break;
1616
1617                 case 4:
1618 // delete right panes
1619                         delete pane[TOP_RIGHT_PANE];
1620                         pane[TOP_RIGHT_PANE] = 0;
1621                         delete pane[BOTTOM_RIGHT_PANE];
1622                         pane[BOTTOM_RIGHT_PANE] = 0;
1623                         pane[TOP_LEFT_PANE]->resize_event(
1624                                 mwindow->theme->mcanvas_x,
1625                                 pane[TOP_LEFT_PANE]->y,
1626                                 mwindow->theme->mcanvas_w,
1627                                 pane[TOP_LEFT_PANE]->h);
1628                         pane[BOTTOM_LEFT_PANE]->resize_event(
1629                                 mwindow->theme->mcanvas_x,
1630                                 pane[BOTTOM_LEFT_PANE]->y,
1631                                 mwindow->theme->mcanvas_w,
1632                                 pane[BOTTOM_LEFT_PANE]->h);
1633                         break;
1634         }
1635 }
1636
1637 void MWindowGUI::create_y_pane(int cursor_y)
1638 {
1639         if(total_panes() == 1)
1640         {
1641                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1642                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1643                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] =
1644                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] +
1645                         cursor_y -
1646                         mwindow->theme->mtimebar_h;
1647 // do this 1st so the resize_event knows there are 2 panes
1648                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1649                         BOTTOM_LEFT_PANE,
1650                         mwindow->theme->mcanvas_x,
1651                         mwindow->theme->mcanvas_y +
1652                                 cursor_y,
1653                         mwindow->theme->mcanvas_w,
1654                         mwindow->theme->mcanvas_h -
1655                                 cursor_y);
1656                 pane[TOP_LEFT_PANE]->resize_event(
1657                         mwindow->theme->mcanvas_x,
1658                         mwindow->theme->mcanvas_y,
1659                         mwindow->theme->mcanvas_w,
1660                         pane[BOTTOM_LEFT_PANE]->y -
1661                                 mwindow->theme->mcanvas_y -
1662                                 mwindow->theme->pane_h);
1663                 pane[BOTTOM_LEFT_PANE]->create_objects();
1664         }
1665         else
1666         if(horizontal_panes())
1667         {
1668 // create 2 panes
1669                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1670                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1671                 mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1672                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE];
1673                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] =
1674                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1675                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] +
1676                         cursor_y -
1677                         mwindow->theme->mtimebar_h;
1678
1679                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1680                         BOTTOM_LEFT_PANE,
1681                         pane[TOP_LEFT_PANE]->x,
1682                         mwindow->theme->mcanvas_y +
1683                                 cursor_y,
1684                         pane[TOP_LEFT_PANE]->w,
1685                         mwindow->theme->mcanvas_h -
1686                                 cursor_y);
1687                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1688                         BOTTOM_RIGHT_PANE,
1689                         pane[TOP_RIGHT_PANE]->x,
1690                         mwindow->theme->mcanvas_y +
1691                                 cursor_y,
1692                         pane[TOP_RIGHT_PANE]->w,
1693                         mwindow->theme->mcanvas_h -
1694                                 cursor_y);
1695
1696                 pane[TOP_LEFT_PANE]->resize_event(
1697                         pane[TOP_LEFT_PANE]->x,
1698                         pane[TOP_LEFT_PANE]->y,
1699                         pane[TOP_LEFT_PANE]->w,
1700                         pane[BOTTOM_LEFT_PANE]->y -
1701                                 mwindow->theme->mcanvas_y -
1702                                 mwindow->theme->pane_h);
1703                 pane[TOP_RIGHT_PANE]->resize_event(
1704                         pane[TOP_RIGHT_PANE]->x,
1705                         pane[TOP_RIGHT_PANE]->y,
1706                         pane[TOP_RIGHT_PANE]->w,
1707                         pane[BOTTOM_RIGHT_PANE]->y -
1708                                 mwindow->theme->mcanvas_y -
1709                                 mwindow->theme->pane_h);
1710
1711                 pane[BOTTOM_LEFT_PANE]->create_objects();
1712                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1713         }
1714         else
1715         if(vertical_panes())
1716         {
1717 // resize a pane
1718                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] +=
1719                         cursor_y -
1720                         (pane[BOTTOM_LEFT_PANE]->y - mwindow->theme->mcanvas_y);
1721                 if(mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] < 0)
1722                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] = 0;
1723                 pane[TOP_LEFT_PANE]->resize_event(
1724                         mwindow->theme->mcanvas_x,
1725                         mwindow->theme->mcanvas_y,
1726                         mwindow->theme->mcanvas_w,
1727                         cursor_y - mwindow->theme->pane_h);
1728                 pane[BOTTOM_LEFT_PANE]->resize_event(
1729                         pane[BOTTOM_LEFT_PANE]->x,
1730                         cursor_y +
1731                                 mwindow->theme->mcanvas_y,
1732                         mwindow->theme->mcanvas_w,
1733                         mwindow->theme->mcanvas_h -
1734                                 cursor_y);
1735         }
1736         else
1737         {
1738 // resize 2 panes
1739                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] +=
1740                         cursor_y -
1741                         (pane[BOTTOM_LEFT_PANE]->y - mwindow->theme->mcanvas_y);
1742                 if(mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] < 0)
1743                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] = 0;
1744                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1745                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE];
1746                 pane[TOP_LEFT_PANE]->resize_event(
1747                         pane[TOP_LEFT_PANE]->x,
1748                         pane[TOP_LEFT_PANE]->y,
1749                         pane[TOP_LEFT_PANE]->w,
1750                         cursor_y - mwindow->theme->pane_h);
1751                 pane[BOTTOM_LEFT_PANE]->resize_event(
1752                         pane[BOTTOM_LEFT_PANE]->x,
1753                         cursor_y +
1754                                 mwindow->theme->mcanvas_y,
1755                         pane[BOTTOM_LEFT_PANE]->w,
1756                         mwindow->theme->mcanvas_h -
1757                                         cursor_y);
1758                 pane[TOP_RIGHT_PANE]->resize_event(
1759                         pane[TOP_RIGHT_PANE]->x,
1760                         pane[TOP_RIGHT_PANE]->y,
1761                         pane[TOP_RIGHT_PANE]->w,
1762                         cursor_y - mwindow->theme->pane_h);
1763                 pane[BOTTOM_RIGHT_PANE]->resize_event(
1764                         pane[BOTTOM_RIGHT_PANE]->x,
1765                         cursor_y +
1766                                 mwindow->theme->mcanvas_y,
1767                         pane[BOTTOM_RIGHT_PANE]->w,
1768                         mwindow->theme->mcanvas_h -
1769                                         cursor_y);
1770         }
1771 }
1772
1773 void MWindowGUI::delete_y_pane(int cursor_y)
1774 {
1775         if(cursor_y < mwindow->theme->mtimebar_h +
1776                 PANE_DRAG_MARGIN &&
1777                 pane[BOTTOM_LEFT_PANE])
1778         {
1779 // give top pane coordinates of bottom pane
1780                 mwindow->edl->local_session->track_start[TOP_LEFT_PANE] =
1781                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] -
1782                         pane[BOTTOM_LEFT_PANE]->y;
1783                 if(mwindow->edl->local_session->track_start[TOP_LEFT_PANE] < 0)
1784                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] = 0;
1785                 mwindow->edl->local_session->track_start[TOP_RIGHT_PANE] =
1786                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE];
1787         }
1788
1789 // delete a pane
1790         switch(total_panes())
1791         {
1792                 case 2:
1793                         delete pane[BOTTOM_LEFT_PANE];
1794                         pane[BOTTOM_LEFT_PANE] = 0;
1795                         pane[TOP_LEFT_PANE]->resize_event(
1796                                 mwindow->theme->mcanvas_x,
1797                                 mwindow->theme->mcanvas_y,
1798                                 mwindow->theme->mcanvas_w,
1799                                 mwindow->theme->mcanvas_h);
1800                         break;
1801
1802                 case 4:
1803 // delete bottom 2 panes
1804
1805                         delete pane[BOTTOM_LEFT_PANE];
1806                         pane[BOTTOM_LEFT_PANE] = 0;
1807                         delete pane[BOTTOM_RIGHT_PANE];
1808                         pane[BOTTOM_RIGHT_PANE] = 0;
1809                         pane[TOP_LEFT_PANE]->resize_event(
1810                                 pane[TOP_LEFT_PANE]->x,
1811                                 mwindow->theme->mcanvas_y,
1812                                 pane[TOP_LEFT_PANE]->w,
1813                                 mwindow->theme->mcanvas_h);
1814                         pane[TOP_RIGHT_PANE]->resize_event(
1815                                 pane[TOP_RIGHT_PANE]->x,
1816                                 mwindow->theme->mcanvas_y,
1817                                 pane[TOP_RIGHT_PANE]->w,
1818                                 mwindow->theme->mcanvas_h);
1819                         break;
1820         }
1821 }
1822
1823 void MWindowGUI::stop_pane_drag()
1824 {
1825         dragging_pane = 0;
1826         resource_thread->stop_draw(1);
1827
1828         if(x_pane_drag)
1829         {
1830 // cursor position relative to canvas
1831                 int cursor_x = x_pane_drag->get_x() -
1832                         get_x() -
1833                         BC_DisplayInfo::get_left_border() -
1834                         mwindow->theme->mcanvas_x +
1835                         mwindow->theme->pane_w;
1836                 delete x_pane_drag;
1837                 x_pane_drag = 0;
1838
1839
1840                 if(cursor_x >= mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1841                         cursor_x < mwindow->theme->mcanvas_w -
1842                                 BC_ScrollBar::get_span(SCROLL_VERT) -
1843                                 PANE_DRAG_MARGIN)
1844                 {
1845                         create_x_pane(cursor_x);
1846                         mwindow->edl->local_session->x_pane = cursor_x;
1847                 }
1848                 else
1849 // deleted a pane
1850                 {
1851                         delete_x_pane(cursor_x);
1852                         mwindow->edl->local_session->x_pane = -1;
1853                 }
1854
1855
1856         }
1857
1858         if(y_pane_drag)
1859         {
1860 // cursor position relative to canvas
1861                 int cursor_y = y_pane_drag->get_y() -
1862                         get_y() -
1863                         BC_DisplayInfo::get_top_border() -
1864                         mwindow->theme->mcanvas_y +
1865                         mwindow->theme->pane_h;
1866                 delete y_pane_drag;
1867                 y_pane_drag = 0;
1868
1869
1870
1871                 if(cursor_y >= mwindow->theme->mtimebar_h +
1872                                 PANE_DRAG_MARGIN &&
1873                         cursor_y < mwindow->theme->mcanvas_h -
1874                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
1875                                 PANE_DRAG_MARGIN)
1876                 {
1877                         create_y_pane(cursor_y);
1878                         mwindow->edl->local_session->y_pane = cursor_y;
1879                 }
1880                 else
1881                 {
1882                         delete_y_pane(cursor_y);
1883                         mwindow->edl->local_session->y_pane = -1;
1884                 }
1885         }
1886
1887         update_pane_dividers();
1888         update_cursor();
1889 // required to get new widgets to appear
1890         show_window();
1891         resource_thread->start_draw();
1892 }
1893
1894 // create panes from EDL
1895 void MWindowGUI::load_panes()
1896 {
1897         int need_x_panes = 0;
1898         int need_y_panes = 0;
1899 // use names from create functions
1900         int cursor_x = mwindow->edl->local_session->x_pane;
1901         int cursor_y = mwindow->edl->local_session->y_pane;
1902
1903         resource_thread->stop_draw(1);
1904         if(cursor_x >=
1905                 mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1906                 cursor_x <
1907                 mwindow->theme->mcanvas_w -
1908                                 BC_ScrollBar::get_span(SCROLL_VERT) -
1909                                 PANE_DRAG_MARGIN)
1910         {
1911                 need_x_panes = 1;
1912         }
1913
1914         if(cursor_y >=
1915                 mwindow->theme->mtimebar_h + PANE_DRAG_MARGIN &&
1916                 cursor_y <
1917                 mwindow->theme->mcanvas_h -
1918                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
1919                                 PANE_DRAG_MARGIN)
1920         {
1921                 need_y_panes = 1;
1922         }
1923
1924 //printf("MWindowGUI::load_panes %d %d %d\n", __LINE__, need_x_panes, need_y_panes);
1925
1926
1927         if(need_x_panes)
1928         {
1929                 if(need_y_panes)
1930                 {
1931 // 4 panes
1932                         if(total_panes() == 1)
1933                         {
1934 // create 4 panes
1935 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1936                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1937                                         TOP_RIGHT_PANE,
1938                                         mwindow->theme->mcanvas_x +
1939                                                 cursor_x,
1940                                         mwindow->theme->mcanvas_y,
1941                                         mwindow->theme->mcanvas_x +
1942                                                 mwindow->theme->mcanvas_w -
1943                                                 cursor_x,
1944                                         cursor_y - mwindow->theme->pane_h);
1945                                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1946                                         BOTTOM_LEFT_PANE,
1947                                         mwindow->theme->mcanvas_x,
1948                                         mwindow->theme->mcanvas_y +
1949                                                 cursor_y,
1950                                         cursor_x - mwindow->theme->pane_w,
1951                                         mwindow->theme->mcanvas_h -
1952                                                 cursor_y);
1953                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1954                                         BOTTOM_RIGHT_PANE,
1955                                         pane[TOP_RIGHT_PANE]->x,
1956                                         mwindow->theme->mcanvas_y +
1957                                                 cursor_y,
1958                                         pane[TOP_RIGHT_PANE]->w,
1959                                         mwindow->theme->mcanvas_h -
1960                                                 cursor_y);
1961                                 pane[TOP_LEFT_PANE]->resize_event(
1962                                         pane[TOP_LEFT_PANE]->x,
1963                                         pane[TOP_LEFT_PANE]->y,
1964                                         cursor_x - mwindow->theme->pane_w,
1965                                         cursor_y - mwindow->theme->pane_h);
1966                                 pane[TOP_RIGHT_PANE]->create_objects();
1967                                 pane[BOTTOM_LEFT_PANE]->create_objects();
1968                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1969                         }
1970                         else
1971                         if(horizontal_panes())
1972                         {
1973 // create vertical panes
1974 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1975                                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1976                                         BOTTOM_LEFT_PANE,
1977                                         mwindow->theme->mcanvas_x,
1978                                         mwindow->theme->mcanvas_y +
1979                                                 cursor_y,
1980                                         cursor_x - mwindow->theme->pane_w,
1981                                         mwindow->theme->mcanvas_h -
1982                                                 cursor_y);
1983                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1984                                         BOTTOM_RIGHT_PANE,
1985                                         pane[TOP_RIGHT_PANE]->x,
1986                                         mwindow->theme->mcanvas_y +
1987                                                 cursor_y,
1988                                         pane[TOP_RIGHT_PANE]->w,
1989                                         mwindow->theme->mcanvas_h -
1990                                                 cursor_y);
1991                                 pane[TOP_LEFT_PANE]->resize_event(
1992                                         pane[TOP_LEFT_PANE]->x,
1993                                         pane[TOP_LEFT_PANE]->y,
1994                                         cursor_x - mwindow->theme->pane_w,
1995                                         cursor_y - mwindow->theme->pane_h);
1996                                 pane[TOP_RIGHT_PANE]->resize_event(
1997                                         mwindow->theme->mcanvas_x +
1998                                                 cursor_x,
1999                                         mwindow->theme->mcanvas_y,
2000                                         mwindow->theme->mcanvas_x +
2001                                                 mwindow->theme->mcanvas_w -
2002                                                 cursor_x,
2003                                         cursor_y - mwindow->theme->pane_h);
2004                                 pane[BOTTOM_LEFT_PANE]->create_objects();
2005                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
2006                         }
2007                         else
2008                         if(vertical_panes())
2009                         {
2010 // create horizontal panes
2011 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2012                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
2013                                         TOP_RIGHT_PANE,
2014                                         mwindow->theme->mcanvas_x +
2015                                                 cursor_x,
2016                                         mwindow->theme->mcanvas_y,
2017                                         mwindow->theme->mcanvas_x +
2018                                                 mwindow->theme->mcanvas_w -
2019                                                 cursor_x,
2020                                         cursor_y - mwindow->theme->pane_h);
2021                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
2022                                         BOTTOM_RIGHT_PANE,
2023                                         pane[TOP_RIGHT_PANE]->x,
2024                                         mwindow->theme->mcanvas_y +
2025                                                 cursor_y,
2026                                         pane[TOP_RIGHT_PANE]->w,
2027                                         mwindow->theme->mcanvas_h -
2028                                                 cursor_y);
2029                                 pane[TOP_LEFT_PANE]->resize_event(
2030                                         pane[TOP_LEFT_PANE]->x,
2031                                         pane[TOP_LEFT_PANE]->y,
2032                                         cursor_x - mwindow->theme->pane_w,
2033                                         cursor_y - mwindow->theme->pane_h);
2034                                 pane[BOTTOM_LEFT_PANE]->resize_event(
2035                                         pane[TOP_LEFT_PANE]->x,
2036                                         mwindow->theme->mcanvas_y +
2037                                                 cursor_y,
2038                                         mwindow->theme->mcanvas_x +
2039                                                 mwindow->theme->mcanvas_w -
2040                                                 cursor_x -  mwindow->theme->pane_w,
2041                                         mwindow->theme->mcanvas_h -
2042                                                 cursor_y);
2043                                 pane[TOP_RIGHT_PANE]->create_objects();
2044                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
2045
2046
2047                         }
2048                         else
2049                         {
2050 // resize all panes
2051 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2052                                 pane[TOP_LEFT_PANE]->resize_event(
2053                                         pane[TOP_LEFT_PANE]->x,
2054                                         pane[TOP_LEFT_PANE]->y,
2055                                         cursor_x - mwindow->theme->pane_w,
2056                                         cursor_y - mwindow->theme->pane_h);
2057                                 pane[TOP_RIGHT_PANE]->resize_event(
2058                                         mwindow->theme->mcanvas_x +
2059                                                 cursor_x,
2060                                         mwindow->theme->mcanvas_y,
2061                                         mwindow->theme->mcanvas_x +
2062                                                 mwindow->theme->mcanvas_w -
2063                                                 cursor_x,
2064                                         cursor_y - mwindow->theme->pane_h);
2065                                 pane[BOTTOM_LEFT_PANE]->resize_event(
2066                                         pane[TOP_LEFT_PANE]->x,
2067                                         mwindow->theme->mcanvas_y +
2068                                                 cursor_y,
2069                                         mwindow->theme->mcanvas_x +
2070                                                 mwindow->theme->mcanvas_w -
2071                                                 cursor_x - mwindow->theme->pane_w,
2072                                         mwindow->theme->mcanvas_h -
2073                                                 cursor_y);
2074                                 pane[BOTTOM_RIGHT_PANE]->resize_event(
2075                                         pane[TOP_RIGHT_PANE]->x,
2076                                         mwindow->theme->mcanvas_y +
2077                                                 cursor_y,
2078                                         pane[TOP_RIGHT_PANE]->w,
2079                                         mwindow->theme->mcanvas_h -
2080                                                 cursor_y);
2081
2082
2083                         }
2084                 }
2085                 else
2086                 {
2087 // 2 X panes
2088                         if(pane[BOTTOM_LEFT_PANE]) delete pane[BOTTOM_LEFT_PANE];
2089                         if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2090                         pane[BOTTOM_LEFT_PANE] = 0;
2091                         pane[BOTTOM_RIGHT_PANE] = 0;
2092
2093                         if(!pane[TOP_RIGHT_PANE])
2094                         {
2095                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
2096                                         TOP_RIGHT_PANE,
2097                                         mwindow->theme->mcanvas_x +
2098                                                 cursor_x,
2099                                         mwindow->theme->mcanvas_y,
2100                                         mwindow->theme->mcanvas_x +
2101                                                 mwindow->theme->mcanvas_w -
2102                                                 cursor_x,
2103                                         mwindow->theme->mcanvas_h);
2104                                 pane[TOP_LEFT_PANE]->resize_event(
2105                                         mwindow->theme->mcanvas_x,
2106                                         mwindow->theme->mcanvas_y,
2107                                         cursor_x - mwindow->theme->pane_w,
2108                                         mwindow->theme->mcanvas_h);
2109                                 pane[TOP_RIGHT_PANE]->create_objects();
2110                         }
2111                         else
2112                         {
2113                                 pane[TOP_LEFT_PANE]->resize_event(
2114                                         mwindow->theme->mcanvas_x,
2115                                         mwindow->theme->mcanvas_y,
2116                                         cursor_x - mwindow->theme->pane_w,
2117                                         mwindow->theme->mcanvas_h);
2118                                 pane[TOP_RIGHT_PANE]->resize_event(
2119                                         mwindow->theme->mcanvas_x +
2120                                                 cursor_x,
2121                                         pane[TOP_RIGHT_PANE]->y,
2122                                         mwindow->theme->mcanvas_x +
2123                                                 mwindow->theme->mcanvas_w -
2124                                                 cursor_x,
2125                                         mwindow->theme->mcanvas_h);
2126                         }
2127                 }
2128         }
2129         else
2130         if(need_y_panes)
2131         {
2132 // 2 Y panes
2133                 if(pane[TOP_RIGHT_PANE]) delete pane[TOP_RIGHT_PANE];
2134                 if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2135                 pane[TOP_RIGHT_PANE] = 0;
2136                 pane[BOTTOM_RIGHT_PANE] = 0;
2137
2138                 if(!pane[BOTTOM_LEFT_PANE])
2139                 {
2140 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2141                         pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
2142                                 BOTTOM_LEFT_PANE,
2143                                 mwindow->theme->mcanvas_x,
2144                                 mwindow->theme->mcanvas_y +
2145                                         cursor_y,
2146                                 mwindow->theme->mcanvas_w,
2147                                 mwindow->theme->mcanvas_h -
2148                                         cursor_y);
2149                         pane[TOP_LEFT_PANE]->resize_event(
2150                                 mwindow->theme->mcanvas_x,
2151                                 mwindow->theme->mcanvas_y,
2152                                 mwindow->theme->mcanvas_w,
2153                                 pane[BOTTOM_LEFT_PANE]->y -
2154                                         mwindow->theme->mcanvas_y -
2155                                         mwindow->theme->pane_h);
2156                         pane[BOTTOM_LEFT_PANE]->create_objects();
2157                 }
2158                 else
2159                 {
2160                         pane[TOP_LEFT_PANE]->resize_event(
2161                                 mwindow->theme->mcanvas_x,
2162                                 mwindow->theme->mcanvas_y,
2163                                 mwindow->theme->mcanvas_w,
2164                                 cursor_y - mwindow->theme->pane_h);
2165                         pane[BOTTOM_LEFT_PANE]->resize_event(
2166                                 pane[BOTTOM_LEFT_PANE]->x,
2167                                 cursor_y +
2168                                         mwindow->theme->mcanvas_y,
2169                                 mwindow->theme->mcanvas_w,
2170                                 mwindow->theme->mcanvas_h -
2171                                         cursor_y);
2172                 }
2173         }
2174         else
2175         {
2176 // 1 pane
2177                 if(pane[TOP_RIGHT_PANE]) delete pane[TOP_RIGHT_PANE];
2178                 if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2179                 if(pane[BOTTOM_LEFT_PANE]) delete pane[BOTTOM_LEFT_PANE];
2180                 pane[TOP_RIGHT_PANE] = 0;
2181                 pane[BOTTOM_RIGHT_PANE] = 0;
2182                 pane[BOTTOM_LEFT_PANE] = 0;
2183                 pane[TOP_LEFT_PANE]->resize_event(
2184                         mwindow->theme->mcanvas_x,
2185                         mwindow->theme->mcanvas_y,
2186                         mwindow->theme->mcanvas_w,
2187                         mwindow->theme->mcanvas_h);
2188         }
2189
2190         update_pane_dividers();
2191         show_window();
2192
2193         resource_thread->start_draw();
2194 }
2195
2196 void MWindowGUI::update_pane_dividers()
2197 {
2198
2199         if(horizontal_panes() || total_panes() == 4)
2200         {
2201                 int x = pane[TOP_RIGHT_PANE]->x - mwindow->theme->pane_w;
2202                 int y = mwindow->theme->mcanvas_y;
2203                 int h = mwindow->theme->mcanvas_h;
2204
2205                 if(!x_divider)
2206                 {
2207                         add_subwindow(x_divider = new PaneDivider(
2208                                 mwindow, x, y, h, 1));
2209                         x_divider->create_objects();
2210                 }
2211                 else
2212                 {
2213                         x_divider->reposition_window(x, y, h);
2214                         x_divider->draw(0);
2215                 }
2216         }
2217         else
2218         {
2219                 if(x_divider)
2220                 {
2221                         delete x_divider;
2222                         x_divider = 0;
2223                 }
2224         }
2225
2226         if(vertical_panes() || total_panes() == 4)
2227         {
2228                 int x = mwindow->theme->mcanvas_x;
2229                 int y = pane[BOTTOM_LEFT_PANE]->y -
2230                         mwindow->theme->pane_h;
2231                 int w = mwindow->theme->mcanvas_w;
2232                 if(!y_divider)
2233                 {
2234                         add_subwindow(y_divider = new PaneDivider(
2235                                 mwindow, x, y, w, 0));
2236                         y_divider->create_objects();
2237                 }
2238                 else
2239                 {
2240                         y_divider->reposition_window(x, y, w);
2241                         y_divider->draw(0);
2242                 }
2243         }
2244         else
2245         {
2246                 if(y_divider)
2247                 {
2248                         delete y_divider;
2249                         y_divider = 0;
2250                 }
2251         }
2252 }
2253
2254 void MWindowGUI::draw_samplemovement()
2255 {
2256         draw_canvas(0, 1);
2257         show_cursor(1);
2258         flash_canvas(0);
2259         update_timebar(0);
2260         zoombar->update();
2261         update_scrollbars(1);
2262 }
2263
2264 void MWindowGUI::draw_trackmovement()
2265 {
2266         update_scrollbars(0);
2267         draw_canvas(0, 0);
2268         update_patchbay();
2269         flash_canvas(1);
2270 }
2271
2272
2273 void MWindowGUI::update_mixers(Track *track, int v)
2274 {
2275         for( int i=0; i<TOTAL_PANES;  ++i ) {
2276                 if( !pane[i] ) continue;
2277                 PatchBay *patchbay = pane[i]->patchbay;
2278                 if( !patchbay ) continue;
2279                 for( int j=0; j<patchbay->patches.total; ++j ) {
2280                         PatchGUI *patchgui = patchbay->patches.values[j];
2281                         if( !patchgui->mix ) continue;
2282                         if( !track || patchgui->track == track ) {
2283                                 patchgui->mix->update(v>=0 ? v :
2284                                         mwindow->mixer_track_active(patchgui->track));
2285                         }
2286                 }
2287         }
2288 }
2289
2290 void MWindowGUI::stop_transport(const char *lock_msg)
2291 {
2292         if( !mbuttons->transport->is_stopped() ) {
2293                 if( lock_msg ) unlock_window();
2294                 mbuttons->transport->handle_transport(STOP, 1, 0, 0);
2295                 if( lock_msg ) lock_window(lock_msg);
2296         }
2297 }
2298
2299 PaneButton::PaneButton(MWindow *mwindow, int x, int y)
2300  : BC_Button(x, y, mwindow->theme->get_image_set("pane"))
2301 {
2302         this->mwindow = mwindow;
2303 }
2304
2305 int PaneButton::cursor_motion_event()
2306 {
2307         if(get_top_level()->get_button_down() &&
2308                 is_event_win() &&
2309                 get_status() == BUTTON_DOWNHI &&
2310                 !cursor_inside())
2311         {
2312 //              printf("PaneButton::cursor_motion_event %d\n", __LINE__);
2313 // create drag bar
2314                 if(get_cursor_x() < 0 && !mwindow->gui->dragging_pane)
2315                 {
2316                         mwindow->gui->start_x_pane_drag();
2317                 }
2318                 else
2319                 if(get_cursor_y() < 0 && !mwindow->gui->dragging_pane)
2320                 {
2321                         mwindow->gui->start_y_pane_drag();
2322                 }
2323         }
2324
2325         mwindow->gui->handle_pane_drag();
2326
2327         int result = BC_Button::cursor_motion_event();
2328         return result;
2329 }
2330
2331 int PaneButton::button_release_event()
2332 {
2333         if( get_buttonpress() != WHEEL_DOWN && get_buttonpress() != WHEEL_UP )
2334                 mwindow->gui->stop_pane_drag();
2335         int result = BC_Button::button_release_event();
2336         return result;
2337 }
2338
2339
2340 FFMpegToggle::FFMpegToggle(MWindow *mwindow, MButtons *mbuttons, int x, int y)
2341  : BC_Toggle(x, y, mwindow->theme->ffmpeg_toggle,
2342          mwindow->preferences->get_file_probe_armed("FFMPEG_Early") > 0 ? 1 : 0)
2343 {
2344         this->mwindow = mwindow;
2345         this->mbuttons = mbuttons;
2346         set_tooltip(get_value() ? FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
2347 }
2348
2349 FFMpegToggle::~FFMpegToggle()
2350 {
2351 }
2352
2353 int FFMpegToggle::handle_event()
2354 {
2355         int ffmpeg_early_probe = get_value();
2356         set_tooltip(ffmpeg_early_probe ? FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
2357         mwindow->preferences->set_file_probe_armed("FFMPEG_Early", ffmpeg_early_probe);
2358         mwindow->preferences->set_file_probe_armed("FFMPEG_Late", !ffmpeg_early_probe);
2359
2360         mwindow->show_warning(&mwindow->preferences->warn_indexes,
2361                 _("Changing the base codecs may require rebuilding indexes."));
2362         return 1;
2363 }
2364
2365