improve resize flash operation, fixup xv grab/ungrab, fixup label updates
[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(0) : 0;
1058         if( vwindow ) vwindow->gui->lock_window("MWindowGUI::default_positions");
1059         mwindow->cwindow->gui->lock_window("MWindowGUI::default_positions");
1060         mwindow->awindow->gui->lock_window("MWindowGUI::default_positions");
1061
1062 // printf("MWindowGUI::default_positions 1 %d %d %d %d\n", mwindow->session->vwindow_x,
1063 // mwindow->session->vwindow_y,
1064 // mwindow->session->vwindow_w,
1065 // mwindow->session->vwindow_h);
1066         reposition_window(mwindow->session->mwindow_x,
1067                 mwindow->session->mwindow_y,
1068                 mwindow->session->mwindow_w,
1069                 mwindow->session->mwindow_h);
1070         if( vwindow ) vwindow->gui->reposition_window(mwindow->session->vwindow_x,
1071                 mwindow->session->vwindow_y,
1072                 mwindow->session->vwindow_w,
1073                 mwindow->session->vwindow_h);
1074         mwindow->cwindow->gui->reposition_window(mwindow->session->cwindow_x,
1075                 mwindow->session->cwindow_y,
1076                 mwindow->session->cwindow_w,
1077                 mwindow->session->cwindow_h);
1078         mwindow->awindow->gui->reposition_window(mwindow->session->awindow_x,
1079                 mwindow->session->awindow_y,
1080                 mwindow->session->awindow_w,
1081                 mwindow->session->awindow_h);
1082 //printf("MWindowGUI::default_positions 1\n");
1083
1084         resize_event(mwindow->session->mwindow_w,
1085                 mwindow->session->mwindow_h);
1086 //printf("MWindowGUI::default_positions 1\n");
1087         if( vwindow ) vwindow->gui->resize_event(mwindow->session->vwindow_w,
1088                 mwindow->session->vwindow_h);
1089 //printf("MWindowGUI::default_positions 1\n");
1090         mwindow->cwindow->gui->resize_event(mwindow->session->cwindow_w,
1091                 mwindow->session->cwindow_h);
1092 //printf("MWindowGUI::default_positions 1\n");
1093         mwindow->awindow->gui->resize_event(mwindow->session->awindow_w,
1094                 mwindow->session->awindow_h);
1095
1096 //printf("MWindowGUI::default_positions 1\n");
1097
1098         flush();
1099         if( vwindow ) vwindow->gui->flush();
1100         mwindow->cwindow->gui->flush();
1101         mwindow->awindow->gui->flush();
1102
1103         if( vwindow ) vwindow->gui->unlock_window();
1104         mwindow->cwindow->gui->unlock_window();
1105         mwindow->awindow->gui->unlock_window();
1106 //printf("MWindowGUI::default_positions 2\n");
1107 }
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125 int MWindowGUI::repeat_event(int64_t duration)
1126 {
1127 // if(duration == 100)
1128 // mwindow->sync_parameters(CHANGE_ALL);
1129         int result = 0;
1130         for(int i = 0; i < TOTAL_PANES; i++)
1131         {
1132                 if(pane[i]) result = pane[i]->cursor->repeat_event(duration);
1133         }
1134         return result;
1135 }
1136
1137
1138 int MWindowGUI::translation_event()
1139 {
1140 //printf("MWindowGUI::translation_event 1 %d %d\n", get_x(), get_y());
1141         mwindow->session->mwindow_x = get_x();
1142         mwindow->session->mwindow_y = get_y();
1143         return 0;
1144 }
1145
1146
1147 int MWindowGUI::save_defaults(BC_Hash *defaults)
1148 {
1149         defaults->update("MWINDOWWIDTH", get_w());
1150         defaults->update("MWINDOWHEIGHT", get_h());
1151         mainmenu->save_defaults(defaults);
1152         BC_WindowBase::save_defaults(defaults);
1153         return 0;
1154 }
1155
1156 int MWindowGUI::keypress_event()
1157 {
1158 //printf("MWindowGUI::keypress_event 1 %d\n", get_keypress());
1159         int result = mbuttons->keypress_event();
1160         if( result ) return result;
1161
1162         switch(get_keypress()) {
1163         case 'e':
1164                 mwindow->toggle_editing_mode();
1165                 result = 1;
1166                 break;
1167
1168         case '1': case '2': case '3': case '4':
1169         case '5': case '6': case '7': case '8':
1170                 if( !alt_down() || shift_down() ) break;
1171                 if( !mwindow->select_asset(get_keypress()-'1',1) )
1172                         result = 1;
1173                 break;
1174
1175         case LEFT:
1176                 if( !ctrl_down() ) {
1177                         if( alt_down() ) {
1178                                 unlock_window();
1179                                 mbuttons->transport->handle_transport(STOP, 1, 0, 0);
1180                                 lock_window("MWindowGUI::keypress_event 1");
1181                                 mwindow->prev_edit_handle(shift_down());
1182                         }
1183                         else
1184                                 mwindow->move_left();
1185                         result = 1;
1186                 }
1187                 break;
1188
1189         case RIGHT:
1190                 if( !ctrl_down() ) {
1191                         if( alt_down() ) {
1192                                 unlock_window();
1193                                 mbuttons->transport->handle_transport(STOP, 1, 0, 0);
1194                                 lock_window("MWindowGUI::keypress_event 2");
1195                                 mwindow->next_edit_handle(shift_down());
1196                         }
1197                         else
1198                                 mwindow->move_right();
1199                         result = 1;
1200                 }
1201                 break;
1202
1203         case UP:
1204                 if( ctrl_down() && !alt_down() )
1205                         mwindow->expand_y();
1206                 else if( !ctrl_down() && alt_down() )
1207                         mwindow->expand_autos(0,1,1);
1208                 else if( ctrl_down() && alt_down() )
1209                         mwindow->expand_autos(1,1,1);
1210                 else
1211                         mwindow->expand_sample();
1212                 result = 1;
1213                 break;
1214
1215         case DOWN:
1216                 if( ctrl_down() && !alt_down() )
1217                         mwindow->zoom_in_y();
1218                 else if( !ctrl_down() && alt_down() )
1219                         mwindow->shrink_autos(0,1,1);
1220                 else if( ctrl_down() && alt_down() )
1221                         mwindow->shrink_autos(1,1,1);
1222                 else
1223                         mwindow->zoom_in_sample();
1224                 result = 1;
1225                 break;
1226
1227         case PGUP:
1228                 if( !ctrl_down() )
1229                         mwindow->move_up();
1230                 else
1231                         mwindow->expand_t();
1232                 result = 1;
1233                 break;
1234
1235         case PGDN:
1236                 if( !ctrl_down() )
1237                         mwindow->move_down();
1238                 else
1239                         mwindow->zoom_in_t();
1240                 result = 1;
1241                 break;
1242
1243         case TAB:
1244         case LEFTTAB:
1245                 Track *this_track = 0;
1246                 for( int i=0; i<TOTAL_PANES; ++i ) {
1247                         if( !pane[i] ) continue;
1248                         if( (this_track = pane[i]->over_track()) != 0 ) break;
1249                         if( (this_track = pane[i]->over_patchbay()) != 0 ) break;
1250                 }
1251
1252                 if( get_keypress() == TAB ) { // Switch the record button
1253                         if( this_track )
1254                                 this_track->record = !this_track->record ? 1 : 0;
1255                 }
1256                 else {
1257                         int total_selected = mwindow->edl->tracks->total_of(Tracks::RECORD);
1258                         // all selected if nothing previously selected or
1259                         // if this patch was previously the only one selected and armed
1260                         int selected = !total_selected || (total_selected == 1 &&
1261                                 this_track && this_track->record ) ? 1 : 0;
1262                         mwindow->edl->tracks->select_all(Tracks::RECORD, selected);
1263                         if( !selected && this_track ) this_track->record = 1;
1264                 }
1265
1266                 update(0, 1, 0, 0, 1, 0, 1);
1267                 unlock_window();
1268                 mwindow->cwindow->update(0, 1, 1);
1269                 lock_window("TrackCanvas::keypress_event 3");
1270
1271                 result = 1;
1272                 break;
1273         }
1274
1275 // since things under cursor have changed...
1276         if(result)
1277                 cursor_motion_event();
1278
1279         return result;
1280 }
1281
1282
1283 int MWindowGUI::keyboard_listener(BC_WindowBase *wp)
1284 {
1285         return key_listener(wp->get_keypress());
1286 }
1287
1288 int MWindowGUI::key_listener(int key)
1289 {
1290         int result = 1;
1291         switch( key ) {
1292         case KPTV:
1293                 if( !record->running() )
1294                         record->start();
1295                 else
1296                         record->record_gui->interrupt_thread->start(0);
1297                 break;
1298         case KPHAND:
1299                 mwindow->quit(0);
1300                 break;
1301 #ifdef HAVE_DVB
1302         case KPBOOK:
1303                 channel_info->toggle_scan();
1304                 break;
1305 #endif
1306         case KPMENU:
1307                 if( !remote_control->deactivate() )
1308                         remote_control->activate();
1309                 break;
1310         default:
1311                 result = 0;
1312                 break;
1313         }
1314         return result;
1315 }
1316
1317
1318 void MWindowGUI::use_android_remote(int on)
1319 {
1320         if( !on ) {
1321                 delete android_control;
1322                 android_control = 0;
1323                 return;
1324         }
1325         if( android_control ) return;
1326         android_control = new AndroidControl(this);
1327 }
1328
1329 int MWindowGUI::close_event()
1330 {
1331         mainmenu->quit();
1332         return 0;
1333 }
1334
1335 void MWindowGUI::stop_drawing()
1336 {
1337         resource_thread->stop_draw(1);
1338 }
1339
1340 int MWindowGUI::menu_w()
1341 {
1342         return mainmenu->get_w();
1343 }
1344
1345 int MWindowGUI::menu_h()
1346 {
1347         return mainmenu->get_h();
1348 }
1349
1350 void MWindowGUI::start_x_pane_drag()
1351 {
1352         if(!x_pane_drag)
1353         {
1354                 x_pane_drag = new BC_Popup(this,
1355                         get_abs_cursor_x(0) - mwindow->theme->pane_w,
1356                         BC_DisplayInfo::get_top_border() +
1357                                 get_y() +
1358                                 mwindow->theme->mcanvas_y,
1359                         mwindow->theme->pane_w,
1360                         mwindow->theme->mcanvas_h,
1361                         mwindow->theme->drag_pane_color);
1362                 x_pane_drag->draw_3segmentv(0,
1363                         0,
1364                         x_pane_drag->get_h(),
1365                         mwindow->theme->get_image_set("xpane")[BUTTON_DOWNHI]);
1366                 x_pane_drag->flash(1);
1367         }
1368         dragging_pane = 1;
1369 }
1370
1371 void MWindowGUI::start_y_pane_drag()
1372 {
1373         if(!y_pane_drag)
1374         {
1375 //printf("MWindowGUI::start_y_pane_drag %d %d %d\n", __LINE__, get_x(), get_y());
1376                 y_pane_drag = new BC_Popup(this,
1377                         BC_DisplayInfo::get_left_border() +
1378                                 get_x() +
1379                                 mwindow->theme->mcanvas_x,
1380                         get_abs_cursor_y(0) - mwindow->theme->pane_h,
1381                         mwindow->theme->mcanvas_w,
1382                         mwindow->theme->pane_h,
1383                         mwindow->theme->drag_pane_color);
1384                 y_pane_drag->draw_3segmenth(0,
1385                         0,
1386                         y_pane_drag->get_w(),
1387                         mwindow->theme->get_image_set("ypane")[BUTTON_DOWNHI]);
1388                 y_pane_drag->flash(1);
1389         }
1390         dragging_pane = 1;
1391 }
1392
1393 void MWindowGUI::handle_pane_drag()
1394 {
1395         if(dragging_pane)
1396         {
1397                 if(x_pane_drag)
1398                 {
1399                         x_pane_drag->reposition_window(
1400                                 get_abs_cursor_x(0) - mwindow->theme->pane_w,
1401                                 x_pane_drag->get_y());
1402                 }
1403
1404                 if(y_pane_drag)
1405                 {
1406                         y_pane_drag->reposition_window(
1407                                 y_pane_drag->get_x(),
1408                                 get_abs_cursor_y(0) - mwindow->theme->pane_h);
1409                 }
1410         }
1411 }
1412
1413
1414 void MWindowGUI::create_x_pane(int cursor_x)
1415 {
1416         if(total_panes() == 1)
1417         {
1418 // create a horizontal pane
1419 // do this 1st so the resize_event knows there are 2 panes
1420                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] =
1421                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] +
1422                         cursor_x -
1423                         mwindow->theme->patchbay_w;
1424                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1425                         TOP_RIGHT_PANE,
1426                         mwindow->theme->mcanvas_x +
1427                                 cursor_x,
1428                         mwindow->theme->mcanvas_y,
1429                         mwindow->theme->mcanvas_x +
1430                                 mwindow->theme->mcanvas_w -
1431                                 cursor_x,
1432                         mwindow->theme->mcanvas_h);
1433                 pane[TOP_LEFT_PANE]->resize_event(
1434                         mwindow->theme->mcanvas_x,
1435                         mwindow->theme->mcanvas_y,
1436                         cursor_x - mwindow->theme->pane_w,
1437                         mwindow->theme->mcanvas_h);
1438                 pane[TOP_RIGHT_PANE]->create_objects();
1439         }
1440         else
1441         if(vertical_panes())
1442         {
1443 // create 2 horizontal panes
1444                 mwindow->edl->local_session->track_start[TOP_RIGHT_PANE] =
1445                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE];
1446                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1447                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE];
1448                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] =
1449                         mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1450                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] +
1451                         cursor_x -
1452                         mwindow->theme->patchbay_w;
1453                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1454                         TOP_RIGHT_PANE,
1455                         mwindow->theme->mcanvas_x +
1456                                 cursor_x,
1457                         pane[TOP_LEFT_PANE]->y,
1458                         mwindow->theme->mcanvas_x +
1459                                 mwindow->theme->mcanvas_w -
1460                                 cursor_x,
1461                         pane[TOP_LEFT_PANE]->h);
1462                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1463                         BOTTOM_RIGHT_PANE,
1464                         mwindow->theme->mcanvas_x +
1465                                 cursor_x,
1466                         pane[BOTTOM_LEFT_PANE]->y,
1467                         mwindow->theme->mcanvas_x +
1468                                 mwindow->theme->mcanvas_w -
1469                                 cursor_x,
1470                         pane[BOTTOM_LEFT_PANE]->h);
1471                 pane[TOP_LEFT_PANE]->resize_event(
1472                         pane[TOP_LEFT_PANE]->x,
1473                         pane[TOP_LEFT_PANE]->y,
1474                         cursor_x - mwindow->theme->pane_w,
1475                         pane[TOP_LEFT_PANE]->h);
1476                 pane[BOTTOM_LEFT_PANE]->resize_event(
1477                         pane[BOTTOM_LEFT_PANE]->x,
1478                         pane[BOTTOM_LEFT_PANE]->y,
1479                         cursor_x - mwindow->theme->pane_w,
1480                         pane[BOTTOM_LEFT_PANE]->h);
1481                 pane[TOP_RIGHT_PANE]->create_objects();
1482                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1483         }
1484         else
1485         if(horizontal_panes())
1486         {
1487 // resize a horizontal pane
1488                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] +=
1489                         cursor_x -
1490                         pane[TOP_RIGHT_PANE]->x;
1491                 if(mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] < 0)
1492                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] = 0;
1493                 pane[TOP_LEFT_PANE]->resize_event(
1494                         mwindow->theme->mcanvas_x,
1495                         mwindow->theme->mcanvas_y,
1496                         cursor_x - mwindow->theme->pane_w,
1497                         mwindow->theme->mcanvas_h);
1498                 pane[TOP_RIGHT_PANE]->resize_event(
1499                         mwindow->theme->mcanvas_x +
1500                                 cursor_x,
1501                         pane[TOP_RIGHT_PANE]->y,
1502                         mwindow->theme->mcanvas_x +
1503                                 mwindow->theme->mcanvas_w -
1504                                 cursor_x,
1505                         mwindow->theme->mcanvas_h);
1506         }
1507         else
1508         {
1509 // resize 2 horizontal panes
1510                 mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] +=
1511                         cursor_x -
1512                         pane[TOP_RIGHT_PANE]->x;
1513                 if(mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] < 0)
1514                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] = 0;
1515                 mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1516                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE];
1517
1518                 pane[TOP_LEFT_PANE]->resize_event(
1519                         mwindow->theme->mcanvas_x,
1520                         pane[TOP_LEFT_PANE]->y,
1521                         cursor_x - mwindow->theme->pane_w,
1522                         pane[TOP_LEFT_PANE]->h);
1523                 pane[TOP_RIGHT_PANE]->resize_event(
1524                         mwindow->theme->mcanvas_x +
1525                                 cursor_x,
1526                         pane[TOP_RIGHT_PANE]->y,
1527                         mwindow->theme->mcanvas_x +
1528                                 mwindow->theme->mcanvas_w -
1529                                 cursor_x,
1530                         pane[TOP_RIGHT_PANE]->h);
1531                 pane[BOTTOM_LEFT_PANE]->resize_event(
1532                         mwindow->theme->mcanvas_x,
1533                         pane[BOTTOM_LEFT_PANE]->y,
1534                         cursor_x - mwindow->theme->pane_w,
1535                         pane[BOTTOM_LEFT_PANE]->h);
1536                 pane[BOTTOM_RIGHT_PANE]->resize_event(
1537                         mwindow->theme->mcanvas_x +
1538                                 cursor_x,
1539                         pane[BOTTOM_RIGHT_PANE]->y,
1540                         mwindow->theme->mcanvas_x +
1541                                 mwindow->theme->mcanvas_w -
1542                                 cursor_x,
1543                         pane[BOTTOM_RIGHT_PANE]->h);
1544
1545         }
1546 }
1547
1548
1549 void MWindowGUI::delete_x_pane(int cursor_x)
1550 {
1551 // give left panes coordinates of right pane
1552         if(cursor_x < mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1553                 pane[TOP_RIGHT_PANE])
1554         {
1555                 mwindow->edl->local_session->view_start[TOP_LEFT_PANE] =
1556                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE] -
1557                         pane[TOP_RIGHT_PANE]->x + mwindow->theme->patchbay_w;
1558                 if(mwindow->edl->local_session->view_start[TOP_LEFT_PANE] < 0)
1559                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE] = 0;
1560                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1561                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1562         }
1563
1564         switch(total_panes())
1565         {
1566                 case 2:
1567                         if(pane[TOP_LEFT_PANE] && pane[TOP_RIGHT_PANE])
1568                         {
1569 // delete right pane
1570                                 delete pane[TOP_RIGHT_PANE];
1571                                 pane[TOP_RIGHT_PANE] = 0;
1572                                 pane[TOP_LEFT_PANE]->resize_event(
1573                                         mwindow->theme->mcanvas_x,
1574                                         mwindow->theme->mcanvas_y,
1575                                         mwindow->theme->mcanvas_w,
1576                                         mwindow->theme->mcanvas_h);
1577
1578                         }
1579                         break;
1580
1581                 case 4:
1582 // delete right panes
1583                         delete pane[TOP_RIGHT_PANE];
1584                         pane[TOP_RIGHT_PANE] = 0;
1585                         delete pane[BOTTOM_RIGHT_PANE];
1586                         pane[BOTTOM_RIGHT_PANE] = 0;
1587                         pane[TOP_LEFT_PANE]->resize_event(
1588                                 mwindow->theme->mcanvas_x,
1589                                 pane[TOP_LEFT_PANE]->y,
1590                                 mwindow->theme->mcanvas_w,
1591                                 pane[TOP_LEFT_PANE]->h);
1592                         pane[BOTTOM_LEFT_PANE]->resize_event(
1593                                 mwindow->theme->mcanvas_x,
1594                                 pane[BOTTOM_LEFT_PANE]->y,
1595                                 mwindow->theme->mcanvas_w,
1596                                 pane[BOTTOM_LEFT_PANE]->h);
1597                         break;
1598         }
1599 }
1600
1601 void MWindowGUI::create_y_pane(int cursor_y)
1602 {
1603         if(total_panes() == 1)
1604         {
1605                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1606                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1607                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] =
1608                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] +
1609                         cursor_y -
1610                         mwindow->theme->mtimebar_h;
1611 // do this 1st so the resize_event knows there are 2 panes
1612                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1613                         BOTTOM_LEFT_PANE,
1614                         mwindow->theme->mcanvas_x,
1615                         mwindow->theme->mcanvas_y +
1616                                 cursor_y,
1617                         mwindow->theme->mcanvas_w,
1618                         mwindow->theme->mcanvas_h -
1619                                 cursor_y);
1620                 pane[TOP_LEFT_PANE]->resize_event(
1621                         mwindow->theme->mcanvas_x,
1622                         mwindow->theme->mcanvas_y,
1623                         mwindow->theme->mcanvas_w,
1624                         pane[BOTTOM_LEFT_PANE]->y -
1625                                 mwindow->theme->mcanvas_y -
1626                                 mwindow->theme->pane_h);
1627                 pane[BOTTOM_LEFT_PANE]->create_objects();
1628         }
1629         else
1630         if(horizontal_panes())
1631         {
1632 // create 2 panes
1633                 mwindow->edl->local_session->view_start[BOTTOM_LEFT_PANE] =
1634                         mwindow->edl->local_session->view_start[TOP_LEFT_PANE];
1635                 mwindow->edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
1636                         mwindow->edl->local_session->view_start[TOP_RIGHT_PANE];
1637                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] =
1638                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1639                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] +
1640                         cursor_y -
1641                         mwindow->theme->mtimebar_h;
1642
1643                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1644                         BOTTOM_LEFT_PANE,
1645                         pane[TOP_LEFT_PANE]->x,
1646                         mwindow->theme->mcanvas_y +
1647                                 cursor_y,
1648                         pane[TOP_LEFT_PANE]->w,
1649                         mwindow->theme->mcanvas_h -
1650                                 cursor_y);
1651                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1652                         BOTTOM_RIGHT_PANE,
1653                         pane[TOP_RIGHT_PANE]->x,
1654                         mwindow->theme->mcanvas_y +
1655                                 cursor_y,
1656                         pane[TOP_RIGHT_PANE]->w,
1657                         mwindow->theme->mcanvas_h -
1658                                 cursor_y);
1659
1660                 pane[TOP_LEFT_PANE]->resize_event(
1661                         pane[TOP_LEFT_PANE]->x,
1662                         pane[TOP_LEFT_PANE]->y,
1663                         pane[TOP_LEFT_PANE]->w,
1664                         pane[BOTTOM_LEFT_PANE]->y -
1665                                 mwindow->theme->mcanvas_y -
1666                                 mwindow->theme->pane_h);
1667                 pane[TOP_RIGHT_PANE]->resize_event(
1668                         pane[TOP_RIGHT_PANE]->x,
1669                         pane[TOP_RIGHT_PANE]->y,
1670                         pane[TOP_RIGHT_PANE]->w,
1671                         pane[BOTTOM_RIGHT_PANE]->y -
1672                                 mwindow->theme->mcanvas_y -
1673                                 mwindow->theme->pane_h);
1674
1675                 pane[BOTTOM_LEFT_PANE]->create_objects();
1676                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1677         }
1678         else
1679         if(vertical_panes())
1680         {
1681 // resize a pane
1682                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] +=
1683                         cursor_y -
1684                         (pane[BOTTOM_LEFT_PANE]->y - mwindow->theme->mcanvas_y);
1685                 if(mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] < 0)
1686                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] = 0;
1687                 pane[TOP_LEFT_PANE]->resize_event(
1688                         mwindow->theme->mcanvas_x,
1689                         mwindow->theme->mcanvas_y,
1690                         mwindow->theme->mcanvas_w,
1691                         cursor_y - mwindow->theme->pane_h);
1692                 pane[BOTTOM_LEFT_PANE]->resize_event(
1693                         pane[BOTTOM_LEFT_PANE]->x,
1694                         cursor_y +
1695                                 mwindow->theme->mcanvas_y,
1696                         mwindow->theme->mcanvas_w,
1697                         mwindow->theme->mcanvas_h -
1698                                 cursor_y);
1699         }
1700         else
1701         {
1702 // resize 2 panes
1703                 mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] +=
1704                         cursor_y -
1705                         (pane[BOTTOM_LEFT_PANE]->y - mwindow->theme->mcanvas_y);
1706                 if(mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] < 0)
1707                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] = 0;
1708                 mwindow->edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
1709                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE];
1710                 pane[TOP_LEFT_PANE]->resize_event(
1711                         pane[TOP_LEFT_PANE]->x,
1712                         pane[TOP_LEFT_PANE]->y,
1713                         pane[TOP_LEFT_PANE]->w,
1714                         cursor_y - mwindow->theme->pane_h);
1715                 pane[BOTTOM_LEFT_PANE]->resize_event(
1716                         pane[BOTTOM_LEFT_PANE]->x,
1717                         cursor_y +
1718                                 mwindow->theme->mcanvas_y,
1719                         pane[BOTTOM_LEFT_PANE]->w,
1720                         mwindow->theme->mcanvas_h -
1721                                         cursor_y);
1722                 pane[TOP_RIGHT_PANE]->resize_event(
1723                         pane[TOP_RIGHT_PANE]->x,
1724                         pane[TOP_RIGHT_PANE]->y,
1725                         pane[TOP_RIGHT_PANE]->w,
1726                         cursor_y - mwindow->theme->pane_h);
1727                 pane[BOTTOM_RIGHT_PANE]->resize_event(
1728                         pane[BOTTOM_RIGHT_PANE]->x,
1729                         cursor_y +
1730                                 mwindow->theme->mcanvas_y,
1731                         pane[BOTTOM_RIGHT_PANE]->w,
1732                         mwindow->theme->mcanvas_h -
1733                                         cursor_y);
1734         }
1735 }
1736
1737 void MWindowGUI::delete_y_pane(int cursor_y)
1738 {
1739         if(cursor_y < mwindow->theme->mtimebar_h +
1740                 PANE_DRAG_MARGIN &&
1741                 pane[BOTTOM_LEFT_PANE])
1742         {
1743 // give top pane coordinates of bottom pane
1744                 mwindow->edl->local_session->track_start[TOP_LEFT_PANE] =
1745                         mwindow->edl->local_session->track_start[BOTTOM_LEFT_PANE] -
1746                         pane[BOTTOM_LEFT_PANE]->y;
1747                 if(mwindow->edl->local_session->track_start[TOP_LEFT_PANE] < 0)
1748                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE] = 0;
1749                 mwindow->edl->local_session->track_start[TOP_RIGHT_PANE] =
1750                         mwindow->edl->local_session->track_start[TOP_LEFT_PANE];
1751         }
1752
1753 // delete a pane
1754         switch(total_panes())
1755         {
1756                 case 2:
1757                         delete pane[BOTTOM_LEFT_PANE];
1758                         pane[BOTTOM_LEFT_PANE] = 0;
1759                         pane[TOP_LEFT_PANE]->resize_event(
1760                                 mwindow->theme->mcanvas_x,
1761                                 mwindow->theme->mcanvas_y,
1762                                 mwindow->theme->mcanvas_w,
1763                                 mwindow->theme->mcanvas_h);
1764                         break;
1765
1766                 case 4:
1767 // delete bottom 2 panes
1768
1769                         delete pane[BOTTOM_LEFT_PANE];
1770                         pane[BOTTOM_LEFT_PANE] = 0;
1771                         delete pane[BOTTOM_RIGHT_PANE];
1772                         pane[BOTTOM_RIGHT_PANE] = 0;
1773                         pane[TOP_LEFT_PANE]->resize_event(
1774                                 pane[TOP_LEFT_PANE]->x,
1775                                 mwindow->theme->mcanvas_y,
1776                                 pane[TOP_LEFT_PANE]->w,
1777                                 mwindow->theme->mcanvas_h);
1778                         pane[TOP_RIGHT_PANE]->resize_event(
1779                                 pane[TOP_RIGHT_PANE]->x,
1780                                 mwindow->theme->mcanvas_y,
1781                                 pane[TOP_RIGHT_PANE]->w,
1782                                 mwindow->theme->mcanvas_h);
1783                         break;
1784         }
1785 }
1786
1787 void MWindowGUI::stop_pane_drag()
1788 {
1789         dragging_pane = 0;
1790         resource_thread->stop_draw(1);
1791
1792         if(x_pane_drag)
1793         {
1794 // cursor position relative to canvas
1795                 int cursor_x = x_pane_drag->get_x() -
1796                         get_x() -
1797                         BC_DisplayInfo::get_left_border() -
1798                         mwindow->theme->mcanvas_x +
1799                         mwindow->theme->pane_w;
1800                 delete x_pane_drag;
1801                 x_pane_drag = 0;
1802
1803
1804                 if(cursor_x >= mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1805                         cursor_x < mwindow->theme->mcanvas_w -
1806                                 BC_ScrollBar::get_span(SCROLL_VERT) -
1807                                 PANE_DRAG_MARGIN)
1808                 {
1809                         create_x_pane(cursor_x);
1810                         mwindow->edl->local_session->x_pane = cursor_x;
1811                 }
1812                 else
1813 // deleted a pane
1814                 {
1815                         delete_x_pane(cursor_x);
1816                         mwindow->edl->local_session->x_pane = -1;
1817                 }
1818
1819
1820         }
1821
1822         if(y_pane_drag)
1823         {
1824 // cursor position relative to canvas
1825                 int cursor_y = y_pane_drag->get_y() -
1826                         get_y() -
1827                         BC_DisplayInfo::get_top_border() -
1828                         mwindow->theme->mcanvas_y +
1829                         mwindow->theme->pane_h;
1830                 delete y_pane_drag;
1831                 y_pane_drag = 0;
1832
1833
1834
1835                 if(cursor_y >= mwindow->theme->mtimebar_h +
1836                                 PANE_DRAG_MARGIN &&
1837                         cursor_y < mwindow->theme->mcanvas_h -
1838                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
1839                                 PANE_DRAG_MARGIN)
1840                 {
1841                         create_y_pane(cursor_y);
1842                         mwindow->edl->local_session->y_pane = cursor_y;
1843                 }
1844                 else
1845                 {
1846                         delete_y_pane(cursor_y);
1847                         mwindow->edl->local_session->y_pane = -1;
1848                 }
1849         }
1850
1851         update_pane_dividers();
1852         update_cursor();
1853 // required to get new widgets to appear
1854         show_window();
1855         resource_thread->start_draw();
1856 }
1857
1858 // create panes from EDL
1859 void MWindowGUI::load_panes()
1860 {
1861         int need_x_panes = 0;
1862         int need_y_panes = 0;
1863 // use names from create functions
1864         int cursor_x = mwindow->edl->local_session->x_pane;
1865         int cursor_y = mwindow->edl->local_session->y_pane;
1866
1867         resource_thread->stop_draw(1);
1868         if(cursor_x >=
1869                 mwindow->theme->patchbay_w + PANE_DRAG_MARGIN &&
1870                 cursor_x <
1871                 mwindow->theme->mcanvas_w -
1872                                 BC_ScrollBar::get_span(SCROLL_VERT) -
1873                                 PANE_DRAG_MARGIN)
1874         {
1875                 need_x_panes = 1;
1876         }
1877
1878         if(cursor_y >=
1879                 mwindow->theme->mtimebar_h + PANE_DRAG_MARGIN &&
1880                 cursor_y <
1881                 mwindow->theme->mcanvas_h -
1882                                 BC_ScrollBar::get_span(SCROLL_HORIZ) -
1883                                 PANE_DRAG_MARGIN)
1884         {
1885                 need_y_panes = 1;
1886         }
1887
1888 //printf("MWindowGUI::load_panes %d %d %d\n", __LINE__, need_x_panes, need_y_panes);
1889
1890
1891         if(need_x_panes)
1892         {
1893                 if(need_y_panes)
1894                 {
1895 // 4 panes
1896                         if(total_panes() == 1)
1897                         {
1898 // create 4 panes
1899 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1900                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1901                                         TOP_RIGHT_PANE,
1902                                         mwindow->theme->mcanvas_x +
1903                                                 cursor_x,
1904                                         mwindow->theme->mcanvas_y,
1905                                         mwindow->theme->mcanvas_x +
1906                                                 mwindow->theme->mcanvas_w -
1907                                                 cursor_x,
1908                                         cursor_y - mwindow->theme->pane_h);
1909                                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1910                                         BOTTOM_LEFT_PANE,
1911                                         mwindow->theme->mcanvas_x,
1912                                         mwindow->theme->mcanvas_y +
1913                                                 cursor_y,
1914                                         cursor_x - mwindow->theme->pane_w,
1915                                         mwindow->theme->mcanvas_h -
1916                                                 cursor_y);
1917                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1918                                         BOTTOM_RIGHT_PANE,
1919                                         pane[TOP_RIGHT_PANE]->x,
1920                                         mwindow->theme->mcanvas_y +
1921                                                 cursor_y,
1922                                         pane[TOP_RIGHT_PANE]->w,
1923                                         mwindow->theme->mcanvas_h -
1924                                                 cursor_y);
1925                                 pane[TOP_LEFT_PANE]->resize_event(
1926                                         pane[TOP_LEFT_PANE]->x,
1927                                         pane[TOP_LEFT_PANE]->y,
1928                                         cursor_x - mwindow->theme->pane_w,
1929                                         cursor_y - mwindow->theme->pane_h);
1930                                 pane[TOP_RIGHT_PANE]->create_objects();
1931                                 pane[BOTTOM_LEFT_PANE]->create_objects();
1932                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1933                         }
1934                         else
1935                         if(horizontal_panes())
1936                         {
1937 // create vertical panes
1938 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1939                                 pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
1940                                         BOTTOM_LEFT_PANE,
1941                                         mwindow->theme->mcanvas_x,
1942                                         mwindow->theme->mcanvas_y +
1943                                                 cursor_y,
1944                                         cursor_x - mwindow->theme->pane_w,
1945                                         mwindow->theme->mcanvas_h -
1946                                                 cursor_y);
1947                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1948                                         BOTTOM_RIGHT_PANE,
1949                                         pane[TOP_RIGHT_PANE]->x,
1950                                         mwindow->theme->mcanvas_y +
1951                                                 cursor_y,
1952                                         pane[TOP_RIGHT_PANE]->w,
1953                                         mwindow->theme->mcanvas_h -
1954                                                 cursor_y);
1955                                 pane[TOP_LEFT_PANE]->resize_event(
1956                                         pane[TOP_LEFT_PANE]->x,
1957                                         pane[TOP_LEFT_PANE]->y,
1958                                         cursor_x - mwindow->theme->pane_w,
1959                                         cursor_y - mwindow->theme->pane_h);
1960                                 pane[TOP_RIGHT_PANE]->resize_event(
1961                                         mwindow->theme->mcanvas_x +
1962                                                 cursor_x,
1963                                         mwindow->theme->mcanvas_y,
1964                                         mwindow->theme->mcanvas_x +
1965                                                 mwindow->theme->mcanvas_w -
1966                                                 cursor_x,
1967                                         cursor_y - mwindow->theme->pane_h);
1968                                 pane[BOTTOM_LEFT_PANE]->create_objects();
1969                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
1970                         }
1971                         else
1972                         if(vertical_panes())
1973                         {
1974 // create horizontal panes
1975 //printf("MWindowGUI::load_panes %d\n", __LINE__);
1976                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
1977                                         TOP_RIGHT_PANE,
1978                                         mwindow->theme->mcanvas_x +
1979                                                 cursor_x,
1980                                         mwindow->theme->mcanvas_y,
1981                                         mwindow->theme->mcanvas_x +
1982                                                 mwindow->theme->mcanvas_w -
1983                                                 cursor_x,
1984                                         cursor_y - mwindow->theme->pane_h);
1985                                 pane[BOTTOM_RIGHT_PANE] = new TimelinePane(mwindow,
1986                                         BOTTOM_RIGHT_PANE,
1987                                         pane[TOP_RIGHT_PANE]->x,
1988                                         mwindow->theme->mcanvas_y +
1989                                                 cursor_y,
1990                                         pane[TOP_RIGHT_PANE]->w,
1991                                         mwindow->theme->mcanvas_h -
1992                                                 cursor_y);
1993                                 pane[TOP_LEFT_PANE]->resize_event(
1994                                         pane[TOP_LEFT_PANE]->x,
1995                                         pane[TOP_LEFT_PANE]->y,
1996                                         cursor_x - mwindow->theme->pane_w,
1997                                         cursor_y - mwindow->theme->pane_h);
1998                                 pane[BOTTOM_LEFT_PANE]->resize_event(
1999                                         pane[TOP_LEFT_PANE]->x,
2000                                         mwindow->theme->mcanvas_y +
2001                                                 cursor_y,
2002                                         mwindow->theme->mcanvas_x +
2003                                                 mwindow->theme->mcanvas_w -
2004                                                 cursor_x -  mwindow->theme->pane_w,
2005                                         mwindow->theme->mcanvas_h -
2006                                                 cursor_y);
2007                                 pane[TOP_RIGHT_PANE]->create_objects();
2008                                 pane[BOTTOM_RIGHT_PANE]->create_objects();
2009
2010
2011                         }
2012                         else
2013                         {
2014 // resize all panes
2015 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2016                                 pane[TOP_LEFT_PANE]->resize_event(
2017                                         pane[TOP_LEFT_PANE]->x,
2018                                         pane[TOP_LEFT_PANE]->y,
2019                                         cursor_x - mwindow->theme->pane_w,
2020                                         cursor_y - mwindow->theme->pane_h);
2021                                 pane[TOP_RIGHT_PANE]->resize_event(
2022                                         mwindow->theme->mcanvas_x +
2023                                                 cursor_x,
2024                                         mwindow->theme->mcanvas_y,
2025                                         mwindow->theme->mcanvas_x +
2026                                                 mwindow->theme->mcanvas_w -
2027                                                 cursor_x,
2028                                         cursor_y - mwindow->theme->pane_h);
2029                                 pane[BOTTOM_LEFT_PANE]->resize_event(
2030                                         pane[TOP_LEFT_PANE]->x,
2031                                         mwindow->theme->mcanvas_y +
2032                                                 cursor_y,
2033                                         mwindow->theme->mcanvas_x +
2034                                                 mwindow->theme->mcanvas_w -
2035                                                 cursor_x - mwindow->theme->pane_w,
2036                                         mwindow->theme->mcanvas_h -
2037                                                 cursor_y);
2038                                 pane[BOTTOM_RIGHT_PANE]->resize_event(
2039                                         pane[TOP_RIGHT_PANE]->x,
2040                                         mwindow->theme->mcanvas_y +
2041                                                 cursor_y,
2042                                         pane[TOP_RIGHT_PANE]->w,
2043                                         mwindow->theme->mcanvas_h -
2044                                                 cursor_y);
2045
2046
2047                         }
2048                 }
2049                 else
2050                 {
2051 // 2 X panes
2052                         if(pane[BOTTOM_LEFT_PANE]) delete pane[BOTTOM_LEFT_PANE];
2053                         if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2054                         pane[BOTTOM_LEFT_PANE] = 0;
2055                         pane[BOTTOM_RIGHT_PANE] = 0;
2056
2057                         if(!pane[TOP_RIGHT_PANE])
2058                         {
2059                                 pane[TOP_RIGHT_PANE] = new TimelinePane(mwindow,
2060                                         TOP_RIGHT_PANE,
2061                                         mwindow->theme->mcanvas_x +
2062                                                 cursor_x,
2063                                         mwindow->theme->mcanvas_y,
2064                                         mwindow->theme->mcanvas_x +
2065                                                 mwindow->theme->mcanvas_w -
2066                                                 cursor_x,
2067                                         mwindow->theme->mcanvas_h);
2068                                 pane[TOP_LEFT_PANE]->resize_event(
2069                                         mwindow->theme->mcanvas_x,
2070                                         mwindow->theme->mcanvas_y,
2071                                         cursor_x - mwindow->theme->pane_w,
2072                                         mwindow->theme->mcanvas_h);
2073                                 pane[TOP_RIGHT_PANE]->create_objects();
2074                         }
2075                         else
2076                         {
2077                                 pane[TOP_LEFT_PANE]->resize_event(
2078                                         mwindow->theme->mcanvas_x,
2079                                         mwindow->theme->mcanvas_y,
2080                                         cursor_x - mwindow->theme->pane_w,
2081                                         mwindow->theme->mcanvas_h);
2082                                 pane[TOP_RIGHT_PANE]->resize_event(
2083                                         mwindow->theme->mcanvas_x +
2084                                                 cursor_x,
2085                                         pane[TOP_RIGHT_PANE]->y,
2086                                         mwindow->theme->mcanvas_x +
2087                                                 mwindow->theme->mcanvas_w -
2088                                                 cursor_x,
2089                                         mwindow->theme->mcanvas_h);
2090                         }
2091                 }
2092         }
2093         else
2094         if(need_y_panes)
2095         {
2096 // 2 Y panes
2097                 if(pane[TOP_RIGHT_PANE]) delete pane[TOP_RIGHT_PANE];
2098                 if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2099                 pane[TOP_RIGHT_PANE] = 0;
2100                 pane[BOTTOM_RIGHT_PANE] = 0;
2101
2102                 if(!pane[BOTTOM_LEFT_PANE])
2103                 {
2104 //printf("MWindowGUI::load_panes %d\n", __LINE__);
2105                         pane[BOTTOM_LEFT_PANE] = new TimelinePane(mwindow,
2106                                 BOTTOM_LEFT_PANE,
2107                                 mwindow->theme->mcanvas_x,
2108                                 mwindow->theme->mcanvas_y +
2109                                         cursor_y,
2110                                 mwindow->theme->mcanvas_w,
2111                                 mwindow->theme->mcanvas_h -
2112                                         cursor_y);
2113                         pane[TOP_LEFT_PANE]->resize_event(
2114                                 mwindow->theme->mcanvas_x,
2115                                 mwindow->theme->mcanvas_y,
2116                                 mwindow->theme->mcanvas_w,
2117                                 pane[BOTTOM_LEFT_PANE]->y -
2118                                         mwindow->theme->mcanvas_y -
2119                                         mwindow->theme->pane_h);
2120                         pane[BOTTOM_LEFT_PANE]->create_objects();
2121                 }
2122                 else
2123                 {
2124                         pane[TOP_LEFT_PANE]->resize_event(
2125                                 mwindow->theme->mcanvas_x,
2126                                 mwindow->theme->mcanvas_y,
2127                                 mwindow->theme->mcanvas_w,
2128                                 cursor_y - mwindow->theme->pane_h);
2129                         pane[BOTTOM_LEFT_PANE]->resize_event(
2130                                 pane[BOTTOM_LEFT_PANE]->x,
2131                                 cursor_y +
2132                                         mwindow->theme->mcanvas_y,
2133                                 mwindow->theme->mcanvas_w,
2134                                 mwindow->theme->mcanvas_h -
2135                                         cursor_y);
2136                 }
2137         }
2138         else
2139         {
2140 // 1 pane
2141                 if(pane[TOP_RIGHT_PANE]) delete pane[TOP_RIGHT_PANE];
2142                 if(pane[BOTTOM_RIGHT_PANE]) delete pane[BOTTOM_RIGHT_PANE];
2143                 if(pane[BOTTOM_LEFT_PANE]) delete pane[BOTTOM_LEFT_PANE];
2144                 pane[TOP_RIGHT_PANE] = 0;
2145                 pane[BOTTOM_RIGHT_PANE] = 0;
2146                 pane[BOTTOM_LEFT_PANE] = 0;
2147                 pane[TOP_LEFT_PANE]->resize_event(
2148                         mwindow->theme->mcanvas_x,
2149                         mwindow->theme->mcanvas_y,
2150                         mwindow->theme->mcanvas_w,
2151                         mwindow->theme->mcanvas_h);
2152         }
2153
2154         update_pane_dividers();
2155         show_window();
2156
2157         resource_thread->start_draw();
2158 }
2159
2160 void MWindowGUI::update_pane_dividers()
2161 {
2162
2163         if(horizontal_panes() || total_panes() == 4)
2164         {
2165                 int x = pane[TOP_RIGHT_PANE]->x - mwindow->theme->pane_w;
2166                 int y = mwindow->theme->mcanvas_y;
2167                 int h = mwindow->theme->mcanvas_h;
2168
2169                 if(!x_divider)
2170                 {
2171                         add_subwindow(x_divider = new PaneDivider(
2172                                 mwindow, x, y, h, 1));
2173                         x_divider->create_objects();
2174                 }
2175                 else
2176                 {
2177                         x_divider->reposition_window(x, y, h);
2178                         x_divider->draw(0);
2179                 }
2180         }
2181         else
2182         {
2183                 if(x_divider)
2184                 {
2185                         delete x_divider;
2186                         x_divider = 0;
2187                 }
2188         }
2189
2190         if(vertical_panes() || total_panes() == 4)
2191         {
2192                 int x = mwindow->theme->mcanvas_x;
2193                 int y = pane[BOTTOM_LEFT_PANE]->y -
2194                         mwindow->theme->pane_h;
2195                 int w = mwindow->theme->mcanvas_w;
2196                 if(!y_divider)
2197                 {
2198                         add_subwindow(y_divider = new PaneDivider(
2199                                 mwindow, x, y, w, 0));
2200                         y_divider->create_objects();
2201                 }
2202                 else
2203                 {
2204                         y_divider->reposition_window(x, y, w);
2205                         y_divider->draw(0);
2206                 }
2207         }
2208         else
2209         {
2210                 if(y_divider)
2211                 {
2212                         delete y_divider;
2213                         y_divider = 0;
2214                 }
2215         }
2216 }
2217
2218 void MWindowGUI::draw_samplemovement()
2219 {
2220         draw_canvas(0, 1);
2221         show_cursor(1);
2222         flash_canvas(0);
2223         update_timebar(0);
2224         zoombar->update();
2225         update_scrollbars(1);
2226 }
2227
2228 void MWindowGUI::draw_trackmovement()
2229 {
2230         update_scrollbars(0);
2231         draw_canvas(0, 0);
2232         update_patchbay();
2233         flash_canvas(1);
2234 }
2235
2236
2237 PaneButton::PaneButton(MWindow *mwindow, int x, int y)
2238  : BC_Button(x, y, mwindow->theme->get_image_set("pane"))
2239 {
2240         this->mwindow = mwindow;
2241 }
2242
2243 int PaneButton::cursor_motion_event()
2244 {
2245         if(get_top_level()->get_button_down() &&
2246                 is_event_win() &&
2247                 get_status() == BUTTON_DOWNHI &&
2248                 !cursor_inside())
2249         {
2250 //              printf("PaneButton::cursor_motion_event %d\n", __LINE__);
2251 // create drag bar
2252                 if(get_cursor_x() < 0 && !mwindow->gui->dragging_pane)
2253                 {
2254                         mwindow->gui->start_x_pane_drag();
2255                 }
2256                 else
2257                 if(get_cursor_y() < 0 && !mwindow->gui->dragging_pane)
2258                 {
2259                         mwindow->gui->start_y_pane_drag();
2260                 }
2261         }
2262
2263         mwindow->gui->handle_pane_drag();
2264
2265         int result = BC_Button::cursor_motion_event();
2266         return result;
2267 }
2268
2269 int PaneButton::button_release_event()
2270 {
2271         mwindow->gui->stop_pane_drag();
2272
2273         int result = BC_Button::button_release_event();
2274         return result;
2275 }
2276
2277
2278 FFMpegToggle::FFMpegToggle(MWindow *mwindow, MButtons *mbuttons, int x, int y)
2279  : BC_Toggle(x, y, mwindow->theme->ffmpeg_toggle, mwindow->preferences->ffmpeg_early_probe)
2280 {
2281         this->mwindow = mwindow;
2282         this->mbuttons = mbuttons;
2283         set_tooltip( mwindow->preferences->ffmpeg_early_probe ?
2284                 _("Try FFMpeg first") : _("Try FFMpeg last"));
2285 }
2286
2287 FFMpegToggle::~FFMpegToggle()
2288 {
2289 }
2290
2291 int FFMpegToggle::handle_event()
2292 {
2293         mwindow->preferences->ffmpeg_early_probe = get_value();
2294         set_tooltip( mwindow->preferences->ffmpeg_early_probe ?
2295                 _("Try FFMpeg first") : _("Try FFMpeg last"));
2296         mwindow->show_warning(&mwindow->preferences->warn_indexes,
2297                 _("Changing the base codecs may require rebuilding indexes."));
2298         return 1;
2299 }
2300
2301