4 #include "cwindowgui.h"
6 #include "edlsession.h"
8 #include "localsession.h"
9 #include "maincursor.h"
10 #include "mainsession.h"
13 #include "mwindowgui.h"
15 #include "playbackengine.h"
17 #include "samplescroll.h"
18 #include "trackcanvas.h"
20 #include "transportque.h"
24 void MWindow::update_plugins()
26 // Show plugins which are visible and hide plugins which aren't
27 // Update plugin pointers in plugin servers
31 int MWindow::expand_sample(double fixed_sample)
35 if(edl->local_session->zoom_sample < 0x100000)
38 int64_t new_zoom_sample = edl->local_session->zoom_sample * 2;
44 double viewstart_position = (double)edl->local_session->view_start *
45 edl->local_session->zoom_sample /
46 edl->session->sample_rate * 2 - fixed_sample;
47 view_start = Units::round(viewstart_position *
48 edl->session->sample_rate /
52 zoom_sample(new_zoom_sample, view_start);
58 int MWindow::zoom_in_sample(double fixed_sample)
62 if(edl->local_session->zoom_sample > 1)
64 int64_t new_zoom_sample = edl->local_session->zoom_sample / 2;
70 double viewstart_position = (double)edl->local_session->view_start *
71 edl->local_session->zoom_sample /
72 edl->session->sample_rate;
73 viewstart_position = viewstart_position + (fixed_sample - viewstart_position) / 2;
75 view_start = Units::round(viewstart_position *
76 edl->session->sample_rate /
80 zoom_sample(new_zoom_sample, view_start);
86 int MWindow::zoom_sample(int64_t zoom_sample, int64_t view_start)
88 CLIP(zoom_sample, 1, 0x100000);
89 edl->local_session->zoom_sample = zoom_sample;
93 edl->local_session->view_start = view_start;
95 gui->get_scrollbars();
97 if(!gui->samplescroll) edl->local_session->view_start = 0;
98 samplemovement(edl->local_session->view_start);
99 gui->zoombar->sample_zoom->update(zoom_sample);
103 void MWindow::find_cursor()
105 // if((edl->local_session->selectionend >
106 // (double)gui->canvas->get_w() *
107 // edl->local_session->zoom_sample /
108 // edl->session->sample_rate) ||
109 // (edl->local_session->selectionstart >
110 // (double)gui->canvas->get_w() *
111 // edl->local_session->zoom_sample /
112 // edl->session->sample_rate))
114 edl->local_session->view_start =
115 Units::round((edl->local_session->get_selectionend(1) +
116 edl->local_session->get_selectionstart(1)) /
118 edl->session->sample_rate /
119 edl->local_session->zoom_sample -
120 (double)gui->canvas->get_w() /
124 // edl->local_session->view_start = 0;
126 //printf("MWindow::find_cursor %f\n", edl->local_session->view_start);
127 if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
131 void MWindow::fit_selection()
133 if(EQUIV(edl->local_session->get_selectionstart(1),
134 edl->local_session->get_selectionend(1)))
136 double total_samples = edl->tracks->total_length() *
137 edl->session->sample_rate;
138 for(edl->local_session->zoom_sample = 1;
139 gui->canvas->get_w() * edl->local_session->zoom_sample < total_samples;
140 edl->local_session->zoom_sample *= 2)
145 double total_samples = (edl->local_session->get_selectionend(1) -
146 edl->local_session->get_selectionstart(1)) *
147 edl->session->sample_rate;
148 for(edl->local_session->zoom_sample = 1;
149 gui->canvas->get_w() * edl->local_session->zoom_sample < total_samples;
150 edl->local_session->zoom_sample *= 2)
154 edl->local_session->zoom_sample = MIN(0x100000,
155 edl->local_session->zoom_sample);
156 zoom_sample(edl->local_session->zoom_sample);
160 void MWindow::fit_autos()
162 float min = 0, max = 0;
166 if(EQUIV(edl->local_session->get_selectionstart(1),
167 edl->local_session->get_selectionend(1)))
170 end = edl->tracks->total_length();
173 // Test autos in highlighting only
175 start = edl->local_session->get_selectionstart(1);
176 end = edl->local_session->get_selectionend(1);
179 // Adjust min and max
180 edl->tracks->get_automation_extents(&min, &max, start, end);
181 //printf("MWindow::fit_autos %f %f\n", min, max);
184 float range = max - min;
185 // No automation visible
191 float pad = range * 0.33;
194 edl->local_session->automation_min = min;
195 edl->local_session->automation_max = max;
197 // Show range in zoombar
198 gui->zoombar->update();
201 gui->canvas->draw_overlays();
202 gui->canvas->flash();
206 void MWindow::expand_autos()
208 float range = edl->local_session->automation_max -
209 edl->local_session->automation_min;
210 float center = range / 2 +
211 edl->local_session->automation_min;
212 if(EQUIV(range, 0)) range = 0.002;
213 edl->local_session->automation_min = center - range;
214 edl->local_session->automation_max = center + range;
215 gui->zoombar->update_autozoom();
216 gui->canvas->draw_overlays();
217 gui->canvas->flash();
220 void MWindow::shrink_autos()
222 float range = edl->local_session->automation_max -
223 edl->local_session->automation_min;
224 float center = range / 2 +
225 edl->local_session->automation_min;
226 float new_range = range / 4;
227 edl->local_session->automation_min = center - new_range;
228 edl->local_session->automation_max = center + new_range;
229 gui->zoombar->update_autozoom();
230 gui->canvas->draw_overlays();
231 gui->canvas->flash();
235 void MWindow::zoom_amp(int64_t zoom_amp)
237 edl->local_session->zoom_y = zoom_amp;
238 gui->canvas->draw(0, 0);
239 gui->canvas->flash();
240 gui->patchbay->update();
244 void MWindow::zoom_track(int64_t zoom_track)
246 edl->local_session->zoom_y = (int64_t)((float)edl->local_session->zoom_y *
248 edl->local_session->zoom_track);
249 CLAMP(edl->local_session->zoom_y, MIN_AMP_ZOOM, MAX_AMP_ZOOM);
250 edl->local_session->zoom_track = zoom_track;
251 trackmovement(edl->local_session->track_start);
252 //printf("MWindow::zoom_track %d %d\n", edl->local_session->zoom_y, edl->local_session->zoom_track);
255 void MWindow::trackmovement(int track_start)
257 edl->local_session->track_start = track_start;
258 if(edl->local_session->track_start < 0) edl->local_session->track_start = 0;
259 edl->tracks->update_y_pixels(theme);
260 gui->get_scrollbars();
261 gui->canvas->draw(0, 0);
262 gui->patchbay->update();
263 gui->canvas->flash();
267 void MWindow::move_up(int64_t distance)
269 if(!gui->trackscroll) return;
270 if(distance == 0) distance = edl->local_session->zoom_track;
271 edl->local_session->track_start -= distance;
272 trackmovement(edl->local_session->track_start);
275 void MWindow::move_down(int64_t distance)
277 if(!gui->trackscroll) return;
278 if(distance == 0) distance = edl->local_session->zoom_track;
279 edl->local_session->track_start += distance;
280 trackmovement(edl->local_session->track_start);
283 int MWindow::goto_end()
285 int64_t old_view_start = edl->local_session->view_start;
287 if(edl->tracks->total_length() > (double)gui->canvas->get_w() *
288 edl->local_session->zoom_sample /
289 edl->session->sample_rate)
291 edl->local_session->view_start =
292 Units::round(edl->tracks->total_length() *
293 edl->session->sample_rate /
294 edl->local_session->zoom_sample -
295 gui->canvas->get_w() /
300 edl->local_session->view_start = 0;
303 if(gui->shift_down())
305 edl->local_session->set_selectionend(edl->tracks->total_length());
309 edl->local_session->set_selectionstart(edl->tracks->total_length());
310 edl->local_session->set_selectionend(edl->tracks->total_length());
313 if(edl->local_session->view_start != old_view_start)
314 samplemovement(edl->local_session->view_start);
316 update_plugin_guis();
317 gui->patchbay->update();
318 gui->cursor->update();
319 gui->canvas->activate();
320 gui->zoombar->update();
321 cwindow->update(1, 0, 0, 0, 0);
325 int MWindow::goto_start()
327 int64_t old_view_start = edl->local_session->view_start;
329 edl->local_session->view_start = 0;
330 if(gui->shift_down())
332 edl->local_session->set_selectionstart(0);
336 edl->local_session->set_selectionstart(0);
337 edl->local_session->set_selectionend(0);
340 if(edl->local_session->view_start != old_view_start)
341 samplemovement(edl->local_session->view_start);
343 update_plugin_guis();
344 gui->patchbay->update();
345 gui->cursor->update();
346 gui->canvas->activate();
347 gui->zoombar->update();
348 cwindow->update(1, 0, 0, 0, 0);
352 int MWindow::samplemovement(int64_t view_start)
354 edl->local_session->view_start = view_start;
355 if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
358 gui->canvas->flash();
359 gui->timebar->update();
360 gui->zoombar->update();
362 if(gui->samplescroll) gui->samplescroll->set_position();
366 int MWindow::move_left(int64_t distance)
369 distance = gui->canvas->get_w() /
371 edl->local_session->view_start -= distance;
372 if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
373 samplemovement(edl->local_session->view_start);
377 int MWindow::move_right(int64_t distance)
380 distance = gui->canvas->get_w() /
382 edl->local_session->view_start += distance;
383 samplemovement(edl->local_session->view_start);
387 void MWindow::select_all()
389 edl->local_session->set_selectionstart(0);
390 edl->local_session->set_selectionend(edl->tracks->total_length());
391 gui->update(0, 1, 1, 1, 0, 1, 0);
392 gui->canvas->activate();
393 cwindow->update(1, 0, 0);
396 int MWindow::next_label()
398 Label *current = edl->labels->next_label(
399 edl->local_session->get_selectionstart(1));
404 edl->local_session->set_selectionend(current->position);
405 if(!gui->shift_down())
406 edl->local_session->set_selectionstart(
407 edl->local_session->get_selectionend(1));
409 if(edl->local_session->get_selectionend(1) >=
410 (double)edl->local_session->view_start *
411 edl->local_session->zoom_sample /
412 edl->session->sample_rate +
413 gui->canvas->time_visible() ||
414 edl->local_session->get_selectionend(1) < (double)edl->local_session->view_start *
415 edl->local_session->zoom_sample /
416 edl->session->sample_rate)
418 samplemovement((int64_t)(edl->local_session->get_selectionend(1) *
419 edl->session->sample_rate /
420 edl->local_session->zoom_sample -
421 gui->canvas->get_w() /
423 cwindow->update(1, 0, 0, 0, 0);
427 update_plugin_guis();
428 gui->patchbay->update();
429 gui->timebar->update();
432 gui->zoombar->update();
433 gui->canvas->flash();
435 cwindow->update(1, 0, 0);
445 int MWindow::prev_label()
447 Label *current = edl->labels->prev_label(
448 edl->local_session->get_selectionstart(1));;
452 edl->local_session->set_selectionstart(current->position);
453 if(!gui->shift_down())
454 edl->local_session->set_selectionend(edl->local_session->get_selectionstart(1));
456 // Scroll the display
457 if(edl->local_session->get_selectionstart(1) >= edl->local_session->view_start *
458 edl->local_session->zoom_sample /
459 edl->session->sample_rate +
460 gui->canvas->time_visible()
462 edl->local_session->get_selectionstart(1) < edl->local_session->view_start *
463 edl->local_session->zoom_sample /
464 edl->session->sample_rate)
466 samplemovement((int64_t)(edl->local_session->get_selectionstart(1) *
467 edl->session->sample_rate /
468 edl->local_session->zoom_sample -
469 gui->canvas->get_w() /
471 cwindow->update(1, 0, 0, 0, 0);
474 // Don't scroll the display
476 update_plugin_guis();
477 gui->patchbay->update();
478 gui->timebar->update();
481 gui->zoombar->update();
482 gui->canvas->flash();
484 cwindow->update(1, 0, 0);
494 int MWindow::next_edit_handle()
496 double position = edl->local_session->get_selectionend(1);
497 double new_position = INFINITY;
498 // Test for edit handles after cursor position
499 for (Track *track = edl->tracks->first; track; track = track->next)
503 for (Edit *edit = track->edits->first; edit; edit = edit->next)
505 double edit_end = track->from_units(edit->startproject + edit->length);
506 if (edit_end > position && edit_end < new_position)
507 new_position = edit_end;
512 if(new_position != INFINITY)
515 edl->local_session->set_selectionend(new_position);
516 if(!gui->shift_down())
517 edl->local_session->set_selectionstart(
518 edl->local_session->get_selectionend(1));
520 if(edl->local_session->get_selectionend(1) >=
521 (double)edl->local_session->view_start *
522 edl->local_session->zoom_sample /
523 edl->session->sample_rate +
524 gui->canvas->time_visible() ||
525 edl->local_session->get_selectionend(1) < (double)edl->local_session->view_start *
526 edl->local_session->zoom_sample /
527 edl->session->sample_rate)
529 samplemovement((int64_t)(edl->local_session->get_selectionend(1) *
530 edl->session->sample_rate /
531 edl->local_session->zoom_sample -
532 gui->canvas->get_w() /
534 cwindow->update(1, 0, 0, 0, 0);
538 update_plugin_guis();
539 gui->patchbay->update();
540 gui->timebar->update();
543 gui->zoombar->update();
544 gui->canvas->flash();
546 cwindow->update(1, 0, 0);
556 int MWindow::prev_edit_handle()
558 double position = edl->local_session->get_selectionstart(1);
559 double new_position = -1;
560 // Test for edit handles before cursor position
561 for (Track *track = edl->tracks->first; track; track = track->next)
565 for (Edit *edit = track->edits->first; edit; edit = edit->next)
567 double edit_end = track->from_units(edit->startproject);
568 if (edit_end < position && edit_end > new_position)
569 new_position = edit_end;
574 if(new_position != -1)
577 edl->local_session->set_selectionstart(new_position);
578 if(!gui->shift_down())
579 edl->local_session->set_selectionend(edl->local_session->get_selectionstart(1));
581 // Scroll the display
582 if(edl->local_session->get_selectionstart(1) >= edl->local_session->view_start *
583 edl->local_session->zoom_sample /
584 edl->session->sample_rate +
585 gui->canvas->time_visible()
587 edl->local_session->get_selectionstart(1) < edl->local_session->view_start *
588 edl->local_session->zoom_sample /
589 edl->session->sample_rate)
591 samplemovement((int64_t)(edl->local_session->get_selectionstart(1) *
592 edl->session->sample_rate /
593 edl->local_session->zoom_sample -
594 gui->canvas->get_w() /
596 cwindow->update(1, 0, 0, 0, 0);
599 // Don't scroll the display
601 update_plugin_guis();
602 gui->patchbay->update();
603 gui->timebar->update();
606 gui->zoombar->update();
607 gui->canvas->flash();
609 cwindow->update(1, 0, 0);
621 int MWindow::expand_y()
623 int result = edl->local_session->zoom_y * 2;
624 result = MIN(result, MAX_AMP_ZOOM);
626 gui->zoombar->update();
630 int MWindow::zoom_in_y()
632 int result = edl->local_session->zoom_y / 2;
633 result = MAX(result, MIN_AMP_ZOOM);
635 gui->zoombar->update();
639 int MWindow::expand_t()
641 int result = edl->local_session->zoom_track * 2;
642 result = MIN(result, MAX_TRACK_ZOOM);
644 gui->zoombar->update();
648 int MWindow::zoom_in_t()
650 int result = edl->local_session->zoom_track / 2;
651 result = MAX(result, MIN_TRACK_ZOOM);
653 gui->zoombar->update();