/*
  Tunes -- Play melodies on specified output pins.
    #include <pitches.h> in the app if you want to defile your own melodies.
  This code is in some domain.
 */
#ifndef TUNES_h
#define TUNES_h

#include "Arduino.h"

/** definition of one note in a melody sequence
 **  an array of these is a Melody to be played
 **  where the last "length" should be 0
 **/
typedef struct
{
	uint16_t pitch;		// note frequency
	uint8_t duration;	// note on duration, 8ms steps
	uint8_t length;		// time until next note, 8ms steps, 0==Sequence End
} Note;

/** the stuff we want to use
 **/
class Tunes
{
  public:
	  // instantiate using given pin# as output
	  Tunes( uint8_t pin );
	  // play the given note and repost current task with arg
	  static byte play( word arg, word pitch, word duration, word length );
	  // start playing the given note sequence
	  void startTune( Note* sequence );
	  // start generating and playing a random sequence
	  void startRandomTune();
	  // set the range parameters for RandomTune
	  void setRandomRange( byte pitch, byte duration, byte length );
	  // end playing sequence but let note finish
	  void endTune(void);
	  // stop playing now
	  void stopTune(void);
	  static uint8_t SPEAKERout; // output pin assignment
	  static Note* Melody;	// currently playing note sequence
  private:
};

// melodies we have here,
//  note: need to be in *.cpp files or crapulation occurs
extern Note Shave_and_haircut[];
extern Note Twinkle[];
extern Note Lullaby[];
extern Note HatDance[];
extern Note Charge[];
extern Note noCharge[];

extern Note HighArp[];
extern Note LowArp[];
extern Note Purr[];
extern Note Hunt[];
extern Note Razz[];
extern Note Chirp[];

#endif //TUNES_h
