Music Engine plays Music Macro Language compositions in the background
Dependents: RETRO_BallsAndPaddle RETRO_BallAndHoles MusicBoxForFathersDay USBSec_mbed-os_dev
Music Engine is a simply library to execute Music Macro Language sequences asynchronously. Learn more about MML on wikipedia http://en.wikipedia.org/wiki/Music_Macro_Language
The following sample plays a simple tune
#include "mbed.h" #include "MusicEngine.h" // Play music on MCU Pin 0.18 // The pin should support PWM MusicEngine music(P0_18); main() { music.play("T224L8O5CL16>C<P16GP16L8EL16P16>C<GP16L8E.L16P16L8C#L16>C#<P16G#P16L8FL16P16>C#<G#P16L8F.L16P16L8CL16>C<P16GP16L8EL16P16>C<GP16L8E.L16P16D#EFP16FF#GP16GG#AP16L8>C<P8L4>C"); while(1) { } }
Diff: MusicEngine.h
- Revision:
- 1:7eb27d971c01
- Parent:
- 0:d873d5d62d3b
diff -r d873d5d62d3b -r 7eb27d971c01 MusicEngine.h --- a/MusicEngine.h Thu Feb 05 04:18:39 2015 +0000 +++ b/MusicEngine.h Thu Feb 05 04:51:11 2015 +0000 @@ -6,21 +6,39 @@ #ifndef __MUSICENGINE_H__ #define __MUSICENGINE_H__ + +/** MusicEngine provides a means to play Music Macro Language sequences asynchronously. + * Learn more about Music Macro Language (MML) on wikipedia + * http://en.wikipedia.org/wiki/Music_Macro_Language +*/ class MusicEngine { public: + /** Creates an instance of the MusicEngine + * @param pin pin used to generate the note frequencies + */ MusicEngine(PinName pin); + /** Starts playing a new MML sequence. If one is already playing it is stopped and the new sequences started. + * @param mml string of MML commands to be played + */ void play(char *mml); + + /** Stop a currently playing sequence */ void stop(); - + + /** Query the engine to determine if a MML sequence is currently being played. */ bool getIsPlaying() { return _isPlaying; } + /** Setup a callback function that will be executed when the music sequence ends. */ void setCompletionCallback(void (*function)(void)) { _completionCallback.attach(function); } + /** Setup a callback function that will be executed when the music sequence ends. + * @note This override is used if the callback is a class member + */ template<typename T> void setCompletionCallback(T *object, void (T::*member)(void)) {