author | František Kučera <franta-hg@frantovo.cz> |
Sat, 27 Nov 2021 23:15:15 +0100 | |
branch | v_0 |
changeset 22 | 6ba42fe7cf0e |
parent 20 | b6dd93370d8c |
permissions | -rw-r--r-- |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* Relational pipes |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
*/ |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
17 |
#include <memory> |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
18 |
#include <csignal> |
20
b6dd93370d8c
add header for std::bind
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
19 |
#include <functional> |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
20 |
|
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
#include <relpipe/writer/RelpipeWriterException.h> |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
#include <relpipe/writer/Factory.h> |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
23 |
#include <relpipe/cli/CLI.h> |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
24 |
|
8
8ef1980db907
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
25 |
#include "Configuration.h" |
8ef1980db907
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
26 |
#include "CLIParser.h" |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
27 |
#include "JackException.h" |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
28 |
#include "JackCommand.h" |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
29 |
|
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
using namespace relpipe::cli; |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
using namespace relpipe::writer; |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
32 |
using namespace relpipe::in::jack; |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
33 |
|
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
34 |
static std::shared_ptr<JackCommand> jackCommand = nullptr; |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
|
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
36 |
void finish(int sig) { |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
37 |
if (jackCommand) jackCommand->finish(sig); |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
} |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
|
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
int main(int argc, char** argv) { |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
setlocale(LC_ALL, ""); |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
CLI::untieStdIO(); |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
CLI cli(argc, argv); |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
45 |
|
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
try { |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
47 |
signal(SIGHUP, finish); |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
48 |
signal(SIGINT, finish); |
8
8ef1980db907
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
49 |
CLIParser cliParser; |
8ef1980db907
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
50 |
Configuration configuration = cliParser.parse(cli.arguments()); |
8ef1980db907
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
51 |
jackCommand.reset(new JackCommand(configuration)); |
2
e5f0d3f92eb4
pass RelationalWriter instead of std::ostream to the JackCommand
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
52 |
std::shared_ptr<RelationalWriter> writer(Factory::create(std::cout)); |
e5f0d3f92eb4
pass RelationalWriter instead of std::ostream to the JackCommand
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
53 |
jackCommand->processJackStream(writer, std::bind(fflush, stdout)); // std::bind(fflush, XXX) Factory::create(XXX) must be the same stream XXX |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
54 |
resultCode = CLI::EXIT_CODE_SUCCESS; |
11
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
55 |
} catch (RelpipeCLIException e) { |
22
6ba42fe7cf0e
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
56 |
fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str()); |
11
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
57 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
58 |
resultCode = e.getExitCode(); |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
59 |
} catch (JackException e) { |
22
6ba42fe7cf0e
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
60 |
fwprintf(stderr, L"Caught JACK exception: %ls\n", e.getMessage().c_str()); |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
61 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
62 |
resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR; |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
63 |
} catch (RelpipeWriterException e) { |
22
6ba42fe7cf0e
exception: fix typo: getMessge() → getMessage()
František Kučera <franta-hg@frantovo.cz>
parents:
20
diff
changeset
|
64 |
fwprintf(stderr, L"Caught Writer exception: %ls\n", e.getMessage().c_str()); |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
65 |
fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount()); |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
66 |
resultCode = CLI::EXIT_CODE_DATA_ERROR; |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
67 |
} |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
68 |
|
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
69 |
return resultCode; |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
70 |
} |