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.

241 lines
6.7KB

  1. /*
  2. * DISTRHO CVCRack Plugin
  3. * Copyright (C) 2021 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <asset.hpp>
  17. #include <audio.hpp>
  18. #include <context.hpp>
  19. #include <library.hpp>
  20. #include <keyboard.hpp>
  21. #include <midi.hpp>
  22. #include <plugin.hpp>
  23. #include <random.hpp>
  24. #include <settings.hpp>
  25. #include <system.hpp>
  26. #include <ui/common.hpp>
  27. #include <window/Window.hpp>
  28. #include <osdialog.h>
  29. #include "DistrhoPlugin.hpp"
  30. START_NAMESPACE_DISTRHO
  31. // -----------------------------------------------------------------------------------------------------------
  32. struct Initializer {
  33. Initializer()
  34. {
  35. using namespace rack;
  36. settings::devMode = true;
  37. system::init();
  38. asset::init();
  39. logger::init();
  40. random::init();
  41. // Log environment
  42. INFO("%s %s v%s", APP_NAME.c_str(), APP_EDITION.c_str(), APP_VERSION.c_str());
  43. INFO("%s", system::getOperatingSystemInfo().c_str());
  44. INFO("System directory: %s", asset::systemDir.c_str());
  45. INFO("User directory: %s", asset::userDir.c_str());
  46. INFO("System time: %s", string::formatTimeISO(system::getUnixTime()).c_str());
  47. // Load settings
  48. settings::init();
  49. #if 0
  50. try {
  51. settings::load();
  52. }
  53. catch (Exception& e) {
  54. std::string message = e.what();
  55. message += "\n\nResetting settings to default";
  56. d_stdout(message.c_str());
  57. /*
  58. if (!osdialog_message(OSDIALOG_WARNING, OSDIALOG_OK_CANCEL, msg.c_str())) {
  59. exit(1);
  60. }
  61. */
  62. }
  63. #endif
  64. // Check existence of the system res/ directory
  65. std::string resDir = asset::system("res");
  66. if (!system::isDirectory(resDir)) {
  67. std::string message = string::f("Rack's resource directory \"%s\" does not exist. Make sure Rack is correctly installed and launched.", resDir.c_str());
  68. d_stderr2(message.c_str());
  69. /*
  70. osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, message.c_str());
  71. */
  72. exit(1);
  73. }
  74. INFO("Initializing environment");
  75. // network::init();
  76. audio::init();
  77. // rtaudioInit();
  78. midi::init();
  79. // rtmidiInit();
  80. keyboard::init();
  81. plugin::init();
  82. library::init();
  83. // discord::init();
  84. ui::init();
  85. window::init();
  86. }
  87. ~Initializer()
  88. {
  89. using namespace rack;
  90. window::destroy();
  91. ui::destroy();
  92. // discord::destroy();
  93. library::destroy();
  94. midi::destroy();
  95. audio::destroy();
  96. plugin::destroy();
  97. INFO("Destroying logger");
  98. logger::destroy();
  99. }
  100. };
  101. static const Initializer& getInitializerInstance()
  102. {
  103. static const Initializer init;
  104. return init;
  105. }
  106. /**
  107. Plugin to demonstrate parameter outputs using meters.
  108. */
  109. class CVCRackPlugin : public Plugin
  110. {
  111. public:
  112. CVCRackPlugin()
  113. : Plugin(0, 0, 0)
  114. {
  115. }
  116. protected:
  117. /* --------------------------------------------------------------------------------------------------------
  118. * Information */
  119. /**
  120. Get the plugin label.
  121. A plugin label follows the same rules as Parameter::symbol, with the exception that it can start with numbers.
  122. */
  123. const char* getLabel() const override
  124. {
  125. return "CVCRack";
  126. }
  127. /**
  128. Get an extensive comment/description about the plugin.
  129. */
  130. const char* getDescription() const override
  131. {
  132. return "...";
  133. }
  134. /**
  135. Get the plugin author/maker.
  136. */
  137. const char* getMaker() const override
  138. {
  139. return "DISTRHO";
  140. }
  141. /**
  142. Get the plugin homepage.
  143. */
  144. const char* getHomePage() const override
  145. {
  146. return "https://github.com/DISTRHO/CVCRack";
  147. }
  148. /**
  149. Get the plugin license name (a single line of text).
  150. For commercial plugins this should return some short copyright information.
  151. */
  152. const char* getLicense() const override
  153. {
  154. return "ISC";
  155. }
  156. /**
  157. Get the plugin version, in hexadecimal.
  158. */
  159. uint32_t getVersion() const override
  160. {
  161. return d_version(1, 0, 0);
  162. }
  163. /**
  164. Get the plugin unique Id.
  165. This value is used by LADSPA, DSSI and VST plugin formats.
  166. */
  167. int64_t getUniqueId() const override
  168. {
  169. return d_cconst('d', 'C', 'V', 'C');
  170. }
  171. /* --------------------------------------------------------------------------------------------------------
  172. * Init */
  173. /* --------------------------------------------------------------------------------------------------------
  174. * Internal data */
  175. /* --------------------------------------------------------------------------------------------------------
  176. * Process */
  177. /**
  178. Run/process function for plugins without MIDI input.
  179. */
  180. void run(const float** inputs, float** outputs, uint32_t frames) override
  181. {
  182. // copy inputs over outputs if needed
  183. if (outputs[0] != inputs[0])
  184. std::memcpy(outputs[0], inputs[0], sizeof(float)*frames);
  185. if (outputs[1] != inputs[1])
  186. std::memcpy(outputs[1], inputs[1], sizeof(float)*frames);
  187. }
  188. // -------------------------------------------------------------------------------------------------------
  189. private:
  190. /**
  191. Set our plugin class as non-copyable and add a leak detector just in case.
  192. */
  193. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CVCRackPlugin)
  194. };
  195. /* ------------------------------------------------------------------------------------------------------------
  196. * Plugin entry point, called by DPF to create a new plugin instance. */
  197. Plugin* createPlugin()
  198. {
  199. getInitializerInstance();
  200. return new CVCRackPlugin();
  201. }
  202. // -----------------------------------------------------------------------------------------------------------
  203. END_NAMESPACE_DISTRHO