<commit_before>#include "PuroHeader.h"
#if 0

// TODO
// - Random deviation parameters for granulator
// - ints to size_ts where appropriate

int main()
{
    const int n = 256;
    const int blockSize = 32;
    const int numChannels = 2;

    std::vector<float> left (n, 0.0f);
    std::vector<float> right (n, 0.0f);

    using Envelope = SineEnvelope<float>;
    //using AudioSource = NoiseSource<float>;
    using AudioSource = AudioBufferSource<float>;

    using Context = EnvelopeProcessorContext<float>;
    using Grain = EnvelopeProcessor<float, Context, AudioSource, Envelope>;
    using Sound = SoundObject<float, Grain, Context>;
    using Pool = DynamicPool<Sound, 4>;

    //using Engine = EngineTemplate<float, Grain, Pool, AudioObj, Context>;
    using Engine = SoundObjectEngine<float, Sound, Grain, Context, Pool>;
    using Controller = BufferedGranularController<float, Engine, Sound, AudioSource, Envelope>;

    Engine engine;
    Controller controller (engine);

    std::vector<float> fileVector;

    Buffer<float> fileBuffer (2, 1024, fileVector);

    for (int i=0; i<fileBuffer.size(); ++i)
    {
        const float r1 = ((float)std::rand() / (float)RAND_MAX) * 2 -1;
        fileBuffer.channel(0)[i] = r1;

        const float r2 = ((float)std::rand() / (float)RAND_MAX) * 2 -1;
        fileBuffer.channel(1)[i] = r2;
    }

    controller.setAudioBuffer(fileBuffer);

    for (int i = 0; i < n - blockSize; i += blockSize)
    {
        Buffer<float> buffer ( { &left[i], &right[i] }, numChannels, blockSize);

        controller.advance(blockSize);
        engine.addNextOutput(buffer);
    }


    std::cout << "\n    OUTPUT\n----------\n";

    for (int i=0; i<n; i++)
    {
        std::cout << i << ":\t" << left[i] << "\t" << right[i] << std::endl;
    }

    return 0;
}
#endif

#include "SafePool.hpp"


class Element
{
public:

    Element() : value(-1) {}
    Element(int v) : value(v) {}

    void print()
    {
        std::cout << value << std::endl;
    }

    int value;
};

int main()
{
    const int n = 4;
    SafePool<Element> pool;
    pool.reserve(8);

    for (int i=0; i<n; i++)
        pool.add((n-1-i)*10);

    std::cout << "After init\n";

    std::cout << "Iterate additions" << std::endl;
    //for (auto it = pool.begin(); it != pool.end(); ++it)
    for (auto it : pool)
    {
        if (it->value == 10)
        {
            pool.remove(it);
        }
        else
        {
            it->print();
        }
    }

    /*
    for (auto e : pool)
    {
        if (e->value == 10)
        {
            pool.remove(e);
        }<commit_msg>WIP initially working, need to use auto& in range-loop<commit_after>#include "PuroHeader.h"
#if 0

// TODO
// - Random deviation parameters for granulator
// - ints to size_ts where appropriate

int main()
{
    const int n = 256;
    const int blockSize = 32;
    const int numChannels = 2;

    std::vector<float> left (n, 0.0f);
    std::vector<float> right (n, 0.0f);

    using Envelope = SineEnvelope<float>;
    //using AudioSource = NoiseSource<float>;
    using AudioSource = AudioBufferSource<float>;

    using Context = EnvelopeProcessorContext<float>;
    using Grain = EnvelopeProcessor<float, Context, AudioSource, Envelope>;
    using Sound = SoundObject<float, Grain, Context>;
    using Pool = DynamicPool<Sound, 4>;

    //using Engine = EngineTemplate<float, Grain, Pool, AudioObj, Context>;
    using Engine = SoundObjectEngine<float, Sound, Grain, Context, Pool>;
    using Controller = BufferedGranularController<float, Engine, Sound, AudioSource, Envelope>;

    Engine engine;
    Controller controller (engine);

    std::vector<float> fileVector;

    Buffer<float> fileBuffer (2, 1024, fileVector);

    for (int i=0; i<fileBuffer.size(); ++i)
    {
        const float r1 = ((float)std::rand() / (float)RAND_MAX) * 2 -1;
        fileBuffer.channel(0)[i] = r1;

        const float r2 = ((float)std::rand() / (float)RAND_MAX) * 2 -1;
        fileBuffer.channel(1)[i] = r2;
    }

    controller.setAudioBuffer(fileBuffer);

    for (int i = 0; i < n - blockSize; i += blockSize)
    {
        Buffer<float> buffer ( { &left[i], &right[i] }, numChannels, blockSize);

        controller.advance(blockSize);
        engine.addNextOutput(buffer);
    }


    std::cout << "\n    OUTPUT\n----------\n";

    for (int i=0; i<n; i++)
    {
        std::cout << i << ":\t" << left[i] << "\t" << right[i] << std::endl;
    }

    return 0;
}
#endif

#include "SafePool.hpp"


class Element
{
public:

    Element() : value(-1) {}
    Element(int v) : value(v) {}

    void print()
    {
        std::cout << value << std::endl;
    }

    int value;
};

int main()
{
    const int n = 8;
    SafePool<Element> pool;
    pool.reserve(8);

    for (int i=0; i<n; i++)
        pool.add((n-1-i)*10);

    std::cout << "After init\n";

    std::cout << "Iterate additions, remove 10" << std::endl;

    for (auto& it : pool)
    {
        if (it->value == 10)
        {
            pool.remove(it);
        }
        else
        {
            it->print();
        }
    }

    std::cout << "Iterate active" << std::endl;
    for (auto& it : pool)
    {
        it->print();
    }

    std::cout << "Iterate active, remove 30" << std::endl;
    for (auto& it : pool)
    {
        if (it->value == 30)
        {
            pool.remove(it);
        }
        else
        {
            it->print();
        }
    }

    std::cout << "Iterate active" << std::endl;
    for (auto& it : pool)
    {
        it->print();
    }

    std::cout << "Add 100" << std::endl;

    pool.add(100);

    std::cout << "Iterate active and added" << std::endl;
    for (auto& it : pool)
    {
        it->print();
    }

    /*
    for (auto e : pool)
    {
        if (e->value == 10)
        {
            pool.remove(e);
        }
{'fraction_non_alphanumeric': 0.16275483981497343, 'fraction_numerical': 0.016446804865513105, 'mean_word_length': 2.2325581395348837, 'pattern_counts': {'":': 2, '<': 111, '<?xml version=': 0, '>': 46, 'https://': 0, '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': '7504833', 'n_tokens_mistral': 2058, 'n_tokens_neox': 1934, 'n_words': 493}