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