Debian Codegraph @

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

raw
1 /*
2
3 SimpleTest2ViewController.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 SimpleTest2ViewController: BaseCsoundViewController {
30
31 @IBOutlet var onOffSwitch: UISwitch!
32
33 @IBOutlet var rateSlider: UISlider!
34 @IBOutlet var durationSlider: UISlider!
35 @IBOutlet var rateLabel: UILabel!
36 @IBOutlet var durationLabel: UILabel!
37
38 @IBOutlet var attackSlider: UISlider!
39 @IBOutlet var decaySlider: UISlider!
40 @IBOutlet var sustainSlider: UISlider!
41 @IBOutlet var releaseSlider: UISlider!
42
43 @IBOutlet var attackLabel: UILabel!
44 @IBOutlet var decayLabel: UILabel!
45 @IBOutlet var sustainLabel: UILabel!
46 @IBOutlet var releaseLabel: UILabel!
47
48 override func viewDidLoad() {
49 title = "02. Simple Test 2"
50 super.viewDidLoad()
51 }
52
53 func toggleOnOff(_ sender: UISwitch) {
54 if sender.isOn {
55 let tempFile = Bundle.main.path(forResource: "test2", ofType: "csd")
56
57 csound.stop()
58 csound = CsoundObj()
59 csound.add(self)
60
61 // Add UI bindings using CsoundUI, a class that binds Csound values to UIKit objects
62 let csoundUI = CsoundUI(csoundObj: csound)
63 csoundUI?.labelPrecision = 2
64 csoundUI?.add(rateSlider, forChannelName: "noteRate")
65 csoundUI?.add(durationSlider, forChannelName: "duration")
66 csoundUI?.add(attackSlider, forChannelName: "attack")
67 csoundUI?.add(decaySlider, forChannelName: "decay")
68 csoundUI?.add(sustainSlider, forChannelName: "sustain")
69 csoundUI?.add(releaseSlider, forChannelName: "release")
70
71 csoundUI?.add(rateLabel, forChannelName: "noteRate")
72 csoundUI?.add(durationLabel, forChannelName: "duration")
73 csoundUI?.add(attackLabel, forChannelName: "attack")
74 csoundUI?.add(decayLabel, forChannelName: "decay")
75 csoundUI?.add(sustainLabel, forChannelName: "sustain")
76 csoundUI?.add(releaseLabel, forChannelName: "release")
77
78 csound.play(tempFile)
79 } else {
80 csound.stop()
81 }
82 }
83
84 @IBAction func showInfo(_ sender: UIButton) {
85 infoVC.preferredContentSize = CGSize(width: 300, height: 140)
86 infoText = "A generative music example that contains a number of sliders that affect the rate, duration, and envelope of each note."
87 displayInfo(sender)
88 }
89
90 override func didReceiveMemoryWarning() {
91 super.didReceiveMemoryWarning()
92 // Dispose of any resources that can be recreated.
93 }
94 }
95
96 extension SimpleTest2ViewController: CsoundObjListener {
97 func csoundObjCompleted(_ csoundObj: CsoundObj!) {
98 DispatchQueue.main.async { [unowned self] in
99 self.onOffSwitch.isOn = false
100 }
101 }
102 }