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(_("sample zoom"));
74 x += sample_zoom->get_w();
75 amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
76 amp_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
77 amp_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
78 amp_zoom->create_objects();
79 amp_zoom->zoom_text->set_tooltip(_("amp zoom"));
80 x += amp_zoom->get_w();
81 track_zoom = new TrackZoomPanel(mwindow, this, x, y);
82 track_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
83 track_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
84 track_zoom->create_objects();
85 track_zoom->zoom_text->set_tooltip(_("track zoom"));
86 x += track_zoom->get_w() + 10;
88 #define DEFAULT_TEXT "000.00 - 000.00"
89 add_subwindow(auto_zoom_popup = new AutoZoomPopup(
94 get_text_width(MEDIUMFONT, DEFAULT_TEXT) + 20));
95 auto_zoom_popup->create_objects();
96 auto_zoom_popup->set_tooltip(_("curve zoom (autofit Alt f)"));
97 x += auto_zoom_popup->get_w() + 5;
98 // add_subwindow(auto_zoom_text = new BC_Title(
100 // get_h() / 2 - BC_Title::calculate_h(this, "0") / 2,
102 // x += auto_zoom_text->get_w() + 5;
103 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y));
105 x += auto_zoom->get_w() + 5;
107 add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
108 x += from_value->get_w() + 5;
109 add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
110 x += length_value->get_w() + 5;
111 add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
112 x += to_value->get_w() + 5;
114 update_formatting(from_value);
115 update_formatting(length_value);
116 update_formatting(to_value);
118 add_subwindow(playback_value = new BC_Title(x, 100, "--", MEDIUMFONT, RED));
120 add_subwindow(zoom_value = new BC_Title(x, 100, "--", MEDIUMFONT, BLACK));
125 void ZoomBar::update_formatting(BC_TextBox *dst)
128 Units::format_to_separators(mwindow->edl->session->time_format));
131 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 // sample_zoom->reposition_window(x, y);
142 // x += sample_zoom->get_w();
143 // amp_zoom->reposition_window(x, y);
144 // x += amp_zoom->get_w();
145 // track_zoom->reposition_window(x, y);
150 void ZoomBar::redraw_time_dependancies()
152 // Recalculate sample zoom menu
153 sample_zoom->update_menu();
154 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
155 update_formatting(from_value);
156 update_formatting(length_value);
157 update_formatting(to_value);
168 void ZoomBar::update_autozoom()
170 char string[BCTEXTLEN];
171 sprintf(string, "%0.02f - %0.02f\n",
172 mwindow->edl->local_session->automation_min,
173 mwindow->edl->local_session->automation_max);
174 // auto_zoom_text->update(string);
175 auto_zoom_popup->set_text(string);
178 int ZoomBar::update()
180 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
181 amp_zoom->update(mwindow->edl->local_session->zoom_y);
182 track_zoom->update(mwindow->edl->local_session->zoom_track);
188 int ZoomBar::update_clocks()
190 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
191 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
192 mwindow->edl->local_session->get_selectionstart(1));
193 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
197 int ZoomBar::update_playback(int64_t new_position)
199 if(new_position != old_position)
201 Units::totext(string,
203 mwindow->edl->session->sample_rate,
204 mwindow->edl->session->time_format,
205 mwindow->edl->session->frame_rate,
206 mwindow->edl->session->frames_per_foot);
207 playback_value->update(string);
208 old_position = new_position;
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,
332 mwindow->edl->local_session->zoom_sample,
340 this->mwindow = mwindow;
341 this->zoombar = zoombar;
343 int SampleZoomPanel::handle_event()
345 mwindow->zoom_sample((int64_t)get_value());
359 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
362 mwindow->edl->local_session->zoom_y,
370 this->mwindow = mwindow;
371 this->zoombar = zoombar;
373 int AmpZoomPanel::handle_event()
375 mwindow->zoom_amp((int64_t)get_value());
379 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
382 mwindow->edl->local_session->zoom_track,
390 this->mwindow = mwindow;
391 this->zoombar = zoombar;
393 int TrackZoomPanel::handle_event()
395 mwindow->zoom_track((int64_t)get_value());
396 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
403 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
406 mwindow->theme->get_image_set("zoombar_tumbler"))
408 this->mwindow = mwindow;
409 this->zoombar = zoombar;
412 int AutoZoom::handle_up_event()
414 mwindow->expand_autos();
418 int AutoZoom::handle_down_event()
420 mwindow->shrink_autos();
430 AutoZoomPopup::AutoZoomPopup(MWindow *mwindow,
440 mwindow->theme->get_image_set("zoombar_menu", 0))
442 this->mwindow = mwindow;
443 this->zoombar = zoombar;
447 static const struct {
456 { INFINITYGAIN, MAX_AUDIO_FADE, },
459 void AutoZoomPopup::create_objects()
461 char string[BCTEXTLEN];
462 int n = sizeof(auto_zooms)/sizeof(auto_zooms[0]);
463 for( int i=0; i<n; ++i ) {
464 sprintf(string, "%d - %d", auto_zooms[i].min, auto_zooms[i].max);
465 add_item(new BC_MenuItem(string));
469 int AutoZoomPopup::handle_event()
471 const char *cp = get_text();
472 int i = total_items();
473 while( --i >= 0 && strcmp(cp, get_item(i)->get_text()) );
475 mwindow->zoom_autos(auto_zooms[i].min, auto_zooms[i].max);
482 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
483 : BC_TextBox(x, y, 90, 1, "")
485 this->mwindow = mwindow;
486 this->zoombar = zoombar;
489 int FromTextBox::handle_event()
491 if(get_keypress() == 13)
493 zoombar->set_selection(SET_FROM);
499 int FromTextBox::update_position(double new_position)
501 Units::totext(string,
503 mwindow->edl->session->time_format,
504 mwindow->edl->session->sample_rate,
505 mwindow->edl->session->frame_rate,
506 mwindow->edl->session->frames_per_foot);
507 //printf("FromTextBox::update_position %f %s\n", new_position, string);
517 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
518 : BC_TextBox(x, y, 90, 1, "")
520 this->mwindow = mwindow;
521 this->zoombar = zoombar;
524 int LengthTextBox::handle_event()
526 if(get_keypress() == 13)
528 zoombar->set_selection(SET_LENGTH);
534 int LengthTextBox::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);
550 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
551 : BC_TextBox(x, y, 90, 1, "")
553 this->mwindow = mwindow;
554 this->zoombar = zoombar;
557 int ToTextBox::handle_event()
559 if(get_keypress() == 13)
561 zoombar->set_selection(SET_TO);
567 int ToTextBox::update_position(double new_position)
569 Units::totext(string,
571 mwindow->edl->session->time_format,
572 mwindow->edl->session->sample_rate,
573 mwindow->edl->session->frame_rate,
574 mwindow->edl->session->frames_per_foot);