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.

230 lines
6.6KB

  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 <osdialog.h>
  27. #include "DistrhoPlugin.hpp"
  28. START_NAMESPACE_DISTRHO
  29. // -----------------------------------------------------------------------------------------------------------
  30. struct Initializer {
  31. Initializer()
  32. {
  33. using namespace rack;
  34. settings::devMode = true;
  35. system::init();
  36. asset::init();
  37. logger::init();
  38. random::init();
  39. // Log environment
  40. INFO("%s %s v%s", APP_NAME.c_str(), APP_EDITION.c_str(), APP_VERSION.c_str());
  41. INFO("%s", system::getOperatingSystemInfo().c_str());
  42. INFO("System directory: %s", asset::systemDir.c_str());
  43. INFO("User directory: %s", asset::userDir.c_str());
  44. INFO("System time: %s", string::formatTimeISO(system::getUnixTime()).c_str());
  45. // Load settings
  46. settings::init();
  47. try {
  48. settings::load();
  49. }
  50. catch (Exception& e) {
  51. std::string message = e.what();
  52. message += "\n\nResetting settings to default";
  53. d_stdout(message.c_str());
  54. /*
  55. if (!osdialog_message(OSDIALOG_WARNING, OSDIALOG_OK_CANCEL, msg.c_str())) {
  56. exit(1);
  57. }
  58. */
  59. }
  60. // Check existence of the system res/ directory
  61. std::string resDir = asset::system("res");
  62. if (!system::isDirectory(resDir)) {
  63. std::string message = string::f("Rack's resource directory \"%s\" does not exist. Make sure Rack is correctly installed and launched.", resDir.c_str());
  64. d_stderr2(message.c_str());
  65. /*
  66. osdialog_message(OSDIALOG_ERROR, OSDIALOG_OK, message.c_str());
  67. */
  68. exit(1);
  69. }
  70. INFO("Initializing environment");
  71. // network::init();
  72. audio::init();
  73. // rtaudioInit();
  74. midi::init();
  75. // rtmidiInit();
  76. keyboard::init();
  77. plugin::init();
  78. library::init();
  79. // discord::init();
  80. }
  81. ~Initializer()
  82. {
  83. using namespace rack;
  84. // discord::destroy();
  85. library::destroy();
  86. midi::destroy();
  87. audio::destroy();
  88. plugin::destroy();
  89. INFO("Destroying logger");
  90. logger::destroy();
  91. }
  92. };
  93. static Initializer& getInitializerInstance()
  94. {
  95. static Initializer init;
  96. return init;
  97. }
  98. /**
  99. Plugin to demonstrate parameter outputs using meters.
  100. */
  101. class CVCRackPlugin : public Plugin
  102. {
  103. public:
  104. CVCRackPlugin()
  105. : Plugin(0, 0, 0)
  106. {
  107. }
  108. protected:
  109. /* --------------------------------------------------------------------------------------------------------
  110. * Information */
  111. /**
  112. Get the plugin label.
  113. A plugin label follows the same rules as Parameter::symbol, with the exception that it can start with numbers.
  114. */
  115. const char* getLabel() const override
  116. {
  117. return "CVCRack";
  118. }
  119. /**
  120. Get an extensive comment/description about the plugin.
  121. */
  122. const char* getDescription() const override
  123. {
  124. return "...";
  125. }
  126. /**
  127. Get the plugin author/maker.
  128. */
  129. const char* getMaker() const override
  130. {
  131. return "DISTRHO";
  132. }
  133. /**
  134. Get the plugin homepage.
  135. */
  136. const char* getHomePage() const override
  137. {
  138. return "https://github.com/DISTRHO/CVCRack";
  139. }
  140. /**
  141. Get the plugin license name (a single line of text).
  142. For commercial plugins this should return some short copyright information.
  143. */
  144. const char* getLicense() const override
  145. {
  146. return "ISC";
  147. }
  148. /**
  149. Get the plugin version, in hexadecimal.
  150. */
  151. uint32_t getVersion() const override
  152. {
  153. return d_version(1, 0, 0);
  154. }
  155. /**
  156. Get the plugin unique Id.
  157. This value is used by LADSPA, DSSI and VST plugin formats.
  158. */
  159. int64_t getUniqueId() const override
  160. {
  161. return d_cconst('d', 'C', 'V', 'C');
  162. }
  163. /* --------------------------------------------------------------------------------------------------------
  164. * Init */
  165. /* --------------------------------------------------------------------------------------------------------
  166. * Internal data */
  167. /* --------------------------------------------------------------------------------------------------------
  168. * Process */
  169. /**
  170. Run/process function for plugins without MIDI input.
  171. */
  172. void run(const float** inputs, float** outputs, uint32_t frames) override
  173. {
  174. // copy inputs over outputs if needed
  175. if (outputs[0] != inputs[0])
  176. std::memcpy(outputs[0], inputs[0], sizeof(float)*frames);
  177. if (outputs[1] != inputs[1])
  178. std::memcpy(outputs[1], inputs[1], sizeof(float)*frames);
  179. }
  180. // -------------------------------------------------------------------------------------------------------
  181. private:
  182. /**
  183. Set our plugin class as non-copyable and add a leak detector just in case.
  184. */
  185. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CVCRackPlugin)
  186. };
  187. /* ------------------------------------------------------------------------------------------------------------
  188. * Plugin entry point, called by DPF to create a new plugin instance. */
  189. Plugin* createPlugin()
  190. {
  191. getInitializerInstance();
  192. return new CVCRackPlugin();
  193. }
  194. // -----------------------------------------------------------------------------------------------------------
  195. END_NAMESPACE_DISTRHO