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