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