ReverbEdit.c++
11.1 KB
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*******************************************************************************
* File: ReverbEdit.c
*
* Impliments the gui for the reverb editor portion of midiDmon.
*
******************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <Xm/Xm.h>
#include <Xm/Label.h>
#include <Xm/ToggleB.h>
#include <Xm/RowColumn.h>
#include <Xm/Separator.h>
#include <Xm/Form.h>
#include <Xm/Scale.h>
#include <Xm/MainW.h>
#include "Editor.h"
#include "EditMgr.h"
#include "Mgrs.h"
static char noFXStr[] = "Sorry, no effects were specified in the config file";
static char* paramNames[] = { "input",
"output",
"fbcoef",
"ffcoef",
"gain",
"chorus rate",
"chorus depth",
"lpfilt" };
#define INPUT_PARAM 0
#define OUPUT_PARAM 1
#define FBCOEF_PARAM 2
#define FFCOEF_PARAM 3
#define GAIN_PARAM 4
#define C_RATE_PARAM 5
#define C_DEPTH_PARAM 6
#define LPFILT_PARAM 7
/* Callbacks */
static void param_section_cb(Widget w, XtPointer client_data, XmAnyCallbackStruct *call_data);
static void param_value_cb(Widget w, XtPointer client_data, XmScaleCallbackStruct *call_data);
static void destroy_editor_cb(Widget w, XtPointer client_data, XmAnyCallbackStruct *call_data);
static void destroy_item_cb(Widget w, XtPointer client_data, XmAnyCallbackStruct *call_data);
/******************************************************************************
*
* Init the Reverb Editor's gui.
* 1) create the shell widget
* 2) create the row column widget for selecting the primatives
* 3) add the toggle buttons for the primatives
* 4) create the separator widget
* 5) create the row column widget for the scale widgets
* 6) create the scale widgets with their labels
*
******************************************************************************/
ReverbEditor::ReverbEditor(void *theEdMgr, Display *display)
{
Widget theForm, sep1Widg;
Widget butRowCol, tog;
Widget scaleRowCol;
Widget label[NUM_FX_PARAMS];
int i,n;
int paramID;
Arg args[8];
XmString xms;
AEItemRef *itemRef;
char numStr[6];
s32 paramVal,delaySize;
reverbAsset = theAssetMgr->GetReverb();
shellWidget = XtVaAppCreateShell("ReverbEditor", "XReverbEditor",
topLevelShellWidgetClass, display, NULL);
XtAddCallback(shellWidget, XmNdestroyCallback, destroy_editor_cb, (XtPointer)theEdMgr);
if(reverbAsset && reverbAsset->GetParam(0, &numFxSets))
{
curParamSet = 0;
theForm = XtVaCreateManagedWidget("ReverbForm", xmFormWidgetClass, shellWidget, NULL);
butRowCol = XtVaCreateManagedWidget("OneOfMany", xmRowColumnWidgetClass, theForm,
XmNorientation, XmVERTICAL,
XmNradioBehavior, TRUE,
XmNradioAlwaysOne, TRUE,
XmNleftAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
/* Add the ToggleButton widgets */
for(i = 0; i < numFxSets; i++)
{
sprintf(numStr,"%d",i);
xms = XmStringCreateLtoR(numStr, XmSTRING_DEFAULT_CHARSET);
if(i == 0)
tog = XtVaCreateManagedWidget("TButton", xmToggleButtonWidgetClass, butRowCol,
XmNset, TRUE,
XmNlabelString, xms,
NULL);
else
tog = XtVaCreateManagedWidget("TButton", xmToggleButtonWidgetClass, butRowCol,
XmNlabelString, xms,
NULL);
itemRef = (AEItemRef*)malloc(sizeof(AEItemRef));
itemRef->item = i;
itemRef->editor = this;
XtAddCallback(tog, XmNvalueChangedCallback, param_section_cb, (XtPointer)itemRef);
XtAddCallback(tog, XmNdestroyCallback, destroy_item_cb, (XtPointer)itemRef);
XmStringFree(xms);
}
sep1Widg = XtVaCreateManagedWidget("Separator", xmSeparatorWidgetClass, theForm,
XmNorientation, XmVERTICAL,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, butRowCol,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
scaleRowCol = XtVaCreateManagedWidget("ScaleRowCol", xmRowColumnWidgetClass, theForm,
XmNorientation, XmVERTICAL,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, sep1Widg,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL);
/* Add the scale widgets */
if(!reverbAsset->GetParam(1, &delaySize))
delaySize = 44100; /* pick a default of one second at 44100 */
paramID = (curParamSet * NUM_FX_PARAMS) + FX_PARAM_OFFSET;
for(i = 0; i < NUM_FX_PARAMS; i++, paramID++)
{
if(!reverbAsset->GetParam(paramID,¶mVal))
paramVal = 0;
xms = XmStringCreateLtoR(paramNames[i], XmSTRING_DEFAULT_CHARSET);
label[i] = XtVaCreateManagedWidget("Label", xmLabelWidgetClass, scaleRowCol,
XmNlabelString, xms,
NULL);
XmStringFree(xms);
n = 0;
XtSetArg(args[n], XmNwidth, 500); n++;
XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
XtSetArg(args[n], XmNborderWidth, 1); n++;
XtSetArg(args[n], XmNshowValue, TRUE); n++;
XtSetArg(args[n], XmNvalue, paramVal); n++;
switch(i)
{
case INPUT_PARAM:
XtSetArg(args[n], XmNminimum, 0); n++;
XtSetArg(args[n], XmNmaximum, delaySize); n++;
XtSetArg(args[n], XmNdecimalPoints, 0); n++;
break;
case OUPUT_PARAM:
XtSetArg(args[n], XmNminimum, 0); n++;
XtSetArg(args[n], XmNmaximum, delaySize); n++;
XtSetArg(args[n], XmNdecimalPoints, 0); n++;
break;
case FBCOEF_PARAM:
XtSetArg(args[n], XmNminimum, -32768); n++;
XtSetArg(args[n], XmNmaximum, 32767); n++;
XtSetArg(args[n], XmNdecimalPoints, 0); n++;
break;
case FFCOEF_PARAM:
XtSetArg(args[n], XmNminimum, -32768); n++;
XtSetArg(args[n], XmNmaximum, 32767); n++;
XtSetArg(args[n], XmNdecimalPoints, 0); n++;
break;
case GAIN_PARAM:
XtSetArg(args[n], XmNminimum, 0); n++;
XtSetArg(args[n], XmNmaximum, 0x7fff); n++;
XtSetArg(args[n], XmNdecimalPoints, 0); n++;
break;
case LPFILT_PARAM:
XtSetArg(args[n], XmNminimum, -32768); n++;
XtSetArg(args[n], XmNmaximum, 32767); n++;
XtSetArg(args[n], XmNdecimalPoints, 0); n++;
break;
case C_RATE_PARAM:
XtSetArg(args[n], XmNminimum, 0); n++;
XtSetArg(args[n], XmNmaximum, 32767); n++;
XtSetArg(args[n], XmNdecimalPoints, 0); n++;
break;
case C_DEPTH_PARAM:
XtSetArg(args[n], XmNminimum, 0); n++;
XtSetArg(args[n], XmNmaximum, 32767); n++;
XtSetArg(args[n], XmNdecimalPoints, 0); n++;
break;
}
scale[i] = XtCreateManagedWidget("RScale", xmScaleWidgetClass, scaleRowCol,
args, n);
itemRef = (AEItemRef*)malloc(sizeof(AEItemRef));
itemRef->item = i;
itemRef->editor = this;
XtAddCallback(scale[i], XmNvalueChangedCallback, param_value_cb, (XtPointer)itemRef);
XtAddCallback(scale[i], XmNdragCallback, param_value_cb, (XtPointer)itemRef);
XtAddCallback(scale[i], XmNdestroyCallback, destroy_item_cb, (XtPointer)itemRef);
}
} /* end if(reverbAsset && reverbAsset->GetParam(0, &numFxSets)) */
else
{
xms = XmStringCreateLtoR(noFXStr, XmSTRING_DEFAULT_CHARSET);
XtVaCreateManagedWidget("Label", xmLabelWidgetClass, shellWidget,
XmNlabelString, xms,
NULL);
XmStringFree(xms);
}
XtRealizeWidget(shellWidget);
}
/******************************************************************************
*
* param_set_cb. Called everytime a new section is selected.
*
*****************************************************************************/
static void param_section_cb(Widget w, XtPointer client_data, XmAnyCallbackStruct *call_data)
{
AEItemRef *ref = (AEItemRef*)client_data;
ReverbEditor *editor = (ReverbEditor*)ref->editor;
AEReverb *revAsset = editor->reverbAsset;
int selected = ref->item;
int i;
int paramID;
s32 paramVal;
if(editor->curParamSet != selected) /* if it is a new primative */
{
editor->curParamSet = selected;
paramID = (selected * NUM_FX_PARAMS) + FX_PARAM_OFFSET;
for(i = 0; i < NUM_FX_PARAMS; i++,paramID++)
{
if(!revAsset->GetParam(paramID,¶mVal))
paramVal = 0;
XmScaleSetValue(editor->scale[i], paramVal); /* change the scale widgets to */
/* reflect the new values */
}
}
}
#define INPUT_PARAM 0
#define OUTPUT_PARAM 1
static void param_value_cb(Widget w, XtPointer client_data, XmScaleCallbackStruct *call_data)
{
AEItemRef *ref = (AEItemRef*)client_data;
ReverbEditor *editor = (ReverbEditor*)ref->editor;
AEReverb *revAsset = editor->reverbAsset;
int paramID = ref->item;
s32 otherPtr,otherParamID;
paramID += (editor->curParamSet * NUM_FX_PARAMS) + FX_PARAM_OFFSET;
if(ref->item == INPUT_PARAM)
{
otherParamID = (editor->curParamSet * NUM_FX_PARAMS) + FX_PARAM_OFFSET + OUTPUT_PARAM;
revAsset->GetParam(otherParamID, &otherPtr);
if(call_data->value == otherPtr)
{
printf("Trying to set input to the output value\n");
return;
}
}
else if(ref->item == OUTPUT_PARAM)
{
otherParamID = (editor->curParamSet * NUM_FX_PARAMS) + FX_PARAM_OFFSET + INPUT_PARAM;
revAsset->GetParam(otherParamID, &otherPtr);
if(call_data->value == otherPtr)
{
printf("Trying to set output to the input value\n");
return;
}
}
revAsset->SetParam(paramID, call_data->value);
theU64Dev->UpdateFXParam(paramID, call_data->value);
}
static void destroy_editor_cb(Widget w, XtPointer client_data, XmAnyCallbackStruct *call_data)
{
EditMgr *theEdMgr = (EditMgr*)client_data;
theEdMgr->removeReverb();
}
static void destroy_item_cb(Widget w, XtPointer client_data, XmAnyCallbackStruct *call_data)
{
free (client_data);
}