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"
42 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
43 : BC_SubWindow(mwindow->theme->mzoom_x,
44 mwindow->theme->mzoom_y,
45 mwindow->theme->mzoom_w,
46 mwindow->theme->mzoom_h)
49 this->mwindow = mwindow;
59 void ZoomBar::create_objects()
63 mwindow->theme->get_image_set("zoombar_menu", 0)[0]->get_h() / 2;
65 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
66 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
67 sample_zoom->create_objects();
68 sample_zoom->set_tooltip(_("Duration visible in the timeline"));
69 x += sample_zoom->get_w();
70 amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
71 amp_zoom->create_objects();
72 amp_zoom->set_tooltip(_("Audio waveform scale"));
73 x += amp_zoom->get_w();
74 track_zoom = new TrackZoomPanel(mwindow, this, x, y);
75 track_zoom->create_objects();
76 track_zoom->set_tooltip(_("Height of tracks in the timeline"));
77 x += track_zoom->get_w() + 10;
80 for( int i=AUTOGROUPTYPE_AUDIO_FADE; i<=AUTOGROUPTYPE_Y; ++i ) {
81 int ww = BC_GenericButton::calculate_w(this, AutoTypeMenu::to_text(i));
82 if( ww > wid ) wid = ww;
84 add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y, wid));
85 auto_type->create_objects();
86 x += auto_type->get_w() + 10;
87 #define DEFAULT_TEXT "000.00 to 000.00"
88 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 0));
89 x += auto_zoom->get_w();
90 add_subwindow(auto_zoom_text = new ZoomTextBox(
96 x += auto_zoom_text->get_w() + 5;
97 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 1));
99 x += auto_zoom->get_w() + 5;
101 add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
102 x += from_value->get_w() + 5;
103 add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
104 x += length_value->get_w() + 5;
105 add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
106 x += to_value->get_w() + 5;
107 add_subwindow(title_alpha_bar = new TitleAlphaBar(mwindow, this, x, y));
108 x += title_alpha_bar->get_w() + 5;
109 add_subwindow(title_alpha_text = new TitleAlphaText(mwindow, this, x, y));
111 update_formatting(from_value);
112 update_formatting(length_value);
113 update_formatting(to_value);
119 void ZoomBar::update_formatting(BC_TextBox *dst)
122 Units::format_to_separators(mwindow->edl->session->time_format));
125 void ZoomBar::resize_event()
127 reposition_window(mwindow->theme->mzoom_x, mwindow->theme->mzoom_y,
128 mwindow->theme->mzoom_w, mwindow->theme->mzoom_h);
129 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
132 void ZoomBar::redraw_time_dependancies()
134 // Recalculate sample zoom menu
135 sample_zoom->update_menu();
136 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
137 update_formatting(from_value);
138 update_formatting(length_value);
139 update_formatting(to_value);
150 void ZoomBar::update_autozoom()
152 char string[BCTEXTLEN];
153 int autogroup_type = mwindow->edl->local_session->zoombar_showautotype;
154 switch( autogroup_type ) {
155 case AUTOGROUPTYPE_AUDIO_FADE:
156 case AUTOGROUPTYPE_VIDEO_FADE:
157 sprintf(string, "%0.01f to %0.01f\n",
158 mwindow->edl->local_session->automation_mins[autogroup_type],
159 mwindow->edl->local_session->automation_maxs[autogroup_type]);
161 case AUTOGROUPTYPE_ZOOM:
162 case AUTOGROUPTYPE_SPEED:
163 sprintf(string, "%0.03f to %0.03f\n",
164 mwindow->edl->local_session->automation_mins[autogroup_type],
165 mwindow->edl->local_session->automation_maxs[autogroup_type]);
167 case AUTOGROUPTYPE_X:
168 case AUTOGROUPTYPE_Y:
169 sprintf(string, "%0.0f to %.0f\n",
170 mwindow->edl->local_session->automation_mins[autogroup_type],
171 mwindow->edl->local_session->automation_maxs[autogroup_type]);
174 auto_zoom_text->update(string);
175 const char *group_name = AutoTypeMenu::to_text(autogroup_type);
176 auto_type->set_text(group_name);
179 int ZoomBar::update()
181 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
182 amp_zoom->update(mwindow->edl->local_session->zoom_y);
183 track_zoom->update(mwindow->edl->local_session->zoom_track);
189 int ZoomBar::update_clocks()
191 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
192 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
193 mwindow->edl->local_session->get_selectionstart(1));
194 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
198 TitleAlphaBar::TitleAlphaBar(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
199 : BC_FSlider(x, y, 0, 150, 200, 0, 1.0, mwindow->session->title_bar_alpha, 0)
201 this->mwindow = mwindow;
202 this->zoombar = zoombar;
204 set_tooltip(_("Title Alpha"));
207 int TitleAlphaBar::handle_event()
209 float v = get_value();
210 mwindow->session->title_bar_alpha = v;
211 zoombar->title_alpha_text->update(v);
212 mwindow->gui->draw_trackmovement();
213 mwindow->gui->flush();
217 TitleAlphaText::TitleAlphaText(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
218 : BC_TextBox(x, y, 48, 1, mwindow->session->title_bar_alpha, 0, MEDIUMFONT, 2)
220 this->mwindow = mwindow;
221 this->zoombar = zoombar;
222 set_tooltip(_("Title Alpha"));
225 int TitleAlphaText::handle_event()
227 float v = atof(get_text())*100;
228 mwindow->session->title_bar_alpha = v;
229 zoombar->title_alpha_bar->update(v);
230 mwindow->gui->draw_trackmovement();
231 mwindow->gui->flush();
235 int ZoomBar::resize_event(int w, int h)
237 // don't change anything but y and width
238 reposition_window(0, h - this->get_h(), w, this->get_h());
243 // Values for which_one
249 int ZoomBar::set_selection(int which_one)
251 double start_position = mwindow->edl->local_session->get_selectionstart(1);
252 double end_position = mwindow->edl->local_session->get_selectionend(1);
253 double length = end_position - start_position;
260 start_position = Units::text_to_seconds(from_value->get_text(),
261 mwindow->edl->session->sample_rate,
262 mwindow->edl->session->time_format,
263 mwindow->edl->session->frame_rate,
264 mwindow->edl->session->frames_per_foot);
265 length = Units::text_to_seconds(length_value->get_text(),
266 mwindow->edl->session->sample_rate,
267 mwindow->edl->session->time_format,
268 mwindow->edl->session->frame_rate,
269 mwindow->edl->session->frames_per_foot);
270 end_position = start_position + length;
272 if(end_position < start_position)
274 start_position = end_position;
275 mwindow->edl->local_session->set_selectionend(
276 mwindow->edl->local_session->get_selectionstart(1));
281 start_position = Units::text_to_seconds(from_value->get_text(),
282 mwindow->edl->session->sample_rate,
283 mwindow->edl->session->time_format,
284 mwindow->edl->session->frame_rate,
285 mwindow->edl->session->frames_per_foot);
286 end_position = Units::text_to_seconds(to_value->get_text(),
287 mwindow->edl->session->sample_rate,
288 mwindow->edl->session->time_format,
289 mwindow->edl->session->frame_rate,
290 mwindow->edl->session->frames_per_foot);
292 if(end_position < start_position)
294 end_position = start_position;
295 mwindow->edl->local_session->set_selectionend(
296 mwindow->edl->local_session->get_selectionstart(1));
301 start_position = Units::text_to_seconds(from_value->get_text(),
302 mwindow->edl->session->sample_rate,
303 mwindow->edl->session->time_format,
304 mwindow->edl->session->frame_rate,
305 mwindow->edl->session->frames_per_foot);
306 end_position = Units::text_to_seconds(to_value->get_text(),
307 mwindow->edl->session->sample_rate,
308 mwindow->edl->session->time_format,
309 mwindow->edl->session->frame_rate,
310 mwindow->edl->session->frames_per_foot);
312 if(end_position < start_position)
314 start_position = end_position;
315 mwindow->edl->local_session->set_selectionend(
316 mwindow->edl->local_session->get_selectionstart(1));
321 mwindow->edl->local_session->set_selectionstart(
322 mwindow->edl->align_to_frame(start_position, 1));
323 mwindow->edl->local_session->set_selectionend(
324 mwindow->edl->align_to_frame(end_position, 1));
327 mwindow->gui->update_timebar_highlights();
328 mwindow->gui->hide_cursor(1);
329 mwindow->gui->show_cursor(1);
331 mwindow->sync_parameters(CHANGE_PARAMS);
332 mwindow->gui->flash_canvas(1);
348 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
349 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_sample,
350 x, y, 110, MIN_ZOOM_TIME, MAX_ZOOM_TIME, ZOOM_TIME)
352 this->mwindow = mwindow;
353 this->zoombar = zoombar;
355 int SampleZoomPanel::handle_event()
357 mwindow->zoom_sample((int64_t)get_value());
362 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
363 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_y,
364 x, y, 80, MIN_AMP_ZOOM, MAX_AMP_ZOOM, ZOOM_LONG)
366 this->mwindow = mwindow;
367 this->zoombar = zoombar;
369 int AmpZoomPanel::handle_event()
371 mwindow->zoom_amp((int64_t)get_value());
375 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
376 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_track,
377 x, y, 70, MIN_TRACK_ZOOM, MAX_TRACK_ZOOM, ZOOM_LONG)
379 this->mwindow = mwindow;
380 this->zoombar = zoombar;
382 int TrackZoomPanel::handle_event()
384 mwindow->zoom_track((int64_t)get_value());
385 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
392 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
393 : BC_Tumbler(x, y, mwindow->theme->get_image_set("zoombar_tumbler"))
395 this->mwindow = mwindow;
396 this->zoombar = zoombar;
397 this->changemax = changemax;
399 set_tooltip(_("Automation range maximum"));
401 set_tooltip(_("Automation range minimum"));
404 int AutoZoom::handle_up_event()
406 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
408 mwindow->gui->zoombar->update_autozoom();
409 mwindow->gui->draw_overlays(0);
410 mwindow->gui->update_patchbay();
411 mwindow->gui->flash_canvas(1);
415 int AutoZoom::handle_down_event()
417 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
419 mwindow->gui->zoombar->update_autozoom();
420 mwindow->gui->draw_overlays(0);
421 mwindow->gui->update_patchbay();
422 mwindow->gui->flash_canvas(1);
428 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int wid)
429 : BC_PopupMenu(x, y, wid, to_text(mwindow->edl->local_session->zoombar_showautotype), 1)
431 this->mwindow = mwindow;
432 this->zoombar = zoombar;
433 set_tooltip(_("Automation Type"));
436 void AutoTypeMenu::create_objects()
438 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
439 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
440 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
441 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_SPEED)));
442 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
443 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
446 const char* AutoTypeMenu::to_text(int mode)
449 case AUTOGROUPTYPE_AUDIO_FADE: return _("Audio Fade:");
450 case AUTOGROUPTYPE_VIDEO_FADE: return _("Video Fade:");
451 case AUTOGROUPTYPE_ZOOM: return _("Zoom:");
452 case AUTOGROUPTYPE_SPEED: return _("Speed:");
453 case AUTOGROUPTYPE_X: return "X:";
454 case AUTOGROUPTYPE_Y: return "Y:";
459 int AutoTypeMenu::from_text(char *text)
461 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE))) return AUTOGROUPTYPE_AUDIO_FADE;
462 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE))) return AUTOGROUPTYPE_VIDEO_FADE;
463 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM))) return AUTOGROUPTYPE_ZOOM;
464 if(!strcmp(text, to_text(AUTOGROUPTYPE_SPEED))) return AUTOGROUPTYPE_SPEED;
465 if(!strcmp(text, to_text(AUTOGROUPTYPE_X))) return AUTOGROUPTYPE_X;
466 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y))) return AUTOGROUPTYPE_Y;
467 return AUTOGROUPTYPE_INT255;
470 int AutoTypeMenu::handle_event()
472 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
473 this->zoombar->update_autozoom();
478 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, const char *text)
479 : BC_TextBox(x, y, 130, 1, text)
481 this->mwindow = mwindow;
482 this->zoombar = zoombar;
483 set_tooltip(_("Automation range"));
486 int ZoomTextBox::button_press_event()
488 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
489 BC_TextBox::button_press_event();
492 if (!is_event_win()) return 0;
495 if (get_relative_cursor_x() < get_w()/2)
499 if (get_buttonpress() == 4)
500 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
503 if (get_buttonpress() == 5)
504 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
506 mwindow->gui->zoombar->update_autozoom();
507 mwindow->gui->draw_overlays(0);
508 mwindow->gui->update_patchbay();
509 mwindow->gui->flash_canvas(1);
513 int ZoomTextBox::handle_event()
516 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
518 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
519 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
522 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
523 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
524 mwindow->gui->zoombar->update_autozoom();
525 mwindow->gui->draw_overlays(0);
526 mwindow->gui->update_patchbay();
527 mwindow->gui->flash_canvas(1);
530 // TODO: Make the text turn red when it's a bad range..
538 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
539 : BC_TextBox(x, y, 90, 1, "")
541 this->mwindow = mwindow;
542 this->zoombar = zoombar;
543 set_tooltip(_("Selection start time"));
546 int FromTextBox::handle_event()
548 if(get_keypress() == 13)
550 zoombar->set_selection(SET_FROM);
556 int FromTextBox::update_position(double new_position)
558 Units::totext(string,
560 mwindow->edl->session->time_format,
561 mwindow->edl->session->sample_rate,
562 mwindow->edl->session->frame_rate,
563 mwindow->edl->session->frames_per_foot);
564 //printf("FromTextBox::update_position %f %s\n", new_position, string);
574 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
575 : BC_TextBox(x, y, 90, 1, "")
577 this->mwindow = mwindow;
578 this->zoombar = zoombar;
579 set_tooltip(_("Selection length"));
582 int LengthTextBox::handle_event()
584 if(get_keypress() == 13)
586 zoombar->set_selection(SET_LENGTH);
592 int LengthTextBox::update_position(double new_position)
594 Units::totext(string,
596 mwindow->edl->session->time_format,
597 mwindow->edl->session->sample_rate,
598 mwindow->edl->session->frame_rate,
599 mwindow->edl->session->frames_per_foot);
608 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
609 : BC_TextBox(x, y, 90, 1, "")
611 this->mwindow = mwindow;
612 this->zoombar = zoombar;
613 set_tooltip(_("Selection end time"));
616 int ToTextBox::handle_event()
618 if(get_keypress() == 13)
620 zoombar->set_selection(SET_TO);
626 int ToTextBox::update_position(double new_position)
628 Units::totext(string, new_position,
629 mwindow->edl->session->time_format,
630 mwindow->edl->session->sample_rate,
631 mwindow->edl->session->frame_rate,
632 mwindow->edl->session->frames_per_foot);