Debian Codegraph @

iOS/Csound iOS Swift Examples/Csound iOS SwiftExamples/MasterViewController.swift

raw
1 /*
2
3 MasterViewController.swift
4
5 Nikhil Singh, Dr. Richard Boulanger
6 Adapted from the Csound iOS Examples by Steven Yi and Victor Lazzarini
7
8 This file is part of Csound iOS SwiftExamples.
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 UIKit
28
29 class MasterViewController: UITableViewController {
30
31 var detailViewController: BaseCsoundViewController? = nil
32
33 // All ViewController Classes
34 var allVCClasses: [BaseCsoundViewController.Type] = [SimpleTest1ViewController.self,
35 SimpleTest2ViewController.self,
36 ButtonTestViewController.self,
37 CsoundHaiku4ViewController.self,
38 TrappedGeneratorViewController.self,
39 ConsoleOutputViewController.self,
40 InstrumentEditorViewController.self,
41 WaveviewViewController.self,
42 AudioFilesTestViewController.self,
43 AudioInTestViewController.self,
44 HarmonizerTestViewController.self,
45 RecordTestViewController.self,
46 MidiTestViewController.self,
47 HardwareTestViewController.self,
48 MultiTouchXYViewController.self,
49 PitchShifterViewController.self]
50
51 // Display titles for ViewControllers, and for master TableView cells
52 let testNames = ["01. Simple Test 1",
53 "02. Simple Test 2",
54 "03. Button Test",
55 "04. Play: Haiku IV",
56 "05. Render: Trapped in Convert",
57 "06. Render: Console Output",
58 "07. Instrument Tweaker",
59 "08. F-table Viewer",
60 "09. Soundfile: Pitch Shifter",
61 "10. Mic: Stereo Delay",
62 "11. Mic: Harmonizer",
63 "12. Mic: Recording",
64 "13. Hardware: MIDI Controller",
65 "14. Hardware: Motion Control",
66 "15. XY Pad: MultiTouch ",
67 "16. XY Pad: Mic PitchShift+Mix"]
68
69 override func viewDidLoad() {
70 super.viewDidLoad()
71 title = "Csound for iOS"
72 if let split = splitViewController {
73 let controllers = split.viewControllers
74 detailViewController = (controllers[controllers.count-1] as! UINavigationController).topViewController as? BaseCsoundViewController
75 tableView.selectRow(at: IndexPath.init(row: 0, section: 0), animated: false, scrollPosition: .middle)
76 }
77 }
78
79 override func viewWillAppear(_ animated: Bool) {
80 clearsSelectionOnViewWillAppear = splitViewController!.isCollapsed
81 super.viewWillAppear(animated)
82 }
83
84 override func didReceiveMemoryWarning() {
85 super.didReceiveMemoryWarning()
86 // Dispose of any resources that can be recreated.
87 }
88
89 // MARK: - Table View
90 override func numberOfSections(in tableView: UITableView) -> Int {
91 return 1
92 }
93
94 override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
95 return testNames.count
96 }
97
98 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
99 let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
100
101 cell.textLabel!.text = testNames[indexPath.row]
102 return cell
103 }
104
105 // Ensure contents are not editable
106 override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
107 return false
108 }
109
110 override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
111 var controller: Any?
112
113 if indexPath.row == 12, UIDevice.current.userInterfaceIdiom == .pad { // Separate .xib for iPad for MIDI Test example (with virtual keyboard)
114 controller = allVCClasses[indexPath.row].init(nibName: String(describing: allVCClasses[indexPath.row]) + "_iPad", bundle: nil)
115 } else if indexPath.row == 0 { // SimpleTest1 UI is housed in Main.storyboard
116 controller = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SimpleTest1ViewController")
117 } else { // Else, use the classes from the allVCClasses array and their names
118 controller = allVCClasses[indexPath.row].init(nibName: String(describing: allVCClasses[indexPath.row]), bundle: nil)
119 }
120
121 if controller != nil {
122 if UIDevice.current.userInterfaceIdiom == .phone { // Push VC if on iPhone
123 navigationController?.pushViewController(controller as! BaseCsoundViewController, animated: true)
124 } else { // SplitViewController management on iPad
125 let navCon = UINavigationController(rootViewController: controller as! BaseCsoundViewController)
126 splitViewController?.viewControllers = [navigationController!, navCon]
127 splitViewController?.delegate = controller as! BaseCsoundViewController
128
129 if UIDevice.current.orientation == .portrait { // If iPad orientation is portrait, animate hiding the master pane
130 UIView.animate(withDuration: 0.2, animations: { [unowned self] in
131 self.splitViewController?.preferredDisplayMode = .primaryHidden
132 })
133 }
134 }
135 }
136 }
137
138
139 }
140