protected void CreateUiRecordedNote(RecordedNote recordedNote, bool useRoundedMidiNote)
    {
        if (recordedNote.StartBeat == recordedNote.EndBeat)
        {
            return;
        }

        // Pitch detection algorithms often have issues finding the correct octave. However, the octave is irrelevant for scores.
        // When notes are drawn far away from the target note because the pitch detection got the wrong octave then it looks wrong.
        // Thus, only the relative pitch of the roundedMidiNote is used and drawn on the octave of the target note.
        int midiNote;

        if (useRoundedMidiNote &&
            recordedNote.TargetNote != null)
        {
            midiNote = MidiUtils.GetMidiNoteOnOctaveOfTargetMidiNote(recordedNote.RoundedMidiNote, recordedNote.TargetNote.MidiNote);
        }
        else
        {
            midiNote = recordedNote.RecordedMidiNote;
        }

        UiRecordedNote uiNote = Instantiate(uiRecordedNotePrefab, uiRecordedNotesContainer);

        uiNote.RecordedNote  = recordedNote;
        uiNote.StartBeat     = recordedNote.StartBeat;
        uiNote.TargetEndBeat = recordedNote.EndBeat;
        // Draw already a portion of the note
        uiNote.LifeTimeInSeconds = Time.deltaTime;
        uiNote.EndBeat           = recordedNote.StartBeat + (uiNote.LifeTimeInSeconds * beatsPerSecond);

        uiNote.MidiNote = midiNote;
        if (micProfile != null)
        {
            uiNote.SetColorOfMicProfile(micProfile);
        }

        Text uiNoteText = uiNote.lyricsUiText;

        if (showPitchOfNotes)
        {
            string pitchName = MidiUtils.GetAbsoluteName(midiNote);
            uiNoteText.text = " (" + pitchName + ")";
        }
        else
        {
            uiNoteText.text = "";
        }

        RectTransform uiNoteRectTransform = uiNote.RectTransform;

        PositionUiNote(uiNoteRectTransform, midiNote, uiNote.StartBeat, uiNote.EndBeat);

        uiRecordedNotes.Add(uiNote);
        recordedNoteToUiRecordedNotesMap.AddInsideList(recordedNote, uiNote);
    }
Beispiel #2
0
    void Start()
    {
        if (micProfile == null)
        {
            gameObject.SetActive(false);
            return;
        }

        arrowImageRectTransform = arrowImage.GetComponent <RectTransform>();
        arrowImage.color        = micProfile.Color;
        samplesPerBeat          = (int)(micSampleRecorder.SampleRateHz * BpmUtils.MillisecondsPerBeat(songMeta) / 1000);
        playerNoteRecorder.RecordedNoteContinuedEventStream
        .Subscribe(recordedNoteEvent =>
        {
            lastRecordedRoundedMidiNote = MidiUtils.GetMidiNoteOnOctaveOfTargetMidiNote(
                recordedNoteEvent.RecordedNote.RoundedMidiNote,
                recordedNoteEvent.RecordedNote.TargetNote.MidiNote);
        });
        UpdatePosition(60);
    }