Track.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * Track.h - declaration of Track class
  3. *
  4. * Copyright (c) 2004-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 TRACK_H
  25. #define TRACK_H
  26. #include <QtCore/QVector>
  27. #include <QColor>
  28. #include "AutomatableModel.h"
  29. #include "JournallingObject.h"
  30. #include "lmms_basics.h"
  31. class TimePos;
  32. class TrackContainer;
  33. class TrackContainerView;
  34. class Clip;
  35. class TrackView;
  36. /*! The minimum track height in pixels
  37. *
  38. * Tracks can be resized by shift-dragging anywhere inside the track
  39. * display. This sets the minimum size in pixels for a track.
  40. */
  41. const int MINIMAL_TRACK_HEIGHT = 32;
  42. const int DEFAULT_TRACK_HEIGHT = 32;
  43. char const *const FILENAME_FILTER = "[\\0000-\x1f\"*/:<>?\\\\|\x7f]";
  44. //! Base-class for all tracks
  45. class LMMS_EXPORT Track : public Model, public JournallingObject
  46. {
  47. Q_OBJECT
  48. MM_OPERATORS
  49. mapPropertyFromModel(bool,isMuted,setMuted,m_mutedModel);
  50. mapPropertyFromModel(bool,isSolo,setSolo,m_soloModel);
  51. public:
  52. typedef QVector<Clip *> clipVector;
  53. enum TrackTypes
  54. {
  55. InstrumentTrack,
  56. PatternTrack,
  57. SampleTrack,
  58. EventTrack,
  59. VideoTrack,
  60. AutomationTrack,
  61. HiddenAutomationTrack,
  62. NumTrackTypes
  63. } ;
  64. Track( TrackTypes type, TrackContainer * tc );
  65. virtual ~Track();
  66. static Track * create( TrackTypes tt, TrackContainer * tc );
  67. static Track * create( const QDomElement & element,
  68. TrackContainer * tc );
  69. Track * clone();
  70. // pure virtual functions
  71. TrackTypes type() const
  72. {
  73. return m_type;
  74. }
  75. virtual bool play( const TimePos & start, const fpp_t frames,
  76. const f_cnt_t frameBase, int clipNum = -1 ) = 0;
  77. virtual TrackView * createView( TrackContainerView * view ) = 0;
  78. virtual Clip * createClip( const TimePos & pos ) = 0;
  79. virtual void saveTrackSpecificSettings( QDomDocument & doc,
  80. QDomElement & parent ) = 0;
  81. virtual void loadTrackSpecificSettings( const QDomElement & element ) = 0;
  82. void saveSettings( QDomDocument & doc, QDomElement & element ) override;
  83. void loadSettings( const QDomElement & element ) override;
  84. void setSimpleSerializing()
  85. {
  86. m_simpleSerializingMode = true;
  87. }
  88. // -- for usage by Clip only ---------------
  89. Clip * addClip( Clip * clip );
  90. void removeClip( Clip * clip );
  91. // -------------------------------------------------------
  92. void deleteClips();
  93. int numOfClips();
  94. Clip * getClip( int clipNum );
  95. int getClipNum(const Clip* clip );
  96. const clipVector & getClips() const
  97. {
  98. return m_clips;
  99. }
  100. void getClipsInRange( clipVector & clipV, const TimePos & start,
  101. const TimePos & end );
  102. void swapPositionOfClips( int clipNum1, int clipNum2 );
  103. void createClipsForPattern(int pattern);
  104. void insertBar( const TimePos & pos );
  105. void removeBar( const TimePos & pos );
  106. bar_t length() const;
  107. inline TrackContainer* trackContainer() const
  108. {
  109. return m_trackContainer;
  110. }
  111. // name-stuff
  112. virtual const QString & name() const
  113. {
  114. return m_name;
  115. }
  116. QString displayName() const override
  117. {
  118. return name();
  119. }
  120. using Model::dataChanged;
  121. inline int getHeight()
  122. {
  123. return m_height >= MINIMAL_TRACK_HEIGHT
  124. ? m_height
  125. : DEFAULT_TRACK_HEIGHT;
  126. }
  127. inline void setHeight( int height )
  128. {
  129. m_height = height;
  130. }
  131. void lock()
  132. {
  133. m_processingLock.lock();
  134. }
  135. void unlock()
  136. {
  137. m_processingLock.unlock();
  138. }
  139. bool tryLock()
  140. {
  141. return m_processingLock.tryLock();
  142. }
  143. QColor color()
  144. {
  145. return m_color;
  146. }
  147. bool useColor()
  148. {
  149. return m_hasColor;
  150. }
  151. bool isMutedBeforeSolo() const
  152. {
  153. return m_mutedBeforeSolo;
  154. }
  155. BoolModel* getMutedModel();
  156. public slots:
  157. virtual void setName( const QString & newName )
  158. {
  159. m_name = newName;
  160. emit nameChanged();
  161. }
  162. void setMutedBeforeSolo(const bool muted)
  163. {
  164. m_mutedBeforeSolo = muted;
  165. }
  166. void toggleSolo();
  167. void setColor(const QColor& c);
  168. void resetColor();
  169. private:
  170. TrackContainer* m_trackContainer;
  171. TrackTypes m_type;
  172. QString m_name;
  173. int m_height;
  174. protected:
  175. BoolModel m_mutedModel;
  176. private:
  177. BoolModel m_soloModel;
  178. bool m_mutedBeforeSolo;
  179. bool m_simpleSerializingMode;
  180. clipVector m_clips;
  181. QMutex m_processingLock;
  182. QColor m_color;
  183. bool m_hasColor;
  184. friend class TrackView;
  185. signals:
  186. void destroyedTrack();
  187. void nameChanged();
  188. void clipAdded( Clip * );
  189. void colorChanged();
  190. } ;
  191. #endif