/* ============================================================================== OSCReceiverWrapper.cpp Created: 5 May 2025 2:34:15pm Author: Luigi ============================================================================== */ #include "OSCReceiverWrapper.h" #include OSCReceiverWrapper::OSCReceiverWrapper(int port, juce::AudioProcessor* pluginProcessor) { this->pluginProcessor = (CMLSProjectAudioProcessor*)pluginProcessor; if (!this->connect(port)) { this->oscConnectionError(); } // Declaring the listeners for the iDraw OSC paths addListener(this, "/r"); addListener(this, "/g"); addListener(this, "/b"); addListener(this, "/a"); addListener(this, "/pen"); addListener(this, "/pencil"); addListener(this, "/marker"); addListener(this, "/monoline"); addListener(this, "/crayon"); addListener(this, "/fountainPen"); addListener(this, "/waterColor"); addListener(this, "/bitmapEraser"); addListener(this, "/vectorEraser"); addListener(this, "/canvasWidth"); addListener(this, "/canvasHeight"); addListener(this, "/drawingWidth"); addListener(this, "/eraserWidth"); addListener(this, "/x"); addListener(this, "/y"); addListener(this, "/pressure"); addListener(this, "/aspectX"); addListener(this, "/aspectY"); std::string test = "Connection opened\n"; OutputDebugString(test.c_str()); } OSCReceiverWrapper::~OSCReceiverWrapper() {} void OSCReceiverWrapper::oscMessageReceived(const juce::OSCMessage& message) { std::string debugString = "=== OSC Message at address: " + message.getAddressPattern().toString().toStdString() + " ===\n"; OutputDebugString(debugString.c_str()); if (!message.isEmpty() && message.size() == 1) { auto address = message.getAddressPattern().toString(); float argument = 0.0; try { argument = message[0].getFloat32(); } catch (const std::exception e) { return; // Bypass packet intepretation because the argument is not a float } if (address == "/r") { // Unused } else if (address == "/g") { // Unused } else if (address == "/b") { // Unused } else if (address == "a") { // Unused } // Pen types are used to manage the presets else if (address == "/pen") { // Unused } else if (address == "/pencil" && argument == 1.0) { this->currentPreset = Preset::PENCIL; } else if (address == "/marker") { // Unused } else if (address == "/monoline") { // Unused } else if (address == "/crayon" && argument == 1.0) { this->currentPreset = Preset::CRAYON; } else if (address == "/fountainPen") { // Preset #3 } else if (address == "/waterColor" && argument == 1.0) { this->currentPreset = Preset::WATERCOLOR; } else if (address == "/bitmapEraser") { } else if (address == "/vectorEraser") { } else if (address == "/canvasWidth") { } else if (address == "/canvasHeight") { } else if (address == "/drawingWidth") { this->thickness = argument; } else if (address == "/eraserWidth") { } // Value assignment else if (address == "/x") { } else if (address == "/y") { } else if (address == "/pressure") { } else if (address == "/aspectX") { this->aspectX = argument; this->processMessage(); } else if (address == "/aspectY") { this->aspectY = argument; this->processMessage(); } } } void OSCReceiverWrapper::oscConnectionError() { return; } void OSCReceiverWrapper::processMessage() { if (this->currentPreset == Preset::PENCIL) { this->pluginProcessor->setReverbRoomSize(this->aspectY + 0.5); } else if (this->currentPreset == Preset::CRAYON) { this->pluginProcessor->setDelayAmount(this->aspectX + 0.5); this->pluginProcessor->setReverbDryWet(this->aspectY + 0.5); } else if (this->currentPreset == Preset::WATERCOLOR) { // Changing parameters of single effects if (this->thickness <= 6) { //EQ this->pluginProcessor->setEqLowGain(this->aspectX + 0.5); this->pluginProcessor->setEqHighGain(this->aspectY + 0.5); } else if (this->thickness <= 12) { // Dist this->pluginProcessor->setDistortionDrive(this->aspectY + 0.5); this->pluginProcessor->setDistortionMix(this->aspectX + 0.5); } else if (this->thickness <= 18) { // Chorus this->pluginProcessor->setChorusAmount(this->aspectY + 0.5); this->pluginProcessor->setChorusDryWet(this->aspectX + 0.5); } else if (this->thickness <= 24) { // Reverb this->pluginProcessor->setReverbRoomSize(this->aspectY + 0.5); this->pluginProcessor->setReverbDryWet(this->aspectX + 0.5); } else if (this->thickness <= 30) { //Delay this->pluginProcessor->setDelayAmount(this->aspectY + 0.5); this->pluginProcessor->setDelayDryWet(this->aspectX + 0.5); } } }