Pattern.h 5.0 KB

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