using UnityEngine;
using System.Collections;

public class Teest : MonoBehaviour {

    float lastplay;
    int curr;

    int[] list;
    int lcurr;

    int note;

    float starttime;

    System.Random r;

    void Awake() {
        starttime = Time.time;
        lastplay = Time.time;
        GetComponents<AudioSource>()[0].Play();
        curr = 1;

        note = 0;

        lcurr = 0;
        list = new int[] {
            4,3,4,5,
            7,-5,7,-5,7,-5,7,-5,7,-5,7,-5,7,-5,7,-5,
            0,0,0,0,0,0,0,0,0,0,0,0,0,-1,0,2,
            4,-5,4,-5,4,-5,4,-5,4,-5,4,-5,4,-5,4,-5,
            -3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-4,-3,-1,
            0,-5,0,-5,0,-5,-5,-5,2,-5,2,-5,2,-5,-5,-5,
            4,-5,0,-5,4,-5,7,-5,12,-5,7,-5,9,-5,5,-5,
            7,7,7,7,7,7,7,7,7,7,7
        };
         r = new System.Random();
    }
	
	// Update is called once per frame
	void Update () {
        if (Time.time - lastplay > 3.25f) {
            GetComponents<AudioSource>()[curr].Play();
            curr++; curr %= 2;
            lastplay = Time.time;
        }

        int t = (int)((Time.time - starttime) * 8);
        if (t > lcurr) {
            lcurr = t;
            note = ((int)Mathf.Abs(r.Next()))%12; //list[(int)((Time.time - starttime) * 15)];
        }

        GetComponents<AudioSource>()[0].pitch = Mathf.Pow(2,note/12f); //1.0f + 0.1f * Mathf.Sin(Mathf.PI*2*5*Time.time);
        GetComponents<AudioSource>()[1].pitch = Mathf.Pow(2, note / 12f);//1.0f + 0.1f * Mathf.Sin(Mathf.PI*2*5 * Time.time);

    }
}
