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