iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IPlugCocoaViewController.mm
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#import "IPlugCocoaViewController.h"
13#include "IPlugStructs.h"
14
15using namespace iplug;
16
17@implementation IPlugCocoaViewController
18
19- (id) initWithEditorDelegateAndBundleID: (void*) _editorDelegate : (const char*) _bundleID
20{
21 if (self = [super init]) {
22 editorDelegate = _editorDelegate;
23 bundleID = [NSString stringWithUTF8String:_bundleID];
24 }
25 return self;
26}
27
28- (void) setEditorDelegate: (void*) _editorDelegate
29{
30 editorDelegate = _editorDelegate;
31}
32
33- (BOOL) onMessage: (NSInteger) msgTag : (NSInteger) ctrlTag : (NSData*) msg
34{
35 return FALSE;
36}
37
38- (void) onParamChangeUI: (NSInteger) paramIdx : (double) value
39{
40 //NO-OP
41}
42
43- (void) onMidiMsgUI: (UInt8) status : (UInt8) data1 : (UInt8) data2 : (NSInteger) offset
44{
45 //NO-OP
46}
47
48- (void) onSysexMsgUI: (NSData*) msg : (NSInteger) offset
49{
50 //NO-OP
51}
52
53- (void) sendControlValueFromDelegate: (NSInteger) ctrlTag : (double) normalizedValue
54{
55 //NO-OP
56}
57
58- (void) sendControlMsgFromDelegate: (NSInteger) ctrlTag : (NSInteger) msgTag : (NSData*) msg
59{
60 //NO-OP
61}
62
63- (void) sendParameterValueFromDelegate: (NSInteger) paramIdx : (double) value : (BOOL) normalized
64{
65 [self onParamChangeUI: paramIdx : value];
66}
67
68-(void) sendParameterValueFromUI: (NSInteger) paramIdx : (double) value
69{
70 ((CocoaEditorDelegate*) editorDelegate)->SendParameterValueFromUI(static_cast<int>(paramIdx), value);
71}
72
73-(void) beginInformHostOfParamChangeFromUI: (NSInteger) paramIdx
74{
75 ((CocoaEditorDelegate*) editorDelegate)->BeginInformHostOfParamChangeFromUI(static_cast<int>(paramIdx));
76}
77
78-(void) endInformHostOfParamChangeFromUI: (NSInteger) paramIdx
79{
80 ((CocoaEditorDelegate*) editorDelegate)->EndInformHostOfParamChangeFromUI(static_cast<int>(paramIdx));
81}
82
83-(void) sendArbitraryMsgFromUI: (NSInteger) msgTag : (NSInteger) ctrlTag : (NSData*) msg
84{
85 ((CocoaEditorDelegate*) editorDelegate)->SendArbitraryMsgFromUI(static_cast<int>(msgTag), static_cast<int>(ctrlTag), static_cast<int>([msg length]), [msg bytes]);
86}
87
88-(void) sendMidiMsgFromUI: (UInt8) status : (UInt8) data1 : (UInt8) data2 : (NSInteger) offset
89{
90 IMidiMsg msg { static_cast<int>(offset), status, data1, data2 };
91 ((CocoaEditorDelegate*) editorDelegate)->SendMidiMsgFromUI(msg);
92}
93
94-(void) sendSysexMsgFromUI: (NSData*) msg : (NSInteger) offset
95{
96 ISysEx smsg { static_cast<int>(offset), reinterpret_cast<const uint8_t*>([msg bytes]), static_cast<int>([msg length]) };
97 ((CocoaEditorDelegate*) editorDelegate)->SendSysexMsgFromUI(smsg);
98}
99
100- (NSInteger) parameterCount
101{
102 return ((CocoaEditorDelegate*) editorDelegate)->NParams();
103}
104
105- (NSString*) getParameterName: (NSInteger) paramIdx
106{
107 NSString* name = [NSString stringWithUTF8String:((CocoaEditorDelegate*) editorDelegate)->GetParam(static_cast<int>(paramIdx))->GetName()];
108 return name;
109}
110
111- (double) getParameterDefault: (NSInteger) paramIdx
112{
113 return ((CocoaEditorDelegate*) editorDelegate)->GetParam(static_cast<int>(paramIdx))->GetDefault();
114}
115
116- (double) getParameterMin: (NSInteger) paramIdx
117{
118 return ((CocoaEditorDelegate*) editorDelegate)->GetParam(static_cast<int>(paramIdx))->GetMin();
119}
120
121- (double) getParameterMax: (NSInteger) paramIdx
122{
123 return ((CocoaEditorDelegate*) editorDelegate)->GetParam(static_cast<int>(paramIdx))->GetMax();
124}
125
126- (double) getParameterStep: (NSInteger) paramIdx
127{
128 return ((CocoaEditorDelegate*) editorDelegate)->GetParam(static_cast<int>(paramIdx))->GetStep();
129}
130
131- (NSString*) getParameterLabel: (NSInteger) paramIdx
132{
133 NSString* label = [NSString stringWithUTF8String:((CocoaEditorDelegate*) editorDelegate)->GetParam(static_cast<int>(paramIdx))->GetLabel()];
134 return label;
135}
136
137- (NSString*) getParameterGroup: (NSInteger) paramIdx
138{
139 NSString* group = [NSString stringWithUTF8String:((CocoaEditorDelegate*) editorDelegate)->GetParam(static_cast<int>(paramIdx))->GetGroup()];
140 return group;
141}
142
143- (NSInteger) getParameterNumDisplayTexts:(NSInteger)paramIdx
144{
145 if (paramIdx < 0 || paramIdx >= [self parameterCount]) {
146 return 0;
147 }
148
149 IParam* pParam = ((CocoaEditorDelegate*) editorDelegate)->GetParam(static_cast<int>(paramIdx));
150 return pParam->NDisplayTexts();
151}
152
153- (NSString*) getParameterDisplayText:(NSInteger)paramIdx
154 index:(NSInteger)displayIndex
155{
156 if (paramIdx < 0 || paramIdx >= [self parameterCount]) {
157 return @"";
158 }
159
160 IParam* pParam = ((CocoaEditorDelegate*) editorDelegate)->GetParam(static_cast<int>(paramIdx));
161
162 // We don’t care about the numeric value here,
163 // but we have to call GetDisplayTextAtIdx:
164 double dummyValue = 0.0;
165 const char* text = pParam->GetDisplayTextAtIdx(static_cast<int>(displayIndex), &dummyValue);
166
167 if (!text) {
168 return @"";
169 }
170 return [NSString stringWithUTF8String:text];
171}
172
173- (double) getParameterDisplayTextValue:(NSInteger)paramIdx
174 index:(NSInteger)displayIndex
175{
176 if (paramIdx < 0 || paramIdx >= [self parameterCount]) {
177 return 0.0;
178 }
179
180 IParam* pParam = ((CocoaEditorDelegate*) editorDelegate)->GetParam(static_cast<int>(paramIdx));
181
182 double outVal = 0.0;
183 pParam->GetDisplayTextAtIdx(static_cast<int>(displayIndex), &outVal);
184 return outVal;
185}
186
187- (int) getParameterFlags:(NSInteger) paramIdx
188{
189 if (paramIdx < 0 || paramIdx >= [self parameterCount]) {
190 return 0;
191 }
192
193 IParam* pParam = ((CocoaEditorDelegate*) editorDelegate)->GetParam(static_cast<int>(paramIdx));
194 return pParam->GetFlags();
195}
196
197- (int) getParameterShapeID:(NSInteger)paramIdx
198{
199 if (paramIdx < 0 || paramIdx >= [self parameterCount]) {
200 return -1;
201 }
202 IParam* pParam = ((CocoaEditorDelegate*) editorDelegate)->GetParam(static_cast<int>(paramIdx));
203
204 return pParam->GetShapeID();
205}
206
207- (double) getParameterShapeValue:(NSInteger)paramIdx
208{
209 if (paramIdx < 0 || paramIdx >= [self parameterCount]) {
210 return 0.0;
211 }
212 IParam* pParam = ((CocoaEditorDelegate*) editorDelegate)->GetParam(static_cast<int>(paramIdx));
213
214 return pParam->GetShapeValue();
215}
216
217
218- (void) setBundleID: (const char *) _bundleID
219{
220 bundleID = [NSString stringWithUTF8String:_bundleID];
221}
222
223- (NSString*) getBundleID
224{
225 return bundleID;
226}
227
228@end
An editor delegate base class that uses Apple frameworks for the UI, either in Objective C,...
IPlug's parameter class.
int GetFlags() const
Returns the parameter's flags.
const char * GetDisplayTextAtIdx(int idx, double *pValue=nullptr) const
Get the display text at a particular index.
double GetShapeValue() const
int NDisplayTexts() const
Get the number of display texts for the parameter.
EShapeIDs GetShapeID() const
An objc view controller base which reproduces some functionality from EditorDelegate in objc.
Encapsulates a MIDI message and provides helper functions.
Definition: IPlugMidi.h:31
A struct for dealing with SysEx messages.
Definition: IPlugMidi.h:539