carla.h 3.5 KB

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