a9e93c6419a18f5a3f061358ee6ec94bcd195598
[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( !alt_down() ) {
1088                         if( !ctrl_down() || !shift_down() ) break;
1089                         mwindow->edl->tracks->clear_selected_edits();
1090                         draw_overlays(1);
1091                         result = 1;
1092                         break;
1093                 } // fall thru
1094         case 'a':
1095                 if( !alt_down() ) break;
1096                 stop_transport("MWindowGUI::keypress_event 1");
1097                 mwindow->nearest_auto_keyframe(shift_down(),
1098                         !ctrl_down() ? PLAY_FORWARD : PLAY_REVERSE);
1099                 result = 1;
1100                 break;
1101
1102         case 'e':
1103                 mwindow->toggle_editing_mode();
1104                 result = 1;
1105                 break;
1106
1107         case 'k': case 'K':
1108                 if( alt_down() ) break;
1109                 stop_transport("MWindowGUI::keypress_event 2");
1110                 mwindow->nearest_plugin_keyframe(shift_down(),
1111                         !ctrl_down() ? PLAY_FORWARD : PLAY_REVERSE);
1112                 result = 1;
1113                 break;
1114
1115         case 'C':
1116                 packed = 1;
1117         case 'c':
1118                 if( !ctrl_down() || alt_down() ) break;
1119                 mwindow->selected_edits_to_clipboard(packed);
1120                 result = 1;
1121                 break;
1122         case 'P':
1123                 plugins = 1;
1124         case 'b':
1125                 overwrite = -1; // fall thru
1126         case 'v':
1127                 if( !ctrl_down() || alt_down() ) break;
1128                 if( mwindow->session->current_operation == DROP_TARGETING ) {
1129                         mwindow->session->current_operation = NO_OPERATION;
1130                         mwindow->gui->set_editing_mode(1);
1131                         int pane_no = 0;
1132                         for( ; pane_no<TOTAL_PANES; ++pane_no  ) {
1133                                 if( !pane[pane_no] ) continue;
1134                                 first_track = pane[pane_no]->over_track();
1135                                 if( first_track ) break;
1136                         }
1137                         if( first_track ) {
1138                                 int cursor_x = pane[pane_no]->canvas->get_relative_cursor_x();
1139                                 position = mwindow->edl->get_cursor_position(cursor_x, pane_no);
1140                         }
1141                 }
1142                 else
1143                         position = mwindow->edl->local_session->get_selectionstart();
1144                 if( !plugins )
1145                         mwindow->paste(position, first_track, 0, overwrite);
1146                 else
1147                         mwindow->paste_clipboard(first_track, position, 1, 0, 1, 1, 1);
1148                 mwindow->edl->tracks->clear_selected_edits();
1149                 draw_overlays(1);
1150                 result = 1;
1151                 break;
1152         case 'M':
1153                 collapse = 1;
1154         case BACKSPACE:
1155         case 'm':
1156                 mwindow->cut_selected_edits(0, collapse);
1157                 result = 1;
1158                 break;
1159         case 'z':
1160                 collapse = 1;
1161         case 'x':
1162                 if( !ctrl_down() || alt_down() ) break;
1163                 mwindow->cut_selected_edits(1, collapse);
1164                 result = 1;
1165                 break;
1166
1167         case '1' ... '8':
1168                 if( !alt_down() || shift_down() ) break;
1169                 if( !mwindow->select_asset(get_keypress()-'1',1) )
1170                         result = 1;
1171                 break;
1172
1173         case LEFT:
1174                 if( !ctrl_down() ) {
1175                         if( alt_down() ) {
1176                                 stop_transport("MWindowGUI::keypress_event 1");
1177                                 mwindow->prev_edit_handle(shift_down());
1178                         }
1179                         else
1180                                 mwindow->move_left();
1181                         result = 1;
1182                 }
1183                 break;
1184
1185         case ',':
1186                 if( !ctrl_down() && !alt_down() ) {
1187                         mwindow->move_left();
1188                         result = 1;
1189                 }
1190                 break;
1191
1192         case RIGHT:
1193                 if( !ctrl_down() ) {
1194                         if( alt_down() ) {
1195                                 stop_transport("MWindowGUI::keypress_event 2");
1196                                 mwindow->next_edit_handle(shift_down());
1197                         }
1198                         else
1199                                 mwindow->move_right();
1200                         result = 1;
1201                 }
1202                 break;
1203
1204         case '.':
1205                 if( !ctrl_down() && !alt_down() ) {
1206                         mwindow->move_right();
1207                         result = 1;
1208                 }
1209                 break;
1210
1211         case UP:
1212                 if( ctrl_down() && !alt_down() )
1213                         mwindow->expand_y();
1214                 else if( !ctrl_down() && alt_down() )
1215                         mwindow->expand_autos(0,1,1);
1216                 else if( ctrl_down() && alt_down() )
1217                         mwindow->expand_autos(1,1,1);
1218                 else
1219                         mwindow->expand_sample();
1220                 result = 1;
1221                 break;
1222
1223         case DOWN:
1224                 if( ctrl_down() && !alt_down() )
1225                         mwindow->zoom_in_y();
1226                 else if( !ctrl_down() && alt_down() )
1227                         mwindow->shrink_autos(0,1,1);
1228                 else if( ctrl_down() && alt_down() )
1229                         mwindow->shrink_autos(1,1,1);
1230                 else
1231                         mwindow->zoom_in_sample();
1232                 result = 1;
1233                 break;
1234
1235         case PGUP:
1236                 if( !ctrl_down() )
1237                         mwindow->move_up();
1238                 else
1239                         mwindow->expand_t();
1240                 result = 1;
1241                 break;
1242
1243         case PGDN:
1244                 if( !ctrl_down() )
1245                         mwindow->move_down();
1246                 else
1247                         mwindow->zoom_in_t();
1248                 result = 1;
1249                 break;
1250
1251         case TAB:
1252         case LEFTTAB:
1253                 for( int i=0; i<TOTAL_PANES; ++i ) {
1254                         if( !pane[i] ) continue;
1255                         if( (this_track = pane[i]->over_track()) != 0 ) break;
1256                         if( (this_track = pane[i]->over_patchbay()) != 0 ) break;
1257                 }
1258
1259                 if( get_keypress() == TAB ) { // Switch the record button
1260                         if( this_track )
1261                                 this_track->record = !this_track->record ? 1 : 0;
1262                 }
1263                 else {
1264                         int total_selected = mwindow->edl->tracks->total_of(Tracks::RECORD);
1265                         // all selected if nothing previously selected or
1266                         // if this patch was previously the only one selected and armed
1267                         int selected = !total_selected || (total_selected == 1 &&
1268                                 this_track && this_track->record ) ? 1 : 0;
1269                         mwindow->edl->tracks->select_all(Tracks::RECORD, selected);
1270                         if( !selected && this_track ) this_track->record = 1;
1271                 }
1272
1273                 update(0, NORMAL_DRAW, 0, 0, 1, 0, 1);
1274                 unlock_window();
1275                 mwindow->cwindow->update(0, 1, 1);
1276                 lock_window("MWindowGUI::keypress_event 3");
1277
1278                 result = 1;
1279                 break;
1280
1281         case KEY_F1 ... KEY_F12:
1282                 resend_event(mwindow->cwindow->gui);
1283                 return 1;
1284         }
1285
1286 // since things under cursor have changed...
1287         if(result)
1288                 cursor_motion_event();
1289
1290         return result;
1291 }
1292
1293 int MWindowGUI::keyboard_listener(BC_WindowBase *wp)
1294 {
1295         return key_listener(wp->get_keypress());
1296 }
1297
1298 int MWindowGUI::key_listener(int key)
1299 {
1300         int result = 1;
1301         switch( key ) {
1302         case KPTV:
1303                 if( !record->running() )
1304                         record->start();
1305                 else
1306                         record->record_gui->interrupt_thread->start(0);
1307                 break;
1308         case KPHAND:
1309                 mwindow->quit();
1310                 break;
1311 #ifdef HAVE_DVB
1312         case KPBOOK:
1313                 channel_info->toggle_scan();
1314                 break;
1315 #endif
1316         case KPMENU:
1317                 if( !remote_control->deactivate() )
1318                         remote_control->activate();
1319                 break;
1320         default:
1321                 result = 0;
1322                 break;
1323         }
1324         return result;
1325 }
1326
1327
1328 void MWindowGUI::use_android_remote(int on)
1329 {
1330         if( !on ) {
1331                 delete android_control;
1332                 android_control = 0;
1333                 return;
1334         }
1335         if( android_control ) return;
1336         android_control = new AndroidControl(this);
1337 }
1338 int MWindowGUI::keyev_grab_remote()
1339 {
1340         if( cwindow_remote_handler && cwindow_remote_handler->is_keytv() &&
1341             record_remote_handler  && record_remote_handler->is_keytv() )
1342                 return 0;
1343         delete cwindow_remote_handler;
1344         delete record_remote_handler;
1345         cwindow_remote_handler = (RemoteHandler*)
1346                 new CWindowKeyEvHandler(mwindow->gui->remote_control);
1347         record_remote_handler = (RemoteHandler*)
1348                 new RecordKeyEvHandler(mwindow->gui->remote_control);
1349         return 1;
1350 }
1351
1352 int MWindowGUI::close_event()
1353 {
1354         mainmenu->quit();
1355         return 0;
1356 }
1357
1358 void MWindowGUI::stop_drawing()
1359 {
1360         resource_thread->stop_draw(1);
1361 }
1362
1363 int MWindowGUI::menu_w()
1364 {
1365         return mainmenu->get_w();
1366 }
1367
1368 int MWindowGUI::menu_h()
1369 {
1370         return mainmenu->get_h();
1371 }
1372
1373 void MWindowGUI::start_x_pane_drag()
1374 {
1375         if(!x_pane_drag)
1376         {
1377                 x_pane_drag = new BC_Popup(this,
1378                         get_abs_cursor_x(0) - mwindow->theme->pane_w,
1379                         BC_DisplayInfo::get_top_border() +
1380                                 get_y() +
1381                                 mwindow->theme->mcanvas_y,
1382                         mwindow->theme->pane_w,
1383                         mwindow->theme->mcanvas_h,
1384                         mwindow->theme->drag_pane_color);
1385                 x_pane_drag->draw_3segmentv(0,
1386                         0,
1387                         x_pane_drag->get_h(),
1388                         mwindow->theme->get_image_set("xpane")[BUTTON_DOWNHI]);
1389                 x_pane_drag->flash(1);
1390         }
1391         dragging_pane = 1;
1392 }
1393
1394 void MWindowGUI::start_y_pane_drag()
1395 {
1396         if(!y_pane_drag)
1397         {
1398 //printf("MWindowGUI::start_y_pane_drag %d %d %d\n", __LINE__, get_x(), get_y());
1399                 y_pane_drag = new BC_Popup(this,
1400                         BC_DisplayInfo::get_left_border() +
1401                                 get_x() +
1402                                 mwindow->theme->mcanvas_x,
1403                         get_abs_cursor_y(0) - mwindow->theme->pane_h,
1404                         mwindow->theme->mcanvas_w,
1405                         mwindow->theme->pane_h,
1406                         mwindow->theme->drag_pane_color);
1407                 y_pane_drag->draw_3segmenth(0,
1408                         0,
1409                         y_pane_drag->get_w(),
1410                         mwindow->theme->get_image_set("ypane")[BUTTON_DOWNHI]);
1411                 y_pane_drag->flash(1);
1412         }
1413         dragging_pane = 1;
1414 }
1415
1416 void MWindowGUI::handle_pane_drag()
1417 {
1418         if(dragging_pane)
1419         {
1420                 if(x_pane_drag)
1421                 {
1422                         x_pane_drag->reposition_window(
1423                                 get_abs_cursor_x(0) - mwindow->theme->pane_w,
1424                                 x_pane_drag->get_y());
1425                 }
1426
1427                 if(y_pane_drag)
1428                 {
1429                         y_pane_drag->reposition_window(
1430                                 y_pane_drag->get_x(),
1431                                 get_abs_cursor_y(0) - mwindow->theme->pane_h);
1432                 }
1433         }
1434 }
1435
1436
1437 void MWindowGUI::create_x_pane(int cursor_x)
1438 {
1439         if(total_panes() == 1)
1440         {
1441 // create a horizontal pane
1442 // do this 1st so the resize_event knows there are 2 panes
1443                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] =
1444                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] +
1445                         cursor_x -
1446                         mwindow->theme->patchbay_w;
1447                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1448                         TOP_RIGHT_PANE,
1449                         mwindow->theme->mcanvas_x +
1450                                 cursor_x,
1451                         mwindow->theme->mcanvas_y,
1452                         mwindow->theme->mcanvas_x +
1453                                 mwindow->theme->mcanvas_w -
1454                                 cursor_x,
1455                         mwindow->theme->mcanvas_h);
1456                 pane[TOP_LEFT_PANE]->resize_event(
1457                         mwindow->theme->mcanvas_x,
1458                         mwindow->theme->mcanvas_y,
1459                         cursor_x - mwindow->theme->pane_w,
1460                         mwindow->theme->mcanvas_h);
1461                 pane[TOP_RIGHT_PANE]->create_objects();
1462         }
1463         else
1464         if(vertical_panes())
1465         {
1466 // create 2 horizontal panes
1467                 mwindow->edl->local_session->track_start[TOP_RIGHT_PANE] =
1468                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE];
1469                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1470                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE];
1471                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] =
1472                         mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1473                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] +
1474                         cursor_x -
1475                         mwindow->theme->patchbay_w;
1476                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1477                         TOP_RIGHT_PANE,
1478                         mwindow->theme->mcanvas_x +
1479                                 cursor_x,
1480                         pane[TOP_LEFT_PANE]->y,
1481                         mwindow->theme->mcanvas_x +
1482                                 mwindow->theme->mcanvas_w -
1483                                 cursor_x,
1484                         pane[TOP_LEFT_PANE]->h);
1485                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1486                         BOTTOM_RIGHT_PANE,
1487                         mwindow->theme->mcanvas_x +
1488                                 cursor_x,
1489                         pane[BOTTOM_LEFT_PANE]->y,
1490                         mwindow->theme->mcanvas_x +
1491                                 mwindow->theme->mcanvas_w -
1492                                 cursor_x,
1493                         pane[BOTTOM_LEFT_PANE]->h);
1494                 pane[TOP_LEFT_PANE]->resize_event(
1495                         pane[TOP_LEFT_PANE]->x,
1496                         pane[TOP_LEFT_PANE]->y,
1497                         cursor_x - mwindow->theme->pane_w,
1498                         pane[TOP_LEFT_PANE]->h);
1499                 pane[BOTTOM_LEFT_PANE]->resize_event(
1500                         pane[BOTTOM_LEFT_PANE]->x,
1501                         pane[BOTTOM_LEFT_PANE]->y,
1502                         cursor_x - mwindow->theme->pane_w,
1503                         pane[BOTTOM_LEFT_PANE]->h);
1504                 pane[TOP_RIGHT_PANE]->create_objects();
1505                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1506         }
1507         else
1508         if(horizontal_panes())
1509         {
1510 // resize a horizontal pane
1511                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] +=
1512                         cursor_x -
1513                         pane[TOP_RIGHT_PANE]->x;
1514                 if(mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] < 0)
1515                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] = 0;
1516                 pane[TOP_LEFT_PANE]->resize_event(
1517                         mwindow->theme->mcanvas_x,
1518                         mwindow->theme->mcanvas_y,
1519                         cursor_x - mwindow->theme->pane_w,
1520                         mwindow->theme->mcanvas_h);
1521                 pane[TOP_RIGHT_PANE]->resize_event(
1522                         mwindow->theme->mcanvas_x +
1523                                 cursor_x,
1524                         pane[TOP_RIGHT_PANE]->y,
1525                         mwindow->theme->mcanvas_x +
1526                                 mwindow->theme->mcanvas_w -
1527                                 cursor_x,
1528                         mwindow->theme->mcanvas_h);
1529         }
1530         else
1531         {
1532 // resize 2 horizontal panes
1533                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] +=
1534                         cursor_x -
1535                         pane[TOP_RIGHT_PANE]->x;
1536                 if(mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] < 0)
1537                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] = 0;
1538                 mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1539                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE];
1540
1541                 pane[TOP_LEFT_PANE]->resize_event(
1542                         mwindow->theme->mcanvas_x,
1543                         pane[TOP_LEFT_PANE]->y,
1544                         cursor_x - mwindow->theme->pane_w,
1545                         pane[TOP_LEFT_PANE]->h);
1546                 pane[TOP_RIGHT_PANE]->resize_event(
1547                         mwindow->theme->mcanvas_x +
1548                                 cursor_x,
1549                         pane[TOP_RIGHT_PANE]->y,
1550                         mwindow->theme->mcanvas_x +
1551                                 mwindow->theme->mcanvas_w -
1552                                 cursor_x,
1553                         pane[TOP_RIGHT_PANE]->h);
1554                 pane[BOTTOM_LEFT_PANE]->resize_event(
1555                         mwindow->theme->mcanvas_x,
1556                         pane[BOTTOM_LEFT_PANE]->y,
1557                         cursor_x - mwindow->theme->pane_w,
1558                         pane[BOTTOM_LEFT_PANE]->h);
1559                 pane[BOTTOM_RIGHT_PANE]->resize_event(
1560                         mwindow->theme->mcanvas_x +
1561                                 cursor_x,
1562                         pane[BOTTOM_RIGHT_PANE]->y,
1563                         mwindow->theme->mcanvas_x +
1564                                 mwindow->theme->mcanvas_w -
1565                                 cursor_x,
1566                         pane[BOTTOM_RIGHT_PANE]->h);
1567
1568         }
1569 }
1570
1571
1572 void MWindowGUI::delete_x_pane(int cursor_x)
1573 {
1574 // give left panes coordinates of right pane
1575         if(cursor_x < mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1576                 pane[TOP_RIGHT_PANE])
1577         {
1578                 mwindow->edl->local_session->view_start[TOP_LEFT_PANE] =
1579                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] -
1580                         pane[TOP_RIGHT_PANE]->x + mwindow->theme->patchbay_w;
1581                 if(mwindow->edl->local_session->view_start[TOP_LEFT_PANE] < 0)
1582                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] = 0;
1583                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1584                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1585         }
1586
1587         switch(total_panes())
1588         {
1589                 case 2:
1590                         if(pane[TOP_LEFT_PANE] && pane[TOP_RIGHT_PANE])
1591                         {
1592 // delete right pane
1593                                 delete pane[TOP_RIGHT_PANE];
1594                                 pane[TOP_RIGHT_PANE] = 0;
1595                                 pane[TOP_LEFT_PANE]->resize_event(
1596                                         mwindow->theme->mcanvas_x,
1597                                         mwindow->theme->mcanvas_y,
1598                                         mwindow->theme->mcanvas_w,
1599                                         mwindow->theme->mcanvas_h);
1600
1601                         }
1602                         break;
1603
1604                 case 4:
1605 // delete right panes
1606                         delete pane[TOP_RIGHT_PANE];
1607                         pane[TOP_RIGHT_PANE] = 0;
1608                         delete pane[BOTTOM_RIGHT_PANE];
1609                         pane[BOTTOM_RIGHT_PANE] = 0;
1610                         pane[TOP_LEFT_PANE]->resize_event(
1611                                 mwindow->theme->mcanvas_x,
1612                                 pane[TOP_LEFT_PANE]->y,
1613                                 mwindow->theme->mcanvas_w,
1614                                 pane[TOP_LEFT_PANE]->h);
1615                         pane[BOTTOM_LEFT_PANE]->resize_event(
1616                                 mwindow->theme->mcanvas_x,
1617                                 pane[BOTTOM_LEFT_PANE]->y,
1618                                 mwindow->theme->mcanvas_w,
1619                                 pane[BOTTOM_LEFT_PANE]->h);
1620                         break;
1621         }
1622 }
1623
1624 void MWindowGUI::create_y_pane(int cursor_y)
1625 {
1626         if(total_panes() == 1)
1627         {
1628                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1629                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1630                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] =
1631                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] +
1632                         cursor_y -
1633                         mwindow->theme->mtimebar_h;
1634 // do this 1st so the resize_event knows there are 2 panes
1635                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1636                         BOTTOM_LEFT_PANE,
1637                         mwindow->theme->mcanvas_x,
1638                         mwindow->theme->mcanvas_y +
1639                                 cursor_y,
1640                         mwindow->theme->mcanvas_w,
1641                         mwindow->theme->mcanvas_h -
1642                                 cursor_y);
1643                 pane[TOP_LEFT_PANE]->resize_event(
1644                         mwindow->theme->mcanvas_x,
1645                         mwindow->theme->mcanvas_y,
1646                         mwindow->theme->mcanvas_w,
1647                         pane[BOTTOM_LEFT_PANE]->y -
1648                                 mwindow->theme->mcanvas_y -
1649                                 mwindow->theme->pane_h);
1650                 pane[BOTTOM_LEFT_PANE]->create_objects();
1651         }
1652         else
1653         if(horizontal_panes())
1654         {
1655 // create 2 panes
1656                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1657                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1658                 mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1659                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE];
1660                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] =
1661                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1662                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] +
1663                         cursor_y -
1664                         mwindow->theme->mtimebar_h;
1665
1666                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1667                         BOTTOM_LEFT_PANE,
1668                         pane[TOP_LEFT_PANE]->x,
1669                         mwindow->theme->mcanvas_y +
1670                                 cursor_y,
1671                         pane[TOP_LEFT_PANE]->w,
1672                         mwindow->theme->mcanvas_h -
1673                                 cursor_y);
1674                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1675                         BOTTOM_RIGHT_PANE,
1676                         pane[TOP_RIGHT_PANE]->x,
1677                         mwindow->theme->mcanvas_y +
1678                                 cursor_y,
1679                         pane[TOP_RIGHT_PANE]->w,
1680                         mwindow->theme->mcanvas_h -
1681                                 cursor_y);
1682
1683                 pane[TOP_LEFT_PANE]->resize_event(
1684                         pane[TOP_LEFT_PANE]->x,
1685                         pane[TOP_LEFT_PANE]->y,
1686                         pane[TOP_LEFT_PANE]->w,
1687                         pane[BOTTOM_LEFT_PANE]->y -
1688                                 mwindow->theme->mcanvas_y -
1689                                 mwindow->theme->pane_h);
1690                 pane[TOP_RIGHT_PANE]->resize_event(
1691                         pane[TOP_RIGHT_PANE]->x,
1692                         pane[TOP_RIGHT_PANE]->y,
1693                         pane[TOP_RIGHT_PANE]->w,
1694                         pane[BOTTOM_RIGHT_PANE]->y -
1695                                 mwindow->theme->mcanvas_y -
1696                                 mwindow->theme->pane_h);
1697
1698                 pane[BOTTOM_LEFT_PANE]->create_objects();
1699                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1700         }
1701         else
1702         if(vertical_panes())
1703         {
1704 // resize a pane
1705                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] +=
1706                         cursor_y -
1707                         (pane[BOTTOM_LEFT_PANE]->y - mwindow->theme->mcanvas_y);
1708                 if(mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] < 0)
1709                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] = 0;
1710                 pane[TOP_LEFT_PANE]->resize_event(
1711                         mwindow->theme->mcanvas_x,
1712                         mwindow->theme->mcanvas_y,
1713                         mwindow->theme->mcanvas_w,
1714                         cursor_y - mwindow->theme->pane_h);
1715                 pane[BOTTOM_LEFT_PANE]->resize_event(
1716                         pane[BOTTOM_LEFT_PANE]->x,
1717                         cursor_y +
1718                                 mwindow->theme->mcanvas_y,
1719                         mwindow->theme->mcanvas_w,
1720                         mwindow->theme->mcanvas_h -
1721                                 cursor_y);
1722         }
1723         else
1724         {
1725 // resize 2 panes
1726                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] +=
1727                         cursor_y -
1728                         (pane[BOTTOM_LEFT_PANE]->y - mwindow->theme->mcanvas_y);
1729                 if(mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] < 0)
1730                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] = 0;
1731                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1732                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE];
1733                 pane[TOP_LEFT_PANE]->resize_event(
1734                         pane[TOP_LEFT_PANE]->x,
1735                         pane[TOP_LEFT_PANE]->y,
1736                         pane[TOP_LEFT_PANE]->w,
1737                         cursor_y - mwindow->theme->pane_h);
1738                 pane[BOTTOM_LEFT_PANE]->resize_event(
1739                         pane[BOTTOM_LEFT_PANE]->x,
1740                         cursor_y +
1741                                 mwindow->theme->mcanvas_y,
1742                         pane[BOTTOM_LEFT_PANE]->w,
1743                         mwindow->theme->mcanvas_h -
1744                                         cursor_y);
1745                 pane[TOP_RIGHT_PANE]->resize_event(
1746                         pane[TOP_RIGHT_PANE]->x,
1747                         pane[TOP_RIGHT_PANE]->y,
1748                         pane[TOP_RIGHT_PANE]->w,
1749                         cursor_y - mwindow->theme->pane_h);
1750                 pane[BOTTOM_RIGHT_PANE]->resize_event(
1751                         pane[BOTTOM_RIGHT_PANE]->x,
1752                         cursor_y +
1753                                 mwindow->theme->mcanvas_y,
1754                         pane[BOTTOM_RIGHT_PANE]->w,
1755                         mwindow->theme->mcanvas_h -
1756                                         cursor_y);
1757         }
1758 }
1759
1760 void MWindowGUI::delete_y_pane(int cursor_y)
1761 {
1762         if(cursor_y < mwindow->theme->mtimebar_h +
1763                 PANE_DRAG_MARGIN &&
1764                 pane[BOTTOM_LEFT_PANE])
1765         {
1766 // give top pane coordinates of bottom pane
1767                 mwindow->edl->local_session->track_start[TOP_LEFT_PANE] =
1768                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] -
1769                         pane[BOTTOM_LEFT_PANE]->y;
1770                 if(mwindow->edl->local_session->track_start[TOP_LEFT_PANE] < 0)
1771                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] = 0;
1772                 mwindow->edl->local_session->track_start[TOP_RIGHT_PANE] =
1773                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE];
1774         }
1775
1776 // delete a pane
1777         switch(total_panes())
1778         {
1779                 case 2:
1780                         delete pane[BOTTOM_LEFT_PANE];
1781                         pane[BOTTOM_LEFT_PANE] = 0;
1782                         pane[TOP_LEFT_PANE]->resize_event(
1783                                 mwindow->theme->mcanvas_x,
1784                                 mwindow->theme->mcanvas_y,
1785                                 mwindow->theme->mcanvas_w,
1786                                 mwindow->theme->mcanvas_h);
1787                         break;
1788
1789                 case 4:
1790 // delete bottom 2 panes
1791
1792                         delete pane[BOTTOM_LEFT_PANE];
1793                         pane[BOTTOM_LEFT_PANE] = 0;
1794                         delete pane[BOTTOM_RIGHT_PANE];
1795                         pane[BOTTOM_RIGHT_PANE] = 0;
1796                         pane[TOP_LEFT_PANE]->resize_event(
1797                                 pane[TOP_LEFT_PANE]->x,
1798                                 mwindow->theme->mcanvas_y,
1799                                 pane[TOP_LEFT_PANE]->w,
1800                                 mwindow->theme->mcanvas_h);
1801                         pane[TOP_RIGHT_PANE]->resize_event(
1802                                 pane[TOP_RIGHT_PANE]->x,
1803                                 mwindow->theme->mcanvas_y,
1804                                 pane[TOP_RIGHT_PANE]->w,
1805                                 mwindow->theme->mcanvas_h);
1806                         break;
1807         }
1808 }
1809
1810 void MWindowGUI::stop_pane_drag()
1811 {
1812         dragging_pane = 0;
1813         resource_thread->stop_draw(0);
1814
1815         if(x_pane_drag)
1816         {
1817 // cursor position relative to canvas
1818                 int cursor_x = x_pane_drag->get_x() -
1819                         get_x() -
1820                         BC_DisplayInfo::get_left_border() -
1821                         mwindow->theme->mcanvas_x +
1822                         mwindow->theme->pane_w;
1823                 delete x_pane_drag;
1824                 x_pane_drag = 0;
1825
1826
1827                 if(cursor_x >= mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1828                         cursor_x < mwindow->theme->mcanvas_w -
1829                                 BC_ScrollBar::get_span(SCROLL_VERT) -
1830                                 PANE_DRAG_MARGIN)
1831                 {
1832                         create_x_pane(cursor_x);
1833                         mwindow->edl->local_session->x_pane = cursor_x;
1834                 }
1835                 else
1836 // deleted a pane
1837                 {
1838                         delete_x_pane(cursor_x);
1839                         mwindow->edl->local_session->x_pane = -1;
1840                 }
1841
1842
1843         }
1844
1845         if(y_pane_drag)
1846         {
1847 // cursor position relative to canvas
1848                 int cursor_y = y_pane_drag->get_y() -
1849                         get_y() -
1850                         BC_DisplayInfo::get_top_border() -
1851                         mwindow->theme->mcanvas_y +
1852                         mwindow->theme->pane_h;
1853                 delete y_pane_drag;
1854                 y_pane_drag = 0;
1855
1856
1857
1858                 if(cursor_y >= mwindow->theme->mtimebar_h +
1859                                 PANE_DRAG_MARGIN &&
1860                         cursor_y < mwindow->theme->mcanvas_h -
1861                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
1862                                 PANE_DRAG_MARGIN)
1863                 {
1864                         create_y_pane(cursor_y);
1865                         mwindow->edl->local_session->y_pane = cursor_y;
1866                 }
1867                 else
1868                 {
1869                         delete_y_pane(cursor_y);
1870                         mwindow->edl->local_session->y_pane = -1;
1871                 }
1872         }
1873
1874         update_pane_dividers();
1875         update_cursor();
1876 // required to get new widgets to appear
1877         show_window();
1878         resource_thread->start_draw();
1879 }
1880
1881 // create panes from EDL
1882 void MWindowGUI::load_panes()
1883 {
1884         int need_x_panes = 0;
1885         int need_y_panes = 0;
1886 // use names from create functions
1887         int cursor_x = mwindow->edl->local_session->x_pane;
1888         int cursor_y = mwindow->edl->local_session->y_pane;
1889
1890         resource_thread->stop_draw(1);
1891         if(cursor_x >=
1892                 mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1893                 cursor_x <
1894                 mwindow->theme->mcanvas_w -
1895                                 BC_ScrollBar::get_span(SCROLL_VERT) -
1896                                 PANE_DRAG_MARGIN)
1897         {
1898                 need_x_panes = 1;
1899         }
1900
1901         if(cursor_y >=
1902                 mwindow->theme->mtimebar_h + PANE_DRAG_MARGIN &&
1903                 cursor_y <
1904                 mwindow->theme->mcanvas_h -
1905                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
1906                                 PANE_DRAG_MARGIN)
1907         {
1908                 need_y_panes = 1;
1909         }
1910
1911 //printf("MWindowGUI::load_panes %d %d %d\n", __LINE__, need_x_panes, need_y_panes);
1912
1913
1914         if(need_x_panes)
1915         {
1916                 if(need_y_panes)
1917                 {
1918 // 4 panes
1919                         if(total_panes() == 1)
1920                         {
1921 // create 4 panes
1922 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1923                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1924                                         TOP_RIGHT_PANE,
1925                                         mwindow->theme->mcanvas_x +
1926                                                 cursor_x,
1927                                         mwindow->theme->mcanvas_y,
1928                                         mwindow->theme->mcanvas_x +
1929                                                 mwindow->theme->mcanvas_w -
1930                                                 cursor_x,
1931                                         cursor_y - mwindow->theme->pane_h);
1932                                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1933                                         BOTTOM_LEFT_PANE,
1934                                         mwindow->theme->mcanvas_x,
1935                                         mwindow->theme->mcanvas_y +
1936                                                 cursor_y,
1937                                         cursor_x - mwindow->theme->pane_w,
1938                                         mwindow->theme->mcanvas_h -
1939                                                 cursor_y);
1940                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1941                                         BOTTOM_RIGHT_PANE,
1942                                         pane[TOP_RIGHT_PANE]->x,
1943                                         mwindow->theme->mcanvas_y +
1944                                                 cursor_y,
1945                                         pane[TOP_RIGHT_PANE]->w,
1946                                         mwindow->theme->mcanvas_h -
1947                                                 cursor_y);
1948                                 pane[TOP_LEFT_PANE]->resize_event(
1949                                         pane[TOP_LEFT_PANE]->x,
1950                                         pane[TOP_LEFT_PANE]->y,
1951                                         cursor_x - mwindow->theme->pane_w,
1952                                         cursor_y - mwindow->theme->pane_h);
1953                                 pane[TOP_RIGHT_PANE]->create_objects();
1954                                 pane[BOTTOM_LEFT_PANE]->create_objects();
1955                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1956                         }
1957                         else
1958                         if(horizontal_panes())
1959                         {
1960 // create vertical panes
1961 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1962                                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1963                                         BOTTOM_LEFT_PANE,
1964                                         mwindow->theme->mcanvas_x,
1965                                         mwindow->theme->mcanvas_y +
1966                                                 cursor_y,
1967                                         cursor_x - mwindow->theme->pane_w,
1968                                         mwindow->theme->mcanvas_h -
1969                                                 cursor_y);
1970                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1971                                         BOTTOM_RIGHT_PANE,
1972                                         pane[TOP_RIGHT_PANE]->x,
1973                                         mwindow->theme->mcanvas_y +
1974                                                 cursor_y,
1975                                         pane[TOP_RIGHT_PANE]->w,
1976                                         mwindow->theme->mcanvas_h -
1977                                                 cursor_y);
1978                                 pane[TOP_LEFT_PANE]->resize_event(
1979                                         pane[TOP_LEFT_PANE]->x,
1980                                         pane[TOP_LEFT_PANE]->y,
1981                                         cursor_x - mwindow->theme->pane_w,
1982                                         cursor_y - mwindow->theme->pane_h);
1983                                 pane[TOP_RIGHT_PANE]->resize_event(
1984                                         mwindow->theme->mcanvas_x +
1985                                                 cursor_x,
1986                                         mwindow->theme->mcanvas_y,
1987                                         mwindow->theme->mcanvas_x +
1988                                                 mwindow->theme->mcanvas_w -
1989                                                 cursor_x,
1990                                         cursor_y - mwindow->theme->pane_h);
1991                                 pane[BOTTOM_LEFT_PANE]->create_objects();
1992                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1993                         }
1994                         else
1995                         if(vertical_panes())
1996                         {
1997 // create horizontal panes
1998 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1999                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
2000                                         TOP_RIGHT_PANE,
2001                                         mwindow->theme->mcanvas_x +
2002                                                 cursor_x,
2003                                         mwindow->theme->mcanvas_y,
2004                                         mwindow->theme->mcanvas_x +
2005                                                 mwindow->theme->mcanvas_w -
2006                                                 cursor_x,
2007                                         cursor_y - mwindow->theme->pane_h);
2008                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
2009                                         BOTTOM_RIGHT_PANE,
2010                                         pane[TOP_RIGHT_PANE]->x,
2011                                         mwindow->theme->mcanvas_y +
2012                                                 cursor_y,
2013                                         pane[TOP_RIGHT_PANE]->w,
2014                                         mwindow->theme->mcanvas_h -
2015                                                 cursor_y);
2016                                 pane[TOP_LEFT_PANE]->resize_event(
2017                                         pane[TOP_LEFT_PANE]->x,
2018                                         pane[TOP_LEFT_PANE]->y,
2019                                         cursor_x - mwindow->theme->pane_w,
2020                                         cursor_y - mwindow->theme->pane_h);
2021                                 pane[BOTTOM_LEFT_PANE]->resize_event(
2022                                         pane[TOP_LEFT_PANE]->x,
2023                                         mwindow->theme->mcanvas_y +
2024                                                 cursor_y,
2025                                         mwindow->theme->mcanvas_x +
2026                                                 mwindow->theme->mcanvas_w -
2027                                                 cursor_x -  mwindow->theme->pane_w,
2028                                         mwindow->theme->mcanvas_h -
2029                                                 cursor_y);
2030                                 pane[TOP_RIGHT_PANE]->create_objects();
2031                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
2032
2033
2034                         }
2035                         else
2036                         {
2037 // resize all panes
2038 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2039                                 pane[TOP_LEFT_PANE]->resize_event(
2040                                         pane[TOP_LEFT_PANE]->x,
2041                                         pane[TOP_LEFT_PANE]->y,
2042                                         cursor_x - mwindow->theme->pane_w,
2043                                         cursor_y - mwindow->theme->pane_h);
2044                                 pane[TOP_RIGHT_PANE]->resize_event(
2045                                         mwindow->theme->mcanvas_x +
2046                                                 cursor_x,
2047                                         mwindow->theme->mcanvas_y,
2048                                         mwindow->theme->mcanvas_x +
2049                                                 mwindow->theme->mcanvas_w -
2050                                                 cursor_x,
2051                                         cursor_y - mwindow->theme->pane_h);
2052                                 pane[BOTTOM_LEFT_PANE]->resize_event(
2053                                         pane[TOP_LEFT_PANE]->x,
2054                                         mwindow->theme->mcanvas_y +
2055                                                 cursor_y,
2056                                         mwindow->theme->mcanvas_x +
2057                                                 mwindow->theme->mcanvas_w -
2058                                                 cursor_x - mwindow->theme->pane_w,
2059                                         mwindow->theme->mcanvas_h -
2060                                                 cursor_y);
2061                                 pane[BOTTOM_RIGHT_PANE]->resize_event(
2062                                         pane[TOP_RIGHT_PANE]->x,
2063                                         mwindow->theme->mcanvas_y +
2064                                                 cursor_y,
2065                                         pane[TOP_RIGHT_PANE]->w,
2066                                         mwindow->theme->mcanvas_h -
2067                                                 cursor_y);
2068
2069
2070                         }
2071                 }
2072                 else
2073                 {
2074 // 2 X panes
2075                         if(pane[BOTTOM_LEFT_PANE]) delete pane[BOTTOM_LEFT_PANE];
2076                         if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2077                         pane[BOTTOM_LEFT_PANE] = 0;
2078                         pane[BOTTOM_RIGHT_PANE] = 0;
2079
2080                         if(!pane[TOP_RIGHT_PANE])
2081                         {
2082                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
2083                                         TOP_RIGHT_PANE,
2084                                         mwindow->theme->mcanvas_x +
2085                                                 cursor_x,
2086                                         mwindow->theme->mcanvas_y,
2087                                         mwindow->theme->mcanvas_x +
2088                                                 mwindow->theme->mcanvas_w -
2089                                                 cursor_x,
2090                                         mwindow->theme->mcanvas_h);
2091                                 pane[TOP_LEFT_PANE]->resize_event(
2092                                         mwindow->theme->mcanvas_x,
2093                                         mwindow->theme->mcanvas_y,
2094                                         cursor_x - mwindow->theme->pane_w,
2095                                         mwindow->theme->mcanvas_h);
2096                                 pane[TOP_RIGHT_PANE]->create_objects();
2097                         }
2098                         else
2099                         {
2100                                 pane[TOP_LEFT_PANE]->resize_event(
2101                                         mwindow->theme->mcanvas_x,
2102                                         mwindow->theme->mcanvas_y,
2103                                         cursor_x - mwindow->theme->pane_w,
2104                                         mwindow->theme->mcanvas_h);
2105                                 pane[TOP_RIGHT_PANE]->resize_event(
2106                                         mwindow->theme->mcanvas_x +
2107                                                 cursor_x,
2108                                         pane[TOP_RIGHT_PANE]->y,
2109                                         mwindow->theme->mcanvas_x +
2110                                                 mwindow->theme->mcanvas_w -
2111                                                 cursor_x,
2112                                         mwindow->theme->mcanvas_h);
2113                         }
2114                 }
2115         }
2116         else
2117         if(need_y_panes)
2118         {
2119 // 2 Y panes
2120                 if(pane[TOP_RIGHT_PANE]) delete pane[TOP_RIGHT_PANE];
2121                 if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2122                 pane[TOP_RIGHT_PANE] = 0;
2123                 pane[BOTTOM_RIGHT_PANE] = 0;
2124
2125                 if(!pane[BOTTOM_LEFT_PANE])
2126                 {
2127 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2128                         pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
2129                                 BOTTOM_LEFT_PANE,
2130                                 mwindow->theme->mcanvas_x,
2131                                 mwindow->theme->mcanvas_y +
2132                                         cursor_y,
2133                                 mwindow->theme->mcanvas_w,
2134                                 mwindow->theme->mcanvas_h -
2135                                         cursor_y);
2136                         pane[TOP_LEFT_PANE]->resize_event(
2137                                 mwindow->theme->mcanvas_x,
2138                                 mwindow->theme->mcanvas_y,
2139                                 mwindow->theme->mcanvas_w,
2140                                 pane[BOTTOM_LEFT_PANE]->y -
2141                                         mwindow->theme->mcanvas_y -
2142                                         mwindow->theme->pane_h);
2143                         pane[BOTTOM_LEFT_PANE]->create_objects();
2144                 }
2145                 else
2146                 {
2147                         pane[TOP_LEFT_PANE]->resize_event(
2148                                 mwindow->theme->mcanvas_x,
2149                                 mwindow->theme->mcanvas_y,
2150                                 mwindow->theme->mcanvas_w,
2151                                 cursor_y - mwindow->theme->pane_h);
2152                         pane[BOTTOM_LEFT_PANE]->resize_event(
2153                                 pane[BOTTOM_LEFT_PANE]->x,
2154                                 cursor_y +
2155                                         mwindow->theme->mcanvas_y,
2156                                 mwindow->theme->mcanvas_w,
2157                                 mwindow->theme->mcanvas_h -
2158                                         cursor_y);
2159                 }
2160         }
2161         else
2162         {
2163 // 1 pane
2164                 if(pane[TOP_RIGHT_PANE]) delete pane[TOP_RIGHT_PANE];
2165                 if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2166                 if(pane[BOTTOM_LEFT_PANE]) delete pane[BOTTOM_LEFT_PANE];
2167                 pane[TOP_RIGHT_PANE] = 0;
2168                 pane[BOTTOM_RIGHT_PANE] = 0;
2169                 pane[BOTTOM_LEFT_PANE] = 0;
2170                 pane[TOP_LEFT_PANE]->resize_event(
2171                         mwindow->theme->mcanvas_x,
2172                         mwindow->theme->mcanvas_y,
2173                         mwindow->theme->mcanvas_w,
2174                         mwindow->theme->mcanvas_h);
2175         }
2176
2177         update_pane_dividers();
2178         show_window();
2179
2180         resource_thread->start_draw();
2181 }
2182
2183 void MWindowGUI::update_pane_dividers()
2184 {
2185
2186         if(horizontal_panes() || total_panes() == 4)
2187         {
2188                 int x = pane[TOP_RIGHT_PANE]->x - mwindow->theme->pane_w;
2189                 int y = mwindow->theme->mcanvas_y;
2190                 int h = mwindow->theme->mcanvas_h;
2191
2192                 if(!x_divider)
2193                 {
2194                         add_subwindow(x_divider = new PaneDivider(
2195                                 mwindow, x, y, h, 1));
2196                         x_divider->create_objects();
2197                 }
2198                 else
2199                 {
2200                         x_divider->reposition_window(x, y, h);
2201                         x_divider->draw(0);
2202                 }
2203         }
2204         else
2205         {
2206                 if(x_divider)
2207                 {
2208                         delete x_divider;
2209                         x_divider = 0;
2210                 }
2211         }
2212
2213         if(vertical_panes() || total_panes() == 4)
2214         {
2215                 int x = mwindow->theme->mcanvas_x;
2216                 int y = pane[BOTTOM_LEFT_PANE]->y -
2217                         mwindow->theme->pane_h;
2218                 int w = mwindow->theme->mcanvas_w;
2219                 if(!y_divider)
2220                 {
2221                         add_subwindow(y_divider = new PaneDivider(
2222                                 mwindow, x, y, w, 0));
2223                         y_divider->create_objects();
2224                 }
2225                 else
2226                 {
2227                         y_divider->reposition_window(x, y, w);
2228                         y_divider->draw(0);
2229                 }
2230         }
2231         else
2232         {
2233                 if(y_divider)
2234                 {
2235                         delete y_divider;
2236                         y_divider = 0;
2237                 }
2238         }
2239 }
2240
2241 void MWindowGUI::draw_samplemovement()
2242 {
2243         draw_canvas(0, 1);
2244         show_cursor(1);
2245         flash_canvas(0);
2246         update_timebar(0);
2247         zoombar->update();
2248         update_scrollbars(1);
2249 }
2250
2251 void MWindowGUI::draw_trackmovement()
2252 {
2253         update_scrollbars(0);
2254         draw_canvas(0, 0);
2255         update_patchbay();
2256         flash_canvas(1);
2257 }
2258
2259
2260 void MWindowGUI::update_mixers(Track *track, int v)
2261 {
2262         for( int i=0; i<TOTAL_PANES;  ++i ) {
2263                 if( !pane[i] ) continue;
2264                 PatchBay *patchbay = pane[i]->patchbay;
2265                 if( !patchbay ) continue;
2266                 for( int j=0; j<patchbay->patches.total; ++j ) {
2267                         PatchGUI *patchgui = patchbay->patches.values[j];
2268                         if( !patchgui->mix ) continue;
2269                         if( !track || patchgui->track == track ) {
2270                                 patchgui->mix->update(v>=0 ? v :
2271                                         mwindow->mixer_track_active(patchgui->track));
2272                         }
2273                 }
2274         }
2275 }
2276
2277 void MWindowGUI::stop_transport(const char *lock_msg)
2278 {
2279         if( !mbuttons->transport->is_stopped() ) {
2280                 if( lock_msg ) unlock_window();
2281                 mbuttons->transport->handle_transport(STOP, 1);
2282                 if( lock_msg ) lock_window(lock_msg);
2283         }
2284 }
2285
2286 PaneButton::PaneButton(MWindow *mwindow, int x, int y)
2287  : BC_Button(x, y, mwindow->theme->get_image_set("pane"))
2288 {
2289         this->mwindow = mwindow;
2290 }
2291
2292 int PaneButton::cursor_motion_event()
2293 {
2294         if(get_top_level()->get_button_down() &&
2295                 is_event_win() &&
2296                 get_status() == BUTTON_DOWNHI &&
2297                 !cursor_inside())
2298         {
2299 //              printf("PaneButton::cursor_motion_event %d\n", __LINE__);
2300 // create drag bar
2301                 if(get_cursor_x() < 0 && !mwindow->gui->dragging_pane)
2302                 {
2303                         mwindow->gui->start_x_pane_drag();
2304                 }
2305                 else
2306                 if(get_cursor_y() < 0 && !mwindow->gui->dragging_pane)
2307                 {
2308                         mwindow->gui->start_y_pane_drag();
2309                 }
2310         }
2311
2312         mwindow->gui->handle_pane_drag();
2313
2314         int result = BC_Button::cursor_motion_event();
2315         return result;
2316 }
2317
2318 int PaneButton::button_release_event()
2319 {
2320         if( get_buttonpress() != WHEEL_DOWN && get_buttonpress() != WHEEL_UP )
2321                 mwindow->gui->stop_pane_drag();
2322         int result = BC_Button::button_release_event();
2323         return result;
2324 }
2325
2326
2327 FFMpegToggle::FFMpegToggle(MWindow *mwindow, MButtons *mbuttons, int x, int y)
2328  : BC_Toggle(x, y, mwindow->theme->ffmpeg_toggle,
2329          mwindow->preferences->get_file_probe_armed("FFMPEG_Early") > 0 ? 1 : 0)
2330 {
2331         this->mwindow = mwindow;
2332         this->mbuttons = mbuttons;
2333         set_tooltip(get_value() ? FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
2334 }
2335
2336 FFMpegToggle::~FFMpegToggle()
2337 {
2338 }
2339
2340 int FFMpegToggle::handle_event()
2341 {
2342         int ffmpeg_early_probe = get_value();
2343         set_tooltip(ffmpeg_early_probe ? FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
2344         mwindow->preferences->set_file_probe_armed("FFMPEG_Early", ffmpeg_early_probe);
2345         mwindow->preferences->set_file_probe_armed("FFMPEG_Late", !ffmpeg_early_probe);
2346         mwindow->update_preferences(mwindow->preferences);
2347         mwindow->show_warning(&mwindow->preferences->warn_indexes,
2348                 _("Changing the base codecs may require rebuilding indexes."));
2349         return 1;
2350 }
2351
2352
2353 StackButton::StackButton(MWindow *mwindow, int x, int y)
2354  : BC_GenericButton(x, y, mwindow->theme->stack_button_w, "0")
2355 {
2356         this->mwindow = mwindow;
2357         set_tooltip(_("Close EDL"));
2358 }
2359
2360 int StackButton::handle_event()
2361 {
2362         mwindow->save_backup();
2363         mwindow->stack_pop();
2364         return 1;
2365 }
2366
2367 void StackButton::update()
2368 {
2369         char text[BCSTRLEN];
2370         int i = mwindow->stack.size();
2371         sprintf(text, "%d", i);
2372         set_text(text);
2373         draw_face();
2374 }
2375
2376
2377 ProxyToggle::ProxyToggle(MWindow *mwindow, MButtons *mbuttons, int x, int y)
2378  : BC_Toggle(x, y, ( !mwindow->edl->session->proxy_use_scaler ?
2379                         mwindow->theme->proxy_p_toggle :
2380                         mwindow->theme->proxy_s_toggle ),
2381                 mwindow->edl->session->proxy_disabled_scale != 1)
2382 {
2383         this->mwindow = mwindow;
2384         this->mbuttons = mbuttons;
2385         scaler_images = mwindow->edl->session->proxy_use_scaler;
2386         set_tooltip(mwindow->edl->session->proxy_disabled_scale==1 ?
2387                 _("Disable proxy") : _("Enable proxy"));
2388 }
2389
2390 void ProxyToggle::show()
2391 {
2392         int use_scaler = mwindow->edl->session->proxy_use_scaler;
2393         if( scaler_images != use_scaler )
2394                 set_images(!(scaler_images=use_scaler) ?
2395                         mwindow->theme->proxy_p_toggle :
2396                         mwindow->theme->proxy_s_toggle );
2397         draw_face(1, 0);
2398         if( is_hidden() )
2399                 show_window();
2400 }
2401
2402 void ProxyToggle::hide()
2403 {
2404         if( !is_hidden() )
2405                 hide_window();
2406 }
2407
2408 ProxyToggle::~ProxyToggle()
2409 {
2410 }
2411
2412 int ProxyToggle::handle_event()
2413 {
2414         int disabled = get_value();
2415         mwindow->gui->unlock_window();
2416         if( disabled )
2417                 mwindow->disable_proxy();
2418         else
2419                 mwindow->enable_proxy();
2420         mwindow->gui->lock_window("ProxyToggle::handle_event");
2421         set_tooltip(!disabled ? _("Disable proxy") : _("Enable proxy"));
2422         return 1;
2423 }
2424
2425 int ProxyToggle::keypress_event()
2426 {
2427         if( ctrl_down() && !shift_down() && !alt_down() ) {
2428                 int key = get_keypress();
2429                 if( key == 'r' ) {
2430                         int value = get_value() ? 0 : 1;
2431                         set_value(value);
2432                         return handle_event();
2433                 }
2434         }
2435         return 0;
2436 }
2437