carla.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #define REAL_BUILD // FIXME this shouldn't be needed
  28. #if CARLA_VERSION_HEX >= 0x010911
  29. #include "CarlaNativePlugin.h"
  30. #else
  31. #include "CarlaBackend.h"
  32. #include "CarlaNative.h"
  33. #include "CarlaUtils.h"
  34. CARLA_EXPORT
  35. const NativePluginDescriptor* carla_get_native_patchbay_plugin();
  36. CARLA_EXPORT
  37. const NativePluginDescriptor* carla_get_native_rack_plugin();
  38. #endif
  39. #include "Instrument.h"
  40. #include "InstrumentView.h"
  41. class QPushButton;
  42. class PLUGIN_EXPORT CarlaInstrument : public Instrument
  43. {
  44. Q_OBJECT
  45. public:
  46. static const uint32_t kMaxMidiEvents = 512;
  47. CarlaInstrument(InstrumentTrack* const instrumentTrack, const Descriptor* const descriptor, const bool isPatchbay);
  48. virtual ~CarlaInstrument();
  49. // Carla NativeHostDescriptor functions
  50. uint32_t handleGetBufferSize() const;
  51. double handleGetSampleRate() const;
  52. bool handleIsOffline() const;
  53. const NativeTimeInfo* handleGetTimeInfo() const;
  54. void handleUiParameterChanged(const uint32_t index, const float value) const;
  55. void handleUiClosed();
  56. intptr_t handleDispatcher(const NativeHostDispatcherOpcode opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt);
  57. // LMMS functions
  58. virtual Flags flags() const;
  59. virtual QString nodeName() const;
  60. virtual void saveSettings(QDomDocument& doc, QDomElement& parent);
  61. virtual void loadSettings(const QDomElement& elem);
  62. virtual void play(sampleFrame* workingBuffer);
  63. virtual bool handleMidiEvent(const MidiEvent& event, const MidiTime& time, f_cnt_t offset);
  64. virtual PluginView* instantiateView(QWidget* parent);
  65. signals:
  66. void uiClosed();
  67. private slots:
  68. void sampleRateChanged();
  69. private:
  70. const bool kIsPatchbay;
  71. NativePluginHandle fHandle;
  72. NativeHostDescriptor fHost;
  73. const NativePluginDescriptor* fDescriptor;
  74. uint32_t fMidiEventCount;
  75. NativeMidiEvent fMidiEvents[kMaxMidiEvents];
  76. NativeTimeInfo fTimeInfo;
  77. // this is only needed because note-offs are being sent during play
  78. QMutex fMutex;
  79. friend class CarlaInstrumentView;
  80. };
  81. class CarlaInstrumentView : public InstrumentView
  82. {
  83. Q_OBJECT
  84. public:
  85. CarlaInstrumentView(CarlaInstrument* const instrument, QWidget* const parent);
  86. virtual ~CarlaInstrumentView();
  87. private slots:
  88. void toggleUI(bool);
  89. void uiClosed();
  90. private:
  91. virtual void modelChanged();
  92. virtual void timerEvent(QTimerEvent*);
  93. NativePluginHandle fHandle;
  94. const NativePluginDescriptor* fDescriptor;
  95. int fTimerId;
  96. QPushButton * m_toggleUIButton;
  97. };
  98. #endif