DISTRHO ProM
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.

292 lines
7.3KB

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