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