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 /數組操作的幫助下,像魅力一樣工作 –