-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainconsole.cpp
113 lines (97 loc) · 4.03 KB
/
mainconsole.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/***************************************************************************
Copyright (C) 2011 - Olivier ROUITS <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the
Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
***************************************************************************/
/**
* @file mainconsole.cpp
* $Author$
* $Date$
* $Revision$
* @brief Implementation of MainConsole class that manages CLI mode interaction through QT events.
*/
#include "mainconsole.h"
#include <QCoreApplication>
MainConsole::MainConsole(Recorder *recorder, QObject *parent) : QObject(parent), qout(stdout), qin(stdin), qinNotifier(fileno(stdin), QSocketNotifier::Read, this)
{
// the recorder given by the application.
this->recorder = recorder;
application = QCoreApplication::instance();
qout << application->applicationName() << " " << tr("running in console mode") << endl;
qout << tr("Congiguration:") << endl;
qout << "pauseLevel(DB)" << "\t" << recorder->getPauseLevel() << endl;
qout << "pauseDelay(sec)" << "\t" << recorder->getPauseActivationDelay() << endl;
qout << "splitMode" << "\t" << toBoolText(recorder->isSplitMode()) << endl;
qout << "recordAtLaunch" << "\t" << toBoolText(recorder->isRecordAtLaunch()) << endl;
qout << "connections1" << "\t" << recorder->getJackCns1() << endl;
qout << "connections2" << "\t" << recorder->getJackCns2() << endl;
qout << "outputDir" << "\t" << recorder->getOutputDir().absolutePath() << endl;
qout << "processCmdLine" << "\t" << recorder->getProcessCmdLine() << endl;
qout << "jackAutoMode" << "\t" << toBoolText(recorder->isJackAutoMode()) << endl;
qout << "jackTransMode" << "\t" << toBoolText(recorder->isJackTransMode()) << endl;
connect(recorder, SIGNAL(statusChanged()), this, SLOT(onRecorderStatusChanged()));
connect(&qinNotifier, SIGNAL(activated(int)), this, SLOT(onInput()));
connect(this, SIGNAL(quit()), application, SLOT(quit()));
}
MainConsole::~MainConsole()
{
}
void MainConsole::onRecorderStatusChanged()
{
qout << "\r" << tr("[ENTER] to exit - ");
if (recorder->isRecording()) {
if (recorder->isPaused()) {
qout << tr("Waiting for sound...");
}
else {
qout << tr("Recording...");
}
}
else if (!recorder->isRecordEnabled()) {
qout << tr("Disabled");
}
else {
qout << tr("Ready");
}
qout << " "
<< recorder->getCurrentRecordSize()/1024 << "KB"
<< " [" << toTimeText(recorder->getCurrentRecordTimeSecs()) << "]"
<< " - "
<< recorder->getTotalRecordSize()/1024 << "KB"
<< " [" << toTimeText(recorder->getTotalRecordTimeSecs()) << "]";
qout << " - " << toGraphText((recorder->getLeftLevel() + recorder->getRightLevel()) / 2, recorder->getPauseLevel());
qout.flush();
}
void MainConsole::onInput()
{
qout << tr("Quit") << endl;
emit quit();
}
QString MainConsole::toGraphText(float level, float fixedLevel)
{
QString str;
int min = -40;
int max = 3;
for (int i = min; i<=max; i++)
{
if (i == (int)fixedLevel) str.append("|");
else if (i <= level) str.append("#");
else str.append(".");
}
return str;
}
QString MainConsole::toTimeText(long secs)
{
// cannot use QTime because it wraps after 24h
return QString("%1:%2:%3").arg(secs/3600,2,10,QLatin1Char('0')).arg((secs/60)%60,2,10,QLatin1Char('0')).arg(secs%60,2,10,QLatin1Char('0'));
}