Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could create two NSMutableArrays and empty them when you hit record. You would also need an NSTimer and an int. So in header:</p> <pre><code>NSTimer *recordTimer; NSTimer *playTimer; int incrementation; NSMutableArray *timeHit; NSMutableArray *noteHit; </code></pre> <p>Include in your header all of the voids and IBActions and such below.</p> <p>Make your sound buttons all have different, unique tags.</p> <p>and then in your main file:</p> <pre><code>-(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 { //These notes would correspond to the tags of the buttons they are played by. if (note == 1) { //Play your first note } else if (note == 2) { //Play second note } else if (note == 3) { //And so on } else if (note == 4) { //etc. } } </code></pre> <p>With a little bit of fiddling (I doubt this code is perfect), you might get this to work. Like you will probably want the play/record buttons to be disabled once you hit one of them. Good luck!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload