/*====================================================
App.cpp

Simple app that simulates a piano keyboard.
====================================================*/
#include "DragonFireSDK.h"

// Defines the position of each of the white keys.
int WhiteKeyY[9] = {0, 55, 110, 165, 220, 275, 330, 385, 440};
// Defines the position of each of the black keys.  
// Each is offset from its neighboring white key by 35 pixels.
int BlackKeyY[6] = {  35, 90,     200, 255, 310,      420};
// Holds handles to each of the white piano keys' sounds.
int WhiteKeySound[9];   
// Holds handles to each of the black piano keys' sounds.
int BlackKeySound[6];   
// Forward declaration for Key Press Event.
int OnKeyPress(int id);

// AppMain is the first function called by the DragonFireSDK.  It is resposible
// for initialization of all variables and creating the appilcation's objects.
void AppMain()
{
    int i;
    char FileName[255];

	//View iPhone Simulator Landscape
	LandscapeMode();


    // Initialize each white key and then set up its corresponding sound.
	// White key sounds and ID's start at 0.
    for (i = 0; i < 9; i++)
    {
		PushButtonAdd("Images/WhiteKey", WhiteKeyY[i], 0, OnKeyPress, i);
        sprintf(FileName, "Sounds/WhiteKey%d.snd", i);
        WhiteKeySound[i] = SoundAdd(FileName);
    }

    // Initialize each black key and then set up its corresponding sound.
	// Black key sounds start at zero, their ID's start at 10.
    for (i = 0; i < 6; i++)
    {
		PushButtonAdd("Images/BlackKey", BlackKeyY[i], 0, OnKeyPress, i+10);
        sprintf(FileName, "Sounds/BlackKey%d.snd", i);
        BlackKeySound[i] = SoundAdd(FileName);
    }

 
}

void AppExit()
{

}

void OnTimer()
{
    // Do nothing.
}

// OnKeyPress responds to all Key Presses on the piano keyboard.
int OnKeyPress(int id)
{
    // White keys have ID's less than 10.  No index adjustment necessary.
	// black keys have ID's greater than 10.
    if (id < 10)
        SoundPlay(WhiteKeySound[id]);
   else
     SoundPlay(BlackKeySound[id-10]);
    
    return 0;
}