ControllerRackView: do not loose focus when adding controller
[lmms.git] / include / automation_editor.h
blob22a097fd1a058733b108ab8d79d60ae59fee1120
1 /*
2 * automation_editor.h - declaration of class automationEditor which is a window
3 * where you can edit dynamic values in an easy way
5 * Copyright (c) 2006-2008 Javier Serrano Polo <jasp00/at/users.sourceforge.net>
6 *
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 _AUTOMATION_EDITOR_H
27 #define _AUTOMATION_EDITOR_H
29 #include <QtCore/QMutex>
30 #include <QtGui/QWidget>
32 #include "lmms_basics.h"
33 #include "JournallingObject.h"
34 #include "midi_time.h"
35 #include "automation_pattern.h"
36 #include "ComboBoxModel.h"
39 class QPainter;
40 class QPixmap;
41 class QScrollBar;
43 class comboBox;
44 class notePlayHandle;
45 class timeLine;
46 class toolButton;
49 class automationEditor : public QWidget, public JournallingObject
51 Q_OBJECT
52 public:
53 void setCurrentPattern( automationPattern * _new_pattern );
55 inline const automationPattern * currentPattern() const
57 return( m_pattern );
60 inline bool validPattern() const
62 return( m_pattern != NULL );
65 int quantization() const;
68 virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
69 virtual void loadSettings( const QDomElement & _this );
70 inline virtual QString nodeName() const
72 return( "automationeditor" );
76 public slots:
77 void update();
78 void updateAfterPatternChange();
81 protected:
82 typedef automationPattern::timeMap timeMap;
84 virtual void closeEvent( QCloseEvent * _ce );
85 virtual void keyPressEvent( QKeyEvent * _ke );
86 virtual void leaveEvent( QEvent * _e );
87 virtual void mousePressEvent( QMouseEvent * _me );
88 virtual void mouseReleaseEvent( QMouseEvent * _me );
89 virtual void mouseMoveEvent( QMouseEvent * _me );
90 virtual void paintEvent( QPaintEvent * _pe );
91 virtual void resizeEvent( QResizeEvent * _re );
92 virtual void wheelEvent( QWheelEvent * _we );
94 float getLevel( int _y );
95 static inline void drawValueRect( QPainter & _p, int _x, int _y,
96 int _width, int _height,
97 const bool _is_selected );
98 void removeSelection();
99 void selectAll();
100 void getSelectedValues( timeMap & _selected_values );
102 void drawLine( int x0, float y0, int x1, float y1 );
104 protected slots:
105 void play();
106 void stop();
108 void horScrolled( int _new_pos );
109 void verScrolled( int _new_pos );
111 void drawButtonToggled();
112 void eraseButtonToggled();
113 void selectButtonToggled();
114 void moveButtonToggled();
116 void copySelectedValues();
117 void cutSelectedValues();
118 void pasteValues();
119 void deleteSelectedValues();
121 void updatePosition( const midiTime & _t );
123 void zoomingXChanged();
124 void zoomingYChanged();
127 private:
129 enum editModes
131 DRAW,
132 ERASE,
133 SELECT,
134 MOVE
137 enum actions
139 NONE,
140 MOVE_VALUE,
141 SELECT_VALUES,
142 MOVE_SELECTION
145 // some constants...
146 static const int INITIAL_WIDTH = 740;
147 static const int INITIAL_HEIGHT = 480;
149 static const int SCROLLBAR_SIZE = 16;
150 static const int TOP_MARGIN = 48;
152 static const int DEFAULT_Y_DELTA = 6;
153 static const int DEFAULT_STEPS_PER_TACT = 16;
154 static const int DEFAULT_PPT = 12 * DEFAULT_STEPS_PER_TACT;
156 static const int VALUES_WIDTH = 64;
158 automationEditor();
159 automationEditor( const automationEditor & );
160 virtual ~automationEditor();
163 static QPixmap * s_toolDraw;
164 static QPixmap * s_toolErase;
165 static QPixmap * s_toolSelect;
166 static QPixmap * s_toolMove;
169 QWidget * m_toolBar;
171 toolButton * m_playButton;
172 toolButton * m_stopButton;
174 toolButton * m_drawButton;
175 toolButton * m_eraseButton;
176 toolButton * m_selectButton;
177 toolButton * m_moveButton;
179 toolButton * m_cutButton;
180 toolButton * m_copyButton;
181 toolButton * m_pasteButton;
183 comboBox * m_zoomingXComboBox;
184 comboBox * m_zoomingYComboBox;
185 comboBox * m_quantizeComboBox;
187 ComboBoxModel m_zoomingXModel;
188 ComboBoxModel m_zoomingYModel;
189 ComboBoxModel m_quantizeModel;
191 QMutex m_patternMutex;
192 automationPattern * m_pattern;
193 float m_minLevel;
194 float m_maxLevel;
195 float m_step;
196 float m_scrollLevel;
197 float m_bottomLevel;
198 float m_topLevel;
200 void updateTopBottomLevels();
202 QScrollBar * m_leftRightScroll;
203 QScrollBar * m_topBottomScroll;
205 midiTime m_currentPosition;
207 actions m_action;
209 tick_t m_selectStartTick;
210 tick_t m_selectedTick;
211 float m_selectStartLevel;
212 float m_selectedLevels;
214 float m_moveStartLevel;
215 tick_t m_moveStartTick;
216 int m_moveXOffset;
218 float m_drawLastLevel;
219 tick_t m_drawLastTick;
221 int m_ppt;
222 int m_y_delta;
223 bool m_y_auto;
225 timeMap m_valuesToCopy;
226 timeMap m_selValuesForMove;
229 editModes m_editMode;
232 timeLine * m_timeLine;
233 bool m_scrollBack;
235 void drawCross( QPainter & _p );
236 bool inBBEditor();
240 friend class engine;
243 signals:
244 void currentPatternChanged();
245 void positionChanged( const midiTime & );
250 #endif