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