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