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