hydrogen 1.2.6
AudioEngineInfoForm.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 "AudioEngineInfoForm.h"
24
25#include <QtGui>
26#include <QtWidgets>
27
28
29#include "HydrogenApp.h"
30
31#include <core/Basics/Pattern.h>
34#include <core/Hydrogen.h>
35#include <core/IO/MidiInput.h>
36#include <core/IO/AudioOutput.h>
40using namespace H2Core;
41
43 : QWidget( parent )
44 , Object()
45{
46 setupUi( this );
47 adjustSize();
48 setFixedSize( width(), height() ); // not resizable
49
50 setWindowTitle( tr( "Audio Engine Info" ) );
51
52 updateInfo();
53
54 m_pTimer = new QTimer(this);
55 connect(m_pTimer, SIGNAL(timeout()), this, SLOT(updateInfo()));
56
59}
60
61
62
69
70
75{
76 updateInfo();
77 m_pTimer->start(200);
78}
79
80
85{
86 m_pTimer->stop();
87}
88
89
91{
92 Hydrogen *pHydrogen = Hydrogen::get_instance();
93 AudioEngine* pAudioEngine = pHydrogen->getAudioEngine();;
94 std::shared_ptr<Song> pSong = pHydrogen->getSong();
95
96 // Song position
97 QString sColumn = "N/A";
98 if ( pAudioEngine->getTransportPosition()->getColumn() != -1 ) {
99 sColumn = QString::number( pAudioEngine->getTransportPosition()->getColumn() );
100 }
101 m_pSongPositionLbl->setText( sColumn );
102
103
104 // Audio engine Playing notes
105 char tmp[100];
106
107 // Process time
108 int perc = 0;
109 if ( pAudioEngine->getMaxProcessTime() != 0.0 ) {
110 perc= (int)( pAudioEngine->getProcessTime() / ( pAudioEngine->getMaxProcessTime() / 100.0 ) );
111 }
112 sprintf(tmp, "%#.2f / %#.2f (%d%%)", pAudioEngine->getProcessTime(), pAudioEngine->getMaxProcessTime(), perc );
113 processTimeLbl->setText(tmp);
114
115 // Song state
116 if (pSong == nullptr) {
117 songStateLbl->setText( "NULL song" );
118 }
119 else {
120 if (pSong->getIsModified()) {
121 songStateLbl->setText( "Modified" );
122 }
123 else {
124 songStateLbl->setText( "Saved" );
125 }
126 }
127
128 // tick number
129 sprintf(tmp, "%03d", (int)pAudioEngine->getTransportPosition()->getPatternTickPosition() );
130 nTicksLbl->setText(tmp);
131
132
133
134 // Audio driver info
135 AudioOutput *driver = pHydrogen->getAudioOutput();
136 if (driver) {
137 QString audioDriverName = driver->class_name();
138 driverLbl->setText(audioDriverName);
139
140 // Audio driver buffer size
141 sprintf(tmp, "%d", driver->getBufferSize());
142 bufferSizeLbl->setText(QString(tmp));
143
144 // Audio latency estimate
145 latencyLbl->setText( QString( "%1 frames" ).arg( driver->getLatency() ) );
146
147 // Audio driver sampleRate
148 sprintf(tmp, "%d", driver->getSampleRate());
149 sampleRateLbl->setText(QString(tmp));
150
151 // Number of frames
152 sprintf(tmp, "%d", static_cast<int>( pAudioEngine->getTransportPosition()->getFrame() ) );
153 nFramesLbl->setText(tmp);
154 }
155 else {
156 driverLbl->setText( "NULL driver" );
157 bufferSizeLbl->setText( "N/A" );
158 latencyLbl->setText( "N/A" );
159 sampleRateLbl->setText( "N/A" );
160 nFramesLbl->setText( "N/A" );
161 }
162 nRealtimeFramesLbl->setText( QString( "%1" ).arg( pAudioEngine->getRealtimeFrame() ) );
163
164
165 // Midi driver info
166 MidiInput *pMidiDriver = pHydrogen->getMidiInput();
167 if ( pMidiDriver != nullptr ) {
168 midiDriverName->setText( pMidiDriver->class_name() );
169 }
170 else {
171 midiDriverName->setText("No MIDI driver support");
172 }
173
174 m_pMidiDeviceName->setText( Preferences::get_instance()->m_sMidiPortName );
175
176
177 int nSelectedPatternNumber = pHydrogen->getSelectedPatternNumber();
178 if (nSelectedPatternNumber == -1) {
179 selectedPatLbl->setText( "N/A");
180 }
181 else {
182 selectedPatLbl->setText( QString("%1").arg(nSelectedPatternNumber) );
183 }
184
185 int nSelectedInstrumentNumber = pHydrogen->getSelectedInstrumentNumber();
186 if (nSelectedInstrumentNumber == -1) {
187 m_pSelectedInstrLbl->setText( "N/A" );
188 }
189 else {
190 m_pSelectedInstrLbl->setText( QString("%1").arg(nSelectedInstrumentNumber) );
191 }
192
193 auto pPatternList = pAudioEngine->getPlayingPatterns();
194 if ( pPatternList != nullptr ) {
195 currentPatternLbl->setText( QString::number( pPatternList->size() ) );
196 } else {
197 currentPatternLbl->setText( "N/A" );
198 }
199
200 // SAMPLER
201 Sampler *pSampler = pAudioEngine->getSampler();
202 sampler_playingNotesLbl->setText(QString( "%1 / %2" ).arg(pSampler->getPlayingNotesNumber()).arg(Preferences::get_instance()->m_nMaxNotes));
203
204 // Synth
205 Synth *pSynth = pAudioEngine->getSynth();
206 synth_playingNotesLbl->setText( QString( "%1" ).arg( pSynth->getPlayingNotesNumber() ) );
207}
208
209
210
211
212
213
218 // Audio Engine state
219 QString stateTxt;
220 switch ( H2Core::Hydrogen::get_instance()->getAudioEngine()->getState() ) {
222 stateTxt = "Uninitialized";
223 break;
224
226 stateTxt = "Initialized";
227 break;
228
230 stateTxt = "Prepared";
231 break;
232
234 stateTxt = "Ready";
235 break;
236
238 stateTxt = "Playing";
239 break;
240
241 default:
242 stateTxt = "Unknown!?";
243 break;
244 }
245 engineStateLbl->setText(stateTxt);
246}
247
248
254
255
260
262{
263 // A new song got loaded
264 if ( nValue == 0 ) {
266 }
267}
268
269
void hideEvent(QHideEvent *ev) override
hide event
AudioEngineInfoForm(QWidget *parent)
void showEvent(QShowEvent *ev) override
show event
virtual void playingPatternsChangedEvent() override
virtual void stateChangedEvent(H2Core::AudioEngine::State state) override
virtual void updateSongEvent(int) override
void updateAudioEngineState()
Update engineStateLbl with the current audio engine state.
The audio engine deals with two distinct TransportPosition.
Definition AudioEngine.h:99
@ Prepared
Drivers are set up, but not ready to process audio.
@ Initialized
Not ready, but most pointers are now valid or NULL.
@ Playing
Transport is rolling.
@ Ready
Ready to process audio.
@ Uninitialized
Not even the constructors have been called.
float getProcessTime() const
float getMaxProcessTime() const
const PatternList * getPlayingPatterns() const
Sampler * getSampler() const
const std::shared_ptr< TransportPosition > getTransportPosition() const
Synth * getSynth() const
long long getRealtimeFrame() const
Base abstract class for audio output classes.
Definition AudioOutput.h:39
virtual int getLatency()
Approximate audio latency (in frames) A reasonable approximation is the buffer time on most audio sys...
Definition AudioOutput.h:55
virtual unsigned getSampleRate()=0
virtual unsigned getBufferSize()=0
virtual const char * class_name() const
Definition Object.h:79
Hydrogen Audio Engine.
Definition Hydrogen.h:54
std::shared_ptr< Song > getSong() const
Get the current song.
Definition Hydrogen.h:123
int getSelectedInstrumentNumber() const
Definition Hydrogen.h:678
MidiInput * getMidiInput() const
Used to display midi driver info.
Definition Hydrogen.cpp:747
int getSelectedPatternNumber() const
Definition Hydrogen.h:674
static Hydrogen * get_instance()
Returns the current Hydrogen instance __instance.
Definition Hydrogen.h:84
AudioEngine * getAudioEngine() const
Definition Hydrogen.h:663
AudioOutput * getAudioOutput() const
Used to display audio driver info.
Definition Hydrogen.cpp:741
MIDI input base class.
Definition MidiInput.h:39
static Preferences * get_instance()
Returns a pointer to the current Preferences singleton stored in __instance.
Waveform based sampler.
Definition Sampler.h:51
int getPlayingNotesNumber()
Definition Sampler.h:190
A simple synthetizer...
Definition Synth.h:43
int getPlayingNotesNumber()
Definition Synth.h:67
void addEventListener(EventListener *pListener)
static HydrogenApp * get_instance()
Returns the instance of HydrogenApp class.
#define UNUSED(v)
Definition Globals.h:42