Dev:Adding a Sound notification

From Synfig Studio :: Documentation
Revision as of 22:40, 16 December 2018 by BobSynfig (Talk | contribs) (1st Part)

Jump to: navigation, search

After the implementation of #648 - GUI: Play a sound when rendering is done, it could be useful to keep a track of the way to implement a new sound notification in SynfigStudio

This tutorial will be divided in 2 parts:

  • Adding the sound notification
  • Adding an option to Preferences dialog

Adding the sound notification


  • Add your sample in this directory in your source tree
  • Add a notice about the license of your sample in readme.txt (the asset should have a permissive license)
  • Add your sound sample to the list in


  • Declare the sound (Mix_Chunk*) as a static member.
//The sound effects that will be used
static Mix_Chunk* gRenderDone;

You could add a bool declared as a static member for an option to play the sound (to be defined in Preferences dialog).

bool       App::use_render_done_sound = true;


  • Initialize the sound (Mix_Chunk*) to NULL.

You could find the gRenderDone and add it after.

Mix_Chunk* App::gRenderDone           = NULL;

As well you may add a bool for allow to play the sound; this will be connected later in the Preferences dialog

bool       App::use_render_done_sound = true;
  • Locate this part (at the end of the constructor App::App )
path_to_sounds += ETL_DIRECTORY_SEPARATOR;

and load your sound as follow (the volume is set at 50% if success)

//Load sound effects
App::gRenderDone = Mix_LoadWAV( (path_to_sounds + "renderdone.wav").c_str() );
if ( App::gRenderDone == NULL ) {
    synfig::error( _("SDL_mixer could not load gRenderDone : %s\n"), Mix_GetError() );
}  else {
    Mix_VolumeChunk(App::gRenderDone, MIX_MAX_VOLUME/2);
  • Finally, free the sound in the destructor App::~App(and NULL the pointer)
//<!- ----- SDL2 - Sound effects -----
//Free the sound effects
Mix_FreeChunk( App::gRenderDone );
App::gRenderDone = NULL;


  • You should add
#include <SDL2/SDL.h>
#include <SDL2/SDL_mixer.h>
  • Add your sound effect play where it should be (end of an event for example)

You have 2 possibilities after this
1) Play directly without control in the preferences

//Sound effect - RenderDone (-1 : play on first free channel, 0 : no repeat)
Mix_PlayChannel( -1, App::gRenderDone, 0 );

2) Play according the preferences

//Sound effect - RenderDone (-1 : play on first free channel, 0 : no repeat)
if (App::use_render_done_sound) Mix_PlayChannel( -1, App::gRenderDone, 0 );