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)
     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 
    18 #include <memory>
    19 #include <iostream>
    20 #include <chrono>
    21 #include <thread>
    22 #include <csignal>
    23 #include <atomic>
    24 
    25 #include "DJMFix.h"
    26 #include "AlsaBridge.h"
    27 
    28 static std::atomic<bool> run{true};
    29 
    30 void interrupt(int signal) {
    31 	run = false;
    32 	std::cerr << "interrupt()" << std::endl; // TODO: do not mess STDIO
    33 }
    34 
    35 int main(int argc, char**argv) {
    36 	std::string deviceName = argc == 2 ? argv[1] : "hw:1"; // FIXME: parse CLI options + automatic device search
    37 	
    38 	signal(SIGINT, interrupt);
    39 	std::unique_ptr<djmfix::DJMFix> djmFix(djmfix::create());
    40 	std::unique_ptr<djmfix::alsa::AlsaBridge> alsaBridge(djmfix::alsa::create(djmFix.get(), deviceName));
    41 
    42 	alsaBridge->start();
    43 	while (run) std::this_thread::sleep_for(std::chrono::milliseconds(100));
    44 	alsaBridge->stop();
    45 
    46 	return 0;
    47 }