@@ -399,9 +399,9 @@ void CJamRecorder::Start()
399399
400400 QString error;
401401
402- // needs to be after OnEnd() as that also locks
403- ChIdMutex.lock ();
404402 {
403+ // needs to be after OnEnd() as that also locks
404+ QMutexLocker mutexLocker ( &ChIdMutex );
405405 try
406406 {
407407 currentSession = new CJamSession ( recordBaseDir );
@@ -413,7 +413,6 @@ void CJamRecorder::Start()
413413 error = err.GetErrorText ();
414414 }
415415 }
416- ChIdMutex.unlock ();
417416
418417 if ( !currentSession )
419418 {
@@ -429,21 +428,18 @@ void CJamRecorder::Start()
429428 */
430429void CJamRecorder::OnEnd ()
431430{
432- ChIdMutex.lock (); // iChId used in currentSession->End()
431+ QMutexLocker mutexLocker ( &ChIdMutex );
432+ if ( isRecording )
433433 {
434- if ( isRecording )
435- {
436- isRecording = false ;
437- currentSession->End ();
434+ isRecording = false ;
435+ currentSession->End ();
438436
439- ReaperProjectFromCurrentSession ();
440- AudacityLofFromCurrentSession ();
437+ ReaperProjectFromCurrentSession ();
438+ AudacityLofFromCurrentSession ();
441439
442- delete currentSession;
443- currentSession = nullptr ;
444- }
440+ delete currentSession;
441+ currentSession = nullptr ;
445442 }
446- ChIdMutex.unlock ();
447443}
448444
449445/* *
@@ -571,21 +567,18 @@ void CJamRecorder::SessionDirToReaper ( QString& strSessionDirName, int serverFr
571567 */
572568void CJamRecorder::OnDisconnected ( int iChID )
573569{
574- ChIdMutex.lock ();
570+ QMutexLocker mutexLocker ( &ChIdMutex );
571+ if ( !isRecording )
575572 {
576- if ( !isRecording )
577- {
578- qWarning () << " CJamRecorder::OnDisconnected: channel" << iChID << " disconnected but not recording" ;
579- }
580- if ( currentSession == nullptr )
581- {
582- qWarning () << " CJamRecorder::OnDisconnected: channel" << iChID << " disconnected but no currentSession" ;
583- return ;
584- }
585-
586- currentSession->DisconnectClient ( iChID );
573+ qWarning () << " CJamRecorder::OnDisconnected: channel" << iChID << " disconnected but not recording" ;
587574 }
588- ChIdMutex.unlock ();
575+ if ( currentSession == nullptr )
576+ {
577+ qWarning () << " CJamRecorder::OnDisconnected: channel" << iChID << " disconnected but no currentSession" ;
578+ return ;
579+ }
580+
581+ currentSession->DisconnectClient ( iChID );
589582}
590583
591584/* *
@@ -617,9 +610,8 @@ void CJamRecorder::OnFrame ( const int iChID,
617610 }
618611
619612 // needs to be after Start() as that also locks
620- ChIdMutex.lock ();
621613 {
614+ QMutexLocker mutexLocker ( &ChIdMutex );
622615 currentSession->Frame ( iChID, name, address, numAudioChannels, data, iServerFrameSizeSamples );
623616 }
624- ChIdMutex.unlock ();
625617}
0 commit comments