-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathChord.m
executable file
·346 lines (304 loc) · 8.36 KB
/
Chord.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
//
// Chord.m
// Señor Staff
//
// Created by Konstantine Prevas on 9/30/06.
// Copyright 2006 Konstantine Prevas. All rights reserved.
//
#import "Chord.h"
//#import <Chomp/Chomp.h>
@class ChordDraw;
@class ChordController;
@implementation Chord
- (id)initWithStaff:(Staff *)_staff {
if(self = [super init]){
staff = _staff;
notes = [[NSMutableArray arrayWithCapacity:3] retain];
}
return self;
}
- (id)initWithStaff:(Staff *)_staff withNotes:(NSMutableArray *)_notes {
if(self = [super init]){
staff = _staff;
notes = [[NSMutableArray arrayWithArray:_notes] retain];
}
return self;
}
- (id)initWithStaff:(Staff *)_staff withNotes:(NSArray *)_notes copyItems:(BOOL)_copyItems {
if(self = [super init]){
staff = _staff;
notes = [[[NSMutableArray alloc] initWithArray:_notes copyItems:_copyItems] retain];
}
return self;
}
//- (id)copyWithZone:(NSZone *)zone{
// return [[Chord allocWithZone:zone] initWithStaff:staff withNotes:notes copyItems:YES];
//}
//
//- (void)setStaff:(Staff *)_staff{
// [super setStaff:_staff];
// [[notes do] setStaff:_staff];
//}
//
//- (int)getDuration{
// if([notes count] > 0){
// return [[notes objectAtIndex:0] getDuration];
// } else{
// return 0;
// }
//}
- (BOOL)getDotted {
if([notes count] > 0){
return [[notes objectAtIndex:0] getDotted];
} else{
return NO;
}
}
//- (BOOL)isDrawBars{
// if([notes count] > 0){
// return [[notes objectAtIndex:0] isDrawBars];
// } else{
// return NO;
// }
//}
- (void)setDuration:(int)_duration{
NoteBase *note;
for (note in notes) {
[note setDuration:_duration];
}
}
//- (void)setDotted:(BOOL)_dotted {
//
// NoteBase *note;
// for (note in notes) {
// [note setDotted:_dotted];
// }
//}
//- (void)setDottedSilently:(BOOL)_dotted {
//
// NoteBase *note;
// for (note in notes) {
// [note setDottedSilently:_dotted];
// }
//}
//- (float)addToMIDITrack:(MusicTrack *)musicTrack atPosition:(float)pos
// withKeySignature:(KeySignature *)sig accidentals:(NSMutableDictionary *)accidentals
// transpose:(int)transposition onChannel:(int)channel{
// [[notes do] addToMIDITrack:musicTrack atPosition:pos withKeySignature:sig
// accidentals:accidentals transpose:transposition onChannel:channel];
// return 4.0 * [self getEffectiveDuration] / 3;
//}
//
//- (void)transposeBy:(int)numLines{
// [[notes do] transposeBy:numLines];
//}
//
//- (void)transposeBy:(int)numHalfSteps oldSignature:(KeySignature *)oldSig newSignature:(KeySignature *)newSig{
// [[notes do] transposeBy:numHalfSteps oldSignature:oldSig newSignature:newSig];
//}
- (void)prepareForDelete{
[notes makeObjectsPerformSelector:@selector(prepareForDelete)];
}
- (void)sendChangeNotification{
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"modelChanged" object:self]];
}
- (NSArray *)subtractDuration:(float)maxDuration {
NSMutableArray *remainingNotes = [NSMutableArray array];
NoteBase *nt;
for(nt in notes){
[remainingNotes addObject:[nt subtractDuration:maxDuration]];
}
NSMutableArray *remainingChords = [[NSMutableArray arrayWithCapacity:[remainingNotes count]] autorelease];
int i;
for(i=0; i<[[remainingNotes objectAtIndex:0] count]; i++)
{
NSMutableArray *newChordNotes = [NSMutableArray array];
NSEnumerator *notesEnum = [remainingNotes objectEnumerator];
id noteArr;
while(noteArr = [notesEnum nextObject]){
if([noteArr count] > i){
[newChordNotes addObject:[noteArr objectAtIndex:i]];
}
}
[remainingChords addObject:[[[Chord alloc] initWithStaff:staff withNotes:newChordNotes] autorelease]];
}
return remainingChords;
}
- (void)tryToFill:(float)maxDuration {
NoteBase *nt;
for (nt in notes){
[nt tryToFill:maxDuration];
}
}
- (void)tieTo:(NoteBase *)note{
}
- (NoteBase *)getTieTo{
return nil;
}
- (void)tieFrom:(NoteBase *)note{
}
- (NoteBase *)getTieFrom{
return nil;
}
- (NSArray *)notes {
return notes;
}
//- (NoteBase *)highestNote{
// NoteBase *highestNote = nil;
// NSEnumerator *notesEnum = [notes objectEnumerator];
// id note;
// while(note = [notesEnum nextObject]){
// if(highestNote == nil || [note isHigherThan:highestNote]){
// highestNote = note;
// }
// }
// return highestNote;
//}
//
//- (NoteBase *)lowestNote{
// NoteBase *lowestNote = nil;
// NSEnumerator *notesEnum = [notes objectEnumerator];
// id note;
// while(note = [notesEnum nextObject]){
// if(lowestNote == nil || [note isLowerThan:lowestNote]){
// lowestNote = note;
// }
// }
// return lowestNote;
//}
- (void)setNotes:(NSMutableArray *)_notes {
[self prepUndo];
if(![notes isEqual:_notes]){
[notes release];
notes = [_notes retain];
}
[self sendChangeNotification];
}
- (void)prepUndo{
[[[self undoManager] prepareWithInvocationTarget:self] setNotes:[NSMutableArray arrayWithArray:notes]];
}
- (void)addNote:(NoteBase *)note {
[self prepUndo];
if([self getDuration] != 0){
[note setDuration:[self getDuration]];
// [note setDotted:[self getDotted]];
}
if([note respondsToSelector:@selector(notes)])
{
NSArray *someNotes = [note notes];
NoteBase *nt;
for(nt in someNotes){
[notes addObject:nt];
}
} else {
[notes addObject:note];
}
[self sendChangeNotification];
}
//- (void)removeNote:(NoteBase *)note{
// [self prepUndo];
// [notes removeObject:note];
// [self sendChangeNotification];
//}
- (int)getEffectivePitchWithKeySignature:(KeySignature *)keySig priorAccidentals:(NSMutableDictionary *)accidentals {
NoteBase *nt;
for(nt in notes){
[nt getEffectivePitchWithKeySignature:keySig priorAccidentals:accidentals];
}
return 0;
}
- (NoteBase *)getNoteMatching:(NoteBase *)note {
NSEnumerator *notesEnum = [notes objectEnumerator];
id chordNote;
while(chordNote = [notesEnum nextObject]){
if([chordNote respondsToSelector:@selector(pitchMatches:)] && [chordNote pitchMatches:note]){
return chordNote;
}
}
return nil;
}
//- (int)getLastPitch{
// return [[notes objectAtIndex:0] getLastPitch];
//}
//
//- (int)getLastOctave{
// return [[notes objectAtIndex:0] getLastOctave];
//}
//
//- (void)setPitch:(int)pitch octave:(int)octave finished:(BOOL)finished{
// int delta = (octave * 7 + pitch) - ([[notes objectAtIndex:0] getLastOctave] * 7 + [[notes objectAtIndex:0] getLastPitch]);
// NSEnumerator *notesEnum = [notes objectEnumerator];
// id note;
// while(note = [notesEnum nextObject]){
// int lastPitch = [note getLastPitch];
// int lastOctave = [note getLastOctave];
// int newAbsPitch = (lastOctave * 7 + lastPitch) + delta;
// int newPitch = newAbsPitch % 7;
// int newOctave = newAbsPitch / 7;
// [note setPitch:newPitch octave:newOctave finished:finished];
// }
//}
//
//- (void)addNoteToLilypondString:(NSMutableString *)string accidentals:(NSMutableDictionary *)accidentals{
// if(![staff isDrums]){
// [string appendString:@"<"];
// NSEnumerator *notesEnum = [notes objectEnumerator];
// id note;
// while(note = [notesEnum nextObject]){
// [note addPitchToLilypondString:string accidentals:accidentals];
// if([note getTieTo] != nil){
// [string appendString:@"~"];
// }
// [string appendString:@" "];
// }
// [string deleteCharactersInRange:NSMakeRange([string length] - 1, 1)];
// [string appendString:@">"];
// [self addDurationToLilypondString:string];
// [string appendString:@" "];
// } else {
// [string appendString:@"<<"];
// NSEnumerator *notesEnum = [notes objectEnumerator];
// id note;
// while(note = [notesEnum nextObject]){
// [note addPitchToLilypondString:string accidentals:accidentals];
// [note addDurationToLilypondString:string];
// [string appendString:@" "];
// }
// [string appendString:@">> "];
// }
//}
//
//- (void)addToMusicXMLString:(NSMutableString *)string accidentals:(NSMutableDictionary *)accidentals{
// NSEnumerator *notesEnum = [notes objectEnumerator];
// BOOL first = YES;
// id note;
// while(note = [notesEnum nextObject]){
// [note addToMusicXMLString:string accidentals:accidentals chord:(!first)];
// first = NO;
// }
//}
//
//- (void)encodeWithCoder:(NSCoder *)coder{
// [coder encodeObject:notes forKey:@"notes"];
//}
//
//- (id)initWithCoder:(NSCoder *)coder{
// if(self = [super init]){
// [self setNotes:[coder decodeObjectForKey:@"notes"]];
// }
// return self;
//}
//
//- (Class)getViewClass{
// return [ChordDraw class];
//}
//
//- (Class)getControllerClass{
// return [ChordController class];
//}
- (void)dealloc {
[notes release];
notes = nil;
[super dealloc];
}
@end