public static Song[] LoadSongs(string address) { var songList = new List <Song>(); using (var reader = new StreamReader(address, Encoding.UTF8)) { var line = ""; while (true) { line = reader.ReadLine(); if (line == null) { break; } var segments = line.Split(' '); if (segments.Length < 2) { continue; } var song = new Song { name = segments[0], score = new NoteOctave[segments.Length - 1][] }; for (var i = 1; i < segments.Length; i++) { var noteOctaveList = new List <NoteOctave>(); var noteOctave = new NoteOctave() { octave = -1 }; var noteString = ""; for (var j = 0; j < segments[i].Length; j++) { if (segments[i].Length > j + 1 && segments[i][j + 1] == 's') { noteOctave.note = NoteUtility.StringToNote($"{segments[i][j]}s"); } else if (NoteUtility.IsNote($"{segments[i][j]}")) { noteOctave.note = NoteUtility.StringToNote($"{segments[i][j]}"); } else if (noteOctave.octave == -1 && int.TryParse($"{segments[i][j]}", out var octave)) { noteOctave.octave = octave; noteOctaveList.Add(noteOctave); noteOctave = new NoteOctave() { octave = -1 }; } } song.score[i - 1] = noteOctaveList.ToArray(); } songList.Add(song); } } return(songList.ToArray()); try { } catch (Exception e) { throw e; } }
public static void NoteStreamLoader(NoteOctave noteOctave) { for (var i = 0; i < _candidates.Count; ++i) { var candidate = _candidates[i]; var currentNoteOctave = candidate.song.score[candidate.scoreIndex][candidate.numberOfArrival]; if (currentNoteOctave.note == noteOctave.note && currentNoteOctave.octave == noteOctave.octave) { continue; } var targetNoteOctave = candidate.song.score[candidate.scoreIndex][candidate.numberOfArrival + 1]; if (targetNoteOctave.note == noteOctave.note && targetNoteOctave.octave == noteOctave.octave) { ++candidate.numberOfArrival; if (candidate.song.score[candidate.scoreIndex].Length - 1 == candidate.numberOfArrival) { foundSong = candidate.song; _candidates.RemoveAt(i); Console.WriteLine($"Find and Remove from candidates: {candidate.song.name} of {candidate.scoreIndex}"); } else { candidate.wrongCount = 0; _candidates[i] = candidate; Console.WriteLine( $"Add number of arrival: {candidate.song.name} of {candidate.scoreIndex}, {candidate.numberOfArrival}/{candidate.song.score[candidate.scoreIndex].Length - 1}"); } } else { ++candidate.wrongCount; if (candidate.wrongCount >= WrongCapacity) { _candidates.RemoveAt(i); Console.WriteLine($"Not found and Remove from candidates: {candidate.song.name} of {candidate.scoreIndex}"); } else { _candidates[i] = candidate; Console.WriteLine($"Add number of wrong: {candidate.song.name} of {candidate.scoreIndex}, {candidate.wrongCount}/{WrongCapacity}"); } } } foreach (var song in _songs) { for (var i = 0; i < song.score.Length; ++i) { var targetNoteOctave = song.score[i][0]; if (_candidates.Any(item => item.song.name == song.name && item.scoreIndex == i)) { continue; } if (targetNoteOctave.note == noteOctave.note && targetNoteOctave.octave == noteOctave.octave) { _candidates.Add(new SongCandidate() { numberOfArrival = 0, scoreIndex = i, song = song, wrongCount = 0 }); Console.WriteLine($"Add to candidates: {song.name} of {i}"); } } } }