upgraded x265,ffmpeg,tdb,it.po fixed tab armed toggle
[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( (this_track = pane[i]->over_track()) != 0 ) break;
1253                         if( (this_track = pane[i]->over_patchbay()) != 0 ) break;
1254                 }
1255
1256                 if( get_keypress() == TAB ) { // Switch the record button
1257                         if( this_track )
1258                                 this_track->record = !this_track->record ? 1 : 0;
1259                 }
1260                 else {
1261                         int total_selected = mwindow->edl->tracks->total_of(Tracks::RECORD);
1262                         // all selected if nothing previously selected or
1263                         // if this patch was previously the only one selected and armed
1264                         int selected = !total_selected || (total_selected == 1 &&
1265                                 this_track && this_track->record ) ? 1 : 0;
1266                         mwindow->edl->tracks->select_all(Tracks::RECORD, selected);
1267                         if( !selected && this_track ) this_track->record = 1;
1268                 }
1269
1270                 update(0, 1, 0, 0, 1, 0, 1);
1271                 unlock_window();
1272                 mwindow->cwindow->update(0, 1, 1);
1273                 lock_window("TrackCanvas::keypress_event 3");
1274
1275                 result = 1;
1276                 break;
1277         }
1278
1279 // since things under cursor have changed...
1280         if(result)
1281                 cursor_motion_event();
1282
1283         return result;
1284 }
1285
1286
1287 int MWindowGUI::keyboard_listener(BC_WindowBase *wp)
1288 {
1289         return key_listener(wp->get_keypress());
1290 }
1291
1292 int MWindowGUI::key_listener(int key)
1293 {
1294         int result = 1;
1295         switch( key ) {
1296         case KPTV:
1297                 if( !record->running() )
1298                         record->start();
1299                 else
1300                         record->record_gui->interrupt_thread->start(0);
1301                 break;
1302         case KPHAND:
1303                 mwindow->quit(0);
1304                 break;
1305 #ifdef HAVE_DVB
1306         case KPBOOK:
1307                 channel_info->toggle_scan();
1308                 break;
1309 #endif
1310         case KPMENU:
1311                 if( !remote_control->deactivate() )
1312                         remote_control->activate();
1313                 break;
1314         default:
1315                 result = 0;
1316                 break;
1317         }
1318         return result;
1319 }
1320
1321
1322 void MWindowGUI::use_android_remote(int on)
1323 {
1324         if( !on ) {
1325                 delete android_control;
1326                 android_control = 0;
1327                 return;
1328         }
1329         if( android_control ) return;
1330         android_control = new AndroidControl(this);
1331 }
1332
1333 int MWindowGUI::close_event()
1334 {
1335         mainmenu->quit();
1336         return 0;
1337 }
1338
1339 void MWindowGUI::stop_drawing()
1340 {
1341         resource_thread->stop_draw(1);
1342 }
1343
1344 int MWindowGUI::menu_w()
1345 {
1346         return mainmenu->get_w();
1347 }
1348
1349 int MWindowGUI::menu_h()
1350 {
1351         return mainmenu->get_h();
1352 }
1353
1354 void MWindowGUI::start_x_pane_drag()
1355 {
1356         if(!x_pane_drag)
1357         {
1358                 x_pane_drag = new BC_Popup(this,
1359                         get_abs_cursor_x(0) - mwindow->theme->pane_w,
1360                         BC_DisplayInfo::get_top_border() +
1361                                 get_y() +
1362                                 mwindow->theme->mcanvas_y,
1363                         mwindow->theme->pane_w,
1364                         mwindow->theme->mcanvas_h,
1365                         mwindow->theme->drag_pane_color);
1366                 x_pane_drag->draw_3segmentv(0,
1367                         0,
1368                         x_pane_drag->get_h(),
1369                         mwindow->theme->get_image_set("xpane")[BUTTON_DOWNHI]);
1370                 x_pane_drag->flash(1);
1371         }
1372         dragging_pane = 1;
1373 }
1374
1375 void MWindowGUI::start_y_pane_drag()
1376 {
1377         if(!y_pane_drag)
1378         {
1379 //printf("MWindowGUI::start_y_pane_drag %d %d %d\n", __LINE__, get_x(), get_y());
1380                 y_pane_drag = new BC_Popup(this,
1381                         BC_DisplayInfo::get_left_border() +
1382                                 get_x() +
1383                                 mwindow->theme->mcanvas_x,
1384                         get_abs_cursor_y(0) - mwindow->theme->pane_h,
1385                         mwindow->theme->mcanvas_w,
1386                         mwindow->theme->pane_h,
1387                         mwindow->theme->drag_pane_color);
1388                 y_pane_drag->draw_3segmenth(0,
1389                         0,
1390                         y_pane_drag->get_w(),
1391                         mwindow->theme->get_image_set("ypane")[BUTTON_DOWNHI]);
1392                 y_pane_drag->flash(1);
1393         }
1394         dragging_pane = 1;
1395 }
1396
1397 void MWindowGUI::handle_pane_drag()
1398 {
1399         if(dragging_pane)
1400         {
1401                 if(x_pane_drag)
1402                 {
1403                         x_pane_drag->reposition_window(
1404                                 get_abs_cursor_x(0) - mwindow->theme->pane_w,
1405                                 x_pane_drag->get_y());
1406                 }
1407
1408                 if(y_pane_drag)
1409                 {
1410                         y_pane_drag->reposition_window(
1411                                 y_pane_drag->get_x(),
1412                                 get_abs_cursor_y(0) - mwindow->theme->pane_h);
1413                 }
1414         }
1415 }
1416
1417
1418 void MWindowGUI::create_x_pane(int cursor_x)
1419 {
1420         if(total_panes() == 1)
1421         {
1422 // create a horizontal pane
1423 // do this 1st so the resize_event knows there are 2 panes
1424                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] =
1425                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] +
1426                         cursor_x -
1427                         mwindow->theme->patchbay_w;
1428                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1429                         TOP_RIGHT_PANE,
1430                         mwindow->theme->mcanvas_x +
1431                                 cursor_x,
1432                         mwindow->theme->mcanvas_y,
1433                         mwindow->theme->mcanvas_x +
1434                                 mwindow->theme->mcanvas_w -
1435                                 cursor_x,
1436                         mwindow->theme->mcanvas_h);
1437                 pane[TOP_LEFT_PANE]->resize_event(
1438                         mwindow->theme->mcanvas_x,
1439                         mwindow->theme->mcanvas_y,
1440                         cursor_x - mwindow->theme->pane_w,
1441                         mwindow->theme->mcanvas_h);
1442                 pane[TOP_RIGHT_PANE]->create_objects();
1443         }
1444         else
1445         if(vertical_panes())
1446         {
1447 // create 2 horizontal panes
1448                 mwindow->edl->local_session->track_start[TOP_RIGHT_PANE] =
1449                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE];
1450                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1451                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE];
1452                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] =
1453                         mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1454                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] +
1455                         cursor_x -
1456                         mwindow->theme->patchbay_w;
1457                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1458                         TOP_RIGHT_PANE,
1459                         mwindow->theme->mcanvas_x +
1460                                 cursor_x,
1461                         pane[TOP_LEFT_PANE]->y,
1462                         mwindow->theme->mcanvas_x +
1463                                 mwindow->theme->mcanvas_w -
1464                                 cursor_x,
1465                         pane[TOP_LEFT_PANE]->h);
1466                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1467                         BOTTOM_RIGHT_PANE,
1468                         mwindow->theme->mcanvas_x +
1469                                 cursor_x,
1470                         pane[BOTTOM_LEFT_PANE]->y,
1471                         mwindow->theme->mcanvas_x +
1472                                 mwindow->theme->mcanvas_w -
1473                                 cursor_x,
1474                         pane[BOTTOM_LEFT_PANE]->h);
1475                 pane[TOP_LEFT_PANE]->resize_event(
1476                         pane[TOP_LEFT_PANE]->x,
1477                         pane[TOP_LEFT_PANE]->y,
1478                         cursor_x - mwindow->theme->pane_w,
1479                         pane[TOP_LEFT_PANE]->h);
1480                 pane[BOTTOM_LEFT_PANE]->resize_event(
1481                         pane[BOTTOM_LEFT_PANE]->x,
1482                         pane[BOTTOM_LEFT_PANE]->y,
1483                         cursor_x - mwindow->theme->pane_w,
1484                         pane[BOTTOM_LEFT_PANE]->h);
1485                 pane[TOP_RIGHT_PANE]->create_objects();
1486                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1487         }
1488         else
1489         if(horizontal_panes())
1490         {
1491 // resize a horizontal pane
1492                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] +=
1493                         cursor_x -
1494                         pane[TOP_RIGHT_PANE]->x;
1495                 if(mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] < 0)
1496                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] = 0;
1497                 pane[TOP_LEFT_PANE]->resize_event(
1498                         mwindow->theme->mcanvas_x,
1499                         mwindow->theme->mcanvas_y,
1500                         cursor_x - mwindow->theme->pane_w,
1501                         mwindow->theme->mcanvas_h);
1502                 pane[TOP_RIGHT_PANE]->resize_event(
1503                         mwindow->theme->mcanvas_x +
1504                                 cursor_x,
1505                         pane[TOP_RIGHT_PANE]->y,
1506                         mwindow->theme->mcanvas_x +
1507                                 mwindow->theme->mcanvas_w -
1508                                 cursor_x,
1509                         mwindow->theme->mcanvas_h);
1510         }
1511         else
1512         {
1513 // resize 2 horizontal panes
1514                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] +=
1515                         cursor_x -
1516                         pane[TOP_RIGHT_PANE]->x;
1517                 if(mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] < 0)
1518                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] = 0;
1519                 mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1520                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE];
1521
1522                 pane[TOP_LEFT_PANE]->resize_event(
1523                         mwindow->theme->mcanvas_x,
1524                         pane[TOP_LEFT_PANE]->y,
1525                         cursor_x - mwindow->theme->pane_w,
1526                         pane[TOP_LEFT_PANE]->h);
1527                 pane[TOP_RIGHT_PANE]->resize_event(
1528                         mwindow->theme->mcanvas_x +
1529                                 cursor_x,
1530                         pane[TOP_RIGHT_PANE]->y,
1531                         mwindow->theme->mcanvas_x +
1532                                 mwindow->theme->mcanvas_w -
1533                                 cursor_x,
1534                         pane[TOP_RIGHT_PANE]->h);
1535                 pane[BOTTOM_LEFT_PANE]->resize_event(
1536                         mwindow->theme->mcanvas_x,
1537                         pane[BOTTOM_LEFT_PANE]->y,
1538                         cursor_x - mwindow->theme->pane_w,
1539                         pane[BOTTOM_LEFT_PANE]->h);
1540                 pane[BOTTOM_RIGHT_PANE]->resize_event(
1541                         mwindow->theme->mcanvas_x +
1542                                 cursor_x,
1543                         pane[BOTTOM_RIGHT_PANE]->y,
1544                         mwindow->theme->mcanvas_x +
1545                                 mwindow->theme->mcanvas_w -
1546                                 cursor_x,
1547                         pane[BOTTOM_RIGHT_PANE]->h);
1548
1549         }
1550 }
1551
1552
1553 void MWindowGUI::delete_x_pane(int cursor_x)
1554 {
1555 // give left panes coordinates of right pane
1556         if(cursor_x < mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1557                 pane[TOP_RIGHT_PANE])
1558         {
1559                 mwindow->edl->local_session->view_start[TOP_LEFT_PANE] =
1560                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] -
1561                         pane[TOP_RIGHT_PANE]->x + mwindow->theme->patchbay_w;
1562                 if(mwindow->edl->local_session->view_start[TOP_LEFT_PANE] < 0)
1563                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] = 0;
1564                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1565                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1566         }
1567
1568         switch(total_panes())
1569         {
1570                 case 2:
1571                         if(pane[TOP_LEFT_PANE] && pane[TOP_RIGHT_PANE])
1572                         {
1573 // delete right pane
1574                                 delete pane[TOP_RIGHT_PANE];
1575                                 pane[TOP_RIGHT_PANE] = 0;
1576                                 pane[TOP_LEFT_PANE]->resize_event(
1577                                         mwindow->theme->mcanvas_x,
1578                                         mwindow->theme->mcanvas_y,
1579                                         mwindow->theme->mcanvas_w,
1580                                         mwindow->theme->mcanvas_h);
1581
1582                         }
1583                         break;
1584
1585                 case 4:
1586 // delete right panes
1587                         delete pane[TOP_RIGHT_PANE];
1588                         pane[TOP_RIGHT_PANE] = 0;
1589                         delete pane[BOTTOM_RIGHT_PANE];
1590                         pane[BOTTOM_RIGHT_PANE] = 0;
1591                         pane[TOP_LEFT_PANE]->resize_event(
1592                                 mwindow->theme->mcanvas_x,
1593                                 pane[TOP_LEFT_PANE]->y,
1594                                 mwindow->theme->mcanvas_w,
1595                                 pane[TOP_LEFT_PANE]->h);
1596                         pane[BOTTOM_LEFT_PANE]->resize_event(
1597                                 mwindow->theme->mcanvas_x,
1598                                 pane[BOTTOM_LEFT_PANE]->y,
1599                                 mwindow->theme->mcanvas_w,
1600                                 pane[BOTTOM_LEFT_PANE]->h);
1601                         break;
1602         }
1603 }
1604
1605 void MWindowGUI::create_y_pane(int cursor_y)
1606 {
1607         if(total_panes() == 1)
1608         {
1609                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1610                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1611                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] =
1612                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] +
1613                         cursor_y -
1614                         mwindow->theme->mtimebar_h;
1615 // do this 1st so the resize_event knows there are 2 panes
1616                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1617                         BOTTOM_LEFT_PANE,
1618                         mwindow->theme->mcanvas_x,
1619                         mwindow->theme->mcanvas_y +
1620                                 cursor_y,
1621                         mwindow->theme->mcanvas_w,
1622                         mwindow->theme->mcanvas_h -
1623                                 cursor_y);
1624                 pane[TOP_LEFT_PANE]->resize_event(
1625                         mwindow->theme->mcanvas_x,
1626                         mwindow->theme->mcanvas_y,
1627                         mwindow->theme->mcanvas_w,
1628                         pane[BOTTOM_LEFT_PANE]->y -
1629                                 mwindow->theme->mcanvas_y -
1630                                 mwindow->theme->pane_h);
1631                 pane[BOTTOM_LEFT_PANE]->create_objects();
1632         }
1633         else
1634         if(horizontal_panes())
1635         {
1636 // create 2 panes
1637                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1638                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1639                 mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1640                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE];
1641                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] =
1642                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1643                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] +
1644                         cursor_y -
1645                         mwindow->theme->mtimebar_h;
1646
1647                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1648                         BOTTOM_LEFT_PANE,
1649                         pane[TOP_LEFT_PANE]->x,
1650                         mwindow->theme->mcanvas_y +
1651                                 cursor_y,
1652                         pane[TOP_LEFT_PANE]->w,
1653                         mwindow->theme->mcanvas_h -
1654                                 cursor_y);
1655                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1656                         BOTTOM_RIGHT_PANE,
1657                         pane[TOP_RIGHT_PANE]->x,
1658                         mwindow->theme->mcanvas_y +
1659                                 cursor_y,
1660                         pane[TOP_RIGHT_PANE]->w,
1661                         mwindow->theme->mcanvas_h -
1662                                 cursor_y);
1663
1664                 pane[TOP_LEFT_PANE]->resize_event(
1665                         pane[TOP_LEFT_PANE]->x,
1666                         pane[TOP_LEFT_PANE]->y,
1667                         pane[TOP_LEFT_PANE]->w,
1668                         pane[BOTTOM_LEFT_PANE]->y -
1669                                 mwindow->theme->mcanvas_y -
1670                                 mwindow->theme->pane_h);
1671                 pane[TOP_RIGHT_PANE]->resize_event(
1672                         pane[TOP_RIGHT_PANE]->x,
1673                         pane[TOP_RIGHT_PANE]->y,
1674                         pane[TOP_RIGHT_PANE]->w,
1675                         pane[BOTTOM_RIGHT_PANE]->y -
1676                                 mwindow->theme->mcanvas_y -
1677                                 mwindow->theme->pane_h);
1678
1679                 pane[BOTTOM_LEFT_PANE]->create_objects();
1680                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1681         }
1682         else
1683         if(vertical_panes())
1684         {
1685 // resize a pane
1686                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] +=
1687                         cursor_y -
1688                         (pane[BOTTOM_LEFT_PANE]->y - mwindow->theme->mcanvas_y);
1689                 if(mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] < 0)
1690                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] = 0;
1691                 pane[TOP_LEFT_PANE]->resize_event(
1692                         mwindow->theme->mcanvas_x,
1693                         mwindow->theme->mcanvas_y,
1694                         mwindow->theme->mcanvas_w,
1695                         cursor_y - mwindow->theme->pane_h);
1696                 pane[BOTTOM_LEFT_PANE]->resize_event(
1697                         pane[BOTTOM_LEFT_PANE]->x,
1698                         cursor_y +
1699                                 mwindow->theme->mcanvas_y,
1700                         mwindow->theme->mcanvas_w,
1701                         mwindow->theme->mcanvas_h -
1702                                 cursor_y);
1703         }
1704         else
1705         {
1706 // resize 2 panes
1707                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] +=
1708                         cursor_y -
1709                         (pane[BOTTOM_LEFT_PANE]->y - mwindow->theme->mcanvas_y);
1710                 if(mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] < 0)
1711                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] = 0;
1712                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1713                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE];
1714                 pane[TOP_LEFT_PANE]->resize_event(
1715                         pane[TOP_LEFT_PANE]->x,
1716                         pane[TOP_LEFT_PANE]->y,
1717                         pane[TOP_LEFT_PANE]->w,
1718                         cursor_y - mwindow->theme->pane_h);
1719                 pane[BOTTOM_LEFT_PANE]->resize_event(
1720                         pane[BOTTOM_LEFT_PANE]->x,
1721                         cursor_y +
1722                                 mwindow->theme->mcanvas_y,
1723                         pane[BOTTOM_LEFT_PANE]->w,
1724                         mwindow->theme->mcanvas_h -
1725                                         cursor_y);
1726                 pane[TOP_RIGHT_PANE]->resize_event(
1727                         pane[TOP_RIGHT_PANE]->x,
1728                         pane[TOP_RIGHT_PANE]->y,
1729                         pane[TOP_RIGHT_PANE]->w,
1730                         cursor_y - mwindow->theme->pane_h);
1731                 pane[BOTTOM_RIGHT_PANE]->resize_event(
1732                         pane[BOTTOM_RIGHT_PANE]->x,
1733                         cursor_y +
1734                                 mwindow->theme->mcanvas_y,
1735                         pane[BOTTOM_RIGHT_PANE]->w,
1736                         mwindow->theme->mcanvas_h -
1737                                         cursor_y);
1738         }
1739 }
1740
1741 void MWindowGUI::delete_y_pane(int cursor_y)
1742 {
1743         if(cursor_y < mwindow->theme->mtimebar_h +
1744                 PANE_DRAG_MARGIN &&
1745                 pane[BOTTOM_LEFT_PANE])
1746         {
1747 // give top pane coordinates of bottom pane
1748                 mwindow->edl->local_session->track_start[TOP_LEFT_PANE] =
1749                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] -
1750                         pane[BOTTOM_LEFT_PANE]->y;
1751                 if(mwindow->edl->local_session->track_start[TOP_LEFT_PANE] < 0)
1752                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] = 0;
1753                 mwindow->edl->local_session->track_start[TOP_RIGHT_PANE] =
1754                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE];
1755         }
1756
1757 // delete a pane
1758         switch(total_panes())
1759         {
1760                 case 2:
1761                         delete pane[BOTTOM_LEFT_PANE];
1762                         pane[BOTTOM_LEFT_PANE] = 0;
1763                         pane[TOP_LEFT_PANE]->resize_event(
1764                                 mwindow->theme->mcanvas_x,
1765                                 mwindow->theme->mcanvas_y,
1766                                 mwindow->theme->mcanvas_w,
1767                                 mwindow->theme->mcanvas_h);
1768                         break;
1769
1770                 case 4:
1771 // delete bottom 2 panes
1772
1773                         delete pane[BOTTOM_LEFT_PANE];
1774                         pane[BOTTOM_LEFT_PANE] = 0;
1775                         delete pane[BOTTOM_RIGHT_PANE];
1776                         pane[BOTTOM_RIGHT_PANE] = 0;
1777                         pane[TOP_LEFT_PANE]->resize_event(
1778                                 pane[TOP_LEFT_PANE]->x,
1779                                 mwindow->theme->mcanvas_y,
1780                                 pane[TOP_LEFT_PANE]->w,
1781                                 mwindow->theme->mcanvas_h);
1782                         pane[TOP_RIGHT_PANE]->resize_event(
1783                                 pane[TOP_RIGHT_PANE]->x,
1784                                 mwindow->theme->mcanvas_y,
1785                                 pane[TOP_RIGHT_PANE]->w,
1786                                 mwindow->theme->mcanvas_h);
1787                         break;
1788         }
1789 }
1790
1791 void MWindowGUI::stop_pane_drag()
1792 {
1793         dragging_pane = 0;
1794         resource_thread->stop_draw(1);
1795
1796         if(x_pane_drag)
1797         {
1798 // cursor position relative to canvas
1799                 int cursor_x = x_pane_drag->get_x() -
1800                         get_x() -
1801                         BC_DisplayInfo::get_left_border() -
1802                         mwindow->theme->mcanvas_x +
1803                         mwindow->theme->pane_w;
1804                 delete x_pane_drag;
1805                 x_pane_drag = 0;
1806
1807
1808                 if(cursor_x >= mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1809                         cursor_x < mwindow->theme->mcanvas_w -
1810                                 BC_ScrollBar::get_span(SCROLL_VERT) -
1811                                 PANE_DRAG_MARGIN)
1812                 {
1813                         create_x_pane(cursor_x);
1814                         mwindow->edl->local_session->x_pane = cursor_x;
1815                 }
1816                 else
1817 // deleted a pane
1818                 {
1819                         delete_x_pane(cursor_x);
1820                         mwindow->edl->local_session->x_pane = -1;
1821                 }
1822
1823
1824         }
1825
1826         if(y_pane_drag)
1827         {
1828 // cursor position relative to canvas
1829                 int cursor_y = y_pane_drag->get_y() -
1830                         get_y() -
1831                         BC_DisplayInfo::get_top_border() -
1832                         mwindow->theme->mcanvas_y +
1833                         mwindow->theme->pane_h;
1834                 delete y_pane_drag;
1835                 y_pane_drag = 0;
1836
1837
1838
1839                 if(cursor_y >= mwindow->theme->mtimebar_h +
1840                                 PANE_DRAG_MARGIN &&
1841                         cursor_y < mwindow->theme->mcanvas_h -
1842                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
1843                                 PANE_DRAG_MARGIN)
1844                 {
1845                         create_y_pane(cursor_y);
1846                         mwindow->edl->local_session->y_pane = cursor_y;
1847                 }
1848                 else
1849                 {
1850                         delete_y_pane(cursor_y);
1851                         mwindow->edl->local_session->y_pane = -1;
1852                 }
1853         }
1854
1855         update_pane_dividers();
1856         update_cursor();
1857 // required to get new widgets to appear
1858         show_window();
1859         resource_thread->start_draw();
1860 }
1861
1862 // create panes from EDL
1863 void MWindowGUI::load_panes()
1864 {
1865         int need_x_panes = 0;
1866         int need_y_panes = 0;
1867 // use names from create functions
1868         int cursor_x = mwindow->edl->local_session->x_pane;
1869         int cursor_y = mwindow->edl->local_session->y_pane;
1870
1871         resource_thread->stop_draw(1);
1872         if(cursor_x >=
1873                 mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1874                 cursor_x <
1875                 mwindow->theme->mcanvas_w -
1876                                 BC_ScrollBar::get_span(SCROLL_VERT) -
1877                                 PANE_DRAG_MARGIN)
1878         {
1879                 need_x_panes = 1;
1880         }
1881
1882         if(cursor_y >=
1883                 mwindow->theme->mtimebar_h + PANE_DRAG_MARGIN &&
1884                 cursor_y <
1885                 mwindow->theme->mcanvas_h -
1886                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
1887                                 PANE_DRAG_MARGIN)
1888         {
1889                 need_y_panes = 1;
1890         }
1891
1892 //printf("MWindowGUI::load_panes %d %d %d\n", __LINE__, need_x_panes, need_y_panes);
1893
1894
1895         if(need_x_panes)
1896         {
1897                 if(need_y_panes)
1898                 {
1899 // 4 panes
1900                         if(total_panes() == 1)
1901                         {
1902 // create 4 panes
1903 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1904                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1905                                         TOP_RIGHT_PANE,
1906                                         mwindow->theme->mcanvas_x +
1907                                                 cursor_x,
1908                                         mwindow->theme->mcanvas_y,
1909                                         mwindow->theme->mcanvas_x +
1910                                                 mwindow->theme->mcanvas_w -
1911                                                 cursor_x,
1912                                         cursor_y - mwindow->theme->pane_h);
1913                                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1914                                         BOTTOM_LEFT_PANE,
1915                                         mwindow->theme->mcanvas_x,
1916                                         mwindow->theme->mcanvas_y +
1917                                                 cursor_y,
1918                                         cursor_x - mwindow->theme->pane_w,
1919                                         mwindow->theme->mcanvas_h -
1920                                                 cursor_y);
1921                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1922                                         BOTTOM_RIGHT_PANE,
1923                                         pane[TOP_RIGHT_PANE]->x,
1924                                         mwindow->theme->mcanvas_y +
1925                                                 cursor_y,
1926                                         pane[TOP_RIGHT_PANE]->w,
1927                                         mwindow->theme->mcanvas_h -
1928                                                 cursor_y);
1929                                 pane[TOP_LEFT_PANE]->resize_event(
1930                                         pane[TOP_LEFT_PANE]->x,
1931                                         pane[TOP_LEFT_PANE]->y,
1932                                         cursor_x - mwindow->theme->pane_w,
1933                                         cursor_y - mwindow->theme->pane_h);
1934                                 pane[TOP_RIGHT_PANE]->create_objects();
1935                                 pane[BOTTOM_LEFT_PANE]->create_objects();
1936                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1937                         }
1938                         else
1939                         if(horizontal_panes())
1940                         {
1941 // create vertical panes
1942 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1943                                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1944                                         BOTTOM_LEFT_PANE,
1945                                         mwindow->theme->mcanvas_x,
1946                                         mwindow->theme->mcanvas_y +
1947                                                 cursor_y,
1948                                         cursor_x - mwindow->theme->pane_w,
1949                                         mwindow->theme->mcanvas_h -
1950                                                 cursor_y);
1951                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1952                                         BOTTOM_RIGHT_PANE,
1953                                         pane[TOP_RIGHT_PANE]->x,
1954                                         mwindow->theme->mcanvas_y +
1955                                                 cursor_y,
1956                                         pane[TOP_RIGHT_PANE]->w,
1957                                         mwindow->theme->mcanvas_h -
1958                                                 cursor_y);
1959                                 pane[TOP_LEFT_PANE]->resize_event(
1960                                         pane[TOP_LEFT_PANE]->x,
1961                                         pane[TOP_LEFT_PANE]->y,
1962                                         cursor_x - mwindow->theme->pane_w,
1963                                         cursor_y - mwindow->theme->pane_h);
1964                                 pane[TOP_RIGHT_PANE]->resize_event(
1965                                         mwindow->theme->mcanvas_x +
1966                                                 cursor_x,
1967                                         mwindow->theme->mcanvas_y,
1968                                         mwindow->theme->mcanvas_x +
1969                                                 mwindow->theme->mcanvas_w -
1970                                                 cursor_x,
1971                                         cursor_y - mwindow->theme->pane_h);
1972                                 pane[BOTTOM_LEFT_PANE]->create_objects();
1973                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1974                         }
1975                         else
1976                         if(vertical_panes())
1977                         {
1978 // create horizontal panes
1979 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1980                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1981                                         TOP_RIGHT_PANE,
1982                                         mwindow->theme->mcanvas_x +
1983                                                 cursor_x,
1984                                         mwindow->theme->mcanvas_y,
1985                                         mwindow->theme->mcanvas_x +
1986                                                 mwindow->theme->mcanvas_w -
1987                                                 cursor_x,
1988                                         cursor_y - mwindow->theme->pane_h);
1989                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1990                                         BOTTOM_RIGHT_PANE,
1991                                         pane[TOP_RIGHT_PANE]->x,
1992                                         mwindow->theme->mcanvas_y +
1993                                                 cursor_y,
1994                                         pane[TOP_RIGHT_PANE]->w,
1995                                         mwindow->theme->mcanvas_h -
1996                                                 cursor_y);
1997                                 pane[TOP_LEFT_PANE]->resize_event(
1998                                         pane[TOP_LEFT_PANE]->x,
1999                                         pane[TOP_LEFT_PANE]->y,
2000                                         cursor_x - mwindow->theme->pane_w,
2001                                         cursor_y - mwindow->theme->pane_h);
2002                                 pane[BOTTOM_LEFT_PANE]->resize_event(
2003                                         pane[TOP_LEFT_PANE]->x,
2004                                         mwindow->theme->mcanvas_y +
2005                                                 cursor_y,
2006                                         mwindow->theme->mcanvas_x +
2007                                                 mwindow->theme->mcanvas_w -
2008                                                 cursor_x,
2009                                         mwindow->theme->mcanvas_h -
2010                                                 cursor_y);
2011                                 pane[TOP_RIGHT_PANE]->create_objects();
2012                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
2013
2014
2015                         }
2016                         else
2017                         {
2018 // resize all panes
2019 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2020                                 pane[TOP_LEFT_PANE]->resize_event(
2021                                         pane[TOP_LEFT_PANE]->x,
2022                                         pane[TOP_LEFT_PANE]->y,
2023                                         cursor_x - mwindow->theme->pane_w,
2024                                         cursor_y - mwindow->theme->pane_h);
2025                                 pane[TOP_RIGHT_PANE]->resize_event(
2026                                         mwindow->theme->mcanvas_x +
2027                                                 cursor_x,
2028                                         mwindow->theme->mcanvas_y,
2029                                         mwindow->theme->mcanvas_x +
2030                                                 mwindow->theme->mcanvas_w -
2031                                                 cursor_x,
2032                                         cursor_y - mwindow->theme->pane_h);
2033                                 pane[BOTTOM_LEFT_PANE]->resize_event(
2034                                         pane[TOP_LEFT_PANE]->x,
2035                                         mwindow->theme->mcanvas_y +
2036                                                 cursor_y,
2037                                         mwindow->theme->mcanvas_x +
2038                                                 mwindow->theme->mcanvas_w -
2039                                                 cursor_x,
2040                                         mwindow->theme->mcanvas_h -
2041                                                 cursor_y);
2042                                 pane[BOTTOM_RIGHT_PANE]->resize_event(
2043                                         pane[TOP_RIGHT_PANE]->x,
2044                                         mwindow->theme->mcanvas_y +
2045                                                 cursor_y,
2046                                         pane[TOP_RIGHT_PANE]->w,
2047                                         mwindow->theme->mcanvas_h -
2048                                                 cursor_y);
2049
2050
2051                         }
2052                 }
2053                 else
2054                 {
2055 // 2 X panes
2056                         if(pane[BOTTOM_LEFT_PANE]) delete pane[BOTTOM_LEFT_PANE];
2057                         if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2058                         pane[BOTTOM_LEFT_PANE] = 0;
2059                         pane[BOTTOM_RIGHT_PANE] = 0;
2060
2061                         if(!pane[TOP_RIGHT_PANE])
2062                         {
2063                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
2064                                         TOP_RIGHT_PANE,
2065                                         mwindow->theme->mcanvas_x +
2066                                                 cursor_x,
2067                                         mwindow->theme->mcanvas_y,
2068                                         mwindow->theme->mcanvas_x +
2069                                                 mwindow->theme->mcanvas_w -
2070                                                 cursor_x,
2071                                         mwindow->theme->mcanvas_h);
2072                                 pane[TOP_LEFT_PANE]->resize_event(
2073                                         mwindow->theme->mcanvas_x,
2074                                         mwindow->theme->mcanvas_y,
2075                                         cursor_x - mwindow->theme->pane_w,
2076                                         mwindow->theme->mcanvas_h);
2077                                 pane[TOP_RIGHT_PANE]->create_objects();
2078                         }
2079                         else
2080                         {
2081                                 pane[TOP_LEFT_PANE]->resize_event(
2082                                         mwindow->theme->mcanvas_x,
2083                                         mwindow->theme->mcanvas_y,
2084                                         cursor_x - mwindow->theme->pane_w,
2085                                         mwindow->theme->mcanvas_h);
2086                                 pane[TOP_RIGHT_PANE]->resize_event(
2087                                         mwindow->theme->mcanvas_x +
2088                                                 cursor_x,
2089                                         pane[TOP_RIGHT_PANE]->y,
2090                                         mwindow->theme->mcanvas_x +
2091                                                 mwindow->theme->mcanvas_w -
2092                                                 cursor_x,
2093                                         mwindow->theme->mcanvas_h);
2094                         }
2095                 }
2096         }
2097         else
2098         if(need_y_panes)
2099         {
2100 // 2 Y panes
2101                 if(pane[TOP_RIGHT_PANE]) delete pane[TOP_RIGHT_PANE];
2102                 if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2103                 pane[TOP_RIGHT_PANE] = 0;
2104                 pane[BOTTOM_RIGHT_PANE] = 0;
2105
2106                 if(!pane[BOTTOM_LEFT_PANE])
2107                 {
2108 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2109                         pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
2110                                 BOTTOM_LEFT_PANE,
2111                                 mwindow->theme->mcanvas_x,
2112                                 mwindow->theme->mcanvas_y +
2113                                         cursor_y,
2114                                 mwindow->theme->mcanvas_w,
2115                                 mwindow->theme->mcanvas_h -
2116                                         cursor_y);
2117                         pane[TOP_LEFT_PANE]->resize_event(
2118                                 mwindow->theme->mcanvas_x,
2119                                 mwindow->theme->mcanvas_y,
2120                                 mwindow->theme->mcanvas_w,
2121                                 pane[BOTTOM_LEFT_PANE]->y -
2122                                         mwindow->theme->mcanvas_y -
2123                                         mwindow->theme->pane_h);
2124                         pane[BOTTOM_LEFT_PANE]->create_objects();
2125                 }
2126                 else
2127                 {
2128                         pane[TOP_LEFT_PANE]->resize_event(
2129                                 mwindow->theme->mcanvas_x,
2130                                 mwindow->theme->mcanvas_y,
2131                                 mwindow->theme->mcanvas_w,
2132                                 cursor_y - mwindow->theme->pane_h);
2133                         pane[BOTTOM_LEFT_PANE]->resize_event(
2134                                 pane[BOTTOM_LEFT_PANE]->x,
2135                                 cursor_y +
2136                                         mwindow->theme->mcanvas_y,
2137                                 mwindow->theme->mcanvas_w,
2138                                 mwindow->theme->mcanvas_h -
2139                                         cursor_y);
2140                 }
2141         }
2142         else
2143         {
2144 // 1 pane
2145                 if(pane[TOP_RIGHT_PANE]) delete pane[TOP_RIGHT_PANE];
2146                 if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2147                 if(pane[BOTTOM_LEFT_PANE]) delete pane[BOTTOM_LEFT_PANE];
2148                 pane[TOP_RIGHT_PANE] = 0;
2149                 pane[BOTTOM_RIGHT_PANE] = 0;
2150                 pane[BOTTOM_LEFT_PANE] = 0;
2151                 pane[TOP_LEFT_PANE]->resize_event(
2152                         mwindow->theme->mcanvas_x,
2153                         mwindow->theme->mcanvas_y,
2154                         mwindow->theme->mcanvas_w,
2155                         mwindow->theme->mcanvas_h);
2156         }
2157
2158         update_pane_dividers();
2159         show_window();
2160
2161         resource_thread->start_draw();
2162 }
2163
2164 void MWindowGUI::update_pane_dividers()
2165 {
2166
2167         if(horizontal_panes() || total_panes() == 4)
2168         {
2169                 int x = pane[TOP_RIGHT_PANE]->x - mwindow->theme->pane_w;
2170                 int y = mwindow->theme->mcanvas_y;
2171                 int h = mwindow->theme->mcanvas_h;
2172
2173                 if(!x_divider)
2174                 {
2175                         add_subwindow(x_divider = new PaneDivider(
2176                                 mwindow, x, y, h, 1));
2177                         x_divider->create_objects();
2178                 }
2179                 else
2180                 {
2181                         x_divider->reposition_window(x, y, h);
2182                         x_divider->draw(0);
2183                 }
2184         }
2185         else
2186         {
2187                 if(x_divider)
2188                 {
2189                         delete x_divider;
2190                         x_divider = 0;
2191                 }
2192         }
2193
2194         if(vertical_panes() || total_panes() == 4)
2195         {
2196                 int x = mwindow->theme->mcanvas_x;
2197                 int y = pane[BOTTOM_LEFT_PANE]->y -
2198                         mwindow->theme->pane_h;
2199                 int w = mwindow->theme->mcanvas_w;
2200                 if(!y_divider)
2201                 {
2202                         add_subwindow(y_divider = new PaneDivider(
2203                                 mwindow, x, y, w, 0));
2204                         y_divider->create_objects();
2205                 }
2206                 else
2207                 {
2208                         y_divider->reposition_window(x, y, w);
2209                         y_divider->draw(0);
2210                 }
2211         }
2212         else
2213         {
2214                 if(y_divider)
2215                 {
2216                         delete y_divider;
2217                         y_divider = 0;
2218                 }
2219         }
2220 }
2221
2222 void MWindowGUI::draw_samplemovement()
2223 {
2224         draw_canvas(0, 1);
2225         show_cursor(1);
2226         flash_canvas(0);
2227         update_timebar(0);
2228         zoombar->update();
2229         update_scrollbars(1);
2230 }
2231
2232 void MWindowGUI::draw_trackmovement()
2233 {
2234         update_scrollbars(0);
2235         draw_canvas(0, 0);
2236         update_patchbay();
2237         flash_canvas(1);
2238 }
2239
2240
2241 PaneButton::PaneButton(MWindow *mwindow, int x, int y)
2242  : BC_Button(x, y, mwindow->theme->get_image_set("pane"))
2243 {
2244         this->mwindow = mwindow;
2245 }
2246
2247 int PaneButton::cursor_motion_event()
2248 {
2249         if(get_top_level()->get_button_down() &&
2250                 is_event_win() &&
2251                 get_status() == BUTTON_DOWNHI &&
2252                 !cursor_inside())
2253         {
2254 //              printf("PaneButton::cursor_motion_event %d\n", __LINE__);
2255 // create drag bar
2256                 if(get_cursor_x() < 0 && !mwindow->gui->dragging_pane)
2257                 {
2258                         mwindow->gui->start_x_pane_drag();
2259                 }
2260                 else
2261                 if(get_cursor_y() < 0 && !mwindow->gui->dragging_pane)
2262                 {
2263                         mwindow->gui->start_y_pane_drag();
2264                 }
2265         }
2266
2267         mwindow->gui->handle_pane_drag();
2268
2269         int result = BC_Button::cursor_motion_event();
2270         return result;
2271 }
2272
2273 int PaneButton::button_release_event()
2274 {
2275         mwindow->gui->stop_pane_drag();
2276
2277         int result = BC_Button::button_release_event();
2278         return result;
2279 }
2280
2281
2282 FFMpegToggle::FFMpegToggle(MWindow *mwindow, MButtons *mbuttons, int x, int y)
2283  : BC_Toggle(x, y, mwindow->theme->ffmpeg_toggle, mwindow->preferences->ffmpeg_early_probe)
2284 {
2285         this->mwindow = mwindow;
2286         this->mbuttons = mbuttons;
2287         set_tooltip( mwindow->preferences->ffmpeg_early_probe ?
2288                 _("Try FFMpeg first") : _("Try FFMpeg last"));
2289 }
2290
2291 FFMpegToggle::~FFMpegToggle()
2292 {
2293 }
2294
2295 int FFMpegToggle::handle_event()
2296 {
2297         mwindow->preferences->ffmpeg_early_probe = get_value();
2298         set_tooltip( mwindow->preferences->ffmpeg_early_probe ?
2299                 _("Try FFMpeg first") : _("Try FFMpeg last"));
2300         mwindow->show_warning(&mwindow->preferences->warn_indexes,
2301                 _("Changing the base codecs may require rebuilding indexes."));
2302         return 1;
2303 }
2304
2305