1 /*
2  * TimeLineWidget.h - class timeLine, representing a time-line with position marker
3  *
4  * Copyright (c) 2004-2008 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5  *
6  * This file is part of LMMS - https://lmms.io
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public
19  * License along with this program (see COPYING); if not, write to the
20  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301 USA.
22  *
23  */
24 
25 
26 #ifndef TIMELINE_H
27 #define TIMELINE_H
28 
29 #include <QWidget>
30 
31 #include "Song.h"
32 
33 
34 class QPixmap;
35 class QToolBar;
36 class NStateButton;
37 class TextFloat;
38 class SongEditor;
39 
40 
41 class TimeLineWidget : public QWidget, public JournallingObject
42 {
43 	Q_OBJECT
44 public:
45 	Q_PROPERTY( QColor barLineColor READ getBarLineColor WRITE setBarLineColor )
46 	Q_PROPERTY( QColor barNumberColor READ getBarNumberColor WRITE setBarNumberColor )
47 	Q_PROPERTY( QColor inactiveLoopColor READ getInactiveLoopColor WRITE setInactiveLoopColor )
48 	Q_PROPERTY( QBrush inactiveLoopBrush READ getInactiveLoopBrush WRITE setInactiveLoopBrush )
49 	Q_PROPERTY( QColor inactiveLoopInnerColor READ getInactiveLoopInnerColor WRITE setInactiveLoopInnerColor )
50 	Q_PROPERTY( QColor activeLoopColor READ getActiveLoopColor WRITE setActiveLoopColor )
51 	Q_PROPERTY( QBrush activeLoopBrush READ getActiveLoopBrush WRITE setActiveLoopBrush )
52 	Q_PROPERTY( QColor activeLoopInnerColor READ getActiveLoopInnerColor WRITE setActiveLoopInnerColor )
53 	Q_PROPERTY( int loopRectangleVerticalPadding READ getLoopRectangleVerticalPadding WRITE setLoopRectangleVerticalPadding )
54 
55 	enum AutoScrollStates
56 	{
57 		AutoScrollEnabled,
58 		AutoScrollDisabled
59 	} ;
60 
61 	enum LoopPointStates
62 	{
63 		LoopPointsDisabled,
64 		LoopPointsEnabled
65 	} ;
66 
67 	enum BehaviourAtStopStates
68 	{
69 		BackToZero,
70 		BackToStart,
71 		KeepStopPosition
72 	} ;
73 
74 
75 	TimeLineWidget( int xoff, int yoff, float ppt, Song::PlayPos & pos,
76 				const MidiTime & begin, QWidget * parent );
77 	virtual ~TimeLineWidget();
78 
getBarLineColor()79 	inline QColor const & getBarLineColor() const { return m_barLineColor; }
setBarLineColor(QColor const & tactLineColor)80 	inline void setBarLineColor(QColor const & tactLineColor) { m_barLineColor = tactLineColor; }
81 
getBarNumberColor()82 	inline QColor const & getBarNumberColor() const { return m_barNumberColor; }
setBarNumberColor(QColor const & tactNumberColor)83 	inline void setBarNumberColor(QColor const & tactNumberColor) { m_barNumberColor = tactNumberColor; }
84 
getInactiveLoopColor()85 	inline QColor const & getInactiveLoopColor() const { return m_inactiveLoopColor; }
setInactiveLoopColor(QColor const & inactiveLoopColor)86 	inline void setInactiveLoopColor(QColor const & inactiveLoopColor) { m_inactiveLoopColor = inactiveLoopColor; }
87 
getInactiveLoopBrush()88 	inline QBrush const & getInactiveLoopBrush() const { return m_inactiveLoopBrush; }
setInactiveLoopBrush(QBrush const & inactiveLoopBrush)89 	inline void setInactiveLoopBrush(QBrush const & inactiveLoopBrush) { m_inactiveLoopBrush = inactiveLoopBrush; }
90 
getInactiveLoopInnerColor()91 	inline QColor const & getInactiveLoopInnerColor() const { return m_inactiveLoopInnerColor; }
setInactiveLoopInnerColor(QColor const & inactiveLoopInnerColor)92 	inline void setInactiveLoopInnerColor(QColor const & inactiveLoopInnerColor) { m_inactiveLoopInnerColor = inactiveLoopInnerColor; }
93 
getActiveLoopColor()94 	inline QColor const & getActiveLoopColor() const { return m_activeLoopColor; }
setActiveLoopColor(QColor const & activeLoopColor)95 	inline void setActiveLoopColor(QColor const & activeLoopColor) { m_activeLoopColor = activeLoopColor; }
96 
getActiveLoopBrush()97 	inline QBrush const & getActiveLoopBrush() const { return m_activeLoopBrush; }
setActiveLoopBrush(QBrush const & activeLoopBrush)98 	inline void setActiveLoopBrush(QBrush const & activeLoopBrush) { m_activeLoopBrush = activeLoopBrush; }
99 
getActiveLoopInnerColor()100 	inline QColor const & getActiveLoopInnerColor() const { return m_activeLoopInnerColor; }
setActiveLoopInnerColor(QColor const & activeLoopInnerColor)101 	inline void setActiveLoopInnerColor(QColor const & activeLoopInnerColor) { m_activeLoopInnerColor = activeLoopInnerColor; }
102 
getLoopRectangleVerticalPadding()103 	inline int const & getLoopRectangleVerticalPadding() const { return m_loopRectangleVerticalPadding; }
setLoopRectangleVerticalPadding(int const & loopRectangleVerticalPadding)104 	inline void setLoopRectangleVerticalPadding(int const & loopRectangleVerticalPadding) { m_loopRectangleVerticalPadding = loopRectangleVerticalPadding; }
105 
pos()106 	inline Song::PlayPos & pos()
107 	{
108 		return( m_pos );
109 	}
110 
autoScroll()111 	AutoScrollStates autoScroll() const
112 	{
113 		return m_autoScroll;
114 	}
115 
behaviourAtStop()116 	BehaviourAtStopStates behaviourAtStop() const
117 	{
118 		return m_behaviourAtStop;
119 	}
120 
loopPointsEnabled()121 	bool loopPointsEnabled() const
122 	{
123 		return m_loopPoints == LoopPointsEnabled;
124 	}
125 
loopBegin()126 	inline const MidiTime & loopBegin() const
127 	{
128 		return ( m_loopPos[0] < m_loopPos[1] ) ?
129 						m_loopPos[0] : m_loopPos[1];
130 	}
131 
loopEnd()132 	inline const MidiTime & loopEnd() const
133 	{
134 		return ( m_loopPos[0] > m_loopPos[1] ) ?
135 						m_loopPos[0] : m_loopPos[1];
136 	}
137 
savePos(const MidiTime & _pos)138 	inline void savePos( const MidiTime & _pos )
139 	{
140 		m_savedPos = _pos;
141 	}
savedPos()142 	inline const MidiTime & savedPos() const
143 	{
144 		return m_savedPos;
145 	}
146 
setPixelsPerTact(float _ppt)147 	inline void setPixelsPerTact( float _ppt )
148 	{
149 		m_ppt = _ppt;
150 		update();
151 	}
152 
153 	void addToolButtons(QToolBar* _tool_bar );
154 
155 
156 	virtual void saveSettings( QDomDocument & _doc, QDomElement & _parent );
157 	virtual void loadSettings( const QDomElement & _this );
nodeName()158 	inline virtual QString nodeName() const
159 	{
160 		return "timeline";
161 	}
162 
markerX(const MidiTime & _t)163 	inline int markerX( const MidiTime & _t ) const
164 	{
165 		return m_xOffset + static_cast<int>( ( _t - m_begin ) *
166 					m_ppt / MidiTime::ticksPerTact() );
167 	}
168 
169 signals:
170 
171 	void regionSelectedFromPixels( int, int );
172 	void selectionFinished();
173 
174 
175 public slots:
176 	void updatePosition( const MidiTime & );
updatePosition()177 	void updatePosition()
178 	{
179 		updatePosition( MidiTime() );
180 	}
181 	void toggleAutoScroll( int _n );
182 	void toggleLoopPoints( int _n );
183 	void toggleBehaviourAtStop( int _n );
184 
185 
186 protected:
187 	virtual void paintEvent( QPaintEvent * _pe );
188 	virtual void mousePressEvent( QMouseEvent * _me );
189 	virtual void mouseMoveEvent( QMouseEvent * _me );
190 	virtual void mouseReleaseEvent( QMouseEvent * _me );
191 
192 
193 private:
194 	static QPixmap * s_posMarkerPixmap;
195 
196 	QColor m_inactiveLoopColor;
197 	QBrush m_inactiveLoopBrush;
198 	QColor m_inactiveLoopInnerColor;
199 
200 	QColor m_activeLoopColor;
201 	QBrush m_activeLoopBrush;
202 	QColor m_activeLoopInnerColor;
203 
204 	int m_loopRectangleVerticalPadding;
205 
206 	QColor m_barLineColor;
207 	QColor m_barNumberColor;
208 
209 	AutoScrollStates m_autoScroll;
210 	LoopPointStates m_loopPoints;
211 	BehaviourAtStopStates m_behaviourAtStop;
212 
213 	bool m_changedPosition;
214 
215 	int m_xOffset;
216 	int m_posMarkerX;
217 	float m_ppt;
218 	Song::PlayPos & m_pos;
219 	const MidiTime & m_begin;
220 	MidiTime m_loopPos[2];
221 
222 	MidiTime m_savedPos;
223 
224 
225 	TextFloat * m_hint;
226 	int m_initalXSelect;
227 
228 
229 	enum actions
230 	{
231 		NoAction,
232 		MovePositionMarker,
233 		MoveLoopBegin,
234 		MoveLoopEnd,
235 		SelectSongTCO,
236 	} m_action;
237 
238 	int m_moveXOff;
239 
240 
241 signals:
242 	void positionChanged( const MidiTime & _t );
243 	void loopPointStateLoaded( int _n );
244 	void positionMarkerMoved();
245 
246 } ;
247 
248 
249 #endif
250