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