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