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