-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathC700.cpp
More file actions
718 lines (654 loc) · 25.6 KB
/
C700.cpp
File metadata and controls
718 lines (654 loc) · 25.6 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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
#include <AudioToolbox/AudioToolbox.h>
#include "C700.h"
#include "brrcodec.h"
#include "AudioFile.h"
//-----------------------------------------------------------------------------
//COMPONENT_ENTRY(C700)
AUDIOCOMPONENT_ENTRY(AUMusicDeviceFactory, C700)
//-----------------------------------------------------------------------------
// C700::C700
//-----------------------------------------------------------------------------
C700::C700(AudioUnit component)
: MusicDeviceBase(component, 0, 1/*, 32, 0*/)
, mEfx(NULL)
{
createPropertyParamMap(mPropertyParams);
CreateElements();
Globals()->UseIndexedParameters(kNumberOfParameters);
mEfx = new C700Kernel();
mEfx->SetPropertyNotifyFunc(PropertyNotifyFunc, this);
mEfx->SetParameterSetFunc(ParameterSetFunc, this);
//プリセット名テーブルを作成する
mPresets = new AUPreset[NUM_PRESETS];
for (int i = 0; i < NUM_PRESETS; ++i) {
const char *pname;
pname = C700Kernel::GetPresetName(i);
mPresets[i].presetNumber = i;
CFMutableStringRef cfpname = CFStringCreateMutable(NULL, 64);
mPresets[i].presetName = cfpname;
CFStringAppendCString( cfpname, pname, kCFStringEncodingASCII );
}
//デフォルト値を設定する
for ( int i=0; i<kNumberOfParameters; i++ ) {
Globals()->SetParameter(i, C700Kernel::GetParameterDefault(i) );
mParameterHasChanged[i] = false;
}
#if AU_DEBUG_DISPATCHER
mDebugDispatcher = new AUDebugDispatcher(this);
#endif
}
//-----------------------------------------------------------------------------
C700::~C700()
{
for (int i = 0; i < NUM_PRESETS; ++i) {
CFRelease(mPresets[i].presetName);
}
delete [] mPresets;
if ( mEfx ) {
delete mEfx;
}
#if AU_DEBUG_DISPATCHER
delete mDebugDispatcher;
#endif
}
//-----------------------------------------------------------------------------
void C700::PropertyNotifyFunc(int propID, void* userData)
{
C700 *This = reinterpret_cast<C700*> (userData);
This->PropertyChanged(propID, kAudioUnitScope_Global, 0);
}
//-----------------------------------------------------------------------------
void C700::ParameterSetFunc(int paramID, float value, void* userData)
{
C700 *This = reinterpret_cast<C700*> (userData);
This->Globals()->SetParameter(paramID, value);
AudioUnitEvent auEvent;
auEvent.mEventType = kAudioUnitEvent_ParameterValueChange;
auEvent.mArgument.mParameter.mAudioUnit = (AudioUnit)This->GetComponentInstance();
auEvent.mArgument.mParameter.mScope = kAudioUnitScope_Global;
auEvent.mArgument.mParameter.mParameterID = paramID;
auEvent.mArgument.mParameter.mElement = 0;
AUEventListenerNotify(NULL, NULL, &auEvent);
This->mParameterHasChanged[paramID] = true;
}
//-----------------------------------------------------------------------------
ComponentResult C700::Initialize()
{
MusicDeviceBase::Initialize();
return noErr;
}
//-----------------------------------------------------------------------------
void C700::Cleanup()
{
}
//-----------------------------------------------------------------------------
ComponentResult C700::Reset( AudioUnitScope inScope,
AudioUnitElement inElement)
{
// if (inScope == kAudioUnitScope_Global) {
mEfx->Reset();
// }
return MusicDeviceBase::Reset(inScope, inElement);
}
//-----------------------------------------------------------------------------
bool C700::StreamFormatWritable( AudioUnitScope scope,
AudioUnitElement element)
{
return IsInitialized() ? false : true;
}
//-----------------------------------------------------------------------------
OSStatus C700::Render( AudioUnitRenderActionFlags & ioActionFlags,
const AudioTimeStamp & inTimeStamp,
UInt32 inNumberFrames)
{
OSStatus result = MusicDeviceBase::Render(ioActionFlags, inTimeStamp, inNumberFrames);
{
double tempo;
double currentBeat;
Boolean isPlaying;
CallHostBeatAndTempo(¤tBeat, &tempo);
CallHostTransportState(&isPlaying, NULL, NULL, NULL, NULL, NULL);
mEfx->SetTempo( tempo );
mEfx->SetCurrentSampleInTimeLine( currentBeat );
mEfx->SetSampleRate( GetOutput(0)->GetStreamFormat().mSampleRate );
mEfx->SetIsPlaying(isPlaying?true:false);
}
//バッファの確保
float *output[2];
AudioBufferList& bufferList = GetOutput(0)->GetBufferList();
UInt32 numOutputs = Outputs().GetNumberOfElements();
for (UInt32 j = 0; j < numOutputs; ++j)
{
AudioBufferList& bufferList = GetOutput(j)->GetBufferList();
for (UInt32 k = 0; k < bufferList.mNumberBuffers; ++k)
{
memset(bufferList.mBuffers[k].mData, 0, bufferList.mBuffers[k].mDataByteSize);
}
}
int numChans = bufferList.mNumberBuffers;
if (numChans > 2) return -1;
output[0] = (float*)bufferList.mBuffers[0].mData;
output[1] = numChans==2 ? (float*)bufferList.mBuffers[1].mData : NULL;
//パラメータの反映
for ( int i=0; i<kNumberOfParameters; i++ ) {
if (mParameterHasChanged[i]) {
mEfx->SetParameter(i, Globals()->GetParameter(i));
mParameterHasChanged[i] = false;
if (i == kParam_alwaysDelayNote) {
// 遅延時間の変更をホストに通知
PropertyChanged(kAudioUnitProperty_Latency, kAudioUnitScope_Global, 0);
}
}
}
mEfx->Render(inNumberFrames, output);
return result;
}
//-----------------------------------------------------------------------------
// C700::SetParameter
//-----------------------------------------------------------------------------
OSStatus C700::SetParameter( AudioUnitParameterID inID,
AudioUnitScope inScope,
AudioUnitElement inElement,
Float32 inValue,
UInt32 inBufferOffsetInFrames)
{
OSStatus result = MusicDeviceBase::SetParameter(inID, inScope, inElement, inValue, inBufferOffsetInFrames);
if ( inScope == kAudioUnitScope_Global ) {
//mEfx->SetParameter(inID, inValue);
if (inID < kNumberOfParameters) {
mParameterHasChanged[inID] = true;
}
switch ( inID ) {
case kParam_echodelay:
PropertyChanged(kAudioUnitCustomProperty_TotalRAM, kAudioUnitScope_Global, 0);
break;
}
}
return result;
}
//-----------------------------------------------------------------------------
AudioUnitParameterUnit getParameterUnit( int id )
{
switch(id)
{
case kParam_poly:
return kAudioUnitParameterUnit_Indexed;
case kParam_vibdepth:
case kParam_vibdepth_2:
case kParam_vibdepth_3:
case kParam_vibdepth_4:
case kParam_vibdepth_5:
case kParam_vibdepth_6:
case kParam_vibdepth_7:
case kParam_vibdepth_8:
case kParam_vibdepth_9:
case kParam_vibdepth_10:
case kParam_vibdepth_11:
case kParam_vibdepth_12:
case kParam_vibdepth_13:
case kParam_vibdepth_14:
case kParam_vibdepth_15:
case kParam_vibdepth_16:
return kAudioUnitParameterUnit_Indexed;
case kParam_vibrate:
return kAudioUnitParameterUnit_Hertz;
case kParam_vibdepth2:
return kAudioUnitParameterUnit_Generic;
case kParam_velocity:
return kAudioUnitParameterUnit_Indexed;
case kParam_engine:
return kAudioUnitParameterUnit_Indexed;
case kParam_bendrange:
return kAudioUnitParameterUnit_Indexed;
case kParam_program:
case kParam_program_2:
case kParam_program_3:
case kParam_program_4:
case kParam_program_5:
case kParam_program_6:
case kParam_program_7:
case kParam_program_8:
case kParam_program_9:
case kParam_program_10:
case kParam_program_11:
case kParam_program_12:
case kParam_program_13:
case kParam_program_14:
case kParam_program_15:
case kParam_program_16:
return kAudioUnitParameterUnit_Indexed;
case kParam_bankAmulti:
return kAudioUnitParameterUnit_Boolean;
case kParam_bankBmulti:
return kAudioUnitParameterUnit_Boolean;
case kParam_bankCmulti:
return kAudioUnitParameterUnit_Boolean;
case kParam_bankDmulti:
return kAudioUnitParameterUnit_Boolean;
//エコー
case kParam_mainvol_L:
return kAudioUnitParameterUnit_Indexed;
case kParam_mainvol_R:
return kAudioUnitParameterUnit_Indexed;
case kParam_echovol_L:
return kAudioUnitParameterUnit_Indexed;
case kParam_echovol_R:
return kAudioUnitParameterUnit_Indexed;
case kParam_echoFB:
return kAudioUnitParameterUnit_Indexed;
case kParam_echodelay:
return kAudioUnitParameterUnit_Indexed;
case kParam_fir0:
return kAudioUnitParameterUnit_Indexed;
case kParam_fir1:
return kAudioUnitParameterUnit_Indexed;
case kParam_fir2:
return kAudioUnitParameterUnit_Indexed;
case kParam_fir3:
return kAudioUnitParameterUnit_Indexed;
case kParam_fir4:
return kAudioUnitParameterUnit_Indexed;
case kParam_fir5:
return kAudioUnitParameterUnit_Indexed;
case kParam_fir6:
return kAudioUnitParameterUnit_Indexed;
case kParam_fir7:
return kAudioUnitParameterUnit_Indexed;
case kParam_voiceAllocMode:
return kAudioUnitParameterUnit_Indexed;
case kParam_fastReleaseAsKeyOff:
return kAudioUnitParameterUnit_Boolean;
default:
return kAudioUnitParameterUnit_Indexed;
}
}
//-----------------------------------------------------------------------------
// C700::GetParameterInfo
//-----------------------------------------------------------------------------
ComponentResult C700::GetParameterInfo(AudioUnitScope inScope,
AudioUnitParameterID inParameterID,
AudioUnitParameterInfo &outParameterInfo )
{
ComponentResult result = noErr;
outParameterInfo.flags = kAudioUnitParameterFlag_IsWritable
| kAudioUnitParameterFlag_IsReadable;
if (inScope == kAudioUnitScope_Global) {
if ( /*inParameterID >= 0 &&*/ inParameterID < kNumberOfParameters ) {
CFStringRef cfName = CFStringCreateWithCString(NULL, mEfx->GetParameterName(inParameterID), kCFStringEncodingUTF8);
AUBase::FillInParameterName(outParameterInfo, cfName, true);
outParameterInfo.unit = getParameterUnit( inParameterID );
outParameterInfo.minValue = C700Kernel::GetParameterMin(inParameterID);
outParameterInfo.maxValue = C700Kernel::GetParameterMax(inParameterID);
outParameterInfo.defaultValue = C700Kernel::GetParameterDefault(inParameterID);
}
else {
result = kAudioUnitErr_InvalidParameter;
}
}
else {
result = kAudioUnitErr_InvalidParameter;
}
return result;
}
//-----------------------------------------------------------------------------
// C700::GetPropertyInfo
//-----------------------------------------------------------------------------
ComponentResult C700::GetPropertyInfo (AudioUnitPropertyID inID,
AudioUnitScope inScope,
AudioUnitElement inElement,
UInt32 & outDataSize,
Boolean & outWritable)
{
if (inScope == kAudioUnitScope_Global) {
#ifndef USE_CARBON_UI
if (inID == kAudioUnitProperty_CocoaUI) {
outWritable = false;
outDataSize = sizeof (AudioUnitCocoaViewInfo);
return noErr;
}
#endif
auto it = mPropertyParams.find(inID);
if (it != mPropertyParams.end()) {
if ((it->second.dataType == propertyDataTypeString) ||
(it->second.dataType == propertyDataTypeFilePath)) {
// outDataSizeには最大文字数が格納されている
outDataSize = sizeof(void *);
}
else {
outDataSize = it->second.outDataSize;
}
outWritable = it->second.outWritable;
return noErr;
}
}
return MusicDeviceBase::GetPropertyInfo(inID, inScope, inElement, outDataSize, outWritable);
}
//-----------------------------------------------------------------------------
// C700::GetProperty
//-----------------------------------------------------------------------------
ComponentResult C700::GetProperty( AudioUnitPropertyID inID,
AudioUnitScope inScope,
AudioUnitElement inElement,
void * outData )
{
if (inScope == kAudioUnitScope_Global) {
#ifndef USE_CARBON_UI
if (inID == kAudioUnitProperty_CocoaUI) {
// Look for a resource in the main bundle by name and type.
CFBundleRef bundle = CFBundleGetBundleWithIdentifier( CFSTR("com.picopicose.audiounit.C700") );
if (bundle == NULL) return fnfErr;
CFURLRef bundleURL = CFBundleCopyBundleURL( bundle );
if (bundleURL == NULL) return fnfErr;
AudioUnitCocoaViewInfo cocoaInfo;
cocoaInfo.mCocoaAUViewBundleLocation = bundleURL;
cocoaInfo.mCocoaAUViewClass[0] = CFStringCreateWithCString(NULL, "C700_CocoaViewFactory", kCFStringEncodingUTF8);
*((AudioUnitCocoaViewInfo *)outData) = cocoaInfo;
return noErr;
}
#endif
auto it = mPropertyParams.find(inID);
if (it != mPropertyParams.end()) {
switch (it->second.dataType) {
case propertyDataTypeFloat32:
*((Float32 *)outData) = mEfx->GetPropertyValue(inID);
break;
case propertyDataTypeDouble:
*((double *)outData) = mEfx->GetPropertyDoubleValue(inID);
break;
case propertyDataTypeInt32:
*((int *)outData) = mEfx->GetPropertyValue(inID);
break;
case propertyDataTypeBool:
*((bool *)outData) = mEfx->GetPropertyValue(inID)>0.5f? true:false;
break;
case propertyDataTypeStruct:
mEfx->GetPropertyStructValue(inID, outData);
break;
case propertyDataTypeString:
{
const char *string = (char *)mEfx->GetPropertyPtrValue(inID);
CFStringRef str =
CFStringCreateWithCString(NULL, string, kCFStringEncodingUTF8);
*((char **)outData) = (char *)str; //使用後要release
break;
}
case propertyDataTypeFilePath:
{
const char *string = (char *)mEfx->GetPropertyPtrValue(inID);
CFURLRef url =
CFURLCreateFromFileSystemRepresentation(NULL, (UInt8*)string, strlen(string), false);
*((char **)outData) = (char *)url; //使用後要release
break;
}
case propertyDataTypeVariableData:
{
CFDataRef dataRef;
dataRef = CFDataCreate(NULL, (UInt8*)mEfx->GetPropertyPtrValue(inID), mEfx->GetPropertyPtrDataSize(inID));
*((char **)outData) = (char *)dataRef; //使用後要release
break;
}
case propertyDataTypePointer:
*((char **)outData) = (char *)mEfx->GetPropertyPtrValue(inID);
break;
}
return noErr;
}
}
return MusicDeviceBase::GetProperty(inID, inScope, inElement, outData);
}
//-----------------------------------------------------------------------------
// C700::SetProperty
//-----------------------------------------------------------------------------
ComponentResult C700::SetProperty( AudioUnitPropertyID inID,
AudioUnitScope inScope,
AudioUnitElement inElement,
const void * inData,
UInt32 inDataSize)
{
if (inScope == kAudioUnitScope_Global) {
auto it = mPropertyParams.find(inID);
if (it != mPropertyParams.end()) {
if (it->second.readOnly == false) {
switch (it->second.dataType) {
case propertyDataTypeFloat32:
mEfx->SetPropertyValue(inID, *((float*)inData) );
break;
case propertyDataTypeDouble:
mEfx->SetPropertyDoubleValue(inID, *((double*)inData));
break;
case propertyDataTypeInt32:
mEfx->SetPropertyValue(inID, *((int*)inData) );
break;
case propertyDataTypeBool:
mEfx->SetPropertyValue(inID, *((bool*)inData) ? 1.0f:.0f );
break;
case propertyDataTypeStruct:
mEfx->SetPropertyPtrValue(inID, inData, it->second.outDataSize);
break;
case propertyDataTypeString:
{
char **ptr = (char**)inData;
CFIndex length = CFStringGetLength(reinterpret_cast<CFStringRef>(*ptr)) + 1;
char *string = new char[length];
CFStringGetCString(reinterpret_cast<CFStringRef>(*ptr), string, length, kCFStringEncodingUTF8);
mEfx->SetPropertyPtrValue(inID, string, length);
delete [] string;
break;
}
case propertyDataTypeFilePath:
{
char **ptr = (char**)inData;
CFStringRef pathStr = CFURLCopyFileSystemPath(reinterpret_cast<CFURLRef>(*ptr), kCFURLPOSIXPathStyle);
char *path = new char[it->second.outDataSize];
CFStringGetCString(pathStr, path, it->second.outDataSize, kCFStringEncodingUTF8);
CFRelease(pathStr);
mEfx->SetPropertyPtrValue(inID, path, it->second.outDataSize);
delete [] path;
break;
}
case propertyDataTypeVariableData:
{
char **ptr = (char**)inData;
CFDataRef data = reinterpret_cast<CFDataRef>(*ptr);
mEfx->SetPropertyPtrValue(inID, CFDataGetBytePtr(data), CFDataGetLength(data));
break;
}
case propertyDataTypePointer:
{
char **ptr = (char**)inData;
mEfx->SetPropertyPtrValue(inID, *ptr, it->second.outDataSize);
break;
}
}
}
return noErr;
}
}
return MusicDeviceBase::SetProperty(inID, inScope, inElement, inData, inDataSize);
}
//-----------------------------------------------------------------------------
// C700::GetPresets
//-----------------------------------------------------------------------------
ComponentResult C700::GetPresets(CFArrayRef *outData) const
{
if (outData == NULL) return noErr;
CFMutableArrayRef theArray = CFArrayCreateMutable(NULL, NUM_PRESETS, NULL);
for (int i = 0; i < NUM_PRESETS; ++i) {
CFArrayAppendValue(theArray, &mPresets[i]);
}
*outData = (CFArrayRef)theArray;
return noErr;
}
//-----------------------------------------------------------------------------
OSStatus C700::NewFactoryPresetSet(const AUPreset &inNewFactoryPreset)
{
UInt32 chosenPreset = inNewFactoryPreset.presetNumber;
if ( chosenPreset < (UInt32)NUM_PRESETS ) {
mEfx->SelectPreset(chosenPreset);
char cname[32];
CFStringGetCString(inNewFactoryPreset.presetName, cname, 32, kCFStringEncodingASCII);
//mEfx->setProgramName(cname);
SetAFactoryPresetAsCurrent(inNewFactoryPreset);
for ( UInt32 i=0; i<kNumberOfParameters; i++ ) {
Globals()->SetParameter(i, mEfx->GetParameter(i));
}
return noErr;
}
return kAudioUnitErr_InvalidPropertyValue;
}
//-----------------------------------------------------------------------------
// C700::SaveState
//-----------------------------------------------------------------------------
ComponentResult C700::SaveState(CFPropertyListRef *outData)
{
ComponentResult result;
result = MusicDeviceBase::SaveState(outData);
CFMutableDictionaryRef dict=(CFMutableDictionaryRef)*outData;
if (result == noErr) {
CFDictionaryRef pgdata;
CFStringRef pgnum,pgname;
mEfx->SetPropertyToDict(dict, mPropertyParams[kAudioUnitCustomProperty_EditingChannel]);
mEfx->SetPropertyToDict(dict, mPropertyParams[kAudioUnitCustomProperty_EditingProgram]);
for (int i=0; i<128; i++) {
const BRRData *brr = mEfx->GetBRRData(i);
if (brr->data) {
mEfx->CreatePGDataDic(&pgdata, i);
pgnum = CFStringCreateWithFormat(NULL,NULL,CFSTR("pg%03d"),i);
CFDictionarySetValue(dict, pgnum, pgdata);
CFRelease(pgdata);
CFRelease(pgnum);
}
}
// saveToSongの設定を保存
auto it = mPropertyParams.begin();
while (it != mPropertyParams.end()) {
if (it->second.saveToSong) {
if (it->first == kAudioUnitCustomProperty_EditingChannel ||
it->first == kAudioUnitCustomProperty_EditingProgram) {
it++;
continue;
}
mEfx->SetPropertyToDict(dict, it->second);
}
it++;
}
pgname = CFStringCreateCopy(NULL,CFSTR("C700"));
CFDictionarySetValue(dict, CFSTR(kAUPresetNameKey), pgname);
CFRelease(pgname);
}
return result;
}
//-----------------------------------------------------------------------------
// C700::RestoreState
//-----------------------------------------------------------------------------
ComponentResult C700::RestoreState(CFPropertyListRef plist)
{
ComponentResult result;
result = MusicDeviceBase::RestoreState(plist);
for (int i=0; i<kNumberOfParameters; i++) {
mParameterHasChanged[i] = true;
}
CFDictionaryRef dict = static_cast<CFDictionaryRef>(plist);
if (result == noErr) {
mEfx->BeginRestorePGData();
//プログラムの復元
CFStringRef pgnum;
CFDictionaryRef pgdata;
for (int i=0; i<128; i++) {
pgnum = CFStringCreateWithFormat(NULL,NULL,CFSTR("pg%03d"),i);
if (CFDictionaryContainsKey(dict, pgnum)) {
pgdata = reinterpret_cast<CFDictionaryRef>(CFDictionaryGetValue(dict, pgnum));
mEfx->RestorePGDataDic(pgdata, i);
}
CFRelease(pgnum);
}
// saveToSongのプロパティを復元
auto it = mPropertyParams.begin();
while (it != mPropertyParams.end()) {
if (it->second.saveToSong) {
if (it->first == kAudioUnitCustomProperty_EditingChannel ||
it->first == kAudioUnitCustomProperty_EditingProgram) {
it++;
continue;
}
mEfx->RestorePropertyFromDict(dict, it->second);
}
it++;
}
// EditChanの方が後に設定されてしまうとうまく復元されない
mEfx->RestorePropertyFromDict(dict, mPropertyParams[kAudioUnitCustomProperty_EditingChannel]);
mEfx->RestorePropertyFromDict(dict, mPropertyParams[kAudioUnitCustomProperty_EditingProgram]);
mEfx->EndRestorePGData();
}
return result;
}
//-----------------------------------------------------------------------------
OSStatus C700::StartNote( MusicDeviceInstrumentID inInstrument,
MusicDeviceGroupID inGroupID,
NoteInstanceID * outNoteInstanceID,
UInt32 inOffsetSampleFrame,
const MusicDeviceNoteParams &inParams)
{
//MIDIチャンネルの取得
unsigned int chID = inGroupID % 16;
mEfx->HandleNoteOn(chID, inParams.mPitch, inParams.mVelocity, inParams.mPitch+chID*256, inOffsetSampleFrame);
return noErr;
}
//-----------------------------------------------------------------------------
OSStatus C700::StopNote( MusicDeviceGroupID inGroupID,
NoteInstanceID inNoteInstanceID,
UInt32 inOffsetSampleFrame)
{
//MIDIチャンネルの取得
unsigned int chID = inGroupID % 16;
mEfx->HandleNoteOff(chID, inNoteInstanceID, inNoteInstanceID+chID*256, inOffsetSampleFrame);
return noErr;
}
//-----------------------------------------------------------------------------
OSStatus C700::HandlePitchWheel( UInt8 inChannel,
UInt8 inPitch1,
UInt8 inPitch2,
UInt32 inStartFrame)
{
mEfx->HandlePitchBend(inChannel, inPitch1, inPitch2, inStartFrame);
return noErr;
}
//-----------------------------------------------------------------------------
// C700::HandleControlChange
//-----------------------------------------------------------------------------
OSStatus C700::HandleControlChange( UInt8 inChannel,
UInt8 inController,
UInt8 inValue,
UInt32 inStartFrame)
{
mEfx->HandleControlChange(inChannel, inController, inValue, inStartFrame);
return MusicDeviceBase::HandleControlChange(inChannel, inController, inValue, inStartFrame);
}
//-----------------------------------------------------------------------------
// C700::HandleProgramChange
//-----------------------------------------------------------------------------
OSStatus C700::HandleProgramChange( UInt8 inChannel,
UInt8 inValue,
UInt32 inStartFrame)
{
mEfx->HandleProgramChange(inChannel, inValue, inStartFrame);
return MusicDeviceBase::HandleProgramChange(inChannel, inValue, inStartFrame);
}
//-----------------------------------------------------------------------------
OSStatus C700::HandleResetAllControllers( UInt8 inChannel)
{
mEfx->HandleResetAllControllers(inChannel, 0);
return MusicDeviceBase::HandleResetAllControllers( inChannel);
}
//-----------------------------------------------------------------------------
OSStatus C700::HandleAllNotesOff( UInt8 inChannel )
{
mEfx->HandleAllNotesOff(inChannel, 0);
return MusicDeviceBase::HandleAllNotesOff( inChannel);
}
//-----------------------------------------------------------------------------
OSStatus C700::HandleAllSoundOff( UInt8 inChannel )
{
mEfx->HandleAllSoundOff(inChannel, 0);
return MusicDeviceBase::HandleAllSoundOff( inChannel);
}