summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2024-10-08 16:14:22 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2024-10-08 16:14:22 +0200
commitc05e271a0507231eaf131930b5b9711ef85ae4a8 (patch)
tree768eeb6b03a2e7f5485d9a739618920a8f442d6f /main.c
parent65ffdf410ca5c36f059bee8619f87147f802a82e (diff)
downloadttdaw-c05e271a0507231eaf131930b5b9711ef85ae4a8.tar.gz
MIDI is now read in threaded way
Diffstat (limited to 'main.c')
-rw-r--r--main.c65
1 files changed, 48 insertions, 17 deletions
diff --git a/main.c b/main.c
index c196cdd..3a45592 100644
--- a/main.c
+++ b/main.c
@@ -2,32 +2,48 @@
#include <stdlib.h>
#include <stdarg.h>
#include <getopt.h>
+#include <pthread.h>
#include "version.h"
+#include "midi.h"
void help(const char *argv0) {
printf("Usage: %s [options]\n"
"\nAvailable options:\n"
- " -h,--help this help\n"
- " -v,--version show version\n"
- " -l,--list list available devices\n"
- " -p,--port=client:port device port\n",
+ " -l,--list list available devices\n"
+ " -p,--port=client:port device port\n"
+ " -s,--soundfont=file.sf2 soundfont file\n"
+ " -h,--help this help\n"
+ " -v,--version show version\n",
argv0);
}
int main(int argc, char *argv[]) {
- const char short_options[] = "hvlp";
+ const char short_options[] = "lp:s:hv:";
const struct option long_options[] = {
- { "help", 0, NULL, 'h' },
- { "version", 0, NULL, 'v' },
{ "list", 0, NULL, 'l' },
{ "port", 1, NULL, 'p' },
+ { "soundfont", 1, NULL, 's' },
+ { "help", 0, NULL, 'h' },
+ { "version", 0, NULL, 'v' },
{ 0 },
};
- int c;
- while ((c = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
- switch (c) {
+ char *port_name = NULL;
+ char *soundfont_file = NULL;
+
+ int opt;
+ while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
+ switch (opt) {
+ case 'l':
+ fprintf(stderr, "List feature is NOT implemented yet.\n");
+ return 0;
+ case 'p':
+ port_name = optarg;
+ break;
+ case 's':
+ soundfont_file = optarg;
+ break;
case 'h':
help(argv[0]);
return 0;
@@ -38,18 +54,33 @@ int main(int argc, char *argv[]) {
fprintf(stdout, "%s\n", TTDAW_WARRANTY);
fprintf(stdout, "\n%s\n", TTDAW_AUTHOR);
return 0;
- case 'l':
- fprintf(stderr, "List feature is NOT implemented yet.\n");
- return 0;
- case 'p':
- fprintf(stderr, "Port feature is NOT implemented yet.\n");
- return 0;
default:
- fprintf(stdout, "No option provided\n");
+ fprintf(stdout, "Missing options. Check help.\n");
return 0;
}
}
+ if (port_name == NULL || soundfont_file == NULL) {
+ fprintf(stdout, "Missing options. Check help.\n\n");
+ fprintf(stdout, "Port and soundfile are required fields.\n\n");
+ return 1;
+ }
+
+ fprintf(stdout, "> Device port: %s\n", port_name);
+ fprintf(stdout, "> Soundfont: %s\n", soundfont_file);
+
+ // Create and start MIDI thread.
+ pthread_t midi_thread;
+ MidiArgs midi_args = { port_name };
+
+ if (pthread_create(&midi_thread, NULL, midi, (void*)&midi_args) != 0) {
+ fprintf(stderr, "Error creating midi thread\n");
+ return 1;
+ }
+
+ pthread_join(midi_thread, NULL);
+
+ fprintf(stdout, "Exiting...\n");
return 0;
}