Example #1
0
    void OnLightMIDIEvent(object sender, EightNightsMIDIMgr.EightNightsMIDIEventArgs e)
    {
        if (!EffectsEnabled)
         return;

          if ((e.Group == MIDIGroup) && IsGroupPlaying() && !ButtonSoundMgr.Instance.IsGroupCrescendoing(MIDIGroup))
          {
         //pick an effect to trigger
         List<EffectEntry> effectsToTrigger = PickEffects(e);
         if (effectsToTrigger != null)
         {
            foreach (EffectEntry effectEntry in effectsToTrigger)
            {
               if (effectEntry.LightEffectToTrigger != null)
                  effectEntry.Trigger(this, false, e);
            }
         }
          }
    }
Example #2
0
    List<EffectEntry> PickEffects(EightNightsMIDIMgr.EightNightsMIDIEventArgs midiEvent)
    {
        if ((EffectsToTrigger != null) && (EffectsToTrigger.Length > 0))
          {
         _lastPickedEffects.Clear();

         //TODO: check MIDI mappings!
         List<MIDINoteMapping> midiMaps = new List<MIDINoteMapping>();
         foreach (MIDINoteMapping m in NoteMappings)
         {
            foreach (int note in m.MIDINotes)
            {
               if (note == midiEvent.MidiNote)
               {
                  midiMaps.Add(m);
                  break;
               }
            }
         }

         if (midiMaps.Count > 0)
         {
            _lastMIDINote = midiEvent.MidiNote;
            _lastPickedIdx = midiMaps[0].EffectIdxToTrigger;
            //Debug.Log("Mapped MIDI note " + _lastMIDINote + " to effect: " + _lastPickedIdx );
            for (int i = 0; i < midiMaps.Count; i++)
            {
               _lastPickedEffects.Add(EffectsToTrigger[midiMaps[i].EffectIdxToTrigger]);
            }
            return _lastPickedEffects;
         }
         else if (TriggerRule == TriggerMode.Sequential)
         {
            _lastPickedIdx = (_lastPickedIdx + 1) % EffectsToTrigger.Length;
            _lastPickedEffects.Add(EffectsToTrigger[_lastPickedIdx]);
            return _lastPickedEffects;
         }
         else if (TriggerRule == TriggerMode.AllAtOnce)
         {
            _lastPickedIdx = -1;
            int i = 0;
            foreach (EffectEntry e in EffectsToTrigger)
            {
               _lastPickedEffects.Add(EffectsToTrigger[i]);
               i++;
            }
            return _lastPickedEffects;
         }
         else if (TriggerRule == TriggerMode.Random)
         {
            _lastPickedIdx = Random.Range(0, EffectsToTrigger.Length);
            _lastPickedEffects.Add(EffectsToTrigger[_lastPickedIdx]);
            return _lastPickedEffects;
         }
         else if (TriggerRule == TriggerMode.FollowPitch)
         {
            if (_lastMIDINote == -1)
               _lastPickedIdx = 0;
            else
            {
               if (midiEvent.MidiNote > _lastMIDINote) //higher note, move up
               {
                  _lastPickedIdx++;
                  if(FollowPitchClamping) //clamp
                  {
                         if(_lastPickedIdx >= EffectsToTrigger.Length - 1)
                        _lastPickedIdx = EffectsToTrigger.Length - 1;
                  }
                      else //wrap
                         _lastPickedIdx = (_lastPickedIdx % EffectsToTrigger.Length);
               }
               else if (midiEvent.MidiNote < _lastMIDINote) //lower note, move down
               {
                  _lastPickedIdx--;
                  if(FollowPitchClamping) //clamp
                  {
                     if (_lastPickedIdx < 0)
                        _lastPickedIdx = 0;
                  }
                  else
                  {
                     if (_lastPickedIdx < 0)
                        _lastPickedIdx = EffectsToTrigger.Length - 1;
                  }
               }
            }
            _lastMIDINote = midiEvent.MidiNote;
            //Debug.Log("FollowPitch mapped note " + _lastMIDINote + " to effect: " + _lastPickedIdx);

            _lastPickedEffects.Add(EffectsToTrigger[_lastPickedIdx]);
            return _lastPickedEffects;
         }
          }

          return null;
    }
Example #3
0
        public void Trigger(TriggerLightEffect parentEffect, bool forceLooping = false, EightNightsMIDIMgr.EightNightsMIDIEventArgs midiEvent = null)
        {
            //if we have a looping effect playing, ignore...
             if (_spawnedObj != null)
            return;

             if (LightEffectToTrigger != null)
             {
            //instatiate new effect and override light if specified
            GameObject spawnedLightObj = Instantiate(LightEffectToTrigger.gameObject) as GameObject;
            spawnedLightObj.transform.parent = parentEffect.transform;
            LightEffect spawnedLightEffect = spawnedLightObj.GetComponent<LightEffect>();
            if (EnableLightOverride)
            {
               foreach (LightEffect.EffectKeyframe k in spawnedLightEffect.Keyframes)
               {
                  foreach (LightEffect.LightState s in k.LightKeys)
                  {
                     s.Light = LightOverride;
                  }
               }
            }
            spawnedLightEffect.LightGroup = parentEffect.MIDIGroup;
            spawnedLightEffect.MasterFader = parentEffect.ApplyNoteVelocity ? Mathf.Lerp(parentEffect.MinNoteVelocity, 1.0f, midiEvent.Velocity) : 1.0f;
            spawnedLightEffect.AutoTrigger = true;
            spawnedLightEffect.TriggerEffect(); //redundant, I know
            if (forceLooping)
            {
               KillEffect(); //kill any previous version of this effect

               spawnedLightEffect.Loop = true;
               _spawnedObj = spawnedLightObj;
               spawnedLightEffect.AutoDestroy = false;
               spawnedLightEffect.FadeWithStemVolume = false;
               spawnedLightEffect.FadeWithButtonCrescendo = true;

            }
            else //if we aren't looping then we auto destroy
            {
               spawnedLightEffect.FadeWithStemVolume = true;
               spawnedLightEffect.FadeWithButtonCrescendo = false;
               spawnedLightEffect.AutoDestroy = true;
               _spawnedObj = null;

               //Debug.Log("Note " + midiEvent.MidiNote + " velocity: " + midiEvent.Velocity);

               //send out event that we're triggering an effect on a particular light
               if ((EightNightsMgr.Instance != null) && (midiEvent != null))
               {
                  //assume all the lights its driving are the same
                  EightNightsMgr.LightID lID = spawnedLightEffect.Keyframes[0].LightKeys[0].Light;
                  //queue this up to send out once latency is elapsed
                  LightTriggerEvent delayedEvent = new LightTriggerEvent();
                  delayedEvent.Group = parentEffect.MIDIGroup;
                  delayedEvent.Light = lID;
                  delayedEvent.BeatTime = midiEvent.NoteBeat;
                  delayedEvent.Weight = midiEvent.Velocity;

                  //WHY?
                  delayedEvent.BeatTime -= (BeatClock.Instance.LatencySecs() / BeatClock.Instance.SecsPerBeat());

                  parentEffect.AddDelayedEvent(delayedEvent);
               }
            }

            //LightEffectToTrigger.TriggerEffect();
             }
        }
Example #4
0
 void Awake()
 {
     Instance = this;
 }