SDL_mixer: timidity: added new function Timidity_SetSoundfont() to the api.

From 97569181a05023c6be15d6be131952c877a24d30 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Fri, 31 Jul 2026 23:11:10 +0300
Subject: [PATCH] timidity: added new function Timidity_SetSoundfont() to the
 api.

---
 src/timidity/timidity.c | 16 ++++++++++++++++
 src/timidity/timidity.h |  3 +++
 2 files changed, 19 insertions(+)

diff --git a/src/timidity/timidity.c b/src/timidity/timidity.c
index 1c0b5f65..63c97ee0 100644
--- a/src/timidity/timidity.c
+++ b/src/timidity/timidity.c
@@ -553,12 +553,28 @@ int Timidity_Init(const char *config_file)
   if (rc != 0) {
       return rc;
   }
+  if (sf_file) {
+      /* a soundfont specified by mid_set_soundfont().
+       * skip config parsing. */
+      return 0;
+  }
   if (config_file == NULL || *config_file == '\0') {
       return init_with_config(TIMIDITY_CFG);
   }
   return init_with_config(config_file);
 }
 
+int Timidity_SetSoundfont(const char *file)
+{
+  if (file) {
+      char *fname = SDL_strdup(file);
+      if (!fname) return -1;
+      SDL_free(sf_file);
+      sf_file = fname;
+  }
+  return 0;
+}
+
 static void do_song_load(SDL_IOStream *io, const SDL_AudioSpec *audio, MidiSong **out)
 {
   MidiSong *song;
diff --git a/src/timidity/timidity.h b/src/timidity/timidity.h
index 89408945..5d0145a4 100644
--- a/src/timidity/timidity.h
+++ b/src/timidity/timidity.h
@@ -157,6 +157,9 @@ typedef struct {
 
 extern int Timidity_Init(const char *config_file);
 extern int Timidity_Init_NoConfig(void);
+/* Set the full path of a soundfont (sf2) to use. Must be called before Timidity_Init().
+ * If a soundfont is set, config file will not be parsed by Timidity_Init(). */
+extern int Timidity_SetSoundfont(const char *sf2_file);
 extern void Timidity_SetVolume(MidiSong *song, int volume);
 extern int Timidity_PlaySome(MidiSong *song, void *stream, Sint32 len);
 extern MidiSong *Timidity_LoadSong(SDL_IOStream *io, const SDL_AudioSpec *audio);