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->create_objects();
71 sample_zoom->set_tooltip(_("Duration visible in the timeline"));
72 x += sample_zoom->get_w();
73 amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
74 amp_zoom->create_objects();
75 amp_zoom->set_tooltip(_("Audio waveform scale"));
76 x += amp_zoom->get_w();
77 track_zoom = new TrackZoomPanel(mwindow, this, x, y);
78 track_zoom->create_objects();
79 track_zoom->set_tooltip(_("Height of tracks in the timeline"));
80 x += track_zoom->get_w() + 10;
83 for( int i=AUTOGROUPTYPE_AUDIO_FADE; i<=AUTOGROUPTYPE_Y; ++i ) {
84 int ww = BC_GenericButton::calculate_w(this, AutoTypeMenu::to_text(i));
85 if( ww > wid ) wid = ww;
87 add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y, wid));
88 auto_type->create_objects();
89 x += auto_type->get_w() + 10;
90 #define DEFAULT_TEXT "000.00 to 000.00"
91 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 0));
92 x += auto_zoom->get_w();
93 add_subwindow(auto_zoom_text = new ZoomTextBox(
99 x += auto_zoom_text->get_w() + 5;
100 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 1));
102 x += auto_zoom->get_w() + 5;
104 add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
105 x += from_value->get_w() + 5;
106 add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
107 x += length_value->get_w() + 5;
108 add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
109 x += to_value->get_w() + 5;
111 update_formatting(from_value);
112 update_formatting(length_value);
113 update_formatting(to_value);
115 add_subwindow(playback_value = new BC_Title(x, 100, "--", MEDIUMFONT, RED));
117 add_subwindow(zoom_value = new BC_Title(x, 100, "--", MEDIUMFONT, BLACK));
122 void ZoomBar::update_formatting(BC_TextBox *dst)
125 Units::format_to_separators(mwindow->edl->session->time_format));
128 void ZoomBar::resize_event()
130 reposition_window(mwindow->theme->mzoom_x, mwindow->theme->mzoom_y,
131 mwindow->theme->mzoom_w, mwindow->theme->mzoom_h);
132 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
135 void ZoomBar::redraw_time_dependancies()
137 // Recalculate sample zoom menu
138 sample_zoom->update_menu();
139 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
140 update_formatting(from_value);
141 update_formatting(length_value);
142 update_formatting(to_value);
153 void ZoomBar::update_autozoom()
155 char string[BCTEXTLEN];
156 int autogroup_type = mwindow->edl->local_session->zoombar_showautotype;
157 switch( autogroup_type ) {
158 case AUTOGROUPTYPE_AUDIO_FADE:
159 case AUTOGROUPTYPE_VIDEO_FADE:
160 sprintf(string, "%0.01f to %0.01f\n",
161 mwindow->edl->local_session->automation_mins[autogroup_type],
162 mwindow->edl->local_session->automation_maxs[autogroup_type]);
164 case AUTOGROUPTYPE_ZOOM:
165 case AUTOGROUPTYPE_SPEED:
166 sprintf(string, "%0.03f to %0.03f\n",
167 mwindow->edl->local_session->automation_mins[autogroup_type],
168 mwindow->edl->local_session->automation_maxs[autogroup_type]);
170 case AUTOGROUPTYPE_X:
171 case AUTOGROUPTYPE_Y:
172 sprintf(string, "%0.0f to %.0f\n",
173 mwindow->edl->local_session->automation_mins[autogroup_type],
174 mwindow->edl->local_session->automation_maxs[autogroup_type]);
177 auto_zoom_text->update(string);
178 const char *group_name = AutoTypeMenu::to_text(autogroup_type);
179 auto_type->set_text(group_name);
182 int ZoomBar::update()
184 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
185 amp_zoom->update(mwindow->edl->local_session->zoom_y);
186 track_zoom->update(mwindow->edl->local_session->zoom_track);
192 int ZoomBar::update_clocks()
194 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
195 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
196 mwindow->edl->local_session->get_selectionstart(1));
197 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
201 int ZoomBar::update_playback(int64_t new_position)
203 if(new_position != old_position)
205 Units::totext(string, new_position,
206 mwindow->edl->session->sample_rate,
207 mwindow->edl->session->time_format,
208 mwindow->edl->session->frame_rate,
209 mwindow->edl->session->frames_per_foot);
210 playback_value->update(string);
211 old_position = new_position;
216 int ZoomBar::resize_event(int w, int h)
218 // don't change anything but y and width
219 reposition_window(0, h - this->get_h(), w, this->get_h());
224 // Values for which_one
230 int ZoomBar::set_selection(int which_one)
232 double start_position = mwindow->edl->local_session->get_selectionstart(1);
233 double end_position = mwindow->edl->local_session->get_selectionend(1);
234 double length = end_position - start_position;
241 start_position = Units::text_to_seconds(from_value->get_text(),
242 mwindow->edl->session->sample_rate,
243 mwindow->edl->session->time_format,
244 mwindow->edl->session->frame_rate,
245 mwindow->edl->session->frames_per_foot);
246 length = Units::text_to_seconds(length_value->get_text(),
247 mwindow->edl->session->sample_rate,
248 mwindow->edl->session->time_format,
249 mwindow->edl->session->frame_rate,
250 mwindow->edl->session->frames_per_foot);
251 end_position = start_position + length;
253 if(end_position < start_position)
255 start_position = end_position;
256 mwindow->edl->local_session->set_selectionend(
257 mwindow->edl->local_session->get_selectionstart(1));
262 start_position = Units::text_to_seconds(from_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 = Units::text_to_seconds(to_value->get_text(),
268 mwindow->edl->session->sample_rate,
269 mwindow->edl->session->time_format,
270 mwindow->edl->session->frame_rate,
271 mwindow->edl->session->frames_per_foot);
273 if(end_position < start_position)
275 end_position = start_position;
276 mwindow->edl->local_session->set_selectionend(
277 mwindow->edl->local_session->get_selectionstart(1));
282 start_position = Units::text_to_seconds(from_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);
287 end_position = Units::text_to_seconds(to_value->get_text(),
288 mwindow->edl->session->sample_rate,
289 mwindow->edl->session->time_format,
290 mwindow->edl->session->frame_rate,
291 mwindow->edl->session->frames_per_foot);
293 if(end_position < start_position)
295 start_position = end_position;
296 mwindow->edl->local_session->set_selectionend(
297 mwindow->edl->local_session->get_selectionstart(1));
302 mwindow->edl->local_session->set_selectionstart(
303 mwindow->edl->align_to_frame(start_position, 1));
304 mwindow->edl->local_session->set_selectionend(
305 mwindow->edl->align_to_frame(end_position, 1));
308 mwindow->gui->update_timebar_highlights();
309 mwindow->gui->hide_cursor(1);
310 mwindow->gui->show_cursor(1);
312 mwindow->sync_parameters(CHANGE_PARAMS);
313 mwindow->gui->flash_canvas(1);
329 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
330 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_sample,
331 x, y, 110, MIN_ZOOM_TIME, MAX_ZOOM_TIME, ZOOM_TIME)
333 this->mwindow = mwindow;
334 this->zoombar = zoombar;
336 int SampleZoomPanel::handle_event()
338 mwindow->zoom_sample((int64_t)get_value());
343 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
344 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_y,
345 x, y, 80, MIN_AMP_ZOOM, MAX_AMP_ZOOM, ZOOM_LONG)
347 this->mwindow = mwindow;
348 this->zoombar = zoombar;
350 int AmpZoomPanel::handle_event()
352 mwindow->zoom_amp((int64_t)get_value());
356 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
357 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_track,
358 x, y, 70, MIN_TRACK_ZOOM, MAX_TRACK_ZOOM, ZOOM_LONG)
360 this->mwindow = mwindow;
361 this->zoombar = zoombar;
363 int TrackZoomPanel::handle_event()
365 mwindow->zoom_track((int64_t)get_value());
366 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
373 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
374 : BC_Tumbler(x, y, mwindow->theme->get_image_set("zoombar_tumbler"))
376 this->mwindow = mwindow;
377 this->zoombar = zoombar;
378 this->changemax = changemax;
380 set_tooltip(_("Automation range maximum"));
382 set_tooltip(_("Automation range minimum"));
385 int AutoZoom::handle_up_event()
387 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
389 mwindow->gui->zoombar->update_autozoom();
390 mwindow->gui->draw_overlays(0);
391 mwindow->gui->update_patchbay();
392 mwindow->gui->flash_canvas(1);
396 int AutoZoom::handle_down_event()
398 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
400 mwindow->gui->zoombar->update_autozoom();
401 mwindow->gui->draw_overlays(0);
402 mwindow->gui->update_patchbay();
403 mwindow->gui->flash_canvas(1);
409 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int wid)
410 : BC_PopupMenu(x, y, wid, to_text(mwindow->edl->local_session->zoombar_showautotype), 1)
412 this->mwindow = mwindow;
413 this->zoombar = zoombar;
414 set_tooltip(_("Automation Type"));
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_SPEED)));
423 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
424 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
427 const char* AutoTypeMenu::to_text(int mode)
430 case AUTOGROUPTYPE_AUDIO_FADE: return _("Audio Fade:");
431 case AUTOGROUPTYPE_VIDEO_FADE: return _("Video Fade:");
432 case AUTOGROUPTYPE_ZOOM: return _("Zoom:");
433 case AUTOGROUPTYPE_SPEED: return _("Speed:");
434 case AUTOGROUPTYPE_X: return "X:";
435 case AUTOGROUPTYPE_Y: return "Y:";
440 int AutoTypeMenu::from_text(char *text)
442 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE))) return AUTOGROUPTYPE_AUDIO_FADE;
443 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE))) return AUTOGROUPTYPE_VIDEO_FADE;
444 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM))) return AUTOGROUPTYPE_ZOOM;
445 if(!strcmp(text, to_text(AUTOGROUPTYPE_SPEED))) return AUTOGROUPTYPE_SPEED;
446 if(!strcmp(text, to_text(AUTOGROUPTYPE_X))) return AUTOGROUPTYPE_X;
447 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y))) return AUTOGROUPTYPE_Y;
448 return AUTOGROUPTYPE_INT255;
451 int AutoTypeMenu::handle_event()
453 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
454 this->zoombar->update_autozoom();
459 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, const char *text)
460 : BC_TextBox(x, y, 130, 1, text)
462 this->mwindow = mwindow;
463 this->zoombar = zoombar;
464 set_tooltip(_("Automation range"));
467 int ZoomTextBox::button_press_event()
469 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
470 BC_TextBox::button_press_event();
473 if (!is_event_win()) return 0;
476 if (get_relative_cursor_x() < get_w()/2)
480 if (get_buttonpress() == 4)
481 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
484 if (get_buttonpress() == 5)
485 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
487 mwindow->gui->zoombar->update_autozoom();
488 mwindow->gui->draw_overlays(0);
489 mwindow->gui->update_patchbay();
490 mwindow->gui->flash_canvas(1);
494 int ZoomTextBox::handle_event()
497 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
499 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
500 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
503 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
504 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
505 mwindow->gui->zoombar->update_autozoom();
506 mwindow->gui->draw_overlays(0);
507 mwindow->gui->update_patchbay();
508 mwindow->gui->flash_canvas(1);
511 // TODO: Make the text turn red when it's a bad range..
519 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
520 : BC_TextBox(x, y, 90, 1, "")
522 this->mwindow = mwindow;
523 this->zoombar = zoombar;
524 set_tooltip(_("Selection start time"));
527 int FromTextBox::handle_event()
529 if(get_keypress() == 13)
531 zoombar->set_selection(SET_FROM);
537 int FromTextBox::update_position(double new_position)
539 Units::totext(string,
541 mwindow->edl->session->time_format,
542 mwindow->edl->session->sample_rate,
543 mwindow->edl->session->frame_rate,
544 mwindow->edl->session->frames_per_foot);
545 //printf("FromTextBox::update_position %f %s\n", new_position, string);
555 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
556 : BC_TextBox(x, y, 90, 1, "")
558 this->mwindow = mwindow;
559 this->zoombar = zoombar;
560 set_tooltip(_("Selection length"));
563 int LengthTextBox::handle_event()
565 if(get_keypress() == 13)
567 zoombar->set_selection(SET_LENGTH);
573 int LengthTextBox::update_position(double new_position)
575 Units::totext(string,
577 mwindow->edl->session->time_format,
578 mwindow->edl->session->sample_rate,
579 mwindow->edl->session->frame_rate,
580 mwindow->edl->session->frames_per_foot);
589 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
590 : BC_TextBox(x, y, 90, 1, "")
592 this->mwindow = mwindow;
593 this->zoombar = zoombar;
594 set_tooltip(_("Selection end time"));
597 int ToTextBox::handle_event()
599 if(get_keypress() == 13)
601 zoombar->set_selection(SET_TO);
607 int ToTextBox::update_position(double new_position)
609 Units::totext(string, new_position,
610 mwindow->edl->session->time_format,
611 mwindow->edl->session->sample_rate,
612 mwindow->edl->session->frame_rate,
613 mwindow->edl->session->frames_per_foot);