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.

105 lines
3.5KB

  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, bbtValid;
  35. int32_t bar, beat, beatsPerBar, beatType;
  36. uint64_t frame;
  37. double barStartTick, beatsPerMinute;
  38. double tick, tickClock, ticksPerBeat, ticksPerClock, ticksPerFrame;
  39. uintptr_t nativeWindowId;
  40. Plugin* const plugin;
  41. CardinalPluginContext(Plugin* const p)
  42. : bufferSize(p->getBufferSize()),
  43. sampleRate(p->getSampleRate()),
  44. playing(false),
  45. reset(false),
  46. bbtValid(false),
  47. bar(1),
  48. beat(1),
  49. beatsPerBar(4),
  50. beatType(4),
  51. frame(0),
  52. barStartTick(0.0),
  53. beatsPerMinute(120.0),
  54. tick(0.0),
  55. tickClock(0.0),
  56. ticksPerBeat(0.0),
  57. ticksPerClock(0.0),
  58. ticksPerFrame(0.0),
  59. nativeWindowId(0),
  60. plugin(p)
  61. {
  62. std::memset(parameters, 0, sizeof(parameters));
  63. }
  64. };
  65. // -----------------------------------------------------------------------------------------------------------
  66. struct CardinalAudioDevice;
  67. struct CardinalMidiInputDevice;
  68. struct CardinalMidiOutputDevice;
  69. class CardinalBasePlugin : public Plugin {
  70. public:
  71. CardinalPluginContext* const context;
  72. CardinalBasePlugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount)
  73. : Plugin(parameterCount, programCount, stateCount),
  74. context(new CardinalPluginContext(this)) {}
  75. ~CardinalBasePlugin() override {}
  76. virtual bool isActive() const noexcept = 0;
  77. virtual bool canAssignAudioDevice() const noexcept = 0;
  78. virtual bool canAssignMidiInputDevice() const noexcept = 0;
  79. virtual bool canAssignMidiOutputDevice() const noexcept = 0;
  80. virtual void assignAudioDevice(CardinalAudioDevice* dev) noexcept = 0;
  81. virtual void assignMidiInputDevice(CardinalMidiInputDevice* dev) noexcept = 0;
  82. virtual void assignMidiOutputDevice(CardinalMidiOutputDevice* dev) noexcept = 0;
  83. virtual bool clearAudioDevice(CardinalAudioDevice* dev) noexcept = 0;
  84. virtual bool clearMidiInputDevice(CardinalMidiInputDevice* dev) noexcept = 0;
  85. virtual bool clearMidiOutputDevice(CardinalMidiOutputDevice* dev) noexcept = 0;
  86. };
  87. // -----------------------------------------------------------------------------------------------------------
  88. END_NAMESPACE_DISTRHO