00001 #include "automation.h"
00002 #include "clip.h"
00003 #include "cplayback.h"
00004 #include "cwindow.h"
00005 #include "cwindowgui.h"
00006 #include "edits.h"
00007 #include "edl.h"
00008 #include "edlsession.h"
00009 #include "labels.h"
00010 #include "localsession.h"
00011 #include "maincursor.h"
00012 #include "mainsession.h"
00013 #include "mtimebar.h"
00014 #include "mwindow.h"
00015 #include "mwindowgui.h"
00016 #include "patchbay.h"
00017 #include "playbackengine.h"
00018 #include "plugin.h"
00019 #include "samplescroll.h"
00020 #include "trackcanvas.h"
00021 #include "tracks.h"
00022 #include "transportque.h"
00023 #include "zoombar.h"
00024
00025
00026 void MWindow::update_plugins()
00027 {
00028
00029
00030 }
00031
00032
00033 int MWindow::expand_sample(double fixed_sample)
00034 {
00035 if(gui)
00036 {
00037 if(edl->local_session->zoom_sample < 0x100000)
00038 {
00039 int64_t new_zoom_sample = edl->local_session->zoom_sample * 2;
00040 int64_t view_start;
00041 if (fixed_sample < 0)
00042 view_start = -1;
00043 else
00044 {
00045 double viewstart_position = (double)edl->local_session->view_start *
00046 edl->local_session->zoom_sample /
00047 edl->session->sample_rate * 2 - fixed_sample;
00048 view_start = Units::round(viewstart_position *
00049 edl->session->sample_rate /
00050 new_zoom_sample);
00051 }
00052
00053 zoom_sample(new_zoom_sample, view_start);
00054 }
00055 }
00056 return 0;
00057 }
00058
00059 int MWindow::zoom_in_sample(double fixed_sample)
00060 {
00061 if(gui)
00062 {
00063 if(edl->local_session->zoom_sample > 1)
00064 {
00065 int64_t new_zoom_sample = edl->local_session->zoom_sample / 2;
00066 int64_t view_start;
00067 if (fixed_sample < 0)
00068 view_start = -1;
00069 else
00070 {
00071 double viewstart_position = (double)edl->local_session->view_start *
00072 edl->local_session->zoom_sample /
00073 edl->session->sample_rate;
00074 viewstart_position = viewstart_position + (fixed_sample - viewstart_position) / 2;
00075
00076 view_start = Units::round(viewstart_position *
00077 edl->session->sample_rate /
00078 new_zoom_sample);
00079 }
00080
00081 zoom_sample(new_zoom_sample, view_start);
00082 }
00083 }
00084 return 0;
00085 }
00086
00087 int MWindow::zoom_sample(int64_t zoom_sample, int64_t view_start)
00088 {
00089 CLIP(zoom_sample, 1, 0x100000);
00090 edl->local_session->zoom_sample = zoom_sample;
00091 if (view_start < 0)
00092 find_cursor();
00093 else
00094 edl->local_session->view_start = view_start;
00095
00096 gui->get_scrollbars();
00097
00098 if(!gui->samplescroll) edl->local_session->view_start = 0;
00099 samplemovement(edl->local_session->view_start);
00100 gui->zoombar->sample_zoom->update(zoom_sample);
00101 return 0;
00102 }
00103
00104 void MWindow::find_cursor()
00105 {
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 edl->local_session->view_start =
00116 Units::round((edl->local_session->get_selectionend(1) +
00117 edl->local_session->get_selectionstart(1)) /
00118 2 *
00119 edl->session->sample_rate /
00120 edl->local_session->zoom_sample -
00121 (double)gui->canvas->get_w() /
00122 2);
00123
00124
00125
00126
00127
00128 if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
00129 }
00130
00131
00132 void MWindow::fit_selection()
00133 {
00134 if(EQUIV(edl->local_session->get_selectionstart(1),
00135 edl->local_session->get_selectionend(1)))
00136 {
00137 double total_samples = edl->tracks->total_length() *
00138 edl->session->sample_rate;
00139 for(edl->local_session->zoom_sample = 1;
00140 gui->canvas->get_w() * edl->local_session->zoom_sample < total_samples;
00141 edl->local_session->zoom_sample *= 2)
00142 ;
00143 }
00144 else
00145 {
00146 double total_samples = (edl->local_session->get_selectionend(1) -
00147 edl->local_session->get_selectionstart(1)) *
00148 edl->session->sample_rate;
00149 for(edl->local_session->zoom_sample = 1;
00150 gui->canvas->get_w() * edl->local_session->zoom_sample < total_samples;
00151 edl->local_session->zoom_sample *= 2)
00152 ;
00153 }
00154
00155 edl->local_session->zoom_sample = MIN(0x100000,
00156 edl->local_session->zoom_sample);
00157 zoom_sample(edl->local_session->zoom_sample);
00158 }
00159
00160
00161 void MWindow::fit_autos(int doall)
00162 {
00163 float min = 0, max = 0;
00164 double start, end;
00165
00166
00167 if(EQUIV(edl->local_session->get_selectionstart(1),
00168 edl->local_session->get_selectionend(1)))
00169 {
00170 start = 0;
00171 end = edl->tracks->total_length();
00172 }
00173 else
00174
00175 {
00176 start = edl->local_session->get_selectionstart(1);
00177 end = edl->local_session->get_selectionend(1);
00178 }
00179
00180 int forstart = edl->local_session->zoombar_showautotype;
00181 int forend = edl->local_session->zoombar_showautotype + 1;
00182
00183 if (doall) {
00184 forstart = 0;
00185 forend = AUTOGROUPTYPE_COUNT;
00186 }
00187
00188 for (int i = forstart; i < forend; i++)
00189 {
00190
00191 edl->tracks->get_automation_extents(&min, &max, start, end, i);
00192
00193
00194 float range = max - min;
00195 switch (i)
00196 {
00197 case AUTOGROUPTYPE_AUDIO_FADE:
00198 case AUTOGROUPTYPE_VIDEO_FADE:
00199 if (range < 0.1) {
00200 min = MIN(min, edl->local_session->automation_mins[i]);
00201 max = MAX(max, edl->local_session->automation_maxs[i]);
00202 }
00203 break;
00204 case AUTOGROUPTYPE_ZOOM:
00205 if (range < 0.001) {
00206 min = floor(min*50)/100;
00207 max = floor(max*200)/100;
00208 }
00209 break;
00210 case AUTOGROUPTYPE_X:
00211 case AUTOGROUPTYPE_Y:
00212 if (range < 5) {
00213 min = floor((min+max)/2) - 50;
00214 max = floor((min+max)/2) + 50;
00215 }
00216 break;
00217 }
00218
00219 if (!Automation::autogrouptypes_fixedrange[i])
00220 {
00221 edl->local_session->automation_mins[i] = min;
00222 edl->local_session->automation_maxs[i] = max;
00223 }
00224 }
00225
00226
00227 gui->zoombar->update();
00228
00229
00230 gui->canvas->draw_overlays();
00231 gui->canvas->flash();
00232 }
00233
00234
00235 void MWindow::change_currentautorange(int autogrouptype, int increment, int changemax) {
00236 float val;
00237 if (changemax) {
00238 val = edl->local_session->automation_maxs[autogrouptype];
00239 } else {
00240 val = edl->local_session->automation_mins[autogrouptype];
00241 }
00242
00243 if (increment)
00244 {
00245 switch (autogrouptype) {
00246 case AUTOGROUPTYPE_AUDIO_FADE:
00247 val += 2;
00248 break;
00249 case AUTOGROUPTYPE_VIDEO_FADE:
00250 val += 1;
00251 break;
00252 case AUTOGROUPTYPE_ZOOM:
00253 if (val == 0)
00254 val = 0.001;
00255 else
00256 val = val*2;
00257 break;
00258 case AUTOGROUPTYPE_X:
00259 case AUTOGROUPTYPE_Y:
00260 val = floor(val + 5);
00261 break;
00262 }
00263 }
00264 else
00265 {
00266 switch (autogrouptype) {
00267 case AUTOGROUPTYPE_AUDIO_FADE:
00268 val -= 2;
00269 break;
00270 case AUTOGROUPTYPE_VIDEO_FADE:
00271 val -= 1;
00272 break;
00273 case AUTOGROUPTYPE_ZOOM:
00274 if (val > 0) val = val/2;
00275 break;
00276 case AUTOGROUPTYPE_X:
00277 case AUTOGROUPTYPE_Y:
00278 val = floor(val-5);
00279 break;
00280 }
00281 }
00282
00283 AUTOMATIONVIEWCLAMPS(val, autogrouptype);
00284
00285 if (changemax) {
00286 if (val > edl->local_session->automation_mins[autogrouptype])
00287 edl->local_session->automation_maxs[autogrouptype] = val;
00288 }
00289 else
00290 {
00291 if (val < edl->local_session->automation_maxs[autogrouptype])
00292 edl->local_session->automation_mins[autogrouptype] = val;
00293 }
00294 }
00295
00296
00297 void MWindow::expand_autos(int changeall, int domin, int domax)
00298 {
00299 if (changeall)
00300 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
00301 if (domin) change_currentautorange(i, 1, 0);
00302 if (domax) change_currentautorange(i, 1, 1);
00303 }
00304 else
00305 {
00306 if (domin) change_currentautorange(edl->local_session->zoombar_showautotype, 1, 0);
00307 if (domax) change_currentautorange(edl->local_session->zoombar_showautotype, 1, 1);
00308 }
00309 gui->zoombar->update_autozoom();
00310 gui->canvas->draw_overlays();
00311 gui->patchbay->update();
00312 gui->canvas->flash();
00313 }
00314
00315 void MWindow::shrink_autos(int changeall, int domin, int domax)
00316 {
00317 if (changeall)
00318 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
00319 if (domin) change_currentautorange(i, 0, 0);
00320 if (domax) change_currentautorange(i, 0, 1);
00321 }
00322 else
00323 {
00324 if (domin) change_currentautorange(edl->local_session->zoombar_showautotype, 0, 0);
00325 if (domax) change_currentautorange(edl->local_session->zoombar_showautotype, 0, 1);
00326 }
00327 gui->zoombar->update_autozoom();
00328 gui->canvas->draw_overlays();
00329 gui->patchbay->update();
00330 gui->canvas->flash();
00331 }
00332
00333
00334 void MWindow::zoom_amp(int64_t zoom_amp)
00335 {
00336 edl->local_session->zoom_y = zoom_amp;
00337 gui->canvas->draw(0, 0);
00338 gui->canvas->flash();
00339 gui->patchbay->update();
00340 gui->flush();
00341 }
00342
00343 void MWindow::zoom_track(int64_t zoom_track)
00344 {
00345 edl->local_session->zoom_y = (int64_t)((float)edl->local_session->zoom_y *
00346 zoom_track /
00347 edl->local_session->zoom_track);
00348 CLAMP(edl->local_session->zoom_y, MIN_AMP_ZOOM, MAX_AMP_ZOOM);
00349 edl->local_session->zoom_track = zoom_track;
00350 trackmovement(edl->local_session->track_start);
00351
00352 }
00353
00354 void MWindow::trackmovement(int track_start)
00355 {
00356 edl->local_session->track_start = track_start;
00357 if(edl->local_session->track_start < 0) edl->local_session->track_start = 0;
00358 edl->tracks->update_y_pixels(theme);
00359 gui->get_scrollbars();
00360 gui->canvas->draw(0, 0);
00361 gui->patchbay->update();
00362 gui->canvas->flash();
00363 gui->flush();
00364 }
00365
00366 void MWindow::move_up(int64_t distance)
00367 {
00368 if(!gui->trackscroll) return;
00369 if(distance == 0) distance = edl->local_session->zoom_track;
00370 edl->local_session->track_start -= distance;
00371 trackmovement(edl->local_session->track_start);
00372 }
00373
00374 void MWindow::move_down(int64_t distance)
00375 {
00376 if(!gui->trackscroll) return;
00377 if(distance == 0) distance = edl->local_session->zoom_track;
00378 edl->local_session->track_start += distance;
00379 trackmovement(edl->local_session->track_start);
00380 }
00381
00382 int MWindow::goto_end()
00383 {
00384 int64_t old_view_start = edl->local_session->view_start;
00385
00386 if(edl->tracks->total_length() > (double)gui->canvas->get_w() *
00387 edl->local_session->zoom_sample /
00388 edl->session->sample_rate)
00389 {
00390 edl->local_session->view_start =
00391 Units::round(edl->tracks->total_length() *
00392 edl->session->sample_rate /
00393 edl->local_session->zoom_sample -
00394 gui->canvas->get_w() /
00395 2);
00396 }
00397 else
00398 {
00399 edl->local_session->view_start = 0;
00400 }
00401
00402 if(gui->shift_down())
00403 {
00404 edl->local_session->set_selectionend(edl->tracks->total_length());
00405 }
00406 else
00407 {
00408 edl->local_session->set_selectionstart(edl->tracks->total_length());
00409 edl->local_session->set_selectionend(edl->tracks->total_length());
00410 }
00411
00412 if(edl->local_session->view_start != old_view_start)
00413 samplemovement(edl->local_session->view_start);
00414
00415 update_plugin_guis();
00416 gui->patchbay->update();
00417 gui->cursor->update();
00418 gui->canvas->activate();
00419 gui->zoombar->update();
00420 cwindow->update(1, 0, 0, 0, 1);
00421 return 0;
00422 }
00423
00424 int MWindow::goto_start()
00425 {
00426 int64_t old_view_start = edl->local_session->view_start;
00427
00428 edl->local_session->view_start = 0;
00429 if(gui->shift_down())
00430 {
00431 edl->local_session->set_selectionstart(0);
00432 }
00433 else
00434 {
00435 edl->local_session->set_selectionstart(0);
00436 edl->local_session->set_selectionend(0);
00437 }
00438
00439 if(edl->local_session->view_start != old_view_start)
00440 samplemovement(edl->local_session->view_start);
00441
00442 update_plugin_guis();
00443 gui->patchbay->update();
00444 gui->cursor->update();
00445 gui->canvas->activate();
00446 gui->zoombar->update();
00447 cwindow->update(1, 0, 0, 0, 1);
00448 return 0;
00449 }
00450
00451 int MWindow::samplemovement(int64_t view_start)
00452 {
00453 edl->local_session->view_start = view_start;
00454 if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
00455 gui->canvas->draw();
00456 gui->cursor->show();
00457 gui->canvas->flash();
00458 gui->timebar->update();
00459 gui->zoombar->update();
00460
00461 if(gui->samplescroll) gui->samplescroll->set_position();
00462 return 0;
00463 }
00464
00465 int MWindow::move_left(int64_t distance)
00466 {
00467 if(!distance)
00468 distance = gui->canvas->get_w() /
00469 10;
00470 edl->local_session->view_start -= distance;
00471 if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
00472 samplemovement(edl->local_session->view_start);
00473 return 0;
00474 }
00475
00476 int MWindow::move_right(int64_t distance)
00477 {
00478 if(!distance)
00479 distance = gui->canvas->get_w() /
00480 10;
00481 edl->local_session->view_start += distance;
00482 samplemovement(edl->local_session->view_start);
00483 return 0;
00484 }
00485
00486 void MWindow::select_all()
00487 {
00488 edl->local_session->set_selectionstart(0);
00489 edl->local_session->set_selectionend(edl->tracks->total_length());
00490 gui->update(0, 1, 1, 1, 0, 1, 0);
00491 gui->canvas->activate();
00492 cwindow->update(1, 0, 0);
00493 }
00494
00495 int MWindow::next_label(int shift_down)
00496 {
00497 Label *current = edl->labels->next_label(
00498 edl->local_session->get_selectionstart(1));
00499
00500 if(current)
00501 {
00502
00503 edl->local_session->set_selectionend(current->position);
00504 if(!shift_down)
00505 edl->local_session->set_selectionstart(
00506 edl->local_session->get_selectionend(1));
00507
00508 update_plugin_guis();
00509 gui->patchbay->update();
00510 if(edl->local_session->get_selectionend(1) >=
00511 (double)edl->local_session->view_start *
00512 edl->local_session->zoom_sample /
00513 edl->session->sample_rate +
00514 gui->canvas->time_visible() ||
00515 edl->local_session->get_selectionend(1) < (double)edl->local_session->view_start *
00516 edl->local_session->zoom_sample /
00517 edl->session->sample_rate)
00518 {
00519 samplemovement((int64_t)(edl->local_session->get_selectionend(1) *
00520 edl->session->sample_rate /
00521 edl->local_session->zoom_sample -
00522 gui->canvas->get_w() /
00523 2));
00524 }
00525 else
00526 {
00527 gui->timebar->update();
00528 gui->cursor->hide(0);
00529 gui->cursor->draw(1);
00530 gui->zoombar->update();
00531 gui->canvas->flash();
00532 gui->flush();
00533 }
00534 cwindow->update(1, 0, 0, 0, 1);
00535 }
00536 else
00537 {
00538 goto_end();
00539 }
00540 return 0;
00541 }
00542
00543 int MWindow::prev_label(int shift_down)
00544 {
00545 Label *current = edl->labels->prev_label(
00546 edl->local_session->get_selectionstart(1));;
00547
00548 if(current)
00549 {
00550 edl->local_session->set_selectionstart(current->position);
00551 if(!shift_down)
00552 edl->local_session->set_selectionend(edl->local_session->get_selectionstart(1));
00553
00554 update_plugin_guis();
00555 gui->patchbay->update();
00556
00557 if(edl->local_session->get_selectionstart(1) >= edl->local_session->view_start *
00558 edl->local_session->zoom_sample /
00559 edl->session->sample_rate +
00560 gui->canvas->time_visible()
00561 ||
00562 edl->local_session->get_selectionstart(1) < edl->local_session->view_start *
00563 edl->local_session->zoom_sample /
00564 edl->session->sample_rate)
00565 {
00566 samplemovement((int64_t)(edl->local_session->get_selectionstart(1) *
00567 edl->session->sample_rate /
00568 edl->local_session->zoom_sample -
00569 gui->canvas->get_w() /
00570 2));
00571 }
00572 else
00573
00574 {
00575 gui->timebar->update();
00576 gui->cursor->hide(0);
00577 gui->cursor->draw(1);
00578 gui->zoombar->update();
00579 gui->canvas->flash();
00580 gui->flush();
00581 }
00582 cwindow->update(1, 0, 0, 0, 1);
00583 }
00584 else
00585 {
00586 goto_start();
00587 }
00588 return 0;
00589 }
00590
00591
00592
00593
00594
00595
00596 int MWindow::next_edit_handle(int shift_down)
00597 {
00598 double position = edl->local_session->get_selectionend(1);
00599 Units::fix_double(&position);
00600 double new_position = INFINITY;
00601
00602 for (Track *track = edl->tracks->first; track; track = track->next)
00603 {
00604 if (track->record)
00605 {
00606 for (Edit *edit = track->edits->first; edit; edit = edit->next)
00607 {
00608 double edit_end = track->from_units(edit->startproject + edit->length);
00609 Units::fix_double(&edit_end);
00610 if (edit_end > position && edit_end < new_position)
00611 new_position = edit_end;
00612 }
00613 }
00614 }
00615
00616 if(new_position != INFINITY)
00617 {
00618
00619 edl->local_session->set_selectionend(new_position);
00620 printf("MWindow::next_edit_handle %d\n", shift_down);
00621 if(!shift_down)
00622 edl->local_session->set_selectionstart(
00623 edl->local_session->get_selectionend(1));
00624
00625 update_plugin_guis();
00626 gui->patchbay->update();
00627 if(edl->local_session->get_selectionend(1) >=
00628 (double)edl->local_session->view_start *
00629 edl->local_session->zoom_sample /
00630 edl->session->sample_rate +
00631 gui->canvas->time_visible() ||
00632 edl->local_session->get_selectionend(1) < (double)edl->local_session->view_start *
00633 edl->local_session->zoom_sample /
00634 edl->session->sample_rate)
00635 {
00636 samplemovement((int64_t)(edl->local_session->get_selectionend(1) *
00637 edl->session->sample_rate /
00638 edl->local_session->zoom_sample -
00639 gui->canvas->get_w() /
00640 2));
00641 }
00642 else
00643 {
00644 gui->timebar->update();
00645 gui->cursor->hide(0);
00646 gui->cursor->draw(1);
00647 gui->zoombar->update();
00648 gui->canvas->flash();
00649 gui->flush();
00650 }
00651 cwindow->update(1, 0, 0, 0, 1);
00652 }
00653 else
00654 {
00655 goto_end();
00656 }
00657 return 0;
00658 }
00659
00660 int MWindow::prev_edit_handle(int shift_down)
00661 {
00662 double position = edl->local_session->get_selectionstart(1);
00663 double new_position = -1;
00664 Units::fix_double(&position);
00665
00666 for (Track *track = edl->tracks->first; track; track = track->next)
00667 {
00668 if (track->record)
00669 {
00670 for (Edit *edit = track->edits->first; edit; edit = edit->next)
00671 {
00672 double edit_end = track->from_units(edit->startproject);
00673 Units::fix_double(&edit_end);
00674 if (edit_end < position && edit_end > new_position)
00675 new_position = edit_end;
00676 }
00677 }
00678 }
00679
00680 if(new_position != -1)
00681 {
00682
00683 edl->local_session->set_selectionstart(new_position);
00684 printf("MWindow::next_edit_handle %d\n", shift_down);
00685 if(!shift_down)
00686 edl->local_session->set_selectionend(edl->local_session->get_selectionstart(1));
00687
00688 update_plugin_guis();
00689 gui->patchbay->update();
00690
00691 if(edl->local_session->get_selectionstart(1) >= edl->local_session->view_start *
00692 edl->local_session->zoom_sample /
00693 edl->session->sample_rate +
00694 gui->canvas->time_visible()
00695 ||
00696 edl->local_session->get_selectionstart(1) < edl->local_session->view_start *
00697 edl->local_session->zoom_sample /
00698 edl->session->sample_rate)
00699 {
00700 samplemovement((int64_t)(edl->local_session->get_selectionstart(1) *
00701 edl->session->sample_rate /
00702 edl->local_session->zoom_sample -
00703 gui->canvas->get_w() /
00704 2));
00705 }
00706 else
00707
00708 {
00709 gui->timebar->update();
00710 gui->cursor->hide(0);
00711 gui->cursor->draw(1);
00712 gui->zoombar->update();
00713 gui->canvas->flash();
00714 gui->flush();
00715 }
00716 cwindow->update(1, 0, 0, 0, 1);
00717 }
00718 else
00719 {
00720 goto_start();
00721 }
00722 return 0;
00723 }
00724
00725
00726
00727
00728
00729
00730
00731
00732 int MWindow::expand_y()
00733 {
00734 int result = edl->local_session->zoom_y * 2;
00735 result = MIN(result, MAX_AMP_ZOOM);
00736 zoom_amp(result);
00737 gui->zoombar->update();
00738 return 0;
00739 }
00740
00741 int MWindow::zoom_in_y()
00742 {
00743 int result = edl->local_session->zoom_y / 2;
00744 result = MAX(result, MIN_AMP_ZOOM);
00745 zoom_amp(result);
00746 gui->zoombar->update();
00747 return 0;
00748 }
00749
00750 int MWindow::expand_t()
00751 {
00752 int result = edl->local_session->zoom_track * 2;
00753 result = MIN(result, MAX_TRACK_ZOOM);
00754 zoom_track(result);
00755 gui->zoombar->update();
00756 return 0;
00757 }
00758
00759 int MWindow::zoom_in_t()
00760 {
00761 int result = edl->local_session->zoom_track / 2;
00762 result = MAX(result, MIN_TRACK_ZOOM);
00763 zoom_track(result);
00764 gui->zoombar->update();
00765 return 0;
00766 }
00767