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