private void refreshAdjustments()
        {
            // because these components may be pooled, relying on DI is not feasible.
            // in the majority of cases the traversal should be quite short. may require later attention if a use case comes up which this is not true for.
            if (parentAdjustment != null)
            {
                adjustments.UnbindAdjustments(parentAdjustment);
                parentAdjustment = null;
            }

            Drawable cursor = this;

            while ((cursor = cursor.Parent) != null)
            {
                if (!(cursor is IAggregateAudioAdjustment candidate))
                {
                    continue;
                }

                // components may be delegating the aggregates of a contained child.
                // to avoid binding to one's self, check reference equality on an arbitrary bindable.
                if (candidate.AggregateVolume != adjustments.AggregateVolume)
                {
                    parentAdjustment = candidate;
                    adjustments.BindAdjustments(parentAdjustment);
                    break;
                }
            }
        }
示例#2
0
        public void TestValueRestoredAfterComponentUnind()
        {
            var adjustments  = new AudioAdjustments();
            var adjustments2 = new AudioAdjustments();

            adjustments.BindAdjustments(adjustments2);

            adjustments2.Volume.Value = 0.5f;

            adjustments.UnbindAdjustments(adjustments2);

            Assert.AreEqual(1.0, adjustments.AggregateVolume.Value);
        }
示例#3
0
        private void refreshLayoutFromParent()
        {
            // because these components may be pooled, relying on DI is not feasible.
            // in the majority of cases the traversal should be quite short. may require later attention if a use case comes up which this is not true for.
            Drawable cursor = this;
            IAggregateAudioAdjustment newAdjustments = null;
            IAudioMixer newMixer = null;

            while ((cursor = cursor.Parent) != null)
            {
                if (newAdjustments == null && cursor is IAggregateAudioAdjustment candidateAdjustment)
                {
                    // components may be delegating the aggregates of a contained child.
                    // to avoid binding to one's self, check reference equality on an arbitrary bindable.
                    if (candidateAdjustment.AggregateVolume != adjustments.AggregateVolume)
                    {
                        newAdjustments = candidateAdjustment;
                    }
                }

                if (newMixer == null && cursor is IAudioMixer candidateMixer)
                {
                    newMixer = candidateMixer;
                }

                if (newAdjustments != null && newMixer != null)
                {
                    break;
                }
            }

            if (newAdjustments != parentAdjustment)
            {
                if (parentAdjustment != null)
                {
                    adjustments.UnbindAdjustments(parentAdjustment);
                }
                parentAdjustment = newAdjustments;
                if (parentAdjustment != null)
                {
                    adjustments.BindAdjustments(parentAdjustment);
                }
            }

            if (parentMixer != newMixer)
            {
                OnMixerChanged(new ValueChangedEvent <IAudioMixer>(parentMixer, newMixer));
            }

            parentMixer = newMixer;
        }