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"
35 #include "mainsession.h"
38 #include "mwindowgui.h"
43 #include "trackcanvas.h"
46 APatchGUI::APatchGUI(MWindow *mwindow, PatchBay *patchbay,
47 ATrack *track, int x, int y)
48 : PatchGUI(mwindow, patchbay, track, x, y)
50 data_type = TRACK_AUDIO;
57 APatchGUI::~APatchGUI()
59 if( fade ) delete fade;
60 if( meter ) delete meter;
64 void APatchGUI::create_objects()
69 int APatchGUI::reposition(int x, int y)
71 int y1 = PatchGUI::reposition(x, y);
74 fade->reposition_window(fade->get_x(), y1+y);
75 y1 += mwindow->theme->fade_h;
77 meter->reposition_window(meter->get_x(), y1+y, -1, meter->get_w());
78 y1 += mwindow->theme->meter_h;
80 mix->reposition_window(mix->get_x(), y1+y);
82 pan->reposition_window(pan->get_x(), y1+y);
84 nudge->reposition_window(nudge->get_x(), y1+y);
85 y1 += mwindow->theme->pan_h;
90 int APatchGUI::update(int x, int y)
92 int h = track->vertical_span(mwindow->theme);
94 int y1 = PatchGUI::update(x, y);
96 int y2 = y1 + mwindow->theme->fade_h;
103 FloatAuto *previous = 0, *next = 0;
104 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
105 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
106 unit_position = atrack->to_units(unit_position, 0);
107 FloatAutos *ptr = (FloatAutos*)atrack->automation->autos[AUTOMATION_FADE];
108 float value = ptr->get_value((long)unit_position, PLAY_FORWARD, previous, next);
109 fade->update(fade->get_w(), value,
110 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
111 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE]);
115 patchbay->add_subwindow(fade = new AFadePatch(mwindow, this, x1+x, y1+y,
116 patchbay->get_w() - 10));
121 y2 = y1 + mwindow->theme->meter_h;
124 delete meter; meter = 0;
128 patchbay->add_subwindow(meter = new AMeterPatch(mwindow, this, x1+x, y1+y));
133 y2 = y1 + mwindow->theme->pan_h;
138 delete nudge; nudge = 0;
141 if( mwindow->session->selected_zwindow >= 0 ) {
142 int v = mwindow->mixer_track_active(track);
145 if( pan->get_total_values() != mwindow->edl->session->audio_channels ) {
146 pan->change_channels(mwindow->edl->session->audio_channels,
147 mwindow->edl->session->achannel_positions);
150 int handle_x, handle_y;
151 PanAuto *previous = 0, *next = 0;
152 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
153 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
154 unit_position = atrack->to_units(unit_position, 0);
155 PanAutos *ptr = (PanAutos*)atrack->automation->autos[AUTOMATION_PAN];
156 ptr->get_handle(handle_x, handle_y, (long)unit_position,
157 PLAY_FORWARD, previous, next);
158 pan->update(handle_x, handle_y);
164 patchbay->add_subwindow(mix = new AMixPatch(mwindow, this, x1+x, y1+y+5));
165 x1 += mix->get_w() + 10;
166 patchbay->add_subwindow(pan = new APanPatch(mwindow, this, x1+x, y1+y));
167 x1 += pan->get_w() + 20;
168 patchbay->add_subwindow(nudge = new NudgePatch(mwindow, this, x1+x, y1+y,
169 patchbay->get_w() - x1-x - 10));
177 void APatchGUI::synchronize_fade(float value_change)
179 if( fade && !change_source ) {
180 fade->update(fade->get_value() + value_change);
187 AFadePatch::AFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y, int w)
188 : BC_FSlider(x, y, 0, w, w,
189 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
190 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE],
191 mwindow->get_float_auto(patch, AUTOMATION_FADE)->get_value())
193 this->mwindow = mwindow;
197 float AFadePatch::update_edl()
200 double position = mwindow->edl->local_session->get_selectionstart(1);
201 Autos *fade_autos = patch->atrack->automation->autos[AUTOMATION_FADE];
202 int need_undo = !fade_autos->auto_exists_for_editing(position);
204 mwindow->undo->update_undo_before(_("fade"), need_undo ? 0 : this);
206 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
208 float result = get_value() - current->get_value();
209 current->set_value(this->get_value());
211 mwindow->undo->update_undo_after(_("fade"), LOAD_AUTOMATION);
217 int AFadePatch::handle_event()
221 set_tooltip(get_caption());
224 patch->change_source = 1;
225 float change = update_edl();
226 if( patch->track->gang && patch->track->record )
227 patch->patchbay->synchronize_faders(change, TRACK_AUDIO, patch->track);
228 patch->change_source = 0;
230 mwindow->sync_parameters(CHANGE_PARAMS);
232 if( mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE] ) {
233 mwindow->gui->draw_overlays(1);
238 AKeyFadePatch::AKeyFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
239 : BC_SubWindow(x,y, patch->patchbay->get_w(),20,
240 GWindowGUI::auto_colors[AUTOMATION_FADE])
242 this->mwindow = mwindow;
246 void AKeyFadePatch::create_objects()
248 akey_fade_value = new AKeyFadeValue(this);
249 add_subwindow(akey_fade_value);
250 akey_fade_value->activate();
254 AKeyFadeValue::AKeyFadeValue(AKeyFadePatch *akey_fade_patch)
255 : AFadePatch(akey_fade_patch->mwindow, akey_fade_patch->patch,
256 0,0, akey_fade_patch->get_w())
258 this->akey_fade_patch = akey_fade_patch;
261 int AKeyFadeValue::button_release_event()
263 AFadePatch::button_release_event();
267 int AKeyFadeValue::handle_event()
269 APatchGUI *patch = akey_fade_patch->patch;
270 int ret = AFadePatch::handle_event();
271 AFadePatch *fade = patch->fade;
273 fade->update(get_value());
278 APanPatch::APanPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
279 : BC_Pan(x, y, PAN_RADIUS, MAX_PAN,
280 mwindow->edl->session->audio_channels,
281 mwindow->edl->session->achannel_positions,
282 mwindow->get_pan_auto(patch)->handle_x,
283 mwindow->get_pan_auto(patch)->handle_y,
284 mwindow->get_pan_auto(patch)->values)
286 this->mwindow = mwindow;
288 set_tooltip(_("Pan"));
291 int APanPatch::handle_event()
294 double position = mwindow->edl->local_session->get_selectionstart(1);
295 Autos *pan_autos = patch->atrack->automation->autos[AUTOMATION_PAN];
296 int need_undo = !pan_autos->auto_exists_for_editing(position);
298 mwindow->undo->update_undo_before(_("pan"), need_undo ? 0 : this);
300 current = (PanAuto*)pan_autos->get_auto_for_editing(position);
302 current->handle_x = get_stick_x();
303 current->handle_y = get_stick_y();
304 memcpy(current->values, get_values(), sizeof(float) * mwindow->edl->session->audio_channels);
306 mwindow->undo->update_undo_after(_("pan"), LOAD_AUTOMATION);
308 mwindow->sync_parameters(CHANGE_PARAMS);
310 if( need_undo && mwindow->edl->session->auto_conf->autos[AUTOMATION_PAN] ) {
311 mwindow->gui->draw_overlays(1);
316 AKeyPanPatch::AKeyPanPatch(MWindow *mwindow, APatchGUI *patch)
317 : APanPatch(mwindow, patch, -1,-1)
321 int AKeyPanPatch::button_release_event()
323 APanPatch::button_release_event();
327 int AKeyPanPatch::handle_event()
329 int ret = APanPatch::handle_event();
330 APanPatch *pan = patch->pan;
332 pan->update(get_stick_x(), get_stick_y());
337 AMeterPatch::AMeterPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
338 : BC_Meter(x, y, METER_HORIZ, patch->patchbay->get_w() - 10,
339 mwindow->edl->session->min_meter_db, mwindow->edl->session->max_meter_db,
340 mwindow->edl->session->meter_format, 0, -1)
342 this->mwindow = mwindow;
344 set_delays(TRACKING_RATE * 10,
348 int AMeterPatch::button_press_event()
350 if( cursor_inside() && is_event_win() && get_buttonpress() == 1 ) {
351 mwindow->reset_meters();
358 AMixPatch::AMixPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
359 : MixPatch(mwindow, patch, x, y)
361 set_tooltip(_("Mixer"));
364 AMixPatch::~AMixPatch()