Lv2Instrument.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 Lv2Instrument : public Instrument, public Lv2ControlBase
  36. {
  37. Q_OBJECT
  38. public:
  39. /*
  40. initialization
  41. */
  42. Lv2Instrument(InstrumentTrack *instrumentTrackArg,
  43. Descriptor::SubPluginFeatures::Key* key);
  44. ~Lv2Instrument() override;
  45. //! Must be checked after ctor or reload
  46. bool isValid() const;
  47. /*
  48. load/save
  49. */
  50. void saveSettings(QDomDocument &doc, QDomElement &that) override;
  51. void loadSettings(const QDomElement &that) override;
  52. void loadFile(const QString &file) override;
  53. /*
  54. realtime funcs
  55. */
  56. bool hasNoteInput() const override { return Lv2ControlBase::hasNoteInput(); }
  57. #ifdef LV2_INSTRUMENT_USE_MIDI
  58. bool handleMidiEvent(const MidiEvent &event,
  59. const TimePos &time = TimePos(), f_cnt_t offset = 0) override;
  60. #else
  61. void playNote(NotePlayHandle *nph, sampleFrame *) override;
  62. #endif
  63. void play(sampleFrame *buf) override;
  64. /*
  65. misc
  66. */
  67. Flags flags() const override
  68. {
  69. #ifdef LV2_INSTRUMENT_USE_MIDI
  70. return IsSingleStreamed | IsMidiBased;
  71. #else
  72. return IsSingleStreamed;
  73. #endif
  74. }
  75. PluginView *instantiateView(QWidget *parent) override;
  76. private slots:
  77. void updatePitchRange();
  78. private:
  79. QString nodeName() const override;
  80. DataFile::Types settingsType() override;
  81. void setNameFromFile(const QString &name) override;
  82. #ifdef LV2_INSTRUMENT_USE_MIDI
  83. int m_runningNotes[NumKeys];
  84. #endif
  85. friend class Lv2InsView;
  86. };
  87. class Lv2InsView : public InstrumentView, public Lv2ViewBase
  88. {
  89. Q_OBJECT
  90. public:
  91. Lv2InsView(Lv2Instrument *_instrument, QWidget *_parent);
  92. protected:
  93. void dragEnterEvent(QDragEnterEvent *_dee) override;
  94. void dropEvent(QDropEvent *_de) override;
  95. private:
  96. void modelChanged() override;
  97. };
  98. #endif // LV2_INSTRUMENT_H