コード例 #1
0
        /// <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);
            }
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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;
        }
コード例 #4
0
        /// <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;
            }
        }