| 1 |
/* |
| 2 |
|
| 3 |
AudioFilesTestViewController.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 AudioFilesTestViewController: BaseCsoundViewController { |
| 30 |
|
| 31 |
@IBOutlet var playButton: UIButton! |
| 32 |
@IBOutlet var pitchKnob: ControlKnob! |
| 33 |
@IBOutlet var pitchLabel: UILabel! |
| 34 |
|
| 35 |
@IBAction func play(_ sender: UIButton) { |
| 36 |
let audioFilePath = Bundle.main.path(forResource: "testAudioFile", ofType: "aif") |
| 37 |
if audioFilePath != nil { |
| 38 |
let score = "i1 0 1 \"\(audioFilePath!)\"" |
| 39 |
csound.sendScore(score) |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
@IBAction func changePitch(_ sender: ControlKnob) { |
| 44 |
pitchLabel.text = String(format: "%.2f", sender.value) |
| 45 |
} |
| 46 |
|
| 47 |
@IBAction func stop(_ sender: UIButton) { |
| 48 |
csound.sendScore("i3 0 1 2") |
| 49 |
} |
| 50 |
|
| 51 |
@IBAction func showInfo(_ sender: UIButton) { |
| 52 |
infoVC.preferredContentSize = CGSize(width: 300, height: 140) |
| 53 |
infoText = "Soundfile PitchShifter uses the URL of a bundled AIFF file and playing it with Csound. Also demonstrated is a custom UI control knob widget, used to change playback pitch." |
| 54 |
displayInfo(sender) |
| 55 |
} |
| 56 |
|
| 57 |
override func viewDidLoad() { |
| 58 |
super.viewDidLoad() |
| 59 |
|
| 60 |
title = "10. Soundfile: Pitch Shifter" |
| 61 |
csound = CsoundObj() |
| 62 |
let csdPath = Bundle.main.path(forResource: "audiofiletest", ofType: "csd") |
| 63 |
|
| 64 |
pitchKnob.minimumValue = 0.5 |
| 65 |
pitchKnob.maximumValue = 2.0 |
| 66 |
pitchKnob.value = 1.0 |
| 67 |
|
| 68 |
csound.addBinding(self.pitchKnob) |
| 69 |
csound.play(csdPath) |
| 70 |
} |
| 71 |
|
| 72 |
override func didReceiveMemoryWarning() { |
| 73 |
super.didReceiveMemoryWarning() |
| 74 |
// Dispose of any resources that can be recreated. |
| 75 |
} |
| 76 |
} |