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