diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-10-09 18:32:27 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-10-09 18:32:27 +0200 |
| commit | ac6283f92b0579c0e820e13a83715389455d3171 (patch) | |
| tree | 9db9e5ca0f6e30a5faab339757f37941ec134738 | |
| parent | 2468c0afd3ac239ae634cba24583467b8e553c37 (diff) | |
| download | ttdaw-ac6283f92b0579c0e820e13a83715389455d3171.tar.gz | |
Added preset to args
| -rw-r--r-- | README.md | 9 | ||||
| -rw-r--r-- | main.c | 24 | ||||
| -rw-r--r-- | midi.c | 1 | ||||
| -rw-r--r-- | mutex.h | 1 | ||||
| -rw-r--r-- | synth.c | 4 | ||||
| -rw-r--r-- | synth.h | 1 |
6 files changed, 29 insertions, 11 deletions
@@ -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 @@ -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"); @@ -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); @@ -7,7 +7,6 @@ typedef struct { int note; int state; int velocity; - int preset; int action; } SharedData; @@ -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); @@ -7,6 +7,7 @@ typedef struct { char *soundfont_file; + int soundfont_preset; } SynthArgs; void *synth(void *arg); |
