OSCReceiverWrapper.cpp 5.7 KB

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