private LilypondToken SetNextRest(LilypondToken startToken) { Note n = FindRest(startToken); SetNextSymbol(symbols, n); return(startToken); }
public LilypondToken GetRootToken() { LilypondToken t = rootToken; rootToken = null; return(t); }
private LilypondToken FindSection(LilypondToken startToken) { int countSectionStarts = 0; LilypondToken currentToken = startToken; while (currentToken.NextToken != null) { if (currentToken.TokenKind == LilypondTokenKind.SectionStart) { countSectionStarts++; } else if (currentToken.TokenKind == LilypondTokenKind.SectionEnd) { countSectionStarts--; } if (countSectionStarts == 0) { break; } else if (countSectionStarts < 0) { return(startToken); } currentToken = currentToken.NextToken; } return(currentToken); }
public void ReadLily(string text) { string currentWord = ""; int position = 0; while (position < text.Length) { LilypondTokenKind[] resultToken = lookupTable.Where(pv => Regex.IsMatch(currentWord, pv.Key)).Select(pv => pv.Value).ToArray(); char currentChar = text[position]; if (currentChar.Equals(' ')) { LilypondToken tempToken = new LilypondToken { TokenKind = LilypondTokenKind.Unknown }; if (resultToken.Length > 0) { tempToken = new LilypondToken { TokenKind = resultToken[0] }; tempToken.Value = currentWord; } if (currentWord.Length > 0) { SetNextToken(tempToken); } currentWord = ""; } else { currentWord += currentChar; } position++; } }
private Note FindRest(LilypondToken currentToken) { string text = currentToken.Value; Regex re = new Regex(@"^r(\d+)([.]*)$"); Match result = re.Match(text); noteBuilder.SetDuriation(int.Parse(result.Groups[1].Value)); noteBuilder.SetDotted(result.Groups[2].Value.Length); return(noteBuilder.BuildNote()); }
private LilypondToken FindTimeSignature(LilypondToken startToken) { LilypondToken currentToken = startToken.NextToken; if (currentToken.TokenKind == LilypondTokenKind.TimeValue) { SetTimeSignature(currentToken.Value); } return(currentToken); }
private LilypondToken FindTempo(LilypondToken startToken) { LilypondToken currentToken = startToken.NextToken; if (currentToken.TokenKind == LilypondTokenKind.TempoValue) { SetTempo(currentToken.Value); } return(currentToken); }
private LilypondToken FindClef(LilypondToken startToken) { LilypondToken currentToken = startToken.NextToken; if (currentToken.TokenKind == LilypondTokenKind.ClefValue) { SetClef(currentToken.Value); } return(currentToken); }
private LilypondToken FindRelative(LilypondToken startToken) { LilypondToken currentToken = startToken.NextToken; if (currentToken.TokenKind == LilypondTokenKind.RelativeValue) { Regex re = new Regex(@"^c([,']*)$"); var result = re.Match(currentToken.Value); noteBuilder.ModifyOctave(FindOctaveModifier(result.Groups[1].Value)); } return(currentToken); }
private void SetNextToken(LilypondToken nextToken) { if (rootToken == null) { rootToken = nextToken; } else { prefToken.NextToken = nextToken; } prefToken = nextToken; }
private Note FindNote(LilypondToken currentToken) { string text = currentToken.Value; Regex re = new Regex(@"^([a-g])([eis]*)([,']*)(\d+)([.]*)$"); Match result = re.Match(text); noteBuilder.SetPitch(result.Groups[1].Value); noteBuilder.SetSemitone(pitchModifiers[result.Groups[2].Value]); noteBuilder.ModifyOctave(FindOctaveModifier(result.Groups[3].Value) + RelativeOctaveModifier(result.Groups[1].Value)); noteBuilder.SetDuriation(int.Parse(result.Groups[4].Value)); noteBuilder.SetDotted(result.Groups[5].Value.Length); return(noteBuilder.BuildNote()); }
public void ReadLily(LilypondToken rootToken) { Clear(); LilypondToken currentToken = rootToken; while (currentToken != null) { if (parserFunctions.ContainsKey(currentToken.TokenKind)) { currentToken = (LilypondToken)parserFunctions[currentToken.TokenKind].DynamicInvoke(currentToken); } currentToken = currentToken.NextToken; } }
private Note[] FindNoteSection(LilypondToken startToken, LilypondToken endToken) { LilypondToken currentToken = startToken; Note[] newSymbols = new Note[2]; while ((currentToken != endToken && currentToken.NextToken != endToken) && currentToken.NextToken != null) { currentToken = currentToken.NextToken; if (currentToken.TokenKind == LilypondTokenKind.Note) { newSymbols = (Note[])SetNextSymbol(newSymbols, FindNote(currentToken)); } } return(newSymbols); }
private LilypondToken SetAlternitive(LilypondToken startToken) { LilypondToken currentToken = startToken.NextToken; LilypondToken lastToken = FindSection(currentToken); Symbol prevSymbol = symbols[1]; if (prevSymbol.GetType() == typeof(BarLine)) { BarLine barline = prevSymbol as BarLine; while (currentToken != lastToken && currentToken.NextToken != lastToken) { currentToken = currentToken.NextToken; LilypondToken templastToken = FindSection(currentToken); Note tempRoot = FindNoteSection(currentToken, templastToken)[0]; currentToken = templastToken; barline.Alternatives.Add(tempRoot); } } return(currentToken); }
private LilypondToken SetRepeat(LilypondToken startToken) { LilypondToken currentToken = startToken.NextToken.NextToken.NextToken; BarLine firstBarline = new BarLine { Type = BarLine.TYPE.START }; BarLine lastBarline = new BarLine { Type = BarLine.TYPE.REPEAT, Buddy = firstBarline }; LilypondToken lastToken = FindSection(currentToken); SetNextSymbol(symbols, firstBarline); Symbol[] newSymbols = FindNoteSection(currentToken, lastToken); SetNextSymbol(symbols, newSymbols[0]); symbols[1] = newSymbols[1]; SetNextSymbol(symbols, lastBarline); return(lastToken); }
private void Clear() { rootToken = null; prefToken = null; }