예제 #1
0
    IEnumerator PlayMelody(int[] melody, float repeatQuant = -1f, int initialWait = 0, int noteDuration = 1)
    {
        if (repeatQuant == -1)
        {
            repeatQuant = Mathf.Infinity;
        }
        while (initialWait > 0)
        {
            print("Waiting");
            yield return(NextCompass());

            initialWait--;
        }
        for (int repetition = 0; repetition < repeatQuant; repetition++)
        {
            foreach (int note in melody)
            {
                print("Playing: " + note);
                yield return(WaitBeats(noteDuration));

                musicPlayer.PlayNote(note % 12, (note / 12) - musicPlayer.baseOctave);
                PositionController.MoveNoteToPosition(VisualNote.main, note);
            }
        }
    }
예제 #2
0
    void Update()
    {
        List <int> notes = new List <int>();

        if (Input.GetKeyDown("a"))
        {
            notes.Add(0);                                 // C
        }
        if (Input.GetKeyDown("w"))
        {
            notes.Add(1);                                 // C#
        }
        if (Input.GetKeyDown("s"))
        {
            notes.Add(2);                                 // D
        }
        if (Input.GetKeyDown("e"))
        {
            notes.Add(3);                                 // D#
        }
        if (Input.GetKeyDown("d"))
        {
            notes.Add(4);                                 // E
        }
        if (Input.GetKeyDown("f"))
        {
            notes.Add(5);                                 // F
        }
        if (Input.GetKeyDown("t"))
        {
            notes.Add(6);                                 // F#
        }
        if (Input.GetKeyDown("g"))
        {
            notes.Add(7);                                 // G
        }
        if (Input.GetKeyDown("y"))
        {
            notes.Add(8);                                 // G#
        }
        if (Input.GetKeyDown("h"))
        {
            notes.Add(9);                                 // A
        }
        if (Input.GetKeyDown("u"))
        {
            notes.Add(10);                                // A#
        }
        if (Input.GetKeyDown("j"))
        {
            notes.Add(11);                                // B
        }
        if (Input.GetKeyDown("k"))
        {
            notes.Add(12);                                // C
        }
        if (Input.GetKeyDown("o"))
        {
            notes.Add(13);                                // C#
        }
        if (Input.GetKeyDown("l"))
        {
            notes.Add(14);                                // D
        }
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            octave += 1;
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            octave += -1;
        }

        // if some key pressed...
        if (notes.Count > 0)
        {
            foreach (int note in notes)
            {
                switch (livePlayerMode)
                {
                case LivePlayerMode.NOTE:
                    musicPlayer.PlayNote(note + transpose, octave);
                    break;

                case LivePlayerMode.CHORD:
                    musicPlayer.PlayChord(new Chord(note + transpose, octave, chordType));
                    break;

                case LivePlayerMode.ARPEGGIO:
                    musicPlayer.PlayChordArpeggio(
                        new Arpeggio(
                            new Chord(note + transpose, octave, chordType),
                            1f,
                            ArpeggioPatternRepository.patterns[ArpeggioPattern.OPEN_CHORD_WITHOUT_THIRD]
                            )
                        );
                    break;

                default:
                    break;
                }

                // Control the position of the main VisualNote instantiated
                PositionController.MoveNoteToPosition(VisualNote.main, note + transpose + octave * 12);
            }
        }
    }