1 //-----------------------------------------------------------------------------
2 // LICENSE
3 // (c) 2005, Steinberg Media Technologies GmbH, All Rights Reserved
4 // (c) 2018, Guillaume Piolat (contact@auburnsounds.com)
5 //-----------------------------------------------------------------------------
6 // 
7 // This Software Development Kit is licensed under the terms of the General 
8 // Public License (GPL) Version 3.
9 // 
10 // Details of that license can be found at: www.gnu.org/licenses/gpl-3.0.html
11 //-----------------------------------------------------------------------------
12 module dplug.vst3.ivstcomponent;
13 
14 version(VST3):
15 
16 import dplug.vst3.ftypes;
17 import dplug.vst3.ipluginbase;
18 import dplug.vst3.ibstream;
19 
20 
21 
22 /** \defgroup vstBus VST Buses
23 Bus Description
24 
25 A bus can be understood as a "collection of data channels" belonging together.
26 It describes a data input or a data output of the Plug-in.
27 A VST component can define any desired number of buses, but this number must \b never change.
28 Dynamic usage of buses is handled in the host by activating and deactivating buses.
29 The component has to define the maximum number of supported buses and it has to
30 define which of them are active by default. A host that can handle multiple buses,
31 allows the user to activate buses that were initially inactive.
32 
33 See also: IComponent::getBusInfo, IComponent::activateBus
34 
35 @{*/
36 
37 /** Bus media types */
38 alias MediaTypes = int;
39 enum : MediaTypes
40 {
41     kAudio = 0,     ///< audio
42     kEvent,         ///< events
43     kNumMediaTypes
44 }
45 
46 /** Bus directions */
47 enum : BusDirection
48 {
49     kInput = 0,     ///< input bus
50     kOutput         ///< output bus
51 }
52 
53 /** Bus types */
54 alias BusTypes = int;
55 enum : BusTypes
56 {
57     kMain = 0,      ///< main bus
58     kAux            ///< auxiliary bus (sidechain)
59 }
60 
61 /** BusInfo:
62 This is the structure used with getBusInfo, informing the host about what is a specific given bus.
63 \n See also: IComponent::getBusInfo */
64 struct BusInfo
65 {
66 nothrow:
67 @nogc:
68     MediaType mediaType;    ///< Media type - has to be a value of \ref MediaTypes
69     BusDirection direction; ///< input or output \ref BusDirections
70     int32 channelCount;     ///< number of channels (if used then need to be recheck after \ref
71                             /// IAudioProcessor::setBusArrangements is called).
72                             /// For a bus of type MediaTypes::kEvent the channelCount corresponds
73                             /// to the number of supported MIDI channels by this bus
74     String128 name;         ///< name of the bus
75     BusType busType;        ///< main or aux - has to be a value of \ref BusTypes
76     uint32 flags;           ///< flags - a combination of \ref BusFlags
77     enum BusFlags
78     {
79         kDefaultActive = 1 << 0 ///< bus active per default
80     }
81 
82     void setName(wstring newName)
83     {
84         name[] = '\0';
85         int len = cast(int)(newName.length);
86         if (len > 127) len = 127;
87         name[0..len] = newName[0..len];
88     }
89 }
90 
91 mixin SMTG_TYPE_SIZE_CHECK!(BusInfo, 276, 276, 276);
92 
93 /** I/O modes */
94 alias IoModes = int;
95 enum : IoModes
96 {
97     kSimple = 0,        ///< 1:1 Input / Output. Only used for Instruments. See \ref vst3IoMode
98     kAdvanced,          ///< n:m Input / Output. Only used for Instruments.
99     kOfflineProcessing  ///< Plug-in used in an offline processing context
100 }
101 
102 /** Routing Information:
103 When the Plug-in supports multiple I/O buses, a host may want to know how the buses are related. The
104 relation of an event-input-channel to an audio-output-bus in particular is of interest to the host
105 (in order to relate MIDI-tracks to audio-channels)
106 \n See also: IComponent::getRoutingInfo, \ref vst3Routing */
107 struct RoutingInfo
108 {
109     MediaType mediaType;    ///< media type see \ref MediaTypes
110     int32 busIndex;         ///< bus index
111     int32 channel;          ///< channel (-1 for all channels)
112 }
113 
114 mixin SMTG_TYPE_SIZE_CHECK!(RoutingInfo, 12, 12, 12);
115 
116 // IComponent Interface
117 /** Component Base Interface
118 \ingroup vstIPlug vst300
119 - [plug imp]
120 - [released: 3.0.0]
121 - [mandatory]
122 
123 This is the basic interface for a VST component and must always be supported.
124 It contains the common parts of any kind of processing class. The parts that
125 are specific to a media type are defined in a separate interface. An implementation
126 component must provide both the specific interface and IComponent.
127 */
128 interface IComponent: IPluginBase
129 {
130 public:
131 nothrow:
132 @nogc:
133     /** Called before initializing the component to get information about the controller class. */
134     tresult getControllerClassId (TUID* classId);
135 
136     /** Called before 'initialize' to set the component usage (optional). See \ref IoModes */
137     tresult setIoMode (IoMode mode);
138 
139     /** Called after the Plug-in is initialized. See \ref MediaTypes, BusDirections */
140     int32 getBusCount (MediaType type, BusDirection dir);
141 
142     /** Called after the Plug-in is initialized. See \ref MediaTypes, BusDirections */
143     tresult getBusInfo (MediaType type, BusDirection dir, int32 index, ref BusInfo bus /*out*/);
144 
145     /** Retrieves routing information (to be implemented when more than one regular input or output bus exists).
146         The inInfo always refers to an input bus while the returned outInfo must refer to an output bus! */
147     tresult getRoutingInfo (ref RoutingInfo inInfo, ref RoutingInfo outInfo /*out*/);
148 
149     /** Called upon (de-)activating a bus in the host application. The Plug-in should only processed an activated bus,
150         the host could provide less see \ref AudioBusBuffers in the process call (see \ref IAudioProcessor::process) if last buses are not activated */
151     tresult activateBus (MediaType type, BusDirection dir, int32 index, TBool state);
152 
153     /** Activates / deactivates the component. */
154     tresult setActive (TBool state);
155 
156     /** Sets complete state of component. */
157     tresult setState (IBStream state);
158 
159     /** Retrieves complete state of component. */
160     tresult getState (IBStream state);
161 
162     __gshared immutable TUID iid = INLINE_UID(0xE831FF31, 0xF2D54301, 0x928EBBEE, 0x25697802);
163 }
164