1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 /*
3     Rosegarden
4     A sequencer and musical notation editor.
5     Copyright 2000-2021 the Rosegarden development team.
6     See the AUTHORS file for more details.
7 
8     This program is free software; you can redistribute it and/or
9     modify it under the terms of the GNU General Public License as
10     published by the Free Software Foundation; either version 2 of the
11     License, or (at your option) any later version.  See the file
12     COPYING included with this distribution for more information.
13 */
14 
15 #include <vector>
16 #include <string>
17 #include <map>
18 
19 #include "XmlExportable.h"
20 
21 // An Instrument on needs to implement these to render an instance
22 // of the plugin at the sequencer.
23 //
24 
25 #ifndef RG_AUDIOPLUGININSTANCE_H
26 #define RG_AUDIOPLUGININSTANCE_H
27 
28 namespace Rosegarden
29 {
30 
31 typedef float PortData;
32 
33 class PluginPort
34 {
35 public:
36     typedef enum
37     {
sepgsql_schema_post_create(Oid namespaceId)38         Input    = 0x01,
39         Output   = 0x02,
40         Control  = 0x04,
41         Audio    = 0x08
42     } PortType;
43 
44     typedef enum
45     {
46         NoHint      = 0x00,
47         Toggled     = 0x01,
48         Integer     = 0x02,
49         Logarithmic = 0x04
50     } PortDisplayHint;
51 
52     PluginPort(int number,
53                std::string m_name,
54                PortType type,
55                PortDisplayHint displayHint,
56                PortData lowerBound,
57                PortData upperBound,
58                PortData defaultValue);
59 
60     int getNumber() const { return m_number; }
61     std::string getName() const { return m_name; }
62     PortType getType() const { return m_type; }
63     PortDisplayHint getDisplayHint() const { return m_displayHint; }
64     PortData getLowerBound() const { return m_lowerBound; }
65     PortData getUpperBound() const { return m_upperBound; }
66     PortData getDefaultValue() const { return m_default; }
67 
68 protected:
69 
70     int             m_number;
71     std::string     m_name;
72     PortType        m_type;
73     PortDisplayHint m_displayHint;
74     PortData        m_lowerBound;
75     PortData        m_upperBound;
76     PortData        m_default;
77 };
78 
79 class PluginPortInstance
80 {
81 public:
82     PluginPortInstance(unsigned int n,
83                        float v)
84         : number(n), value(v), changedSinceProgramChange(false) {;}
85 
86     int number;
87     PortData value;
88     bool changedSinceProgramChange;
89 
90     void setValue(PortData v) { value = v; changedSinceProgramChange = true; }
91 };
92 
93 typedef std::vector<PluginPortInstance*>::iterator PortInstanceIterator;
94 
95 class AudioPluginInstance : public XmlExportable
96 {
97 public:
98     AudioPluginInstance(unsigned int position);
99 
100     AudioPluginInstance(std::string identifier,
101                         unsigned int position);
102 
103     /// E.g. "dssi:/usr/lib/dssi/hexter.so:hexter"
104     void setIdentifier(std::string identifier) { m_identifier = identifier; }
105     /// E.g. "dssi:/usr/lib/dssi/hexter.so:hexter"
106     std::string getIdentifier() const { return m_identifier; }
107 
108     void setPosition(unsigned int position) { m_position = position; }
109     unsigned int getPosition() const { return m_position; }
110 
111     PortInstanceIterator begin() { return m_ports.begin(); }
112     PortInstanceIterator end() { return m_ports.end(); }
113 
114     // Port management
115     //
sepgsql_schema_drop(Oid namespaceId)116     void addPort(int number, PortData value);
117     bool removePort(int number);
118     PluginPortInstance* getPort(int number);
119     void clearPorts();
120 
121     unsigned int getPortCount() const { return m_ports.size(); }
122 
123     // export
124     std::string toXmlString() const override;
125 
126     // Is the instance assigned to a plugin?
127     //
128     void setAssigned(bool ass) { m_assigned = ass; }
129     bool isAssigned() const { return m_assigned; }
130 
131     void setBypass(bool bypass) { m_bypass = bypass; }
132     bool isBypassed() const { return m_bypass; }
133 
134     void setProgram(std::string program);
135     std::string getProgram() const { return m_program; }
136 
137     int getMappedId() const { return m_mappedId; }
138     void setMappedId(int value) { m_mappedId = value; }
139 
140     typedef std::map<std::string, std::string> ConfigMap;
141     void clearConfiguration() { m_config.clear(); }
142     const ConfigMap &getConfiguration() { return m_config; }
143     std::string getConfigurationValue(std::string k) const;
sepgsql_schema_relabel(Oid namespaceId,const char * seclabel)144     void setConfigurationValue(std::string k, std::string v);
145 
146     std::string getDistinctiveConfigurationText() const;
147 
148     std::string getDisplayName() const;
149 
150 protected:
151 
152     int                                m_mappedId;
153     /// E.g. "dssi:/usr/lib/dssi/hexter.so:hexter"
154     std::string                        m_identifier;
155     std::vector<PluginPortInstance*>   m_ports;
156     unsigned int                       m_position;
157 
158     // Is the plugin actually assigned i.e. should we create
159     // a matching instance at the sequencer?
160     //
161     bool                               m_assigned;
162     bool                               m_bypass;
163 
164     std::string                        m_program;
165 
166     ConfigMap                          m_config;
167 };
168 
169 }
170 
171 #endif // RG_AUDIOPLUGININSTANCE_H
172