BBTrack.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * BBTrack.h - class BBTrack, a wrapper for using bbEditor
  3. * (which is a singleton-class) as track
  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 BB_TRACK_H
  26. #define BB_TRACK_H
  27. #include <QtCore/QObject>
  28. #include <QtCore/QMap>
  29. #include <QStaticText>
  30. #include "Track.h"
  31. class TrackLabelButton;
  32. class TrackContainer;
  33. class BBTCO : public TrackContentObject
  34. {
  35. public:
  36. BBTCO( Track * _track );
  37. virtual ~BBTCO() = default;
  38. void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
  39. void loadSettings( const QDomElement & _this ) override;
  40. inline QString nodeName() const override
  41. {
  42. return( "bbtco" );
  43. }
  44. unsigned int color() const
  45. {
  46. return( m_color.rgb() );
  47. }
  48. QColor colorObj() const
  49. {
  50. return m_color;
  51. }
  52. void setColor( const QColor & c )
  53. {
  54. m_color = QColor( c );
  55. }
  56. void setUseStyleColor( bool b )
  57. {
  58. m_useStyleColor = b;
  59. }
  60. int bbTrackIndex();
  61. TrackContentObjectView * createView( TrackView * _tv ) override;
  62. private:
  63. QColor m_color;
  64. bool m_useStyleColor;
  65. friend class BBTCOView;
  66. } ;
  67. class BBTCOView : public TrackContentObjectView
  68. {
  69. Q_OBJECT
  70. public:
  71. BBTCOView( TrackContentObject * _tco, TrackView * _tv );
  72. virtual ~BBTCOView() = default;
  73. QColor color() const
  74. {
  75. return( m_bbTCO->m_color );
  76. }
  77. void setColor( QColor _new_color );
  78. public slots:
  79. void update() override;
  80. protected slots:
  81. void openInBBEditor();
  82. void resetName();
  83. void changeName();
  84. void changeColor();
  85. void resetColor();
  86. protected:
  87. void paintEvent( QPaintEvent * pe ) override;
  88. void mouseDoubleClickEvent( QMouseEvent * _me ) override;
  89. void constructContextMenu( QMenu * ) override;
  90. private:
  91. BBTCO * m_bbTCO;
  92. QPixmap m_paintPixmap;
  93. QStaticText m_staticTextName;
  94. } ;
  95. class LMMS_EXPORT BBTrack : public Track
  96. {
  97. Q_OBJECT
  98. public:
  99. BBTrack( TrackContainer* tc );
  100. virtual ~BBTrack();
  101. virtual bool play( const MidiTime & _start, const fpp_t _frames,
  102. const f_cnt_t _frame_base, int _tco_num = -1 ) override;
  103. TrackView * createView( TrackContainerView* tcv ) override;
  104. TrackContentObject * createTCO( const MidiTime & _pos ) override;
  105. virtual void saveTrackSpecificSettings( QDomDocument & _doc,
  106. QDomElement & _parent ) override;
  107. void loadTrackSpecificSettings( const QDomElement & _this ) override;
  108. static BBTrack * findBBTrack( int _bb_num );
  109. static void swapBBTracks( Track * _track1, Track * _track2 );
  110. int index()
  111. {
  112. return s_infoMap[this];
  113. }
  114. bool automationDisabled( Track * _track )
  115. {
  116. return( m_disabledTracks.contains( _track ) );
  117. }
  118. void disableAutomation( Track * _track )
  119. {
  120. m_disabledTracks.append( _track );
  121. }
  122. void enableAutomation( Track * _track )
  123. {
  124. m_disabledTracks.removeAll( _track );
  125. }
  126. static void setLastTCOColor( const QColor & c )
  127. {
  128. if( ! s_lastTCOColor )
  129. {
  130. s_lastTCOColor = new QColor( c );
  131. }
  132. else
  133. {
  134. *s_lastTCOColor = QColor( c );
  135. }
  136. }
  137. static void clearLastTCOColor()
  138. {
  139. if( s_lastTCOColor )
  140. {
  141. delete s_lastTCOColor;
  142. }
  143. s_lastTCOColor = NULL;
  144. }
  145. protected:
  146. inline QString nodeName() const override
  147. {
  148. return( "bbtrack" );
  149. }
  150. private:
  151. QList<Track *> m_disabledTracks;
  152. typedef QMap<BBTrack *, int> infoMap;
  153. static infoMap s_infoMap;
  154. static QColor * s_lastTCOColor;
  155. friend class BBTrackView;
  156. } ;
  157. class BBTrackView : public TrackView
  158. {
  159. Q_OBJECT
  160. public:
  161. BBTrackView( BBTrack* bbt, TrackContainerView* tcv );
  162. virtual ~BBTrackView();
  163. bool close() override;
  164. const BBTrack * getBBTrack() const
  165. {
  166. return( m_bbTrack );
  167. }
  168. public slots:
  169. void clickedTrackLabel();
  170. private:
  171. BBTrack * m_bbTrack;
  172. TrackLabelButton * m_trackLabel;
  173. } ;
  174. #endif