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, 1);
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, 1);
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 gui->patchbay->update();
510 if(edl->local_session->get_selectionend(1) >=
511 (double)edl->local_session->view_start *
512 edl->local_session->zoom_sample /
513 edl->session->sample_rate +
514 gui->canvas->time_visible() ||
515 edl->local_session->get_selectionend(1) < (double)edl->local_session->view_start *
516 edl->local_session->zoom_sample /
517 edl->session->sample_rate)
519 samplemovement((int64_t)(edl->local_session->get_selectionend(1) *
520 edl->session->sample_rate /
521 edl->local_session->zoom_sample -
522 gui->canvas->get_w() /
527 gui->timebar->update();
528 gui->cursor->hide(0);
529 gui->cursor->draw(1);
530 gui->zoombar->update();
531 gui->canvas->flash();
534 cwindow->update(1, 0, 0, 0, 1);
543 int MWindow::prev_label(int shift_down)
545 Label *current = edl->labels->prev_label(
546 edl->local_session->get_selectionstart(1));;
550 edl->local_session->set_selectionstart(current->position);
552 edl->local_session->set_selectionend(edl->local_session->get_selectionstart(1));
554 update_plugin_guis();
555 gui->patchbay->update();
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() /
573 // Don't scroll the display
575 gui->timebar->update();
576 gui->cursor->hide(0);
577 gui->cursor->draw(1);
578 gui->zoombar->update();
579 gui->canvas->flash();
582 cwindow->update(1, 0, 0, 0, 1);
596 int MWindow::next_edit_handle(int shift_down)
598 double position = edl->local_session->get_selectionend(1);
599 Units::fix_double(&position);
600 double new_position = INFINITY;
601 // Test for edit handles after cursor position
602 for (Track *track = edl->tracks->first; track; track = track->next)
606 for (Edit *edit = track->edits->first; edit; edit = edit->next)
608 double edit_end = track->from_units(edit->startproject + edit->length);
609 Units::fix_double(&edit_end);
610 if (edit_end > position && edit_end < new_position)
611 new_position = edit_end;
616 if(new_position != INFINITY)
619 edl->local_session->set_selectionend(new_position);
620 printf("MWindow::next_edit_handle %d\n", shift_down);
622 edl->local_session->set_selectionstart(
623 edl->local_session->get_selectionend(1));
625 update_plugin_guis();
626 gui->patchbay->update();
627 if(edl->local_session->get_selectionend(1) >=
628 (double)edl->local_session->view_start *
629 edl->local_session->zoom_sample /
630 edl->session->sample_rate +
631 gui->canvas->time_visible() ||
632 edl->local_session->get_selectionend(1) < (double)edl->local_session->view_start *
633 edl->local_session->zoom_sample /
634 edl->session->sample_rate)
636 samplemovement((int64_t)(edl->local_session->get_selectionend(1) *
637 edl->session->sample_rate /
638 edl->local_session->zoom_sample -
639 gui->canvas->get_w() /
644 gui->timebar->update();
645 gui->cursor->hide(0);
646 gui->cursor->draw(1);
647 gui->zoombar->update();
648 gui->canvas->flash();
651 cwindow->update(1, 0, 0, 0, 1);
660 int MWindow::prev_edit_handle(int shift_down)
662 double position = edl->local_session->get_selectionstart(1);
663 double new_position = -1;
664 Units::fix_double(&position);
665 // Test for edit handles before cursor position
666 for (Track *track = edl->tracks->first; track; track = track->next)
670 for (Edit *edit = track->edits->first; edit; edit = edit->next)
672 double edit_end = track->from_units(edit->startproject);
673 Units::fix_double(&edit_end);
674 if (edit_end < position && edit_end > new_position)
675 new_position = edit_end;
680 if(new_position != -1)
683 edl->local_session->set_selectionstart(new_position);
684 printf("MWindow::next_edit_handle %d\n", shift_down);
686 edl->local_session->set_selectionend(edl->local_session->get_selectionstart(1));
688 update_plugin_guis();
689 gui->patchbay->update();
690 // Scroll the display
691 if(edl->local_session->get_selectionstart(1) >= edl->local_session->view_start *
692 edl->local_session->zoom_sample /
693 edl->session->sample_rate +
694 gui->canvas->time_visible()
696 edl->local_session->get_selectionstart(1) < edl->local_session->view_start *
697 edl->local_session->zoom_sample /
698 edl->session->sample_rate)
700 samplemovement((int64_t)(edl->local_session->get_selectionstart(1) *
701 edl->session->sample_rate /
702 edl->local_session->zoom_sample -
703 gui->canvas->get_w() /
707 // Don't scroll the display
709 gui->timebar->update();
710 gui->cursor->hide(0);
711 gui->cursor->draw(1);
712 gui->zoombar->update();
713 gui->canvas->flash();
716 cwindow->update(1, 0, 0, 0, 1);
732 int MWindow::expand_y()
734 int result = edl->local_session->zoom_y * 2;
735 result = MIN(result, MAX_AMP_ZOOM);
737 gui->zoombar->update();
741 int MWindow::zoom_in_y()
743 int result = edl->local_session->zoom_y / 2;
744 result = MAX(result, MIN_AMP_ZOOM);
746 gui->zoombar->update();
750 int MWindow::expand_t()
752 int result = edl->local_session->zoom_track * 2;
753 result = MIN(result, MAX_TRACK_ZOOM);
755 gui->zoombar->update();
759 int MWindow::zoom_in_t()
761 int result = edl->local_session->zoom_track / 2;
762 result = MAX(result, MIN_TRACK_ZOOM);
764 gui->zoombar->update();
771 // c-file-style: "linux"