SampleTrack.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * SampleTrack.h - class SampleTrack, a track which provides arrangement of samples
  3. *
  4. * Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/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 SAMPLE_TRACK_H
  25. #define SAMPLE_TRACK_H
  26. #include <QDialog>
  27. #include <QLayout>
  28. #include "AudioPort.h"
  29. #include "FxMixer.h"
  30. #include "FxLineLcdSpinBox.h"
  31. #include "Track.h"
  32. class EffectRackView;
  33. class Knob;
  34. class SampleBuffer;
  35. class SampleTrackWindow;
  36. class TrackLabelButton;
  37. class QLineEdit;
  38. class SampleTCO : public TrackContentObject
  39. {
  40. Q_OBJECT
  41. mapPropertyFromModel(bool,isRecord,setRecord,m_recordModel);
  42. public:
  43. SampleTCO( Track * _track );
  44. virtual ~SampleTCO();
  45. void changeLength( const MidiTime & _length ) override;
  46. const QString & sampleFile() const;
  47. void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
  48. void loadSettings( const QDomElement & _this ) override;
  49. inline QString nodeName() const override
  50. {
  51. return "sampletco";
  52. }
  53. SampleBuffer* sampleBuffer()
  54. {
  55. return m_sampleBuffer;
  56. }
  57. MidiTime sampleLength() const;
  58. void setSampleStartFrame( f_cnt_t startFrame );
  59. void setSamplePlayLength( f_cnt_t length );
  60. TrackContentObjectView * createView( TrackView * _tv ) override;
  61. bool isPlaying() const;
  62. void setIsPlaying(bool isPlaying);
  63. public slots:
  64. void setSampleBuffer( SampleBuffer* sb );
  65. void setSampleFile( const QString & _sf );
  66. void updateLength();
  67. void toggleRecord();
  68. void playbackPositionChanged();
  69. void updateTrackTcos();
  70. private:
  71. SampleBuffer* m_sampleBuffer;
  72. BoolModel m_recordModel;
  73. bool m_isPlaying;
  74. friend class SampleTCOView;
  75. signals:
  76. void sampleChanged();
  77. } ;
  78. class SampleTCOView : public TrackContentObjectView
  79. {
  80. Q_OBJECT
  81. public:
  82. SampleTCOView( SampleTCO * _tco, TrackView * _tv );
  83. virtual ~SampleTCOView() = default;
  84. public slots:
  85. void updateSample();
  86. protected:
  87. void contextMenuEvent( QContextMenuEvent * _cme ) override;
  88. void mousePressEvent( QMouseEvent * _me ) override;
  89. void mouseReleaseEvent( QMouseEvent * _me ) override;
  90. void dragEnterEvent( QDragEnterEvent * _dee ) override;
  91. void dropEvent( QDropEvent * _de ) override;
  92. void mouseDoubleClickEvent( QMouseEvent * ) override;
  93. void paintEvent( QPaintEvent * ) override;
  94. private:
  95. SampleTCO * m_tco;
  96. QPixmap m_paintPixmap;
  97. } ;
  98. class SampleTrack : public Track
  99. {
  100. Q_OBJECT
  101. public:
  102. SampleTrack( TrackContainer* tc );
  103. virtual ~SampleTrack();
  104. virtual bool play( const MidiTime & _start, const fpp_t _frames,
  105. const f_cnt_t _frame_base, int _tco_num = -1 ) override;
  106. TrackView * createView( TrackContainerView* tcv ) override;
  107. TrackContentObject * createTCO( const MidiTime & _pos ) override;
  108. virtual void saveTrackSpecificSettings( QDomDocument & _doc,
  109. QDomElement & _parent ) override;
  110. void loadTrackSpecificSettings( const QDomElement & _this ) override;
  111. inline IntModel * effectChannelModel()
  112. {
  113. return &m_effectChannelModel;
  114. }
  115. inline AudioPort * audioPort()
  116. {
  117. return &m_audioPort;
  118. }
  119. QString nodeName() const override
  120. {
  121. return "sampletrack";
  122. }
  123. public slots:
  124. void updateTcos();
  125. void setPlayingTcos( bool isPlaying );
  126. void updateEffectChannel();
  127. private:
  128. FloatModel m_volumeModel;
  129. FloatModel m_panningModel;
  130. IntModel m_effectChannelModel;
  131. AudioPort m_audioPort;
  132. friend class SampleTrackView;
  133. friend class SampleTrackWindow;
  134. } ;
  135. class SampleTrackView : public TrackView
  136. {
  137. Q_OBJECT
  138. public:
  139. SampleTrackView( SampleTrack* Track, TrackContainerView* tcv );
  140. virtual ~SampleTrackView();
  141. SampleTrackWindow * getSampleTrackWindow()
  142. {
  143. return m_window;
  144. }
  145. SampleTrack * model()
  146. {
  147. return castModel<SampleTrack>();
  148. }
  149. const SampleTrack * model() const
  150. {
  151. return castModel<SampleTrack>();
  152. }
  153. QMenu * createFxMenu( QString title, QString newFxLabel ) override;
  154. public slots:
  155. void showEffects();
  156. protected:
  157. void modelChanged() override;
  158. QString nodeName() const override
  159. {
  160. return "SampleTrackView";
  161. }
  162. void dragEnterEvent(QDragEnterEvent *dee) override;
  163. void dropEvent(QDropEvent *de) override;
  164. private slots:
  165. void assignFxLine( int channelIndex );
  166. void createFxLine();
  167. private:
  168. SampleTrackWindow * m_window;
  169. Knob * m_volumeKnob;
  170. Knob * m_panningKnob;
  171. TrackLabelButton * m_tlb;
  172. friend class SampleTrackWindow;
  173. } ;
  174. class SampleTrackWindow : public QWidget, public ModelView, public SerializingObjectHook
  175. {
  176. Q_OBJECT
  177. public:
  178. SampleTrackWindow(SampleTrackView * tv);
  179. virtual ~SampleTrackWindow();
  180. SampleTrack * model()
  181. {
  182. return castModel<SampleTrack>();
  183. }
  184. const SampleTrack * model() const
  185. {
  186. return castModel<SampleTrack>();
  187. }
  188. void setSampleTrackView(SampleTrackView * tv);
  189. SampleTrackView *sampleTrackView()
  190. {
  191. return m_stv;
  192. }
  193. public slots:
  194. void textChanged(const QString & new_name);
  195. void toggleVisibility(bool on);
  196. void updateName();
  197. protected:
  198. // capture close-events for toggling sample-track-button
  199. void closeEvent(QCloseEvent * ce) override;
  200. void saveSettings(QDomDocument & doc, QDomElement & element) override;
  201. void loadSettings(const QDomElement & element) override;
  202. private:
  203. void modelChanged() override;
  204. SampleTrack * m_track;
  205. SampleTrackView * m_stv;
  206. // widgets on the top of an sample-track-window
  207. QLineEdit * m_nameLineEdit;
  208. Knob * m_volumeKnob;
  209. Knob * m_panningKnob;
  210. FxLineLcdSpinBox * m_effectChannelNumber;
  211. EffectRackView * m_effectRack;
  212. } ;
  213. #endif