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.

305 lines
7.4KB

  1. /*
  2. * DISTRHO ProM Plugin
  3. * Copyright (C) 2015 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(512, 512)
  44. {
  45. }
  46. DistrhoUIProM::~DistrhoUIProM()
  47. {
  48. if (DistrhoPluginProM* const dspPtr = (DistrhoPluginProM*)getPluginInstancePointer())
  49. {
  50. const MutexLocker csm(dspPtr->fMutex);
  51. dspPtr->fPM = nullptr;
  52. }
  53. }
  54. // -----------------------------------------------------------------------
  55. // DSP Callbacks
  56. void DistrhoUIProM::parameterChanged(uint32_t, float)
  57. {
  58. }
  59. // -----------------------------------------------------------------------
  60. // UI Callbacks
  61. void DistrhoUIProM::uiIdle()
  62. {
  63. if (fPM == nullptr)
  64. return;
  65. repaint();
  66. if (DistrhoPluginProM* const dspPtr = (DistrhoPluginProM*)getPluginInstancePointer())
  67. {
  68. if (dspPtr->fPM != nullptr)
  69. return;
  70. const MutexLocker csm(dspPtr->fMutex);
  71. dspPtr->fPM = fPM;
  72. }
  73. }
  74. void DistrhoUIProM::uiReshape(uint width, uint height)
  75. {
  76. glEnable(GL_BLEND);
  77. glEnable(GL_LINE_SMOOTH);
  78. glEnable(GL_POINT_SMOOTH);
  79. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  80. glShadeModel(GL_SMOOTH);
  81. glMatrixMode(GL_TEXTURE);
  82. glLoadIdentity();
  83. glMatrixMode(GL_PROJECTION);
  84. glLoadIdentity();
  85. glOrtho(0, width, height, 0, 0.0f, 1.0f);
  86. glViewport(0, 0, width, height);
  87. glMatrixMode(GL_MODELVIEW);
  88. glLoadIdentity();
  89. glDrawBuffer(GL_BACK);
  90. glReadBuffer(GL_BACK);
  91. glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
  92. glLineStipple(2, 0xAAAA);
  93. if (fPM == nullptr)
  94. //fPM = new projectM(kSettings);
  95. fPM = new projectM("/usr/share/projectM/config.inp");
  96. fPM->projectM_resetGL(width, height);
  97. }
  98. // -----------------------------------------------------------------------
  99. // Widget Callbacks
  100. void DistrhoUIProM::onDisplay()
  101. {
  102. if (fPM == nullptr)
  103. return;
  104. fPM->renderFrame();
  105. }
  106. bool DistrhoUIProM::onKeyboard(const KeyboardEvent& ev)
  107. {
  108. if (fPM == nullptr)
  109. return false;
  110. if (ev.press && (ev.key == '1' || ev.key == '+' || ev.key == '-'))
  111. {
  112. if (ev.key == '1')
  113. {
  114. if (getWidth() != 512 || getHeight() != 512)
  115. setSize(512, 512);
  116. }
  117. else if (ev.key == '+')
  118. {
  119. /**/ if (getWidth() < 1100 && getHeight() < 1100)
  120. setSize(getWidth()+100, getHeight()+100);
  121. else if (getWidth() != 1100 || getHeight() != 1100)
  122. setSize(1100, 1100);
  123. }
  124. else if (ev.key == '-')
  125. {
  126. /**/ if (getWidth() >= 200 && getHeight() >= 200)
  127. setSize(getWidth()-100, getHeight()-100);
  128. else if (getWidth() != 100 || getHeight() != 100)
  129. setSize(100, 100);
  130. }
  131. return true;
  132. }
  133. projectMKeycode pmKey = PROJECTM_K_NONE;
  134. projectMModifier pmMod = PROJECTM_KMOD_LSHIFT;
  135. if ((ev.key >= PROJECTM_K_0 && ev.key <= PROJECTM_K_9) ||
  136. (ev.key >= PROJECTM_K_A && ev.key <= PROJECTM_K_Z) ||
  137. (ev.key >= PROJECTM_K_a && ev.key <= PROJECTM_K_z))
  138. {
  139. pmKey = static_cast<projectMKeycode>(ev.key);
  140. }
  141. else
  142. {
  143. switch (ev.key)
  144. {
  145. case DGL::kCharBackspace:
  146. pmKey = PROJECTM_K_BACKSPACE;
  147. break;
  148. case DGL::kCharEscape:
  149. pmKey = PROJECTM_K_ESCAPE;
  150. break;
  151. case DGL::kCharDelete:
  152. pmKey = PROJECTM_K_DELETE;
  153. break;
  154. }
  155. }
  156. if (pmKey == PROJECTM_K_NONE)
  157. return false;
  158. if (ev.mod & DGL::kModifierControl)
  159. pmMod = PROJECTM_KMOD_LCTRL;
  160. fPM->key_handler(ev.press ? PROJECTM_KEYUP : PROJECTM_KEYDOWN, pmKey, pmMod);
  161. return true;
  162. }
  163. bool DistrhoUIProM::onSpecial(const SpecialEvent& ev)
  164. {
  165. if (fPM == nullptr)
  166. return false;
  167. projectMKeycode pmKey = PROJECTM_K_NONE;
  168. projectMModifier pmMod = PROJECTM_KMOD_LSHIFT;
  169. switch (ev.key)
  170. {
  171. case DGL::kKeyF1:
  172. pmKey = PROJECTM_K_F1;
  173. break;
  174. case DGL::kKeyF2:
  175. pmKey = PROJECTM_K_F2;
  176. break;
  177. case DGL::kKeyF3:
  178. pmKey = PROJECTM_K_F3;
  179. break;
  180. case DGL::kKeyF4:
  181. pmKey = PROJECTM_K_F4;
  182. break;
  183. case DGL::kKeyF5:
  184. pmKey = PROJECTM_K_F5;
  185. break;
  186. case DGL::kKeyF6:
  187. pmKey = PROJECTM_K_F6;
  188. break;
  189. case DGL::kKeyF7:
  190. pmKey = PROJECTM_K_F7;
  191. break;
  192. case DGL::kKeyF8:
  193. pmKey = PROJECTM_K_F8;
  194. break;
  195. case DGL::kKeyF9:
  196. pmKey = PROJECTM_K_F9;
  197. break;
  198. case DGL::kKeyF10:
  199. pmKey = PROJECTM_K_F10;
  200. break;
  201. case DGL::kKeyF11:
  202. pmKey = PROJECTM_K_F11;
  203. break;
  204. case DGL::kKeyF12:
  205. pmKey = PROJECTM_K_F12;
  206. break;
  207. case DGL::kKeyLeft:
  208. pmKey = PROJECTM_K_LEFT;
  209. break;
  210. case DGL::kKeyUp:
  211. pmKey = PROJECTM_K_UP;
  212. break;
  213. case DGL::kKeyRight:
  214. pmKey = PROJECTM_K_RIGHT;
  215. break;
  216. case DGL::kKeyDown:
  217. pmKey = PROJECTM_K_DOWN;
  218. break;
  219. case DGL::kKeyPageUp:
  220. pmKey = PROJECTM_K_PAGEUP;
  221. break;
  222. case DGL::kKeyPageDown:
  223. pmKey = PROJECTM_K_PAGEDOWN;
  224. break;
  225. case DGL::kKeyHome:
  226. pmKey = PROJECTM_K_HOME;
  227. break;
  228. case DGL::kKeyEnd:
  229. pmKey = PROJECTM_K_END;
  230. break;
  231. case DGL::kKeyInsert:
  232. pmKey = PROJECTM_K_INSERT;
  233. break;
  234. case DGL::kKeyShift:
  235. pmKey = PROJECTM_K_LSHIFT;
  236. break;
  237. case DGL::kKeyControl:
  238. pmKey = PROJECTM_K_LCTRL;
  239. break;
  240. case DGL::kKeyAlt:
  241. case DGL::kKeySuper:
  242. break;
  243. }
  244. if (pmKey == PROJECTM_K_NONE)
  245. return false;
  246. if (ev.mod & DGL::kModifierControl)
  247. pmMod = PROJECTM_KMOD_LCTRL;
  248. fPM->key_handler(ev.press ? PROJECTM_KEYUP : PROJECTM_KEYDOWN, pmKey, pmMod);
  249. return true;
  250. }
  251. // -----------------------------------------------------------------------
  252. UI* createUI()
  253. {
  254. return new DistrhoUIProM();
  255. }
  256. // -----------------------------------------------------------------------
  257. END_NAMESPACE_DISTRHO