00001 #include "apatchgui.h"
00002 #include "apatchgui.inc"
00003 #include "atrack.h"
00004 #include "autoconf.h"
00005 #include "automation.h"
00006 #include "edl.h"
00007 #include "edlsession.h"
00008 #include "floatauto.h"
00009 #include "floatautos.h"
00010 #include "language.h"
00011 #include "localsession.h"
00012 #include "mainundo.h"
00013 #include "mwindow.h"
00014 #include "mwindowgui.h"
00015 #include "panauto.h"
00016 #include "panautos.h"
00017 #include "patchbay.h"
00018 #include "theme.h"
00019 #include "trackcanvas.h"
00020
00021
00022
00023
00024 APatchGUI::APatchGUI(MWindow *mwindow,
00025 PatchBay *patchbay,
00026 ATrack *track,
00027 int x,
00028 int y)
00029 : PatchGUI(mwindow,
00030 patchbay,
00031 track,
00032 x,
00033 y)
00034 {
00035 data_type = TRACK_AUDIO;
00036 this->atrack = track;
00037 meter = 0;
00038 pan = 0;
00039 fade = 0;
00040 }
00041 APatchGUI::~APatchGUI()
00042 {
00043 if(fade) delete fade;
00044 if(meter) delete meter;
00045 if(pan) delete pan;
00046 }
00047
00048 int APatchGUI::create_objects()
00049 {
00050 return update(x, y);
00051 }
00052
00053 int APatchGUI::reposition(int x, int y)
00054 {
00055 int x1 = 0;
00056 int y1 = PatchGUI::reposition(x, y);
00057
00058 if(fade) fade->reposition_window(fade->get_x(),
00059 y1 + y);
00060 y1 += mwindow->theme->fade_h;
00061
00062 if(meter) meter->reposition_window(meter->get_x(),
00063 y1 + y,
00064 meter->get_w());
00065 y1 += mwindow->theme->meter_h;
00066
00067 if(pan) pan->reposition_window(pan->get_x(),
00068 y1 + y);
00069
00070 if(nudge) nudge->reposition_window(nudge->get_x(),
00071 y1 + y);
00072
00073 y1 += mwindow->theme->pan_h;
00074 return y1;
00075 }
00076
00077 int APatchGUI::update(int x, int y)
00078 {
00079 int h = track->vertical_span(mwindow->theme);
00080 int x1 = 0;
00081 int y1 = PatchGUI::update(x, y);
00082
00083 if(fade)
00084 {
00085 if(h - y1 < mwindow->theme->fade_h)
00086 {
00087 delete fade;
00088 fade = 0;
00089 }
00090 else
00091 {
00092 FloatAuto *previous = 0, *next = 0;
00093 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
00094 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
00095 unit_position = atrack->to_units(unit_position, 0);
00096 FloatAutos *ptr = (FloatAutos*)atrack->automation->autos[AUTOMATION_FADE];
00097 float value = ptr->get_value(
00098 (long)unit_position,
00099 PLAY_FORWARD,
00100 previous,
00101 next);
00102 fade->update(fade->get_w(),
00103 value,
00104 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
00105 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE]);
00106 }
00107 }
00108 else
00109 if(h - y1 >= mwindow->theme->fade_h)
00110 {
00111 patchbay->add_subwindow(fade = new AFadePatch(mwindow,
00112 this,
00113 x1 + x,
00114 y1 + y,
00115 patchbay->get_w() - 10));
00116 }
00117 y1 += mwindow->theme->fade_h;
00118
00119 if(meter)
00120 {
00121 if(h - y1 < mwindow->theme->meter_h)
00122 {
00123 delete meter;
00124 meter = 0;
00125 }
00126 }
00127 else
00128 if(h - y1 >= mwindow->theme->meter_h)
00129 {
00130 patchbay->add_subwindow(meter = new AMeterPatch(mwindow,
00131 this,
00132 x1 + x,
00133 y1 + y));
00134 }
00135 y1 += mwindow->theme->meter_h;
00136 x1 += 10;
00137
00138 if(pan)
00139 {
00140 if(h - y1 < mwindow->theme->pan_h)
00141 {
00142 delete pan;
00143 pan = 0;
00144 delete nudge;
00145 nudge = 0;
00146 }
00147 else
00148 {
00149 if(pan->get_total_values() != mwindow->edl->session->audio_channels)
00150 {
00151 pan->change_channels(mwindow->edl->session->audio_channels,
00152 mwindow->edl->session->achannel_positions);
00153 }
00154 else
00155 {
00156 int handle_x, handle_y;
00157 PanAuto *previous = 0, *next = 0;
00158 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
00159 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
00160 unit_position = atrack->to_units(unit_position, 0);
00161 PanAutos *ptr = (PanAutos*)atrack->automation->autos[AUTOMATION_PAN];
00162 ptr->get_handle(handle_x,
00163 handle_y,
00164 (long)unit_position,
00165 PLAY_FORWARD,
00166 previous,
00167 next);
00168 pan->update(handle_x, handle_y);
00169 }
00170 nudge->update();
00171 }
00172 }
00173 else
00174 if(h - y1 >= mwindow->theme->pan_h)
00175 {
00176 patchbay->add_subwindow(pan = new APanPatch(mwindow,
00177 this,
00178 x1 + x,
00179 y1 + y));
00180 x1 += pan->get_w() + 10;
00181 patchbay->add_subwindow(nudge = new NudgePatch(mwindow,
00182 this,
00183 x1 + x,
00184 y1 + y,
00185 patchbay->get_w() - x1 - 10));
00186 }
00187 y1 += mwindow->theme->pan_h;
00188
00189 return y1;
00190 }
00191
00192 void APatchGUI::synchronize_fade(float value_change)
00193 {
00194 if(fade && !change_source)
00195 {
00196 fade->update(fade->get_value() + value_change);
00197 fade->update_edl();
00198 }
00199 }
00200
00201
00202
00203 AFadePatch::AFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y, int w)
00204 : BC_FSlider(x,
00205 y,
00206 0,
00207 w,
00208 w,
00209 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
00210 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE],
00211 get_keyframe(mwindow, patch)->value)
00212 {
00213 this->mwindow = mwindow;
00214 this->patch = patch;
00215 }
00216
00217 float AFadePatch::update_edl()
00218 {
00219 FloatAuto *current;
00220 double position = mwindow->edl->local_session->get_selectionstart(1);
00221 Autos *fade_autos = patch->atrack->automation->autos[AUTOMATION_FADE];
00222 int need_undo = !fade_autos->auto_exists_for_editing(position);
00223
00224 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
00225
00226 float result = get_value() - current->value;
00227 current->value = get_value();
00228
00229 mwindow->undo->update_undo(_("fade"),
00230 LOAD_AUTOMATION,
00231 need_undo ? 0 : this);
00232
00233 return result;
00234 }
00235
00236
00237 int AFadePatch::handle_event()
00238 {
00239 if(shift_down())
00240 {
00241 update(0.0);
00242 set_tooltip(get_caption());
00243 }
00244
00245 patch->change_source = 1;
00246 float change = update_edl();
00247 if(patch->track->gang)
00248 patch->patchbay->synchronize_faders(change, TRACK_AUDIO, patch->track);
00249 patch->change_source = 0;
00250
00251 mwindow->sync_parameters(CHANGE_PARAMS);
00252
00253 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE])
00254 {
00255 mwindow->gui->canvas->draw_overlays();
00256 mwindow->gui->canvas->flash();
00257 }
00258 return 1;
00259 }
00260
00261 FloatAuto* AFadePatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
00262 {
00263 Auto *current = 0;
00264 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
00265 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
00266 unit_position = patch->atrack->to_units(unit_position, 0);
00267
00268 FloatAutos *ptr = (FloatAutos*)patch->atrack->automation->autos[AUTOMATION_FADE];
00269 return (FloatAuto*)ptr->get_prev_auto(
00270 (long)unit_position,
00271 PLAY_FORWARD,
00272 current);
00273 }
00274
00275
00276 APanPatch::APanPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
00277 : BC_Pan(x,
00278 y,
00279 PAN_RADIUS,
00280 MAX_PAN,
00281 mwindow->edl->session->audio_channels,
00282 mwindow->edl->session->achannel_positions,
00283 get_keyframe(mwindow, patch)->handle_x,
00284 get_keyframe(mwindow, patch)->handle_y,
00285 get_keyframe(mwindow, patch)->values)
00286 {
00287 this->mwindow = mwindow;
00288 this->patch = patch;
00289 set_tooltip("Pan");
00290 }
00291
00292 int APanPatch::handle_event()
00293 {
00294 PanAuto *current;
00295 double position = mwindow->edl->local_session->get_selectionstart(1);
00296 Autos *pan_autos = patch->atrack->automation->autos[AUTOMATION_PAN];
00297 int need_undo = !pan_autos->auto_exists_for_editing(position);
00298
00299 current = (PanAuto*)pan_autos->get_auto_for_editing(position);
00300
00301 current->handle_x = get_stick_x();
00302 current->handle_y = get_stick_y();
00303 memcpy(current->values, get_values(), sizeof(float) * mwindow->edl->session->audio_channels);
00304
00305 mwindow->undo->update_undo(_("pan"), LOAD_AUTOMATION, need_undo ? 0 : this);
00306
00307 mwindow->sync_parameters(CHANGE_PARAMS);
00308
00309 if(need_undo && mwindow->edl->session->auto_conf->autos[AUTOMATION_PAN])
00310 {
00311 mwindow->gui->canvas->draw_overlays();
00312 mwindow->gui->canvas->flash();
00313 }
00314 return 1;
00315 }
00316
00317 PanAuto* APanPatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
00318 {
00319 Auto *current = 0;
00320 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
00321 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
00322 unit_position = patch->atrack->to_units(unit_position, 0);
00323
00324 PanAutos *ptr = (PanAutos*)patch->atrack->automation->autos[AUTOMATION_PAN];
00325 return (PanAuto*)ptr->get_prev_auto(
00326 (long)unit_position,
00327 PLAY_FORWARD,
00328 current);
00329 }
00330
00331
00332
00333
00334 AMeterPatch::AMeterPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
00335 : BC_Meter(x,
00336 y,
00337 METER_HORIZ,
00338 patch->patchbay->get_w() - 10,
00339 mwindow->edl->session->min_meter_db,
00340 mwindow->edl->session->max_meter_db,
00341 mwindow->edl->session->meter_format,
00342 0,
00343 TRACKING_RATE * 10,
00344 TRACKING_RATE)
00345 {
00346 this->mwindow = mwindow;
00347 this->patch = patch;
00348 }
00349
00350 int AMeterPatch::button_press_event()
00351 {
00352 if(cursor_inside() && is_event_win() && get_buttonpress() == 1)
00353 {
00354 mwindow->reset_meters();
00355 return 1;
00356 }
00357
00358 return 0;
00359 }
00360
00361
00362
00363
00364