download MKNoteSender.m
Language: ObjectiveC
Copyright: (c) 1988-1992, NeXT Computer, Inc. (c) 1999-2004, The MusicKit Project. (c) 1994 NeXT Computer, Inc. and reproduced under license from NeXT (c) 1994 Stanford University
LOC: 235
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
/*
 $Id: MKNoteSender.m,v 1.12 2005/03/22 06:10:27 leighsmith Exp $
 Defined In: The MusicKit
 HEADER FILES: MusicKit.h
 
 Description:
   See comments in MKNoteSender.h
 
 Original Author: David A. 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  
 Portions Copyright (c) 1999-2004, The MusicKit Project.
 */
/* 
Modification history prior to commit to CVS:
 
 09/19/89/daj - Changed dataObject to type void *.
 03/13/90/daj - Moved private methods to category.
 03/21/90/daj - Added archiving.
 04/21/90/daj - Small mods to get rid of -W compiler warnings.
 08/23/90/daj - Zone API changes
 09/23/95/daj - Bug fix to copyFromZone:. 
 */
#import "_musickit.h"
#import "NotePrivate.h"
#import "MKNoteSender.h"

@implementation MKNoteSender

#define VERSION2 2

+ (void) initialize
{
    if (self != [MKNoteSender class])
	return;
    [MKNoteSender setVersion: VERSION2];//sb: suggested by Stone conversion guide (replaced self)
}

/* Gets the owner (an MKInstrument or MKNoteFilter). */
- owner
{
    return owner;
}

/* Querying; YES if aNoteReceiver is a connection.
* Returns YES if aNoteReceiver is connected to the receiver.
*/
- (BOOL) isConnected: (MKNoteReceiver *) aNoteReceiver 
{
    return ([noteReceivers indexOfObject: aNoteReceiver] != NSNotFound); 
}

/* Squelch; Turns off message-sending capability.
* Squelches the receiver.  While a receiver is squelched it can't send
* messages to its noteReceivers.
*
* Note:  You can schedule a sendNote: message through
* sendNote:atTime: or sendNote:withDelay even if the
* receiver is squelched.
* However, if the receiver is still squelched when the
* sendNote: message is received, the MKNote isn't sent.
*
* Returns the receiver.
*/
- squelch
{
    isSquelched = YES;
    return self;
}

/* Squelch; Turns on message-sending capability.
* Unsquelches and returns the receiver.
*/
- unsquelch
{
    isSquelched = NO;
    return self;
}

/* Querying; YES if the receiver is squelched.
* Returns YES if the receiver is squelched.
*/
- (BOOL) isSquelched
{
    return isSquelched;
}

/* Querying; Returns the number of noteReceivers.
* Returns the number of noteReceivers in the
* receiver's connection set.
*/
- (unsigned) connectionCount
{
    return [noteReceivers count];
}

/* Manipulating; Returns an NSArray of the connections - the receiver's noteReceivers. */
- (NSArray *) connections
{
    return [[noteReceivers copy] autorelease];
}

- (void) dealloc 
{
    // Illegal while the receiver is sending.
    if (isSending)
	NSLog(@"Assertion failed: attempting to dealloc while MKNoteSender %@ is sending %d\n", self, isSending);
    
    if (noteReceivers != nil) {
	// NSLog(@"in MKNoteSenders dealloc disconnecting all receivers %p\n", noteReceivers);
	[self disconnectAllReceivers];
	[noteReceivers release];
	noteReceivers = nil;
    }
    [dataObject release];
    dataObject = nil;
    // We don't release the owner since it is a weak reference.
    // Also removes the name, if any, from the name table. TODO check if appropriate to do here.
    MKRemoveObjectName(self);
    [super dealloc];
}			

- (NSString *) description
{
    return [NSString stringWithFormat: @"%@ connected to %@\n", [super description], noteReceivers];
}

- init
{
    self = [super init];
    if(self != nil) {
	noteReceivers = [[NSMutableArray alloc] initWithCapacity: 2];
	isSending = 0;
	owner = nil;
	dataObject = nil;
    }
    return self;
}

// Disconnects aNoteReceiver from our MKNoteSender instance.
- disconnect: (MKNoteReceiver *) aNoteReceiver
{
    if (!aNoteReceiver) 
	return self;
    if ([aNoteReceiver _disconnect: self])
	[self _disconnect: aNoteReceiver];
    return self;
}	

/* Manipulating; Connects aNoteReceiver to the receiver.
* Connects aNoteReceiver to the receiver 
* and returns self.  
*/
- connect: (MKNoteReceiver *) aNoteReceiver 
{
    if (![aNoteReceiver isKindOfClass: [MKNoteReceiver class]])
	return self;
    if ([self _connect: aNoteReceiver])  
	[aNoteReceiver _connect: self];    
    return self;
}

- (void) disconnectAllReceivers
{
    /* This can happen if you use finishUnarchiving to replace a MKNoteSender */
    if (noteReceivers != nil) {
	// causes a release of each element in the noteReceivers NSArray. dealloc in each noteReceiver
	// must not then disconnect senders as this will cause a release cycle.
	[noteReceivers removeAllObjects];
    }
}

/* Keep in mind that the connection set may change between the time that
 * this message is received and the time that the sendNote:
 * message is sent.
 */
- (void) sendNote: (MKNote *) aNote atTime: (double) time
{	
    [[aNote conductor] sel: @selector(sendNote:) to: self atTime: time argCount: 1, aNote];
}

/* Keep in mind that the connection set may change between the time that
 * this message is received and the time that the sendNote:
 * message is sent.
 */
- (void) sendNote: (MKNote *) aNote withDelay: (double) deltaT
{
    [[aNote conductor] sel: @selector(sendNote:) to: self withDelay: deltaT argCount: 1, aNote];
}

/* Sends the specifed note, delayed by delayTime from the
current time, as far as the note's conductor is concerned. Then
frees the note. */
- sendAndFreeNote: (MKNote *) aNote withDelay: (double) delayTime
{
    [[aNote conductor] sel: @selector(sendAndFreeNote:) to: self withDelay: delayTime argCount: 1, aNote];
    return self;
}

/* Send note and then free it. */
- sendAndFreeNote: (MKNote *) aNote
{
    [self sendNote: aNote];
    [aNote release];
    return self;
}

/* Send the specifed note at the specified time using
the note's MKConductor for time coordination. Then free the note. */
- sendAndFreeNote: (MKNote *) aNote atTime: (double) time
{
    [[aNote conductor] sel: @selector(sendAndFreeNote:) to: self atTime: (double) time argCount: 1, aNote];
    return self;
}

/* Sending; Immediately sends aNote.
* If the receiver isn't squelched, the receiveNote:aNote
* message is sent to its noteReceivers and the receiver is returned.
* If the receiver is squelched, the message isn't sent 
* and nil is returned.
*/
- sendNote: (MKNote *) aNote
{
    if (![self connectionCount])
	return self;
    if (_ownerIsAPerformer)
	[aNote _setPerformer: owner];
    isSending++;
    if(!isSquelched)
	[noteReceivers makeObjectsPerformSelector: @selector(receiveNote:) withObject: aNote];
    if (_ownerIsAPerformer)
	[aNote _setPerformer: nil];
    isSending--;
    return (isSquelched) ? nil : self;
}

/* Creates a new MKNoteSender as a copy of the receiver.
* Creates, initializes, and returns a new MKNoteSender with the same noteReceivers as the receiver.
* Thus a new array but the elements are the original noteSenders.
* If we copied the noteSenders, then we couldn't connect senders.
*/
- copyWithZone: (NSZone *) zone
{
    unsigned int noteReceiverIndex;
    MKNoteSender *newObj = NSCopyObject(self, 0, zone);
    
    newObj->noteReceivers = [[NSMutableArray arrayWithCapacity: [noteReceivers count]] retain];
    for (noteReceiverIndex = 0; noteReceiverIndex < [noteReceivers count]; noteReceiverIndex++) {
        [newObj connect: [noteReceivers objectAtIndex: noteReceiverIndex]];
    }
    newObj->dataObject = [dataObject retain];
    newObj->owner = owner;
    newObj->_ownerIsAPerformer = _ownerIsAPerformer;
    newObj->isSending = isSending;
    return newObj;
}

- (void) encodeWithCoder: (NSCoder *) aCoder
{
    // Check if decoding a newer keyed coding archive
    if([aCoder allowsKeyedCoding]) {
	NSString *objectName = MKGetObjectName(self);
	
	/* We don't write connection count here because we can deduce it in initWithCoder: */
	[aCoder encodeConditionalObject: noteReceivers forKey: @"MKNoteSender_noteReceivers"];
	[aCoder encodeObject: objectName forKey: @"MKNoteSender_objectName"];
	[aCoder encodeBool: isSquelched forKey: @"MKNoteSender_isSquelched"];
	[aCoder encodeBool: _ownerIsAPerformer forKey: @"MKNoteSender_ownerIsAPerformer"];
	[aCoder encodeConditionalObject: owner forKey: @"MKNoteSender_owner"];
    }
    else {
	NSString *str = MKGetObjectName(self);
	/* We don't write connection count here because we can deduce it in initWithCoder: */
	[aCoder encodeValuesOfObjCTypes:"@cc", &str, &isSquelched, &_ownerIsAPerformer];
	[aCoder encodeConditionalObject:owner];
	[aCoder encodeConditionalObject:noteReceivers];
    }    
}

- (id) initWithCoder: (NSCoder *) aDecoder
{
    // Check if decoding a newer keyed coding archive
    if([aDecoder allowsKeyedCoding]) {
	NSString *objectName;
	
	[noteReceivers release];
	noteReceivers = [[aDecoder decodeObjectForKey: @"MKNoteSender_noteReceivers"] retain];
	objectName = [aDecoder decodeObjectForKey: @"MKNoteSender_objectName"];
	if (objectName) {
	    MKNameObject(objectName, self);
	}
	isSquelched = [aDecoder decodeBoolForKey: @"MKNoteSender_isSquelched"];
	_ownerIsAPerformer = [aDecoder decodeBoolForKey: @"MKNoteSender_ownerIsAPerformer"];
	[owner release];
	owner = [[aDecoder decodeObjectForKey: @"MKNoteSender_owner"] retain];
    }
    else {
	NSString *str;
	if ([aDecoder versionForClassName: @"MKNoteSender"] == VERSION2) {
	    [aDecoder decodeValuesOfObjCTypes: "@cc", &str, &isSquelched, &_ownerIsAPerformer];
	    if (str) {
		MKNameObject(str, self);
		[str release];
	    }
	    owner = [[aDecoder decodeObject] retain];
	    noteReceivers = [[aDecoder decodeObject] retain];
	}
    }
    return self;    
}

@end

@implementation MKNoteSender(Private)

/* Sets the owner (an MKInstrument or MKNoteFilter). In most cases,
only the owner itself sends this message. 
*/
- _setOwner: obj
{
    owner = obj;
    return self;
}

/* Facility for associating arbitrary data with a MKNoteSender */
- (void) _setData: (id) anObj 
{
    [dataObject release];
    dataObject = [anObj retain];
}

- (id) _getData
{
    return [[dataObject retain] autorelease];
}

- (void) _setPerformer: aPerformer
{
    if (!aPerformer) 
	_ownerIsAPerformer = NO;
    else {
	owner = aPerformer;
	_ownerIsAPerformer = YES;
    }
}

- _disconnect: (MKNoteReceiver *) aNoteReceiver
{
    unsigned int i;
    
    if (noteReceivers == nil) /* This can happen if you use finishUnarchiving to replace a MKNoteSender */
	return self;
    if ((i = [noteReceivers indexOfObject: aNoteReceiver]) != NSNotFound) {
	[noteReceivers removeObjectAtIndex: i];
	return self;
    }
    return nil;
}

- _connect: (MKNoteReceiver *) aNoteReceiver
{
    unsigned int i = [noteReceivers indexOfObject: aNoteReceiver];
    
    if (i != NSNotFound) 
	return nil; /* Already there. */
    [noteReceivers addObject: aNoteReceiver];
    return self;
}

@end

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