public Composition Compose(IEnumerable <LilypondToken> lilypondTokens) { composition = new Composition(); var enumerator = new LilypondTokenEnumerator(lilypondTokens); while (enumerator.HasTokensLeft) { AddToComposition(enumerator); } return(composition); }
public Token Convert(LilypondTokenEnumerator enumerator) { enumerator.Next(); ClefBuilder builder = new ClefBuilder(); ClefTone tone = ClefTone.G; if (enumerator.Current != null) { Enum.TryParse(enumerator.Current.TokenText, true, out tone); } builder.WithTone(tone); return(builder.Build()); }
private void AddToComposition(LilypondTokenEnumerator enumerator) { var input = enumerator.Current; if (_tokenConverters.ContainsKey(input.Kind)) { var converter = _tokenConverters[input.Kind]; var token = converter.Convert(enumerator); if (token != null) { composition.Tokens.Add(token); } } enumerator.Next(); }
public Token Convert(LilypondTokenEnumerator enumerator) { enumerator.Next(); var signature = enumerator.Current; string[] parts = signature.TokenText.Split('/'); var builder = new TimeSignatureBuilder(); if (int.TryParse(parts[0], out int count) && int.TryParse(parts[1], out int denominator)) { builder.WithCount(count); builder.WithDenominator(denominator); } return(builder.Build()); }
public Token Convert(LilypondTokenEnumerator enumerator) { enumerator.Next(); var builder = new TempoBuilder(); int bpm = 120; if (enumerator.Current != null) { var match = Regex.Match(enumerator.Current.TokenText, @"\d+=(\d+)"); if (match.Success) { int.TryParse(match.Groups[1].Value, out bpm); } } bpm = Math.Max(1, bpm); // make sure no <= 0 bpm is set builder.WithBPM(bpm); return(builder.Build()); }
public Token Convert(LilypondTokenEnumerator enumerator) { var input = enumerator.Current; var match = regex.Match(input.TokenText); if (match.Success) { SymbolBuilder builder = new SymbolBuilder(); if (int.TryParse(match.Groups[1].Value, out int denominator)) { int dots = match.Groups[2].Length; builder.WithLength(denominator, dots); return(builder.Build()); } else { throw new InvalidOperationException("Not a rest that can be converted"); } } else { throw new InvalidOperationException("Not a rest that can be converted"); } }
public Token Convert(LilypondTokenEnumerator enumerator) { var input = enumerator.Current; var match = noteRegex.Match(input.TokenText); if (match.Success) { SymbolBuilder builder = new SymbolBuilder(); var tone = GetToneFromLetter(match.Groups[1].Value); Accidental accidental = Accidental.None; if (match.Groups[2].Success) { accidental = match.Groups[2].Value == "is" ? Accidental.Sharp : Accidental.Flat; } // determine octave MoveToClosestOctaveOffset(tone); previousNoteTone = tone; if (match.Groups[3].Success) { UpdateOctaveOffset(match.Groups[3].Value); } // set pitch builder.WithPitch(tone, accidental, octaveOffset); // determine length if (int.TryParse(match.Groups[4].Value, out int denominator)) { int dots = match.Groups[5].Length; builder.WithLength(denominator, dots); } return(builder.Build()); } else { throw new InvalidOperationException("Not a note that can be read"); } }
public Token Convert(LilypondTokenEnumerator enumerator) { return(new Barline()); }
public Token Convert(LilypondTokenEnumerator enumerator) { enumerator.Next(); // skips next token as it is a parameter for relative return(null); }