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 case AUTOGROUPTYPE_SPEED:
183 sprintf(string, "%0.03f to %0.03f\n",
184 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
185 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
187 case AUTOGROUPTYPE_X:
188 case AUTOGROUPTYPE_Y:
189 sprintf(string, "%0.0f to %.0f\n",
190 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
191 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
194 auto_zoom_text->update(string);
197 int ZoomBar::update()
199 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
200 amp_zoom->update(mwindow->edl->local_session->zoom_y);
201 track_zoom->update(mwindow->edl->local_session->zoom_track);
207 int ZoomBar::update_clocks()
209 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
210 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
211 mwindow->edl->local_session->get_selectionstart(1));
212 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
216 int ZoomBar::update_playback(int64_t new_position)
218 if(new_position != old_position)
220 Units::totext(string,
222 mwindow->edl->session->sample_rate,
223 mwindow->edl->session->time_format,
224 mwindow->edl->session->frame_rate,
225 mwindow->edl->session->frames_per_foot);
226 playback_value->update(string);
227 old_position = new_position;
232 int ZoomBar::resize_event(int w, int h)
234 // don't change anything but y and width
235 reposition_window(0, h - this->get_h(), w, this->get_h());
240 // Values for which_one
246 int ZoomBar::set_selection(int which_one)
248 double start_position = mwindow->edl->local_session->get_selectionstart(1);
249 double end_position = mwindow->edl->local_session->get_selectionend(1);
250 double length = end_position - start_position;
257 start_position = Units::text_to_seconds(from_value->get_text(),
258 mwindow->edl->session->sample_rate,
259 mwindow->edl->session->time_format,
260 mwindow->edl->session->frame_rate,
261 mwindow->edl->session->frames_per_foot);
262 length = Units::text_to_seconds(length_value->get_text(),
263 mwindow->edl->session->sample_rate,
264 mwindow->edl->session->time_format,
265 mwindow->edl->session->frame_rate,
266 mwindow->edl->session->frames_per_foot);
267 end_position = start_position + length;
269 if(end_position < start_position)
271 start_position = end_position;
272 mwindow->edl->local_session->set_selectionend(
273 mwindow->edl->local_session->get_selectionstart(1));
278 start_position = Units::text_to_seconds(from_value->get_text(),
279 mwindow->edl->session->sample_rate,
280 mwindow->edl->session->time_format,
281 mwindow->edl->session->frame_rate,
282 mwindow->edl->session->frames_per_foot);
283 end_position = Units::text_to_seconds(to_value->get_text(),
284 mwindow->edl->session->sample_rate,
285 mwindow->edl->session->time_format,
286 mwindow->edl->session->frame_rate,
287 mwindow->edl->session->frames_per_foot);
289 if(end_position < start_position)
291 end_position = start_position;
292 mwindow->edl->local_session->set_selectionend(
293 mwindow->edl->local_session->get_selectionstart(1));
298 start_position = Units::text_to_seconds(from_value->get_text(),
299 mwindow->edl->session->sample_rate,
300 mwindow->edl->session->time_format,
301 mwindow->edl->session->frame_rate,
302 mwindow->edl->session->frames_per_foot);
303 end_position = Units::text_to_seconds(to_value->get_text(),
304 mwindow->edl->session->sample_rate,
305 mwindow->edl->session->time_format,
306 mwindow->edl->session->frame_rate,
307 mwindow->edl->session->frames_per_foot);
309 if(end_position < start_position)
311 start_position = end_position;
312 mwindow->edl->local_session->set_selectionend(
313 mwindow->edl->local_session->get_selectionstart(1));
318 mwindow->edl->local_session->set_selectionstart(
319 mwindow->edl->align_to_frame(start_position, 1));
320 mwindow->edl->local_session->set_selectionend(
321 mwindow->edl->align_to_frame(end_position, 1));
324 mwindow->gui->update_timebar_highlights();
325 mwindow->gui->hide_cursor(1);
326 mwindow->gui->show_cursor(1);
328 mwindow->sync_parameters(CHANGE_PARAMS);
329 mwindow->gui->flash_canvas(1);
345 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow,
351 mwindow->edl->local_session->zoom_sample,
359 this->mwindow = mwindow;
360 this->zoombar = zoombar;
362 int SampleZoomPanel::handle_event()
364 mwindow->zoom_sample((int64_t)get_value());
369 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
372 mwindow->edl->local_session->zoom_y,
380 this->mwindow = mwindow;
381 this->zoombar = zoombar;
383 int AmpZoomPanel::handle_event()
385 mwindow->zoom_amp((int64_t)get_value());
389 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
392 mwindow->edl->local_session->zoom_track,
400 this->mwindow = mwindow;
401 this->zoombar = zoombar;
403 int TrackZoomPanel::handle_event()
405 mwindow->zoom_track((int64_t)get_value());
406 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
413 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
416 mwindow->theme->get_image_set("zoombar_tumbler"))
418 this->mwindow = mwindow;
419 this->zoombar = zoombar;
420 this->changemax = changemax;
422 set_tooltip(_("Automation range maximum"));
424 set_tooltip(_("Automation range minimum"));
427 int AutoZoom::handle_up_event()
429 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
431 mwindow->gui->zoombar->update_autozoom();
432 mwindow->gui->draw_overlays(0);
433 mwindow->gui->update_patchbay();
434 mwindow->gui->flash_canvas(1);
438 int AutoZoom::handle_down_event()
440 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
442 mwindow->gui->zoombar->update_autozoom();
443 mwindow->gui->draw_overlays(0);
444 mwindow->gui->update_patchbay();
445 mwindow->gui->flash_canvas(1);
451 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
452 : BC_PopupMenu(x, y, 120,to_text(mwindow->edl->local_session->zoombar_showautotype), 1)
454 this->mwindow = mwindow;
455 this->zoombar = zoombar;
456 set_tooltip(_("Automation Type"));
459 void AutoTypeMenu::create_objects()
461 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
462 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
463 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
464 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_SPEED)));
465 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
466 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
469 const char* AutoTypeMenu::to_text(int mode)
472 case AUTOGROUPTYPE_AUDIO_FADE: return _("Audio Fade:");
473 case AUTOGROUPTYPE_VIDEO_FADE: return _("Video Fade:");
474 case AUTOGROUPTYPE_ZOOM: return _("Zoom:");
475 case AUTOGROUPTYPE_SPEED: return _("Speed:");
476 case AUTOGROUPTYPE_X: return "X:";
477 case AUTOGROUPTYPE_Y: return "Y:";
482 int AutoTypeMenu::from_text(char *text)
484 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE))) return AUTOGROUPTYPE_AUDIO_FADE;
485 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE))) return AUTOGROUPTYPE_VIDEO_FADE;
486 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM))) return AUTOGROUPTYPE_ZOOM;
487 if(!strcmp(text, to_text(AUTOGROUPTYPE_SPEED))) return AUTOGROUPTYPE_SPEED;
488 if(!strcmp(text, to_text(AUTOGROUPTYPE_X))) return AUTOGROUPTYPE_X;
489 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y))) return AUTOGROUPTYPE_Y;
490 return AUTOGROUPTYPE_INT255;
493 int AutoTypeMenu::handle_event()
495 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
496 this->zoombar->update_autozoom();
501 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, const char *text)
502 : BC_TextBox(x, y, 130, 1, text)
504 this->mwindow = mwindow;
505 this->zoombar = zoombar;
506 set_tooltip(_("Automation range"));
509 int ZoomTextBox::button_press_event()
511 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
512 BC_TextBox::button_press_event();
515 if (!is_event_win()) return 0;
518 if (get_relative_cursor_x() < get_w()/2)
522 if (get_buttonpress() == 4)
523 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
526 if (get_buttonpress() == 5)
527 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
529 mwindow->gui->zoombar->update_autozoom();
530 mwindow->gui->draw_overlays(0);
531 mwindow->gui->update_patchbay();
532 mwindow->gui->flash_canvas(1);
536 int ZoomTextBox::handle_event()
539 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
541 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
542 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
545 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
546 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
547 mwindow->gui->zoombar->update_autozoom();
548 mwindow->gui->draw_overlays(0);
549 mwindow->gui->update_patchbay();
550 mwindow->gui->flash_canvas(1);
553 // TODO: Make the text turn red when it's a bad range..
561 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
562 : BC_TextBox(x, y, 90, 1, "")
564 this->mwindow = mwindow;
565 this->zoombar = zoombar;
566 set_tooltip(_("Selection start time"));
569 int FromTextBox::handle_event()
571 if(get_keypress() == 13)
573 zoombar->set_selection(SET_FROM);
579 int FromTextBox::update_position(double new_position)
581 new_position += mwindow->edl->session->get_frame_offset() /
582 mwindow->edl->session->frame_rate;;
583 Units::totext(string,
585 mwindow->edl->session->time_format,
586 mwindow->edl->session->sample_rate,
587 mwindow->edl->session->frame_rate,
588 mwindow->edl->session->frames_per_foot);
589 //printf("FromTextBox::update_position %f %s\n", new_position, string);
599 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
600 : BC_TextBox(x, y, 90, 1, "")
602 this->mwindow = mwindow;
603 this->zoombar = zoombar;
604 set_tooltip(_("Selection length"));
607 int LengthTextBox::handle_event()
609 if(get_keypress() == 13)
611 zoombar->set_selection(SET_LENGTH);
617 int LengthTextBox::update_position(double new_position)
619 Units::totext(string,
621 mwindow->edl->session->time_format,
622 mwindow->edl->session->sample_rate,
623 mwindow->edl->session->frame_rate,
624 mwindow->edl->session->frames_per_foot);
633 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
634 : BC_TextBox(x, y, 90, 1, "")
636 this->mwindow = mwindow;
637 this->zoombar = zoombar;
638 set_tooltip(_("Selection end time"));
641 int ToTextBox::handle_event()
643 if(get_keypress() == 13)
645 zoombar->set_selection(SET_TO);
651 int ToTextBox::update_position(double new_position)
653 new_position += mwindow->edl->session->get_frame_offset() /
654 mwindow->edl->session->frame_rate;
655 Units::totext(string,
657 mwindow->edl->session->time_format,
658 mwindow->edl->session->sample_rate,
659 mwindow->edl->session->frame_rate,
660 mwindow->edl->session->frames_per_foot);