OSCReceiverWrapper.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. ==============================================================================
  3. OSCReceiverWrapper.cpp
  4. Created: 5 May 2025 2:34:15pm
  5. Author: Luigi
  6. ==============================================================================
  7. */
  8. #include "OSCReceiverWrapper.h"
  9. #include <windows.h>
  10. OSCReceiverWrapper::OSCReceiverWrapper(int port, juce::AudioProcessor* pluginProcessor) {
  11. this->pluginProcessor = (CMLSProjectAudioProcessor*)pluginProcessor;
  12. if (!this->connect(port)) {
  13. this->oscConnectionError();
  14. }
  15. // Declaring the listeners for the iDraw OSC paths
  16. addListener(this, "/r");
  17. addListener(this, "/g");
  18. addListener(this, "/b");
  19. addListener(this, "/a");
  20. addListener(this, "/pen");
  21. addListener(this, "/pencil");
  22. addListener(this, "/marker");
  23. addListener(this, "/monoline");
  24. addListener(this, "/crayon");
  25. addListener(this, "/fountainPen");
  26. addListener(this, "/waterColor");
  27. addListener(this, "/bitmapEraser");
  28. addListener(this, "/vectorEraser");
  29. addListener(this, "/canvasWidth");
  30. addListener(this, "/canvasHeight");
  31. addListener(this, "/drawingWidth");
  32. addListener(this, "/eraserWidth");
  33. addListener(this, "/x");
  34. addListener(this, "/y");
  35. addListener(this, "/pressure");
  36. addListener(this, "/aspectX");
  37. addListener(this, "/aspectY");
  38. std::string test = "Connection opened\n";
  39. OutputDebugString(test.c_str());
  40. }
  41. OSCReceiverWrapper::~OSCReceiverWrapper() {}
  42. void OSCReceiverWrapper::oscMessageReceived(const juce::OSCMessage& message)
  43. {
  44. std::string debugString = "=== OSC Message at address: " + message.getAddressPattern().toString().toStdString() + " ===\n";
  45. OutputDebugString(debugString.c_str());
  46. if (!message.isEmpty() && message.size() == 1) {
  47. auto address = message.getAddressPattern().toString();
  48. float argument = 0.0;
  49. try {
  50. argument = message[0].getFloat32();
  51. }
  52. catch (const std::exception e) {
  53. return; // Bypass packet intepretation because the argument is not a float
  54. }
  55. if (address == "/r") {
  56. // Unused
  57. }
  58. else if (address == "/g") {
  59. // Unused
  60. }
  61. else if (address == "/b") {
  62. // Unused
  63. }
  64. else if (address == "a") {
  65. // Unused
  66. }
  67. // Pen types are used to manage the presets
  68. else if (address == "/pen") {
  69. // Unused
  70. }
  71. else if (address == "/pencil" && argument == 1.0) {
  72. this->currentPreset = Preset::PENCIL;
  73. }
  74. else if (address == "/marker") {
  75. // Unused
  76. }
  77. else if (address == "/monoline") {
  78. // Unused
  79. }
  80. else if (address == "/crayon" && argument == 1.0) {
  81. this->currentPreset = Preset::CRAYON;
  82. }
  83. else if (address == "/fountainPen") {
  84. // Preset #3
  85. }
  86. else if (address == "/waterColor" && argument == 1.0) {
  87. this->currentPreset = Preset::WATERCOLOR;
  88. }
  89. else if (address == "/bitmapEraser") {
  90. }
  91. else if (address == "/vectorEraser") {
  92. }
  93. else if (address == "/canvasWidth") {
  94. }
  95. else if (address == "/canvasHeight") {
  96. }
  97. else if (address == "/drawingWidth") {
  98. this->thickness = argument;
  99. }
  100. else if (address == "/eraserWidth") {
  101. }
  102. // Value assignment
  103. else if (address == "/x") {
  104. }
  105. else if (address == "/y") {
  106. }
  107. else if (address == "/pressure") {
  108. }
  109. else if (address == "/aspectX") {
  110. this->aspectX = argument;
  111. this->processMessage();
  112. }
  113. else if (address == "/aspectY") {
  114. this->aspectY = argument;
  115. this->processMessage();
  116. }
  117. }
  118. }
  119. void OSCReceiverWrapper::oscConnectionError() {
  120. return;
  121. }
  122. void OSCReceiverWrapper::processMessage() {
  123. if (this->currentPreset == Preset::PENCIL) {
  124. this->pluginProcessor->setReverbRoomSize(this->aspectY + 0.5);
  125. }
  126. else if (this->currentPreset == Preset::CRAYON) {
  127. this->pluginProcessor->setDelayAmount(this->aspectX + 0.5);
  128. this->pluginProcessor->setReverbDryWet(this->aspectY + 0.5);
  129. }
  130. else if (this->currentPreset == Preset::WATERCOLOR) {
  131. // Changing parameters of single effects
  132. if (this->thickness <= 6) { //EQ
  133. this->pluginProcessor->setEqLowGain(this->aspectX + 0.5);
  134. this->pluginProcessor->setEqHighGain(this->aspectY + 0.5);
  135. }
  136. else if (this->thickness <= 12) { // Dist
  137. this->pluginProcessor->setDistortionDrive(this->aspectY + 0.5);
  138. this->pluginProcessor->setDistortionMix(this->aspectX + 0.5);
  139. }
  140. else if (this->thickness <= 18) { // Chorus
  141. this->pluginProcessor->setChorusAmount(this->aspectY + 0.5);
  142. this->pluginProcessor->setChorusDryWet(this->aspectX + 0.5);
  143. }
  144. else if (this->thickness <= 24) { // Reverb
  145. this->pluginProcessor->setReverbRoomSize(this->aspectY + 0.5);
  146. this->pluginProcessor->setReverbDryWet(this->aspectX + 0.5);
  147. }
  148. else if (this->thickness <= 30) { //Delay
  149. this->pluginProcessor->setDelayAmount(this->aspectY + 0.5);
  150. this->pluginProcessor->setDelayDryWet(this->aspectX + 0.5);
  151. }
  152. }
  153. }