Esempio n. 1
0
        public void ConvertEventsSaveScoresAndViewFeedback(List <MidiEventStorage> midiEvents,
                                                           List <CompressedNoteDuration> durs, float noteScale, float velocityIn, float offsetStartTime)
        {
            Debug.Log("Displaying scores");
            var evs = ConvertToNoteDurationFromMidiEventStorage(midiEvents);

            MakeSegmentsFor(evs, durs);
            var total   = 0d;
            var correct = 0d;

            var midiSessionDTO = new MidiSessionDto(RuntimeSettings.MIDI_FILE_NAME, 0, evs, durs, noteScale, velocityIn,
                                                    offsetStartTime);

            SaveScoresAndViewFeedback(midiSessionDTO);
        }
Esempio n. 2
0
        private void processSessionsAndPlaceUiEntry(string midiPath)
        {
            var sessions = MidiSessionController.getMidiSessions(midiPath);
            var row      = Instantiate(rowEntryObj);

            row.transform.SetParent(scrollViewParent);
            var rowRect = row.transform.GetComponent <RectTransform>();

            rowRect.localScale    = Vector3.one;
            rowRect.localPosition = Vector3.zero;

            // Load UI contents
            var head      = new MidiSessionDto(midiPath);
            var bestScore = 0d;
            var passes    = 0;

            if (sessions.Count > 0)
            {
                head      = sessions.First();
                bestScore = sessions.OrderByDescending(x => x.Accuracy).First().Accuracy;
                passes    = sessions.Where(x => x.Accuracy >= SCORE_TO_PASS).Count();
            }

            Debug.Log(sessions.Count());
            //var best = string.Format("%.2f\\%", bestScore * 100);
            setText(head.FormattedTrackName, NAME_INDEX, row);
            setText((bestScore * 100).ToString("F2") + "%", BEST_SCORE_INDEX, row);
            setText(passes + "/" + sessions.Count(), OVERALL_SCORE_INDEX, row);

            var difficulty = MidiSessionController.GetDifficultyFor(midiPath);

            setText(difficulty.ToString(), DIFFICULTY_INDEX, row);

            // Setup button
            row.GetComponent <Button>().onClick.AddListener(delegate { playButtonEvent(midiPath, difficulty); });

            if (passes > 0)
            {
                tracksCompleted++;
            }
            totalTracks++;

            // Add to list to fix sizing in update()
            scrollViewRows.Add(row);
        }
Esempio n. 3
0
        public void SaveScoresAndViewFeedback(MidiSessionDto session, bool save = true)
        {
            var userEvents  = session.userNoteDurations;
            var trackEvents = session.trackNoteDurations;

            Debug.Log("User events: " + userEvents.Count());
            Debug.Log("Track events: " + trackEvents.Count());

            var segments = MakeSegmentsFor(userEvents, trackEvents);
            var velocity = 1f / session.velocityIn * session.noteScale;
            var total    = 0d;
            var correct  = 0d;

            if (userEvents.Count == 0)
            {
                Debug.LogWarning("No midievents recorded");
            }

            foreach (var e in segments)
            {
                var keyNum = e.Key;
                var list   = e.Value;

                foreach (var m in list)
                {
                    var key = PianoKeys.GetKeyFor(keyNum);
                    total++;
                    var go      = Instantiate(cube);
                    var lmraway = piano.GetLMRAwayVectorsForKey(key,
                                                                MidiFileSequencer.calcX(m.offsetY / velocity + m.scaleY / 2f / velocity));
                    spawnedSegments.Add(go);
                    var dummy = new GameObject();
                    var k     = piano.GetKeyObj(key);
                    dummy.transform.SetParent(k.transform);
                    go.transform.SetParent(piano.transform);
                    var dropdownScale = go.transform.localScale;
                    go.transform.localScale = new Vector3(dropdownScale.x, m.scaleY / velocity, dropdownScale.z);
                    go.transform.position   = lmraway.away;

                    Color color;
                    switch (m.type)
                    {
                    case MidiSegment.SegmentType.EXTRA:
                        color = Color.red;
                        go.transform.localScale += new Vector3(.0001f, .0001f, .0001f);
                        break;

                    case MidiSegment.SegmentType.CORRECT:
                        color = Color.green;
                        go.transform.localScale += new Vector3(.0002f, .0002f, .0002f);
                        correct++;
                        break;

                    case MidiSegment.SegmentType.MISSED:
                        color = Color.yellow;
                        break;

                    default:
                        color = Color.black;     // WTF C#??
                        break;
                    }

                    var rder = go.GetComponent <Renderer>();
                    rder.material.color = color;
                    var rotation = Quaternion.LookRotation(lmraway.centre - lmraway.away);
                    go.transform.rotation = rotation;
                    go.transform.Rotate(0, -90f, 90f);
                }
            }

            var accuracy = correct / total;

            Debug.Log("Displaying end feedback text");
            int score;

            if (save)
            {
                score = (int)(accuracy * 100);
            }
            else
            {
                score = (int)(session.Accuracy * 100);
            }
            piano.showText(session.FormattedTrackName + ": " + score + "%", 50, false);

            if (save) // dont resave a loaded session
            {
                Debug.Log("Saving session - score = " + accuracy * 100);
                // Same but update accuracy
                var midiSessionDTO = new MidiSessionDto(RuntimeSettings.MIDI_FILE_NAME, accuracy, userEvents,
                                                        session.trackNoteDurations, session.noteScale, session.velocityIn, session.offsetStartTime);
                new MidiSessionController().putMidiSession(midiSessionDTO);
            }
        }
Esempio n. 4
0
 private void playButtonEvent(MidiSessionDto session)
 {
     RuntimeSettings.CACHED_SESSION = session;
     RuntimeSettings.LOAD_SAVED_SESSION_AT_STARTUP = true;
     SceneManager.LoadScene(PlayModeSceneName);
 }