Pattern.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Pattern.h - declaration of class Pattern, which contains all information
  3. * about a pattern
  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 PATTERN_H
  26. #define PATTERN_H
  27. #include <QtCore/QVector>
  28. #include <QWidget>
  29. #include <QDialog>
  30. #include <QPixmap>
  31. #include <QStaticText>
  32. #include "Note.h"
  33. #include "Track.h"
  34. class QAction;
  35. class QProgressBar;
  36. class QPushButton;
  37. class InstrumentTrack;
  38. class SampleBuffer;
  39. class LMMS_EXPORT Pattern : public TrackContentObject
  40. {
  41. Q_OBJECT
  42. public:
  43. enum PatternTypes
  44. {
  45. BeatPattern,
  46. MelodyPattern
  47. } ;
  48. Pattern( InstrumentTrack* instrumentTrack );
  49. Pattern( const Pattern& other );
  50. virtual ~Pattern();
  51. void init();
  52. void updateLength();
  53. // note management
  54. Note * addNote( const Note & _new_note, const bool _quant_pos = true );
  55. void removeNote( Note * _note_to_del );
  56. Note * noteAtStep( int _step );
  57. void rearrangeAllNotes();
  58. void clearNotes();
  59. inline const NoteVector & notes() const
  60. {
  61. return m_notes;
  62. }
  63. Note * addStepNote( int step );
  64. void setStep( int step, bool enabled );
  65. // pattern-type stuff
  66. inline PatternTypes type() const
  67. {
  68. return m_patternType;
  69. }
  70. // next/previous track based on position in the containing track
  71. Pattern * previousPattern() const;
  72. Pattern * nextPattern() const;
  73. // settings-management
  74. void saveSettings( QDomDocument & _doc, QDomElement & _parent ) override;
  75. void loadSettings( const QDomElement & _this ) override;
  76. inline QString nodeName() const override
  77. {
  78. return "pattern";
  79. }
  80. inline InstrumentTrack * instrumentTrack() const
  81. {
  82. return m_instrumentTrack;
  83. }
  84. bool empty();
  85. TrackContentObjectView * createView( TrackView * _tv ) override;
  86. using Model::dataChanged;
  87. protected:
  88. void updateBBTrack();
  89. protected slots:
  90. void addSteps();
  91. void cloneSteps();
  92. void removeSteps();
  93. void clear();
  94. void changeTimeSignature();
  95. private:
  96. MidiTime beatPatternLength() const;
  97. void setType( PatternTypes _new_pattern_type );
  98. void checkType();
  99. void resizeToFirstTrack();
  100. InstrumentTrack * m_instrumentTrack;
  101. PatternTypes m_patternType;
  102. // data-stuff
  103. NoteVector m_notes;
  104. int m_steps;
  105. Pattern * adjacentPatternByOffset(int offset) const;
  106. friend class PatternView;
  107. friend class BBTrackContainerView;
  108. signals:
  109. void destroyedPattern( Pattern* );
  110. } ;
  111. class PatternView : public TrackContentObjectView
  112. {
  113. Q_OBJECT
  114. public:
  115. PatternView( Pattern* pattern, TrackView* parent );
  116. virtual ~PatternView() = default;
  117. Q_PROPERTY(QColor noteFillColor READ getNoteFillColor WRITE setNoteFillColor)
  118. Q_PROPERTY(QColor noteBorderColor READ getNoteBorderColor WRITE setNoteBorderColor)
  119. Q_PROPERTY(QColor mutedNoteFillColor READ getMutedNoteFillColor WRITE setMutedNoteFillColor)
  120. Q_PROPERTY(QColor mutedNoteBorderColor READ getMutedNoteBorderColor WRITE setMutedNoteBorderColor)
  121. QColor const & getNoteFillColor() const { return m_noteFillColor; }
  122. void setNoteFillColor(QColor const & color) { m_noteFillColor = color; }
  123. QColor const & getNoteBorderColor() const { return m_noteBorderColor; }
  124. void setNoteBorderColor(QColor const & color) { m_noteBorderColor = color; }
  125. QColor const & getMutedNoteFillColor() const { return m_mutedNoteFillColor; }
  126. void setMutedNoteFillColor(QColor const & color) { m_mutedNoteFillColor = color; }
  127. QColor const & getMutedNoteBorderColor() const { return m_mutedNoteBorderColor; }
  128. void setMutedNoteBorderColor(QColor const & color) { m_mutedNoteBorderColor = color; }
  129. public slots:
  130. void update() override;
  131. protected slots:
  132. void openInPianoRoll();
  133. void setGhostInPianoRoll();
  134. void resetName();
  135. void changeName();
  136. protected:
  137. void constructContextMenu( QMenu * ) override;
  138. void mousePressEvent( QMouseEvent * _me ) override;
  139. void mouseDoubleClickEvent( QMouseEvent * _me ) override;
  140. void paintEvent( QPaintEvent * pe ) override;
  141. void wheelEvent( QWheelEvent * _we ) override;
  142. private:
  143. static QPixmap * s_stepBtnOn0;
  144. static QPixmap * s_stepBtnOn200;
  145. static QPixmap * s_stepBtnOff;
  146. static QPixmap * s_stepBtnOffLight;
  147. Pattern* m_pat;
  148. QPixmap m_paintPixmap;
  149. QColor m_noteFillColor;
  150. QColor m_noteBorderColor;
  151. QColor m_mutedNoteFillColor;
  152. QColor m_mutedNoteBorderColor;
  153. QStaticText m_staticTextName;
  154. } ;
  155. #endif