]> git.sesse.net Git - vlc/blobdiff - modules/codec/fluidsynth.c
Made vout_display_opengl_t private.
[vlc] / modules / codec / fluidsynth.c
index c98d28f797d1f445cdf0f72c47bda8861b600e85..79ed0da3b30ecf05530cced6b69e284f1e72f6a9 100644 (file)
@@ -29,6 +29,7 @@
 #include <vlc_codec.h>
 #include <vlc_cpu.h>
 #include <vlc_dialog.h>
+#include <vlc_charset.h>
 
 /* On Win32, we link statically */
 #ifdef WIN32
 
 #include <fluidsynth.h>
 
+#if (FLUIDSYNTH_VERSION_MAJOR < 1) \
+ || (FLUIDSYNTH_VERSION_MAJOR == 1 && FLUIDSYNTH_VERSION_MINOR < 1)
+# define FLUID_FAILED (-1)
+# define fluid_synth_sysex(synth, ptr, len, d, e, f, g) (FLUID_FAILED)
+# define fluid_synth_system_reset(synth) (FLUID_FAILED)
+# define fluid_synth_channel_pressure(synth, channel, p) (FLUID_FAILED)
+#endif
+
 #define SOUNDFONT_TEXT N_("Sound fonts (required)")
 #define SOUNDFONT_LONGTEXT N_( \
     "A sound fonts file is required for software synthesis." )
@@ -51,8 +60,8 @@ vlc_module_begin ()
     set_category (CAT_INPUT)
     set_subcategory (SUBCAT_INPUT_ACODEC)
     set_callbacks (Open, Close)
-    add_file ("soundfont", "", NULL,
-              SOUNDFONT_TEXT, SOUNDFONT_LONGTEXT, false);
+    add_loadfile ("soundfont", "",
+                  SOUNDFONT_TEXT, SOUNDFONT_LONGTEXT, false);
 vlc_module_end ()
 
 
@@ -84,7 +93,8 @@ static int Open (vlc_object_t *p_this)
         dialog_Fatal (p_this, _("MIDI synthesis not set up"),
             _("A sound font file (.SF2) is required for MIDI synthesis.\n"
               "Please install a sound font and configure it "
-              "from the VLC preferences (Codecs / Audio / FluidSynth).\n"));
+              "from the VLC preferences "
+              "(Input / Codecs > Audio codecs > FluidSynth).\n"));
         return VLC_EGENERIC;
     }
 
@@ -99,7 +109,9 @@ static int Open (vlc_object_t *p_this)
     p_sys->settings = new_fluid_settings ();
     p_sys->synth = new_fluid_synth (p_sys->settings);
     /* FIXME: I bet this is not thread-safe */
+    const char *lpath = ToLocale (font_path);
     p_sys->soundfont = fluid_synth_sfload (p_sys->synth, font_path, 1);
+    LocaleFree (lpath);
     if (p_sys->soundfont == -1)
     {
         msg_Err (p_this, "cannot load sound fonts file %s", font_path);
@@ -176,11 +188,32 @@ static aout_buffer_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block)
     if (p_block->i_buffer < 1)
         goto drop;
 
+    uint8_t event = p_block->p_buffer[0];
     uint8_t channel = p_block->p_buffer[0] & 0xf;
+    event &= 0xF0;
+
+    if (event == 0xF0)
+        switch (channel)
+        {
+            case 0:
+                if (p_block->p_buffer[p_block->i_buffer - 1] != 0xF7)
+                {
+            case 7:
+                    msg_Warn (p_dec, "fragmented SysEx not implemented");
+                    goto drop;
+                }
+                fluid_synth_sysex (p_sys->synth, (char *)p_block->p_buffer + 1,
+                                   p_block->i_buffer - 2, NULL, NULL, NULL, 0);
+                break;
+            case 0xF:
+                fluid_synth_system_reset (p_sys->synth);
+                break;
+        }
+
     uint8_t p1 = (p_block->i_buffer > 1) ? (p_block->p_buffer[1] & 0x7f) : 0;
     uint8_t p2 = (p_block->i_buffer > 2) ? (p_block->p_buffer[2] & 0x7f) : 0;
 
-    switch (p_block->p_buffer[0] & 0xf0)
+    switch (event & 0xF0)
     {
         case 0x80:
             fluid_synth_noteoff (p_sys->synth, channel, p1);
@@ -188,21 +221,25 @@ static aout_buffer_t *DecodeBlock (decoder_t *p_dec, block_t **pp_block)
         case 0x90:
             fluid_synth_noteon (p_sys->synth, channel, p1, p2);
             break;
+        /*case 0xA0: note aftertouch not implemented */
         case 0xB0:
             fluid_synth_cc (p_sys->synth, channel, p1, p2);
             break;
         case 0xC0:
             fluid_synth_program_change (p_sys->synth, channel, p1);
             break;
+        case 0xD0:
+            fluid_synth_channel_pressure (p_sys->synth, channel, p1);
+            break;
         case 0xE0:
-            fluid_synth_pitch_bend (p_sys->synth, channel, (p1 << 7) | p2);
+            fluid_synth_pitch_bend (p_sys->synth, channel, (p2 << 7) | p1);
             break;
     }
 
     unsigned samples =
         (p_block->i_pts - date_Get (&p_sys->end_date)) * 441 / 10000;
     if (samples == 0)
-        return NULL;
+        goto drop;
 
     p_out = decoder_NewAudioBuffer (p_dec, samples);
     if (p_out == NULL)