Exemplo n.º 1
0
    private void NoteDown(MelodyNote note)
    {
        CancelInvoke("StopMelody");

        if (!_activeNotes.ContainsKey(note.GetHashCode()))
        {
            // there's currently no input - so we should start recording now.
            // we assume, that the melody isn't longer than 10 minutes
            if (CurrentMelody.IsEmpty)
            {
                CurrentMelody.Audio = Microphone.Start(MicrophoneDevice, true, 600, MicrophoneFreq);
            }

            if (!CurrentMelody.IsEmpty)
            {
                note.Start = Time.time - CurrentMelody.Start;
            }
            else
            {
                note.Start          = 0;
                CurrentMelody.Start = Time.time;
            }
            _activeNotes.Add(note.GetHashCode(), note);
            CurrentMelody.Notes.Add(note);
        }
    }
Exemplo n.º 2
0
    private void NoteUp(MelodyNote note)
    {
        MelodyNote activeNote;

        _activeNotes.TryGetValue(note.GetHashCode(), out activeNote);
        if (activeNote == null)
        {
            return;
        }

        activeNote.Duration = Time.time - activeNote.Start - CurrentMelody.Start;
        _activeNotes.Remove(activeNote.GetHashCode());
        Invoke("StopMelody", SilenceBetweenMelodies);
    }