File: main.cpp

package info (click to toggle)
qjackrcd 1.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 352 kB
  • sloc: cpp: 1,052; sh: 42; makefile: 5
file content (189 lines) | stat: -rw-r--r-- 9,080 bytes parent folder | download | duplicates (2)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/***************************************************************************
 Copyright (C) 2011 - Olivier ROUITS <olivier.rouits@free.fr>

 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 main.cpp
* $Author$
* $Date$
* $Revision$
* @brief Main function implementation
*/

/**
* @mainpage
*
* QJackRcd is a simple QT application to record JACK server outputs (use it with QJackCtl)
*
* The initial goal of this project is to record from an old tape, with an automatic split/pause feature when you are away. Another goal is to have a litle tool ready to use with a minimum of configuration for simple stereo recording needs.
* It manages natively silence by threshold and activation time. Silence event can be used to pause the record or to split files by closing the current record and opening a new one.
* Optionaly QJackRcd is enable to post-process each file record at closure in background mode. the command is a simple bash command.
*
* Made with QTCreator
* It Depends on jack, sndfile and qt4 libraries.
*/
#include "mainwindow.h"
#include "mainconsole.h"
#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include <QSettings>
#include <QCommandLineParser>

#define RCD_APP_NAME "qjackrcd" // Name of the recorder instance used in jack client name
#define RCD_APP_VERSION "1.1" // Version of recorder application
#define RCD_JK_NAME "QJackRcd" // Name of the recorder instance used in jack client name

//=============================================================================
// Settings methods
//=============================================================================

void readSettings(Recorder &recorder, QSettings &settings, QCommandLineParser &parser)
{
    if (!parser.isSet("no-settings")) {
        settings.beginGroup("Recorder");
        recorder.setPauseLevel(settings.value("pauseLevel", -20).toFloat());
        recorder.setPauseActivationDelay(settings.value("pauseActivationDelay", 3).toInt());
        recorder.setSplitMode(settings.value("splitMode", false).toBool());
        recorder.setRecordAtLaunch(settings.value("recordAtLaunch", false).toBool());
        recorder.setProcessCmdLine(settings.value("processCmdLine", "").toString());
        recorder.setJackCns1(settings.value("jackCns1", "").toString());
        recorder.setJackCns2(settings.value("jackCns2", "").toString());
        recorder.setJackAutoMode(settings.value("jackAuto", true).toBool());
        recorder.setJackTransMode(settings.value("jackTrans", true).toBool());
        recorder.setOutputDir(QDir(settings.value("outputDir", QDir::home().absolutePath()).toString()));
        settings.endGroup();
    }

    if (parser.isSet("l")) recorder.setPauseLevel(parser.value("l").toInt());
    if (parser.isSet("d")) recorder.setPauseActivationDelay(parser.value("d").toInt());
    if (parser.isSet("s")) recorder.setSplitMode(true);
    if (parser.isSet("r")) recorder.setRecordAtLaunch(true);
    if (parser.isSet("dir")) recorder.setOutputDir(QDir(parser.value("dir")));
    if (parser.isSet("pcmd")) recorder.setProcessCmdLine(parser.value("pcmd"));
    if (parser.isSet("jack-cns1")) recorder.setJackCns1(parser.value("jack-cns1"));
    if (parser.isSet("jack-cns2")) recorder.setJackCns1(parser.value("jack-cns2"));
    if (parser.isSet("jack-auto")) recorder.setJackAutoMode(true);
    if (parser.isSet("jack-trans")) recorder.setJackTransMode(true);
}

void writeSettings(Recorder &recorder, QSettings &settings, QCommandLineParser &parser)
{
    if (!parser.isSet("no-settings")) {
        settings.beginGroup("Recorder");
        settings.setValue("pauseLevel", recorder.getPauseLevel());
        settings.setValue("pauseActivationDelay", recorder.getPauseActivationDelay());
        settings.setValue("splitMode", recorder.isSplitMode());
        settings.setValue("recordAtLaunch", recorder.isRecordAtLaunch());
        settings.setValue("processCmdLine", recorder.getProcessCmdLine());
        settings.setValue("jackCns1", recorder.getJackCns1());
        settings.setValue("jackCns2", recorder.getJackCns2());
        settings.setValue("jackAuto", recorder.isJackAutoMode());
        settings.setValue("jackTrans", recorder.isJackTransMode());
        settings.setValue("outputDir", recorder.getOutputDir().absolutePath());
        settings.endGroup();
    }
}

//=============================================================================
// Main
//=============================================================================

/**
 * @fn int main (int argc, char *argv[])
 * @brief Program entry.
 *
 * Main doesn't take any special paramerter, only standard QT parameters.
 *
 * @return 0 if normal GUI quit.
 */
int main(int argc, char *argv[])
{
    int exitcode = 0;

    // Application
    QApplication application(argc, argv);

    application.setApplicationName(RCD_APP_NAME);
    application.setApplicationVersion(RCD_APP_VERSION);

    // Translator
    QString locale = QLocale::system().name();
    QTranslator translator;

    // for packaged system install
    if (!translator.load(QString("qjackrcd_") + locale, "/usr/share/qjackrcd/locale"))
        // for install from source
        if (!translator.load(QString("qjackrcd_") + locale, "/usr/local/share/qjackrcd/locale"))
            // for dev test
            translator.load(QString("qjackrcd_") + locale, "locale");

    application.installTranslator(&translator);

    // CLI && Settings
    QCommandLineParser parser;
    parser.setApplicationDescription("Jack simple stereo recorder");
    parser.addHelpOption();
    parser.addVersionOption();

    parser.addOption(QCommandLineOption(QStringList() << "c" << "config", application.translate("main","Show config.")));
    parser.addOption(QCommandLineOption(QStringList() << "l" << "level", application.translate("main","Pause level in db."), "level"));
    parser.addOption(QCommandLineOption(QStringList() << "d" << "delay", application.translate("main","Pause activation delay in seconds."), "delay"));
    parser.addOption(QCommandLineOption(QStringList() << "s" << "split", application.translate("main","Split files mode.")));
    parser.addOption(QCommandLineOption(QStringList() << "r" << "record", application.translate("main","Record at launch.")));
    parser.addOption(QCommandLineOption("dir", application.translate("main","Output directory."), "dirpath"));
    parser.addOption(QCommandLineOption("pcmd", application.translate("main","Post process command line."), "cmdline"));
    parser.addOption(QCommandLineOption("jack-cns1", application.translate("main","Connections string channel 1."), "connections"));
    parser.addOption(QCommandLineOption("jack-cns2", application.translate("main","Connections string channel 2."), "connections"));
    parser.addOption(QCommandLineOption("jack-auto", application.translate("main","Auto connect new jack ports.")));
    parser.addOption(QCommandLineOption("jack-trans", application.translate("main","Process jack transport events.")));

    //parser.addOption(QCommandLineOption("exit-on-pause", application.translate("main","Exit the application at the first pause.")));
    //parser.addOption(QCommandLineOption("exit-on-time", application.translate("main","Exit the application after a delay in seconds."), "delay"));
    //parser.addOption(QCommandLineOption("exit-on-size", application.translate("main","Exit the application after a size of recorded data reached."), "size"));

    parser.addOption(QCommandLineOption("no-gui", application.translate("main","No GUI mode, command line only.")));
    parser.addOption(QCommandLineOption("no-settings", application.translate("main","Ignore stored settings and do not change them.")));

    parser.process(application);

    QSettings settings(application.applicationName(), application.applicationName());

    // Recorder
    Recorder recorder(RCD_JK_NAME);
    readSettings(recorder, settings, parser);

    if (parser.isSet("c")) {
        MainConsole console(&recorder);
    }
    else {
        recorder.start();
        if (parser.isSet("no-gui")) {
            MainConsole console(&recorder);
            exitcode =  application.exec();
        }
        else {
            MainWindow window(&recorder);
            window.show();
            exitcode =  application.exec();
        }
    }

    writeSettings(recorder, settings, parser);

    return exitcode;
}