4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "apatchgui.inc"
25 #include "edlsession.h"
27 #include "localsession.h"
28 #include "maincursor.h"
30 #include "mwindowgui.h"
31 #include "mainsession.h"
33 #include "preferences.h"
35 #include "trackcanvas.h"
38 #include "vpatchgui.inc"
44 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
45 : BC_SubWindow(mwindow->theme->mzoom_x,
46 mwindow->theme->mzoom_y,
47 mwindow->theme->mzoom_w,
48 mwindow->theme->mzoom_h)
51 this->mwindow = mwindow;
62 void ZoomBar::create_objects()
66 mwindow->theme->get_image_set("zoombar_menu", 0)[0]->get_h() / 2;
68 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
69 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
70 sample_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
71 sample_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
72 sample_zoom->create_objects();
73 sample_zoom->zoom_text->set_tooltip(_("Duration visible in the timeline"));
74 sample_zoom->zoom_tumbler->set_tooltip(_("Duration visible in the timeline"));
75 x += sample_zoom->get_w();
76 amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
77 amp_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
78 amp_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
79 amp_zoom->create_objects();
80 amp_zoom->zoom_text->set_tooltip(_("Audio waveform scale"));
81 amp_zoom->zoom_tumbler->set_tooltip(_("Audio waveform scale"));
82 x += amp_zoom->get_w();
83 track_zoom = new TrackZoomPanel(mwindow, this, x, y);
84 track_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
85 track_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
86 track_zoom->create_objects();
87 track_zoom->zoom_text->set_tooltip(_("Height of tracks in the timeline"));
88 track_zoom->zoom_tumbler->set_tooltip(_("Height of tracks in the timeline"));
89 x += track_zoom->get_w() + 10;
91 add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y));
92 auto_type->create_objects();
93 x += auto_type->get_w() + 10;
94 #define DEFAULT_TEXT "000.00 to 000.00"
95 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 0));
96 x += auto_zoom->get_w();
97 add_subwindow(auto_zoom_text = new ZoomTextBox(
103 x += auto_zoom_text->get_w() + 5;
104 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 1));
106 x += auto_zoom->get_w() + 5;
108 add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
109 x += from_value->get_w() + 5;
110 add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
111 x += length_value->get_w() + 5;
112 add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
113 x += to_value->get_w() + 5;
115 update_formatting(from_value);
116 update_formatting(length_value);
117 update_formatting(to_value);
119 add_subwindow(playback_value = new BC_Title(x, 100, "--", MEDIUMFONT, RED));
121 add_subwindow(zoom_value = new BC_Title(x, 100, "--", MEDIUMFONT, BLACK));
126 void ZoomBar::update_formatting(BC_TextBox *dst)
129 Units::format_to_separators(mwindow->edl->session->time_format));
132 void ZoomBar::resize_event()
134 reposition_window(mwindow->theme->mzoom_x,
135 mwindow->theme->mzoom_y,
136 mwindow->theme->mzoom_w,
137 mwindow->theme->mzoom_h);
139 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
141 if (sample_zoom) delete sample_zoom;
142 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
143 sample_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
144 sample_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
145 sample_zoom->create_objects();
146 // x += sample_zoom->get_w();
147 // amp_zoom->reposition_window(x, y);
148 // x += amp_zoom->get_w();
149 // track_zoom->reposition_window(x, y);
153 void ZoomBar::redraw_time_dependancies()
155 // Recalculate sample zoom menu
156 sample_zoom->update_menu();
157 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
158 update_formatting(from_value);
159 update_formatting(length_value);
160 update_formatting(to_value);
171 void ZoomBar::update_autozoom()
173 char string[BCTEXTLEN];
174 switch (mwindow->edl->local_session->zoombar_showautotype) {
175 case AUTOGROUPTYPE_AUDIO_FADE:
176 case AUTOGROUPTYPE_VIDEO_FADE:
177 sprintf(string, "%0.01f to %0.01f\n",
178 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
179 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
181 case AUTOGROUPTYPE_ZOOM:
182 sprintf(string, "%0.03f to %0.03f\n",
183 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
184 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
186 case AUTOGROUPTYPE_X:
187 case AUTOGROUPTYPE_Y:
188 sprintf(string, "%0.0f to %.0f\n",
189 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
190 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
193 auto_zoom_text->update(string);
196 int ZoomBar::update()
198 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
199 amp_zoom->update(mwindow->edl->local_session->zoom_y);
200 track_zoom->update(mwindow->edl->local_session->zoom_track);
206 int ZoomBar::update_clocks()
208 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
209 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
210 mwindow->edl->local_session->get_selectionstart(1));
211 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
215 int ZoomBar::update_playback(int64_t new_position)
217 if(new_position != old_position)
219 Units::totext(string,
221 mwindow->edl->session->sample_rate,
222 mwindow->edl->session->time_format,
223 mwindow->edl->session->frame_rate,
224 mwindow->edl->session->frames_per_foot);
225 playback_value->update(string);
226 old_position = new_position;
231 int ZoomBar::resize_event(int w, int h)
233 // don't change anything but y and width
234 reposition_window(0, h - this->get_h(), w, this->get_h());
239 // Values for which_one
245 int ZoomBar::set_selection(int which_one)
247 double start_position = mwindow->edl->local_session->get_selectionstart(1);
248 double end_position = mwindow->edl->local_session->get_selectionend(1);
249 double length = end_position - start_position;
256 start_position = Units::text_to_seconds(from_value->get_text(),
257 mwindow->edl->session->sample_rate,
258 mwindow->edl->session->time_format,
259 mwindow->edl->session->frame_rate,
260 mwindow->edl->session->frames_per_foot);
261 length = Units::text_to_seconds(length_value->get_text(),
262 mwindow->edl->session->sample_rate,
263 mwindow->edl->session->time_format,
264 mwindow->edl->session->frame_rate,
265 mwindow->edl->session->frames_per_foot);
266 end_position = start_position + length;
268 if(end_position < start_position)
270 start_position = end_position;
271 mwindow->edl->local_session->set_selectionend(
272 mwindow->edl->local_session->get_selectionstart(1));
277 start_position = Units::text_to_seconds(from_value->get_text(),
278 mwindow->edl->session->sample_rate,
279 mwindow->edl->session->time_format,
280 mwindow->edl->session->frame_rate,
281 mwindow->edl->session->frames_per_foot);
282 end_position = Units::text_to_seconds(to_value->get_text(),
283 mwindow->edl->session->sample_rate,
284 mwindow->edl->session->time_format,
285 mwindow->edl->session->frame_rate,
286 mwindow->edl->session->frames_per_foot);
288 if(end_position < start_position)
290 end_position = start_position;
291 mwindow->edl->local_session->set_selectionend(
292 mwindow->edl->local_session->get_selectionstart(1));
297 start_position = Units::text_to_seconds(from_value->get_text(),
298 mwindow->edl->session->sample_rate,
299 mwindow->edl->session->time_format,
300 mwindow->edl->session->frame_rate,
301 mwindow->edl->session->frames_per_foot);
302 end_position = Units::text_to_seconds(to_value->get_text(),
303 mwindow->edl->session->sample_rate,
304 mwindow->edl->session->time_format,
305 mwindow->edl->session->frame_rate,
306 mwindow->edl->session->frames_per_foot);
308 if(end_position < start_position)
310 start_position = end_position;
311 mwindow->edl->local_session->set_selectionend(
312 mwindow->edl->local_session->get_selectionstart(1));
317 mwindow->edl->local_session->set_selectionstart(
318 mwindow->edl->align_to_frame(start_position, 1));
319 mwindow->edl->local_session->set_selectionend(
320 mwindow->edl->align_to_frame(end_position, 1));
323 mwindow->gui->update_timebar_highlights();
324 mwindow->gui->hide_cursor(1);
325 mwindow->gui->show_cursor(1);
327 mwindow->sync_parameters(CHANGE_PARAMS);
328 mwindow->gui->flash_canvas(1);
344 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow,
350 mwindow->edl->local_session->zoom_sample,
358 this->mwindow = mwindow;
359 this->zoombar = zoombar;
361 int SampleZoomPanel::handle_event()
363 mwindow->zoom_sample((int64_t)get_value());
368 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
371 mwindow->edl->local_session->zoom_y,
379 this->mwindow = mwindow;
380 this->zoombar = zoombar;
382 int AmpZoomPanel::handle_event()
384 mwindow->zoom_amp((int64_t)get_value());
388 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
391 mwindow->edl->local_session->zoom_track,
399 this->mwindow = mwindow;
400 this->zoombar = zoombar;
402 int TrackZoomPanel::handle_event()
404 mwindow->zoom_track((int64_t)get_value());
405 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
412 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
415 mwindow->theme->get_image_set("zoombar_tumbler"))
417 this->mwindow = mwindow;
418 this->zoombar = zoombar;
419 this->changemax = changemax;
421 set_tooltip(_("Automation range maximum"));
423 set_tooltip(_("Automation range minimum"));
426 int AutoZoom::handle_up_event()
428 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
430 mwindow->gui->zoombar->update_autozoom();
431 mwindow->gui->draw_overlays(0);
432 mwindow->gui->update_patchbay();
433 mwindow->gui->flash_canvas(1);
437 int AutoZoom::handle_down_event()
439 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
441 mwindow->gui->zoombar->update_autozoom();
442 mwindow->gui->draw_overlays(0);
443 mwindow->gui->update_patchbay();
444 mwindow->gui->flash_canvas(1);
450 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
451 : BC_PopupMenu(x, y, 120,to_text(mwindow->edl->local_session->zoombar_showautotype), 1)
453 this->mwindow = mwindow;
454 this->zoombar = zoombar;
455 set_tooltip(_("Automation Type"));
458 void AutoTypeMenu::create_objects()
460 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
461 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
462 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
463 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
464 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
467 const char* AutoTypeMenu::to_text(int mode)
470 case AUTOGROUPTYPE_AUDIO_FADE: return _("Audio Fade:");
471 case AUTOGROUPTYPE_VIDEO_FADE: return _("Video Fade:");
472 case AUTOGROUPTYPE_ZOOM: return _("Zoom:");
473 case AUTOGROUPTYPE_X: return "X:";
474 case AUTOGROUPTYPE_Y: return "Y:";
479 int AutoTypeMenu::from_text(char *text)
481 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE)))
482 return AUTOGROUPTYPE_AUDIO_FADE;
483 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE)))
484 return AUTOGROUPTYPE_VIDEO_FADE;
485 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM)))
486 return AUTOGROUPTYPE_ZOOM;
487 if(!strcmp(text, to_text(AUTOGROUPTYPE_X)))
488 return AUTOGROUPTYPE_X;
489 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y)))
490 return AUTOGROUPTYPE_Y;
491 return AUTOGROUPTYPE_INT255;
494 int AutoTypeMenu::handle_event()
496 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
497 this->zoombar->update_autozoom();
502 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, const char *text)
503 : BC_TextBox(x, y, 130, 1, text)
505 this->mwindow = mwindow;
506 this->zoombar = zoombar;
507 set_tooltip(_("Automation range"));
510 int ZoomTextBox::button_press_event()
512 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
513 BC_TextBox::button_press_event();
516 if (!is_event_win()) return 0;
519 if (get_relative_cursor_x() < get_w()/2)
523 if (get_buttonpress() == 4)
524 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
527 if (get_buttonpress() == 5)
528 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
530 mwindow->gui->zoombar->update_autozoom();
531 mwindow->gui->draw_overlays(0);
532 mwindow->gui->update_patchbay();
533 mwindow->gui->flash_canvas(1);
537 int ZoomTextBox::handle_event()
540 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
542 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
543 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
546 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
547 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
548 mwindow->gui->zoombar->update_autozoom();
549 mwindow->gui->draw_overlays(0);
550 mwindow->gui->update_patchbay();
551 mwindow->gui->flash_canvas(1);
554 // TODO: Make the text turn red when it's a bad range..
562 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
563 : BC_TextBox(x, y, 90, 1, "")
565 this->mwindow = mwindow;
566 this->zoombar = zoombar;
567 set_tooltip(_("Selection start time"));
570 int FromTextBox::handle_event()
572 if(get_keypress() == 13)
574 zoombar->set_selection(SET_FROM);
580 int FromTextBox::update_position(double new_position)
582 new_position += mwindow->edl->session->get_frame_offset() /
583 mwindow->edl->session->frame_rate;;
584 Units::totext(string,
586 mwindow->edl->session->time_format,
587 mwindow->edl->session->sample_rate,
588 mwindow->edl->session->frame_rate,
589 mwindow->edl->session->frames_per_foot);
590 //printf("FromTextBox::update_position %f %s\n", new_position, string);
600 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
601 : BC_TextBox(x, y, 90, 1, "")
603 this->mwindow = mwindow;
604 this->zoombar = zoombar;
605 set_tooltip(_("Selection length"));
608 int LengthTextBox::handle_event()
610 if(get_keypress() == 13)
612 zoombar->set_selection(SET_LENGTH);
618 int LengthTextBox::update_position(double new_position)
620 Units::totext(string,
622 mwindow->edl->session->time_format,
623 mwindow->edl->session->sample_rate,
624 mwindow->edl->session->frame_rate,
625 mwindow->edl->session->frames_per_foot);
634 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
635 : BC_TextBox(x, y, 90, 1, "")
637 this->mwindow = mwindow;
638 this->zoombar = zoombar;
639 set_tooltip(_("Selection end time"));
642 int ToTextBox::handle_event()
644 if(get_keypress() == 13)
646 zoombar->set_selection(SET_TO);
652 int ToTextBox::update_position(double new_position)
654 new_position += mwindow->edl->session->get_frame_offset() /
655 mwindow->edl->session->frame_rate;
656 Units::totext(string,
658 mwindow->edl->session->time_format,
659 mwindow->edl->session->sample_rate,
660 mwindow->edl->session->frame_rate,
661 mwindow->edl->session->frames_per_foot);