File: PluginFactory.h

package info (click to toggle)
pd-vstplugin 0.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,008 kB
  • sloc: cpp: 22,794; lisp: 2,860; makefile: 37; sh: 26
file content (56 lines) | stat: -rw-r--r-- 1,869 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once

#include "Interface.h"
#include "PluginDesc.h"
#include "CpuArch.h"
#include "HostApp.h"

// for testing we don't want to load hundreds of sub plugins
// #define PLUGIN_LIMIT 50

// We probe sub-plugins asynchronously with "futures".
// Each future spawns a subprocess and then waits for the results.
#define PROBE_FUTURES 8 // max. number of futures to wait for

// The sleep interval when probing several plugins in a factory asynchronously
#define PROBE_SLEEP_MS 2

namespace vst {

class PluginFactory :
        public std::enable_shared_from_this<PluginFactory>,
        public IFactory
{
 public:
    PluginFactory(const std::string& path);
    virtual ~PluginFactory(){}

    PluginFactory(const PluginFactory&) = delete;
    PluginFactory(PluginFactory&&) = delete;

    ProbeFuture probeAsync(float timeout, bool nonblocking) override;

    void addPlugin(PluginDesc::ptr desc) override;
    PluginDesc::const_ptr getPlugin(int index) const override;
    PluginDesc::const_ptr findPlugin(const std::string& name) const override;
    int numPlugins() const override;

    const std::string& path() const override { return path_; }
    CpuArch arch() const override { return arch_; }
 protected:
    using ProbeResultFuture = std::function<bool(ProbeResult&)>;
    ProbeResultFuture doProbePlugin(float timeout, bool nonblocking);
    ProbeResultFuture doProbePlugin(const PluginDesc::SubPlugin& subplugin,
                                    float timeout, bool nonblocking);
    std::vector<PluginDesc::ptr> doProbePlugins(
            const PluginDesc::SubPluginList& pluginList,
            float timeout, ProbeCallback callback);
    // data
    std::string path_;
    CpuArch arch_;
    std::unique_ptr<IModule> module_;
    std::vector<PluginDesc::ptr> plugins_;
    std::unordered_map<std::string, PluginDesc::ptr> pluginMap_;
};

} // vst