| 1 |
/* |
| 2 |
|
| 3 |
WaveviewViewController.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 WaveviewViewController: BaseCsoundViewController { |
| 30 |
|
| 31 |
@IBOutlet var titleLabel: UILabel! |
| 32 |
@IBOutlet var waveview: Waveview! |
| 33 |
|
| 34 |
var fTableIndex = 0 |
| 35 |
let fTables = ["Sine", "Exponential Curves", "Data Points", "Normalizing Function", "Triangle"] |
| 36 |
|
| 37 |
override func viewDidLoad() { |
| 38 |
title = "09. F-table Viewer" |
| 39 |
super.viewDidLoad() |
| 40 |
} |
| 41 |
|
| 42 |
override func viewDidAppear(_ animated: Bool) { |
| 43 |
let tempFile = Bundle.main.path(forResource: "Waveviewtest", ofType: "csd") |
| 44 |
|
| 45 |
csound.stop() |
| 46 |
csound = CsoundObj() |
| 47 |
csound.addBinding(waveview) |
| 48 |
|
| 49 |
// Add a tap gesture recognizer to increment F-table by tapping the Waveview |
| 50 |
let tap = UITapGestureRecognizer(target: self, action: #selector(incrementFTable(_:))) |
| 51 |
waveview.addGestureRecognizer(tap) |
| 52 |
|
| 53 |
csound.play(tempFile) |
| 54 |
} |
| 55 |
|
| 56 |
// Cycle through available F-tables |
| 57 |
@IBAction func incrementFTable(_ tap: UITapGestureRecognizer) { |
| 58 |
fTableIndex += 1 |
| 59 |
fTableIndex %= fTables.count |
| 60 |
titleLabel.text = fTables[fTableIndex] |
| 61 |
waveview.displayFTable(fTableIndex+1) // Offset by 1 to match F-table numbering in Csound |
| 62 |
} |
| 63 |
|
| 64 |
@IBAction func showInfo(_ sender: UIButton) { |
| 65 |
infoVC.preferredContentSize = CGSize(width: 300, height: 120) |
| 66 |
infoText = "Demonstrates using a Csound binding to draw F-table content to a view. Tap the screen to cycle through available F-tables." |
| 67 |
displayInfo(sender) |
| 68 |
} |
| 69 |
|
| 70 |
override func didReceiveMemoryWarning() { |
| 71 |
super.didReceiveMemoryWarning() |
| 72 |
// Dispose of any resources that can be recreated. |
| 73 |
} |
| 74 |
} |