public override void Interpret(LilypondContext context) { context.PreviousNotePitch = _startPitch; context.CurrentOctave += _octaveChange; base.Interpret(context); }
public void Solve(LilypondContext context, LilypondToken token) { token = token.NextToken; var times = token.Value.Split('/'); var timeSignature = new PSAMControlLibrary.TimeSignature(TimeSignatureType.Numbers, UInt32.Parse(times[0]), UInt32.Parse(times[1])); context.Symbols.Add(timeSignature); }
public void Solve(LilypondContext context, LilypondToken token) { // Length int noteLength = Int32.Parse(Regex.Match(token.Value, @"\d+").Value); // Crosses and Moles int alter = 0; alter += Regex.Matches(token.Value, "is").Count; alter -= Regex.Matches(token.Value, "es|as").Count; // Octaves int distanceWithPreviousNote = notesorder.IndexOf(token.Value[0]) - notesorder.IndexOf(context.PreviousNote); if (distanceWithPreviousNote > 3) // Shorter path possible the other way around { distanceWithPreviousNote -= 7; // The number of notes in an octave } else if (distanceWithPreviousNote < -3) { distanceWithPreviousNote += 7; // The number of notes in an octave } if (distanceWithPreviousNote + notesorder.IndexOf(context.PreviousNote) >= 7) { context.PreviousOctave++; } else if (distanceWithPreviousNote + notesorder.IndexOf(context.PreviousNote) < 0) { context.PreviousOctave--; } // Force up or down. context.PreviousOctave += token.Value.Count(c => c == '\''); context.PreviousOctave -= token.Value.Count(c => c == ','); context.PreviousNote = token.Value[0]; var note = new Note(token.Value[0].ToString().ToUpper(), alter, context.PreviousOctave, (MusicalSymbolDuration)noteLength, NoteStemDirection.Up, NoteTieType.None, new List <NoteBeamType>() { NoteBeamType.Single }); note.NumberOfDots += token.Value.Count(c => c.Equals('.')); context.Symbols.Add(note); }
public void Solve(LilypondContext context, LilypondToken token) { token = token.NextToken; if (token == null) { return; } if (token.Value == "treble") { context.CurrentClef = new PSAMControlLibrary.Clef(ClefType.GClef, 2); } else if (token.Value == "bass") { context.CurrentClef = new PSAMControlLibrary.Clef(ClefType.FClef, 4); } //else // throw new NotSupportedException($"Clef {token.Value} is not supported."); context.Symbols.Add(context.CurrentClef); }
public void Solve(LilypondContext context, LilypondToken token) { var restLength = Int32.Parse(token.Value[1].ToString()); context.Symbols.Add(new Rest((MusicalSymbolDuration)restLength)); }
public abstract void Interpret(LilypondContext context);
public void Solve(LilypondContext context, LilypondToken token) { context.Symbols.Add(new Barline()); }
public void Solve(LilypondContext context, LilypondToken token) { // Tempo not supported }
public LilypondSequenceReader(string lilyContent) { string[] lilypondText = lilyContent.Split().Where(item => item.Length > 0).ToArray(); LilypondContext context = new LilypondContext(); Stack <LilypondSection> sections = new Stack <LilypondSection>(); LilypondSection rootSection = null; for (int i = 0; i < lilypondText.Length; i++) { switch (lilypondText[i]) { case "\\relative": // New relative section start with a startPitch and an ocatveChange RelativeExpression relativeExpression = new RelativeExpression(lilypondText[i + 1][0], string.Concat(lilypondText[i + 1].Skip(1))); sections.Push(relativeExpression); if (rootSection == null) { rootSection = relativeExpression; } i += 2; break; case "\\repeat": RepeatExpression repeatExpression = new RepeatExpression(); sections.Peek()?.ChildExpressions.Add(repeatExpression); sections.Push(repeatExpression); i += 3; break; case "\\alternative": AlternativeExpression alternativeExpression = new AlternativeExpression(); sections.Peek()?.ChildExpressions.Add(alternativeExpression); sections.Push(alternativeExpression); context.InAlternative = true; i++; break; case "\\clef": sections.Peek().ChildExpressions.Add(new ClefExpression(lilypondText[i + 1])); i++; break; case "\\tempo": sections.Peek().ChildExpressions.Add(new TempoExpression(lilypondText[i + 1])); i += 1; break; case "\\time": sections.Peek().ChildExpressions.Add(new TimeSignatureExpression(lilypondText[i + 1])); i++; break; case "{": if (context.InAlternative) { // There is a new alternative group in the current alternative block AlternativeGroupExpression alternativeGroup = new AlternativeGroupExpression(); sections.Peek()?.ChildExpressions.Add(alternativeGroup); sections.Push(alternativeGroup); context.InAlternativeGroup = true; } else { LilypondSection lilypondSection = new LilypondSection(); if (sections.Any()) { sections.Peek()?.ChildExpressions.Add(lilypondSection); sections.Push(lilypondSection); } } break; case "}": // Section has ended. It is no longer the current section, so pop it from the stack if (context.InRepeat) { if (lilypondText[i + 1] != "\\alternative") { sections.Peek().ChildExpressions.Add(new BarlineExpression(true)); } context.InRepeat = false; } if (sections.Any()) { sections.Pop(); } break; case "|": sections.Peek().ChildExpressions.Add(new BarlineExpression()); break; // It is a note or an unknown token default: try { sections.Peek().ChildExpressions.Add(new NoteExpression(lilypondText[i])); break; } catch (Exception) { /* It is an unknown token, skip it. */ break; } } } rootSection.Interpret(context); if (!context.ClefAdded) { context.Sequence.Symbols.Insert(0, new Clef(ClefType.GClef)); } Sequence = context.Sequence; }