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