carla.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * carla.h - Carla for LMMS
  3. *
  4. * Copyright (C) 2014-2018 Filipe Coelho <falktx@falktx.com>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) 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 GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef CARLA_H
  25. #define CARLA_H
  26. #include <QtCore/QMutex>
  27. #include "plugin_export.h"
  28. #include "CarlaNative.h"
  29. #define REAL_BUILD // FIXME this shouldn't be needed
  30. #if CARLA_VERSION_HEX >= 0x010911
  31. #include "CarlaNativePlugin.h"
  32. #else
  33. #include "CarlaBackend.h"
  34. #include "CarlaNative.h"
  35. #include "CarlaUtils.h"
  36. CARLA_EXPORT
  37. const NativePluginDescriptor* carla_get_native_patchbay_plugin();
  38. CARLA_EXPORT
  39. const NativePluginDescriptor* carla_get_native_rack_plugin();
  40. #endif
  41. #include "Instrument.h"
  42. #include "InstrumentView.h"
  43. class QPushButton;
  44. class PLUGIN_EXPORT CarlaInstrument : public Instrument
  45. {
  46. Q_OBJECT
  47. public:
  48. static const uint32_t kMaxMidiEvents = 512;
  49. CarlaInstrument(InstrumentTrack* const instrumentTrack, const Descriptor* const descriptor, const bool isPatchbay);
  50. virtual ~CarlaInstrument();
  51. // Carla NativeHostDescriptor functions
  52. uint32_t handleGetBufferSize() const;
  53. double handleGetSampleRate() const;
  54. bool handleIsOffline() const;
  55. const NativeTimeInfo* handleGetTimeInfo() const;
  56. void handleUiParameterChanged(const uint32_t index, const float value) const;
  57. void handleUiClosed();
  58. intptr_t handleDispatcher(const NativeHostDispatcherOpcode opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt);
  59. // LMMS functions
  60. virtual Flags flags() const;
  61. virtual QString nodeName() const;
  62. virtual void saveSettings(QDomDocument& doc, QDomElement& parent);
  63. virtual void loadSettings(const QDomElement& elem);
  64. virtual void play(sampleFrame* workingBuffer);
  65. virtual bool handleMidiEvent(const MidiEvent& event, const MidiTime& time, f_cnt_t offset);
  66. virtual PluginView* instantiateView(QWidget* parent);
  67. signals:
  68. void uiClosed();
  69. private slots:
  70. void sampleRateChanged();
  71. private:
  72. const bool kIsPatchbay;
  73. NativePluginHandle fHandle;
  74. NativeHostDescriptor fHost;
  75. const NativePluginDescriptor* fDescriptor;
  76. uint32_t fMidiEventCount;
  77. NativeMidiEvent fMidiEvents[kMaxMidiEvents];
  78. NativeTimeInfo fTimeInfo;
  79. // this is only needed because note-offs are being sent during play
  80. QMutex fMutex;
  81. friend class CarlaInstrumentView;
  82. };
  83. class CarlaInstrumentView : public InstrumentViewFixedSize
  84. {
  85. Q_OBJECT
  86. public:
  87. CarlaInstrumentView(CarlaInstrument* const instrument, QWidget* const parent);
  88. virtual ~CarlaInstrumentView();
  89. private slots:
  90. void toggleUI(bool);
  91. void uiClosed();
  92. private:
  93. virtual void modelChanged();
  94. virtual void timerEvent(QTimerEvent*);
  95. NativePluginHandle fHandle;
  96. const NativePluginDescriptor* fDescriptor;
  97. int fTimerId;
  98. QPushButton * m_toggleUIButton;
  99. };
  100. #endif