Lv2Instrument.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Lv2Instrument.h - implementation of LV2 instrument
  3. *
  4. * Copyright (c) 2018-2020 Johannes Lorenz <jlsf2013$users.sourceforge.net, $=@>
  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 LV2_INSTRUMENT_H
  25. #define LV2_INSTRUMENT_H
  26. #include <QString>
  27. #include "Instrument.h"
  28. #include "InstrumentView.h"
  29. #include "Note.h"
  30. #include "Lv2ControlBase.h"
  31. #include "Lv2ViewBase.h"
  32. // whether to use MIDI vs playHandle
  33. // currently only MIDI works
  34. #define LV2_INSTRUMENT_USE_MIDI
  35. class QPushButton;
  36. class Lv2Instrument : public Instrument, public Lv2ControlBase
  37. {
  38. Q_OBJECT
  39. public:
  40. /*
  41. initialization
  42. */
  43. Lv2Instrument(InstrumentTrack *instrumentTrackArg,
  44. Descriptor::SubPluginFeatures::Key* key);
  45. ~Lv2Instrument() override;
  46. //! Must be checked after ctor or reload
  47. bool isValid() const;
  48. /*
  49. load/save
  50. */
  51. void saveSettings(QDomDocument &doc, QDomElement &that) override;
  52. void loadSettings(const QDomElement &that) override;
  53. void loadFile(const QString &file) override;
  54. /*
  55. realtime funcs
  56. */
  57. bool hasNoteInput() const override { return Lv2ControlBase::hasNoteInput(); }
  58. #ifdef LV2_INSTRUMENT_USE_MIDI
  59. bool handleMidiEvent(const MidiEvent &event,
  60. const TimePos &time = TimePos(), f_cnt_t offset = 0) override;
  61. #else
  62. void playNote(NotePlayHandle *nph, sampleFrame *) override;
  63. #endif
  64. void play(sampleFrame *buf) override;
  65. /*
  66. misc
  67. */
  68. Flags flags() const override
  69. {
  70. #ifdef LV2_INSTRUMENT_USE_MIDI
  71. return IsSingleStreamed | IsMidiBased;
  72. #else
  73. return IsSingleStreamed;
  74. #endif
  75. }
  76. PluginView *instantiateView(QWidget *parent) override;
  77. private slots:
  78. void updatePitchRange();
  79. private:
  80. QString nodeName() const override;
  81. DataFile::Types settingsType() override;
  82. void setNameFromFile(const QString &name) override;
  83. #ifdef LV2_INSTRUMENT_USE_MIDI
  84. int m_runningNotes[NumKeys];
  85. #endif
  86. friend class Lv2InsView;
  87. };
  88. class Lv2InsView : public InstrumentView, public Lv2ViewBase
  89. {
  90. Q_OBJECT
  91. public:
  92. Lv2InsView(Lv2Instrument *_instrument, QWidget *_parent);
  93. protected:
  94. void dragEnterEvent(QDragEnterEvent *_dee) override;
  95. void dropEvent(QDropEvent *_de) override;
  96. private:
  97. void modelChanged() override;
  98. };
  99. #endif // LV2_INSTRUMENT_H