2 #include "apatchgui.inc"
5 #include "automation.h"
7 #include "edlsession.h"
9 #include "floatautos.h"
10 #include "localsession.h"
13 #include "mwindowgui.h"
18 #include "trackcanvas.h"
22 #define _(String) gettext(String)
23 #define gettext_noop(String) String
24 #define N_(String) gettext_noop (String)
27 APatchGUI::APatchGUI(MWindow *mwindow, PatchBay *patchbay, ATrack *track, int x, int y)
28 : PatchGUI(mwindow, patchbay, track, x, y)
30 data_type = TRACK_AUDIO;
36 APatchGUI::~APatchGUI()
39 if(meter) delete meter;
43 int APatchGUI::create_objects()
48 int APatchGUI::reposition(int x, int y)
51 int y1 = PatchGUI::reposition(x, y);
53 if(fade) fade->reposition_window(x1 + x,
55 y1 += mwindow->theme->fade_h;
57 if(meter) meter->reposition_window(x1 + x,
60 y1 += mwindow->theme->meter_h;
62 if(pan) pan->reposition_window(x1 + x + mwindow->theme->pan_x,
64 y1 += mwindow->theme->pan_h;
68 int APatchGUI::update(int x, int y)
70 int h = track->vertical_span(mwindow->theme);
72 int y1 = PatchGUI::update(x, y);
76 if(h - y1 < mwindow->theme->fade_h)
83 //printf("APatchGUI::update %f\n", fade->get_keyframe(mwindow, this)->value);
84 FloatAuto *previous = 0, *next = 0;
85 double unit_position = mwindow->edl->local_session->selectionstart;
86 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
87 unit_position = atrack->to_units(unit_position, 0);
88 float value = atrack->automation->fade_autos->get_value(
94 // fade->update(fade->get_keyframe(mwindow, this)->value);
98 if(h - y1 >= mwindow->theme->fade_h)
100 patchbay->add_subwindow(fade = new AFadePatch(mwindow,
104 patchbay->get_w() - 10));
106 y1 += mwindow->theme->fade_h;
110 if(h - y1 < mwindow->theme->meter_h)
117 if(h - y1 >= mwindow->theme->meter_h)
119 patchbay->add_subwindow(meter = new AMeterPatch(mwindow,
124 y1 += mwindow->theme->meter_h;
128 if(h - y1 < mwindow->theme->pan_h)
134 if(pan->get_total_values() != mwindow->edl->session->audio_channels)
136 pan->change_channels(mwindow->edl->session->audio_channels,
137 mwindow->edl->session->achannel_positions);
141 int handle_x, handle_y;
142 PanAuto *previous = 0, *next = 0;
143 double unit_position = mwindow->edl->local_session->selectionstart;
144 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
145 unit_position = atrack->to_units(unit_position, 0);
146 atrack->automation->pan_autos->get_handle(handle_x,
152 pan->update(handle_x, handle_y);
156 if(h - y1 >= mwindow->theme->pan_h)
158 patchbay->add_subwindow(pan = new APanPatch(mwindow,
160 x1 + x + mwindow->theme->pan_x,
163 y1 += mwindow->theme->pan_h;
168 void APatchGUI::synchronize_fade(float value_change)
170 if(fade && !change_source)
172 fade->update(fade->get_value() + value_change);
179 AFadePatch::AFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y, int w)
186 (float)MAX_AUDIO_FADE,
187 get_keyframe(mwindow, patch)->value)
189 //printf("AFadePatch::AFadePatch 1 %p %f\n", patch->track, get_keyframe(mwindow, patch)->value);
190 //printf("AFadePatch::AFadePatch 2 %f\n", ((FloatAuto*)patch->track->automation->fade_autos->first)->value);
191 this->mwindow = mwindow;
195 float AFadePatch::update_edl()
198 double position = mwindow->edl->local_session->selectionstart;
199 Autos *fade_autos = patch->atrack->automation->fade_autos;
200 int update_undo = !fade_autos->auto_exists_for_editing(position);
202 //printf("AFadePatch::update_edl 1 %d\n", update_undo);
204 mwindow->undo->update_undo_before(_("fade"), LOAD_AUTOMATION);
206 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
208 float result = get_value() - current->value;
209 current->value = get_value();
212 mwindow->undo->update_undo_after();
218 int AFadePatch::handle_event()
223 set_tooltip(get_caption());
226 patch->change_source = 1;
227 float change = update_edl();
228 if(patch->track->gang)
229 patch->patchbay->synchronize_faders(change, TRACK_AUDIO, patch->track);
230 patch->change_source = 0;
232 mwindow->sync_parameters(CHANGE_PARAMS);
234 if(mwindow->edl->session->auto_conf->fade)
236 mwindow->gui->canvas->draw_overlays();
237 mwindow->gui->canvas->flash();
242 FloatAuto* AFadePatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
245 double unit_position = mwindow->edl->local_session->selectionstart;
246 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
247 unit_position = patch->atrack->to_units(unit_position, 0);
249 return (FloatAuto*)patch->atrack->automation->fade_autos->get_prev_auto(
256 APanPatch::APanPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
261 mwindow->edl->session->audio_channels,
262 mwindow->edl->session->achannel_positions,
263 get_keyframe(mwindow, patch)->handle_x,
264 get_keyframe(mwindow, patch)->handle_y,
265 get_keyframe(mwindow, patch)->values)
267 this->mwindow = mwindow;
269 //printf("APanPatch::APanPatch %d %d\n", get_keyframe(mwindow, patch)->handle_x, get_keyframe(mwindow, patch)->handle_y);
272 int APanPatch::handle_event()
275 double position = mwindow->edl->local_session->selectionstart;
276 Autos *pan_autos = patch->atrack->automation->pan_autos;
277 int update_undo = !pan_autos->auto_exists_for_editing(position);
280 mwindow->undo->update_undo_before(_("pan"), LOAD_AUTOMATION);
282 current = (PanAuto*)pan_autos->get_auto_for_editing(position);
284 current->handle_x = get_stick_x();
285 current->handle_y = get_stick_y();
286 memcpy(current->values, get_values(), sizeof(float) * mwindow->edl->session->audio_channels);
289 mwindow->undo->update_undo_after();
291 mwindow->sync_parameters(CHANGE_PARAMS);
293 if(update_undo && mwindow->edl->session->auto_conf->pan)
295 mwindow->gui->canvas->draw_overlays();
296 mwindow->gui->canvas->flash();
301 PanAuto* APanPatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
304 double unit_position = mwindow->edl->local_session->selectionstart;
305 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
306 unit_position = patch->atrack->to_units(unit_position, 0);
308 return (PanAuto*)patch->atrack->automation->pan_autos->get_prev_auto(
317 AMeterPatch::AMeterPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
321 patch->patchbay->get_w() - 10,
322 mwindow->edl->session->min_meter_db,
323 mwindow->edl->session->meter_format,
325 mwindow->edl->session->record_speed * 10,
326 mwindow->edl->session->record_speed)
328 this->mwindow = mwindow;
332 int AMeterPatch::button_press_event()
334 if(cursor_inside() && is_event_win() && get_buttonpress() == 1)
336 mwindow->reset_meters();