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