You can create two NSMutableArrays and delete them when you click the entry. You will also need NSTimer and int. So in the title:
NSTimer *recordTimer;
NSTimer *playTimer;
int incrementation;
NSMutableArray *timeHit;
NSMutableArray *noteHit;
Include in your heading all voids and IBActions and such below.
Your sound buttons have all different unique tags.
and then in the main file:
-(void)viewDidLoad {
timeHit = [[NSMutableArray alloc] init];
noteHit = [[NSMutableArray alloc] init];
}
-(IBAction)record {
recordTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(timerSelector) userInfo:nil repeats:YES];
[timeHit removeAllObjects];
[noteHit removeAllObjects];
incrementation = 0;
}
-(void)timerSelector {
incrementation += 1;
}
-(IBAction)hitSoundButton:(id)sender {
int note = [sender tag];
int time = incrementation;
[timeHit addObject:[NSNumber numberWithInt:time]];
[noteHit addObject:[NSNumber numberWithInt:note]];
[self playNote:note];
}
-(IBAction)stop {
if ([recordTimer isRunning]) {
[recordTimer invalidate];
} else if ([playTimer isRunning]) {
[playTimer invalidate];
}
}
-(IBAction)playSounds {
playTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(playback) userInfo:nil repeats:YES];
incrementation = 0;
}
-(void)playback {
incrementation += 1;
if ([timeHit containsObject:[NSNumber numberWithInt:incrementation]]) {
int index = [timeHit indexOfObject:[NSNumber numberWithInt:incrementation]];
int note = [[noteHit objectAtIndex:index] intValue];
[self playNote:note];
}
}
-(void)playNote:(int)note {
if (note == 1) {
} else if (note == 2) {
} else if (note == 3) {
} else if (note == 4) {
}
}
With a bit of messing around (I doubt this code is perfect), you can make it work. As you probably want the play / record buttons to be disabled after clicking on one of them. Good luck
source
share