public Note(double duration, Pitch pitch) { this.duration = duration; this.Pitch = pitch; }
/// <summary> /// Read and return things /// </summary> Serial parseSerial() { var content = new List <Audible>(); string duration = ""; string pitchName = ""; while (true) { // Skip spaces and linebreaks this.parseSpace(); if (EndOfStream) { if (content.Count == 0 || duration.Length > 0) { throw parseError("Expected music objects"); } return(new Serial(content.ToArray())); } char c = this.peek(); switch (c) { case '#': this.parseComment(); break; case '{': Parallel parallel; if (duration.Length == 0) { parallel = this.parseParallel(); } else { parallel = this.parseParallel(double.Parse(duration)); duration = ""; } content.Add(parallel); break; case ',': // Return this.read(); return(new Serial(content.ToArray())); case '}': // Return return(new Serial(content.ToArray())); default: if (char.IsDigit(c) || c == '.') { // Must be part of duration, // because notes don't start with a digit duration = this.parseDouble(); } else { pitchName = this.parseWord(); // We're done parsing a note, so let's construct it try { Pitch pitch = Pitch.FromString(pitchName); Note note; if (duration.Length == 0) { note = new Note(1, pitch); } else { note = new Note(double.Parse(duration), pitch); duration = ""; } content.Add(note); } catch (KeyNotFoundException) { throw parseError("Don't know pitch '" + pitchName + "'"); } } break; } } }