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