//*****************************************************************************
//
// Test of playtune library for Arduino NANO
//
// L. Shustek, 31 Jan 2011, initial release.
// L. Shustek, 27 Feb 2011, new score data
// L. Shustek, 6 April 2015; change for compatibility with Arduino IDE v1.6.x
// T. Wasiluk, 28 May 2016; added debug & delay code, moved to examples subdirectory
//
//*****************************************************************************


#include "Playtune.h"

// Playtune bytestream for file "jinglebells.mid" created by MIDITONES V2.4 on Wed Dec 13 10:51:54 2023
// command line: ./miditones -v -i -pt -d -t=3 jinglebells
const unsigned char PROGMEM score [] = {
'P','t', 6, 0xE0, 0x00,  3, // (Playtune file header)
// The Coventry Carol
0x90,62,64, 0x91,59,56, 0x92,43,55, 1,29, 0x90,71,75, 0x92,50,63, 1,30, 0x90,69,70, 0x92,55,62, 1,30,
0x90,67,68, 0x92,50,59, 1,29, 0x90,62,66, 0x91,59,58, 0x92,43,58, 1,30, 0x92,50,63, 1,30, 0x92,55,63,
1,29, 0x90,62,70, 0x92,50,59, 0,143, 0x90,62,73, 0,143, 0x90,62,70, 0x91,59,60, 0x92,43,56, 1,30,
0x90,71,79, 0x92,50,63, 1,30, 0x90,69,70, 0x92,55,64, 1,29, 0x90,67,69, 0x92,50,58, 1,30, 0x90,64,68,
0x91,60,63, 0x92,48,61, 1,30, 0x92,52,60, 1,29, 0x92,55,62, 1,30, 0x92,52,63, 1,30, 0x90,64,71,
0x91,60,58, 0x92,45,59, 1,30, 0x90,72,78, 0x92,52,61, 1,29, 0x90,71,70, 0x92,57,63, 1,30, 0x90,69,68,
0x92,52,57, 1,30, 0x90,66,67, 0x91,62,62, 0x92,50,60, 1,29, 0x92,54,62, 1,30, 0x92,57,60, 1,30,
0x92,54,60, 1,30, 0x90,74,77, 0x91,66,64, 0x92,50,61, 1,29, 0x90,74,73, 0x92,54,61, 1,30, 0x90,72,68,
0x91,66,60, 0x92,57,60, 1,30, 0x90,69,68, 0x92,50,60, 1,29, 0x90,71,72, 0x91,67,64, 0x92,43,59, 1,30,
0x92,50,65, 1,30, 0x92,55,63, 1,30, 0x92,50,59, 1,29, 0x90,62,64, 0x91,59,59, 0x92,43,57, 1,30,
0x90,71,78, 0x92,50,62, 1,30, 0x90,69,68, 0x92,55,63, 1,29, 0x90,67,70, 0x92,50,59, 1,30, 0x90,62,67,
0x91,59,61, 0x92,43,61, 1,30, 0x92,50,63, 1,30, 0x92,55,60, 1,29, 0x90,62,72, 0x92,50,60, 0,143,
0x90,62,73, 0,143, 0x90,62,70, 0x91,59,61, 0x92,43,58, 1,30, 0x90,71,79, 0x92,50,63, 1,29, 0x90,69,70,
0x92,55,61, 1,30, 0x90,67,68, 0x92,50,59, 1,30, 0x90,64,69, 0x91,60,63, 0x92,48,60, 1,30, 0x92,52,63,
1,29, 0x92,55,62, 1,30, 0x92,52,58, 1,30, 0x90,64,72, 0x91,60,62, 0x92,45,60, 1,29, 0x90,72,77,
0x92,52,62, 1,30, 0x90,71,71, 0x92,57,63, 1,30, 0x90,69,71, 0x92,52,59, 1,30, 0x90,74,75, 0x91,67,67,
0x92,47,60, 1,29, 0x90,74,73, 0x92,50,62, 1,30, 0x90,74,72, 0x91,67,62, 0x92,55,61, 1,30, 0x90,74,70,
0x92,50,60, 1,29, 0x90,76,73, 0x91,66,61, 0x92,45,57, 1,30, 0x90,74,69, 0x92,50,62, 1,30, 0x90,72,69,
0x91,66,63, 0x92,54,62, 1,30, 0x90,69,69, 0x92,50,59, 1,29, 0x90,67,70, 0x91,62,58, 0x92,43,59, 1,30,
0x92,50,62, 1,30, 0x90,74,77, 0x91,67,65, 0x92,55,63, 2,59, 0x90,67,69, 0x91,71,69, 0x92,43,55, 1,30,
0x90,67,74, 0x91,71,74, 1,30, 0x90,67,70, 0x91,71,70, 1,29, 0x92,50,64, 1,30, 0x90,67,72, 0x91,71,72,
0x92,55,64, 1,30, 0x90,67,70, 0x91,71,70, 1,29, 0x90,67,72, 0x91,71,72, 1,30, 0x92,50,58, 1,30,
0x90,71,70, 0x91,67,62, 0x92,43,57, 1,30, 0x90,74,73, 0x92,50,64, 1,29, 0x90,67,64, 0x91,64,59, 0x92,48,62,
1,173, 0x90,69,73, 0,143, 0x90,71,75, 0x91,62,60, 0x92,43,56, 1,29, 0x92,50,64, 1,30, 0x92,55,62,
2,60, 0x90,72,73, 0x91,64,64, 0x92,48,60, 1,29, 0x90,72,72, 0x91,64,61, 0x92,52,64, 1,30, 0x90,72,72,
0x91,64,62, 0x92,55,61, 1,30, 0x92,52,60, 0,143, 0x90,72,71, 0,142, 0x90,72,73, 0x91,62,58, 0x92,47,58,
1,30, 0x90,71,70, 0x92,50,61, 1,30, 0x90,71,72, 0x91,62,61, 0x92,55,60, 1,30, 0x90,71,70, 0x92,50,58,
0,142, 0x90,71,71, 0,143, 0x90,71,70, 0x91,61,59, 0x92,45,59, 1,30, 0x90,69,67, 0x92,52,61, 1,30,
0x90,69,71, 0x91,61,61, 0x92,57,62, 1,29, 0x90,71,73, 0x92,52,60, 1,30, 0x90,69,71, 0x91,62,63, 0x92,50,61,
1,30, 0x92,54,62, 1,30, 0x90,74,74, 0x91,66,64, 0x92,57,64, 1,29, 0x92,54,58, 1,30, 0x90,67,68,
0x91,71,68, 0x92,43,57, 1,30, 0x90,67,71, 0x91,71,71, 1,29, 0x90,67,71, 0x91,71,71, 1,30, 0x92,50,63,
1,30, 0x90,67,71, 0x91,71,71, 0x92,55,62, 1,30, 0x90,67,71, 0x91,71,71, 1,29, 0x90,67,71, 0x91,71,71,
1,30, 0x92,50,58, 1,30, 0x90,71,71, 0x91,67,61, 0x92,43,60, 1,29, 0x90,74,73, 0x92,50,62, 1,30,
0x90,67,62, 0x91,64,58, 0x92,48,61, 1,173, 0x90,69,74, 0,143, 0x90,71,73, 0x91,62,58, 0x92,43,56, 1,29,
0x92,50,66, 1,30, 0x92,55,65, 2,59, 0x90,72,73, 0x91,64,64, 0x92,48,57, 1,30, 0x90,72,69, 0x91,64,62,
0x92,52,64, 1,30, 0x90,72,73, 0x91,64,62, 0x92,55,62, 1,29, 0x92,52,60, 0,143, 0x90,72,72, 0,143,
0x90,72,72, 0x91,62,59, 0x92,47,60, 1,30, 0x90,71,69, 0x92,50,62, 1,30, 0x90,71,71, 0x91,62,61, 0x92,55,64,
1,29, 0x90,71,73, 0x92,50,58, 0,143, 0x90,71,72, 0,143, 0x90,74,74, 0x91,66,66, 0x92,45,58, 1,30,
0x90,74,72, 0x92,50,61, 1,29, 0x90,72,67, 0x91,62,56, 0x92,54,61, 1,30, 0x90,69,69, 0x92,50,62, 1,30,
0x90,67,69, 0x91,59,60, 0x92,43,58, 1,30, 0x92,50,61, 1,29, 0x92,55,63, 2,60, 0x90,62,65, 0x91,59,59,
0x92,43,55, 1,29, 0x90,71,78, 0x92,50,63, 1,30, 0x90,69,70, 0x92,55,64, 1,30, 0x90,67,70, 0x92,50,57,
1,30, 0x90,62,65, 0x91,59,61, 0x92,43,59, 1,29, 0x92,50,63, 1,30, 0x92,55,65, 1,30, 0x90,62,70,
0x92,50,59, 0,143, 0x90,62,70, 0,142, 0x90,62,71, 0x91,59,62, 0x92,43,59, 1,30, 0x90,71,80, 0x92,50,62,
1,30, 0x90,69,70, 0x92,55,63, 1,30, 0x90,67,68, 0x92,50,60, 1,29, 0x90,64,69, 0x91,60,64, 0x92,48,60,
1,30, 0x92,52,64, 1,30, 0x92,55,61, 1,29, 0x92,52,59, 1,30, 0x90,64,69, 0x91,60,62, 0x92,45,59,
1,30, 0x90,72,78, 0x92,52,64, 1,30, 0x90,71,71, 0x92,57,62, 1,29, 0x90,69,66, 0x92,52,59, 1,30,
0x90,66,68, 0x91,62,62, 0x92,50,59, 1,30, 0x92,54,65, 1,29, 0x92,57,61, 1,30, 0x92,54,65, 1,30,
0x90,74,78, 0x91,66,64, 0x92,50,61, 1,30, 0x90,74,71, 0x92,54,62, 1,29, 0x90,72,72, 0x91,66,60, 0x92,57,61,
1,30, 0x90,69,67, 0x92,50,59, 1,30, 0x90,71,74, 0x91,67,62, 0x92,43,62, 1,29, 0x92,50,63, 1,30,
0x92,55,64, 1,30, 0x92,50,61, 1,30, 0x90,62,61, 0x91,59,59, 0x92,43,57, 1,29, 0x90,71,80, 0x92,50,63,
1,30, 0x90,69,69, 0x92,55,63, 1,30, 0x90,67,69, 0x92,50,59, 1,29, 0x90,62,66, 0x91,59,61, 0x92,43,61,
1,30, 0x92,50,61, 1,30, 0x92,55,63, 1,30, 0x90,62,72, 0x92,50,59, 0,142, 0x90,62,72, 0,143, 0x90,62,73,
0x91,59,58, 0x92,43,59, 1,30, 0x90,71,77, 0x92,50,66, 1,30, 0x90,69,69, 0x92,55,64, 1,29, 0x90,67,69,
0x92,50,57, 1,30, 0x90,64,68, 0x91,60,62, 0x92,48,62, 1,30, 0x92,52,61, 1,30, 0x92,55,63, 1,29,
0x92,52,58, 1,30, 0x90,64,73, 0x91,60,63, 0x92,45,59, 1,30, 0x90,72,77, 0x92,52,62, 1,29, 0x90,71,73,
0x92,57,61, 1,30, 0x90,69,68, 0x92,52,56, 1,30, 0x90,74,77, 0x91,67,65, 0x92,47,58, 1,30, 0x90,74,74,
0x92,50,61, 1,29, 0x90,74,74, 0x91,67,62, 0x92,55,63, 1,30, 0x90,74,71, 0x92,50,61, 1,30, 0x90,76,74,
0x91,66,57, 0x92,45,59, 1,29, 0x90,74,70, 0x92,50,62, 1,30, 0x90,72,69, 0x91,66,60, 0x92,54,64, 1,30,
0x90,69,69, 0x92,50,58, 1,30, 0x90,67,69, 0x91,62,56, 0x92,43,59, 1,29, 0x92,50,64, 1,30, 0x90,74,76,
0x91,67,64, 0x92,55,65, 2,59, 0x90,67,69, 0x91,71,69, 0x92,43,60, 1,30, 0x90,67,72, 0x91,71,72, 1,30,
0x90,67,70, 0x91,71,70, 1,30, 0x92,50,65, 1,29, 0x90,67,70, 0x91,71,70, 0x92,55,63, 1,30, 0x90,67,71,
0x91,71,71, 1,30, 0x90,67,72, 0x91,71,72, 1,29, 0x92,50,60, 1,30, 0x90,71,71, 0x91,67,63, 0x92,43,55,
1,30, 0x90,74,73, 0x92,50,63, 1,30, 0x90,67,65, 0x91,64,59, 0x92,48,64, 1,172, 0x90,69,72, 0,143,
0x90,71,74, 0x91,62,58, 0x92,43,59, 1,30, 0x92,50,63, 1,29, 0x92,55,62, 2,60, 0x90,72,72, 0x91,64,64,
0x92,48,59, 1,30, 0x90,72,72, 0x91,64,60, 0x92,52,62, 1,29, 0x90,72,73, 0x91,64,61, 0x92,55,64, 1,30,
0x92,52,60, 0,143, 0x90,72,71, 0,143, 0x90,72,71, 0x91,62,58, 0x92,47,59, 1,29, 0x90,71,71, 0x92,50,62,
1,30, 0x90,71,75, 0x91,62,60, 0x92,55,66, 1,30, 0x90,71,72, 0x92,50,58, 0,143, 0x90,71,71, 0,143,
0x90,71,71, 0x91,61,58, 0x92,45,57, 1,29, 0x90,69,70, 0x92,52,65, 1,30, 0x90,69,69, 0x91,61,61, 0x92,57,60,
1,30, 0x90,71,74, 0x92,52,59, 1,29, 0x90,69,69, 0x91,62,62, 0x92,50,60, 1,30, 0x92,54,62, 1,30,
0x90,74,76, 0x91,66,65, 0x92,57,64, 1,29, 0x92,54,57, 1,30, 0x90,67,70, 0x91,71,70, 0x92,43,59, 1,30,
0x90,67,69, 0x91,71,69, 1,30, 0x90,67,71, 0x91,71,71, 1,29, 0x92,50,64, 1,30, 0x90,67,73, 0x91,71,73,
0x92,55,63, 1,30, 0x90,67,71, 0x91,71,71, 1,29, 0x90,67,72, 0x91,71,72, 1,30, 0x92,50,58, 1,30,
0x90,71,70, 0x91,67,65, 0x92,43,56, 1,30, 0x90,74,74, 0x92,50,64, 1,29, 0x90,67,64, 0x91,64,59, 0x92,48,62,
1,173, 0x90,69,74, 0,143, 0x90,71,71, 0x91,62,59, 0x92,43,58, 1,29, 0x92,50,63, 1,30, 0x92,55,61,
2,60, 0x90,72,74, 0x91,64,63, 0x92,48,57, 1,29, 0x90,72,69, 0x91,64,62, 0x92,52,64, 1,30, 0x90,72,71,
0x91,64,59, 0x92,55,59, 1,30, 0x92,52,62, 0,143, 0x90,72,70, 0,142, 0x90,72,72, 0x91,62,59, 0x92,47,58,
1,30, 0x90,71,69, 0x92,50,62, 1,30, 0x90,71,69, 0x91,62,60, 0x92,55,60, 1,30, 0x90,71,71, 0x92,50,59,
0,142, 0x90,71,70, 0,143, 0x90,74,72, 0x91,66,65, 0x92,45,59, 1,30, 0x90,74,70, 0x92,50,65, 1,30,
0x90,72,69, 0x91,62,59, 0x92,54,63, 1,29, 0x90,69,67, 0x92,50,60, 1,30, 0x90,67,69, 0x91,59,63, 0x92,43,60,
1,30, 0x92,50,61, 1,30, 0x92,55,63, 2,59, 0x80, 0x81, 0x82, 0xF0};

// This 2138 byte score contains 536 notes and uses 3 tone generators
// 4 notes had to be skipped

Playtune pt;

void setup() {

  // Enable all 3 NANO timers for notes that are output on digital pins 10, 11, and 12.
  // Those pins should be wired to 500-ohm resistors, the other ends of which should be connected together
  // to one terminal of an 8-ohm speaker. The other terminal of the speaker should be connected to ground.
  // No other hardware is needed!

  pt.tune_initchan (10); 
  pt.tune_initchan (11);
  pt.tune_initchan (12);

  #define DBUG 0
  #if DBUG
  Serial.begin(9600);
  Serial.println("Debug");
  #endif
  
}

void loop() {

  pt.tune_playscore (score); /* start playing */
  while (pt.tune_playing) ; /* wait here until playing stops */
  pt.tune_delay(1000); /* wait a second */
  
}