コード例 #1
0
        /// <summary>
        /// Add an effect to the launchpad
        /// </summary>
        /// <param name="effect"></param>
        /// <param name="updateFrequency"></param>
        public void RegisterEffect(ILaunchpadEffect effect, TimeSpan updateFrequency)
        {
            try
            {
                // Register any observables being used
                CompositeDisposable effectDisposables = new CompositeDisposable();

                // If this effect needs the ability to change its frequency
                if (effect.WhenChangeUpdateFrequency != null)
                {
                    // Subscribe to the event to change the frequency and add it to this effects disposables
                    effectDisposables.Add(
                        effect
                        .WhenChangeUpdateFrequency
                        .Subscribe(newFrequency =>
                    {
                        // Change the frequency for this effect
                        OnChangeEffectUpdateFrequency(effect, newFrequency);
                    }));
                }

                // If this effect will notify us it needs to be unregistered
                if (effect.WhenComplete != null)
                {
                    effectDisposables.Add(
                        effect
                        .WhenComplete
                        .Subscribe(_ =>
                    {
                        // Unregister the effect and destroy its disposables
                        UnregisterEffect(effect);
                    }));
                }

                EffectsDisposables.Add(effect, effectDisposables);

                // Create an update timer at the specified frequency
                EffectsTimers.Add(effect, new Timer(state => effect.Update(), null, 0, (int)updateFrequency.TotalMilliseconds));

                // Initiate the effect (provide all buttons and button changed event
                effect.Initiate(this);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
コード例 #2
0
        public override void UnregisterEffect(ILaunchpadEffect effect)
        {
            try
            {
                EffectsDisposables[effect].Dispose();
                EffectsDisposables.Remove(effect);
            }
            catch { }

            try
            {
                EffectsTimers[effect].Dispose();
                EffectsTimers.Remove(effect);
            }
            catch { }
            effect.Dispose();
        }
コード例 #3
0
        /// <summary>
        /// Removes an effect from the launchpad
        /// </summary>
        /// <param name="effect">The effect to remove.</param>
        public override void UnregisterEffect(ILaunchpadEffect effect)
        {
            try
            {
                // Dispose of the update timer for the effect
                effectsTimers[effect]?.Dispose();

                // Dispose of the OnComplete subscription
                effectsDisposables[effect]?.Dispose();

                // Remove the effect from the launchpad
                Effects.Remove(effect);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
コード例 #4
0
 public void RegisterEffect(ILaunchpadEffect effect, int updateFrequency)
 {
     RegisterEffect(effect, TimeSpan.FromMilliseconds(updateFrequency));
 }
コード例 #5
0
 void OnChangeEffectUpdateFrequency(ILaunchpadEffect effect, int newFrequency)
 {
     EffectsTimers[effect].Change(0, newFrequency);
 }
コード例 #6
0
 public abstract void UnregisterEffect(ILaunchpadEffect effect);