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"
25 #include "automation.h"
27 #include "edlsession.h"
28 #include "floatauto.h"
29 #include "floatautos.h"
30 #include "gwindowgui.h"
34 #include "localsession.h"
37 #include "mwindowgui.h"
42 #include "trackcanvas.h"
47 APatchGUI::APatchGUI(MWindow *mwindow,
58 data_type = TRACK_AUDIO;
65 APatchGUI::~APatchGUI()
68 if(meter) delete meter;
72 void APatchGUI::create_objects()
77 int APatchGUI::reposition(int x, int y)
79 int y1 = PatchGUI::reposition(x, y);
81 if(fade) fade->reposition_window(fade->get_x(),
83 y1 += mwindow->theme->fade_h;
85 if(meter) meter->reposition_window(meter->get_x(),
89 y1 += mwindow->theme->meter_h;
91 if(pan) pan->reposition_window(pan->get_x(),
94 if(nudge) nudge->reposition_window(nudge->get_x(),
97 y1 += mwindow->theme->pan_h;
101 int APatchGUI::update(int x, int y)
103 int h = track->vertical_span(mwindow->theme);
105 int y1 = PatchGUI::update(x, y);
109 if(h - y1 < mwindow->theme->fade_h)
116 FloatAuto *previous = 0, *next = 0;
117 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
118 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
119 unit_position = atrack->to_units(unit_position, 0);
120 FloatAutos *ptr = (FloatAutos*)atrack->automation->autos[AUTOMATION_FADE];
121 float value = ptr->get_value(
126 fade->update(fade->get_w(),
128 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
129 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE]);
133 if(h - y1 >= mwindow->theme->fade_h)
135 patchbay->add_subwindow(fade = new AFadePatch(mwindow,
139 patchbay->get_w() - 10));
141 y1 += mwindow->theme->fade_h;
145 if(h - y1 < mwindow->theme->meter_h)
152 if(h - y1 >= mwindow->theme->meter_h)
154 patchbay->add_subwindow(meter = new AMeterPatch(mwindow,
159 y1 += mwindow->theme->meter_h;
164 if(h - y1 < mwindow->theme->pan_h)
173 if(pan->get_total_values() != mwindow->edl->session->audio_channels)
175 pan->change_channels(mwindow->edl->session->audio_channels,
176 mwindow->edl->session->achannel_positions);
180 int handle_x, handle_y;
181 PanAuto *previous = 0, *next = 0;
182 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
183 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
184 unit_position = atrack->to_units(unit_position, 0);
185 PanAutos *ptr = (PanAutos*)atrack->automation->autos[AUTOMATION_PAN];
186 ptr->get_handle(handle_x,
192 pan->update(handle_x, handle_y);
198 if(h - y1 >= mwindow->theme->pan_h)
200 patchbay->add_subwindow(pan = new APanPatch(mwindow,
204 x1 += pan->get_w() + 10;
205 patchbay->add_subwindow(nudge = new NudgePatch(mwindow,
209 patchbay->get_w() - x1 - 10));
211 y1 += mwindow->theme->pan_h;
216 void APatchGUI::synchronize_fade(float value_change)
218 if(fade && !change_source)
220 fade->update(fade->get_value() + value_change);
227 AFadePatch::AFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y, int w)
228 : BC_FSlider(x, y, 0, w, w,
229 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
230 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE],
231 mwindow->get_float_auto(patch, AUTOMATION_FADE)->get_value())
233 this->mwindow = mwindow;
237 float AFadePatch::update_edl()
240 double position = mwindow->edl->local_session->get_selectionstart(1);
241 Autos *fade_autos = patch->atrack->automation->autos[AUTOMATION_FADE];
242 int need_undo = !fade_autos->auto_exists_for_editing(position);
244 mwindow->undo->update_undo_before(_("fade"), need_undo ? 0 : this);
246 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
248 float result = get_value() - current->get_value();
249 current->set_value(this->get_value());
251 mwindow->undo->update_undo_after(_("fade"), LOAD_AUTOMATION);
257 int AFadePatch::handle_event()
262 set_tooltip(get_caption());
265 patch->change_source = 1;
266 float change = update_edl();
267 if(patch->track->gang && patch->track->record)
268 patch->patchbay->synchronize_faders(change, TRACK_AUDIO, patch->track);
269 patch->change_source = 0;
271 mwindow->sync_parameters(CHANGE_PARAMS);
273 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE])
275 mwindow->gui->draw_overlays(1);
280 AKeyFadePatch::AKeyFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
281 : BC_SubWindow(x,y, patch->patchbay->get_w(),20,
282 GWindowGUI::auto_colors[AUTOMATION_FADE])
284 this->mwindow = mwindow;
288 void AKeyFadePatch::create_objects()
290 akey_fade_value = new AKeyFadeValue(this);
291 add_subwindow(akey_fade_value);
292 akey_fade_value->activate();
296 AKeyFadeValue::AKeyFadeValue(AKeyFadePatch *akey_fade_patch)
297 : AFadePatch(akey_fade_patch->mwindow, akey_fade_patch->patch,
298 0,0, akey_fade_patch->get_w())
300 this->akey_fade_patch = akey_fade_patch;
303 int AKeyFadeValue::button_release_event()
305 AFadePatch::button_release_event();
309 int AKeyFadeValue::handle_event()
311 APatchGUI *patch = akey_fade_patch->patch;
312 int ret = AFadePatch::handle_event();
313 AFadePatch *fade = patch->fade;
315 fade->update(get_value());
320 APanPatch::APanPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
321 : BC_Pan(x, y, PAN_RADIUS, MAX_PAN,
322 mwindow->edl->session->audio_channels,
323 mwindow->edl->session->achannel_positions,
324 mwindow->get_pan_auto(patch)->handle_x,
325 mwindow->get_pan_auto(patch)->handle_y,
326 mwindow->get_pan_auto(patch)->values)
328 this->mwindow = mwindow;
330 set_tooltip(_("Pan"));
333 int APanPatch::handle_event()
336 double position = mwindow->edl->local_session->get_selectionstart(1);
337 Autos *pan_autos = patch->atrack->automation->autos[AUTOMATION_PAN];
338 int need_undo = !pan_autos->auto_exists_for_editing(position);
340 mwindow->undo->update_undo_before(_("pan"), need_undo ? 0 : this);
342 current = (PanAuto*)pan_autos->get_auto_for_editing(position);
344 current->handle_x = get_stick_x();
345 current->handle_y = get_stick_y();
346 memcpy(current->values, get_values(), sizeof(float) * mwindow->edl->session->audio_channels);
348 mwindow->undo->update_undo_after(_("pan"), LOAD_AUTOMATION);
350 mwindow->sync_parameters(CHANGE_PARAMS);
352 if(need_undo && mwindow->edl->session->auto_conf->autos[AUTOMATION_PAN])
354 mwindow->gui->draw_overlays(1);
359 AKeyPanPatch::AKeyPanPatch(MWindow *mwindow, APatchGUI *patch)
360 : APanPatch(mwindow, patch, -1,-1)
364 int AKeyPanPatch::button_release_event()
366 APanPatch::button_release_event();
370 int AKeyPanPatch::handle_event()
372 int ret = APanPatch::handle_event();
373 APanPatch *pan = patch->pan;
375 pan->update(get_stick_x(), get_stick_y());
380 AMeterPatch::AMeterPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
384 patch->patchbay->get_w() - 10,
385 mwindow->edl->session->min_meter_db,
386 mwindow->edl->session->max_meter_db,
387 mwindow->edl->session->meter_format,
391 this->mwindow = mwindow;
393 set_delays(TRACKING_RATE * 10,
397 int AMeterPatch::button_press_event()
399 if(cursor_inside() && is_event_win() && get_buttonpress() == 1)
401 mwindow->reset_meters();