diff --git a/pkgs/swift2objc/lib/src/ast/declarations/built_in/built_in_declaration.dart b/pkgs/swift2objc/lib/src/ast/declarations/built_in/built_in_declaration.dart index 319febf61..9a2263d63 100644 --- a/pkgs/swift2objc/lib/src/ast/declarations/built_in/built_in_declaration.dart +++ b/pkgs/swift2objc/lib/src/ast/declarations/built_in/built_in_declaration.dart @@ -39,6 +39,10 @@ const _floatDecl = BuiltInDeclaration(id: 's:Sf', name: 'Float'); const _doubleDecl = BuiltInDeclaration(id: 's:Sd', name: 'Double'); const _boolDecl = BuiltInDeclaration(id: 's:Sb', name: 'Bool'); const _voidDecl = BuiltInDeclaration(id: 's:s4Voida', name: 'Void'); +const _swiftURLDecl = + BuiltInDeclaration(id: 's:10Foundation3URLV', name: 'URL'); // HACK +const _swiftTimeIntervalDecl = + BuiltInDeclaration(id: 'c:@T@NSTimeInterval', name: 'TimeInterval'); // HACK const builtInDeclarations = [ _objectDecl, diff --git a/pkgs/swiftgen/example/avf_audio_bindings.dart b/pkgs/swiftgen/example/avf_audio_bindings.dart index a8046a713..412e4366a 100644 --- a/pkgs/swiftgen/example/avf_audio_bindings.dart +++ b/pkgs/swiftgen/example/avf_audio_bindings.dart @@ -38,7 +38,12 @@ class AVAudioFormatWrapper extends objc.NSObject { ffi.Pointer pointer, { bool retain = false, bool release = false, - }) : super.castFromPointer(pointer, retain: retain, release: release); + }) : super.castFromPointer(pointer, retain: retain, release: release) { + objc.checkOsVersionInternal( + 'AVAudioFormatWrapper', + macOS: (false, (10, 10, 0)), + ); + } /// Constructs a [AVAudioFormatWrapper] that points to the same underlying object as [other]. AVAudioFormatWrapper.castFrom(objc.ObjCObjectBase other) @@ -107,57 +112,6 @@ final _objc_msgSend_xtuoz7 = objc.msgSendPointer ffi.Pointer, ) >(); -late final _sel_currentTime = objc.registerName("currentTime"); -final _objc_msgSend_1ukqyt8 = objc.msgSendPointer - .cast< - ffi.NativeFunction< - ffi.Double Function( - ffi.Pointer, - ffi.Pointer, - ) - > - >() - .asFunction< - double Function( - ffi.Pointer, - ffi.Pointer, - ) - >(); -final _objc_msgSend_1ukqyt8Fpret = objc.msgSendFpretPointer - .cast< - ffi.NativeFunction< - ffi.Double Function( - ffi.Pointer, - ffi.Pointer, - ) - > - >() - .asFunction< - double Function( - ffi.Pointer, - ffi.Pointer, - ) - >(); -late final _sel_setCurrentTime_ = objc.registerName("setCurrentTime:"); -final _objc_msgSend_hwm8nu = objc.msgSendPointer - .cast< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Double, - ) - > - >() - .asFunction< - void Function( - ffi.Pointer, - ffi.Pointer, - double, - ) - >(); -late final _sel_deviceCurrentTime = objc.registerName("deviceCurrentTime"); -late final _sel_duration = objc.registerName("duration"); late final _sel_enableRate = objc.registerName("enableRate"); final _objc_msgSend_91o635 = objc.msgSendPointer .cast< @@ -281,57 +235,8 @@ final _objc_msgSend_v5hmet = objc.msgSendPointer late final _sel_isPlaying = objc.registerName("isPlaying"); late final _sel_rate = objc.registerName("rate"); late final _sel_setRate_ = objc.registerName("setRate:"); -late final _sel_url = objc.registerName("url"); late final _sel_volume = objc.registerName("volume"); late final _sel_setVolume_ = objc.registerName("setVolume:"); -typedef instancetype = ffi.Pointer; -typedef Dartinstancetype = objc.ObjCObjectBase; -late final _sel_initWithContentsOf_error_ = objc.registerName( - "initWithContentsOf:error:", -); -final _objc_msgSend_1lhpu4m = objc.msgSendPointer - .cast< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer>, - ) - > - >() - .asFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer>, - ) - >(); -late final _sel_initWithContentsOf_fileTypeHint_error_ = objc.registerName( - "initWithContentsOf:fileTypeHint:error:", -); -final _objc_msgSend_1pnyuds = objc.msgSendPointer - .cast< - ffi.NativeFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer>, - ) - > - >() - .asFunction< - ffi.Pointer Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer>, - ) - >(); late final _sel_averagePowerForChannel_ = objc.registerName( "averagePowerForChannel:", ); @@ -389,49 +294,11 @@ late final _sel_peakPowerForChannel_ = objc.registerName( "peakPowerForChannel:", ); late final _sel_play = objc.registerName("play"); -late final _sel_playAtTime_ = objc.registerName("playAtTime:"); -final _objc_msgSend_18chyc = objc.msgSendPointer - .cast< - ffi.NativeFunction< - ffi.Bool Function( - ffi.Pointer, - ffi.Pointer, - ffi.Double, - ) - > - >() - .asFunction< - bool Function( - ffi.Pointer, - ffi.Pointer, - double, - ) - >(); late final _sel_prepareToPlay = objc.registerName("prepareToPlay"); -late final _sel_setVolume_fadeDuration_ = objc.registerName( - "setVolume:fadeDuration:", -); -final _objc_msgSend_1p4uk9e = objc.msgSendPointer - .cast< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Float, - ffi.Double, - ) - > - >() - .asFunction< - void Function( - ffi.Pointer, - ffi.Pointer, - double, - double, - ) - >(); late final _sel_stop = objc.registerName("stop"); late final _sel_updateMeters = objc.registerName("updateMeters"); +typedef instancetype = ffi.Pointer; +typedef Dartinstancetype = objc.ObjCObjectBase; late final _sel_init = objc.registerName("init"); late final _sel_new = objc.registerName("new"); late final _sel_allocWithZone_ = objc.registerName("allocWithZone:"); @@ -596,7 +463,12 @@ class AVAudioPlayerWrapper extends objc.NSObject { ffi.Pointer pointer, { bool retain = false, bool release = false, - }) : super.castFromPointer(pointer, retain: retain, release: release); + }) : super.castFromPointer(pointer, retain: retain, release: release) { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper', + macOS: (false, (10, 7, 0)), + ); + } /// Constructs a [AVAudioPlayerWrapper] that points to the same underlying object as [other]. AVAudioPlayerWrapper.castFrom(objc.ObjCObjectBase other) @@ -618,8 +490,51 @@ class AVAudioPlayerWrapper extends objc.NSObject { ); } + /// new + static AVAudioPlayerWrapper new$() { + final _ret = _objc_msgSend_151sglz(_class_AVAudioPlayerWrapper, _sel_new); + return AVAudioPlayerWrapper.castFromPointer( + _ret, + retain: false, + release: true, + ); + } + + /// allocWithZone: + static AVAudioPlayerWrapper allocWithZone(ffi.Pointer zone) { + final _ret = _objc_msgSend_1cwp428( + _class_AVAudioPlayerWrapper, + _sel_allocWithZone_, + zone, + ); + return AVAudioPlayerWrapper.castFromPointer( + _ret, + retain: false, + release: true, + ); + } + + /// alloc + static AVAudioPlayerWrapper alloc() { + final _ret = _objc_msgSend_151sglz(_class_AVAudioPlayerWrapper, _sel_alloc); + return AVAudioPlayerWrapper.castFromPointer( + _ret, + retain: false, + release: true, + ); + } + + /// Returns a new instance of AVAudioPlayerWrapper constructed with the default `new` method. + factory AVAudioPlayerWrapper() => new$(); +} + +extension AVAudioPlayerWrapper$Methods on AVAudioPlayerWrapper { /// currentDevice objc.NSString? get currentDevice { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.currentDevice', + macOS: (false, (10, 13, 0)), + ); final _ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_currentDevice); return _ret.address == 0 ? null @@ -628,6 +543,10 @@ class AVAudioPlayerWrapper extends objc.NSObject { /// setCurrentDevice: set currentDevice(objc.NSString? value) { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.setCurrentDevice:', + macOS: (false, (10, 13, 0)), + ); _objc_msgSend_xtuoz7( this.ref.pointer, _sel_setCurrentDevice_, @@ -635,44 +554,30 @@ class AVAudioPlayerWrapper extends objc.NSObject { ); } - /// currentTime - double get currentTime { - return objc.useMsgSendVariants - ? _objc_msgSend_1ukqyt8Fpret(this.ref.pointer, _sel_currentTime) - : _objc_msgSend_1ukqyt8(this.ref.pointer, _sel_currentTime); - } - - /// setCurrentTime: - set currentTime(double value) { - _objc_msgSend_hwm8nu(this.ref.pointer, _sel_setCurrentTime_, value); - } - - /// deviceCurrentTime - double get deviceCurrentTime { - return objc.useMsgSendVariants - ? _objc_msgSend_1ukqyt8Fpret(this.ref.pointer, _sel_deviceCurrentTime) - : _objc_msgSend_1ukqyt8(this.ref.pointer, _sel_deviceCurrentTime); - } - - /// duration - double get duration { - return objc.useMsgSendVariants - ? _objc_msgSend_1ukqyt8Fpret(this.ref.pointer, _sel_duration) - : _objc_msgSend_1ukqyt8(this.ref.pointer, _sel_duration); - } - /// enableRate bool get enableRate { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.enableRate', + macOS: (false, (10, 8, 0)), + ); return _objc_msgSend_91o635(this.ref.pointer, _sel_enableRate); } /// setEnableRate: set enableRate(bool value) { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.setEnableRate:', + macOS: (false, (10, 8, 0)), + ); _objc_msgSend_1s56lr9(this.ref.pointer, _sel_setEnableRate_, value); } /// format AVAudioFormatWrapper get format { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.format', + macOS: (false, (10, 12, 0)), + ); final _ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_format); return AVAudioFormatWrapper.castFromPointer( _ret, @@ -683,31 +588,55 @@ class AVAudioPlayerWrapper extends objc.NSObject { /// isMeteringEnabled bool get isMeteringEnabled { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.isMeteringEnabled', + macOS: (false, (10, 7, 0)), + ); return _objc_msgSend_91o635(this.ref.pointer, _sel_isMeteringEnabled); } /// setIsMeteringEnabled: set isMeteringEnabled(bool value) { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.setIsMeteringEnabled:', + macOS: (false, (10, 7, 0)), + ); _objc_msgSend_1s56lr9(this.ref.pointer, _sel_setIsMeteringEnabled_, value); } /// numberOfChannels int get numberOfChannels { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.numberOfChannels', + macOS: (false, (10, 7, 0)), + ); return _objc_msgSend_1hz7y9r(this.ref.pointer, _sel_numberOfChannels); } /// numberOfLoops int get numberOfLoops { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.numberOfLoops', + macOS: (false, (10, 7, 0)), + ); return _objc_msgSend_1hz7y9r(this.ref.pointer, _sel_numberOfLoops); } /// setNumberOfLoops: set numberOfLoops(int value) { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.setNumberOfLoops:', + macOS: (false, (10, 7, 0)), + ); _objc_msgSend_4sp4xj(this.ref.pointer, _sel_setNumberOfLoops_, value); } /// pan double get pan { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.pan', + macOS: (false, (10, 7, 0)), + ); return objc.useMsgSendVariants ? _objc_msgSend_2cgrxlFpret(this.ref.pointer, _sel_pan) : _objc_msgSend_2cgrxl(this.ref.pointer, _sel_pan); @@ -715,16 +644,28 @@ class AVAudioPlayerWrapper extends objc.NSObject { /// setPan: set pan(double value) { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.setPan:', + macOS: (false, (10, 7, 0)), + ); _objc_msgSend_v5hmet(this.ref.pointer, _sel_setPan_, value); } /// isPlaying bool get isPlaying { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.isPlaying', + macOS: (false, (10, 7, 0)), + ); return _objc_msgSend_91o635(this.ref.pointer, _sel_isPlaying); } /// rate double get rate { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.rate', + macOS: (false, (10, 8, 0)), + ); return objc.useMsgSendVariants ? _objc_msgSend_2cgrxlFpret(this.ref.pointer, _sel_rate) : _objc_msgSend_2cgrxl(this.ref.pointer, _sel_rate); @@ -732,19 +673,19 @@ class AVAudioPlayerWrapper extends objc.NSObject { /// setRate: set rate(double value) { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.setRate:', + macOS: (false, (10, 8, 0)), + ); _objc_msgSend_v5hmet(this.ref.pointer, _sel_setRate_, value); } - /// url - objc.NSURL? get url { - final _ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_url); - return _ret.address == 0 - ? null - : objc.NSURL.castFromPointer(_ret, retain: true, release: true); - } - /// volume double get volume { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.volume', + macOS: (false, (10, 7, 0)), + ); return objc.useMsgSendVariants ? _objc_msgSend_2cgrxlFpret(this.ref.pointer, _sel_volume) : _objc_msgSend_2cgrxl(this.ref.pointer, _sel_volume); @@ -752,53 +693,19 @@ class AVAudioPlayerWrapper extends objc.NSObject { /// setVolume: set volume(double value) { - _objc_msgSend_v5hmet(this.ref.pointer, _sel_setVolume_, value); - } - - /// initWithContentsOf:error: - AVAudioPlayerWrapper? initWithContentsOf( - objc.NSURL url$1, { - required ffi.Pointer> error, - }) { - final _ret = _objc_msgSend_1lhpu4m( - this.ref.retainAndReturnPointer(), - _sel_initWithContentsOf_error_, - url$1.ref.pointer, - error, - ); - return _ret.address == 0 - ? null - : AVAudioPlayerWrapper.castFromPointer( - _ret, - retain: false, - release: true, - ); - } - - /// initWithContentsOf:fileTypeHint:error: - AVAudioPlayerWrapper? initWithContentsOf$1( - objc.NSURL url$1, { - objc.NSString? fileTypeHint, - required ffi.Pointer> error, - }) { - final _ret = _objc_msgSend_1pnyuds( - this.ref.retainAndReturnPointer(), - _sel_initWithContentsOf_fileTypeHint_error_, - url$1.ref.pointer, - fileTypeHint?.ref.pointer ?? ffi.nullptr, - error, + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.setVolume:', + macOS: (false, (10, 7, 0)), ); - return _ret.address == 0 - ? null - : AVAudioPlayerWrapper.castFromPointer( - _ret, - retain: false, - release: true, - ); + _objc_msgSend_v5hmet(this.ref.pointer, _sel_setVolume_, value); } /// averagePowerForChannel: double averagePowerForChannel(int channelNumber) { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.averagePowerForChannel:', + macOS: (false, (10, 7, 0)), + ); return objc.useMsgSendVariants ? _objc_msgSend_1o3b4v9Fpret( this.ref.pointer, @@ -814,11 +721,19 @@ class AVAudioPlayerWrapper extends objc.NSObject { /// pause void pause() { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.pause', + macOS: (false, (10, 7, 0)), + ); _objc_msgSend_1pl9qdv(this.ref.pointer, _sel_pause); } /// peakPowerForChannel: double peakPowerForChannel(int channelNumber) { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.peakPowerForChannel:', + macOS: (false, (10, 7, 0)), + ); return objc.useMsgSendVariants ? _objc_msgSend_1o3b4v9Fpret( this.ref.pointer, @@ -834,36 +749,37 @@ class AVAudioPlayerWrapper extends objc.NSObject { /// play bool play() { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.play', + macOS: (false, (10, 7, 0)), + ); return _objc_msgSend_91o635(this.ref.pointer, _sel_play); } - /// playAtTime: - bool playAtTime(double time) { - return _objc_msgSend_18chyc(this.ref.pointer, _sel_playAtTime_, time); - } - /// prepareToPlay bool prepareToPlay() { - return _objc_msgSend_91o635(this.ref.pointer, _sel_prepareToPlay); - } - - /// setVolume:fadeDuration: - void setVolume(double volume$1, {required double fadeDuration}) { - _objc_msgSend_1p4uk9e( - this.ref.pointer, - _sel_setVolume_fadeDuration_, - volume$1, - fadeDuration, + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.prepareToPlay', + macOS: (false, (10, 7, 0)), ); + return _objc_msgSend_91o635(this.ref.pointer, _sel_prepareToPlay); } /// stop void stop() { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.stop', + macOS: (false, (10, 7, 0)), + ); _objc_msgSend_1pl9qdv(this.ref.pointer, _sel_stop); } /// updateMeters void updateMeters() { + objc.checkOsVersionInternal( + 'AVAudioPlayerWrapper.updateMeters', + macOS: (false, (10, 7, 0)), + ); _objc_msgSend_1pl9qdv(this.ref.pointer, _sel_updateMeters); } @@ -885,40 +801,6 @@ class AVAudioPlayerWrapper extends objc.NSObject { ); } - /// new - static AVAudioPlayerWrapper new$() { - final _ret = _objc_msgSend_151sglz(_class_AVAudioPlayerWrapper, _sel_new); - return AVAudioPlayerWrapper.castFromPointer( - _ret, - retain: false, - release: true, - ); - } - - /// allocWithZone: - static AVAudioPlayerWrapper allocWithZone(ffi.Pointer zone) { - final _ret = _objc_msgSend_1cwp428( - _class_AVAudioPlayerWrapper, - _sel_allocWithZone_, - zone, - ); - return AVAudioPlayerWrapper.castFromPointer( - _ret, - retain: false, - release: true, - ); - } - - /// alloc - static AVAudioPlayerWrapper alloc() { - final _ret = _objc_msgSend_151sglz(_class_AVAudioPlayerWrapper, _sel_alloc); - return AVAudioPlayerWrapper.castFromPointer( - _ret, - retain: false, - release: true, - ); - } - /// self AVAudioPlayerWrapper self$1() { final _ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_self); @@ -948,7 +830,4 @@ class AVAudioPlayerWrapper extends objc.NSObject { release: true, ); } - - /// Returns a new instance of AVAudioPlayerWrapper constructed with the default `new` method. - factory AVAudioPlayerWrapper() => new$(); } diff --git a/pkgs/swiftgen/example/avf_audio_wrapper.swift b/pkgs/swiftgen/example/avf_audio_wrapper.swift index ff373096c..0a8e611b9 100644 --- a/pkgs/swiftgen/example/avf_audio_wrapper.swift +++ b/pkgs/swiftgen/example/avf_audio_wrapper.swift @@ -1,6 +1,3 @@ -// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. import AVFAudio import Foundation @@ -177,10 +174,32 @@ import Foundation @objc public class AVAudio3DVectorOrientationWrapper: NSObject { var wrappedInstance: AVAudio3DVectorOrientation + @objc public var forward: AVAudio3DPointWrapper { + get { + AVAudio3DPointWrapper(wrappedInstance.forward) + } + set { + wrappedInstance.forward = newValue.wrappedInstance + } + } + + @objc public var up: AVAudio3DPointWrapper { + get { + AVAudio3DPointWrapper(wrappedInstance.up) + } + set { + wrappedInstance.up = newValue.wrappedInstance + } + } + init(_ wrappedInstance: AVAudio3DVectorOrientation) { self.wrappedInstance = wrappedInstance } + @objc init(forward: AVAudio3DPointWrapper, up: AVAudio3DPointWrapper) { + wrappedInstance = AVAudio3DVectorOrientation(forward: forward.wrappedInstance, up: up.wrappedInstance) + } + @objc override init() { wrappedInstance = AVAudio3DVectorOrientation() } @@ -200,6 +219,7 @@ import Foundation } +@available(macOS, introduced: 14.0) @objc public class AVAudioVoiceProcessingOtherAudioDuckingConfigurationWrapper: NSObject { var wrappedInstance: AVAudioVoiceProcessingOtherAudioDuckingConfiguration @@ -207,12 +227,14 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 14.0) @objc override init() { wrappedInstance = AVAudioVoiceProcessingOtherAudioDuckingConfiguration() } } +@available(macOS, introduced: 13.0) @objc public class AVAUPresetEventWrapper: NSObject { var wrappedInstance: AVAUPresetEvent @@ -222,21 +244,25 @@ import Foundation } +@available(macOS, introduced: 14.0) @objc public class AVAudioApplicationWrapper: NSObject { var wrappedInstance: AVAudioApplication + @available(macOS, introduced: 14.0) @objc static public var muteStateKey: String { get { AVAudioApplication.muteStateKey } } + @available(macOS, introduced: 14.0) @objc static public var shared: AVAudioApplicationWrapper { get { AVAudioApplicationWrapper(AVAudioApplication.shared) } } + @available(macOS, introduced: 14.0) @objc public var isInputMuted: Bool { get { wrappedInstance.isInputMuted @@ -247,15 +273,18 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 14.0) @objc public func setInputMuted(_ muted: Bool) throws { return try wrappedInstance.setInputMuted(muted) } } +@available(macOS, introduced: 10.10) @objc public class AVAudioBufferWrapper: NSObject { var wrappedInstance: AVAudioBuffer + @available(macOS, introduced: 10.10) @objc public var format: AVAudioFormatWrapper { get { AVAudioFormatWrapper(wrappedInstance.format) @@ -268,6 +297,7 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioChannelLayoutWrapper: NSObject { var wrappedInstance: AVAudioChannelLayout @@ -277,9 +307,11 @@ import Foundation } +@available(macOS, introduced: 10.11) @objc public class AVAudioCompressedBufferWrapper: NSObject { var wrappedInstance: AVAudioCompressedBuffer + @available(macOS, introduced: 10.11) @objc public var maximumPacketSize: Int { get { wrappedInstance.maximumPacketSize @@ -292,10 +324,19 @@ import Foundation } +@available(macOS, introduced: 10.11) @objc public class AVAudioConnectionPointWrapper: NSObject { var wrappedInstance: AVAudioConnectionPoint - @objc public var node: AVAudioNodeWrapper? { + @available(macOS, introduced: 10.11) + @objc public var bus: AVAudioNodeBus { + get { + wrappedInstance.bus + } + } + + @available(macOS, introduced: 10.11) + @objc public weak var node: AVAudioNodeWrapper? { get { wrappedInstance.node == nil ? nil : AVAudioNodeWrapper(wrappedInstance.node!) } @@ -305,8 +346,14 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.11) + @objc init(node: AVAudioNodeWrapper, bus: AVAudioNodeBus) { + wrappedInstance = AVAudioConnectionPoint(node: node.wrappedInstance, bus: bus) + } + } +@available(macOS, introduced: 10.11) @objc public class AVAudioConverterWrapper: NSObject { var wrappedInstance: AVAudioConverter @@ -328,6 +375,7 @@ import Foundation } } + @available(macOS, introduced: 10.11) @objc public var dither: Bool { get { wrappedInstance.dither @@ -337,6 +385,7 @@ import Foundation } } + @available(macOS, introduced: 10.11) @objc public var downmix: Bool { get { wrappedInstance.downmix @@ -346,6 +395,7 @@ import Foundation } } + @available(macOS, introduced: 10.11) @objc public var inputFormat: AVAudioFormatWrapper { get { AVAudioFormatWrapper(wrappedInstance.inputFormat) @@ -358,12 +408,14 @@ import Foundation } } + @available(macOS, introduced: 10.11) @objc public var outputFormat: AVAudioFormatWrapper { get { AVAudioFormatWrapper(wrappedInstance.outputFormat) } } + @available(macOS, introduced: 10.11) @objc public var primeInfo: AVAudioConverterPrimeInfoWrapper { get { AVAudioConverterPrimeInfoWrapper(wrappedInstance.primeInfo) @@ -373,6 +425,7 @@ import Foundation } } + @available(macOS, introduced: 10.11) @objc public var sampleRateConverterAlgorithm: String? { get { wrappedInstance.sampleRateConverterAlgorithm @@ -382,6 +435,7 @@ import Foundation } } + @available(macOS, introduced: 10.11) @objc public var sampleRateConverterQuality: Int { get { wrappedInstance.sampleRateConverterQuality @@ -395,6 +449,7 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.11) @objc init?(from fromFormat: AVAudioFormatWrapper, to toFormat: AVAudioFormatWrapper) { if let instance = AVAudioConverter(from: fromFormat.wrappedInstance, to: toFormat.wrappedInstance) { wrappedInstance = instance @@ -403,19 +458,23 @@ import Foundation } } + @available(macOS, introduced: 10.11) @objc public func convert(to outputBuffer: AVAudioPCMBufferWrapper, from inputBuffer: AVAudioPCMBufferWrapper) throws { return try wrappedInstance.convert(to: outputBuffer.wrappedInstance, from: inputBuffer.wrappedInstance) } + @available(macOS, introduced: 10.11) @objc public func reset() { return wrappedInstance.reset() } } +@available(macOS, introduced: 10.10) @objc public class AVAudioEngineWrapper: NSObject { var wrappedInstance: AVAudioEngine + @available(macOS, introduced: 10.13) @objc public var isAutoShutdownEnabled: Bool { get { wrappedInstance.isAutoShutdownEnabled @@ -425,36 +484,42 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var inputNode: AVAudioInputNodeWrapper { get { AVAudioInputNodeWrapper(wrappedInstance.inputNode) } } + @available(macOS, introduced: 10.13) @objc public var isInManualRenderingMode: Bool { get { wrappedInstance.isInManualRenderingMode } } + @available(macOS, introduced: 10.10) @objc public var mainMixerNode: AVAudioMixerNodeWrapper { get { AVAudioMixerNodeWrapper(wrappedInstance.mainMixerNode) } } + @available(macOS, introduced: 10.13) @objc public var manualRenderingFormat: AVAudioFormatWrapper { get { AVAudioFormatWrapper(wrappedInstance.manualRenderingFormat) } } + @available(macOS, introduced: 10.10) @objc public var outputNode: AVAudioOutputNodeWrapper { get { AVAudioOutputNodeWrapper(wrappedInstance.outputNode) } } + @available(macOS, introduced: 10.10) @objc public var isRunning: Bool { get { wrappedInstance.isRunning @@ -465,71 +530,109 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.10) @objc override init() { wrappedInstance = AVAudioEngine() } + @available(macOS, introduced: 10.10) @objc public func attach(_ node: AVAudioNodeWrapper) { return wrappedInstance.attach(node.wrappedInstance) } + @available(macOS, introduced: 10.10) @objc public func connect(_ node1: AVAudioNodeWrapper, to node2: AVAudioNodeWrapper, format: AVAudioFormatWrapper?) { return wrappedInstance.connect(node1.wrappedInstance, to: node2.wrappedInstance, format: format?.wrappedInstance) } + @available(macOS, introduced: 10.10) + @objc public func connect(_ node1: AVAudioNodeWrapper, to node2: AVAudioNodeWrapper, fromBus bus1: AVAudioNodeBus, toBus bus2: AVAudioNodeBus, format: AVAudioFormatWrapper?) { + return wrappedInstance.connect(node1.wrappedInstance, to: node2.wrappedInstance, fromBus: bus1, toBus: bus2, format: format?.wrappedInstance) + } + + @available(macOS, introduced: 10.10) @objc public func detach(_ node: AVAudioNodeWrapper) { return wrappedInstance.detach(node.wrappedInstance) } + @available(macOS, introduced: 10.13) @objc public func disableManualRenderingMode() { return wrappedInstance.disableManualRenderingMode() } + @available(macOS, introduced: 10.14) @objc public func disconnectMIDI(_ sourceNode: AVAudioNodeWrapper, from destinationNode: AVAudioNodeWrapper) { return wrappedInstance.disconnectMIDI(sourceNode.wrappedInstance, from: destinationNode.wrappedInstance) } + @available(macOS, introduced: 10.14) @objc public func disconnectMIDIInput(_ node: AVAudioNodeWrapper) { return wrappedInstance.disconnectMIDIInput(node.wrappedInstance) } + @available(macOS, introduced: 10.14) @objc public func disconnectMIDIOutput(_ node: AVAudioNodeWrapper) { return wrappedInstance.disconnectMIDIOutput(node.wrappedInstance) } + @available(macOS, introduced: 10.10) @objc public func disconnectNodeInput(_ node: AVAudioNodeWrapper) { return wrappedInstance.disconnectNodeInput(node.wrappedInstance) } + @available(macOS, introduced: 10.10) + @objc public func disconnectNodeInput(_ node: AVAudioNodeWrapper, bus: AVAudioNodeBus) { + return wrappedInstance.disconnectNodeInput(node.wrappedInstance, bus: bus) + } + + @available(macOS, introduced: 10.10) @objc public func disconnectNodeOutput(_ node: AVAudioNodeWrapper) { return wrappedInstance.disconnectNodeOutput(node.wrappedInstance) } + @available(macOS, introduced: 10.10) + @objc public func disconnectNodeOutput(_ node: AVAudioNodeWrapper, bus: AVAudioNodeBus) { + return wrappedInstance.disconnectNodeOutput(node.wrappedInstance, bus: bus) + } + + @available(macOS, introduced: 10.11) + @objc public func inputConnectionPoint(for node: AVAudioNodeWrapper, inputBus bus: AVAudioNodeBus) -> AVAudioConnectionPointWrapper? { + let result = wrappedInstance.inputConnectionPoint(for: node.wrappedInstance, inputBus: bus) + return result == nil ? nil : AVAudioConnectionPointWrapper(result!) + } + + @available(macOS, introduced: 10.10) @objc public func pause() { return wrappedInstance.pause() } + @available(macOS, introduced: 10.10) @objc public func prepare() { return wrappedInstance.prepare() } + @available(macOS, introduced: 10.10) @objc public func reset() { return wrappedInstance.reset() } + @available(macOS, introduced: 10.10) @objc public func start() throws { return try wrappedInstance.start() } + @available(macOS, introduced: 10.10) @objc public func stop() { return wrappedInstance.stop() } } +@available(macOS, introduced: 10.10) @objc public class AVAudioEnvironmentDistanceAttenuationParametersWrapper: NSObject { var wrappedInstance: AVAudioEnvironmentDistanceAttenuationParameters + @available(macOS, introduced: 10.10) @objc public var maximumDistance: Float { get { wrappedInstance.maximumDistance @@ -539,6 +642,7 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var referenceDistance: Float { get { wrappedInstance.referenceDistance @@ -548,6 +652,7 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var rolloffFactor: Float { get { wrappedInstance.rolloffFactor @@ -563,15 +668,18 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioEnvironmentNodeWrapper: NSObject { var wrappedInstance: AVAudioEnvironmentNode + @available(macOS, introduced: 10.10) @objc public var distanceAttenuationParameters: AVAudioEnvironmentDistanceAttenuationParametersWrapper { get { AVAudioEnvironmentDistanceAttenuationParametersWrapper(wrappedInstance.distanceAttenuationParameters) } } + @available(macOS, introduced: 10.10) @objc public var listenerAngularOrientation: AVAudio3DAngularOrientationWrapper { get { AVAudio3DAngularOrientationWrapper(wrappedInstance.listenerAngularOrientation) @@ -581,6 +689,17 @@ import Foundation } } + @available(macOS, introduced: 15.0) + @objc public var isListenerHeadTrackingEnabled: Bool { + get { + wrappedInstance.isListenerHeadTrackingEnabled + } + set { + wrappedInstance.isListenerHeadTrackingEnabled = newValue + } + } + + @available(macOS, introduced: 10.10) @objc public var listenerPosition: AVAudio3DPointWrapper { get { AVAudio3DPointWrapper(wrappedInstance.listenerPosition) @@ -590,6 +709,7 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var listenerVectorOrientation: AVAudio3DVectorOrientationWrapper { get { AVAudio3DVectorOrientationWrapper(wrappedInstance.listenerVectorOrientation) @@ -599,6 +719,14 @@ import Foundation } } + @available(macOS, introduced: 10.10) + @objc public var nextAvailableInputBus: AVAudioNodeBus { + get { + wrappedInstance.nextAvailableInputBus + } + } + + @available(macOS, introduced: 10.10) @objc public var outputVolume: Float { get { wrappedInstance.outputVolume @@ -608,6 +736,7 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var reverbParameters: AVAudioEnvironmentReverbParametersWrapper { get { AVAudioEnvironmentReverbParametersWrapper(wrappedInstance.reverbParameters) @@ -618,15 +747,18 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.10) @objc override init() { wrappedInstance = AVAudioEnvironmentNode() } } +@available(macOS, introduced: 10.10) @objc public class AVAudioEnvironmentReverbParametersWrapper: NSObject { var wrappedInstance: AVAudioEnvironmentReverbParameters + @available(macOS, introduced: 10.10) @objc public var enable: Bool { get { wrappedInstance.enable @@ -636,12 +768,14 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var filterParameters: AVAudioUnitEQFilterParametersWrapper { get { AVAudioUnitEQFilterParametersWrapper(wrappedInstance.filterParameters) } } + @available(macOS, introduced: 10.10) @objc public var level: Float { get { wrappedInstance.level @@ -657,24 +791,28 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioFileWrapper: NSObject { var wrappedInstance: AVAudioFile + @available(macOS, introduced: 10.10) @objc public var fileFormat: AVAudioFormatWrapper { get { AVAudioFormatWrapper(wrappedInstance.fileFormat) } } - @objc public var processingFormat: AVAudioFormatWrapper { + @available(macOS, introduced: 15.0) + @objc public var isOpen: Bool { get { - AVAudioFormatWrapper(wrappedInstance.processingFormat) + wrappedInstance.isOpen } } - @objc public var url: URL { + @available(macOS, introduced: 10.10) + @objc public var processingFormat: AVAudioFormatWrapper { get { - wrappedInstance.url + AVAudioFormatWrapper(wrappedInstance.processingFormat) } } @@ -682,41 +820,49 @@ import Foundation self.wrappedInstance = wrappedInstance } - @objc init(forReading fileURL: URL) throws { - wrappedInstance = try AVAudioFile(forReading: fileURL) + @available(macOS, introduced: 15.0) + @objc public func close() { + return wrappedInstance.close() } + @available(macOS, introduced: 10.10) @objc public func read(into buffer: AVAudioPCMBufferWrapper) throws { return try wrappedInstance.read(into: buffer.wrappedInstance) } + @available(macOS, introduced: 10.10) @objc public func write(from buffer: AVAudioPCMBufferWrapper) throws { return try wrappedInstance.write(from: buffer.wrappedInstance) } } +@available(macOS, introduced: 10.10) @objc public class AVAudioFormatWrapper: NSObject { var wrappedInstance: AVAudioFormat + @available(macOS, introduced: 10.10) @objc public var channelLayout: AVAudioChannelLayoutWrapper? { get { wrappedInstance.channelLayout == nil ? nil : AVAudioChannelLayoutWrapper(wrappedInstance.channelLayout!) } } + @available(macOS, introduced: 10.10) @objc public var isInterleaved: Bool { get { wrappedInstance.isInterleaved } } + @available(macOS, introduced: 10.10) @objc public var sampleRate: Double { get { wrappedInstance.sampleRate } } + @available(macOS, introduced: 10.10) @objc public var isStandard: Bool { get { wrappedInstance.isStandard @@ -727,21 +873,18 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.10) @objc init(standardFormatWithSampleRate sampleRate: Double, channelLayout layout: AVAudioChannelLayoutWrapper) { wrappedInstance = AVAudioFormat(standardFormatWithSampleRate: sampleRate, channelLayout: layout.wrappedInstance) } } +@available(macOS, introduced: 10.10) @objc public class AVAudioIONodeWrapper: NSObject { var wrappedInstance: AVAudioIONode - @objc public var presentationLatency: TimeInterval { - get { - wrappedInstance.presentationLatency - } - } - + @available(macOS, introduced: 10.15) @objc public var isVoiceProcessingEnabled: Bool { get { wrappedInstance.isVoiceProcessingEnabled @@ -752,15 +895,18 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.15) @objc public func setVoiceProcessingEnabled(_ enabled: Bool) throws { return try wrappedInstance.setVoiceProcessingEnabled(enabled) } } +@available(macOS, introduced: 10.10) @objc public class AVAudioInputNodeWrapper: NSObject { var wrappedInstance: AVAudioInputNode + @available(macOS, introduced: 10.15) @objc public var isVoiceProcessingAGCEnabled: Bool { get { wrappedInstance.isVoiceProcessingAGCEnabled @@ -770,6 +916,7 @@ import Foundation } } + @available(macOS, introduced: 10.15) @objc public var isVoiceProcessingBypassed: Bool { get { wrappedInstance.isVoiceProcessingBypassed @@ -779,6 +926,7 @@ import Foundation } } + @available(macOS, introduced: 10.15) @objc public var isVoiceProcessingInputMuted: Bool { get { wrappedInstance.isVoiceProcessingInputMuted @@ -788,6 +936,7 @@ import Foundation } } + @available(macOS, introduced: 14.0) @objc public var voiceProcessingOtherAudioDuckingConfiguration: AVAudioVoiceProcessingOtherAudioDuckingConfigurationWrapper { get { AVAudioVoiceProcessingOtherAudioDuckingConfigurationWrapper(wrappedInstance.voiceProcessingOtherAudioDuckingConfiguration) @@ -803,9 +952,18 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioMixerNodeWrapper: NSObject { var wrappedInstance: AVAudioMixerNode + @available(macOS, introduced: 10.10) + @objc public var nextAvailableInputBus: AVAudioNodeBus { + get { + wrappedInstance.nextAvailableInputBus + } + } + + @available(macOS, introduced: 10.10) @objc public var outputVolume: Float { get { wrappedInstance.outputVolume @@ -819,15 +977,18 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.10) @objc override init() { wrappedInstance = AVAudioMixerNode() } } +@available(macOS, introduced: 10.11) @objc public class AVAudioMixingDestinationWrapper: NSObject { var wrappedInstance: AVAudioMixingDestination + @available(macOS, introduced: 10.11) @objc public var connectionPoint: AVAudioConnectionPointWrapper { get { AVAudioConnectionPointWrapper(wrappedInstance.connectionPoint) @@ -840,55 +1001,77 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioNodeWrapper: NSObject { var wrappedInstance: AVAudioNode + @available(macOS, introduced: 10.10) @objc public var engine: AVAudioEngineWrapper? { get { wrappedInstance.engine == nil ? nil : AVAudioEngineWrapper(wrappedInstance.engine!) } } + @available(macOS, introduced: 10.10) @objc public var lastRenderTime: AVAudioTimeWrapper? { get { wrappedInstance.lastRenderTime == nil ? nil : AVAudioTimeWrapper(wrappedInstance.lastRenderTime!) } } - @objc public var latency: TimeInterval { - get { - wrappedInstance.latency - } - } - + @available(macOS, introduced: 10.10) @objc public var numberOfInputs: Int { get { wrappedInstance.numberOfInputs } } + @available(macOS, introduced: 10.10) @objc public var numberOfOutputs: Int { get { wrappedInstance.numberOfOutputs } } - @objc public var outputPresentationLatency: TimeInterval { - get { - wrappedInstance.outputPresentationLatency - } - } - init(_ wrappedInstance: AVAudioNode) { self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.10) + @objc public func inputFormat(forBus bus: AVAudioNodeBus) -> AVAudioFormatWrapper { + let result = wrappedInstance.inputFormat(forBus: bus) + return AVAudioFormatWrapper(result) + } + + @available(macOS, introduced: 10.10) + @objc public func name(forInputBus bus: AVAudioNodeBus) -> String? { + return wrappedInstance.name(forInputBus: bus) + } + + @available(macOS, introduced: 10.10) + @objc public func name(forOutputBus bus: AVAudioNodeBus) -> String? { + return wrappedInstance.name(forOutputBus: bus) + } + + @available(macOS, introduced: 10.10) + @objc public func outputFormat(forBus bus: AVAudioNodeBus) -> AVAudioFormatWrapper { + let result = wrappedInstance.outputFormat(forBus: bus) + return AVAudioFormatWrapper(result) + } + + @available(macOS, introduced: 10.10) + @objc public func removeTap(onBus bus: AVAudioNodeBus) { + return wrappedInstance.removeTap(onBus: bus) + } + + @available(macOS, introduced: 10.10) @objc public func reset() { return wrappedInstance.reset() } } +@available(macOS, introduced: 10.10) @objc public class AVAudioOutputNodeWrapper: NSObject { var wrappedInstance: AVAudioOutputNode @@ -898,9 +1081,11 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioPCMBufferWrapper: NSObject { var wrappedInstance: AVAudioPCMBuffer + @available(macOS, introduced: 10.10) @objc public var stride: Int { get { wrappedInstance.stride @@ -913,9 +1098,11 @@ import Foundation } +@available(macOS, introduced: 10.7) @objc public class AVAudioPlayerWrapper: NSObject { var wrappedInstance: AVAudioPlayer + @available(macOS, introduced: 10.13) @objc public var currentDevice: String? { get { wrappedInstance.currentDevice @@ -925,27 +1112,7 @@ import Foundation } } - @objc public var currentTime: TimeInterval { - get { - wrappedInstance.currentTime - } - set { - wrappedInstance.currentTime = newValue - } - } - - @objc public var deviceCurrentTime: TimeInterval { - get { - wrappedInstance.deviceCurrentTime - } - } - - @objc public var duration: TimeInterval { - get { - wrappedInstance.duration - } - } - + @available(macOS, introduced: 10.8) @objc public var enableRate: Bool { get { wrappedInstance.enableRate @@ -955,12 +1122,14 @@ import Foundation } } + @available(macOS, introduced: 10.12) @objc public var format: AVAudioFormatWrapper { get { AVAudioFormatWrapper(wrappedInstance.format) } } + @available(macOS, introduced: 10.7) @objc public var isMeteringEnabled: Bool { get { wrappedInstance.isMeteringEnabled @@ -970,12 +1139,14 @@ import Foundation } } + @available(macOS, introduced: 10.7) @objc public var numberOfChannels: Int { get { wrappedInstance.numberOfChannels } } + @available(macOS, introduced: 10.7) @objc public var numberOfLoops: Int { get { wrappedInstance.numberOfLoops @@ -985,6 +1156,7 @@ import Foundation } } + @available(macOS, introduced: 10.7) @objc public var pan: Float { get { wrappedInstance.pan @@ -994,12 +1166,14 @@ import Foundation } } + @available(macOS, introduced: 10.7) @objc public var isPlaying: Bool { get { wrappedInstance.isPlaying } } + @available(macOS, introduced: 10.8) @objc public var rate: Float { get { wrappedInstance.rate @@ -1009,12 +1183,7 @@ import Foundation } } - @objc public var url: URL? { - get { - wrappedInstance.url - } - } - + @available(macOS, introduced: 10.7) @objc public var volume: Float { get { wrappedInstance.volume @@ -1028,55 +1197,48 @@ import Foundation self.wrappedInstance = wrappedInstance } - @objc init(contentsOf url: URL) throws { - wrappedInstance = try AVAudioPlayer(contentsOf: url) - } - - @objc init(contentsOf url: URL, fileTypeHint utiString: String?) throws { - wrappedInstance = try AVAudioPlayer(contentsOf: url, fileTypeHint: utiString) - } - + @available(macOS, introduced: 10.7) @objc public func averagePower(forChannel channelNumber: Int) -> Float { return wrappedInstance.averagePower(forChannel: channelNumber) } + @available(macOS, introduced: 10.7) @objc public func pause() { return wrappedInstance.pause() } + @available(macOS, introduced: 10.7) @objc public func peakPower(forChannel channelNumber: Int) -> Float { return wrappedInstance.peakPower(forChannel: channelNumber) } + @available(macOS, introduced: 10.7) @objc public func play() -> Bool { return wrappedInstance.play() } - @objc public func play(atTime time: TimeInterval) -> Bool { - return wrappedInstance.play(atTime: time) - } - + @available(macOS, introduced: 10.7) @objc public func prepareToPlay() -> Bool { return wrappedInstance.prepareToPlay() } - @objc public func setVolume(_ volume: Float, fadeDuration duration: TimeInterval) { - return wrappedInstance.setVolume(volume, fadeDuration: duration) - } - + @available(macOS, introduced: 10.7) @objc public func stop() { return wrappedInstance.stop() } + @available(macOS, introduced: 10.7) @objc public func updateMeters() { return wrappedInstance.updateMeters() } } +@available(macOS, introduced: 10.10) @objc public class AVAudioPlayerNodeWrapper: NSObject { var wrappedInstance: AVAudioPlayerNode + @available(macOS, introduced: 10.10) @objc public var isPlaying: Bool { get { wrappedInstance.isPlaying @@ -1087,67 +1249,62 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.10) @objc override init() { wrappedInstance = AVAudioPlayerNode() } + @available(macOS, introduced: 10.10) @objc public func nodeTime(forPlayerTime playerTime: AVAudioTimeWrapper) -> AVAudioTimeWrapper? { let result = wrappedInstance.nodeTime(forPlayerTime: playerTime.wrappedInstance) return result == nil ? nil : AVAudioTimeWrapper(result!) } + @available(macOS, introduced: 10.10) @objc public func pause() { return wrappedInstance.pause() } + @available(macOS, introduced: 10.10) @objc public func play() { return wrappedInstance.play() } + @available(macOS, introduced: 10.10) @objc public func play(at when: AVAudioTimeWrapper?) { return wrappedInstance.play(at: when?.wrappedInstance) } + @available(macOS, introduced: 10.10) @objc public func playerTime(forNodeTime nodeTime: AVAudioTimeWrapper) -> AVAudioTimeWrapper? { let result = wrappedInstance.playerTime(forNodeTime: nodeTime.wrappedInstance) return result == nil ? nil : AVAudioTimeWrapper(result!) } - @objc public func scheduleBuffer(_ buffer: AVAudioPCMBufferWrapper) async { - return await wrappedInstance.scheduleBuffer(buffer.wrappedInstance) - } - + @available(macOS, introduced: 10.10) @objc public func scheduleFile(_ file: AVAudioFileWrapper, at when: AVAudioTimeWrapper?) async { return await wrappedInstance.scheduleFile(file.wrappedInstance, at: when?.wrappedInstance) } + @available(macOS, introduced: 10.10) @objc public func stop() { return wrappedInstance.stop() } } +@available(macOS, introduced: 10.7) @objc public class AVAudioRecorderWrapper: NSObject { var wrappedInstance: AVAudioRecorder - @objc public var currentTime: TimeInterval { - get { - wrappedInstance.currentTime - } - } - - @objc public var deviceCurrentTime: TimeInterval { - get { - wrappedInstance.deviceCurrentTime - } - } - + @available(macOS, introduced: 10.12) @objc public var format: AVAudioFormatWrapper { get { AVAudioFormatWrapper(wrappedInstance.format) } } + @available(macOS, introduced: 10.7) @objc public var isMeteringEnabled: Bool { get { wrappedInstance.isMeteringEnabled @@ -1157,75 +1314,64 @@ import Foundation } } + @available(macOS, introduced: 10.7) @objc public var isRecording: Bool { get { wrappedInstance.isRecording } } - @objc public var url: URL { - get { - wrappedInstance.url - } - } - init(_ wrappedInstance: AVAudioRecorder) { self.wrappedInstance = wrappedInstance } - @objc init(url: URL, format: AVAudioFormatWrapper) throws { - wrappedInstance = try AVAudioRecorder(url: url, format: format.wrappedInstance) - } - + @available(macOS, introduced: 10.7) @objc public func averagePower(forChannel channelNumber: Int) -> Float { return wrappedInstance.averagePower(forChannel: channelNumber) } + @available(macOS, introduced: 10.7) @objc public func deleteRecording() -> Bool { return wrappedInstance.deleteRecording() } + @available(macOS, introduced: 10.7) @objc public func pause() { return wrappedInstance.pause() } + @available(macOS, introduced: 10.7) @objc public func peakPower(forChannel channelNumber: Int) -> Float { return wrappedInstance.peakPower(forChannel: channelNumber) } + @available(macOS, introduced: 10.7) @objc public func prepareToRecord() -> Bool { return wrappedInstance.prepareToRecord() } + @available(macOS, introduced: 10.7) @objc public func record() -> Bool { return wrappedInstance.record() } - @objc public func record(atTime time: TimeInterval) -> Bool { - return wrappedInstance.record(atTime: time) - } - - @objc public func record(atTime time: TimeInterval, forDuration duration: TimeInterval) -> Bool { - return wrappedInstance.record(atTime: time, forDuration: duration) - } - - @objc public func record(forDuration duration: TimeInterval) -> Bool { - return wrappedInstance.record(forDuration: duration) - } - + @available(macOS, introduced: 10.7) @objc public func stop() { return wrappedInstance.stop() } + @available(macOS, introduced: 10.7) @objc public func updateMeters() { return wrappedInstance.updateMeters() } } +@available(macOS, introduced: 11.0) @objc public class AVAudioRoutingArbiterWrapper: NSObject { var wrappedInstance: AVAudioRoutingArbiter + @available(macOS, introduced: 11.0) @objc static public var shared: AVAudioRoutingArbiterWrapper { get { AVAudioRoutingArbiterWrapper(AVAudioRoutingArbiter.shared) @@ -1236,39 +1382,25 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 11.0) @objc public func leave() { return wrappedInstance.leave() } } +@available(macOS, introduced: 10.11) @objc public class AVAudioSequencerWrapper: NSObject { var wrappedInstance: AVAudioSequencer - @objc public var currentPositionInBeats: TimeInterval { - get { - wrappedInstance.currentPositionInBeats - } - set { - wrappedInstance.currentPositionInBeats = newValue - } - } - - @objc public var currentPositionInSeconds: TimeInterval { - get { - wrappedInstance.currentPositionInSeconds - } - set { - wrappedInstance.currentPositionInSeconds = newValue - } - } - + @available(macOS, introduced: 10.11) @objc public var isPlaying: Bool { get { wrappedInstance.isPlaying } } + @available(macOS, introduced: 10.11) @objc public var rate: Float { get { wrappedInstance.rate @@ -1278,6 +1410,7 @@ import Foundation } } + @available(macOS, introduced: 10.11) @objc public var tempoTrack: AVMusicTrackWrapper { get { AVMusicTrackWrapper(wrappedInstance.tempoTrack) @@ -1288,172 +1421,199 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.11) @objc override init() { wrappedInstance = AVAudioSequencer() } + @available(macOS, introduced: 10.11) @objc init(audioEngine engine: AVAudioEngineWrapper) { wrappedInstance = AVAudioSequencer(audioEngine: engine.wrappedInstance) } + @available(macOS, introduced: 13.0) @objc public func createAndAppendTrack() -> AVMusicTrackWrapper { let result = wrappedInstance.createAndAppendTrack() return AVMusicTrackWrapper(result) } + @available(macOS, introduced: 10.11) @objc public func prepareToPlay() { return wrappedInstance.prepareToPlay() } + @available(macOS, introduced: 13.0) @objc public func removeTrack(_ track: AVMusicTrackWrapper) -> Bool { return wrappedInstance.removeTrack(track.wrappedInstance) } + @available(macOS, introduced: 13.0) @objc public func reverseEvents() { return wrappedInstance.reverseEvents() } + @available(macOS, introduced: 10.11) @objc public func start() throws { return try wrappedInstance.start() } + @available(macOS, introduced: 10.11) @objc public func stop() { return wrappedInstance.stop() } - @objc public func write(to fileURL: URL, smpteResolution resolution: Int, replaceExisting replace: Bool) throws { - return try wrappedInstance.write(to: fileURL, smpteResolution: resolution, replaceExisting: replace) - } - + @available(macOS, introduced: 13.0) @objc public class InfoDictionaryKeyWrapper: NSObject { var wrappedInstance: AVAudioSequencer.InfoDictionaryKey + @available(macOS, introduced: 13.0) @objc static public var album: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.album) } } + @available(macOS, introduced: 13.0) @objc static public var approximateDurationInSeconds: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.approximateDurationInSeconds) } } + @available(macOS, introduced: 13.0) @objc static public var artist: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.artist) } } + @available(macOS, introduced: 13.0) @objc static public var channelLayout: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.channelLayout) } } + @available(macOS, introduced: 13.0) @objc static public var comments: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.comments) } } + @available(macOS, introduced: 13.0) @objc static public var composer: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.composer) } } + @available(macOS, introduced: 13.0) @objc static public var copyright: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.copyright) } } + @available(macOS, introduced: 13.0) @objc static public var encodingApplication: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.encodingApplication) } } + @available(macOS, introduced: 13.0) @objc static public var genre: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.genre) } } + @available(macOS, introduced: 13.0) @objc static public var ISRC: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.ISRC) } } + @available(macOS, introduced: 13.0) @objc static public var keySignature: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.keySignature) } } + @available(macOS, introduced: 13.0) @objc static public var lyricist: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.lyricist) } } + @available(macOS, introduced: 13.0) @objc static public var nominalBitRate: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.nominalBitRate) } } + @available(macOS, introduced: 13.0) @objc static public var recordedDate: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.recordedDate) } } + @available(macOS, introduced: 13.0) @objc static public var sourceBitDepth: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.sourceBitDepth) } } + @available(macOS, introduced: 13.0) @objc static public var sourceEncoder: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.sourceEncoder) } } + @available(macOS, introduced: 13.0) @objc static public var subTitle: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.subTitle) } } + @available(macOS, introduced: 13.0) @objc static public var tempo: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.tempo) } } + @available(macOS, introduced: 13.0) @objc static public var timeSignature: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.timeSignature) } } + @available(macOS, introduced: 13.0) @objc static public var title: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.title) } } + @available(macOS, introduced: 13.0) @objc static public var trackNumber: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.trackNumber) } } + @available(macOS, introduced: 13.0) @objc static public var year: AVAudioSequencerWrapper.InfoDictionaryKeyWrapper { get { InfoDictionaryKeyWrapper(AVAudioSequencer.InfoDictionaryKey.year) @@ -1464,6 +1624,7 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 13.0) @objc init(rawValue: String) { wrappedInstance = AVAudioSequencer.InfoDictionaryKey(rawValue: rawValue) } @@ -1472,6 +1633,7 @@ import Foundation } +@available(macOS, introduced: 10.15) @objc public class AVAudioSinkNodeWrapper: NSObject { var wrappedInstance: AVAudioSinkNode @@ -1481,6 +1643,7 @@ import Foundation } +@available(macOS, introduced: 10.15) @objc public class AVAudioSourceNodeWrapper: NSObject { var wrappedInstance: AVAudioSourceNode @@ -1490,21 +1653,25 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioTimeWrapper: NSObject { var wrappedInstance: AVAudioTime + @available(macOS, introduced: 10.10) @objc public var isHostTimeValid: Bool { get { wrappedInstance.isHostTimeValid } } + @available(macOS, introduced: 10.10) @objc public var sampleRate: Double { get { wrappedInstance.sampleRate } } + @available(macOS, introduced: 10.10) @objc public var isSampleTimeValid: Bool { get { wrappedInstance.isSampleTimeValid @@ -1515,6 +1682,7 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.10) @objc public func extrapolateTime(fromAnchor anchorTime: AVAudioTimeWrapper) -> AVAudioTimeWrapper? { let result = wrappedInstance.extrapolateTime(fromAnchor: anchorTime.wrappedInstance) return result == nil ? nil : AVAudioTimeWrapper(result!) @@ -1522,21 +1690,25 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitWrapper: NSObject { var wrappedInstance: AVAudioUnit + @available(macOS, introduced: 10.10) @objc public var manufacturerName: String { get { wrappedInstance.manufacturerName } } + @available(macOS, introduced: 10.10) @objc public var name: String { get { wrappedInstance.name } } + @available(macOS, introduced: 10.10) @objc public var version: Int { get { wrappedInstance.version @@ -1547,87 +1719,83 @@ import Foundation self.wrappedInstance = wrappedInstance } - @objc public func loadPreset(at url: URL) throws { - return try wrappedInstance.loadPreset(at: url) - } - } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitComponentWrapper: NSObject { var wrappedInstance: AVAudioUnitComponent - @objc public var componentURL: URL? { - get { - wrappedInstance.componentURL - } - } - + @available(macOS, introduced: 10.10) @objc public var hasCustomView: Bool { get { wrappedInstance.hasCustomView } } + @available(macOS, introduced: 10.10) @objc public var hasMIDIInput: Bool { get { wrappedInstance.hasMIDIInput } } + @available(macOS, introduced: 10.10) @objc public var hasMIDIOutput: Bool { get { wrappedInstance.hasMIDIOutput } } - @objc public var iconURL: URL? { - get { - wrappedInstance.iconURL - } - } - + @available(macOS, introduced: 10.10) @objc public var localizedTypeName: String { get { wrappedInstance.localizedTypeName } } + @available(macOS, introduced: 10.10) @objc public var manufacturerName: String { get { wrappedInstance.manufacturerName } } + @available(macOS, introduced: 10.10) @objc public var name: String { get { wrappedInstance.name } } + @available(macOS, introduced: 10.10) @objc public var passesAUVal: Bool { get { wrappedInstance.passesAUVal } } + @available(macOS, introduced: 10.10) @objc public var isSandboxSafe: Bool { get { wrappedInstance.isSandboxSafe } } + @available(macOS, introduced: 10.10) @objc public var typeName: String { get { wrappedInstance.typeName } } + @available(macOS, introduced: 10.10) @objc public var version: Int { get { wrappedInstance.version } } + @available(macOS, introduced: 10.10) @objc public var versionString: String { get { wrappedInstance.versionString @@ -1638,12 +1806,14 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.10) @objc public func supportsNumberInputChannels(_ numInputChannels: Int, outputChannels numOutputChannels: Int) -> Bool { return wrappedInstance.supportsNumberInputChannels(numInputChannels, outputChannels: numOutputChannels) } } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitComponentManagerWrapper: NSObject { var wrappedInstance: AVAudioUnitComponentManager @@ -1653,18 +1823,11 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitDelayWrapper: NSObject { var wrappedInstance: AVAudioUnitDelay - @objc public var delayTime: TimeInterval { - get { - wrappedInstance.delayTime - } - set { - wrappedInstance.delayTime = newValue - } - } - + @available(macOS, introduced: 10.10) @objc public var feedback: Float { get { wrappedInstance.feedback @@ -1674,6 +1837,7 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var lowPassCutoff: Float { get { wrappedInstance.lowPassCutoff @@ -1683,6 +1847,7 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var wetDryMix: Float { get { wrappedInstance.wetDryMix @@ -1698,9 +1863,11 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitDistortionWrapper: NSObject { var wrappedInstance: AVAudioUnitDistortion + @available(macOS, introduced: 10.10) @objc public var preGain: Float { get { wrappedInstance.preGain @@ -1710,6 +1877,7 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var wetDryMix: Float { get { wrappedInstance.wetDryMix @@ -1725,9 +1893,11 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitEQWrapper: NSObject { var wrappedInstance: AVAudioUnitEQ + @available(macOS, introduced: 10.10) @objc public var globalGain: Float { get { wrappedInstance.globalGain @@ -1741,15 +1911,18 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.10) @objc init(numberOfBands: Int) { wrappedInstance = AVAudioUnitEQ(numberOfBands: numberOfBands) } } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitEQFilterParametersWrapper: NSObject { var wrappedInstance: AVAudioUnitEQFilterParameters + @available(macOS, introduced: 10.10) @objc public var bandwidth: Float { get { wrappedInstance.bandwidth @@ -1759,6 +1932,7 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var bypass: Bool { get { wrappedInstance.bypass @@ -1768,6 +1942,7 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var frequency: Float { get { wrappedInstance.frequency @@ -1777,6 +1952,7 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var gain: Float { get { wrappedInstance.gain @@ -1792,9 +1968,11 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitEffectWrapper: NSObject { var wrappedInstance: AVAudioUnitEffect + @available(macOS, introduced: 10.10) @objc public var bypass: Bool { get { wrappedInstance.bypass @@ -1810,9 +1988,11 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitGeneratorWrapper: NSObject { var wrappedInstance: AVAudioUnitGenerator + @available(macOS, introduced: 10.10) @objc public var bypass: Bool { get { wrappedInstance.bypass @@ -1828,6 +2008,7 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitMIDIInstrumentWrapper: NSObject { var wrappedInstance: AVAudioUnitMIDIInstrument @@ -1837,9 +2018,11 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitReverbWrapper: NSObject { var wrappedInstance: AVAudioUnitReverb + @available(macOS, introduced: 10.10) @objc public var wetDryMix: Float { get { wrappedInstance.wetDryMix @@ -1855,9 +2038,11 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitSamplerWrapper: NSObject { var wrappedInstance: AVAudioUnitSampler + @available(macOS, introduced: 10.10) @objc public var globalTuning: Float { get { wrappedInstance.globalTuning @@ -1867,6 +2052,7 @@ import Foundation } } + @available(macOS, introduced: 10.10, deprecated: 12.0) @objc public var masterGain: Float { get { wrappedInstance.masterGain @@ -1876,6 +2062,7 @@ import Foundation } } + @available(macOS, introduced: 12.0) @objc public var overallGain: Float { get { wrappedInstance.overallGain @@ -1885,6 +2072,7 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var stereoPan: Float { get { wrappedInstance.stereoPan @@ -1898,15 +2086,13 @@ import Foundation self.wrappedInstance = wrappedInstance } - @objc public func loadInstrument(at instrumentURL: URL) throws { - return try wrappedInstance.loadInstrument(at: instrumentURL) - } - } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitTimeEffectWrapper: NSObject { var wrappedInstance: AVAudioUnitTimeEffect + @available(macOS, introduced: 10.10) @objc public var bypass: Bool { get { wrappedInstance.bypass @@ -1922,9 +2108,11 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitTimePitchWrapper: NSObject { var wrappedInstance: AVAudioUnitTimePitch + @available(macOS, introduced: 10.10) @objc public var overlap: Float { get { wrappedInstance.overlap @@ -1934,6 +2122,7 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var pitch: Float { get { wrappedInstance.pitch @@ -1943,6 +2132,7 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc public var rate: Float { get { wrappedInstance.rate @@ -1958,9 +2148,11 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVAudioUnitVarispeedWrapper: NSObject { var wrappedInstance: AVAudioUnitVarispeed + @available(macOS, introduced: 10.10) @objc public var rate: Float { get { wrappedInstance.rate @@ -1976,9 +2168,21 @@ import Foundation } +@available(macOS, introduced: 13.0) @objc public class AVExtendedNoteOnEventWrapper: NSObject { var wrappedInstance: AVExtendedNoteOnEvent + @available(macOS, introduced: 13.0) + @objc public var duration: AVMusicTimeStamp { + get { + wrappedInstance.duration + } + set { + wrappedInstance.duration = newValue + } + } + + @available(macOS, introduced: 13.0) @objc public var midiNote: Float { get { wrappedInstance.midiNote @@ -1988,6 +2192,7 @@ import Foundation } } + @available(macOS, introduced: 13.0) @objc public var velocity: Float { get { wrappedInstance.velocity @@ -2003,9 +2208,11 @@ import Foundation } +@available(macOS, introduced: 13.0) @objc public class AVExtendedTempoEventWrapper: NSObject { var wrappedInstance: AVExtendedTempoEvent + @available(macOS, introduced: 13.0) @objc public var tempo: Double { get { wrappedInstance.tempo @@ -2019,12 +2226,14 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 13.0) @objc init(tempo: Double) { wrappedInstance = AVExtendedTempoEvent(tempo: tempo) } } +@available(macOS, introduced: 13.0) @objc public class AVMIDIChannelEventWrapper: NSObject { var wrappedInstance: AVMIDIChannelEvent @@ -2034,6 +2243,7 @@ import Foundation } +@available(macOS, introduced: 13.0) @objc public class AVMIDIChannelPressureEventWrapper: NSObject { var wrappedInstance: AVMIDIChannelPressureEvent @@ -2043,6 +2253,7 @@ import Foundation } +@available(macOS, introduced: 13.0) @objc public class AVMIDIControlChangeEventWrapper: NSObject { var wrappedInstance: AVMIDIControlChangeEvent @@ -2052,6 +2263,7 @@ import Foundation } +@available(macOS, introduced: 13.0) @objc public class AVMIDIMetaEventWrapper: NSObject { var wrappedInstance: AVMIDIMetaEvent @@ -2061,15 +2273,27 @@ import Foundation } +@available(macOS, introduced: 13.0) @objc public class AVMIDINoteEventWrapper: NSObject { var wrappedInstance: AVMIDINoteEvent + @available(macOS, introduced: 13.0) + @objc public var duration: AVMusicTimeStamp { + get { + wrappedInstance.duration + } + set { + wrappedInstance.duration = newValue + } + } + init(_ wrappedInstance: AVMIDINoteEvent) { self.wrappedInstance = wrappedInstance } } +@available(macOS, introduced: 13.0) @objc public class AVMIDIPitchBendEventWrapper: NSObject { var wrappedInstance: AVMIDIPitchBendEvent @@ -2079,30 +2303,18 @@ import Foundation } +@available(macOS, introduced: 10.10) @objc public class AVMIDIPlayerWrapper: NSObject { var wrappedInstance: AVMIDIPlayer - @objc public var currentPosition: TimeInterval { - get { - wrappedInstance.currentPosition - } - set { - wrappedInstance.currentPosition = newValue - } - } - - @objc public var duration: TimeInterval { - get { - wrappedInstance.duration - } - } - + @available(macOS, introduced: 10.10) @objc public var isPlaying: Bool { get { wrappedInstance.isPlaying } } + @available(macOS, introduced: 10.10) @objc public var rate: Float { get { wrappedInstance.rate @@ -2116,20 +2328,19 @@ import Foundation self.wrappedInstance = wrappedInstance } - @objc init(contentsOf inURL: URL, soundBankURL bankURL: URL?) throws { - wrappedInstance = try AVMIDIPlayer(contentsOf: inURL, soundBankURL: bankURL) - } - + @available(macOS, introduced: 10.10) @objc public func prepareToPlay() { return wrappedInstance.prepareToPlay() } + @available(macOS, introduced: 10.10) @objc public func stop() { return wrappedInstance.stop() } } +@available(macOS, introduced: 13.0) @objc public class AVMIDIPolyPressureEventWrapper: NSObject { var wrappedInstance: AVMIDIPolyPressureEvent @@ -2139,6 +2350,7 @@ import Foundation } +@available(macOS, introduced: 13.0) @objc public class AVMIDIProgramChangeEventWrapper: NSObject { var wrappedInstance: AVMIDIProgramChangeEvent @@ -2148,6 +2360,7 @@ import Foundation } +@available(macOS, introduced: 13.0) @objc public class AVMIDISysexEventWrapper: NSObject { var wrappedInstance: AVMIDISysexEvent @@ -2157,6 +2370,7 @@ import Foundation } +@available(macOS, introduced: 13.0) @objc public class AVMusicEventWrapper: NSObject { var wrappedInstance: AVMusicEvent @@ -2166,9 +2380,11 @@ import Foundation } +@available(macOS, introduced: 10.11) @objc public class AVMusicTrackWrapper: NSObject { var wrappedInstance: AVMusicTrack + @available(macOS, introduced: 10.11) @objc public var destinationAudioUnit: AVAudioUnitWrapper? { get { wrappedInstance.destinationAudioUnit == nil ? nil : AVAudioUnitWrapper(wrappedInstance.destinationAudioUnit!) @@ -2178,15 +2394,17 @@ import Foundation } } - @objc public var lengthInSeconds: TimeInterval { + @available(macOS, introduced: 10.11) + @objc public var lengthInBeats: AVMusicTimeStamp { get { - wrappedInstance.lengthInSeconds + wrappedInstance.lengthInBeats } set { - wrappedInstance.lengthInSeconds = newValue + wrappedInstance.lengthInBeats = newValue } } + @available(macOS, introduced: 10.11) @objc public var isLoopingEnabled: Bool { get { wrappedInstance.isLoopingEnabled @@ -2196,6 +2414,7 @@ import Foundation } } + @available(macOS, introduced: 10.11) @objc public var isMuted: Bool { get { wrappedInstance.isMuted @@ -2205,6 +2424,7 @@ import Foundation } } + @available(macOS, introduced: 10.11) @objc public var numberOfLoops: Int { get { wrappedInstance.numberOfLoops @@ -2214,6 +2434,17 @@ import Foundation } } + @available(macOS, introduced: 10.11) + @objc public var offsetTime: AVMusicTimeStamp { + get { + wrappedInstance.offsetTime + } + set { + wrappedInstance.offsetTime = newValue + } + } + + @available(macOS, introduced: 10.11) @objc public var isSoloed: Bool { get { wrappedInstance.isSoloed @@ -2223,12 +2454,14 @@ import Foundation } } + @available(macOS, introduced: 10.11) @objc public var timeResolution: Int { get { wrappedInstance.timeResolution } } + @available(macOS, introduced: 13.0) @objc public var usesAutomatedParameters: Bool { get { wrappedInstance.usesAutomatedParameters @@ -2242,8 +2475,14 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 13.0) + @objc public func addEvent(_ event: AVMusicEventWrapper, at beat: AVMusicTimeStamp) { + return wrappedInstance.addEvent(event.wrappedInstance, at: beat) + } + } +@available(macOS, introduced: 13.0) @objc public class AVMusicUserEventWrapper: NSObject { var wrappedInstance: AVMusicUserEvent @@ -2253,9 +2492,11 @@ import Foundation } +@available(macOS, introduced: 13.0) @objc public class AVParameterEventWrapper: NSObject { var wrappedInstance: AVParameterEvent + @available(macOS, introduced: 13.0) @objc public var value: Float { get { wrappedInstance.value @@ -2271,9 +2512,11 @@ import Foundation } +@available(macOS, introduced: 13.0) @objc public class AVSpeechSynthesisMarkerWrapper: NSObject { var wrappedInstance: AVSpeechSynthesisMarker + @available(macOS, introduced: 14.0) @objc public var bookmarkName: String { get { wrappedInstance.bookmarkName @@ -2283,6 +2526,7 @@ import Foundation } } + @available(macOS, introduced: 13.0) @objc public var byteSampleOffset: Int { get { wrappedInstance.byteSampleOffset @@ -2292,6 +2536,7 @@ import Foundation } } + @available(macOS, introduced: 14.0) @objc public var phoneme: String { get { wrappedInstance.phoneme @@ -2305,16 +2550,19 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 14.0) @objc init(bookmarkName mark: String, atByteSampleOffset byteSampleOffset: Int) { wrappedInstance = AVSpeechSynthesisMarker(bookmarkName: mark, atByteSampleOffset: byteSampleOffset) } + @available(macOS, introduced: 14.0) @objc init(phonemeString phoneme: String, atByteSampleOffset byteSampleOffset: Int) { wrappedInstance = AVSpeechSynthesisMarker(phonemeString: phoneme, atByteSampleOffset: byteSampleOffset) } } +@available(macOS, introduced: 13.0) @objc public class AVSpeechSynthesisProviderAudioUnitWrapper: NSObject { var wrappedInstance: AVSpeechSynthesisProviderAudioUnit @@ -2322,25 +2570,30 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 13.0) @objc public func cancelSpeechRequest() { return wrappedInstance.cancelSpeechRequest() } + @available(macOS, introduced: 13.0) @objc public func synthesizeSpeechRequest(_ speechRequest: AVSpeechSynthesisProviderRequestWrapper) { return wrappedInstance.synthesizeSpeechRequest(speechRequest.wrappedInstance) } } +@available(macOS, introduced: 13.0) @objc public class AVSpeechSynthesisProviderRequestWrapper: NSObject { var wrappedInstance: AVSpeechSynthesisProviderRequest + @available(macOS, introduced: 13.0) @objc public var ssmlRepresentation: String { get { wrappedInstance.ssmlRepresentation } } + @available(macOS, introduced: 13.0) @objc public var voice: AVSpeechSynthesisProviderVoiceWrapper { get { AVSpeechSynthesisProviderVoiceWrapper(wrappedInstance.voice) @@ -2351,15 +2604,18 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 13.0) @objc init(ssmlRepresentation text: String, voice: AVSpeechSynthesisProviderVoiceWrapper) { wrappedInstance = AVSpeechSynthesisProviderRequest(ssmlRepresentation: text, voice: voice.wrappedInstance) } } +@available(macOS, introduced: 13.0) @objc public class AVSpeechSynthesisProviderVoiceWrapper: NSObject { var wrappedInstance: AVSpeechSynthesisProviderVoice + @available(macOS, introduced: 13.0) @objc public var age: Int { get { wrappedInstance.age @@ -2369,18 +2625,21 @@ import Foundation } } + @available(macOS, introduced: 13.0) @objc public var identifier: String { get { wrappedInstance.identifier } } + @available(macOS, introduced: 13.0) @objc public var name: String { get { wrappedInstance.name } } + @available(macOS, introduced: 13.0) @objc public var version: String { get { wrappedInstance.version @@ -2394,33 +2653,39 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 13.0) @objc static public func updateSpeechVoices() { return AVSpeechSynthesisProviderVoice.updateSpeechVoices() } } +@available(macOS, introduced: 10.14) @objc public class AVSpeechSynthesisVoiceWrapper: NSObject { var wrappedInstance: AVSpeechSynthesisVoice + @available(macOS, introduced: 10.14) @objc public var identifier: String { get { wrappedInstance.identifier } } + @available(macOS, introduced: 10.14) @objc public var language: String { get { wrappedInstance.language } } + @available(macOS, introduced: 10.14) @objc public var name: String { get { wrappedInstance.name } } + @available(macOS, introduced: 14.0) @objc public var voiceTraits: AVSpeechSynthesisVoiceWrapper.TraitsWrapper { get { TraitsWrapper(wrappedInstance.voiceTraits) @@ -2431,6 +2696,7 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.14) @objc init?(identifier: String) { if let instance = AVSpeechSynthesisVoice(identifier: identifier) { wrappedInstance = instance @@ -2439,6 +2705,7 @@ import Foundation } } + @available(macOS, introduced: 10.14) @objc init?(language languageCode: String?) { if let instance = AVSpeechSynthesisVoice(language: languageCode) { wrappedInstance = instance @@ -2447,19 +2714,23 @@ import Foundation } } + @available(macOS, introduced: 10.14) @objc static public func currentLanguageCode() -> String { return AVSpeechSynthesisVoice.currentLanguageCode() } + @available(macOS, introduced: 14.0) @objc public class TraitsWrapper: NSObject { var wrappedInstance: AVSpeechSynthesisVoice.Traits + @available(macOS, introduced: 14.0) @objc static public var isNoveltyVoice: AVSpeechSynthesisVoiceWrapper.TraitsWrapper { get { TraitsWrapper(AVSpeechSynthesisVoice.Traits.isNoveltyVoice) } } + @available(macOS, introduced: 14.0) @objc static public var isPersonalVoice: AVSpeechSynthesisVoiceWrapper.TraitsWrapper { get { TraitsWrapper(AVSpeechSynthesisVoice.Traits.isPersonalVoice) @@ -2484,15 +2755,18 @@ import Foundation } +@available(macOS, introduced: 10.14) @objc public class AVSpeechSynthesizerWrapper: NSObject { var wrappedInstance: AVSpeechSynthesizer + @available(macOS, introduced: 10.14) @objc public var isPaused: Bool { get { wrappedInstance.isPaused } } + @available(macOS, introduced: 10.14) @objc public var isSpeaking: Bool { get { wrappedInstance.isSpeaking @@ -2503,19 +2777,23 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 10.14) @objc public func continueSpeaking() -> Bool { return wrappedInstance.continueSpeaking() } + @available(macOS, introduced: 10.14) @objc public func speak(_ utterance: AVSpeechUtteranceWrapper) { return wrappedInstance.speak(utterance.wrappedInstance) } } +@available(macOS, introduced: 10.14) @objc public class AVSpeechUtteranceWrapper: NSObject { var wrappedInstance: AVSpeechUtterance + @available(macOS, introduced: 10.14) @objc public var pitchMultiplier: Float { get { wrappedInstance.pitchMultiplier @@ -2525,24 +2803,7 @@ import Foundation } } - @objc public var postUtteranceDelay: TimeInterval { - get { - wrappedInstance.postUtteranceDelay - } - set { - wrappedInstance.postUtteranceDelay = newValue - } - } - - @objc public var preUtteranceDelay: TimeInterval { - get { - wrappedInstance.preUtteranceDelay - } - set { - wrappedInstance.preUtteranceDelay = newValue - } - } - + @available(macOS, introduced: 11.0) @objc public var prefersAssistiveTechnologySettings: Bool { get { wrappedInstance.prefersAssistiveTechnologySettings @@ -2552,6 +2813,7 @@ import Foundation } } + @available(macOS, introduced: 10.14) @objc public var rate: Float { get { wrappedInstance.rate @@ -2561,12 +2823,14 @@ import Foundation } } + @available(macOS, introduced: 10.14) @objc public var speechString: String { get { wrappedInstance.speechString } } + @available(macOS, introduced: 10.14) @objc public var voice: AVSpeechSynthesisVoiceWrapper? { get { wrappedInstance.voice == nil ? nil : AVSpeechSynthesisVoiceWrapper(wrappedInstance.voice!) @@ -2576,6 +2840,7 @@ import Foundation } } + @available(macOS, introduced: 10.14) @objc public var volume: Float { get { wrappedInstance.volume @@ -2589,6 +2854,7 @@ import Foundation self.wrappedInstance = wrappedInstance } + @available(macOS, introduced: 13.0) @objc init?(ssmlRepresentation string: String) { if let instance = AVSpeechUtterance(ssmlRepresentation: string) { wrappedInstance = instance @@ -2597,6 +2863,7 @@ import Foundation } } + @available(macOS, introduced: 10.14) @objc init(string: String) { wrappedInstance = AVSpeechUtterance(string: string) } @@ -2604,30 +2871,35 @@ import Foundation } @objc public class GlobalsWrapper: NSObject { + @available(macOS, introduced: 10.9) @objc static public var AVAudioBitRateStrategy_ConstantWrapper: String { get { AVAudioBitRateStrategy_Constant } } + @available(macOS, introduced: 10.9) @objc static public var AVAudioBitRateStrategy_LongTermAverageWrapper: String { get { AVAudioBitRateStrategy_LongTermAverage } } + @available(macOS, introduced: 10.9) @objc static public var AVAudioBitRateStrategy_VariableWrapper: String { get { AVAudioBitRateStrategy_Variable } } + @available(macOS, introduced: 10.9) @objc static public var AVAudioBitRateStrategy_VariableConstrainedWrapper: String { get { AVAudioBitRateStrategy_VariableConstrained } } + @available(macOS, introduced: 10.13) @objc static public var AVAudioFileTypeKeyWrapper: String { get { AVAudioFileTypeKey @@ -2640,210 +2912,245 @@ import Foundation } } + @available(macOS, introduced: 10.10) @objc static public var AVAudioUnitManufacturerNameAppleWrapper: String { get { AVAudioUnitManufacturerNameApple } } + @available(macOS, introduced: 10.10) @objc static public var AVAudioUnitTypeEffectWrapper: String { get { AVAudioUnitTypeEffect } } + @available(macOS, introduced: 10.10) @objc static public var AVAudioUnitTypeFormatConverterWrapper: String { get { AVAudioUnitTypeFormatConverter } } + @available(macOS, introduced: 10.10) @objc static public var AVAudioUnitTypeGeneratorWrapper: String { get { AVAudioUnitTypeGenerator } } + @available(macOS, introduced: 10.10) @objc static public var AVAudioUnitTypeMIDIProcessorWrapper: String { get { AVAudioUnitTypeMIDIProcessor } } + @available(macOS, introduced: 10.10) @objc static public var AVAudioUnitTypeMixerWrapper: String { get { AVAudioUnitTypeMixer } } + @available(macOS, introduced: 10.10) @objc static public var AVAudioUnitTypeMusicDeviceWrapper: String { get { AVAudioUnitTypeMusicDevice } } + @available(macOS, introduced: 10.10) @objc static public var AVAudioUnitTypeMusicEffectWrapper: String { get { AVAudioUnitTypeMusicEffect } } + @available(macOS, introduced: 10.10) @objc static public var AVAudioUnitTypeOfflineEffectWrapper: String { get { AVAudioUnitTypeOfflineEffect } } + @available(macOS, introduced: 10.10) @objc static public var AVAudioUnitTypeOutputWrapper: String { get { AVAudioUnitTypeOutput } } + @available(macOS, introduced: 10.10) @objc static public var AVAudioUnitTypePannerWrapper: String { get { AVAudioUnitTypePanner } } + @available(macOS, introduced: 10.7) @objc static public var AVChannelLayoutKeyWrapper: String { get { AVChannelLayoutKey } } + @available(macOS, introduced: 10.9) @objc static public var AVEncoderAudioQualityForVBRKeyWrapper: String { get { AVEncoderAudioQualityForVBRKey } } + @available(macOS, introduced: 10.7) @objc static public var AVEncoderAudioQualityKeyWrapper: String { get { AVEncoderAudioQualityKey } } + @available(macOS, introduced: 10.7) @objc static public var AVEncoderBitDepthHintKeyWrapper: String { get { AVEncoderBitDepthHintKey } } + @available(macOS, introduced: 10.7) @objc static public var AVEncoderBitRateKeyWrapper: String { get { AVEncoderBitRateKey } } + @available(macOS, introduced: 10.7) @objc static public var AVEncoderBitRatePerChannelKeyWrapper: String { get { AVEncoderBitRatePerChannelKey } } + @available(macOS, introduced: 10.9) @objc static public var AVEncoderBitRateStrategyKeyWrapper: String { get { AVEncoderBitRateStrategyKey } } + @available(macOS, introduced: 10.7) @objc static public var AVFormatIDKeyWrapper: String { get { AVFormatIDKey } } + @available(macOS, introduced: 10.7) @objc static public var AVLinearPCMBitDepthKeyWrapper: String { get { AVLinearPCMBitDepthKey } } + @available(macOS, introduced: 10.7) @objc static public var AVLinearPCMIsBigEndianKeyWrapper: String { get { AVLinearPCMIsBigEndianKey } } + @available(macOS, introduced: 10.7) @objc static public var AVLinearPCMIsFloatKeyWrapper: String { get { AVLinearPCMIsFloatKey } } + @available(macOS, introduced: 10.7) @objc static public var AVLinearPCMIsNonInterleavedWrapper: String { get { AVLinearPCMIsNonInterleaved } } + @available(macOS, introduced: 10.7) @objc static public var AVNumberOfChannelsKeyWrapper: String { get { AVNumberOfChannelsKey } } + @available(macOS, introduced: 10.9) @objc static public var AVSampleRateConverterAlgorithmKeyWrapper: String { get { AVSampleRateConverterAlgorithmKey } } + @available(macOS, introduced: 10.9) @objc static public var AVSampleRateConverterAlgorithm_MasteringWrapper: String { get { AVSampleRateConverterAlgorithm_Mastering } } + @available(macOS, introduced: 10.12) @objc static public var AVSampleRateConverterAlgorithm_MinimumPhaseWrapper: String { get { AVSampleRateConverterAlgorithm_MinimumPhase } } + @available(macOS, introduced: 10.9) @objc static public var AVSampleRateConverterAlgorithm_NormalWrapper: String { get { AVSampleRateConverterAlgorithm_Normal } } + @available(macOS, introduced: 10.9) @objc static public var AVSampleRateConverterAudioQualityKeyWrapper: String { get { AVSampleRateConverterAudioQualityKey } } + @available(macOS, introduced: 10.7) @objc static public var AVSampleRateKeyWrapper: String { get { AVSampleRateKey } } + @available(macOS, introduced: 10.14) @objc static public var AVSpeechSynthesisIPANotationAttributeWrapper: String { get { AVSpeechSynthesisIPANotationAttribute } } + @available(macOS, introduced: 10.14) @objc static public var AVSpeechSynthesisVoiceIdentifierAlexWrapper: String { get { AVSpeechSynthesisVoiceIdentifierAlex } } + @available(macOS, introduced: 10.14) @objc static public var AVSpeechUtteranceDefaultSpeechRateWrapper: Float { get { AVSpeechUtteranceDefaultSpeechRate } } + @available(macOS, introduced: 10.14) @objc static public var AVSpeechUtteranceMaximumSpeechRateWrapper: Float { get { AVSpeechUtteranceMaximumSpeechRate } } + @available(macOS, introduced: 10.14) @objc static public var AVSpeechUtteranceMinimumSpeechRateWrapper: Float { get { AVSpeechUtteranceMinimumSpeechRate @@ -2866,5 +3173,15 @@ import Foundation return AVAudio3DPointWrapper(result) } + @objc static public func AVAudioMake3DVectorWrapper(_ x: Float, _ y: Float, _ z: Float) -> AVAudio3DPointWrapper { + let result = AVAudioMake3DVector(x, y, z) + return AVAudio3DPointWrapper(result) + } + + @objc static public func AVAudioMake3DVectorOrientationWrapper(_ forward: AVAudio3DPointWrapper, _ up: AVAudio3DPointWrapper) -> AVAudio3DVectorOrientationWrapper { + let result = AVAudioMake3DVectorOrientation(forward.wrappedInstance, up.wrappedInstance) + return AVAudio3DVectorOrientationWrapper(result) + } + } diff --git a/pkgs/swiftgen/example/generate_code.dart b/pkgs/swiftgen/example/generate_code.dart index 90499ad2a..c3271e5da 100644 --- a/pkgs/swiftgen/example/generate_code.dart +++ b/pkgs/swiftgen/example/generate_code.dart @@ -22,10 +22,8 @@ Future main() async { '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk', ), ), - input: ObjCCompatibleSwiftFileInput( - module: 'AVFAudio', - files: [Uri.file('avf_audio_wrapper.swift')], - ), + input: SwiftModuleInput(module: 'AVFAudio'), + objcSwiftFile: Uri.file('avf_audio_wrapper.swift'), tempDirectory: Uri.directory('temp'), outputModule: 'AVFAudioWrapper', ffigen: FfiGenConfig( diff --git a/pkgs/swiftgen/example/pubspec.yaml b/pkgs/swiftgen/example/pubspec.yaml index ff54ce7c3..5312354f6 100644 --- a/pkgs/swiftgen/example/pubspec.yaml +++ b/pkgs/swiftgen/example/pubspec.yaml @@ -28,3 +28,5 @@ dependency_overrides: path: ../../ffigen/ objective_c: path: ../../objective_c/ + swift2objc: + path: ../../swift2objc/ diff --git a/pkgs/swiftgen/lib/src/config.dart b/pkgs/swiftgen/lib/src/config.dart index 6992e6648..6498241d5 100644 --- a/pkgs/swiftgen/lib/src/config.dart +++ b/pkgs/swiftgen/lib/src/config.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. import 'package:ffigen/ffigen.dart' as ffigen; +import 'package:swift2objc/swift2objc.dart' as swift2objc; import 'util.dart'; @@ -10,6 +11,11 @@ import 'util.dart'; class SwiftGen { final Target target; final SwiftGenInput input; + + // TODO: Move these two to SwiftGenInput, and maybe rename that class. + final String? objcSwiftPreamble; + final Uri objcSwiftFile; + final Uri tempDir; final String? outputModule; final FfiGenConfig ffigen; @@ -17,6 +23,8 @@ class SwiftGen { SwiftGen({ required this.target, required this.input, + this.objcSwiftPreamble, + required this.objcSwiftFile, Uri? tempDirectory, this.outputModule, required this.ffigen, @@ -36,6 +44,7 @@ class Target { /// Describes the inputs to the swiftgen pipeline. abstract interface class SwiftGenInput { String get module; + swift2objc.InputConfig? asSwift2ObjCConfig(Target target); Iterable get files; Iterable get compileArgs; } @@ -48,12 +57,72 @@ class ObjCCompatibleSwiftFileInput implements SwiftGenInput { @override final List files; + @override + swift2objc.InputConfig? asSwift2ObjCConfig(Target target) => null; + ObjCCompatibleSwiftFileInput({required this.module, required this.files}); @override Iterable get compileArgs => const []; } +class SwiftFileInput implements SwiftGenInput { + @override + final String module; + + @override + final List files; + + SwiftFileInput({required this.module, required this.files}); + + @override + swift2objc.InputConfig? asSwift2ObjCConfig(Target target) => + swift2objc.FilesInputConfig(files: files, generatedModuleName: module); + + @override + Iterable get compileArgs => const []; +} + +class SwiftModuleInput implements SwiftGenInput { + @override + final String module; + + SwiftModuleInput({required this.module}); + + @override + swift2objc.InputConfig? asSwift2ObjCConfig(Target target) => + swift2objc.ModuleInputConfig( + module: module, + target: target.triple, + sdk: target.sdk, + ); + + @override + Iterable get files => const []; + + @override + Iterable get compileArgs => const []; +} + +class JsonFileInput implements SwiftGenInput { + @override + final String module; + + final Uri jsonFile; + + JsonFileInput({required this.module, required this.jsonFile}); + + @override + swift2objc.InputConfig? asSwift2ObjCConfig(Target target) => + swift2objc.JsonFileInputConfig(jsonFile: jsonFile); + + @override + Iterable get files => []; + + @override + Iterable get compileArgs => const []; +} + /// Selected options from [ffigen.FfiGen]. class FfiGenConfig { /// [ffigen.FfiGen.output] diff --git a/pkgs/swiftgen/lib/src/generator.dart b/pkgs/swiftgen/lib/src/generator.dart index 868df6eca..f44ebf079 100644 --- a/pkgs/swiftgen/lib/src/generator.dart +++ b/pkgs/swiftgen/lib/src/generator.dart @@ -7,6 +7,7 @@ import 'dart:io'; import 'package:ffigen/ffigen.dart' as fg; import 'package:logging/logging.dart'; import 'package:path/path.dart' as p; +import 'package:swift2objc/swift2objc.dart' as swift2objc; import 'config.dart'; import 'util.dart'; @@ -14,6 +15,10 @@ import 'util.dart'; extension SwiftGenGenerator on SwiftGen { Future generate(Logger logger) async { Directory(absTempDir).createSync(recursive: true); + final swift2objcConfig = input.asSwift2ObjCConfig(target); + if (swift2objcConfig != null) { + await _generateObjCSwiftFile(swift2objcConfig); + } await _generateObjCFile(); _generateDartFile(logger); } @@ -22,9 +27,21 @@ extension SwiftGenGenerator on SwiftGen { String get outModule => outputModule ?? input.module; String get objcHeader => p.join(absTempDir, '$outModule.h'); + Future _generateObjCSwiftFile( + swift2objc.InputConfig swift2objcConfig, + ) => swift2objc.generateWrapper( + swift2objc.Config( + input: swift2objcConfig, + outputFile: objcSwiftFile, + tempDir: tempDir, + preamble: objcSwiftPreamble, + ), + ); + Future _generateObjCFile() => run('swiftc', [ '-c', for (final uri in input.files) p.absolute(uri.toFilePath()), + p.absolute(objcSwiftFile.toFilePath()), '-module-name', outModule, '-emit-objc-header-path', diff --git a/pkgs/swiftgen/lib/swiftgen.dart b/pkgs/swiftgen/lib/swiftgen.dart index fc27ea2b4..2028223a1 100644 --- a/pkgs/swiftgen/lib/swiftgen.dart +++ b/pkgs/swiftgen/lib/swiftgen.dart @@ -3,5 +3,12 @@ // BSD-style license that can be found in the LICENSE file. export 'src/config.dart' - show FfiGenConfig, ObjCCompatibleSwiftFileInput, SwiftGen, Target; + show + FfiGenConfig, + JsonFileInput, + ObjCCompatibleSwiftFileInput, + SwiftFileInput, + SwiftGen, + SwiftModuleInput, + Target; export 'src/generator.dart' show SwiftGenGenerator; diff --git a/pkgs/swiftgen/pubspec.yaml b/pkgs/swiftgen/pubspec.yaml index 0a64269fd..67163b050 100644 --- a/pkgs/swiftgen/pubspec.yaml +++ b/pkgs/swiftgen/pubspec.yaml @@ -24,6 +24,7 @@ dependencies: objective_c: ^8.0.0 package_config: ^2.2.0 path: ^1.9.1 + swift2objc: ^0.1.0 dev_dependencies: dart_flutter_team_lints: ^3.5.2 @@ -36,3 +37,5 @@ dependency_overrides: path: ../ffigen/ objective_c: path: ../objective_c/ + swift2objc: + path: ../swift2objc/ diff --git a/pkgs/swiftgen/test/integration/classes.swift b/pkgs/swiftgen/test/integration/classes.swift new file mode 100644 index 000000000..a906f3a41 --- /dev/null +++ b/pkgs/swiftgen/test/integration/classes.swift @@ -0,0 +1,17 @@ +import Foundation + +public class TestClass { + public func myMethod() -> TestOtherClass { + return TestOtherClass() + } + + public static func create() -> TestClass { + return TestClass() + } +} + +public class TestOtherClass { + public func times10(x: Int) -> Int { + return x * 10 + } +} diff --git a/pkgs/swiftgen/test/integration/classes_bindings.dart b/pkgs/swiftgen/test/integration/classes_bindings.dart index ab70b9acc..7d3421d4d 100644 --- a/pkgs/swiftgen/test/integration/classes_bindings.dart +++ b/pkgs/swiftgen/test/integration/classes_bindings.dart @@ -28,7 +28,7 @@ external ffi.Pointer _classes_protocolTrampoline_1mbt9g9( ffi.Pointer arg0, ); -late final _class_TestClass = objc.getClass("classes.TestClass"); +late final _class_TestClassWrapper = objc.getClass("classes.TestClassWrapper"); late final _sel_isKindOfClass_ = objc.registerName("isKindOfClass:"); final _objc_msgSend_19nvye5 = objc.msgSendPointer .cast< @@ -47,43 +47,46 @@ final _objc_msgSend_19nvye5 = objc.msgSendPointer ffi.Pointer, ) >(); -late final _class_TestOtherClass = objc.getClass("classes.TestOtherClass"); -late final _sel_times10WithX_ = objc.registerName("times10WithX:"); -final _objc_msgSend_12hwf9n = objc.msgSendPointer +late final _sel_create = objc.registerName("create"); +final _objc_msgSend_151sglz = objc.msgSendPointer .cast< ffi.NativeFunction< - ffi.Long Function( + ffi.Pointer Function( ffi.Pointer, ffi.Pointer, - ffi.Long, ) > >() .asFunction< - int Function( + ffi.Pointer Function( ffi.Pointer, ffi.Pointer, - int, ) >(); -typedef instancetype = ffi.Pointer; -typedef Dartinstancetype = objc.ObjCObjectBase; -late final _sel_init = objc.registerName("init"); -final _objc_msgSend_151sglz = objc.msgSendPointer +late final _class_TestOtherClassWrapper = objc.getClass( + "classes.TestOtherClassWrapper", +); +late final _sel_times10WithX_ = objc.registerName("times10WithX:"); +final _objc_msgSend_12hwf9n = objc.msgSendPointer .cast< ffi.NativeFunction< - ffi.Pointer Function( + ffi.Long Function( ffi.Pointer, ffi.Pointer, + ffi.Long, ) > >() .asFunction< - ffi.Pointer Function( + int Function( ffi.Pointer, ffi.Pointer, + int, ) >(); +typedef instancetype = ffi.Pointer; +typedef Dartinstancetype = objc.ObjCObjectBase; +late final _sel_init = objc.registerName("init"); late final _sel_new = objc.registerName("new"); late final _sel_allocWithZone_ = objc.registerName("allocWithZone:"); final _objc_msgSend_1cwp428 = objc.msgSendPointer @@ -241,43 +244,85 @@ extension ObjCBlock_objcObjCObject_ffiVoid_CallExtension late final _sel_retain = objc.registerName("retain"); late final _sel_autorelease = objc.registerName("autorelease"); -/// TestOtherClass -class TestOtherClass extends objc.NSObject { - TestOtherClass._( +/// TestOtherClassWrapper +class TestOtherClassWrapper extends objc.NSObject { + TestOtherClassWrapper._( ffi.Pointer pointer, { bool retain = false, bool release = false, }) : super.castFromPointer(pointer, retain: retain, release: release); - /// Constructs a [TestOtherClass] that points to the same underlying object as [other]. - TestOtherClass.castFrom(objc.ObjCObjectBase other) + /// Constructs a [TestOtherClassWrapper] that points to the same underlying object as [other]. + TestOtherClassWrapper.castFrom(objc.ObjCObjectBase other) : this._(other.ref.pointer, retain: true, release: true); - /// Constructs a [TestOtherClass] that wraps the given raw object pointer. - TestOtherClass.castFromPointer( + /// Constructs a [TestOtherClassWrapper] that wraps the given raw object pointer. + TestOtherClassWrapper.castFromPointer( ffi.Pointer other, { bool retain = false, bool release = false, }) : this._(other, retain: retain, release: release); - /// Returns whether [obj] is an instance of [TestOtherClass]. + /// Returns whether [obj] is an instance of [TestOtherClassWrapper]. static bool isInstance(objc.ObjCObjectBase obj) { return _objc_msgSend_19nvye5( obj.ref.pointer, _sel_isKindOfClass_, - _class_TestOtherClass, + _class_TestOtherClassWrapper, + ); + } + + /// new + static TestOtherClassWrapper new$() { + final _ret = _objc_msgSend_151sglz(_class_TestOtherClassWrapper, _sel_new); + return TestOtherClassWrapper.castFromPointer( + _ret, + retain: false, + release: true, + ); + } + + /// allocWithZone: + static TestOtherClassWrapper allocWithZone(ffi.Pointer zone) { + final _ret = _objc_msgSend_1cwp428( + _class_TestOtherClassWrapper, + _sel_allocWithZone_, + zone, + ); + return TestOtherClassWrapper.castFromPointer( + _ret, + retain: false, + release: true, + ); + } + + /// alloc + static TestOtherClassWrapper alloc() { + final _ret = _objc_msgSend_151sglz( + _class_TestOtherClassWrapper, + _sel_alloc, + ); + return TestOtherClassWrapper.castFromPointer( + _ret, + retain: false, + release: true, ); } + /// Returns a new instance of TestOtherClassWrapper constructed with the default `new` method. + factory TestOtherClassWrapper() => new$(); +} + +extension TestOtherClassWrapper$Methods on TestOtherClassWrapper { /// times10WithX: int times10WithX(int x) { return _objc_msgSend_12hwf9n(this.ref.pointer, _sel_times10WithX_, x); } /// init - TestOtherClass init() { + TestOtherClassWrapper init() { objc.checkOsVersionInternal( - 'TestOtherClass.init', + 'TestOtherClassWrapper.init', iOS: (false, (2, 0, 0)), macOS: (false, (10, 0, 0)), ); @@ -285,150 +330,146 @@ class TestOtherClass extends objc.NSObject { this.ref.retainAndReturnPointer(), _sel_init, ); - return TestOtherClass.castFromPointer(_ret, retain: false, release: true); - } - - /// new - static TestOtherClass new$() { - final _ret = _objc_msgSend_151sglz(_class_TestOtherClass, _sel_new); - return TestOtherClass.castFromPointer(_ret, retain: false, release: true); - } - - /// allocWithZone: - static TestOtherClass allocWithZone(ffi.Pointer zone) { - final _ret = _objc_msgSend_1cwp428( - _class_TestOtherClass, - _sel_allocWithZone_, - zone, + return TestOtherClassWrapper.castFromPointer( + _ret, + retain: false, + release: true, ); - return TestOtherClass.castFromPointer(_ret, retain: false, release: true); - } - - /// alloc - static TestOtherClass alloc() { - final _ret = _objc_msgSend_151sglz(_class_TestOtherClass, _sel_alloc); - return TestOtherClass.castFromPointer(_ret, retain: false, release: true); } /// self - TestOtherClass self$1() { + TestOtherClassWrapper self$1() { final _ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_self); - return TestOtherClass.castFromPointer(_ret, retain: true, release: true); + return TestOtherClassWrapper.castFromPointer( + _ret, + retain: true, + release: true, + ); } /// retain - TestOtherClass retain() { + TestOtherClassWrapper retain() { final _ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_retain); - return TestOtherClass.castFromPointer(_ret, retain: true, release: true); + return TestOtherClassWrapper.castFromPointer( + _ret, + retain: true, + release: true, + ); } /// autorelease - TestOtherClass autorelease() { + TestOtherClassWrapper autorelease() { final _ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_autorelease); - return TestOtherClass.castFromPointer(_ret, retain: true, release: true); + return TestOtherClassWrapper.castFromPointer( + _ret, + retain: true, + release: true, + ); } - - /// Returns a new instance of TestOtherClass constructed with the default `new` method. - factory TestOtherClass() => new$(); } late final _sel_myMethod = objc.registerName("myMethod"); -late final _sel_create = objc.registerName("create"); -/// TestClass -class TestClass extends objc.NSObject { - TestClass._( +/// TestClassWrapper +class TestClassWrapper extends objc.NSObject { + TestClassWrapper._( ffi.Pointer pointer, { bool retain = false, bool release = false, }) : super.castFromPointer(pointer, retain: retain, release: release); - /// Constructs a [TestClass] that points to the same underlying object as [other]. - TestClass.castFrom(objc.ObjCObjectBase other) + /// Constructs a [TestClassWrapper] that points to the same underlying object as [other]. + TestClassWrapper.castFrom(objc.ObjCObjectBase other) : this._(other.ref.pointer, retain: true, release: true); - /// Constructs a [TestClass] that wraps the given raw object pointer. - TestClass.castFromPointer( + /// Constructs a [TestClassWrapper] that wraps the given raw object pointer. + TestClassWrapper.castFromPointer( ffi.Pointer other, { bool retain = false, bool release = false, }) : this._(other, retain: retain, release: release); - /// Returns whether [obj] is an instance of [TestClass]. + /// Returns whether [obj] is an instance of [TestClassWrapper]. static bool isInstance(objc.ObjCObjectBase obj) { return _objc_msgSend_19nvye5( obj.ref.pointer, _sel_isKindOfClass_, - _class_TestClass, + _class_TestClassWrapper, ); } - /// myMethod - TestOtherClass myMethod() { - final _ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_myMethod); - return TestOtherClass.castFromPointer(_ret, retain: true, release: true); - } - /// create - static TestClass create() { - final _ret = _objc_msgSend_151sglz(_class_TestClass, _sel_create); - return TestClass.castFromPointer(_ret, retain: true, release: true); - } - - /// init - TestClass init() { - objc.checkOsVersionInternal( - 'TestClass.init', - iOS: (false, (2, 0, 0)), - macOS: (false, (10, 0, 0)), - ); - final _ret = _objc_msgSend_151sglz( - this.ref.retainAndReturnPointer(), - _sel_init, - ); - return TestClass.castFromPointer(_ret, retain: false, release: true); + static TestClassWrapper create() { + final _ret = _objc_msgSend_151sglz(_class_TestClassWrapper, _sel_create); + return TestClassWrapper.castFromPointer(_ret, retain: true, release: true); } /// new - static TestClass new$() { - final _ret = _objc_msgSend_151sglz(_class_TestClass, _sel_new); - return TestClass.castFromPointer(_ret, retain: false, release: true); + static TestClassWrapper new$() { + final _ret = _objc_msgSend_151sglz(_class_TestClassWrapper, _sel_new); + return TestClassWrapper.castFromPointer(_ret, retain: false, release: true); } /// allocWithZone: - static TestClass allocWithZone(ffi.Pointer zone) { + static TestClassWrapper allocWithZone(ffi.Pointer zone) { final _ret = _objc_msgSend_1cwp428( - _class_TestClass, + _class_TestClassWrapper, _sel_allocWithZone_, zone, ); - return TestClass.castFromPointer(_ret, retain: false, release: true); + return TestClassWrapper.castFromPointer(_ret, retain: false, release: true); } /// alloc - static TestClass alloc() { - final _ret = _objc_msgSend_151sglz(_class_TestClass, _sel_alloc); - return TestClass.castFromPointer(_ret, retain: false, release: true); + static TestClassWrapper alloc() { + final _ret = _objc_msgSend_151sglz(_class_TestClassWrapper, _sel_alloc); + return TestClassWrapper.castFromPointer(_ret, retain: false, release: true); + } + + /// Returns a new instance of TestClassWrapper constructed with the default `new` method. + factory TestClassWrapper() => new$(); +} + +extension TestClassWrapper$Methods on TestClassWrapper { + /// myMethod + TestOtherClassWrapper myMethod() { + final _ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_myMethod); + return TestOtherClassWrapper.castFromPointer( + _ret, + retain: true, + release: true, + ); + } + + /// init + TestClassWrapper init() { + objc.checkOsVersionInternal( + 'TestClassWrapper.init', + iOS: (false, (2, 0, 0)), + macOS: (false, (10, 0, 0)), + ); + final _ret = _objc_msgSend_151sglz( + this.ref.retainAndReturnPointer(), + _sel_init, + ); + return TestClassWrapper.castFromPointer(_ret, retain: false, release: true); } /// self - TestClass self$1() { + TestClassWrapper self$1() { final _ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_self); - return TestClass.castFromPointer(_ret, retain: true, release: true); + return TestClassWrapper.castFromPointer(_ret, retain: true, release: true); } /// retain - TestClass retain() { + TestClassWrapper retain() { final _ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_retain); - return TestClass.castFromPointer(_ret, retain: true, release: true); + return TestClassWrapper.castFromPointer(_ret, retain: true, release: true); } /// autorelease - TestClass autorelease() { + TestClassWrapper autorelease() { final _ret = _objc_msgSend_151sglz(this.ref.pointer, _sel_autorelease); - return TestClass.castFromPointer(_ret, retain: true, release: true); + return TestClassWrapper.castFromPointer(_ret, retain: true, release: true); } - - /// Returns a new instance of TestClass constructed with the default `new` method. - factory TestClass() => new$(); } diff --git a/pkgs/swiftgen/test/integration/classes_test.dart b/pkgs/swiftgen/test/integration/classes_test.dart index ec4daaded..6f28ef17d 100644 --- a/pkgs/swiftgen/test/integration/classes_test.dart +++ b/pkgs/swiftgen/test/integration/classes_test.dart @@ -24,7 +24,7 @@ void main() { }); test('method invocation', () { - final testClass = TestClass.create(); + final testClass = TestClassWrapper.create(); final testOtherClass = testClass.myMethod(); expect(testOtherClass.times10WithX(123), 1230); }); diff --git a/pkgs/swiftgen/test/integration/classes_wrapper.swift b/pkgs/swiftgen/test/integration/classes_wrapper.swift deleted file mode 100644 index a40c03d4b..000000000 --- a/pkgs/swiftgen/test/integration/classes_wrapper.swift +++ /dev/null @@ -1,17 +0,0 @@ -import Foundation - -@objc public class TestClass: NSObject { - @objc public func myMethod() -> TestOtherClass { - return TestOtherClass() - } - - @objc public static func create() -> TestClass { - return TestClass() - } -} - -@objc public class TestOtherClass: NSObject { - @objc public func times10(x: Int) -> Int { - return x * 10 - } -} diff --git a/pkgs/swiftgen/test/integration/util.dart b/pkgs/swiftgen/test/integration/util.dart index af3fa4962..6a000971a 100644 --- a/pkgs/swiftgen/test/integration/util.dart +++ b/pkgs/swiftgen/test/integration/util.dart @@ -23,11 +23,14 @@ String objCTestDylib = path.join( 'objective_c.dylib', ); +Future hostTarget = Target.host(); + class TestGenerator { final String name; late final String testDir; late final String tempDir; late final String inputFile; + late final String wrapperFile; late final String outputFile; late final String outputObjCFile; late final String objInputFile; @@ -39,7 +42,8 @@ class TestGenerator { TestGenerator(this.name) { testDir = path.absolute(path.join(pkgDir, 'test/integration')); tempDir = path.join(testDir, 'temp'); - inputFile = path.join(testDir, '${name}_wrapper.swift'); + inputFile = path.join(testDir, '${name}.swift'); + wrapperFile = path.join(tempDir, '${name}_wrapper.swift'); outputFile = path.join(tempDir, '${name}_output.dart'); outputObjCFile = path.join(tempDir, '${name}_output.m'); objInputFile = path.join(tempDir, '$name.o'); @@ -50,11 +54,12 @@ class TestGenerator { } Future generateBindings() async => SwiftGen( - target: await Target.host(), - input: ObjCCompatibleSwiftFileInput( + target: await hostTarget, + input: SwiftFileInput( module: name, files: [Uri.file(inputFile)], ), + objcSwiftFile: Uri.file(wrapperFile), tempDirectory: Directory(tempDir).uri, ffigen: FfiGenConfig( output: Uri.file(outputFile), @@ -84,35 +89,56 @@ class TestGenerator { await generateBindings(); expect(File(inputFile).existsSync(), isTrue); + expect(File(wrapperFile).existsSync(), isTrue); expect(File(outputFile).existsSync(), isTrue); - expect(File(outputObjCFile).existsSync(), isTrue); - // The generation pipeline also creates some obj files as a byproduct. - expect(File(objWrapperFile).existsSync(), isTrue); + // The generation pipeline also an obj file as a byproduct. + expect(File(objInputFile).existsSync(), isTrue); - // We also need to compile outputObjCFile to an obj file. - await run('clang', [ - '-x', - 'objective-c', - '-fobjc-arc', + final target = await hostTarget; + await run('swiftc', [ '-c', - outputObjCFile, - '-fpic', - '-o', - objObjCFile, + inputFile, + wrapperFile, + '-module-name', + name, + '-target', + target.triple, + '-sdk', + path.absolute(target.sdk.toFilePath()), ], tempDir); - expect(File(objObjCFile).existsSync(), isTrue); + + final hasOutputObjCFile = File(outputObjCFile).existsSync(); + if (hasOutputObjCFile) { + // We also need to compile outputObjCFile to an obj file. + await run('clang', [ + '-x', + 'objective-c', + '-fobjc-arc', + '-c', + outputObjCFile, + '-fpic', + '-o', + objObjCFile, + ], tempDir); + expect(File(objObjCFile).existsSync(), isTrue); + } // Link all the obj files into a dylib. await run('clang', [ '-shared', '-framework', 'Foundation', + objInputFile, objWrapperFile, - objObjCFile, + if (hasOutputObjCFile) objObjCFile, '-o', dylibFile, ], tempDir); expect(File(dylibFile).existsSync(), isTrue); + + // Expect that the bindings match. + expect(File(outputFile).readAsStringSync(), + File(actualOutputFile).readAsStringSync()); } }