Example #1
0
        public double ReturnAtNext(BeatValue next)
        {
            switch (next)
            {
            case (BeatValue.Measure):
                return(AtNextMeasure());

            case (BeatValue.Whole):
                return(AtNextWhole());

            case (BeatValue.Half):
                return(AtNextHalf());

            case (BeatValue.Quarter):
                return(AtNextQuarter());

            case (BeatValue.Eighth):
                return(AtNextEighth());

            case (BeatValue.Sixteenth):
                return(AtNextSixteenth());

            case (BeatValue.ThirtySecond):
                return(AtNextThirtySecond());
            }

            return(0.0d);
        }
Example #2
0
 void Start()
 {
     beatValue      = BeatValue.EighthBeat;
     beatInSamples  = TempoUtils.instance.GetBeatInSamples(beatValue);
     beatInSequence = 0;
     //Debug.Log(beatInSamples);
 }
Example #3
0
        IEnumerator YieldForSync(System.Action callback, BeatValue beatValue)
        {
            int  startCount  = _thirtySecondCount % 32;
            bool isStartNote = true;
            bool waiting     = true;

            while (waiting)
            {
                isStartNote = (isStartNote && startCount == (_thirtySecondCount % 32));
                if (isStartNote)
                {
                    yield return(false);
                }
                isStartNote = false;
                if (beatValue == BeatValue.ThirtySecond || (_thirtySecondCount % 32) % (int)beatValue == 1)
                {
                    waiting = false;
                }
                else
                {
                    yield return(false);
                }
            }
            callback();
        }
Example #4
0
 public void SetObjectsReferences()
 {
     offset = 60f / (MusicController.bpm * BeatDecimalValues.values[(int)beatOffset]);
     patternController.SetOffsetTolerance();
     Player.PatternSynchNumber = (int)LineSync;
     playerSpeed = Player.attackSpeed;
 }
Example #5
0
 public T this[BeatValue i] {
     get {
         return(_beatMaskArr[(int)i]);
     }
     set {
         _beatMaskArr[(int)i] = value;
     }
 }
Example #6
0
 public BeatArgs(BeatValue beatVal, int beatCount, double beatTime, double nextBeatTime, bool[] beatMask)
 {
     BeatVal      = beatVal;
     BeatCount    = beatCount;
     BeatTime     = beatTime;
     NextBeatTime = nextBeatTime;
     BeatMask     = beatMask;
 }
Example #7
0
 public void Stop(BeatValue beat)
 {
     if (AssertExpired())
     {
         audioSource.ShallowStop(beat);
         Expire();
     }
 }
Example #8
0
 internal void Start(BeatValue beat = ShallowMusic.DEFAULT_BEAT)
 {
     if (AssertExpired())
     {
         if (!audioSource.isPlaying)
         {
             audioSource.ShallowPlay(beat);
         }
     }
 }
Example #9
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        ExplosionEmitter.Emit(transform.position);
        Destroy(gameObject);
        BeatValue.AddScore(1);

        var bullet = collider.gameObject.GetComponent <Bullet>();

        if (bullet != null)
        {
            bullet.GetPlayer().AddReward();
        }
    }
Example #10
0
    private void SetNoteValues(List <Note> nl, PatternSynch ps)
    {
        bool[]      restNotes           = new bool[nl.Count];
        BeatValue[] beatValues          = new BeatValue[nl.Count];
        BeatValue[] leggatoValues       = new BeatValue[nl.Count];
        BeatValue[] secondLeggatoValues = new BeatValue[nl.Count];
        for (int i = 0; i < nl.Count; i++)
        {
            if (nl[i].GetColor() == NoteColor.NONE)
            {
                restNotes[i] = true;
            }
            else
            {
                restNotes[i] = false;
            }

            beatValues[i]          = nl[i].GetBeatValue();
            leggatoValues[i]       = nl[i].GetLegatto();
            secondLeggatoValues[i] = nl[i].GetSecondLegatto();
        }

        samplePeriods = new double[beatValues.Length];

        // Calculate number of samples between each beat in the sequence.
        for (int i = 0; i < beatValues.Length; ++i)
        {
            if (leggatoValues[i] == BeatValue.None)
            {
                samplePeriods[i] = 60f / (bpm * BeatDecimalValues.values[(int)beatValues[i]]);
            }

            else if (secondLeggatoValues[i] == BeatValue.None)
            {
                samplePeriods[i] = 60f / (bpm * BeatDecimalValues.values[(int)beatValues[i]]) +
                                   60f / (bpm * BeatDecimalValues.values[(int)leggatoValues[i]]);
            }
            else
            {
                samplePeriods[i] = 60f / (bpm * BeatDecimalValues.values[(int)beatValues[i]]) +
                                   60f / (bpm * BeatDecimalValues.values[(int)leggatoValues[i]]) +
                                   60f / (bpm * BeatDecimalValues.values[(int)secondLeggatoValues[i]]);
            }
        }

        ps.SetSamplePeriods(samplePeriods, restNotes);
        //ps.gameObject.GetComponent<NotePooler>().SetBullets(nl, ps);
    }
Example #11
0
        //Helper functions for cueing things to play (usually audio) at the next available interval
        //For playing audio, use AudioSource.PlayScheduled(AtNextThirtySecond());
        public double AtNext(BeatValue beat)
        {
            switch (beat)
            {
            case BeatValue.Measure:
            default:
                return(AtNextMeasure());

            case BeatValue.Half:
                return(AtNextHalf());

            case BeatValue.Quarter:
                return(AtNextQuarter());

            case BeatValue.Eighth:
                return(AtNextEighth());

            case BeatValue.Sixteenth:
                return(AtNextSixteenth());

            case BeatValue.ThirtySecond:
                return(AtNextThirtySecond());
            }
        }
Example #12
0
 public float GetBeatInSamples(BeatValue beatValue)
 {
     return((60f / (bpm * BeatDecimalValues.values[(int)beatValue])) * audioSource.clip.frequency);
 }
Example #13
0
 public WaitForBeatSync(BeatValue wtBeatValue)
 {
     this._waitBeatValue      = wtBeatValue;
     this.currentThirtySecond = Clock.Instance._thirtySecondCount;
     //print("Starting Tick: " + currentTick);
 }
Example #14
0
 public void SetTimeSignature(int beatsPerMeasure, BeatValue unitOfTempo)
 {
     _beatsPerMeasure = beatsPerMeasure;
     _unitOfTempo     = unitOfTempo;
     _InitializeBPM(BPM);
 }
Example #15
0
 ShallowAudioSource MemberPlay(Notes note, BeatValue beat = DEFAULT_BEAT, float volume = 1.0f)
 {
     return(MemberPlay(note, Vector2.zero, beat, volume));
 }
Example #16
0
 public WaitForBeat(BeatValue beatValue)
 {
     waitUntil      = Clock.Instance.AtNext(beatValue);
     this.beatValue = beatValue;
 }
Example #17
0
 /// <summary>
 /// This overloaded method is called by each PatternCounter this object is observing. Since pattern counters contain a sequence of 
 /// different beat types, keeping track of the beat type isn't necessary. To test for a beat from the pattern counter, the beat mask
 /// should be checked for the BeatType.OnBeat flag.
 /// </summary>
 public void BeatNotify(BeatValue value)
 {
     beatValue = value;
     beatMask |= BeatType.OnBeat;
     StartCoroutine(WaitOnBeat(BeatType.OnBeat));
 }
Example #18
0
 void Start()
 {
     beatMask = BeatType.None;
     beatValue = BeatValue.None;
 }
Example #19
0
 ShallowAudioSource MemberPlay(string clip, int index, BeatValue beat = DEFAULT_BEAT, float volume = 1.0f)
 {
     return(MemberPlay(clip, index, Vector2.zero, beat, volume));
 }
Example #20
0
 void MemberStop(AudioSource source, BeatValue beat = DEFAULT_BEAT)
 {
     source.SetScheduledEndTime(Clock.Instance.AtNext(beat));
 }
Example #21
0
 void MemberPlay(AudioSource source, BeatValue beat = DEFAULT_BEAT)
 {
     source.PlayScheduled(Clock.Instance.AtNext(beat));
 }
Example #22
0
        ShallowAudioSource MemberPlay(AudioClip clip, Vector2 location, bool loop = false, BeatValue beat = DEFAULT_BEAT, float volume = 1.0f)
        {
            ShallowAudioSource source = GetShallowAudioSource(clip);

            source.loop     = loop;
            source.position = location;
            source.volume   = volume;
            source.Start(beat);

            return(source);
        }
Example #23
0
 ShallowAudioSource MemberPlay(AudioClip clip, bool loop = false, BeatValue beat = DEFAULT_BEAT, float volume = 1.0f)
 {
     return(MemberPlay(clip, Vector2.zero, loop, beat, volume));
 }
Example #24
0
 ShallowAudioSource MemberPlay(Notes note, Vector2 location, BeatValue beat = DEFAULT_BEAT, float volume = 1.0f)
 {
     return(MemberPlay(notes[(int)note].randomClip, location, false, beat, volume));
 }
Example #25
0
 /// <summary>
 /// This overloaded method is called by each PatternCounter this object is observing. Since pattern counters contain a sequence of
 /// different beat types, keeping track of the beat type isn't necessary. To test for a beat from the pattern counter, the beat mask
 /// should be checked for the BeatType.OnBeat flag.
 /// </summary>
 public void BeatNotify(BeatValue value)
 {
     beatValue = value;
     beatMask |= BeatType.OnBeat;
     StartCoroutine(WaitOnBeat(BeatType.OnBeat));
 }
Example #26
0
 public static ShallowAudioSource Play(Notes note, Vector2 location, BeatValue beat = DEFAULT_BEAT, float volume = 1.0f)
 {
     return(Instance.MemberPlay(note, location, beat, volume));
 }
Example #27
0
 //CoRoutine to sync the execution of a particular callback to the next relevant beat of a particular value
 //Usage: Clock.Instance.SyncFunction(FunctionToCallback, BeatValue.Quarter)
 public void SyncFunction(System.Action callback, BeatValue beatValue = BeatValue.Measure)
 {
     StartCoroutine(YieldForSync(callback, beatValue));
 }
Example #28
0
 public static ShallowAudioSource Play(AudioClip clip, Vector2 location, bool loop, BeatValue beat = DEFAULT_BEAT, float volume = 1.0f)
 {
     return(Instance.MemberPlay(clip, location, loop, beat, volume));
 }
Example #29
0
 public static void Stop(AudioSource source, BeatValue beat = DEFAULT_BEAT)
 {
     Instance.MemberStop(source, beat);
 }
Example #30
0
 public static void ShallowStop(this AudioSource source, BeatValue beat = ShallowMusic.DEFAULT_BEAT)
 {
     ShallowMusic.Stop(source, beat);
 }
Example #31
0
 public static ShallowAudioSource Play(string clip, int index, Vector2 location, BeatValue beat = DEFAULT_BEAT, float volume = 1.0f)
 {
     return(Instance.MemberPlay(clip, index, location, beat, volume));
 }
Example #32
0
 ShallowAudioSource MemberPlay(string clip, int index, Vector2 location, BeatValue beat = DEFAULT_BEAT, float volume = 1.0f)
 {
     return(MemberPlay(sfxClips[clip].clips[index], location, false, beat, volume));
 }