Created
August 6, 2010 22:07
-
-
Save augustl/512089 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BarModel.h | |
// MusicalNotation | |
// | |
// Created by August Lilleaas on 8/4/10. | |
// Copyright (c) 2010 Shortcut AS. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
typedef struct { | |
int count; | |
int val; | |
} TimeSignature; | |
@interface BarModel : NSObject { | |
} | |
-(TimeSignature)timeSignatureFromSelfOrParent; | |
-(BOOL)hasSetTimeSignature; | |
@property (nonatomic, retain) BarModel *parent; | |
@property TimeSignature timeSignature; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BarModel.m | |
// MusicalNotation | |
// | |
// Created by August Lilleaas on 8/4/10. | |
// Copyright (c) 2010 Shortcut AS. All rights reserved. | |
// | |
#import "BarModel.h" | |
@implementation BarModel | |
@synthesize parent, timeSignature; | |
-(TimeSignature)timeSignatureFromSelfOrParent { | |
if (self.parent && ![self hasSetTimeSignature]) { | |
return self.parent.timeSignature; | |
} else { | |
return self.timeSignature; | |
} | |
} | |
-(BOOL)hasSetTimeSignature { | |
return self.timeSignature.count != 0 && self.timeSignature.val != 0; | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// BarModelTest.m | |
// MusicalNotation | |
// | |
// Created by August Lilleaas on 8/4/10. | |
// Copyright (c) 2010 Shortcut AS. All rights reserved. | |
// | |
#import "BarModelTest.h" | |
@implementation BarModelTest | |
-(void) setUp { | |
bar = [[BarModel alloc] init]; | |
parentBar = [[BarModel alloc] init]; | |
} | |
-(void) tearDown { | |
[bar release]; | |
[parentBar release]; | |
} | |
-(void) testTimeSignatureFromSelfOrParent { | |
bar.timeSignature = (TimeSignature) {3,4}; | |
STAssertEquals(3, [bar timeSignatureFromSelfOrParent].count, nil); | |
STAssertEquals(4, [bar timeSignatureFromSelfOrParent].val, nil); | |
} | |
-(void) testTimeSignatureFromSelfOrParentWithParent { | |
bar.parent = parentBar; | |
parentBar.timeSignature = (TimeSignature) {7, 8}; | |
STAssertEquals(7, [bar timeSignatureFromSelfOrParent].count, nil); | |
STAssertEquals(8, [bar timeSignatureFromSelfOrParent].val, nil); | |
} | |
-(void) testTimeSignatureFromSelfOrParentWithParentAndSelf { | |
bar.parent = parentBar; | |
bar.timeSignature = (TimeSignature) {3,4}; | |
parentBar.timeSignature = (TimeSignature) {7, 8}; | |
STAssertEquals(3, [bar timeSignatureFromSelfOrParent].count, nil); | |
STAssertEquals(4, [bar timeSignatureFromSelfOrParent].val, nil); | |
} | |
-(void) testClefWithParent { | |
bar.parent = parentBar; | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PitchModel.h | |
// MusicalNotation | |
// | |
// Created by August Lilleaas on 8/6/10. | |
// Copyright (c) 2010 __MyCompanyName__. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
enum PitchModelNote { | |
PitchModelNoteA, | |
PitchModelNoteB, | |
PitchModelNoteC, | |
PitchModelNoteD, | |
PitchModelNoteE, | |
PitchModelNoteF, | |
PitchModelNoteG }; | |
enum PitchModelOctave { | |
PitchModelSubSubContraOctave, | |
PitchModelSubContraOctave, | |
PitchModelContraOctave, | |
PitchModelGreatOctave, | |
PitchModelSmallOctave, | |
PitchModelOneLinedOctave, | |
PitchModelTwoLinedOctave, | |
PitchModelThreeLinedOctave, | |
PitchModelFourLinedOctave, | |
PitchModelFiveLinedOctave, | |
PitchModelSixLinedOctave }; | |
enum PitchModelShift { | |
PitchModelDoubleFlatShift = -2, | |
PitchModelFlatShift, | |
PitchModelNaturalShift, | |
PitchModelSharpShift, | |
PitchModelDoubleSharpShift }; | |
@interface PitchModel : NSObject { | |
enum PitchModelNote note; | |
enum PitchModelOctave octave; | |
enum PitchModelShift shift; | |
} | |
@property enum PitchModelNote note; | |
@property enum PitchModelOctave octave; | |
@property enum PitchModelShift shift; | |
-(id)initWithOctave:(enum PitchModelOctave)octave andNote:(enum PitchModelNote)note; | |
-(id)initTrebleClefPitch; | |
-(id)initBassClefPitch; | |
-(NSString *)noteName; | |
-(NSString *)noteNameAndOctaveNumbered; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PitchModel.m | |
// MusicalNotation | |
// | |
// Created by August Lilleaas on 8/6/10. | |
// Copyright (c) 2010 __MyCompanyName__. All rights reserved. | |
// | |
#import "PitchModel.h" | |
@implementation PitchModel | |
@synthesize note, octave, shift; | |
static NSArray *noteNames = nil; | |
+ (void)initialize | |
{ | |
if ( self == [PitchModel class] ) { | |
noteNames = [[NSArray alloc] initWithObjects:@"A", @"B", @"C", @"D", @"E", @"F", @"G", nil]; | |
} | |
} | |
-(id)init { | |
if (self = [super init]) { | |
shift = PitchModelNaturalShift; | |
} | |
return self; | |
} | |
-(id) initWithOctave:(enum PitchModelOctave)anOctave andNote:(enum PitchModelNote)aNote { | |
if (self = [super init]) { | |
octave = anOctave; | |
note = aNote; | |
} | |
return self; | |
} | |
-(id)initTrebleClefPitch { | |
if (self = [super init]) { | |
octave = PitchModelOneLinedOctave; | |
note = PitchModelNoteB; | |
} | |
return self; | |
} | |
-(id)initBassClefPitch { | |
if (self = [super init]) { | |
octave = PitchModelSmallOctave; | |
note = PitchModelNoteD; | |
} | |
return self; | |
} | |
-(NSString *)noteName { | |
return [noteNames objectAtIndex:note]; | |
} | |
-(NSString *)noteNameAndOctaveNumbered { | |
return @"foo"; | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// PitchModelTest.m | |
// MusicalNotation | |
// | |
// Created by August Lilleaas on 8/6/10. | |
// Copyright (c) 2010 __MyCompanyName__. All rights reserved. | |
// | |
#import "PitchModelTest.h" | |
@implementation PitchModelTest | |
-(void)setUp { | |
pitch = [[PitchModel alloc] init]; | |
aPitch = [PitchModel alloc]; | |
} | |
-(void)tearDown { | |
[pitch release]; | |
[aPitch release]; | |
} | |
-(void) testInitSetsDefaultValues { | |
STAssertEquals(PitchModelNaturalShift, pitch.shift, nil); | |
} | |
-(void) testInitTrebleClefPitch { | |
aPitch = [aPitch initTrebleClefPitch]; | |
STAssertEquals(PitchModelOneLinedOctave, aPitch.octave, nil); | |
STAssertEquals(PitchModelNoteB, aPitch.note, nil); | |
} | |
-(void) testInitBassClefPitch { | |
aPitch = [aPitch initBassClefPitch]; | |
STAssertEquals(PitchModelSmallOctave, aPitch.octave, nil); | |
STAssertEquals(PitchModelNoteD, aPitch.note, nil); | |
} | |
-(void) testNoteNameString { | |
pitch.note = PitchModelNoteC; | |
STAssertEqualObjects(@"C", [pitch noteName], nil); | |
pitch.note = PitchModelNoteB; | |
STAssertEqualObjects(@"B", [pitch noteName], nil); | |
pitch.note = PitchModelNoteG; | |
STAssertEqualObjects(@"G", [pitch noteName], nil); | |
} | |
-(void) testNoteNameNumbered{ | |
aPitch = [aPitch initWithOctave:PitchModelOneLinedOctave andNote:PitchModelNoteC]; | |
// STAssertEquals(@"C4", [aPitch noteNameNumbered], nil); | |
} | |
-(void) testFooBar { | |
STAssertEquals(PitchModelNaturalShift, 0, nil); | |
STAssertEquals(PitchModelNaturalShift, (enum PitchModelShift) 0, nil); | |
pitch.shift = (enum PitchModelShift) 10; | |
STAssertEquals(10, pitch.shift, nil); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment