private void RecordNote(int midiNote, double positionInSongInMillis, ESongEditorLayer targetLayer)
    {
        int currentBeat = GetCurrentBeat(positionInSongInMillis);

        if (currentBeat <= lastPitchDetectedBeat)
        {
            return;
        }

        if (lastRecordedNote != null &&
            lastRecordedNote.MidiNote == midiNote)
        {
            // Also fire the event for any skipped beats (e.g. because of low frame-rate)
            for (int beat = lastPitchDetectedBeat; beat <= currentBeat; beat++)
            {
                ContinueLastRecordedNote(beat, targetLayer);
            }
        }
        else
        {
            CreateNewRecordedNote(midiNote, currentBeat, targetLayer);
        }

        editorNoteDisplayer.UpdateNotes();

        lastPitchDetectedFrame = Time.frameCount;
        lastPitchDetectedBeat  = currentBeat;
        hasRecordedNotes       = true;
    }
    private void CreateNewRecordedNote(int midiNote, int currentBeat, ESongEditorLayer targetLayer)
    {
        lastRecordedNote = new Note(ENoteType.Normal, currentBeat, 1, midiNote - 60, " ");
        songEditorLayerManager.AddNoteToLayer(targetLayer, lastRecordedNote);

        // EndBeat of new note is currentBeat + 1. Overwrite notes that start before this beat.
        OverwriteExistingNotes(currentBeat + 1, targetLayer);
    }
    private List <Note> GetUpcomingSortedRecordedNotes()
    {
        int currentBeat = GetCurrentBeat(songAudioPlayer.PositionInSongInMillis - settings.SongEditorSettings.MicDelayInMillis);
        ESongEditorLayer targetLayer = GetRecordingTargetLayer();
        List <Note>      result      = songEditorLayerManager.GetNotes(targetLayer).Where(note => (note.StartBeat >= currentBeat)).ToList();

        result.Sort(Note.comparerByStartBeat);
        return(result);
    }
    private void ContinueLastRecordedNote(int currentBeat, ESongEditorLayer targetLayer)
    {
        if (currentBeat > lastRecordedNote.EndBeat)
        {
            lastRecordedNote.SetEndBeat(currentBeat);

            // EndBeat of extended note is currentBeat. Overwrite notes that start before this beat.
            OverwriteExistingNotes(currentBeat, targetLayer);
        }
    }
    private void OverwriteExistingNotes(int currentBeat, ESongEditorLayer targetLayer)
    {
        // Move the start beat of existing notes behind the given beat.
        // If afterwards no length would be left (or negative), then remove the note completely.
        List <Note> overlappingNotes = new List <Note>();
        int         behindNoteCount  = 0;

        foreach (Note upcomingNote in upcomingSortedRecordedNotes)
        {
            // Do not shorten the note that is currently beeing recorded.
            if (upcomingNote == lastRecordedNote)
            {
                continue;
            }

            if (upcomingNote.StartBeat < currentBeat && currentBeat <= upcomingNote.EndBeat)
            {
                overlappingNotes.Add(upcomingNote);
            }
            else if (upcomingNote.EndBeat < currentBeat)
            {
                // The position is behind the note, thus this note is not 'upcoming' anymore.
                behindNoteCount++;
            }
            else if (upcomingNote.EndBeat > currentBeat)
            {
                // The list is sorted, thus the other notes in the list will also not overlap with the currentBeat.
                break;
            }
        }
        if (behindNoteCount > 0)
        {
            upcomingSortedRecordedNotes.RemoveRange(0, behindNoteCount);
        }

        foreach (Note note in overlappingNotes)
        {
            if (note.EndBeat > currentBeat)
            {
                note.SetStartBeat(currentBeat);
            }
            else
            {
                songEditorLayerManager.RemoveNoteFromAllLayers(note);
                editorNoteDisplayer.DeleteNote(note);
            }
        }
    }
    private void RecordNote(int midiNote, double positionInSongInMillis, ESongEditorLayer targetLayer)
    {
        int currentBeat = (int)BpmUtils.MillisecondInSongToBeat(songMeta, positionInSongInMillis);

        if (lastRecordedNote != null &&
            lastRecordedNote.MidiNote == midiNote &&
            lastPitchDetectedFrame == Time.frameCount - 1)
        {
            ContinueLastRecordedNote(currentBeat);
        }
        else
        {
            CreateNewRecordedNote(midiNote, currentBeat, targetLayer);
        }

        lastPitchDetectedFrame = Time.frameCount;
    }
Beispiel #7
0
    private void DrawNotesInLayer(ESongEditorLayer layerKey)
    {
        List <Note> notesInLayer    = songEditorLayerManager.GetNotes(layerKey);
        List <Note> notesInViewport = notesInLayer
                                      .Where(note => noteArea.IsInViewport(note))
                                      .ToList();

        Color layerColor = songEditorLayerManager.GetColor(layerKey);

        foreach (Note note in notesInViewport)
        {
            EditorUiNote uiNote = UpdateOrCreateNote(note);
            if (uiNote != null)
            {
                uiNote.SetColor(layerColor);
            }
        }
    }
 public void SetLayerEnabled(ESongEditorLayer layerKey, bool newValue)
 {
     layerKeyToLayerMap[layerKey].IsEnabled = newValue;
 }
 public bool IsLayerEnabled(ESongEditorLayer layerKey)
 {
     return(layerKeyToLayerMap[layerKey].IsEnabled);
 }
 public Color GetColor(ESongEditorLayer layerKey)
 {
     return(layerKeyToLayerMap[layerKey].Color);
 }
 public List <Note> GetNotes(ESongEditorLayer layerKey)
 {
     return(layerKeyToLayerMap[layerKey].GetNotes());
 }
 public void ClearLayer(ESongEditorLayer layerKey)
 {
     layerKeyToLayerMap[layerKey].ClearNotes();
 }
 public void AddNoteToLayer(ESongEditorLayer layerKey, Note note)
 {
     layerKeyToLayerMap[layerKey].AddNote(note);
 }
Beispiel #14
0
 public LayerChangedEvent(ESongEditorLayer layerEnum)
 {
     LayerEnum = layerEnum;
 }
Beispiel #15
0
 public SongEditorLayer(ESongEditorLayer layerKey)
 {
     this.LayerKey = layerKey;
 }
Beispiel #16
0
 private void CreateNewRecordedNote(int midiNote, int currentBeat, ESongEditorLayer targetLayer)
 {
     lastRecordedNote = new Note(ENoteType.Normal, currentBeat, 1, midiNote - 60, " ");
     songEditorLayerManager.AddNoteToLayer(targetLayer, lastRecordedNote);
 }