-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging visionos branch into main (#87)
* Move code to extension * Don't have MTKView on VisionOS * Add encode function and draw(in:) * Resize waveformTexture * Use drawable size for width of waveformTexture * Move code out * FloatPlot shouldn't be an MTKView * Make private * Add MetalView * Add createDisplayLink * Logging * Add logging * visionOS support * uncomment display lnk * Update FloatPlot.swift * Fix warning * Fix warnings * Fix macOS build * visionOS support Co-Authored-By: Aurelius Prochazka <aure@aure.com> * FloatPloat now defaults to a clear background --------- Co-authored-by: Taylor Holliday <wtholliday@gmail.com> Co-authored-by: Aurelius Prochazka <aure@aure.com>
- Loading branch information
1 parent
63443b3
commit 3559d8b
Showing
7 changed files
with
234 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright AudioKit. All Rights Reserved. Revision History at http://github.com/AudioKit/Waveform/ | ||
|
||
#if os(iOS) || os(visionOS) | ||
import UIKit | ||
|
||
class MetalView: UIView { | ||
|
||
var renderer: FloatPlot? | ||
var displayLink: CADisplayLink? | ||
|
||
@objc static override var layerClass: AnyClass { | ||
CAMetalLayer.self | ||
} | ||
|
||
var metalLayer: CAMetalLayer { | ||
layer as! CAMetalLayer | ||
} | ||
|
||
func createDisplayLink() { | ||
displayLink = CADisplayLink(target: self, | ||
selector: #selector(render)) | ||
|
||
displayLink?.add(to: .current, | ||
forMode: .default) | ||
} | ||
|
||
override func draw(_ rect: CGRect) { | ||
render() | ||
} | ||
|
||
override func draw(_ layer: CALayer, in ctx: CGContext) { | ||
render() | ||
} | ||
|
||
override func display(_ layer: CALayer) { | ||
render() | ||
} | ||
|
||
@objc func render() { | ||
guard let renderer else { | ||
print("⚠️ no renderer") | ||
return | ||
} | ||
renderer.draw(to: metalLayer) | ||
} | ||
|
||
func resizeDrawable() { | ||
|
||
var newSize = bounds.size | ||
newSize.width *= contentScaleFactor | ||
newSize.height *= contentScaleFactor | ||
|
||
if newSize.width <= 0 || newSize.height <= 0 { | ||
return | ||
} | ||
|
||
if newSize.width == metalLayer.drawableSize.width && | ||
newSize.height == metalLayer.drawableSize.height { | ||
return | ||
} | ||
|
||
metalLayer.drawableSize = newSize | ||
renderer?.resize(width: Int(newSize.width)) | ||
|
||
setNeedsDisplay() | ||
} | ||
|
||
@objc override var frame: CGRect { | ||
get { super.frame } | ||
set { | ||
super.frame = newValue | ||
resizeDrawable() | ||
} | ||
} | ||
|
||
@objc override func layoutSubviews() { | ||
super.layoutSubviews() | ||
resizeDrawable() | ||
} | ||
|
||
@objc override var bounds: CGRect { | ||
get { super.bounds } | ||
set { | ||
super.bounds = newValue | ||
resizeDrawable() | ||
} | ||
} | ||
|
||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.