djm-fix.cpp
branchv_0
changeset 11 5b351628a377
parent 10 4d95b089457d
child 12 15d87fdd6e6c
equal deleted inserted replaced
10:4d95b089457d 11:5b351628a377
    68  *
    68  *
    69  * Compile:
    69  * Compile:
    70  *   make                                                        # we can skip this step, it will be compiled on the first run
    70  *   make                                                        # we can skip this step, it will be compiled on the first run
    71  *
    71  *
    72  * Run:
    72  * Run:
    73  *   make run
    73  *   make run                                                    # in most cases
       
    74  *   build/djm-fix 'Pioneer DJ.*'                                # or provide custom name pattern (regular expression) to select the proper card
    74  *
    75  *
    75  * Stop:
    76  * Stop:
    76  *   press Ctrl+C
    77  *   press Ctrl+C
       
    78  * 
       
    79  * Look for updates in the Mercurial repositories and at <https://blog.frantovo.cz/c/387/>.
    77  */
    80  */
    78 
    81 
    79 int main(int argc, char**argv) {
    82 int main(int argc, char**argv) {
    80 	std::string deviceName = argc == 2 ? argv[1] : "hw:1"; // FIXME: parse CLI options + automatic device search
    83 	try {
       
    84 		std::string cardNamePattern = argc == 2 ? argv[1] : "Pioneer DJ.*";
    81 
    85 
    82 	signal(SIGINT, interrupt);
    86 		signal(SIGINT, interrupt);
    83 	std::unique_ptr<djmfix::DJMFix> djmFix(djmfix::create());
    87 		std::unique_ptr<djmfix::DJMFix> djmFix(djmfix::create());
    84 	std::unique_ptr<djmfix::alsa::AlsaBridge> alsaBridge(djmfix::alsa::create(djmFix.get(), deviceName));
    88 		std::unique_ptr<djmfix::alsa::AlsaBridge> alsaBridge(djmfix::alsa::create(djmFix.get(), cardNamePattern));
    85 
    89 
    86 	alsaBridge->start();
    90 		alsaBridge->start();
    87 	while (run) std::this_thread::sleep_for(std::chrono::milliseconds(100));
    91 		while (run) std::this_thread::sleep_for(std::chrono::milliseconds(100));
    88 	alsaBridge->stop();
    92 		alsaBridge->stop();
    89 
    93 
    90 	return 0;
    94 		return 0;
       
    95 	} catch (const std::exception& e) {
       
    96 		std::cerr << "ERROR: " << e.what() << std::endl; // TODO: do not mess STDIO
       
    97 	}
    91 }
    98 }