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.

171 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. #ifndef STUTTERJUICEPLUGIN_HPP_INCLUDED
  18. #define STUTTERJUICEPLUGIN_HPP_INCLUDED
  19. #include "DistrhoPlugin.hpp"
  20. #include "CModule.hxx"
  21. START_NAMESPACE_DISTRHO
  22. // -----------------------------------------------------------------------
  23. class StutterJuicePlugin : public Plugin
  24. {
  25. public:
  26. enum Parameters
  27. {
  28. p1 = 0, p2, p3, p4, p5, p6, p7, p8, p9,
  29. p11, p12, p13, p14, p15, p16, p17, p18,
  30. p19, p20, p21, p22, p23, p24, p25, p26,
  31. o1, o2, o3, o4, o5, o6, o7, o8, o9,
  32. paramCount
  33. };
  34. void prepareOutputParams() {
  35. for (int i=0; i<6; i++) {
  36. if (modules[i]->isActive()) {
  37. outputParams[i] = modules[i]->getOutputParam();
  38. } else {
  39. outputParams[i] = 0;
  40. }
  41. }
  42. }
  43. void rollLFOs() {
  44. float bar, tick, tickOffset, sinePos, percentage;
  45. for (int i=0; i<6; i++) {
  46. sinePos = modules[i]->getSinePos();
  47. float tempoDivider = modules[i]->getTempoDivider();
  48. //if (i==4)
  49. //printf("divider: %i\n", tempoDivider);
  50. /* sample count for one bar */
  51. const TimePos& time = d_getTimePos();
  52. bar = ((120.0/(time.bbt.valid ? time.bbt.beatsPerMinute : 120.0))*(d_getSampleRate())); //ONE, two, three, four
  53. tick = bar/(std::round(params[i][0]*16+2))*tempoDivider; //size of one target wob
  54. //if (time.bbt.valid) printf("hell yeah!\n");
  55. if (time.playing)
  56. {
  57. /* if rolling then sync to timepos */
  58. tickOffset = time.frame-std::floor(time.frame/tick)*tick; //how much after last tick
  59. if (tickOffset!=0) {
  60. //TODO: why do we need this??
  61. percentage = tickOffset/tick;
  62. } else {
  63. percentage = 0;
  64. }
  65. sinePos = (M_PI*2)*percentage;
  66. if (sinePos>2*M_PI) {
  67. //TODO: can this ever happen??
  68. sinePos = 0;
  69. }
  70. }
  71. else
  72. {
  73. /* else just keep on wobblin' */
  74. sinePos += (2*M_PI)/(tick); //wtf, but works
  75. if (sinePos>2*M_PI) {
  76. sinePos = 0;
  77. }
  78. }
  79. modules[i]->setSinePos(sinePos);
  80. //printf("sinepos: %f\n", sinePos);
  81. }
  82. }
  83. StutterJuicePlugin();
  84. //~StutterJuicePlugin() override;
  85. protected:
  86. // -------------------------------------------------------------------
  87. // Information
  88. const char* d_getLabel() const noexcept override
  89. {
  90. return "StutterJuice";
  91. }
  92. const char* d_getMaker() const noexcept override
  93. {
  94. return "Andre Sklenar";
  95. }
  96. const char* d_getLicense() const noexcept override
  97. {
  98. return "GPL v2+";
  99. }
  100. uint32_t d_getVersion() const noexcept override
  101. {
  102. return 0x1000;
  103. }
  104. long d_getUniqueId() const noexcept override
  105. {
  106. return d_cconst('S', 't', 't', 'J');
  107. }
  108. // -------------------------------------------------------------------
  109. // Init
  110. void d_initParameter(uint32_t index, Parameter& parameter) override;
  111. void d_initProgramName(uint32_t index, d_string& programName) override;
  112. // -------------------------------------------------------------------
  113. // Internal data
  114. float d_getParameterValue(uint32_t index) const override;
  115. void d_setParameterValue(uint32_t index, float value) override;
  116. void d_setProgram(uint32_t index) override;
  117. // -------------------------------------------------------------------
  118. // Process
  119. void d_activate() override;
  120. void d_deactivate() override;
  121. void d_run(const float** inputs, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount) override;
  122. // -------------------------------------------------------------------
  123. private:
  124. float params[9][3]; // left-> right, top->bottom
  125. bool moduleActive[9];
  126. float outputParams[9];
  127. CModule* modules[9];
  128. };
  129. // -----------------------------------------------------------------------
  130. END_NAMESPACE_DISTRHO
  131. #endif // TRIGGERJUICE_HPP_INCLUDED