private MusicElement CreateMusicElement(string token) { NoteType noteType; Enum.TryParse(token.Substring(0, 1).ToUpper(), out noteType); var dots = token.Count(c => c == '.'); var number = int.Parse(Regex.Match(token, @"\d+").Value); var durationType = (DurationType)number; if (new Regex(@"[a-g][,'eis]*[0-9]+[.]*").IsMatch(token)) { var builder = new NoteBuilder(noteType); // Octave var increaseOctaves = token.Count(c => c == '\''); var decreaseOctaves = token.Count(c => c == ',') * -1; builder.ChangeOctave(increaseOctaves + decreaseOctaves); // Sharp or flat if (token.Contains("is")) { builder = builder.Sharp(); } else if (token.Contains("token")) { builder = builder.Flat(); } if (token.Contains("~")) { builder = builder.IsTied(); } builder.AddDots(dots).Duration(durationType); return(builder.Build()); } if (new Regex(@"r.*?[0-9][.]*").IsMatch(token)) { var builder = new RestBuilder(); builder.AddDots(dots).Duration(durationType); return(builder.Build()); } return(null); }