dblclk label folder item is goto, fix no-drag trns if not drawn, amp up pane divider...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mwindowgui.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "androidcontrol.h"
23 #include "awindowgui.h"
24 #include "awindow.h"
25 #include "bcdisplayinfo.h"
26 #include "bchash.h"
27 #include "bcsignals.h"
28 #include "clip.h"
29 #include "cwindowgui.h"
30 #include "cwindow.h"
31 #include "channelinfo.h"
32 #include "dbwindow.h"
33 #include "edit.h"
34 #include "editpopup.h"
35 #include "edits.h"
36 #include "edl.h"
37 #include "edlsession.h"
38 #include "filesystem.h"
39 #include "filexml.h"
40 #include "keyframepopup.h"
41 #include "keys.h"
42 #include "language.h"
43 #include "localsession.h"
44 #include "mainclock.h"
45 #include "maincursor.h"
46 #include "mainmenu.h"
47 #include "mainsession.h"
48 #include "mainundo.h"
49 #include "mbuttons.h"
50 #include "mtimebar.h"
51 #include "mwindowgui.h"
52 #include "mwindow.h"
53 #include "panedividers.h"
54 #include "patchbay.h"
55 #include "plugin.h"
56 #include "pluginpopup.h"
57 #include "pluginset.h"
58 #include "preferences.h"
59 #include "record.h"
60 #include "recordgui.h"
61 #include "renderengine.h"
62 #include "remotecontrol.h"
63 #include "resourcethread.h"
64 #include "samplescroll.h"
65 #include "shbtnprefs.h"
66 #include "statusbar.h"
67 #include "swindow.h"
68 #include "theme.h"
69 #include "trackcanvas.h"
70 #include "trackpopup.h"
71 #include "trackscroll.h"
72 #include "tracks.h"
73 #include "transitionpopup.h"
74 #include "vwindowgui.h"
75 #include "vwindow.h"
76 #include "wintv.h"
77 #include "x10tv.h"
78 #include "zoombar.h"
79
80 #define PANE_DRAG_MARGIN MAX(mwindow->theme->pane_w, mwindow->theme->pane_h)
81
82
83 // the main window uses its own private colormap for video
84 MWindowGUI::MWindowGUI(MWindow *mwindow)
85  : BC_Window(_(PROGRAM_NAME ": Program"),
86                 mwindow->session->mwindow_x, mwindow->session->mwindow_y,
87                 mwindow->session->mwindow_w, mwindow->session->mwindow_h,
88                 xS(100), yS(100), 1, 1, 1)
89 {
90         this->mwindow = mwindow;
91 //      samplescroll = 0;
92 //      trackscroll = 0;
93 //      cursor = 0;
94 //      patchbay = 0;
95 //      timebar = 0;
96 //      canvas = 0;
97         focused_pane = TOP_LEFT_PANE;
98         x_divider = 0;
99         y_divider = 0;
100         x_pane_drag = 0;
101         y_pane_drag = 0;
102         dragging_pane = 0;
103         drag_popup = 0;
104
105         render_engine = 0;
106         render_engine_id = -1;
107         for(int i = 0; i < TOTAL_PANES; i++)
108                 pane[i] = 0;
109
110         record = 0;
111         channel_info = 0;
112         swindow = 0;
113         db_window = 0;
114 // subwindows
115         mbuttons = 0;
116         statusbar = 0;
117         zoombar = 0;
118         mainclock = 0;
119         track_menu = 0;
120         edit_menu = 0;
121         plugin_menu = 0;
122         keyframe_menu = 0;
123         keyframe_hide = 0;
124         keyvalue_popup = 0;
125         transition_menu = 0;
126         remote_control = 0;
127         cwindow_remote_handler = 0;
128         record_remote_handler = 0;
129         android_control = 0;
130 }
131
132
133 MWindowGUI::~MWindowGUI()
134 {
135         delete android_control;
136         delete cwindow_remote_handler;
137         delete record_remote_handler;
138         delete remote_control;
139         delete keyvalue_popup;
140 //      delete samplescroll;
141 //      delete trackscroll;
142         for(int i = 0; i < TOTAL_PANES; i++)
143                 if(pane[i]) delete pane[i];
144 //      delete cursor;
145         delete render_engine;
146         delete resource_thread;
147         resource_pixmaps.remove_all_objects();
148         delete swindow;
149 #ifdef HAVE_DVB
150         delete channel_info;
151 #endif
152         delete db_window;
153         delete x_divider;
154         delete y_divider;
155 }
156
157 void MWindowGUI::create_objects()
158 {
159         lock_window("MWindowGUI::create_objects");
160         const int debug = 0;
161
162         resource_thread = new ResourceThread(mwindow);
163         resource_thread->create_objects();
164
165
166         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
167         set_icon(mwindow->theme->get_image("mwindow_icon"));
168         remote_control = new RemoteControl(this);
169         cwindow_remote_handler = 0;
170         record_remote_handler = 0;
171 #ifdef HAVE_X10TV
172 // should be first, use if plugged
173         if( !cwindow_remote_handler && mwindow->x10tv ) {
174                 cwindow_remote_handler = (RemoteHandler*)
175                         new X10TVCWindowHandler(mwindow->x10tv, remote_control);
176                 record_remote_handler = (RemoteHandler*)
177                         new X10TVRecordHandler(mwindow->x10tv, remote_control);
178         }
179 #endif
180 #ifdef HAVE_WINTV
181         if( !cwindow_remote_handler && mwindow->wintv ) {
182                 cwindow_remote_handler = (RemoteHandler*)
183                         new WinTVCWindowHandler(mwindow->wintv, remote_control);
184                 record_remote_handler = (RemoteHandler*)
185                         new WinTVRecordHandler(mwindow->wintv, remote_control);
186         }
187 #endif
188         mwindow->reset_android_remote();
189         if( !cwindow_remote_handler )
190                 cwindow_remote_handler = (RemoteHandler*)
191                         new CWindowKeyEvHandler(mwindow->gui->remote_control);
192         if( !record_remote_handler )
193                 record_remote_handler = (RemoteHandler*)
194                         new RecordKeyEvHandler(mwindow->gui->remote_control);
195         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
196
197         int x1 = get_w() - MainShBtns::calculate_w(-1, 0, -1) - xS(5);
198         add_subwindow(mainshbtns = new MainShBtns(mwindow, x1, -1));
199         mainshbtns->load(mwindow->preferences);
200         int x2 = x1 - mwindow->theme->stack_button_w - xS(5);
201         add_subwindow(stack_button = new StackButton(mwindow, x2, yS(2)));
202         add_subwindow(mainmenu = new MainMenu(mwindow, this, x2));
203         mainmenu->create_objects();
204         mwindow->theme->get_mwindow_sizes(this, get_w(), get_h());
205         mwindow->theme->draw_mwindow_bg(this);
206         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
207
208         add_subwindow(mbuttons = new MButtons(mwindow, this));
209         mbuttons->create_objects();
210         int y1 = mbuttons->get_y()+yS(2);
211         add_subwindow(proxy_toggle = new ProxyToggle(mwindow, mbuttons, x2, y1));
212         add_subwindow(ffmpeg_toggle = new FFMpegToggle(mwindow, mbuttons, x1, y1));
213
214         pane[TOP_LEFT_PANE] = new TimelinePane(mwindow,
215                 TOP_LEFT_PANE,
216                 mwindow->theme->mcanvas_x,
217                 mwindow->theme->mcanvas_y,
218                 mwindow->theme->mcanvas_w,
219                 mwindow->theme->mcanvas_h);
220         pane[TOP_LEFT_PANE]->create_objects();
221
222         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
223         add_subwindow(zoombar = new ZoomBar(mwindow, this));
224         zoombar->create_objects();
225
226
227         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
228         add_subwindow(statusbar = new StatusBar(mwindow, this));
229         statusbar->create_objects();
230
231
232
233         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
234         add_subwindow(mainclock = new MainClock(mwindow,
235                 mwindow->theme->mclock_x, mwindow->theme->mclock_y,
236                 mwindow->theme->mclock_w));
237         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
238         mainclock->update(0);
239
240
241
242 //      if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
243 //      cursor = new MainCursor(mwindow, this);
244 //      cursor->create_objects();
245
246
247         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
248         add_subwindow(track_menu = new TrackPopup(mwindow, this));
249         track_menu->create_objects();
250         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
251         add_subwindow(edit_menu = new EditPopup(mwindow, this));
252         edit_menu->create_objects();
253
254
255         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
256         add_subwindow(plugin_menu = new PluginPopup(mwindow, this));
257         plugin_menu->create_objects();
258
259
260         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
261         add_subwindow(keyframe_menu = new KeyframePopup(mwindow, this));
262         keyframe_menu->create_objects();
263         add_subwindow(keyframe_hide = new KeyframeHidePopup(mwindow, this));
264         keyframe_hide->create_objects();
265
266
267         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
268         add_subwindow(transition_menu = new TransitionPopup(mwindow, this));
269         transition_menu->create_objects();
270
271 #ifdef HAVE_DVB
272         channel_info = new ChannelInfo(mwindow);
273 #endif
274 #ifdef HAVE_COMMERCIAL
275         db_window = new DbWindow(mwindow);
276 #endif
277         swindow = new SWindow(mwindow);
278
279         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
280
281         add_subwindow(pane_button = new PaneButton(mwindow,
282                 get_w() - mwindow->theme->get_image_set("pane")[0]->get_w(),
283                 mwindow->theme->mzoom_y + 1 - mwindow->theme->get_image_set("pane")[0]->get_h()));
284
285         pane[TOP_LEFT_PANE]->canvas->activate();
286
287         if(debug) printf("MWindowGUI::create_objects %d\n", __LINE__);
288         unlock_window();
289 }
290
291 void MWindowGUI::redraw_time_dependancies()
292 {
293         zoombar->redraw_time_dependancies();
294         for(int i = 0; i < TOTAL_PANES; i++)
295                 if(pane[i] && pane[i]->timebar) pane[i]->timebar->update(0);
296         mainclock->update(mwindow->edl->local_session->get_selectionstart(1));
297 }
298
299 int MWindowGUI::focus_in_event()
300 {
301         for(int i = 0; i < TOTAL_PANES; i++)
302                 if(pane[i] && pane[i]->cursor) pane[i]->cursor->focus_in_event();
303         return 1;
304 }
305
306 int MWindowGUI::focus_out_event()
307 {
308         for(int i = 0; i < TOTAL_PANES; i++)
309                 if(pane[i] && pane[i]->cursor) pane[i]->cursor->focus_out_event();
310         return 1;
311 }
312
313
314 int MWindowGUI::resize_event(int w, int h)
315 {
316 //printf("MWindowGUI::resize_event %d\n", __LINE__);
317         mwindow->session->mwindow_w = w;
318         mwindow->session->mwindow_h = h;
319         int x1 = w - MainShBtns::calculate_w(-1, 0, -1) - xS(5);
320         mainshbtns->reposition_window(x1, -1);
321         int x2 = x1 - mwindow->theme->stack_button_w - xS(5);
322         stack_button->reposition_window(x2, stack_button->get_y());
323         mainmenu->resize_event(x2, mainmenu->get_h());
324         mwindow->theme->get_mwindow_sizes(this, w, h);
325         mwindow->theme->draw_mwindow_bg(this);
326         mbuttons->resize_event();
327         int y1 = mbuttons->get_y()+yS(2);
328         proxy_toggle->reposition_window(x2, y1);
329         ffmpeg_toggle->reposition_window(x1, y1);
330         statusbar->resize_event();
331         zoombar->resize_event();
332
333         resource_thread->stop_draw(1);
334
335         if(total_panes() > 1)
336         {
337                 if(horizontal_panes())
338                 {
339 //                      printf("MWindowGUI::resize_event %d %d %d\n",
340 //                              __LINE__,
341 //                              pane[TOP_RIGHT_PANE]->x,
342 //                              mwindow->theme->mcanvas_w -
343 //                                      BC_ScrollBar::get_span(SCROLL_VERT) -
344 //                                      PANE_DRAG_MARGIN);
345                         if(pane[TOP_RIGHT_PANE]->x >= mwindow->theme->mcanvas_w -
346                                 BC_ScrollBar::get_span(SCROLL_VERT) -
347                                 PANE_DRAG_MARGIN)
348                         {
349                                 delete_x_pane(pane[TOP_RIGHT_PANE]->x);
350                                 mwindow->edl->local_session->x_pane = -1;
351                         }
352                 }
353                 else
354                 if(vertical_panes())
355                 {
356                         if(pane[BOTTOM_LEFT_PANE]->y >= mwindow->theme->mzoom_y -
357                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
358                                 PANE_DRAG_MARGIN)
359                         {
360                                 delete_y_pane(pane[BOTTOM_LEFT_PANE]->y);
361                                 mwindow->edl->local_session->y_pane = -1;
362                         }
363                 }
364                 else
365                 {
366                         if(pane[TOP_RIGHT_PANE]->x >= mwindow->theme->mcanvas_w -
367                                         BC_ScrollBar::get_span(SCROLL_VERT) -
368                                         PANE_DRAG_MARGIN)
369                         {
370                                 delete_x_pane(pane[TOP_RIGHT_PANE]->x);
371                                 mwindow->edl->local_session->x_pane = -1;
372                         }
373
374                         if(pane[BOTTOM_LEFT_PANE]->y >= mwindow->theme->mzoom_y -
375                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
376                                 PANE_DRAG_MARGIN)
377                         {
378                                 delete_y_pane(pane[BOTTOM_LEFT_PANE]->y);
379                                 mwindow->edl->local_session->y_pane = -1;
380                         }
381                 }
382         }
383
384         if(total_panes() == 1)
385         {
386                 pane[TOP_LEFT_PANE]->resize_event(
387                         mwindow->theme->mcanvas_x,
388                         mwindow->theme->mcanvas_y,
389                         mwindow->theme->mcanvas_w,
390                         mwindow->theme->mcanvas_h);
391         }
392         else
393         if(horizontal_panes())
394         {
395                 pane[TOP_LEFT_PANE]->resize_event(
396                         pane[TOP_LEFT_PANE]->x,
397                         pane[TOP_LEFT_PANE]->y,
398                         pane[TOP_LEFT_PANE]->w,
399                         mwindow->theme->mcanvas_h);
400                 pane[TOP_RIGHT_PANE]->resize_event(
401                         pane[TOP_RIGHT_PANE]->x,
402                         pane[TOP_RIGHT_PANE]->y,
403                         mwindow->theme->mcanvas_w - pane[TOP_RIGHT_PANE]->x,
404                         mwindow->theme->mcanvas_h);
405         }
406         else
407         if(vertical_panes())
408         {
409                 pane[TOP_LEFT_PANE]->resize_event(
410                         pane[TOP_LEFT_PANE]->x,
411                         pane[TOP_LEFT_PANE]->y,
412                         mwindow->theme->mcanvas_w,
413                         pane[TOP_LEFT_PANE]->h);
414                 pane[BOTTOM_LEFT_PANE]->resize_event(
415                         pane[BOTTOM_LEFT_PANE]->x,
416                         pane[BOTTOM_LEFT_PANE]->y,
417                         mwindow->theme->mcanvas_w,
418                         mwindow->theme->mcanvas_y +
419                                 mwindow->theme->mcanvas_h -
420                                 pane[BOTTOM_LEFT_PANE]->y);
421         }
422         else
423         {
424                 pane[TOP_LEFT_PANE]->resize_event(
425                         pane[TOP_LEFT_PANE]->x,
426                         pane[TOP_LEFT_PANE]->y,
427                         pane[TOP_LEFT_PANE]->w,
428                         pane[TOP_LEFT_PANE]->h);
429                 pane[TOP_RIGHT_PANE]->resize_event(
430                         pane[TOP_RIGHT_PANE]->x,
431                         pane[TOP_RIGHT_PANE]->y,
432                         mwindow->theme->mcanvas_w - pane[TOP_RIGHT_PANE]->x,
433                         pane[TOP_RIGHT_PANE]->h);
434                 pane[BOTTOM_LEFT_PANE]->resize_event(
435                         pane[BOTTOM_LEFT_PANE]->x,
436                         pane[BOTTOM_LEFT_PANE]->y,
437                         pane[BOTTOM_LEFT_PANE]->w,
438                         mwindow->theme->mcanvas_y +
439                                 mwindow->theme->mcanvas_h -
440                                 pane[BOTTOM_LEFT_PANE]->y);
441                 pane[BOTTOM_RIGHT_PANE]->resize_event(
442                         pane[BOTTOM_RIGHT_PANE]->x,
443                         pane[BOTTOM_RIGHT_PANE]->y,
444                         mwindow->theme->mcanvas_w -
445                                 pane[BOTTOM_RIGHT_PANE]->x,
446                         mwindow->theme->mcanvas_y +
447                                 mwindow->theme->mcanvas_h -
448                                 pane[BOTTOM_RIGHT_PANE]->y);
449         }
450
451         update_pane_dividers();
452         pane_button->reposition_window(w - mwindow->theme->get_image_set("pane")[0]->get_w(),
453                 mwindow->theme->mzoom_y + 1 - mwindow->theme->get_image_set("pane")[0]->get_h());
454         resource_thread->start_draw();
455
456         flash(1);
457         return 0;
458 }
459
460 int MWindowGUI::total_panes()
461 {
462         int total = 0;
463         for(int i = 0; i < TOTAL_PANES; i++)
464                 if(pane[i]) total++;
465         return total;
466 }
467
468 int MWindowGUI::vertical_panes()
469 {
470         return total_panes() == 2 &&
471                 pane[TOP_LEFT_PANE] &&
472                 pane[BOTTOM_LEFT_PANE];
473 }
474
475 int MWindowGUI::horizontal_panes()
476 {
477         return total_panes() == 2 &&
478                 pane[TOP_LEFT_PANE] &&
479                 pane[TOP_RIGHT_PANE];
480 }
481
482 TimelinePane* MWindowGUI::get_focused_pane()
483 {
484         if(pane[focused_pane]) return pane[focused_pane];
485         for(int i = 0; i < TOTAL_PANES; i++)
486         {
487                 if(pane[i]) return pane[i];
488         }
489         return 0;
490 }
491
492 void MWindowGUI::activate_timeline()
493 {
494         if(pane[focused_pane])
495         {
496                 pane[focused_pane]->activate();
497         }
498         else
499         {
500                 for(int i = 0; i < TOTAL_PANES; i++)
501                 {
502                         if(pane[i])
503                         {
504                                 pane[i]->activate();
505                                 return;
506                         }
507                 }
508         }
509 }
510
511 void MWindowGUI::deactivate_timeline()
512 {
513         for(int i = 0; i < TOTAL_PANES; i++)
514         {
515                 if(pane[i] && pane[i]->canvas)
516                 {
517                         pane[i]->canvas->deactivate();
518                 }
519         }
520 }
521
522 void MWindowGUI::update_title(char *path)
523 {
524         FileSystem fs;
525         char filename[BCTEXTLEN], string[BCTEXTLEN];
526         fs.extract_name(filename, path);
527         sprintf(string, _(PROGRAM_NAME ": %s"), filename);
528         set_title(string);
529 //printf("MWindowGUI::update_title %s\n", string);
530         flush();
531 }
532
533 void MWindowGUI::draw_overlays(int flash_it)
534 {
535         for(int i = 0; i < TOTAL_PANES; i++)
536         {
537                 if(pane[i] && pane[i]->canvas)
538                 {
539                         pane[i]->canvas->draw_overlays();
540                         if(flash_it) pane[i]->canvas->flash();
541                 }
542         }
543 }
544
545 void MWindowGUI::update_timebar(int flush_it)
546 {
547         for(int i = 0; i < TOTAL_PANES; i++)
548         {
549                 if(pane[i] && pane[i]->timebar)
550                 {
551                         pane[i]->timebar->update(flush_it);
552                 }
553         }
554 }
555
556 void MWindowGUI::update_timebar_highlights()
557 {
558         for(int i = 0; i < TOTAL_PANES; i++)
559         {
560                 if(pane[i] && pane[i]->timebar)
561                 {
562                         pane[i]->timebar->update_highlights();
563                 }
564         }
565 }
566
567
568 void MWindowGUI::update_patchbay()
569 {
570         for(int i = 0; i < TOTAL_PANES; i++)
571         {
572                 if(pane[i] && pane[i]->patchbay)
573                 {
574                         pane[i]->patchbay->update();
575                 }
576         }
577 }
578
579 void MWindowGUI::update_proxy_toggle()
580 {
581         int value = mwindow->edl->session->proxy_scale == 1 ? 1 : 0;
582         proxy_toggle->set_value(value);
583         if( mwindow->edl->session->proxy_scale == 1 &&
584             mwindow->edl->session->proxy_disabled_scale == 1 )
585                 proxy_toggle->hide();
586         else
587                 proxy_toggle->show();
588 }
589
590 void MWindowGUI::update_plugintoggles()
591 {
592         for(int i = 0; i < TOTAL_PANES; i++)
593         {
594                 if(pane[i] && 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 }
1046
1047
1048 int MWindowGUI::repeat_event(int64_t duration)
1049 {
1050 // if(duration == 100)
1051 // mwindow->sync_parameters(CHANGE_ALL);
1052         int result = 0;
1053         for(int i = 0; i < TOTAL_PANES; i++)
1054         {
1055                 if(pane[i] && pane[i]->cursor)
1056                         result = pane[i]->cursor->repeat_event(duration);
1057         }
1058         return result;
1059 }
1060
1061
1062 int MWindowGUI::translation_event()
1063 {
1064 //printf("MWindowGUI::translation_event 1 %d %d\n", get_x(), get_y());
1065         mwindow->session->mwindow_x = get_x();
1066         mwindow->session->mwindow_y = get_y();
1067         return 0;
1068 }
1069
1070
1071 int MWindowGUI::save_defaults(BC_Hash *defaults)
1072 {
1073         defaults->update("MWINDOWWIDTH", get_w());
1074         defaults->update("MWINDOWHEIGHT", get_h());
1075         mainmenu->save_defaults(defaults);
1076         BC_WindowBase::save_defaults(defaults);
1077         return 0;
1078 }
1079
1080 int MWindowGUI::keypress_event()
1081 {
1082 //printf("MWindowGUI::keypress_event 1 %d\n", get_keypress());
1083         int result = mbuttons->keypress_event();
1084         if( result ) return result;
1085
1086         Track *this_track = 0, *first_track = 0;
1087         int packed = 0, overwrite = 0, plugins = 0;
1088         double position = 0;
1089
1090         switch( get_keypress() ) {
1091         case 'A':
1092                 if( !alt_down() && ctrl_down() ) {
1093                         mwindow->edl->tracks->clear_selected_edits();
1094                         draw_overlays(1);
1095                         result = 1;
1096                 }
1097                 break;
1098         case 'a':
1099                 if( !ctrl_down() && alt_down() ) {
1100                         stop_transport("MWindowGUI::keypress_event 1");
1101                         mwindow->nearest_auto_keyframe(shift_down(),
1102                                 !ctrl_down() ? PLAY_FORWARD : PLAY_REVERSE);
1103                         result = 1;
1104                 }
1105                 else if( ctrl_down() && alt_down() ) {
1106                         mwindow->select_edits(1);
1107                         result = 1;
1108                 }
1109                 break;
1110
1111         case 'e':
1112                 if( ctrl_down() || alt_down() ) break;
1113                 mwindow->toggle_editing_mode();
1114                 result = 1;
1115                 break;
1116
1117         case 'k': case 'K':
1118                 if( alt_down() ) break;
1119                 stop_transport("MWindowGUI::keypress_event 2");
1120                 mwindow->nearest_plugin_keyframe(shift_down(),
1121                         !ctrl_down() ? PLAY_FORWARD : PLAY_REVERSE);
1122                 result = 1;
1123                 break;
1124
1125         case 'C':
1126                 packed = 1;
1127         case 'c':
1128                 if( !ctrl_down() || alt_down() ) break;
1129                 mwindow->selected_edits_to_clipboard(packed);
1130                 result = 1;
1131                 break;
1132         case 'P':
1133                 plugins = 1;
1134         case 'b':
1135                 overwrite = -1; // fall thru
1136         case 'v':
1137                 if( !ctrl_down() || alt_down() ) break;
1138                 if( mwindow->session->current_operation == DROP_TARGETING ) {
1139                         mwindow->session->current_operation = NO_OPERATION;
1140                         mwindow->gui->set_editing_mode(1);
1141                         int pane_no = 0;
1142                         for( ; pane_no<TOTAL_PANES; ++pane_no  ) {
1143                                 if( !pane[pane_no] ) continue;
1144                                 first_track = pane[pane_no]->over_track();
1145                                 if( first_track ) break;
1146                         }
1147                         if( first_track ) {
1148                                 int cursor_x = pane[pane_no]->canvas->get_relative_cursor_x();
1149                                 position = mwindow->edl->get_cursor_position(cursor_x, pane_no);
1150                         }
1151                 }
1152                 else
1153                         position = mwindow->edl->local_session->get_selectionstart();
1154                 if( !plugins )
1155                         mwindow->paste(position, first_track, 0, overwrite);
1156                 else
1157                         mwindow->paste_clipboard(first_track, position, 1, 0, 1, 1, 1);
1158                 mwindow->edl->tracks->clear_selected_edits();
1159                 draw_overlays(1);
1160                 result = 1;
1161                 break;
1162         case 'M':
1163                 mwindow->cut_selected_edits(0, 1);
1164                 result = 1;
1165                 break;
1166         case BACKSPACE:
1167         case 'm':
1168                 mwindow->cut_selected_edits(0, 0);
1169                 result = 1;
1170                 break;
1171         case 'z':
1172                 if( !alt_down() ) {
1173                         // z and ctrl-z both are undo, z mainmenu item
1174                         if( mwindow->session->current_operation == NO_OPERATION )
1175                                 mwindow->undo_entry(this);
1176                         result = 1;
1177                 }
1178                 else if( ctrl_down() ) {
1179                         mwindow->cut_selected_edits(1, 1);
1180                         result = 1;
1181                 }
1182                 break;
1183         case 'x':
1184                 if( !ctrl_down() || alt_down() ) break;
1185                 mwindow->cut_selected_edits(1, 0);
1186                 result = 1;
1187                 break;
1188
1189         case '1' ... '8':
1190                 if( !alt_down() || shift_down() ) break;
1191                 if( !mwindow->select_asset(get_keypress()-'1',1) )
1192                         result = 1;
1193                 break;
1194
1195         case LEFT:
1196                 if( !ctrl_down() ) {
1197                         if( alt_down() ) {
1198                                 stop_transport("MWindowGUI::keypress_event 1");
1199                                 mwindow->prev_edit_handle(shift_down());
1200                         }
1201                         else
1202                                 mwindow->move_left();
1203                         result = 1;
1204                 }
1205                 break;
1206
1207         case ',':
1208                 if( !ctrl_down() && !alt_down() ) {
1209                         mwindow->move_left();
1210                         result = 1;
1211                 }
1212                 break;
1213
1214         case RIGHT:
1215                 if( !ctrl_down() ) {
1216                         if( alt_down() ) {
1217                                 stop_transport("MWindowGUI::keypress_event 2");
1218                                 mwindow->next_edit_handle(shift_down());
1219                         }
1220                         else
1221                                 mwindow->move_right();
1222                         result = 1;
1223                 }
1224                 break;
1225
1226         case '.':
1227                 if( !ctrl_down() && !alt_down() ) {
1228                         mwindow->move_right();
1229                         result = 1;
1230                 }
1231                 break;
1232
1233         case UP:
1234                 if( ctrl_down() && !alt_down() )
1235                         mwindow->expand_y();
1236                 else if( !ctrl_down() && alt_down() )
1237                         mwindow->expand_autos(0,1,1);
1238                 else if( ctrl_down() && alt_down() )
1239                         mwindow->expand_autos(1,1,1);
1240                 else
1241                         mwindow->expand_sample();
1242                 result = 1;
1243                 break;
1244
1245         case DOWN:
1246                 if( ctrl_down() && !alt_down() )
1247                         mwindow->zoom_in_y();
1248                 else if( !ctrl_down() && alt_down() )
1249                         mwindow->shrink_autos(0,1,1);
1250                 else if( ctrl_down() && alt_down() )
1251                         mwindow->shrink_autos(1,1,1);
1252                 else
1253                         mwindow->zoom_in_sample();
1254                 result = 1;
1255                 break;
1256
1257         case PGUP:
1258                 if( !ctrl_down() )
1259                         mwindow->move_up();
1260                 else
1261                         mwindow->expand_t();
1262                 result = 1;
1263                 break;
1264
1265         case PGDN:
1266                 if( !ctrl_down() )
1267                         mwindow->move_down();
1268                 else
1269                         mwindow->zoom_in_t();
1270                 result = 1;
1271                 break;
1272
1273         case TAB:
1274         case LEFTTAB:
1275                 for( int i=0; i<TOTAL_PANES; ++i ) {
1276                         if( !pane[i] ) continue;
1277                         if( (this_track = pane[i]->over_track()) != 0 ) break;
1278                         if( (this_track = pane[i]->over_patchbay()) != 0 ) break;
1279                 }
1280
1281                 if( get_keypress() == TAB ) { // Switch the armed button
1282                         if( this_track )
1283                                 this_track->armed = !this_track->armed ? 1 : 0;
1284                 }
1285                 else {
1286                         int total_selected = mwindow->edl->tracks->total_of(Tracks::RECORD);
1287                         // all selected if nothing previously selected or
1288                         // if this patch was previously the only one selected and armed
1289                         int selected = !total_selected || (total_selected == 1 &&
1290                                 this_track && this_track->armed ) ? 1 : 0;
1291                         mwindow->edl->tracks->select_all(Tracks::RECORD, selected);
1292                         if( !selected && this_track ) this_track->armed = 1;
1293                 }
1294
1295                 update(0, NORMAL_DRAW, 0, 0, 1, 0, 1);
1296                 unlock_window();
1297                 mwindow->cwindow->update(0, 1, 1);
1298                 lock_window("MWindowGUI::keypress_event 3");
1299
1300                 result = 1;
1301                 break;
1302
1303         case KEY_F1 ... KEY_F12:
1304                 resend_event(mwindow->cwindow->gui);
1305                 return 1;
1306         }
1307
1308 // since things under cursor have changed...
1309         if(result)
1310                 cursor_motion_event();
1311
1312         return result;
1313 }
1314
1315 int MWindowGUI::keyboard_listener(BC_WindowBase *wp)
1316 {
1317         return key_listener(wp->get_keypress());
1318 }
1319
1320 int MWindowGUI::key_listener(int key)
1321 {
1322         int result = 1;
1323         switch( key ) {
1324         case KPTV:
1325                 if( !record->running() )
1326                         record->start();
1327                 else
1328                         record->record_gui->interrupt_thread->start(0);
1329                 break;
1330         case KPHAND:
1331                 mwindow->quit();
1332                 break;
1333 #ifdef HAVE_DVB
1334         case KPBOOK:
1335                 channel_info->toggle_scan();
1336                 break;
1337 #endif
1338         case KPMENU:
1339                 if( !remote_control->deactivate() )
1340                         remote_control->activate();
1341                 break;
1342         default:
1343                 result = 0;
1344                 break;
1345         }
1346         return result;
1347 }
1348
1349
1350 void MWindowGUI::use_android_remote(int on)
1351 {
1352         if( !on ) {
1353                 delete android_control;
1354                 android_control = 0;
1355                 return;
1356         }
1357         if( android_control ) return;
1358         android_control = new AndroidControl(this);
1359 }
1360 int MWindowGUI::keyev_grab_remote()
1361 {
1362         if( cwindow_remote_handler && cwindow_remote_handler->is_keytv() &&
1363             record_remote_handler  && record_remote_handler->is_keytv() )
1364                 return 0;
1365         delete cwindow_remote_handler;
1366         delete record_remote_handler;
1367         cwindow_remote_handler = (RemoteHandler*)
1368                 new CWindowKeyEvHandler(mwindow->gui->remote_control);
1369         record_remote_handler = (RemoteHandler*)
1370                 new RecordKeyEvHandler(mwindow->gui->remote_control);
1371         return 1;
1372 }
1373
1374 int MWindowGUI::close_event()
1375 {
1376         mainmenu->quit();
1377         return 0;
1378 }
1379
1380 void MWindowGUI::stop_drawing()
1381 {
1382         resource_thread->stop_draw(1);
1383 }
1384
1385 int MWindowGUI::menu_w()
1386 {
1387         return mainmenu->get_w();
1388 }
1389
1390 int MWindowGUI::menu_h()
1391 {
1392         return mainmenu->get_h();
1393 }
1394
1395 void MWindowGUI::start_x_pane_drag()
1396 {
1397         if(!x_pane_drag)
1398         {
1399                 x_pane_drag = new BC_Popup(this,
1400                         get_abs_cursor_x(0) - mwindow->theme->pane_w,
1401                         BC_DisplayInfo::get_top_border() +
1402                                 get_y() +
1403                                 mwindow->theme->mcanvas_y,
1404                         mwindow->theme->pane_w,
1405                         mwindow->theme->mcanvas_h,
1406                         mwindow->theme->drag_pane_color);
1407                 x_pane_drag->draw_3segmentv(0,
1408                         0,
1409                         x_pane_drag->get_h(),
1410                         mwindow->theme->get_image_set("xpane")[BUTTON_DOWNHI]);
1411                 x_pane_drag->flash(1);
1412         }
1413         dragging_pane = 1;
1414 }
1415
1416 void MWindowGUI::start_y_pane_drag()
1417 {
1418         if(!y_pane_drag)
1419         {
1420 //printf("MWindowGUI::start_y_pane_drag %d %d %d\n", __LINE__, get_x(), get_y());
1421                 y_pane_drag = new BC_Popup(this,
1422                         BC_DisplayInfo::get_left_border() +
1423                                 get_x() +
1424                                 mwindow->theme->mcanvas_x,
1425                         get_abs_cursor_y(0) - mwindow->theme->pane_h,
1426                         mwindow->theme->mcanvas_w,
1427                         mwindow->theme->pane_h,
1428                         mwindow->theme->drag_pane_color);
1429                 y_pane_drag->draw_3segmenth(0,
1430                         0,
1431                         y_pane_drag->get_w(),
1432                         mwindow->theme->get_image_set("ypane")[BUTTON_DOWNHI]);
1433                 y_pane_drag->flash(1);
1434         }
1435         dragging_pane = 1;
1436 }
1437
1438 void MWindowGUI::handle_pane_drag()
1439 {
1440         if(dragging_pane)
1441         {
1442                 if(x_pane_drag)
1443                 {
1444                         x_pane_drag->reposition_window(
1445                                 get_abs_cursor_x(0) - mwindow->theme->pane_w,
1446                                 x_pane_drag->get_y());
1447                 }
1448
1449                 if(y_pane_drag)
1450                 {
1451                         y_pane_drag->reposition_window(
1452                                 y_pane_drag->get_x(),
1453                                 get_abs_cursor_y(0) - mwindow->theme->pane_h);
1454                 }
1455         }
1456 }
1457
1458
1459 void MWindowGUI::create_x_pane(int cursor_x)
1460 {
1461         if(total_panes() == 1)
1462         {
1463 // create a horizontal pane
1464 // do this 1st so the resize_event knows there are 2 panes
1465                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] =
1466                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] +
1467                         cursor_x -
1468                         mwindow->theme->patchbay_w;
1469                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1470                         TOP_RIGHT_PANE,
1471                         mwindow->theme->mcanvas_x +
1472                                 cursor_x,
1473                         mwindow->theme->mcanvas_y,
1474                         mwindow->theme->mcanvas_x +
1475                                 mwindow->theme->mcanvas_w -
1476                                 cursor_x,
1477                         mwindow->theme->mcanvas_h);
1478                 pane[TOP_LEFT_PANE]->resize_event(
1479                         mwindow->theme->mcanvas_x,
1480                         mwindow->theme->mcanvas_y,
1481                         cursor_x - mwindow->theme->pane_w,
1482                         mwindow->theme->mcanvas_h);
1483                 pane[TOP_RIGHT_PANE]->create_objects();
1484         }
1485         else
1486         if(vertical_panes())
1487         {
1488 // create 2 horizontal panes
1489                 mwindow->edl->local_session->track_start[TOP_RIGHT_PANE] =
1490                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE];
1491                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1492                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE];
1493                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] =
1494                         mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1495                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] +
1496                         cursor_x -
1497                         mwindow->theme->patchbay_w;
1498                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1499                         TOP_RIGHT_PANE,
1500                         mwindow->theme->mcanvas_x +
1501                                 cursor_x,
1502                         pane[TOP_LEFT_PANE]->y,
1503                         mwindow->theme->mcanvas_x +
1504                                 mwindow->theme->mcanvas_w -
1505                                 cursor_x,
1506                         pane[TOP_LEFT_PANE]->h);
1507                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1508                         BOTTOM_RIGHT_PANE,
1509                         mwindow->theme->mcanvas_x +
1510                                 cursor_x,
1511                         pane[BOTTOM_LEFT_PANE]->y,
1512                         mwindow->theme->mcanvas_x +
1513                                 mwindow->theme->mcanvas_w -
1514                                 cursor_x,
1515                         pane[BOTTOM_LEFT_PANE]->h);
1516                 pane[TOP_LEFT_PANE]->resize_event(
1517                         pane[TOP_LEFT_PANE]->x,
1518                         pane[TOP_LEFT_PANE]->y,
1519                         cursor_x - mwindow->theme->pane_w,
1520                         pane[TOP_LEFT_PANE]->h);
1521                 pane[BOTTOM_LEFT_PANE]->resize_event(
1522                         pane[BOTTOM_LEFT_PANE]->x,
1523                         pane[BOTTOM_LEFT_PANE]->y,
1524                         cursor_x - mwindow->theme->pane_w,
1525                         pane[BOTTOM_LEFT_PANE]->h);
1526                 pane[TOP_RIGHT_PANE]->create_objects();
1527                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1528         }
1529         else
1530         if(horizontal_panes())
1531         {
1532 // resize a horizontal pane
1533                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] +=
1534                         cursor_x -
1535                         pane[TOP_RIGHT_PANE]->x;
1536                 if(mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] < 0)
1537                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] = 0;
1538                 pane[TOP_LEFT_PANE]->resize_event(
1539                         mwindow->theme->mcanvas_x,
1540                         mwindow->theme->mcanvas_y,
1541                         cursor_x - mwindow->theme->pane_w,
1542                         mwindow->theme->mcanvas_h);
1543                 pane[TOP_RIGHT_PANE]->resize_event(
1544                         mwindow->theme->mcanvas_x +
1545                                 cursor_x,
1546                         pane[TOP_RIGHT_PANE]->y,
1547                         mwindow->theme->mcanvas_x +
1548                                 mwindow->theme->mcanvas_w -
1549                                 cursor_x,
1550                         mwindow->theme->mcanvas_h);
1551         }
1552         else
1553         {
1554 // resize 2 horizontal panes
1555                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] +=
1556                         cursor_x -
1557                         pane[TOP_RIGHT_PANE]->x;
1558                 if(mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] < 0)
1559                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] = 0;
1560                 mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1561                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE];
1562
1563                 pane[TOP_LEFT_PANE]->resize_event(
1564                         mwindow->theme->mcanvas_x,
1565                         pane[TOP_LEFT_PANE]->y,
1566                         cursor_x - mwindow->theme->pane_w,
1567                         pane[TOP_LEFT_PANE]->h);
1568                 pane[TOP_RIGHT_PANE]->resize_event(
1569                         mwindow->theme->mcanvas_x +
1570                                 cursor_x,
1571                         pane[TOP_RIGHT_PANE]->y,
1572                         mwindow->theme->mcanvas_x +
1573                                 mwindow->theme->mcanvas_w -
1574                                 cursor_x,
1575                         pane[TOP_RIGHT_PANE]->h);
1576                 pane[BOTTOM_LEFT_PANE]->resize_event(
1577                         mwindow->theme->mcanvas_x,
1578                         pane[BOTTOM_LEFT_PANE]->y,
1579                         cursor_x - mwindow->theme->pane_w,
1580                         pane[BOTTOM_LEFT_PANE]->h);
1581                 pane[BOTTOM_RIGHT_PANE]->resize_event(
1582                         mwindow->theme->mcanvas_x +
1583                                 cursor_x,
1584                         pane[BOTTOM_RIGHT_PANE]->y,
1585                         mwindow->theme->mcanvas_x +
1586                                 mwindow->theme->mcanvas_w -
1587                                 cursor_x,
1588                         pane[BOTTOM_RIGHT_PANE]->h);
1589
1590         }
1591 }
1592
1593
1594 void MWindowGUI::delete_x_pane(int cursor_x)
1595 {
1596 // give left panes coordinates of right pane
1597         if(cursor_x < mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1598                 pane[TOP_RIGHT_PANE])
1599         {
1600                 mwindow->edl->local_session->view_start[TOP_LEFT_PANE] =
1601                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] -
1602                         pane[TOP_RIGHT_PANE]->x + mwindow->theme->patchbay_w;
1603                 if(mwindow->edl->local_session->view_start[TOP_LEFT_PANE] < 0)
1604                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] = 0;
1605                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1606                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1607         }
1608
1609         switch(total_panes())
1610         {
1611                 case 2:
1612                         if(pane[TOP_LEFT_PANE] && pane[TOP_RIGHT_PANE])
1613                         {
1614 // delete right pane
1615                                 delete pane[TOP_RIGHT_PANE];
1616                                 pane[TOP_RIGHT_PANE] = 0;
1617                                 pane[TOP_LEFT_PANE]->resize_event(
1618                                         mwindow->theme->mcanvas_x,
1619                                         mwindow->theme->mcanvas_y,
1620                                         mwindow->theme->mcanvas_w,
1621                                         mwindow->theme->mcanvas_h);
1622
1623                         }
1624                         break;
1625
1626                 case 4:
1627 // delete right panes
1628                         delete pane[TOP_RIGHT_PANE];
1629                         pane[TOP_RIGHT_PANE] = 0;
1630                         delete pane[BOTTOM_RIGHT_PANE];
1631                         pane[BOTTOM_RIGHT_PANE] = 0;
1632                         pane[TOP_LEFT_PANE]->resize_event(
1633                                 mwindow->theme->mcanvas_x,
1634                                 pane[TOP_LEFT_PANE]->y,
1635                                 mwindow->theme->mcanvas_w,
1636                                 pane[TOP_LEFT_PANE]->h);
1637                         pane[BOTTOM_LEFT_PANE]->resize_event(
1638                                 mwindow->theme->mcanvas_x,
1639                                 pane[BOTTOM_LEFT_PANE]->y,
1640                                 mwindow->theme->mcanvas_w,
1641                                 pane[BOTTOM_LEFT_PANE]->h);
1642                         break;
1643         }
1644 }
1645
1646 void MWindowGUI::create_y_pane(int cursor_y)
1647 {
1648         if(total_panes() == 1)
1649         {
1650                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1651                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1652                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] =
1653                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] +
1654                         cursor_y -
1655                         mwindow->theme->mtimebar_h;
1656 // do this 1st so the resize_event knows there are 2 panes
1657                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1658                         BOTTOM_LEFT_PANE,
1659                         mwindow->theme->mcanvas_x,
1660                         mwindow->theme->mcanvas_y +
1661                                 cursor_y,
1662                         mwindow->theme->mcanvas_w,
1663                         mwindow->theme->mcanvas_h -
1664                                 cursor_y);
1665                 pane[TOP_LEFT_PANE]->resize_event(
1666                         mwindow->theme->mcanvas_x,
1667                         mwindow->theme->mcanvas_y,
1668                         mwindow->theme->mcanvas_w,
1669                         pane[BOTTOM_LEFT_PANE]->y -
1670                                 mwindow->theme->mcanvas_y -
1671                                 mwindow->theme->pane_h);
1672                 pane[BOTTOM_LEFT_PANE]->create_objects();
1673         }
1674         else
1675         if(horizontal_panes())
1676         {
1677 // create 2 panes
1678                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1679                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1680                 mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1681                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE];
1682                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] =
1683                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1684                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] +
1685                         cursor_y -
1686                         mwindow->theme->mtimebar_h;
1687
1688                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1689                         BOTTOM_LEFT_PANE,
1690                         pane[TOP_LEFT_PANE]->x,
1691                         mwindow->theme->mcanvas_y +
1692                                 cursor_y,
1693                         pane[TOP_LEFT_PANE]->w,
1694                         mwindow->theme->mcanvas_h -
1695                                 cursor_y);
1696                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1697                         BOTTOM_RIGHT_PANE,
1698                         pane[TOP_RIGHT_PANE]->x,
1699                         mwindow->theme->mcanvas_y +
1700                                 cursor_y,
1701                         pane[TOP_RIGHT_PANE]->w,
1702                         mwindow->theme->mcanvas_h -
1703                                 cursor_y);
1704
1705                 pane[TOP_LEFT_PANE]->resize_event(
1706                         pane[TOP_LEFT_PANE]->x,
1707                         pane[TOP_LEFT_PANE]->y,
1708                         pane[TOP_LEFT_PANE]->w,
1709                         pane[BOTTOM_LEFT_PANE]->y -
1710                                 mwindow->theme->mcanvas_y -
1711                                 mwindow->theme->pane_h);
1712                 pane[TOP_RIGHT_PANE]->resize_event(
1713                         pane[TOP_RIGHT_PANE]->x,
1714                         pane[TOP_RIGHT_PANE]->y,
1715                         pane[TOP_RIGHT_PANE]->w,
1716                         pane[BOTTOM_RIGHT_PANE]->y -
1717                                 mwindow->theme->mcanvas_y -
1718                                 mwindow->theme->pane_h);
1719
1720                 pane[BOTTOM_LEFT_PANE]->create_objects();
1721                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1722         }
1723         else
1724         if(vertical_panes())
1725         {
1726 // resize a pane
1727                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] +=
1728                         cursor_y -
1729                         (pane[BOTTOM_LEFT_PANE]->y - mwindow->theme->mcanvas_y);
1730                 if(mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] < 0)
1731                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] = 0;
1732                 pane[TOP_LEFT_PANE]->resize_event(
1733                         mwindow->theme->mcanvas_x,
1734                         mwindow->theme->mcanvas_y,
1735                         mwindow->theme->mcanvas_w,
1736                         cursor_y - mwindow->theme->pane_h);
1737                 pane[BOTTOM_LEFT_PANE]->resize_event(
1738                         pane[BOTTOM_LEFT_PANE]->x,
1739                         cursor_y +
1740                                 mwindow->theme->mcanvas_y,
1741                         mwindow->theme->mcanvas_w,
1742                         mwindow->theme->mcanvas_h -
1743                                 cursor_y);
1744         }
1745         else
1746         {
1747 // resize 2 panes
1748                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] +=
1749                         cursor_y -
1750                         (pane[BOTTOM_LEFT_PANE]->y - mwindow->theme->mcanvas_y);
1751                 if(mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] < 0)
1752                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] = 0;
1753                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1754                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE];
1755                 pane[TOP_LEFT_PANE]->resize_event(
1756                         pane[TOP_LEFT_PANE]->x,
1757                         pane[TOP_LEFT_PANE]->y,
1758                         pane[TOP_LEFT_PANE]->w,
1759                         cursor_y - mwindow->theme->pane_h);
1760                 pane[BOTTOM_LEFT_PANE]->resize_event(
1761                         pane[BOTTOM_LEFT_PANE]->x,
1762                         cursor_y +
1763                                 mwindow->theme->mcanvas_y,
1764                         pane[BOTTOM_LEFT_PANE]->w,
1765                         mwindow->theme->mcanvas_h -
1766                                         cursor_y);
1767                 pane[TOP_RIGHT_PANE]->resize_event(
1768                         pane[TOP_RIGHT_PANE]->x,
1769                         pane[TOP_RIGHT_PANE]->y,
1770                         pane[TOP_RIGHT_PANE]->w,
1771                         cursor_y - mwindow->theme->pane_h);
1772                 pane[BOTTOM_RIGHT_PANE]->resize_event(
1773                         pane[BOTTOM_RIGHT_PANE]->x,
1774                         cursor_y +
1775                                 mwindow->theme->mcanvas_y,
1776                         pane[BOTTOM_RIGHT_PANE]->w,
1777                         mwindow->theme->mcanvas_h -
1778                                         cursor_y);
1779         }
1780 }
1781
1782 void MWindowGUI::delete_y_pane(int cursor_y)
1783 {
1784         if(cursor_y < mwindow->theme->mtimebar_h +
1785                 PANE_DRAG_MARGIN &&
1786                 pane[BOTTOM_LEFT_PANE])
1787         {
1788 // give top pane coordinates of bottom pane
1789                 mwindow->edl->local_session->track_start[TOP_LEFT_PANE] =
1790                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] -
1791                         pane[BOTTOM_LEFT_PANE]->y;
1792                 if(mwindow->edl->local_session->track_start[TOP_LEFT_PANE] < 0)
1793                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] = 0;
1794                 mwindow->edl->local_session->track_start[TOP_RIGHT_PANE] =
1795                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE];
1796         }
1797
1798 // delete a pane
1799         switch(total_panes())
1800         {
1801                 case 2:
1802                         delete pane[BOTTOM_LEFT_PANE];
1803                         pane[BOTTOM_LEFT_PANE] = 0;
1804                         pane[TOP_LEFT_PANE]->resize_event(
1805                                 mwindow->theme->mcanvas_x,
1806                                 mwindow->theme->mcanvas_y,
1807                                 mwindow->theme->mcanvas_w,
1808                                 mwindow->theme->mcanvas_h);
1809                         break;
1810
1811                 case 4:
1812 // delete bottom 2 panes
1813
1814                         delete pane[BOTTOM_LEFT_PANE];
1815                         pane[BOTTOM_LEFT_PANE] = 0;
1816                         delete pane[BOTTOM_RIGHT_PANE];
1817                         pane[BOTTOM_RIGHT_PANE] = 0;
1818                         pane[TOP_LEFT_PANE]->resize_event(
1819                                 pane[TOP_LEFT_PANE]->x,
1820                                 mwindow->theme->mcanvas_y,
1821                                 pane[TOP_LEFT_PANE]->w,
1822                                 mwindow->theme->mcanvas_h);
1823                         pane[TOP_RIGHT_PANE]->resize_event(
1824                                 pane[TOP_RIGHT_PANE]->x,
1825                                 mwindow->theme->mcanvas_y,
1826                                 pane[TOP_RIGHT_PANE]->w,
1827                                 mwindow->theme->mcanvas_h);
1828                         break;
1829         }
1830 }
1831
1832 void MWindowGUI::stop_pane_drag()
1833 {
1834         if( !dragging_pane ) return;
1835         dragging_pane = 0;
1836         resource_thread->stop_draw(0);
1837
1838         if(x_pane_drag)
1839         {
1840 // cursor position relative to canvas
1841                 int cursor_x = x_pane_drag->get_x() -
1842                         get_x() -
1843                         BC_DisplayInfo::get_left_border() -
1844                         mwindow->theme->mcanvas_x +
1845                         mwindow->theme->pane_w;
1846                 delete x_pane_drag;
1847                 x_pane_drag = 0;
1848
1849
1850                 if(cursor_x >= mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1851                         cursor_x < mwindow->theme->mcanvas_w -
1852                                 BC_ScrollBar::get_span(SCROLL_VERT) -
1853                                 PANE_DRAG_MARGIN)
1854                 {
1855                         create_x_pane(cursor_x);
1856                         mwindow->edl->local_session->x_pane = cursor_x;
1857                 }
1858                 else
1859 // deleted a pane
1860                 {
1861                         delete_x_pane(cursor_x);
1862                         mwindow->edl->local_session->x_pane = -1;
1863                 }
1864
1865
1866         }
1867
1868         if(y_pane_drag)
1869         {
1870 // cursor position relative to canvas
1871                 int cursor_y = y_pane_drag->get_y() -
1872                         get_y() -
1873                         BC_DisplayInfo::get_top_border() -
1874                         mwindow->theme->mcanvas_y +
1875                         mwindow->theme->pane_h;
1876                 delete y_pane_drag;
1877                 y_pane_drag = 0;
1878
1879
1880
1881                 if(cursor_y >= mwindow->theme->mtimebar_h +
1882                                 PANE_DRAG_MARGIN &&
1883                         cursor_y < mwindow->theme->mcanvas_h -
1884                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
1885                                 PANE_DRAG_MARGIN)
1886                 {
1887                         create_y_pane(cursor_y);
1888                         mwindow->edl->local_session->y_pane = cursor_y;
1889                 }
1890                 else
1891                 {
1892                         delete_y_pane(cursor_y);
1893                         mwindow->edl->local_session->y_pane = -1;
1894                 }
1895         }
1896
1897         update_pane_dividers();
1898         update_cursor();
1899 // required to get new widgets to appear
1900         show_window();
1901         resource_thread->start_draw();
1902 }
1903
1904 // create panes from EDL
1905 void MWindowGUI::load_panes()
1906 {
1907         int need_x_panes = 0;
1908         int need_y_panes = 0;
1909 // use names from create functions
1910         int cursor_x = mwindow->edl->local_session->x_pane;
1911         int cursor_y = mwindow->edl->local_session->y_pane;
1912
1913         resource_thread->stop_draw(1);
1914         if(cursor_x >=
1915                 mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1916                 cursor_x <
1917                 mwindow->theme->mcanvas_w -
1918                                 BC_ScrollBar::get_span(SCROLL_VERT) -
1919                                 PANE_DRAG_MARGIN)
1920         {
1921                 need_x_panes = 1;
1922         }
1923
1924         if(cursor_y >=
1925                 mwindow->theme->mtimebar_h + PANE_DRAG_MARGIN &&
1926                 cursor_y <
1927                 mwindow->theme->mcanvas_h -
1928                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
1929                                 PANE_DRAG_MARGIN)
1930         {
1931                 need_y_panes = 1;
1932         }
1933
1934 //printf("MWindowGUI::load_panes %d %d %d\n", __LINE__, need_x_panes, need_y_panes);
1935
1936
1937         if(need_x_panes)
1938         {
1939                 if(need_y_panes)
1940                 {
1941 // 4 panes
1942                         if(total_panes() == 1)
1943                         {
1944 // create 4 panes
1945 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1946                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1947                                         TOP_RIGHT_PANE,
1948                                         mwindow->theme->mcanvas_x +
1949                                                 cursor_x,
1950                                         mwindow->theme->mcanvas_y,
1951                                         mwindow->theme->mcanvas_x +
1952                                                 mwindow->theme->mcanvas_w -
1953                                                 cursor_x,
1954                                         cursor_y - mwindow->theme->pane_h);
1955                                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1956                                         BOTTOM_LEFT_PANE,
1957                                         mwindow->theme->mcanvas_x,
1958                                         mwindow->theme->mcanvas_y +
1959                                                 cursor_y,
1960                                         cursor_x - mwindow->theme->pane_w,
1961                                         mwindow->theme->mcanvas_h -
1962                                                 cursor_y);
1963                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1964                                         BOTTOM_RIGHT_PANE,
1965                                         pane[TOP_RIGHT_PANE]->x,
1966                                         mwindow->theme->mcanvas_y +
1967                                                 cursor_y,
1968                                         pane[TOP_RIGHT_PANE]->w,
1969                                         mwindow->theme->mcanvas_h -
1970                                                 cursor_y);
1971                                 pane[TOP_LEFT_PANE]->resize_event(
1972                                         pane[TOP_LEFT_PANE]->x,
1973                                         pane[TOP_LEFT_PANE]->y,
1974                                         cursor_x - mwindow->theme->pane_w,
1975                                         cursor_y - mwindow->theme->pane_h);
1976                                 pane[TOP_RIGHT_PANE]->create_objects();
1977                                 pane[BOTTOM_LEFT_PANE]->create_objects();
1978                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1979                         }
1980                         else
1981                         if(horizontal_panes())
1982                         {
1983 // create vertical panes
1984 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1985                                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1986                                         BOTTOM_LEFT_PANE,
1987                                         mwindow->theme->mcanvas_x,
1988                                         mwindow->theme->mcanvas_y +
1989                                                 cursor_y,
1990                                         cursor_x - mwindow->theme->pane_w,
1991                                         mwindow->theme->mcanvas_h -
1992                                                 cursor_y);
1993                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1994                                         BOTTOM_RIGHT_PANE,
1995                                         pane[TOP_RIGHT_PANE]->x,
1996                                         mwindow->theme->mcanvas_y +
1997                                                 cursor_y,
1998                                         pane[TOP_RIGHT_PANE]->w,
1999                                         mwindow->theme->mcanvas_h -
2000                                                 cursor_y);
2001                                 pane[TOP_LEFT_PANE]->resize_event(
2002                                         pane[TOP_LEFT_PANE]->x,
2003                                         pane[TOP_LEFT_PANE]->y,
2004                                         cursor_x - mwindow->theme->pane_w,
2005                                         cursor_y - mwindow->theme->pane_h);
2006                                 pane[TOP_RIGHT_PANE]->resize_event(
2007                                         mwindow->theme->mcanvas_x +
2008                                                 cursor_x,
2009                                         mwindow->theme->mcanvas_y,
2010                                         mwindow->theme->mcanvas_x +
2011                                                 mwindow->theme->mcanvas_w -
2012                                                 cursor_x,
2013                                         cursor_y - mwindow->theme->pane_h);
2014                                 pane[BOTTOM_LEFT_PANE]->create_objects();
2015                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
2016                         }
2017                         else
2018                         if(vertical_panes())
2019                         {
2020 // create horizontal panes
2021 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2022                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
2023                                         TOP_RIGHT_PANE,
2024                                         mwindow->theme->mcanvas_x +
2025                                                 cursor_x,
2026                                         mwindow->theme->mcanvas_y,
2027                                         mwindow->theme->mcanvas_x +
2028                                                 mwindow->theme->mcanvas_w -
2029                                                 cursor_x,
2030                                         cursor_y - mwindow->theme->pane_h);
2031                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
2032                                         BOTTOM_RIGHT_PANE,
2033                                         pane[TOP_RIGHT_PANE]->x,
2034                                         mwindow->theme->mcanvas_y +
2035                                                 cursor_y,
2036                                         pane[TOP_RIGHT_PANE]->w,
2037                                         mwindow->theme->mcanvas_h -
2038                                                 cursor_y);
2039                                 pane[TOP_LEFT_PANE]->resize_event(
2040                                         pane[TOP_LEFT_PANE]->x,
2041                                         pane[TOP_LEFT_PANE]->y,
2042                                         cursor_x - mwindow->theme->pane_w,
2043                                         cursor_y - mwindow->theme->pane_h);
2044                                 pane[BOTTOM_LEFT_PANE]->resize_event(
2045                                         pane[TOP_LEFT_PANE]->x,
2046                                         mwindow->theme->mcanvas_y +
2047                                                 cursor_y,
2048                                         mwindow->theme->mcanvas_x +
2049                                                 mwindow->theme->mcanvas_w -
2050                                                 cursor_x -  mwindow->theme->pane_w,
2051                                         mwindow->theme->mcanvas_h -
2052                                                 cursor_y);
2053                                 pane[TOP_RIGHT_PANE]->create_objects();
2054                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
2055
2056
2057                         }
2058                         else
2059                         {
2060 // resize all panes
2061 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2062                                 pane[TOP_LEFT_PANE]->resize_event(
2063                                         pane[TOP_LEFT_PANE]->x,
2064                                         pane[TOP_LEFT_PANE]->y,
2065                                         cursor_x - mwindow->theme->pane_w,
2066                                         cursor_y - mwindow->theme->pane_h);
2067                                 pane[TOP_RIGHT_PANE]->resize_event(
2068                                         mwindow->theme->mcanvas_x +
2069                                                 cursor_x,
2070                                         mwindow->theme->mcanvas_y,
2071                                         mwindow->theme->mcanvas_x +
2072                                                 mwindow->theme->mcanvas_w -
2073                                                 cursor_x,
2074                                         cursor_y - mwindow->theme->pane_h);
2075                                 pane[BOTTOM_LEFT_PANE]->resize_event(
2076                                         pane[TOP_LEFT_PANE]->x,
2077                                         mwindow->theme->mcanvas_y +
2078                                                 cursor_y,
2079                                         mwindow->theme->mcanvas_x +
2080                                                 mwindow->theme->mcanvas_w -
2081                                                 cursor_x - mwindow->theme->pane_w,
2082                                         mwindow->theme->mcanvas_h -
2083                                                 cursor_y);
2084                                 pane[BOTTOM_RIGHT_PANE]->resize_event(
2085                                         pane[TOP_RIGHT_PANE]->x,
2086                                         mwindow->theme->mcanvas_y +
2087                                                 cursor_y,
2088                                         pane[TOP_RIGHT_PANE]->w,
2089                                         mwindow->theme->mcanvas_h -
2090                                                 cursor_y);
2091
2092
2093                         }
2094                 }
2095                 else
2096                 {
2097 // 2 X panes
2098                         if(pane[BOTTOM_LEFT_PANE]) delete pane[BOTTOM_LEFT_PANE];
2099                         if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2100                         pane[BOTTOM_LEFT_PANE] = 0;
2101                         pane[BOTTOM_RIGHT_PANE] = 0;
2102
2103                         if(!pane[TOP_RIGHT_PANE])
2104                         {
2105                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
2106                                         TOP_RIGHT_PANE,
2107                                         mwindow->theme->mcanvas_x +
2108                                                 cursor_x,
2109                                         mwindow->theme->mcanvas_y,
2110                                         mwindow->theme->mcanvas_x +
2111                                                 mwindow->theme->mcanvas_w -
2112                                                 cursor_x,
2113                                         mwindow->theme->mcanvas_h);
2114                                 pane[TOP_LEFT_PANE]->resize_event(
2115                                         mwindow->theme->mcanvas_x,
2116                                         mwindow->theme->mcanvas_y,
2117                                         cursor_x - mwindow->theme->pane_w,
2118                                         mwindow->theme->mcanvas_h);
2119                                 pane[TOP_RIGHT_PANE]->create_objects();
2120                         }
2121                         else
2122                         {
2123                                 pane[TOP_LEFT_PANE]->resize_event(
2124                                         mwindow->theme->mcanvas_x,
2125                                         mwindow->theme->mcanvas_y,
2126                                         cursor_x - mwindow->theme->pane_w,
2127                                         mwindow->theme->mcanvas_h);
2128                                 pane[TOP_RIGHT_PANE]->resize_event(
2129                                         mwindow->theme->mcanvas_x +
2130                                                 cursor_x,
2131                                         pane[TOP_RIGHT_PANE]->y,
2132                                         mwindow->theme->mcanvas_x +
2133                                                 mwindow->theme->mcanvas_w -
2134                                                 cursor_x,
2135                                         mwindow->theme->mcanvas_h);
2136                         }
2137                 }
2138         }
2139         else
2140         if(need_y_panes)
2141         {
2142 // 2 Y panes
2143                 if(pane[TOP_RIGHT_PANE]) delete pane[TOP_RIGHT_PANE];
2144                 if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2145                 pane[TOP_RIGHT_PANE] = 0;
2146                 pane[BOTTOM_RIGHT_PANE] = 0;
2147
2148                 if(!pane[BOTTOM_LEFT_PANE])
2149                 {
2150 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2151                         pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
2152                                 BOTTOM_LEFT_PANE,
2153                                 mwindow->theme->mcanvas_x,
2154                                 mwindow->theme->mcanvas_y +
2155                                         cursor_y,
2156                                 mwindow->theme->mcanvas_w,
2157                                 mwindow->theme->mcanvas_h -
2158                                         cursor_y);
2159                         pane[TOP_LEFT_PANE]->resize_event(
2160                                 mwindow->theme->mcanvas_x,
2161                                 mwindow->theme->mcanvas_y,
2162                                 mwindow->theme->mcanvas_w,
2163                                 pane[BOTTOM_LEFT_PANE]->y -
2164                                         mwindow->theme->mcanvas_y -
2165                                         mwindow->theme->pane_h);
2166                         pane[BOTTOM_LEFT_PANE]->create_objects();
2167                 }
2168                 else
2169                 {
2170                         pane[TOP_LEFT_PANE]->resize_event(
2171                                 mwindow->theme->mcanvas_x,
2172                                 mwindow->theme->mcanvas_y,
2173                                 mwindow->theme->mcanvas_w,
2174                                 cursor_y - mwindow->theme->pane_h);
2175                         pane[BOTTOM_LEFT_PANE]->resize_event(
2176                                 pane[BOTTOM_LEFT_PANE]->x,
2177                                 cursor_y +
2178                                         mwindow->theme->mcanvas_y,
2179                                 mwindow->theme->mcanvas_w,
2180                                 mwindow->theme->mcanvas_h -
2181                                         cursor_y);
2182                 }
2183         }
2184         else
2185         {
2186 // 1 pane
2187                 if(pane[TOP_RIGHT_PANE]) delete pane[TOP_RIGHT_PANE];
2188                 if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2189                 if(pane[BOTTOM_LEFT_PANE]) delete pane[BOTTOM_LEFT_PANE];
2190                 pane[TOP_RIGHT_PANE] = 0;
2191                 pane[BOTTOM_RIGHT_PANE] = 0;
2192                 pane[BOTTOM_LEFT_PANE] = 0;
2193                 pane[TOP_LEFT_PANE]->resize_event(
2194                         mwindow->theme->mcanvas_x,
2195                         mwindow->theme->mcanvas_y,
2196                         mwindow->theme->mcanvas_w,
2197                         mwindow->theme->mcanvas_h);
2198         }
2199
2200         update_pane_dividers();
2201         show_window();
2202
2203         resource_thread->start_draw();
2204 }
2205
2206 void MWindowGUI::update_pane_dividers()
2207 {
2208
2209         if(horizontal_panes() || total_panes() == 4)
2210         {
2211                 int x = pane[TOP_RIGHT_PANE]->x - mwindow->theme->pane_w;
2212                 int y = mwindow->theme->mcanvas_y;
2213                 int h = mwindow->theme->mcanvas_h;
2214
2215                 if(!x_divider)
2216                 {
2217                         add_subwindow(x_divider = new PaneDivider(
2218                                 mwindow, x, y, h, 1));
2219                         x_divider->create_objects();
2220                 }
2221                 else
2222                 {
2223                         x_divider->reposition_window(x, y, h);
2224                         x_divider->draw(0);
2225                 }
2226         }
2227         else
2228         {
2229                 if(x_divider)
2230                 {
2231                         delete x_divider;
2232                         x_divider = 0;
2233                 }
2234         }
2235
2236         if(vertical_panes() || total_panes() == 4)
2237         {
2238                 int x = mwindow->theme->mcanvas_x;
2239                 int y = pane[BOTTOM_LEFT_PANE]->y -
2240                         mwindow->theme->pane_h;
2241                 int w = mwindow->theme->mcanvas_w;
2242                 if(!y_divider)
2243                 {
2244                         add_subwindow(y_divider = new PaneDivider(
2245                                 mwindow, x, y, w, 0));
2246                         y_divider->create_objects();
2247                 }
2248                 else
2249                 {
2250                         y_divider->reposition_window(x, y, w);
2251                         y_divider->draw(0);
2252                 }
2253         }
2254         else
2255         {
2256                 if(y_divider)
2257                 {
2258                         delete y_divider;
2259                         y_divider = 0;
2260                 }
2261         }
2262 }
2263
2264 void MWindowGUI::draw_samplemovement()
2265 {
2266         draw_canvas(0, 1);
2267         show_cursor(1);
2268         flash_canvas(0);
2269         update_timebar(0);
2270         zoombar->update();
2271         update_scrollbars(1);
2272 }
2273
2274 void MWindowGUI::draw_trackmovement()
2275 {
2276         update_scrollbars(0);
2277         draw_canvas(0, 0);
2278         update_patchbay();
2279         flash_canvas(1);
2280 }
2281
2282
2283 void MWindowGUI::update_mixers(Track *track, int v)
2284 {
2285         for( int i=0; i<TOTAL_PANES;  ++i ) {
2286                 if( !pane[i] ) continue;
2287                 PatchBay *patchbay = pane[i]->patchbay;
2288                 if( !patchbay ) continue;
2289                 for( int j=0; j<patchbay->patches.total; ++j ) {
2290                         PatchGUI *patchgui = patchbay->patches.values[j];
2291                         if( !patchgui->mix ) continue;
2292                         if( !track || patchgui->track == track ) {
2293                                 patchgui->mix->update(v>=0 ? v :
2294                                         mwindow->mixer_track_active(patchgui->track));
2295                         }
2296                 }
2297         }
2298 }
2299
2300 void MWindowGUI::stop_transport(const char *lock_msg)
2301 {
2302         if( !mbuttons->transport->is_stopped() ) {
2303                 if( lock_msg ) unlock_window();
2304                 mbuttons->transport->handle_transport(STOP, 1);
2305                 if( lock_msg ) lock_window(lock_msg);
2306         }
2307 }
2308
2309 void MWindowGUI::close_keyvalue_popup()
2310 {
2311         if( !keyvalue_popup ) return;
2312         delete keyvalue_popup;
2313         keyvalue_popup = 0;
2314 }
2315
2316 void MWindowGUI::open_keyvalue_popup(BC_SubWindow *popup)
2317 {
2318         close_keyvalue_popup();
2319         keyvalue_popup = popup;
2320 }
2321
2322 PaneButton::PaneButton(MWindow *mwindow, int x, int y)
2323  : BC_Button(x, y, mwindow->theme->get_image_set("pane"))
2324 {
2325         this->mwindow = mwindow;
2326 }
2327
2328 int PaneButton::cursor_motion_event()
2329 {
2330         if(get_top_level()->get_button_down() &&
2331                 is_event_win() &&
2332                 get_status() == BUTTON_DOWNHI &&
2333                 !cursor_inside())
2334         {
2335 //              printf("PaneButton::cursor_motion_event %d\n", __LINE__);
2336 // create drag bar
2337                 if(get_cursor_x() < 0 && !mwindow->gui->dragging_pane)
2338                 {
2339                         mwindow->gui->start_x_pane_drag();
2340                 }
2341                 else
2342                 if(get_cursor_y() < 0 && !mwindow->gui->dragging_pane)
2343                 {
2344                         mwindow->gui->start_y_pane_drag();
2345                 }
2346         }
2347
2348         mwindow->gui->handle_pane_drag();
2349
2350         int result = BC_Button::cursor_motion_event();
2351         return result;
2352 }
2353
2354 int PaneButton::button_release_event()
2355 {
2356         if( get_buttonpress() != WHEEL_DOWN && get_buttonpress() != WHEEL_UP )
2357                 mwindow->gui->stop_pane_drag();
2358         int result = BC_Button::button_release_event();
2359         return result;
2360 }
2361
2362
2363 FFMpegToggle::FFMpegToggle(MWindow *mwindow, MButtons *mbuttons, int x, int y)
2364  : BC_Toggle(x, y, mwindow->theme->ffmpeg_toggle,
2365          mwindow->preferences->get_file_probe_armed("FFMPEG_Early") > 0 ? 1 : 0)
2366 {
2367         this->mwindow = mwindow;
2368         this->mbuttons = mbuttons;
2369         set_tooltip(get_value() ? FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
2370 }
2371
2372 FFMpegToggle::~FFMpegToggle()
2373 {
2374 }
2375
2376 int FFMpegToggle::handle_event()
2377 {
2378         int ffmpeg_early_probe = get_value();
2379         set_tooltip(ffmpeg_early_probe ? FFMPEG_EARLY_TIP : FFMPEG_LATE_TIP);
2380         mwindow->preferences->set_file_probe_armed("FFMPEG_Early", ffmpeg_early_probe);
2381         mwindow->preferences->set_file_probe_armed("FFMPEG_Late", !ffmpeg_early_probe);
2382         mwindow->update_preferences(mwindow->preferences);
2383         mwindow->show_warning(&mwindow->preferences->warn_indexes,
2384                 _("Changing the base codecs may require rebuilding indexes."));
2385         return 1;
2386 }
2387
2388
2389 StackButton::StackButton(MWindow *mwindow, int x, int y)
2390  : BC_GenericButton(x, y, mwindow->theme->stack_button_w, "0")
2391 {
2392         this->mwindow = mwindow;
2393         set_tooltip(_("Close EDL"));
2394 }
2395
2396 int StackButton::handle_event()
2397 {
2398         mwindow->save_backup();
2399         mwindow->stack_pop();
2400         return 1;
2401 }
2402
2403 void StackButton::update()
2404 {
2405         char text[BCSTRLEN];
2406         int i = mwindow->stack.size();
2407         sprintf(text, "%d", i);
2408         set_text(text);
2409         draw_face();
2410 }
2411
2412
2413 ProxyToggle::ProxyToggle(MWindow *mwindow, MButtons *mbuttons, int x, int y)
2414  : BC_Toggle(x, y, ( !mwindow->edl->session->proxy_use_scaler ?
2415                         mwindow->theme->proxy_p_toggle :
2416                         mwindow->theme->proxy_s_toggle ),
2417                 mwindow->edl->session->proxy_disabled_scale != 1)
2418 {
2419         this->mwindow = mwindow;
2420         this->mbuttons = mbuttons;
2421         scaler_images = mwindow->edl->session->proxy_use_scaler;
2422         set_tooltip(mwindow->edl->session->proxy_disabled_scale==1 ?
2423                 _("Disable proxy") : _("Enable proxy"));
2424 }
2425
2426 void ProxyToggle::show()
2427 {
2428         int use_scaler = mwindow->edl->session->proxy_use_scaler;
2429         if( scaler_images != use_scaler )
2430                 set_images(!(scaler_images=use_scaler) ?
2431                         mwindow->theme->proxy_p_toggle :
2432                         mwindow->theme->proxy_s_toggle );
2433         draw_face(1, 0);
2434         if( is_hidden() )
2435                 show_window();
2436 }
2437
2438 void ProxyToggle::hide()
2439 {
2440         if( !is_hidden() )
2441                 hide_window();
2442 }
2443
2444 ProxyToggle::~ProxyToggle()
2445 {
2446 }
2447
2448 int ProxyToggle::handle_event()
2449 {
2450         int disabled = get_value();
2451         mwindow->gui->unlock_window();
2452         if( disabled )
2453                 mwindow->disable_proxy();
2454         else
2455                 mwindow->enable_proxy();
2456         mwindow->gui->lock_window("ProxyToggle::handle_event");
2457         set_tooltip(!disabled ? _("Disable proxy") : _("Enable proxy"));
2458         return 1;
2459 }
2460
2461 int ProxyToggle::keypress_event()
2462 {
2463         if( ctrl_down() && !shift_down() && !alt_down() ) {
2464                 int key = get_keypress();
2465                 if( key == 'r' ) {
2466                         int value = get_value() ? 0 : 1;
2467                         set_value(value);
2468                         return handle_event();
2469                 }
2470         }
2471         return 0;
2472 }
2473