From 2277d143fa4e407bffa9cb169820c9612ebae7a0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 28 Jul 2013 13:12:08 +0200 Subject: [PATCH] decoder/fluidsynth: convert to C++ --- Makefile.am | 4 ++- src/DecoderList.cxx | 2 +- ...r_plugin.c => FluidsynthDecoderPlugin.cxx} | 35 +++++++++++-------- src/decoder/FluidsynthDecoderPlugin.hxx | 25 +++++++++++++ 4 files changed, 50 insertions(+), 16 deletions(-) rename src/decoder/{fluidsynth_decoder_plugin.c => FluidsynthDecoderPlugin.cxx} (89%) create mode 100644 src/decoder/FluidsynthDecoderPlugin.hxx diff --git a/Makefile.am b/Makefile.am index 376ebe88c..c16d56aec 100644 --- a/Makefile.am +++ b/Makefile.am @@ -596,7 +596,9 @@ libdecoder_plugins_a_SOURCES += src/decoder/sidplay_decoder_plugin.cxx endif if ENABLE_FLUIDSYNTH -libdecoder_plugins_a_SOURCES += src/decoder/fluidsynth_decoder_plugin.c +libdecoder_plugins_a_SOURCES += \ + src/decoder/FluidsynthDecoderPlugin.cxx \ + src/decoder/FluidsynthDecoderPlugin.hxx endif if ENABLE_WILDMIDI diff --git a/src/DecoderList.cxx b/src/DecoderList.cxx index 241997817..a66a21e2f 100644 --- a/src/DecoderList.cxx +++ b/src/DecoderList.cxx @@ -41,13 +41,13 @@ #include "decoder/MikmodDecoderPlugin.hxx" #include "decoder/ModplugDecoderPlugin.hxx" #include "decoder/MpcdecDecoderPlugin.hxx" +#include "decoder/FluidsynthDecoderPlugin.hxx" #include #include extern const struct decoder_plugin sidplay_decoder_plugin; -extern const struct decoder_plugin fluidsynth_decoder_plugin; const struct decoder_plugin *const decoder_plugins[] = { #ifdef HAVE_MAD diff --git a/src/decoder/fluidsynth_decoder_plugin.c b/src/decoder/FluidsynthDecoderPlugin.cxx similarity index 89% rename from src/decoder/fluidsynth_decoder_plugin.c rename to src/decoder/FluidsynthDecoderPlugin.cxx index 894b2d353..da1b41a58 100644 --- a/src/decoder/fluidsynth_decoder_plugin.c +++ b/src/decoder/FluidsynthDecoderPlugin.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2012 The Music Player Daemon Project + * Copyright (C) 2003-2013 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -18,6 +18,7 @@ */ #include "config.h" +#include "FluidsynthDecoderPlugin.hxx" #include "decoder_api.h" #include "audio_check.h" #include "conf.h" @@ -65,13 +66,14 @@ fluidsynth_level_to_glib(enum fluid_log_level level) static void fluidsynth_mpd_log_function(int level, char *message, G_GNUC_UNUSED void *data) { - g_log(G_LOG_DOMAIN, fluidsynth_level_to_glib(level), "%s", message); + g_log(G_LOG_DOMAIN, fluidsynth_level_to_glib(fluid_log_level(level)), + "%s", message); } static bool fluidsynth_init(const struct config_param *param) { - GError *error = NULL; + GError *error = nullptr; sample_rate = config_get_block_unsigned(param, "sample_rate", 48000); if (!audio_check_sample_rate(sample_rate, &error)) { @@ -85,7 +87,7 @@ fluidsynth_init(const struct config_param *param) "/usr/share/sounds/sf2/FluidR3_GM.sf2"); fluid_set_log_function(LAST_LOG_LEVEL, - fluidsynth_mpd_log_function, NULL); + fluidsynth_mpd_log_function, nullptr); return true; } @@ -107,7 +109,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) /* set up fluid settings */ settings = new_fluid_settings(); - if (settings == NULL) + if (settings == nullptr) return; fluid_settings_setnum(settings, setting_sample_rate, sample_rate); @@ -119,7 +121,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) /* create the fluid synth */ synth = new_fluid_synth(settings); - if (synth == NULL) { + if (synth == nullptr) { delete_fluid_settings(settings); return; } @@ -135,7 +137,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) /* create the fluid player */ player = new_fluid_player(synth); - if (player == NULL) { + if (player == nullptr) { delete_fluid_synth(synth); delete_fluid_settings(settings); return; @@ -181,7 +183,7 @@ fluidsynth_file_decode(struct decoder *decoder, const char *path_fs) if (ret != 0) break; - cmd = decoder_data(decoder, NULL, buffer, sizeof(buffer), + cmd = decoder_data(decoder, nullptr, buffer, sizeof(buffer), 0); if (cmd != DECODE_COMMAND_NONE) break; @@ -207,13 +209,18 @@ fluidsynth_scan_file(const char *file, static const char *const fluidsynth_suffixes[] = { "mid", - NULL + nullptr }; const struct decoder_plugin fluidsynth_decoder_plugin = { - .name = "fluidsynth", - .init = fluidsynth_init, - .file_decode = fluidsynth_file_decode, - .scan_file = fluidsynth_scan_file, - .suffixes = fluidsynth_suffixes, + "fluidsynth", + fluidsynth_init, + nullptr, + nullptr, + fluidsynth_file_decode, + fluidsynth_scan_file, + nullptr, + nullptr, + fluidsynth_suffixes, + nullptr, }; diff --git a/src/decoder/FluidsynthDecoderPlugin.hxx b/src/decoder/FluidsynthDecoderPlugin.hxx new file mode 100644 index 000000000..40ed7e4d8 --- /dev/null +++ b/src/decoder/FluidsynthDecoderPlugin.hxx @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_DECODER_FLUIDSYNTH_HXX +#define MPD_DECODER_FLUIDSYNTH_HXX + +extern const struct decoder_plugin fluidsynth_decoder_plugin; + +#endif