/// <summary> /// Returns the size of the period for genConfigInfo in samples /// </summary> /// <remarks> /// Preconditions: sample rate must be initialized in hostInfoOutputPort. If /// genConfigInfo is for a beat synced generator then the time signature must also be /// initialized in hostInfoOutputPort. /// </remarks> protected int GetPeriodSizeInSamples(GenEntryConfigInfo genConfigInfo) { if (genConfigInfo.PeriodType == GenPeriodType.BeatSynced || genConfigInfo.PeriodType == GenPeriodType.Bars) { Debug.Assert(hostInfoOutputPort.TimeSignatureIsInitialized == true); Debug.Assert(hostInfoOutputPort.SampleRateIsInitialized == true); double periodSizeInBars = genConfigInfo.GetSizeOfBarsPeriod(hostInfoOutputPort.TimeSignatureNumerator, hostInfoOutputPort.TimeSignatureDenominator); double timeSig = (double)hostInfoOutputPort.TimeSignatureNumerator / hostInfoOutputPort.TimeSignatureDenominator; double beatsPerBar = timeSig / (1 / 4d); double secondsPerBar = (beatsPerBar / hostInfoOutputPort.Tempo) * 60; return((int)System.Math.Round( secondsPerBar * periodSizeInBars * hostInfoOutputPort.SampleRate)); } else if (genConfigInfo.PeriodType == GenPeriodType.Time) { Debug.Assert(hostInfoOutputPort.SampleRateIsInitialized == true); return((int)System.Math.Round( (genConfigInfo.TimePeriodInMs / 1000d) * hostInfoOutputPort.SampleRate)); } else { //Unexpected GenPeriodType Debug.Assert(false); return(1000); } }
public void InitAllMembers(IMssMsgRange inMsgRange, IMssMsgRange outMsgRange, bool overrideDuplicates, CurveShapeInfo curveShapeInfo, GenEntryConfigInfo generatorConfigInfo) { this.GenConfigInfo = generatorConfigInfo; InitAllMembers(inMsgRange, outMsgRange, overrideDuplicates, curveShapeInfo); }
//Initialized the entry fields on the dialog. This method must be called. public void Init(GenEntryConfigInfo genInfo) { this.genNameTextBox.Text = genInfo.Name; this.periodTypeCombo.Text = GenEntryConfigInfo.GenPeriodTypeNames[(int)genInfo.PeriodType]; this.periodTextBox.Text = genInfo.TimePeriodInMs.ToString(); this.periodCombo.Text = GenEntryConfigInfo.GenBarsPeriodNames[(int)genInfo.BarsPeriod]; this.loopCheckBox.Checked = genInfo.Loop; this.enabledCheckBox.Checked = genInfo.Enabled; }
/// <summary> /// populate mappingEntry's members based on the information in genInfo /// </summary> protected void InitializeEntryFromGenInfo(GenEntryConfigInfo genInfo, int id, IGeneratorMappingEntry mappingEntry) { //Sets mappingEntry.Id mappingEntry.Id = id; //Sets mappingEntry.GeneratorInfo mappingEntry.GenConfigInfo = genInfo; //Sets mappingEntry.inMsgRange IMssMsgRange inMsgRange = new MssMsgRange(); switch (genInfo.PeriodType) { case GenPeriodType.Bars: case GenPeriodType.BeatSynced: inMsgRange.InitPublicMembers(MssMsgType.RelBarPeriodPos, id, MssMsgUtil.UNUSED_MSS_MSG_DATA); break; case GenPeriodType.Time: inMsgRange.InitPublicMembers(MssMsgType.RelTimePeriodPos, id, MssMsgUtil.UNUSED_MSS_MSG_DATA); break; default: //Unknown period type Debug.Assert(false); break; } mappingEntry.InMssMsgRange = inMsgRange; //Sets mappingEntry.outMsgRange IMssMsgRange outMsgRange = new MssMsgRange(); outMsgRange.InitPublicMembers(MssMsgType.Generator, id, MssMsgUtil.UNUSED_MSS_MSG_DATA); mappingEntry.OutMssMsgRange = outMsgRange; //Sets mappingEntry.OverrideDuplicates mappingEntry.OverrideDuplicates = false; //Sets mappingEntry.CurveShapeInfo. This function is also used to reinitialize //mappingEntry so sometimes CurveShapeInfo will already be initialized. if (mappingEntry.CurveShapeInfo == null) { mappingEntry.CurveShapeInfo = new CurveShapeInfo(); mappingEntry.CurveShapeInfo.InitWithDefaultValues(); } }
/// <summary> /// Regererates an existing GeneratorMappingEntry based on genInfo. genInfo's ID must be /// the same as an ID in this GeneratorMappingManager. /// </summary> public bool UpdateEntryWithNewGenInfo(GenEntryConfigInfo genInfo, int id) { lock (MssComponentHub.criticalSectioinLock) { IGeneratorMappingEntry mappingEntry = GetMappingEntryById(id); if (mappingEntry == null) { return(false); } else { InitializeEntryFromGenInfo(genInfo, id, mappingEntry); return(true); } } }
/// <summary> /// Creates a new GeneratorMappingEntry based on the info in genInfo. The newly created /// GeneratorMappingEntry will be stored in this GeneratorMappingManager. /// <returns>Returns the id of the newly created entry.</returns> /// </summary> public int CreateAndAddEntryFromGenInfo(GenEntryConfigInfo genInfo) { lock (MssComponentHub.criticalSectioinLock) { IGeneratorMappingEntry mappingEntry = new GeneratorMappingEntry(); int curId = this.nextId; this.nextId++; InitializeEntryFromGenInfo(genInfo, curId, mappingEntry); //Add new mapping entry to list this.mappingEntryList.Add(mappingEntry); return(mappingEntry.Id); } }
public GeneratorDlg() { InitializeComponent(); GenInfoResult = new GenEntryConfigInfo(); //Populate the dropdown meunes on the dialog foreach (string PeriodTypeName in GenEntryConfigInfo.GenPeriodTypeNames) { this.periodTypeCombo.Items.Add(PeriodTypeName); } foreach (string BarsPeriodName in GenEntryConfigInfo.GenBarsPeriodNames) { this.periodCombo.Items.Add(BarsPeriodName); } }
/// <summary> /// Get the relative position into the beat synced period for genInfo at sampleTime /// </summary> /// <remarks> /// Preconditions: genInfo refers to a beat synced generator. CalculatedBarZero and /// TimeSignature have been initialized in hostInfoOutputPort. /// </remarks> protected double GetRelPosInBeatSyncedPeriod(GenEntryConfigInfo genInfo, long sampleTime) { Debug.Assert(genInfo.PeriodType == GenPeriodType.BeatSynced); Debug.Assert(hostInfoOutputPort.CalculatedBarZeroIsInitialized == true); Debug.Assert(hostInfoOutputPort.TimeSignatureIsInitialized == true); //TODO: Need to rethink notion of beat synced gen. Maybe it should just by like a time based gen //that can adjust to a changing tempo instead of jumping to a particular part of the bar. //Need to cover two use cases //LFO that runs on off time quarter note //LFO that is looped and enabled so it should start at bar 0 and always keep in time. double barPos = hostInfoOutputPort.GetBarPosAtSampleTime(sampleTime); double periodSizeInBars = genInfo.GetSizeOfBarsPeriod(hostInfoOutputPort.TimeSignatureNumerator, hostInfoOutputPort.TimeSignatureDenominator); return(barPos % periodSizeInBars / periodSizeInBars); }
protected GenEntryConfigInfo Factory_GenEntryConfigInfo_Default() { //Don't need to bother mocking GenEntryConfigInfo as it does not have any internal //logic that needs testing. GenEntryConfigInfo configInfo = new GenEntryConfigInfo(); configInfo.InitWithDefaultValues(); return configInfo; }
/// <summary> /// Get the relative position into the beat synced period for genInfo at sampleTime /// </summary> /// <remarks> /// Preconditions: genInfo refers to a beat synced generator. CalculatedBarZero and /// TimeSignature have been initialized in hostInfoOutputPort. /// </remarks> protected double GetRelPosInBeatSyncedPeriod(GenEntryConfigInfo genInfo, long sampleTime) { Debug.Assert(genInfo.PeriodType == GenPeriodType.BeatSynced); Debug.Assert(hostInfoOutputPort.CalculatedBarZeroIsInitialized == true); Debug.Assert(hostInfoOutputPort.TimeSignatureIsInitialized == true); //TODO: Need to rethink notion of beat synced gen. Maybe it should just by like a time based gen //that can adjust to a changing tempo instead of jumping to a particular part of the bar. //Need to cover two use cases //LFO that runs on off time quarter note //LFO that is looped and enabled so it should start at bar 0 and always keep in time. double barPos = hostInfoOutputPort.GetBarPosAtSampleTime(sampleTime); double periodSizeInBars = genInfo.GetSizeOfBarsPeriod(hostInfoOutputPort.TimeSignatureNumerator, hostInfoOutputPort.TimeSignatureDenominator); return barPos % periodSizeInBars / periodSizeInBars; }
/// <summary> /// Returns the size of the period for genConfigInfo in samples /// </summary> /// <remarks> /// Preconditions: sample rate must be initialized in hostInfoOutputPort. If /// genConfigInfo is for a beat synced generator then the time signature must also be /// initialized in hostInfoOutputPort. /// </remarks> protected int GetPeriodSizeInSamples(GenEntryConfigInfo genConfigInfo) { if (genConfigInfo.PeriodType == GenPeriodType.BeatSynced || genConfigInfo.PeriodType == GenPeriodType.Bars) { Debug.Assert(hostInfoOutputPort.TimeSignatureIsInitialized == true); Debug.Assert(hostInfoOutputPort.SampleRateIsInitialized == true); double periodSizeInBars = genConfigInfo.GetSizeOfBarsPeriod(hostInfoOutputPort.TimeSignatureNumerator, hostInfoOutputPort.TimeSignatureDenominator); double timeSig = (double)hostInfoOutputPort.TimeSignatureNumerator / hostInfoOutputPort.TimeSignatureDenominator; double beatsPerBar = timeSig / (1/4d); double secondsPerBar = (beatsPerBar / hostInfoOutputPort.Tempo) * 60; return (int)System.Math.Round( secondsPerBar * periodSizeInBars * hostInfoOutputPort.SampleRate); } else if (genConfigInfo.PeriodType == GenPeriodType.Time) { Debug.Assert(hostInfoOutputPort.SampleRateIsInitialized == true); return (int)System.Math.Round( (genConfigInfo.TimePeriodInMs / 1000d) * hostInfoOutputPort.SampleRate); } else { //Unexpected GenPeriodType Debug.Assert(false); return 1000; } }