| 1 |
/* |
| 2 |
|
| 3 |
ButtonTestViewController.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 ButtonTestViewController: BaseCsoundViewController { |
| 30 |
|
| 31 |
@IBOutlet var mValueButton: UIButton! |
| 32 |
@IBOutlet var mEventButton: UIButton! |
| 33 |
|
| 34 |
@IBOutlet var mDurationSlider: UISlider! |
| 35 |
|
| 36 |
@IBOutlet var mAttackSlider: UISlider! |
| 37 |
@IBOutlet var mDecaySlider: UISlider! |
| 38 |
@IBOutlet var mSustainSlider: UISlider! |
| 39 |
@IBOutlet var mReleaseSlider: UISlider! |
| 40 |
@IBOutlet var mSwitch: UISwitch! |
| 41 |
|
| 42 |
@IBAction func toggleOnOf(_ sender: UISwitch) { |
| 43 |
if sender.isOn { |
| 44 |
let tempFile = Bundle.main.path(forResource: "buttonTest", ofType: "csd") |
| 45 |
csound = CsoundObj() |
| 46 |
csound.add(self) |
| 47 |
|
| 48 |
let csoundUI = CsoundUI(csoundObj: csound) |
| 49 |
csoundUI?.addMomentaryButton(mValueButton, forChannelName: "button1") |
| 50 |
csoundUI?.add(mDurationSlider, forChannelName: "duration") |
| 51 |
csoundUI?.add(mAttackSlider, forChannelName: "attack") |
| 52 |
csoundUI?.add(mDecaySlider, forChannelName: "decay") |
| 53 |
csoundUI?.add(mSustainSlider, forChannelName: "sustain") |
| 54 |
csoundUI?.add(mReleaseSlider, forChannelName: "release") |
| 55 |
|
| 56 |
csound.play(tempFile) |
| 57 |
} else { |
| 58 |
csound.stop() |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
@IBAction func eventButtonHit(_ sender: UIButton) { |
| 63 |
let score = "i2 0 \(mDurationSlider.value)" |
| 64 |
csound.sendScore(score) |
| 65 |
} |
| 66 |
|
| 67 |
override func viewDidLoad() { |
| 68 |
title = "03. Button Test" |
| 69 |
super.viewDidLoad() |
| 70 |
} |
| 71 |
|
| 72 |
override func didReceiveMemoryWarning() { |
| 73 |
super.didReceiveMemoryWarning() |
| 74 |
// Dispose of any resources that can be recreated. |
| 75 |
} |
| 76 |
|
| 77 |
@IBAction func showInfo(_ sender: UIButton) { |
| 78 |
infoVC.preferredContentSize = CGSize(width: 300, height: 160) |
| 79 |
infoText = "Uses a .csd based on SimpleTest 2, but depends on the user to press a button to trigger each note. One button uses a binding and the other sends a score message to CsoundObj." |
| 80 |
displayInfo(sender) |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
extension ButtonTestViewController: CsoundObjListener { |
| 85 |
func csoundObjCompleted(_ csoundObj: CsoundObj!) { |
| 86 |
DispatchQueue.main.async { [unowned self] in |
| 87 |
self.mSwitch.isOn = false |
| 88 |
} |
| 89 |
} |
| 90 |
} |