summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2024-10-09 18:32:27 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2024-10-09 18:32:27 +0200
commitac6283f92b0579c0e820e13a83715389455d3171 (patch)
tree9db9e5ca0f6e30a5faab339757f37941ec134738
parent2468c0afd3ac239ae634cba24583467b8e553c37 (diff)
downloadttdaw-ac6283f92b0579c0e820e13a83715389455d3171.tar.gz
Added preset to args
-rw-r--r--README.md9
-rw-r--r--main.c24
-rw-r--r--midi.c1
-rw-r--r--mutex.h1
-rw-r--r--synth.c4
-rw-r--r--synth.h1
6 files changed, 29 insertions, 11 deletions
diff --git a/README.md b/README.md
index 1e104d7..64af80b 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,15 @@
experimentation and learning more about audio, MIDI and terminal applications
in general.
+## Compile and run
+
+```sh
+make
+./ttdaw -c 28:0 -s soundfonts/general-808.sf2 -p 1
+```
+
+List all available MIDI devices with `acconect -l`.
+
## Soundfonts
- https://dev.nando.audio/pages/soundfonts.html
diff --git a/main.c b/main.c
index 1df6ec3..2bc6927 100644
--- a/main.c
+++ b/main.c
@@ -13,19 +13,21 @@ void help(const char *argv0) {
printf("Usage: %s [options]\n"
"\nAvailable options:\n"
" -l,--list list available devices\n"
- " -p,--port=client:port device port\n"
+ " -c,--client=client:port device client and port\n"
" -s,--soundfont=file.sf2 soundfont file\n"
+ " -p,--preset=1 soundfont preset\n"
" -h,--help this help\n"
" -v,--version show version\n",
argv0);
}
int main(int argc, char *argv[]) {
- const char short_options[] = "lp:s:hv";
+ const char short_options[] = "lc:s:p:hv";
const struct option long_options[] = {
{ "list", 0, NULL, 'l' },
- { "port", 1, NULL, 'p' },
+ { "client", 1, NULL, 'c' },
{ "soundfont", 1, NULL, 's' },
+ { "preset", 1, NULL, 'p' },
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ 0 },
@@ -33,6 +35,7 @@ int main(int argc, char *argv[]) {
char *port_name = NULL;
char *soundfont_file = NULL;
+ int soundfont_preset = -1;
int opt;
while ((opt = getopt_long(argc, argv, short_options, long_options, NULL)) != -1) {
@@ -40,12 +43,15 @@ int main(int argc, char *argv[]) {
case 'l':
fprintf(stderr, "List feature is NOT implemented yet.\n");
return 0;
- case 'p':
+ case 'c':
port_name = optarg;
break;
case 's':
soundfont_file = optarg;
break;
+ case 'p':
+ soundfont_preset = atoi(optarg);
+ break;
case 'h':
help(argv[0]);
return 0;
@@ -62,21 +68,25 @@ int main(int argc, char *argv[]) {
}
}
- if (port_name == NULL || soundfont_file == NULL) {
+ if (port_name == NULL || soundfont_file == NULL || soundfont_preset < 0) {
fprintf(stdout, "Missing options. Check help.\n");
- fprintf(stdout, "Port and soundfile are required fields.\n");
+ fprintf(stdout, "Port, soundfile and preset are required fields.\n");
return 1;
}
fprintf(stdout, "> Device port: %s\n", port_name);
fprintf(stdout, "> Soundfont: %s\n", soundfont_file);
+ fprintf(stdout, "> SF preset: %d\n", soundfont_preset);
// Create mutex.
initialize_mutex();
// Create synth thread.
pthread_t synth_thread;
- SynthArgs synth_args = { soundfont_file };
+ SynthArgs synth_args = {
+ .soundfont_file = soundfont_file,
+ .soundfont_preset = soundfont_preset,
+ };
if (pthread_create(&synth_thread, NULL, synth, (void*)&synth_args) != 0) {
fprintf(stderr, "Error creating synth thread\n");
diff --git a/midi.c b/midi.c
index f389826..92df3d3 100644
--- a/midi.c
+++ b/midi.c
@@ -109,7 +109,6 @@ void *midi(void *arg) {
}
shared_data.action = 1;
- shared_data.preset = 3;
pthread_cond_signal(&cond_synth);
pthread_mutex_unlock(&mutex);
diff --git a/mutex.h b/mutex.h
index 2f3c653..78b4cdf 100644
--- a/mutex.h
+++ b/mutex.h
@@ -7,7 +7,6 @@ typedef struct {
int note;
int state;
int velocity;
- int preset;
int action;
} SharedData;
diff --git a/synth.c b/synth.c
index 05c3664..d65ba41 100644
--- a/synth.c
+++ b/synth.c
@@ -65,10 +65,10 @@ void *synth(void *arg) {
SDL_LockMutex(g_Mutex);
if (shared_data.state == 0) {
- tsf_note_off(g_TinySoundFont, shared_data.preset, shared_data.note);
+ tsf_note_off(g_TinySoundFont, args->soundfont_preset, shared_data.note);
} else {
float normalized_velocity = (float)shared_data.velocity / 127.0f;
- tsf_note_on(g_TinySoundFont, shared_data.preset, shared_data.note, normalized_velocity);
+ tsf_note_on(g_TinySoundFont, args->soundfont_preset, shared_data.note, normalized_velocity);
}
SDL_UnlockMutex(g_Mutex);
diff --git a/synth.h b/synth.h
index 90fd410..7e08157 100644
--- a/synth.h
+++ b/synth.h
@@ -7,6 +7,7 @@
typedef struct {
char *soundfont_file;
+ int soundfont_preset;
} SynthArgs;
void *synth(void *arg);