Esempio n. 1
0
 private void ReadSong(StreamReader reader, ISongInterpreter songInterpreter)
 {
     while (!reader.EndOfStream)
     {
         var line            = reader.ReadLine();
         var interpretedLine = songInterpreter.ConvertToNotes(line);
         if (interpretedLine != null && interpretedLine.Any())
         {
             foreach (var note in interpretedLine)
             {
                 Notes.Add(note);
             }
         }
     }
 }
        public IList <Tuple <int, Note> > ConvertToNotes(string str)
        {
            var parts         = str.Split(' ');
            var measureParsed = Int32.TryParse(parts[0], out var measureNumber);
            var beatsParsed   = double.TryParse(parts[1], out var beatsNumber);
            var chordParsed   = _chordLookup.TryGetValue(parts[2].ToUpperInvariant(), out var chord);

            //TODO parse the inversion and octave

            if (measureParsed && beatsParsed && chordParsed)
            {
                if (parts.Length > 3)
                {
                    chord = ModifyChord(chord, parts.Skip(3).ToArray());
                }
                var sampleNum       = (int)(_sampleRate * ((measureNumber * _timeSignature + beatsNumber) * 60) / (double)_tempo);
                var specifiedOctave = parts.FirstOrDefault(s => s.StartsWith("octave=")) ?? "";
                var inversion       = parts.FirstOrDefault(s => s.StartsWith("inversion=")) ?? "";
                var notes           = chord.GetNotes(inversion == "" ? Inversion.Base : (Inversion)(inversion.Last() - '0'), specifiedOctave == "" ? (short)3 : (short)(specifiedOctave.Last() - '0'));
                if (parts.Any(s => s == "strup"))
                {
                    var noteTimes = new List <Tuple <int, Note> >();
                    for (int i = notes.Count - 1; i >= 0; --i)
                    {
                        noteTimes.Add(new Tuple <int, Note>(sampleNum + (int)((notes.Count - (i + 1)) * _sampleRate / 100.0), notes[i]));
                    }
                    return(noteTimes);
                }
                if (parts.Any(s => s == "strdown"))
                {
                    var noteTimes = new List <Tuple <int, Note> >();
                    for (int i = 0; i < notes.Count; ++i)
                    {
                        noteTimes.Add(new Tuple <int, Note>(sampleNum + (int)(i * _sampleRate / 100.0), notes[i]));
                    }
                    return(noteTimes);
                }
                return(notes.Select(n => new Tuple <int, Note>(sampleNum, n)).ToList());
            }
            return(_fallbackInterpreter.ConvertToNotes(str));
        }