Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
	midi_event = kick_drum;

	char option;
	while((option = getopt(argc, argv, "at:m:c:i:n:")) != -1)
		switch(option) {
			case 'a':
				analog = 1;
				break;
			case 't':
				threshold = atof(optarg);
				break;
			case 'm':
				min_time_between_hits = atoi(optarg);
				break;
			case 'c':
				midi_event.channel = atoi(optarg);
				break;
			case 'i':
				midi_event.instrument = atoi(optarg);
				break;
			case 'n':
				midi_event.note = atoi(optarg);
				break;

			case '?':
				exit(1);
			default:
				printf("What's going on here?\n");
				break;
		}

	jack_start();

	while(1)
		sleep(1);

	return 0;
}
Ejemplo n.º 2
0
int
jack_watchdog(void) {
    int		watchdog_state = WATCHDOG_STATE_CLIENT_ACTIVE;

    while (!shutdown) {
#ifdef EXTRA_DEBUG
	if (debug) {
	    fprintf (stderr, "JACK Watchdog loop...\n");
	}
#endif

	if (gtkui_restarting) {
	    pthread_join (gtkui_thread_p, NULL);
	    start_gtkui_thread ();
	}

    /* poll lash for events */
    #ifndef WITHOUT_LASH
    lash_pollevent();
    #endif

	/* everybody sleeps */
	usleep (250000);

	switch (watchdog_state) {
	case WATCHDOG_STATE_CLIENT_ACTIVE:
	    /* make sure the thread didn't go away */
	    if (client == NULL) {
		if (debug && !shutdown) {
		    fprintf (stderr, "JACK Watchdog: JACK client went away!  Attempting to recover.\n");
		}
		watchdog_state = WATCHDOG_STATE_NO_CLIENT;
		usleep (250000);
	    }
	    else {
#ifdef JOIN_JACK_CLIENT_THREAD
		/* if there's a jack client thread, wait for it to die */
		if (debug) {
		    fprintf (stderr, "JACK Watchdog: Waiting for JACK client thread 0x%lx to exit.\n", jack_thread_p);
		}
		if (pthread_join (jack_thread_p, NULL) == 0) {
		    if (debug) {
			fprintf (stderr, "JACK Watchdog: pthread_join() successful!\n");
		    }
		    /* client is invalid at this point, so don't call jack_client_close() */
		    client = NULL;
		    jack_thread_p = 0;
		    jack_running = 0;
		    watchdog_state = WATCHDOG_STATE_NO_CLIENT;
		    usleep (250000);
		}
		else {
		    if (debug) {
			fprintf (stderr, "JACK Watchdog: pthread_join() on JACK client thread 0x%lx failed!\n", jack_thread_p);
		    }
		}
#else
		if (jack_thread_p == 0) {
		    if (debug) {
			fprintf (stderr, "JACK Watchdog: JACK thread went away!  Attempting to recover.\n");
		    }
		    client       = NULL;
		    jack_running = 0;
		    watchdog_state = WATCHDOG_STATE_NO_CLIENT;
		    usleep (250000);
		}
#endif
	    }
	    usleep (250000);
	    break;

	case WATCHDOG_STATE_NO_CLIENT:
	    /* open a new client */
	    if (jack_init () == 0) {
		if (debug) {
		    fprintf (stderr, "JACK Watchdog: Initialized JACK client.\n");
		}
		jack_thread_p = 0;
		jack_running = 0;
		watchdog_state = WATCHDOG_STATE_CLIENT_INIT;
	    }
	    else {
		if (debug) {
		    fprintf (stderr, "JACK Watchdog: Waiting for JACK server...\n");
		}
	    }
	    usleep (250000);
	    break;

	case WATCHDOG_STATE_CLIENT_INIT:
	    /* start client */
	    if (jack_start () == 0) {
		if (debug) {
		    fprintf (stderr, "JACK Watchdog: Started JACK with client thread 0x%lx\n", jack_thread_p);
		}
		jack_running = 1;
		watchdog_state = WATCHDOG_STATE_CLIENT_ACTIVE;
	    }
	    else {
		if (debug) {
		    fprintf (stderr, "JACK Watchdog: Unable to start JACK client.\n");
		}
		jack_thread_p = 0;
		if (client != NULL) {
		    /* no thread to wait for unless jack client actually starts */
		    jack_client_close (client);
		    client = NULL;
		}
		watchdog_state = WATCHDOG_STATE_NO_CLIENT;
	    }
	    usleep (250000);
	    break;
	}
    }

    usleep (250000);

    if ((client != NULL) && (jack_thread_p != 0)) {
	jack_client_close (client);
	client = NULL;
	jack_thread_p = 0;
    }

    /* not reached */
    return 0;
}