Updated SWH plugins and added missing hermes_filter plugin
[lmms/mlankhorst.git] / include / pattern.h
blob4f8b9953f1923908b8bc9c20e54a3a1830a967f6
1 /*
2 * pattern.h - declaration of class pattern, which contains all informations
3 * about a pattern
5 * Copyright (c) 2004-2011 Tobias Doerffel <tobydox/at/users.sourceforge.net>
7 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
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.
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.
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.
26 #ifndef _PATTERN_H
27 #define _PATTERN_H
29 #include <QtCore/QVector>
30 #include <QtGui/QWidget>
31 #include <QtGui/QDialog>
32 #include <QtCore/QThread>
33 #include <QtGui/QPixmap>
36 #include "note.h"
37 #include "track.h"
40 class QAction;
41 class QProgressBar;
42 class QPushButton;
44 class InstrumentTrack;
45 class patternFreezeThread;
46 class sampleBuffer;
50 class EXPORT pattern : public trackContentObject
52 Q_OBJECT
53 public:
54 enum PatternTypes
56 BeatPattern,
57 MelodyPattern
58 } ;
60 pattern( InstrumentTrack * _instrument_track );
61 pattern( const pattern & _pat_to_copy );
62 virtual ~pattern();
64 void init();
67 virtual midiTime length() const;
68 midiTime beatPatternLength() const;
70 // note management
71 note * addNote( const note & _new_note, const bool _quant_pos = true );
73 void removeNote( const note * _note_to_del );
75 note * rearrangeNote( const note * _note_to_proc,
76 const bool _quant_pos = true );
77 void rearrangeAllNotes();
78 void clearNotes();
80 inline const NoteVector & notes() const
82 return m_notes;
85 void setStep( int _step, bool _enabled );
87 // pattern-type stuff
88 inline PatternTypes type() const
90 return m_patternType;
92 void setType( PatternTypes _new_pattern_type );
93 void checkType();
96 // functions which are part of freezing-feature
97 inline bool isFreezing() const
99 return m_freezing;
102 inline bool isFrozen() const
104 return m_frozenPattern != NULL;
107 sampleBuffer *frozenPattern()
109 return m_frozenPattern;
112 // settings-management
113 virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
114 virtual void loadSettings( const QDomElement & _this );
115 inline virtual QString nodeName() const
117 return "pattern";
120 inline InstrumentTrack * instrumentTrack() const
122 return m_instrumentTrack;
125 bool empty();
128 void addSteps( int _n );
129 void removeSteps( int _n );
131 virtual trackContentObjectView * createView( trackView * _tv );
134 using Model::dataChanged;
137 protected:
138 void ensureBeatNotes();
139 void updateBBTrack();
142 protected slots:
143 void clear();
144 void freeze();
145 void unfreeze();
146 void abortFreeze();
147 void changeTimeSignature();
150 private:
151 InstrumentTrack * m_instrumentTrack;
153 PatternTypes m_patternType;
155 // data-stuff
156 NoteVector m_notes;
157 int m_steps;
159 // pattern freezing
160 sampleBuffer * m_frozenPattern;
161 bool m_freezing;
162 volatile bool m_freezeAborted;
165 friend class patternView;
166 friend class patternFreezeThread;
172 class patternView : public trackContentObjectView
174 Q_OBJECT
175 public:
176 patternView( pattern * _pattern, trackView * _parent );
177 virtual ~patternView();
180 public slots:
181 virtual void update();
184 protected slots:
185 void openInPianoRoll();
187 void resetName();
188 void changeName();
190 void addSteps( QAction * _item );
191 void removeSteps( QAction * _item );
194 protected:
195 virtual void constructContextMenu( QMenu * );
196 virtual void mouseDoubleClickEvent( QMouseEvent * _me );
197 virtual void mousePressEvent( QMouseEvent * _me );
198 virtual void paintEvent( QPaintEvent * _pe );
199 virtual void resizeEvent( QResizeEvent * _re )
201 m_needsUpdate = true;
202 trackContentObjectView::resizeEvent( _re );
204 virtual void wheelEvent( QWheelEvent * _we );
207 private:
208 static QPixmap * s_stepBtnOn;
209 static QPixmap * s_stepBtnOverlay;
210 static QPixmap * s_stepBtnOff;
211 static QPixmap * s_stepBtnOffLight;
212 static QPixmap * s_frozen;
214 pattern * m_pat;
215 QPixmap m_paintPixmap;
216 bool m_needsUpdate;
223 // TODO: move to own header-files
227 class patternFreezeStatusDialog : public QDialog
229 Q_OBJECT
230 public:
231 patternFreezeStatusDialog( QThread * _thread );
232 virtual ~patternFreezeStatusDialog();
234 void setProgress( int _p );
237 protected:
238 void closeEvent( QCloseEvent * _ce );
241 protected slots:
242 void cancelBtnClicked();
243 void updateProgress();
246 private:
247 QProgressBar * m_progressBar;
248 QPushButton * m_cancelBtn;
250 QThread * m_freezeThread;
252 int m_progress;
255 signals:
256 void aborted();
264 class patternFreezeThread : public QThread
266 public:
267 patternFreezeThread( pattern * _pattern );
268 virtual ~patternFreezeThread();
271 protected:
272 virtual void run();
275 private:
276 pattern * m_pattern;
277 patternFreezeStatusDialog * m_statusDlg;
282 #endif