diff options
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 65 |
1 files changed, 48 insertions, 17 deletions
| @@ -2,32 +2,48 @@ | |||
| 2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
| 3 | #include <stdarg.h> | 3 | #include <stdarg.h> |
| 4 | #include <getopt.h> | 4 | #include <getopt.h> |
| 5 | #include <pthread.h> | ||
| 5 | 6 | ||
| 6 | #include "version.h" | 7 | #include "version.h" |
| 8 | #include "midi.h" | ||
| 7 | 9 | ||
| 8 | void help(const char *argv0) { | 10 | void help(const char *argv0) { |
| 9 | printf("Usage: %s [options]\n" | 11 | printf("Usage: %s [options]\n" |
| 10 | "\nAvailable options:\n" | 12 | "\nAvailable options:\n" |
| 11 | " -h,--help this help\n" | 13 | " -l,--list list available devices\n" |
| 12 | " -v,--version show version\n" | 14 | " -p,--port=client:port device port\n" |
| 13 | " -l,--list list available devices\n" | 15 | " -s,--soundfont=file.sf2 soundfont file\n" |
| 14 | " -p,--port=client:port device port\n", | 16 | " -h,--help this help\n" |
| 17 | " -v,--version show version\n", | ||
| 15 | argv0); | 18 | argv0); |
| 16 | } | 19 | } |
| 17 | 20 | ||
| 18 | int main(int argc, char *argv[]) { | 21 | int main(int argc, char *argv[]) { |
| 19 | const char short_options[] = "hvlp"; | 22 | const char short_options[] = "lp:s:hv:"; |
| 20 | const struct option long_options[] = { | 23 | const struct option long_options[] = { |
| 21 | { "help", 0, NULL, 'h' }, | ||
| 22 | { "version", 0, NULL, 'v' }, | ||
| 23 | { "list", 0, NULL, 'l' }, | 24 | { "list", 0, NULL, 'l' }, |
| 24 | { "port", 1, NULL, 'p' }, | 25 | { "port", 1, NULL, 'p' }, |
| 26 | { "soundfont", 1, NULL, 's' }, | ||
| 27 | { "help", 0, NULL, 'h' }, | ||
| 28 | { "version", 0, NULL, 'v' }, | ||
| 25 | { 0 }, | 29 | { 0 }, |
| 26 | }; | 30 | }; |
| 27 | 31 | ||
| 28 | int c; | 32 | char *port_name = NULL; |
| 29 | while ((c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) { | 33 | char *soundfont_file = NULL; |
| 30 | switch (c) { | 34 | |
| 35 | int opt; | ||
| 36 | while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) { | ||
| 37 | switch (opt) { | ||
| 38 | case 'l': | ||
| 39 | fprintf(stderr, "List feature is NOT implemented yet.\n"); | ||
| 40 | return 0; | ||
| 41 | case 'p': | ||
| 42 | port_name = optarg; | ||
| 43 | break; | ||
| 44 | case 's': | ||
| 45 | soundfont_file = optarg; | ||
| 46 | break; | ||
| 31 | case 'h': | 47 | case 'h': |
| 32 | help(argv[0]); | 48 | help(argv[0]); |
| 33 | return 0; | 49 | return 0; |
| @@ -38,18 +54,33 @@ int main(int argc, char *argv[]) { | |||
| 38 | fprintf(stdout, "%s\n", TTDAW_WARRANTY); | 54 | fprintf(stdout, "%s\n", TTDAW_WARRANTY); |
| 39 | fprintf(stdout, "\n%s\n", TTDAW_AUTHOR); | 55 | fprintf(stdout, "\n%s\n", TTDAW_AUTHOR); |
| 40 | return 0; | 56 | return 0; |
| 41 | case 'l': | ||
| 42 | fprintf(stderr, "List feature is NOT implemented yet.\n"); | ||
| 43 | return 0; | ||
| 44 | case 'p': | ||
| 45 | fprintf(stderr, "Port feature is NOT implemented yet.\n"); | ||
| 46 | return 0; | ||
| 47 | default: | 57 | default: |
| 48 | fprintf(stdout, "No option provided\n"); | 58 | fprintf(stdout, "Missing options. Check help.\n"); |
| 49 | return 0; | 59 | return 0; |
| 50 | } | 60 | } |
| 51 | } | 61 | } |
| 52 | 62 | ||
| 63 | if (port_name == NULL || soundfont_file == NULL) { | ||
| 64 | fprintf(stdout, "Missing options. Check help.\n\n"); | ||
| 65 | fprintf(stdout, "Port and soundfile are required fields.\n\n"); | ||
| 66 | return 1; | ||
| 67 | } | ||
| 68 | |||
| 69 | fprintf(stdout, "> Device port: %s\n", port_name); | ||
| 70 | fprintf(stdout, "> Soundfont: %s\n", soundfont_file); | ||
| 71 | |||
| 72 | // Create and start MIDI thread. | ||
| 73 | pthread_t midi_thread; | ||
| 74 | MidiArgs midi_args = { port_name }; | ||
| 75 | |||
| 76 | if (pthread_create(&midi_thread, NULL, midi, (void*)&midi_args) != 0) { | ||
| 77 | fprintf(stderr, "Error creating midi thread\n"); | ||
| 78 | return 1; | ||
| 79 | } | ||
| 80 | |||
| 81 | pthread_join(midi_thread, NULL); | ||
| 82 | |||
| 83 | fprintf(stdout, "Exiting...\n"); | ||
| 53 | return 0; | 84 | return 0; |
| 54 | } | 85 | } |
| 55 | 86 | ||
