0
我正在制作一个iPhone应用程序,其中包含有关吉他音阶的教程。我的目标是,我有很多声音,我的功能发挥,直到规模完成。音乐比例:循环播放不同音符的功能
这里是一个随机比例:F G A B C D E.我记录了类似C.mp3,D,E,F,G,A,B,C2,D2,E2 ... 2的声音。这里是我使用的代码:
- (IBAction) playScale {
NSLog(@"s: %i", s);
NSLog(@"p: %i", pressed);
[self.player prepareToPlay];
components = [self.scale componentsSeparatedByString:@", "];
ns_NoteToPlay = [components objectAtIndex:s];
NSString *path = [[NSBundle mainBundle] pathForResource:ns_NoteToPlay ofType:@"m4a"];
NSLog(@"Path : %@", path);
self.player.delegate = self;
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[self.player play];
mChord.text = ns_NoteToPlay;
NSLog(@"Nombre de notes ds Array : %i", components.count);
if (s == 0) {
int clean;
clean = components.count + 1;
[NSTimer scheduledTimerWithTimeInterval:clean target:self selector:@selector(cleanDots) userInfo:nil repeats:NO];
}
nsNowPlayingNote = ns_NoteToPlay;
[self instrument];
s = s+1;
if ((s < components.count) && (pressed == 0)) {
[self performSelector:@selector(playScale) withObject:nil afterDelay:0.8];
}
}
This works。该功能可以播放音阶,但我无法找到一种方法来确定何时调用较高的音符C2。结果,当它播放D时,C,C应该是C2,但仍然调用C,C更低。
谢谢!我会尽量玩这个! :p –
解决!在大型NSArray和多个int/strings /数组操作的帮助下,像魅力一样工作 –