From 9c55e48f436acc587e569a951d30277b2ab3df6a Mon Sep 17 00:00:00 2001 From: Duilio Protti Date: Tue, 21 Jun 2016 21:08:54 -0300 Subject: [PATCH] Move from 100% C to mix of C/C++ to match Audacious 3.6 API --- HISTORY | 2 + configure.ac | 21 ++++++++-- src/Makefile.am | 11 +++-- src/{main.c => main.cc} | 73 ++++++++++++++++++--------------- src/{renderer.c => renderer.cc} | 30 +++++++------- 5 files changed, 82 insertions(+), 55 deletions(-) rename src/{main.c => main.cc} (66%) rename src/{renderer.c => renderer.cc} (97%) diff --git a/HISTORY b/HISTORY index e0b226d..d392ab0 100644 --- a/HISTORY +++ b/HISTORY @@ -8,3 +8,5 @@ In October 2003 I've found this plugin and I thought it was really beautiful so I decided to improve it by adding MMX support and created a project in Sourceforge. In 2013 the project was moved into Github. +In 2016 code moved from 100% C to mix of C / C++ to match Audacious +3.6 API. diff --git a/configure.ac b/configure.ac index d439a05..e73ff1d 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ ## Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) -AC_INIT([Infinity plugin],[0.8.0beta2],[dprotti@users.sourceforge.net],[infinity-plugin-4-audacious]) +AC_INIT([Infinity plugin],[0.9.0alpha],[dprotti@users.sourceforge.net],[infinity-plugin-4-audacious]) AM_INIT_AUTOMAKE([1.9.0 dist-bzip2]) AC_CONFIG_HEADER(config.h) @@ -12,7 +12,7 @@ AC_PREFIX_PROGRAM(audacious) AC_CANONICAL_TARGET # Check for programs. -AC_PROG_CC +AC_PROG_CXX AC_PROG_INSTALL AC_DISABLE_STATIC @@ -121,6 +121,7 @@ INF_CFLAGS_EXTRA='' if test x"$GCC" = xyes; then INF_CFLAGS_EXTRA="${INF_CFLAGS_EXTRA} -Wall -Wimplicit -Wunused -Wmissing-prototypes" + CXXFLAGS="${CXXFLAGS} -std=c++11" fi AC_ARG_ENABLE([vectorization], @@ -166,6 +167,19 @@ fi AC_SUBST(INF_CFLAGS_EXTRA) +dnl Prevent symbol collisions +dnl ========================= +if test "x$HAVE_MSWINDOWS" = "xyes" ; then + EXPORT="__declspec(dllexport)" +elif test "x$GCC" = "xyes" ; then + CFLAGS="$CFLAGS -fvisibility=hidden" + CXXFLAGS="$CXXFLAGS -fvisibility=hidden" + EXPORT="__attribute__((visibility(\"default\")))" +else + AC_MSG_ERROR([Unknown syntax for EXPORT keyword]) +fi +AC_DEFINE_UNQUOTED([EXPORT], [$EXPORT], [Compiler syntax for export of public symbols]) + AC_CHECK_FILE("${prefix}/lib/x86_64-linux-gnu/libSDL.so", # Ubuntu on AMD64 puts libraries into x86_64-linux-gnu/ libdir="${libdir}/x86_64-linux-gnu/audacious/Visualization", @@ -188,7 +202,8 @@ Infinity Plugin for the Audacious Player -- version $VERSION Install path : ${libdir} Compiler : ${CC} -CFLAGS : ${INF_CFLAGS_EXTRA} ${CFLAGS} +CFLAGS : ${INF_CFLAGS_EXTRA} ${CFLAGS} +CXXFLAGS : ${CXXFLAGS} Debug enabled : ${debug} MMX Extensions support : ${mmx} " diff --git a/src/Makefile.am b/src/Makefile.am index 58a11a6..511f9a8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,14 +10,17 @@ infinity_datadir = @datadir@ localedir = $(infinity_datadir)/locale DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ -AM_CFLAGS = @CFLAGS@ @AUDACIOUS_CFLAGS@ @AUDCLIENT_CFLAGS@ @SDL_CFLAGS@ @GTK_CFLAGS@\ +COMMON_FLAGS = @AUDACIOUS_CFLAGS@ @AUDCLIENT_CFLAGS@ @SDL_CFLAGS@ @GTK_CFLAGS@\ @GLIB_CFLAGS@ @DBUSGLIB1_CFLAGS@ $(INF_CFLAGS_EXTRA) -DDATADIR='"$(datadir)"' -libinfinite_la_LDFLAGS = -export-dynamic -avoid-version +AM_CFLAGS = @CFLAGS@ $(COMMON_FLAGS) +AM_CXXFLAGS = @CXXFLAGS@ $(COMMON_FLAGS) + +libinfinite_la_LDFLAGS = ${CXX} libinfinite_la_LIBADD = @AUDACIOUS_LIBS@ @AUDCLIENT_LIBS@ @SDL_LIBS@ @GTK_LIBS@ @GLIB_LIBS@ @DBUSGLIB1_LIBS@ libinfinite_la_SOURCES = \ - main.c \ - renderer.c renderer.h\ + main.cc \ + renderer.cc renderer.h\ compute.c compute.h \ display.c display.h \ infconfig.c infconfig.h\ diff --git a/src/main.c b/src/main.cc similarity index 66% rename from src/main.c rename to src/main.cc index 9bc83a5..909f279 100644 --- a/src/main.c +++ b/src/main.cc @@ -21,59 +21,54 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include -#include +#include +#include #include #include +extern "C" { #include "config.h" #include "gettext.h" #include "infconfig.h" #include "renderer.h" +} -static const char infinity_about[] = +static const char about_text[] = N_("Infinity Visualization Plugin for Audacious\n\n" "Version " PACKAGE_VERSION "\n\n" "https://github.com/dprotti/infinity-plugin"); -static bool_t plugin_init(void); -static void plugin_close(void); -static void clear(void); +static const PreferencesWidget prefs_widgets[] = { + WidgetLabel ("Coming soon...") +}; -/* - * Registers plugin with Audacious. - */ -AUD_VIS_PLUGIN( - .name = "Infinity", - .init = plugin_init, - .cleanup = plugin_close, - .take_message = NULL, - .about = NULL, - .about_text = infinity_about, - .configure = config_plugin_config_window, - //.playback_stop = NULL, +static const PluginPreferences preferences = {{prefs_widgets}}; - /* reset internal state and clear display */ - .clear = clear, +class InfinityPlugin : VisPlugin { - /* 512 frames of a single-channel PCM signal */ - .render_mono_pcm = NULL, +public: + static constexpr PluginInfo info = { + N_("Infinity"), + PACKAGE, + about_text, + & preferences + }; - /* 512 frames of an interleaved multi-channel PCM signal */ - .render_multi_pcm = renderer_render_multi_pcm, + constexpr InfinityPlugin () : VisPlugin (info, Visualizer::MultiPCM) {} - /* intensity of frequencies 1/512, 2/512, ..., 256/512 of sample rate */ - .render_freq = NULL, + bool init (); + void cleanup (); - /* GtkWidget * (* get_widget) (void); */ - .get_widget = NULL - ); + //void * get_gtk_widget (); -static void clear(void) -{ - g_message("TODO implement clear()"); -} + void clear (); + void render_multi_pcm (const float * pcm, int channels); +}; -static bool_t plugin_init(void) + +EXPORT InfinityPlugin aud_plugin_instance; + +bool InfinityPlugin::init(void) { #if ENABLE_NLS (void)setlocale(LC_MESSAGES, ""); @@ -99,8 +94,18 @@ static bool_t plugin_init(void) return TRUE; } -static void plugin_close(void) +void InfinityPlugin::clear () { + g_message("TODO implement clear()"); +} + +void InfinityPlugin::cleanup(void) +{ + g_message("cleanup()"); config_plugin_save_prefs(); renderer_finish(); } + +void InfinityPlugin::render_multi_pcm (const float * pcm, int channels) { + renderer_render_multi_pcm(pcm, channels); +} diff --git a/src/renderer.c b/src/renderer.cc similarity index 97% rename from src/renderer.c rename to src/renderer.cc index 30e4a48..ea974ea 100644 --- a/src/renderer.c +++ b/src/renderer.cc @@ -20,10 +20,10 @@ #include #include -#include -#include -#include +#include +#include +#include #include @@ -31,6 +31,7 @@ #include /*#include */ +extern "C" { #include "config.h" #include "gettext.h" #include "renderer.h" @@ -41,6 +42,7 @@ #if MMX_DETECTION #include "cputest.h" #endif +} #define wrap(a) (a < 0 ? 0 : (a > 255 ? 255 : a)) #define next_effect() (t_last_effect++) @@ -92,15 +94,15 @@ static void set_title(void); void renderer_init(void) { GError *error = NULL; - gint32 try; + gint32 _try; if (initializing) { g_warning(_("We are already initializing")); - try = 0; + _try = 0; while (initializing) { g_usleep(1000000); (void)sleep(1); - if (try++ > 10) + if (_try++ > 10) return; } } @@ -154,14 +156,14 @@ void renderer_init(void) void renderer_finish(void) { - gint32 try; + gint32 _try; if (initializing) { g_warning(_("The plugin have not yet initialized")); - try = 0; + _try = 0; while (initializing) { g_usleep(1000000); - if (try++ > 10) + if (_try++ > 10) return; } } @@ -259,14 +261,14 @@ static void check_events() if (aud_drct_get_playing() && aud_drct_get_ready()) { if (current_title) g_free(current_title); - current_title = g_strdup(aud_playlist_entry_get_title(aud_playlist_get_playing(), aud_playlist_get_position(aud_playlist_get_playing()), FALSE)); - set_title(); + String title = aud_playlist_get_title(aud_playlist_get_playing()); + current_title = g_strdup(title.to_raw()); } else { if (current_title) g_free(current_title); current_title = g_strdup("Infinity"); - set_title(); } + set_title(); g_timer_reset(title_timer); } } @@ -325,12 +327,12 @@ static void check_events() aud_drct_seek(aud_drct_get_time() - 5000); break; case SDLK_UP: - aud_drct_get_volume_main(&volume); + volume = aud_drct_get_volume_main(); g_message(_("Increasing volume to %d"), volume + 5); aud_drct_set_volume_main(volume + 5); break; case SDLK_DOWN: - aud_drct_get_volume_main(&volume); + volume = aud_drct_get_volume_main(); g_message(_("Decreasing volume to %d"), volume - 5); aud_drct_set_volume_main(volume - 5); break;