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