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