#include "player.h"

vs10xx vs1053(D11, D12, D13, A3, A2, A1, A0);//mosi,miso,sclk,xcs,xdcs,dreq,xreset

/**********************************Midi Player Part***************************/
void Player::beginMidi(void)
{

  //Init VS105B in Midi Format
  printf("Init vs10xx in MIDI format...\r\n");
  vs1053.resetForMidi();
  printf("done\r\n");

  //pinMode(chipSelect, OUTPUT);
}

void Player::midiNoteOn(char channel, char note, char rate)
{
  vs1053.midiWriteData((0x90 | channel), note, rate);
}

void Player::midiNoteOff(char channel, char note, char rate)
{
  vs1053.midiWriteData((0x80 | channel), note, rate);
}



void Player::midiDemoPlayer(void)
{
  wait_ms(1000);
  vs1053.midiWriteData(0xB0, 0x07, 120);

  //GM2 Mode
  printf("Fancy Midi Sounds\r\n");
  vs1053.midiWriteData(0xB0, 0, 0x78);
  for(int instrument = 30 ; instrument < 31 ; instrument++)
  {
    printf(" Instrument: %d\r\n",instrument);

    vs1053.midiWriteData(0xC0, instrument, 0);    //Set instrument number. 0xC0 is a 1 data byte command

    //Play notes from F#-0 (30) to F#-5 (90):
    for (int note = 27 ; note < 87 ; note++)
    {
      printf("N: %d\r\n",note);
      //Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
      midiNoteOn(0, note, 127);
      wait_ms(50);

      //Turn off the note with a given off/release velocity
      midiNoteOff(0, note, 127);
      wait_ms(50);
    }

    //delay 100ms between each instruments
    wait_ms(100);
    }
}

