00001 #include "clip.h"
00002 #include "edl.h"
00003 #include "edlsession.h"
00004 #include "language.h"
00005 #include "localsession.h"
00006 #include "maincursor.h"
00007 #include "mwindow.h"
00008 #include "mwindowgui.h"
00009 #include "mainsession.h"
00010 #include "mtimebar.h"
00011 #include "preferences.h"
00012 #include "patchbay.h"
00013 #include "theme.h"
00014 #include "trackcanvas.h"
00015 #include "tracks.h"
00016 #include "units.h"
00017 #include "zoombar.h"
00018
00019
00020
00021
00022 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
00023 : BC_SubWindow(mwindow->theme->mzoom_x,
00024 mwindow->theme->mzoom_y,
00025 mwindow->theme->mzoom_w,
00026 mwindow->theme->mzoom_h)
00027 {
00028 this->gui = gui;
00029 this->mwindow = mwindow;
00030 old_position = 0;
00031 }
00032
00033 ZoomBar::~ZoomBar()
00034 {
00035 delete sample_zoom;
00036 delete amp_zoom;
00037 delete track_zoom;
00038 }
00039
00040 int ZoomBar::create_objects()
00041 {
00042 int x = 3;
00043 int y = get_h() / 2 -
00044 mwindow->theme->get_image_set("zoombar_menu", 0)[0]->get_h() / 2;
00045
00046 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
00047 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
00048 sample_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
00049 sample_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
00050 sample_zoom->create_objects();
00051 sample_zoom->zoom_text->set_tooltip(_("Duration visible in the timeline"));
00052 sample_zoom->zoom_tumbler->set_tooltip(_("Duration visible in the timeline"));
00053 x += sample_zoom->get_w();
00054 amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
00055 amp_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
00056 amp_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
00057 amp_zoom->create_objects();
00058 amp_zoom->zoom_text->set_tooltip(_("Audio waveform scale"));
00059 amp_zoom->zoom_tumbler->set_tooltip(_("Audio waveform scale"));
00060 x += amp_zoom->get_w();
00061 track_zoom = new TrackZoomPanel(mwindow, this, x, y);
00062 track_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
00063 track_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
00064 track_zoom->create_objects();
00065 track_zoom->zoom_text->set_tooltip(_("Height of tracks in the timeline"));
00066 track_zoom->zoom_tumbler->set_tooltip(_("Height of tracks in the timeline"));
00067 x += track_zoom->get_w() + 10;
00068
00069 add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y));
00070 auto_type->create_objects();
00071 x += auto_type->get_w() + 10;
00072 #define DEFAULT_TEXT "000.00 to 000.00"
00073 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 0));
00074 x += auto_zoom->get_w();
00075 add_subwindow(auto_zoom_text = new ZoomTextBox(
00076 mwindow,
00077 this,
00078 x,
00079 y,
00080 DEFAULT_TEXT));
00081 x += auto_zoom_text->get_w() + 5;
00082 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 1));
00083 update_autozoom();
00084 x += auto_zoom->get_w() + 5;
00085
00086 add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
00087 x += from_value->get_w() + 5;
00088 add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
00089 x += length_value->get_w() + 5;
00090 add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
00091 x += to_value->get_w() + 5;
00092
00093 update_formatting(from_value);
00094 update_formatting(length_value);
00095 update_formatting(to_value);
00096
00097 add_subwindow(playback_value = new BC_Title(x, 100, _("--"), MEDIUMFONT, RED));
00098
00099 add_subwindow(zoom_value = new BC_Title(x, 100, _("--"), MEDIUMFONT, BLACK));
00100 update();
00101 return 0;
00102 }
00103
00104
00105 void ZoomBar::update_formatting(BC_TextBox *dst)
00106 {
00107 dst->set_separators(
00108 Units::format_to_separators(mwindow->edl->session->time_format));
00109 }
00110
00111 void ZoomBar::resize_event()
00112 {
00113 reposition_window(mwindow->theme->mzoom_x,
00114 mwindow->theme->mzoom_y,
00115 mwindow->theme->mzoom_w,
00116 mwindow->theme->mzoom_h);
00117
00118 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
00119 int x = 3, y = 1;
00120 if (sample_zoom) delete sample_zoom;
00121 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
00122 sample_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
00123 sample_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
00124 sample_zoom->create_objects();
00125
00126
00127
00128
00129 flash();
00130 }
00131
00132 void ZoomBar::redraw_time_dependancies()
00133 {
00134
00135 sample_zoom->update_menu();
00136 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
00137 update_formatting(from_value);
00138 update_formatting(length_value);
00139 update_formatting(to_value);
00140 update_autozoom();
00141 update_clocks();
00142 }
00143
00144 int ZoomBar::draw()
00145 {
00146 update();
00147 return 0;
00148 }
00149
00150 void ZoomBar::update_autozoom()
00151 {
00152 char string[BCTEXTLEN];
00153 switch (mwindow->edl->local_session->zoombar_showautotype) {
00154 case AUTOGROUPTYPE_AUDIO_FADE:
00155 case AUTOGROUPTYPE_VIDEO_FADE:
00156 sprintf(string, "%0.01f to %0.01f\n",
00157 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
00158 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
00159 break;
00160 case AUTOGROUPTYPE_ZOOM:
00161 sprintf(string, "%0.03f to %0.03f\n",
00162 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
00163 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
00164 break;
00165 case AUTOGROUPTYPE_X:
00166 case AUTOGROUPTYPE_Y:
00167 sprintf(string, "%0.0f to %.0f\n",
00168 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
00169 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
00170 break;
00171 }
00172 auto_zoom_text->update(string);
00173 }
00174
00175 int ZoomBar::update()
00176 {
00177 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
00178 amp_zoom->update(mwindow->edl->local_session->zoom_y);
00179 track_zoom->update(mwindow->edl->local_session->zoom_track);
00180 update_autozoom();
00181 update_clocks();
00182 return 0;
00183 }
00184
00185 int ZoomBar::update_clocks()
00186 {
00187 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
00188 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
00189 mwindow->edl->local_session->get_selectionstart(1));
00190 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
00191 return 0;
00192 }
00193
00194 int ZoomBar::update_playback(int64_t new_position)
00195 {
00196 if(new_position != old_position)
00197 {
00198 Units::totext(string,
00199 new_position,
00200 mwindow->edl->session->sample_rate,
00201 mwindow->edl->session->time_format,
00202 mwindow->edl->session->frame_rate,
00203 mwindow->edl->session->frames_per_foot);
00204 playback_value->update(string);
00205 old_position = new_position;
00206 }
00207 return 0;
00208 }
00209
00210 int ZoomBar::resize_event(int w, int h)
00211 {
00212
00213 reposition_window(0, h - this->get_h(), w, this->get_h());
00214 return 0;
00215 }
00216
00217
00218
00219 #define SET_FROM 1
00220 #define SET_LENGTH 2
00221 #define SET_TO 3
00222
00223
00224 int ZoomBar::set_selection(int which_one)
00225 {
00226 double start_position = mwindow->edl->local_session->get_selectionstart(1);
00227 double end_position = mwindow->edl->local_session->get_selectionend(1);
00228 double length = end_position - start_position;
00229
00230
00231
00232 switch(which_one)
00233 {
00234 case SET_LENGTH:
00235 start_position = Units::text_to_seconds(from_value->get_text(),
00236 mwindow->edl->session->sample_rate,
00237 mwindow->edl->session->time_format,
00238 mwindow->edl->session->frame_rate,
00239 mwindow->edl->session->frames_per_foot);
00240 length = Units::text_to_seconds(length_value->get_text(),
00241 mwindow->edl->session->sample_rate,
00242 mwindow->edl->session->time_format,
00243 mwindow->edl->session->frame_rate,
00244 mwindow->edl->session->frames_per_foot);
00245 end_position = start_position + length;
00246
00247 if(end_position < start_position)
00248 {
00249 start_position = end_position;
00250 mwindow->edl->local_session->set_selectionend(
00251 mwindow->edl->local_session->get_selectionstart(1));
00252 }
00253 break;
00254
00255 case SET_FROM:
00256 start_position = Units::text_to_seconds(from_value->get_text(),
00257 mwindow->edl->session->sample_rate,
00258 mwindow->edl->session->time_format,
00259 mwindow->edl->session->frame_rate,
00260 mwindow->edl->session->frames_per_foot);
00261 end_position = Units::text_to_seconds(to_value->get_text(),
00262 mwindow->edl->session->sample_rate,
00263 mwindow->edl->session->time_format,
00264 mwindow->edl->session->frame_rate,
00265 mwindow->edl->session->frames_per_foot);
00266
00267 if(end_position < start_position)
00268 {
00269 end_position = start_position;
00270 mwindow->edl->local_session->set_selectionend(
00271 mwindow->edl->local_session->get_selectionstart(1));
00272 }
00273 break;
00274
00275 case SET_TO:
00276 start_position = Units::text_to_seconds(from_value->get_text(),
00277 mwindow->edl->session->sample_rate,
00278 mwindow->edl->session->time_format,
00279 mwindow->edl->session->frame_rate,
00280 mwindow->edl->session->frames_per_foot);
00281 end_position = Units::text_to_seconds(to_value->get_text(),
00282 mwindow->edl->session->sample_rate,
00283 mwindow->edl->session->time_format,
00284 mwindow->edl->session->frame_rate,
00285 mwindow->edl->session->frames_per_foot);
00286
00287 if(end_position < start_position)
00288 {
00289 start_position = end_position;
00290 mwindow->edl->local_session->set_selectionend(
00291 mwindow->edl->local_session->get_selectionstart(1));
00292 }
00293 break;
00294 }
00295
00296 mwindow->edl->local_session->set_selectionstart(
00297 mwindow->edl->align_to_frame(start_position, 1));
00298 mwindow->edl->local_session->set_selectionend(
00299 mwindow->edl->align_to_frame(end_position, 1));
00300
00301
00302 mwindow->gui->timebar->update_highlights();
00303 mwindow->gui->cursor->hide();
00304 mwindow->gui->cursor->show();
00305 update();
00306 mwindow->sync_parameters(CHANGE_PARAMS);
00307 mwindow->gui->canvas->flash();
00308
00309 return 0;
00310 }
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow,
00324 ZoomBar *zoombar,
00325 int x,
00326 int y)
00327 : ZoomPanel(mwindow,
00328 zoombar,
00329 mwindow->edl->local_session->zoom_sample,
00330 x,
00331 y,
00332 110,
00333 MIN_ZOOM_TIME,
00334 MAX_ZOOM_TIME,
00335 ZOOM_TIME)
00336 {
00337 this->mwindow = mwindow;
00338 this->zoombar = zoombar;
00339 }
00340 int SampleZoomPanel::handle_event()
00341 {
00342 mwindow->zoom_sample((int64_t)get_value());
00343 return 1;
00344 }
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
00357 : ZoomPanel(mwindow,
00358 zoombar,
00359 mwindow->edl->local_session->zoom_y,
00360 x,
00361 y,
00362 80,
00363 MIN_AMP_ZOOM,
00364 MAX_AMP_ZOOM,
00365 ZOOM_LONG)
00366 {
00367 this->mwindow = mwindow;
00368 this->zoombar = zoombar;
00369 }
00370 int AmpZoomPanel::handle_event()
00371 {
00372 mwindow->zoom_amp((int64_t)get_value());
00373 return 1;
00374 }
00375
00376 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
00377 : ZoomPanel(mwindow,
00378 zoombar,
00379 mwindow->edl->local_session->zoom_track,
00380 x,
00381 y,
00382 70,
00383 MIN_TRACK_ZOOM,
00384 MAX_TRACK_ZOOM,
00385 ZOOM_LONG)
00386 {
00387 this->mwindow = mwindow;
00388 this->zoombar = zoombar;
00389 }
00390 int TrackZoomPanel::handle_event()
00391 {
00392 mwindow->zoom_track((int64_t)get_value());
00393 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
00394 return 1;
00395 }
00396
00397
00398
00399
00400 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
00401 : BC_Tumbler(x,
00402 y,
00403 mwindow->theme->get_image_set("zoombar_tumbler"))
00404 {
00405 this->mwindow = mwindow;
00406 this->zoombar = zoombar;
00407 this->changemax = changemax;
00408 if (changemax)
00409 set_tooltip(_("Automation range maximum"));
00410 else
00411 set_tooltip(_("Automation range minimum"));
00412 }
00413
00414 int AutoZoom::handle_up_event()
00415 {
00416 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
00417
00418 mwindow->gui->zoombar->update_autozoom();
00419 mwindow->gui->canvas->draw_overlays();
00420 mwindow->gui->patchbay->update();
00421 mwindow->gui->canvas->flash();
00422 return 1;
00423 }
00424
00425 int AutoZoom::handle_down_event()
00426 {
00427 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
00428
00429 mwindow->gui->zoombar->update_autozoom();
00430 mwindow->gui->canvas->draw_overlays();
00431 mwindow->gui->patchbay->update();
00432 mwindow->gui->canvas->flash();
00433 return 1;
00434 }
00435
00436
00437
00438 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
00439 : BC_PopupMenu(x, y, 120,to_text(mwindow->edl->local_session->zoombar_showautotype), 1)
00440 {
00441 this->mwindow = mwindow;
00442 this->zoombar = zoombar;
00443 set_tooltip(_("Automation Type"));
00444 }
00445
00446 void AutoTypeMenu::create_objects()
00447 {
00448 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
00449 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
00450 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
00451 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
00452 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
00453 }
00454
00455 char* AutoTypeMenu::to_text(int mode)
00456 {
00457 switch(mode)
00458 {
00459 case AUTOGROUPTYPE_AUDIO_FADE:
00460 return _("Audio Fade:");
00461 case AUTOGROUPTYPE_VIDEO_FADE:
00462 return _("Video Fade:");
00463 case AUTOGROUPTYPE_ZOOM:
00464 return _("Zoom:");
00465 case AUTOGROUPTYPE_X:
00466 return _("X:");
00467 case AUTOGROUPTYPE_Y:
00468 return _("Y:");
00469 default:
00470 return _("??");
00471 }
00472 }
00473
00474 int AutoTypeMenu::from_text(char *text)
00475 {
00476 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE)))
00477 return AUTOGROUPTYPE_AUDIO_FADE;
00478 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE)))
00479 return AUTOGROUPTYPE_VIDEO_FADE;
00480 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM)))
00481 return AUTOGROUPTYPE_ZOOM;
00482 if(!strcmp(text, to_text(AUTOGROUPTYPE_X)))
00483 return AUTOGROUPTYPE_X;
00484 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y)))
00485 return AUTOGROUPTYPE_Y;
00486 }
00487
00488 int AutoTypeMenu::handle_event()
00489 {
00490 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
00491 this->zoombar->update_autozoom();
00492 }
00493
00494
00495 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, char *text)
00496 : BC_TextBox(x, y, 130, 1, text)
00497 {
00498 this->mwindow = mwindow;
00499 this->zoombar = zoombar;
00500 set_tooltip(_("Automation range"));
00501 }
00502
00503 int ZoomTextBox::button_press_event()
00504 {
00505 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
00506 BC_TextBox::button_press_event();
00507 return 0;
00508 }
00509 if (!is_event_win()) return 0;
00510
00511 int changemax = 1;
00512 if (get_relative_cursor_x() < get_w()/2)
00513 changemax = 0;
00514
00515
00516 if (get_buttonpress() == 4)
00517 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
00518
00519
00520 if (get_buttonpress() == 5)
00521 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
00522
00523 mwindow->gui->zoombar->update_autozoom();
00524 mwindow->gui->canvas->draw_overlays();
00525 mwindow->gui->patchbay->update();
00526 mwindow->gui->canvas->flash();
00527 return 1;
00528 }
00529
00530 int ZoomTextBox::handle_event()
00531 {
00532 float min, max;
00533 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
00534 {
00535 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
00536 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
00537 if (max > min)
00538 {
00539 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
00540 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
00541 mwindow->gui->zoombar->update_autozoom();
00542 mwindow->gui->canvas->draw_overlays();
00543 mwindow->gui->patchbay->update();
00544 mwindow->gui->canvas->flash();
00545 }
00546 }
00547
00548 return 0;
00549 }
00550
00551
00552
00553
00554
00555 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
00556 : BC_TextBox(x, y, 90, 1, "")
00557 {
00558 this->mwindow = mwindow;
00559 this->zoombar = zoombar;
00560 set_tooltip(_("Selection start time"));
00561 }
00562
00563 int FromTextBox::handle_event()
00564 {
00565 if(get_keypress() == 13)
00566 {
00567 zoombar->set_selection(SET_FROM);
00568 return 1;
00569 }
00570 return 0;
00571 }
00572
00573 int FromTextBox::update_position(double new_position)
00574 {
00575 new_position += mwindow->edl->session->get_frame_offset() /
00576 mwindow->edl->session->frame_rate;;
00577 Units::totext(string,
00578 new_position,
00579 mwindow->edl->session->time_format,
00580 mwindow->edl->session->sample_rate,
00581 mwindow->edl->session->frame_rate,
00582 mwindow->edl->session->frames_per_foot);
00583
00584 update(string);
00585 return 0;
00586 }
00587
00588
00589
00590
00591
00592
00593 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
00594 : BC_TextBox(x, y, 90, 1, "")
00595 {
00596 this->mwindow = mwindow;
00597 this->zoombar = zoombar;
00598 set_tooltip(_("Selection length"));
00599 }
00600
00601 int LengthTextBox::handle_event()
00602 {
00603 if(get_keypress() == 13)
00604 {
00605 zoombar->set_selection(SET_LENGTH);
00606 return 1;
00607 }
00608 return 0;
00609 }
00610
00611 int LengthTextBox::update_position(double new_position)
00612 {
00613 Units::totext(string,
00614 new_position,
00615 mwindow->edl->session->time_format,
00616 mwindow->edl->session->sample_rate,
00617 mwindow->edl->session->frame_rate,
00618 mwindow->edl->session->frames_per_foot);
00619 update(string);
00620 return 0;
00621 }
00622
00623
00624
00625
00626
00627 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
00628 : BC_TextBox(x, y, 90, 1, "")
00629 {
00630 this->mwindow = mwindow;
00631 this->zoombar = zoombar;
00632 set_tooltip(_("Selection end time"));
00633 }
00634
00635 int ToTextBox::handle_event()
00636 {
00637 if(get_keypress() == 13)
00638 {
00639 zoombar->set_selection(SET_TO);
00640 return 1;
00641 }
00642 return 0;
00643 }
00644
00645 int ToTextBox::update_position(double new_position)
00646 {
00647 new_position += mwindow->edl->session->get_frame_offset() /
00648 mwindow->edl->session->frame_rate;
00649 Units::totext(string,
00650 new_position,
00651 mwindow->edl->session->time_format,
00652 mwindow->edl->session->sample_rate,
00653 mwindow->edl->session->frame_rate,
00654 mwindow->edl->session->frames_per_foot);
00655 update(string);
00656 return 0;
00657 }