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