-
Notifications
You must be signed in to change notification settings - Fork 169
/
Director.cpp
232 lines (189 loc) · 6.4 KB
/
Director.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
* Hydrogen
* Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
*
* http://www.hydrogen-music.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY, without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/**
**
** this dialog is used to use show a director.
** for example to play live without a click in your ears.
** here you get :
** - song name
** - a visual metronome
** - bar position info
** - beat position info
** - bar position tags (current and next)
**
** -------------------------------------------
** | |
** | song name |
** | |
** -------------------------------------------
** | | |
** | Bar | Beat |
** | | |
** -------------------------------------------
** | |
** | current bar tag |
** | |
** -------------------------------------------
** | |
** | next bar tag |
** | |
** -------------------------------------------
**/
#include "Director.h"
#include "HydrogenApp.h"
#include "widgets/PixmapWidget.h"
#include <hydrogen/Preferences.h>
#include <hydrogen/hydrogen.h>
#include <hydrogen/timeline.h>
#include <QRect>
using namespace H2Core;
using namespace std;
Director::Director ( QWidget* pParent )
: QDialog ( pParent )
, Object ( "Director" )
{
HydrogenApp::get_instance()->addEventListener( this );
setupUi ( this );
//INFOLOG ( "INIT" );
setWindowTitle ( trUtf8 ( "Director" ) );
m_nCounter = 1; // to compute the right beat
m_nFadeAlpha = 255; //default alpha
m_nBar = 1; // default bar
m_nFlashingArea = width() * 5/100;
m_fBpm = Hydrogen::get_instance()->getSong()->__bpm;
m_pTimeline = Hydrogen::get_instance()->getTimeline();
m_pTimer = new QTimer( this );
connect( m_pTimer, SIGNAL( timeout() ), this, SLOT( updateMetronomBackground() ) );
}
Director::~Director()
{
//INFOLOG ( "DESTROY" );
}
void Director::keyPressEvent( QKeyEvent* ev )
{
if(ev->key() == Qt::Key_Escape) {
HydrogenApp::get_instance()->showDirector();
}
}
void Director::closeEvent( QCloseEvent* ev )
{
HydrogenApp::get_instance()->showDirector();
}
void Director::metronomeEvent( int nValue )
{
//load a new song
if( nValue == 3 ){
//update songname
QStringList list = Hydrogen::get_instance()->getSong()->get_filename().split("/");
if ( !list.isEmpty() ){
__songName = list.last().replace( ".h2song", "" );
// if songname is not set, default on an empty song, we call them "Untitled Song".
if( __songName.isEmpty() ){
__songName = QString("Untitled Song");
}
}
update();
return;
}
//bpm
m_fBpm = Hydrogen::get_instance()->getSong()->__bpm;
//bar
m_nBar = Hydrogen::get_instance()->getPatternPos() + 1;
if ( m_nBar <= 0 ){
m_nBar = 1;
}
// 1000 ms / bpm / 60s
m_pTimer->start( static_cast<int>( 1000 / ( m_fBpm / 60 )) / 2 );
m_nFlashingArea = width() * 5/100;
m_nFadeAlpha = 255;
if ( nValue == 2 ){
m_nFadeAlpha = 0;
update();
__TAG="";
__TAG2="";
return;
}
if ( nValue == 1 ) { //foregroundcolor "rect" for first blink
__color = QColor( 255, 50, 1 ,255 );
m_nCounter = 1;
}
else { //foregroundcolor "rect" for all other blinks
m_nCounter++;
if( m_nCounter %2 == 0 )
m_nFlashingArea = width() * 52.5/100;
__color = QColor( 24, 250, 31, 255 );
}
// get tags
__TAG="";
__TAG2="";
for ( size_t t = 0; t < m_pTimeline->m_timelinetagvector.size(); t++){
if(t+1<m_pTimeline->m_timelinetagvector.size() &&
m_pTimeline->m_timelinetagvector[t+1].m_htimelinetagbeat == m_nBar ){
__TAG2 = m_pTimeline->m_timelinetagvector[t+1].m_htimelinetag ;
}
if ( m_pTimeline->m_timelinetagvector[t].m_htimelinetagbeat <= m_nBar-1){
__TAG = m_pTimeline->m_timelinetagvector[t].m_htimelinetag ;
}
if( m_pTimeline->m_timelinetagvector[t].m_htimelinetagbeat > m_nBar-1){
break;
}
}
update();
}
void Director::updateMetronomBackground()
{
__color.setAlpha( 0 );
m_pTimer->stop();
update();
}
void Director::paintEvent( QPaintEvent* ev )
{
QPainter painter(this);
//draw the songname
painter.setFont(QFont("Arial", height() * 14/100 ));
QRect rect(QPoint( width() * 5/100 , height () * 2/100 ), QSize( width() * 90/100, height() * 21/100));
painter.drawText( rect, Qt::AlignCenter, QString( __songName ) );
//draw the metronome
painter.setPen( QPen(QColor( 249, 235, 116, 200 ) ,1 , Qt::SolidLine ) );
painter.setBrush( __color );
painter.drawRect ( m_nFlashingArea, height() * 25/100, width() * 42.5/100, height() * 35/100);
//draw bars
painter.setPen(Qt::white);
painter.setFont(QFont("Arial", height() * 25/100 ));
QRect r1(QPoint( width() * 5/100 , height() * 25/100 ), QSize( width() * 42.5/100, height() * 35/100));
painter.drawText( r1, Qt::AlignCenter, QString("%1").arg( m_nBar) );
//draw beats
QRect r2(QPoint( width() * 52.5/100 , height() * 25/100 ), QSize( width() * 42.5/100, height() * 35/100));
painter.drawText( r2, Qt::AlignCenter, QString("%1").arg( m_nCounter) );
if( __TAG == __TAG2 )
__TAG2 = "";
//draw current bar tag
painter.setPen(Qt::white);
painter.setFont(QFont("Arial", height() * 8/100 ));
QRect r3(QPoint ( width() * 5/100 , height() * 65/100 ), QSize( width() * 90/100, height() * 14/100));
painter.drawText( r3, Qt::AlignCenter, QString( (__TAG) ) );
//draw next bar tag
painter.setPen(Qt::gray);
painter.setFont(QFont("Arial", height() * 6/100 ));
QRect r4(QPoint ( width() * 5/100 , height() * 83/100 ), QSize( width() * 90/100, height() * 11/100));
painter.drawText( r4, Qt::AlignCenter, QString( __TAG2 ) );
}