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.

306 lines
7.4KB

  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. #if 0
  22. static const projectM::Settings kSettings = {
  23. /* meshX */ 32,
  24. /* meshY */ 24,
  25. /* fps */ 35,
  26. /* textureSize */ 1024,
  27. /* windowWidth */ 512,
  28. /* windowHeight */ 512,
  29. /* presetURL */ "/usr/share/projectM/presets",
  30. /* titleFontURL */ "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf",
  31. /* menuFontURL */ "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf",
  32. /* smoothPresetDuration */ 5,
  33. /* presetDuration */ 30,
  34. /* beatSensitivity */ 10.0f,
  35. /* aspectCorrection */ true,
  36. /* easterEgg */ 1.0f,
  37. /* shuffleEnabled */ true,
  38. /* softCutRatingsEnabled */ false
  39. };
  40. #endif
  41. // -----------------------------------------------------------------------
  42. DistrhoUIProM::DistrhoUIProM()
  43. : UI()
  44. {
  45. setSize(512, 512);
  46. }
  47. DistrhoUIProM::~DistrhoUIProM()
  48. {
  49. if (DistrhoPluginProM* const dspPtr = (DistrhoPluginProM*)d_getPluginInstancePointer())
  50. {
  51. const MutexLocker csm(dspPtr->fMutex);
  52. dspPtr->fPM = nullptr;
  53. }
  54. }
  55. // -----------------------------------------------------------------------
  56. // DSP Callbacks
  57. void DistrhoUIProM::d_parameterChanged(uint32_t, float)
  58. {
  59. }
  60. // -----------------------------------------------------------------------
  61. // UI Callbacks
  62. void DistrhoUIProM::d_uiIdle()
  63. {
  64. if (fPM == nullptr)
  65. return;
  66. repaint();
  67. if (DistrhoPluginProM* const dspPtr = (DistrhoPluginProM*)d_getPluginInstancePointer())
  68. {
  69. if (dspPtr->fPM != nullptr)
  70. return;
  71. const MutexLocker csm(dspPtr->fMutex);
  72. dspPtr->fPM = fPM;
  73. }
  74. }
  75. void DistrhoUIProM::d_uiReshape(uint width, uint height)
  76. {
  77. glEnable(GL_BLEND);
  78. glEnable(GL_LINE_SMOOTH);
  79. glEnable(GL_POINT_SMOOTH);
  80. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  81. glShadeModel(GL_SMOOTH);
  82. glMatrixMode(GL_TEXTURE);
  83. glLoadIdentity();
  84. glMatrixMode(GL_PROJECTION);
  85. glLoadIdentity();
  86. glOrtho(0, width, height, 0, 0.0f, 1.0f);
  87. glViewport(0, 0, width, height);
  88. glMatrixMode(GL_MODELVIEW);
  89. glLoadIdentity();
  90. glDrawBuffer(GL_BACK);
  91. glReadBuffer(GL_BACK);
  92. glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  93. glLineStipple(2, 0xAAAA);
  94. if (fPM == nullptr)
  95. //fPM = new projectM(kSettings);
  96. fPM = new projectM("/usr/share/projectM/config.inp");
  97. fPM->projectM_resetGL(width, height);
  98. }
  99. // -----------------------------------------------------------------------
  100. // Widget Callbacks
  101. void DistrhoUIProM::onDisplay()
  102. {
  103. if (fPM == nullptr)
  104. return;
  105. fPM->renderFrame();
  106. }
  107. bool DistrhoUIProM::onKeyboard(const KeyboardEvent& ev)
  108. {
  109. if (fPM == nullptr)
  110. return false;
  111. if (ev.press && (ev.key == '1' || ev.key == '+' || ev.key == '-'))
  112. {
  113. if (ev.key == '1')
  114. {
  115. if (getWidth() != 512 || getHeight() != 512)
  116. setSize(512, 512);
  117. }
  118. else if (ev.key == '+')
  119. {
  120. /**/ if (getWidth() < 1100 && getHeight() < 1100)
  121. setSize(getWidth()+100, getHeight()+100);
  122. else if (getWidth() != 1100 || getHeight() != 1100)
  123. setSize(1100, 1100);
  124. }
  125. else if (ev.key == '-')
  126. {
  127. /**/ if (getWidth() >= 200 && getHeight() >= 200)
  128. setSize(getWidth()-100, getHeight()-100);
  129. else if (getWidth() != 100 || getHeight() != 100)
  130. setSize(100, 100);
  131. }
  132. return true;
  133. }
  134. projectMKeycode pmKey = PROJECTM_K_NONE;
  135. projectMModifier pmMod = PROJECTM_KMOD_LSHIFT;
  136. if ((ev.key >= PROJECTM_K_0 && ev.key <= PROJECTM_K_9) ||
  137. (ev.key >= PROJECTM_K_A && ev.key <= PROJECTM_K_Z) ||
  138. (ev.key >= PROJECTM_K_a && ev.key <= PROJECTM_K_z))
  139. {
  140. pmKey = static_cast<projectMKeycode>(ev.key);
  141. }
  142. else
  143. {
  144. switch (ev.key)
  145. {
  146. case DGL::CHAR_BACKSPACE:
  147. pmKey = PROJECTM_K_BACKSPACE;
  148. break;
  149. case DGL::CHAR_ESCAPE:
  150. pmKey = PROJECTM_K_ESCAPE;
  151. break;
  152. case DGL::CHAR_DELETE:
  153. pmKey = PROJECTM_K_DELETE;
  154. break;
  155. }
  156. }
  157. if (pmKey == PROJECTM_K_NONE)
  158. return false;
  159. if (ev.mod & DGL::MODIFIER_CTRL)
  160. pmMod = PROJECTM_KMOD_LCTRL;
  161. fPM->key_handler(ev.press ? PROJECTM_KEYUP : PROJECTM_KEYDOWN, pmKey, pmMod);
  162. return true;
  163. }
  164. bool DistrhoUIProM::onSpecial(const SpecialEvent& ev)
  165. {
  166. if (fPM == nullptr)
  167. return false;
  168. projectMKeycode pmKey = PROJECTM_K_NONE;
  169. projectMModifier pmMod = PROJECTM_KMOD_LSHIFT;
  170. switch (ev.key)
  171. {
  172. case DGL::KEY_F1:
  173. pmKey = PROJECTM_K_F1;
  174. break;
  175. case DGL::KEY_F2:
  176. pmKey = PROJECTM_K_F2;
  177. break;
  178. case DGL::KEY_F3:
  179. pmKey = PROJECTM_K_F3;
  180. break;
  181. case DGL::KEY_F4:
  182. pmKey = PROJECTM_K_F4;
  183. break;
  184. case DGL::KEY_F5:
  185. pmKey = PROJECTM_K_F5;
  186. break;
  187. case DGL::KEY_F6:
  188. pmKey = PROJECTM_K_F6;
  189. break;
  190. case DGL::KEY_F7:
  191. pmKey = PROJECTM_K_F7;
  192. break;
  193. case DGL::KEY_F8:
  194. pmKey = PROJECTM_K_F8;
  195. break;
  196. case DGL::KEY_F9:
  197. pmKey = PROJECTM_K_F9;
  198. break;
  199. case DGL::KEY_F10:
  200. pmKey = PROJECTM_K_F10;
  201. break;
  202. case DGL::KEY_F11:
  203. pmKey = PROJECTM_K_F11;
  204. break;
  205. case DGL::KEY_F12:
  206. pmKey = PROJECTM_K_F12;
  207. break;
  208. case DGL::KEY_LEFT:
  209. pmKey = PROJECTM_K_LEFT;
  210. break;
  211. case DGL::KEY_UP:
  212. pmKey = PROJECTM_K_UP;
  213. break;
  214. case DGL::KEY_RIGHT:
  215. pmKey = PROJECTM_K_RIGHT;
  216. break;
  217. case DGL::KEY_DOWN:
  218. pmKey = PROJECTM_K_DOWN;
  219. break;
  220. case DGL::KEY_PAGE_UP:
  221. pmKey = PROJECTM_K_PAGEUP;
  222. break;
  223. case DGL::KEY_PAGE_DOWN:
  224. pmKey = PROJECTM_K_PAGEDOWN;
  225. break;
  226. case DGL::KEY_HOME:
  227. pmKey = PROJECTM_K_HOME;
  228. break;
  229. case DGL::KEY_END:
  230. pmKey = PROJECTM_K_END;
  231. break;
  232. case DGL::KEY_INSERT:
  233. pmKey = PROJECTM_K_INSERT;
  234. break;
  235. case DGL::KEY_SHIFT:
  236. pmKey = PROJECTM_K_LSHIFT;
  237. break;
  238. case DGL::KEY_CTRL:
  239. pmKey = PROJECTM_K_LCTRL;
  240. break;
  241. case DGL::KEY_ALT:
  242. case DGL::KEY_SUPER:
  243. break;
  244. }
  245. if (pmKey == PROJECTM_K_NONE)
  246. return false;
  247. if (ev.mod & DGL::MODIFIER_CTRL)
  248. pmMod = PROJECTM_KMOD_LCTRL;
  249. fPM->key_handler(ev.press ? PROJECTM_KEYUP : PROJECTM_KEYDOWN, pmKey, pmMod);
  250. return true;
  251. }
  252. // -----------------------------------------------------------------------
  253. UI* createUI()
  254. {
  255. return new DistrhoUIProM();
  256. }
  257. // -----------------------------------------------------------------------
  258. END_NAMESPACE_DISTRHO