hydrogen 1.2.6
SongEditorPanelBpmWidget.cpp
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2025 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (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
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#include <QtGui>
24#include <QtWidgets>
25
26#include "UndoActions.h"
27#include "../HydrogenApp.h"
28#include "../CommonStrings.h"
30#include "SongEditorPanel.h"
31#include "SongEditor.h"
32#include "../Widgets/Button.h"
33
34#include <core/Hydrogen.h>
35#include <core/Timeline.h>
36
37namespace H2Core
38{
39
40SongEditorPanelBpmWidget::SongEditorPanelBpmWidget( QWidget* pParent, int nColumn, bool bTempoMarkerPresent )
41 : QDialog( pParent )
42 , m_nColumn( nColumn )
43 , m_bTempoMarkerPresent( bTempoMarkerPresent )
44{
45 setupUi( this );
46 setWindowTitle( bTempoMarkerPresent ? tr( "Edit Tempo Marker" ) :
47 tr( "Create New Tempo Marker" ) );
48 adjustSize();
49 setFixedSize( width(), height() );
50
51 auto pHydrogen = Hydrogen::get_instance();
52
53 bpmSpinBox->setType( LCDSpinBox::Type::Double );
54 bpmSpinBox->setMinimum( MIN_BPM );
55 bpmSpinBox->setMaximum( MAX_BPM );
56 bpmSpinBox->setValue( pHydrogen->getTimeline()->getTempoAtColumn( m_nColumn ) );
57 bpmSpinBox->setToolTip( bTempoMarkerPresent ?
58 tr( "Alter tempo of selected tempo marker" ) :
59 tr( "Set tempo of new tempo marker" ) );
60 // Required for correct focus highlighting.
61 bpmSpinBox->setSize( QSize( 146, 23 ) );
62 bpmSpinBox->setFocus();
63
64 columnSpinBox->setType( LCDSpinBox::Type::Int );
65 columnSpinBox->setMinimum( 1 );
66 columnSpinBox->setMaximum( Preferences::get_instance()->getMaxBars() );
67 columnSpinBox->setValue( m_nColumn + 1 );
68 columnSpinBox->setToolTip( bTempoMarkerPresent ?
69 tr( "Move tempo marker to different column" ) :
70 tr( "Set column of new tempo marker" ) );
71 // Required for correct focus highlighting.
72 columnSpinBox->setSize( QSize( 146, 23 ) );
73
74 deleteBtn->setSize( QSize( 180, 23 ) );
75 deleteBtn->setIsActive( bTempoMarkerPresent );
76 deleteBtn->setFixedFontSize( 12 );
77}
78
79
80
81
85
86
87
92
93
94
96{
97 auto pCommonStrings = HydrogenApp::get_instance()->getCommonStrings();
98 float fNewBpm = bpmSpinBox->text().toFloat( nullptr );
99
100 // In case the input text can not be parsed by Qt `fNewBpm' is 0
101 // and also covered by the warning below.
102 if ( fNewBpm > MAX_BPM || fNewBpm < MIN_BPM ){
103 QMessageBox::warning(
104 this, "Hydrogen",
105 QString( tr( "Please enter a number within the range of " )
106 .append( QString( "[%1,%2]" ).arg( MIN_BPM )
107 .arg( MAX_BPM ) ) ),
108 QMessageBox::Cancel, QMessageBox::Cancel );
109 return;
110 }
111
112 auto pTimeline = Hydrogen::get_instance()->getTimeline();
113 int nNewColumn = columnSpinBox->text().toInt() - 1;
114 if ( ! ( m_bTempoMarkerPresent && nNewColumn == m_nColumn ) &&
115 pTimeline->hasColumnTempoMarker( nNewColumn ) ) {
116 QMessageBox::warning(
117 this, "Hydrogen",
118 QString( tr( "There is already a tempo marker present at this Column. Please use left-click to edit it instead." ) ),
119 QMessageBox::Cancel, QMessageBox::Cancel );
120 return;
121 }
122
123 float fOldBpm = pTimeline->getTempoAtColumn( m_nColumn );
124
125 SE_editTimelineAction *action = new SE_editTimelineAction( m_nColumn, nNewColumn, fOldBpm, bpmSpinBox->value(), m_bTempoMarkerPresent );
126 HydrogenApp::get_instance()->m_pUndoStack->push( action );
127 accept();
128}
129
130
132{
133 Hydrogen* pHydrogen = Hydrogen::get_instance();
134 auto pTimeline = pHydrogen->getTimeline();
135
136 float fBpm = pTimeline->getTempoAtColumn( m_nColumn );
137
139 HydrogenApp::get_instance()->m_pUndoStack->push( action );
140 accept();
141}
142
143}
Hydrogen Audio Engine.
Definition Hydrogen.h:54
std::shared_ptr< Timeline > getTimeline() const
Definition Hydrogen.h:644
static Hydrogen * get_instance()
Returns the current Hydrogen instance __instance.
Definition Hydrogen.h:84
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
SongEditorPanelBpmWidget(QWidget *pParent, int nColumn, bool bTempoMarkerPresent)
static HydrogenApp * get_instance()
Returns the instance of HydrogenApp class.
std::shared_ptr< CommonStrings > getCommonStrings()
QUndoStack * m_pUndoStack
#define MAX_BPM
Definition Globals.h:36
#define MIN_BPM
Definition Globals.h:35