summary refs log tree commit diff
path: root/src/sdl.c
diff options
context:
space:
mode:
authorzlago2024-09-01 18:14:38 +0200
committerzlago2024-09-01 18:14:38 +0200
commit90b967d9d1b5970969f758c7993d244936fff324 (patch)
tree275c8b45d9dd7a1e6022d4b3929dd1f064f8caaa /src/sdl.c
parent2eab12e43c040d369b685efc13e2452405cf6451 (diff)
libfluidsynth
Diffstat (limited to 'src/sdl.c')
-rw-r--r--src/sdl.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/sdl.c b/src/sdl.c
index 875cde5..8deb8ca 100644
--- a/src/sdl.c
+++ b/src/sdl.c
@@ -8,6 +8,7 @@
 #include "include.h"
 
 int module_openmpt(struct blob *file, struct userdata *userdata);
+int module_fluidsynth(struct blob *file, struct userdata *userdata);
 
 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
 
@@ -103,9 +104,22 @@ int main(void) {
 						SDL_free(evt.drop.file);
 						break;
 					}
-					SDL_free(evt.drop.file);
 					struct userdata newuser = {.callback = NULL, .freefunc = NULL};
-					if (module_openmpt(&file, audio, &newuser)) {
+					int (*module_func)(struct blob *, struct userdata *) = NULL;
+					size_t len = strlen(evt.drop.file);
+					#define ext(extension) memcmp(evt.drop.file + len - sizeof (extension) + 1, extension, sizeof (extension))
+					if ((ext(".mptm") && ext(".mod") && ext(".xm") && ext(".s3m") && ext(".it")) == 0) {
+						module_func = module_openmpt;
+					} else if ((ext(".mid") && ext(".midi")) == 0) {
+						module_func = module_fluidsynth;
+					}
+					if (module_func == NULL) {
+						eprintf("%s: unrecognized file extension\n", evt.drop.file);
+						free(file.data);
+						break;
+					}
+					SDL_free(evt.drop.file);
+					if (module_func(&file, &newuser)) {
 						// error
 					} else {
 						SDL_LockAudioDevice(audio);
@@ -126,6 +140,7 @@ int main(void) {
 	if (userdata.freefunc != NULL) {
 		SDL_LockAudioDevice(audio);
 		userdata.freefunc(userdata.user);
+		SDL_PauseAudioDevice(audio, 1);
 		SDL_UnlockAudioDevice(audio);
 	}