# HG changeset patch # User Chris Cannam # Date 1442401466 -3600 # Node ID 3dbc964f5907ad7961d5a04b3b281d28c63e147a # Parent 493f2af85497469f6682a80c172942493e5fb527 Add status bar "Recording" message and timer while recording diff -r 493f2af85497 -r 3dbc964f5907 audio/AudioRecordTarget.cpp --- a/audio/AudioRecordTarget.cpp Tue Sep 15 16:34:08 2015 +0100 +++ b/audio/AudioRecordTarget.cpp Wed Sep 16 12:04:26 2015 +0100 @@ -27,6 +27,7 @@ m_clientName(clientName.toUtf8().data()), m_recording(false), m_recordSampleRate(44100), + m_frameCount(0), m_model(0) { } @@ -55,9 +56,30 @@ void AudioRecordTarget::putSamples(int nframes, float **samples) { - QMutexLocker locker(&m_mutex); //!!! bad here - if (!m_recording) return; - m_model->addSamples(samples, nframes); + bool secChanged = false; + sv_frame_t frameToEmit = 0; + + { + QMutexLocker locker(&m_mutex); //!!! bad here + if (!m_recording) return; + + m_model->addSamples(samples, nframes); + + sv_frame_t priorFrameCount = m_frameCount; + m_frameCount += nframes; + + RealTime priorRT = RealTime::frame2RealTime + (priorFrameCount, m_recordSampleRate); + RealTime postRT = RealTime::frame2RealTime + (m_frameCount, m_recordSampleRate); + + secChanged = (postRT.sec > priorRT.sec); + if (secChanged) frameToEmit = m_frameCount; + } + + if (secChanged) { + emit recordDurationChanged(frameToEmit, m_recordSampleRate); + } } void @@ -99,6 +121,7 @@ } m_model = 0; + m_frameCount = 0; QString folder = getRecordFolder(); if (folder == "") return 0; diff -r 493f2af85497 -r 3dbc964f5907 audio/AudioRecordTarget.h --- a/audio/AudioRecordTarget.h Tue Sep 15 16:34:08 2015 +0100 +++ b/audio/AudioRecordTarget.h Wed Sep 16 12:04:26 2015 +0100 @@ -59,6 +59,7 @@ signals: void recordStatusChanged(bool recording); + void recordDurationChanged(sv_frame_t, sv_samplerate_t); // emitted occasionally protected slots: void modelAboutToBeDeleted(); @@ -68,6 +69,7 @@ std::string m_clientName; bool m_recording; sv_samplerate_t m_recordSampleRate; + sv_frame_t m_frameCount; QString m_audioFileName; WritableWaveFileModel *m_model; QMutex m_mutex; diff -r 493f2af85497 -r 3dbc964f5907 framework/MainWindowBase.cpp --- a/framework/MainWindowBase.cpp Tue Sep 15 16:34:08 2015 +0100 +++ b/framework/MainWindowBase.cpp Wed Sep 16 12:04:26 2015 +0100 @@ -233,6 +233,8 @@ if (m_soundOptions & WithAudioInput) { m_recordTarget = new AudioRecordTarget(m_viewManager, QApplication::applicationName()); + connect(m_recordTarget, SIGNAL(recordDurationChanged(sv_frame_t, sv_samplerate_t)), + this, SLOT(recordDurationChanged(sv_frame_t, sv_samplerate_t))); } connect(m_playSource, SIGNAL(sampleRateMismatch(sv_samplerate_t, sv_samplerate_t, bool)), @@ -3359,6 +3361,17 @@ } void +MainWindowBase::recordDurationChanged(sv_frame_t frame, sv_samplerate_t rate) +{ + RealTime duration = RealTime::frame2RealTime(frame, rate); + QString durStr = duration.toSecText().c_str(); + + m_myStatusMessage = tr("Recording: %1").arg(durStr); + + getStatusLabel()->setText(m_myStatusMessage); +} + +void MainWindowBase::globalCentreFrameChanged(sv_frame_t ) { if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return; diff -r 493f2af85497 -r 3dbc964f5907 framework/MainWindowBase.h --- a/framework/MainWindowBase.h Tue Sep 15 16:34:08 2015 +0100 +++ b/framework/MainWindowBase.h Wed Sep 16 12:04:26 2015 +0100 @@ -247,6 +247,7 @@ virtual void viewCentreFrameChanged(View *, sv_frame_t); virtual void viewZoomLevelChanged(View *, int, bool); virtual void outputLevelsChanged(float, float) = 0; + virtual void recordDurationChanged(sv_frame_t, sv_samplerate_t); virtual void currentPaneChanged(Pane *); virtual void currentLayerChanged(Pane *, Layer *);