Debian Codegraph @

iOS/Csound iOS Obj-C Examples/Csound iOS Examples/MasterViewController.m

raw
1 /*
2
3 MasterViewController.m:
4
5 Copyright (C) 2011 Steven Yi
6 Updated in 2017 by Dr. Richard Boulanger, Nikhil Singh
7
8 This file is part of Csound iOS Examples.
9
10 The Csound for iOS Library is free software; you can redistribute it
11 and/or modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
14
15 Csound is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public
21 License along with Csound; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 02111-1307 USA
24
25 */
26
27 #import "MasterViewController.h"
28 #import "DetailViewController.h"
29 #import "SimpleTest1ViewController.h"
30 #import "SimpleTest2ViewController.h"
31 #import "ButtonTestViewController.h"
32 #import "MidiTestViewController.h"
33 #import "AppDelegate.h"
34 #import "BaseCsoundViewController.h"
35 #import "AudioInTestViewController.h"
36 #import "HarmonizerTest.h"
37 #import "HardwareTestViewController.h"
38 #import "InstrumentEditorViewController.h"
39 #import "CsoundHaiku4ViewController.h"
40 #import "RecordTestViewController.h"
41 #import "MultiTouchXYViewController.h"
42 #import "WaveviewViewController.h"
43 #import "AudioFileTestViewController.h"
44 #import "ConsoleOutputViewController.h"
45 #import "PitchShifterViewController.h"
46 #import "TrappedGeneratorViewController.h"
47
48 @implementation MasterViewController
49
50 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
51 {
52 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
53 if (self) {
54 self.title = @"Csound for iOS";
55 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
56 self.clearsSelectionOnViewWillAppear = NO;
57 self.preferredContentSize = CGSizeMake(320.0, 600.0);
58 }
59 testNames = [NSMutableArray arrayWithObjects:
60 @"01. Simple Test 1",
61 @"02. Simple Test 2",
62 @"03. Button Test",
63 @"04. Play: Haiku IV",
64 @"05. Render: Trapped in Convert",
65 @"06. Render: Console Output",
66 @"07. Instrument Tweaker",
67 @"08. F-table Viewer",
68 @"09. Soundfile: Pitch Shifter",
69 @"10. Mic: Stereo Delay",
70 @"11. Mic: Harmonizer",
71 @"12. Mic: Recording",
72 @"13. Hardware: MIDI Controller",
73 @"14. Hardware: Motion Control",
74 @"15. XY Pad: MultiTouch ",
75 @"16. XY Pad: Mic PitchShift+Mix",
76 nil];
77 }
78 return self;
79 }
80
81
82 - (void)didReceiveMemoryWarning
83 {
84 [super didReceiveMemoryWarning];
85 // Release any cached data, images, etc that aren't in use.
86 }
87
88 #pragma mark - View lifecycle
89
90 - (void)viewDidLoad
91 {
92 [super viewDidLoad];
93 // Do any additional setup after loading the view, typically from a nib.
94 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
95 [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
96 }
97 }
98
99 - (void)viewDidUnload
100 {
101 [super viewDidUnload];
102 // Release any retained subviews of the main view.
103 // e.g. self.myOutlet = nil;
104 }
105
106 - (void)viewWillAppear:(BOOL)animated
107 {
108 [super viewWillAppear:animated];
109 }
110
111 - (void)viewDidAppear:(BOOL)animated
112 {
113 [super viewDidAppear:animated];
114 }
115
116 - (void)viewWillDisappear:(BOOL)animated
117 {
118 [super viewWillDisappear:animated];
119 }
120
121 - (void)viewDidDisappear:(BOOL)animated
122 {
123 [super viewDidDisappear:animated];
124 }
125
126 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
127 {
128 // Return YES for supported orientations
129 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
130 return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
131 } else {
132 return YES;
133 }
134 }
135
136 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
137 {
138 return 1;
139 }
140
141 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
142 {
143 return testNames.count;
144 }
145
146 // Customize the appearance of table view cells.
147 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
148 {
149 static NSString *CellIdentifier = @"Cell";
150
151 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
152 if (cell == nil) {
153 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
154 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
155 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
156 }
157 }
158
159 // Configure the cell.
160 cell.textLabel.text = [testNames objectAtIndex:indexPath.row];
161 return cell;
162 }
163
164 /*
165 // Override to support conditional editing of the table view.
166 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
167 {
168 // Return NO if you do not want the specified item to be editable.
169 return YES;
170 }
171 */
172
173 /*
174 // Override to support editing the table view.
175 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
176 {
177 if (editingStyle == UITableViewCellEditingStyleDelete) {
178 // Delete the row from the data source.
179 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
180 } else if (editingStyle == UITableViewCellEditingStyleInsert) {
181 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
182 }
183 }
184 */
185
186 /*
187 // Override to support rearranging the table view.
188 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
189 {
190 }
191 */
192
193 /*
194 // Override to support conditional rearranging of the table view.
195 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
196 {
197 // Return NO if you do not want the item to be re-orderable.
198 return YES;
199 }
200 */
201
202 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
203 {
204
205 BaseCsoundViewController* controller;
206
207 //should probably enum this someday
208
209 switch (indexPath.row) {
210 case 0:
211 controller = [[SimpleTest1ViewController alloc] initWithNibName:@"SimpleTest1ViewController" bundle:nil];
212 break;
213 case 1:
214 controller = [[SimpleTest2ViewController alloc] initWithNibName:@"SimpleTest2ViewController" bundle:nil];
215 break;
216 case 2:
217 controller = [[ButtonTestViewController alloc] initWithNibName:@"ButtonTestViewController" bundle:nil];
218 break;
219 case 3:
220 controller = [[CsoundHaiku4ViewController alloc] initWithNibName:@"CsoundHaiku4ViewController" bundle:nil];
221 break;
222 case 4:
223 controller = [[TrappedGeneratorViewController alloc] initWithNibName:@"TrappedGeneratorViewController" bundle:nil];
224 break;
225 case 5:
226 controller = [[ConsoleOutputViewController alloc] initWithNibName:@"ConsoleOutputViewController" bundle:nil];
227 break;
228 case 6:
229 controller = [[InstrumentEditorViewController alloc] initWithNibName:@"InstrumentEditorViewController" bundle:nil];
230 break;
231 case 7:
232 controller = [[WaveviewViewController alloc] initWithNibName:@"WaveviewViewController" bundle:nil];
233 break;
234 case 8:
235 controller = [[AudioFileTestViewController alloc] initWithNibName:@"AudioFileTestViewController" bundle:nil];
236 break;
237 case 9:
238 controller = [[AudioInTestViewController alloc] initWithNibName:@"AudioInTestViewController" bundle:nil];
239 break;
240 case 10:
241 controller = [[HarmonizerTest alloc] initWithNibName:@"HarmonizerTest" bundle:nil];
242 break;
243 case 11:
244 controller = [[RecordTestViewController alloc] initWithNibName:@"RecordTestViewController" bundle:nil];
245 break;
246 case 12:
247 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
248 controller = [[MidiTestViewController alloc] initWithNibName:@"MidiTestViewController" bundle:nil];
249 } else {
250 controller = [[MidiTestViewController alloc] initWithNibName:@"MidiTestViewController_iPad" bundle:nil];
251 }
252 break;
253 case 13:
254 controller = [[HardwareTestViewController alloc] initWithNibName:@"HardwareTestViewController" bundle:nil];
255 break;
256 case 14:
257 controller = [[MultiTouchXYViewController alloc] initWithNibName:@"MultiTouchXYViewController" bundle:nil];
258 break;
259 case 15:
260 controller = [[PitchShifterViewController alloc] initWithNibName:@"PitchShifterViewController" bundle:nil];
261 break;
262 default:
263 break;
264 }
265
266 if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
267 [self.navigationController pushViewController:controller animated:YES];
268 [(UITableView *)self.view deselectRowAtIndexPath:indexPath animated:YES];
269
270 } else {
271
272 AppDelegate *appDelegate = (AppDelegate *)([UIApplication sharedApplication].delegate);
273 UISplitViewController *splitViewController = appDelegate.splitViewController;
274
275 BaseCsoundViewController *currentDetail = (BaseCsoundViewController *)splitViewController.delegate;
276
277 if(currentDetail.navigationItem.leftBarButtonItem != nil) {
278 controller.navigationItem.leftBarButtonItem = currentDetail.navigationItem.leftBarButtonItem;
279 controller.masterPopoverController = currentDetail.masterPopoverController;
280 }
281
282 UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:controller];
283
284 NSArray *viewControllers = [[NSArray alloc] initWithObjects:[splitViewController.viewControllers objectAtIndex:0], detailNavigationController, nil];
285 splitViewController.viewControllers = viewControllers;
286 splitViewController.delegate = controller;
287
288 if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) {
289 [UIView animateWithDuration:0.2 animations:^{
290 splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
291 }];
292 }
293 }
294
295
296
297
298 }
299
300 @end