File: PluginDesc.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 (218 lines) | stat: -rw-r--r-- 5,821 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#pragma once

#include "Interface.h"
#include "HashTable.h"

#include <assert.h>

namespace vst {

class PluginDesc final {
public:
    static const uint32_t NoParamID = 0xffffffff;

    using ptr = std::shared_ptr<PluginDesc>;
    using const_ptr = std::shared_ptr<const PluginDesc>;

    PluginDesc(std::shared_ptr<const IFactory> f);
    ~PluginDesc();
    PluginDesc(const PluginDesc&) = delete;
    void operator =(const PluginDesc&) = delete;

    void setFactory(std::shared_ptr<const IFactory> factory);
    const std::string& path() const { return path_; }
    CpuArch arch() const;
    // create new instances
    // throws an Error exception on failure!
    IPlugin::ptr create(bool editor, bool threaded, RunMode mode = RunMode::Auto) const;
    // read/write plugin description
    void serialize(std::ostream& file) const;
    void deserialize(std::istream& file, int versionMajor = VERSION_MAJOR,
                     int versionMinor = VERSION_MINOR, int versionPatch = VERSION_PATCH);
#if USE_VST2
    void setUniqueID(int _id); // VST2
    int getUniqueID() const {
        return id_.id;
    }
#endif
#if USE_VST3
    void setUID(const char *uid); // VST3
    const char* getUID() const {
        return id_.uid;
    }
#endif
    struct SubPlugin {
        std::string name;
        int id;
    };
    using SubPluginList = std::vector<SubPlugin>;
    SubPluginList subPlugins;

    PluginType type() const { return type_; }

    std::string key() const {
        if (type_ == PluginType::VST3){
            // VST3: plug-in name + ".vst3"
            return name + ".vst3";
        } else {
            // VST2: plug-in name
            return name;
        }
    }
    // info data
    std::string uniqueID;
    std::string name;
    std::string vendor;
    std::string category;
    std::string version;
    std::string sdkVersion;

    struct Bus {
        enum Type {
            Main = 0,
            Aux
        };
        int numChannels = 0;
        Type type = Main;
        std::string label;
    };

    std::vector<Bus> inputs;
    int numInputs() const {
        return inputs.size();
    }

    std::vector<Bus> outputs;
    int numOutputs() const {
        return outputs.size();
    }

#if USE_VST3
    uint32_t programChange = NoParamID; // no param
    uint32_t bypass = NoParamID; // no param
#endif
    // parameters
    struct Param {
        std::string name;
        std::string label;
        uint32_t id = 0;
        bool automatable = true;
    };
    std::vector<Param> parameters;

    void addParameter(Param param);
    void addParamAlias(int index, std::string_view key);

    // returns -1 if the parameter is not found
    int findParam(std::string_view key) const {
        return paramMap_.findOr(key, -1);
    }
    int numParameters() const {
        return parameters.size();
    }
#if USE_VST3
    // get VST3 parameter ID from index
    uint32_t getParamID(int index) const {
        auto result = indexToIdMap_.find(index);
        assert(result); // throw?
        return *result;
    }
    // get index from VST3 parameter ID
    // returns -1 if the parameter is not found (not automatable)
    int getParamIndex(uint32_t id) const {
        return idToIndexMap_.findOr(id, -1);
    }
#endif
    // presets
    void scanPresets();
    int numPresets() const { return presets.size(); }
    int findPreset(std::string_view name) const;
    Preset makePreset(std::string_view name, PresetType type = PresetType::User) const;
    int addPreset(Preset preset);
    bool removePreset(int index, bool del = true);
    bool renamePreset(int index, std::string_view newName);
    std::string getPresetFolder(PresetType type, bool create = false) const;
    PresetList presets;
    // default programs
    std::vector<std::string> programs;
    int numPrograms() const {
        return programs.size();
    }
    // flags
    enum Flags {
        HasEditor = 1 << 0,
        IsSynth = 1 << 1,
        SinglePrecision = 1 << 2,
        DoublePrecision = 1 << 3,
        MidiInput = 1 << 4,
        MidiOutput = 1 << 5,
        SysexInput = 1 << 6,
        SysexOutput = 1 << 7,
        Bridged = 1 << 8,
        EditorResizable = 1 << 9
    };
    bool editor() const {
        return flags & HasEditor;
    }
    bool editorResizable() const {
        return flags & EditorResizable;
    }
    bool synth() const {
        return flags & IsSynth;
    }
    bool singlePrecision() const {
        return flags & SinglePrecision;
    }
    bool doublePrecision() const {
        return flags & DoublePrecision;
    }
    bool hasPrecision(ProcessPrecision precision) const {
        if (precision == ProcessPrecision::Double) {
            return doublePrecision();
        }
        else {
            return singlePrecision();
        }
    }
    bool midiInput() const {
        return flags & MidiInput;
    }
    bool midiOutput() const {
        return flags & MidiOutput;
    }
    bool sysexInput() const {
        return flags & SysexInput;
    }
    bool sysexOutput() const {
        return flags & SysexOutput;
    }
    bool bridged() const {
        return flags & Bridged;
    }
    uint32_t flags = 0;
#if WARN_VST3_PARAMETERS
    bool warnParameters = false;
#endif
 private:
    std::weak_ptr<const IFactory> factory_;
    std::string path_;
    // param name -> param index mapping
    HashTable<std::string, int, std::string_view> paramMap_;
#if USE_VST3
    // param index to ID (VST3 only)
    HashTable<int, uint32_t> indexToIdMap_;
    // param ID to index (VST3 only)
    HashTable<uint32_t, int> idToIndexMap_;
#endif
    PluginType type_;
    union ID {
        char uid[16];
        int32_t id;
    };
    ID id_;
    // helper methods
    void sortPresets(bool userOnly = true);
    mutable bool didCreatePresetFolder = false;
};

} // vst