@@ -12,6 +12,8 @@ import FDWaveformView
1212
1313class ViewController : UIViewController {
1414 @IBOutlet weak var waveform : FDWaveformView !
15+ @IBOutlet weak var logarithmicButton : UIButton !
16+ @IBOutlet weak var linearButton : UIButton !
1517
1618 fileprivate var startRendering = Date ( )
1719 fileprivate var endRendering = Date ( )
@@ -105,6 +107,30 @@ class ViewController: UIViewController {
105107 waveform. doesAllowScroll = sender. isOn
106108 }
107109
110+ @IBAction func doLinear( ) {
111+ /* TODO: Make this public and then use it here
112+ waveform.waveformType = .linear
113+ updateWaveformTypeButtons()
114+ */
115+ }
116+
117+ @IBAction func doLogarithmic( ) {
118+ /* TODO: Make this public and then use it here
119+ waveform.waveformType = .logarithmic
120+ updateWaveformTypeButtons()
121+ */
122+ }
123+
124+ @IBAction func doChangeColors( ) {
125+ let randomColor : ( ) -> ( UIColor ) = {
126+ return UIColor ( red: CGFloat ( drand48 ( ) ) , green: CGFloat ( drand48 ( ) ) , blue: CGFloat ( drand48 ( ) ) , alpha: 1 )
127+ }
128+
129+ UIView . animate ( withDuration: 0.3 , animations: {
130+ self . waveform. wavesColor = randomColor ( )
131+ self . waveform. progressColor = randomColor ( )
132+ } )
133+ }
108134 override func viewDidLoad( ) {
109135 super. viewDidLoad ( )
110136 let thisBundle = Bundle ( for: type ( of: self ) )
@@ -117,30 +143,45 @@ class ViewController: UIViewController {
117143 waveform. doesAllowScrubbing = true
118144 waveform. doesAllowStretch = true
119145 waveform. doesAllowScroll = true
146+ updateWaveformTypeButtons ( )
147+ }
148+
149+ func updateWaveformTypeButtons( ) {
150+ /* TODO: Make this public and then use it here
151+ let (selectedButton, nonSelectedButton): (UIButton, UIButton) = {
152+ switch waveform.waveformType {
153+ case .linear: return (linearButton, logarithmicButton)
154+ case .logarithmic: return (logarithmicButton, linearButton)
155+ }
156+ }()
157+ selectedButton.layer.borderColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.25).cgColor
158+ selectedButton.layer.borderWidth = 2
159+ nonSelectedButton.layer.borderWidth = 0
160+ */
120161 }
121162}
122163
123164extension ViewController : FDWaveformViewDelegate {
124165 func waveformViewWillRender( _ waveformView: FDWaveformView ) {
125- self . startRendering = Date ( )
166+ startRendering = Date ( )
126167 }
127168
128169 func waveformViewDidRender( _ waveformView: FDWaveformView ) {
129- self . endRendering = Date ( )
130- NSLog ( " FDWaveformView rendering done, took %0.3f seconds " , self . endRendering. timeIntervalSince ( self . startRendering) )
131- self . profileResult. append ( String ( format: " render %0.3f " , self . endRendering. timeIntervalSince ( self . startRendering) ) )
170+ endRendering = Date ( )
171+ NSLog ( " FDWaveformView rendering done, took %0.3f seconds " , endRendering. timeIntervalSince ( startRendering) )
172+ profileResult. append ( String ( format: " render %0.3f " , endRendering. timeIntervalSince ( startRendering) ) )
132173 UIView . animate ( withDuration: 0.25 , animations: { ( ) -> Void in
133174 waveformView. alpha = 1.0
134175 } )
135176 }
136177
137178 func waveformViewWillLoad( _ waveformView: FDWaveformView ) {
138- self . startLoading = Date ( )
179+ startLoading = Date ( )
139180 }
140181
141182 func waveformViewDidLoad( _ waveformView: FDWaveformView ) {
142- self . endLoading = Date ( )
143- NSLog ( " FDWaveformView loading done, took %f seconds " , self . endLoading. timeIntervalSince ( self . startLoading) )
144- self . profileResult. append ( " load \( self . endLoading. timeIntervalSince ( self . startLoading) ) " )
183+ endLoading = Date ( )
184+ NSLog ( " FDWaveformView loading done, took %0.3f seconds " , endLoading. timeIntervalSince ( startLoading) )
185+ profileResult. append ( String ( format : " load %0.3f " , endLoading. timeIntervalSince ( startLoading) ) )
145186 }
146187}
0 commit comments