download ArielQP.m
Language: ObjectiveC
Copyright: (c) 1988-1992, NeXT Computer, Inc. (c) 1994 NeXT Computer, Inc. and reproduced under license from NeXT (c) 1994 Stanford University
LOC: 392
Project Info
The MusicKit(musickit)
Server: SourceForge
Type: cvs
...sicKit\Frameworks\MusicKit\
   _ArielQP.h
   _DSPMK.h
   _error.h
   _midi.h
   _MKAppProxy.h
   _MKAppProxy.m
   _MKNameTable.h
   _MKNameTable.m
   _MKParameter.h
   _MTCHelper.h
   _MTCHelper.m
   _musickit.h
   _noteRecorder.h
   _OrchloopbeginUG.h
   _OrchloopbeginUG.m
   _ParName.h
   _ParName.m
   _scorefile.h
   _ScorefileVar.h
   _ScorefileVar.m
   _SharedSynthInfo.h
   _SharedSynthInfo.m
   _synthElementMethods.m
   _time.h
   ArielQP.h
   ArielQP.m
   classFuncs.h
   ConductorPrivate.h
   dsp_types.h
   DSPSerialPortDevice.h
   dspwrap.h
   EnvelopePrivate.h
   equalTempered.m
   errors.h
   fastFFT.c
   fastFFT.h
   GNUmakefile.postamble
   GNUmakefile.preamble.in
   InstrumentPrivate.h
   keynums.h
   libMusicKit.def
   Localized.strings
   make.sh
   Makefile.postamble
   Makefile.preamble
   midi_spec.h
   midifile.h
   midifile.m
   MidiPrivate.h
   midiTranslation.h
   MKConductor.h
   MKConductor.m
   MKConductorDelegate.h
   MKDeviceStatus.h
   MKEnvelope.h
   MKEnvelope.m
   MKFilePerformer.h
   MKFilePerformer.m
   MKFileWriter.h
   MKFileWriter.m
   MKInstrument.h
   MKInstrument.m
   MKMidi.h
   MKMidi.m
   MKMixerInstrument.h
   MKMixerInstrument.m
   MKMTCPerformer.h
   MKMTCPerformer.m
   MKNote.h
   MKNoteFilter.h
   MKNoteFilter.m
   MKNoteReceiver.h
   MKNoteReceiver.m
   MKNoteSender.h
   MKNoteSender.m
   MKOrchestra.h
   MKPart.m
   MKPartials.h
   MKPartials.m
   ...tialsWaveshapingTable.m
   MKPartPerformer.h
   MKPartPerformer.m
   MKPartRecorder.h
   MKPartRecorder.m
   MKPatch.h
   MKPatch.m
   MKPatchConnection.h
   MKPatchConnection.m
   MKPatchEntry.h
   MKPatchEntry.m
   MKPatchTemplate.h
   MKPatchTemplate.m
   MKPerformer.h
   MKPerformer.m
   MKPerformerDelegate.h
   MKPlugin.h
   MKSamplerInstrument.h
   MKSamplerInstrument.m
   MKSamples.h
   MKScore.h
   MKScore.m
   MKScorefileObject.h
   MKScorefilePerformer.h
   MKScorefilePerformer.m
   MKScorefileWriter.m
   MKScorePerformer.h
   MKScorePerformer.m
   MKScoreRecorder.h
   MKScoreRecorder.m
   MKSynthData.h
   MKSynthData.m
   MKSynthInstrument.h
   MKSynthPatch.h
   MKTimbre.h
   MKTimbre.m
   MKTuningSystem.h
   MKTuningSystem.m
   MKUnitGenerator.h
   MKUnitGenerator.m
   MKWaveTable.h
   MKWaveTable.m
   mtcMidi.m
   mtcMidiPrivate.m
   MusicKit-Info.plist
   MusicKit.h
   MusicKitConfig.h.in
   names.h
   noDVal.h
   noteDispatcherMethods.m
   NotePrivate.h
   noteRecorderCFuncs.m
   noteRecorderMethods.m
   orch.h
   OrchestraPrivate.h
   OrchloopbeginUG.h
   OrchloopbeginUG.m
   orchloopbeginUGInclude.m
   params.h
   parNames.m
   partialsDBInclude.m
   PartialsPrivate.h
   PartPerformerPrivate.h
   PartPrivate.h
   PartRecorderPrivate.h
   PatchTemplatePrivate.h
   PB.project
   PerformerPrivate.h
   pitches.h
   platform.make
   ...efilePerformerPrivate.h
   ScorePerformerPrivate.h
   ScorePrivate.h
   ScoreRecorderPrivate.h
   SynthDataPrivate.h
   synthElementCFuncs.m
   synthElementMethods.m
   SynthInstrumentPrivate.h
   SynthPatchList.h
   SynthPatchList.m
   SynthPatchPrivate.h
   timetagInclude.m
   timeunits.h
   tokenNames.m
   tokens.h
   trigonometry.c
   trigonometry.h
   TuningSystemPrivate.h
   UnitGeneratorPrivate.h
   win32-def.top
   writeBinary.m
   writeMidi.m
   writeScore.m

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
/*
  $Id: ArielQP.m,v 1.5 2000/04/07 18:47:09 leigh Exp $
  Defined In: The MusicKit

  Description:
  Original Author: David Jaffe

  Copyright (c) 1988-1992, NeXT Computer, Inc.
  Portions Copyright (c) 1994 NeXT Computer, Inc. and reproduced under license from NeXT
  Portions Copyright (c) 1994 Stanford University
*/
/*
Modification history:

  $Log: ArielQP.m,v $
  Revision 1.5  2000/04/07 18:47:09  leigh
  Upgraded logging to NSLog

  Revision 1.4  2000/03/07 18:21:14  leigh
  Removed redundant getTime function (using NSDate nowdays)

  Revision 1.3  2000/01/13 06:41:46  leigh
  Corrected _MKErrorf to take NSString error message

  Revision 1.2  1999/07/29 01:25:42  leigh
  Added Win32 compatibility, CVS logs, SBs changes

*/
#import "_musickit.h"
#import <Foundation/NSArray.h>
#import "_ArielQP.h"
#import "OrchestraPrivate.h"
#import "_error.h"

@implementation ArielQP:MKOrchestra
{
    int slot;         /* One of 2, 4 or 6 */
    BOOL satSoundIn;  /* YES if we're receiving sound from the satellites */
    BOOL DRAMAutoRefresh; /* YES if we're refreshing when needed */
    MKSynthData * _satSynthData; /* Buffers for incoming sound data */
    BOOL _initialized;
    NSDate * _reservedArielQP1; //sb: was double
}

#define NO_SLOT (-1)
#define NO_DSP (-1)
#define NO_BOARD (-1)

#define SLOT_TO_BOARD(_slot) ((_slot==2)?0:(_slot==4)?1:(_slot==6)?2:NO_BOARD)
#define SLOT_TO_HUB(_slot) ((_slot==2)?5:(_slot==4)?10:(_slot==6)?15:NO_DSP)
#define HUB_TO_SLOT(_index) ((_index==5)?2:(_index==10)?4:(_index==15)?6:NO_SLOT)
#define VALID_SLOT(_slot) ((_slot == 2)||(_slot == 4)||(_slot == 6))

+ (void)initialize
{
    int i;
    int dsps = [MKOrchestra DSPCount];
    if (dsps > 15) 
      dsps = 15;
    for (i=1; i<= dsps; i++)
      if ((i % 5)==0)
	[MKOrchestra registerOrchestraSubclass:self forOrchIndex:i];
      else [MKOrchestra registerOrchestraSubclass:[ArielQPSat class] 
	    forOrchIndex:i];
    return;
}

+allocFromZone:(NSZone *)zone onDSP:(unsigned short)index
{
    int theSlot = HUB_TO_SLOT(index);
    ArielQP *obj;
    if (!VALID_SLOT(theSlot))
      return nil;
    obj = [super allocFromZone:zone onDSP:index];
    if (!obj)    /* This will happen if QP is not there. */
      return nil;
    obj->slot = theSlot;
    return obj;
}

+allocFromZone:(NSZone *)zone inSlot:(unsigned short)slotNumber
{
    if (!VALID_SLOT(slotNumber))
      return nil;
    return [self allocFromZone:zone onDSP:SLOT_TO_HUB(slotNumber)];
}

+newInSlot:(unsigned short)slotNumber
{
    return [[self allocFromZone:NSDefaultMallocZone() inSlot:slotNumber] init];
}

+new
{
    return [[self alloc] init];
}

+alloc
{
    return [self allocFromZone:NSDefaultMallocZone() inSlot:2];
}

+ allocWithZone:(NSZone *)zone
{
    return [self allocFromZone:zone inSlot:2];
}

-init
  /* Creates all satellite DSPs */
{
    int board = SLOT_TO_BOARD(slot);
    int i,startDSP,hubDSP;
    id obj;
    [super init];
    if (_initialized)
      return self;
    _initialized = YES;
    [self setSoundOut:NO];
    [self setSerialSoundOut:YES];
    [self setSatSoundIn:YES];
    startDSP = 1+board*5;
    if (startDSP >= [MKOrchestra DSPCount]) {
	[super release];
        return nil; /* sb: nil for compatibility with old -free method */
    }
    hubDSP = startDSP + 4;
    for (i=startDSP; i<hubDSP; i++) {
	obj = [ArielQPSat newOnDSP:i];
	if (!obj) {
	    [super release];
            return nil; /* sb: nil for compatibility with old -free method */

	}
    }
    [self setMonitorFileName:@"mkmon_A_qp_hub_8k.dsp"];
    return self;
}

-(double)systemOverhead
{
    return (satSoundIn) ? .3 : 0;
}

-(BOOL)startSoundWhenOpening {
    return NO;
}

-setUpDSP
  /* This gets invoked by -open method when DSP is booted but before sound
   * of any kind is started.  
   */
{
    if (satSoundIn) {
	int addr;
	int varAddr;
	int hmVal;
	int bufferSize = DSPGetSystemSymbolValueInLC("NB_DMA_W", DSP_LC_N);
#if 1
	if (bufferSize != 0x200)
	  NSLog(@"Warning: NB_DMA_W != 0x200.  == %d\n",bufferSize);
#endif
	_satSynthData = [self allocSynthData:MK_yData length:bufferSize*4]; /* FIXME */
        if (!_satSynthData)
	  NSLog(@"Can't allocate hub memory.\n");
	addr = [_satSynthData address];
        varAddr =  DSPGetSystemSymbolValueInLC("X_SAT1_REB", DSP_LC_X);     
        if (varAddr > 0)
	  DSPWriteValue(addr,DSP_MS_X,varAddr);
        else _MKErrorf(MK_dspMonitorVersionError, NSStringFromClass([self class]));
	hmVal = DSPGetSystemSymbolValueInLC("HM_DMA_RD_SAT_ON", DSP_LC_P);      
	if (hmVal > 0)
	  DSPHostMessage(hmVal);
        else _MKErrorf(MK_dspMonitorVersionError, NSStringFromClass([self class]));
    }
    return self;
}

-(BOOL)DRAMAutoRefresh
{
    return DRAMAutoRefresh;
}


- setDRAMAutoRefresh:(BOOL)yesOrNo
{
    int hmVal;
    char *s;
    if (yesOrNo == DRAMAutoRefresh)
      return self;
    DRAMAutoRefresh = yesOrNo;
    if (yesOrNo)
      s = "HM_DRAM_REFRESH_ON";
    else s = "HM_DRAM_REFRESH_OFF";
    hmVal = DSPGetSystemSymbolValueInLC(s, DSP_LC_P);      
    if (hmVal > 0) {
	DSPHostMessage(hmVal);
	return self;
    }
    _MKErrorf(MK_dspMonitorVersionError, NSStringFromClass([self class]));
    return nil;
}

-abort
{
    [_satSynthData release];
    _satSynthData = nil;
    return [super abort];
}

-satellite:(char)which
{
    if (which < 'A' || which > 'D')
      return nil;
    which -= 'A';
    which += (orchIndex - 4);
    return [ArielQPSat newOnDSP:which];
}

-setSatSoundIn:(BOOL)yesOrNo
  /* Default is YES. */
{
    int i;
    if (deviceStatus != MK_devClosed)
      return nil;
    for (i='A';i<='D';i++) {
	[[self satellite:i] _setHubSoundOut:yesOrNo];
    }
    [self _setSatSoundIn:yesOrNo];
    return self;
}

-(BOOL)satSoundIn
{
    return satSoundIn;
}

-makeSatellitesPerform:(SEL)selector
{
    [[self satellite:'A'] performSelector:selector];
    [[self satellite:'B'] performSelector:selector];
    [[self satellite:'C'] performSelector:selector];
    [[self satellite:'D'] performSelector:selector];
    return self;
}

-makeQPPerform:(SEL)selector
{
    [self makeSatellitesPerform:selector];
    [self performSelector:selector];
    return self;
}

-makeSatellitesPerform:(SEL)selector with:arg;
{
    [[self satellite:'A'] performSelector:selector withObject:arg];
    [[self satellite:'B'] performSelector:selector withObject:arg];
    [[self satellite:'C'] performSelector:selector withObject:arg];
    [[self satellite:'D'] performSelector:selector withObject:arg];
    return self;
}

-makeQPPerform:(SEL)selector with:arg;
{
    [self makeSatellitesPerform:selector with:arg];
    [self performSelector:selector withObject:arg];
    return self;
}

- (void)dealloc
{
    [self makeQPPerform:@selector(abort)];
    [self makeSatellitesPerform:@selector(release)];
    [super dealloc];
}

- close
{
    if (!satSoundIn)
        return [super close];
    [super close];  /* Waits for the end of time */
    [self makeSatellitesPerform:@selector(abort)];
    return self;
}

#define DSP_AWAIT_BROKEN 1

#if DSP_AWAIT_BROKEN
/* The following is to work around the fact that we can't seem to
 * wait for the end of time successfully. 
 */

#define _runT _reservedArielQP1 

-awaitEndOfTime:(double)endOfTime timeStamp:(DSPTimeStamp *)aTimeStampP
/* sb: endOfTime should be relative, so _runT needs to be absolute  (relative - (abs - abs))*/
{
//    double timeToWait = endOfTime - ([NSDate date]-_runT);
    double timeToWait = endOfTime + [_runT timeIntervalSinceNow];//sb: timeIntervalSinceNow is neg!
//    int sleepTime = timeToWait + .9999999; /* Round up */ //sb: unnecessary now, as sleepuntilDate uses millis.
    [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:(timeToWait)]]; //sb: changed from sleepTime
    return self;
}

- run
{
    id val = [super run];
    [_runT autorelease];//sb
    _runT = [[NSDate date] retain]; //sb: was getTime();
    return val;
}
#endif


@end

@implementation ArielQP(Private)

-_setSatSoundIn:(BOOL)yesOrNo
  /* Default is YES. */
{
    satSoundIn = yesOrNo;
    return self;
}

@end


@implementation ArielQPSat:MKOrchestra
{
    BOOL hubSoundOut; /* YES if we're sending sound to the hub. */
    NSDate * _reservedArielQPSat1; //sb: this is a timestamp, thus changed from double to NSDate *
}

#if DSP_AWAIT_BROKEN
/* The following is to work around the fact that we can't seem to
 * wait for the end of time successfully. 
 */
#undef _runT
#define _runT _reservedArielQPSat1 
-awaitEndOfTime:(double)endOfTime timeStamp:(DSPTimeStamp *)aTimeStampP
{
//    double timeToWait = endOfTime - ([NSDate date]-_runT); //sb: was getTime();
    double timeToWait = endOfTime + [_runT timeIntervalSinceNow];//sb: timeIntervalSinceNow is neg!
//    int sleepTime = timeToWait + .9999999; /* Round up */ //sb: unnec because sleepUntilDate works!
    [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:(timeToWait)]];//sb: was sleepTime
    return self;
}

- run
{
    id val = [super run];
    _runT = [NSDate date]; //sb: was getTime();
    return val;
}
#endif

static int getSlot(int index)
{
    int i = index;
    if (i >= 1 && i <= 4)
      return 2;
    else if (i >= 6 && i <= 9)
      return 4;
    else if (i >= 11 && i <= 14)
      return 6;
    return NO_SLOT;
}

static int validSlot(int i)
{
    return (i==2 || i==4 || i==6);
}

-(BOOL)isRealTime
{
    return hubSoundOut ? [[self hub] isRealTime] : [super isRealTime];
}

-hub
{
    int slot;
    slot = getSlot(self->orchIndex);
    return [ArielQP newInSlot:slot];
}

+allocFromZone:(NSZone *)zone onDSP:(unsigned short)index
{
    int slot = getSlot(index);
    if (!validSlot(slot))
      return nil;
    return [super allocFromZone:zone onDSP:index];
}

-init
{
    [super init];
    [self setSoundOut:NO];
    hubSoundOut = YES;
    [self setMonitorFileName:@"mkmon_A_qp_sat_16k.dsp"];
    return self;
}

-(BOOL)startSoundWhenOpening {
    return NO;
}

- close
{
    if (hubSoundOut)
      return self;
    else return [super close];
}

-setUpDSP
{
    int hmVal;
#if 0
    int varAddr =  DSPGetSystemSymbolValueInLC("X_SAT_ID", DSP_LC_X);     
    int theBit;
    theBit = 1 << (self->orchIndex - 1)*2;
    if (varAddr > 0)
      DSPWriteValue(theBit,DSP_MS_X,varAddr);
    else NSLog(@"Warning: Can't find X_SAT_ID\n");
#endif
    if (hubSoundOut) {
	hmVal = DSPGetSystemSymbolValueInLC("HM_DMA_WD_HUB_ON", DSP_LC_P);      
	if (hmVal > 0)
	  DSPHostMessage(hmVal);
        else _MKErrorf(MK_dspMonitorVersionError, NSStringFromClass([self class]));
    }
    return self;
}

-setHubSoundOut:(BOOL)yesOrNo
  /* Default is YES. Setting hubSoundOut disables serialSoundOut.  */
{
    if (deviceStatus != MK_devClosed)
      return nil;
    [[self hub] setSatSoundIn:yesOrNo];
    return self;
}

-setSerialSoundOut:(BOOL)yesOrNo
{
    if (deviceStatus != MK_devClosed)
      return nil;
    if (yesOrNo == serialSoundOut)
      return self;
    if (yesOrNo)
      [self setHubSoundOut:NO];
    [super setSerialSoundOut:YES];
    return self;
}

-(BOOL)hubSoundOut
{
    return hubSoundOut;
}

-(int)outputChannelOffset
  /* Offset in DSP sound output buffer of the second channel.
   * Note that we don't support simultaneous SSI output and hub output.
   * If hubSoundOut, Hub orchestra's serialPortDevice must be set before 
   * sending this message.
   */
{
    if (serialSoundOut) 
      return [super outputChannelOffset];
    else return [[self hub] outputChannelOffset]; 
}

-(int)outputChannelCount
{
    if (serialSoundOut) 
      return [super outputChannelCount];
    else return [[self hub] outputChannelCount]; 
}	    

-(BOOL)upSamplingOutput
{
    if (serialSoundOut) 
      return [super upSamplingOutput];
    else return [[self hub] upSamplingOutput]; 
}

-(int)outputInitialOffset
  /* Offset in DSP sound output buffer of the second channel */
{
    if (serialSoundOut) 
      return [super outputInitialOffset];
    else return [[self hub] outputInitialOffset]; 
}

@end

@implementation ArielQPSat(Private)

-_setHubSoundOut:(BOOL)yesOrNo
  /* Default is YES. Setting hubSoundOut disables serialSoundOut.  */
{
    hubSoundOut = yesOrNo;
    if (yesOrNo)
      [self setSerialSoundOut:NO];
    return self;
}

@end

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us