protected virtual SourceText CreateSourceText(INotation notation) { var sb = new StringBuilder(); notation.Record(sb); return(SourceText.From(sb.ToString(), Encoding.UTF8)); }
public Measure(INotation notation) { Notation = notation; _beats = new List <IBeat>(BeatCount); for (var i = 0; i < BeatCount; i++) { _beats.Add(CreateBeat()); } }
public void CombineWhenListEmpty() { var result = new INotation[0].Combine(); Assert.IsType <ActionNotation>(result); var sb = new StringBuilder(); result.Record(sb); Assert.Empty(sb.ToString()); }
public void CombineWhenListNotEmpty() { var result = new INotation[] { "a".ToNotation(), "b".ToNotation() }.Combine(); Assert.NotSame(ConstNotations.Nothing, result); var sb = new StringBuilder(); result.Record(sb); Assert.Equal("ab", sb.ToString()); }
public object Interpret(INotation notation, IContext context) { object result = null; switch (notation) { case PostfixNotation postfixNotation: result = InterpretPostifix(postfixNotation, context); break; } return(result); }
public string GetNotationValue(string inputNotation, string inputValue, string outputNotation) { //проверяем параметры if (string.IsNullOrEmpty(inputNotation)) { throw new ArgumentException(nameof(inputNotation)); } if (string.IsNullOrEmpty(inputValue)) { throw new ArgumentException(nameof(inputValue)); } if (string.IsNullOrEmpty(outputNotation)) { throw new ArgumentException(nameof(outputNotation)); } //ищем входную нотацию, INotation inputN = _notations.SingleOrDefault(n => n.Name.Equals(inputNotation)); if (inputN == null) { return(String.Empty); } //ищем выходную нотацию INotation outputN = _notations.SingleOrDefault(n => n.Name.Equals(outputNotation)); if (outputN == null) { return(String.Empty); } //пытаемся присвоить входной нотации значение if (inputN.SetValue(inputValue)) { //передаем значение через int в выходную нотацию outputN.SetValue(inputN.ValueInt); //отдаем результат return(outputN.ValueString); } //иначе возвращаем пустую строку return(String.Empty); }
public JsNotation(INotation baseObject, ISvgScriptEngine engine) : base(baseObject, engine) { }
public To16Notation(int _number, INotation _base) { numberToShift = _number; baseToShift = _base; }
public string toString(INotation ntn) { return(this.value.ToString()); }
private void BuildScoreConvertSameSlurredNotesToTies_RecursiveFixSlurs(Score score, int partIndex, int staffIndex, int elementGroupIndex, int elementIndex, INotation currentElementSlurStartNotation) { var part = score.Parts[partIndex]; var staff = part.Staves[staffIndex]; var elementGroup = staff.Elements[elementGroupIndex]; var element = elementGroup[elementIndex]; var isEndOfElementGroup = elementGroupIndex >= staff.Elements.Length; if (isEndOfElementGroup) { return; } var nextElementGroup = staff.Elements[elementGroupIndex + 1]; var nextElementGroupNoteOfSamePitch = nextElementGroup.FirstOrDefault(nextElement => nextElement.Pitch == element.Pitch); if (nextElementGroupNoteOfSamePitch == null) { return; } /* If the next element group at the same pitch has an ending slur, convert this to a start/stop tie. */ { var nextElementGroupNoteStopSlur = nextElementGroupNoteOfSamePitch.Notations.FirstOrDefault(nextElementNotation => nextElementNotation != null && nextElementNotation is Slur && (nextElementNotation as Slur).Type == StartStopContinue.Stop); if (nextElementGroupNoteStopSlur == null) { /* No issue with two notes of the same pitch being slurred */ return; } else { /* For current element. replace the slur start notation with a tie start notation */ { var newNotations = element.Notations.ToList(); newNotations = (List <INotation>)newNotations.Where(x => x != currentElementSlurStartNotation); newNotations.Add(new Tie() { Type = StartStopContinue.Start, Number = (currentElementSlurStartNotation as Slur).Number, }); element.Notations = newNotations.ToArray(); } /* For next element. replace the slur stop notation with a tie stop notation */ { var newNotations = nextElementGroupNoteOfSamePitch.Notations.ToList(); newNotations = (List <INotation>)newNotations.Where(x => x != nextElementGroupNoteStopSlur); newNotations.Add(new Tie() { Type = StartStopContinue.Stop, Number = (currentElementSlurStartNotation as Slur).Number, }); nextElementGroupNoteOfSamePitch.Notations = newNotations.ToArray(); } } } /* If the next element group at the same pitch has a continuation slur, recursively evaluate this */ { var nextElementGroupNoteContinueSlur = nextElementGroupNoteOfSamePitch.Notations.FirstOrDefault(nextElementNotation => nextElementNotation != null && nextElementNotation is Slur && (nextElementNotation as Slur).Type == StartStopContinue.Stop); if (nextElementGroupNoteContinueSlur == null) { /* No issue with two notes of the same pitch being slurred */ return; } else { /* For current element. replace the slur start notation with a tie start notation */ { var newNotations = element.Notations.ToList(); newNotations = (List <INotation>)newNotations.Where(x => x != currentElementSlurStartNotation); newNotations.Add(new Tie() { Type = StartStopContinue.Start, Number = (currentElementSlurStartNotation as Slur).Number, }); element.Notations = newNotations.ToArray(); } /* For next element. replace the slur stop notation with a tie continue notation */ { var newNotations = nextElementGroupNoteOfSamePitch.Notations.ToList(); newNotations = (List <INotation>)newNotations.Where(x => x != nextElementGroupNoteContinueSlur); newNotations.Add(new Tie() { Type = StartStopContinue.Stop, Number = (currentElementSlurStartNotation as Slur).Number, }); var newStartNotation = new Slur() { Type = StartStopContinue.Start, Number = (currentElementSlurStartNotation as Slur).Number, }; newNotations.Add(newStartNotation); nextElementGroupNoteOfSamePitch.Notations = newNotations.ToArray(); BuildScoreConvertSameSlurredNotesToTies_RecursiveFixSlurs(score, partIndex, staffIndex, elementGroupIndex + 1, elementIndex, newStartNotation); } } } }
public Calc(INotation notation) { this.notation = notation; }
public string toString(INotation ntn) { return(a + "x^" + n); }
public ISongPart AddNotation(INotation notation) { _notations.Add(notation); return(this); }
protected virtual void Parse(IList <IToken> tokens, INotation notation, BeatType beatType, InstrumentType instrumentType) { notation.Repeating = DetectRepeating(tokens); notation.BeatType = beatType; notation.InstrumentType = instrumentType; var tokenIndex = 0; var measureIndex = -1; var lineIndex = 0; var beatIndex = 0; var noteIndex = 0f; TokenType?flamStart = null; IMeasure[] measures = null; var tokensToParse = tokens.ToList(); while (tokensToParse.Any()) { var token = tokensToParse.First(); tokensToParse.RemoveAt(0); switch (token.TokenType) { case TokenType.MeasureLine: beatIndex = 0; noteIndex = 0; if (!tokensToParse.Any() || tokensToParse.First().TokenType == TokenType.NextBeatNewLine || tokensToParse.First().TokenType == TokenType.End) { break; } measureIndex++; notation.AddMeasure(); measures = notation.Measures; break; case TokenType.NextBeat: beatIndex++; noteIndex = 0; break; case TokenType.NextBeatHalf: if (noteIndex % .5f == 0f) { beatIndex++; noteIndex = 0f; } else { noteIndex += .5f; } break; case TokenType.NextBeatTwoThird: if (noteIndex % .6667f == 0f) { beatIndex++; noteIndex = 0f; } else { noteIndex += .6667f; } break; case TokenType.NextBeatNewLine: lineIndex++; beatIndex = 0; noteIndex = 0; break; case TokenType.OpenBassFlam: case TokenType.OpenToneFlam: case TokenType.OpenSlapFlam: EnsureMeasures(notation.Name, measures, tokenIndex, token); flamStart = token.TokenType; break; case TokenType.OpenBass: case TokenType.OpenBassSmall: case TokenType.OpenTone: case TokenType.OpenToneSmall: case TokenType.OpenSlap: case TokenType.OpenSlapSmall: EnsureMeasures(notation.Name, measures, tokenIndex, token); if (flamStart != null) { measures[measureIndex].Beats[beatIndex].AddSound(noteIndex, TokenToSound(instrumentType, flamStart.Value)); measures[measureIndex].Beats[beatIndex].AddSound(noteIndex, TokenToSound(instrumentType, token.TokenType), .05f); flamStart = null; } else { measures[measureIndex].Beats[beatIndex].AddSound(noteIndex, TokenToSound(instrumentType, token.TokenType)); } break; case TokenType.DounBell: measures[measureIndex].Beats[beatIndex].AddSound(noteIndex, TokenToSound(instrumentType, token.TokenType)); break; case TokenType.ConnectionLine: noteIndex++; break; case TokenType.ConnectionLineHalf: case TokenType.DoubleConnectionLineHalf: noteIndex += .5f; break; case TokenType.ConnectionLineTwoThird: case TokenType.DoubleConnectionLineTwoThird: noteIndex += .6667f; break; } if (notation.BeatType != BeatType.Unknown && noteIndex > notation.NotesPerBeat * 2) { noteIndex = 0f; beatIndex++; } tokenIndex++; } }
public string toString(INotation ntn) { return(ntn.arrange(this.getOperator(), this.exp1.toString(ntn), this.exp2.toString(ntn))); }