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