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