| 58 | } |
| 59 | |
| 60 | bool PluginProcessor::loadPlugin(double sampleRate, int samplesPerBlock) { |
| 61 | OwnedArray<PluginDescription> pluginDescriptions; |
| 62 | KnownPluginList pluginList; |
| 63 | AudioPluginFormatManager pluginFormatManager; |
| 64 | |
| 65 | pluginFormatManager.addDefaultFormats(); |
| 66 | |
| 67 | for (int i = pluginFormatManager.getNumFormats(); --i >= 0;) { |
| 68 | pluginList.scanAndAddFile(String(myPluginPath), true, pluginDescriptions, |
| 69 | *pluginFormatManager.getFormat(i)); |
| 70 | } |
| 71 | |
| 72 | if (myPlugin.get()) { |
| 73 | myPlugin.get()->releaseResources(); |
| 74 | myPlugin.reset(); |
| 75 | } |
| 76 | |
| 77 | // If there is a problem here first check the preprocessor definitions |
| 78 | // in the projucer are sensible - is it set up to scan for plugin's? |
| 79 | if (pluginDescriptions.size() <= 0) { |
| 80 | throw std::runtime_error("Unable to load plugin."); |
| 81 | } |
| 82 | |
| 83 | String errorMessage; |
| 84 | |
| 85 | myPlugin = pluginFormatManager.createPluginInstance( |
| 86 | *pluginDescriptions[0], sampleRate, samplesPerBlock, errorMessage); |
| 87 | |
| 88 | if (myPlugin.get() == nullptr) { |
| 89 | throw std::runtime_error("PluginProcessor::loadPlugin error: " + |
| 90 | errorMessage.toStdString()); |
| 91 | } |
| 92 | // We loaded the plugin. |
| 93 | |
| 94 | auto outputs = myPlugin->getTotalNumOutputChannels(); |
| 95 | |
| 96 | if (outputs == 0) { |
| 97 | myPlugin->enableAllBuses(); |
| 98 | myPlugin->disableNonMainBuses(); |
| 99 | outputs = myPlugin->getTotalNumOutputChannels(); |
| 100 | } |
| 101 | auto inputs = myPlugin->getTotalNumInputChannels(); |
| 102 | |
| 103 | ProcessorBase::setBusesLayout(myPlugin->getBusesLayout()); |
| 104 | |
| 105 | this->setPlayConfigDetails(inputs, outputs, sampleRate, samplesPerBlock); |
| 106 | myPlugin->prepareToPlay(sampleRate, samplesPerBlock); |
| 107 | myPlugin->setNonRealtime(true); |
| 108 | mySampleRate = sampleRate; |
| 109 | |
| 110 | createParameterLayout(); |
| 111 | |
| 112 | { |
| 113 | // Process a block of silence a few times to "warm up" the processor. |
| 114 | juce::AudioSampleBuffer audioBuffer = |
| 115 | AudioSampleBuffer(std::max(inputs, outputs), samplesPerBlock); |
| 116 | MidiBuffer emptyMidiBuffer; |
| 117 | for (int i = 0; i < 5; i++) { |
nothing calls this directly
no test coverage detected