| 18 | |
| 19 | namespace { |
| 20 | std::vector<std::shared_ptr<EffectInstance>> MakeInstances( |
| 21 | const EffectStage::Factory& factory, EffectSettings& settings, |
| 22 | double sampleRate, std::optional<sampleCount> genLength, int channel, |
| 23 | int nInputChannels) |
| 24 | { |
| 25 | std::vector<std::shared_ptr<EffectInstance>> instances; |
| 26 | // Make as many instances as needed for the channels of the source, which |
| 27 | // depends on how the instances report how many channels they accept |
| 28 | const auto nChannels = (channel < 0) ? nInputChannels : 1; |
| 29 | for (size_t ii = 0; ii < nChannels;) |
| 30 | { |
| 31 | auto pInstance = factory(); |
| 32 | if (!pInstance) |
| 33 | // A constructor that can't satisfy its post should throw instead |
| 34 | throw std::exception{}; |
| 35 | auto count = pInstance->GetAudioInCount(); |
| 36 | ChannelName map[3]{ ChannelNameEOL, ChannelNameEOL, ChannelNameEOL }; |
| 37 | MakeChannelMap(nInputChannels, channel, map); |
| 38 | // Give the plugin a chance to initialize |
| 39 | if (!pInstance->ProcessInitialize(settings, sampleRate, map)) |
| 40 | throw std::exception{}; |
| 41 | instances.resize(ii); |
| 42 | |
| 43 | // Beware generators with zero in count |
| 44 | if (genLength) |
| 45 | count = nChannels; |
| 46 | |
| 47 | instances.push_back(move(pInstance)); |
| 48 | |
| 49 | // Advance ii |
| 50 | if (count == 0) |
| 51 | // What? Can't make progress |
| 52 | throw std::exception(); |
| 53 | ii += count; |
| 54 | } |
| 55 | return instances; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | EffectStage::EffectStage( |
no test coverage detected