2 #include "apatchgui.inc"
5 #include "automation.h"
7 #include "edlsession.h"
9 #include "floatautos.h"
11 #include "localsession.h"
14 #include "mwindowgui.h"
19 #include "trackcanvas.h"
24 APatchGUI::APatchGUI(MWindow *mwindow,
35 data_type = TRACK_AUDIO;
41 APatchGUI::~APatchGUI()
44 if(meter) delete meter;
48 int APatchGUI::create_objects()
53 int APatchGUI::reposition(int x, int y)
56 int y1 = PatchGUI::reposition(x, y);
58 if(fade) fade->reposition_window(fade->get_x(),
60 y1 += mwindow->theme->fade_h;
62 if(meter) meter->reposition_window(meter->get_x(),
65 y1 += mwindow->theme->meter_h;
67 if(pan) pan->reposition_window(pan->get_x(),
70 if(nudge) nudge->reposition_window(nudge->get_x(),
73 y1 += mwindow->theme->pan_h;
77 int APatchGUI::update(int x, int y)
79 int h = track->vertical_span(mwindow->theme);
81 int y1 = PatchGUI::update(x, y);
85 if(h - y1 < mwindow->theme->fade_h)
92 FloatAuto *previous = 0, *next = 0;
93 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
94 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
95 unit_position = atrack->to_units(unit_position, 0);
96 FloatAutos *ptr = (FloatAutos*)atrack->automation->autos[AUTOMATION_FADE];
97 float value = ptr->get_value(
102 fade->update(fade->get_w(),
104 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
105 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE]);
109 if(h - y1 >= mwindow->theme->fade_h)
111 patchbay->add_subwindow(fade = new AFadePatch(mwindow,
115 patchbay->get_w() - 10));
117 y1 += mwindow->theme->fade_h;
121 if(h - y1 < mwindow->theme->meter_h)
128 if(h - y1 >= mwindow->theme->meter_h)
130 patchbay->add_subwindow(meter = new AMeterPatch(mwindow,
135 y1 += mwindow->theme->meter_h;
140 if(h - y1 < mwindow->theme->pan_h)
149 if(pan->get_total_values() != mwindow->edl->session->audio_channels)
151 pan->change_channels(mwindow->edl->session->audio_channels,
152 mwindow->edl->session->achannel_positions);
156 int handle_x, handle_y;
157 PanAuto *previous = 0, *next = 0;
158 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
159 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
160 unit_position = atrack->to_units(unit_position, 0);
161 PanAutos *ptr = (PanAutos*)atrack->automation->autos[AUTOMATION_PAN];
162 ptr->get_handle(handle_x,
168 pan->update(handle_x, handle_y);
174 if(h - y1 >= mwindow->theme->pan_h)
176 patchbay->add_subwindow(pan = new APanPatch(mwindow,
180 x1 += pan->get_w() + 10;
181 patchbay->add_subwindow(nudge = new NudgePatch(mwindow,
185 patchbay->get_w() - x1 - 10));
187 y1 += mwindow->theme->pan_h;
192 void APatchGUI::synchronize_fade(float value_change)
194 if(fade && !change_source)
196 fade->update(fade->get_value() + value_change);
203 AFadePatch::AFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y, int w)
209 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
210 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE],
211 get_keyframe(mwindow, patch)->value)
213 this->mwindow = mwindow;
217 float AFadePatch::update_edl()
220 double position = mwindow->edl->local_session->get_selectionstart(1);
221 Autos *fade_autos = patch->atrack->automation->autos[AUTOMATION_FADE];
222 int need_undo = !fade_autos->auto_exists_for_editing(position);
224 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
226 float result = get_value() - current->value;
227 current->value = get_value();
229 mwindow->undo->update_undo(_("fade"),
231 need_undo ? 0 : this);
237 int AFadePatch::handle_event()
242 set_tooltip(get_caption());
245 patch->change_source = 1;
246 float change = update_edl();
247 if(patch->track->gang)
248 patch->patchbay->synchronize_faders(change, TRACK_AUDIO, patch->track);
249 patch->change_source = 0;
251 mwindow->sync_parameters(CHANGE_PARAMS);
253 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE])
255 mwindow->gui->canvas->draw_overlays();
256 mwindow->gui->canvas->flash();
261 FloatAuto* AFadePatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
264 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
265 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
266 unit_position = patch->atrack->to_units(unit_position, 0);
268 FloatAutos *ptr = (FloatAutos*)patch->atrack->automation->autos[AUTOMATION_FADE];
269 return (FloatAuto*)ptr->get_prev_auto(
276 APanPatch::APanPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
281 mwindow->edl->session->audio_channels,
282 mwindow->edl->session->achannel_positions,
283 get_keyframe(mwindow, patch)->handle_x,
284 get_keyframe(mwindow, patch)->handle_y,
285 get_keyframe(mwindow, patch)->values)
287 this->mwindow = mwindow;
292 int APanPatch::handle_event()
295 double position = mwindow->edl->local_session->get_selectionstart(1);
296 Autos *pan_autos = patch->atrack->automation->autos[AUTOMATION_PAN];
297 int need_undo = !pan_autos->auto_exists_for_editing(position);
299 current = (PanAuto*)pan_autos->get_auto_for_editing(position);
301 current->handle_x = get_stick_x();
302 current->handle_y = get_stick_y();
303 memcpy(current->values, get_values(), sizeof(float) * mwindow->edl->session->audio_channels);
305 mwindow->undo->update_undo(_("pan"), LOAD_AUTOMATION, need_undo ? 0 : this);
307 mwindow->sync_parameters(CHANGE_PARAMS);
309 if(need_undo && mwindow->edl->session->auto_conf->autos[AUTOMATION_PAN])
311 mwindow->gui->canvas->draw_overlays();
312 mwindow->gui->canvas->flash();
317 PanAuto* APanPatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
320 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
321 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
322 unit_position = patch->atrack->to_units(unit_position, 0);
324 PanAutos *ptr = (PanAutos*)patch->atrack->automation->autos[AUTOMATION_PAN];
325 return (PanAuto*)ptr->get_prev_auto(
334 AMeterPatch::AMeterPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
338 patch->patchbay->get_w() - 10,
339 mwindow->edl->session->min_meter_db,
340 mwindow->edl->session->max_meter_db,
341 mwindow->edl->session->meter_format,
346 this->mwindow = mwindow;
350 int AMeterPatch::button_press_event()
352 if(cursor_inside() && is_event_win() && get_buttonpress() == 1)
354 mwindow->reset_meters();