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