Merge pull request #312 from pljones/feature/228-turn-recording-on-off

#228 Enable/Disable recording from command line
This commit is contained in:
Volker Fischer 2020-06-01 09:47:26 +02:00 committed by GitHub
commit 9cdf178e86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 113 additions and 46 deletions

View file

@ -302,7 +302,7 @@ QMap<QString, QList<STrackItem>> CJamSession::TracksFromSessionDir(const QString
* @brief CJamRecorder::Init Create recording directory, if necessary, and connect signal handlers * @brief CJamRecorder::Init Create recording directory, if necessary, and connect signal handlers
* @param server Server object emiting signals * @param server Server object emiting signals
*/ */
void CJamRecorder::Init( const CServer* server, bool CJamRecorder::Init( const CServer* server,
const int _iServerFrameSizeSamples ) const int _iServerFrameSizeSamples )
{ {
QFileInfo fi(recordBaseDir.absolutePath()); QFileInfo fi(recordBaseDir.absolutePath());
@ -310,21 +310,28 @@ void CJamRecorder::Init( const CServer* server,
if (!fi.exists() && !QDir().mkpath(recordBaseDir.absolutePath())) if (!fi.exists() && !QDir().mkpath(recordBaseDir.absolutePath()))
{ {
throw std::runtime_error( (recordBaseDir.absolutePath() + " does not exist but could not be created").toStdString() ); qCritical() << recordBaseDir.absolutePath() << "does not exist but could not be created";
return false;
} }
if (!fi.isDir()) if (!fi.isDir())
{ {
throw std::runtime_error( (recordBaseDir.absolutePath() + " exists but is not a directory").toStdString() ); qCritical() << recordBaseDir.absolutePath() << "exists but is not a directory";
return false;
} }
if (!fi.isWritable()) if (!fi.isWritable())
{ {
throw std::runtime_error( (recordBaseDir.absolutePath() + " is a directory but cannot be written to").toStdString() ); qCritical() << recordBaseDir.absolutePath() << "is a directory but cannot be written to";
return false;
} }
QObject::connect( (const QObject *)server, SIGNAL ( RestartRecorder() ), QObject::connect( (const QObject *)server, SIGNAL ( RestartRecorder() ),
this, SLOT( OnTriggerSession() ), this, SLOT( OnTriggerSession() ),
Qt::ConnectionType::QueuedConnection ); Qt::ConnectionType::QueuedConnection );
QObject::connect( (const QObject *)server, SIGNAL ( StopRecorder() ),
this, SLOT( OnEnd() ),
Qt::ConnectionType::QueuedConnection );
QObject::connect( (const QObject *)server, SIGNAL ( Stopped() ), QObject::connect( (const QObject *)server, SIGNAL ( Stopped() ),
this, SLOT( OnEnd() ), this, SLOT( OnEnd() ),
Qt::ConnectionType::QueuedConnection ); Qt::ConnectionType::QueuedConnection );
@ -346,6 +353,8 @@ void CJamRecorder::Init( const CServer* server,
thisThread = new QThread(); thisThread = new QThread();
moveToThread ( thisThread ); moveToThread ( thisThread );
thisThread->start(); thisThread->start();
return true;
} }
/** /**
@ -363,15 +372,10 @@ void CJamRecorder::Start() {
/** /**
* @brief CJamRecorder::OnEnd Finalise the recording and emit the Reaper RPP file * @brief CJamRecorder::OnEnd Finalise the recording and write the Reaper RPP file
*
* Emits RecordingSessionEnded with the Reaper project file name,
* or null if was not recording or a problem occurs
*/ */
void CJamRecorder::OnEnd() void CJamRecorder::OnEnd()
{ {
QString reaperProjectFileName = QString::Null();
if ( isRecording ) if ( isRecording )
{ {
isRecording = false; isRecording = false;

View file

@ -148,7 +148,7 @@ public:
* @brief Create recording directory, if necessary, and connect signal handlers * @brief Create recording directory, if necessary, and connect signal handlers
* @param server Server object emiting signals * @param server Server object emiting signals
*/ */
void Init( const CServer* server, const int _iServerFrameSizeSamples ); bool Init( const CServer* server, const int _iServerFrameSizeSamples );
/** /**
* @brief SessionDirToReaper Method that allows an RPP file to be recreated * @brief SessionDirToReaper Method that allows an RPP file to be recreated

View file

@ -239,7 +239,6 @@ CServer::CServer ( const int iNewMaxNumChan,
Socket ( this, iPortNumber ), Socket ( this, iPortNumber ),
Logging ( iMaxDaysHistory ), Logging ( iMaxDaysHistory ),
JamRecorder ( strRecordingDirName ), JamRecorder ( strRecordingDirName ),
bEnableRecording ( !strRecordingDirName.isEmpty() ),
bWriteStatusHTMLFile ( false ), bWriteStatusHTMLFile ( false ),
HighPrecisionTimer ( bNUseDoubleSystemFrameSize ), HighPrecisionTimer ( bNUseDoubleSystemFrameSize ),
ServerListManager ( iPortNumber, ServerListManager ( iPortNumber,
@ -402,9 +401,10 @@ CServer::CServer ( const int iNewMaxNumChan,
} }
// Enable jam recording (if requested) - kicks off the thread // Enable jam recording (if requested) - kicks off the thread
if ( bEnableRecording ) if ( !strRecordingDirName.isEmpty() )
{ {
JamRecorder.Init ( this, iServerFrameSizeSamples ); bRecorderInitialised = JamRecorder.Init ( this, iServerFrameSizeSamples );
bEnableRecording = bRecorderInitialised;
} }
// enable all channels (for the server all channel must be enabled the // enable all channels (for the server all channel must be enabled the
@ -691,6 +691,10 @@ void CServer::OnHandledSignal ( int sigNum )
RequestNewRecording(); RequestNewRecording();
break; break;
case SIGUSR2:
SetEnableRecording ( !bEnableRecording );
break;
case SIGINT: case SIGINT:
case SIGTERM: case SIGTERM:
// This should trigger OnAboutToQuit // This should trigger OnAboutToQuit
@ -705,12 +709,28 @@ void CServer::OnHandledSignal ( int sigNum )
void CServer::RequestNewRecording() void CServer::RequestNewRecording()
{ {
if ( bEnableRecording ) if ( bRecorderInitialised && bEnableRecording )
{ {
emit RestartRecorder(); emit RestartRecorder();
} }
} }
void CServer::SetEnableRecording ( bool bNewEnableRecording )
{
if ( bRecorderInitialised ) {
bEnableRecording = bNewEnableRecording;
if ( !bEnableRecording )
{
emit StopRecorder();
}
else if ( !IsRunning() )
{
// This dirty hack is for the GUI. It doesn't care.
emit StopRecorder();
}
}
}
void CServer::Start() void CServer::Start()
{ {
// only start if not already running // only start if not already running

View file

@ -197,7 +197,10 @@ public:
CVector<int>& veciJitBufNumFrames, CVector<int>& veciJitBufNumFrames,
CVector<int>& veciNetwFrameSizeFact ); CVector<int>& veciNetwFrameSizeFact );
bool GetRecorderInitialised() { return bRecorderInitialised; }
bool GetRecordingEnabled() { return bEnableRecording; } bool GetRecordingEnabled() { return bEnableRecording; }
void RequestNewRecording();
void SetEnableRecording ( bool bNewEnableRecording );
// Server list management -------------------------------------------------- // Server list management --------------------------------------------------
void UpdateServerList() { ServerListManager.Update(); } void UpdateServerList() { ServerListManager.Update(); }
@ -300,8 +303,6 @@ protected:
const CVector<CVector<int16_t> > vecvecsData, const CVector<CVector<int16_t> > vecvecsData,
CVector<uint16_t>& vecLevelsOut ); CVector<uint16_t>& vecLevelsOut );
void RequestNewRecording();
// do not use the vector class since CChannel does not have appropriate // do not use the vector class since CChannel does not have appropriate
// copy constructor/operator // copy constructor/operator
CChannel vecChannels[MAX_NUM_CHANNELS]; CChannel vecChannels[MAX_NUM_CHANNELS];
@ -350,6 +351,7 @@ protected:
// recording thread // recording thread
recorder::CJamRecorder JamRecorder; recorder::CJamRecorder JamRecorder;
bool bRecorderInitialised;
bool bEnableRecording; bool bEnableRecording;
// HTML file server status // HTML file server status
@ -383,6 +385,7 @@ signals:
const int iNumAudChan, const int iNumAudChan,
const CVector<int16_t> vecsData ); const CVector<int16_t> vecsData );
void RestartRecorder(); void RestartRecorder();
void StopRecorder();
void RecordingSessionStarted ( QString sessionDir ); void RecordingSessionStarted ( QString sessionDir );
public slots: public slots:

View file

@ -121,6 +121,28 @@ CServerDlg::CServerDlg ( CServer* pNServP,
cbxLocationCountry->setAccessibleName ( tr ( cbxLocationCountry->setAccessibleName ( tr (
"Country where the server is located combo box" ) ); "Country where the server is located combo box" ) );
// enable recorder
chbEnableRecorder->setAccessibleName( tr ( "Checkbox to turn on or off server recording" ) );
chbEnableRecorder->setWhatsThis( "<b>" + tr ( "Enable Recorder" ) + ":</b>"
+ tr ( "Checked when the recorder is enabled, otherwise unchecked. "
"The recorder will run when a session is in progress, if (set up correctly and) enabled.") );
// current session directory
edtCurrentSessionDir->setAccessibleName( tr ( "Current session directory text box (read-only)" ) );
edtCurrentSessionDir->setWhatsThis( "<b>" + tr ( "Current Session Directory" ) + ":</b>"
+ tr ( "Enabled during recording and holds the current recording session directory. "
"Disabled after recording or when the recorder is not enabled.") );
// recorder status
lblRecorderStatus->setAccessibleName ( tr ( "Recorder status label" ) );
lblRecorderStatus->setWhatsThis ( "<b>" + tr ( "Recorder Status" ) + ":</b>"
+ tr ( "Displays the current status of the recorder." ) );
// new recording
pbtNewRecording->setAccessibleName ( tr ( "Request new recording button" ) );
pbtNewRecording->setWhatsThis ( "<b>" + tr ( "New Recording" ) + ":</b>"
+ tr ( "During a recording session, the button can be used to start a new recording." ) );
// check if system tray icon can be used // check if system tray icon can be used
bSystemTrayIconAvaialbe = SystemTrayIcon.isSystemTrayAvailable(); bSystemTrayIconAvaialbe = SystemTrayIcon.isSystemTrayAvailable();
@ -268,21 +290,25 @@ lvwClients->setMinimumHeight ( 140 );
#endif #endif
// Recorder controls // Recorder controls
pbtNewRecording->setAutoDefault ( false ); if ( !pServer->GetRecorderInitialised() )
if ( !pServer->GetRecordingEnabled() )
{ {
// The recorder was not enabled from the command line // The recorder was not initialised successfully from the command line
// TODO: Once enabling from the GUI is implemented, remove // TODO: Once initialising from the GUI is implemented, remove
chbEnableRecorder->setVisible ( false );
edtCurrentSessionDir->setVisible ( false );
lblRecorderStatus->setVisible ( false ); lblRecorderStatus->setVisible ( false );
pbtNewRecording->setVisible ( false ); pbtNewRecording->setVisible ( false );
} }
edtCurrentSessionDir->setText ( "" );
pbtNewRecording->setAutoDefault ( false );
// TODO: Not yet implemented, so hide them! // TODO: Not yet implemented, so hide them!
chbEnableRecorder->setVisible ( false );
pbtRecordingDir->setVisible ( false ); pbtRecordingDir->setVisible ( false );
edtRecordingsDir->setVisible ( false ); edtRecordingsDir->setVisible ( false );
UpdateRecorderStatus ( QString::null );
// update GUI dependencies // update GUI dependencies
UpdateGUIDependencies(); UpdateGUIDependencies();
@ -318,6 +344,9 @@ lvwClients->setMinimumHeight ( 140 );
QObject::connect ( chbUseCCLicence, SIGNAL ( stateChanged ( int ) ), QObject::connect ( chbUseCCLicence, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnUseCCLicenceStateChanged ( int ) ) ); this, SLOT ( OnUseCCLicenceStateChanged ( int ) ) );
QObject::connect ( chbEnableRecorder, SIGNAL ( stateChanged ( int ) ),
this, SLOT ( OnEnableRecorderStateChanged ( int ) ) );
// line edits // line edits
QObject::connect ( edtCentralServerAddress, SIGNAL ( editingFinished() ), QObject::connect ( edtCentralServerAddress, SIGNAL ( editingFinished() ),
this, SLOT ( OnCentralServerAddressEditingFinished() ) ); this, SLOT ( OnCentralServerAddressEditingFinished() ) );
@ -355,6 +384,9 @@ lvwClients->setMinimumHeight ( 140 );
QObject::connect ( pServer, SIGNAL ( RecordingSessionStarted ( QString ) ), QObject::connect ( pServer, SIGNAL ( RecordingSessionStarted ( QString ) ),
this, SLOT ( OnRecordingSessionStarted ( QString ) ) ); this, SLOT ( OnRecordingSessionStarted ( QString ) ) );
QObject::connect ( pServer, SIGNAL ( StopRecorder() ),
this, SLOT ( OnStopRecorder() ) );
QObject::connect ( QCoreApplication::instance(), SIGNAL ( aboutToQuit() ), QObject::connect ( QCoreApplication::instance(), SIGNAL ( aboutToQuit() ),
this, SLOT ( OnAboutToQuit() ) ); this, SLOT ( OnAboutToQuit() ) );
@ -474,12 +506,23 @@ void CServerDlg::OnCentServAddrTypeActivated ( int iTypeIdx )
UpdateGUIDependencies(); UpdateGUIDependencies();
} }
void CServerDlg::OnServerStarted()
{
UpdateSystemTrayIcon ( true );
UpdateRecorderStatus ( QString::null );
}
void CServerDlg::OnServerStopped() void CServerDlg::OnServerStopped()
{ {
UpdateSystemTrayIcon ( false ); UpdateSystemTrayIcon ( false );
UpdateRecorderStatus ( QString::null ); UpdateRecorderStatus ( QString::null );
} }
void CServerDlg::OnStopRecorder()
{
UpdateRecorderStatus ( QString::null );
}
void CServerDlg::OnSysTrayActivated ( QSystemTrayIcon::ActivationReason ActReason ) void CServerDlg::OnSysTrayActivated ( QSystemTrayIcon::ActivationReason ActReason )
{ {
// on double click on the icon, show window in fore ground // on double click on the icon, show window in fore ground
@ -589,9 +632,6 @@ void CServerDlg::UpdateGUIDependencies()
} }
lblRegSvrStatus->setText ( strStatus ); lblRegSvrStatus->setText ( strStatus );
edtCurrentSessionDir->setText ( "" );
UpdateRecorderStatus ( QString::null );
} }
void CServerDlg::UpdateSystemTrayIcon ( const bool bIsActive ) void CServerDlg::UpdateSystemTrayIcon ( const bool bIsActive )
@ -652,12 +692,20 @@ void CServerDlg::ModifyAutoStartEntry ( const bool bDoAutoStart )
void CServerDlg::UpdateRecorderStatus ( QString sessionDir ) void CServerDlg::UpdateRecorderStatus ( QString sessionDir )
{ {
if ( !pServer->GetRecorderInitialised() )
{
// everything should be hidden.
return;
}
Qt::CheckState csIsEnabled;
QString currentSessionDir = edtCurrentSessionDir->text(); QString currentSessionDir = edtCurrentSessionDir->text();
bool bIsRecording = false; bool bIsRecording = false;
QString strRecorderStatus; QString strRecorderStatus;
if ( pServer->GetRecordingEnabled() ) if ( pServer->GetRecordingEnabled() )
{ {
csIsEnabled = Qt::CheckState::Checked;
if ( pServer->IsRunning() ) if ( pServer->IsRunning() )
{ {
currentSessionDir = sessionDir != QString::null ? sessionDir : ""; currentSessionDir = sessionDir != QString::null ? sessionDir : "";
@ -671,10 +719,12 @@ void CServerDlg::UpdateRecorderStatus ( QString sessionDir )
} }
else else
{ {
csIsEnabled = Qt::CheckState::Unchecked;
strRecorderStatus = tr ( "Not enabled" ); strRecorderStatus = tr ( "Not enabled" );
} }
edtCurrentSessionDir->setVisible ( pServer->GetRecordingEnabled() ); chbEnableRecorder->setCheckState ( csIsEnabled );
edtCurrentSessionDir->setEnabled ( bIsRecording ); edtCurrentSessionDir->setEnabled ( bIsRecording );
edtCurrentSessionDir->setText ( currentSessionDir ); edtCurrentSessionDir->setText ( currentSessionDir );

View file

@ -86,15 +86,19 @@ public slots:
void OnRegisterServerStateChanged ( int value ); void OnRegisterServerStateChanged ( int value );
void OnStartOnOSStartStateChanged ( int value ); void OnStartOnOSStartStateChanged ( int value );
void OnUseCCLicenceStateChanged ( int value ); void OnUseCCLicenceStateChanged ( int value );
void OnEnableRecorderStateChanged ( int value )
{ pServer->SetEnableRecording ( Qt::CheckState::Checked == value ); }
void OnCentralServerAddressEditingFinished(); void OnCentralServerAddressEditingFinished();
void OnServerNameTextChanged ( const QString& strNewName ); void OnServerNameTextChanged ( const QString& strNewName );
void OnLocationCityTextChanged ( const QString& strNewCity ); void OnLocationCityTextChanged ( const QString& strNewCity );
void OnLocationCountryActivated ( int iCntryListItem ); void OnLocationCountryActivated ( int iCntryListItem );
void OnCentServAddrTypeActivated ( int iTypeIdx ); void OnCentServAddrTypeActivated ( int iTypeIdx );
void OnTimer(); void OnTimer();
void OnServerStarted() { UpdateSystemTrayIcon ( true ); } void OnServerStarted();
void OnServerStopped(); void OnServerStopped();
void OnSvrRegStatusChanged() { UpdateGUIDependencies(); } void OnSvrRegStatusChanged() { UpdateGUIDependencies(); }
void OnStopRecorder();
void OnSysTrayMenuOpen() { ShowWindowInForeground(); } void OnSysTrayMenuOpen() { ShowWindowInForeground(); }
void OnSysTrayMenuHide() { hide(); } void OnSysTrayMenuHide() { hide(); }
void OnSysTrayMenuExit() { close(); } void OnSysTrayMenuExit() { close(); }
@ -103,7 +107,7 @@ public slots:
void keyPressEvent ( QKeyEvent *e ) // block escape key void keyPressEvent ( QKeyEvent *e ) // block escape key
{ if ( e->key() != Qt::Key_Escape ) QDialog::keyPressEvent ( e ); } { if ( e->key() != Qt::Key_Escape ) QDialog::keyPressEvent ( e ); }
void OnNewRecordingClicked() { pServer->RestartRecorder(); } void OnNewRecordingClicked() { pServer->RequestNewRecording(); }
void OnRecordingSessionStarted ( QString sessionDir ) void OnRecordingSessionStarted ( QString sessionDir )
{ UpdateRecorderStatus ( sessionDir ); } { UpdateRecorderStatus ( sessionDir ); }
}; };

View file

@ -167,22 +167,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item> <item>
<widget class="QLineEdit" name="edtCurrentSessionDir"> <widget class="QLineEdit" name="edtCurrentSessionDir">
<property name="readOnly"> <property name="readOnly">

View file

@ -146,6 +146,7 @@ CSignalUnix::CSignalUnix ( CSignalHandler* nPSignalHandler ) :
socketNotifier->setEnabled ( true ); socketNotifier->setEnabled ( true );
setSignalHandled ( SIGUSR1, true ); setSignalHandled ( SIGUSR1, true );
setSignalHandled ( SIGUSR2, true );
setSignalHandled ( SIGINT, true ); setSignalHandled ( SIGINT, true );
setSignalHandled ( SIGTERM, true ); setSignalHandled ( SIGTERM, true );
} }
@ -153,6 +154,7 @@ CSignalUnix::CSignalUnix ( CSignalHandler* nPSignalHandler ) :
CSignalUnix::~CSignalUnix() { CSignalUnix::~CSignalUnix() {
setSignalHandled ( SIGUSR1, false ); setSignalHandled ( SIGUSR1, false );
setSignalHandled ( SIGUSR2, false );
setSignalHandled ( SIGINT, false ); setSignalHandled ( SIGINT, false );
setSignalHandled ( SIGTERM, false ); setSignalHandled ( SIGTERM, false );
} }
@ -167,7 +169,7 @@ bool CSignalUnix::setSignalHandled ( int sigNum, bool state )
if ( state ) if ( state )
{ {
sa.sa_handler = CSignalUnix::signalHandler; sa.sa_handler = CSignalUnix::signalHandler;
sa.sa_flags |= SA_RESTART; sa.sa_flags = SA_RESTART;
} }
else else
{ {