InstrumentTrack.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*
  2. * InstrumentTrack.h - declaration of class InstrumentTrack, a track which
  3. * holds an instrument-plugin
  4. *
  5. * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #ifndef INSTRUMENT_TRACK_H
  26. #define INSTRUMENT_TRACK_H
  27. #include "AudioPort.h"
  28. #include "InstrumentFunctions.h"
  29. #include "InstrumentSoundShaping.h"
  30. #include "Microtuner.h"
  31. #include "Midi.h"
  32. #include "MidiEventProcessor.h"
  33. #include "MidiPort.h"
  34. #include "NotePlayHandle.h"
  35. #include "Piano.h"
  36. #include "Pitch.h"
  37. #include "Plugin.h"
  38. #include "Track.h"
  39. #include "TrackView.h"
  40. class Instrument;
  41. class DataFile;
  42. class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor
  43. {
  44. Q_OBJECT
  45. MM_OPERATORS
  46. mapPropertyFromModel(int,getVolume,setVolume,m_volumeModel);
  47. public:
  48. InstrumentTrack( TrackContainer* tc );
  49. virtual ~InstrumentTrack();
  50. // used by instrument
  51. void processAudioBuffer( sampleFrame * _buf, const fpp_t _frames,
  52. NotePlayHandle * _n );
  53. MidiEvent applyMasterKey( const MidiEvent& event );
  54. void processInEvent( const MidiEvent& event, const TimePos& time = TimePos(), f_cnt_t offset = 0 ) override;
  55. void processOutEvent( const MidiEvent& event, const TimePos& time = TimePos(), f_cnt_t offset = 0 ) override;
  56. // silence all running notes played by this track
  57. void silenceAllNotes( bool removeIPH = false );
  58. bool isSustainPedalPressed() const
  59. {
  60. return m_sustainPedalPressed;
  61. }
  62. f_cnt_t beatLen( NotePlayHandle * _n ) const;
  63. // for capturing note-play-events -> need that for arpeggio,
  64. // filter and so on
  65. void playNote( NotePlayHandle * _n, sampleFrame * _working_buffer );
  66. QString instrumentName() const;
  67. const Instrument *instrument() const
  68. {
  69. return m_instrument;
  70. }
  71. Instrument *instrument()
  72. {
  73. return m_instrument;
  74. }
  75. void deleteNotePluginData( NotePlayHandle * _n );
  76. // name-stuff
  77. void setName( const QString & _new_name ) override;
  78. // translate given key of a note-event to absolute key (i.e.
  79. // add global master-pitch and base-note of this instrument track)
  80. int masterKey( int _midi_key ) const;
  81. // translate pitch to midi-pitch [0,16383]
  82. int midiPitch() const
  83. {
  84. return static_cast<int>( ( ( m_pitchModel.value() + m_pitchModel.range()/2 ) * MidiMaxPitchBend ) / m_pitchModel.range() );
  85. }
  86. /*! \brief Returns current range for pitch bend in semitones */
  87. int midiPitchRange() const
  88. {
  89. return m_pitchRangeModel.value();
  90. }
  91. // play everything in given frame-range - creates note-play-handles
  92. virtual bool play( const TimePos & _start, const fpp_t _frames,
  93. const f_cnt_t _frame_base, int _clip_num = -1 ) override;
  94. // create new view for me
  95. TrackView * createView( TrackContainerView* tcv ) override;
  96. // create new track-content-object = clip
  97. Clip* createClip(const TimePos & pos) override;
  98. // called by track
  99. virtual void saveTrackSpecificSettings( QDomDocument & _doc,
  100. QDomElement & _parent ) override;
  101. void loadTrackSpecificSettings( const QDomElement & _this ) override;
  102. using Track::setJournalling;
  103. // load instrument whose name matches given one
  104. Instrument * loadInstrument(const QString & _instrument_name,
  105. const Plugin::Descriptor::SubPluginFeatures::Key* key = nullptr,
  106. bool keyFromDnd = false);
  107. AudioPort * audioPort()
  108. {
  109. return &m_audioPort;
  110. }
  111. MidiPort * midiPort()
  112. {
  113. return &m_midiPort;
  114. }
  115. const IntModel *baseNoteModel() const
  116. {
  117. return &m_baseNoteModel;
  118. }
  119. IntModel *baseNoteModel()
  120. {
  121. return &m_baseNoteModel;
  122. }
  123. IntModel *firstKeyModel()
  124. {
  125. return &m_firstKeyModel;
  126. }
  127. IntModel *lastKeyModel()
  128. {
  129. return &m_lastKeyModel;
  130. }
  131. bool keyRangeImport() const;
  132. bool isKeyMapped(int key) const;
  133. int firstKey() const;
  134. int lastKey() const;
  135. int baseNote() const;
  136. float baseFreq() const;
  137. Piano *pianoModel()
  138. {
  139. return &m_piano;
  140. }
  141. Microtuner *microtuner()
  142. {
  143. return &m_microtuner;
  144. }
  145. bool isArpeggioEnabled() const
  146. {
  147. return m_arpeggio.m_arpEnabledModel.value();
  148. }
  149. // simple helper for removing midiport-XML-node when loading presets
  150. static void removeMidiPortNode( DataFile& dataFile );
  151. FloatModel * pitchModel()
  152. {
  153. return &m_pitchModel;
  154. }
  155. FloatModel * volumeModel()
  156. {
  157. return &m_volumeModel;
  158. }
  159. FloatModel * panningModel()
  160. {
  161. return &m_panningModel;
  162. }
  163. IntModel* pitchRangeModel()
  164. {
  165. return &m_pitchRangeModel;
  166. }
  167. IntModel * mixerChannelModel()
  168. {
  169. return &m_mixerChannelModel;
  170. }
  171. void setPreviewMode( const bool );
  172. bool isPreviewMode() const
  173. {
  174. return m_previewMode;
  175. }
  176. void replaceInstrument(DataFile dataFile);
  177. void autoAssignMidiDevice( bool );
  178. signals:
  179. void instrumentChanged();
  180. void midiNoteOn( const Note& );
  181. void midiNoteOff( const Note& );
  182. void nameChanged();
  183. void newNote();
  184. void endNote();
  185. protected:
  186. QString nodeName() const override
  187. {
  188. return "instrumenttrack";
  189. }
  190. // get the name of the instrument in the saved data
  191. QString getSavedInstrumentName(const QDomElement & thisElement) const;
  192. protected slots:
  193. void updateBaseNote();
  194. void updatePitch();
  195. void updatePitchRange();
  196. void updateMixerChannel();
  197. private:
  198. void processCCEvent(int controller);
  199. MidiPort m_midiPort;
  200. NotePlayHandle* m_notes[NumKeys];
  201. NotePlayHandleList m_sustainedNotes;
  202. int m_runningMidiNotes[NumKeys];
  203. QMutex m_midiNotesMutex;
  204. bool m_sustainPedalPressed;
  205. bool m_silentBuffersProcessed;
  206. bool m_previewMode;
  207. IntModel m_baseNoteModel; //!< The "A4" or "440 Hz" key (default 69)
  208. IntModel m_firstKeyModel; //!< First key the instrument reacts to
  209. IntModel m_lastKeyModel; //!< Last key the instrument reacts to
  210. bool m_hasAutoMidiDev;
  211. static InstrumentTrack *s_autoAssignedTrack;
  212. NotePlayHandleList m_processHandles;
  213. FloatModel m_volumeModel;
  214. FloatModel m_panningModel;
  215. AudioPort m_audioPort;
  216. FloatModel m_pitchModel;
  217. IntModel m_pitchRangeModel;
  218. IntModel m_mixerChannelModel;
  219. BoolModel m_useMasterPitchModel;
  220. Instrument * m_instrument;
  221. InstrumentSoundShaping m_soundShaping;
  222. InstrumentFunctionArpeggio m_arpeggio;
  223. InstrumentFunctionNoteStacking m_noteStacking;
  224. Piano m_piano;
  225. Microtuner m_microtuner;
  226. std::unique_ptr<BoolModel> m_midiCCEnable;
  227. std::unique_ptr<FloatModel> m_midiCCModel[MidiControllerCount];
  228. friend class InstrumentTrackView;
  229. friend class InstrumentTrackWindow;
  230. friend class NotePlayHandle;
  231. friend class InstrumentMiscView;
  232. friend class MidiCCRackView;
  233. } ;
  234. #endif