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(
128 if(h - y1 >= mwindow->theme->fade_h)
130 patchbay->add_subwindow(fade = new AFadePatch(mwindow,
134 patchbay->get_w() - 10));
136 y1 += mwindow->theme->fade_h;
140 if(h - y1 < mwindow->theme->meter_h)
147 if(h - y1 >= mwindow->theme->meter_h)
149 patchbay->add_subwindow(meter = new AMeterPatch(mwindow,
154 y1 += mwindow->theme->meter_h;
159 if(h - y1 < mwindow->theme->pan_h)
168 if(pan->get_total_values() != mwindow->edl->session->audio_channels)
170 pan->change_channels(mwindow->edl->session->audio_channels,
171 mwindow->edl->session->achannel_positions);
175 int handle_x, handle_y;
176 PanAuto *previous = 0, *next = 0;
177 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
178 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
179 unit_position = atrack->to_units(unit_position, 0);
180 PanAutos *ptr = (PanAutos*)atrack->automation->autos[AUTOMATION_PAN];
181 ptr->get_handle(handle_x,
187 pan->update(handle_x, handle_y);
193 if(h - y1 >= mwindow->theme->pan_h)
195 patchbay->add_subwindow(pan = new APanPatch(mwindow,
199 x1 += pan->get_w() + 10;
200 patchbay->add_subwindow(nudge = new NudgePatch(mwindow,
204 patchbay->get_w() - x1 - 10));
206 y1 += mwindow->theme->pan_h;
211 void APatchGUI::synchronize_fade(float value_change)
213 if(fade && !change_source)
215 fade->update(fade->get_value() + value_change);
222 AFadePatch::AFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y, int w)
229 (float)MAX_AUDIO_FADE,
230 get_keyframe(mwindow, patch)->value)
232 this->mwindow = mwindow;
236 float AFadePatch::update_edl()
239 double position = mwindow->edl->local_session->get_selectionstart(1);
240 Autos *fade_autos = patch->atrack->automation->autos[AUTOMATION_FADE];
241 int need_undo = !fade_autos->auto_exists_for_editing(position);
243 mwindow->undo->update_undo_before(_("fade"), need_undo ? 0 : this);
245 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
247 float result = get_value() - current->value;
248 current->value = get_value();
250 mwindow->undo->update_undo_after(_("fade"), LOAD_AUTOMATION);
256 int AFadePatch::handle_event()
261 set_tooltip(get_caption());
264 patch->change_source = 1;
265 float change = update_edl();
266 if(patch->track->gang && patch->track->record)
267 patch->patchbay->synchronize_faders(change, TRACK_AUDIO, patch->track);
268 patch->change_source = 0;
270 mwindow->sync_parameters(CHANGE_PARAMS);
272 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE])
274 mwindow->gui->draw_overlays(1);
279 FloatAuto* AFadePatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
282 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
283 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
284 unit_position = patch->atrack->to_units(unit_position, 0);
286 FloatAutos *ptr = (FloatAutos*)patch->atrack->automation->autos[AUTOMATION_FADE];
287 return (FloatAuto*)ptr->get_prev_auto(
294 APanPatch::APanPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
299 mwindow->edl->session->audio_channels,
300 mwindow->edl->session->achannel_positions,
301 get_keyframe(mwindow, patch)->handle_x,
302 get_keyframe(mwindow, patch)->handle_y,
303 get_keyframe(mwindow, patch)->values)
305 this->mwindow = mwindow;
307 set_tooltip(_("Pan"));
310 int APanPatch::handle_event()
313 double position = mwindow->edl->local_session->get_selectionstart(1);
314 Autos *pan_autos = patch->atrack->automation->autos[AUTOMATION_PAN];
315 int need_undo = !pan_autos->auto_exists_for_editing(position);
317 mwindow->undo->update_undo_before(_("pan"), need_undo ? 0 : this);
319 current = (PanAuto*)pan_autos->get_auto_for_editing(position);
321 current->handle_x = get_stick_x();
322 current->handle_y = get_stick_y();
323 memcpy(current->values, get_values(), sizeof(float) * mwindow->edl->session->audio_channels);
325 mwindow->undo->update_undo_after(_("pan"), LOAD_AUTOMATION);
327 mwindow->sync_parameters(CHANGE_PARAMS);
329 if(need_undo && mwindow->edl->session->auto_conf->autos[AUTOMATION_PAN])
331 mwindow->gui->draw_overlays(1);
336 PanAuto* APanPatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
339 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
340 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
341 unit_position = patch->atrack->to_units(unit_position, 0);
343 PanAutos *ptr = (PanAutos*)patch->atrack->automation->autos[AUTOMATION_PAN];
344 return (PanAuto*)ptr->get_prev_auto(
353 AMeterPatch::AMeterPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
357 patch->patchbay->get_w() - 10,
358 mwindow->edl->session->min_meter_db,
359 mwindow->edl->session->max_meter_db,
360 mwindow->edl->session->meter_format,
364 this->mwindow = mwindow;
366 set_delays(TRACKING_RATE * 10,
370 int AMeterPatch::button_press_event()
372 if(cursor_inside() && is_event_win() && get_buttonpress() == 1)
374 mwindow->reset_meters();