From c190f26f5b47bbf1f7bb70a1334c121eafa86472 Mon Sep 17 00:00:00 2001 From: "black.dragon74" Date: Wed, 14 Oct 2020 23:55:32 +0530 Subject: [PATCH] Push initial source code Signed-off-by: black.dragon74 --- .gitignore | 35 ++ ALCPlugFix-Swift.xcodeproj/project.pbxproj | 390 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + ALCPlugFix-Swift/ALCPlugFix.swift | 81 ++++ ALCPlugFix-Swift/Command.swift | 16 + ALCPlugFix-Swift/Listener.swift | 47 +++ ALCPlugFix-Swift/Misc/alc-verb | Bin 0 -> 70256 bytes ALCPlugFix-Swift/Misc/alc_295.plist | 26 ++ .../Misc/com.black-dragon74.ALCPlugFix.plist | 25 ++ ALCPlugFix-Swift/Misc/install.sh | 79 ++++ ALCPlugFix-Swift/Models/HDAVerbModel.swift | 33 ++ .../Protocols/ListenerDelegate.swift | 13 + ALCPlugFix-Swift/Utils/Utils.swift | 41 ++ ALCPlugFix-Swift/main.swift | 42 ++ 14 files changed, 835 insertions(+) create mode 100644 .gitignore create mode 100644 ALCPlugFix-Swift.xcodeproj/project.pbxproj create mode 100644 ALCPlugFix-Swift.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 ALCPlugFix-Swift/ALCPlugFix.swift create mode 100644 ALCPlugFix-Swift/Command.swift create mode 100644 ALCPlugFix-Swift/Listener.swift create mode 100755 ALCPlugFix-Swift/Misc/alc-verb create mode 100644 ALCPlugFix-Swift/Misc/alc_295.plist create mode 100644 ALCPlugFix-Swift/Misc/com.black-dragon74.ALCPlugFix.plist create mode 100755 ALCPlugFix-Swift/Misc/install.sh create mode 100644 ALCPlugFix-Swift/Models/HDAVerbModel.swift create mode 100644 ALCPlugFix-Swift/Protocols/ListenerDelegate.swift create mode 100644 ALCPlugFix-Swift/Utils/Utils.swift create mode 100644 ALCPlugFix-Swift/main.swift diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee1da11 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +## Build generated +build/ +DerivedData +build.xcarchive + +## macOS Specific +.DS_Store + +## Various settings +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata + +## Other +*.xccheckout +*.moved-aside +*.xcuserstate +*.xcscmblueprint + +## Obj-C/Swift specific +*.hmap +*.ipa + +# CocoaPods +Pods/ + +# Carthage +Carthage/Checkouts +Carthage/Build \ No newline at end of file diff --git a/ALCPlugFix-Swift.xcodeproj/project.pbxproj b/ALCPlugFix-Swift.xcodeproj/project.pbxproj new file mode 100644 index 0000000..de7c325 --- /dev/null +++ b/ALCPlugFix-Swift.xcodeproj/project.pbxproj @@ -0,0 +1,390 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 0139EEF92537282100D42E15 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0139EEF82537282100D42E15 /* Utils.swift */; }; + 0139EEFD253728E000D42E15 /* Command.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0139EEFC253728E000D42E15 /* Command.swift */; }; + 01821FA925372B4B009C92A3 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01B1AD3225372242009C072C /* CoreAudio.framework */; }; + 01821FC125372ECB009C92A3 /* ALCPlugFix.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01821FC025372ECB009C92A3 /* ALCPlugFix.swift */; }; + 01B1AD1425370B3A009C072C /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01B1AD1325370B3A009C072C /* main.swift */; }; + 01B1AD2125370EF2009C072C /* HDAVerbModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01B1AD2025370EF2009C072C /* HDAVerbModel.swift */; }; + 01B1AD26253710E9009C072C /* ListenerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01B1AD25253710E9009C072C /* ListenerDelegate.swift */; }; + 01B1AD2A2537112F009C072C /* Listener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01B1AD292537112F009C072C /* Listener.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 01B1AD0E25370B3A009C072C /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 0139EEF82537282100D42E15 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; + 0139EEFC253728E000D42E15 /* Command.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Command.swift; sourceTree = ""; }; + 01821FC025372ECB009C92A3 /* ALCPlugFix.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ALCPlugFix.swift; sourceTree = ""; }; + 01A752D125374D1700A7A109 /* install.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = install.sh; sourceTree = ""; }; + 01A752DA2537680E00A7A109 /* alc_295.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = alc_295.plist; sourceTree = ""; }; + 01A752DB2537694300A7A109 /* com.black-dragon74.ALCPlugFix.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "com.black-dragon74.ALCPlugFix.plist"; sourceTree = ""; }; + 01A752DC2537718B00A7A109 /* alc-verb */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = "alc-verb"; sourceTree = ""; }; + 01B1AD1025370B3A009C072C /* ALCPlugFix-Swift */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "ALCPlugFix-Swift"; sourceTree = BUILT_PRODUCTS_DIR; }; + 01B1AD1325370B3A009C072C /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; + 01B1AD2025370EF2009C072C /* HDAVerbModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HDAVerbModel.swift; sourceTree = ""; }; + 01B1AD25253710E9009C072C /* ListenerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListenerDelegate.swift; sourceTree = ""; }; + 01B1AD292537112F009C072C /* Listener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Listener.swift; sourceTree = ""; }; + 01B1AD3225372242009C072C /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 01B1AD0D25370B3A009C072C /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 01821FA925372B4B009C92A3 /* CoreAudio.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 0139EEF7253727E800D42E15 /* Utils */ = { + isa = PBXGroup; + children = ( + 0139EEF82537282100D42E15 /* Utils.swift */, + ); + path = Utils; + sourceTree = ""; + }; + 01A752D025374CF100A7A109 /* Misc */ = { + isa = PBXGroup; + children = ( + 01A752DC2537718B00A7A109 /* alc-verb */, + 01A752DB2537694300A7A109 /* com.black-dragon74.ALCPlugFix.plist */, + 01A752DA2537680E00A7A109 /* alc_295.plist */, + 01A752D125374D1700A7A109 /* install.sh */, + ); + path = Misc; + sourceTree = ""; + }; + 01B1AD0725370B3A009C072C = { + isa = PBXGroup; + children = ( + 01B1AD1225370B3A009C072C /* ALCPlugFix-Swift */, + 01B1AD1125370B3A009C072C /* Products */, + 01B1AD3125372242009C072C /* Frameworks */, + ); + sourceTree = ""; + }; + 01B1AD1125370B3A009C072C /* Products */ = { + isa = PBXGroup; + children = ( + 01B1AD1025370B3A009C072C /* ALCPlugFix-Swift */, + ); + name = Products; + sourceTree = ""; + }; + 01B1AD1225370B3A009C072C /* ALCPlugFix-Swift */ = { + isa = PBXGroup; + children = ( + 01A752D025374CF100A7A109 /* Misc */, + 0139EEF7253727E800D42E15 /* Utils */, + 01B1AD24253710B9009C072C /* Protocols */, + 01B1AD1C25370B88009C072C /* Models */, + 01B1AD1325370B3A009C072C /* main.swift */, + 0139EEFC253728E000D42E15 /* Command.swift */, + 01B1AD292537112F009C072C /* Listener.swift */, + 01821FC025372ECB009C92A3 /* ALCPlugFix.swift */, + ); + path = "ALCPlugFix-Swift"; + sourceTree = ""; + }; + 01B1AD1C25370B88009C072C /* Models */ = { + isa = PBXGroup; + children = ( + 01B1AD2025370EF2009C072C /* HDAVerbModel.swift */, + ); + path = Models; + sourceTree = ""; + }; + 01B1AD24253710B9009C072C /* Protocols */ = { + isa = PBXGroup; + children = ( + 01B1AD25253710E9009C072C /* ListenerDelegate.swift */, + ); + path = Protocols; + sourceTree = ""; + }; + 01B1AD3125372242009C072C /* Frameworks */ = { + isa = PBXGroup; + children = ( + 01B1AD3225372242009C072C /* CoreAudio.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 01B1AD0F25370B3A009C072C /* ALCPlugFix-Swift */ = { + isa = PBXNativeTarget; + buildConfigurationList = 01B1AD1725370B3A009C072C /* Build configuration list for PBXNativeTarget "ALCPlugFix-Swift" */; + buildPhases = ( + 01B1AD0C25370B3A009C072C /* Sources */, + 01B1AD0D25370B3A009C072C /* Frameworks */, + 01B1AD0E25370B3A009C072C /* CopyFiles */, + 01A752DD2537737B00A7A109 /* Archive */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "ALCPlugFix-Swift"; + productName = "ALCPlugFix-Swift"; + productReference = 01B1AD1025370B3A009C072C /* ALCPlugFix-Swift */; + productType = "com.apple.product-type.tool"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 01B1AD0825370B3A009C072C /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 1200; + LastUpgradeCheck = 1200; + TargetAttributes = { + 01B1AD0F25370B3A009C072C = { + CreatedOnToolsVersion = 12.0.1; + }; + }; + }; + buildConfigurationList = 01B1AD0B25370B3A009C072C /* Build configuration list for PBXProject "ALCPlugFix-Swift" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 01B1AD0725370B3A009C072C; + productRefGroup = 01B1AD1125370B3A009C072C /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 01B1AD0F25370B3A009C072C /* ALCPlugFix-Swift */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXShellScriptBuildPhase section */ + 01A752DD2537737B00A7A109 /* Archive */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = Archive; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "cd \"${PROJECT_DIR}/${PROJECT_NAME}/Misc/\"\ncp alc-verb \"${TARGET_BUILD_DIR}\"\ncp install.sh \"${TARGET_BUILD_DIR}\"\ncp com.black-dragon74.ALCPlugFix.plist \"${TARGET_BUILD_DIR}\"\n\ncd \"${TARGET_BUILD_DIR}\"\n\ndist=(\"${FULL_PRODUCT_NAME}\")\ndist+=(\"alc-verb\")\ndist+=(\"install.sh\")\ndist+=(\"com.black-dragon74.ALCPlugFix.plist\")\n\narchive=\"${PRODUCT_NAME}-$(echo $CONFIGURATION | tr /a-z/ /A-Z/).zip\"\nrm -rf *.zip\nif [ \"$CONFIGURATION\" == \"Release\" ]; then\n strip -x -T \"${EXECUTABLE_PATH}\" &>/dev/null || strip -x \"${EXECUTABLE_PATH}\"\nfi\nzip -qry -FS \"${archive}\" \"${dist[@]}\"\n"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 01B1AD0C25370B3A009C072C /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 0139EEFD253728E000D42E15 /* Command.swift in Sources */, + 0139EEF92537282100D42E15 /* Utils.swift in Sources */, + 01B1AD2125370EF2009C072C /* HDAVerbModel.swift in Sources */, + 01B1AD1425370B3A009C072C /* main.swift in Sources */, + 01B1AD26253710E9009C072C /* ListenerDelegate.swift in Sources */, + 01821FC125372ECB009C92A3 /* ALCPlugFix.swift in Sources */, + 01B1AD2A2537112F009C072C /* Listener.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 01B1AD1525370B3A009C072C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 01B1AD1625370B3A009C072C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.15; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 01B1AD1825370B3A009C072C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_STYLE = Manual; + DEVELOPMENT_TEAM = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 01B1AD1925370B3A009C072C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_STYLE = Manual; + DEVELOPMENT_TEAM = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 01B1AD0B25370B3A009C072C /* Build configuration list for PBXProject "ALCPlugFix-Swift" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 01B1AD1525370B3A009C072C /* Debug */, + 01B1AD1625370B3A009C072C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 01B1AD1725370B3A009C072C /* Build configuration list for PBXNativeTarget "ALCPlugFix-Swift" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 01B1AD1825370B3A009C072C /* Debug */, + 01B1AD1925370B3A009C072C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 01B1AD0825370B3A009C072C /* Project object */; +} diff --git a/ALCPlugFix-Swift.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/ALCPlugFix-Swift.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/ALCPlugFix-Swift.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/ALCPlugFix-Swift/ALCPlugFix.swift b/ALCPlugFix-Swift/ALCPlugFix.swift new file mode 100644 index 0000000..a660f8a --- /dev/null +++ b/ALCPlugFix-Swift/ALCPlugFix.swift @@ -0,0 +1,81 @@ +// +// ALCPlugFix.swift +// ALCPlugFix-Swift +// +// Created by Nick on 10/14/20. +// + +import Foundation +import NotificationCenter + +class ALCPlugFix { + private let listener = Listener() + private let alcVerbPath = "/usr/local/bin/alc-verb" + private let hdaVerbs: [HDAVerbModel] + + init(withPlistFile plist: URL) throws { + hdaVerbs = try Command.getCommands(fromPlistFile: plist) + } + + func start() { + // If there are verbs to be sent on boot, now is the time + processOnBootVerbs() + + // Declare ourselves as the delegate and listen + listener.delegate = self + listener.listen() + + // Register ourselves as wake observer + NotificationCenter.default.addObserver(self, selector: #selector(handleWake(_:)), name: NSWorkspace.didWakeNotification, object: nil) + } + + private func processOnBootVerbs() { + print("ALCPlugFix::machineDidBoot") + hdaVerbs.filter { + $0.onBoot && $0.enabled + }.forEach { + sendHDAVerb($0) + } + } + + private func sendHDAVerb(_ command: HDAVerbModel) { + // Otherwise, execute the commands + print("Executing command labelled: \(command.comment ?? "No Description")") + runShellCommand(alcVerbPath, args: [command.nodeID, command.verb, command.param]) + } + + // MARK: - Notification handlers + + @objc private func handleWake(_ notification: NSNotification) { + print("ALCPlugFix::machineDidWake") + hdaVerbs.filter { + $0.onWake && $0.enabled + }.forEach { + sendHDAVerb($0) + } + } +} + +// MARK: - Listener delegate + +extension ALCPlugFix: ListenerDelegate { + func headphoneDidConnect() { + print("ALCPlugFix::headphoneDidConnect") + // Only if the command is supposed to be executed on connect and is enabled + hdaVerbs.filter { + $0.onConnect && $0.enabled + }.forEach { + sendHDAVerb($0) + } + } + + func headphoneDidDisconnect() { + print("ALCPlugFix::headphoneDidDisconnect") + // Only if the command is supposed to be executed on disconnect + hdaVerbs.filter { + $0.onDisconnect && $0.enabled + }.forEach { + sendHDAVerb($0) + } + } +} diff --git a/ALCPlugFix-Swift/Command.swift b/ALCPlugFix-Swift/Command.swift new file mode 100644 index 0000000..f5aceeb --- /dev/null +++ b/ALCPlugFix-Swift/Command.swift @@ -0,0 +1,16 @@ +// +// Command.swift +// ALCPlugFix-Swift +// +// Created by Nick on 10/14/20. +// + +import Foundation + +class Command { + static func getCommands(fromPlistFile plist: URL) throws -> [HDAVerbModel] { + let data = try Data(contentsOf: plist) + let decoder = PropertyListDecoder() + return try decoder.decode([HDAVerbModel].self, from: data) + } +} diff --git a/ALCPlugFix-Swift/Listener.swift b/ALCPlugFix-Swift/Listener.swift new file mode 100644 index 0000000..4aca7c2 --- /dev/null +++ b/ALCPlugFix-Swift/Listener.swift @@ -0,0 +1,47 @@ +// +// Listener.swift +// ALCPlugFix-Swift +// +// Created by Nick on 10/14/20. +// Adapted from ALCPlugFix (main.m) +// + +import CoreAudio +import Foundation + +class Listener { + private var defaultDevice: AudioDeviceID = 0 + private var dataSourceID: UInt32 = 0 + + private var defaultSize = UInt32(MemoryLayout.size) + private var dataSourceSize = UInt32(MemoryLayout.size) + + private var defaultAddress = AudioObjectPropertyAddress(mSelector: kAudioHardwarePropertyDefaultOutputDevice, mScope: kAudioObjectPropertyScopeGlobal, mElement: kAudioObjectPropertyElementMaster) + private var sourceAddress = AudioObjectPropertyAddress(mSelector: kAudioDevicePropertyDataSource, mScope: kAudioDevicePropertyScopeOutput, mElement: kAudioObjectPropertyElementMaster) + + var delegate: ListenerDelegate? + + init() { + AudioObjectGetPropertyData(AudioObjectID(kAudioObjectSystemObject), &defaultAddress, 0, nil, &defaultSize, &defaultDevice) + } + + func listen() { + AudioObjectAddPropertyListenerBlock(defaultDevice, &sourceAddress, .main, propertyListenerBlock) + } + + // Listener as per CoreAudio:136 + func propertyListenerBlock(inNumberAddresses: UInt32, inAddresses: UnsafePointer) { + AudioObjectGetPropertyData(defaultDevice, inAddresses, 0, nil, &dataSourceSize, &dataSourceID) + + // 1751412846 is for Headphones + // 1769173099 is for speakers + // print(dataSourceID) + if dataSourceID == 1751412846 { + delegate?.headphoneDidConnect() + } + + if dataSourceID == 1769173099 { + delegate?.headphoneDidDisconnect() + } + } +} diff --git a/ALCPlugFix-Swift/Misc/alc-verb b/ALCPlugFix-Swift/Misc/alc-verb new file mode 100755 index 0000000000000000000000000000000000000000..54476b906ece3ebe2af2793b758944fe188466c6 GIT binary patch literal 70256 zcmeI5dvsgHoyW({1IHwh0}XkQ5D_pW1Y0)bVL}ojTS_D%+rpAV2!x9)UB`-LNk~_* zT^=z>%tkA`C$!xj;P7mh?v}PJOF6tBW)lc>+2yemC>tQl^03L0atefyP`uyY+>tCP zq4bp%{Pl4{l#CHVlp>yhI5Nre_0_m}4*1V1tefd(;l18d6nJX&xcheHnU%P6N)meiw@&$*yB@O8bo>tyKl0rfrPn zE$cV>!*ZHorD>m)H2o=Aft1EIglLW{ucEJLT+lMCG?VPOvUAq7NI*;WcD2PKTHHu{ zqrV-dxuD%eKC*$f;k2wks%fEs5g08f9^cMBbA0!yO-s69|Bjl<-01!3aW}1TI@~6G z+{9|0u$N)bOyVtOO57=C!(5D9vK=(nqXKDPwi4-1Xcr9Lcv=W6H1U~^DE?Upvb*yc zA>t@J9(ga7BTzj>>W9Xe&jGS9zTO{0O3-v}q&=gKaq&~*4 zobvU+`t$cbbo*6zH+7A9_#Bj35vgxsDHr1rDQ~V#p!6){E2vHd^xa2(=)A}e)NdUk z)zO?wLM1qkN=C?SwcH-NVjoZ1aTM5`jdoZB-)B zrFX{?ok^R!c}>`;ZqF9j*6N95I2K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xAMaIKU(%rCtf}M{-upm-s-a5IR9DSy(fL}w|CFGIY5WYUleZYweD>Cg+4je zbHlg`@4T<2X;a@*duIN$>d-4oem1S)%j>_*d0XV>#}>pcd*Y$py`SDb`LQKeY`Oi0 zU)}M-o#!lBP_ppM3B$kI^2__z#hx8*9~}Go%P)79Hm@5ua`gjOf4~3DCo-<|*?<3S z^$-5x>4EF6-ameGY4yxh)yoU zp?wv54qWqMD7F5Nzj=9M)f;ccmc4%CvOVSBb^kjK9J=_YttV$9Th6@kw5z86XFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCcp%k025#W zOn?b60Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCcp%k025#W cOn?b60Vco%m;e)C0!)AjFaaj;|Bt}`01;yT_y7O^ literal 0 HcmV?d00001 diff --git a/ALCPlugFix-Swift/Misc/alc_295.plist b/ALCPlugFix-Swift/Misc/alc_295.plist new file mode 100644 index 0000000..f4e0896 --- /dev/null +++ b/ALCPlugFix-Swift/Misc/alc_295.plist @@ -0,0 +1,26 @@ + + + + + + Comment + Enable combo jack mic detection + Enabled + + Node ID + 0x19 + On Boot + + On Connect + + On Disconnect + + On Wake + + Param + 0x20 + Verb + SET_PIN_WIDGET_CONTROL + + + diff --git a/ALCPlugFix-Swift/Misc/com.black-dragon74.ALCPlugFix.plist b/ALCPlugFix-Swift/Misc/com.black-dragon74.ALCPlugFix.plist new file mode 100644 index 0000000..0a71f8a --- /dev/null +++ b/ALCPlugFix-Swift/Misc/com.black-dragon74.ALCPlugFix.plist @@ -0,0 +1,25 @@ + + + + + Debug + + KeepAlive + + Label + com.black-dragon74.ALCPlugFix + ProgramArguments + + /usr/local/bin/ALCPlugFix + REPLACE_ME + + RunAtLoad + + ServiceIPC + + StandardErrorPath + /var/log/alcplugfix_stderr.log + StandardOutPath + /var/log/alcplugfix_stdout.log + + diff --git a/ALCPlugFix-Swift/Misc/install.sh b/ALCPlugFix-Swift/Misc/install.sh new file mode 100755 index 0000000..0a8a6c6 --- /dev/null +++ b/ALCPlugFix-Swift/Misc/install.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +# install.sh +# ALCPlugFix-Swift +# +# Created by Nick on 10/14/20. +# + +# Get hold of actual directory +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" +pledit=/usr/libexec/PlistBuddy + +# Clean up old installs +function cleanUpOldInstall() { + # Remove codec commander based ALCPlugFix + sudo launchctl unload /Library/LaunchAgents/good.win.ALCPlugFix.plist + sudo rm -rf /Library/LaunchAgents/good.win.ALCPlugFix.plist + + # Remove any existing alc-verb install + sudo launchctl unload /Library/LaunchAgents/com.black-dragon74.ALCPlugFix.plist + sudo rm -rf /Library/LaunchAgents/com.black-dragon74.ALCPlugFix.plist + + # Clean up old clients + sudo rm -rf $(which alc-verb) + sudo rm -rf $(which hda-verb) +} + +# Function that exits with an error code and message +function abort() { + echo $1 + exit 1 +} + +echo "** **" +echo "** Installing ALCPlugFix (AppleALC variant) **" +echo "** **" + +echo "" +read -p "Please drag your config file to the terminal: " inputFile + +# Verify the input file +if [[ ! -z $inputFile && -f $inputFile ]]; # If input exists and is of type 'file' +then + # Verify if it is a correct PLIST file + if /usr/bin/plutil "$inputFile" | grep -q "OK"; + then + # Plist is valid, write the inputfile path to it + $pledit -c "Set ProgramArguments:1 $inputFile" ./com.black-dragon74.ALCPlugFix.plist || abort "Failed to write to launchd plist" + else + abort "The provided file is not a valid plist" + fi +else + abort "Invalid input." +fi +echo "" + +echo "** Removing old installs **" +cleanUpOldInstall 2>/dev/null + +echo "** Copying new files **" +sudo cp "$DIR/ALCPlugFix-Swift" /usr/local/bin/ALCPlugFix || abort "Failed to copy ALCPlugFix" +sudo cp "$DIR/alc-verb" /usr/local/bin || abort "Failed to copy alc-verb" +sudo cp "$DIR/com.black-dragon74.ALCPlugFix.plist" /Library/LaunchAgents || abort "Failed to copy launchd plist file" + +echo "** Setting permissions **" +sudo chmod 755 /usr/local/bin/ALCPlugFix +sudo chmod 755 /usr/local/bin/alc-verb +sudo chmod 644 /Library/LaunchAgents/com.black-dragon74.ALCPlugFix.plist + +sudo chown root:wheel /usr/local/bin/ALCPlugFix +sudo chown root:wheel /usr/local/bin/alc-verb +sudo chown root:wheel /Library/LaunchAgents/com.black-dragon74.ALCPlugFix.plist + +echo "** Loading launch daemon **" +sudo launchctl load /Library/LaunchAgents/com.black-dragon74.ALCPlugFix.plist + +echo "** **" +echo "** All done. Enjoy! **" +echo "** **" diff --git a/ALCPlugFix-Swift/Models/HDAVerbModel.swift b/ALCPlugFix-Swift/Models/HDAVerbModel.swift new file mode 100644 index 0000000..270740f --- /dev/null +++ b/ALCPlugFix-Swift/Models/HDAVerbModel.swift @@ -0,0 +1,33 @@ +// +// HDAVerbModel.swift +// ALCPlugFix-Swift +// +// Created by Nick on 10/14/20. +// + +import Foundation + +struct HDAVerbModel: Codable { + let enabled: Bool // Whether the command is supposed to be executed or not, overrides all conditions + let comment: String? // Human readable description of the command + let nodeID: String // Node id of the codec + let verb: String // Verb selector (see hdaverb.h) + let param: String // The command for the node + let onBoot: Bool // Send verb on boot (at lauchd load actually) + let onWake: Bool // Send verb when machine wakes from sleep + let onConnect: Bool // Send verb on headphone plug in + let onDisconnect: Bool // Send verb on headphone plug out + + // For easy decoding + enum CodingKeys: String, CodingKey { + case enabled = "Enabled" + case comment = "Comment" + case nodeID = "Node ID" + case verb = "Verb" + case param = "Param" + case onBoot = "On Boot" + case onWake = "On Wake" + case onConnect = "On Connect" + case onDisconnect = "On Disconnect" + } +} diff --git a/ALCPlugFix-Swift/Protocols/ListenerDelegate.swift b/ALCPlugFix-Swift/Protocols/ListenerDelegate.swift new file mode 100644 index 0000000..856286e --- /dev/null +++ b/ALCPlugFix-Swift/Protocols/ListenerDelegate.swift @@ -0,0 +1,13 @@ +// +// ListenerDelegate.swift +// ALCPlugFix-Swift +// +// Created by Nick on 10/14/20. +// + +import Foundation + +protocol ListenerDelegate: class { + func headphoneDidConnect() + func headphoneDidDisconnect() +} diff --git a/ALCPlugFix-Swift/Utils/Utils.swift b/ALCPlugFix-Swift/Utils/Utils.swift new file mode 100644 index 0000000..5783a6e --- /dev/null +++ b/ALCPlugFix-Swift/Utils/Utils.swift @@ -0,0 +1,41 @@ +// +// Utils.swift +// ALCPlugFix-Swift +// +// Created by Nick on 10/14/20. +// + +import Foundation + +@discardableResult +func runShellCommand(_ command: String, args: [String]) -> String? { + #if DEBUG + print("Running: \(command) with args: \(args)") + #endif + + let task = Process() + task.executableURL = URL(fileURLWithPath: command) + task.arguments = args + + let pipe = Pipe() + task.standardOutput = pipe + task.standardError = pipe + + do { + try task.run() + } + catch let ex { + return ex.localizedDescription + } + + let data = pipe.fileHandleForReading.readDataToEndOfFile() + let output = String(data: data, encoding: .utf8) + + #if DEBUG + print("Output: \(output ?? "")") + #endif + + task.waitUntilExit() + + return output?.trimmingCharacters(in: .whitespacesAndNewlines) +} diff --git a/ALCPlugFix-Swift/main.swift b/ALCPlugFix-Swift/main.swift new file mode 100644 index 0000000..c0d23e3 --- /dev/null +++ b/ALCPlugFix-Swift/main.swift @@ -0,0 +1,42 @@ +// +// main.swift +// ALCPlugFix-Swift +// +// Created by Nick on 10/14/20. +// + +import Foundation + +private func printHelp() { + let help = """ + ALCPlugFix for alc-verb (adapted from ALCPlugFix) + usage: alc-verb [alc_xxx.plist] + alc_xxx.plist is a PLIST file containing custom HDA Verb commands + """ + + print(help) +} + +private func lockAndLoad() { + for (index, _) in CommandLine.arguments.enumerated() { + if CommandLine.arguments.indices.contains(index + 1) { + let plistFile = CommandLine.arguments[index + 1] + print(plistFile) + do { + try ALCPlugFix(withPlistFile: URL(fileURLWithPath: plistFile)).start() + + // Run forever + RunLoop.current.run() + } catch let ex { + print("Exception in initializing ALCPlugFix\n\(ex.localizedDescription)") + exit(1) + } + } + break + } + + // Either the program will keep running or exit, if not, invalid args, print help + printHelp() +} + +lockAndLoad()