forked from yepher/MusicNotes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMusicNotesViewController.m
More file actions
88 lines (63 loc) · 2.35 KB
/
MusicNotesViewController.m
File metadata and controls
88 lines (63 loc) · 2.35 KB
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
//
// MusicNotesViewController.m
// MusicNotes
//
// Created by Christopher Wilson on 1/11/11.
// Copyright 2011 Yepher.com All rights reserved.
//
#import "MusicNotesViewController.h"
#import "MusicStaffView.h"
@implementation MusicNotesViewController
@synthesize audio;
@synthesize keyboardView;
@synthesize startLocation;
//@synthesize wholeNote;
@synthesize drawingView;
@synthesize octaveSelectionView;
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle {
if (!(self = [super initWithNibName:nibName bundle:nibBundle])) return nil;
return self;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return YES; //(interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
-(void) viewDidLoad {
[super viewDidLoad];
[keyboardView setVisibleKeyRange: NSMakeRange(48, 5)];
if (audio == nil) {
[self setAudio:[NSMutableArray arrayWithCapacity:0]];
}
[drawingView setShowOutsideLedger:YES];
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"keyboardLayout" ofType:@"plist"];
NSArray* names = [NSArray arrayWithContentsOfFile:plistPath];
// Load Audio
for (int i = 0; i < [names count]; i++) {
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:names[i] ofType:@"aif"]], &soundID);
NSNumber* audioId = @(soundID);
[audio addObject:audioId];
}
[[self keyboardView] setDelegate:self];
[[self octaveSelectionView] setDelegate:self];
}
- (void) keysPressed:(NSSet *)keys {
NSLog(@"keysPressed=%d", [keys count]);
[drawingView addNotes:keys];
for (NSNumber* keyIndex in keys) {
if ([audio count] > [keyIndex intValue]) {
SystemSoundID soundID = [audio[[keyIndex intValue]] unsignedLongValue];
AudioServicesPlaySystemSound(soundID);
}
}
}
- (void) rangeChanged: (NSRange) newRange {
NSLog(@"Got new range %d, %d", newRange.location, newRange.length);
[keyboardView setVisibleKeyRange:newRange];
[keyboardView setNeedsLayout];
}
@end