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 "theme.h"
00013 #include "trackcanvas.h"
00014 #include "tracks.h"
00015 #include "units.h"
00016 #include "zoombar.h"
00017
00018
00019
00020
00021 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
00022 : BC_SubWindow(mwindow->theme->mzoom_x,
00023 mwindow->theme->mzoom_y,
00024 mwindow->theme->mzoom_w,
00025 mwindow->theme->mzoom_h)
00026 {
00027 this->gui = gui;
00028 this->mwindow = mwindow;
00029 old_position = 0;
00030 }
00031
00032 ZoomBar::~ZoomBar()
00033 {
00034 delete sample_zoom;
00035 delete amp_zoom;
00036 delete track_zoom;
00037 }
00038
00039 int ZoomBar::create_objects()
00040 {
00041 int x = 3;
00042 int y = get_h() / 2 -
00043 mwindow->theme->get_image_set("zoombar_menu", 0)[0]->get_h() / 2;
00044
00045 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
00046 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
00047 sample_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
00048 sample_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
00049 sample_zoom->create_objects();
00050 x += sample_zoom->get_w();
00051 amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
00052 amp_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
00053 amp_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
00054 amp_zoom->create_objects();
00055 x += amp_zoom->get_w();
00056 track_zoom = new TrackZoomPanel(mwindow, this, x, y);
00057 track_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
00058 track_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
00059 track_zoom->create_objects();
00060 x += track_zoom->get_w() + 10;
00061
00062 #define DEFAULT_TEXT "000.00 - 000.00"
00063 add_subwindow(auto_zoom_text = new BC_Title(
00064 x,
00065 get_h() / 2 - BC_Title::calculate_h(this, "0") / 2,
00066 DEFAULT_TEXT));
00067 x += auto_zoom_text->get_w() + 5;
00068 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y));
00069 update_autozoom();
00070 x += auto_zoom->get_w() + 5;
00071
00072 add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
00073 x += from_value->get_w() + 5;
00074 add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
00075 x += length_value->get_w() + 5;
00076 add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
00077 x += to_value->get_w() + 5;
00078
00079 update_formatting(from_value);
00080 update_formatting(length_value);
00081 update_formatting(to_value);
00082
00083 add_subwindow(playback_value = new BC_Title(x, 100, _("--"), MEDIUMFONT, RED));
00084
00085 add_subwindow(zoom_value = new BC_Title(x, 100, _("--"), MEDIUMFONT, BLACK));
00086 update();
00087 return 0;
00088 }
00089
00090
00091 void ZoomBar::update_formatting(BC_TextBox *dst)
00092 {
00093 dst->set_separators(
00094 Units::format_to_separators(mwindow->edl->session->time_format));
00095 }
00096
00097 void ZoomBar::resize_event()
00098 {
00099 reposition_window(mwindow->theme->mzoom_x,
00100 mwindow->theme->mzoom_y,
00101 mwindow->theme->mzoom_w,
00102 mwindow->theme->mzoom_h);
00103
00104 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
00105
00106
00107
00108
00109
00110
00111 flash();
00112 }
00113
00114 void ZoomBar::redraw_time_dependancies()
00115 {
00116
00117 sample_zoom->update_menu();
00118 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
00119 update_formatting(from_value);
00120 update_formatting(length_value);
00121 update_formatting(to_value);
00122 update_autozoom();
00123 update_clocks();
00124 }
00125
00126 int ZoomBar::draw()
00127 {
00128 update();
00129 return 0;
00130 }
00131
00132 void ZoomBar::update_autozoom()
00133 {
00134 char string[BCTEXTLEN];
00135 sprintf(string, "%0.02f - %0.02f\n",
00136 mwindow->edl->local_session->automation_min,
00137 mwindow->edl->local_session->automation_max);
00138 auto_zoom_text->update(string);
00139 }
00140
00141 int ZoomBar::update()
00142 {
00143 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
00144 amp_zoom->update(mwindow->edl->local_session->zoom_y);
00145 track_zoom->update(mwindow->edl->local_session->zoom_track);
00146 update_autozoom();
00147 update_clocks();
00148 return 0;
00149 }
00150
00151 int ZoomBar::update_clocks()
00152 {
00153 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
00154 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
00155 mwindow->edl->local_session->get_selectionstart(1));
00156 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
00157 return 0;
00158 }
00159
00160 int ZoomBar::update_playback(int64_t new_position)
00161 {
00162 if(new_position != old_position)
00163 {
00164 Units::totext(string,
00165 new_position,
00166 mwindow->edl->session->sample_rate,
00167 mwindow->edl->session->time_format,
00168 mwindow->edl->session->frame_rate,
00169 mwindow->edl->session->frames_per_foot);
00170 playback_value->update(string);
00171 old_position = new_position;
00172 }
00173 return 0;
00174 }
00175
00176 int ZoomBar::resize_event(int w, int h)
00177 {
00178
00179 reposition_window(0, h - this->get_h(), w, this->get_h());
00180 return 0;
00181 }
00182
00183
00184
00185 #define SET_FROM 1
00186 #define SET_LENGTH 2
00187 #define SET_TO 3
00188
00189
00190 int ZoomBar::set_selection(int which_one)
00191 {
00192 double start_position = mwindow->edl->local_session->get_selectionstart(1);
00193 double end_position = mwindow->edl->local_session->get_selectionend(1);
00194 double length = end_position - start_position;
00195
00196
00197
00198 switch(which_one)
00199 {
00200 case SET_LENGTH:
00201 start_position = Units::text_to_seconds(from_value->get_text(),
00202 mwindow->edl->session->sample_rate,
00203 mwindow->edl->session->time_format,
00204 mwindow->edl->session->frame_rate,
00205 mwindow->edl->session->frames_per_foot);
00206 length = Units::text_to_seconds(length_value->get_text(),
00207 mwindow->edl->session->sample_rate,
00208 mwindow->edl->session->time_format,
00209 mwindow->edl->session->frame_rate,
00210 mwindow->edl->session->frames_per_foot);
00211 end_position = start_position + length;
00212
00213 if(end_position < start_position)
00214 {
00215 start_position = end_position;
00216 mwindow->edl->local_session->set_selectionend(
00217 mwindow->edl->local_session->get_selectionstart(1));
00218 }
00219 break;
00220
00221 case SET_FROM:
00222 start_position = Units::text_to_seconds(from_value->get_text(),
00223 mwindow->edl->session->sample_rate,
00224 mwindow->edl->session->time_format,
00225 mwindow->edl->session->frame_rate,
00226 mwindow->edl->session->frames_per_foot);
00227 end_position = Units::text_to_seconds(to_value->get_text(),
00228 mwindow->edl->session->sample_rate,
00229 mwindow->edl->session->time_format,
00230 mwindow->edl->session->frame_rate,
00231 mwindow->edl->session->frames_per_foot);
00232
00233 if(end_position < start_position)
00234 {
00235 end_position = start_position;
00236 mwindow->edl->local_session->set_selectionend(
00237 mwindow->edl->local_session->get_selectionstart(1));
00238 }
00239 break;
00240
00241 case SET_TO:
00242 start_position = Units::text_to_seconds(from_value->get_text(),
00243 mwindow->edl->session->sample_rate,
00244 mwindow->edl->session->time_format,
00245 mwindow->edl->session->frame_rate,
00246 mwindow->edl->session->frames_per_foot);
00247 end_position = Units::text_to_seconds(to_value->get_text(),
00248 mwindow->edl->session->sample_rate,
00249 mwindow->edl->session->time_format,
00250 mwindow->edl->session->frame_rate,
00251 mwindow->edl->session->frames_per_foot);
00252
00253 if(end_position < start_position)
00254 {
00255 start_position = end_position;
00256 mwindow->edl->local_session->set_selectionend(
00257 mwindow->edl->local_session->get_selectionstart(1));
00258 }
00259 break;
00260 }
00261
00262 mwindow->edl->local_session->set_selectionstart(
00263 mwindow->edl->align_to_frame(start_position, 1));
00264 mwindow->edl->local_session->set_selectionend(
00265 mwindow->edl->align_to_frame(end_position, 1));
00266
00267
00268 mwindow->gui->timebar->update_highlights();
00269 mwindow->gui->cursor->hide();
00270 mwindow->gui->cursor->show();
00271 update();
00272 mwindow->sync_parameters(CHANGE_PARAMS);
00273 mwindow->gui->canvas->flash();
00274
00275 return 0;
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow,
00290 ZoomBar *zoombar,
00291 int x,
00292 int y)
00293 : ZoomPanel(mwindow,
00294 zoombar,
00295 mwindow->edl->local_session->zoom_sample,
00296 x,
00297 y,
00298 110,
00299 MIN_ZOOM_TIME,
00300 MAX_ZOOM_TIME,
00301 ZOOM_TIME)
00302 {
00303 this->mwindow = mwindow;
00304 this->zoombar = zoombar;
00305 }
00306 int SampleZoomPanel::handle_event()
00307 {
00308 mwindow->zoom_sample((int64_t)get_value());
00309 return 1;
00310 }
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
00323 : ZoomPanel(mwindow,
00324 zoombar,
00325 mwindow->edl->local_session->zoom_y,
00326 x,
00327 y,
00328 80,
00329 MIN_AMP_ZOOM,
00330 MAX_AMP_ZOOM,
00331 ZOOM_LONG)
00332 {
00333 this->mwindow = mwindow;
00334 this->zoombar = zoombar;
00335 }
00336 int AmpZoomPanel::handle_event()
00337 {
00338 mwindow->zoom_amp((int64_t)get_value());
00339 return 1;
00340 }
00341
00342 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
00343 : ZoomPanel(mwindow,
00344 zoombar,
00345 mwindow->edl->local_session->zoom_track,
00346 x,
00347 y,
00348 70,
00349 MIN_TRACK_ZOOM,
00350 MAX_TRACK_ZOOM,
00351 ZOOM_LONG)
00352 {
00353 this->mwindow = mwindow;
00354 this->zoombar = zoombar;
00355 }
00356 int TrackZoomPanel::handle_event()
00357 {
00358 mwindow->zoom_track((int64_t)get_value());
00359 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
00360 return 1;
00361 }
00362
00363
00364
00365
00366 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
00367 : BC_Tumbler(x,
00368 y,
00369 mwindow->theme->get_image_set("zoombar_tumbler"))
00370 {
00371 this->mwindow = mwindow;
00372 this->zoombar = zoombar;
00373 }
00374
00375 int AutoZoom::handle_up_event()
00376 {
00377 mwindow->expand_autos();
00378 return 1;
00379 }
00380
00381 int AutoZoom::handle_down_event()
00382 {
00383 mwindow->shrink_autos();
00384 return 1;
00385 }
00386
00387
00388
00389
00390
00391
00392
00393
00394 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
00395 : BC_TextBox(x, y, 90, 1, "")
00396 {
00397 this->mwindow = mwindow;
00398 this->zoombar = zoombar;
00399 }
00400
00401 int FromTextBox::handle_event()
00402 {
00403 if(get_keypress() == 13)
00404 {
00405 zoombar->set_selection(SET_FROM);
00406 return 1;
00407 }
00408 return 0;
00409 }
00410
00411 int FromTextBox::update_position(double new_position)
00412 {
00413 new_position += mwindow->edl->session->get_frame_offset() /
00414 mwindow->edl->session->frame_rate;;
00415 Units::totext(string,
00416 new_position,
00417 mwindow->edl->session->time_format,
00418 mwindow->edl->session->sample_rate,
00419 mwindow->edl->session->frame_rate,
00420 mwindow->edl->session->frames_per_foot);
00421
00422 update(string);
00423 return 0;
00424 }
00425
00426
00427
00428
00429
00430
00431 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
00432 : BC_TextBox(x, y, 90, 1, "")
00433 {
00434 this->mwindow = mwindow;
00435 this->zoombar = zoombar;
00436 }
00437
00438 int LengthTextBox::handle_event()
00439 {
00440 if(get_keypress() == 13)
00441 {
00442 zoombar->set_selection(SET_LENGTH);
00443 return 1;
00444 }
00445 return 0;
00446 }
00447
00448 int LengthTextBox::update_position(double new_position)
00449 {
00450 Units::totext(string,
00451 new_position,
00452 mwindow->edl->session->time_format,
00453 mwindow->edl->session->sample_rate,
00454 mwindow->edl->session->frame_rate,
00455 mwindow->edl->session->frames_per_foot);
00456 update(string);
00457 return 0;
00458 }
00459
00460
00461
00462
00463
00464 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
00465 : BC_TextBox(x, y, 90, 1, "")
00466 {
00467 this->mwindow = mwindow;
00468 this->zoombar = zoombar;
00469 }
00470
00471 int ToTextBox::handle_event()
00472 {
00473 if(get_keypress() == 13)
00474 {
00475 zoombar->set_selection(SET_TO);
00476 return 1;
00477 }
00478 return 0;
00479 }
00480
00481 int ToTextBox::update_position(double new_position)
00482 {
00483 new_position += mwindow->edl->session->get_frame_offset() /
00484 mwindow->edl->session->frame_rate;
00485 Units::totext(string,
00486 new_position,
00487 mwindow->edl->session->time_format,
00488 mwindow->edl->session->sample_rate,
00489 mwindow->edl->session->frame_rate,
00490 mwindow->edl->session->frames_per_foot);
00491 update(string);
00492 return 0;
00493 }