Beispiel #1
0
/* read config files and store contents */
int scr_param_init()
{
  /* allocate storage and read in config files if we haven't already */
  if (scr_param_ref_count == 0) {
    /* allocate hash object to hold names we cannot read from the
     * environment */
    scr_no_user_hash = scr_hash_new();
    scr_hash_set(scr_no_user_hash, "SCR_CNTL_BASE", scr_hash_new());

    /* allocate hash object to store values from user config file,
     * if specified */
    char* user_file = user_config_path();
    if (user_file != NULL) {
      scr_user_hash = scr_hash_new();
      scr_config_read(user_file, scr_user_hash);
    }
    scr_free(&user_file);

    /* allocate hash object to store values from system config file */
    scr_system_hash = scr_hash_new();
    scr_config_read(scr_config_file, scr_system_hash);

    /* initialize our hash to cache lookups to getenv */
    scr_env_hash = scr_hash_new();

    /* warn user if he set any parameters in his environment or user
     * config file which aren't permitted */
    scr_hash_elem* elem;
    for (elem = scr_hash_elem_first(scr_no_user_hash);
         elem != NULL;
         elem = scr_hash_elem_next(elem))
    {
      /* get the parameter name */
      char* key = scr_hash_elem_key(elem);

      char* env_val = getenv(key);
      scr_hash* env_hash = scr_hash_get(scr_user_hash, key);

      /* check whether this is set in the environment */
      if (env_val != NULL || env_hash != NULL) {
        scr_err("%s cannot be set in the environment or user configuration file, ignoring setting",
          key
        );
      }
    }
  }

  /* increment our reference count */
  scr_param_ref_count++;

  return SCR_SUCCESS;
}
Beispiel #2
0
Datei: rove.c Projekt: rknLA/rove
int main(int argc, char **argv) {
    char *session_file, c;
    int i;

    struct option arguments[] = {
        {"help",			no_argument,       0, 'u'}, /* for "usage", get it?  hah, hah... */
        {"monome-columns",	required_argument, 0, 'c'},
        {"monome-rows",		required_argument, 0, 'r'},
        {"osc-prefix", 		required_argument, 0, 'p'},
        {"osc-host-port", 	required_argument, 0, 'h'},
        {"osc-listen-port",	required_argument, 0, 'l'},
        {0, 0, 0, 0}
    };

    memset(&state, 0, sizeof(rove_state_t));

    session_file = NULL;
    opterr = 0;

    while( (c = getopt_long(argc, argv, "uc:r:p:h:l:", arguments, &i)) > 0 ) {
        switch( c ) {
        case 'u':
            usage();
            exit(EXIT_FAILURE); /* should we exit after displaying usage? (i think so) */

        case 'c':
            state.config.cols = ((atoi(optarg) - 1) & 0xF) + 1;
            break;

        case 'r':
            state.config.rows = ((atoi(optarg) - 1) & 0xF) + 1;
            break;

        case 'p':
            if( *optarg == '/' ) /* remove the leading slash if there is one */
                optarg++;

            state.config.osc_prefix = strdup(optarg);
            break;

        case 'h':
            if( !is_numstr(optarg) )
                usage_printf_exit("error: \"%s\" is not a valid host port.\n\n", optarg);

            state.config.osc_host_port = strdup(optarg);
            break;

        case 'l':
            if( !is_numstr(optarg) )
                usage_printf_exit("error: \"%s\" is not a valid listen port.\n\n", optarg);

            state.config.osc_listen_port = strdup(optarg);
            break;
        }
    }

    if( optind == argc )
        usage_printf_exit("error: you did not specify a session file!\n\n");

    if( rove_settings_load(user_config_path()) )
        exit(EXIT_FAILURE);

    session_file = argv[optind];

    state.files    = rove_list_new();
    state.patterns = rove_list_new();

    state.active   = rove_list_new();
    state.staging  = rove_list_new();

    printf("\nhey, welcome to rove!\n\n"
           "you've got the following loops loaded:\n"
           "\t[rows]\t[file]\n");

    if( session_load(session_file) ) {
        printf("error parsing session file :(\n");
        exit(EXIT_FAILURE);
    }

    if( rove_list_is_empty(state.files) ) {
        fprintf(stderr, "\t(none, evidently.  get some and come play!)\n\n");
        exit(EXIT_FAILURE);
    }

    if( rove_jack_init() ) {
        fprintf(stderr, "error initializing JACK :(\n");
        exit(EXIT_FAILURE);
    }

    rove_recalculate_bpm_variables();

#define ASSIGN_IF_UNSET(k, v) do { \
	if( !k ) \
		k = v; \
} while( 0 );

    ASSIGN_IF_UNSET(state.config.osc_prefix, DEFAULT_OSC_PREFIX);
    ASSIGN_IF_UNSET(state.config.osc_host_port, DEFAULT_OSC_HOST_PORT);
    ASSIGN_IF_UNSET(state.config.osc_listen_port, DEFAULT_OSC_LISTEN_PORT);
    ASSIGN_IF_UNSET(state.config.cols, DEFAULT_MONOME_COLUMNS);
    ASSIGN_IF_UNSET(state.config.rows, DEFAULT_MONOME_ROWS);

#undef ASSIGN_IF_UNSET

    if( rove_monome_init() )
        exit(EXIT_FAILURE);

    if( rove_jack_activate() )
        exit(EXIT_FAILURE);

    signal(SIGINT, exit_on_signal);
    atexit(cleanup);

    rove_monome_run_thread(state.monome);
    monome_display_loop();

    return 0;
}