Collection of DPF-based plugins for packaging
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.

143 lines
3.6KB

  1. /*
  2. * DISTRHO glBars Plugin based on XMMS/XBMC "GL Bars"
  3. * Copyright (C) 1998-2000 Peter Alm, Mikael Alm, Olle Hallnas, Thomas Nilsson and 4Front Technologies
  4. * Copyright (C) 2000 Christian Zander <phoenix@minion.de>
  5. * Copyright (C) 2015 Nedko Arnaudov
  6. * Copyright (C) 2016-2019 Filipe Coelho <falktx@falktx.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * For a full copy of the license see the LICENSE file.
  19. */
  20. #include "DistrhoPluginGLBars.hpp"
  21. #include "DistrhoUIGLBars.hpp"
  22. START_NAMESPACE_DISTRHO
  23. // -----------------------------------------------------------------------
  24. DistrhoUIGLBars::DistrhoUIGLBars()
  25. : UI(512, 512),
  26. fInitialized(false)
  27. {
  28. setGeometryConstraints(256, 256, true);
  29. }
  30. DistrhoUIGLBars::~DistrhoUIGLBars()
  31. {
  32. if (! fInitialized)
  33. return;
  34. if (DistrhoPluginGLBars* const dspPtr = (DistrhoPluginGLBars*)getPluginInstancePointer())
  35. {
  36. const MutexLocker csm(dspPtr->fMutex);
  37. dspPtr->fState = nullptr;
  38. }
  39. }
  40. // -----------------------------------------------------------------------
  41. // DSP Callbacks
  42. void DistrhoUIGLBars::parameterChanged(uint32_t index, float value)
  43. {
  44. switch (index)
  45. {
  46. case kParameterScale:
  47. fState.scale = value;
  48. break;
  49. case kParameterSpeed:
  50. fState.hSpeed = value;
  51. break;
  52. case kParameterX:
  53. fState.x_speed = value;
  54. break;
  55. case kParameterY:
  56. fState.y_speed = value;
  57. break;
  58. case kParameterZ:
  59. fState.z_speed = value;
  60. break;
  61. }
  62. }
  63. // -----------------------------------------------------------------------
  64. // UI Callbacks
  65. void DistrhoUIGLBars::uiIdle()
  66. {
  67. repaint();
  68. if (DistrhoPluginGLBars* const dspPtr = (DistrhoPluginGLBars*)getPluginInstancePointer())
  69. {
  70. if (dspPtr->fState != nullptr)
  71. return;
  72. fInitialized = true;
  73. const MutexLocker csm(dspPtr->fMutex);
  74. dspPtr->fState = &fState;
  75. }
  76. }
  77. // -----------------------------------------------------------------------
  78. // Widget Callbacks
  79. void DistrhoUIGLBars::onDisplay()
  80. {
  81. fState.Render();
  82. }
  83. bool DistrhoUIGLBars::onKeyboard(const KeyboardEvent& ev)
  84. {
  85. if (ev.press && (ev.key == '1' || ev.key == '+' || ev.key == '-'))
  86. {
  87. if (ev.key == '1')
  88. {
  89. if (getWidth() != 512 || getHeight() != 512)
  90. setSize(512, 512);
  91. }
  92. else if (ev.key == '+')
  93. {
  94. /**/ if (getWidth() < 1100 && getHeight() < 1100)
  95. setSize(std::min(getWidth()+100, 1100U), std::min(getHeight()+100, 1100U));
  96. else if (getWidth() != 1100 || getHeight() != 1100)
  97. setSize(1100, 1100);
  98. }
  99. else if (ev.key == '-')
  100. {
  101. /**/ if (getWidth() > 100 && getHeight() > 100)
  102. setSize(std::max(getWidth()-100, 100U), std::max(getHeight()-100, 100U));
  103. else if (getWidth() != 100 || getHeight() != 100)
  104. setSize(100, 100);
  105. }
  106. return true;
  107. }
  108. return true;
  109. }
  110. // -----------------------------------------------------------------------
  111. UI* createUI()
  112. {
  113. return new DistrhoUIGLBars();
  114. }
  115. // -----------------------------------------------------------------------
  116. END_NAMESPACE_DISTRHO