author | František Kučera <franta-hg@frantovo.cz> |
Sat, 19 Dec 2020 23:59:39 +0100 | |
branch | v_0 |
changeset 6 | bddcf2bf29f2 |
parent 5 | ef8f4023e32e |
child 10 | 4d95b089457d |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* DJM-Fix |
|
3 |
* Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
5 |
* This program is free software: you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation, version 3 of the License. |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
*/ |
|
17 |
||
1 | 18 |
#include <memory> |
19 |
#include <iostream> |
|
2
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
20 |
#include <chrono> |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
21 |
#include <thread> |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
22 |
#include <csignal> |
5
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
23 |
#include <atomic> |
1 | 24 |
|
25 |
#include "DJMFix.h" |
|
2
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
26 |
#include "AlsaBridge.h" |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
27 |
|
5
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
28 |
static std::atomic<bool> run{true}; |
2
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
29 |
|
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
30 |
void interrupt(int signal) { |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
31 |
run = false; |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
32 |
std::cerr << "interrupt()" << std::endl; // TODO: do not mess STDIO |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
33 |
} |
1 | 34 |
|
0 | 35 |
int main(int argc, char**argv) { |
5
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
36 |
std::string deviceName = argc == 2 ? argv[1] : "hw:1"; // FIXME: parse CLI options + automatic device search |
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
37 |
|
2
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
38 |
signal(SIGINT, interrupt); |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
39 |
std::unique_ptr<djmfix::DJMFix> djmFix(djmfix::create()); |
5
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
40 |
std::unique_ptr<djmfix::alsa::AlsaBridge> alsaBridge(djmfix::alsa::create(djmFix.get(), deviceName)); |
1 | 41 |
|
2
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
42 |
alsaBridge->start(); |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
43 |
while (run) std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
44 |
alsaBridge->stop(); |
1 | 45 |
|
0 | 46 |
return 0; |
47 |
} |