<commit_before>// Copyright 2012-2013 Samplecount S.L.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef METHCLA_AUDIO_SYNTHDEF_HPP_INCLUDED
#define METHCLA_AUDIO_SYNTHDEF_HPP_INCLUDED

#include <methcla/engine.h>
#include <methcla/plugin.h>

#include "Methcla/Plugin/Loader.hpp"
#include "Methcla/Utility/Hash.hpp"

#include <boost/utility.hpp>
#include <cstring>
#include <list>
#include <memory>
#include <oscpp/server.hpp>
#include <string>
#include <unordered_map>
#include <vector>

namespace Methcla { namespace Audio {

// class Port
// {
// public:
//     Port(Methcla_PortDescriptor port, uint32_t index, const char* symbol="")
//         : m_port(port)
//         , m_index(index)
//         , m_symbol(symbol)
//     { }
// 
//     Methcla_PortType type() const { return m_port.type; }
//     Methcla_PortDirection direction() const { return m_port.direction; }
//     uint32_t index() const { return m_index; }
//     const char* symbol() const { return m_symbol.c_str(); }
// 
// private:
//     Methcla_PortDescriptor    m_port;
//     uint32_t        m_index;
//     std::string     m_symbol;
// };

class Synth;

class SynthDef : boost::noncopyable
{
public:
    SynthDef(const Methcla_SynthDef* def);
    ~SynthDef();

    inline const char* uri() const { return m_descriptor->uri; }

    inline size_t instanceSize () const { return m_descriptor->instance_size; }

    // inline size_t numPorts() const { return m_ports.size(); }
    // inline const Port& port(size_t i) const { return m_ports.at(i); }
    // 
    // inline size_t numAudioInputs    () const { return m_numAudioInputs;    }
    // inline size_t numAudioOutputs   () const { return m_numAudioOutputs;   }
    // inline size_t numControlInputs  () const { return m_numControlInputs;  }
    // inline size_t numControlOutputs () const { return m_numControlOutputs; }

    // NOTE: Uses static data and should only be called from a single thread (normally the audio thread) at a time.
    const Methcla_SynthOptions* configure(OSCPP::Server::ArgStream options) const;

    //* Return port descriptor at index.
    bool portDescriptor(const Methcla_SynthOptions* options, size_t index, Methcla_PortDescriptor* port) const;

    void construct(const Methcla_World* world, const Methcla_SynthOptions* options, Synth* owner, Methcla_Synth* synth) const;
    void destroy(const Methcla_World* world, Methcla_Synth* synth) const;

    inline void connect(Methcla_Synth* synth, Methcla_PortCount port, void* data) const
    {
        m_descriptor->connect(synth, port, data);
    }

    inline void activate(const Methcla_World* world, Methcla_Synth* synth) const
    {
        if (m_descriptor->activate) m_descriptor->activate(world, synth);
    }

    inline void process(const Methcla_World* world, Methcla_Synth* synth, size_t numFrames) const
    {
        m_descriptor->process(world, synth, numFrames);
    }

private:
    const Methcla_SynthDef* m_descriptor;
    Methcla_SynthOptions*   m_options; // Only access from one thread
    // std::vector<Port>       m_ports;
    // size_t                  m_numAudioInputs;
    // size_t                  m_numAudioOutputs;
    // size_t                  m_numControlInputs;
    // size_t                  m_numControlOutputs;
};

typedef std::unordered_map<const char*,
                           std::shared_ptr<SynthDef>,
                           Utility::Hash::cstr_hash,
                           Utility::Hash::cstr_equal>
        SynthDefMap;

//* Plugin library.
class PluginLibrary : boost::noncopyable
{
public:
    PluginLibrary(const Methcla_Library* lib, std::shared_ptr<Methcla::Plugin::Library> plugin=nullptr);
    ~PluginLibrary();

private:
    const Methcla_Library*                      m_lib;
    std::shared_ptr<Methcla::Plugin::Library>   m_plugin;
};

class PluginManager : boost::noncopyable
{
public:
    //* Load plugins from static functions.
    void loadPlugins(const Methcla_Host* host, const std::list<Methcla_LibraryFunction>& funcs);<commit_msg>Remove stale code<commit_after>// Copyright 2012-2013 Samplecount S.L.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef METHCLA_AUDIO_SYNTHDEF_HPP_INCLUDED
#define METHCLA_AUDIO_SYNTHDEF_HPP_INCLUDED

#include <methcla/engine.h>
#include <methcla/plugin.h>

#include "Methcla/Plugin/Loader.hpp"
#include "Methcla/Utility/Hash.hpp"

#include <boost/utility.hpp>
#include <cstring>
#include <list>
#include <memory>
#include <oscpp/server.hpp>
#include <string>
#include <unordered_map>

namespace Methcla { namespace Audio {

class Synth;

class SynthDef : boost::noncopyable
{
public:
    SynthDef(const Methcla_SynthDef* def);
    ~SynthDef();

    inline const char* uri() const { return m_descriptor->uri; }

    inline size_t instanceSize () const { return m_descriptor->instance_size; }

    // NOTE: Uses static data and should only be called from a single thread (normally the audio thread) at a time.
    const Methcla_SynthOptions* configure(OSCPP::Server::ArgStream options) const;

    //* Return port descriptor at index.
    bool portDescriptor(const Methcla_SynthOptions* options, size_t index, Methcla_PortDescriptor* port) const;

    void construct(const Methcla_World* world, const Methcla_SynthOptions* options, Synth* owner, Methcla_Synth* synth) const;
    void destroy(const Methcla_World* world, Methcla_Synth* synth) const;

    inline void connect(Methcla_Synth* synth, Methcla_PortCount port, void* data) const
    {
        m_descriptor->connect(synth, port, data);
    }

    inline void activate(const Methcla_World* world, Methcla_Synth* synth) const
    {
        if (m_descriptor->activate) m_descriptor->activate(world, synth);
    }

    inline void process(const Methcla_World* world, Methcla_Synth* synth, size_t numFrames) const
    {
        m_descriptor->process(world, synth, numFrames);
    }

private:
    const Methcla_SynthDef* m_descriptor;
    Methcla_SynthOptions*   m_options; // Only access from one thread
};

typedef std::unordered_map<const char*,
                           std::shared_ptr<SynthDef>,
                           Utility::Hash::cstr_hash,
                           Utility::Hash::cstr_equal>
        SynthDefMap;

//* Plugin library.
class PluginLibrary : boost::noncopyable
{
public:
    PluginLibrary(const Methcla_Library* lib, std::shared_ptr<Methcla::Plugin::Library> plugin=nullptr);
    ~PluginLibrary();

private:
    const Methcla_Library*                      m_lib;
    std::shared_ptr<Methcla::Plugin::Library>   m_plugin;
};

class PluginManager : boost::noncopyable
{
public:
    //* Load plugins from static functions.
    void loadPlugins(const Methcla_Host* host, const std::list<Methcla_LibraryFunction>& funcs);
{'fraction_non_alphanumeric': 0.10251775338928341, 'fraction_numerical': 0.003873466752743706, 'mean_word_length': 3.3861834654586636, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2255359', 'n_tokens_mistral': 2534, 'n_tokens_neox': 2391, 'n_words': 658}