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 = new TitleBarAlpha(mwindow, this, x, y));
109 update_formatting(from_value);
110 update_formatting(length_value);
111 update_formatting(to_value);
117 void ZoomBar::update_formatting(BC_TextBox *dst)
120 Units::format_to_separators(mwindow->edl->session->time_format));
123 void ZoomBar::resize_event()
125 reposition_window(mwindow->theme->mzoom_x, mwindow->theme->mzoom_y,
126 mwindow->theme->mzoom_w, mwindow->theme->mzoom_h);
127 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
130 void ZoomBar::redraw_time_dependancies()
132 // Recalculate sample zoom menu
133 sample_zoom->update_menu();
134 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
135 update_formatting(from_value);
136 update_formatting(length_value);
137 update_formatting(to_value);
148 void ZoomBar::update_autozoom()
150 char string[BCTEXTLEN];
151 int autogroup_type = mwindow->edl->local_session->zoombar_showautotype;
152 switch( autogroup_type ) {
153 case AUTOGROUPTYPE_AUDIO_FADE:
154 case AUTOGROUPTYPE_VIDEO_FADE:
155 sprintf(string, "%0.01f to %0.01f\n",
156 mwindow->edl->local_session->automation_mins[autogroup_type],
157 mwindow->edl->local_session->automation_maxs[autogroup_type]);
159 case AUTOGROUPTYPE_ZOOM:
160 case AUTOGROUPTYPE_SPEED:
161 sprintf(string, "%0.03f to %0.03f\n",
162 mwindow->edl->local_session->automation_mins[autogroup_type],
163 mwindow->edl->local_session->automation_maxs[autogroup_type]);
165 case AUTOGROUPTYPE_X:
166 case AUTOGROUPTYPE_Y:
167 sprintf(string, "%0.0f to %.0f\n",
168 mwindow->edl->local_session->automation_mins[autogroup_type],
169 mwindow->edl->local_session->automation_maxs[autogroup_type]);
172 auto_zoom_text->update(string);
173 const char *group_name = AutoTypeMenu::to_text(autogroup_type);
174 auto_type->set_text(group_name);
177 int ZoomBar::update()
179 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
180 amp_zoom->update(mwindow->edl->local_session->zoom_y);
181 track_zoom->update(mwindow->edl->local_session->zoom_track);
187 int ZoomBar::update_clocks()
189 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
190 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
191 mwindow->edl->local_session->get_selectionstart(1));
192 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
196 TitleBarAlpha::TitleBarAlpha(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
197 : BC_FSlider(x, y, 0, 150, 200, 0, 1.0, mwindow->session->title_bar_alpha, 0)
199 this->mwindow = mwindow;
200 this->zoombar = zoombar;
202 set_tooltip(_("TitleBar Alpha"));
205 int TitleBarAlpha::handle_event()
207 mwindow->session->title_bar_alpha = get_value();
208 mwindow->gui->draw_trackmovement();
209 mwindow->gui->flush();
213 int ZoomBar::resize_event(int w, int h)
215 // don't change anything but y and width
216 reposition_window(0, h - this->get_h(), w, this->get_h());
221 // Values for which_one
227 int ZoomBar::set_selection(int which_one)
229 double start_position = mwindow->edl->local_session->get_selectionstart(1);
230 double end_position = mwindow->edl->local_session->get_selectionend(1);
231 double length = end_position - start_position;
238 start_position = Units::text_to_seconds(from_value->get_text(),
239 mwindow->edl->session->sample_rate,
240 mwindow->edl->session->time_format,
241 mwindow->edl->session->frame_rate,
242 mwindow->edl->session->frames_per_foot);
243 length = Units::text_to_seconds(length_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 = start_position + length;
250 if(end_position < start_position)
252 start_position = end_position;
253 mwindow->edl->local_session->set_selectionend(
254 mwindow->edl->local_session->get_selectionstart(1));
259 start_position = Units::text_to_seconds(from_value->get_text(),
260 mwindow->edl->session->sample_rate,
261 mwindow->edl->session->time_format,
262 mwindow->edl->session->frame_rate,
263 mwindow->edl->session->frames_per_foot);
264 end_position = Units::text_to_seconds(to_value->get_text(),
265 mwindow->edl->session->sample_rate,
266 mwindow->edl->session->time_format,
267 mwindow->edl->session->frame_rate,
268 mwindow->edl->session->frames_per_foot);
270 if(end_position < start_position)
272 end_position = start_position;
273 mwindow->edl->local_session->set_selectionend(
274 mwindow->edl->local_session->get_selectionstart(1));
279 start_position = Units::text_to_seconds(from_value->get_text(),
280 mwindow->edl->session->sample_rate,
281 mwindow->edl->session->time_format,
282 mwindow->edl->session->frame_rate,
283 mwindow->edl->session->frames_per_foot);
284 end_position = Units::text_to_seconds(to_value->get_text(),
285 mwindow->edl->session->sample_rate,
286 mwindow->edl->session->time_format,
287 mwindow->edl->session->frame_rate,
288 mwindow->edl->session->frames_per_foot);
290 if(end_position < start_position)
292 start_position = end_position;
293 mwindow->edl->local_session->set_selectionend(
294 mwindow->edl->local_session->get_selectionstart(1));
299 mwindow->edl->local_session->set_selectionstart(
300 mwindow->edl->align_to_frame(start_position, 1));
301 mwindow->edl->local_session->set_selectionend(
302 mwindow->edl->align_to_frame(end_position, 1));
305 mwindow->gui->update_timebar_highlights();
306 mwindow->gui->hide_cursor(1);
307 mwindow->gui->show_cursor(1);
309 mwindow->sync_parameters(CHANGE_PARAMS);
310 mwindow->gui->flash_canvas(1);
326 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
327 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_sample,
328 x, y, 110, MIN_ZOOM_TIME, MAX_ZOOM_TIME, ZOOM_TIME)
330 this->mwindow = mwindow;
331 this->zoombar = zoombar;
333 int SampleZoomPanel::handle_event()
335 mwindow->zoom_sample((int64_t)get_value());
340 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
341 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_y,
342 x, y, 80, MIN_AMP_ZOOM, MAX_AMP_ZOOM, ZOOM_LONG)
344 this->mwindow = mwindow;
345 this->zoombar = zoombar;
347 int AmpZoomPanel::handle_event()
349 mwindow->zoom_amp((int64_t)get_value());
353 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
354 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_track,
355 x, y, 70, MIN_TRACK_ZOOM, MAX_TRACK_ZOOM, ZOOM_LONG)
357 this->mwindow = mwindow;
358 this->zoombar = zoombar;
360 int TrackZoomPanel::handle_event()
362 mwindow->zoom_track((int64_t)get_value());
363 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
370 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
371 : BC_Tumbler(x, y, mwindow->theme->get_image_set("zoombar_tumbler"))
373 this->mwindow = mwindow;
374 this->zoombar = zoombar;
375 this->changemax = changemax;
377 set_tooltip(_("Automation range maximum"));
379 set_tooltip(_("Automation range minimum"));
382 int AutoZoom::handle_up_event()
384 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
386 mwindow->gui->zoombar->update_autozoom();
387 mwindow->gui->draw_overlays(0);
388 mwindow->gui->update_patchbay();
389 mwindow->gui->flash_canvas(1);
393 int AutoZoom::handle_down_event()
395 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
397 mwindow->gui->zoombar->update_autozoom();
398 mwindow->gui->draw_overlays(0);
399 mwindow->gui->update_patchbay();
400 mwindow->gui->flash_canvas(1);
406 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int wid)
407 : BC_PopupMenu(x, y, wid, to_text(mwindow->edl->local_session->zoombar_showautotype), 1)
409 this->mwindow = mwindow;
410 this->zoombar = zoombar;
411 set_tooltip(_("Automation Type"));
414 void AutoTypeMenu::create_objects()
416 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
417 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
418 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
419 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_SPEED)));
420 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
421 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
424 const char* AutoTypeMenu::to_text(int mode)
427 case AUTOGROUPTYPE_AUDIO_FADE: return _("Audio Fade:");
428 case AUTOGROUPTYPE_VIDEO_FADE: return _("Video Fade:");
429 case AUTOGROUPTYPE_ZOOM: return _("Zoom:");
430 case AUTOGROUPTYPE_SPEED: return _("Speed:");
431 case AUTOGROUPTYPE_X: return "X:";
432 case AUTOGROUPTYPE_Y: return "Y:";
437 int AutoTypeMenu::from_text(char *text)
439 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE))) return AUTOGROUPTYPE_AUDIO_FADE;
440 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE))) return AUTOGROUPTYPE_VIDEO_FADE;
441 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM))) return AUTOGROUPTYPE_ZOOM;
442 if(!strcmp(text, to_text(AUTOGROUPTYPE_SPEED))) return AUTOGROUPTYPE_SPEED;
443 if(!strcmp(text, to_text(AUTOGROUPTYPE_X))) return AUTOGROUPTYPE_X;
444 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y))) return AUTOGROUPTYPE_Y;
445 return AUTOGROUPTYPE_INT255;
448 int AutoTypeMenu::handle_event()
450 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
451 this->zoombar->update_autozoom();
456 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, const char *text)
457 : BC_TextBox(x, y, 130, 1, text)
459 this->mwindow = mwindow;
460 this->zoombar = zoombar;
461 set_tooltip(_("Automation range"));
464 int ZoomTextBox::button_press_event()
466 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
467 BC_TextBox::button_press_event();
470 if (!is_event_win()) return 0;
473 if (get_relative_cursor_x() < get_w()/2)
477 if (get_buttonpress() == 4)
478 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
481 if (get_buttonpress() == 5)
482 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
484 mwindow->gui->zoombar->update_autozoom();
485 mwindow->gui->draw_overlays(0);
486 mwindow->gui->update_patchbay();
487 mwindow->gui->flash_canvas(1);
491 int ZoomTextBox::handle_event()
494 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
496 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
497 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
500 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
501 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
502 mwindow->gui->zoombar->update_autozoom();
503 mwindow->gui->draw_overlays(0);
504 mwindow->gui->update_patchbay();
505 mwindow->gui->flash_canvas(1);
508 // TODO: Make the text turn red when it's a bad range..
516 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
517 : BC_TextBox(x, y, 90, 1, "")
519 this->mwindow = mwindow;
520 this->zoombar = zoombar;
521 set_tooltip(_("Selection start time"));
524 int FromTextBox::handle_event()
526 if(get_keypress() == 13)
528 zoombar->set_selection(SET_FROM);
534 int FromTextBox::update_position(double new_position)
536 Units::totext(string,
538 mwindow->edl->session->time_format,
539 mwindow->edl->session->sample_rate,
540 mwindow->edl->session->frame_rate,
541 mwindow->edl->session->frames_per_foot);
542 //printf("FromTextBox::update_position %f %s\n", new_position, string);
552 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
553 : BC_TextBox(x, y, 90, 1, "")
555 this->mwindow = mwindow;
556 this->zoombar = zoombar;
557 set_tooltip(_("Selection length"));
560 int LengthTextBox::handle_event()
562 if(get_keypress() == 13)
564 zoombar->set_selection(SET_LENGTH);
570 int LengthTextBox::update_position(double new_position)
572 Units::totext(string,
574 mwindow->edl->session->time_format,
575 mwindow->edl->session->sample_rate,
576 mwindow->edl->session->frame_rate,
577 mwindow->edl->session->frames_per_foot);
586 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
587 : BC_TextBox(x, y, 90, 1, "")
589 this->mwindow = mwindow;
590 this->zoombar = zoombar;
591 set_tooltip(_("Selection end time"));
594 int ToTextBox::handle_event()
596 if(get_keypress() == 13)
598 zoombar->set_selection(SET_TO);
604 int ToTextBox::update_position(double new_position)
606 Units::totext(string, new_position,
607 mwindow->edl->session->time_format,
608 mwindow->edl->session->sample_rate,
609 mwindow->edl->session->frame_rate,
610 mwindow->edl->session->frames_per_foot);