fix editpanel wdw lock issues, use undo bracketing to avoid stop playback deadlocks
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mwindowmove.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 "automation.h"
23 #include "autos.h"
24 #include "clip.h"
25 #include "cplayback.h"
26 #include "cwindow.h"
27 #include "cwindowgui.h"
28 #include "edits.h"
29 #include "edl.h"
30 #include "edlsession.h"
31 #include "keyframe.h"
32 #include "labels.h"
33 #include "localsession.h"
34 #include "maincursor.h"
35 #include "mainmenu.h"
36 #include "mainsession.h"
37 #include "mtimebar.h"
38 #include "mwindow.h"
39 #include "mwindowgui.h"
40 #include "patchbay.h"
41 #include "playbackengine.h"
42 #include "plugin.h"
43 #include "pluginset.h"
44 #include "resourcethread.h"
45 #include "samplescroll.h"
46 #include "theme.h"
47 #include "trackcanvas.h"
48 #include "tracks.h"
49 #include "track.h"
50 #include "transportque.h"
51 #include "zoombar.h"
52
53
54 void MWindow::update_plugins()
55 {
56 // Show plugins which are visible and hide plugins which aren't
57 // Update plugin pointers in plugin servers
58 }
59
60
61 int MWindow::expand_sample()
62 {
63         if(gui)
64         {
65                 if(edl->local_session->zoom_sample < 0x100000)
66                 {
67                         edl->local_session->zoom_sample *= 2;
68                         gui->zoombar->sample_zoom->update(edl->local_session->zoom_sample);
69                         zoom_sample(edl->local_session->zoom_sample);
70                 }
71         }
72         return 0;
73 }
74
75 int MWindow::zoom_in_sample()
76 {
77         if(gui)
78         {
79                 if(edl->local_session->zoom_sample > 1)
80                 {
81                         edl->local_session->zoom_sample /= 2;
82                         gui->zoombar->sample_zoom->update(edl->local_session->zoom_sample);
83                         zoom_sample(edl->local_session->zoom_sample);
84                 }
85         }
86         return 0;
87 }
88
89 int MWindow::zoom_sample(int64_t zoom_sample)
90 {
91         CLAMP(zoom_sample, 1, 0x100000);
92         edl->local_session->zoom_sample = zoom_sample;
93         find_cursor();
94
95         TimelinePane *pane = gui->get_focused_pane();
96         samplemovement(edl->local_session->view_start[pane->number], pane->number);
97         return 0;
98 }
99
100 void MWindow::find_cursor()
101 {
102         TimelinePane *pane = gui->get_focused_pane();
103         edl->local_session->view_start[pane->number] =
104                 Units::round((edl->local_session->get_selectionend(1) +
105                 edl->local_session->get_selectionstart(1)) /
106                 2 *
107                 edl->session->sample_rate /
108                 edl->local_session->zoom_sample -
109                 (double)pane->canvas->get_w() /
110                 2);
111
112         if(edl->local_session->view_start[pane->number] < 0)
113                 edl->local_session->view_start[pane->number] = 0;
114 }
115
116
117 void MWindow::fit_selection()
118 {
119         if(EQUIV(edl->local_session->get_selectionstart(1),
120                 edl->local_session->get_selectionend(1)))
121         {
122                 double total_samples = edl->tracks->total_length() *
123                         edl->session->sample_rate;
124                 TimelinePane *pane = gui->get_focused_pane();
125                 for(edl->local_session->zoom_sample = 1;
126                         pane->canvas->get_w() * edl->local_session->zoom_sample < total_samples;
127                         edl->local_session->zoom_sample *= 2)
128                         ;
129         }
130         else
131         {
132                 double total_samples = (edl->local_session->get_selectionend(1) -
133                         edl->local_session->get_selectionstart(1)) *
134                         edl->session->sample_rate;
135                 TimelinePane *pane = gui->get_focused_pane();
136                 for(edl->local_session->zoom_sample = 1;
137                         pane->canvas->get_w() * edl->local_session->zoom_sample < total_samples;
138                         edl->local_session->zoom_sample *= 2)
139                         ;
140         }
141
142         edl->local_session->zoom_sample = MIN(0x100000,
143                 edl->local_session->zoom_sample);
144         zoom_sample(edl->local_session->zoom_sample);
145 }
146
147
148 void MWindow::fit_autos(int all)
149 {
150         float min = 0, max = 0;
151         double start, end;
152
153 // Test all autos
154         if(EQUIV(edl->local_session->get_selectionstart(1),
155                 edl->local_session->get_selectionend(1)))
156         {
157                 start = 0;
158                 end = edl->tracks->total_length();
159         }
160         else
161 // Test autos in highlighting only
162         {
163                 start = edl->local_session->get_selectionstart(1);
164                 end = edl->local_session->get_selectionend(1);
165         }
166
167         int forstart = edl->local_session->zoombar_showautotype;
168         int forend   = edl->local_session->zoombar_showautotype + 1;
169
170         if( all ) {
171                 forstart = 0;
172                 forend   = AUTOGROUPTYPE_COUNT;
173         }
174
175         for (int i = forstart; i < forend; i++)
176         {
177 // Adjust min and max
178                 edl->tracks->get_automation_extents(&min, &max, start, end, i);
179 //printf("MWindow::fit_autos %d %f %f results in ", i, min, max);
180
181                 float range = max - min;
182                 switch (i)
183                 {
184                 case AUTOGROUPTYPE_AUDIO_FADE:
185                         if (range < 1) {
186                                 min = MIN(min, edl->local_session->automation_mins[i]);
187                                 max = MAX(max, edl->local_session->automation_maxs[i]);
188                                 if( min >= max-0.1 ) { min = -80.0; min = 6.0; }
189                         }
190                         break;
191                 case AUTOGROUPTYPE_VIDEO_FADE:
192                         if (range < 1) {
193                                 min = MIN(min, edl->local_session->automation_mins[i]);
194                                 max = MAX(max, edl->local_session->automation_maxs[i]);
195                                 if( min >= max-0.1 ) { min = 0.0; min = 100.0; }
196                         }
197                         break;
198                 case AUTOGROUPTYPE_ZOOM:
199                         if (range < 0.001) {
200                                 min = floor(min*50)/100;
201                                 max = floor(max*200)/100;
202                         }
203                         break;
204                 case AUTOGROUPTYPE_SPEED:
205                         if (range < 0.001) {
206                                 min = floor(min*5)/100;
207                                 max = floor(max*300)/100;
208                         }
209                         break;
210                 case AUTOGROUPTYPE_X:
211                 case AUTOGROUPTYPE_Y:
212                         if (range < 1) {
213                                 float scale = bmin(edl->session->output_w, edl->session->output_h);
214                                 min = floor((min+max)/2) - 0.5*scale;
215                                 max = floor((min+max)/2) + 0.5*scale;
216                         }
217                         break;
218                 }
219 //printf("%f %f\n", min, max);
220                 if (!Automation::autogrouptypes_fixedrange[i])
221                 {
222                         edl->local_session->automation_mins[i] = min;
223                         edl->local_session->automation_maxs[i] = max;
224                 }
225         }
226
227 // Show range in zoombar
228         gui->zoombar->update();
229
230 // Draw
231         gui->draw_overlays(1);
232 }
233
234
235 void MWindow::change_currentautorange(int autogrouptype, int increment, int changemax)
236 {
237         float val;
238         if (changemax) {
239                 val = edl->local_session->automation_maxs[autogrouptype];
240         } else {
241                 val = edl->local_session->automation_mins[autogrouptype];
242         }
243
244         if (increment)
245         {
246                 switch (autogrouptype) {
247                 case AUTOGROUPTYPE_AUDIO_FADE:
248                         val += 2;
249                         break;
250                 case AUTOGROUPTYPE_VIDEO_FADE:
251                         val += 1;
252                         break;
253                 case AUTOGROUPTYPE_ZOOM:
254                 case AUTOGROUPTYPE_SPEED:
255                         if (val == 0)
256                                 val = 0.001;
257                         else
258                                 val = val*2;
259                         break;
260                 case AUTOGROUPTYPE_X:
261                 case AUTOGROUPTYPE_Y:
262                         val = floor(val + 5);
263                         break;
264                 }
265         }
266         else
267         { // decrement
268                 switch (autogrouptype) {
269                 case AUTOGROUPTYPE_AUDIO_FADE:
270                         val -= 2;
271                         break;
272                 case AUTOGROUPTYPE_VIDEO_FADE:
273                         val -= 1;
274                         break;
275                 case AUTOGROUPTYPE_ZOOM:
276                 case AUTOGROUPTYPE_SPEED:
277                         if (val > 0) val = val/2;
278                         break;
279                 case AUTOGROUPTYPE_X:
280                 case AUTOGROUPTYPE_Y:
281                         val = floor(val-5);
282                         break;
283                 }
284         }
285
286         AUTOMATIONVIEWCLAMPS(val, autogrouptype);
287
288         if (changemax) {
289                 if (val > edl->local_session->automation_mins[autogrouptype])
290                         edl->local_session->automation_maxs[autogrouptype] = val;
291         }
292         else
293         {
294                 if (val < edl->local_session->automation_maxs[autogrouptype])
295                         edl->local_session->automation_mins[autogrouptype] = val;
296         }
297 }
298
299
300 void MWindow::expand_autos(int changeall, int domin, int domax)
301 {
302         if (changeall)
303                 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
304                         if (domin) change_currentautorange(i, 1, 0);
305                         if (domax) change_currentautorange(i, 1, 1);
306                 }
307         else
308         {
309                 if (domin) change_currentautorange(edl->local_session->zoombar_showautotype, 1, 0);
310                 if (domax) change_currentautorange(edl->local_session->zoombar_showautotype, 1, 1);
311         }
312         gui->zoombar->update_autozoom();
313         gui->draw_overlays(0);
314         gui->update_patchbay();
315         gui->flash_canvas(1);
316 }
317
318 void MWindow::shrink_autos(int changeall, int domin, int domax)
319 {
320         if (changeall)
321                 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
322                         if (domin) change_currentautorange(i, 0, 0);
323                         if (domax) change_currentautorange(i, 0, 1);
324                 }
325         else
326         {
327                 if (domin) change_currentautorange(edl->local_session->zoombar_showautotype, 0, 0);
328                 if (domax) change_currentautorange(edl->local_session->zoombar_showautotype, 0, 1);
329         }
330         gui->zoombar->update_autozoom();
331         gui->draw_overlays(0);
332         gui->update_patchbay();
333         gui->flash_canvas(1);
334 }
335
336
337 void MWindow::zoom_autos(float min, float max)
338 {
339         int i = edl->local_session->zoombar_showautotype;
340         edl->local_session->automation_mins[i] = min;
341         edl->local_session->automation_maxs[i] = max;
342         gui->zoombar->update_autozoom();
343         gui->draw_overlays(1);
344 }
345
346
347 void MWindow::zoom_amp(int64_t zoom_amp)
348 {
349         edl->local_session->zoom_y = zoom_amp;
350         gui->draw_canvas(0, 0);
351         gui->flash_canvas(0);
352         gui->update_patchbay();
353         gui->flush();
354 }
355
356 void MWindow::zoom_track(int64_t zoom_track)
357 {
358 // scale waveforms
359         edl->local_session->zoom_y = (int64_t)((float)edl->local_session->zoom_y *
360                 zoom_track /
361                 edl->local_session->zoom_track);
362         CLAMP(edl->local_session->zoom_y, MIN_AMP_ZOOM, MAX_AMP_ZOOM);
363
364 // scale tracks
365         double scale = (double)zoom_track / edl->local_session->zoom_track;
366         edl->local_session->zoom_track = zoom_track;
367
368 // shift row position
369         for(int i = 0; i < TOTAL_PANES; i++)
370         {
371                 edl->local_session->track_start[i] *= scale;
372         }
373         edl->tracks->update_y_pixels(theme);
374         gui->draw_trackmovement();
375 //printf("MWindow::zoom_track %d %d\n", edl->local_session->zoom_y, edl->local_session->zoom_track);
376 }
377
378 void MWindow::trackmovement(int offset, int pane_number)
379 {
380         edl->local_session->track_start[pane_number] += offset;
381         if(edl->local_session->track_start[pane_number] < 0)
382                 edl->local_session->track_start[pane_number] = 0;
383
384         if(pane_number == TOP_RIGHT_PANE ||
385                 pane_number == TOP_LEFT_PANE)
386         {
387                 edl->local_session->track_start[TOP_LEFT_PANE] =
388                         edl->local_session->track_start[TOP_RIGHT_PANE] =
389                         edl->local_session->track_start[pane_number];
390         }
391         else
392         if(pane_number == BOTTOM_RIGHT_PANE ||
393                 pane_number == BOTTOM_LEFT_PANE)
394         {
395                 edl->local_session->track_start[BOTTOM_LEFT_PANE] =
396                         edl->local_session->track_start[BOTTOM_RIGHT_PANE] =
397                         edl->local_session->track_start[pane_number];
398         }
399
400
401         edl->tracks->update_y_pixels(theme);
402         gui->draw_trackmovement();
403 }
404
405 void MWindow::move_up(int64_t distance)
406 {
407         TimelinePane *pane = gui->get_focused_pane();
408         if(distance == 0) distance = edl->local_session->zoom_track;
409
410         trackmovement(-distance, pane->number);
411 }
412
413 void MWindow::move_down(int64_t distance)
414 {
415         TimelinePane *pane = gui->get_focused_pane();
416         if(distance == 0) distance = edl->local_session->zoom_track;
417
418         trackmovement(distance, pane->number);
419 }
420
421 int MWindow::goto_end()
422 {
423         TimelinePane *pane = gui->get_focused_pane();
424         int64_t old_view_start = edl->local_session->view_start[pane->number];
425
426         if(edl->tracks->total_length() > (double)pane->canvas->get_w() *
427                 edl->local_session->zoom_sample /
428                 edl->session->sample_rate)
429         {
430                 edl->local_session->view_start[pane->number] =
431                         Units::round(edl->tracks->total_length() *
432                                 edl->session->sample_rate /
433                                 edl->local_session->zoom_sample -
434                                 pane->canvas->get_w() /
435                                 2);
436         }
437         else
438         {
439                 edl->local_session->view_start[pane->number] = 0;
440         }
441
442         if(gui->shift_down())
443         {
444                 edl->local_session->set_selectionend(edl->tracks->total_length());
445         }
446         else
447         {
448                 edl->local_session->set_selectionstart(edl->tracks->total_length());
449                 edl->local_session->set_selectionend(edl->tracks->total_length());
450         }
451
452         if(edl->local_session->view_start[pane->number] != old_view_start)
453         {
454                 samplemovement(edl->local_session->view_start[pane->number], pane->number);
455                 gui->draw_samplemovement();
456         }
457
458         update_plugin_guis();
459
460         gui->update_patchbay();
461         gui->update_cursor();
462         gui->activate_timeline();
463         gui->zoombar->update();
464         gui->update_timebar(1);
465         cwindow->update(1, 0, 0, 0, 1);
466         return 0;
467 }
468
469 int MWindow::goto_start()
470 {
471         TimelinePane *pane = gui->get_focused_pane();
472         int64_t old_view_start = edl->local_session->view_start[pane->number];
473
474         edl->local_session->view_start[pane->number] = 0;
475         if(gui->shift_down())
476         {
477                 edl->local_session->set_selectionstart(0);
478         }
479         else
480         {
481                 edl->local_session->set_selectionstart(0);
482                 edl->local_session->set_selectionend(0);
483         }
484
485         if(edl->local_session->view_start[pane->number] != old_view_start)
486         {
487                 samplemovement(edl->local_session->view_start[pane->number], pane->number);
488                 gui->draw_samplemovement();
489         }
490
491         update_plugin_guis();
492         gui->update_patchbay();
493         gui->update_cursor();
494         gui->activate_timeline();
495         gui->zoombar->update();
496         gui->update_timebar(1);
497         cwindow->update(1, 0, 0, 0, 1);
498         return 0;
499 }
500
501 int MWindow::goto_position(double position)
502 {
503         TimelinePane *pane = gui->get_focused_pane();
504         int64_t old_view_start = edl->local_session->view_start[pane->number];
505         edl->local_session->set_selectionstart(position);
506         edl->local_session->set_selectionend(position);
507         find_cursor();
508         int64_t new_view_start = edl->local_session->view_start[pane->number];
509         if(new_view_start != old_view_start)
510                 samplemovement(new_view_start, pane->number);
511         update_plugin_guis();
512         gui->update_patchbay();
513         gui->update_cursor();
514         gui->activate_timeline();
515         gui->zoombar->update();
516         gui->update_timebar(1);
517         cwindow->update(1, 0, 0, 0, 1);
518         return 0;
519 }
520
521 int MWindow::samplemovement(int64_t view_start, int pane_number)
522 {
523         if( view_start < 0 ) view_start = 0;
524         edl->local_session->view_start[pane_number] = view_start;
525         if(edl->local_session->view_start[pane_number] < 0)
526                 edl->local_session->view_start[pane_number] = 0;
527
528         if(pane_number == TOP_LEFT_PANE ||
529                 pane_number == BOTTOM_LEFT_PANE)
530         {
531                 edl->local_session->view_start[TOP_LEFT_PANE] =
532                         edl->local_session->view_start[BOTTOM_LEFT_PANE] =
533                         edl->local_session->view_start[pane_number];
534         }
535         else
536         {
537                 edl->local_session->view_start[TOP_RIGHT_PANE] =
538                         edl->local_session->view_start[BOTTOM_RIGHT_PANE] =
539                         edl->local_session->view_start[pane_number];
540         }
541
542         gui->draw_samplemovement();
543
544         return 0;
545 }
546
547 int MWindow::move_left(int64_t distance)
548 {
549         TimelinePane *pane = gui->get_focused_pane();
550         if(!distance)
551                 distance = pane->canvas->get_w() /
552                         10;
553         edl->local_session->view_start[pane->number] -= distance;
554         samplemovement(edl->local_session->view_start[pane->number],
555                 pane->number);
556         return 0;
557 }
558
559 int MWindow::move_right(int64_t distance)
560 {
561         TimelinePane *pane = gui->get_focused_pane();
562         if(!distance)
563                 distance = pane->canvas->get_w() /
564                         10;
565         edl->local_session->view_start[pane->number] += distance;
566         samplemovement(edl->local_session->view_start[pane->number],
567                 pane->number);
568         return 0;
569 }
570
571 void MWindow::select_all()
572 {
573         if( edl->local_session->get_selectionstart(1) == 0 &&
574             edl->local_session->get_selectionend(1) == edl->tracks->total_length() )
575                 edl->local_session->set_selectionend(0);
576         else {
577                 edl->local_session->set_selectionstart(0);
578                 edl->local_session->set_selectionend(edl->tracks->total_length());
579         }
580         gui->update(0, NORMAL_DRAW, 1, 1, 0, 1, 0);
581         gui->activate_timeline();
582         cwindow->update(1, 0, 0, 0, 1);
583         update_plugin_guis();
584 }
585
586 int MWindow::next_label(int shift_down)
587 {
588         double position = edl->local_session->get_selectionend(1);
589         double total_length = edl->tracks->total_length();
590         Label *current = edl->labels->next_label(position);
591         double new_position = current ? current->position : total_length;
592 // last playback endpoints as fake label positions
593         double playback_start = edl->local_session->playback_start;
594         double playback_end = edl->local_session->playback_end;
595         if( playback_start > position && playback_start < new_position )
596                 new_position = playback_start;
597         else if( playback_end > position && playback_end < new_position )
598                 new_position = playback_end;
599         if( new_position > total_length )
600                 new_position = total_length;
601         edl->local_session->set_selectionend(new_position);
602 //printf("MWindow::next_edit_handle %d\n", shift_down);
603         if( !shift_down )
604                 edl->local_session->set_selectionstart(new_position);
605         return find_selection(new_position);
606 }
607
608 int MWindow::prev_label(int shift_down)
609 {
610         double position = edl->local_session->get_selectionstart(1);
611         Label *current = edl->labels->prev_label(position);
612         double new_position = current ? current->position : 0;
613 // last playback endpoints as fake label positions
614         double playback_start = edl->local_session->playback_start;
615         double playback_end = edl->local_session->playback_end;
616         if( playback_end < position && playback_end > new_position )
617                 new_position = playback_end;
618         else if( playback_start < position && playback_start > new_position )
619                 new_position = playback_start;
620         if( new_position < 0 )
621                 new_position = 0;
622         edl->local_session->set_selectionstart(new_position);
623 //printf("MWindow::next_edit_handle %d\n", shift_down);
624         if( !shift_down )
625                 edl->local_session->set_selectionend(new_position);
626         return find_selection(new_position);
627 }
628
629 int MWindow::next_edit_handle(int shift_down)
630 {
631         double position = edl->local_session->get_selectionend(1);
632         double new_position = edl->next_edit(position);
633         double total_length = edl->tracks->total_length();
634         if( new_position >= total_length )
635                 new_position = total_length;
636         edl->local_session->set_selectionend(new_position);
637 //printf("MWindow::next_edit_handle %d\n", shift_down);
638         if( !shift_down )
639                 edl->local_session->set_selectionstart(new_position);
640         return find_selection(new_position);
641 }
642
643 int MWindow::prev_edit_handle(int shift_down)
644 {
645         double position = edl->local_session->get_selectionstart(1);
646         double new_position = edl->prev_edit(position);
647         if( new_position < 0 )
648                 new_position = 0;
649         edl->local_session->set_selectionstart(new_position);
650         if( !shift_down )
651                 edl->local_session->set_selectionend(new_position);
652         return find_selection(new_position);
653 }
654
655 int MWindow::nearest_plugin_keyframe(int shift_down, int dir)
656 {
657         KeyFrame *keyframe = 0;
658         double start = edl->local_session->get_selectionstart(1);
659         double end = edl->local_session->get_selectionend(1);
660         double position = dir == PLAY_FORWARD ? end : start, new_position = 0;
661         for( Track *track=edl->tracks->first; track; track=track->next ) {
662                 if( !track->record ) continue;
663                 for( int i=0; i<track->plugin_set.size(); ++i ) {
664                         PluginSet *plugin_set = track->plugin_set[i];
665                         int64_t pos = track->to_units(position, 0);
666                         KeyFrame *key = plugin_set->nearest_keyframe(pos, dir);
667                         if( !key ) continue;
668                         double key_position = track->from_units(key->position);
669                         if( keyframe && (dir == PLAY_FORWARD ?
670                                 key_position >= new_position :
671                                 new_position >= key_position ) ) continue;
672                         keyframe = key;  new_position = key_position;
673                 }
674         }
675
676         new_position = keyframe ?
677                 keyframe->autos->track->from_units(keyframe->position) :
678                 dir == PLAY_FORWARD ? edl->tracks->total_length() : 0;
679
680         if( !shift_down )
681                 start = end = new_position;
682         else if( dir == PLAY_FORWARD )
683                 end = new_position;
684         else
685                 start = new_position;
686
687         edl->local_session->set_selectionstart(start);
688         edl->local_session->set_selectionend(end);
689         return find_selection(new_position);
690 }
691
692 int MWindow::find_selection(double position, int scroll_display)
693 {
694         update_plugin_guis();
695         TimelinePane *pane = gui->get_focused_pane();
696         double pixel_zoom = (double)edl->session->sample_rate / edl->local_session->zoom_sample;
697         if( !scroll_display ) {
698                 double timeline_start = edl->local_session->view_start[pane->number] / pixel_zoom;
699                 double timeline_end = timeline_start + pane->canvas->time_visible();
700                 if( position >= timeline_end || position < timeline_start )
701                         scroll_display = 1;
702         }
703         if( scroll_display ) {
704                 samplemovement((int64_t)(position * pixel_zoom - pane->canvas->get_w() / 2), pane->number);
705                 cwindow->update(1, 0, 0, 0, 0);
706         }
707         else {
708                 gui->update_patchbay();
709                 gui->update_timebar(0);
710                 gui->hide_cursor(0);
711                 gui->draw_cursor(0);
712                 gui->zoombar->update();
713                 gui->flash_canvas(1);
714                 cwindow->update(1, 0, 0, 0, 1);
715         }
716         return 0;
717 }
718
719 double MWindow::get_position()
720 {
721         return edl->local_session->get_selectionstart(1);
722 }
723
724 void MWindow::set_position(double position)
725 {
726         if( position != get_position() ) {
727                 if( position < 0 ) position = 0;
728                 edl->local_session->set_selectionstart(position);
729                 edl->local_session->set_selectionend(position);
730                 gui->lock_window();
731                 find_cursor();
732                 gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 0);
733                 gui->unlock_window();
734                 cwindow->update(1, 0, 0, 0, 0);
735         }
736 }
737
738
739 int MWindow::expand_y()
740 {
741         int result = edl->local_session->zoom_y * 2;
742         result = MIN(result, MAX_AMP_ZOOM);
743         zoom_amp(result);
744         gui->zoombar->update();
745         return 0;
746 }
747
748 int MWindow::zoom_in_y()
749 {
750         int result = edl->local_session->zoom_y / 2;
751         result = MAX(result, MIN_AMP_ZOOM);
752         zoom_amp(result);
753         gui->zoombar->update();
754         return 0;
755 }
756
757 int MWindow::expand_t()
758 {
759         int result = edl->local_session->zoom_track * 2;
760         result = MIN(result, MAX_TRACK_ZOOM);
761         zoom_track(result);
762         gui->zoombar->update();
763         return 0;
764 }
765
766 int MWindow::zoom_in_t()
767 {
768         int result = edl->local_session->zoom_track / 2;
769         result = MAX(result, MIN_TRACK_ZOOM);
770         zoom_track(result);
771         gui->zoombar->update();
772         return 0;
773 }
774
775 void MWindow::split_x()
776 {
777         gui->resource_thread->stop_draw(1);
778
779         if(gui->pane[TOP_RIGHT_PANE])
780         {
781                 gui->delete_x_pane(theme->mcanvas_w);
782                 edl->local_session->x_pane = -1;
783         }
784         else
785         {
786                 gui->create_x_pane(theme->mcanvas_w / 2);
787                 edl->local_session->x_pane = theme->mcanvas_w / 2;
788         }
789
790         gui->mainmenu->update_toggles(0);
791         gui->update_pane_dividers();
792         gui->update_cursor();
793         gui->draw_samplemovement();
794 // required to get new widgets to appear
795         gui->show_window();
796
797         gui->resource_thread->start_draw();
798 }
799
800 void MWindow::split_y()
801 {
802         gui->resource_thread->stop_draw(1);
803         if(gui->pane[BOTTOM_LEFT_PANE])
804         {
805                 gui->delete_y_pane(theme->mcanvas_h);
806                 edl->local_session->y_pane = -1;
807         }
808         else
809         {
810                 gui->create_y_pane(theme->mcanvas_h / 2);
811                 edl->local_session->y_pane = theme->mcanvas_h / 2;
812         }
813
814         gui->mainmenu->update_toggles(0);
815         gui->update_pane_dividers();
816         gui->update_cursor();
817         gui->draw_trackmovement();
818 // required to get new widgets to appear
819         gui->show_window();
820         gui->resource_thread->start_draw();
821 }
822