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