From 430ee9e66bd8359037c713ed7ad88bd3c1361447 Mon Sep 17 00:00:00 2001 From: Colin Date: Fri, 4 Jun 2021 13:28:44 +0200 Subject: [PATCH 1/2] Changes to CJamRecorder --- src/recorder/jamrecorder.cpp | 50 +++++++++++++++--------------------- src/recorder/jamrecorder.h | 3 ++- 2 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/recorder/jamrecorder.cpp b/src/recorder/jamrecorder.cpp index 9ae17a7d8b..51c76941bc 100644 --- a/src/recorder/jamrecorder.cpp +++ b/src/recorder/jamrecorder.cpp @@ -399,9 +399,9 @@ void CJamRecorder::Start() QString error; - // needs to be after OnEnd() as that also locks - ChIdMutex.lock(); { + // needs to be after OnEnd() as that also locks + QMutexLocker mutexLocker(&ChIdMutex); try { currentSession = new CJamSession ( recordBaseDir ); @@ -413,7 +413,6 @@ void CJamRecorder::Start() error = err.GetErrorText(); } } - ChIdMutex.unlock(); if ( !currentSession ) { @@ -429,21 +428,18 @@ void CJamRecorder::Start() */ void CJamRecorder::OnEnd() { - ChIdMutex.lock(); // iChId used in currentSession->End() + QMutexLocker mutexLocker(&ChIdMutex); + if ( isRecording ) { - if ( isRecording ) - { - isRecording = false; - currentSession->End(); + isRecording = false; + currentSession->End(); - ReaperProjectFromCurrentSession(); - AudacityLofFromCurrentSession(); + ReaperProjectFromCurrentSession(); + AudacityLofFromCurrentSession(); - delete currentSession; - currentSession = nullptr; - } + delete currentSession; + currentSession = nullptr; } - ChIdMutex.unlock(); } /** @@ -571,21 +567,18 @@ void CJamRecorder::SessionDirToReaper ( QString& strSessionDirName, int serverFr */ void CJamRecorder::OnDisconnected ( int iChID ) { - ChIdMutex.lock(); + QMutexLocker mutexLocker(&ChIdMutex); + if ( !isRecording ) { - if ( !isRecording ) - { - qWarning() << "CJamRecorder::OnDisconnected: channel" << iChID << "disconnected but not recording"; - } - if ( currentSession == nullptr ) - { - qWarning() << "CJamRecorder::OnDisconnected: channel" << iChID << "disconnected but no currentSession"; - return; - } - - currentSession->DisconnectClient ( iChID ); + qWarning() << "CJamRecorder::OnDisconnected: channel" << iChID << "disconnected but not recording"; } - ChIdMutex.unlock(); + if ( currentSession == nullptr ) + { + qWarning() << "CJamRecorder::OnDisconnected: channel" << iChID << "disconnected but no currentSession"; + return; + } + + currentSession->DisconnectClient ( iChID ); } /** @@ -617,9 +610,8 @@ void CJamRecorder::OnFrame ( const int iChID, } // needs to be after Start() as that also locks - ChIdMutex.lock(); { + QMutexLocker mutexLocker(&ChIdMutex); currentSession->Frame ( iChID, name, address, numAudioChannels, data, iServerFrameSizeSamples ); } - ChIdMutex.unlock(); } diff --git a/src/recorder/jamrecorder.h b/src/recorder/jamrecorder.h index a4dedb783e..a89dde58a9 100644 --- a/src/recorder/jamrecorder.h +++ b/src/recorder/jamrecorder.h @@ -157,7 +157,8 @@ class CJamRecorder : public QObject CJamRecorder ( const QString strRecordingBaseDir, const int iServerFrameSizeSamples ) : recordBaseDir ( strRecordingBaseDir ), iServerFrameSizeSamples ( iServerFrameSizeSamples ), - isRecording ( false ) + isRecording ( false ), + currentSession( nullptr ) {} /** From 504cda92b393091e8ff37e0b4bc4410abb26625b Mon Sep 17 00:00:00 2001 From: Colin Date: Sat, 5 Jun 2021 19:34:35 +0200 Subject: [PATCH 2/2] Formatted with clang-format --- src/recorder/jamrecorder.cpp | 8 ++++---- src/recorder/jamrecorder.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/recorder/jamrecorder.cpp b/src/recorder/jamrecorder.cpp index 51c76941bc..373c596d30 100644 --- a/src/recorder/jamrecorder.cpp +++ b/src/recorder/jamrecorder.cpp @@ -401,7 +401,7 @@ void CJamRecorder::Start() { // needs to be after OnEnd() as that also locks - QMutexLocker mutexLocker(&ChIdMutex); + QMutexLocker mutexLocker ( &ChIdMutex ); try { currentSession = new CJamSession ( recordBaseDir ); @@ -428,7 +428,7 @@ void CJamRecorder::Start() */ void CJamRecorder::OnEnd() { - QMutexLocker mutexLocker(&ChIdMutex); + QMutexLocker mutexLocker ( &ChIdMutex ); if ( isRecording ) { isRecording = false; @@ -567,7 +567,7 @@ void CJamRecorder::SessionDirToReaper ( QString& strSessionDirName, int serverFr */ void CJamRecorder::OnDisconnected ( int iChID ) { - QMutexLocker mutexLocker(&ChIdMutex); + QMutexLocker mutexLocker ( &ChIdMutex ); if ( !isRecording ) { qWarning() << "CJamRecorder::OnDisconnected: channel" << iChID << "disconnected but not recording"; @@ -611,7 +611,7 @@ void CJamRecorder::OnFrame ( const int iChID, // needs to be after Start() as that also locks { - QMutexLocker mutexLocker(&ChIdMutex); + QMutexLocker mutexLocker ( &ChIdMutex ); currentSession->Frame ( iChID, name, address, numAudioChannels, data, iServerFrameSizeSamples ); } } diff --git a/src/recorder/jamrecorder.h b/src/recorder/jamrecorder.h index a89dde58a9..02ef534d5d 100644 --- a/src/recorder/jamrecorder.h +++ b/src/recorder/jamrecorder.h @@ -158,7 +158,7 @@ class CJamRecorder : public QObject recordBaseDir ( strRecordingBaseDir ), iServerFrameSizeSamples ( iServerFrameSizeSamples ), isRecording ( false ), - currentSession( nullptr ) + currentSession ( nullptr ) {} /**