Mercurial > hg > svapp
changeset 486:3dbc964f5907 recording
Add status bar "Recording" message and timer while recording
author | Chris Cannam |
---|---|
date | Wed, 16 Sep 2015 12:04:26 +0100 |
parents | 493f2af85497 |
children | 66b92c188cbd |
files | audio/AudioRecordTarget.cpp audio/AudioRecordTarget.h framework/MainWindowBase.cpp framework/MainWindowBase.h |
diffstat | 4 files changed, 42 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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;
--- 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;
--- 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 *);