/// <summary>
        /// Create the relitive position message that genEntry should generate given relPosInPeriod.
        /// This message should match an entry in the GeneratorMappingManager so that when it is
        /// processed by mssMsgProcessor a Generator message will be returned.
        /// </summary>
        protected MssMsg CreateInputMsgForGenMappingEntry(IGeneratorMappingEntry genEntry,
                                                          double relPosInPeriod)
        {
            MssMsg relPosMsg = new MssMsg();

            if (genEntry.GenConfigInfo.PeriodType == GenPeriodType.BeatSynced ||
                genEntry.GenConfigInfo.PeriodType == GenPeriodType.Bars)
            {
                relPosMsg.Type = MssMsgType.RelBarPeriodPos;
            }
            else if (genEntry.GenConfigInfo.PeriodType == GenPeriodType.Time)
            {
                relPosMsg.Type = MssMsgType.RelTimePeriodPos;
            }
            else
            {
                //Unexpected GenPeriodType
                Debug.Assert(false);
                return(null);
            }

            //Data1RangeBottom and Data2RangeBottom should be the same as the top of the range
            relPosMsg.Data1 = genEntry.InMssMsgRange.Data1RangeBottom;
            relPosMsg.Data2 = genEntry.InMssMsgRange.Data2RangeBottom;
            relPosMsg.Data3 = relPosInPeriod;

            return(relPosMsg);
        }
Пример #2
0
        public void CreateAndAddEntryFromGenInfo_DefaultGenInfo_CorrectlyInitializedInfoClassses()
        {
            GeneratorMappingManager genMgr        = Factory_GeneratorMappingManager_Default();
            GenEntryConfigInfo      genConfigInfo = Factory_GenEntryConfigInfo_Default();

            int newId = genMgr.CreateAndAddEntryFromGenInfo(genConfigInfo);

            IGeneratorMappingEntry genEntry = genMgr.GetCopyOfMappingEntryById(newId).Value;

            //GenHistoryInfo should not be initialized until the first MSS Event is generated
            Assert.IsFalse(genEntry.GenHistoryInfo.Initialized);
            Assert_GenEntryIsInitialized(genEntry);
            Assert.IsNotNull(genEntry.CurveShapeInfo);
        }
Пример #3
0
        public void GetGenMappingEntryById_RetrieveSecondEntry_SuccessfullyRetrieved()
        {
            GeneratorMappingManager       genMgr        = Factory_GeneratorMappingManager_Default();
            Mock <IGeneratorMappingEntry> genEntryMock1 = MockFactory_IGeneratorMappingEntry();
            Mock <IGeneratorMappingEntry> genEntryMock2 = MockFactory_IGeneratorMappingEntry();
            Mock <IGeneratorMappingEntry> genEntryMock3 = MockFactory_IGeneratorMappingEntry();
            int id1 = genMgr.AddMappingEntry(genEntryMock1.Object);
            int id2 = genMgr.AddMappingEntry(genEntryMock2.Object);
            int id3 = genMgr.AddMappingEntry(genEntryMock3.Object);

            IGeneratorMappingEntry retrievedEntry =
                genMgr.GetCopyOfMappingEntryById(genEntryMock2.Object.Id).Value;

            Assert.AreEqual(genEntryMock2.Object.Id, retrievedEntry.Id);
        }
Пример #4
0
        public override bool SetData1RangeFromField(out string errorMsg)
        {
            IGeneratorMappingEntry selectedGenEntry = (IGeneratorMappingEntry)((ComboBox)EntryField1).SelectedItem;

            if (selectedGenEntry == null)
            {
                errorMsg = "You must create a generator before mapping it to something";
                return(false);
            }
            else
            {
                int selectedGenId = selectedGenEntry.Id;
                this.msgRange.Data1RangeBottom = selectedGenId;
                this.msgRange.Data1RangeTop    = selectedGenId;

                errorMsg = "";
                return(true);
            }
        }
Пример #5
0
        public void CreateAndAddEntryFromGenInfo_DefaultGenInfo_CorrectlyInitializedOutRange()
        {
            GeneratorMappingManager genMgr        = Factory_GeneratorMappingManager_Default();
            GenEntryConfigInfo      genConfigInfo = Factory_GenEntryConfigInfo_Default();

            int newId = genMgr.CreateAndAddEntryFromGenInfo(genConfigInfo);

            IReturnStatus <IGeneratorMappingEntry> getCopyRetStatus = genMgr.GetCopyOfMappingEntryById(newId);

            Assert.IsTrue(getCopyRetStatus.IsValid);
            IGeneratorMappingEntry genEntry = getCopyRetStatus.Value;

            Assert.AreEqual(genEntry.Id, genEntry.OutMssMsgRange.Data1RangeBottom);
            Assert.AreEqual(genEntry.Id, genEntry.OutMssMsgRange.Data1RangeTop);
            Assert.AreEqual(MssMsgUtil.UNUSED_MSS_MSG_DATA,
                            genEntry.OutMssMsgRange.Data2RangeBottom);
            Assert.AreEqual(MssMsgUtil.UNUSED_MSS_MSG_DATA,
                            genEntry.OutMssMsgRange.Data2RangeTop);
            Assert.AreEqual(MssMsgType.Generator, genEntry.OutMssMsgRange.MsgType);
        }
        /// <summary>
        /// Each call to GenerateEvent() will generate the next event for genEntry. The
        /// next event's sample time will be set to SAMPLES_PER_GENERATOR_UPDATE more then the
        /// sample time for the event that was previously created for genEntry. Returns null if
        /// no event currently needs to be generated for this generator.
        /// </summary>
        /// <remarks>
        /// Preconditions: genEntry is initilaized and enabled.
        /// </remarks>
        protected MssEvent GenerateEvent(IGeneratorMappingEntry genEntry)
        {
            Debug.Assert(genEntry.GenConfigInfo.Enabled == true);
            Debug.Assert(genEntry.GenHistoryInfo.Initialized == true);

            //Stores the relative position through the period that the next event for genEntry
            //will occur.
            double relPosInPeriod;
            bool   reachedEndOfPeriod;

            if (genEntry.GenConfigInfo.PeriodType == GenPeriodType.BeatSynced)
            {
                //TODO: this code does not work. relPosInPeriod can be negative which screws everything up.
                //It also doesn't take looping into account
                relPosInPeriod = GetRelPosInBeatSyncedPeriod(genEntry.GenConfigInfo,
                                                             genEntry.GenHistoryInfo.SampleTimeAtLastGeneratorUpdate +
                                                             SAMPLES_PER_GENERATOR_UPDATE);
                reachedEndOfPeriod = false;
            }
            else if (genEntry.GenConfigInfo.PeriodType == GenPeriodType.Time ||
                     genEntry.GenConfigInfo.PeriodType == GenPeriodType.Bars)
            {
                int    periodSizeInSamples     = GetPeriodSizeInSamples(genEntry.GenConfigInfo);
                double RelativeperiodIncrement =
                    ((double)SAMPLES_PER_GENERATOR_UPDATE) / ((double)periodSizeInSamples);

                //PercentThroughPeriodOnLastUpdate will be NaN the first time it's generator is updated.
                if (double.IsNaN(genEntry.GenHistoryInfo.PercentThroughPeriodOnLastUpdate) == false)
                {
                    relPosInPeriod = genEntry.GenHistoryInfo.PercentThroughPeriodOnLastUpdate +
                                     RelativeperiodIncrement;
                }
                else
                {
                    relPosInPeriod = 0;
                }
                reachedEndOfPeriod = (relPosInPeriod >= 1);
                //Remove the interger component of relPosInPeriod so that it is between 0 and 1.
                relPosInPeriod = relPosInPeriod % 1;
            }
            else
            {
                //Unexpected period type
                Debug.Assert(false);
                return(null);
            }

            Debug.Assert(relPosInPeriod >= 0);

            //If this generator is not set to loop and it has finished one full period then disable it
            //it and return null so that no more events are sent.
            if (genEntry.GenConfigInfo.Loop == false && reachedEndOfPeriod)
            {
                genEntry.GenConfigInfo.Enabled = false;
                genEntry.GenHistoryInfo.PercentThroughPeriodOnLastUpdate = 0;
                genEntry.GenHistoryInfo.Initialized = false;
                return(null);
            }

            MssMsg relPosMsg = CreateInputMsgForGenMappingEntry(genEntry, relPosInPeriod);
            //Processing the relPosMsg should convert it into a Generator message and apply the
            //equation for this generator to it's data3.
            List <MssMsg> processedMsgList = this.mssMsgProcessor.ProcessMssMsg(relPosMsg).ToList();

            //Sample time for new event.
            long updatedSampleTime = genEntry.GenHistoryInfo.SampleTimeAtLastGeneratorUpdate +
                                     SAMPLES_PER_GENERATOR_UPDATE;

            //Update the generator's history info.
            genEntry.GenHistoryInfo.SampleTimeAtLastGeneratorUpdate  = updatedSampleTime;
            genEntry.GenHistoryInfo.PercentThroughPeriodOnLastUpdate = relPosInPeriod;

            //Count could equal 0 if data 3 has been mapped above 1 or mapped to NaN.
            Debug.Assert(processedMsgList.Count <= 1);

            if (processedMsgList.Count == 0)
            {
                genEntry.GenHistoryInfo.LastValueSent = double.NaN;
                return(null);
            }
            //Don't bother sending the event if it is the same as the last one sent.
            else if (processedMsgList[0].Data3 == genEntry.GenHistoryInfo.LastValueSent)
            {
                return(null);
            }
            else
            {
                //Initialize the fields in the new event and return it.
                MssEvent generatedEvent = new MssEvent();
                generatedEvent.mssMsg     = processedMsgList[0];
                generatedEvent.sampleTime = updatedSampleTime;

                genEntry.GenHistoryInfo.LastValueSent = generatedEvent.mssMsg.Data3;

                return(generatedEvent);
            }
        }
Пример #7
0
 protected void Assert_GenEntryIsInitialized(IGeneratorMappingEntry genEntry)
 {
     Assert.AreNotEqual(GeneratorMappingEntry.UNINITIALIZED_ID, genEntry.Id);
 }
 protected void Assert_GenEntryIsInitialized(IGeneratorMappingEntry genEntry)
 {
     Assert.AreNotEqual(GeneratorMappingEntry.UNINITIALIZED_ID, genEntry.Id);
 }
        /// <summary>
        /// Create the relitive position message that genEntry should generate given relPosInPeriod.
        /// This message should match an entry in the GeneratorMappingManager so that when it is
        /// processed by mssMsgProcessor a Generator message will be returned.
        /// </summary>
        protected MssMsg CreateInputMsgForGenMappingEntry(IGeneratorMappingEntry genEntry, 
            double relPosInPeriod)
        {
            MssMsg relPosMsg = new MssMsg();

            if (genEntry.GenConfigInfo.PeriodType == GenPeriodType.BeatSynced ||
                genEntry.GenConfigInfo.PeriodType == GenPeriodType.Bars)
            {
                relPosMsg.Type = MssMsgType.RelBarPeriodPos;
            }
            else if (genEntry.GenConfigInfo.PeriodType == GenPeriodType.Time)
            {
                relPosMsg.Type = MssMsgType.RelTimePeriodPos;
            }
            else
            {
                //Unexpected GenPeriodType
                Debug.Assert(false);
                return null;
            }

            //Data1RangeBottom and Data2RangeBottom should be the same as the top of the range
            relPosMsg.Data1 = genEntry.InMssMsgRange.Data1RangeBottom;
            relPosMsg.Data2 = genEntry.InMssMsgRange.Data2RangeBottom;
            relPosMsg.Data3 = relPosInPeriod;

            return relPosMsg;
        }
        /// <summary>
        /// Each call to GenerateEvent() will generate the next event for genEntry. The 
        /// next event's sample time will be set to SAMPLES_PER_GENERATOR_UPDATE more then the 
        /// sample time for the event that was previously created for genEntry. Returns null if 
        /// no event currently needs to be generated for this generator.
        /// </summary>
        /// <remarks>
        /// Preconditions: genEntry is initilaized and enabled.
        /// </remarks>
        protected MssEvent GenerateEvent(IGeneratorMappingEntry genEntry)
        {
            Debug.Assert(genEntry.GenConfigInfo.Enabled == true);
            Debug.Assert(genEntry.GenHistoryInfo.Initialized == true);

            //Stores the relative position through the period that the next event for genEntry
            //will occur.
            double relPosInPeriod;
            bool reachedEndOfPeriod;
            if (genEntry.GenConfigInfo.PeriodType == GenPeriodType.BeatSynced)
            {
                //TODO: this code does not work. relPosInPeriod can be negative which screws everything up.
                //It also doesn't take looping into account
                relPosInPeriod = GetRelPosInBeatSyncedPeriod(genEntry.GenConfigInfo,
                        genEntry.GenHistoryInfo.SampleTimeAtLastGeneratorUpdate +
                        SAMPLES_PER_GENERATOR_UPDATE);
                reachedEndOfPeriod = false;
            }
            else if (genEntry.GenConfigInfo.PeriodType == GenPeriodType.Time ||
                     genEntry.GenConfigInfo.PeriodType == GenPeriodType.Bars)
            {
                int periodSizeInSamples = GetPeriodSizeInSamples(genEntry.GenConfigInfo);
                double RelativeperiodIncrement =
                        ((double)SAMPLES_PER_GENERATOR_UPDATE) / ((double)periodSizeInSamples);

                //PercentThroughPeriodOnLastUpdate will be NaN the first time it's generator is updated.
                if (double.IsNaN(genEntry.GenHistoryInfo.PercentThroughPeriodOnLastUpdate) == false)
                {
                    relPosInPeriod = genEntry.GenHistoryInfo.PercentThroughPeriodOnLastUpdate +
                                            RelativeperiodIncrement;
                }
                else {
                    relPosInPeriod = 0;
                }
                reachedEndOfPeriod = (relPosInPeriod >= 1);
                //Remove the interger component of relPosInPeriod so that it is between 0 and 1.
                relPosInPeriod = relPosInPeriod % 1;
            }
            else
            {
                //Unexpected period type
                Debug.Assert(false);
                return null;
            }

            Debug.Assert(relPosInPeriod >= 0);

            //If this generator is not set to loop and it has finished one full period then disable it
            //it and return null so that no more events are sent.
            if (genEntry.GenConfigInfo.Loop == false && reachedEndOfPeriod)
            {
                genEntry.GenConfigInfo.Enabled = false;
                genEntry.GenHistoryInfo.PercentThroughPeriodOnLastUpdate = 0;
                genEntry.GenHistoryInfo.Initialized = false;
                return null;
            }

            MssMsg relPosMsg = CreateInputMsgForGenMappingEntry(genEntry, relPosInPeriod);
            //Processing the relPosMsg should convert it into a Generator message and apply the
            //equation for this generator to it's data3.
            List<MssMsg> processedMsgList = this.mssMsgProcessor.ProcessMssMsg(relPosMsg).ToList();

            //Sample time for new event.
            long updatedSampleTime = genEntry.GenHistoryInfo.SampleTimeAtLastGeneratorUpdate +
                                      SAMPLES_PER_GENERATOR_UPDATE;

            //Update the generator's history info.
            genEntry.GenHistoryInfo.SampleTimeAtLastGeneratorUpdate = updatedSampleTime;
            genEntry.GenHistoryInfo.PercentThroughPeriodOnLastUpdate = relPosInPeriod;

            //Count could equal 0 if data 3 has been mapped above 1 or mapped to NaN.
            Debug.Assert(processedMsgList.Count <= 1);

            if (processedMsgList.Count == 0) {
                genEntry.GenHistoryInfo.LastValueSent = double.NaN;
                return null;
            }
            //Don't bother sending the event if it is the same as the last one sent.
            else if (processedMsgList[0].Data3 == genEntry.GenHistoryInfo.LastValueSent)
            {
                return null;
            }
            else
            {
                //Initialize the fields in the new event and return it.
                MssEvent generatedEvent = new MssEvent();
                generatedEvent.mssMsg = processedMsgList[0];
                generatedEvent.sampleTime = updatedSampleTime;

                genEntry.GenHistoryInfo.LastValueSent = generatedEvent.mssMsg.Data3;

                return generatedEvent;
            }
        }