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
    // Use this for initialization
    void Start()
    {
        _keys = Enumerable.Range((int)KeyCode.A, 26).Select(x => (KeyCode)x);

        if (string.IsNullOrEmpty(MicrophoneDevice))
        {
            MicrophoneDevice = Microphone.devices.FirstOrDefault(x => !string.IsNullOrEmpty(x));
            if (string.IsNullOrEmpty(MicrophoneDevice))
            {
                Debug.Log("No Microphone found :(");
            }
        }

        int minFreq, maxFreq;

        Microphone.GetDeviceCaps(MicrophoneDevice, out minFreq, out maxFreq);
        MicrophoneFreq = (minFreq + maxFreq) / 2;

        MidiMaster.noteOnDelegate += (channel, midiNote, velocity) =>
        {
            var note = MelodyNote.FromMidiNote(midiNote - MinNoteValue);
            note.Velocity = velocity;
            NoteDown(note);
        };

        MidiMaster.noteOffDelegate += (channel, note) =>
        {
            var midiNote = MelodyNote.FromMidiNote(note - MinNoteValue);

            NoteUp(midiNote);
        };

        StartNewMelody();
    }
Exemplo n.º 3
0
        public PercussionNote Drums;              //!< The @link Music::PercussionNote drum note@endlink.

        public CombinedNote(MelodyNote aMelodyNote, PercussionNote aPercussionNote, NoteLength aOffset)
        {
            MusicalNote        = aMelodyNote;
            NumPitches         = MusicalNote.NumPitches;
            Drums              = aPercussionNote;
            NumDrums           = Drums.NumHits;
            OffsetFromPrevNote = aOffset;
        }
Exemplo n.º 4
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);
    }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        foreach (var keyCode in _keys)
        {
            var note = MelodyNote.FromKeyCode(keyCode);
            if (note == null)
            {
                continue;
            }
            // Keyboard Down
            if (Input.GetKeyDown(keyCode))
            {
                NoteDown(note);
            }

            // Keyboard Up
            if (Input.GetKeyUp(keyCode))
            {
                NoteUp(note);
            }
        }
    }