| 22 | #include "WaveTrack.h" |
| 23 | |
| 24 | void EffectPreview(EffectBase &effect, |
| 25 | EffectSettingsAccess &access, std::function<void()> updateUI, bool dryOnly) |
| 26 | { |
| 27 | auto cleanup0 = effect.BeginPreview(access.Get()); |
| 28 | |
| 29 | // These are temporary state in the Effect object that are meant be moved to |
| 30 | // a new class EffectContext |
| 31 | const auto numTracks = effect.mNumTracks; |
| 32 | const auto rate = effect.mProjectRate; |
| 33 | const auto &factory = effect.mFactory; |
| 34 | auto &mT0 = effect.mT0; |
| 35 | auto &mT1 = effect.mT1; |
| 36 | auto &mTracks = effect.mTracks; |
| 37 | auto &mProgress = effect.mProgress; |
| 38 | auto &mIsPreview = effect.mIsPreview; |
| 39 | |
| 40 | // Get certain immutable properties of the effect |
| 41 | const auto previewFullSelection = effect.PreviewsFullSelection(); |
| 42 | const auto isLinearEffect = effect.IsLinearEffect(); |
| 43 | |
| 44 | if (numTracks == 0) { // nothing to preview |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | auto gAudioIO = AudioIO::Get(); |
| 49 | if (gAudioIO->IsBusy()) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | const auto FocusDialog = BasicUI::FindFocus(); |
| 54 | assert(FocusDialog); // postcondition |
| 55 | |
| 56 | double previewDuration; |
| 57 | bool isNyquist = effect.GetFamily() == NYQUISTEFFECTS_FAMILY; |
| 58 | bool isGenerator = effect.GetType() == EffectTypeGenerate; |
| 59 | |
| 60 | // Mix a few seconds of audio from all of the tracks |
| 61 | double previewLen; |
| 62 | gPrefs->Read(wxT("/AudioIO/EffectsPreviewLen"), &previewLen, 6.0); |
| 63 | |
| 64 | const auto &settings = access.Get(); |
| 65 | if (isNyquist && isGenerator) |
| 66 | previewDuration = effect.CalcPreviewInputLength(settings, previewLen); |
| 67 | else |
| 68 | previewDuration = std::min(settings.extra.GetDuration(), |
| 69 | effect.CalcPreviewInputLength(settings, previewLen)); |
| 70 | |
| 71 | double t1 = mT0 + previewDuration; |
| 72 | |
| 73 | if ((t1 > mT1) && !isGenerator) { |
| 74 | t1 = mT1; |
| 75 | } |
| 76 | |
| 77 | if (t1 <= mT0) |
| 78 | return; |
| 79 | |
| 80 | bool success = true; |
| 81 |
no test coverage detected