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