Exemplo n.º 1
0
        public OctaveTone GetNextSemiTone(OctaveTone tone)
        {
            int indexTone = -1;
            int length    = tones.Length;

            for (int i = 0; i < length; i++)
            {
                if (tones[i] == tone.Tone)
                {
                    indexTone = i;
                }
            }

            if (indexTone < 0)
            {
                return(null);
            }
            else if (indexTone < length - 1)
            {
                return(new OctaveTone(tones[indexTone + 1], tone.Octave));
            }
            else
            {
                return(new OctaveTone(tones[0], tone.Octave + 1));
            }
        }
Exemplo n.º 2
0
 public void MuteTone(OctaveTone tone)
 {
     if (tone == null)
     {
         return;
     }
     controllers.ForEach(controller => {
         if (controller.IsInUse && controller.GetCurrentTone == tone)
         {
             controller.MuteTone();
         }
     }
                         );
 }
Exemplo n.º 3
0
 private void CheckTone(OctaveTone octaveTone)
 {
     if (currentTone.Tone == octaveTone.Tone)
     {
         PlayRandomTone();
         streak++;
         feedbackText.text = "Yeah " + streak + "!";
     }
     else
     {
         Debug.Log("NO! Expected " + currentTone.ToneName);
         feedbackText.text = "<color=red>Oh no!</color>";
         streak            = 0;
         soundController.PlayTone(octaveTone, 1);
     }
 }
Exemplo n.º 4
0
        private void Start()
        {
            toneController = new ToneController();
            List <OctaveTone> keyboardTones = new List <OctaveTone>(12);
            OctaveTone        currentTone   = toneController.GetOctaveTone("C", startOctave);

            for (int i = 0; i < 12; i++)
            {
                keyboardTones.Add(currentTone);
                currentTone = toneController.GetNextSemiTone(currentTone);
            }
            toneKeyboard.SetKeyboard(keyboardTones, CheckTone);
            PlayRandomTone();
            feedbackText.text = "Choose your destiny!";
            streak            = 0;
            //StartCoroutine( PlayToneRoutine());
        }
Exemplo n.º 5
0
        public int PlayTone(OctaveTone tone, float seg)
        {
            ToneControllerBehaviour controller = null;

            for (int i = 0; i < controllers.Count; i++)
            {
                if (!controllers[i].IsInUse)
                {
                    controller = controllers[i];
                }
            }
            if (controller == null)
            {
                controller = NewToneController();
            }
            StartCoroutine(PlayToneRoutine(controller, tone, seg));
            return(0);
        }
Exemplo n.º 6
0
        private IEnumerator PlayToneRoutine(ToneControllerBehaviour toneController, OctaveTone tone, float seg)
        {
            toneController.IsInUse = true;
            toneController.PlayTone(tone);
            if (seg > 0)
            {
                yield return(new WaitForSeconds(seg));

                toneController.IsInUse = false;
            }
            else
            {
                do
                {
                    yield return(new WaitForEndOfFrame());
                } while (toneController.GetCurrentTone != null);
                toneController.IsInUse = false;
            }
        }
Exemplo n.º 7
0
        private void PlayRandomTone()
        {
            soundController.MuteTone(currentTone);
            OctaveTone newTone;

            do
            {
                if (streak > 5)
                {
                    newTone = toneController.GetRandomOctaveTone(3);
                }
                else
                {
                    newTone = toneController.GetScale(toneController.GetOctaveTone("C", 3), 7, ToneController.MajorScale)[Random.Range(0, 7)];
                }
            } while (newTone.Equals(currentTone));

            currentTone = newTone;
            soundController.PlayTone(currentTone, 0);
        }
Exemplo n.º 8
0
        public List <OctaveTone> GetScale(OctaveTone tone, int count, List <bool> pattern)
        {
            List <OctaveTone> scale = new List <OctaveTone>(count);

            scale.Add(tone);
            OctaveTone semiTone    = tone;
            int        scaleLength = pattern.Count;

            for (int i = 0; i < count - 1; i++)
            {
                semiTone = GetNextSemiTone(semiTone);
                if (pattern[i % scaleLength])
                {
                    semiTone = GetNextSemiTone(semiTone);
                }
                scale.Add(semiTone);
            }

            return(scale);
        }