forked from osoumen/C700
-
Notifications
You must be signed in to change notification settings - Fork 0
/
C700.cpp
1270 lines (1128 loc) · 44.9 KB
/
C700.cpp
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
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <AudioToolbox/AudioToolbox.h>
#include "C700.h"
#include "brrcodec.h"
#include "AudioFile.h"
#include "XIFile.h"
static CFStringRef kSaveKey_ProgName = CFSTR("progname");
static CFStringRef kSaveKey_EditProg = CFSTR("editprog");
static CFStringRef kSaveKey_EditChan = CFSTR("editchan");
static CFStringRef kSaveKey_brrdata = CFSTR("brrdata");
static CFStringRef kSaveKey_looppoint = CFSTR("looppoint");
static CFStringRef kSaveKey_samplerate = CFSTR("samplerate");
static CFStringRef kSaveKey_basekey = CFSTR("key");
static CFStringRef kSaveKey_lowkey = CFSTR("lowkey");
static CFStringRef kSaveKey_highkey = CFSTR("highkey");
static CFStringRef kSaveKey_ar = CFSTR("ar");
static CFStringRef kSaveKey_dr = CFSTR("dr");
static CFStringRef kSaveKey_sl = CFSTR("sl");
static CFStringRef kSaveKey_sr = CFSTR("sr");
static CFStringRef kSaveKey_volL = CFSTR("volL");
static CFStringRef kSaveKey_volR = CFSTR("volR");
static CFStringRef kSaveKey_echo = CFSTR("echo");
static CFStringRef kSaveKey_bank = CFSTR("bank");
static CFStringRef kSaveKey_IsEmphasized = CFSTR("isemph");
static CFStringRef kSaveKey_SourceFile = CFSTR("srcfile");
static CFStringRef kSaveKey_SustainMode = CFSTR("sustainmode");
static CFStringRef kSaveKey_MonoMode = CFSTR("monomode");
static CFStringRef kSaveKey_PortamentoOn = CFSTR("portamentoon");
static CFStringRef kSaveKey_PortamentoRate = CFSTR("portamentorate");
static CFStringRef kSaveKey_NoteOnPriority = CFSTR("noteonpriority");
static CFStringRef kSaveKey_ReleasePriority = CFSTR("releasepriority");
//-----------------------------------------------------------------------------
COMPONENT_ENTRY(C700)
//-----------------------------------------------------------------------------
// C700::C700
//-----------------------------------------------------------------------------
C700::C700(AudioUnit component)
: AUInstrumentBase(component, 0, 1)
, mEfx(NULL)
{
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) );
}
#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()
{
AUInstrumentBase::Initialize();
for (int i=0; i<kNumberOfParameters; i++) {
mParameterHasChanged[i] = true;
}
return noErr;
}
//-----------------------------------------------------------------------------
void C700::Cleanup()
{
}
//-----------------------------------------------------------------------------
ComponentResult C700::Reset( AudioUnitScope inScope,
AudioUnitElement inElement)
{
// if (inScope == kAudioUnitScope_Global) {
mEfx->Reset();
// }
return AUInstrumentBase::Reset(inScope, inElement);
}
//-----------------------------------------------------------------------------
OSStatus C700::Render( AudioUnitRenderActionFlags & ioActionFlags,
const AudioTimeStamp & inTimeStamp,
UInt32 inNumberFrames)
{
OSStatus result = AUInstrumentBase::Render(ioActionFlags, inTimeStamp, inNumberFrames);
CallHostBeatAndTempo(NULL, &mTempo);
mEfx->SetTempo( mTempo );
//バッファの確保
float *output[2];
AudioBufferList& bufferList = GetOutput(0)->GetBufferList();
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->SetSampleRate( GetOutput(0)->GetStreamFormat().mSampleRate );
mEfx->Render(inNumberFrames, output);
return result;
}
//-----------------------------------------------------------------------------
// C700::SetParameter
//-----------------------------------------------------------------------------
OSStatus C700::SetParameter( AudioUnitParameterID inID,
AudioUnitScope inScope,
AudioUnitElement inElement,
Float32 inValue,
UInt32 inBufferOffsetInFrames)
{
OSStatus result = AUInstrumentBase::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_newadpcm:
return kAudioUnitParameterUnit_Boolean;
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;
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) {
switch (inID) {
#ifndef USE_CARBON_UI
case kAudioUnitProperty_CocoaUI:
outWritable = false;
outDataSize = sizeof (AudioUnitCocoaViewInfo);
return noErr;
#endif
case kAudioUnitCustomProperty_BaseKey:
case kAudioUnitCustomProperty_LowKey:
case kAudioUnitCustomProperty_HighKey:
case kAudioUnitCustomProperty_AR:
case kAudioUnitCustomProperty_DR:
case kAudioUnitCustomProperty_SL:
case kAudioUnitCustomProperty_SR:
case kAudioUnitCustomProperty_VolL:
case kAudioUnitCustomProperty_VolR:
case kAudioUnitCustomProperty_EditingProgram:
case kAudioUnitCustomProperty_EditingChannel:
case kAudioUnitCustomProperty_LoopPoint:
outDataSize = sizeof(int);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_Rate:
outDataSize = sizeof(double);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_Loop:
outDataSize = sizeof(bool);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_Echo:
outDataSize = sizeof(bool);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_Bank:
outDataSize = sizeof(UInt32);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_BRRData:
outDataSize = sizeof(BRRData);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_PGDictionary:
outDataSize = sizeof(CFDictionaryRef);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_XIData:
outDataSize = sizeof(CFDataRef);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_ProgramName:
outDataSize = sizeof(CFStringRef);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_TotalRAM:
outDataSize = sizeof(UInt32);
outWritable = false;
return noErr;
//エコー
case kAudioUnitCustomProperty_Band1:
case kAudioUnitCustomProperty_Band2:
case kAudioUnitCustomProperty_Band3:
case kAudioUnitCustomProperty_Band4:
case kAudioUnitCustomProperty_Band5:
outWritable = false;
outDataSize = sizeof(Float32);
return noErr;
// トラックインジケーター
case kAudioUnitCustomProperty_NoteOnTrack_1:
case kAudioUnitCustomProperty_NoteOnTrack_2:
case kAudioUnitCustomProperty_NoteOnTrack_3:
case kAudioUnitCustomProperty_NoteOnTrack_4:
case kAudioUnitCustomProperty_NoteOnTrack_5:
case kAudioUnitCustomProperty_NoteOnTrack_6:
case kAudioUnitCustomProperty_NoteOnTrack_7:
case kAudioUnitCustomProperty_NoteOnTrack_8:
case kAudioUnitCustomProperty_NoteOnTrack_9:
case kAudioUnitCustomProperty_NoteOnTrack_10:
case kAudioUnitCustomProperty_NoteOnTrack_11:
case kAudioUnitCustomProperty_NoteOnTrack_12:
case kAudioUnitCustomProperty_NoteOnTrack_13:
case kAudioUnitCustomProperty_NoteOnTrack_14:
case kAudioUnitCustomProperty_NoteOnTrack_15:
case kAudioUnitCustomProperty_NoteOnTrack_16:
outWritable = false;
outDataSize = sizeof(UInt32);
return noErr;
//トラック最大発音数
case kAudioUnitCustomProperty_MaxNoteTrack_1:
case kAudioUnitCustomProperty_MaxNoteTrack_2:
case kAudioUnitCustomProperty_MaxNoteTrack_3:
case kAudioUnitCustomProperty_MaxNoteTrack_4:
case kAudioUnitCustomProperty_MaxNoteTrack_5:
case kAudioUnitCustomProperty_MaxNoteTrack_6:
case kAudioUnitCustomProperty_MaxNoteTrack_7:
case kAudioUnitCustomProperty_MaxNoteTrack_8:
case kAudioUnitCustomProperty_MaxNoteTrack_9:
case kAudioUnitCustomProperty_MaxNoteTrack_10:
case kAudioUnitCustomProperty_MaxNoteTrack_11:
case kAudioUnitCustomProperty_MaxNoteTrack_12:
case kAudioUnitCustomProperty_MaxNoteTrack_13:
case kAudioUnitCustomProperty_MaxNoteTrack_14:
case kAudioUnitCustomProperty_MaxNoteTrack_15:
case kAudioUnitCustomProperty_MaxNoteTrack_16:
outWritable = false;
outDataSize = sizeof(UInt32);
return noErr;
case kAudioUnitCustomProperty_SourceFileRef:
outDataSize = sizeof(CFURLRef);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_IsEmaphasized:
outDataSize = sizeof(bool);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_SustainMode:
outDataSize = sizeof(bool);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_MonoMode:
outDataSize = sizeof(bool);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_PortamentoOn:
outDataSize = sizeof(bool);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_PortamentoRate:
outDataSize = sizeof(int);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_NoteOnPriority:
outDataSize = sizeof(int);
outWritable = false;
return noErr;
case kAudioUnitCustomProperty_ReleasePriority:
outDataSize = sizeof(int);
outWritable = false;
return noErr;
}
}
return AUInstrumentBase::GetPropertyInfo(inID, inScope, inElement, outDataSize, outWritable);
}
//-----------------------------------------------------------------------------
// C700::GetProperty
//-----------------------------------------------------------------------------
ComponentResult C700::GetProperty( AudioUnitPropertyID inID,
AudioUnitScope inScope,
AudioUnitElement inElement,
void * outData )
{
if (inScope == kAudioUnitScope_Global) {
switch (inID) {
#ifndef USE_CARBON_UI
case 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
case kAudioUnitCustomProperty_Rate:
*((double *)outData) = mEfx->GetPropertyValue(inID);
return noErr;
case kAudioUnitCustomProperty_BaseKey:
case kAudioUnitCustomProperty_LowKey:
case kAudioUnitCustomProperty_HighKey:
case kAudioUnitCustomProperty_LoopPoint:
case kAudioUnitCustomProperty_Bank:
case kAudioUnitCustomProperty_AR:
case kAudioUnitCustomProperty_DR:
case kAudioUnitCustomProperty_SL:
case kAudioUnitCustomProperty_SR:
case kAudioUnitCustomProperty_VolL:
case kAudioUnitCustomProperty_VolR:
case kAudioUnitCustomProperty_EditingProgram:
case kAudioUnitCustomProperty_EditingChannel:
case kAudioUnitCustomProperty_NoteOnTrack_1:
case kAudioUnitCustomProperty_NoteOnTrack_2:
case kAudioUnitCustomProperty_NoteOnTrack_3:
case kAudioUnitCustomProperty_NoteOnTrack_4:
case kAudioUnitCustomProperty_NoteOnTrack_5:
case kAudioUnitCustomProperty_NoteOnTrack_6:
case kAudioUnitCustomProperty_NoteOnTrack_7:
case kAudioUnitCustomProperty_NoteOnTrack_8:
case kAudioUnitCustomProperty_NoteOnTrack_9:
case kAudioUnitCustomProperty_NoteOnTrack_10:
case kAudioUnitCustomProperty_NoteOnTrack_11:
case kAudioUnitCustomProperty_NoteOnTrack_12:
case kAudioUnitCustomProperty_NoteOnTrack_13:
case kAudioUnitCustomProperty_NoteOnTrack_14:
case kAudioUnitCustomProperty_NoteOnTrack_15:
case kAudioUnitCustomProperty_NoteOnTrack_16:
case kAudioUnitCustomProperty_MaxNoteTrack_1:
case kAudioUnitCustomProperty_MaxNoteTrack_2:
case kAudioUnitCustomProperty_MaxNoteTrack_3:
case kAudioUnitCustomProperty_MaxNoteTrack_4:
case kAudioUnitCustomProperty_MaxNoteTrack_5:
case kAudioUnitCustomProperty_MaxNoteTrack_6:
case kAudioUnitCustomProperty_MaxNoteTrack_7:
case kAudioUnitCustomProperty_MaxNoteTrack_8:
case kAudioUnitCustomProperty_MaxNoteTrack_9:
case kAudioUnitCustomProperty_MaxNoteTrack_10:
case kAudioUnitCustomProperty_MaxNoteTrack_11:
case kAudioUnitCustomProperty_MaxNoteTrack_12:
case kAudioUnitCustomProperty_MaxNoteTrack_13:
case kAudioUnitCustomProperty_MaxNoteTrack_14:
case kAudioUnitCustomProperty_MaxNoteTrack_15:
case kAudioUnitCustomProperty_MaxNoteTrack_16:
case kAudioUnitCustomProperty_PortamentoRate:
case kAudioUnitCustomProperty_NoteOnPriority:
case kAudioUnitCustomProperty_ReleasePriority:
*((int *)outData) = mEfx->GetPropertyValue(inID);
return noErr;
case kAudioUnitCustomProperty_Loop:
case kAudioUnitCustomProperty_Echo:
case kAudioUnitCustomProperty_IsEmaphasized:
case kAudioUnitCustomProperty_SustainMode:
case kAudioUnitCustomProperty_MonoMode:
case kAudioUnitCustomProperty_PortamentoOn:
*((bool *)outData) = mEfx->GetPropertyValue(inID)>0.5f? true:false;
return noErr;
case kAudioUnitCustomProperty_TotalRAM:
*((UInt32 *)outData) = mEfx->GetPropertyValue(inID);
return noErr;
//エコー
case kAudioUnitCustomProperty_Band1:
case kAudioUnitCustomProperty_Band2:
case kAudioUnitCustomProperty_Band3:
case kAudioUnitCustomProperty_Band4:
case kAudioUnitCustomProperty_Band5:
*((Float32 *)outData) = mEfx->GetPropertyValue(inID);
return noErr;
case kAudioUnitCustomProperty_BRRData:
*((BRRData *)outData) = *(mEfx->GetBRRData());
return noErr;
case kAudioUnitCustomProperty_PGDictionary:
{
CFDictionaryRef pgdata;
int editProg = mEfx->GetPropertyValue(kAudioUnitCustomProperty_EditingProgram);
CreatePGDataDic(&pgdata, editProg);
*((CFDictionaryRef *)outData) = pgdata; //使用後要release
return noErr;
}
case kAudioUnitCustomProperty_XIData:
{
XIFile fileData(NULL);
fileData.SetDataFromChip(mEfx->GetGenerator(),
mEfx->GetPropertyValue(kAudioUnitCustomProperty_EditingProgram), mTempo);
if ( fileData.IsLoaded() ) {
CFDataRef xidata;
xidata = CFDataCreate(NULL, fileData.GetDataPtr(), fileData.GetDataSize() );
*((CFDataRef *)outData) = xidata; //使用後要release
}
else {
*((CFDataRef *)outData) = NULL;
}
return noErr;
}
case kAudioUnitCustomProperty_ProgramName:
{
CFStringRef str = CFStringCreateWithCString(NULL, mEfx->GetProgramName(), kCFStringEncodingUTF8);
*((CFStringRef *)outData) = str; //使用後要release
return noErr;
}
case kAudioUnitCustomProperty_SourceFileRef:
{
const char *srcPath = mEfx->GetSourceFilePath();
CFURLRef url =
CFURLCreateFromFileSystemRepresentation(NULL, (UInt8*)srcPath, strlen(srcPath), false);
*((CFURLRef *)outData) = url; //使用後要release
return noErr;
}
}
}
return AUInstrumentBase::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) {
switch (inID) {
case kAudioUnitCustomProperty_BRRData:
{
BRRData *brr = (BRRData *)inData;
mEfx->SetBRRData(brr);
return noErr;
}
case kAudioUnitCustomProperty_Rate:
mEfx->SetPropertyValue(inID, *((double*)inData));
return noErr;
case kAudioUnitCustomProperty_BaseKey:
case kAudioUnitCustomProperty_LowKey:
case kAudioUnitCustomProperty_HighKey:
case kAudioUnitCustomProperty_LoopPoint:
case kAudioUnitCustomProperty_Bank:
case kAudioUnitCustomProperty_AR:
case kAudioUnitCustomProperty_DR:
case kAudioUnitCustomProperty_SL:
case kAudioUnitCustomProperty_SR:
case kAudioUnitCustomProperty_VolL:
case kAudioUnitCustomProperty_VolR:
case kAudioUnitCustomProperty_EditingProgram:
case kAudioUnitCustomProperty_EditingChannel:
case kAudioUnitCustomProperty_MaxNoteTrack_1:
case kAudioUnitCustomProperty_MaxNoteTrack_2:
case kAudioUnitCustomProperty_MaxNoteTrack_3:
case kAudioUnitCustomProperty_MaxNoteTrack_4:
case kAudioUnitCustomProperty_MaxNoteTrack_5:
case kAudioUnitCustomProperty_MaxNoteTrack_6:
case kAudioUnitCustomProperty_MaxNoteTrack_7:
case kAudioUnitCustomProperty_MaxNoteTrack_8:
case kAudioUnitCustomProperty_MaxNoteTrack_9:
case kAudioUnitCustomProperty_MaxNoteTrack_10:
case kAudioUnitCustomProperty_MaxNoteTrack_11:
case kAudioUnitCustomProperty_MaxNoteTrack_12:
case kAudioUnitCustomProperty_MaxNoteTrack_13:
case kAudioUnitCustomProperty_MaxNoteTrack_14:
case kAudioUnitCustomProperty_MaxNoteTrack_15:
case kAudioUnitCustomProperty_MaxNoteTrack_16:
case kAudioUnitCustomProperty_PortamentoRate:
case kAudioUnitCustomProperty_NoteOnPriority:
case kAudioUnitCustomProperty_ReleasePriority:
mEfx->SetPropertyValue(inID, *((int*)inData) );
return noErr;
case kAudioUnitCustomProperty_Loop:
case kAudioUnitCustomProperty_Echo:
case kAudioUnitCustomProperty_IsEmaphasized:
case kAudioUnitCustomProperty_SustainMode:
case kAudioUnitCustomProperty_MonoMode:
case kAudioUnitCustomProperty_PortamentoOn:
mEfx->SetPropertyValue(inID, *((bool*)inData) ? 1.0f:.0f );
return noErr;
case kAudioUnitCustomProperty_TotalRAM:
return noErr;
case kAudioUnitCustomProperty_PGDictionary:
{
CFDictionaryRef pgdata = *((CFDictionaryRef*)inData);
int editProg = mEfx->GetPropertyValue(kAudioUnitCustomProperty_EditingProgram);
RestorePGDataDic(pgdata, editProg);
return noErr;
}
case kAudioUnitCustomProperty_XIData:
{
return noErr;
}
case kAudioUnitCustomProperty_ProgramName:
{
char pgname[PROGRAMNAME_MAX_LEN];
CFStringGetCString(*((CFStringRef*)inData), pgname, PROGRAMNAME_MAX_LEN-1, kCFStringEncodingUTF8);
mEfx->SetProgramName(pgname);
return noErr;
}
//エコー
case kAudioUnitCustomProperty_Band1:
case kAudioUnitCustomProperty_Band2:
case kAudioUnitCustomProperty_Band3:
case kAudioUnitCustomProperty_Band4:
case kAudioUnitCustomProperty_Band5:
mEfx->SetPropertyValue(inID, *((float*)inData) );
return noErr;
case kAudioUnitCustomProperty_NoteOnTrack_1:
case kAudioUnitCustomProperty_NoteOnTrack_2:
case kAudioUnitCustomProperty_NoteOnTrack_3:
case kAudioUnitCustomProperty_NoteOnTrack_4:
case kAudioUnitCustomProperty_NoteOnTrack_5:
case kAudioUnitCustomProperty_NoteOnTrack_6:
case kAudioUnitCustomProperty_NoteOnTrack_7:
case kAudioUnitCustomProperty_NoteOnTrack_8:
case kAudioUnitCustomProperty_NoteOnTrack_9:
case kAudioUnitCustomProperty_NoteOnTrack_10:
case kAudioUnitCustomProperty_NoteOnTrack_11:
case kAudioUnitCustomProperty_NoteOnTrack_12:
case kAudioUnitCustomProperty_NoteOnTrack_13:
case kAudioUnitCustomProperty_NoteOnTrack_14:
case kAudioUnitCustomProperty_NoteOnTrack_15:
case kAudioUnitCustomProperty_NoteOnTrack_16:
return noErr;
case kAudioUnitCustomProperty_SourceFileRef:
{
CFStringRef pathStr = CFURLCopyFileSystemPath(*((CFURLRef*)inData), kCFURLPOSIXPathStyle);
char path[PATH_LEN_MAX];
CFStringGetCString(pathStr, path, PATH_LEN_MAX-1, kCFStringEncodingUTF8);
CFRelease(pathStr);
mEfx->SetSourceFilePath(path);
return noErr;
}
}
}
return AUInstrumentBase::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;
}
//-----------------------------------------------------------------------------
static void AddNumToDictionary(CFMutableDictionaryRef dict, CFStringRef key, int value)
{
CFNumberRef num = CFNumberCreate(NULL, kCFNumberIntType, &value);
CFDictionarySetValue(dict, key, num);
CFRelease(num);
}
//-----------------------------------------------------------------------------
static void AddBooleanToDictionary(CFMutableDictionaryRef dict, CFStringRef key, bool value)
{
if ( value ) {
CFDictionarySetValue(dict, key, kCFBooleanTrue);
}
else {
CFDictionarySetValue(dict, key, kCFBooleanFalse);
}
}
//-----------------------------------------------------------------------------
// C700::SaveState
//-----------------------------------------------------------------------------
ComponentResult C700::SaveState(CFPropertyListRef *outData)
{
ComponentResult result;
result = AUInstrumentBase::SaveState(outData);
CFMutableDictionaryRef dict=(CFMutableDictionaryRef)*outData;
if (result == noErr) {
CFDictionaryRef pgdata;
CFStringRef pgnum,pgname;
for (int i=0; i<128; i++) {
const BRRData *brr = mEfx->GetBRRData(i);
if (brr->data) {
CreatePGDataDic(&pgdata, i);
pgnum = CFStringCreateWithFormat(NULL,NULL,CFSTR("pg%03d"),i);
CFDictionarySetValue(dict, pgnum, pgdata);
CFRelease(pgdata);
CFRelease(pgnum);
}
}
// 作業状態を保存
int editProg = mEfx->GetPropertyValue(kAudioUnitCustomProperty_EditingProgram);
int editChan = mEfx->GetPropertyValue(kAudioUnitCustomProperty_EditingChannel);
AddNumToDictionary(dict, kSaveKey_EditProg, editProg);
AddNumToDictionary(dict, kSaveKey_EditChan, editChan);
pgname = CFStringCreateCopy(NULL,CFSTR("C700"));
CFDictionarySetValue(dict, CFSTR(kAUPresetNameKey), pgname);
CFRelease(pgname);
}
return result;
}
//-----------------------------------------------------------------------------
// C700::RestoreState
//-----------------------------------------------------------------------------
ComponentResult C700::RestoreState(CFPropertyListRef plist)
{
ComponentResult result;
result = AUInstrumentBase::RestoreState(plist);
CFDictionaryRef dict = static_cast<CFDictionaryRef>(plist);
if (result == noErr) {
//波形情報の復元
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));
RestorePGDataDic(pgdata, i);
}
CFRelease(pgnum);
}
if (CFDictionaryContainsKey(dict, kSaveKey_EditChan)) {
int editChan = mEfx->GetPropertyValue(kAudioUnitCustomProperty_EditingChannel);
CFNumberRef cfnum = reinterpret_cast<CFNumberRef>(CFDictionaryGetValue(dict, kSaveKey_EditChan));
CFNumberGetValue(cfnum, kCFNumberIntType, &editChan);
//変更の通知
mEfx->SetPropertyValue(kAudioUnitCustomProperty_EditingChannel, editChan);
}
if (CFDictionaryContainsKey(dict, kSaveKey_EditProg)) {
int editProg;
CFNumberRef cfnum = reinterpret_cast<CFNumberRef>(CFDictionaryGetValue(dict, kSaveKey_EditProg));
CFNumberGetValue(cfnum, kCFNumberIntType, &editProg);
//変更の通知
mEfx->SetPropertyValue(kAudioUnitCustomProperty_EditingProgram, editProg);
}
}
return result;
}
//-----------------------------------------------------------------------------
int C700::CreatePGDataDic(CFDictionaryRef *data, int pgnum)
{
CFMutableDictionaryRef dict = CFDictionaryCreateMutable (NULL, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
const InstParams *vpSet = mEfx->GetVP();
if (vpSet[pgnum].loop) {
vpSet[pgnum].brr.data[vpSet[pgnum].brr.size - 9] |= 2;
}
else {
vpSet[pgnum].brr.data[vpSet[pgnum].brr.size - 9] &= ~2;
}
CFDataRef brrdata = CFDataCreate(NULL, vpSet[pgnum].brr.data, vpSet[pgnum].brr.size);
CFDictionarySetValue(dict, kSaveKey_brrdata, brrdata);
CFRelease(brrdata);
AddNumToDictionary(dict, kSaveKey_looppoint, vpSet[pgnum].lp);
CFNumberRef num = CFNumberCreate(NULL, kCFNumberDoubleType, &vpSet[pgnum].rate);
CFDictionarySetValue(dict, kSaveKey_samplerate, num);
CFRelease(num);
AddNumToDictionary(dict, kSaveKey_basekey, vpSet[pgnum].basekey);
AddNumToDictionary(dict, kSaveKey_lowkey, vpSet[pgnum].lowkey);
AddNumToDictionary(dict, kSaveKey_highkey, vpSet[pgnum].highkey);
AddNumToDictionary(dict, kSaveKey_ar, vpSet[pgnum].ar);
AddNumToDictionary(dict, kSaveKey_dr, vpSet[pgnum].dr);
AddNumToDictionary(dict, kSaveKey_sl, vpSet[pgnum].sl);
AddNumToDictionary(dict, kSaveKey_sr, vpSet[pgnum].sr);
AddBooleanToDictionary(dict, kSaveKey_SustainMode, vpSet[pgnum].sustainMode);
AddNumToDictionary(dict, kSaveKey_volL, vpSet[pgnum].volL);
AddNumToDictionary(dict, kSaveKey_volR, vpSet[pgnum].volR);
AddBooleanToDictionary(dict, kSaveKey_echo, vpSet[pgnum].echo);
AddNumToDictionary(dict, kSaveKey_bank, vpSet[pgnum].bank);
AddBooleanToDictionary(dict, kSaveKey_MonoMode, vpSet[pgnum].monoMode);
AddBooleanToDictionary(dict, kSaveKey_PortamentoOn, vpSet[pgnum].portamentoOn);
AddNumToDictionary(dict, kSaveKey_PortamentoRate, vpSet[pgnum].portamentoRate);
AddNumToDictionary(dict, kSaveKey_NoteOnPriority, vpSet[pgnum].noteOnPriority);
AddNumToDictionary(dict, kSaveKey_ReleasePriority, vpSet[pgnum].releasePriority);
//元波形情報
AddBooleanToDictionary(dict, kSaveKey_IsEmphasized, vpSet[pgnum].isEmphasized);
if ( vpSet[pgnum].sourceFile[0] ) {
CFURLRef url =
CFURLCreateFromFileSystemRepresentation(NULL, (UInt8*)vpSet[pgnum].sourceFile,
strlen(vpSet[pgnum].sourceFile), false);
CFDataRef urlData = CFURLCreateData( NULL, url, kCFStringEncodingUTF8, false );
CFDictionarySetValue(dict, kSaveKey_SourceFile, urlData);
CFRelease(urlData);
CFRelease(url);
}
//プログラム名
if (vpSet[pgnum].pgname[0] != 0) {
CFStringRef str = CFStringCreateWithCString(NULL, vpSet[pgnum].pgname, kCFStringEncodingUTF8);
CFDictionarySetValue(dict, kSaveKey_ProgName, str);
CFRelease(str);
}
*data = dict;
return 0;
}
//-----------------------------------------------------------------------------
void C700::RestorePGDataDic(CFPropertyListRef data, int pgnum)
{
int editProg = mEfx->GetPropertyValue(kAudioUnitCustomProperty_EditingProgram);
mEfx->SetPropertyValue(kAudioUnitCustomProperty_EditingProgram, pgnum);
CFDictionaryRef dict = static_cast<CFDictionaryRef>(data);
CFNumberRef cfnum;
CFDataRef cfdata = reinterpret_cast<CFDataRef>(CFDictionaryGetValue(dict, kSaveKey_brrdata));
int size = CFDataGetLength(cfdata);
const UInt8 *dataptr = CFDataGetBytePtr(cfdata);
BRRData brr;
brr.data = const_cast<unsigned char*>(dataptr);