DISTRHO Juice Plugins
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
4.5KB

  1. /*
  2. * Stutter Juice Plugin
  3. * Copyright (C) 2014 Andre Sklenar <andre.sklenar@gmail.com>, www.juicelab.cz
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "StutterJuicePlugin.hpp"
  18. #include <iostream>
  19. START_NAMESPACE_DISTRHO
  20. // -----------------------------------------------------------------------
  21. StutterJuicePlugin::StutterJuicePlugin()
  22. : Plugin(paramCount, 1, 0) // 1 program, 0 states
  23. {
  24. // set default values
  25. d_setProgram(0);
  26. // reset
  27. d_deactivate();
  28. }
  29. // -----------------------------------------------------------------------
  30. // Init
  31. void StutterJuicePlugin::d_initParameter(uint32_t index, Parameter& parameter)
  32. {
  33. if (index<26) {
  34. parameter.hints = PARAMETER_IS_AUTOMABLE;
  35. parameter.name = "";
  36. parameter.symbol = "";
  37. parameter.unit = "";
  38. parameter.ranges.def = 0.0f;
  39. parameter.ranges.min = 0.0f;
  40. parameter.ranges.max = 1.0f;
  41. } else {
  42. parameter.hints = PARAMETER_IS_OUTPUT;
  43. parameter.name = "";
  44. parameter.symbol = "";
  45. parameter.unit = "";
  46. parameter.ranges.def = 0.0f;
  47. parameter.ranges.min = 0.0f;
  48. parameter.ranges.max = 1.0f;
  49. }
  50. }
  51. void StutterJuicePlugin::d_initProgramName(uint32_t index, d_string& programName)
  52. {
  53. if (index != 0)
  54. return;
  55. programName = "Default";
  56. }
  57. // -----------------------------------------------------------------------
  58. // Internal data
  59. float StutterJuicePlugin::d_getParameterValue(uint32_t index) const
  60. {
  61. if (index<26) {
  62. int module = index/3;
  63. int param = index%3;
  64. return params[module][param];
  65. } else {
  66. return outputParams[index-26];
  67. }
  68. }
  69. void StutterJuicePlugin::d_setParameterValue(uint32_t index, float value)
  70. {
  71. int module = index/3;
  72. int param = index%3;
  73. params[module][param] = value;
  74. modules[module]->setParam(value, param);
  75. if (param ==2) {
  76. //modules[module]->resetSinePos();
  77. }
  78. }
  79. void StutterJuicePlugin::d_setProgram(uint32_t index)
  80. {
  81. if (index != 0)
  82. return;
  83. //default params[][] values
  84. for (int module=0; module<6; module++) {
  85. moduleActive[module] = false;
  86. for (int param=0; param<3; param++) {
  87. params[module][param] = 0.5;
  88. }
  89. }
  90. modules[0] = new CGate();
  91. modules[1] = new CReverse();
  92. modules[2] = new CRepeat();
  93. modules[3] = new CSequence();
  94. modules[4] = new CShift();
  95. modules[5] = new CFilter();
  96. for (int module=0; module<6; module++) {
  97. modules[module]->setSampleRate(d_getSampleRate());
  98. modules[module]->initBuffers();
  99. }
  100. d_activate();
  101. }
  102. // -----------------------------------------------------------------------
  103. // Process
  104. void StutterJuicePlugin::d_activate()
  105. {
  106. }
  107. void StutterJuicePlugin::d_deactivate()
  108. {
  109. }
  110. void StutterJuicePlugin::d_run(const float** inputs, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount)
  111. {
  112. for (uint32_t i; i<frames; i++) {
  113. float audioL = inputs[0][i];
  114. float audioR = inputs[1][i];
  115. rollLFOs();
  116. prepareOutputParams();
  117. for (int i=0; i<6; i++) {
  118. modules[i]->process(audioL, audioR);
  119. }
  120. outputs[0][i] = audioL;
  121. outputs[1][i] = audioR;
  122. }
  123. for (uint32_t i; i<midiEventCount; i++) {
  124. int userNote = 48;//TODO
  125. int range=6;
  126. int mType = midiEvents[i].buf[0] & 0xF0;
  127. int mChan = midiEvents[i].buf[0] & 0x0F;
  128. int mNum = midiEvents[i].buf[1];
  129. if (mNum>=userNote && mNum<userNote+range) {
  130. int module = mNum-userNote;
  131. //printf("note: %i\n", module);
  132. if (mType == 0x90) {
  133. //NOTE ON
  134. moduleActive[module] = true;
  135. modules[module]->activate();
  136. } else if (mType == 0x80) {
  137. //NOTE OFF
  138. moduleActive[module] = false;
  139. modules[module]->deactivate();
  140. }
  141. }
  142. }
  143. }
  144. // -----------------------------------------------------------------------
  145. Plugin* createPlugin()
  146. {
  147. return new StutterJuicePlugin();
  148. }
  149. // -----------------------------------------------------------------------
  150. END_NAMESPACE_DISTRHO