djm-fix.cpp
author František Kučera <franta-hg@frantovo.cz>
Sat, 19 Dec 2020 17:33:16 +0100
branchv_0
changeset 5 ef8f4023e32e
parent 2 f34476ab597f
child 10 4d95b089457d
permissions -rw-r--r--
sending and receiving MIDI messages through ALSA (the dirty way)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * DJM-Fix
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
4ee5349be21d project skeleton
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
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
1
98274757fcf6 more bones
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    18
#include <memory>
98274757fcf6 more bones
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    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
98274757fcf6 more bones
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    24
98274757fcf6 more bones
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    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
98274757fcf6 more bones
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    34
0
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    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
98274757fcf6 more bones
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    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
98274757fcf6 more bones
František Kučera <franta-hg@frantovo.cz>
parents: 0
diff changeset
    45
0
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	return 0;
4ee5349be21d project skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
}