4 * Copyright (C) 2008 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.h"
23 #include "apatchgui.inc"
26 #include "automation.h"
28 #include "edlsession.h"
29 #include "floatauto.h"
30 #include "floatautos.h"
32 #include "localsession.h"
35 #include "mwindowgui.h"
40 #include "trackcanvas.h"
45 APatchGUI::APatchGUI(MWindow *mwindow,
56 data_type = TRACK_AUDIO;
63 APatchGUI::~APatchGUI()
66 if(meter) delete meter;
70 void APatchGUI::create_objects()
75 int APatchGUI::reposition(int x, int y)
77 int y1 = PatchGUI::reposition(x, y);
79 if(fade) fade->reposition_window(fade->get_x(),
81 y1 += mwindow->theme->fade_h;
83 if(meter) meter->reposition_window(meter->get_x(),
87 y1 += mwindow->theme->meter_h;
89 if(pan) pan->reposition_window(pan->get_x(),
92 if(nudge) nudge->reposition_window(nudge->get_x(),
95 y1 += mwindow->theme->pan_h;
99 int APatchGUI::update(int x, int y)
101 int h = track->vertical_span(mwindow->theme);
103 int y1 = PatchGUI::update(x, y);
107 if(h - y1 < mwindow->theme->fade_h)
114 FloatAuto *previous = 0, *next = 0;
115 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
116 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
117 unit_position = atrack->to_units(unit_position, 0);
118 FloatAutos *ptr = (FloatAutos*)atrack->automation->autos[AUTOMATION_FADE];
119 float value = ptr->get_value(
124 fade->update(fade->get_w(),
126 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
127 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE]);
131 if(h - y1 >= mwindow->theme->fade_h)
133 patchbay->add_subwindow(fade = new AFadePatch(mwindow,
137 patchbay->get_w() - 10));
139 y1 += mwindow->theme->fade_h;
143 if(h - y1 < mwindow->theme->meter_h)
150 if(h - y1 >= mwindow->theme->meter_h)
152 patchbay->add_subwindow(meter = new AMeterPatch(mwindow,
157 y1 += mwindow->theme->meter_h;
162 if(h - y1 < mwindow->theme->pan_h)
171 if(pan->get_total_values() != mwindow->edl->session->audio_channels)
173 pan->change_channels(mwindow->edl->session->audio_channels,
174 mwindow->edl->session->achannel_positions);
178 int handle_x, handle_y;
179 PanAuto *previous = 0, *next = 0;
180 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
181 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
182 unit_position = atrack->to_units(unit_position, 0);
183 PanAutos *ptr = (PanAutos*)atrack->automation->autos[AUTOMATION_PAN];
184 ptr->get_handle(handle_x,
190 pan->update(handle_x, handle_y);
196 if(h - y1 >= mwindow->theme->pan_h)
198 patchbay->add_subwindow(pan = new APanPatch(mwindow,
202 x1 += pan->get_w() + 10;
203 patchbay->add_subwindow(nudge = new NudgePatch(mwindow,
207 patchbay->get_w() - x1 - 10));
209 y1 += mwindow->theme->pan_h;
214 void APatchGUI::synchronize_fade(float value_change)
216 if(fade && !change_source)
218 fade->update(fade->get_value() + value_change);
225 AFadePatch::AFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y, int w)
231 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
232 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE],
233 get_keyframe(mwindow, patch)->get_value())
235 this->mwindow = mwindow;
239 float AFadePatch::update_edl()
242 double position = mwindow->edl->local_session->get_selectionstart(1);
243 Autos *fade_autos = patch->atrack->automation->autos[AUTOMATION_FADE];
244 int need_undo = !fade_autos->auto_exists_for_editing(position);
246 mwindow->undo->update_undo_before(_("fade"), need_undo ? 0 : this);
248 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
250 float result = get_value() - current->get_value();
251 current->set_value(this->get_value());
253 mwindow->undo->update_undo_after(_("fade"), LOAD_AUTOMATION);
259 int AFadePatch::handle_event()
264 set_tooltip(get_caption());
267 patch->change_source = 1;
268 float change = update_edl();
269 if(patch->track->gang && patch->track->record)
270 patch->patchbay->synchronize_faders(change, TRACK_AUDIO, patch->track);
271 patch->change_source = 0;
273 mwindow->sync_parameters(CHANGE_PARAMS);
275 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE])
277 mwindow->gui->draw_overlays(1);
282 FloatAuto* AFadePatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
285 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
286 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
287 unit_position = patch->atrack->to_units(unit_position, 0);
289 FloatAutos *ptr = (FloatAutos*)patch->atrack->automation->autos[AUTOMATION_FADE];
290 return (FloatAuto*)ptr->get_prev_auto(
297 APanPatch::APanPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
302 mwindow->edl->session->audio_channels,
303 mwindow->edl->session->achannel_positions,
304 get_keyframe(mwindow, patch)->handle_x,
305 get_keyframe(mwindow, patch)->handle_y,
306 get_keyframe(mwindow, patch)->values)
308 this->mwindow = mwindow;
310 set_tooltip(_("Pan"));
313 int APanPatch::handle_event()
316 double position = mwindow->edl->local_session->get_selectionstart(1);
317 Autos *pan_autos = patch->atrack->automation->autos[AUTOMATION_PAN];
318 int need_undo = !pan_autos->auto_exists_for_editing(position);
320 mwindow->undo->update_undo_before(_("pan"), need_undo ? 0 : this);
322 current = (PanAuto*)pan_autos->get_auto_for_editing(position);
324 current->handle_x = get_stick_x();
325 current->handle_y = get_stick_y();
326 memcpy(current->values, get_values(), sizeof(float) * mwindow->edl->session->audio_channels);
328 mwindow->undo->update_undo_after(_("pan"), LOAD_AUTOMATION);
330 mwindow->sync_parameters(CHANGE_PARAMS);
332 if(need_undo && mwindow->edl->session->auto_conf->autos[AUTOMATION_PAN])
334 mwindow->gui->draw_overlays(1);
339 PanAuto* APanPatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
342 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
343 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
344 unit_position = patch->atrack->to_units(unit_position, 0);
346 PanAutos *ptr = (PanAutos*)patch->atrack->automation->autos[AUTOMATION_PAN];
347 return (PanAuto*)ptr->get_prev_auto(
356 AMeterPatch::AMeterPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
360 patch->patchbay->get_w() - 10,
361 mwindow->edl->session->min_meter_db,
362 mwindow->edl->session->max_meter_db,
363 mwindow->edl->session->meter_format,
367 this->mwindow = mwindow;
369 set_delays(TRACKING_RATE * 10,
373 int AMeterPatch::button_press_event()
375 if(cursor_inside() && is_event_win() && get_buttonpress() == 1)
377 mwindow->reset_meters();