Ejemplo n.º 1
0
    void OnTriggerEnter2D(Collider2D triggerCollider) //This one is for playing notes
    {
        NoteHelper note;

        note.pitch    = "";
        note.octave   = 0;
        note.waveform = 0;
        if (triggerCollider.tag == "Single Note")
        {
            note.pitch    = triggerCollider.GetComponent <Note>().pitch;
            note.waveform = (int)triggerCollider.GetComponent <Note>().wave;
            note.octave   = triggerCollider.GetComponent <Note>().octave;
            float freq = RandomEnumSetter.CalculateFrequency(note.pitch, note.octave);

            msg = "/ch1" + "+/freq-" + freq.ToString();
            //Debug.Log("Actual freq: " + freq + "Freq played: " + FindObjectOfType<tcpserver>().freqMedian);
            msg += "+/selector-" + note.waveform.ToString();
        }

        else if (triggerCollider.tag == "Long Note")
        {
            note.pitch    = triggerCollider.GetComponent <LongNote>().pitch;
            note.waveform = (int)triggerCollider.GetComponent <LongNote>().wave;
            note.octave   = triggerCollider.GetComponent <LongNote>().octave;
            float freq = RandomEnumSetter.CalculateFrequency(note.pitch, note.octave);
            //Debug.Log("Actual freq: " + freq + "Freq played: " + FindObjectOfType<tcpserver>().freqMedian);
            msg  = "/ch1" + "+/freq-" + freq.ToString();
            msg += "+/selector-" + note.waveform.ToString();
        }
    }
Ejemplo n.º 2
0
    public string SendBacktrack(int note)
    {
        float  freq     = RandomEnumSetter.CalculateFrequency(backtrackNotes[note].pitch, backtrackNotes[note].octave);
        int    waveform = backtrackNotes[note].waveform;
        int    length   = backtrackNotes[note].length;
        string msg;

        if (waveform != lastWaveForm)
        {
            msg = "/freq-" + freq.ToString() + "+/selector-" + waveform.ToString();
        }
        else
        {
            msg = "/freq-" + freq.ToString();
        }
        return(msg);
    }
Ejemplo n.º 3
0
    void Update()
    {
        string selectorMsg = "+/selector-";

        if (RotX > 15)
        {
            showWave = pulse;
        }
        else if (RotX < -20)
        {
            showWave = triangle;
        }
        else if (RotY > 20)
        {
            showWave = square;
        }
        else if (RotY < -20)
        {
            showWave = sawtooth;
        }
        else
        {
            showWave = sine;
        }

        if (flex > 750)
        {
            if (RotX > 15)
            {
                selector = pulse;
            }
            else if (RotX < -20)
            {
                selector = triangle;
            }
            else if (RotY > 20)
            {
                selector = square;
            }
            else if (RotY < -20)
            {
                selector = sawtooth;
            }
            else
            {
                selector = sine;
            }
            selectorMsg += selector;
        }
        else
        {
            selector     = 0;
            selectorMsg += selector;
        }

        float frequency = freq;

        if (frequency == 7f)
        {
            if (count > 1)
            {
                frequency = freqs[count - 1];
            }
            else
            {
                frequency = freqs[10];
            }
        }

        freqs[count] = frequency;
        count++;

        if (count > freqs.Length - 1)
        {
            count = 0;
        }

        float[] freqsort = new float[11];
        freqs.CopyTo(freqsort, 0);
        Array.Sort(freqsort);
        median = freqsort[5];

        int lanes = FindObjectOfType <Spawner>().lanes;

        int currLane = (int)Math.Round(Mathf.Lerp(12, lanes - 1, Mathf.InverseLerp(Low, Low + Delta, median)));

        octave = currLane / 7;

        if (currLane < 7)
        {
            pitch = RandomEnumSetter.GMajorPosInv[currLane];
        }
        else
        {
            pitch = RandomEnumSetter.GMajorPosInv[currLane - 7 * octave];
        }

        freqMedian = RandomEnumSetter.CalculateFrequency(pitch, octave);

        freqMsg += "+/freq-" + freqMedian;

        msg = "/ch1" + freqMsg + selectorMsg;

        if (msg != lastMsg)
        {
            FindObjectOfType <BacktrackHandler>().ch1Msg = msg;
            lastMsg = msg;
        }

        freqMsg     = "";
        selectorMsg = "";
    }