protected sealed override void OnNoteStop(ENoteColour aNoteColour, MusicalNote note)
 {
     if (aNoteColour == noteColour)
     {
         Deactivate(note);
         m_isActive = false;
     }
 }
 protected sealed override void OnNoteStart(ENoteColour aNoteColour, MusicalNote note)
 {
     if (aNoteColour == noteColour)
     {
         Activate(note);
         m_isActive = true;
     }
 }
コード例 #3
0
        void TriggerNoteStop(ENoteColour colour)
        {
            m_animator.SetInteger("NoteColour", (int)colour);
            // Triggering the transition to the Stopped state!
            m_animator.ResetTrigger("TNoteStarted");
            m_animator.SetTrigger("TNoteStopped");

            m_pressedColours.Remove(colour);
        }
コード例 #4
0
 public void StopAllPlayingNotPressedNotes()
 {
     for (int i = 0; i < m_playingColours.Count; ++i)
     {
         ENoteColour colour = m_playingColours[i];
         if (!m_pressedColours.Contains(colour) && StopNote(colour))
         {
             --i;
         }
     }
 }
コード例 #5
0
 public void StopAllPlayingNotes()
 {
     for (int i = 0; i < m_playingColours.Count; ++i)
     {
         ENoteColour colour = m_playingColours[i];
         if (!StopNote(colour))
         {
             --i;
         }
     }
 }
コード例 #6
0
        public bool PlayNote(ENoteColour colour, MusicalNote note)
        {
            int  voice   = m_instrumentSource.StartNote(note);
            bool success = voice != -1;

            if (success)
            {
                SetPlayingVoice(colour, voice);
                m_events.playerNoteStartEvent.Invoke(colour, note);
            }
            return(success);
        }
コード例 #7
0
        void TriggerNoteStart(ENoteColour colour, MusicalNote note)
        {
            // Pass info to the StateMachine through the Animator.
            m_animator.SetInteger("NoteColour", (int)colour);
            m_animator.SetInteger("NoteTone", note.tone);
            m_animator.SetFloat("NoteVolume", (float)note.volume);
            m_animator.SetFloat("NotePanning", (float)note.panning);
            // Triggering the transition to the Playing state!
            m_animator.ResetTrigger("TNoteStopped");
            m_animator.SetTrigger("TNoteStarted");

            m_pressedColours.Add(colour);
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <returns>true on success, false on failure.</returns>
        public bool StopNote(ENoteColour colour)
        {
            int voice = GetPlayingVoice(colour);

            Assert.IsTrue(voice >= 0 && voice < m_instrumentSource.GetNumberVoices());
            MusicalNote note    = m_instrumentSource.GetNote(voice);
            bool        success = m_instrumentSource.StopNote(voice);

            if (success)
            {
                UnsetPlayingVoice(colour);
                m_events.playerNoteStopEvent.Invoke(colour, note);
            }
            return(success);
        }
コード例 #9
0
        protected override void OnStateEnterInternal(Animator animator)
        {
            // Resetting the corresponding trigger.
            animator.ResetTrigger("TNoteStarted");

            owner.StopAllPlayingNotes();

            ENoteColour colour = (ENoteColour)animator.GetInteger("NoteColour");

            m_note = new MusicalNote(
                animator.GetInteger("NoteTone"),
                animator.GetFloat("NoteVolume")
                );
            // Debug.Log($"Start {colour}");
            owner.PlayNote(colour, m_note);
        }
コード例 #10
0
 void Update()
 {
     for (int toneIndex = 0; toneIndex < tones.Length; ++toneIndex)
     {
         KeyCode     key    = keys[toneIndex];
         ENoteColour colour = (ENoteColour)toneIndex;
         if (Input.GetKeyDown(key))
         {
             int tone = tones[toneIndex];
             TriggerNoteStart(colour, new MusicalNote(tone, volume));
         }
         else if (Input.GetKeyUp(key))
         {
             TriggerNoteStop(colour);
         }
     }
 }
コード例 #11
0
        public static Color GetColour(ENoteColour noteColour)
        {
            Color colour = Color.clear;

            switch (noteColour)
            {
            case ENoteColour.eBlue:   colour = Color.blue;
                break;

            case ENoteColour.eGreen:  colour = Color.green;
                break;

            case ENoteColour.eYellow: colour = Color.yellow;
                break;

            case ENoteColour.eOrange: colour = Color.Lerp(Color.red, Color.yellow, 0.5f);
                break;

            case ENoteColour.eRed:    colour = Color.red;
                break;
            }
            return(colour);
        }
コード例 #12
0
 void UnsetPlayingVoice(ENoteColour colour)
 {
     m_playingVoices[(int)colour] = -1;
     m_playingColours.Remove(colour);
 }
コード例 #13
0
 void SetPlayingVoice(ENoteColour colour, int voice)
 {
     m_playingVoices[(int)colour] = voice;
     m_playingColours.Add(colour);
 }
コード例 #14
0
 int GetPlayingVoice(ENoteColour colour)
 {
     return(m_playingVoices[(int)colour]);
 }
コード例 #15
0
 protected virtual void OnNoteStop(ENoteColour noteColour, MusicalNote note)
 {
 }
コード例 #16
0
 void OnNoteStartInRange(ENoteColour noteColour, MusicalNote note)
 {
     m_inRangePlayingNotes.Add(new Tuple <ENoteColour, MusicalNote>(noteColour, note));
     OnNoteStart(noteColour, note);
 }
コード例 #17
0
 void OnNoteStopInRange(ENoteColour noteColour, MusicalNote note)
 {
     m_inRangePlayingNotes.RemoveAll(el => el.Item1 == noteColour);
     OnNoteStop(noteColour, note);
 }
コード例 #18
0
 void OnNoteStartOutOfRange(ENoteColour noteColour, MusicalNote note)
 {
     m_outOfRangePlayingNotes.Add(new Tuple <ENoteColour, MusicalNote>(noteColour, note));
 }
コード例 #19
0
 void OnNoteStopOutOfRange(ENoteColour noteColour, MusicalNote note)
 {
     m_outOfRangePlayingNotes.RemoveAll(el => el.Item1 == noteColour);
 }
コード例 #20
0
 protected virtual void OnNoteStart(ENoteColour aNoteColour, MusicalNote note)
 {
 }