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.

96 lines
3.2KB

  1. /*
  2. * DISTRHO Cardinal Plugin
  3. * Copyright (C) 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 General Public License as
  7. * published by the Free Software Foundation; either version 3 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the LICENSE file.
  16. */
  17. #pragma once
  18. #include <audio.hpp>
  19. #include <context.hpp>
  20. #include <midi.hpp>
  21. #ifdef NDEBUG
  22. # undef DEBUG
  23. #endif
  24. #include "DistrhoPlugin.hpp"
  25. #include "extra/Mutex.hpp"
  26. START_NAMESPACE_DISTRHO
  27. // -----------------------------------------------------------------------------------------------------------
  28. static constexpr const uint kModuleParameters = 24;
  29. // -----------------------------------------------------------------------------------------------------------
  30. struct CardinalPluginContext : rack::Context {
  31. uint32_t bufferSize;
  32. double sampleRate;
  33. float parameters[kModuleParameters];
  34. bool playing, reset;
  35. int32_t bar, beat, beatsPerBar;
  36. double tick, tickClock, ticksPerBeat, ticksPerClock, ticksPerFrame;
  37. Plugin* const plugin;
  38. CardinalPluginContext(Plugin* const p)
  39. : bufferSize(p->getBufferSize()),
  40. sampleRate(p->getSampleRate()),
  41. playing(false),
  42. reset(false),
  43. bar(0),
  44. beat(0),
  45. beatsPerBar(0),
  46. tick(0.0),
  47. tickClock(0.0),
  48. ticksPerBeat(0.0),
  49. ticksPerClock(0.0),
  50. ticksPerFrame(0.0),
  51. plugin(p)
  52. {
  53. std::memset(parameters, 0, sizeof(parameters));
  54. }
  55. };
  56. // -----------------------------------------------------------------------------------------------------------
  57. struct CardinalAudioDevice;
  58. struct CardinalMidiInputDevice;
  59. struct CardinalMidiOutputDevice;
  60. class CardinalBasePlugin : public Plugin {
  61. public:
  62. CardinalPluginContext* const context;
  63. CardinalBasePlugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount)
  64. : Plugin(parameterCount, programCount, stateCount),
  65. context(new CardinalPluginContext(this)) {}
  66. ~CardinalBasePlugin() override {}
  67. virtual bool isActive() const noexcept = 0;
  68. virtual bool canAssignAudioDevice() const noexcept = 0;
  69. virtual bool canAssignMidiInputDevice() const noexcept = 0;
  70. virtual bool canAssignMidiOutputDevice() const noexcept = 0;
  71. virtual void assignAudioDevice(CardinalAudioDevice* dev) noexcept = 0;
  72. virtual void assignMidiInputDevice(CardinalMidiInputDevice* dev) noexcept = 0;
  73. virtual void assignMidiOutputDevice(CardinalMidiOutputDevice* dev) noexcept = 0;
  74. virtual bool clearAudioDevice(CardinalAudioDevice* dev) noexcept = 0;
  75. virtual bool clearMidiInputDevice(CardinalMidiInputDevice* dev) noexcept = 0;
  76. virtual bool clearMidiOutputDevice(CardinalMidiOutputDevice* dev) noexcept = 0;
  77. };
  78. // -----------------------------------------------------------------------------------------------------------
  79. END_NAMESPACE_DISTRHO