Pattern.h 3.8 KB

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