-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathRepeat.m
executable file
·110 lines (90 loc) · 2.52 KB
/
Repeat.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
//
// Repeat.m
// Señor Staff
//
// Created by Konstantine Prevas on 12/12/06.
// Copyright 2006 Konstantine Prevas. All rights reserved.
//
#import "Repeat.h"
@implementation Repeat
- (id) initWithSong:(Song *)_song{
if(self = [super init]){
song = _song;
startMeasure = -1;
endMeasure = -1;
numRepeats = 2;
}
return self;
}
- (NSUndoManager *) undoManager{
return [song undoManager];
}
- (void)sendChangeNotification{
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"modelChanged" object:self]];
}
- (int) startMeasure{
return startMeasure;
}
- (int) endMeasure{
return endMeasure;
}
- (int) numRepeats{
return numRepeats;
}
- (void) setStartMeasure:(int)_startMeasure{
[[[self undoManager] prepareWithInvocationTarget:self] setStartMeasure:startMeasure];
startMeasure = _startMeasure;
}
- (void) setEndMeasure:(int)_endMeasure{
[[[self undoManager] prepareWithInvocationTarget:self] setEndMeasure:endMeasure];
[self countClose:nil];
endMeasure = _endMeasure;
}
- (void) setNumRepeats:(int)_numRepeats{
[[[self undoManager] prepareWithInvocationTarget:self] setNumRepeats:numRepeats];
numRepeats = _numRepeats;
[self updateCountPanel];
}
- (BOOL)isShowingCountPanel{
return countPanel != nil && ![countPanel isHidden];
}
- (NSView *)getCountPanel{
if(countPanel == nil){
[NSBundle loadNibNamed:@"RepeatCountPanel" owner:self];
[countPanel setHidden:YES];
}
return countPanel;
}
- (void)updateCountPanel{
[countStep setIntValue:numRepeats];
[countText setIntValue:numRepeats];
}
- (IBAction)countChanged:(id)sender{
[[self undoManager] setActionName:@"changing repeat count"];
int value = [sender intValue];
if(value < 2) value = 2;
[countStep setIntValue:value];
[countText setIntValue:value];
[self setNumRepeats:value];
[self sendChangeNotification];
}
- (IBAction)countClose:(id)sender{
[countPanel setHidden:YES withFade:YES blocking:(sender != nil)];
if([countPanel superview] != nil){
[countPanel removeFromSuperview];
}
}
- (void)encodeWithCoder:(NSCoder *)coder{
[coder encodeObject:song forKey:@"song"];
[coder encodeInt:startMeasure forKey:@"startMeasure"];
[coder encodeInt:endMeasure forKey:@"endMeasure"];
[coder encodeInt:numRepeats forKey:@"numRepeats"];
}
- (id)initWithCoder:(NSCoder *)coder{
song = [coder decodeObjectForKey:@"song"];
[self setStartMeasure:[coder decodeIntForKey:@"startMeasure"]];
[self setEndMeasure:[coder decodeIntForKey:@"endMeasure"]];
[self setNumRepeats:[coder decodeIntForKey:@"numRepeats"]];
return self;
}
@end