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);
97 if( h - y1 < mwindow->theme->fade_h ) {
102 FloatAuto *previous = 0, *next = 0;
103 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
104 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
105 unit_position = atrack->to_units(unit_position, 0);
106 FloatAutos *ptr = (FloatAutos*)atrack->automation->autos[AUTOMATION_FADE];
107 float value = ptr->get_value((long)unit_position, PLAY_FORWARD, previous, next);
108 fade->update(fade->get_w(), value,
109 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
110 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE]);
114 if( h - y1 >= mwindow->theme->fade_h ) {
115 patchbay->add_subwindow(fade = new AFadePatch(mwindow, this, x1+x, y1+y,
116 patchbay->get_w() - 10));
118 y1 += mwindow->theme->fade_h;
121 if( h - y1 < mwindow->theme->meter_h ) {
122 delete meter; meter = 0;
126 if( h - y1 >= mwindow->theme->meter_h ) {
127 patchbay->add_subwindow(meter = new AMeterPatch(mwindow, this, x1+x, y1+y));
129 y1 += mwindow->theme->meter_h;
132 if( h - y1 < mwindow->theme->pan_h ) {
135 delete nudge; nudge = 0;
138 if( mwindow->session->selected_zwindow >= 0 ) {
139 int v = mwindow->mixer_track_active(track);
142 if( pan->get_total_values() != mwindow->edl->session->audio_channels ) {
143 pan->change_channels(mwindow->edl->session->audio_channels,
144 mwindow->edl->session->achannel_positions);
147 int handle_x, handle_y;
148 PanAuto *previous = 0, *next = 0;
149 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
150 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
151 unit_position = atrack->to_units(unit_position, 0);
152 PanAutos *ptr = (PanAutos*)atrack->automation->autos[AUTOMATION_PAN];
153 ptr->get_handle(handle_x, handle_y, (long)unit_position,
154 PLAY_FORWARD, previous, next);
155 pan->update(handle_x, handle_y);
161 if( h - y1 >= mwindow->theme->pan_h ) {
162 patchbay->add_subwindow(mix = new AMixPatch(mwindow, this, x1+x, y1+y+5));
163 x1 += mix->get_w() + 10;
164 patchbay->add_subwindow(pan = new APanPatch(mwindow, this, x1+x, y1+y));
165 x1 += pan->get_w() + 20;
166 patchbay->add_subwindow(nudge = new NudgePatch(mwindow, this, x1+x, y1+y,
167 patchbay->get_w() - x1-x - 10));
169 y1 += mwindow->theme->pan_h;
174 void APatchGUI::synchronize_fade(float value_change)
176 if( fade && !change_source ) {
177 fade->update(fade->get_value() + value_change);
184 AFadePatch::AFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y, int w)
185 : BC_FSlider(x, y, 0, w, w,
186 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
187 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE],
188 mwindow->get_float_auto(patch, AUTOMATION_FADE)->get_value())
190 this->mwindow = mwindow;
194 float AFadePatch::update_edl()
197 double position = mwindow->edl->local_session->get_selectionstart(1);
198 Autos *fade_autos = patch->atrack->automation->autos[AUTOMATION_FADE];
199 int need_undo = !fade_autos->auto_exists_for_editing(position);
201 mwindow->undo->update_undo_before(_("fade"), need_undo ? 0 : this);
203 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
205 float result = get_value() - current->get_value();
206 current->set_value(this->get_value());
208 mwindow->undo->update_undo_after(_("fade"), LOAD_AUTOMATION);
214 int AFadePatch::handle_event()
218 set_tooltip(get_caption());
221 patch->change_source = 1;
222 float change = update_edl();
223 if( patch->track->gang && patch->track->record )
224 patch->patchbay->synchronize_faders(change, TRACK_AUDIO, patch->track);
225 patch->change_source = 0;
227 mwindow->sync_parameters(CHANGE_PARAMS);
229 if( mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE] ) {
230 mwindow->gui->draw_overlays(1);
235 AKeyFadePatch::AKeyFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
236 : BC_SubWindow(x,y, patch->patchbay->get_w(),20,
237 GWindowGUI::auto_colors[AUTOMATION_FADE])
239 this->mwindow = mwindow;
243 void AKeyFadePatch::create_objects()
245 akey_fade_value = new AKeyFadeValue(this);
246 add_subwindow(akey_fade_value);
247 akey_fade_value->activate();
251 AKeyFadeValue::AKeyFadeValue(AKeyFadePatch *akey_fade_patch)
252 : AFadePatch(akey_fade_patch->mwindow, akey_fade_patch->patch,
253 0,0, akey_fade_patch->get_w())
255 this->akey_fade_patch = akey_fade_patch;
258 int AKeyFadeValue::button_release_event()
260 AFadePatch::button_release_event();
264 int AKeyFadeValue::handle_event()
266 APatchGUI *patch = akey_fade_patch->patch;
267 int ret = AFadePatch::handle_event();
268 AFadePatch *fade = patch->fade;
270 fade->update(get_value());
275 APanPatch::APanPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
276 : BC_Pan(x, y, PAN_RADIUS, MAX_PAN,
277 mwindow->edl->session->audio_channels,
278 mwindow->edl->session->achannel_positions,
279 mwindow->get_pan_auto(patch)->handle_x,
280 mwindow->get_pan_auto(patch)->handle_y,
281 mwindow->get_pan_auto(patch)->values)
283 this->mwindow = mwindow;
285 set_tooltip(_("Pan"));
288 int APanPatch::handle_event()
291 double position = mwindow->edl->local_session->get_selectionstart(1);
292 Autos *pan_autos = patch->atrack->automation->autos[AUTOMATION_PAN];
293 int need_undo = !pan_autos->auto_exists_for_editing(position);
295 mwindow->undo->update_undo_before(_("pan"), need_undo ? 0 : this);
297 current = (PanAuto*)pan_autos->get_auto_for_editing(position);
299 current->handle_x = get_stick_x();
300 current->handle_y = get_stick_y();
301 memcpy(current->values, get_values(), sizeof(float) * mwindow->edl->session->audio_channels);
303 mwindow->undo->update_undo_after(_("pan"), LOAD_AUTOMATION);
305 mwindow->sync_parameters(CHANGE_PARAMS);
307 if( need_undo && mwindow->edl->session->auto_conf->autos[AUTOMATION_PAN] ) {
308 mwindow->gui->draw_overlays(1);
313 AKeyPanPatch::AKeyPanPatch(MWindow *mwindow, APatchGUI *patch)
314 : APanPatch(mwindow, patch, -1,-1)
318 int AKeyPanPatch::button_release_event()
320 APanPatch::button_release_event();
324 int AKeyPanPatch::handle_event()
326 int ret = APanPatch::handle_event();
327 APanPatch *pan = patch->pan;
329 pan->update(get_stick_x(), get_stick_y());
334 AMeterPatch::AMeterPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
335 : BC_Meter(x, y, METER_HORIZ, patch->patchbay->get_w() - 10,
336 mwindow->edl->session->min_meter_db, mwindow->edl->session->max_meter_db,
337 mwindow->edl->session->meter_format, 0, -1)
339 this->mwindow = mwindow;
341 set_delays(TRACKING_RATE * 10,
345 int AMeterPatch::button_press_event()
347 if( cursor_inside() && is_event_win() && get_buttonpress() == 1 ) {
348 mwindow->reset_meters();
355 AMixPatch::AMixPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
356 : MixPatch(mwindow, patch, x, y)
358 set_tooltip(_("Mixer"));
361 AMixPatch::~AMixPatch()