Ejemplo n.º 1
0
        /// <summary>
        /// Applies the current trigger and aligns all sample sequences accordingly.
        /// </summary>
        /// <param name="externalSampleSequenceProviders">
        /// The functions that provide the raw signal sample sequences, one function per channel.
        /// </param>
        /// <returns>
        /// Functions that provide the signal sample sequences after the trigger has been applied,
        /// one function per channel.
        /// </returns>
        protected IEnumerable <Func <SampleSequence> > ApplyTriggerAndAlignSampleSequences(
            IEnumerable <Func <SampleSequence> > externalSampleSequenceProviders)
        {
            double triggerX = 0;

            return(externalSampleSequenceProviders.Select((provider, index) =>
            {
                return new Func <SampleSequence>(() =>
                {
                    var sampleSequence = provider();

                    if (index == TriggerChannelIndex)
                    // We are currently providing the sample sequence of the trigger channel,
                    // determine the trigger reference time.
                    {
                        Trigger.Arm();
                        var taken = sampleSequence.Values.TakeWhile(element => !Trigger.Check(element));
                        var numberOfValuesTakenBeforeTrigger = taken.Count();

                        // TODO: Interpolate considering values before and after trigger.
                        triggerX =
                            Trigger.State == TriggerState.Triggered ?
                            numberOfValuesTakenBeforeTrigger * sampleSequence.SampleInterval
                            : 0;
                    }

                    // Set the channel's reference point according to where triggering has happened.
                    sampleSequence.ReferenceX = triggerX;

                    return sampleSequence;
                });
            }));
        }