コード例 #1
0
ファイル: utils.c プロジェクト: somebloke/flame-libmboard
void complain_then_quit(char * msg) {
    
    /* complain */
    fprintf(stderr, "\nERROR: ");
    fprintf(stderr, msg);
    fprintf(stderr, "\n -- Quitting -- \n");
    
    /* clean up */
    shutdown_env();
    
    /* quit */
    exit(1);
}
コード例 #2
0
ファイル: main.c プロジェクト: pmyadlowsky/qmx
int main(int argc, char **argv) {
	struct pollfd polls[MAX_POLL_ITEMS];
	int opt, background, fdin, nfds, watch_alsa;
	int con_in, msg_in;
	background = 0;
	watch_alsa = 0;
	client_name = DEFAULT_CLIENT_NAME;
	server_name = DEFAULT_SERVER_NAME;
	msg_port = DEFAULT_MSG_PORT;
	sampling_rate = DEFAULT_SAMPLING_RATE;
	period_frames = DEFAULT_PERIOD_SIZE;
	while ((opt = getopt(argc, argv, "adn:p:P:r:s:")) != -1) {
		switch (opt) {
			case 'a': watch_alsa = 1; break;
			case 'd': background = 1; break;
			case 'j': use_jack = 1; break;
			case 'n': client_name = optarg; break;
			case 'P': msg_port = atoi(optarg); break;
			case 'p': period_frames = atoi(optarg); break;
			case 'r': sampling_rate = atoi(optarg); break;
			case 's': server_name = optarg; break;
			default:
				fprintf(stderr, "invalid option: %c", opt);
				exit(1);
			}
		}
	if (background) {
		set_handler(SIGCHLD, sigsnag);
		if (fork() > 0) _exit(0);
		}
	set_handler(SIGINT, sigsnag);
	set_handler(SIGTERM, sigsnag);
	set_handler(SIGABRT, sigsnag);
	set_handler(SIGHUP, sigsnag);
	set_handler(SIGQUIT, sigsnag);
	scm_init_guile();
	init_env();
	if (use_jack) start_jack(NULL);
	else {
		size_t memsize = QMX_CHANNELS * period_frames * sizeof(sample_t);
		fixed_cauldron = (sample_t *)malloc(memsize);
		int ret = mlock(fixed_cauldron, memsize);
		if (ret == 0) log_msg("MIXMEM locked: %lu\n", memsize);
		else log_msg("MIXMEM not locked: %s\n", strerror(errno));
		}
	start_outbuffer();
	scm_c_define("jack-sampling-rate", scm_from_int(sampling_rate));
	while (optind < argc) {
		log_msg("load %s\n", argv[optind]);
		scm_c_primitive_load(argv[optind]);
		optind++;
		}
	fdin = fileno(stdin);
	nfds = 0;
	con_in = -1;
	if (!background) {
		con_in = nfds;
		polls[nfds].fd = fdin;
		polls[nfds].events = POLLIN;
		nfds++;
		}
	msg_in = -1;
	if (msg_socket() >= 0) {
		msg_in = nfds;
		polls[nfds].fd = msg_socket();
		polls[nfds].events = POLLIN;
		nfds++;
		}
	if (isatty(fdin)) rl_callback_handler_install(prompt, line_handler);
	running = 1;
	if (!use_jack) spawn_detached_thread(mix_thread_abs, NULL);
	while (running) {
		if (watch_alsa) check_card_event();
		if (poll(polls, nfds, POLL_TIMEOUT) < 1) continue;
		if ((con_in >= 0) && (polls[con_in].revents & POLLIN))
			process_line(fdin);
		if ((msg_in >= 0) && (polls[msg_in].revents & POLLIN))
			msg_process();
		}
	if (isatty(fdin)) rl_callback_handler_remove();
	shutdown_env();
	log_msg("bye!\n");
	cleanup();
	return 0;
	}