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