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.

277 lines
6.6KB

  1. /*
  2. * DISTRHO ProM Plugin
  3. * Copyright (C) 2014 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 Lesser General Public
  7. * License as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * For a full copy of the license see the LICENSE file.
  15. */
  16. #include "DistrhoPluginProM.hpp"
  17. #include "DistrhoUIProM.hpp"
  18. #include "libprojectM/projectM.hpp"
  19. START_NAMESPACE_DISTRHO
  20. // -----------------------------------------------------------------------
  21. static const projectM::Settings kSettings = {
  22. /* meshX */ 32,
  23. /* meshY */ 24,
  24. /* fps */ 35,
  25. /* textureSize */ 1024,
  26. /* windowWidth */ 512,
  27. /* windowHeight */ 512,
  28. /* presetURL */ "/usr/share/projectM/presets",
  29. /* titleFontURL */ "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf",
  30. /* menuFontURL */ "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf",
  31. /* smoothPresetDuration */ 5,
  32. /* presetDuration */ 30,
  33. /* beatSensitivity */ 10.0f,
  34. /* aspectCorrection */ true,
  35. /* easterEgg */ 1.0f,
  36. /* shuffleEnabled */ true,
  37. /* softCutRatingsEnabled */ false
  38. };
  39. // -----------------------------------------------------------------------
  40. DistrhoUIProM::DistrhoUIProM()
  41. : UI()
  42. {
  43. }
  44. DistrhoUIProM::~DistrhoUIProM()
  45. {
  46. if (DistrhoPluginProM* const dspPtr = (DistrhoPluginProM*)d_getPluginInstancePointer())
  47. {
  48. const MutexLocker csm(dspPtr->fMutex);
  49. dspPtr->fPM = nullptr;
  50. }
  51. }
  52. // -----------------------------------------------------------------------
  53. // DSP Callbacks
  54. void DistrhoUIProM::d_parameterChanged(uint32_t, float)
  55. {
  56. }
  57. // -----------------------------------------------------------------------
  58. // UI Callbacks
  59. void DistrhoUIProM::d_uiIdle()
  60. {
  61. if (fPM == nullptr)
  62. return;
  63. repaint();
  64. if (DistrhoPluginProM* const dspPtr = (DistrhoPluginProM*)d_getPluginInstancePointer())
  65. {
  66. if (dspPtr->fPM != nullptr)
  67. return;
  68. const MutexLocker csm(dspPtr->fMutex);
  69. dspPtr->fPM = fPM;
  70. }
  71. }
  72. void DistrhoUIProM::d_uiReshape(int width, int height)
  73. {
  74. glEnable(GL_BLEND);
  75. glEnable(GL_LINE_SMOOTH);
  76. glEnable(GL_POINT_SMOOTH);
  77. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  78. glShadeModel(GL_SMOOTH);
  79. glMatrixMode(GL_TEXTURE);
  80. glLoadIdentity();
  81. glMatrixMode(GL_PROJECTION);
  82. glLoadIdentity();
  83. glOrtho(0, width, height, 0, 0.0f, 1.0f);
  84. glViewport(0, 0, width, height);
  85. glMatrixMode(GL_MODELVIEW);
  86. glLoadIdentity();
  87. glDrawBuffer(GL_BACK);
  88. glReadBuffer(GL_BACK);
  89. glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  90. glLineStipple(2, 0xAAAA);
  91. if (fPM == nullptr)
  92. fPM = new projectM(kSettings); // std::string("/usr/share/projectM/config.inp"));
  93. fPM->projectM_resetGL(width, height);
  94. }
  95. // -----------------------------------------------------------------------
  96. // Widget Callbacks
  97. void DistrhoUIProM::onDisplay()
  98. {
  99. if (fPM == nullptr)
  100. return;
  101. fPM->renderFrame();
  102. }
  103. bool DistrhoUIProM::onKeyboard(const KeyboardEvent& ev)
  104. {
  105. if (fPM == nullptr)
  106. return false;
  107. projectMKeycode pmKey = PROJECTM_K_NONE;
  108. projectMModifier pmMod = PROJECTM_KMOD_LSHIFT;
  109. if ((ev.key >= PROJECTM_K_0 && ev.key <= PROJECTM_K_9) ||
  110. (ev.key >= PROJECTM_K_A && ev.key <= PROJECTM_K_Z) ||
  111. (ev.key >= PROJECTM_K_a && ev.key <= PROJECTM_K_z))
  112. {
  113. pmKey = static_cast<projectMKeycode>(ev.key);
  114. }
  115. else
  116. {
  117. switch (ev.key)
  118. {
  119. case DGL::CHAR_BACKSPACE:
  120. pmKey = PROJECTM_K_BACKSPACE;
  121. break;
  122. case DGL::CHAR_ESCAPE:
  123. pmKey = PROJECTM_K_ESCAPE;
  124. break;
  125. case DGL::CHAR_DELETE:
  126. pmKey = PROJECTM_K_DELETE;
  127. break;
  128. }
  129. }
  130. if (pmKey == PROJECTM_K_NONE)
  131. return false;
  132. if (ev.mod & DGL::MODIFIER_CTRL)
  133. pmMod = PROJECTM_KMOD_LCTRL;
  134. fPM->key_handler(ev.press ? PROJECTM_KEYUP : PROJECTM_KEYDOWN, pmKey, pmMod);
  135. return true;
  136. }
  137. bool DistrhoUIProM::onSpecial(const SpecialEvent& ev)
  138. {
  139. if (fPM == nullptr)
  140. return false;
  141. projectMKeycode pmKey = PROJECTM_K_NONE;
  142. projectMModifier pmMod = PROJECTM_KMOD_LSHIFT;
  143. switch (ev.key)
  144. {
  145. case DGL::KEY_F1:
  146. pmKey = PROJECTM_K_F1;
  147. break;
  148. case DGL::KEY_F2:
  149. pmKey = PROJECTM_K_F2;
  150. break;
  151. case DGL::KEY_F3:
  152. pmKey = PROJECTM_K_F3;
  153. break;
  154. case DGL::KEY_F4:
  155. pmKey = PROJECTM_K_F4;
  156. break;
  157. case DGL::KEY_F5:
  158. pmKey = PROJECTM_K_F5;
  159. break;
  160. case DGL::KEY_F6:
  161. pmKey = PROJECTM_K_F6;
  162. break;
  163. case DGL::KEY_F7:
  164. pmKey = PROJECTM_K_F7;
  165. break;
  166. case DGL::KEY_F8:
  167. pmKey = PROJECTM_K_F8;
  168. break;
  169. case DGL::KEY_F9:
  170. pmKey = PROJECTM_K_F9;
  171. break;
  172. case DGL::KEY_F10:
  173. pmKey = PROJECTM_K_F10;
  174. break;
  175. case DGL::KEY_F11:
  176. pmKey = PROJECTM_K_F11;
  177. break;
  178. case DGL::KEY_F12:
  179. pmKey = PROJECTM_K_F12;
  180. break;
  181. case DGL::KEY_LEFT:
  182. pmKey = PROJECTM_K_LEFT;
  183. break;
  184. case DGL::KEY_UP:
  185. pmKey = PROJECTM_K_UP;
  186. break;
  187. case DGL::KEY_RIGHT:
  188. pmKey = PROJECTM_K_RIGHT;
  189. break;
  190. case DGL::KEY_DOWN:
  191. pmKey = PROJECTM_K_DOWN;
  192. break;
  193. case DGL::KEY_PAGE_UP:
  194. pmKey = PROJECTM_K_PAGEUP;
  195. break;
  196. case DGL::KEY_PAGE_DOWN:
  197. pmKey = PROJECTM_K_PAGEDOWN;
  198. break;
  199. case DGL::KEY_HOME:
  200. pmKey = PROJECTM_K_HOME;
  201. break;
  202. case DGL::KEY_END:
  203. pmKey = PROJECTM_K_END;
  204. break;
  205. case DGL::KEY_INSERT:
  206. pmKey = PROJECTM_K_INSERT;
  207. break;
  208. case DGL::KEY_SHIFT:
  209. pmKey = PROJECTM_K_LSHIFT;
  210. break;
  211. case DGL::KEY_CTRL:
  212. pmKey = PROJECTM_K_LCTRL;
  213. break;
  214. case DGL::KEY_ALT:
  215. case DGL::KEY_SUPER:
  216. break;
  217. }
  218. if (pmKey == PROJECTM_K_NONE)
  219. return false;
  220. if (ev.mod & DGL::MODIFIER_CTRL)
  221. pmMod = PROJECTM_KMOD_LCTRL;
  222. fPM->key_handler(ev.press ? PROJECTM_KEYUP : PROJECTM_KEYDOWN, pmKey, pmMod);
  223. return true;
  224. }
  225. // -----------------------------------------------------------------------
  226. UI* createUI()
  227. {
  228. return new DistrhoUIProM();
  229. }
  230. // -----------------------------------------------------------------------
  231. END_NAMESPACE_DISTRHO