/// <summary> /// Queries the MappingEntry objects in the MappingManager and returns each one that matches InMssMsgRange /// <paramref name="inputMsg"/>. For example, if the MappingManager contained a MappingEntry whose /// InMssMsgRange described a range of NoteOn MIDI messages, then that MappingEntry would be returned if /// <paramref name="inputMsg"/> was a NoteOn message that fell into InMssMsgRange's range. /// /// If multiple MappingEntry objects match <paramref name="inputMsg"/> and one or more has OverrideDuplicates set /// to true then the one with the lowest index will be returned. /// </summary> /// <param name="inputMsg">MssMsg to query the MappingManager with.</param> /// <returns>An enumeration of MappingEntry objects that match <paramref name="inputMsg"/>.</returns> public override IEnumerable <IMappingEntry> GetCopiesOfMappingEntriesForMsg(MssMsg inputMsg) { lock (MssComponentHub.criticalSectioinLock) { var associatedEntiresQuery = from entry in mappingEntryList where entry.InMssMsgRange.MsgIsInRange(inputMsg) select entry; //deal with input overrides var inputOverrideEntriesQuery = from entry in associatedEntiresQuery where entry.OverrideDuplicates == true select entry; var inputOverrideEntriesList = inputOverrideEntriesQuery.ToList(); if (inputOverrideEntriesList.Count > 0) { associatedEntiresQuery = from entry in associatedEntiresQuery where entry == inputOverrideEntriesList[0] select entry; } //Select() will return a querry which references the original list, so if mappingEntryList //was changed then the querry would also be changed. This is why there is a call to //ToList() This creates a seperate list that is not linked to mappingEntryList. return(associatedEntiresQuery.Select(entry => (IMappingEntry)entry.Clone()).ToList()); } }
/// <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); }
public void GetAssociatedEntries_MsgMatchesFirstTwoEntriesAndOverrideDuplicatesIsTrueForTheThirdEntry_FirstTwoEntriesAreReturned() { MappingManager mappingMgr = Factory_MappingManager_Default(); IMappingEntry mappingEntry1 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 1, 16, 0, 127); IMappingEntry mappingEntry2 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 1, 8, 0, 64); IMappingEntry mappingEntry3 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 7, 16, 60, 127); mappingEntry3.OverrideDuplicates = true; int id1 = mappingMgr.AddMappingEntry(mappingEntry1); int id2 = mappingMgr.AddMappingEntry(mappingEntry2); int id3 = mappingMgr.AddMappingEntry(mappingEntry3); MssMsg msg = Factory_MssMsg_InitializedValues( DEFAULT_MSG_TYPE, /*matches all*/ 7, /*matches all*/ 10, /*only matches entries 1 and 2*/ 100 /*doesn't need to match anything*/); var matchingEntries = mappingMgr.GetCopiesOfMappingEntriesForMsg(msg); Assert.IsTrue(matchingEntries.Any(entry => entry.Id == id1)); Assert.IsTrue(matchingEntries.Any(entry => entry.Id == id2)); Assert.IsFalse(matchingEntries.Any(entry => entry.Id == id3)); }
protected void TestCase_GetAssociatedEntries_ManagerWithThreeOverlappingEntriesThatMatchAMsg( bool Entry1Override, bool Entry2Override, bool Entry3Override, bool Entry1Matches, bool Entry2Matches, bool Entry3Matches) { MappingManager mappingMgr = Factory_MappingManager_Default(); IMappingEntry mappingEntry1 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 1, 16, 0, 127); mappingEntry1.OverrideDuplicates = Entry1Override; IMappingEntry mappingEntry2 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 4, 5, 10, 20); mappingEntry2.OverrideDuplicates = Entry2Override; IMappingEntry mappingEntry3 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 5, 5, 15, 15); mappingEntry3.OverrideDuplicates = Entry3Override; int id1 = mappingMgr.AddMappingEntry(mappingEntry1); int id2 = mappingMgr.AddMappingEntry(mappingEntry2); int id3 = mappingMgr.AddMappingEntry(mappingEntry3); MssMsg msg = Factory_MssMsg_InitializedValues( DEFAULT_MSG_TYPE, /*matches all entries*/ 5, /*matches all*/ 15, /*matches all*/ 100 /*doesn't need to match anything*/); var matchingEntries = mappingMgr.GetCopiesOfMappingEntriesForMsg(msg); Assert.IsTrue(matchingEntries.Any(entry => entry.Id == id1) == Entry1Matches); Assert.IsTrue(matchingEntries.Any(entry => entry.Id == id2) == Entry2Matches); Assert.IsTrue(matchingEntries.Any(entry => entry.Id == id3) == Entry3Matches); }
public override void ApplyPreMappingQueryProcessing(MssMsg msgToProcess) { if (msgToProcess.Data3 == 0) { msgToProcess.Type = MssMsgType.NoteOff; } }
public void GetAssociatedEntries_NonGeneratorMessage_NoEntriesRetrieved() { GeneratorMappingManager genMgr = Factory_GeneratorMappingManager_Default(); MssMsg inputMsg = Factory_MssMsg_CustomTypeAndData1(MssMsgType.CC, 0); IEnumerable <IMappingEntry> retrievedEntries = genMgr.GetCopiesOfMappingEntriesForMsg(inputMsg); Assert.AreEqual(0, retrievedEntries.Count()); }
public override void ApplyPostProcessing(MssMsg preProcessedMsg, MssMsg msgToProcess) { if (preProcessedMsg.Type == MssMsgType.NoteOff || msgToProcess.Data3 == 0) { msgToProcess.Type = MssMsgType.NoteOff; } else { msgToProcess.Type = MssMsgType.NoteOn; } }
public void ProcessMssMsg_NoMappings_MsgIsUnaffected() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.NoteOn, 1, 64, 100); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); desiredReturnedMsgList.Add((MssMsg)inputMsg.Clone()); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, false); }
/// <summary> /// Tests the ProcessMssMsg() method. /// </summary> /// <param name="inputMsg">The message to be precessed</param> /// <param name="matchingEntries"> /// Mapping entries where <paramref name="inputMsg"/> is in the input message range /// </param> /// <param name="desiredReturnedMsgList"> List of that should be returned by ProcessMssMsg() </param> /// <param name="doubleData3"> /// Simulates the equation "x*2" in each mapping if true. Simulates the equation "x" in each mapping if /// false. /// </param> protected void Test_ProcessMssMsg(MssMsg inputMsg, List <IMappingEntry> matchingEntries, List <MssMsg> desiredReturnedMsgList, bool doubleData3) { int inputMultiple; if (doubleData3 == true) { inputMultiple = 2; } else { inputMultiple = 1; } //Setup the MssEvaluator that msgProcessor will use so that it always just returns the input var mssEvanuatorMock = new Mock <IEvaluator>(); mssEvanuatorMock.Setup(evaluator => evaluator.Evaluate(It.IsAny <EvaluationCurveInput>())) .Returns((EvaluationCurveInput input) => new ReturnStatus <double>(input.RelData3 * inputMultiple, true)); IocMgr.Kernel.Rebind <IEvaluator>().ToConstant(mssEvanuatorMock.Object); MssMsgProcessor msgProcessor = new MssMsgProcessor(); var mapMgrMock = new Mock <IBaseGraphableMappingManager>(); mapMgrMock.Setup(mapMgr => mapMgr.GetCopiesOfMappingEntriesForMsg(inputMsg)).Returns(matchingEntries); var mssParameterViewerMock = new Mock <IMssParameterViewer>(); msgProcessor.Init(mapMgrMock.Object, mssParameterViewerMock.Object); //Ensure returnedMsgList and desiredReturnedMsgList contain the same elements. foreach (MssMsg returnedMsg in msgProcessor.ProcessMssMsg(inputMsg)) { int foundIndex = desiredReturnedMsgList.FindIndex( desiredReturnedMsg => desiredReturnedMsg.Equals(returnedMsg)); if (foundIndex == -1) { Assert.Fail("The desired MssMsgs were not returned."); return; } else { //Ensures that each message is desiredReturnedMsgs is only matched to a //message in returnedMsgs once. desiredReturnedMsgList.RemoveAt(foundIndex); } } Assert.IsTrue(desiredReturnedMsgList.Count == 0, "Some of the desired MssMSgs were not returned"); }
public MappingDlg() { InitializeComponent(); //Add the types that are valid for input to the input combo. foreach(MssMsgType msgType in MssMsgRangeEntryMetadata.VALID_INPUT_TYPES) { this.inTypeCombo.Items.Add(MssMsg.MssMsgTypeNames[(int)msgType]); } this.learnMode = LearnMode.Off; this.lastMsgReceived = null; }
public MappingDlg() { InitializeComponent(); //Add the types that are valid for input to the input combo. foreach (MssMsgType msgType in MssMsgRangeEntryMetadata.VALID_INPUT_TYPES) { this.inTypeCombo.Items.Add(MssMsg.MssMsgTypeNames[(int)msgType]); } this.learnMode = LearnMode.Off; this.lastMsgReceived = null; }
public void Init(MssMsg mssMsg, List <MssParamInfo> variableParamInfoList, IMappingEntry mappingEntry) { IStaticMssMsgInfo inMsgInfo = Factory_StaticMssMsgInfo.Create(mssMsg.Type); double relativeData1 = (double)mssMsg.Data1 / (double)(inMsgInfo.MaxData1Value - inMsgInfo.MinData1Value); double relativeData2 = (double)mssMsg.Data2 / (double)(inMsgInfo.MaxData2Value - inMsgInfo.MinData2Value); double relativeData3 = (double)mssMsg.Data3 / (double)(inMsgInfo.MaxData3Value - inMsgInfo.MinData3Value); this.Init(relativeData1, relativeData2, relativeData3, variableParamInfoList, mappingEntry); }
protected List <MssMsg> ProcessMssMsg_CopyData3(MssMsg mssMsg) { MssMsg msg = new MssMsg(); msg.Type = MssMsgType.Generator; msg.Data1 = 0; msg.Data2 = MssMsgUtil.UNUSED_MSS_MSG_DATA; msg.Data3 = mssMsg.Data3; List <MssMsg> retList = new List <MssMsg>(); retList.Add(msg); return(retList); }
public void ProcessMssMsg_MapsOutsideOfRange_NoMsgsAreReturned() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.NoteOn, 1, 10, 64); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); IMappingEntry mapsNoteOffToSameMsg = Factory_IMappingEntry( MssMsgType.NoteOn, 1, 1, 10, 10, MssMsgType.NoteOn, 1, 1, 10, 10); matchingEntries.Add(mapsNoteOffToSameMsg); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, true); }
private void outLearnBtn_Click(object sender, EventArgs e) { if (this.learnMode == LearnMode.Out) { this.learnMode = LearnMode.Off; this.lastMsgReceived = null; this.outLearnBtn.Text = "Learn"; } else { this.learnMode = LearnMode.Out; this.outLearnBtn.Text = "Stop Learn"; } this.inLearnBtn.Text = "Learn"; }
public void GetAssociatedEntries_MsgMatchesOneEntry_TheAssociatedEntryIsReturned() { MappingManager mappingMgr = Factory_MappingManager_Default(); IMappingEntry mappingEntry = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 1, 3, 0, 10); int newId = mappingMgr.AddMappingEntry(mappingEntry); MssMsg msg = Factory_MssMsg_InitializedValues( DEFAULT_MSG_TYPE, /*same as type in manager*/ 2, /*between 1 and 3*/ 5, /*between 0 and 10*/ 100 /*doesn't need to match anything*/); var matchingEntries = mappingMgr.GetCopiesOfMappingEntriesForMsg(msg); Assert.IsTrue(matchingEntries.Any(entry => entry.Id == newId)); }
public void ProcessMssMsg_MapsTypeData1AndData2_MsgIsProperlyMapped() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.NoteOff, 1, 64, 0); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); IMappingEntry mappingEntry = Factory_IMappingEntry( MssMsgType.NoteOff, 1, 1, 64, 64, MssMsgType.CC, 2, 2, 100, 100); matchingEntries.Add(mappingEntry); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); desiredReturnedMsgList.Add(Factory_MssMsg(MssMsgType.CC, 2, 100, 0)); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, false); }
public void ProcessMssMsg_MapsToSameMsg_MsgIsUnaffected() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.NoteOff, 1, 64, 0); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); IMappingEntry mapsNoteOffToSameMsg = Factory_IMappingEntry( MssMsgType.NoteOff, 1, 1, 64, 64, MssMsgType.NoteOff, 1, 1, 64, 64); matchingEntries.Add(mapsNoteOffToSameMsg); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); desiredReturnedMsgList.Add((MssMsg)inputMsg.Clone()); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, false); }
public void ProcessMssMsg_MapsCCToPitchbend_MsgIsProperlyMapped() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.CC, 1, 10, 127); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); IMappingEntry mappingEntry = Factory_IMappingEntry( MssMsgType.CC, 1, 1, 10, 10, MssMsgType.PitchBend, 1, 1, 10, 10); matchingEntries.Add(mappingEntry); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); desiredReturnedMsgList.Add(Factory_MssMsg(MssMsgType.PitchBend, 1, 10, 16383)); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, false); }
public void ProcessMssMsg_MapsToRangeOfDifferentSize_MsgIsProperlyMapped() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.NoteOn, 2, 10, 100); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); IMappingEntry mappingEntry = Factory_IMappingEntry( MssMsgType.NoteOn, 1, 3, 9, 10, MssMsgType.NoteOn, 1, 5, 0, 127); matchingEntries.Add(mappingEntry); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); desiredReturnedMsgList.Add(Factory_MssMsg(MssMsgType.NoteOn, 3, 127, 100)); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, false); }
public void ProcessMssMsg_MapsToRangeOfSameSize_MsgIsProperlyMapped() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.PolyAftertouch, 16, 64, 100); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); IMappingEntry mappingEntry = Factory_IMappingEntry( MssMsgType.PolyAftertouch, 15, 16, 60, 70, MssMsgType.PolyAftertouch, 1, 2, 50, 60); matchingEntries.Add(mappingEntry); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); desiredReturnedMsgList.Add(Factory_MssMsg(MssMsgType.PolyAftertouch, 2, 54, 100)); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, false); }
public void GetAssociatedEntries_MatchesAnEntry_CorrectEntryRetrieved() { GeneratorMappingManager genMgr = Factory_GeneratorMappingManager_Default(); Mock <IGeneratorMappingEntry> genEntryMock1 = MockFactory_IGeneratorMappingEntry(); Mock <IGeneratorMappingEntry> genEntryMock2 = MockFactory_IGeneratorMappingEntry(); Mock <IGeneratorMappingEntry> genEntryMock3 = MockFactory_IGeneratorMappingEntry(); genMgr.AddMappingEntry(genEntryMock1.Object); genMgr.AddMappingEntry(genEntryMock2.Object); genMgr.AddMappingEntry(genEntryMock3.Object); MssMsg inputMsg = Factory_MssMsg_CustomTypeAndData1( MssMsgType.RelTimePeriodPos, genEntryMock2.Object.Id); IEnumerable <IMappingEntry> retrievedEntries = genMgr.GetCopiesOfMappingEntriesForMsg(inputMsg); Assert.AreEqual(1, retrievedEntries.Count()); Assert.AreEqual(genEntryMock2.Object.Id, retrievedEntries.First().Id); }
public void GetAssociatedEntries_MsgOnlyMatchesPartsOfEntriesInMgr_TheEnumerationReturnedIsEmpty() { MappingManager mappingMgr = Factory_MappingManager_Default(); IMappingEntry mappingEntry1 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 1, 1, 3, 127); IMappingEntry mappingEntry2 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(DEFAULT_MSG_TYPE, 2, 16, 2, 2); IMappingEntry mappingEntry3 = Factory_IMappingEntry_MapsIdenticalMidiMsgRanges(SECONDARY_MSG_TYPE, 1, 1, 2, 2); mappingMgr.AddMappingEntry(mappingEntry1); mappingMgr.AddMappingEntry(mappingEntry2); mappingMgr.AddMappingEntry(mappingEntry3); MssMsg msg = Factory_MssMsg_InitializedValues( DEFAULT_MSG_TYPE, /*matches entries 1 and 2*/ 1, /*matches entries 1 and 3*/ 2, /*matches entries 2 and 3*/ 100 /*doesn't need to match anything*/); var matchingEntries = mappingMgr.GetCopiesOfMappingEntriesForMsg(msg); Assert.IsEmpty(matchingEntries.ToList()); }
public void ProcessMssMsg_MultipleMappings_MsgIsProperlyMapped() { MssMsg inputMsg = Factory_MssMsg(MssMsgType.NoteOn, 1, 64, 100); List <IMappingEntry> matchingEntries = new List <IMappingEntry>(); IMappingEntry mappingEntry = Factory_IMappingEntry( MssMsgType.NoteOn, 1, 1, 64, 64, MssMsgType.NoteOn, 2, 2, 65, 65); matchingEntries.Add(mappingEntry); IMappingEntry mappingEntry2 = Factory_IMappingEntry( MssMsgType.NoteOn, 1, 1, 64, 64, MssMsgType.CC, 3, 3, 66, 66); matchingEntries.Add(mappingEntry2); List <MssMsg> desiredReturnedMsgList = new List <MssMsg>(); desiredReturnedMsgList.Add(Factory_MssMsg(MssMsgType.NoteOn, 2, 65, 100)); desiredReturnedMsgList.Add(Factory_MssMsg(MssMsgType.CC, 3, 66, 100)); Test_ProcessMssMsg(inputMsg, matchingEntries, desiredReturnedMsgList, false); }
public virtual void ApplyPostProcessing(MssMsg preProcessedMsg, MssMsg msgToProcess) { }
/// <summary> /// Event handler for MssEvents coming /// </summary> /// <param name="dryMssEvent"></param> protected void dryMssEventOutputPort_DryMssEventRecieved(MssEvent dryMssEvent) { if (this.InvokeRequired) { this.BeginInvoke(new Action<MssEvent>(dryMssEventOutputPort_DryMssEventRecieved), dryMssEvent); return; } MssMsg curMsg = dryMssEvent.mssMsg; if (this.learnMode != LearnMode.Off && curMsg.Type != MssMsgType.NoteOff && curMsg.Type != MssMsgType.Generator) { if (curMsg.Type == MssMsgType.NoteOn) { curMsg.Type = MssMsgType.Note; } ComboBox curTypeCombo = null; if (this.learnMode == LearnMode.In) { curTypeCombo = this.inTypeCombo; } else if (this.learnMode == LearnMode.Out) { curTypeCombo = this.outTypeCombo; } else { //Unknown learn mode Debug.Assert(false); return; } string newTypeName = MssMsg.MssMsgTypeNames[(int)curMsg.Type]; //Ensure that the type of the message recieved can be assigned to the current type combo box. if (curTypeCombo.FindStringExact(newTypeName) != -1) { //This will trigger the corresponding MsgMetadata to be regenerated. curTypeCombo.Text = newTypeName; } else { return; } MssMsgRangeEntryMetadata curEntryMetadata; if(this.learnMode == LearnMode.In) { curEntryMetadata = this.inMsgMetadata; } else //(this.learnMode == LearnMode.Out) { curEntryMetadata = this.outMsgMetadata; } IMssMsgRange learnedRange = new MssMsgRange(); learnedRange.MsgType = curMsg.Type; //If the type is the same as the last message and either data1 or data2 has changed //then treat this as a range of notes. if (this.lastMsgReceived != null && this.lastMsgReceived.Type == curMsg.Type && (this.lastMsgReceived.Data1 != curMsg.Data1 || this.lastMsgReceived.Data2 != curMsg.Data2)) { learnedRange.Data1RangeBottom = Math.Min(this.lastMsgReceived.Data1, curMsg.Data1); learnedRange.Data1RangeTop = Math.Max(this.lastMsgReceived.Data1, curMsg.Data1); learnedRange.Data2RangeBottom = Math.Min(this.lastMsgReceived.Data2, curMsg.Data2); learnedRange.Data2RangeTop = Math.Max(this.lastMsgReceived.Data2, curMsg.Data2); } else { learnedRange.Data1RangeBottom = curMsg.Data1; learnedRange.Data1RangeTop = curMsg.Data1; learnedRange.Data2RangeBottom = curMsg.Data2; learnedRange.Data2RangeTop = curMsg.Data2; } curEntryMetadata.UseExistingMsgRange(learnedRange); if (this.learnMode == LearnMode.In) { inMsgMetadata.ValidateEntryField1(); inMsgMetadata.ValidateEntryField2(); } else //(this.learnMode == LearnMode.Out) { outMsgMetadata.ValidateEntryField1(); outMsgMetadata.ValidateEntryField2(); } this.lastMsgReceived = curMsg; } }
public virtual void ApplyPreProcessing(MssMsg msgToProcess) { }
public void Init(MssMsg mssMsg, List<MssParamInfo> variableParamInfoList, IMappingEntry mappingEntry) { IStaticMssMsgInfo inMsgInfo = Factory_StaticMssMsgInfo.Create(mssMsg.Type); double relativeData1 = (double)mssMsg.Data1 / (double)(inMsgInfo.MaxData1Value - inMsgInfo.MinData1Value); double relativeData2 = (double)mssMsg.Data2 / (double)(inMsgInfo.MaxData2Value - inMsgInfo.MinData2Value); double relativeData3 = (double)mssMsg.Data3 / (double)(inMsgInfo.MaxData3Value - inMsgInfo.MinData3Value); this.Init(relativeData1, relativeData2, relativeData3, variableParamInfoList, mappingEntry); }
/// <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; }
public void ApplyPostProcessing(MssMsg preProcessedMsg, MssMsg msgToProcess) { staticInfo.ApplyPostProcessing(preProcessedMsg, msgToProcess); }
public void ApplyPreProcessing(MssMsg msgToProcess) { staticInfo.ApplyPreProcessing(msgToProcess); }
/// <summary> /// Applies any processing to msgToProcess that is nessessary before the associated mapping /// entries are querried. By default don't apply any pre-mapping querry processing. /// </summary> public virtual void ApplyPreMappingQueryProcessing(MssMsg msgToProcess) { }
/// <summary> /// Event handler for MssEvents coming /// </summary> /// <param name="dryMssEvent"></param> protected void dryMssEventOutputPort_DryMssEventRecieved(MssEvent dryMssEvent) { if (this.InvokeRequired) { this.BeginInvoke(new Action <MssEvent>(dryMssEventOutputPort_DryMssEventRecieved), dryMssEvent); return; } MssMsg curMsg = dryMssEvent.mssMsg; if (this.learnMode != LearnMode.Off && curMsg.Type != MssMsgType.NoteOff && curMsg.Type != MssMsgType.Generator) { if (curMsg.Type == MssMsgType.NoteOn) { curMsg.Type = MssMsgType.Note; } ComboBox curTypeCombo = null; if (this.learnMode == LearnMode.In) { curTypeCombo = this.inTypeCombo; } else if (this.learnMode == LearnMode.Out) { curTypeCombo = this.outTypeCombo; } else { //Unknown learn mode Debug.Assert(false); return; } string newTypeName = MssMsg.MssMsgTypeNames[(int)curMsg.Type]; //Ensure that the type of the message recieved can be assigned to the current type combo box. if (curTypeCombo.FindStringExact(newTypeName) != -1) { //This will trigger the corresponding MsgMetadata to be regenerated. curTypeCombo.Text = newTypeName; } else { return; } MssMsgRangeEntryMetadata curEntryMetadata; if (this.learnMode == LearnMode.In) { curEntryMetadata = this.inMsgMetadata; } else //(this.learnMode == LearnMode.Out) { curEntryMetadata = this.outMsgMetadata; } IMssMsgRange learnedRange = new MssMsgRange(); learnedRange.MsgType = curMsg.Type; //If the type is the same as the last message and either data1 or data2 has changed //then treat this as a range of notes. if (this.lastMsgReceived != null && this.lastMsgReceived.Type == curMsg.Type && (this.lastMsgReceived.Data1 != curMsg.Data1 || this.lastMsgReceived.Data2 != curMsg.Data2)) { learnedRange.Data1RangeBottom = Math.Min(this.lastMsgReceived.Data1, curMsg.Data1); learnedRange.Data1RangeTop = Math.Max(this.lastMsgReceived.Data1, curMsg.Data1); learnedRange.Data2RangeBottom = Math.Min(this.lastMsgReceived.Data2, curMsg.Data2); learnedRange.Data2RangeTop = Math.Max(this.lastMsgReceived.Data2, curMsg.Data2); } else { learnedRange.Data1RangeBottom = curMsg.Data1; learnedRange.Data1RangeTop = curMsg.Data1; learnedRange.Data2RangeBottom = curMsg.Data2; learnedRange.Data2RangeTop = curMsg.Data2; } curEntryMetadata.UseExistingMsgRange(learnedRange); if (this.learnMode == LearnMode.In) { inMsgMetadata.ValidateEntryField1(); inMsgMetadata.ValidateEntryField2(); } else //(this.learnMode == LearnMode.Out) { outMsgMetadata.ValidateEntryField1(); outMsgMetadata.ValidateEntryField2(); } this.lastMsgReceived = curMsg; } }
/// <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); } }