3 #include "edlsession.h"
5 #include "localsession.h"
6 #include "maincursor.h"
8 #include "mwindowgui.h"
9 #include "mainsession.h"
11 #include "preferences.h"
13 #include "trackcanvas.h"
21 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
22 : BC_SubWindow(mwindow->theme->mzoom_x,
23 mwindow->theme->mzoom_y,
24 mwindow->theme->mzoom_w,
25 mwindow->theme->mzoom_h)
28 this->mwindow = mwindow;
39 int ZoomBar::create_objects()
43 mwindow->theme->get_image_set("zoombar_menu", 0)[0]->get_h() / 2;
45 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
46 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
47 sample_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
48 sample_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
49 sample_zoom->create_objects();
50 x += sample_zoom->get_w();
51 amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
52 amp_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
53 amp_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
54 amp_zoom->create_objects();
55 x += amp_zoom->get_w();
56 track_zoom = new TrackZoomPanel(mwindow, this, x, y);
57 track_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
58 track_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
59 track_zoom->create_objects();
60 x += track_zoom->get_w() + 10;
62 add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y));
63 auto_type->create_objects();
64 x += auto_type->get_w() + 10;
65 #define DEFAULT_TEXT "000.00 to 000.00"
66 add_subwindow(auto_zoom_text = new ZoomTextBox(
72 x += auto_zoom_text->get_w() + 5;
73 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y));
75 x += auto_zoom->get_w() + 5;
77 add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
78 x += from_value->get_w() + 5;
79 add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
80 x += length_value->get_w() + 5;
81 add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
82 x += to_value->get_w() + 5;
84 update_formatting(from_value);
85 update_formatting(length_value);
86 update_formatting(to_value);
88 add_subwindow(playback_value = new BC_Title(x, 100, _("--"), MEDIUMFONT, RED));
90 add_subwindow(zoom_value = new BC_Title(x, 100, _("--"), MEDIUMFONT, BLACK));
96 void ZoomBar::update_formatting(BC_TextBox *dst)
99 Units::format_to_separators(mwindow->edl->session->time_format));
102 void ZoomBar::resize_event()
104 reposition_window(mwindow->theme->mzoom_x,
105 mwindow->theme->mzoom_y,
106 mwindow->theme->mzoom_w,
107 mwindow->theme->mzoom_h);
109 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
111 // sample_zoom->reposition_window(x, y);
112 // x += sample_zoom->get_w();
113 // amp_zoom->reposition_window(x, y);
114 // x += amp_zoom->get_w();
115 // track_zoom->reposition_window(x, y);
119 void ZoomBar::redraw_time_dependancies()
121 // Recalculate sample zoom menu
122 sample_zoom->update_menu();
123 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
124 update_formatting(from_value);
125 update_formatting(length_value);
126 update_formatting(to_value);
137 void ZoomBar::update_autozoom()
139 char string[BCTEXTLEN];
140 switch (mwindow->edl->local_session->zoombar_showautotype) {
141 case AUTOGROUPTYPE_AUDIO_FADE:
142 case AUTOGROUPTYPE_VIDEO_FADE:
143 sprintf(string, "%0.01f to %0.01f\n",
144 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
145 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
147 case AUTOGROUPTYPE_ZOOM:
148 sprintf(string, "%0.03f to %0.03f\n",
149 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
150 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
152 case AUTOGROUPTYPE_X:
153 case AUTOGROUPTYPE_Y:
154 sprintf(string, "%0.0f to %.0f\n",
155 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
156 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
159 auto_zoom_text->update(string);
162 int ZoomBar::update()
164 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
165 amp_zoom->update(mwindow->edl->local_session->zoom_y);
166 track_zoom->update(mwindow->edl->local_session->zoom_track);
172 int ZoomBar::update_clocks()
174 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
175 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
176 mwindow->edl->local_session->get_selectionstart(1));
177 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
181 int ZoomBar::update_playback(int64_t new_position)
183 if(new_position != old_position)
185 Units::totext(string,
187 mwindow->edl->session->sample_rate,
188 mwindow->edl->session->time_format,
189 mwindow->edl->session->frame_rate,
190 mwindow->edl->session->frames_per_foot);
191 playback_value->update(string);
192 old_position = new_position;
197 int ZoomBar::resize_event(int w, int h)
199 // don't change anything but y and width
200 reposition_window(0, h - this->get_h(), w, this->get_h());
205 // Values for which_one
211 int ZoomBar::set_selection(int which_one)
213 double start_position = mwindow->edl->local_session->get_selectionstart(1);
214 double end_position = mwindow->edl->local_session->get_selectionend(1);
215 double length = end_position - start_position;
222 start_position = Units::text_to_seconds(from_value->get_text(),
223 mwindow->edl->session->sample_rate,
224 mwindow->edl->session->time_format,
225 mwindow->edl->session->frame_rate,
226 mwindow->edl->session->frames_per_foot);
227 length = Units::text_to_seconds(length_value->get_text(),
228 mwindow->edl->session->sample_rate,
229 mwindow->edl->session->time_format,
230 mwindow->edl->session->frame_rate,
231 mwindow->edl->session->frames_per_foot);
232 end_position = start_position + length;
234 if(end_position < start_position)
236 start_position = end_position;
237 mwindow->edl->local_session->set_selectionend(
238 mwindow->edl->local_session->get_selectionstart(1));
243 start_position = Units::text_to_seconds(from_value->get_text(),
244 mwindow->edl->session->sample_rate,
245 mwindow->edl->session->time_format,
246 mwindow->edl->session->frame_rate,
247 mwindow->edl->session->frames_per_foot);
248 end_position = Units::text_to_seconds(to_value->get_text(),
249 mwindow->edl->session->sample_rate,
250 mwindow->edl->session->time_format,
251 mwindow->edl->session->frame_rate,
252 mwindow->edl->session->frames_per_foot);
254 if(end_position < start_position)
256 end_position = start_position;
257 mwindow->edl->local_session->set_selectionend(
258 mwindow->edl->local_session->get_selectionstart(1));
263 start_position = Units::text_to_seconds(from_value->get_text(),
264 mwindow->edl->session->sample_rate,
265 mwindow->edl->session->time_format,
266 mwindow->edl->session->frame_rate,
267 mwindow->edl->session->frames_per_foot);
268 end_position = Units::text_to_seconds(to_value->get_text(),
269 mwindow->edl->session->sample_rate,
270 mwindow->edl->session->time_format,
271 mwindow->edl->session->frame_rate,
272 mwindow->edl->session->frames_per_foot);
274 if(end_position < start_position)
276 start_position = end_position;
277 mwindow->edl->local_session->set_selectionend(
278 mwindow->edl->local_session->get_selectionstart(1));
283 mwindow->edl->local_session->set_selectionstart(
284 mwindow->edl->align_to_frame(start_position, 1));
285 mwindow->edl->local_session->set_selectionend(
286 mwindow->edl->align_to_frame(end_position, 1));
289 mwindow->gui->timebar->update_highlights();
290 mwindow->gui->cursor->hide();
291 mwindow->gui->cursor->show();
293 mwindow->sync_parameters(CHANGE_PARAMS);
294 mwindow->gui->canvas->flash();
310 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow,
316 mwindow->edl->local_session->zoom_sample,
324 this->mwindow = mwindow;
325 this->zoombar = zoombar;
327 int SampleZoomPanel::handle_event()
329 mwindow->zoom_sample((int64_t)get_value());
343 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
346 mwindow->edl->local_session->zoom_y,
354 this->mwindow = mwindow;
355 this->zoombar = zoombar;
357 int AmpZoomPanel::handle_event()
359 mwindow->zoom_amp((int64_t)get_value());
363 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
366 mwindow->edl->local_session->zoom_track,
374 this->mwindow = mwindow;
375 this->zoombar = zoombar;
377 int TrackZoomPanel::handle_event()
379 mwindow->zoom_track((int64_t)get_value());
380 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
387 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
390 mwindow->theme->get_image_set("zoombar_tumbler"))
392 this->mwindow = mwindow;
393 this->zoombar = zoombar;
396 int AutoZoom::handle_up_event()
398 mwindow->expand_autos();
402 int AutoZoom::handle_down_event()
404 mwindow->shrink_autos();
410 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
411 : BC_PopupMenu(x, y, 120,to_text(mwindow->edl->local_session->zoombar_showautotype), 1)
413 this->mwindow = mwindow;
414 this->zoombar = zoombar;
417 void AutoTypeMenu::create_objects()
419 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
420 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
421 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
422 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
423 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
426 char* AutoTypeMenu::to_text(int mode)
430 case AUTOGROUPTYPE_AUDIO_FADE:
431 return _("Audio Fade:");
432 case AUTOGROUPTYPE_VIDEO_FADE:
433 return _("Video Fade:");
434 case AUTOGROUPTYPE_ZOOM:
436 case AUTOGROUPTYPE_X:
438 case AUTOGROUPTYPE_Y:
445 int AutoTypeMenu::from_text(char *text)
447 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE)))
448 return AUTOGROUPTYPE_AUDIO_FADE;
449 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE)))
450 return AUTOGROUPTYPE_VIDEO_FADE;
451 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM)))
452 return AUTOGROUPTYPE_ZOOM;
453 if(!strcmp(text, to_text(AUTOGROUPTYPE_X)))
454 return AUTOGROUPTYPE_X;
455 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y)))
456 return AUTOGROUPTYPE_Y;
459 int AutoTypeMenu::handle_event()
461 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
462 this->zoombar->update_autozoom();
466 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, char *text)
467 : BC_TextBox(x, y, 130, 1, text)
469 this->mwindow = mwindow;
470 this->zoombar = zoombar;
473 int ZoomTextBox::button_press_event()
477 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
478 BC_TextBox::button_press_event();
481 if (!is_event_win()) return 0;
483 if (get_relative_cursor_x() < get_w()/2)
484 val = mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype];
486 val = mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype];
488 if (get_buttonpress() == 5) {
489 switch (mwindow->edl->local_session->zoombar_showautotype) {
490 case AUTOGROUPTYPE_AUDIO_FADE:
493 case AUTOGROUPTYPE_VIDEO_FADE:
495 if (val < 0) val = 0;
497 case AUTOGROUPTYPE_ZOOM:
498 if (val > 0) val = val/2;
499 if (val < 0) val = 0;
501 case AUTOGROUPTYPE_X:
502 case AUTOGROUPTYPE_Y:
508 if (get_buttonpress() == 4) {
509 switch (mwindow->edl->local_session->zoombar_showautotype) {
510 case AUTOGROUPTYPE_AUDIO_FADE:
513 case AUTOGROUPTYPE_VIDEO_FADE:
515 if (val < 0) val = 0;
517 case AUTOGROUPTYPE_ZOOM:
523 case AUTOGROUPTYPE_X:
524 case AUTOGROUPTYPE_Y:
525 val = floor(val + 5);
530 if (get_relative_cursor_x() < get_w()/2) {
531 if (val < mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype])
532 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = val;
535 if (val > mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype])
536 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = val;
538 mwindow->gui->zoombar->update_autozoom();
539 mwindow->gui->canvas->draw_overlays();
540 mwindow->gui->canvas->flash();
544 int ZoomTextBox::handle_event()
547 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
550 && ( mwindow->edl->local_session->zoombar_showautotype != AUTOGROUPTYPE_ZOOM
551 || (max >= 0.000 && min >= 0.000) )
554 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
555 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
556 mwindow->gui->zoombar->update_autozoom();
557 mwindow->gui->canvas->draw_overlays();
558 mwindow->gui->canvas->flash();
560 // TODO: Make the text turn red when it's a bad range..
568 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
569 : BC_TextBox(x, y, 90, 1, "")
571 this->mwindow = mwindow;
572 this->zoombar = zoombar;
575 int FromTextBox::handle_event()
577 if(get_keypress() == 13)
579 zoombar->set_selection(SET_FROM);
585 int FromTextBox::update_position(double new_position)
587 new_position += mwindow->edl->session->get_frame_offset() /
588 mwindow->edl->session->frame_rate;;
589 Units::totext(string,
591 mwindow->edl->session->time_format,
592 mwindow->edl->session->sample_rate,
593 mwindow->edl->session->frame_rate,
594 mwindow->edl->session->frames_per_foot);
595 //printf("FromTextBox::update_position %f %s\n", new_position, string);
605 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
606 : BC_TextBox(x, y, 90, 1, "")
608 this->mwindow = mwindow;
609 this->zoombar = zoombar;
612 int LengthTextBox::handle_event()
614 if(get_keypress() == 13)
616 zoombar->set_selection(SET_LENGTH);
622 int LengthTextBox::update_position(double new_position)
624 Units::totext(string,
626 mwindow->edl->session->time_format,
627 mwindow->edl->session->sample_rate,
628 mwindow->edl->session->frame_rate,
629 mwindow->edl->session->frames_per_foot);
638 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
639 : BC_TextBox(x, y, 90, 1, "")
641 this->mwindow = mwindow;
642 this->zoombar = zoombar;
645 int ToTextBox::handle_event()
647 if(get_keypress() == 13)
649 zoombar->set_selection(SET_TO);
655 int ToTextBox::update_position(double new_position)
657 new_position += mwindow->edl->session->get_frame_offset() /
658 mwindow->edl->session->frame_rate;
659 Units::totext(string,
661 mwindow->edl->session->time_format,
662 mwindow->edl->session->sample_rate,
663 mwindow->edl->session->frame_rate,
664 mwindow->edl->session->frames_per_foot);