Audio plugin host https://kx.studio/carla
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.

300 lines
9.1KB

  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2013 Filipe Coelho <falktx@falktx.com>
  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 "CarlaNative.hpp"
  18. using namespace juce;
  19. #include "vex/cArp.h"
  20. class VexArpPlugin : public PluginDescriptorClass
  21. {
  22. public:
  23. enum Params {
  24. kParamLength = 0,
  25. kParamTimeMode,
  26. kParamSyncMode,
  27. kParamFailMode,
  28. kParamVelMode,
  29. kParamCount
  30. };
  31. VexArpPlugin(const HostDescriptor* const host)
  32. : PluginDescriptorClass(host),
  33. settings(),
  34. arp(&settings),
  35. fWetOnly(false)
  36. {
  37. arp.setSampleRate(getSampleRate());
  38. inMidiBuffer.ensureSize(512*4);
  39. for (int i=0; i < 8; ++i)
  40. settings.grid[i*10] = true;
  41. settings.grid[1] = true;
  42. settings.grid[2] = true;
  43. settings.grid[3] = true;
  44. settings.grid[41] = true;
  45. settings.grid[42] = true;
  46. settings.grid[43] = true;
  47. settings.grid[44] = true;
  48. settings.grid[45] = true;
  49. }
  50. ~VexArpPlugin() override
  51. {
  52. }
  53. protected:
  54. // -------------------------------------------------------------------
  55. // Plugin parameter calls
  56. uint32_t getParameterCount() override
  57. {
  58. return kParamCount;
  59. }
  60. const Parameter* getParameterInfo(const uint32_t index) override
  61. {
  62. static Parameter paramInfo;
  63. static ParameterScalePoint scalePoints[4];
  64. int hints = PARAMETER_IS_ENABLED|PARAMETER_IS_AUTOMABLE|PARAMETER_IS_INTEGER;
  65. paramInfo.name = nullptr;
  66. paramInfo.unit = nullptr;
  67. paramInfo.ranges.def = 0.0f;
  68. paramInfo.ranges.min = 0.0f;
  69. paramInfo.ranges.max = 1.0f;
  70. paramInfo.ranges.step = 1.0f;
  71. paramInfo.ranges.stepSmall = 1.0f;
  72. paramInfo.ranges.stepLarge = 1.0f;
  73. paramInfo.scalePointCount = 0;
  74. paramInfo.scalePoints = nullptr;
  75. switch (index)
  76. {
  77. case kParamLength:
  78. paramInfo.name = "Length";
  79. paramInfo.ranges.def = 8.0f;
  80. paramInfo.ranges.min = 1.0f;
  81. paramInfo.ranges.max = 16.0f;
  82. break;
  83. case kParamTimeMode:
  84. hints |= PARAMETER_USES_SCALEPOINTS;
  85. paramInfo.name = "Time Signature";
  86. paramInfo.ranges.def = 2.0f;
  87. paramInfo.ranges.min = 1.0f;
  88. paramInfo.ranges.max = 3.0f;
  89. paramInfo.scalePointCount = 3;
  90. paramInfo.scalePoints = scalePoints;
  91. scalePoints[0].label = "8";
  92. scalePoints[1].label = "16";
  93. scalePoints[2].label = "32";
  94. scalePoints[0].value = 1.0f;
  95. scalePoints[1].value = 2.0f;
  96. scalePoints[2].value = 3.0f;
  97. break;
  98. case kParamSyncMode:
  99. hints |= PARAMETER_USES_SCALEPOINTS;
  100. paramInfo.name = "Sync Mode";
  101. paramInfo.ranges.def = 1.0f;
  102. paramInfo.ranges.min = 1.0f;
  103. paramInfo.ranges.max = 2.0f;
  104. paramInfo.scalePointCount = 2;
  105. paramInfo.scalePoints = scalePoints;
  106. scalePoints[0].label = "Key Sync";
  107. scalePoints[1].label = "Bar Sync";
  108. scalePoints[0].value = 1.0f;
  109. scalePoints[1].value = 2.0f;
  110. break;
  111. case kParamFailMode:
  112. hints |= PARAMETER_USES_SCALEPOINTS;
  113. paramInfo.name = "Fail Mode";
  114. paramInfo.ranges.def = 1.0f;
  115. paramInfo.ranges.min = 1.0f;
  116. paramInfo.ranges.max = 3.0f;
  117. paramInfo.scalePointCount = 3;
  118. paramInfo.scalePoints = scalePoints;
  119. scalePoints[0].label = "Silent Step";
  120. scalePoints[1].label = "Skip One";
  121. scalePoints[2].label = "Skip Two";
  122. scalePoints[0].value = 1.0f;
  123. scalePoints[1].value = 2.0f;
  124. scalePoints[2].value = 3.0f;
  125. break;
  126. case kParamVelMode:
  127. hints |= PARAMETER_USES_SCALEPOINTS;
  128. paramInfo.name = "Velocity Mode";
  129. paramInfo.ranges.def = 1.0f;
  130. paramInfo.ranges.min = 1.0f;
  131. paramInfo.ranges.max = 3.0f;
  132. paramInfo.scalePointCount = 3;
  133. paramInfo.scalePoints = scalePoints;
  134. scalePoints[0].label = "Pattern Velocity";
  135. scalePoints[1].label = "Input Velocity";
  136. scalePoints[2].label = "Sum Velocities";
  137. scalePoints[0].value = 1.0f;
  138. scalePoints[1].value = 2.0f;
  139. scalePoints[2].value = 3.0f;
  140. break;
  141. }
  142. paramInfo.hints = static_cast<ParameterHints>(hints);
  143. return &paramInfo;
  144. }
  145. float getParameterValue(const uint32_t index) override
  146. {
  147. switch (index)
  148. {
  149. case kParamLength:
  150. return settings.length;
  151. case kParamTimeMode:
  152. return settings.timeMode;
  153. case kParamSyncMode:
  154. return settings.syncMode;
  155. case kParamFailMode:
  156. return settings.failMode;
  157. case kParamVelMode:
  158. return settings.velMode;
  159. default:
  160. return 0.0f;
  161. }
  162. }
  163. // -------------------------------------------------------------------
  164. // Plugin state calls
  165. void setParameterValue(const uint32_t index, const float value)
  166. {
  167. switch (index)
  168. {
  169. case kParamLength:
  170. settings.length = value;
  171. break;
  172. case kParamTimeMode:
  173. settings.timeMode = value;
  174. break;
  175. case kParamSyncMode:
  176. settings.syncMode = value;
  177. break;
  178. case kParamFailMode:
  179. settings.failMode = value;
  180. break;
  181. case kParamVelMode:
  182. settings.velMode = value;
  183. break;
  184. }
  185. }
  186. // -------------------------------------------------------------------
  187. // Plugin process calls
  188. void process(float**, float**, const uint32_t frames, const uint32_t midiEventCount, const MidiEvent* const midiEvents) override
  189. {
  190. const TimeInfo* const timeInfo(getTimeInfo());
  191. double ppqPos, barStartPos, bpm;
  192. if (timeInfo->bbt.valid)
  193. {
  194. ppqPos = 0.0;
  195. barStartPos = 0.0;
  196. bpm = timeInfo->bbt.beatsPerMinute;
  197. }
  198. else
  199. {
  200. double ppqBar = double(timeInfo->bbt.bar - 1) * timeInfo->bbt.beatsPerBar;
  201. double ppqBeat = double(timeInfo->bbt.beat - 1);
  202. double ppqTick = double(timeInfo->bbt.tick) / timeInfo->bbt.ticksPerBeat;
  203. ppqPos = ppqBar + ppqBeat + ppqTick;
  204. barStartPos = ppqBar;
  205. bpm = 120.0;
  206. }
  207. inMidiBuffer.clear();
  208. for (uint32_t i=0; i < midiEventCount; ++i)
  209. {
  210. const MidiEvent* const midiEvent(&midiEvents[i]);
  211. inMidiBuffer.addEvent(MidiMessage(midiEvent->data, midiEvent->size, midiEvent->time), 0/*timeInfo->frame*/);
  212. }
  213. const MidiBuffer& outMidiBuffer(arp.processMidi(inMidiBuffer, timeInfo->playing, ppqPos, barStartPos, bpm, frames));
  214. MidiBuffer::Iterator outBufferIterator(outMidiBuffer);
  215. MidiMessage midiMessage(0xf4);
  216. int sampleNumber;
  217. MidiEvent tmpEvent;
  218. tmpEvent.port = 0;
  219. while (outBufferIterator.getNextEvent(midiMessage, sampleNumber))
  220. {
  221. tmpEvent.size = midiMessage.getRawDataSize();
  222. tmpEvent.time = midiMessage.getTimeStamp();
  223. if (tmpEvent.size > 4)
  224. continue;
  225. std::memcpy(tmpEvent.data, midiMessage.getRawData(), sizeof(uint8_t)*tmpEvent.size);
  226. writeMidiEvent(&tmpEvent);
  227. }
  228. }
  229. private:
  230. PeggySettings settings;
  231. cArp arp;
  232. MidiBuffer inMidiBuffer;
  233. bool fWetOnly;
  234. PluginDescriptorClassEND(VexArpPlugin)
  235. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(VexArpPlugin)
  236. };
  237. // -----------------------------------------------------------------------
  238. static const PluginDescriptor vexArpDesc = {
  239. /* category */ PLUGIN_CATEGORY_UTILITY,
  240. /* hints */ static_cast<PluginHints>(0x0),
  241. /* supports */ static_cast<PluginSupports>(PLUGIN_SUPPORTS_EVERYTHING),
  242. /* audioIns */ 0,
  243. /* audioOuts */ 0,
  244. /* midiIns */ 1,
  245. /* midiOuts */ 1,
  246. /* paramIns */ VexArpPlugin::kParamCount,
  247. /* paramOuts */ 0,
  248. /* name */ "Vex Arp",
  249. /* label */ "vexArp",
  250. /* maker */ "falkTX",
  251. /* copyright */ "GNU GPL v2+",
  252. PluginDescriptorFILL(VexArpPlugin)
  253. };
  254. // -----------------------------------------------------------------------
  255. CARLA_EXPORT
  256. void carla_register_native_plugin_vex()
  257. {
  258. carla_register_native_plugin(&vexArpDesc);
  259. }
  260. // -----------------------------------------------------------------------