private IEnumerable <OMatch <TValue> > GetAllMathes(TValue[] values, int startIndex = -1) { var handler = new SequenceHandler <TValue>(values) { Reverse = Options.HasFlag(ORegexOptions.ReverseSequence) }; startIndex = GetStartIndex(handler, startIndex); var captureTable = new OCaptureTable <TValue>(_fa.CaptureNames); for (int i = startIndex; i <= handler.Count; i++) { Range range; if (_fa.TryRun(handler, i, captureTable, out range)) { bool beginMatched = range.Index == startIndex; bool endMatched = range.RightIndex == handler.Count; if (!_fa.ExactBegin && !_fa.ExactEnd || !(beginMatched ^ _fa.ExactBegin) && !(endMatched ^ _fa.ExactEnd)) { var match = new OMatch <TValue>(handler, captureTable, range); captureTable.Add(0, match); yield return(match); } captureTable = new OCaptureTable <TValue>(_fa.CaptureNames); i += range.Length == 0 ? 0 : range.Length - 1; } if (_fa.ExactBegin) { break; } } }
internal OCapture(SequenceHandler <TValue> handler, Range range) { range = handler.Translate(range); Index = range.Index; Length = range.Length; _collection = handler.Collection; }
public void CorrectInvertTransform() { var seq = new[] {0, 1, 2, 3, 4, 5}; var handler = new SequenceHandler<int>(seq); Range range = new Range(1, 3); Assert.AreEqual(range, handler.Translate(range)); }
public void ConvertBrevePositionChord() { Sequence metricSequence = SequenceHandler.CreateNewSequence("kind of test", "Breve position Chord", "noPage", "Tenor", 3); Panel metricPanel = MeiImport.ImportDocument("..\\..\\files\\tests\\MetricSequenceChord.xml").Root.Descendants <Panel>().FirstOrDefault(); SequenceHandler.FlattenMeiToSequence(metricPanel, metricSequence); Controller.BuildSequence(metricSequence); SequenceConversion.ConvertBrevePosition(metricSequence); foreach (ObjectInSequence obj in metricSequence.ObjectsInSequence) { IAttCommon corresp = (IAttCommon)metricPanel.Descendants().FirstOrDefault(element => element.GetId() == obj.ID); if (corresp.HasN()) { Fraction exp = new Fraction(corresp.GetNValue()); if (obj is Model.Rest rest) { //Check if expected value is not null and then compare Assert.IsNotNull(exp); Assert.AreEqual(exp, rest.BrevePosition); } } } metricPanel = null; metricSequence = null; }
public void ConvertAbsolutePitchTest() { Sequence aPitchSeq = SequenceHandler.CreateNewSequence("Test", "Absolute Pitch", "noPage", "AbsolutePitch", 1); Panel aPitchPanel = MeiImport.ImportDocument("..\\..\\files\\tests\\AbsolutePitch.xml").Root.Descendants <Panel>().FirstOrDefault(); SequenceHandler.FlattenMeiToSequence(aPitchPanel, aPitchSeq); Controller.BuildSequence(aPitchSeq); SequenceConversion.ConvertAbsolutePitch(aPitchSeq); foreach (Model.Note note in aPitchSeq.ObjectsInSequence.Where(item => item is Model.Note)) { Assert.IsNotNull(note.WrittenPitch); mei.Note corresp = (mei.Note)aPitchPanel.Descendants().FirstOrDefault(element => element.GetId() == note.ID); if (corresp.HasPnum()) { if (Int32.TryParse(corresp.GetPnumValue(), out int pnum)) { Assert.AreEqual(pnum, note.PitchWithAccid); } else { throw new ArgumentNullException("Pnum could not be parsed!"); } } } }
public void ConvertLigatureTest() { Sequence ligSequence = SequenceHandler.CreateNewSequence("Test", "Ligature", "noPage", "Tenor", 3); Panel ligPanel = MeiImport.ImportDocument("..\\..\\files\\tests\\LigatureTest.xml").Root.Descendants <Panel>().FirstOrDefault(); SequenceHandler.FlattenMeiToSequence(ligPanel, ligSequence); Controller.BuildSequence(ligSequence); foreach (Model.Note note in ligSequence.ObjectsInSequence.Where(item => item is Model.Note)) { Assert.IsNotNull(note.LigaturePosition); Assert.IsNotNull(note.LigatureForm); if (note.LigaturePosition == 1) { Assert.AreEqual(StemDesc.LeftUp, note.Stem); } if (note.Position == 3 || note.Position == 4 || note.Position == 10 || note.Position == 11) { Assert.AreEqual(LigatureForm.Obliqua, note.LigatureForm); } else { Assert.AreEqual(LigatureForm.Recta, note.LigatureForm); } } }
public static SequenceContext CreateFromPacket(IDataPacket data, int fragmentSize) { SequenceInitPacket initPacket; var ms = new MemoryStream(); data.SerializeTo(ms); NetworkWriter.PrependStreamSize(ms); var completeBuff = ms.ToArray(); Guid seqGuid; var sequence = new SequenceHandler().CreateSequence(data, completeBuff, fragmentSize, out initPacket, out seqGuid); var initPacketStream = new MemoryStream(); initPacket.SerializeTo(initPacketStream); #if DEBUG // var sequenceStreams = new MemoryStream[sequence.Length]; // var sequenceBuffs = new List<byte[]>(); //for (var i = 0; i < sequence.Count; i++) //{ // var seq = sequence[i]; // sequenceStreams[i] = new MemoryStream(); // seq.SerializeTo(sequenceStreams[i]); // sequenceBuffs.Add(sequenceStreams[i].ToArray()); //} #endif var seqCtx = new SequenceContext(initPacket, sequence, initPacketStream.ToArray(), null) { SequenceGuid = seqGuid }; return(seqCtx); }
public override bool IsMatch(SequenceHandler <TValue> values, int index) { if (index >= values.Count) { return(false); } return(Comparer.Equals(values[index], Value)); }
private static int GetStartIndex(SequenceHandler <TValue> handler, int startIndex) { if (startIndex < 0) { return(0); } return(handler.Invert(startIndex)); }
public void CorrectInvertTransform() { var seq = new[] { 0, 1, 2, 3, 4, 5 }; var handler = new SequenceHandler <int>(seq); Range range = new Range(1, 3); Assert.AreEqual(range, handler.Translate(range)); }
public override bool IsMatch(SequenceHandler <TValue> values, int index) { if (index >= values.Count) { return(false); } return(Condition(values, index)); }
public void RemoveSequence(Text text) { if (m_sequenceDic.ContainsKey(text)) { SequenceHandler handler = m_sequenceDic[text]; handler.Stop(); } }
public void ForwardRun() { var seq = new[] {0, 1, 2, 3, 4, 5}; var handler = new SequenceHandler<int>(seq); Assert.AreEqual(handler.Count, seq.Length); for (int i = 0; i < handler.Count; i++) { Assert.AreEqual(seq[i], handler[i]); } }
public void CreateNewSequenceTest(string piece, string part, string page, string voice, int nr) { Sequence test = SequenceHandler.CreateNewSequence(piece, part, page, voice, nr); Assert.IsNotNull(test); Assert.AreEqual(piece, test.Piece); Assert.AreEqual(part, test.PartOfPiece); Assert.AreEqual(page, test.Page); Assert.AreEqual(voice, test.Voice); Assert.AreEqual(nr, test.VoiceNr); }
public void ForwardRun() { var seq = new[] { 0, 1, 2, 3, 4, 5 }; var handler = new SequenceHandler <int>(seq); Assert.AreEqual(handler.Count, seq.Length); for (int i = 0; i < handler.Count; i++) { Assert.AreEqual(seq[i], handler[i]); } }
public void GetMetadataTest() { mei.Panel testPanel = mei.MeiImport.ImportDocument("..\\..\\files\\VatS-13a-TuSolus.xml").Root.Descendants <mei.Panel>().FirstOrDefault(); SequenceHandler.GetMetadata(testPanel, out string part, out string page, out string voice, out int nr); Assert.IsNotNull(part); Assert.IsNotNull(page); Assert.IsNotNull(voice); Assert.IsNotNull(nr); }
public void CorrectRealInvertTransform() { var seq = new[] {0, 1, 2, 3, 4, 5}; var handler = new SequenceHandler<int>(seq) { Reverse = true }; Assert.AreEqual(new Range(2, 3), handler.Translate(new Range(1, 3))); Assert.AreEqual(new Range(0, 0), handler.Translate(new Range(6, 0))); Assert.AreEqual(new Range(3, 3), handler.Translate(new Range(0, 3))); }
public void CorrectRealInvertTransform() { var seq = new[] { 0, 1, 2, 3, 4, 5 }; var handler = new SequenceHandler <int>(seq) { Reverse = true }; Assert.AreEqual(new Range(2, 3), handler.Translate(new Range(1, 3))); Assert.AreEqual(new Range(0, 0), handler.Translate(new Range(6, 0))); Assert.AreEqual(new Range(3, 3), handler.Translate(new Range(0, 3))); }
public override bool IsMatch(SequenceHandler <TValue> values, int index) { index = _isBehind ? index - 1 : index; index = values.Invert(index); if (index < 0) { return(false); } var isMatch = _oregex.IsMatch(values.Collection, index); return(_isNegative ^ isMatch); }
public void InvertRun() { var seq = new[] {0, 1, 2, 3, 4, 5}; var handler = new SequenceHandler<int>(seq) { Reverse = true }; var inverted = seq.Reverse().ToArray(); Assert.AreEqual(handler.Count, seq.Length); for (int i = 0; i < handler.Count; i++) { Assert.AreEqual(inverted[i], handler[i]); } }
public void InvertRun() { var seq = new[] { 0, 1, 2, 3, 4, 5 }; var handler = new SequenceHandler <int>(seq) { Reverse = true }; var inverted = seq.Reverse().ToArray(); Assert.AreEqual(handler.Count, seq.Length); for (int i = 0; i < handler.Count; i++) { Assert.AreEqual(inverted[i], handler[i]); } }
public void AddSequence(Text text, TextSequenceEffect _effect, string str, Action _callBack, float _oneLetterTime, Action _stepCallBack) { Action dele = delegate() { m_sequenceDic.Remove(text); if (_callBack != null) { _callBack(); } }; SequenceHandler handler = new SequenceHandler(text, _effect, str, dele, _oneLetterTime, _stepCallBack); m_sequenceDic.Add(text, handler); }
public void ConvertBrevePositionGap() { Sequence metricSequence = SequenceHandler.CreateNewSequence("kind of test", "Breve position with gaps", "noPage", "Tenor", 3); Panel metricPanel = MeiImport.ImportDocument("..\\..\\files\\tests\\MetricSequenceDamage.xml").Root.Descendants <Panel>().FirstOrDefault(); SequenceHandler.FlattenMeiToSequence(metricPanel, metricSequence); Controller.BuildSequence(metricSequence); SequenceConversion.ConvertBrevePosition(metricSequence); foreach (ObjectInSequence obj in metricSequence.ObjectsInSequence) { if (obj is Model.Rest rest) { IAttCommon corresp = (IAttCommon)metricPanel.Descendants().FirstOrDefault(element => element.GetId() == obj.ID); Fraction expBP = 0; Fraction expPaG = 0; if (corresp.HasN()) { expBP = new Fraction(corresp.GetNValue()); } else if (corresp.HasLabel()) { expPaG = new Fraction(corresp.GetLabelValue()); } //Check if expected value is not null and then compare if (expBP != 0) { Assert.AreEqual(expBP, rest.BrevePosition); } else if (expPaG != 0) { Assert.AreEqual(expPaG, rest.AfterGapPosition); } else { Assert.Fail(); } } } metricPanel = null; metricSequence = null; }
public void FlattenMeiToSequenceTest() { mei.Panel testPanel = mei.MeiImport.ImportDocument("..\\..\\files\\VatS-13a-TuSolus.xml").Root.Descendants <mei.Panel>().FirstOrDefault(); int counter = 0; foreach (Layer layer in testPanel.Descendants <Layer>()) { foreach (MeiElement element in layer.Elements()) { counter++; } } Sequence test = SequenceHandler.CreateNewSequence("kind of mass", "Kyrie", "noPage", "Tenor", 3); SequenceHandler.FlattenMeiToSequence(testPanel, test); Assert.AreEqual(counter, test.MeiObjects.Count()); }
private void ManageSubCaptures(OCaptureTable <TValue> table, SequenceHandler <TValue> handler, FixedSizeStack <FSAState> states, FixedSizeStack <int> piStack) { var stack = _captureStack; stack.Clear(); for (int i = 0; i < piStack.Count; i++) { var s = states[i]; int id = piStack[i] - 1; if (id >= 0) { var cond = _transitionMatrix[s.StateId][id].Condition; if (cond.IsSystemPredicate) { var sys = (SystemPredicateEdge <TValue>)cond; if (sys.IsCapture) { var right = new CaptureEdge { Index = s.CurrentIndex, CaptureId = sys.CaptureId }; if (stack.Count > 0 && stack.Peek().CaptureId == right.CaptureId) { var left = stack.Pop(); table.Add( left.CaptureId, new OCapture <TValue>(handler, new Range(left.Index, right.Index - left.Index))); } else { stack.Push(right); } } } } } }
/// <summary> /// Tries to match pattern starting from startIndex position. /// </summary> /// <param name="values"></param> /// <param name="startIndex"></param> /// <returns></returns> public bool IsMatch(TValue[] values, int startIndex = -1) { Validate(values, startIndex); var handler = new SequenceHandler <TValue>(values) { Reverse = Options.HasFlag(ORegexOptions.ReverseSequence) }; startIndex = GetStartIndex(handler, startIndex); for (int i = startIndex; i <= handler.Count; i++) { Range range; if (_fa.TryRun(handler, i, null, out range)) { bool beginMatched = range.Index == startIndex; bool endMatched = range.RightIndex == handler.Count; if (_fa.ExactBegin && _fa.ExactEnd) { return(beginMatched && endMatched); } if (_fa.ExactBegin) { return(beginMatched); } if (_fa.ExactEnd) { return(endMatched); } return(true); } if (_fa.ExactBegin) { break; } } return(false); }
public void ConvertGapTest() { Sequence gapSequence = SequenceHandler.CreateNewSequence("Test", "Gap", "noPage", "Tenor", 3); Panel gapPanel = MeiImport.ImportDocument("..\\..\\files\\tests\\DamageTest.xml").Root.Descendants <Panel>().FirstOrDefault(); SequenceHandler.FlattenMeiToSequence(gapPanel, gapSequence); Controller.BuildSequence(gapSequence); Assert.IsInstanceOfType(gapSequence.ObjectsInSequence[4], typeof(Model.Gap)); Model.Gap gap1 = (Model.Gap)gapSequence.ObjectsInSequence[4]; Assert.AreEqual(gap1.GapType, GapType.Damage); Assert.IsInstanceOfType(gapSequence.ObjectsInSequence[6], typeof(Model.Gap)); Model.Gap gap2 = (Model.Gap)gapSequence.ObjectsInSequence[6]; Assert.AreEqual(gap2.GapType, GapType.Damage); Assert.IsInstanceOfType(gapSequence.ObjectsInSequence[7], typeof(Model.Gap)); Model.Gap gap3 = (Model.Gap)gapSequence.ObjectsInSequence[7]; Assert.AreEqual(gap3.GapType, GapType.Damage); Assert.IsInstanceOfType(gapSequence.ObjectsInSequence[20], typeof(Model.Gap)); Model.Gap gap4 = (Model.Gap)gapSequence.ObjectsInSequence[20]; Assert.AreEqual(gap4.GapType, GapType.Gap); }
/** * <p>Adds a callback to the end of the callback queue. The callback * will be made at the point in time when the service is ready to * process commands generated by this callback. Callbacks will * always be made in the order they were registered with the * service, so if callback A is added before callback B, then A * will be called before B and consequently any commands added by * A will be processed before any commands added by B.</p> * * <p>Callbacks are one-shot, meaning that a callback needs to be * registered every time the application needs to process commands. * The same callback can only be registered once at a time. The * application is responsible for keeping track of any user input * that occurs while waiting for the callback and convert that * user input into an optimized sequence of NWS commands. The same * callback function can be added again as soon as it has been * called or cancelled.</p> * * <p>NOTE: When the callback is made the supplied RSCommandSequence * instance must be used to add the commands, not RSService.AddCommand().</p> * * @param callback The callback. The callback function will be called with a * single argument which is the RSCommandSequence to which commands should be * added using the AddCommand(command, responseHandler) method. * * @param stateData Optional. The state data to use. If null or omitted * the default state data will be used as specified in the constructor. * * @param delayProcessing Optional. This flag instructs the * service if it should delay processing of the added callback or not. * Defaults to false which is recommended in most cases. */ public void AddCallback(SequenceHandler handler, RSStateData stateData = null, bool delayProcessing = false) { if (handler == null) { return; } if (stateData == null) { stateData = DefaultStateData; } bool found = false; lock (callbackQueue) { foreach (CallbackWrapper wrapper in callbackQueue) { if (wrapper.Callback == handler) { found = true; break; } } if (!found) { callbackQueue.Enqueue(new CallbackWrapper(handler, stateData)); } } if (!delayProcessing) { ProcessCallbacks(); } }
public CallbackWrapper(SequenceHandler callback, RSStateData stateData) { Callback = callback; StateData = stateData; }
// Use this for initialization void Start() { DialogueBoxUI = Singletons.Instance.DialogueUI; CurrentDialoguetextTEXT = Singletons.Instance.DialogueTEXT; sequencescript = Singletons.Instance.SequenceScript; }
public override bool IsMatch(SequenceHandler <TValue> values, int index) { return(true); }
public abstract bool IsMatch(SequenceHandler <TValue> values, int index);
internal OMatch(SequenceHandler <TValue> handler, OCaptureTable <TValue> table, Range range) : base(handler, range) { Captures = table; }
public bool TryRun(SequenceHandler <TValue> values, int startIndex, OCaptureTable <TValue> table, out Range range) { return(FastFsa.TryRun(values, startIndex, null, out range) && CmdFsa.TryRun(values, startIndex, table, out range)); }