1 #include "automation.h"
5 #include "cwindowgui.h"
8 #include "edlsession.h"
10 #include "localsession.h"
11 #include "maincursor.h"
12 #include "mainsession.h"
15 #include "mwindowgui.h"
17 #include "playbackengine.h"
19 #include "samplescroll.h"
20 #include "trackcanvas.h"
22 #include "transportque.h"
26 void MWindow::update_plugins()
28 // Show plugins which are visible and hide plugins which aren't
29 // Update plugin pointers in plugin servers
33 int MWindow::expand_sample(double fixed_sample)
37 if(edl->local_session->zoom_sample < 0x100000)
39 int64_t new_zoom_sample = edl->local_session->zoom_sample * 2;
45 double viewstart_position = (double)edl->local_session->view_start *
46 edl->local_session->zoom_sample /
47 edl->session->sample_rate * 2 - fixed_sample;
48 view_start = Units::round(viewstart_position *
49 edl->session->sample_rate /
53 zoom_sample(new_zoom_sample, view_start);
59 int MWindow::zoom_in_sample(double fixed_sample)
63 if(edl->local_session->zoom_sample > 1)
65 int64_t new_zoom_sample = edl->local_session->zoom_sample / 2;
71 double viewstart_position = (double)edl->local_session->view_start *
72 edl->local_session->zoom_sample /
73 edl->session->sample_rate;
74 viewstart_position = viewstart_position + (fixed_sample - viewstart_position) / 2;
76 view_start = Units::round(viewstart_position *
77 edl->session->sample_rate /
81 zoom_sample(new_zoom_sample, view_start);
87 int MWindow::zoom_sample(int64_t zoom_sample, int64_t view_start)
89 CLIP(zoom_sample, 1, 0x100000);
90 edl->local_session->zoom_sample = zoom_sample;
94 edl->local_session->view_start = view_start;
96 gui->get_scrollbars();
98 if(!gui->samplescroll) edl->local_session->view_start = 0;
99 samplemovement(edl->local_session->view_start);
100 gui->zoombar->sample_zoom->update(zoom_sample);
104 void MWindow::find_cursor()
106 // if((edl->local_session->selectionend >
107 // (double)gui->canvas->get_w() *
108 // edl->local_session->zoom_sample /
109 // edl->session->sample_rate) ||
110 // (edl->local_session->selectionstart >
111 // (double)gui->canvas->get_w() *
112 // edl->local_session->zoom_sample /
113 // edl->session->sample_rate))
115 edl->local_session->view_start =
116 Units::round((edl->local_session->get_selectionend(1) +
117 edl->local_session->get_selectionstart(1)) /
119 edl->session->sample_rate /
120 edl->local_session->zoom_sample -
121 (double)gui->canvas->get_w() /
125 // edl->local_session->view_start = 0;
127 //printf("MWindow::find_cursor %f\n", edl->local_session->view_start);
128 if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
132 void MWindow::fit_selection()
134 if(EQUIV(edl->local_session->get_selectionstart(1),
135 edl->local_session->get_selectionend(1)))
137 double total_samples = edl->tracks->total_length() *
138 edl->session->sample_rate;
139 for(edl->local_session->zoom_sample = 1;
140 gui->canvas->get_w() * edl->local_session->zoom_sample < total_samples;
141 edl->local_session->zoom_sample *= 2)
146 double total_samples = (edl->local_session->get_selectionend(1) -
147 edl->local_session->get_selectionstart(1)) *
148 edl->session->sample_rate;
149 for(edl->local_session->zoom_sample = 1;
150 gui->canvas->get_w() * edl->local_session->zoom_sample < total_samples;
151 edl->local_session->zoom_sample *= 2)
155 edl->local_session->zoom_sample = MIN(0x100000,
156 edl->local_session->zoom_sample);
157 zoom_sample(edl->local_session->zoom_sample);
161 void MWindow::fit_autos(int doall)
163 float min = 0, max = 0;
167 if(EQUIV(edl->local_session->get_selectionstart(1),
168 edl->local_session->get_selectionend(1)))
171 end = edl->tracks->total_length();
174 // Test autos in highlighting only
176 start = edl->local_session->get_selectionstart(1);
177 end = edl->local_session->get_selectionend(1);
180 int forstart = edl->local_session->zoombar_showautotype;
181 int forend = edl->local_session->zoombar_showautotype + 1;
185 forend = AUTOGROUPTYPE_COUNT;
188 for (int i = forstart; i < forend; i++)
190 // Adjust min and max
191 edl->tracks->get_automation_extents(&min, &max, start, end, i);
192 //printf("MWindow::fit_autos %d %f %f results in ", i, min, max);
194 float range = max - min;
197 case AUTOGROUPTYPE_AUDIO_FADE:
198 case AUTOGROUPTYPE_VIDEO_FADE:
200 min = MIN(min, edl->local_session->automation_mins[i]);
201 max = MAX(max, edl->local_session->automation_maxs[i]);
204 case AUTOGROUPTYPE_ZOOM:
206 min = floor(min*50)/100;
207 max = floor(max*200)/100;
210 case AUTOGROUPTYPE_X:
211 case AUTOGROUPTYPE_Y:
213 min = floor((min+max)/2) - 50;
214 max = floor((min+max)/2) + 50;
218 //printf("%f %f\n", min, max);
219 if (!Automation::autogrouptypes_fixedrange[i])
221 edl->local_session->automation_mins[i] = min;
222 edl->local_session->automation_maxs[i] = max;
226 // Show range in zoombar
227 gui->zoombar->update();
230 gui->canvas->draw_overlays();
231 gui->canvas->flash();
235 void MWindow::change_currentautorange(int autogrouptype, int increment, int changemax) {
238 val = edl->local_session->automation_maxs[autogrouptype];
240 val = edl->local_session->automation_mins[autogrouptype];
245 switch (autogrouptype) {
246 case AUTOGROUPTYPE_AUDIO_FADE:
249 case AUTOGROUPTYPE_VIDEO_FADE:
252 case AUTOGROUPTYPE_ZOOM:
258 case AUTOGROUPTYPE_X:
259 case AUTOGROUPTYPE_Y:
260 val = floor(val + 5);
266 switch (autogrouptype) {
267 case AUTOGROUPTYPE_AUDIO_FADE:
270 case AUTOGROUPTYPE_VIDEO_FADE:
273 case AUTOGROUPTYPE_ZOOM:
274 if (val > 0) val = val/2;
276 case AUTOGROUPTYPE_X:
277 case AUTOGROUPTYPE_Y:
283 AUTOMATIONVIEWCLAMPS(val, autogrouptype);
286 if (val > edl->local_session->automation_mins[autogrouptype])
287 edl->local_session->automation_maxs[autogrouptype] = val;
291 if (val < edl->local_session->automation_maxs[autogrouptype])
292 edl->local_session->automation_mins[autogrouptype] = val;
297 void MWindow::expand_autos(int changeall, int domin, int domax)
300 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
301 if (domin) change_currentautorange(i, 1, 0);
302 if (domax) change_currentautorange(i, 1, 1);
306 if (domin) change_currentautorange(edl->local_session->zoombar_showautotype, 1, 0);
307 if (domax) change_currentautorange(edl->local_session->zoombar_showautotype, 1, 1);
309 gui->zoombar->update_autozoom();
310 gui->canvas->draw_overlays();
311 gui->patchbay->update();
312 gui->canvas->flash();
315 void MWindow::shrink_autos(int changeall, int domin, int domax)
318 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
319 if (domin) change_currentautorange(i, 0, 0);
320 if (domax) change_currentautorange(i, 0, 1);
324 if (domin) change_currentautorange(edl->local_session->zoombar_showautotype, 0, 0);
325 if (domax) change_currentautorange(edl->local_session->zoombar_showautotype, 0, 1);
327 gui->zoombar->update_autozoom();
328 gui->canvas->draw_overlays();
329 gui->patchbay->update();
330 gui->canvas->flash();
334 void MWindow::zoom_amp(int64_t zoom_amp)
336 edl->local_session->zoom_y = zoom_amp;
337 gui->canvas->draw(0, 0);
338 gui->canvas->flash();
339 gui->patchbay->update();
343 void MWindow::zoom_track(int64_t zoom_track)
345 edl->local_session->zoom_y = (int64_t)((float)edl->local_session->zoom_y *
347 edl->local_session->zoom_track);
348 CLAMP(edl->local_session->zoom_y, MIN_AMP_ZOOM, MAX_AMP_ZOOM);
349 edl->local_session->zoom_track = zoom_track;
350 trackmovement(edl->local_session->track_start);
351 //printf("MWindow::zoom_track %d %d\n", edl->local_session->zoom_y, edl->local_session->zoom_track);
354 void MWindow::trackmovement(int track_start)
356 edl->local_session->track_start = track_start;
357 if(edl->local_session->track_start < 0) edl->local_session->track_start = 0;
358 edl->tracks->update_y_pixels(theme);
359 gui->get_scrollbars();
360 gui->canvas->draw(0, 0);
361 gui->patchbay->update();
362 gui->canvas->flash();
366 void MWindow::move_up(int64_t distance)
368 if(!gui->trackscroll) return;
369 if(distance == 0) distance = edl->local_session->zoom_track;
370 edl->local_session->track_start -= distance;
371 trackmovement(edl->local_session->track_start);
374 void MWindow::move_down(int64_t distance)
376 if(!gui->trackscroll) return;
377 if(distance == 0) distance = edl->local_session->zoom_track;
378 edl->local_session->track_start += distance;
379 trackmovement(edl->local_session->track_start);
382 int MWindow::goto_end()
384 int64_t old_view_start = edl->local_session->view_start;
386 if(edl->tracks->total_length() > (double)gui->canvas->get_w() *
387 edl->local_session->zoom_sample /
388 edl->session->sample_rate)
390 edl->local_session->view_start =
391 Units::round(edl->tracks->total_length() *
392 edl->session->sample_rate /
393 edl->local_session->zoom_sample -
394 gui->canvas->get_w() /
399 edl->local_session->view_start = 0;
402 if(gui->shift_down())
404 edl->local_session->set_selectionend(edl->tracks->total_length());
408 edl->local_session->set_selectionstart(edl->tracks->total_length());
409 edl->local_session->set_selectionend(edl->tracks->total_length());
412 if(edl->local_session->view_start != old_view_start)
413 samplemovement(edl->local_session->view_start);
415 update_plugin_guis();
416 gui->patchbay->update();
417 gui->cursor->update();
418 gui->canvas->activate();
419 gui->zoombar->update();
420 cwindow->update(1, 0, 0, 0, 0);
424 int MWindow::goto_start()
426 int64_t old_view_start = edl->local_session->view_start;
428 edl->local_session->view_start = 0;
429 if(gui->shift_down())
431 edl->local_session->set_selectionstart(0);
435 edl->local_session->set_selectionstart(0);
436 edl->local_session->set_selectionend(0);
439 if(edl->local_session->view_start != old_view_start)
440 samplemovement(edl->local_session->view_start);
442 update_plugin_guis();
443 gui->patchbay->update();
444 gui->cursor->update();
445 gui->canvas->activate();
446 gui->zoombar->update();
447 cwindow->update(1, 0, 0, 0, 0);
451 int MWindow::samplemovement(int64_t view_start)
453 edl->local_session->view_start = view_start;
454 if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
457 gui->canvas->flash();
458 gui->timebar->update();
459 gui->zoombar->update();
461 if(gui->samplescroll) gui->samplescroll->set_position();
465 int MWindow::move_left(int64_t distance)
468 distance = gui->canvas->get_w() /
470 edl->local_session->view_start -= distance;
471 if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
472 samplemovement(edl->local_session->view_start);
476 int MWindow::move_right(int64_t distance)
479 distance = gui->canvas->get_w() /
481 edl->local_session->view_start += distance;
482 samplemovement(edl->local_session->view_start);
486 void MWindow::select_all()
488 edl->local_session->set_selectionstart(0);
489 edl->local_session->set_selectionend(edl->tracks->total_length());
490 gui->update(0, 1, 1, 1, 0, 1, 0);
491 gui->canvas->activate();
492 cwindow->update(1, 0, 0);
495 int MWindow::next_label(int shift_down)
497 Label *current = edl->labels->next_label(
498 edl->local_session->get_selectionstart(1));
503 edl->local_session->set_selectionend(current->position);
505 edl->local_session->set_selectionstart(
506 edl->local_session->get_selectionend(1));
508 update_plugin_guis();
509 if(edl->local_session->get_selectionend(1) >=
510 (double)edl->local_session->view_start *
511 edl->local_session->zoom_sample /
512 edl->session->sample_rate +
513 gui->canvas->time_visible() ||
514 edl->local_session->get_selectionend(1) < (double)edl->local_session->view_start *
515 edl->local_session->zoom_sample /
516 edl->session->sample_rate)
518 samplemovement((int64_t)(edl->local_session->get_selectionend(1) *
519 edl->session->sample_rate /
520 edl->local_session->zoom_sample -
521 gui->canvas->get_w() /
523 cwindow->update(1, 0, 0, 0, 0);
527 gui->patchbay->update();
528 gui->timebar->update();
529 gui->cursor->hide(0);
530 gui->cursor->draw(1);
531 gui->zoombar->update();
532 gui->canvas->flash();
534 cwindow->update(1, 0, 0);
544 int MWindow::prev_label(int shift_down)
546 Label *current = edl->labels->prev_label(
547 edl->local_session->get_selectionstart(1));;
551 edl->local_session->set_selectionstart(current->position);
553 edl->local_session->set_selectionend(edl->local_session->get_selectionstart(1));
555 update_plugin_guis();
556 // Scroll the display
557 if(edl->local_session->get_selectionstart(1) >= edl->local_session->view_start *
558 edl->local_session->zoom_sample /
559 edl->session->sample_rate +
560 gui->canvas->time_visible()
562 edl->local_session->get_selectionstart(1) < edl->local_session->view_start *
563 edl->local_session->zoom_sample /
564 edl->session->sample_rate)
566 samplemovement((int64_t)(edl->local_session->get_selectionstart(1) *
567 edl->session->sample_rate /
568 edl->local_session->zoom_sample -
569 gui->canvas->get_w() /
571 cwindow->update(1, 0, 0, 0, 0);
574 // Don't scroll the display
576 gui->patchbay->update();
577 gui->timebar->update();
578 gui->cursor->hide(0);
579 gui->cursor->draw(1);
580 gui->zoombar->update();
581 gui->canvas->flash();
583 cwindow->update(1, 0, 0);
598 int MWindow::next_edit_handle(int shift_down)
600 double position = edl->local_session->get_selectionend(1);
601 Units::fix_double(&position);
602 double new_position = INFINITY;
603 // Test for edit handles after cursor position
604 for (Track *track = edl->tracks->first; track; track = track->next)
608 for (Edit *edit = track->edits->first; edit; edit = edit->next)
610 double edit_end = track->from_units(edit->startproject + edit->length);
611 Units::fix_double(&edit_end);
612 if (edit_end > position && edit_end < new_position)
613 new_position = edit_end;
618 if(new_position != INFINITY)
621 edl->local_session->set_selectionend(new_position);
622 printf("MWindow::next_edit_handle %d\n", shift_down);
624 edl->local_session->set_selectionstart(
625 edl->local_session->get_selectionend(1));
627 update_plugin_guis();
628 if(edl->local_session->get_selectionend(1) >=
629 (double)edl->local_session->view_start *
630 edl->local_session->zoom_sample /
631 edl->session->sample_rate +
632 gui->canvas->time_visible() ||
633 edl->local_session->get_selectionend(1) < (double)edl->local_session->view_start *
634 edl->local_session->zoom_sample /
635 edl->session->sample_rate)
637 samplemovement((int64_t)(edl->local_session->get_selectionend(1) *
638 edl->session->sample_rate /
639 edl->local_session->zoom_sample -
640 gui->canvas->get_w() /
642 cwindow->update(1, 0, 0, 0, 0);
646 gui->patchbay->update();
647 gui->timebar->update();
648 gui->cursor->hide(0);
649 gui->cursor->draw(1);
650 gui->zoombar->update();
651 gui->canvas->flash();
653 cwindow->update(1, 0, 0);
663 int MWindow::prev_edit_handle(int shift_down)
665 double position = edl->local_session->get_selectionstart(1);
666 double new_position = -1;
667 Units::fix_double(&position);
668 // Test for edit handles before cursor position
669 for (Track *track = edl->tracks->first; track; track = track->next)
673 for (Edit *edit = track->edits->first; edit; edit = edit->next)
675 double edit_end = track->from_units(edit->startproject);
676 Units::fix_double(&edit_end);
677 if (edit_end < position && edit_end > new_position)
678 new_position = edit_end;
683 if(new_position != -1)
686 edl->local_session->set_selectionstart(new_position);
687 printf("MWindow::next_edit_handle %d\n", shift_down);
689 edl->local_session->set_selectionend(edl->local_session->get_selectionstart(1));
691 update_plugin_guis();
692 // Scroll the display
693 if(edl->local_session->get_selectionstart(1) >= edl->local_session->view_start *
694 edl->local_session->zoom_sample /
695 edl->session->sample_rate +
696 gui->canvas->time_visible()
698 edl->local_session->get_selectionstart(1) < edl->local_session->view_start *
699 edl->local_session->zoom_sample /
700 edl->session->sample_rate)
702 samplemovement((int64_t)(edl->local_session->get_selectionstart(1) *
703 edl->session->sample_rate /
704 edl->local_session->zoom_sample -
705 gui->canvas->get_w() /
707 cwindow->update(1, 0, 0, 0, 0);
710 // Don't scroll the display
712 gui->patchbay->update();
713 gui->timebar->update();
714 gui->cursor->hide(0);
715 gui->cursor->draw(1);
716 gui->zoombar->update();
717 gui->canvas->flash();
719 cwindow->update(1, 0, 0);
736 int MWindow::expand_y()
738 int result = edl->local_session->zoom_y * 2;
739 result = MIN(result, MAX_AMP_ZOOM);
741 gui->zoombar->update();
745 int MWindow::zoom_in_y()
747 int result = edl->local_session->zoom_y / 2;
748 result = MAX(result, MIN_AMP_ZOOM);
750 gui->zoombar->update();
754 int MWindow::expand_t()
756 int result = edl->local_session->zoom_track * 2;
757 result = MIN(result, MAX_TRACK_ZOOM);
759 gui->zoombar->update();
763 int MWindow::zoom_in_t()
765 int result = edl->local_session->zoom_track / 2;
766 result = MAX(result, MIN_TRACK_ZOOM);
768 gui->zoombar->update();