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.

rack0.hpp 7.3KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. #pragma once
  2. #include <rack.hpp>
  3. namespace rack {
  4. ////////////////////
  5. // common
  6. ////////////////////
  7. /** Deprecated lowercase macro */
  8. #define defer(...) DEFER(__VA_ARGS__)
  9. ////////////////////
  10. // math
  11. ////////////////////
  12. using namespace math;
  13. DEPRECATED inline int min(int a, int b) {
  14. return std::min(a, b);
  15. }
  16. DEPRECATED inline int max(int a, int b) {
  17. return std::max(a, b);
  18. }
  19. DEPRECATED inline int eucmod(int a, int base) {
  20. return eucMod(a, base);
  21. }
  22. DEPRECATED inline bool ispow2(int n) {
  23. return isPow2(n);
  24. }
  25. DEPRECATED inline int clamp2(int x, int a, int b) {
  26. return clampSafe(x, a, b);
  27. }
  28. DEPRECATED inline float min(float a, float b) {
  29. return std::min(a, b);
  30. }
  31. DEPRECATED inline float max(float a, float b) {
  32. return std::max(a, b);
  33. }
  34. DEPRECATED inline float eucmod(float a, float base) {
  35. return eucMod(a, base);
  36. }
  37. DEPRECATED inline float clamp2(float x, float a, float b) {
  38. return clampSafe(x, a, b);
  39. }
  40. DEPRECATED inline int mini(int a, int b) {
  41. return std::min(a, b);
  42. }
  43. DEPRECATED inline int maxi(int a, int b) {
  44. return std::max(a, b);
  45. }
  46. DEPRECATED inline int clampi(int x, int min, int max) {
  47. return math::clamp(x, min, max);
  48. }
  49. DEPRECATED inline int absi(int a) {
  50. return std::fabs(a);
  51. }
  52. DEPRECATED inline int eucmodi(int a, int base) {
  53. return eucMod(a, base);
  54. }
  55. DEPRECATED inline int log2i(int n) {
  56. return math::log2(n);
  57. }
  58. DEPRECATED inline bool ispow2i(int n) {
  59. return isPow2(n);
  60. }
  61. DEPRECATED inline float absf(float x) {
  62. return std::fabs(x);
  63. }
  64. DEPRECATED inline float sgnf(float x) {
  65. return sgn(x);
  66. }
  67. DEPRECATED inline float eucmodf(float a, float base) {
  68. return eucMod(a, base);
  69. }
  70. DEPRECATED inline bool nearf(float a, float b, float epsilon = 1.0e-6f) {
  71. return math::isNear(a, b, epsilon);
  72. }
  73. DEPRECATED inline float clampf(float x, float min, float max) {
  74. return math::clamp(x, min, max);
  75. }
  76. DEPRECATED inline float clamp2f(float x, float min, float max) {
  77. return clampSafe(x, min, max);
  78. }
  79. DEPRECATED inline float chopf(float x, float eps) {
  80. return chop(x, eps);
  81. }
  82. DEPRECATED inline float rescalef(float x, float a, float b, float yMin, float yMax) {
  83. return math::rescale(x, a, b, yMin, yMax);
  84. }
  85. DEPRECATED inline float crossf(float a, float b, float frac) {
  86. return crossfade(a, b, frac);
  87. }
  88. DEPRECATED inline float interpf(const float* p, float x) {
  89. return interpolateLinear(p, x);
  90. }
  91. DEPRECATED inline void complexMult(float* cr, float* ci, float ar, float ai, float br, float bi) {
  92. complexMult(ar, ai, br, bi, cr, ci);
  93. }
  94. DEPRECATED inline void cmultf(float* cr, float* ci, float ar, float ai, float br, float bi) {
  95. return complexMult(ar, ai, br, bi, cr, ci);
  96. }
  97. ////////////////////
  98. // string
  99. ////////////////////
  100. #define stringf string::f
  101. ////////////////////
  102. // random
  103. ////////////////////
  104. DEPRECATED inline uint32_t randomu32() {
  105. return random::u32();
  106. }
  107. DEPRECATED inline uint64_t randomu64() {
  108. return random::u64();
  109. }
  110. DEPRECATED inline float randomUniform() {
  111. return random::uniform();
  112. }
  113. DEPRECATED inline float randomNormal() {
  114. return random::normal();
  115. }
  116. DEPRECATED inline float randomf() {
  117. return random::uniform();
  118. }
  119. ////////////////////
  120. // logger
  121. ////////////////////
  122. /** Deprecated lowercase log functions */
  123. #define debug(...) DEBUG(__VA_ARGS__)
  124. #define info(...) INFO(__VA_ARGS__)
  125. #define warn(...) WARN(__VA_ARGS__)
  126. #define fatal(...) FATAL(__VA_ARGS__)
  127. ////////////////////
  128. // asset
  129. ////////////////////
  130. DEPRECATED inline std::string assetGlobal(std::string filename) {
  131. return asset::system(filename);
  132. }
  133. DEPRECATED inline std::string assetLocal(std::string filename) {
  134. return asset::user(filename);
  135. }
  136. DEPRECATED inline std::string assetPlugin(Plugin* plugin, std::string filename) {
  137. return asset::plugin(plugin, filename);
  138. }
  139. ////////////////////
  140. // color
  141. ////////////////////
  142. DEPRECATED inline NVGcolor colorClip(NVGcolor a) {
  143. return color::clamp(a);
  144. }
  145. DEPRECATED inline NVGcolor colorMinus(NVGcolor a, NVGcolor b) {
  146. return color::minus(a, b);
  147. }
  148. DEPRECATED inline NVGcolor colorPlus(NVGcolor a, NVGcolor b) {
  149. return color::plus(a, b);
  150. }
  151. DEPRECATED inline NVGcolor colorMult(NVGcolor a, NVGcolor b) {
  152. return color::mult(a, b);
  153. }
  154. DEPRECATED inline NVGcolor colorMult(NVGcolor a, float x) {
  155. return color::mult(a, x);
  156. }
  157. DEPRECATED inline NVGcolor colorScreen(NVGcolor a, NVGcolor b) {
  158. return color::screen(a, b);
  159. }
  160. DEPRECATED inline NVGcolor colorAlpha(NVGcolor a, float alpha) {
  161. return color::alpha(a, alpha);
  162. }
  163. DEPRECATED inline NVGcolor colorFromHexString(std::string s) {
  164. return color::fromHexString(s);
  165. }
  166. DEPRECATED inline std::string colorToHexString(NVGcolor c) {
  167. return color::toHexString(c);
  168. }
  169. ////////////////////
  170. // componentlibrary
  171. ////////////////////
  172. DEPRECATED static const NVGcolor COLOR_BLACK_TRANSPARENT = componentlibrary::SCHEME_BLACK_TRANSPARENT;
  173. DEPRECATED static const NVGcolor COLOR_BLACK = componentlibrary::SCHEME_BLACK;
  174. DEPRECATED static const NVGcolor COLOR_WHITE = componentlibrary::SCHEME_WHITE;
  175. DEPRECATED static const NVGcolor COLOR_RED = componentlibrary::SCHEME_RED;
  176. DEPRECATED static const NVGcolor COLOR_ORANGE = componentlibrary::SCHEME_ORANGE;
  177. DEPRECATED static const NVGcolor COLOR_YELLOW = componentlibrary::SCHEME_YELLOW;
  178. DEPRECATED static const NVGcolor COLOR_GREEN = componentlibrary::SCHEME_GREEN;
  179. DEPRECATED static const NVGcolor COLOR_CYAN = componentlibrary::SCHEME_CYAN;
  180. DEPRECATED static const NVGcolor COLOR_BLUE = componentlibrary::SCHEME_BLUE;
  181. DEPRECATED static const NVGcolor COLOR_PURPLE = componentlibrary::SCHEME_PURPLE;
  182. DEPRECATED static const NVGcolor COLOR_LIGHT_PANEL = componentlibrary::SCHEME_LIGHT_GRAY;
  183. DEPRECATED static const NVGcolor COLOR_DARK_PANEL = componentlibrary::SCHEME_DARK_GRAY;
  184. ////////////////////
  185. // helpers
  186. ////////////////////
  187. /** Use createWidget() instead */
  188. template <class TScrew>
  189. DEPRECATED TScrew* createScrew(math::Vec pos) {
  190. return createWidget<TScrew>(pos);
  191. }
  192. /** Use createParam(pos, module, paramId) and set the Param properties in your Module constructor */
  193. template <class TParamWidget>
  194. DEPRECATED TParamWidget* createParam(math::Vec pos, Module* module, int paramId, float minValue, float maxValue, float defaultValue) {
  195. TParamWidget* o = createParam<TParamWidget>(pos, module, paramId);
  196. if (module) {
  197. module->configParam(paramId, minValue, maxValue, defaultValue);
  198. }
  199. return o;
  200. }
  201. template <class TParamWidget>
  202. DEPRECATED TParamWidget* createParamCentered(math::Vec pos, Module* module, int paramId, float minValue, float maxValue, float defaultValue) {
  203. TParamWidget* o = createParamCentered<TParamWidget>(pos, module, paramId);
  204. if (module) {
  205. module->configParam(paramId, minValue, maxValue, defaultValue);
  206. }
  207. return o;
  208. }
  209. /** Use createInput() and createOutput() without the `type` variable */
  210. template <class TPortWidget>
  211. DEPRECATED TPortWidget* createPort(math::Vec pos, PortWidget::Type type, Module* module, int inputId) {
  212. TPortWidget* o = new TPortWidget;
  213. o->box.pos = pos;
  214. o->type = type;
  215. o->module = module;
  216. o->portId = inputId;
  217. return o;
  218. }
  219. ////////////////////
  220. // engine
  221. ////////////////////
  222. DEPRECATED inline float engineGetSampleRate() {
  223. return APP->engine->getSampleRate();
  224. }
  225. DEPRECATED inline float engineGetSampleTime() {
  226. return APP->engine->getSampleTime();
  227. }
  228. ////////////////////
  229. // dsp
  230. ////////////////////
  231. using namespace dsp;
  232. DEPRECATED inline float gainToDb(float gain) {
  233. return dsp::amplitudeToDb(gain);
  234. }
  235. DEPRECATED inline float dbToGain(float db) {
  236. return dsp::dbToAmplitude(db);
  237. }
  238. } // namespace rack