Download Source/PluginBridgeProcessor.cpp from RAM2118/pluginbridge: direct link, hf CLI and curl.
- Browser
- Download file 4.55 kB
-
https://huggingface.co/RAM2118/pluginbridge/resolve/2a2323c4e0bcc2fddce057b14befade0a0eccc39/Source/PluginBridgeProcessor.cpp
- Command line
-
hf download hf://RAM2118/pluginbridge@2a2323c4e0bcc2fddce057b14befade0a0eccc39/Source/PluginBridgeProcessor.cpp
-
curl -L -o PluginBridgeProcessor.cpp https://huggingface.co/RAM2118/pluginbridge/resolve/2a2323c4e0bcc2fddce057b14befade0a0eccc39/Source/PluginBridgeProcessor.cpp
4.55 kB
| PluginBridgeProcessor::PluginBridgeProcessor() | |
| : AudioProcessor(BusesProperties() | |
| .withInput("Input", juce::AudioChannelSet::stereo(), true) | |
| .withOutput("Output", juce::AudioChannelSet::stereo(), true)), | |
| mcpServer(kDefaultMcpPort, hostManager) | |
| { | |
| mcpServer.start(); | |
| } | |
| PluginBridgeProcessor::~PluginBridgeProcessor() | |
| { | |
| mcpServer.stop(); | |
| stopTimer(); | |
| } | |
| void PluginBridgeProcessor::prepareToPlay(double sampleRate, int samplesPerBlock) | |
| { | |
| hostManager.prepareToPlay(sampleRate, samplesPerBlock); | |
| } | |
| void PluginBridgeProcessor::releaseResources() | |
| { | |
| hostManager.releaseResources(); | |
| } | |
| void PluginBridgeProcessor::processBlock(juce::AudioBuffer<float>& buffer, | |
| juce::MidiBuffer& midiMessages) | |
| { | |
| juce::ScopedNoDenormals noDenormals; | |
| auto totalNumInputChannels = getTotalNumInputChannels(); | |
| auto totalNumOutputChannels = getTotalNumOutputChannels(); | |
| for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i) | |
| buffer.clear(i, 0, buffer.getNumSamples()); | |
| hostManager.processBlock(buffer, midiMessages); | |
| } | |
| juce::AudioProcessorEditor* PluginBridgeProcessor::createEditor() | |
| { | |
| return new PluginBridgeEditor(*this); | |
| } | |
| void PluginBridgeProcessor::getStateInformation(juce::MemoryBlock& destData) | |
| { | |
| juce::ValueTree state("PluginBridgeState"); | |
| state.setProperty("hostedPluginPath", hostManager.getLoadedPluginPath(), nullptr); | |
| juce::MemoryOutputStream stream(destData, false); | |
| state.writeToStream(stream); | |
| } | |
| void PluginBridgeProcessor::setStateInformation(const void* data, int sizeInBytes) | |
| { | |
| auto state = juce::ValueTree::readFromData(data, (size_t)sizeInBytes); | |
| if (state.isValid()) | |
| { | |
| auto path = state.getProperty("hostedPluginPath").toString(); | |
| if (path.isNotEmpty()) | |
| { | |
| juce::File pluginFile(path); | |
| if (pluginFile.exists()) | |
| loadPluginFromFile(pluginFile); | |
| } | |
| } | |
| } | |
| bool PluginBridgeProcessor::isMcpServerRunning() const | |
| { | |
| return mcpServer.isRunning(); | |
| } | |
| int PluginBridgeProcessor::getMcpServerPort() const | |
| { | |
| return mcpServer.getPort(); | |
| } | |
| void PluginBridgeProcessor::loadPluginFromFile(const juce::File& file) | |
| { | |
| hostManager.loadPlugin(file, getSampleRate(), getBlockSize()); | |
| } | |
| void PluginBridgeProcessor::startPluginScan() | |
| { | |
| if (scanning.load() || scanComplete.load()) | |
| return; | |
| scanning.store(true); | |
| // Initialize scanner on message thread | |
| scanFormatManager = std::make_unique<juce::AudioPluginFormatManager>(); | |
| scanFormatManager->addFormat(new juce::VST3PluginFormat()); | |
| scanFormatManager->addFormat(new juce::AudioUnitPluginFormat()); | |
| scanList = std::make_unique<juce::KnownPluginList>(); | |
| // Build file list to scan | |
| for (int i = 0; i < scanFormatManager->getNumFormats(); ++i) | |
| { | |
| auto* format = scanFormatManager->getFormat(i); | |
| auto paths = format->getDefaultLocationsToSearch(); | |
| // Use a temporary scanner just to get the file list | |
| juce::PluginDirectoryScanner tempScanner( | |
| *scanList, *format, paths, true, juce::File()); | |
| // We'll use the scanner directly — start it | |
| scanners.add(new ScannerState{ | |
| std::make_unique<juce::PluginDirectoryScanner>( | |
| *scanList, *format, paths, true, juce::File()), | |
| false | |
| }); | |
| } | |
| currentScannerIndex = 0; | |
| // Use Timer to scan one file per tick on the message thread | |
| startTimerHz(30); // 30 files per second — responsive UI | |
| } | |
| void PluginBridgeProcessor::timerCallback() | |
| { | |
| if (currentScannerIndex >= scanners.size()) | |
| { | |
| // All scanners done | |
| stopTimer(); | |
| scannedPlugins = scanList->getTypes(); | |
| scanning.store(false); | |
| scanComplete.store(true); | |
| scanners.clear(); | |
| scanFormatManager.reset(); | |
| scanList.reset(); | |
| return; | |
| } | |
| auto* state = scanners[currentScannerIndex]; | |
| if (state->done) | |
| { | |
| currentScannerIndex++; | |
| return; | |
| } | |
| juce::String pluginName; | |
| if (!state->scanner->scanNextFile(true, pluginName)) | |
| { | |
| state->done = true; | |
| currentScannerIndex++; | |
| } | |
| } | |
| // JUCE plugin entry point | |
| juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter() | |
| { | |
| return new PluginBridgeProcessor(); | |
| } | |