<commit_before>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace osu.Framework.Audio
{
    /// <summary>
    /// A collection of audio components which need central property control.
    /// </summary>
    public class AudioCollectionManager<T> : AdjustableAudioComponent
        where T : AdjustableAudioComponent
    {
        protected List<T> Items = new List<T>();

        public void AddItem(T item)
        {
            PendingActions.Enqueue(delegate
            {
                if (Items.Contains(item)) return;

                item.AddAdjustmentDependency(this);
                Items.Add(item);
            });
        }

        internal override void OnStateChanged(object sender, EventArgs e)
        {
            base.OnStateChanged(sender, e);
            foreach (var item in Items)
                item.OnStateChanged(sender, e);
        }

        public virtual void UpdateDevice(int deviceIndex)
        {
            foreach (var item in Items.OfType<IBassAudio>())
                item.UpdateDevice(deviceIndex);
        }

        public override void Update()
        {
            base.Update();

            for (int i = 0; i < Items.Count; i++)
            {
                var item = Items[i];

                //todo: this is wrong (completed items may want to stay in an AudioCollectionManager ie. AudioTracks)
                if (item.HasCompleted)
                {
                    Items.RemoveAt(i--);
                    item.Dispose();
                    continue;
                }

                item.Update();
            }
        }
    }
}
<commit_msg>Assert to not add duplicate items to audio collections<commit_after>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace osu.Framework.Audio
{
    /// <summary>
    /// A collection of audio components which need central property control.
    /// </summary>
    public class AudioCollectionManager<T> : AdjustableAudioComponent
        where T : AdjustableAudioComponent
    {
        protected List<T> Items = new List<T>();

        public void AddItem(T item)
        {
            PendingActions.Enqueue(delegate
            {
                Debug.Assert(!Items.Contains(item), "May not add the same item twice.");

                item.AddAdjustmentDependency(this);
                Items.Add(item);
            });
        }

        internal override void OnStateChanged(object sender, EventArgs e)
        {
            base.OnStateChanged(sender, e);
            foreach (var item in Items)
                item.OnStateChanged(sender, e);
        }

        public virtual void UpdateDevice(int deviceIndex)
        {
            foreach (var item in Items.OfType<IBassAudio>())
                item.UpdateDevice(deviceIndex);
        }

        public override void Update()
        {
            base.Update();

            for (int i = 0; i < Items.Count; i++)
            {
                var item = Items[i];

                //todo: this is wrong (completed items may want to stay in an AudioCollectionManager ie. AudioTracks)
                if (item.HasCompleted)
                {
                    Items.RemoveAt(i--);
                    item.Dispose();
                    continue;
                }

                item.Update();
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.09171443460135487, 'fraction_numerical': 0.004689942678478374, 'mean_word_length': 1.4767741935483871, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5991856', 'n_tokens_mistral': 1035, 'n_tokens_neox': 934, 'n_words': 255}