equal
deleted
inserted
replaced
30 |
30 |
31 #pragma mark - |
31 #pragma mark - |
32 #pragma mark View lifecycle |
32 #pragma mark View lifecycle |
33 -(void) viewDidLoad { |
33 -(void) viewDidLoad { |
34 [super viewDidLoad]; |
34 [super viewDidLoad]; |
35 srandom(time(NULL)); |
|
36 |
35 |
37 voiceBeingPlayed = NULL; |
36 voiceBeingPlayed = NULL; |
38 |
37 |
39 // load all the voices names and store them into voiceArray |
38 // load all the voices names and store them into voiceArray |
40 // it's here and not in viewWillAppear because user cannot add/remove them |
39 // it's here and not in viewWillAppear because user cannot add/remove them |
102 |
101 |
103 |
102 |
104 #pragma mark - |
103 #pragma mark - |
105 #pragma mark Table view delegate |
104 #pragma mark Table view delegate |
106 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
105 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
107 int newRow = [indexPath row]; |
106 NSInteger newRow = [indexPath row]; |
108 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
107 NSInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
109 |
108 |
110 if (newRow != oldRow) { |
109 if (newRow != oldRow) { |
111 [teamDictionary setObject:[voiceArray objectAtIndex:newRow] forKey:@"voicepack"]; |
110 [teamDictionary setObject:[voiceArray objectAtIndex:newRow] forKey:@"voicepack"]; |
112 |
111 |
113 // tell our boss to write this new stuff on disk |
112 // tell our boss to write this new stuff on disk |
127 } |
126 } |
128 |
127 |
129 NSString *voiceDir = [[NSString alloc] initWithFormat:@"%@/%@/",VOICES_DIRECTORY(),[voiceArray objectAtIndex:newRow]]; |
128 NSString *voiceDir = [[NSString alloc] initWithFormat:@"%@/%@/",VOICES_DIRECTORY(),[voiceArray objectAtIndex:newRow]]; |
130 NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:voiceDir error:NULL]; |
129 NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:voiceDir error:NULL]; |
131 |
130 |
132 int index = random() % [array count]; |
131 int index = arc4random_uniform((int)[array count]); |
133 |
132 |
134 voiceBeingPlayed = Mix_LoadWAV([[voiceDir stringByAppendingString:[array objectAtIndex:index]] UTF8String]); |
133 voiceBeingPlayed = Mix_LoadWAV([[voiceDir stringByAppendingString:[array objectAtIndex:index]] UTF8String]); |
135 [voiceDir release]; |
134 [voiceDir release]; |
136 lastChannel = Mix_PlayChannel(-1, voiceBeingPlayed, 0); |
135 lastChannel = Mix_PlayChannel(-1, voiceBeingPlayed, 0); |
137 } |
136 } |