]> git.sesse.net Git - nageru/blobdiff - futatabi/flags.cpp
On errors, abort() instead of exit(1); exit() in a multithreaded program just gives...
[nageru] / futatabi / flags.cpp
index 7a8246030abf7d485836d467800612aaef5a7c95..eea7c0700358f2752318e9d0d18fa56eff536d47 100644 (file)
@@ -4,18 +4,22 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-
 #include <utility>
 
 using namespace std;
 
 Flags global_flags;
+int flow_initialized_interpolation_quality;
 
 // Long options that have no corresponding short option.
 enum LongOption {
        OPTION_HELP = 1000,
        OPTION_SLOW_DOWN_INPUT = 1001,
-       OPTION_HTTP_PORT = 1002
+       OPTION_HTTP_PORT = 1002,
+       OPTION_TALLY_URL = 1003,
+       OPTION_CUE_IN_POINT_PADDING = 1004,
+       OPTION_CUE_OUT_POINT_PADDING = 1005,
+       OPTION_MIDI_MAPPING = 1006
 };
 
 void usage()
@@ -34,11 +38,15 @@ void usage()
        fprintf(stderr, "                                  2 = default (realtime 720p on fast embedded GPUs)\n");
        fprintf(stderr, "                                  3 = good (realtime 720p on GTX 970 or so)\n");
        fprintf(stderr, "                                  4 = best (not realtime on any current GPU)\n");
+       fprintf(stderr, "      --cue-in-point-padding SECS   move cue-in N seconds earlier on set\n");
+       fprintf(stderr, "      --cue-out-point-padding SECS  move cue-out N seconds later on set\n");
        fprintf(stderr, "  -d, --working-directory DIR     where to store frames and database\n");
        fprintf(stderr, "      --http-port PORT            which port to listen on for output\n");
+       fprintf(stderr, "      --tally-url URL             URL to get tally color from (polled every 100 ms)\n");
+       fprintf(stderr, "      --midi-mapping=FILE         start with the given MIDI controller mapping\n");
 }
 
-void parse_flags(int argc, char * const argv[])
+void parse_flags(int argc, char *const argv[])
 {
        static const option long_options[] = {
                { "help", no_argument, 0, OPTION_HELP },
@@ -49,9 +57,13 @@ void parse_flags(int argc, char * const argv[])
                { "interpolation-quality", required_argument, 0, 'q' },
                { "working-directory", required_argument, 0, 'd' },
                { "http-port", required_argument, 0, OPTION_HTTP_PORT },
+               { "tally-url", required_argument, 0, OPTION_TALLY_URL },
+               { "cue-in-point-padding", required_argument, 0, OPTION_CUE_IN_POINT_PADDING },
+               { "cue-out-point-padding", required_argument, 0, OPTION_CUE_OUT_POINT_PADDING },
+               { "midi-mapping", required_argument, 0, OPTION_MIDI_MAPPING },
                { 0, 0, 0, 0 }
        };
-       for ( ;; ) {
+       for (;;) {
                int option_index = 0;
                int c = getopt_long(argc, argv, "w:h:r:q:d:", long_options, &option_index);
 
@@ -73,7 +85,7 @@ void parse_flags(int argc, char * const argv[])
                                global_flags.output_framerate = num;
                        } else {
                                fprintf(stderr, "Invalid frame rate given (must be on the form N or N/M)\n");
-                               exit(1);
+                               abort();
                        }
                        break;
                }
@@ -82,6 +94,7 @@ void parse_flags(int argc, char * const argv[])
                        break;
                case 'q':
                        global_flags.interpolation_quality = atoi(optarg);
+                       global_flags.interpolation_quality_set = true;
                        break;
                case 'd':
                        global_flags.working_directory = optarg;
@@ -89,6 +102,20 @@ void parse_flags(int argc, char * const argv[])
                case OPTION_HTTP_PORT:
                        global_flags.http_port = atoi(optarg);
                        break;
+               case OPTION_TALLY_URL:
+                       global_flags.tally_url = optarg;
+                       break;
+               case OPTION_CUE_IN_POINT_PADDING:
+                       global_flags.cue_in_point_padding_seconds = atof(optarg);
+                       global_flags.cue_in_point_padding_set = true;
+                       break;
+               case OPTION_CUE_OUT_POINT_PADDING:
+                       global_flags.cue_out_point_padding_seconds = atof(optarg);
+                       global_flags.cue_out_point_padding_set = true;
+                       break;
+               case OPTION_MIDI_MAPPING:
+                       global_flags.midi_mapping_filename = optarg;
+                       break;
                case OPTION_HELP:
                        usage();
                        exit(0);
@@ -96,13 +123,19 @@ void parse_flags(int argc, char * const argv[])
                        fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
                        fprintf(stderr, "\n");
                        usage();
-                       exit(1);
+                       abort();
                }
        }
 
        if (global_flags.interpolation_quality < 0 || global_flags.interpolation_quality > 4) {
                fprintf(stderr, "Interpolation quality must be 0, 1, 2, 3 or 4.\n");
                usage();
-               exit(1);
+               abort();
+       }
+       if (global_flags.cue_in_point_padding_seconds < 0.0 ||
+           global_flags.cue_out_point_padding_seconds < 0.0) {
+               fprintf(stderr, "Cue point padding cannot be negative.\n");
+               usage();
+               abort();
        }
 }