Difference between revisions of "Dev:Adding a Sound notification"
From Synfig Studio :: Documentation
(Page creation) |
(1st Part) |
||
Line 1: | Line 1: | ||
− | + | After the implementation of [https://github.com/synfig/synfig/issues/648| #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 == | |
− | + | ||
− | You could add a bool | + | === synfig-studio/sounds/ === |
+ | * Add your sample in this directory in your source tree<br /> | ||
+ | * Add a notice about the license of your sample in readme.txt (the asset should have a permissive license)<br /> | ||
+ | * Add your sound sample to the list in Makefile.am | ||
+ | |||
+ | === synfig-studio/src/gui/app.h === | ||
+ | * 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; | bool App::use_render_done_sound = true; | ||
=== synfig-studio/src/gui/app.cpp === | === synfig-studio/src/gui/app.cpp === | ||
− | Initialize the sound (Mix_Chunk*) to NULL. | + | * Initialize the sound (Mix_Chunk*) to NULL.<br /> |
You could find the gRenderDone and add it after. | You could find the gRenderDone and add it after. | ||
− | |||
Mix_Chunk* App::gRenderDone = NULL; | Mix_Chunk* App::gRenderDone = NULL; | ||
− | As well you may add a bool for | + | 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; | 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; | ||
=== synfig-studio/src/gui/<yourSource>.cpp === | === synfig-studio/src/gui/<yourSource>.cpp === | ||
− | You should add | + | * You should add |
#include <SDL2/SDL.h> | #include <SDL2/SDL.h> | ||
#include <SDL2/SDL_mixer.h> | #include <SDL2/SDL_mixer.h> | ||
− | Add your sound effect play where it should be (end of an event for example) | + | * Add your sound effect play where it should be (end of an event for example)<br /> |
+ | You have 2 possibilities after this<br /> | ||
+ | 1) Play directly without control in the preferences | ||
//Sound effect - RenderDone (-1 : play on first free channel, 0 : no repeat) | //Sound effect - RenderDone (-1 : play on first free channel, 0 : no repeat) | ||
Mix_PlayChannel( -1, App::gRenderDone, 0 ); | Mix_PlayChannel( -1, App::gRenderDone, 0 ); | ||
+ | '''or'''<br /> | ||
+ | 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 ); |
Revision as of 21:40, 16 December 2018
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
Contents
Adding the sound notification
synfig-studio/sounds/
- 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 Makefile.am
synfig-studio/src/gui/app.h
- 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;
synfig-studio/src/gui/app.cpp
- 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;
synfig-studio/src/gui/<yourSource>.cpp
- 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 );
or
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 );