djm-fix.cpp
branchv_0
changeset 12 15d87fdd6e6c
parent 11 5b351628a377
child 13 334b727f7516
equal deleted inserted replaced
11:5b351628a377 12:15d87fdd6e6c
    22 #include <csignal>
    22 #include <csignal>
    23 #include <atomic>
    23 #include <atomic>
    24 
    24 
    25 #include "DJMFix.h"
    25 #include "DJMFix.h"
    26 #include "AlsaBridge.h"
    26 #include "AlsaBridge.h"
       
    27 #include "Logger.h"
    27 
    28 
    28 static std::atomic<bool> run{true};
    29 static std::atomic<bool> run{true};
    29 
    30 
    30 void interrupt(int signal) {
    31 void interrupt(int signal) {
    31 	run = false;
    32 	run = false;
    32 	std::cerr << "interrupt()" << std::endl; // TODO: do not mess STDIO
       
    33 }
    33 }
    34 
    34 
    35 /**
    35 /**
    36  * The support for Pioneer DJ DJM-250MK2 (an external USB sound card / mixer) was added to the Linux (kernel) by these patches:
    36  * The support for Pioneer DJ DJM-250MK2 (an external USB sound card / mixer) was added to the Linux (kernel) by these patches:
    37  *
    37  *
    78  * 
    78  * 
    79  * Look for updates in the Mercurial repositories and at <https://blog.frantovo.cz/c/387/>.
    79  * Look for updates in the Mercurial repositories and at <https://blog.frantovo.cz/c/387/>.
    80  */
    80  */
    81 
    81 
    82 int main(int argc, char**argv) {
    82 int main(int argc, char**argv) {
       
    83 	using L = djmfix::logging::Level;
       
    84 	std::unique_ptr<djmfix::logging::Logger> logger(djmfix::logging::create(std::cerr, L::INFO));
    83 	try {
    85 	try {
       
    86 		logger->log(L::INFO, "djm-fix started");
    84 		std::string cardNamePattern = argc == 2 ? argv[1] : "Pioneer DJ.*";
    87 		std::string cardNamePattern = argc == 2 ? argv[1] : "Pioneer DJ.*";
    85 
    88 
    86 		signal(SIGINT, interrupt);
    89 		signal(SIGINT, interrupt);
    87 		std::unique_ptr<djmfix::DJMFix> djmFix(djmfix::create());
    90 		std::unique_ptr<djmfix::DJMFix> djmFix(djmfix::create(logger.get()));
    88 		std::unique_ptr<djmfix::alsa::AlsaBridge> alsaBridge(djmfix::alsa::create(djmFix.get(), cardNamePattern));
    91 		std::unique_ptr<djmfix::alsa::AlsaBridge> alsaBridge(djmfix::alsa::create(djmFix.get(), cardNamePattern, logger.get()));
    89 
    92 
    90 		alsaBridge->start();
    93 		alsaBridge->start();
    91 		while (run) std::this_thread::sleep_for(std::chrono::milliseconds(100));
    94 		while (run) std::this_thread::sleep_for(std::chrono::milliseconds(100));
       
    95 		
       
    96 		std::cerr << std::endl;
       
    97 		logger->log(L::INFO, "djm-fix stopping");
       
    98 		
    92 		alsaBridge->stop();
    99 		alsaBridge->stop();
    93 
   100 
    94 		return 0;
   101 		return 0;
    95 	} catch (const std::exception& e) {
   102 	} catch (const std::exception& e) {
    96 		std::cerr << "ERROR: " << e.what() << std::endl; // TODO: do not mess STDIO
   103 		logger->log(L::SEVERE, e.what());
    97 	}
   104 	}
    98 }
   105 }