/**<summary>Reset this sound so that it will play from the start.</summary>*/
        public void Reset()
        {
            BeatCollection.Enumerator = BeatCollection.GetEnumerator();
            ByteInterval = 0;
            if (Metronome.GetInstance().IsSilentInterval)
            {
                SetSilentInterval(Metronome.GetInstance().AudibleInterval, Metronome.GetInstance().SilentInterval);
            }
            if (Metronome.GetInstance().IsRandomMute)
            {
                randomMuteCountdown = null;
                currentlyMuted      = false;
            }
            if (Layer.Offset > 0)
            {
                SetOffset(
                    BeatCell.ConvertFromBpm(Layer.Offset, this)
                    );
            }
            // TODO: hihat open settings
            HiHatOpenIsMuted = false;
            //HiHatMuteInitiated = false;
            HiHatCycleToMute = 0;
            cycle            = 0;

            // will first muting occur for first sound?
            SetInitialMuting();

            // set stream back to start.
            Position = 0;
        }
Example #2
0
 public SourceBeatCollection(Layer layer, double[] beats, IStreamProvider src)
 {
     Layer      = layer;
     Beats      = beats.Select((x) => BeatCell.ConvertFromBpm(x, src)).ToArray();
     Enumerator = GetEnumerator();
     isWav      = src.WaveFormat.AverageBytesPerSecond == 64000;
 }
        protected double SilentIntervalRemainder; // fractional portion

        /**<summary>Sets the silent interval.</summary>
         * <param name="audible">Number of quarter notes audible.</param>
         * <param name="silent">Number of quarter notes silent.</param>
         */
        public void SetSilentInterval(double audible, double silent)
        {
            AudibleInterval         = BeatCell.ConvertFromBpm(audible, this);
            SilentInterval          = BeatCell.ConvertFromBpm(silent, this);
            currentSlntIntvl        = (int)AudibleInterval - InitialOffset;
            SilentIntervalRemainder = audible - currentSlntIntvl + OffsetRemainder;
        }
        protected bool HiHatOpenIsMuted = false;  // an open hihat sound was muted so currenthihatduration should not be increased by closed sounds being muted.

        public void SetSilentInterval(double audible, double silent)
        {
            AudibleInterval         = BeatCell.ConvertFromBpm(audible, this) * 4;
            SilentInterval          = BeatCell.ConvertFromBpm(silent, this) * 4;
            currentSlntIntvl        = (int)AudibleInterval - initialOffset - 4;
            SilentIntervalRemainder = audible - currentSlntIntvl + offsetRemainder;

            SetInitialMuting();
        }
Example #5
0
        /** <summary>Set the offset for this layer.</summary>
         * <param name="offset">Quarter notes to offset by.</param> */
        public void SetOffset(double offset)
        {
            Offset = offset;

            foreach (IStreamProvider src in AudioSources.Values)
            {
                double current = src.GetOffset();
                double add     = BeatCell.ConvertFromBpm(offset, src);
                src.SetOffset(current + add);
            }

            //// set for pitch / base source

            if (BasePitchSource != default(PitchStream))
            {
                double current3 = BasePitchSource.GetOffset();
                double add3     = BeatCell.ConvertFromBpm(offset, BasePitchSource);
                BasePitchSource.SetOffset(current3 + add3);
            }
        }
 /**<summary>Reset state to default values.</summary>*/
 public void Reset()
 {
     freqEnum.Reset(); //= Frequencies.Values.GetEnumerator();
     BeatCollection.Enumerator = BeatCollection.GetEnumerator();
     ByteInterval   = 0;
     previousSample = 0;
     Gain           = Volume;
     if (Metronome.GetInstance().IsSilentInterval)
     {
         SetSilentInterval(Metronome.GetInstance().AudibleInterval, Metronome.GetInstance().SilentInterval);
     }
     if (Metronome.GetInstance().IsRandomMute)
     {
         randomMuteCountdown = null;
         currentlyMuted      = false;
     }
     if (Layer.Offset > 0)
     {
         SetOffset(
             BeatCell.ConvertFromBpm(Layer.Offset, this)
             );
     }
 }
Example #7
0
 /** <summary>Set an audible/silent interval.</summary>
  * <param name="audible">The value in quarter notes that a beat plays audibly.</param>
  * <param name="silent">The value in quarter notes that a beat is silenced.</param> */
 public void SetSilentInterval(string audible, string silent)
 {
     SetSilentInterval(BeatCell.Parse(audible), BeatCell.Parse(silent));
 }
 /**<summary>Add a frequency to the frequency enumerator que.</summary>
  * <param name="cell">The cell that uses the pitch.</param>
  * <param name="symbol">The pitch symbol. ex. A4</param>
  */
 public void SetFrequency(string symbol, BeatCell cell)
 {
     Frequencies.Add(cell, ConvertFromSymbol(symbol));
     freqEnum = Frequencies.Values.GetEnumerator();
 }
Example #9
0
        /** <summary>Set the beat collections for each sound source.</summary>
         * <param name="Beat">The cells to process</param>
         */
        public void SetBeatCollectionOnSources(List <BeatCell> Beat)
        {
            List <IStreamProvider> completed = new List <IStreamProvider>();

            // for each beat, iterate over all beats and build a beat list of values from beats of same source.
            for (int i = 0; i < Beat.Count; i++)
            {
                List <double> cells       = new List <double>();
                double        accumulator = 0;
                // Once per audio source
                if (completed.Contains(Beat[i].AudioSource))
                {
                    continue;
                }
                // if selected beat is not first in cycle, set it's offset
                if (i != 0)
                {
                    double offsetAccumulate = Offset;
                    for (int p = 0; p < i; p++)
                    {
                        offsetAccumulate += Beat[p].Bpm;
                    }

                    Beat[i].AudioSource.SetOffset(BeatCell.ConvertFromBpm(offsetAccumulate, Beat[i].AudioSource));
                }
                // iterate over beats starting with current one. Aggregate with cells that have the same audio source.
                for (int p = i; ; p++)
                {
                    if (p == Beat.Count)
                    {
                        p = 0;
                    }

                    if (Beat[p].AudioSource == Beat[i].AudioSource)
                    {
                        // add accumulator to previous element in list
                        if (cells.Count != 0)
                        {
                            cells[cells.Count - 1] += accumulator;
                            accumulator             = 0f;
                        }
                        cells.Add(Beat[p].Bpm);
                    }
                    else
                    {
                        accumulator += Beat[p].Bpm;
                    }

                    // job done if current beat is one before the outer beat.
                    if (p == i - 1 || (i == 0 && p == Beat.Count - 1))
                    {
                        cells[cells.Count - 1] += accumulator;
                        break;
                    }
                }
                completed.Add(Beat[i].AudioSource);

                Beat[i].AudioSource.BeatCollection = new SourceBeatCollection(this, cells.ToArray(), Beat[i].AudioSource);
            }

            // do any initial muting, includes hihat timings
            AudioSources.Values.ToList().ForEach(x => x.SetInitialMuting());
        }
Example #10
0
        /** <summary>Set the offset for this layer.</summary>
         * <param name="offset">Beat code value to offset by.</param> */
        public void SetOffset(string offset)
        {
            double os = BeatCell.Parse(offset);

            SetOffset(os);
        }