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;
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
         }
     }
 }
Ejemplo n.º 5
0
 public void StopAllPlayingNotes()
 {
     for (int i = 0; i < m_playingColours.Count; ++i)
     {
         ENoteColour colour = m_playingColours[i];
         if (!StopNote(colour))
         {
             --i;
         }
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
        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);
        }
Ejemplo n.º 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);
         }
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 12
0
 void UnsetPlayingVoice(ENoteColour colour)
 {
     m_playingVoices[(int)colour] = -1;
     m_playingColours.Remove(colour);
 }
Ejemplo n.º 13
0
 void SetPlayingVoice(ENoteColour colour, int voice)
 {
     m_playingVoices[(int)colour] = voice;
     m_playingColours.Add(colour);
 }
Ejemplo n.º 14
0
 int GetPlayingVoice(ENoteColour colour)
 {
     return(m_playingVoices[(int)colour]);
 }
Ejemplo n.º 15
0
 protected virtual void OnNoteStop(ENoteColour noteColour, MusicalNote note)
 {
 }
Ejemplo n.º 16
0
 void OnNoteStartInRange(ENoteColour noteColour, MusicalNote note)
 {
     m_inRangePlayingNotes.Add(new Tuple <ENoteColour, MusicalNote>(noteColour, note));
     OnNoteStart(noteColour, note);
 }
Ejemplo n.º 17
0
 void OnNoteStopInRange(ENoteColour noteColour, MusicalNote note)
 {
     m_inRangePlayingNotes.RemoveAll(el => el.Item1 == noteColour);
     OnNoteStop(noteColour, note);
 }
Ejemplo n.º 18
0
 void OnNoteStartOutOfRange(ENoteColour noteColour, MusicalNote note)
 {
     m_outOfRangePlayingNotes.Add(new Tuple <ENoteColour, MusicalNote>(noteColour, note));
 }
Ejemplo n.º 19
0
 void OnNoteStopOutOfRange(ENoteColour noteColour, MusicalNote note)
 {
     m_outOfRangePlayingNotes.RemoveAll(el => el.Item1 == noteColour);
 }
Ejemplo n.º 20
0
 protected virtual void OnNoteStart(ENoteColour aNoteColour, MusicalNote note)
 {
 }