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