1 /*
2 * TimeDisplayWidget.cpp - widget for displaying current playback time
3 *
4 * Copyright (c) 2014 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 #include <QMouseEvent>
26
27 #include "TimeDisplayWidget.h"
28 #include "GuiApplication.h"
29 #include "MainWindow.h"
30 #include "Engine.h"
31 #include "ToolTip.h"
32 #include "Song.h"
33
34
35
TimeDisplayWidget()36 TimeDisplayWidget::TimeDisplayWidget() :
37 QWidget(),
38 m_displayMode( MinutesSeconds ),
39 m_spinBoxesLayout( this ),
40 m_majorLCD( 4, this ),
41 m_minorLCD( 2, this ),
42 m_milliSecondsLCD( 3, this )
43 {
44 m_spinBoxesLayout.setSpacing( 0 );
45 m_spinBoxesLayout.setMargin( 0 );
46 m_spinBoxesLayout.addWidget( &m_majorLCD );
47 m_spinBoxesLayout.addWidget( &m_minorLCD );
48 m_spinBoxesLayout.addWidget( &m_milliSecondsLCD );
49
50 setMaximumHeight( 32 );
51
52 ToolTip::add( this, tr( "click to change time units" ) );
53
54 // update labels of LCD spinboxes
55 setDisplayMode( m_displayMode );
56
57 connect( gui->mainWindow(), SIGNAL( periodicUpdate() ),
58 this, SLOT( updateTime() ) );
59 }
60
61
62
63
~TimeDisplayWidget()64 TimeDisplayWidget::~TimeDisplayWidget()
65 {
66 }
67
68
69
70
71
setDisplayMode(DisplayMode displayMode)72 void TimeDisplayWidget::setDisplayMode( DisplayMode displayMode )
73 {
74 m_displayMode = displayMode;
75
76 switch( m_displayMode )
77 {
78 case MinutesSeconds:
79 m_majorLCD.setLabel( tr( "MIN" ) );
80 m_minorLCD.setLabel( tr( "SEC" ) );
81 m_milliSecondsLCD.setLabel( tr( "MSEC" ) );
82 break;
83
84 case BarsTicks:
85 m_majorLCD.setLabel( tr( "BAR" ) );
86 m_minorLCD.setLabel( tr( "BEAT" ) );
87 m_milliSecondsLCD.setLabel( tr( "TICK" ) );
88 break;
89
90 default: break;
91 }
92 }
93
94
95
96
updateTime()97 void TimeDisplayWidget::updateTime()
98 {
99 Song* s = Engine::getSong();
100
101 switch( m_displayMode )
102 {
103 case MinutesSeconds:
104 m_majorLCD.setValue( s->getMilliseconds() / 60000 );
105 m_minorLCD.setValue( ( s->getMilliseconds() / 1000 ) % 60 );
106 m_milliSecondsLCD.setValue( s->getMilliseconds() % 1000 );
107 break;
108
109 case BarsTicks:
110 int tick;
111 tick = ( s->getMilliseconds() * s->getTempo() * (DefaultTicksPerTact / 4 ) ) / 60000 ;
112 m_majorLCD.setValue( (int)(tick / s->ticksPerTact() ) + 1);
113 m_minorLCD.setValue( ( tick % s->ticksPerTact() ) /
114 ( s->ticksPerTact() / s->getTimeSigModel().getNumerator() ) +1 );
115 m_milliSecondsLCD.setValue( ( tick % s->ticksPerTact() ) %
116 ( s->ticksPerTact() / s->getTimeSigModel().getNumerator() ) );
117 break;
118
119 default: break;
120 }
121 }
122
123
124
125
mousePressEvent(QMouseEvent * mouseEvent)126 void TimeDisplayWidget::mousePressEvent( QMouseEvent* mouseEvent )
127 {
128 if( mouseEvent->button() == Qt::LeftButton )
129 {
130 if( m_displayMode == MinutesSeconds )
131 {
132 setDisplayMode( BarsTicks );
133 }
134 else
135 {
136 setDisplayMode( MinutesSeconds );
137 }
138 }
139 }
140