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"
35 #include "localsession.h"
36 #include "mainsession.h"
39 #include "mwindowgui.h"
44 #include "trackcanvas.h"
47 APatchGUI::APatchGUI(MWindow *mwindow, PatchBay *patchbay,
48 ATrack *track, int x, int y)
49 : PatchGUI(mwindow, patchbay, track, x, y)
51 data_type = TRACK_AUDIO;
58 APatchGUI::~APatchGUI()
60 if( fade ) delete fade;
61 if( meter ) delete meter;
65 void APatchGUI::create_objects()
70 int APatchGUI::reposition(int x, int y)
72 int y1 = PatchGUI::reposition(x, y);
75 fade->reposition_window(fade->get_x(), y1+y);
76 y1 += mwindow->theme->fade_h;
78 meter->reposition_window(meter->get_x(), y1+y, -1, meter->get_w());
79 y1 += mwindow->theme->meter_h;
81 mix->reposition_window(mix->get_x(), y1+y);
83 pan->reposition_window(pan->get_x(), y1+y);
85 nudge->reposition_window(nudge->get_x(), y1+y);
86 y1 += mwindow->theme->pan_h;
91 int APatchGUI::update(int x, int y)
93 int h = track->vertical_span(mwindow->theme);
95 int y1 = PatchGUI::update(x, y);
97 int y2 = y1 + mwindow->theme->fade_h;
104 FloatAuto *previous = 0, *next = 0;
105 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
106 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
107 unit_position = atrack->to_units(unit_position, 0);
108 FloatAutos *ptr = (FloatAutos*)atrack->automation->autos[AUTOMATION_FADE];
109 float value = ptr->get_value((long)unit_position, PLAY_FORWARD, previous, next);
110 fade->update(fade->get_w(), value,
111 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
112 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE]);
116 float v = mwindow->get_float_auto(this, AUTOMATION_FADE)->get_value();
117 patchbay->add_subwindow(fade = new AFadePatch(this, x1+x, y1+y,
118 patchbay->get_w() - 10, v));
122 y2 = y1 + mwindow->theme->meter_h;
125 delete meter; meter = 0;
129 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));
176 void APatchGUI::update_faders(float v)
182 double position = mwindow->edl->local_session->get_selectionstart(1);
183 Autos *fade_autos = atrack->automation->autos[AUTOMATION_FADE];
184 int need_undo = !fade_autos->auto_exists_for_editing(position);
186 mwindow->undo->update_undo_before(_("fade"), need_undo ? 0 : this);
187 FloatAuto *current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
188 float change = v - current->get_value();
189 current->set_value(v);
191 if( track->gang && track->record )
192 patchbay->synchronize_faders(change, TRACK_AUDIO, track);
193 mwindow->undo->update_undo_after(_("fade"), LOAD_AUTOMATION);
196 mwindow->sync_parameters(CHANGE_PARAMS);
198 if( mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE] ) {
199 mwindow->gui->draw_overlays(1);
203 AFadePatch::AFadePatch(APatchGUI *patch, int x, int y, int w, float v)
204 : BC_FSlider(x, y, 0, w, w,
205 patch->mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
206 patch->mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE],
213 int AFadePatch::handle_event()
217 set_tooltip(get_caption());
219 patch->update_faders(get_value());
223 AKeyFadePatch::AKeyFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
224 : BC_SubWindow(x,y, 200,20, GWindowGUI::auto_colors[AUTOMATION_FADE])
226 this->mwindow = mwindow;
230 void AKeyFadePatch::create_objects()
233 float v = mwindow->get_float_auto(patch, AUTOMATION_FADE)->get_value();
234 add_subwindow(akey_fade_text = new AKeyFadeText(this, x, y, 64, v));
235 x += akey_fade_text->get_w();
236 VFrame **lok_images = mwindow->theme->get_image_set("lok");
237 int w1 = get_w() - x - lok_images[0]->get_w();
238 add_subwindow(akey_fade_slider = new AKeyFadeSlider(this, x, y, w1, v));
239 x += akey_fade_slider->get_w();
240 add_subwindow(akey_fade_ok = new AKeyFadeOK(this, x, y, lok_images));
245 void AKeyFadePatch::update(float v)
247 akey_fade_text->update(v);
248 akey_fade_slider->update(v);
249 patch->update_faders(v);
252 AKeyFadeOK::AKeyFadeOK(AKeyFadePatch *akey_fade_patch, int x, int y, VFrame **images)
253 : BC_Button(x, y, images)
255 this->akey_fade_patch = akey_fade_patch;
258 int AKeyFadeOK::handle_event()
260 MWindowGUI *mgui = akey_fade_patch->mwindow->gui;
261 delete mgui->keyvalue_popup;
262 mgui->keyvalue_popup = 0;
266 AKeyFadeText::AKeyFadeText(AKeyFadePatch *akey_fade_patch, int x, int y, int w, float v)
267 : BC_TextBox(x, y, w, 1, v, 1, MEDIUMFONT, 2)
269 this->akey_fade_patch = akey_fade_patch;
272 int AKeyFadeText::handle_event()
274 float v = atof(get_text());
275 akey_fade_patch->update(v);
276 return get_keypress() != RETURN ? 1 :
277 akey_fade_patch->akey_fade_ok->handle_event();
280 AKeyFadeSlider::AKeyFadeSlider(AKeyFadePatch *akey_fade_patch, int x, int y, int w, float v)
281 : AFadePatch(akey_fade_patch->patch, x, y, w, v)
283 this->akey_fade_patch = akey_fade_patch;
286 int AKeyFadeSlider::handle_event()
288 float v = get_value();
289 akey_fade_patch->update(v);
294 APanPatch::APanPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
295 : BC_Pan(x, y, PAN_RADIUS, MAX_PAN,
296 mwindow->edl->session->audio_channels,
297 mwindow->edl->session->achannel_positions,
298 mwindow->get_pan_auto(patch)->handle_x,
299 mwindow->get_pan_auto(patch)->handle_y,
300 mwindow->get_pan_auto(patch)->values)
302 this->mwindow = mwindow;
304 set_tooltip(_("Pan"));
307 int APanPatch::handle_event()
310 double position = mwindow->edl->local_session->get_selectionstart(1);
311 Autos *pan_autos = patch->atrack->automation->autos[AUTOMATION_PAN];
312 int need_undo = !pan_autos->auto_exists_for_editing(position);
314 mwindow->undo->update_undo_before(_("pan"), need_undo ? 0 : this);
316 current = (PanAuto*)pan_autos->get_auto_for_editing(position);
318 current->handle_x = get_stick_x();
319 current->handle_y = get_stick_y();
320 memcpy(current->values, get_values(), sizeof(float) * mwindow->edl->session->audio_channels);
322 mwindow->undo->update_undo_after(_("pan"), LOAD_AUTOMATION);
324 mwindow->sync_parameters(CHANGE_PARAMS);
326 if( need_undo && mwindow->edl->session->auto_conf->autos[AUTOMATION_PAN] ) {
327 mwindow->gui->draw_overlays(1);
332 AKeyPanPatch::AKeyPanPatch(MWindow *mwindow, APatchGUI *patch)
333 : APanPatch(mwindow, patch, -1,-1)
337 int AKeyPanPatch::handle_event()
339 int ret = APanPatch::handle_event();
340 APanPatch *pan = patch->pan;
342 pan->update(get_stick_x(), get_stick_y());
347 AMeterPatch::AMeterPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
348 : BC_Meter(x, y, METER_HORIZ, patch->patchbay->get_w() - 10,
349 mwindow->edl->session->min_meter_db, mwindow->edl->session->max_meter_db,
350 mwindow->edl->session->meter_format, 0, -1)
352 this->mwindow = mwindow;
354 set_delays(TRACKING_RATE * 10,
358 int AMeterPatch::button_press_event()
360 if( cursor_inside() && is_event_win() && get_buttonpress() == 1 ) {
361 mwindow->reset_meters();
368 AMixPatch::AMixPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
369 : MixPatch(mwindow, patch, x, y)
371 set_tooltip(_("Mixer"));
374 AMixPatch::~AMixPatch()