DPF Plugin examples
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.

169 lines
4.0KB

  1. #include "DistrhoPlugin.hpp"
  2. #include <math.h>
  3. extern "C" void adainit(void);
  4. extern "C" void adafinal(void);
  5. extern "C" void Add_Note(float);
  6. extern "C" void Remove_Note(float);
  7. extern "C" float Super_Saw(float,float,float,float,float);
  8. extern "C" float Compute_Polyphony(float,float,float,float);
  9. START_NAMESPACE_DISTRHO
  10. class SuperSaw : public Plugin
  11. {
  12. public:
  13. SuperSaw() : Plugin(2,0,0){
  14. adainit();
  15. }
  16. ~SuperSaw() {
  17. adafinal();
  18. }
  19. protected:
  20. const char* getLabel() const override
  21. {
  22. return "Super Saw";
  23. }
  24. const char* getDescription() const override
  25. {
  26. return "Roland JP-8000 Super Saw emulator";
  27. }
  28. const char* getMaker() const override
  29. {
  30. return "Cranix";
  31. }
  32. /**
  33. Get the plugin homepage.
  34. */
  35. const char* getHomePage() const override
  36. {
  37. return "http://example.org/Super_Saw";
  38. }
  39. /**
  40. Get the plugin license name (a single line of text).
  41. For commercial plugins this should return some short copyright information.
  42. */
  43. const char* getLicense() const override
  44. {
  45. return "GPL";
  46. }
  47. /**
  48. Get the plugin version, in hexadecimal.
  49. */
  50. uint32_t getVersion() const override
  51. {
  52. return d_version(1, 0, 0);
  53. }
  54. /**
  55. Get the plugin unique Id.
  56. This value is used by LADSPA, DSSI and VST plugin formats.
  57. */
  58. int64_t getUniqueId() const override
  59. {
  60. return d_cconst('d', 'N', 'f', 'o');
  61. }
  62. void setParameterValue(uint32_t index, float value) override
  63. {
  64. if (index == 0) {
  65. detune = value;
  66. } else if (index == 1) {
  67. mix = value;
  68. }
  69. }
  70. float getParameterValue(uint32_t index) const override
  71. {
  72. if (index == 0) {
  73. return detune;
  74. } else if (index == 1) {
  75. return mix;
  76. }
  77. }
  78. void initParameter(uint32_t index, Parameter& parameter) override {
  79. if (index == 0) { /*Detune*/
  80. parameter.hints = kParameterIsAutomable;
  81. parameter.name = "Detune";
  82. parameter.symbol = "detune";
  83. parameter.ranges.min = 0.0f;
  84. parameter.ranges.max = 0.9f;
  85. parameter.ranges.def = 0.5f;
  86. } else if (index == 1) { /*Mix*/
  87. parameter.hints = kParameterIsAutomable;
  88. parameter.name = "Mix";
  89. parameter.symbol = "mix";
  90. parameter.ranges.min = 0.0f;
  91. parameter.ranges.max = 0.9f;
  92. parameter.ranges.def = 0.5f;
  93. }
  94. }
  95. void run(const float** inputs, float** outputs, uint32_t frames, const MidiEvent* midiEvents,
  96. uint32_t midiEventCount) override {
  97. const uint8_t* data;
  98. uint8_t status;
  99. uint8_t note;
  100. float frequency;
  101. uint32_t framesDone=0;
  102. uint32_t curEventIndex=0;
  103. while (framesDone < frames) {
  104. while (curEventIndex < midiEventCount && framesDone == midiEvents[curEventIndex].frame) {
  105. if ( midiEvents[curEventIndex].size > MidiEvent::kDataSize )
  106. continue;
  107. data=midiEvents[curEventIndex].data;
  108. status=data[0]&0xFF;
  109. if ( ! ( ( status == 0x80 || status == 0x90))) {
  110. curEventIndex++;
  111. continue;
  112. }
  113. note=data[1];
  114. if (status == 0x90) {
  115. frequency=pow(2.0,(note-57.0)/12.0)*440.0;
  116. Add_Note(frequency);
  117. } else if (status == 0x80) {
  118. // frequency = 0.0;
  119. frequency=pow(2.0,(note-57.0)/12.0)*440.0;
  120. Remove_Note(frequency);
  121. }
  122. curEventIndex++;
  123. }
  124. //outputs[0][framesDone]=sin(phase*frequency/44100.0*2.0*3.14);
  125. //outputs[0][framesDone]=sin(phase*frequency/44100.0*2.0*3.14);
  126. outputs[0][framesDone]=Compute_Polyphony(phase,detune,mix,getSampleRate());
  127. phase++;
  128. framesDone++;
  129. }
  130. /*data=midiEvents[0].data;
  131. status=data[0]&0xFF;
  132. if (status == 0x90){
  133. note=data[1];
  134. frequency=pow(2.0,(note-57.0)/12.0)*440.0;
  135. for (i=0;i<frames;i++){
  136. outputs[0][i] = sin(phase*2.0*3.14*frequency);
  137. phase++;
  138. }
  139. }*/
  140. } //run
  141. private:
  142. float phase=0;
  143. float detune;
  144. float mix;
  145. };
  146. Plugin* createPlugin()
  147. {
  148. return new SuperSaw();
  149. }
  150. END_NAMESPACE_DISTRHO