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(value);
00103 }
00104 }
00105 else
00106 if(h - y1 >= mwindow->theme->fade_h)
00107 {
00108 patchbay->add_subwindow(fade = new AFadePatch(mwindow,
00109 this,
00110 x1 + x,
00111 y1 + y,
00112 patchbay->get_w() - 10));
00113 }
00114 y1 += mwindow->theme->fade_h;
00115
00116 if(meter)
00117 {
00118 if(h - y1 < mwindow->theme->meter_h)
00119 {
00120 delete meter;
00121 meter = 0;
00122 }
00123 }
00124 else
00125 if(h - y1 >= mwindow->theme->meter_h)
00126 {
00127 patchbay->add_subwindow(meter = new AMeterPatch(mwindow,
00128 this,
00129 x1 + x,
00130 y1 + y));
00131 }
00132 y1 += mwindow->theme->meter_h;
00133 x1 += 10;
00134
00135 if(pan)
00136 {
00137 if(h - y1 < mwindow->theme->pan_h)
00138 {
00139 delete pan;
00140 pan = 0;
00141 delete nudge;
00142 nudge = 0;
00143 }
00144 else
00145 {
00146 if(pan->get_total_values() != mwindow->edl->session->audio_channels)
00147 {
00148 pan->change_channels(mwindow->edl->session->audio_channels,
00149 mwindow->edl->session->achannel_positions);
00150 }
00151 else
00152 {
00153 int handle_x, handle_y;
00154 PanAuto *previous = 0, *next = 0;
00155 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
00156 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
00157 unit_position = atrack->to_units(unit_position, 0);
00158 PanAutos *ptr = (PanAutos*)atrack->automation->autos[AUTOMATION_PAN];
00159 ptr->get_handle(handle_x,
00160 handle_y,
00161 (long)unit_position,
00162 PLAY_FORWARD,
00163 previous,
00164 next);
00165 pan->update(handle_x, handle_y);
00166 }
00167 nudge->update();
00168 }
00169 }
00170 else
00171 if(h - y1 >= mwindow->theme->pan_h)
00172 {
00173 patchbay->add_subwindow(pan = new APanPatch(mwindow,
00174 this,
00175 x1 + x,
00176 y1 + y));
00177 x1 += pan->get_w() + 10;
00178 patchbay->add_subwindow(nudge = new NudgePatch(mwindow,
00179 this,
00180 x1 + x,
00181 y1 + y,
00182 patchbay->get_w() - x1 - 10));
00183 }
00184 y1 += mwindow->theme->pan_h;
00185
00186 return y1;
00187 }
00188
00189 void APatchGUI::synchronize_fade(float value_change)
00190 {
00191 if(fade && !change_source)
00192 {
00193 fade->update(fade->get_value() + value_change);
00194 fade->update_edl();
00195 }
00196 }
00197
00198
00199
00200 AFadePatch::AFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y, int w)
00201 : BC_FSlider(x,
00202 y,
00203 0,
00204 w,
00205 w,
00206 (float)INFINITYGAIN,
00207 (float)MAX_AUDIO_FADE,
00208 get_keyframe(mwindow, patch)->value)
00209 {
00210 this->mwindow = mwindow;
00211 this->patch = patch;
00212 }
00213
00214 float AFadePatch::update_edl()
00215 {
00216 FloatAuto *current;
00217 double position = mwindow->edl->local_session->get_selectionstart(1);
00218 Autos *fade_autos = patch->atrack->automation->autos[AUTOMATION_FADE];
00219 int need_undo = !fade_autos->auto_exists_for_editing(position);
00220
00221 current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
00222
00223 float result = get_value() - current->value;
00224 current->value = get_value();
00225
00226 mwindow->undo->update_undo(_("fade"),
00227 LOAD_AUTOMATION,
00228 need_undo ? 0 : this);
00229
00230 return result;
00231 }
00232
00233
00234 int AFadePatch::handle_event()
00235 {
00236 if(shift_down())
00237 {
00238 update(0.0);
00239 set_tooltip(get_caption());
00240 }
00241
00242 patch->change_source = 1;
00243 float change = update_edl();
00244 if(patch->track->gang)
00245 patch->patchbay->synchronize_faders(change, TRACK_AUDIO, patch->track);
00246 patch->change_source = 0;
00247
00248 mwindow->sync_parameters(CHANGE_PARAMS);
00249
00250 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE])
00251 {
00252 mwindow->gui->canvas->draw_overlays();
00253 mwindow->gui->canvas->flash();
00254 }
00255 return 1;
00256 }
00257
00258 FloatAuto* AFadePatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
00259 {
00260 Auto *current = 0;
00261 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
00262 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
00263 unit_position = patch->atrack->to_units(unit_position, 0);
00264
00265 FloatAutos *ptr = (FloatAutos*)patch->atrack->automation->autos[AUTOMATION_FADE];
00266 return (FloatAuto*)ptr->get_prev_auto(
00267 (long)unit_position,
00268 PLAY_FORWARD,
00269 current);
00270 }
00271
00272
00273 APanPatch::APanPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
00274 : BC_Pan(x,
00275 y,
00276 PAN_RADIUS,
00277 1,
00278 mwindow->edl->session->audio_channels,
00279 mwindow->edl->session->achannel_positions,
00280 get_keyframe(mwindow, patch)->handle_x,
00281 get_keyframe(mwindow, patch)->handle_y,
00282 get_keyframe(mwindow, patch)->values)
00283 {
00284 this->mwindow = mwindow;
00285 this->patch = patch;
00286 set_tooltip("Pan");
00287 }
00288
00289 int APanPatch::handle_event()
00290 {
00291 PanAuto *current;
00292 double position = mwindow->edl->local_session->get_selectionstart(1);
00293 Autos *pan_autos = patch->atrack->automation->autos[AUTOMATION_PAN];
00294 int need_undo = !pan_autos->auto_exists_for_editing(position);
00295
00296 current = (PanAuto*)pan_autos->get_auto_for_editing(position);
00297
00298 current->handle_x = get_stick_x();
00299 current->handle_y = get_stick_y();
00300 memcpy(current->values, get_values(), sizeof(float) * mwindow->edl->session->audio_channels);
00301
00302 mwindow->undo->update_undo(_("pan"), LOAD_AUTOMATION, need_undo ? 0 : this);
00303
00304 mwindow->sync_parameters(CHANGE_PARAMS);
00305
00306 if(need_undo && mwindow->edl->session->auto_conf->autos[AUTOMATION_PAN])
00307 {
00308 mwindow->gui->canvas->draw_overlays();
00309 mwindow->gui->canvas->flash();
00310 }
00311 return 1;
00312 }
00313
00314 PanAuto* APanPatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
00315 {
00316 Auto *current = 0;
00317 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
00318 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
00319 unit_position = patch->atrack->to_units(unit_position, 0);
00320
00321 PanAutos *ptr = (PanAutos*)patch->atrack->automation->autos[AUTOMATION_PAN];
00322 return (PanAuto*)ptr->get_prev_auto(
00323 (long)unit_position,
00324 PLAY_FORWARD,
00325 current);
00326 }
00327
00328
00329
00330
00331 AMeterPatch::AMeterPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
00332 : BC_Meter(x,
00333 y,
00334 METER_HORIZ,
00335 patch->patchbay->get_w() - 10,
00336 mwindow->edl->session->min_meter_db,
00337 mwindow->edl->session->max_meter_db,
00338 mwindow->edl->session->meter_format,
00339 0,
00340 TRACKING_RATE * 10,
00341 TRACKING_RATE)
00342 {
00343 this->mwindow = mwindow;
00344 this->patch = patch;
00345 }
00346
00347 int AMeterPatch::button_press_event()
00348 {
00349 if(cursor_inside() && is_event_win() && get_buttonpress() == 1)
00350 {
00351 mwindow->reset_meters();
00352 return 1;
00353 }
00354
00355 return 0;
00356 }
00357
00358
00359
00360
00361