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 update_autozoom(mwindow->edl->local_session->zoombar_showautocolor);
155 void ZoomBar::update_autozoom(int grouptype, int color)
157 mwindow->edl->local_session->zoombar_showautotype = grouptype;
158 update_autozoom(color);
161 void ZoomBar::update_autozoom(int color)
163 char string[BCTEXTLEN];
164 int autogroup_type = mwindow->edl->local_session->zoombar_showautotype;
165 mwindow->edl->local_session->zoombar_showautocolor = color;
166 if( color < 0 ) color = get_resources()->default_text_color;
167 switch( autogroup_type ) {
168 case AUTOGROUPTYPE_AUDIO_FADE:
169 case AUTOGROUPTYPE_VIDEO_FADE:
170 sprintf(string, "%0.01f to %0.01f\n",
171 mwindow->edl->local_session->automation_mins[autogroup_type],
172 mwindow->edl->local_session->automation_maxs[autogroup_type]);
174 case AUTOGROUPTYPE_ZOOM:
175 case AUTOGROUPTYPE_SPEED:
176 sprintf(string, "%0.03f to %0.03f\n",
177 mwindow->edl->local_session->automation_mins[autogroup_type],
178 mwindow->edl->local_session->automation_maxs[autogroup_type]);
180 case AUTOGROUPTYPE_X:
181 case AUTOGROUPTYPE_Y:
182 sprintf(string, "%0.0f to %.0f\n",
183 mwindow->edl->local_session->automation_mins[autogroup_type],
184 mwindow->edl->local_session->automation_maxs[autogroup_type]);
187 auto_zoom_text->update(string);
188 const char *group_name = AutoTypeMenu::to_text(autogroup_type);
189 auto_type->set_text(group_name);
193 int ZoomBar::update()
195 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
196 amp_zoom->update(mwindow->edl->local_session->zoom_y);
197 track_zoom->update(mwindow->edl->local_session->zoom_track);
203 int ZoomBar::update_clocks()
205 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
206 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
207 mwindow->edl->local_session->get_selectionstart(1));
208 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
212 TitleAlphaBar::TitleAlphaBar(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
213 : BC_FSlider(x, y, 0, 150, 200, 0, 1.0, mwindow->session->title_bar_alpha, 0)
215 this->mwindow = mwindow;
216 this->zoombar = zoombar;
218 enable_show_value(0);
221 int TitleAlphaBar::handle_event()
223 float v = get_value();
224 mwindow->session->title_bar_alpha = v;
225 zoombar->title_alpha_text->update(v);
226 mwindow->gui->draw_trackmovement();
227 mwindow->gui->flush();
231 TitleAlphaText::TitleAlphaText(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
232 : BC_TextBox(x, y, 48, 1, mwindow->session->title_bar_alpha, 0, MEDIUMFONT, 2)
234 this->mwindow = mwindow;
235 this->zoombar = zoombar;
236 set_tooltip(_("Title Alpha"));
239 int TitleAlphaText::handle_event()
241 float v = atof(get_text());
242 mwindow->session->title_bar_alpha = v;
243 zoombar->title_alpha_bar->update(v);
244 mwindow->gui->draw_trackmovement();
245 mwindow->gui->flush();
249 int ZoomBar::resize_event(int w, int h)
251 // don't change anything but y and width
252 reposition_window(0, h - this->get_h(), w, this->get_h());
257 // Values for which_one
263 int ZoomBar::set_selection(int which_one)
265 double start_position = mwindow->edl->local_session->get_selectionstart(1);
266 double end_position = mwindow->edl->local_session->get_selectionend(1);
267 double length = end_position - start_position;
274 start_position = Units::text_to_seconds(from_value->get_text(),
275 mwindow->edl->session->sample_rate,
276 mwindow->edl->session->time_format,
277 mwindow->edl->session->frame_rate,
278 mwindow->edl->session->frames_per_foot);
279 length = Units::text_to_seconds(length_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 = start_position + length;
286 if(end_position < start_position)
288 start_position = end_position;
289 mwindow->edl->local_session->set_selectionend(
290 mwindow->edl->local_session->get_selectionstart(1));
295 start_position = Units::text_to_seconds(from_value->get_text(),
296 mwindow->edl->session->sample_rate,
297 mwindow->edl->session->time_format,
298 mwindow->edl->session->frame_rate,
299 mwindow->edl->session->frames_per_foot);
300 end_position = Units::text_to_seconds(to_value->get_text(),
301 mwindow->edl->session->sample_rate,
302 mwindow->edl->session->time_format,
303 mwindow->edl->session->frame_rate,
304 mwindow->edl->session->frames_per_foot);
306 if(end_position < start_position)
308 end_position = start_position;
309 mwindow->edl->local_session->set_selectionend(
310 mwindow->edl->local_session->get_selectionstart(1));
315 start_position = Units::text_to_seconds(from_value->get_text(),
316 mwindow->edl->session->sample_rate,
317 mwindow->edl->session->time_format,
318 mwindow->edl->session->frame_rate,
319 mwindow->edl->session->frames_per_foot);
320 end_position = Units::text_to_seconds(to_value->get_text(),
321 mwindow->edl->session->sample_rate,
322 mwindow->edl->session->time_format,
323 mwindow->edl->session->frame_rate,
324 mwindow->edl->session->frames_per_foot);
326 if(end_position < start_position)
328 start_position = end_position;
329 mwindow->edl->local_session->set_selectionend(
330 mwindow->edl->local_session->get_selectionstart(1));
335 mwindow->edl->local_session->set_selectionstart(
336 mwindow->edl->align_to_frame(start_position, 1));
337 mwindow->edl->local_session->set_selectionend(
338 mwindow->edl->align_to_frame(end_position, 1));
341 mwindow->gui->update_timebar_highlights();
342 mwindow->gui->hide_cursor(1);
343 mwindow->gui->show_cursor(1);
345 mwindow->sync_parameters(CHANGE_PARAMS);
346 mwindow->gui->flash_canvas(1);
362 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
363 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_sample,
364 x, y, 130, MIN_ZOOM_TIME, MAX_ZOOM_TIME, ZOOM_TIME)
366 this->mwindow = mwindow;
367 this->zoombar = zoombar;
369 int SampleZoomPanel::handle_event()
371 mwindow->zoom_sample((int64_t)get_value());
376 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
377 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_y,
378 x, y, 100, MIN_AMP_ZOOM, MAX_AMP_ZOOM, ZOOM_LONG)
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)
390 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_track,
391 x, y, 90, MIN_TRACK_ZOOM, MAX_TRACK_ZOOM, ZOOM_LONG)
393 this->mwindow = mwindow;
394 this->zoombar = zoombar;
396 int TrackZoomPanel::handle_event()
398 mwindow->zoom_track((int64_t)get_value());
399 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
406 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
407 : BC_Tumbler(x, y, mwindow->theme->get_image_set("zoombar_tumbler"))
409 this->mwindow = mwindow;
410 this->zoombar = zoombar;
411 this->changemax = changemax;
413 set_tooltip(_("Automation range maximum"));
415 set_tooltip(_("Automation range minimum"));
418 int AutoZoom::handle_up_event()
420 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
422 mwindow->gui->zoombar->update_autozoom();
423 mwindow->gui->draw_overlays(0);
424 mwindow->gui->update_patchbay();
425 mwindow->gui->flash_canvas(1);
429 int AutoZoom::handle_down_event()
431 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
433 mwindow->gui->zoombar->update_autozoom();
434 mwindow->gui->draw_overlays(0);
435 mwindow->gui->update_patchbay();
436 mwindow->gui->flash_canvas(1);
442 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int wid)
443 : BC_PopupMenu(x, y, wid + 24,
444 to_text(mwindow->edl->local_session->zoombar_showautotype), 1, 0, 12)
446 this->mwindow = mwindow;
447 this->zoombar = zoombar;
448 set_tooltip(_("Automation Type"));
451 void AutoTypeMenu::create_objects()
453 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
454 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
455 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
456 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_SPEED)));
457 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
458 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
461 const char* AutoTypeMenu::to_text(int mode)
464 case AUTOGROUPTYPE_AUDIO_FADE: return _("Audio Fade:");
465 case AUTOGROUPTYPE_VIDEO_FADE: return _("Video Fade:");
466 case AUTOGROUPTYPE_ZOOM: return _("Zoom:");
467 case AUTOGROUPTYPE_SPEED: return _("Speed:");
468 case AUTOGROUPTYPE_X: return "X:";
469 case AUTOGROUPTYPE_Y: return "Y:";
474 int AutoTypeMenu::from_text(char *text)
476 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE))) return AUTOGROUPTYPE_AUDIO_FADE;
477 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE))) return AUTOGROUPTYPE_VIDEO_FADE;
478 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM))) return AUTOGROUPTYPE_ZOOM;
479 if(!strcmp(text, to_text(AUTOGROUPTYPE_SPEED))) return AUTOGROUPTYPE_SPEED;
480 if(!strcmp(text, to_text(AUTOGROUPTYPE_X))) return AUTOGROUPTYPE_X;
481 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y))) return AUTOGROUPTYPE_Y;
482 return AUTOGROUPTYPE_INT255;
485 int AutoTypeMenu::draw_face(int dx, int color)
487 BC_PopupMenu::draw_face(dx+8, color);
488 color = mwindow->edl->local_session->zoombar_showautocolor;
491 int margin = get_margin();
492 int mx = margin+4, my = 3*margin/8;
493 int bh = get_h() - 2*my;
494 draw_box(mx,my, bh,bh);
499 int AutoTypeMenu::handle_event()
501 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
502 this->zoombar->update_autozoom();
507 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, const char *text)
508 : BC_TextBox(x, y, 130, 1, text)
510 this->mwindow = mwindow;
511 this->zoombar = zoombar;
512 set_tooltip(_("Automation range"));
515 int ZoomTextBox::button_press_event()
517 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
518 BC_TextBox::button_press_event();
521 if (!is_event_win()) return 0;
524 if (get_relative_cursor_x() < get_w()/2)
528 if (get_buttonpress() == 4)
529 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
532 if (get_buttonpress() == 5)
533 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
535 mwindow->gui->zoombar->update_autozoom();
536 mwindow->gui->draw_overlays(0);
537 mwindow->gui->update_patchbay();
538 mwindow->gui->flash_canvas(1);
542 int ZoomTextBox::handle_event()
545 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
547 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
548 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
551 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
552 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
553 mwindow->gui->zoombar->update_autozoom();
554 mwindow->gui->draw_overlays(0);
555 mwindow->gui->update_patchbay();
556 mwindow->gui->flash_canvas(1);
559 // TODO: Make the text turn red when it's a bad range..
567 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
568 : BC_TextBox(x, y, 90, 1, "")
570 this->mwindow = mwindow;
571 this->zoombar = zoombar;
572 set_tooltip(_("Selection start time"));
575 int FromTextBox::handle_event()
577 if(get_keypress() == 13)
579 zoombar->set_selection(SET_FROM);
585 int FromTextBox::update_position(double new_position)
587 Units::totext(string,
589 mwindow->edl->session->time_format,
590 mwindow->edl->session->sample_rate,
591 mwindow->edl->session->frame_rate,
592 mwindow->edl->session->frames_per_foot);
593 //printf("FromTextBox::update_position %f %s\n", new_position, string);
603 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
604 : BC_TextBox(x, y, 90, 1, "")
606 this->mwindow = mwindow;
607 this->zoombar = zoombar;
608 set_tooltip(_("Selection length"));
611 int LengthTextBox::handle_event()
613 if(get_keypress() == 13)
615 zoombar->set_selection(SET_LENGTH);
621 int LengthTextBox::update_position(double new_position)
623 Units::totext(string,
625 mwindow->edl->session->time_format,
626 mwindow->edl->session->sample_rate,
627 mwindow->edl->session->frame_rate,
628 mwindow->edl->session->frames_per_foot);
637 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
638 : BC_TextBox(x, y, 90, 1, "")
640 this->mwindow = mwindow;
641 this->zoombar = zoombar;
642 set_tooltip(_("Selection end time"));
645 int ToTextBox::handle_event()
647 if(get_keypress() == 13)
649 zoombar->set_selection(SET_TO);
655 int ToTextBox::update_position(double new_position)
657 Units::totext(string, new_position,
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);