SampleTrack.h 6.4 KB

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