00001 #include "clip.h"
00002 #include "cplayback.h"
00003 #include "cwindow.h"
00004 #include "cwindowgui.h"
00005 #include "edl.h"
00006 #include "edlsession.h"
00007 #include "labels.h"
00008 #include "localsession.h"
00009 #include "maincursor.h"
00010 #include "mainsession.h"
00011 #include "mtimebar.h"
00012 #include "mwindow.h"
00013 #include "mwindowgui.h"
00014 #include "patchbay.h"
00015 #include "playbackengine.h"
00016 #include "plugin.h"
00017 #include "samplescroll.h"
00018 #include "trackcanvas.h"
00019 #include "tracks.h"
00020 #include "transportque.h"
00021 #include "zoombar.h"
00022
00023
00024 void MWindow::update_plugins()
00025 {
00026
00027
00028 }
00029
00030
00031 int MWindow::expand_sample(double fixed_sample)
00032 {
00033 if(gui)
00034 {
00035 if(edl->local_session->zoom_sample < 0x100000)
00036 {
00037
00038 int64_t new_zoom_sample = edl->local_session->zoom_sample * 2;
00039 int64_t view_start;
00040 if (fixed_sample < 0)
00041 view_start = -1;
00042 else
00043 {
00044 double viewstart_position = (double)edl->local_session->view_start *
00045 edl->local_session->zoom_sample /
00046 edl->session->sample_rate * 2 - fixed_sample;
00047 view_start = Units::round(viewstart_position *
00048 edl->session->sample_rate /
00049 new_zoom_sample);
00050 }
00051
00052 zoom_sample(new_zoom_sample, view_start);
00053 }
00054 }
00055 return 0;
00056 }
00057
00058 int MWindow::zoom_in_sample(double fixed_sample)
00059 {
00060 if(gui)
00061 {
00062 if(edl->local_session->zoom_sample > 1)
00063 {
00064 int64_t new_zoom_sample = edl->local_session->zoom_sample / 2;
00065 int64_t view_start;
00066 if (fixed_sample < 0)
00067 view_start = -1;
00068 else
00069 {
00070 double viewstart_position = (double)edl->local_session->view_start *
00071 edl->local_session->zoom_sample /
00072 edl->session->sample_rate;
00073 viewstart_position = viewstart_position + (fixed_sample - viewstart_position) / 2;
00074
00075 view_start = Units::round(viewstart_position *
00076 edl->session->sample_rate /
00077 new_zoom_sample);
00078 }
00079
00080 zoom_sample(new_zoom_sample, view_start);
00081 }
00082 }
00083 return 0;
00084 }
00085
00086 int MWindow::zoom_sample(int64_t zoom_sample, int64_t view_start)
00087 {
00088 CLIP(zoom_sample, 1, 0x100000);
00089 edl->local_session->zoom_sample = zoom_sample;
00090 if (view_start < 0)
00091 find_cursor();
00092 else
00093 edl->local_session->view_start = view_start;
00094
00095 gui->get_scrollbars();
00096
00097 if(!gui->samplescroll) edl->local_session->view_start = 0;
00098 samplemovement(edl->local_session->view_start);
00099 gui->zoombar->sample_zoom->update(zoom_sample);
00100 return 0;
00101 }
00102
00103 void MWindow::find_cursor()
00104 {
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 edl->local_session->view_start =
00115 Units::round((edl->local_session->get_selectionend(1) +
00116 edl->local_session->get_selectionstart(1)) /
00117 2 *
00118 edl->session->sample_rate /
00119 edl->local_session->zoom_sample -
00120 (double)gui->canvas->get_w() /
00121 2);
00122
00123
00124
00125
00126
00127 if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
00128 }
00129
00130
00131 void MWindow::fit_selection()
00132 {
00133 if(EQUIV(edl->local_session->get_selectionstart(1),
00134 edl->local_session->get_selectionend(1)))
00135 {
00136 double total_samples = edl->tracks->total_length() *
00137 edl->session->sample_rate;
00138 for(edl->local_session->zoom_sample = 1;
00139 gui->canvas->get_w() * edl->local_session->zoom_sample < total_samples;
00140 edl->local_session->zoom_sample *= 2)
00141 ;
00142 }
00143 else
00144 {
00145 double total_samples = (edl->local_session->get_selectionend(1) -
00146 edl->local_session->get_selectionstart(1)) *
00147 edl->session->sample_rate;
00148 for(edl->local_session->zoom_sample = 1;
00149 gui->canvas->get_w() * edl->local_session->zoom_sample < total_samples;
00150 edl->local_session->zoom_sample *= 2)
00151 ;
00152 }
00153
00154 edl->local_session->zoom_sample = MIN(0x100000,
00155 edl->local_session->zoom_sample);
00156 zoom_sample(edl->local_session->zoom_sample);
00157 }
00158
00159
00160 void MWindow::fit_autos()
00161 {
00162 float min = 0, max = 0;
00163 double start, end;
00164
00165
00166 if(EQUIV(edl->local_session->get_selectionstart(1),
00167 edl->local_session->get_selectionend(1)))
00168 {
00169 start = 0;
00170 end = edl->tracks->total_length();
00171 }
00172 else
00173
00174 {
00175 start = edl->local_session->get_selectionstart(1);
00176 end = edl->local_session->get_selectionend(1);
00177 }
00178
00179
00180 edl->tracks->get_automation_extents(&min, &max, start, end);
00181
00182
00183
00184 float range = max - min;
00185
00186 if(range < 0.001)
00187 {
00188 min -= 1;
00189 max += 1;
00190 }
00191 float pad = range * 0.33;
00192 min -= pad;
00193 max += pad;
00194 edl->local_session->automation_min = min;
00195 edl->local_session->automation_max = max;
00196
00197
00198 gui->zoombar->update();
00199
00200
00201 gui->canvas->draw_overlays();
00202 gui->canvas->flash();
00203 }
00204
00205
00206 void MWindow::expand_autos()
00207 {
00208 float range = edl->local_session->automation_max -
00209 edl->local_session->automation_min;
00210 float center = range / 2 +
00211 edl->local_session->automation_min;
00212 if(EQUIV(range, 0)) range = 0.002;
00213 edl->local_session->automation_min = center - range;
00214 edl->local_session->automation_max = center + range;
00215 gui->zoombar->update_autozoom();
00216 gui->canvas->draw_overlays();
00217 gui->canvas->flash();
00218 }
00219
00220 void MWindow::shrink_autos()
00221 {
00222 float range = edl->local_session->automation_max -
00223 edl->local_session->automation_min;
00224 float center = range / 2 +
00225 edl->local_session->automation_min;
00226 float new_range = range / 4;
00227 edl->local_session->automation_min = center - new_range;
00228 edl->local_session->automation_max = center + new_range;
00229 gui->zoombar->update_autozoom();
00230 gui->canvas->draw_overlays();
00231 gui->canvas->flash();
00232 }
00233
00234
00235 void MWindow::zoom_amp(int64_t zoom_amp)
00236 {
00237 edl->local_session->zoom_y = zoom_amp;
00238 gui->canvas->draw(0, 0);
00239 gui->canvas->flash();
00240 gui->patchbay->update();
00241 gui->flush();
00242 }
00243
00244 void MWindow::zoom_track(int64_t zoom_track)
00245 {
00246 edl->local_session->zoom_y = (int64_t)((float)edl->local_session->zoom_y *
00247 zoom_track /
00248 edl->local_session->zoom_track);
00249 CLAMP(edl->local_session->zoom_y, MIN_AMP_ZOOM, MAX_AMP_ZOOM);
00250 edl->local_session->zoom_track = zoom_track;
00251 trackmovement(edl->local_session->track_start);
00252
00253 }
00254
00255 void MWindow::trackmovement(int track_start)
00256 {
00257 edl->local_session->track_start = track_start;
00258 if(edl->local_session->track_start < 0) edl->local_session->track_start = 0;
00259 edl->tracks->update_y_pixels(theme);
00260 gui->get_scrollbars();
00261 gui->canvas->draw(0, 0);
00262 gui->patchbay->update();
00263 gui->canvas->flash();
00264 gui->flush();
00265 }
00266
00267 void MWindow::move_up(int64_t distance)
00268 {
00269 if(!gui->trackscroll) return;
00270 if(distance == 0) distance = edl->local_session->zoom_track;
00271 edl->local_session->track_start -= distance;
00272 trackmovement(edl->local_session->track_start);
00273 }
00274
00275 void MWindow::move_down(int64_t distance)
00276 {
00277 if(!gui->trackscroll) return;
00278 if(distance == 0) distance = edl->local_session->zoom_track;
00279 edl->local_session->track_start += distance;
00280 trackmovement(edl->local_session->track_start);
00281 }
00282
00283 int MWindow::goto_end()
00284 {
00285 int64_t old_view_start = edl->local_session->view_start;
00286
00287 if(edl->tracks->total_length() > (double)gui->canvas->get_w() *
00288 edl->local_session->zoom_sample /
00289 edl->session->sample_rate)
00290 {
00291 edl->local_session->view_start =
00292 Units::round(edl->tracks->total_length() *
00293 edl->session->sample_rate /
00294 edl->local_session->zoom_sample -
00295 gui->canvas->get_w() /
00296 2);
00297 }
00298 else
00299 {
00300 edl->local_session->view_start = 0;
00301 }
00302
00303 if(gui->shift_down())
00304 {
00305 edl->local_session->set_selectionend(edl->tracks->total_length());
00306 }
00307 else
00308 {
00309 edl->local_session->set_selectionstart(edl->tracks->total_length());
00310 edl->local_session->set_selectionend(edl->tracks->total_length());
00311 }
00312
00313 if(edl->local_session->view_start != old_view_start)
00314 samplemovement(edl->local_session->view_start);
00315
00316 update_plugin_guis();
00317 gui->patchbay->update();
00318 gui->cursor->update();
00319 gui->canvas->activate();
00320 gui->zoombar->update();
00321 cwindow->update(1, 0, 0, 0, 0);
00322 return 0;
00323 }
00324
00325 int MWindow::goto_start()
00326 {
00327 int64_t old_view_start = edl->local_session->view_start;
00328
00329 edl->local_session->view_start = 0;
00330 if(gui->shift_down())
00331 {
00332 edl->local_session->set_selectionstart(0);
00333 }
00334 else
00335 {
00336 edl->local_session->set_selectionstart(0);
00337 edl->local_session->set_selectionend(0);
00338 }
00339
00340 if(edl->local_session->view_start != old_view_start)
00341 samplemovement(edl->local_session->view_start);
00342
00343 update_plugin_guis();
00344 gui->patchbay->update();
00345 gui->cursor->update();
00346 gui->canvas->activate();
00347 gui->zoombar->update();
00348 cwindow->update(1, 0, 0, 0, 0);
00349 return 0;
00350 }
00351
00352 int MWindow::samplemovement(int64_t view_start)
00353 {
00354 edl->local_session->view_start = view_start;
00355 if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
00356 gui->canvas->draw();
00357 gui->cursor->show();
00358 gui->canvas->flash();
00359 gui->timebar->update();
00360 gui->zoombar->update();
00361
00362 if(gui->samplescroll) gui->samplescroll->set_position();
00363 return 0;
00364 }
00365
00366 int MWindow::move_left(int64_t distance)
00367 {
00368 if(!distance)
00369 distance = gui->canvas->get_w() /
00370 10;
00371 edl->local_session->view_start -= distance;
00372 if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
00373 samplemovement(edl->local_session->view_start);
00374 return 0;
00375 }
00376
00377 int MWindow::move_right(int64_t distance)
00378 {
00379 if(!distance)
00380 distance = gui->canvas->get_w() /
00381 10;
00382 edl->local_session->view_start += distance;
00383 samplemovement(edl->local_session->view_start);
00384 return 0;
00385 }
00386
00387 void MWindow::select_all()
00388 {
00389 edl->local_session->set_selectionstart(0);
00390 edl->local_session->set_selectionend(edl->tracks->total_length());
00391 gui->update(0, 1, 1, 1, 0, 1, 0);
00392 gui->canvas->activate();
00393 cwindow->update(1, 0, 0);
00394 }
00395
00396 int MWindow::next_label()
00397 {
00398 Label *current;
00399 Labels *labels = edl->labels;
00400
00401
00402 for(current = labels->first;
00403 current && !edl->equivalent(current->position,
00404 edl->local_session->get_selectionend(1));
00405 current = NEXT)
00406 ;
00407
00408
00409 if(!current)
00410 for(current = labels->last;
00411 current && current->position > edl->local_session->get_selectionend(1);
00412 current = PREVIOUS)
00413 ;
00414
00415
00416 if(!current)
00417 current = labels->first;
00418 else
00419
00420 current = NEXT;
00421
00422 if(current)
00423 {
00424
00425 edl->local_session->set_selectionend(current->position);
00426 if(!gui->shift_down())
00427 edl->local_session->set_selectionstart(
00428 edl->local_session->get_selectionend(1));
00429
00430 if(edl->local_session->get_selectionend(1) >=
00431 (double)edl->local_session->view_start *
00432 edl->local_session->zoom_sample /
00433 edl->session->sample_rate +
00434 gui->canvas->time_visible() ||
00435 edl->local_session->get_selectionend(1) < (double)edl->local_session->view_start *
00436 edl->local_session->zoom_sample /
00437 edl->session->sample_rate)
00438 {
00439 samplemovement((int64_t)(edl->local_session->get_selectionend(1) *
00440 edl->session->sample_rate /
00441 edl->local_session->zoom_sample -
00442 gui->canvas->get_w() /
00443 2));
00444 cwindow->update(1, 0, 0, 0, 0);
00445 }
00446 else
00447 {
00448 update_plugin_guis();
00449 gui->patchbay->update();
00450 gui->timebar->update();
00451 gui->cursor->hide();
00452 gui->cursor->draw();
00453 gui->zoombar->update();
00454 gui->canvas->flash();
00455 gui->flush();
00456 cwindow->update(1, 0, 0);
00457 }
00458 }
00459 else
00460 {
00461 goto_end();
00462 }
00463 return 0;
00464 }
00465
00466 int MWindow::prev_label()
00467 {
00468 Label *current;
00469 Labels *labels = edl->labels;
00470
00471
00472 for(current = labels->first;
00473 current && !edl->equivalent(current->position,
00474 edl->local_session->get_selectionstart(1));
00475 current = NEXT)
00476 ;
00477
00478
00479 if(!current)
00480 for(current = labels->first;
00481 current &&
00482 current->position < edl->local_session->get_selectionstart(1);
00483 current = NEXT)
00484 ;
00485
00486
00487 if(!current)
00488 current = labels->last;
00489 else
00490
00491 current = PREVIOUS;
00492
00493 if(current)
00494 {
00495 edl->local_session->set_selectionstart(current->position);
00496 if(!gui->shift_down())
00497 edl->local_session->set_selectionend(edl->local_session->get_selectionstart(1));
00498
00499
00500 if(edl->local_session->get_selectionstart(1) >= edl->local_session->view_start *
00501 edl->local_session->zoom_sample /
00502 edl->session->sample_rate +
00503 gui->canvas->time_visible()
00504 ||
00505 edl->local_session->get_selectionstart(1) < edl->local_session->view_start *
00506 edl->local_session->zoom_sample /
00507 edl->session->sample_rate)
00508 {
00509 samplemovement((int64_t)(edl->local_session->get_selectionstart(1) *
00510 edl->session->sample_rate /
00511 edl->local_session->zoom_sample -
00512 gui->canvas->get_w() /
00513 2));
00514 cwindow->update(1, 0, 0, 0, 0);
00515 }
00516 else
00517
00518 {
00519 update_plugin_guis();
00520 gui->patchbay->update();
00521 gui->timebar->update();
00522 gui->cursor->hide();
00523 gui->cursor->draw();
00524 gui->zoombar->update();
00525 gui->canvas->flash();
00526 gui->flush();
00527 cwindow->update(1, 0, 0);
00528 }
00529 }
00530 else
00531 {
00532 goto_start();
00533 }
00534 return 0;
00535 }
00536
00537 int MWindow::expand_y()
00538 {
00539 int result = edl->local_session->zoom_y * 2;
00540 result = MIN(result, MAX_AMP_ZOOM);
00541 zoom_amp(result);
00542 gui->zoombar->update();
00543 return 0;
00544 }
00545
00546 int MWindow::zoom_in_y()
00547 {
00548 int result = edl->local_session->zoom_y / 2;
00549 result = MAX(result, MIN_AMP_ZOOM);
00550 zoom_amp(result);
00551 gui->zoombar->update();
00552 return 0;
00553 }
00554
00555 int MWindow::expand_t()
00556 {
00557 int result = edl->local_session->zoom_track * 2;
00558 result = MIN(result, MAX_TRACK_ZOOM);
00559 zoom_track(result);
00560 gui->zoombar->update();
00561 return 0;
00562 }
00563
00564 int MWindow::zoom_in_t()
00565 {
00566 int result = edl->local_session->zoom_track / 2;
00567 result = MAX(result, MIN_TRACK_ZOOM);
00568 zoom_track(result);
00569 gui->zoombar->update();
00570 return 0;
00571 }
00572