asset drag/drop to viewers, bluebanana bug, listbox fontlist highlight
[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 int MWindowGUI::show_message(char *message, int color)
922 {
923 // printf("MWindowGUI::show_message %d: %s 0x%08x 0x%08x\n",
924 // __LINE__, message, color, mwindow->theme->message_normal);
925         if(color < 0) color = mwindow->theme->message_normal;
926         statusbar->status_text->set_color(color);
927         statusbar->status_text->update(message);
928         return 0;
929 }
930
931
932 // Drag motion called from other window
933 int MWindowGUI::drag_motion()
934 {
935         if(get_hidden()) return 0;
936
937         Track *over_track = 0;
938         Edit *over_edit = 0;
939         PluginSet *over_pluginset = 0;
940         Plugin *over_plugin = 0;
941         int redraw = 0;
942
943         if(drag_popup)
944         {
945                 drag_popup->cursor_motion_event();
946         }
947
948
949 // there's no point in drawing highlights has until drag operation has been set
950         if (!mwindow->session->current_operation)
951                 return 0;
952
953         for(int i = 0; i < TOTAL_PANES; i++)
954         {
955                 if(pane[i]) pane[i]->canvas->drag_motion(
956                         &over_track,
957                         &over_edit,
958                         &over_pluginset,
959                         &over_plugin);
960         }
961
962         if(mwindow->session->track_highlighted != over_track)
963         {
964                 mwindow->session->track_highlighted = over_track;
965                 redraw = 1;
966         }
967
968         if(mwindow->session->edit_highlighted != over_edit)
969         {
970                 mwindow->session->edit_highlighted = over_edit;
971                 redraw = 1;
972         }
973
974         if(mwindow->session->pluginset_highlighted != over_pluginset)
975         {
976                 mwindow->session->pluginset_highlighted = over_pluginset;
977                 redraw = 1;
978         }
979
980         if(mwindow->session->plugin_highlighted != over_plugin)
981         {
982                 mwindow->session->plugin_highlighted = over_plugin;
983                 redraw = 1;
984         }
985
986         if( mwindow->session->current_operation == DRAG_ASSET ||
987             mwindow->session->current_operation == DRAG_EDIT ||
988             mwindow->session->current_operation == DRAG_AEFFECT_COPY ||
989             mwindow->session->current_operation == DRAG_VEFFECT_COPY )
990         {
991                 redraw = 1;
992         }
993
994
995 // printf("drag_motion %d %d over_track=%p over_edit=%p\n",
996 // __LINE__,
997 // redraw,
998 // over_track,
999 // over_edit);
1000         if(redraw)
1001         {
1002                 lock_window("MWindowGUI::drag_motion");
1003                 draw_overlays(1);
1004                 unlock_window();
1005         }
1006         return 0;
1007 }
1008
1009 int MWindowGUI::drag_stop()
1010 {
1011         if(get_hidden()) return 0;
1012         int result = 0, redraw = 0;
1013
1014         for(int i = 0; i < TOTAL_PANES; i++)
1015         {
1016                 if(pane[i]) result |= pane[i]->canvas->drag_stop(
1017                         &redraw);
1018         }
1019         mwindow->edl->optimize();
1020
1021 // since we don't have subwindows we have to terminate any drag operation
1022         if(result)
1023         {
1024                 if (mwindow->session->track_highlighted
1025                         || mwindow->session->edit_highlighted
1026                         || mwindow->session->plugin_highlighted
1027                         || mwindow->session->pluginset_highlighted)
1028                         redraw = 1;
1029                 mwindow->session->track_highlighted = 0;
1030                 mwindow->session->edit_highlighted = 0;
1031                 mwindow->session->plugin_highlighted = 0;
1032                 mwindow->session->pluginset_highlighted = 0;
1033                 mwindow->session->current_operation = NO_OPERATION;
1034         }
1035
1036
1037 //printf("TrackCanvas::drag_stop %d %d\n", redraw, mwindow->session->current_operation);
1038         if(redraw)
1039         {
1040                 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
1041                 update_scrollbars(0);
1042                 update_patchbay();
1043                 draw_canvas(1, 1);
1044                 update_cursor();
1045                 flash_canvas(1);
1046         }
1047
1048         if(drag_popup)
1049         {
1050                 delete drag_popup;
1051                 drag_popup = 0;
1052         }
1053         return result;
1054 }
1055
1056 void MWindowGUI::default_positions()
1057 {
1058 //printf("MWindowGUI::default_positions 1\n");
1059         VWindow *vwindow = mwindow->vwindows.size() > DEFAULT_VWINDOW ?
1060                 mwindow->vwindows.get(DEFAULT_VWINDOW) : 0;
1061         if( vwindow && !vwindow->is_running() ) vwindow = 0;
1062         if( vwindow ) vwindow->gui->lock_window("MWindowGUI::default_positions");
1063         mwindow->cwindow->gui->lock_window("MWindowGUI::default_positions");
1064         mwindow->awindow->gui->lock_window("MWindowGUI::default_positions");
1065
1066 // printf("MWindowGUI::default_positions 1 %d %d %d %d\n", mwindow->session->vwindow_x,
1067 // mwindow->session->vwindow_y,
1068 // mwindow->session->vwindow_w,
1069 // mwindow->session->vwindow_h);
1070         reposition_window(mwindow->session->mwindow_x,
1071                 mwindow->session->mwindow_y,
1072                 mwindow->session->mwindow_w,
1073                 mwindow->session->mwindow_h);
1074         if( vwindow ) vwindow->gui->reposition_window(mwindow->session->vwindow_x,
1075                 mwindow->session->vwindow_y,
1076                 mwindow->session->vwindow_w,
1077                 mwindow->session->vwindow_h);
1078         mwindow->cwindow->gui->reposition_window(mwindow->session->cwindow_x,
1079                 mwindow->session->cwindow_y,
1080                 mwindow->session->cwindow_w,
1081                 mwindow->session->cwindow_h);
1082         mwindow->awindow->gui->reposition_window(mwindow->session->awindow_x,
1083                 mwindow->session->awindow_y,
1084                 mwindow->session->awindow_w,
1085                 mwindow->session->awindow_h);
1086 //printf("MWindowGUI::default_positions 1\n");
1087
1088         resize_event(mwindow->session->mwindow_w,
1089                 mwindow->session->mwindow_h);
1090 //printf("MWindowGUI::default_positions 1\n");
1091         if( vwindow ) vwindow->gui->resize_event(mwindow->session->vwindow_w,
1092                 mwindow->session->vwindow_h);
1093 //printf("MWindowGUI::default_positions 1\n");
1094         mwindow->cwindow->gui->resize_event(mwindow->session->cwindow_w,
1095                 mwindow->session->cwindow_h);
1096 //printf("MWindowGUI::default_positions 1\n");
1097         mwindow->awindow->gui->resize_event(mwindow->session->awindow_w,
1098                 mwindow->session->awindow_h);
1099
1100 //printf("MWindowGUI::default_positions 1\n");
1101
1102         flush();
1103         if( vwindow ) vwindow->gui->flush();
1104         mwindow->cwindow->gui->flush();
1105         mwindow->awindow->gui->flush();
1106
1107         if( vwindow ) vwindow->gui->unlock_window();
1108         mwindow->cwindow->gui->unlock_window();
1109         mwindow->awindow->gui->unlock_window();
1110 //printf("MWindowGUI::default_positions 2\n");
1111 }
1112
1113
1114 int MWindowGUI::button_release_event()
1115 {
1116         if( keyvalue_popup ) {
1117                 delete keyvalue_popup;  keyvalue_popup = 0;
1118         }
1119         return 0;
1120 }
1121
1122
1123 int MWindowGUI::repeat_event(int64_t duration)
1124 {
1125 // if(duration == 100)
1126 // mwindow->sync_parameters(CHANGE_ALL);
1127         int result = 0;
1128         for(int i = 0; i < TOTAL_PANES; i++)
1129         {
1130                 if(pane[i]) result = pane[i]->cursor->repeat_event(duration);
1131         }
1132         return result;
1133 }
1134
1135
1136 int MWindowGUI::translation_event()
1137 {
1138 //printf("MWindowGUI::translation_event 1 %d %d\n", get_x(), get_y());
1139         mwindow->session->mwindow_x = get_x();
1140         mwindow->session->mwindow_y = get_y();
1141         return 0;
1142 }
1143
1144
1145 int MWindowGUI::save_defaults(BC_Hash *defaults)
1146 {
1147         defaults->update("MWINDOWWIDTH", get_w());
1148         defaults->update("MWINDOWHEIGHT", get_h());
1149         mainmenu->save_defaults(defaults);
1150         BC_WindowBase::save_defaults(defaults);
1151         return 0;
1152 }
1153
1154 int MWindowGUI::keypress_event()
1155 {
1156 //printf("MWindowGUI::keypress_event 1 %d\n", get_keypress());
1157         int result = mbuttons->keypress_event();
1158         if( result ) return result;
1159
1160         switch(get_keypress()) {
1161         case 'e':
1162                 mwindow->toggle_editing_mode();
1163                 result = 1;
1164                 break;
1165
1166         case '1': case '2': case '3': case '4':
1167         case '5': case '6': case '7': case '8':
1168                 if( !alt_down() || shift_down() ) break;
1169                 if( !mwindow->select_asset(get_keypress()-'1',1) )
1170                         result = 1;
1171                 break;
1172
1173         case LEFT:
1174                 if( !ctrl_down() ) {
1175                         if( alt_down() ) {
1176                                 unlock_window();
1177                                 mbuttons->transport->handle_transport(STOP, 1, 0, 0);
1178                                 lock_window("MWindowGUI::keypress_event 1");
1179                                 mwindow->prev_edit_handle(shift_down());
1180                         }
1181                         else
1182                                 mwindow->move_left();
1183                         result = 1;
1184                 }
1185                 break;
1186
1187         case RIGHT:
1188                 if( !ctrl_down() ) {
1189                         if( alt_down() ) {
1190                                 unlock_window();
1191                                 mbuttons->transport->handle_transport(STOP, 1, 0, 0);
1192                                 lock_window("MWindowGUI::keypress_event 2");
1193                                 mwindow->next_edit_handle(shift_down());
1194                         }
1195                         else
1196                                 mwindow->move_right();
1197                         result = 1;
1198                 }
1199                 break;
1200
1201         case UP:
1202                 if( ctrl_down() && !alt_down() )
1203                         mwindow->expand_y();
1204                 else if( !ctrl_down() && alt_down() )
1205                         mwindow->expand_autos(0,1,1);
1206                 else if( ctrl_down() && alt_down() )
1207                         mwindow->expand_autos(1,1,1);
1208                 else
1209                         mwindow->expand_sample();
1210                 result = 1;
1211                 break;
1212
1213         case DOWN:
1214                 if( ctrl_down() && !alt_down() )
1215                         mwindow->zoom_in_y();
1216                 else if( !ctrl_down() && alt_down() )
1217                         mwindow->shrink_autos(0,1,1);
1218                 else if( ctrl_down() && alt_down() )
1219                         mwindow->shrink_autos(1,1,1);
1220                 else
1221                         mwindow->zoom_in_sample();
1222                 result = 1;
1223                 break;
1224
1225         case PGUP:
1226                 if( !ctrl_down() )
1227                         mwindow->move_up();
1228                 else
1229                         mwindow->expand_t();
1230                 result = 1;
1231                 break;
1232
1233         case PGDN:
1234                 if( !ctrl_down() )
1235                         mwindow->move_down();
1236                 else
1237                         mwindow->zoom_in_t();
1238                 result = 1;
1239                 break;
1240
1241         case TAB:
1242         case LEFTTAB:
1243                 Track *this_track = 0;
1244                 for( int i=0; i<TOTAL_PANES; ++i ) {
1245                         if( !pane[i] ) continue;
1246                         if( (this_track = pane[i]->over_track()) != 0 ) break;
1247                         if( (this_track = pane[i]->over_patchbay()) != 0 ) break;
1248                 }
1249
1250                 if( get_keypress() == TAB ) { // Switch the record button
1251                         if( this_track )
1252                                 this_track->record = !this_track->record ? 1 : 0;
1253                 }
1254                 else {
1255                         int total_selected = mwindow->edl->tracks->total_of(Tracks::RECORD);
1256                         // all selected if nothing previously selected or
1257                         // if this patch was previously the only one selected and armed
1258                         int selected = !total_selected || (total_selected == 1 &&
1259                                 this_track && this_track->record ) ? 1 : 0;
1260                         mwindow->edl->tracks->select_all(Tracks::RECORD, selected);
1261                         if( !selected && this_track ) this_track->record = 1;
1262                 }
1263
1264                 update(0, 1, 0, 0, 1, 0, 1);
1265                 unlock_window();
1266                 mwindow->cwindow->update(0, 1, 1);
1267                 lock_window("TrackCanvas::keypress_event 3");
1268
1269                 result = 1;
1270                 break;
1271         }
1272
1273 // since things under cursor have changed...
1274         if(result)
1275                 cursor_motion_event();
1276
1277         return result;
1278 }
1279
1280 int MWindowGUI::keyboard_listener(BC_WindowBase *wp)
1281 {
1282         return key_listener(wp->get_keypress());
1283 }
1284
1285 int MWindowGUI::key_listener(int key)
1286 {
1287         int result = 1;
1288         switch( key ) {
1289         case KPTV:
1290                 if( !record->running() )
1291                         record->start();
1292                 else
1293                         record->record_gui->interrupt_thread->start(0);
1294                 break;
1295         case KPHAND:
1296                 mwindow->quit();
1297                 break;
1298 #ifdef HAVE_DVB
1299         case KPBOOK:
1300                 channel_info->toggle_scan();
1301                 break;
1302 #endif
1303         case KPMENU:
1304                 if( !remote_control->deactivate() )
1305                         remote_control->activate();
1306                 break;
1307         default:
1308                 result = 0;
1309                 break;
1310         }
1311         return result;
1312 }
1313
1314
1315 void MWindowGUI::use_android_remote(int on)
1316 {
1317         if( !on ) {
1318                 delete android_control;
1319                 android_control = 0;
1320                 return;
1321         }
1322         if( android_control ) return;
1323         android_control = new AndroidControl(this);
1324 }
1325
1326 int MWindowGUI::close_event()
1327 {
1328         mainmenu->quit();
1329         return 0;
1330 }
1331
1332 void MWindowGUI::stop_drawing()
1333 {
1334         resource_thread->stop_draw(1);
1335 }
1336
1337 int MWindowGUI::menu_w()
1338 {
1339         return mainmenu->get_w();
1340 }
1341
1342 int MWindowGUI::menu_h()
1343 {
1344         return mainmenu->get_h();
1345 }
1346
1347 void MWindowGUI::start_x_pane_drag()
1348 {
1349         if(!x_pane_drag)
1350         {
1351                 x_pane_drag = new BC_Popup(this,
1352                         get_abs_cursor_x(0) - mwindow->theme->pane_w,
1353                         BC_DisplayInfo::get_top_border() +
1354                                 get_y() +
1355                                 mwindow->theme->mcanvas_y,
1356                         mwindow->theme->pane_w,
1357                         mwindow->theme->mcanvas_h,
1358                         mwindow->theme->drag_pane_color);
1359                 x_pane_drag->draw_3segmentv(0,
1360                         0,
1361                         x_pane_drag->get_h(),
1362                         mwindow->theme->get_image_set("xpane")[BUTTON_DOWNHI]);
1363                 x_pane_drag->flash(1);
1364         }
1365         dragging_pane = 1;
1366 }
1367
1368 void MWindowGUI::start_y_pane_drag()
1369 {
1370         if(!y_pane_drag)
1371         {
1372 //printf("MWindowGUI::start_y_pane_drag %d %d %d\n", __LINE__, get_x(), get_y());
1373                 y_pane_drag = new BC_Popup(this,
1374                         BC_DisplayInfo::get_left_border() +
1375                                 get_x() +
1376                                 mwindow->theme->mcanvas_x,
1377                         get_abs_cursor_y(0) - mwindow->theme->pane_h,
1378                         mwindow->theme->mcanvas_w,
1379                         mwindow->theme->pane_h,
1380                         mwindow->theme->drag_pane_color);
1381                 y_pane_drag->draw_3segmenth(0,
1382                         0,
1383                         y_pane_drag->get_w(),
1384                         mwindow->theme->get_image_set("ypane")[BUTTON_DOWNHI]);
1385                 y_pane_drag->flash(1);
1386         }
1387         dragging_pane = 1;
1388 }
1389
1390 void MWindowGUI::handle_pane_drag()
1391 {
1392         if(dragging_pane)
1393         {
1394                 if(x_pane_drag)
1395                 {
1396                         x_pane_drag->reposition_window(
1397                                 get_abs_cursor_x(0) - mwindow->theme->pane_w,
1398                                 x_pane_drag->get_y());
1399                 }
1400
1401                 if(y_pane_drag)
1402                 {
1403                         y_pane_drag->reposition_window(
1404                                 y_pane_drag->get_x(),
1405                                 get_abs_cursor_y(0) - mwindow->theme->pane_h);
1406                 }
1407         }
1408 }
1409
1410
1411 void MWindowGUI::create_x_pane(int cursor_x)
1412 {
1413         if(total_panes() == 1)
1414         {
1415 // create a horizontal pane
1416 // do this 1st so the resize_event knows there are 2 panes
1417                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] =
1418                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] +
1419                         cursor_x -
1420                         mwindow->theme->patchbay_w;
1421                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1422                         TOP_RIGHT_PANE,
1423                         mwindow->theme->mcanvas_x +
1424                                 cursor_x,
1425                         mwindow->theme->mcanvas_y,
1426                         mwindow->theme->mcanvas_x +
1427                                 mwindow->theme->mcanvas_w -
1428                                 cursor_x,
1429                         mwindow->theme->mcanvas_h);
1430                 pane[TOP_LEFT_PANE]->resize_event(
1431                         mwindow->theme->mcanvas_x,
1432                         mwindow->theme->mcanvas_y,
1433                         cursor_x - mwindow->theme->pane_w,
1434                         mwindow->theme->mcanvas_h);
1435                 pane[TOP_RIGHT_PANE]->create_objects();
1436         }
1437         else
1438         if(vertical_panes())
1439         {
1440 // create 2 horizontal panes
1441                 mwindow->edl->local_session->track_start[TOP_RIGHT_PANE] =
1442                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE];
1443                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1444                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE];
1445                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] =
1446                         mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1447                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] +
1448                         cursor_x -
1449                         mwindow->theme->patchbay_w;
1450                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1451                         TOP_RIGHT_PANE,
1452                         mwindow->theme->mcanvas_x +
1453                                 cursor_x,
1454                         pane[TOP_LEFT_PANE]->y,
1455                         mwindow->theme->mcanvas_x +
1456                                 mwindow->theme->mcanvas_w -
1457                                 cursor_x,
1458                         pane[TOP_LEFT_PANE]->h);
1459                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1460                         BOTTOM_RIGHT_PANE,
1461                         mwindow->theme->mcanvas_x +
1462                                 cursor_x,
1463                         pane[BOTTOM_LEFT_PANE]->y,
1464                         mwindow->theme->mcanvas_x +
1465                                 mwindow->theme->mcanvas_w -
1466                                 cursor_x,
1467                         pane[BOTTOM_LEFT_PANE]->h);
1468                 pane[TOP_LEFT_PANE]->resize_event(
1469                         pane[TOP_LEFT_PANE]->x,
1470                         pane[TOP_LEFT_PANE]->y,
1471                         cursor_x - mwindow->theme->pane_w,
1472                         pane[TOP_LEFT_PANE]->h);
1473                 pane[BOTTOM_LEFT_PANE]->resize_event(
1474                         pane[BOTTOM_LEFT_PANE]->x,
1475                         pane[BOTTOM_LEFT_PANE]->y,
1476                         cursor_x - mwindow->theme->pane_w,
1477                         pane[BOTTOM_LEFT_PANE]->h);
1478                 pane[TOP_RIGHT_PANE]->create_objects();
1479                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1480         }
1481         else
1482         if(horizontal_panes())
1483         {
1484 // resize a horizontal pane
1485                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] +=
1486                         cursor_x -
1487                         pane[TOP_RIGHT_PANE]->x;
1488                 if(mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] < 0)
1489                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] = 0;
1490                 pane[TOP_LEFT_PANE]->resize_event(
1491                         mwindow->theme->mcanvas_x,
1492                         mwindow->theme->mcanvas_y,
1493                         cursor_x - mwindow->theme->pane_w,
1494                         mwindow->theme->mcanvas_h);
1495                 pane[TOP_RIGHT_PANE]->resize_event(
1496                         mwindow->theme->mcanvas_x +
1497                                 cursor_x,
1498                         pane[TOP_RIGHT_PANE]->y,
1499                         mwindow->theme->mcanvas_x +
1500                                 mwindow->theme->mcanvas_w -
1501                                 cursor_x,
1502                         mwindow->theme->mcanvas_h);
1503         }
1504         else
1505         {
1506 // resize 2 horizontal panes
1507                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] +=
1508                         cursor_x -
1509                         pane[TOP_RIGHT_PANE]->x;
1510                 if(mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] < 0)
1511                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] = 0;
1512                 mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1513                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE];
1514
1515                 pane[TOP_LEFT_PANE]->resize_event(
1516                         mwindow->theme->mcanvas_x,
1517                         pane[TOP_LEFT_PANE]->y,
1518                         cursor_x - mwindow->theme->pane_w,
1519                         pane[TOP_LEFT_PANE]->h);
1520                 pane[TOP_RIGHT_PANE]->resize_event(
1521                         mwindow->theme->mcanvas_x +
1522                                 cursor_x,
1523                         pane[TOP_RIGHT_PANE]->y,
1524                         mwindow->theme->mcanvas_x +
1525                                 mwindow->theme->mcanvas_w -
1526                                 cursor_x,
1527                         pane[TOP_RIGHT_PANE]->h);
1528                 pane[BOTTOM_LEFT_PANE]->resize_event(
1529                         mwindow->theme->mcanvas_x,
1530                         pane[BOTTOM_LEFT_PANE]->y,
1531                         cursor_x - mwindow->theme->pane_w,
1532                         pane[BOTTOM_LEFT_PANE]->h);
1533                 pane[BOTTOM_RIGHT_PANE]->resize_event(
1534                         mwindow->theme->mcanvas_x +
1535                                 cursor_x,
1536                         pane[BOTTOM_RIGHT_PANE]->y,
1537                         mwindow->theme->mcanvas_x +
1538                                 mwindow->theme->mcanvas_w -
1539                                 cursor_x,
1540                         pane[BOTTOM_RIGHT_PANE]->h);
1541
1542         }
1543 }
1544
1545
1546 void MWindowGUI::delete_x_pane(int cursor_x)
1547 {
1548 // give left panes coordinates of right pane
1549         if(cursor_x < mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1550                 pane[TOP_RIGHT_PANE])
1551         {
1552                 mwindow->edl->local_session->view_start[TOP_LEFT_PANE] =
1553                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] -
1554                         pane[TOP_RIGHT_PANE]->x + mwindow->theme->patchbay_w;
1555                 if(mwindow->edl->local_session->view_start[TOP_LEFT_PANE] < 0)
1556                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] = 0;
1557                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1558                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1559         }
1560
1561         switch(total_panes())
1562         {
1563                 case 2:
1564                         if(pane[TOP_LEFT_PANE] && pane[TOP_RIGHT_PANE])
1565                         {
1566 // delete right pane
1567                                 delete pane[TOP_RIGHT_PANE];
1568                                 pane[TOP_RIGHT_PANE] = 0;
1569                                 pane[TOP_LEFT_PANE]->resize_event(
1570                                         mwindow->theme->mcanvas_x,
1571                                         mwindow->theme->mcanvas_y,
1572                                         mwindow->theme->mcanvas_w,
1573                                         mwindow->theme->mcanvas_h);
1574
1575                         }
1576                         break;
1577
1578                 case 4:
1579 // delete right panes
1580                         delete pane[TOP_RIGHT_PANE];
1581                         pane[TOP_RIGHT_PANE] = 0;
1582                         delete pane[BOTTOM_RIGHT_PANE];
1583                         pane[BOTTOM_RIGHT_PANE] = 0;
1584                         pane[TOP_LEFT_PANE]->resize_event(
1585                                 mwindow->theme->mcanvas_x,
1586                                 pane[TOP_LEFT_PANE]->y,
1587                                 mwindow->theme->mcanvas_w,
1588                                 pane[TOP_LEFT_PANE]->h);
1589                         pane[BOTTOM_LEFT_PANE]->resize_event(
1590                                 mwindow->theme->mcanvas_x,
1591                                 pane[BOTTOM_LEFT_PANE]->y,
1592                                 mwindow->theme->mcanvas_w,
1593                                 pane[BOTTOM_LEFT_PANE]->h);
1594                         break;
1595         }
1596 }
1597
1598 void MWindowGUI::create_y_pane(int cursor_y)
1599 {
1600         if(total_panes() == 1)
1601         {
1602                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1603                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1604                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] =
1605                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] +
1606                         cursor_y -
1607                         mwindow->theme->mtimebar_h;
1608 // do this 1st so the resize_event knows there are 2 panes
1609                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1610                         BOTTOM_LEFT_PANE,
1611                         mwindow->theme->mcanvas_x,
1612                         mwindow->theme->mcanvas_y +
1613                                 cursor_y,
1614                         mwindow->theme->mcanvas_w,
1615                         mwindow->theme->mcanvas_h -
1616                                 cursor_y);
1617                 pane[TOP_LEFT_PANE]->resize_event(
1618                         mwindow->theme->mcanvas_x,
1619                         mwindow->theme->mcanvas_y,
1620                         mwindow->theme->mcanvas_w,
1621                         pane[BOTTOM_LEFT_PANE]->y -
1622                                 mwindow->theme->mcanvas_y -
1623                                 mwindow->theme->pane_h);
1624                 pane[BOTTOM_LEFT_PANE]->create_objects();
1625         }
1626         else
1627         if(horizontal_panes())
1628         {
1629 // create 2 panes
1630                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1631                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1632                 mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1633                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE];
1634                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] =
1635                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1636                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] +
1637                         cursor_y -
1638                         mwindow->theme->mtimebar_h;
1639
1640                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1641                         BOTTOM_LEFT_PANE,
1642                         pane[TOP_LEFT_PANE]->x,
1643                         mwindow->theme->mcanvas_y +
1644                                 cursor_y,
1645                         pane[TOP_LEFT_PANE]->w,
1646                         mwindow->theme->mcanvas_h -
1647                                 cursor_y);
1648                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1649                         BOTTOM_RIGHT_PANE,
1650                         pane[TOP_RIGHT_PANE]->x,
1651                         mwindow->theme->mcanvas_y +
1652                                 cursor_y,
1653                         pane[TOP_RIGHT_PANE]->w,
1654                         mwindow->theme->mcanvas_h -
1655                                 cursor_y);
1656
1657                 pane[TOP_LEFT_PANE]->resize_event(
1658                         pane[TOP_LEFT_PANE]->x,
1659                         pane[TOP_LEFT_PANE]->y,
1660                         pane[TOP_LEFT_PANE]->w,
1661                         pane[BOTTOM_LEFT_PANE]->y -
1662                                 mwindow->theme->mcanvas_y -
1663                                 mwindow->theme->pane_h);
1664                 pane[TOP_RIGHT_PANE]->resize_event(
1665                         pane[TOP_RIGHT_PANE]->x,
1666                         pane[TOP_RIGHT_PANE]->y,
1667                         pane[TOP_RIGHT_PANE]->w,
1668                         pane[BOTTOM_RIGHT_PANE]->y -
1669                                 mwindow->theme->mcanvas_y -
1670                                 mwindow->theme->pane_h);
1671
1672                 pane[BOTTOM_LEFT_PANE]->create_objects();
1673                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1674         }
1675         else
1676         if(vertical_panes())
1677         {
1678 // resize a pane
1679                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] +=
1680                         cursor_y -
1681                         (pane[BOTTOM_LEFT_PANE]->y - mwindow->theme->mcanvas_y);
1682                 if(mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] < 0)
1683                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] = 0;
1684                 pane[TOP_LEFT_PANE]->resize_event(
1685                         mwindow->theme->mcanvas_x,
1686                         mwindow->theme->mcanvas_y,
1687                         mwindow->theme->mcanvas_w,
1688                         cursor_y - mwindow->theme->pane_h);
1689                 pane[BOTTOM_LEFT_PANE]->resize_event(
1690                         pane[BOTTOM_LEFT_PANE]->x,
1691                         cursor_y +
1692                                 mwindow->theme->mcanvas_y,
1693                         mwindow->theme->mcanvas_w,
1694                         mwindow->theme->mcanvas_h -
1695                                 cursor_y);
1696         }
1697         else
1698         {
1699 // resize 2 panes
1700                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] +=
1701                         cursor_y -
1702                         (pane[BOTTOM_LEFT_PANE]->y - mwindow->theme->mcanvas_y);
1703                 if(mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] < 0)
1704                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] = 0;
1705                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1706                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE];
1707                 pane[TOP_LEFT_PANE]->resize_event(
1708                         pane[TOP_LEFT_PANE]->x,
1709                         pane[TOP_LEFT_PANE]->y,
1710                         pane[TOP_LEFT_PANE]->w,
1711                         cursor_y - mwindow->theme->pane_h);
1712                 pane[BOTTOM_LEFT_PANE]->resize_event(
1713                         pane[BOTTOM_LEFT_PANE]->x,
1714                         cursor_y +
1715                                 mwindow->theme->mcanvas_y,
1716                         pane[BOTTOM_LEFT_PANE]->w,
1717                         mwindow->theme->mcanvas_h -
1718                                         cursor_y);
1719                 pane[TOP_RIGHT_PANE]->resize_event(
1720                         pane[TOP_RIGHT_PANE]->x,
1721                         pane[TOP_RIGHT_PANE]->y,
1722                         pane[TOP_RIGHT_PANE]->w,
1723                         cursor_y - mwindow->theme->pane_h);
1724                 pane[BOTTOM_RIGHT_PANE]->resize_event(
1725                         pane[BOTTOM_RIGHT_PANE]->x,
1726                         cursor_y +
1727                                 mwindow->theme->mcanvas_y,
1728                         pane[BOTTOM_RIGHT_PANE]->w,
1729                         mwindow->theme->mcanvas_h -
1730                                         cursor_y);
1731         }
1732 }
1733
1734 void MWindowGUI::delete_y_pane(int cursor_y)
1735 {
1736         if(cursor_y < mwindow->theme->mtimebar_h +
1737                 PANE_DRAG_MARGIN &&
1738                 pane[BOTTOM_LEFT_PANE])
1739         {
1740 // give top pane coordinates of bottom pane
1741                 mwindow->edl->local_session->track_start[TOP_LEFT_PANE] =
1742                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] -
1743                         pane[BOTTOM_LEFT_PANE]->y;
1744                 if(mwindow->edl->local_session->track_start[TOP_LEFT_PANE] < 0)
1745                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] = 0;
1746                 mwindow->edl->local_session->track_start[TOP_RIGHT_PANE] =
1747                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE];
1748         }
1749
1750 // delete a pane
1751         switch(total_panes())
1752         {
1753                 case 2:
1754                         delete pane[BOTTOM_LEFT_PANE];
1755                         pane[BOTTOM_LEFT_PANE] = 0;
1756                         pane[TOP_LEFT_PANE]->resize_event(
1757                                 mwindow->theme->mcanvas_x,
1758                                 mwindow->theme->mcanvas_y,
1759                                 mwindow->theme->mcanvas_w,
1760                                 mwindow->theme->mcanvas_h);
1761                         break;
1762
1763                 case 4:
1764 // delete bottom 2 panes
1765
1766                         delete pane[BOTTOM_LEFT_PANE];
1767                         pane[BOTTOM_LEFT_PANE] = 0;
1768                         delete pane[BOTTOM_RIGHT_PANE];
1769                         pane[BOTTOM_RIGHT_PANE] = 0;
1770                         pane[TOP_LEFT_PANE]->resize_event(
1771                                 pane[TOP_LEFT_PANE]->x,
1772                                 mwindow->theme->mcanvas_y,
1773                                 pane[TOP_LEFT_PANE]->w,
1774                                 mwindow->theme->mcanvas_h);
1775                         pane[TOP_RIGHT_PANE]->resize_event(
1776                                 pane[TOP_RIGHT_PANE]->x,
1777                                 mwindow->theme->mcanvas_y,
1778                                 pane[TOP_RIGHT_PANE]->w,
1779                                 mwindow->theme->mcanvas_h);
1780                         break;
1781         }
1782 }
1783
1784 void MWindowGUI::stop_pane_drag()
1785 {
1786         dragging_pane = 0;
1787         resource_thread->stop_draw(1);
1788
1789         if(x_pane_drag)
1790         {
1791 // cursor position relative to canvas
1792                 int cursor_x = x_pane_drag->get_x() -
1793                         get_x() -
1794                         BC_DisplayInfo::get_left_border() -
1795                         mwindow->theme->mcanvas_x +
1796                         mwindow->theme->pane_w;
1797                 delete x_pane_drag;
1798                 x_pane_drag = 0;
1799
1800
1801                 if(cursor_x >= mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1802                         cursor_x < mwindow->theme->mcanvas_w -
1803                                 BC_ScrollBar::get_span(SCROLL_VERT) -
1804                                 PANE_DRAG_MARGIN)
1805                 {
1806                         create_x_pane(cursor_x);
1807                         mwindow->edl->local_session->x_pane = cursor_x;
1808                 }
1809                 else
1810 // deleted a pane
1811                 {
1812                         delete_x_pane(cursor_x);
1813                         mwindow->edl->local_session->x_pane = -1;
1814                 }
1815
1816
1817         }
1818
1819         if(y_pane_drag)
1820         {
1821 // cursor position relative to canvas
1822                 int cursor_y = y_pane_drag->get_y() -
1823                         get_y() -
1824                         BC_DisplayInfo::get_top_border() -
1825                         mwindow->theme->mcanvas_y +
1826                         mwindow->theme->pane_h;
1827                 delete y_pane_drag;
1828                 y_pane_drag = 0;
1829
1830
1831
1832                 if(cursor_y >= mwindow->theme->mtimebar_h +
1833                                 PANE_DRAG_MARGIN &&
1834                         cursor_y < mwindow->theme->mcanvas_h -
1835                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
1836                                 PANE_DRAG_MARGIN)
1837                 {
1838                         create_y_pane(cursor_y);
1839                         mwindow->edl->local_session->y_pane = cursor_y;
1840                 }
1841                 else
1842                 {
1843                         delete_y_pane(cursor_y);
1844                         mwindow->edl->local_session->y_pane = -1;
1845                 }
1846         }
1847
1848         update_pane_dividers();
1849         update_cursor();
1850 // required to get new widgets to appear
1851         show_window();
1852         resource_thread->start_draw();
1853 }
1854
1855 // create panes from EDL
1856 void MWindowGUI::load_panes()
1857 {
1858         int need_x_panes = 0;
1859         int need_y_panes = 0;
1860 // use names from create functions
1861         int cursor_x = mwindow->edl->local_session->x_pane;
1862         int cursor_y = mwindow->edl->local_session->y_pane;
1863
1864         resource_thread->stop_draw(1);
1865         if(cursor_x >=
1866                 mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1867                 cursor_x <
1868                 mwindow->theme->mcanvas_w -
1869                                 BC_ScrollBar::get_span(SCROLL_VERT) -
1870                                 PANE_DRAG_MARGIN)
1871         {
1872                 need_x_panes = 1;
1873         }
1874
1875         if(cursor_y >=
1876                 mwindow->theme->mtimebar_h + PANE_DRAG_MARGIN &&
1877                 cursor_y <
1878                 mwindow->theme->mcanvas_h -
1879                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
1880                                 PANE_DRAG_MARGIN)
1881         {
1882                 need_y_panes = 1;
1883         }
1884
1885 //printf("MWindowGUI::load_panes %d %d %d\n", __LINE__, need_x_panes, need_y_panes);
1886
1887
1888         if(need_x_panes)
1889         {
1890                 if(need_y_panes)
1891                 {
1892 // 4 panes
1893                         if(total_panes() == 1)
1894                         {
1895 // create 4 panes
1896 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1897                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1898                                         TOP_RIGHT_PANE,
1899                                         mwindow->theme->mcanvas_x +
1900                                                 cursor_x,
1901                                         mwindow->theme->mcanvas_y,
1902                                         mwindow->theme->mcanvas_x +
1903                                                 mwindow->theme->mcanvas_w -
1904                                                 cursor_x,
1905                                         cursor_y - mwindow->theme->pane_h);
1906                                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1907                                         BOTTOM_LEFT_PANE,
1908                                         mwindow->theme->mcanvas_x,
1909                                         mwindow->theme->mcanvas_y +
1910                                                 cursor_y,
1911                                         cursor_x - mwindow->theme->pane_w,
1912                                         mwindow->theme->mcanvas_h -
1913                                                 cursor_y);
1914                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1915                                         BOTTOM_RIGHT_PANE,
1916                                         pane[TOP_RIGHT_PANE]->x,
1917                                         mwindow->theme->mcanvas_y +
1918                                                 cursor_y,
1919                                         pane[TOP_RIGHT_PANE]->w,
1920                                         mwindow->theme->mcanvas_h -
1921                                                 cursor_y);
1922                                 pane[TOP_LEFT_PANE]->resize_event(
1923                                         pane[TOP_LEFT_PANE]->x,
1924                                         pane[TOP_LEFT_PANE]->y,
1925                                         cursor_x - mwindow->theme->pane_w,
1926                                         cursor_y - mwindow->theme->pane_h);
1927                                 pane[TOP_RIGHT_PANE]->create_objects();
1928                                 pane[BOTTOM_LEFT_PANE]->create_objects();
1929                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1930                         }
1931                         else
1932                         if(horizontal_panes())
1933                         {
1934 // create vertical panes
1935 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1936                                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1937                                         BOTTOM_LEFT_PANE,
1938                                         mwindow->theme->mcanvas_x,
1939                                         mwindow->theme->mcanvas_y +
1940                                                 cursor_y,
1941                                         cursor_x - mwindow->theme->pane_w,
1942                                         mwindow->theme->mcanvas_h -
1943                                                 cursor_y);
1944                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1945                                         BOTTOM_RIGHT_PANE,
1946                                         pane[TOP_RIGHT_PANE]->x,
1947                                         mwindow->theme->mcanvas_y +
1948                                                 cursor_y,
1949                                         pane[TOP_RIGHT_PANE]->w,
1950                                         mwindow->theme->mcanvas_h -
1951                                                 cursor_y);
1952                                 pane[TOP_LEFT_PANE]->resize_event(
1953                                         pane[TOP_LEFT_PANE]->x,
1954                                         pane[TOP_LEFT_PANE]->y,
1955                                         cursor_x - mwindow->theme->pane_w,
1956                                         cursor_y - mwindow->theme->pane_h);
1957                                 pane[TOP_RIGHT_PANE]->resize_event(
1958                                         mwindow->theme->mcanvas_x +
1959                                                 cursor_x,
1960                                         mwindow->theme->mcanvas_y,
1961                                         mwindow->theme->mcanvas_x +
1962                                                 mwindow->theme->mcanvas_w -
1963                                                 cursor_x,
1964                                         cursor_y - mwindow->theme->pane_h);
1965                                 pane[BOTTOM_LEFT_PANE]->create_objects();
1966                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1967                         }
1968                         else
1969                         if(vertical_panes())
1970                         {
1971 // create horizontal panes
1972 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1973                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1974                                         TOP_RIGHT_PANE,
1975                                         mwindow->theme->mcanvas_x +
1976                                                 cursor_x,
1977                                         mwindow->theme->mcanvas_y,
1978                                         mwindow->theme->mcanvas_x +
1979                                                 mwindow->theme->mcanvas_w -
1980                                                 cursor_x,
1981                                         cursor_y - mwindow->theme->pane_h);
1982                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1983                                         BOTTOM_RIGHT_PANE,
1984                                         pane[TOP_RIGHT_PANE]->x,
1985                                         mwindow->theme->mcanvas_y +
1986                                                 cursor_y,
1987                                         pane[TOP_RIGHT_PANE]->w,
1988                                         mwindow->theme->mcanvas_h -
1989                                                 cursor_y);
1990                                 pane[TOP_LEFT_PANE]->resize_event(
1991                                         pane[TOP_LEFT_PANE]->x,
1992                                         pane[TOP_LEFT_PANE]->y,
1993                                         cursor_x - mwindow->theme->pane_w,
1994                                         cursor_y - mwindow->theme->pane_h);
1995                                 pane[BOTTOM_LEFT_PANE]->resize_event(
1996                                         pane[TOP_LEFT_PANE]->x,
1997                                         mwindow->theme->mcanvas_y +
1998                                                 cursor_y,
1999                                         mwindow->theme->mcanvas_x +
2000                                                 mwindow->theme->mcanvas_w -
2001                                                 cursor_x -  mwindow->theme->pane_w,
2002                                         mwindow->theme->mcanvas_h -
2003                                                 cursor_y);
2004                                 pane[TOP_RIGHT_PANE]->create_objects();
2005                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
2006
2007
2008                         }
2009                         else
2010                         {
2011 // resize all panes
2012 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2013                                 pane[TOP_LEFT_PANE]->resize_event(
2014                                         pane[TOP_LEFT_PANE]->x,
2015                                         pane[TOP_LEFT_PANE]->y,
2016                                         cursor_x - mwindow->theme->pane_w,
2017                                         cursor_y - mwindow->theme->pane_h);
2018                                 pane[TOP_RIGHT_PANE]->resize_event(
2019                                         mwindow->theme->mcanvas_x +
2020                                                 cursor_x,
2021                                         mwindow->theme->mcanvas_y,
2022                                         mwindow->theme->mcanvas_x +
2023                                                 mwindow->theme->mcanvas_w -
2024                                                 cursor_x,
2025                                         cursor_y - mwindow->theme->pane_h);
2026                                 pane[BOTTOM_LEFT_PANE]->resize_event(
2027                                         pane[TOP_LEFT_PANE]->x,
2028                                         mwindow->theme->mcanvas_y +
2029                                                 cursor_y,
2030                                         mwindow->theme->mcanvas_x +
2031                                                 mwindow->theme->mcanvas_w -
2032                                                 cursor_x - mwindow->theme->pane_w,
2033                                         mwindow->theme->mcanvas_h -
2034                                                 cursor_y);
2035                                 pane[BOTTOM_RIGHT_PANE]->resize_event(
2036                                         pane[TOP_RIGHT_PANE]->x,
2037                                         mwindow->theme->mcanvas_y +
2038                                                 cursor_y,
2039                                         pane[TOP_RIGHT_PANE]->w,
2040                                         mwindow->theme->mcanvas_h -
2041                                                 cursor_y);
2042
2043
2044                         }
2045                 }
2046                 else
2047                 {
2048 // 2 X panes
2049                         if(pane[BOTTOM_LEFT_PANE]) delete pane[BOTTOM_LEFT_PANE];
2050                         if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2051                         pane[BOTTOM_LEFT_PANE] = 0;
2052                         pane[BOTTOM_RIGHT_PANE] = 0;
2053
2054                         if(!pane[TOP_RIGHT_PANE])
2055                         {
2056                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
2057                                         TOP_RIGHT_PANE,
2058                                         mwindow->theme->mcanvas_x +
2059                                                 cursor_x,
2060                                         mwindow->theme->mcanvas_y,
2061                                         mwindow->theme->mcanvas_x +
2062                                                 mwindow->theme->mcanvas_w -
2063                                                 cursor_x,
2064                                         mwindow->theme->mcanvas_h);
2065                                 pane[TOP_LEFT_PANE]->resize_event(
2066                                         mwindow->theme->mcanvas_x,
2067                                         mwindow->theme->mcanvas_y,
2068                                         cursor_x - mwindow->theme->pane_w,
2069                                         mwindow->theme->mcanvas_h);
2070                                 pane[TOP_RIGHT_PANE]->create_objects();
2071                         }
2072                         else
2073                         {
2074                                 pane[TOP_LEFT_PANE]->resize_event(
2075                                         mwindow->theme->mcanvas_x,
2076                                         mwindow->theme->mcanvas_y,
2077                                         cursor_x - mwindow->theme->pane_w,
2078                                         mwindow->theme->mcanvas_h);
2079                                 pane[TOP_RIGHT_PANE]->resize_event(
2080                                         mwindow->theme->mcanvas_x +
2081                                                 cursor_x,
2082                                         pane[TOP_RIGHT_PANE]->y,
2083                                         mwindow->theme->mcanvas_x +
2084                                                 mwindow->theme->mcanvas_w -
2085                                                 cursor_x,
2086                                         mwindow->theme->mcanvas_h);
2087                         }
2088                 }
2089         }
2090         else
2091         if(need_y_panes)
2092         {
2093 // 2 Y panes
2094                 if(pane[TOP_RIGHT_PANE]) delete pane[TOP_RIGHT_PANE];
2095                 if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2096                 pane[TOP_RIGHT_PANE] = 0;
2097                 pane[BOTTOM_RIGHT_PANE] = 0;
2098
2099                 if(!pane[BOTTOM_LEFT_PANE])
2100                 {
2101 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2102                         pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
2103                                 BOTTOM_LEFT_PANE,
2104                                 mwindow->theme->mcanvas_x,
2105                                 mwindow->theme->mcanvas_y +
2106                                         cursor_y,
2107                                 mwindow->theme->mcanvas_w,
2108                                 mwindow->theme->mcanvas_h -
2109                                         cursor_y);
2110                         pane[TOP_LEFT_PANE]->resize_event(
2111                                 mwindow->theme->mcanvas_x,
2112                                 mwindow->theme->mcanvas_y,
2113                                 mwindow->theme->mcanvas_w,
2114                                 pane[BOTTOM_LEFT_PANE]->y -
2115                                         mwindow->theme->mcanvas_y -
2116                                         mwindow->theme->pane_h);
2117                         pane[BOTTOM_LEFT_PANE]->create_objects();
2118                 }
2119                 else
2120                 {
2121                         pane[TOP_LEFT_PANE]->resize_event(
2122                                 mwindow->theme->mcanvas_x,
2123                                 mwindow->theme->mcanvas_y,
2124                                 mwindow->theme->mcanvas_w,
2125                                 cursor_y - mwindow->theme->pane_h);
2126                         pane[BOTTOM_LEFT_PANE]->resize_event(
2127                                 pane[BOTTOM_LEFT_PANE]->x,
2128                                 cursor_y +
2129                                         mwindow->theme->mcanvas_y,
2130                                 mwindow->theme->mcanvas_w,
2131                                 mwindow->theme->mcanvas_h -
2132                                         cursor_y);
2133                 }
2134         }
2135         else
2136         {
2137 // 1 pane
2138                 if(pane[TOP_RIGHT_PANE]) delete pane[TOP_RIGHT_PANE];
2139                 if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2140                 if(pane[BOTTOM_LEFT_PANE]) delete pane[BOTTOM_LEFT_PANE];
2141                 pane[TOP_RIGHT_PANE] = 0;
2142                 pane[BOTTOM_RIGHT_PANE] = 0;
2143                 pane[BOTTOM_LEFT_PANE] = 0;
2144                 pane[TOP_LEFT_PANE]->resize_event(
2145                         mwindow->theme->mcanvas_x,
2146                         mwindow->theme->mcanvas_y,
2147                         mwindow->theme->mcanvas_w,
2148                         mwindow->theme->mcanvas_h);
2149         }
2150
2151         update_pane_dividers();
2152         show_window();
2153
2154         resource_thread->start_draw();
2155 }
2156
2157 void MWindowGUI::update_pane_dividers()
2158 {
2159
2160         if(horizontal_panes() || total_panes() == 4)
2161         {
2162                 int x = pane[TOP_RIGHT_PANE]->x - mwindow->theme->pane_w;
2163                 int y = mwindow->theme->mcanvas_y;
2164                 int h = mwindow->theme->mcanvas_h;
2165
2166                 if(!x_divider)
2167                 {
2168                         add_subwindow(x_divider = new PaneDivider(
2169                                 mwindow, x, y, h, 1));
2170                         x_divider->create_objects();
2171                 }
2172                 else
2173                 {
2174                         x_divider->reposition_window(x, y, h);
2175                         x_divider->draw(0);
2176                 }
2177         }
2178         else
2179         {
2180                 if(x_divider)
2181                 {
2182                         delete x_divider;
2183                         x_divider = 0;
2184                 }
2185         }
2186
2187         if(vertical_panes() || total_panes() == 4)
2188         {
2189                 int x = mwindow->theme->mcanvas_x;
2190                 int y = pane[BOTTOM_LEFT_PANE]->y -
2191                         mwindow->theme->pane_h;
2192                 int w = mwindow->theme->mcanvas_w;
2193                 if(!y_divider)
2194                 {
2195                         add_subwindow(y_divider = new PaneDivider(
2196                                 mwindow, x, y, w, 0));
2197                         y_divider->create_objects();
2198                 }
2199                 else
2200                 {
2201                         y_divider->reposition_window(x, y, w);
2202                         y_divider->draw(0);
2203                 }
2204         }
2205         else
2206         {
2207                 if(y_divider)
2208                 {
2209                         delete y_divider;
2210                         y_divider = 0;
2211                 }
2212         }
2213 }
2214
2215 void MWindowGUI::draw_samplemovement()
2216 {
2217         draw_canvas(0, 1);
2218         show_cursor(1);
2219         flash_canvas(0);
2220         update_timebar(0);
2221         zoombar->update();
2222         update_scrollbars(1);
2223 }
2224
2225 void MWindowGUI::draw_trackmovement()
2226 {
2227         update_scrollbars(0);
2228         draw_canvas(0, 0);
2229         update_patchbay();
2230         flash_canvas(1);
2231 }
2232
2233
2234 PaneButton::PaneButton(MWindow *mwindow, int x, int y)
2235  : BC_Button(x, y, mwindow->theme->get_image_set("pane"))
2236 {
2237         this->mwindow = mwindow;
2238 }
2239
2240 int PaneButton::cursor_motion_event()
2241 {
2242         if(get_top_level()->get_button_down() &&
2243                 is_event_win() &&
2244                 get_status() == BUTTON_DOWNHI &&
2245                 !cursor_inside())
2246         {
2247 //              printf("PaneButton::cursor_motion_event %d\n", __LINE__);
2248 // create drag bar
2249                 if(get_cursor_x() < 0 && !mwindow->gui->dragging_pane)
2250                 {
2251                         mwindow->gui->start_x_pane_drag();
2252                 }
2253                 else
2254                 if(get_cursor_y() < 0 && !mwindow->gui->dragging_pane)
2255                 {
2256                         mwindow->gui->start_y_pane_drag();
2257                 }
2258         }
2259
2260         mwindow->gui->handle_pane_drag();
2261
2262         int result = BC_Button::cursor_motion_event();
2263         return result;
2264 }
2265
2266 int PaneButton::button_release_event()
2267 {
2268         mwindow->gui->stop_pane_drag();
2269         int result = BC_Button::button_release_event();
2270         return result;
2271 }
2272
2273
2274 FFMpegToggle::FFMpegToggle(MWindow *mwindow, MButtons *mbuttons, int x, int y)
2275  : BC_Toggle(x, y, mwindow->theme->ffmpeg_toggle, mwindow->preferences->ffmpeg_early_probe)
2276 {
2277         this->mwindow = mwindow;
2278         this->mbuttons = mbuttons;
2279         set_tooltip( mwindow->preferences->ffmpeg_early_probe ?
2280                 _("Try FFMpeg first") : _("Try FFMpeg last"));
2281 }
2282
2283 FFMpegToggle::~FFMpegToggle()
2284 {
2285 }
2286
2287 int FFMpegToggle::handle_event()
2288 {
2289         mwindow->preferences->ffmpeg_early_probe = get_value();
2290         set_tooltip( mwindow->preferences->ffmpeg_early_probe ?
2291                 _("Try FFMpeg first") : _("Try FFMpeg last"));
2292         mwindow->show_warning(&mwindow->preferences->warn_indexes,
2293                 _("Changing the base codecs may require rebuilding indexes."));
2294         return 1;
2295 }
2296
2297