From 506c716cf231182fa2ce9b791963f07c6b27036d Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 16 Apr 2013 21:25:27 +0200 Subject: mixer/Software: convert to a class --- src/mixer/SoftwareMixerPlugin.cxx | 42 ++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'src/mixer') diff --git a/src/mixer/SoftwareMixerPlugin.cxx b/src/mixer/SoftwareMixerPlugin.cxx index ccadadb4d..2782495f5 100644 --- a/src/mixer/SoftwareMixerPlugin.cxx +++ b/src/mixer/SoftwareMixerPlugin.cxx @@ -22,19 +22,30 @@ #include "MixerInternal.hxx" #include "FilterPlugin.hxx" #include "FilterRegistry.hxx" +#include "FilterInternal.hxx" #include "filter/VolumeFilterPlugin.hxx" #include "pcm/PcmVolume.hxx" #include #include -struct software_mixer { - /** the base mixer class */ - struct mixer base; - +struct SoftwareMixer final : public mixer { Filter *filter; unsigned volume; + + SoftwareMixer() + :filter(filter_new(&volume_filter_plugin, nullptr, nullptr)), + volume(100) + { + assert(filter != nullptr); + + mixer_init(this, &software_mixer_plugin); + } + + ~SoftwareMixer() { + delete filter; + } }; static struct mixer * @@ -42,30 +53,21 @@ software_mixer_init(G_GNUC_UNUSED void *ao, G_GNUC_UNUSED const struct config_param *param, G_GNUC_UNUSED GError **error_r) { - struct software_mixer *sm = g_new(struct software_mixer, 1); - - mixer_init(&sm->base, &software_mixer_plugin); - - sm->filter = filter_new(&volume_filter_plugin, NULL, NULL); - assert(sm->filter != NULL); - - sm->volume = 100; - - return &sm->base; + return new SoftwareMixer(); } static void software_mixer_finish(struct mixer *data) { - struct software_mixer *sm = (struct software_mixer *)data; + SoftwareMixer *sm = (SoftwareMixer *)data; - g_free(sm); + delete sm; } static int software_mixer_get_volume(struct mixer *mixer, G_GNUC_UNUSED GError **error_r) { - struct software_mixer *sm = (struct software_mixer *)mixer; + SoftwareMixer *sm = (SoftwareMixer *)mixer; return sm->volume; } @@ -74,7 +76,7 @@ static bool software_mixer_set_volume(struct mixer *mixer, unsigned volume, G_GNUC_UNUSED GError **error_r) { - struct software_mixer *sm = (struct software_mixer *)mixer; + SoftwareMixer *sm = (SoftwareMixer *)mixer; assert(volume <= 100); @@ -103,9 +105,9 @@ const struct mixer_plugin software_mixer_plugin = { Filter * software_mixer_get_filter(struct mixer *mixer) { - struct software_mixer *sm = (struct software_mixer *)mixer; + SoftwareMixer *sm = (SoftwareMixer *)mixer; - assert(sm->base.plugin == &software_mixer_plugin); + assert(sm->plugin == &software_mixer_plugin); return sm->filter; } -- cgit v1.2.3