24 #pragma mark View lifecycle |
24 #pragma mark View lifecycle |
25 - (void)viewDidLoad { |
25 - (void)viewDidLoad { |
26 [super viewDidLoad]; |
26 [super viewDidLoad]; |
27 srandom(time(NULL)); |
27 srandom(time(NULL)); |
28 |
28 |
29 openal_init(1); |
29 openal_init(20); |
30 voiceBeingPlayed = -1; |
|
31 |
|
32 // load all the voices names and store them into voiceArray |
|
33 NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:VOICES_DIRECTORY() error:NULL]; |
|
34 self.voiceArray = array; |
|
35 } |
30 } |
36 |
31 |
37 - (void)viewWillAppear:(BOOL)animated { |
32 - (void)viewWillAppear:(BOOL)animated { |
38 [super viewWillAppear:animated]; |
33 [super viewWillAppear:animated]; |
39 |
34 |
40 // this moves the tableview to the top |
35 // this moves the tableview to the top |
41 [self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
36 [self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
37 voiceBeingPlayed = -1; |
|
38 |
|
39 // load all the voices names and store them into voiceArray |
|
40 NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:VOICES_DIRECTORY() error:NULL]; |
|
41 self.voiceArray = array; |
42 } |
42 } |
43 |
43 |
44 /* |
44 /* |
45 - (void)viewDidAppear:(BOOL)animated { |
45 - (void)viewDidAppear:(BOOL)animated { |
46 [super viewDidAppear:animated]; |
46 [super viewDidAppear:animated]; |
48 */ |
48 */ |
49 |
49 |
50 - (void)viewWillDisappear:(BOOL)animated { |
50 - (void)viewWillDisappear:(BOOL)animated { |
51 [super viewWillDisappear:animated]; |
51 [super viewWillDisappear:animated]; |
52 if(voiceBeingPlayed >= 0) { |
52 if(voiceBeingPlayed >= 0) { |
53 openal_freesound(voiceBeingPlayed); |
53 openal_stopsound(voiceBeingPlayed); |
54 voiceBeingPlayed = -1; |
54 voiceBeingPlayed = -1; |
55 } |
55 } |
56 } |
56 } |
57 |
|
58 /* |
|
59 - (void)viewDidDisappear:(BOOL)animated { |
|
60 [super viewDidDisappear:animated]; |
|
61 } |
|
62 */ |
|
63 |
57 |
64 |
58 |
65 #pragma mark - |
59 #pragma mark - |
66 #pragma mark Table view data source |
60 #pragma mark Table view data source |
67 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
61 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
71 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
65 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
72 return [self.voiceArray count]; |
66 return [self.voiceArray count]; |
73 } |
67 } |
74 |
68 |
75 // Customize the appearance of table view cells. |
69 // Customize the appearance of table view cells. |
76 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
70 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
77 |
71 |
78 static NSString *CellIdentifier = @"Cell"; |
72 static NSString *CellIdentifier = @"Cell"; |
79 |
73 |
80 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
74 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
81 if (cell == nil) { |
75 if (cell == nil) { |
94 |
88 |
95 return cell; |
89 return cell; |
96 } |
90 } |
97 |
91 |
98 |
92 |
99 /* |
|
100 // Override to support conditional editing of the table view. |
|
101 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { |
|
102 // Return NO if you do not want the specified item to be editable. |
|
103 return YES; |
|
104 } |
|
105 */ |
|
106 |
|
107 |
|
108 /* |
|
109 // Override to support editing the table view. |
|
110 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
|
111 |
|
112 if (editingStyle == UITableViewCellEditingStyleDelete) { |
|
113 // Delete the row from the data source |
|
114 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; |
|
115 } |
|
116 else if (editingStyle == UITableViewCellEditingStyleInsert) { |
|
117 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view |
|
118 } |
|
119 } |
|
120 */ |
|
121 |
|
122 |
|
123 /* |
|
124 // Override to support rearranging the table view. |
|
125 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { |
|
126 } |
|
127 */ |
|
128 |
|
129 |
|
130 /* |
|
131 // Override to support conditional rearranging of the table view. |
|
132 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { |
|
133 // Return NO if you do not want the item to be re-orderable. |
|
134 return YES; |
|
135 } |
|
136 */ |
|
137 |
|
138 #pragma mark - |
93 #pragma mark - |
139 #pragma mark Table view delegate |
94 #pragma mark Table view delegate |
140 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
95 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
141 int newRow = [indexPath row]; |
96 int newRow = [indexPath row]; |
142 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
97 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
153 } |
108 } |
154 [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; |
109 [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; |
155 |
110 |
156 if (voiceBeingPlayed >= 0) { |
111 if (voiceBeingPlayed >= 0) { |
157 openal_stopsound(voiceBeingPlayed); |
112 openal_stopsound(voiceBeingPlayed); |
158 openal_freesound(voiceBeingPlayed); |
|
159 voiceBeingPlayed = -1; |
113 voiceBeingPlayed = -1; |
160 } |
114 } |
161 |
115 |
162 // the keyword static prevents re-initialization of the variable |
116 // the keyword static prevents re-initialization of the variable |
163 NSString *voiceDir = [[NSString alloc] initWithFormat:@"%@/%@/",VOICES_DIRECTORY(),[voiceArray objectAtIndex:newRow]]; |
117 NSString *voiceDir = [[NSString alloc] initWithFormat:@"%@/%@/",VOICES_DIRECTORY(),[voiceArray objectAtIndex:newRow]]; |
172 |
126 |
173 |
127 |
174 #pragma mark - |
128 #pragma mark - |
175 #pragma mark Memory management |
129 #pragma mark Memory management |
176 -(void) didReceiveMemoryWarning { |
130 -(void) didReceiveMemoryWarning { |
177 openal_stopsound(voiceBeingPlayed); |
|
178 openal_freesound(voiceBeingPlayed); |
|
179 voiceBeingPlayed = -1; |
|
180 // Releases the view if it doesn't have a superview. |
131 // Releases the view if it doesn't have a superview. |
181 [super didReceiveMemoryWarning]; |
132 [super didReceiveMemoryWarning]; |
182 // Relinquish ownership any cached data, images, etc that aren't in use. |
133 // Relinquish ownership any cached data, images, etc that aren't in use. |
183 } |
134 } |
184 |
135 |