djm-fix.cpp
branchv_0
changeset 11 5b351628a377
parent 10 4d95b089457d
child 12 15d87fdd6e6c
     1.1 --- a/djm-fix.cpp	Mon Jan 04 00:15:56 2021 +0100
     1.2 +++ b/djm-fix.cpp	Mon Jan 04 13:38:08 2021 +0100
     1.3 @@ -70,22 +70,29 @@
     1.4   *   make                                                        # we can skip this step, it will be compiled on the first run
     1.5   *
     1.6   * Run:
     1.7 - *   make run
     1.8 + *   make run                                                    # in most cases
     1.9 + *   build/djm-fix 'Pioneer DJ.*'                                # or provide custom name pattern (regular expression) to select the proper card
    1.10   *
    1.11   * Stop:
    1.12   *   press Ctrl+C
    1.13 + * 
    1.14 + * Look for updates in the Mercurial repositories and at <https://blog.frantovo.cz/c/387/>.
    1.15   */
    1.16  
    1.17  int main(int argc, char**argv) {
    1.18 -	std::string deviceName = argc == 2 ? argv[1] : "hw:1"; // FIXME: parse CLI options + automatic device search
    1.19 +	try {
    1.20 +		std::string cardNamePattern = argc == 2 ? argv[1] : "Pioneer DJ.*";
    1.21  
    1.22 -	signal(SIGINT, interrupt);
    1.23 -	std::unique_ptr<djmfix::DJMFix> djmFix(djmfix::create());
    1.24 -	std::unique_ptr<djmfix::alsa::AlsaBridge> alsaBridge(djmfix::alsa::create(djmFix.get(), deviceName));
    1.25 +		signal(SIGINT, interrupt);
    1.26 +		std::unique_ptr<djmfix::DJMFix> djmFix(djmfix::create());
    1.27 +		std::unique_ptr<djmfix::alsa::AlsaBridge> alsaBridge(djmfix::alsa::create(djmFix.get(), cardNamePattern));
    1.28  
    1.29 -	alsaBridge->start();
    1.30 -	while (run) std::this_thread::sleep_for(std::chrono::milliseconds(100));
    1.31 -	alsaBridge->stop();
    1.32 +		alsaBridge->start();
    1.33 +		while (run) std::this_thread::sleep_for(std::chrono::milliseconds(100));
    1.34 +		alsaBridge->stop();
    1.35  
    1.36 -	return 0;
    1.37 +		return 0;
    1.38 +	} catch (const std::exception& e) {
    1.39 +		std::cerr << "ERROR: " << e.what() << std::endl; // TODO: do not mess STDIO
    1.40 +	}
    1.41  }