Compare commits
44 Commits
c677e124f4
..
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 5040ea1518 | |||
| 21b9123a87 | |||
| 24ce4564e8 | |||
| b1303a25ae | |||
| 21fda7067d | |||
| 8c601e2029 | |||
| 5a07a6d4b4 | |||
| 475dd392e6 | |||
| dff58175f1 | |||
| 42268b65a1 | |||
| 2c36de5c0d | |||
| f19dc2c1b3 | |||
| 6ad813601f | |||
| 652a5a76ca | |||
| 9b31be7921 | |||
| 705b4ed534 | |||
| 4627b3b800 | |||
| c25d783b71 | |||
| b4b2f58762 | |||
| c0605d295d | |||
| cdac587454 | |||
| 69f50b2037 | |||
| b08ce4d999 | |||
| 372494aae4 | |||
| 37ec8cd331 | |||
| 9ebcbd4027 | |||
| 77156e696b | |||
| 46e075fb8c | |||
| ed27ab166c | |||
| c6f567535b | |||
| e36dc3a527 | |||
| 5633ede630 | |||
| c491f97440 | |||
| 499ab1310e | |||
| 9b7c5246ec | |||
| 1a09cf9cf8 | |||
| d8142c9d7d | |||
| 8ffc1caa42 | |||
| 6c1859c59d | |||
| 35971d4acc | |||
| d41ba37093 | |||
| e1ec98413d | |||
| 0960d4e7c5 | |||
| 2ba57cadd6 |
@@ -18,3 +18,4 @@ DerivedData/
|
|||||||
*.swiftmodule
|
*.swiftmodule
|
||||||
|
|
||||||
# Note: Package.resolved is intentionally tracked to pin the Lyrebird dependency.
|
# Note: Package.resolved is intentionally tracked to pin the Lyrebird dependency.
|
||||||
|
icon-source.png
|
||||||
|
|||||||
@@ -0,0 +1,399 @@
|
|||||||
|
// !$*UTF8*$!
|
||||||
|
{
|
||||||
|
archiveVersion = 1;
|
||||||
|
classes = {
|
||||||
|
};
|
||||||
|
objectVersion = 60;
|
||||||
|
objects = {
|
||||||
|
|
||||||
|
/* Begin PBXBuildFile section */
|
||||||
|
C3B100000000000000000020 /* LyrebirdShoeGaze in Frameworks */ = {isa = PBXBuildFile; productRef = C3B10000000000000000001E /* LyrebirdShoeGaze */; };
|
||||||
|
C3B100000000000000000021 /* LyrebirdShoeGazeUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3B10000000000000000001F /* LyrebirdShoeGazeUI */; };
|
||||||
|
C3B100000000000000000022 /* Lyrebird in Frameworks */ = {isa = PBXBuildFile; productRef = C3B100000000000000000023 /* Lyrebird */; };
|
||||||
|
C3B100000000000000000024 /* LyrebirdUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3B100000000000000000025 /* LyrebirdUI */; };
|
||||||
|
C3B100000000000000000031 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C3B100000000000000000030 /* Assets.xcassets */; };
|
||||||
|
C3B1000000000000000000C /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B100000000000000000007 /* main.swift */; };
|
||||||
|
C3B1000000000000000000D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B100000000000000000008 /* AppDelegate.swift */; };
|
||||||
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
|
/* Begin PBXFileReference section */
|
||||||
|
C3B100000000000000000004 /* ShoeGazeBuilder.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ShoeGazeBuilder.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
|
C3B100000000000000000006 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
|
C3B100000000000000000007 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
||||||
|
C3B100000000000000000008 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||||
|
C3B100000000000000000030 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||||
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
C3B100000000000000000012 /* Frameworks */ = {
|
||||||
|
isa = PBXFrameworksBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
C3B100000000000000000020 /* LyrebirdShoeGaze in Frameworks */,
|
||||||
|
C3B100000000000000000021 /* LyrebirdShoeGazeUI in Frameworks */,
|
||||||
|
C3B100000000000000000022 /* Lyrebird in Frameworks */,
|
||||||
|
C3B100000000000000000024 /* LyrebirdUI in Frameworks */,
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXFrameworksBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXGroup section */
|
||||||
|
C3B100000000000000000002 = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
C3B100000000000000000005 /* ShoeGazeBuilder */,
|
||||||
|
C3B100000000000000000003 /* Products */,
|
||||||
|
);
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
C3B100000000000000000003 /* Products */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
C3B100000000000000000004 /* ShoeGazeBuilder.app */,
|
||||||
|
);
|
||||||
|
name = Products;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
C3B100000000000000000005 /* ShoeGazeBuilder */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
C3B100000000000000000007 /* main.swift */,
|
||||||
|
C3B100000000000000000008 /* AppDelegate.swift */,
|
||||||
|
C3B100000000000000000030 /* Assets.xcassets */,
|
||||||
|
C3B100000000000000000006 /* Info.plist */,
|
||||||
|
);
|
||||||
|
path = ShoeGazeBuilder;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
/* End PBXGroup section */
|
||||||
|
|
||||||
|
/* Begin PBXNativeTarget section */
|
||||||
|
C3B100000000000000000014 /* ShoeGazeBuilder */ = {
|
||||||
|
isa = PBXNativeTarget;
|
||||||
|
buildConfigurationList = C3B100000000000000000015 /* Build configuration list for PBXNativeTarget "ShoeGazeBuilder" */;
|
||||||
|
buildPhases = (
|
||||||
|
C3B100000000000000000011 /* Sources */,
|
||||||
|
C3B100000000000000000012 /* Frameworks */,
|
||||||
|
C3B100000000000000000013 /* Resources */,
|
||||||
|
);
|
||||||
|
buildRules = (
|
||||||
|
);
|
||||||
|
dependencies = (
|
||||||
|
);
|
||||||
|
name = ShoeGazeBuilder;
|
||||||
|
packageProductDependencies = (
|
||||||
|
C3B10000000000000000001E /* LyrebirdShoeGaze */,
|
||||||
|
C3B10000000000000000001F /* LyrebirdShoeGazeUI */,
|
||||||
|
C3B100000000000000000023 /* Lyrebird */,
|
||||||
|
C3B100000000000000000025 /* LyrebirdUI */,
|
||||||
|
);
|
||||||
|
productName = ShoeGazeBuilder;
|
||||||
|
productReference = C3B100000000000000000004 /* ShoeGazeBuilder.app */;
|
||||||
|
productType = "com.apple.product-type.application";
|
||||||
|
};
|
||||||
|
/* End PBXNativeTarget section */
|
||||||
|
|
||||||
|
/* Begin PBXProject section */
|
||||||
|
C3B100000000000000000001 /* Project object */ = {
|
||||||
|
isa = PBXProject;
|
||||||
|
attributes = {
|
||||||
|
BuildIndependentTargetsInParallel = 1;
|
||||||
|
LastSwiftUpdateCheck = 1600;
|
||||||
|
LastUpgradeCheck = 2620;
|
||||||
|
TargetAttributes = {
|
||||||
|
C3B100000000000000000014 = {
|
||||||
|
CreatedOnToolsVersion = 16.0;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
buildConfigurationList = C3B100000000000000000018 /* Build configuration list for PBXProject "ShoeGazeBuilder" */;
|
||||||
|
compatibilityVersion = "Xcode 14.0";
|
||||||
|
developmentRegion = en;
|
||||||
|
hasScannedForEncodings = 0;
|
||||||
|
knownRegions = (
|
||||||
|
en,
|
||||||
|
Base,
|
||||||
|
);
|
||||||
|
mainGroup = C3B100000000000000000002;
|
||||||
|
packageReferences = (
|
||||||
|
C3B10000000000000000001B /* XCLocalSwiftPackageReference ".." */,
|
||||||
|
C3B10000000000000000001C /* XCRemoteSwiftPackageReference "Lyrebird" */,
|
||||||
|
);
|
||||||
|
productRefGroup = C3B100000000000000000003 /* Products */;
|
||||||
|
projectDirPath = "";
|
||||||
|
projectRoot = "";
|
||||||
|
targets = (
|
||||||
|
C3B100000000000000000014 /* ShoeGazeBuilder */,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
/* End PBXProject section */
|
||||||
|
|
||||||
|
/* Begin PBXResourcesBuildPhase section */
|
||||||
|
C3B100000000000000000013 /* Resources */ = {
|
||||||
|
isa = PBXResourcesBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
C3B100000000000000000031 /* Assets.xcassets in Resources */,
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXResourcesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXSourcesBuildPhase section */
|
||||||
|
C3B100000000000000000011 /* Sources */ = {
|
||||||
|
isa = PBXSourcesBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
C3B1000000000000000000C /* main.swift in Sources */,
|
||||||
|
C3B1000000000000000000D /* AppDelegate.swift in Sources */,
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXSourcesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin XCBuildConfiguration section */
|
||||||
|
C3B100000000000000000016 /* Debug */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
|
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
|
||||||
|
CODE_SIGNING_REQUIRED = NO;
|
||||||
|
CODE_SIGN_ENTITLEMENTS = ShoeGazeBuilder/ShoeGazeBuilder.entitlements;
|
||||||
|
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||||
|
CODE_SIGN_STYLE = Automatic;
|
||||||
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
|
CURRENT_PROJECT_VERSION = 2;
|
||||||
|
DEAD_CODE_STRIPPING = YES;
|
||||||
|
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||||
|
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||||
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
|
INFOPLIST_FILE = ShoeGazeBuilder/Info.plist;
|
||||||
|
INFOPLIST_KEY_CFBundleDisplayName = ShoeGaze;
|
||||||
|
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
|
||||||
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
|
"$(inherited)",
|
||||||
|
"@executable_path/../Frameworks",
|
||||||
|
);
|
||||||
|
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
||||||
|
MARKETING_VERSION = 0.91;
|
||||||
|
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder;
|
||||||
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
|
SWIFT_VERSION = 5.0;
|
||||||
|
};
|
||||||
|
name = Debug;
|
||||||
|
};
|
||||||
|
C3B100000000000000000017 /* Release */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
|
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES;
|
||||||
|
CODE_SIGNING_REQUIRED = NO;
|
||||||
|
CODE_SIGN_ENTITLEMENTS = ShoeGazeBuilder/ShoeGazeBuilder.entitlements;
|
||||||
|
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||||
|
CODE_SIGN_STYLE = Automatic;
|
||||||
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
|
CURRENT_PROJECT_VERSION = 2;
|
||||||
|
DEAD_CODE_STRIPPING = YES;
|
||||||
|
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||||
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
|
INFOPLIST_FILE = ShoeGazeBuilder/Info.plist;
|
||||||
|
INFOPLIST_KEY_CFBundleDisplayName = ShoeGaze;
|
||||||
|
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
|
||||||
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
|
"$(inherited)",
|
||||||
|
"@executable_path/../Frameworks",
|
||||||
|
);
|
||||||
|
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
||||||
|
MARKETING_VERSION = 0.91;
|
||||||
|
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder;
|
||||||
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
|
SWIFT_VERSION = 5.0;
|
||||||
|
};
|
||||||
|
name = Release;
|
||||||
|
};
|
||||||
|
C3B100000000000000000019 /* 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++20";
|
||||||
|
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;
|
||||||
|
DEAD_CODE_STRIPPING = YES;
|
||||||
|
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||||
|
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||||
|
ENABLE_TESTABILITY = YES;
|
||||||
|
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||||
|
GCC_C_LANGUAGE_STANDARD = gnu17;
|
||||||
|
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;
|
||||||
|
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||||
|
MTL_FAST_MATH = YES;
|
||||||
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
|
SDKROOT = macosx;
|
||||||
|
STRING_CATALOG_GENERATE_SYMBOLS = YES;
|
||||||
|
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||||
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
|
};
|
||||||
|
name = Debug;
|
||||||
|
};
|
||||||
|
C3B10000000000000000001A /* 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++20";
|
||||||
|
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;
|
||||||
|
DEAD_CODE_STRIPPING = YES;
|
||||||
|
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||||
|
ENABLE_NS_ASSERTIONS = NO;
|
||||||
|
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||||
|
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||||
|
GCC_C_LANGUAGE_STANDARD = gnu17;
|
||||||
|
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;
|
||||||
|
MTL_ENABLE_DEBUG_INFO = NO;
|
||||||
|
MTL_FAST_MATH = YES;
|
||||||
|
SDKROOT = macosx;
|
||||||
|
STRING_CATALOG_GENERATE_SYMBOLS = YES;
|
||||||
|
SWIFT_COMPILATION_MODE = wholemodule;
|
||||||
|
SWIFT_OPTIMIZATION_LEVEL = "-O";
|
||||||
|
};
|
||||||
|
name = Release;
|
||||||
|
};
|
||||||
|
/* End XCBuildConfiguration section */
|
||||||
|
|
||||||
|
/* Begin XCConfigurationList section */
|
||||||
|
C3B100000000000000000015 /* Build configuration list for PBXNativeTarget "ShoeGazeBuilder" */ = {
|
||||||
|
isa = XCConfigurationList;
|
||||||
|
buildConfigurations = (
|
||||||
|
C3B100000000000000000016 /* Debug */,
|
||||||
|
C3B100000000000000000017 /* Release */,
|
||||||
|
);
|
||||||
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
|
};
|
||||||
|
C3B100000000000000000018 /* Build configuration list for PBXProject "ShoeGazeBuilder" */ = {
|
||||||
|
isa = XCConfigurationList;
|
||||||
|
buildConfigurations = (
|
||||||
|
C3B100000000000000000019 /* Debug */,
|
||||||
|
C3B10000000000000000001A /* Release */,
|
||||||
|
);
|
||||||
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
|
};
|
||||||
|
/* End XCConfigurationList section */
|
||||||
|
|
||||||
|
/* Begin XCLocalSwiftPackageReference section */
|
||||||
|
C3B10000000000000000001B /* XCLocalSwiftPackageReference ".." */ = {
|
||||||
|
isa = XCLocalSwiftPackageReference;
|
||||||
|
relativePath = ..;
|
||||||
|
};
|
||||||
|
/* End XCLocalSwiftPackageReference section */
|
||||||
|
|
||||||
|
/* Begin XCRemoteSwiftPackageReference section */
|
||||||
|
C3B10000000000000000001C /* XCRemoteSwiftPackageReference "Lyrebird" */ = {
|
||||||
|
isa = XCRemoteSwiftPackageReference;
|
||||||
|
repositoryURL = "https://realizedsound.mooo.com/josh/Lyrebird";
|
||||||
|
requirement = {
|
||||||
|
kind = upToNextMajorVersion;
|
||||||
|
minimumVersion = 1.2.0;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/* End XCRemoteSwiftPackageReference section */
|
||||||
|
|
||||||
|
/* Begin XCSwiftPackageProductDependency section */
|
||||||
|
C3B10000000000000000001E /* LyrebirdShoeGaze */ = {
|
||||||
|
isa = XCSwiftPackageProductDependency;
|
||||||
|
package = C3B10000000000000000001B /* XCLocalSwiftPackageReference ".." */;
|
||||||
|
productName = LyrebirdShoeGaze;
|
||||||
|
};
|
||||||
|
C3B10000000000000000001F /* LyrebirdShoeGazeUI */ = {
|
||||||
|
isa = XCSwiftPackageProductDependency;
|
||||||
|
package = C3B10000000000000000001B /* XCLocalSwiftPackageReference ".." */;
|
||||||
|
productName = LyrebirdShoeGazeUI;
|
||||||
|
};
|
||||||
|
C3B100000000000000000023 /* Lyrebird */ = {
|
||||||
|
isa = XCSwiftPackageProductDependency;
|
||||||
|
package = C3B10000000000000000001C /* XCRemoteSwiftPackageReference "Lyrebird" */;
|
||||||
|
productName = Lyrebird;
|
||||||
|
};
|
||||||
|
C3B100000000000000000025 /* LyrebirdUI */ = {
|
||||||
|
isa = XCSwiftPackageProductDependency;
|
||||||
|
package = C3B10000000000000000001C /* XCRemoteSwiftPackageReference "Lyrebird" */;
|
||||||
|
productName = LyrebirdUI;
|
||||||
|
};
|
||||||
|
/* End XCSwiftPackageProductDependency section */
|
||||||
|
};
|
||||||
|
rootObject = C3B100000000000000000001 /* Project object */;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"originHash" : "cfdd71f4b32d744c862bbe26a8265d75aa9e906275b0fb1b63575b7d68be1b6a",
|
||||||
|
"pins" : [
|
||||||
|
{
|
||||||
|
"identity" : "linenoise-swift",
|
||||||
|
"kind" : "remoteSourceControl",
|
||||||
|
"location" : "https://github.com/andybest/linenoise-swift",
|
||||||
|
"state" : {
|
||||||
|
"revision" : "afc897c02b030af7333105c4fedcd843a8339238",
|
||||||
|
"version" : "0.0.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"identity" : "lyrebird",
|
||||||
|
"kind" : "remoteSourceControl",
|
||||||
|
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
|
||||||
|
"state" : {
|
||||||
|
"revision" : "032b7c39d351eba4029e8399e1ab1ee201e8bb5c",
|
||||||
|
"version" : "1.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"identity" : "nimble",
|
||||||
|
"kind" : "remoteSourceControl",
|
||||||
|
"location" : "https://github.com/Quick/Nimble.git",
|
||||||
|
"state" : {
|
||||||
|
"revision" : "e9d769113660769a4d9dd3afb855562c0b7ae7b0",
|
||||||
|
"version" : "7.3.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version" : 3
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "2620"
|
||||||
|
version = "1.7">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES"
|
||||||
|
buildArchitectures = "Automatic">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "C3B100000000000000000014"
|
||||||
|
BuildableName = "ShoeGazeBuilder.app"
|
||||||
|
BlueprintName = "ShoeGazeBuilder"
|
||||||
|
ReferencedContainer = "container:ShoeGazeBuilder.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
</BuildActionEntries>
|
||||||
|
</BuildAction>
|
||||||
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
shouldAutocreateTestPlan = "YES">
|
||||||
|
</TestAction>
|
||||||
|
<LaunchAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
launchStyle = "0"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES">
|
||||||
|
<BuildableProductRunnable
|
||||||
|
runnableDebuggingMode = "0">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "C3B100000000000000000014"
|
||||||
|
BuildableName = "ShoeGazeBuilder.app"
|
||||||
|
BlueprintName = "ShoeGazeBuilder"
|
||||||
|
ReferencedContainer = "container:ShoeGazeBuilder.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildableProductRunnable>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
<BuildableProductRunnable
|
||||||
|
runnableDebuggingMode = "0">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "C3B100000000000000000014"
|
||||||
|
BuildableName = "ShoeGazeBuilder.app"
|
||||||
|
BlueprintName = "ShoeGazeBuilder"
|
||||||
|
ReferencedContainer = "container:ShoeGazeBuilder.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildableProductRunnable>
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
||||||
@@ -0,0 +1,303 @@
|
|||||||
|
// AppDelegate.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
#if os(macOS)
|
||||||
|
import AppKit
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
import LyrebirdShoeGazeUI
|
||||||
|
|
||||||
|
/// Application delegate for the ShoeGaze Builder.
|
||||||
|
///
|
||||||
|
/// Creates a `SynthesisEngine` and a `ShoeGaze` session seeded with one empty board, then opens a
|
||||||
|
/// `LyrebirdWindow` hosting ``ShoeGazeBuilderView`` — the interactive palette + board builder.
|
||||||
|
///
|
||||||
|
/// The engine is **not** started automatically; the user clicks Start in the builder's toolbar.
|
||||||
|
/// On termination the engine is stopped to release Core Audio resources cleanly.
|
||||||
|
@MainActor
|
||||||
|
final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
|
|
||||||
|
// MARK: - Engine configuration constants
|
||||||
|
|
||||||
|
private static let blockSize: Int = 512
|
||||||
|
private static let sampleRate: Double = 48_000.0
|
||||||
|
private static let outputChannels: Int = 2
|
||||||
|
// Built-in mics are mono; default to one input channel so live input works out of the box.
|
||||||
|
// CoreAudio can't satisfy a request for more input channels than the device provides, which
|
||||||
|
// leaves live input silent. Users with multi-input interfaces can raise this in the UI.
|
||||||
|
private static let inputChannels: Int = 1
|
||||||
|
private static let numAudioBuses: Int = 256
|
||||||
|
|
||||||
|
// MARK: - Window geometry constants
|
||||||
|
|
||||||
|
private static let windowWidth: CGFloat = 1_400
|
||||||
|
private static let windowHeight: CGFloat = 860
|
||||||
|
|
||||||
|
/// Margin from the left edge of the screen's visible area, in points.
|
||||||
|
private static let leftMargin: CGFloat = 100
|
||||||
|
/// Margin reserved at the right edge so the window never runs off-screen.
|
||||||
|
private static let rightMargin: CGFloat = 40
|
||||||
|
/// Fraction of the visible screen height the window should occupy.
|
||||||
|
private static let heightFraction: CGFloat = 0.88
|
||||||
|
|
||||||
|
/// The default pedal the seed board comes up with, so audio is audible immediately on Start.
|
||||||
|
private static let seedPedalType: PedalType = .overdrive
|
||||||
|
|
||||||
|
// MARK: - Owned objects
|
||||||
|
|
||||||
|
private let coreDriver: CoreAudioDriver
|
||||||
|
private let engine: SynthesisEngine
|
||||||
|
private let shoeGaze: ShoeGaze
|
||||||
|
private let window: LyrebirdWindow
|
||||||
|
|
||||||
|
/// Record toggle item, retained so `validateMenuItem(_:)` can flip its title + enabled state.
|
||||||
|
private var recordMenuItem: NSMenuItem?
|
||||||
|
|
||||||
|
/// Default file name offered by the Save panel.
|
||||||
|
private static let defaultRigFileName: String = "ShoeGazeRig"
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
override init() {
|
||||||
|
let coreDriver: CoreAudioDriver = CoreAudioDriver()
|
||||||
|
let engine: SynthesisEngine = SynthesisEngine(
|
||||||
|
blockSize: AppDelegate.blockSize,
|
||||||
|
sampleRate: AppDelegate.sampleRate,
|
||||||
|
numOutputChannels: AppDelegate.outputChannels,
|
||||||
|
numInputChannels: AppDelegate.inputChannels,
|
||||||
|
numAudioBuses: AppDelegate.numAudioBuses,
|
||||||
|
driver: coreDriver
|
||||||
|
)
|
||||||
|
self.coreDriver = coreDriver
|
||||||
|
self.engine = engine
|
||||||
|
self.shoeGaze = ShoeGaze(engine: engine)
|
||||||
|
self.window = LyrebirdWindow(
|
||||||
|
title: "ShoeGaze Builder — Lyrebird Pedalboard",
|
||||||
|
width: AppDelegate.windowWidth,
|
||||||
|
height: AppDelegate.windowHeight
|
||||||
|
)
|
||||||
|
super.init()
|
||||||
|
|
||||||
|
seedInitialBoard()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Seeds one board with a single pedal so the builder opens with an audible starting point.
|
||||||
|
private func seedInitialBoard() {
|
||||||
|
var created: PedalBoard?
|
||||||
|
do {
|
||||||
|
let board: PedalBoard = try shoeGaze.addBoard()
|
||||||
|
created = board
|
||||||
|
try shoeGaze.appendPedal(AppDelegate.seedPedalType, to: board)
|
||||||
|
} catch {
|
||||||
|
if let board: PedalBoard = created { shoeGaze.removeBoard(board) }
|
||||||
|
print("[ShoeGazeBuilder] seed board failed: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - NSApplicationDelegate
|
||||||
|
|
||||||
|
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||||
|
installMainMenu()
|
||||||
|
let session: ShoeGaze = shoeGaze
|
||||||
|
let driver: CoreAudioDriver = coreDriver
|
||||||
|
window.open {
|
||||||
|
ShoeGazeBuilderView(shoeGaze: session, hardwareSampleRate: { driver.deviceSampleRate })
|
||||||
|
}
|
||||||
|
anchorWindowLeft()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Anchors the window `leftMargin` points from the left of the visible screen and sizes it to
|
||||||
|
/// most of the visible height, so it presents large and left-aligned rather than centered.
|
||||||
|
private func anchorWindowLeft() {
|
||||||
|
guard let nsWindow: NSWindow = window.nsWindow,
|
||||||
|
let screen: NSScreen = nsWindow.screen ?? NSScreen.main else { return }
|
||||||
|
let visible: NSRect = screen.visibleFrame
|
||||||
|
let height: CGFloat = visible.height * AppDelegate.heightFraction
|
||||||
|
let maxWidth: CGFloat = visible.width - AppDelegate.leftMargin - AppDelegate.rightMargin
|
||||||
|
let width: CGFloat = min(AppDelegate.windowWidth, maxWidth)
|
||||||
|
let originX: CGFloat = visible.minX + AppDelegate.leftMargin
|
||||||
|
// Top-align: place the window's top near the top of the visible area.
|
||||||
|
let originY: CGFloat = visible.maxY - height
|
||||||
|
nsWindow.setFrame(
|
||||||
|
NSRect(x: originX, y: originY, width: width, height: height),
|
||||||
|
display: true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
func applicationWillTerminate(_ notification: Notification) {
|
||||||
|
engine.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Main menu
|
||||||
|
|
||||||
|
/// Builds a minimal menu bar: an application menu with About / Hide / Quit (⌘Q).
|
||||||
|
private func installMainMenu() {
|
||||||
|
let appName: String = ProcessInfo.processInfo.processName
|
||||||
|
let mainMenu: NSMenu = NSMenu()
|
||||||
|
|
||||||
|
let appMenuItem: NSMenuItem = NSMenuItem()
|
||||||
|
mainMenu.addItem(appMenuItem)
|
||||||
|
let appMenu: NSMenu = NSMenu()
|
||||||
|
appMenuItem.submenu = appMenu
|
||||||
|
appMenu.addItem(
|
||||||
|
withTitle: "About \(appName)",
|
||||||
|
action: #selector(NSApplication.orderFrontStandardAboutPanel(_:)),
|
||||||
|
keyEquivalent: ""
|
||||||
|
)
|
||||||
|
appMenu.addItem(NSMenuItem.separator())
|
||||||
|
appMenu.addItem(
|
||||||
|
withTitle: "Hide \(appName)",
|
||||||
|
action: #selector(NSApplication.hide(_:)),
|
||||||
|
keyEquivalent: "h"
|
||||||
|
)
|
||||||
|
appMenu.addItem(NSMenuItem.separator())
|
||||||
|
appMenu.addItem(
|
||||||
|
withTitle: "Quit \(appName)",
|
||||||
|
action: #selector(NSApplication.terminate(_:)),
|
||||||
|
keyEquivalent: "q"
|
||||||
|
)
|
||||||
|
|
||||||
|
// File menu — rig save / load.
|
||||||
|
let fileMenuItem: NSMenuItem = NSMenuItem()
|
||||||
|
mainMenu.addItem(fileMenuItem)
|
||||||
|
let fileMenu: NSMenu = NSMenu(title: "File")
|
||||||
|
fileMenuItem.submenu = fileMenu
|
||||||
|
addItem(to: fileMenu, title: "Save Rig…", action: #selector(saveRigAction(_:)), key: "s")
|
||||||
|
addItem(to: fileMenu, title: "Load Rig…", action: #selector(loadRigAction(_:)), key: "o")
|
||||||
|
|
||||||
|
// Board menu — add board + transport.
|
||||||
|
let boardMenuItem: NSMenuItem = NSMenuItem()
|
||||||
|
mainMenu.addItem(boardMenuItem)
|
||||||
|
let boardMenu: NSMenu = NSMenu(title: "Board")
|
||||||
|
boardMenuItem.submenu = boardMenu
|
||||||
|
// Engine start/stop lives in the in-window EngineConfigView (with sample-rate/channel
|
||||||
|
// config and the mismatch alert), so the Board menu only adds boards.
|
||||||
|
addItem(to: boardMenu, title: "Add Board", action: #selector(addBoardAction(_:)), key: "b")
|
||||||
|
|
||||||
|
// Record menu — choose an output folder, then toggle recording.
|
||||||
|
let recordMenuItem: NSMenuItem = NSMenuItem()
|
||||||
|
mainMenu.addItem(recordMenuItem)
|
||||||
|
let recordMenu: NSMenu = NSMenu(title: "Record")
|
||||||
|
recordMenuItem.submenu = recordMenu
|
||||||
|
addItem(
|
||||||
|
to: recordMenu,
|
||||||
|
title: "Choose Recording Folder…",
|
||||||
|
action: #selector(chooseRecordingFolderAction(_:)),
|
||||||
|
key: ""
|
||||||
|
)
|
||||||
|
recordMenu.addItem(NSMenuItem.separator())
|
||||||
|
self.recordMenuItem = addItem(
|
||||||
|
to: recordMenu,
|
||||||
|
title: "Start Recording",
|
||||||
|
action: #selector(toggleRecordingAction(_:)),
|
||||||
|
key: "R" // ⇧⌘R
|
||||||
|
)
|
||||||
|
|
||||||
|
NSApplication.shared.mainMenu = mainMenu
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds a menu item targeting this delegate and returns it.
|
||||||
|
@discardableResult
|
||||||
|
private func addItem(
|
||||||
|
to menu: NSMenu,
|
||||||
|
title: String,
|
||||||
|
action: Selector,
|
||||||
|
key: String
|
||||||
|
) -> NSMenuItem {
|
||||||
|
let item: NSMenuItem = NSMenuItem(title: title, action: action, keyEquivalent: key)
|
||||||
|
item.target = self
|
||||||
|
menu.addItem(item)
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Menu actions
|
||||||
|
|
||||||
|
@objc private func saveRigAction(_ sender: Any?) {
|
||||||
|
let panel: NSSavePanel = NSSavePanel()
|
||||||
|
panel.allowedContentTypes = [.json]
|
||||||
|
panel.nameFieldStringValue = "\(AppDelegate.defaultRigFileName).json"
|
||||||
|
panel.canCreateDirectories = true
|
||||||
|
let session: ShoeGaze = shoeGaze
|
||||||
|
panel.begin { response in
|
||||||
|
guard response == .OK, let url: URL = panel.url else { return }
|
||||||
|
do { try session.saveRig(to: url) }
|
||||||
|
catch { print("[ShoeGazeBuilder] saveRig failed: \(error)") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func loadRigAction(_ sender: Any?) {
|
||||||
|
let panel: NSOpenPanel = NSOpenPanel()
|
||||||
|
panel.allowedContentTypes = [.json]
|
||||||
|
panel.canChooseDirectories = false
|
||||||
|
panel.allowsMultipleSelection = false
|
||||||
|
let session: ShoeGaze = shoeGaze
|
||||||
|
let activeEngine: SynthesisEngine = engine
|
||||||
|
panel.begin { response in
|
||||||
|
guard response == .OK, let url: URL = panel.url else { return }
|
||||||
|
// loadRig rebuilds the graph; stop the engine around it and restart if it was running.
|
||||||
|
let wasRunning: Bool = activeEngine.isRunning
|
||||||
|
if wasRunning { activeEngine.stop() }
|
||||||
|
do { try session.loadRig(from: url) }
|
||||||
|
catch { print("[ShoeGazeBuilder] loadRig failed: \(error)") }
|
||||||
|
if wasRunning { try? activeEngine.start() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func addBoardAction(_ sender: Any?) {
|
||||||
|
var created: PedalBoard?
|
||||||
|
do {
|
||||||
|
let board: PedalBoard = try shoeGaze.addBoard()
|
||||||
|
created = board
|
||||||
|
try shoeGaze.finalizeBoard(board)
|
||||||
|
} catch {
|
||||||
|
if let board: PedalBoard = created { shoeGaze.removeBoard(board) }
|
||||||
|
print("[ShoeGazeBuilder] addBoard failed: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func chooseRecordingFolderAction(_ sender: Any?) {
|
||||||
|
let panel: NSOpenPanel = NSOpenPanel()
|
||||||
|
panel.canChooseDirectories = true
|
||||||
|
panel.canChooseFiles = false
|
||||||
|
panel.allowsMultipleSelection = false
|
||||||
|
panel.canCreateDirectories = true
|
||||||
|
panel.prompt = "Choose"
|
||||||
|
panel.message = "Select a folder for recording output"
|
||||||
|
let session: ShoeGaze = shoeGaze
|
||||||
|
panel.begin { response in
|
||||||
|
if response == .OK, let url: URL = panel.url {
|
||||||
|
session.recordingFolder = url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func toggleRecordingAction(_ sender: Any?) {
|
||||||
|
if shoeGaze.isRecording {
|
||||||
|
shoeGaze.stopRecording()
|
||||||
|
} else {
|
||||||
|
do { try shoeGaze.startRecording() }
|
||||||
|
catch { print("[ShoeGazeBuilder] startRecording() failed: \(error)") }
|
||||||
|
}
|
||||||
|
// Reflect the new state on the item immediately, not only on the next menu-open validation.
|
||||||
|
recordMenuItem?.title = shoeGaze.isRecording ? "Stop Recording" : "Start Recording"
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
|
||||||
|
if menuItem == recordMenuItem {
|
||||||
|
menuItem.title = shoeGaze.isRecording ? "Stop Recording" : "Start Recording"
|
||||||
|
// Can always stop; can only start once a folder has been chosen.
|
||||||
|
return shoeGaze.isRecording || shoeGaze.recordingFolder != nil
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{"size":"16x16","idiom":"mac","filename":"icon_16x16.png","scale":"1x"},
|
||||||
|
{"size":"16x16","idiom":"mac","filename":"icon_16x16@2x.png","scale":"2x"},
|
||||||
|
{"size":"32x32","idiom":"mac","filename":"icon_32x32.png","scale":"1x"},
|
||||||
|
{"size":"32x32","idiom":"mac","filename":"icon_32x32@2x.png","scale":"2x"},
|
||||||
|
{"size":"128x128","idiom":"mac","filename":"icon_128x128.png","scale":"1x"},
|
||||||
|
{"size":"128x128","idiom":"mac","filename":"icon_128x128@2x.png","scale":"2x"},
|
||||||
|
{"size":"256x256","idiom":"mac","filename":"icon_256x256.png","scale":"1x"},
|
||||||
|
{"size":"256x256","idiom":"mac","filename":"icon_256x256@2x.png","scale":"2x"},
|
||||||
|
{"size":"512x512","idiom":"mac","filename":"icon_512x512.png","scale":"1x"},
|
||||||
|
{"size":"512x512","idiom":"mac","filename":"icon_512x512@2x.png","scale":"2x"}
|
||||||
|
],
|
||||||
|
"info" : {"author":"xcode","version":1}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 91 KiB |
|
After Width: | Height: | Size: 782 B |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 91 KiB |
|
After Width: | Height: | Size: 345 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 345 KiB |
|
After Width: | Height: | Size: 1.2 MiB |
@@ -0,0 +1 @@
|
|||||||
|
{ "info" : {"author":"xcode","version":1} }
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||||
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
<string>6.0</string>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>$(PRODUCT_NAME)</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>APPL</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>1.0</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>1</string>
|
||||||
|
<key>LSApplicationCategoryType</key>
|
||||||
|
<string>public.app-category.music</string>
|
||||||
|
<key>LSMinimumSystemVersion</key>
|
||||||
|
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||||
|
<key>NSHighResolutionCapable</key>
|
||||||
|
<true/>
|
||||||
|
<key>NSHumanReadableCopyright</key>
|
||||||
|
<string>Copyright © 2026 realizedsound. All rights reserved.</string>
|
||||||
|
<key>NSMicrophoneUsageDescription</key>
|
||||||
|
<string>ShoeGaze Builder can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode.</string>
|
||||||
|
<key>NSPrincipalClass</key>
|
||||||
|
<string>NSApplication</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>com.apple.security.device.audio-input</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// main.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
#if os(macOS)
|
||||||
|
import AppKit
|
||||||
|
|
||||||
|
// Program entry runs on the main thread; assert main-actor isolation for the AppKit bootstrap
|
||||||
|
// rather than hopping asynchronously. `AppDelegate.init` builds `@MainActor` synthesizers and UI.
|
||||||
|
MainActor.assumeIsolated {
|
||||||
|
let app: NSApplication = NSApplication.shared
|
||||||
|
let delegate: AppDelegate = AppDelegate()
|
||||||
|
app.setActivationPolicy(.regular)
|
||||||
|
app.delegate = delegate
|
||||||
|
app.activate(ignoringOtherApps: true)
|
||||||
|
app.run()
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// The ShoeGaze Builder is a macOS AppKit application and has no iOS entry point here.
|
||||||
|
print("ShoeGazeBuilder runs on macOS only.")
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,389 @@
|
|||||||
|
// !$*UTF8*$!
|
||||||
|
{
|
||||||
|
archiveVersion = 1;
|
||||||
|
classes = {
|
||||||
|
};
|
||||||
|
objectVersion = 60;
|
||||||
|
objects = {
|
||||||
|
|
||||||
|
/* Begin PBXBuildFile section */
|
||||||
|
C3C100000000000000000009 /* ShoeGazeBuilderiOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C100000000000000000007 /* ShoeGazeBuilderiOSApp.swift */; };
|
||||||
|
C3C10000000000000000000A /* ShoeGazeBuilderiOSAppModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C100000000000000000008 /* ShoeGazeBuilderiOSAppModel.swift */; };
|
||||||
|
C3C10000000000000000000B /* LyrebirdShoeGaze in Frameworks */ = {isa = PBXBuildFile; productRef = C3C10000000000000000001A /* LyrebirdShoeGaze */; };
|
||||||
|
C3C10000000000000000000C /* LyrebirdShoeGazeUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3C10000000000000000001B /* LyrebirdShoeGazeUI */; };
|
||||||
|
C3C10000000000000000000D /* LyrebirdUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3C10000000000000000001C /* LyrebirdUI */; };
|
||||||
|
C3C10000000000000000001D /* Lyrebird in Frameworks */ = {isa = PBXBuildFile; productRef = C3C10000000000000000001E /* Lyrebird */; };
|
||||||
|
C3C100000000000000000031 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C3C100000000000000000030 /* Assets.xcassets */; };
|
||||||
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
|
/* Begin PBXFileReference section */
|
||||||
|
C3C100000000000000000004 /* ShoeGazeBuilderiOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ShoeGazeBuilderiOS.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
|
C3C100000000000000000006 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
|
C3C100000000000000000007 /* ShoeGazeBuilderiOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoeGazeBuilderiOSApp.swift; sourceTree = "<group>"; };
|
||||||
|
C3C100000000000000000008 /* ShoeGazeBuilderiOSAppModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoeGazeBuilderiOSAppModel.swift; sourceTree = "<group>"; };
|
||||||
|
C3C100000000000000000030 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||||
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
|
C3C10000000000000000000F /* Frameworks */ = {
|
||||||
|
isa = PBXFrameworksBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
C3C10000000000000000000B /* LyrebirdShoeGaze in Frameworks */,
|
||||||
|
C3C10000000000000000000C /* LyrebirdShoeGazeUI in Frameworks */,
|
||||||
|
C3C10000000000000000000D /* LyrebirdUI in Frameworks */,
|
||||||
|
C3C10000000000000000001D /* Lyrebird in Frameworks */,
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXFrameworksBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXGroup section */
|
||||||
|
C3C100000000000000000002 = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
C3C100000000000000000005 /* ShoeGazeBuilderiOS */,
|
||||||
|
C3C100000000000000000003 /* Products */,
|
||||||
|
);
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
C3C100000000000000000003 /* Products */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
C3C100000000000000000004 /* ShoeGazeBuilderiOS.app */,
|
||||||
|
);
|
||||||
|
name = Products;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
C3C100000000000000000005 /* ShoeGazeBuilderiOS */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
C3C100000000000000000007 /* ShoeGazeBuilderiOSApp.swift */,
|
||||||
|
C3C100000000000000000008 /* ShoeGazeBuilderiOSAppModel.swift */,
|
||||||
|
C3C100000000000000000030 /* Assets.xcassets */,
|
||||||
|
C3C100000000000000000006 /* Info.plist */,
|
||||||
|
);
|
||||||
|
path = ShoeGazeBuilderiOS;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
|
/* End PBXGroup section */
|
||||||
|
|
||||||
|
/* Begin PBXNativeTarget section */
|
||||||
|
C3C100000000000000000011 /* ShoeGazeBuilderiOS */ = {
|
||||||
|
isa = PBXNativeTarget;
|
||||||
|
buildConfigurationList = C3C100000000000000000012 /* Build configuration list for PBXNativeTarget "ShoeGazeBuilderiOS" */;
|
||||||
|
buildPhases = (
|
||||||
|
C3C10000000000000000000E /* Sources */,
|
||||||
|
C3C10000000000000000000F /* Frameworks */,
|
||||||
|
C3C100000000000000000010 /* Resources */,
|
||||||
|
);
|
||||||
|
buildRules = (
|
||||||
|
);
|
||||||
|
dependencies = (
|
||||||
|
);
|
||||||
|
name = ShoeGazeBuilderiOS;
|
||||||
|
packageProductDependencies = (
|
||||||
|
C3C10000000000000000001A /* LyrebirdShoeGaze */,
|
||||||
|
C3C10000000000000000001B /* LyrebirdShoeGazeUI */,
|
||||||
|
C3C10000000000000000001C /* LyrebirdUI */,
|
||||||
|
C3C10000000000000000001E /* Lyrebird */,
|
||||||
|
);
|
||||||
|
productName = ShoeGazeBuilderiOS;
|
||||||
|
productReference = C3C100000000000000000004 /* ShoeGazeBuilderiOS.app */;
|
||||||
|
productType = "com.apple.product-type.application";
|
||||||
|
};
|
||||||
|
/* End PBXNativeTarget section */
|
||||||
|
|
||||||
|
/* Begin PBXProject section */
|
||||||
|
C3C100000000000000000001 /* Project object */ = {
|
||||||
|
isa = PBXProject;
|
||||||
|
attributes = {
|
||||||
|
BuildIndependentTargetsInParallel = 1;
|
||||||
|
LastSwiftUpdateCheck = 1600;
|
||||||
|
LastUpgradeCheck = 2620;
|
||||||
|
TargetAttributes = {
|
||||||
|
C3C100000000000000000011 = {
|
||||||
|
CreatedOnToolsVersion = 16.0;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
buildConfigurationList = C3C100000000000000000015 /* Build configuration list for PBXProject "ShoeGazeBuilderiOS" */;
|
||||||
|
compatibilityVersion = "Xcode 14.0";
|
||||||
|
developmentRegion = en;
|
||||||
|
hasScannedForEncodings = 0;
|
||||||
|
knownRegions = (
|
||||||
|
en,
|
||||||
|
Base,
|
||||||
|
);
|
||||||
|
mainGroup = C3C100000000000000000002;
|
||||||
|
packageReferences = (
|
||||||
|
C3C100000000000000000018 /* XCLocalSwiftPackageReference ".." */,
|
||||||
|
C3C100000000000000000019 /* XCRemoteSwiftPackageReference "Lyrebird" */,
|
||||||
|
);
|
||||||
|
productRefGroup = C3C100000000000000000003 /* Products */;
|
||||||
|
projectDirPath = "";
|
||||||
|
projectRoot = "";
|
||||||
|
targets = (
|
||||||
|
C3C100000000000000000011 /* ShoeGazeBuilderiOS */,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
/* End PBXProject section */
|
||||||
|
|
||||||
|
/* Begin PBXResourcesBuildPhase section */
|
||||||
|
C3C100000000000000000010 /* Resources */ = {
|
||||||
|
isa = PBXResourcesBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
C3C100000000000000000031 /* Assets.xcassets in Resources */,
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXResourcesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin PBXSourcesBuildPhase section */
|
||||||
|
C3C10000000000000000000E /* Sources */ = {
|
||||||
|
isa = PBXSourcesBuildPhase;
|
||||||
|
buildActionMask = 2147483647;
|
||||||
|
files = (
|
||||||
|
C3C100000000000000000009 /* ShoeGazeBuilderiOSApp.swift in Sources */,
|
||||||
|
C3C10000000000000000000A /* ShoeGazeBuilderiOSAppModel.swift in Sources */,
|
||||||
|
);
|
||||||
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
};
|
||||||
|
/* End PBXSourcesBuildPhase section */
|
||||||
|
|
||||||
|
/* Begin XCBuildConfiguration section */
|
||||||
|
C3C100000000000000000013 /* Debug */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
|
CODE_SIGNING_REQUIRED = NO;
|
||||||
|
CODE_SIGN_STYLE = Automatic;
|
||||||
|
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||||
|
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||||
|
INFOPLIST_FILE = ShoeGazeBuilderiOS/Info.plist;
|
||||||
|
INFOPLIST_KEY_CFBundleDisplayName = ShoeGaze;
|
||||||
|
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
|
||||||
|
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
|
||||||
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
|
"$(inherited)",
|
||||||
|
"@executable_path/Frameworks",
|
||||||
|
);
|
||||||
|
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilderiOS;
|
||||||
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
SDKROOT = iphoneos;
|
||||||
|
SUPPORTS_MACCATALYST = NO;
|
||||||
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
|
SWIFT_VERSION = 6.0;
|
||||||
|
TARGETED_DEVICE_FAMILY = 2;
|
||||||
|
};
|
||||||
|
name = Debug;
|
||||||
|
};
|
||||||
|
C3C100000000000000000014 /* Release */ = {
|
||||||
|
isa = XCBuildConfiguration;
|
||||||
|
buildSettings = {
|
||||||
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
|
CODE_SIGNING_REQUIRED = NO;
|
||||||
|
CODE_SIGN_STYLE = Automatic;
|
||||||
|
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||||
|
INFOPLIST_FILE = ShoeGazeBuilderiOS/Info.plist;
|
||||||
|
INFOPLIST_KEY_CFBundleDisplayName = ShoeGaze;
|
||||||
|
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
|
||||||
|
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
|
||||||
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
|
"$(inherited)",
|
||||||
|
"@executable_path/Frameworks",
|
||||||
|
);
|
||||||
|
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilderiOS;
|
||||||
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
|
SDKROOT = iphoneos;
|
||||||
|
SUPPORTS_MACCATALYST = NO;
|
||||||
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
|
SWIFT_VERSION = 6.0;
|
||||||
|
TARGETED_DEVICE_FAMILY = 2;
|
||||||
|
};
|
||||||
|
name = Release;
|
||||||
|
};
|
||||||
|
C3C100000000000000000016 /* 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++20";
|
||||||
|
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;
|
||||||
|
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||||
|
GCC_C_LANGUAGE_STANDARD = gnu17;
|
||||||
|
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;
|
||||||
|
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
|
||||||
|
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||||
|
MTL_FAST_MATH = YES;
|
||||||
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
|
SDKROOT = iphoneos;
|
||||||
|
STRING_CATALOG_GENERATE_SYMBOLS = YES;
|
||||||
|
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||||
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
|
};
|
||||||
|
name = Debug;
|
||||||
|
};
|
||||||
|
C3C100000000000000000017 /* 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++20";
|
||||||
|
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;
|
||||||
|
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||||
|
GCC_C_LANGUAGE_STANDARD = gnu17;
|
||||||
|
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;
|
||||||
|
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
|
||||||
|
MTL_ENABLE_DEBUG_INFO = NO;
|
||||||
|
MTL_FAST_MATH = YES;
|
||||||
|
SDKROOT = iphoneos;
|
||||||
|
STRING_CATALOG_GENERATE_SYMBOLS = YES;
|
||||||
|
SWIFT_COMPILATION_MODE = wholemodule;
|
||||||
|
SWIFT_OPTIMIZATION_LEVEL = "-O";
|
||||||
|
};
|
||||||
|
name = Release;
|
||||||
|
};
|
||||||
|
/* End XCBuildConfiguration section */
|
||||||
|
|
||||||
|
/* Begin XCConfigurationList section */
|
||||||
|
C3C100000000000000000012 /* Build configuration list for PBXNativeTarget "ShoeGazeBuilderiOS" */ = {
|
||||||
|
isa = XCConfigurationList;
|
||||||
|
buildConfigurations = (
|
||||||
|
C3C100000000000000000013 /* Debug */,
|
||||||
|
C3C100000000000000000014 /* Release */,
|
||||||
|
);
|
||||||
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
|
};
|
||||||
|
C3C100000000000000000015 /* Build configuration list for PBXProject "ShoeGazeBuilderiOS" */ = {
|
||||||
|
isa = XCConfigurationList;
|
||||||
|
buildConfigurations = (
|
||||||
|
C3C100000000000000000016 /* Debug */,
|
||||||
|
C3C100000000000000000017 /* Release */,
|
||||||
|
);
|
||||||
|
defaultConfigurationIsVisible = 0;
|
||||||
|
defaultConfigurationName = Release;
|
||||||
|
};
|
||||||
|
/* End XCConfigurationList section */
|
||||||
|
|
||||||
|
/* Begin XCLocalSwiftPackageReference section */
|
||||||
|
C3C100000000000000000018 /* XCLocalSwiftPackageReference ".." */ = {
|
||||||
|
isa = XCLocalSwiftPackageReference;
|
||||||
|
relativePath = ..;
|
||||||
|
};
|
||||||
|
/* End XCLocalSwiftPackageReference section */
|
||||||
|
|
||||||
|
/* Begin XCRemoteSwiftPackageReference section */
|
||||||
|
C3C100000000000000000019 /* XCRemoteSwiftPackageReference "Lyrebird" */ = {
|
||||||
|
isa = XCRemoteSwiftPackageReference;
|
||||||
|
repositoryURL = "https://realizedsound.mooo.com/josh/Lyrebird";
|
||||||
|
requirement = {
|
||||||
|
kind = upToNextMajorVersion;
|
||||||
|
minimumVersion = 1.2.0;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
/* End XCRemoteSwiftPackageReference section */
|
||||||
|
|
||||||
|
/* Begin XCSwiftPackageProductDependency section */
|
||||||
|
C3C10000000000000000001A /* LyrebirdShoeGaze */ = {
|
||||||
|
isa = XCSwiftPackageProductDependency;
|
||||||
|
package = C3C100000000000000000018 /* XCLocalSwiftPackageReference ".." */;
|
||||||
|
productName = LyrebirdShoeGaze;
|
||||||
|
};
|
||||||
|
C3C10000000000000000001B /* LyrebirdShoeGazeUI */ = {
|
||||||
|
isa = XCSwiftPackageProductDependency;
|
||||||
|
package = C3C100000000000000000018 /* XCLocalSwiftPackageReference ".." */;
|
||||||
|
productName = LyrebirdShoeGazeUI;
|
||||||
|
};
|
||||||
|
C3C10000000000000000001C /* LyrebirdUI */ = {
|
||||||
|
isa = XCSwiftPackageProductDependency;
|
||||||
|
package = C3C100000000000000000019 /* XCRemoteSwiftPackageReference "Lyrebird" */;
|
||||||
|
productName = LyrebirdUI;
|
||||||
|
};
|
||||||
|
C3C10000000000000000001E /* Lyrebird */ = {
|
||||||
|
isa = XCSwiftPackageProductDependency;
|
||||||
|
package = C3C100000000000000000019 /* XCRemoteSwiftPackageReference "Lyrebird" */;
|
||||||
|
productName = Lyrebird;
|
||||||
|
};
|
||||||
|
/* End XCSwiftPackageProductDependency section */
|
||||||
|
};
|
||||||
|
rootObject = C3C100000000000000000001 /* Project object */;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"originHash" : "cfdd71f4b32d744c862bbe26a8265d75aa9e906275b0fb1b63575b7d68be1b6a",
|
||||||
|
"pins" : [
|
||||||
|
{
|
||||||
|
"identity" : "linenoise-swift",
|
||||||
|
"kind" : "remoteSourceControl",
|
||||||
|
"location" : "https://github.com/andybest/linenoise-swift",
|
||||||
|
"state" : {
|
||||||
|
"revision" : "afc897c02b030af7333105c4fedcd843a8339238",
|
||||||
|
"version" : "0.0.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"identity" : "lyrebird",
|
||||||
|
"kind" : "remoteSourceControl",
|
||||||
|
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
|
||||||
|
"state" : {
|
||||||
|
"revision" : "032b7c39d351eba4029e8399e1ab1ee201e8bb5c",
|
||||||
|
"version" : "1.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"identity" : "nimble",
|
||||||
|
"kind" : "remoteSourceControl",
|
||||||
|
"location" : "https://github.com/Quick/Nimble.git",
|
||||||
|
"state" : {
|
||||||
|
"revision" : "e9d769113660769a4d9dd3afb855562c0b7ae7b0",
|
||||||
|
"version" : "7.3.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version" : 3
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<Scheme
|
||||||
|
LastUpgradeVersion = "2620"
|
||||||
|
version = "1.7">
|
||||||
|
<BuildAction
|
||||||
|
parallelizeBuildables = "YES"
|
||||||
|
buildImplicitDependencies = "YES"
|
||||||
|
buildArchitectures = "Automatic">
|
||||||
|
<BuildActionEntries>
|
||||||
|
<BuildActionEntry
|
||||||
|
buildForTesting = "YES"
|
||||||
|
buildForRunning = "YES"
|
||||||
|
buildForProfiling = "YES"
|
||||||
|
buildForArchiving = "YES"
|
||||||
|
buildForAnalyzing = "YES">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "C3C100000000000000000011"
|
||||||
|
BuildableName = "ShoeGazeBuilderiOS.app"
|
||||||
|
BlueprintName = "ShoeGazeBuilderiOS"
|
||||||
|
ReferencedContainer = "container:ShoeGazeBuilderiOS.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildActionEntry>
|
||||||
|
</BuildActionEntries>
|
||||||
|
</BuildAction>
|
||||||
|
<TestAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
shouldAutocreateTestPlan = "YES">
|
||||||
|
</TestAction>
|
||||||
|
<LaunchAction
|
||||||
|
buildConfiguration = "Debug"
|
||||||
|
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||||
|
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||||
|
launchStyle = "0"
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
ignoresPersistentStateOnLaunch = "NO"
|
||||||
|
debugDocumentVersioning = "YES"
|
||||||
|
debugServiceExtension = "internal"
|
||||||
|
allowLocationSimulation = "YES">
|
||||||
|
<BuildableProductRunnable
|
||||||
|
runnableDebuggingMode = "0">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "C3C100000000000000000011"
|
||||||
|
BuildableName = "ShoeGazeBuilderiOS.app"
|
||||||
|
BlueprintName = "ShoeGazeBuilderiOS"
|
||||||
|
ReferencedContainer = "container:ShoeGazeBuilderiOS.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildableProductRunnable>
|
||||||
|
</LaunchAction>
|
||||||
|
<ProfileAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||||
|
savedToolIdentifier = ""
|
||||||
|
useCustomWorkingDirectory = "NO"
|
||||||
|
debugDocumentVersioning = "YES">
|
||||||
|
<BuildableProductRunnable
|
||||||
|
runnableDebuggingMode = "0">
|
||||||
|
<BuildableReference
|
||||||
|
BuildableIdentifier = "primary"
|
||||||
|
BlueprintIdentifier = "C3C100000000000000000011"
|
||||||
|
BuildableName = "ShoeGazeBuilderiOS.app"
|
||||||
|
BlueprintName = "ShoeGazeBuilderiOS"
|
||||||
|
ReferencedContainer = "container:ShoeGazeBuilderiOS.xcodeproj">
|
||||||
|
</BuildableReference>
|
||||||
|
</BuildableProductRunnable>
|
||||||
|
</ProfileAction>
|
||||||
|
<AnalyzeAction
|
||||||
|
buildConfiguration = "Debug">
|
||||||
|
</AnalyzeAction>
|
||||||
|
<ArchiveAction
|
||||||
|
buildConfiguration = "Release"
|
||||||
|
revealArchiveInOrganizer = "YES">
|
||||||
|
</ArchiveAction>
|
||||||
|
</Scheme>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{"filename":"icon_1024.png","idiom":"universal","platform":"ios","size":"1024x1024"}
|
||||||
|
],
|
||||||
|
"info" : {"author":"xcode","version":1}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 402 KiB |
@@ -0,0 +1 @@
|
|||||||
|
{ "info" : {"author":"xcode","version":1} }
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||||
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
<string>6.0</string>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>$(PRODUCT_NAME)</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>APPL</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>1.0</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>1</string>
|
||||||
|
<key>LSRequiresIPhoneOS</key>
|
||||||
|
<true/>
|
||||||
|
<key>NSHumanReadableCopyright</key>
|
||||||
|
<string>Copyright © 2026 realizedsound. All rights reserved.</string>
|
||||||
|
<key>NSMicrophoneUsageDescription</key>
|
||||||
|
<string>ShoeGaze Builder can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode.</string>
|
||||||
|
<key>UIApplicationSceneManifest</key>
|
||||||
|
<dict>
|
||||||
|
<key>UIApplicationSupportsMultipleScenes</key>
|
||||||
|
<false/>
|
||||||
|
</dict>
|
||||||
|
<key>UILaunchScreen</key>
|
||||||
|
<dict/>
|
||||||
|
<key>UIRequiresFullScreen</key>
|
||||||
|
<true/>
|
||||||
|
<key>UISupportedInterfaceOrientations</key>
|
||||||
|
<array>
|
||||||
|
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||||
|
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||||
|
</array>
|
||||||
|
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||||
|
<array>
|
||||||
|
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||||
|
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// ShoeGazeBuilderiOSApp.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import LyrebirdShoeGazeUI
|
||||||
|
|
||||||
|
/// iOS entry point for the ShoeGaze Builder.
|
||||||
|
///
|
||||||
|
/// Holds the `ShoeGazeBuilderiOSAppModel` as `@State` so it is created once and owned for the
|
||||||
|
/// lifetime of the app. The audio engine is **not** started automatically — the user presses
|
||||||
|
/// Start in ``ShoeGazeBuilderView``. The engine is stopped when the view disappears.
|
||||||
|
///
|
||||||
|
/// ``ShoeGazeBuilderView`` manages its own scroll regions (palette + builder), so it is hosted
|
||||||
|
/// directly rather than wrapped in an outer `ScrollView`.
|
||||||
|
@main
|
||||||
|
struct ShoeGazeBuilderiOSApp: App {
|
||||||
|
|
||||||
|
@State private var model: ShoeGazeBuilderiOSAppModel = ShoeGazeBuilderiOSAppModel()
|
||||||
|
|
||||||
|
var body: some Scene {
|
||||||
|
WindowGroup {
|
||||||
|
NavigationStack {
|
||||||
|
ShoeGazeBuilderView(
|
||||||
|
shoeGaze: model.shoeGaze,
|
||||||
|
hardwareSampleRate: { model.hardwareSampleRate },
|
||||||
|
onEnableLiveInput: { model.enableLiveInput() }
|
||||||
|
)
|
||||||
|
.navigationTitle("ShoeGaze Builder")
|
||||||
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
|
}
|
||||||
|
.onDisappear { model.stop() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,197 @@
|
|||||||
|
// ShoeGazeBuilderiOSAppModel.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import AVFoundation
|
||||||
|
import Observation
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
/// Observable model owning the `SynthesisEngine` and `ShoeGaze` session for the iOS builder.
|
||||||
|
///
|
||||||
|
/// `AVAudioSession` is activated at init so the hardware sample rate is known before the engine
|
||||||
|
/// is constructed (iOS devices typically lock to 48 000 Hz). The session is seeded with one board
|
||||||
|
/// holding a single pedal so the builder opens with an audible starting point; the user adds /
|
||||||
|
/// removes / reorders pedals from the palette. Input defaults to `.testLoop`, so no microphone
|
||||||
|
/// permission is required to start.
|
||||||
|
@Observable
|
||||||
|
@MainActor
|
||||||
|
final class ShoeGazeBuilderiOSAppModel {
|
||||||
|
|
||||||
|
// MARK: - Engine configuration constants
|
||||||
|
|
||||||
|
private static let blockSize: Int = 512
|
||||||
|
private static let outputChannels: Int = 2
|
||||||
|
// Default to one input channel so live input is available immediately. The trade-off is
|
||||||
|
// that the iOS driver runs a `.playAndRecord` session with the RemoteIO input element
|
||||||
|
// enabled, so iOS prompts for microphone access at the first Start even while the input
|
||||||
|
// still defaults to `.testLoop`. (The permission-gated `enableLiveInput()` rebuild remains
|
||||||
|
// available for any future build that starts input-less.)
|
||||||
|
private static let inputChannels: Int = 1
|
||||||
|
private static let numAudioBuses: Int = 256
|
||||||
|
private static let seedPedalType: PedalType = .overdrive
|
||||||
|
|
||||||
|
/// UserDefaults key persisting the input selection. Must match the key written by the
|
||||||
|
/// builder view (`ShoeGazeBuilderView.inputSelectionDefaultsKey`).
|
||||||
|
private static let inputSelectionDefaultsKey: String = "ShoeGaze.inputSelection"
|
||||||
|
/// Persisted value meaning "live input, channel 0".
|
||||||
|
private static let liveInputChannelZeroTag: Int = 0
|
||||||
|
|
||||||
|
// MARK: - Owned objects
|
||||||
|
|
||||||
|
/// The active ShoeGaze builder session. Swapped out when live input is enabled (the engine
|
||||||
|
/// is rebuilt with an input channel); the `@Observable` change re-binds the hosting view.
|
||||||
|
private(set) var shoeGaze: ShoeGaze
|
||||||
|
|
||||||
|
private var engine: SynthesisEngine
|
||||||
|
private var iosDriver: iOSAudioDriver
|
||||||
|
|
||||||
|
/// The sample rate the audio session actually committed to (for the config mismatch warning).
|
||||||
|
var hardwareSampleRate: Double? { iosDriver.sessionSampleRate }
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
init() {
|
||||||
|
ShoeGazeBuilderiOSAppModel.configureAudioSession()
|
||||||
|
let built: (engine: SynthesisEngine, driver: iOSAudioDriver, shoeGaze: ShoeGaze) =
|
||||||
|
ShoeGazeBuilderiOSAppModel.buildEngine(inputChannels: ShoeGazeBuilderiOSAppModel.inputChannels)
|
||||||
|
self.engine = built.engine
|
||||||
|
self.iosDriver = built.driver
|
||||||
|
self.shoeGaze = built.shoeGaze
|
||||||
|
|
||||||
|
do {
|
||||||
|
let board: PedalBoard = try shoeGaze.addBoard()
|
||||||
|
board.label = "Board 1"
|
||||||
|
try shoeGaze.appendPedal(ShoeGazeBuilderiOSAppModel.seedPedalType, to: board)
|
||||||
|
} catch {
|
||||||
|
print("[ShoeGazeBuilderiOS] seed board failed: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Audio session / engine construction
|
||||||
|
|
||||||
|
/// Activates the play-and-record audio session once. Idempotent; safe to call before each
|
||||||
|
/// engine build. Activating the session does not by itself prompt for microphone access —
|
||||||
|
/// the prompt only fires when an input-enabled engine first starts.
|
||||||
|
private static func configureAudioSession() {
|
||||||
|
let session: AVAudioSession = AVAudioSession.sharedInstance()
|
||||||
|
do {
|
||||||
|
try session.setCategory(.playAndRecord,
|
||||||
|
mode: .default,
|
||||||
|
options: [.defaultToSpeaker, .allowBluetoothHFP])
|
||||||
|
try session.setActive(true)
|
||||||
|
} catch {
|
||||||
|
print("[ShoeGazeBuilderiOS] AVAudioSession setup failed: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builds a fresh engine + driver + empty `ShoeGaze` with the given input-channel count.
|
||||||
|
private static func buildEngine(
|
||||||
|
inputChannels: Int
|
||||||
|
) -> (engine: SynthesisEngine, driver: iOSAudioDriver, shoeGaze: ShoeGaze) {
|
||||||
|
let sampleRate: Double = AVAudioSession.sharedInstance().sampleRate
|
||||||
|
let driver: iOSAudioDriver = iOSAudioDriver()
|
||||||
|
let engine: SynthesisEngine = SynthesisEngine(
|
||||||
|
blockSize: ShoeGazeBuilderiOSAppModel.blockSize,
|
||||||
|
sampleRate: sampleRate,
|
||||||
|
numOutputChannels: ShoeGazeBuilderiOSAppModel.outputChannels,
|
||||||
|
numInputChannels: inputChannels,
|
||||||
|
numAudioBuses: ShoeGazeBuilderiOSAppModel.numAudioBuses,
|
||||||
|
driver: driver
|
||||||
|
)
|
||||||
|
return (engine, driver, ShoeGaze(engine: engine))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Live input
|
||||||
|
|
||||||
|
/// Enables live input on iOS: requests microphone access, then (on grant) rebuilds the
|
||||||
|
/// engine with one input channel — preserving the current rig — and selects live input.
|
||||||
|
///
|
||||||
|
/// The rebuild is required because the input-channel count is fixed at engine construction,
|
||||||
|
/// and constructing with an input channel up-front would make iOS prompt for the microphone
|
||||||
|
/// at the first Start even in test-loop mode. Gating the rebuild behind an explicit request
|
||||||
|
/// keeps the prompt where the user expects it.
|
||||||
|
func enableLiveInput() {
|
||||||
|
MicrophonePermission.request { [weak self] granted in
|
||||||
|
guard let self, granted else { return }
|
||||||
|
self.rebuildWithLiveInput()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Snapshots the rig, rebuilds the engine with one input channel, restores the rig, and
|
||||||
|
/// selects live input on channel 0. No-op if the engine already has an input channel.
|
||||||
|
private func rebuildWithLiveInput() {
|
||||||
|
guard engine.numInputChannels == 0 else {
|
||||||
|
// Engine already has an input channel: just select live input, no rebuild.
|
||||||
|
selectLiveInputAndPersist()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let wasRunning: Bool = engine.isRunning
|
||||||
|
|
||||||
|
// Snapshot the rig BEFORE any teardown. If this fails, abort the rebuild rather than
|
||||||
|
// tear the engine down and lose the rig — the user stays on the current engine.
|
||||||
|
let snapshot: Data
|
||||||
|
do {
|
||||||
|
snapshot = try shoeGaze.rigData()
|
||||||
|
} catch {
|
||||||
|
print("[ShoeGazeBuilderiOS] rig snapshot failed; aborting live-input rebuild: \(error)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
engine.stop()
|
||||||
|
shoeGaze.teardown()
|
||||||
|
|
||||||
|
ShoeGazeBuilderiOSAppModel.configureAudioSession()
|
||||||
|
let rebuilt: (engine: SynthesisEngine, driver: iOSAudioDriver, shoeGaze: ShoeGaze) =
|
||||||
|
ShoeGazeBuilderiOSAppModel.buildEngine(inputChannels: 1)
|
||||||
|
self.engine = rebuilt.engine
|
||||||
|
self.iosDriver = rebuilt.driver
|
||||||
|
self.shoeGaze = rebuilt.shoeGaze
|
||||||
|
|
||||||
|
do {
|
||||||
|
// Teardown already happened, so a restore failure can only recover by seeding.
|
||||||
|
try shoeGaze.loadRig(from: snapshot)
|
||||||
|
} catch {
|
||||||
|
print("[ShoeGazeBuilderiOS] rig restore after rebuild failed: \(error)")
|
||||||
|
seedFallbackBoard()
|
||||||
|
}
|
||||||
|
|
||||||
|
selectLiveInputAndPersist()
|
||||||
|
|
||||||
|
if wasRunning { try? engine.start() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Selects live input on channel 0 and persists the choice for restore-on-relaunch.
|
||||||
|
private func selectLiveInputAndPersist() {
|
||||||
|
do {
|
||||||
|
try shoeGaze.setInputSource(.liveInput(channel: 0))
|
||||||
|
UserDefaults.standard.set(
|
||||||
|
ShoeGazeBuilderiOSAppModel.liveInputChannelZeroTag,
|
||||||
|
forKey: ShoeGazeBuilderiOSAppModel.inputSelectionDefaultsKey
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
print("[ShoeGazeBuilderiOS] selecting live input failed: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Seeds a single default board so the rig is never empty after a failed restore.
|
||||||
|
private func seedFallbackBoard() {
|
||||||
|
do {
|
||||||
|
let board: PedalBoard = try shoeGaze.addBoard()
|
||||||
|
board.label = "Board 1"
|
||||||
|
try shoeGaze.appendPedal(ShoeGazeBuilderiOSAppModel.seedPedalType, to: board)
|
||||||
|
} catch {
|
||||||
|
print("[ShoeGazeBuilderiOS] fallback seed board failed: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Transport
|
||||||
|
|
||||||
|
/// Stops the audio engine. Call from `.onDisappear`.
|
||||||
|
func stop() {
|
||||||
|
engine.stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,14 +7,15 @@
|
|||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
C3B0000000000000000000C /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B000000000000000000007 /* main.swift */; };
|
|
||||||
C3B0000000000000000000D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B000000000000000000008 /* AppDelegate.swift */; };
|
|
||||||
C3B0000000000000000000E /* DemoRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B000000000000000000009 /* DemoRootView.swift */; };
|
|
||||||
C3B0000000000000000000F /* ShoeGazeDemoController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B00000000000000000000A /* ShoeGazeDemoController.swift */; };
|
|
||||||
C3B000000000000000000020 /* LyrebirdShoeGaze in Frameworks */ = {isa = PBXBuildFile; productRef = C3B00000000000000000001E /* LyrebirdShoeGaze */; };
|
C3B000000000000000000020 /* LyrebirdShoeGaze in Frameworks */ = {isa = PBXBuildFile; productRef = C3B00000000000000000001E /* LyrebirdShoeGaze */; };
|
||||||
C3B000000000000000000021 /* LyrebirdShoeGazeUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3B00000000000000000001F /* LyrebirdShoeGazeUI */; };
|
C3B000000000000000000021 /* LyrebirdShoeGazeUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3B00000000000000000001F /* LyrebirdShoeGazeUI */; };
|
||||||
C3B000000000000000000022 /* Lyrebird in Frameworks */ = {isa = PBXBuildFile; productRef = C3B000000000000000000023 /* Lyrebird */; };
|
C3B000000000000000000022 /* Lyrebird in Frameworks */ = {isa = PBXBuildFile; productRef = C3B000000000000000000023 /* Lyrebird */; };
|
||||||
C3B000000000000000000024 /* LyrebirdUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3B000000000000000000025 /* LyrebirdUI */; };
|
C3B000000000000000000024 /* LyrebirdUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3B000000000000000000025 /* LyrebirdUI */; };
|
||||||
|
C3B000000000000000000031 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C3B000000000000000000030 /* Assets.xcassets */; };
|
||||||
|
C3B0000000000000000000C /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B000000000000000000007 /* main.swift */; };
|
||||||
|
C3B0000000000000000000D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B000000000000000000008 /* AppDelegate.swift */; };
|
||||||
|
C3B0000000000000000000E /* DemoRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B000000000000000000009 /* DemoRootView.swift */; };
|
||||||
|
C3B0000000000000000000F /* ShoeGazeDemoController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B00000000000000000000A /* ShoeGazeDemoController.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
@@ -24,6 +25,7 @@
|
|||||||
C3B000000000000000000008 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
C3B000000000000000000008 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||||
C3B000000000000000000009 /* DemoRootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoRootView.swift; sourceTree = "<group>"; };
|
C3B000000000000000000009 /* DemoRootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoRootView.swift; sourceTree = "<group>"; };
|
||||||
C3B00000000000000000000A /* ShoeGazeDemoController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoeGazeDemoController.swift; sourceTree = "<group>"; };
|
C3B00000000000000000000A /* ShoeGazeDemoController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoeGazeDemoController.swift; sourceTree = "<group>"; };
|
||||||
|
C3B000000000000000000030 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@@ -64,6 +66,7 @@
|
|||||||
C3B000000000000000000008 /* AppDelegate.swift */,
|
C3B000000000000000000008 /* AppDelegate.swift */,
|
||||||
C3B000000000000000000009 /* DemoRootView.swift */,
|
C3B000000000000000000009 /* DemoRootView.swift */,
|
||||||
C3B00000000000000000000A /* ShoeGazeDemoController.swift */,
|
C3B00000000000000000000A /* ShoeGazeDemoController.swift */,
|
||||||
|
C3B000000000000000000030 /* Assets.xcassets */,
|
||||||
C3B000000000000000000006 /* Info.plist */,
|
C3B000000000000000000006 /* Info.plist */,
|
||||||
);
|
);
|
||||||
path = ShoeGazeDemo;
|
path = ShoeGazeDemo;
|
||||||
@@ -137,6 +140,7 @@
|
|||||||
isa = PBXResourcesBuildPhase;
|
isa = PBXResourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
C3B000000000000000000031 /* Assets.xcassets in Resources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@@ -160,14 +164,17 @@
|
|||||||
C3B000000000000000000016 /* Debug */ = {
|
C3B000000000000000000016 /* Debug */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
CODE_SIGN_STYLE = Automatic;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGNING_REQUIRED = NO;
|
CODE_SIGNING_REQUIRED = NO;
|
||||||
|
CODE_SIGN_ENTITLEMENTS = ShoeGazeDemo/ShoeGazeDemo.entitlements;
|
||||||
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
DEAD_CODE_STRIPPING = YES;
|
DEAD_CODE_STRIPPING = YES;
|
||||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||||
DEVELOPMENT_TEAM = "";
|
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
INFOPLIST_FILE = ShoeGazeDemo/Info.plist;
|
INFOPLIST_FILE = ShoeGazeDemo/Info.plist;
|
||||||
|
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
@@ -183,13 +190,16 @@
|
|||||||
C3B000000000000000000017 /* Release */ = {
|
C3B000000000000000000017 /* Release */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
CODE_SIGN_STYLE = Automatic;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGNING_REQUIRED = NO;
|
CODE_SIGNING_REQUIRED = NO;
|
||||||
|
CODE_SIGN_ENTITLEMENTS = ShoeGazeDemo/ShoeGazeDemo.entitlements;
|
||||||
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
DEAD_CODE_STRIPPING = YES;
|
DEAD_CODE_STRIPPING = YES;
|
||||||
DEVELOPMENT_TEAM = "";
|
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
INFOPLIST_FILE = ShoeGazeDemo/Info.plist;
|
INFOPLIST_FILE = ShoeGazeDemo/Info.plist;
|
||||||
|
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
private static let blockSize: Int = 512
|
private static let blockSize: Int = 512
|
||||||
private static let sampleRate: Double = 48_000.0
|
private static let sampleRate: Double = 48_000.0
|
||||||
private static let outputChannels: Int = 2
|
private static let outputChannels: Int = 2
|
||||||
private static let inputChannels: Int = 6
|
// Built-in mics are mono; default to one input channel so live input works out of the box
|
||||||
|
// (CoreAudio can't satisfy more input channels than the device provides). Raise in the UI.
|
||||||
|
private static let inputChannels: Int = 1
|
||||||
private static let numAudioBuses: Int = 256
|
private static let numAudioBuses: Int = 256
|
||||||
|
|
||||||
// MARK: - Window geometry constants
|
// MARK: - Window geometry constants
|
||||||
@@ -37,6 +39,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
|
|
||||||
// MARK: - Owned objects
|
// MARK: - Owned objects
|
||||||
|
|
||||||
|
private let coreDriver: CoreAudioDriver
|
||||||
private let controller: ShoeGazeDemoController
|
private let controller: ShoeGazeDemoController
|
||||||
private let window: LyrebirdWindow
|
private let window: LyrebirdWindow
|
||||||
|
|
||||||
@@ -46,15 +49,17 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
// MARK: - Init
|
// MARK: - Init
|
||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
|
let coreDriver: CoreAudioDriver = CoreAudioDriver()
|
||||||
let engine: SynthesisEngine = SynthesisEngine(
|
let engine: SynthesisEngine = SynthesisEngine(
|
||||||
blockSize: AppDelegate.blockSize,
|
blockSize: AppDelegate.blockSize,
|
||||||
sampleRate: AppDelegate.sampleRate,
|
sampleRate: AppDelegate.sampleRate,
|
||||||
numOutputChannels: AppDelegate.outputChannels,
|
numOutputChannels: AppDelegate.outputChannels,
|
||||||
numInputChannels: AppDelegate.inputChannels,
|
numInputChannels: AppDelegate.inputChannels,
|
||||||
numAudioBuses: AppDelegate.numAudioBuses,
|
numAudioBuses: AppDelegate.numAudioBuses,
|
||||||
driver: CoreAudioDriver()
|
driver: coreDriver
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.coreDriver = coreDriver
|
||||||
self.controller = ShoeGazeDemoController(engine: engine)
|
self.controller = ShoeGazeDemoController(engine: engine)
|
||||||
self.window = LyrebirdWindow(
|
self.window = LyrebirdWindow(
|
||||||
title: "ShoeGaze — Lyrebird Guitar Pedalboard",
|
title: "ShoeGaze — Lyrebird Guitar Pedalboard",
|
||||||
@@ -69,8 +74,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||||
installMainMenu()
|
installMainMenu()
|
||||||
let demoController: ShoeGazeDemoController = controller
|
let demoController: ShoeGazeDemoController = controller
|
||||||
|
let driver: CoreAudioDriver = coreDriver
|
||||||
window.open {
|
window.open {
|
||||||
DemoRootView(controller: demoController)
|
DemoRootView(controller: demoController, hardwareSampleRate: { driver.deviceSampleRate })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{"size":"16x16","idiom":"mac","filename":"icon_16x16.png","scale":"1x"},
|
||||||
|
{"size":"16x16","idiom":"mac","filename":"icon_16x16@2x.png","scale":"2x"},
|
||||||
|
{"size":"32x32","idiom":"mac","filename":"icon_32x32.png","scale":"1x"},
|
||||||
|
{"size":"32x32","idiom":"mac","filename":"icon_32x32@2x.png","scale":"2x"},
|
||||||
|
{"size":"128x128","idiom":"mac","filename":"icon_128x128.png","scale":"1x"},
|
||||||
|
{"size":"128x128","idiom":"mac","filename":"icon_128x128@2x.png","scale":"2x"},
|
||||||
|
{"size":"256x256","idiom":"mac","filename":"icon_256x256.png","scale":"1x"},
|
||||||
|
{"size":"256x256","idiom":"mac","filename":"icon_256x256@2x.png","scale":"2x"},
|
||||||
|
{"size":"512x512","idiom":"mac","filename":"icon_512x512.png","scale":"1x"},
|
||||||
|
{"size":"512x512","idiom":"mac","filename":"icon_512x512@2x.png","scale":"2x"}
|
||||||
|
],
|
||||||
|
"info" : {"author":"xcode","version":1}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 91 KiB |
|
After Width: | Height: | Size: 782 B |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 91 KiB |
|
After Width: | Height: | Size: 345 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 6.9 KiB |
|
After Width: | Height: | Size: 345 KiB |
|
After Width: | Height: | Size: 1.2 MiB |
@@ -0,0 +1 @@
|
|||||||
|
{ "info" : {"author":"xcode","version":1} }
|
||||||
@@ -47,6 +47,7 @@ struct DemoRootView: View {
|
|||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
|
|
||||||
private let controller: ShoeGazeDemoController
|
private let controller: ShoeGazeDemoController
|
||||||
|
private let hardwareSampleRate: () -> Double?
|
||||||
|
|
||||||
/// Bumped on each transport press so the buttons re-read `controller.isRunning`
|
/// Bumped on each transport press so the buttons re-read `controller.isRunning`
|
||||||
/// (which derives from the non-observable engine).
|
/// (which derives from the non-observable engine).
|
||||||
@@ -56,10 +57,17 @@ struct DemoRootView: View {
|
|||||||
|
|
||||||
/// Creates the root demo view bound to the given controller.
|
/// Creates the root demo view bound to the given controller.
|
||||||
///
|
///
|
||||||
/// - Parameter controller: The `ShoeGazeDemoController` that owns the engine, active
|
/// - Parameters:
|
||||||
/// `ShoeGaze` session, and current mode. All toolbar actions dispatch through this.
|
/// - controller: The `ShoeGazeDemoController` that owns the engine, active `ShoeGaze`
|
||||||
init(controller: ShoeGazeDemoController) {
|
/// session, and current mode. All toolbar actions dispatch through this.
|
||||||
|
/// - hardwareSampleRate: Returns the actual hardware sample rate (or `nil`), for the engine-
|
||||||
|
/// config mismatch warning. Defaults to `nil`.
|
||||||
|
init(
|
||||||
|
controller: ShoeGazeDemoController,
|
||||||
|
hardwareSampleRate: @escaping () -> Double? = { nil }
|
||||||
|
) {
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
|
self.hardwareSampleRate = hardwareSampleRate
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Body
|
// MARK: - Body
|
||||||
@@ -71,6 +79,10 @@ struct DemoRootView: View {
|
|||||||
.overlay(Color.white.opacity(DemoRootView.dividerOpacity))
|
.overlay(Color.white.opacity(DemoRootView.dividerOpacity))
|
||||||
contentArea
|
contentArea
|
||||||
.padding(DemoRootView.contentPadding)
|
.padding(DemoRootView.contentPadding)
|
||||||
|
Divider()
|
||||||
|
.overlay(Color.white.opacity(DemoRootView.dividerOpacity))
|
||||||
|
ShoeGazeScopeView(shoeGaze: controller.shoeGaze)
|
||||||
|
.padding(DemoRootView.contentPadding)
|
||||||
}
|
}
|
||||||
.frame(
|
.frame(
|
||||||
minWidth: DemoRootView.windowMinWidth,
|
minWidth: DemoRootView.windowMinWidth,
|
||||||
@@ -83,6 +95,18 @@ struct DemoRootView: View {
|
|||||||
blue: DemoRootView.backgroundBlue
|
blue: DemoRootView.backgroundBlue
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
.alert(
|
||||||
|
"Microphone Access Needed",
|
||||||
|
isPresented: Binding(
|
||||||
|
get: { controller.microphoneAccessDenied },
|
||||||
|
set: { controller.microphoneAccessDenied = $0 }
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Button("OK", role: .cancel) { }
|
||||||
|
} message: {
|
||||||
|
Text("Live input needs microphone access. Enable it in System Settings › Privacy & "
|
||||||
|
+ "Security › Microphone, then select the input again.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Toolbar
|
// MARK: - Toolbar
|
||||||
@@ -157,7 +181,7 @@ struct DemoRootView: View {
|
|||||||
.foregroundStyle(Color.white.opacity(0.65))
|
.foregroundStyle(Color.white.opacity(0.65))
|
||||||
Picker("Input", selection: inputSourceBinding) {
|
Picker("Input", selection: inputSourceBinding) {
|
||||||
Text("Test Loop").tag(-1)
|
Text("Test Loop").tag(-1)
|
||||||
ForEach(0..<controller.engine.numInputChannels, id: \.self) { channel in
|
ForEach(Array(0..<max(0, controller.engine.numInputChannels)), id: \.self) { channel in
|
||||||
Text("In \(channel)").tag(channel)
|
Text("In \(channel)").tag(channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,29 +190,20 @@ struct DemoRootView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start and Stop transport buttons.
|
/// Engine configuration + transport (sample rate, ins/outs, Start/Stop, mismatch alert).
|
||||||
private var transportButtons: some View {
|
private var transportButtons: some View {
|
||||||
// `controller.isRunning` derives from the engine; toggling the tick on press
|
EngineConfigView(
|
||||||
// re-evaluates this view so the buttons reflect the change immediately.
|
shoeGaze: controller.shoeGaze,
|
||||||
_ = transportTick
|
hardwareSampleRate: hardwareSampleRate,
|
||||||
let isRunning: Bool = controller.isRunning
|
applyConfig: { rate, inputs, outputs in
|
||||||
return HStack(spacing: DemoRootView.toolbarSpacing) {
|
try controller.reconfigure(
|
||||||
Button("Start") {
|
sampleRate: rate,
|
||||||
controller.start()
|
inputChannels: inputs,
|
||||||
transportTick.toggle()
|
outputChannels: outputs
|
||||||
}
|
)
|
||||||
.buttonStyle(.borderedProminent)
|
},
|
||||||
.tint(.green)
|
onConfigApplied: { transportTick.toggle() }
|
||||||
.disabled(isRunning)
|
)
|
||||||
|
|
||||||
Button("Stop") {
|
|
||||||
controller.stop()
|
|
||||||
transportTick.toggle()
|
|
||||||
}
|
|
||||||
.buttonStyle(.bordered)
|
|
||||||
.tint(.red)
|
|
||||||
.disabled(!isRunning)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Content area
|
// MARK: - Content area
|
||||||
@@ -198,7 +213,7 @@ struct DemoRootView: View {
|
|||||||
private var contentArea: some View {
|
private var contentArea: some View {
|
||||||
switch controller.mode {
|
switch controller.mode {
|
||||||
case .boards:
|
case .boards:
|
||||||
ShoeGazeView(shoeGaze: controller.shoeGaze)
|
ShoeGazeView(shoeGaze: controller.shoeGaze, hardwareSampleRate: hardwareSampleRate)
|
||||||
|
|
||||||
case .editor:
|
case .editor:
|
||||||
editorContent
|
editorContent
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<key>NSHighResolutionCapable</key>
|
<key>NSHighResolutionCapable</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSHumanReadableCopyright</key>
|
<key>NSHumanReadableCopyright</key>
|
||||||
<string>Copyright © 2026 Realized Sound. All rights reserved.</string>
|
<string>Copyright © 2026 realizedsound. All rights reserved.</string>
|
||||||
<key>NSMicrophoneUsageDescription</key>
|
<key>NSMicrophoneUsageDescription</key>
|
||||||
<string>ShoeGazeDemo can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode.</string>
|
<string>ShoeGazeDemo can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode.</string>
|
||||||
<key>NSPrincipalClass</key>
|
<key>NSPrincipalClass</key>
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>com.apple.security.device.audio-input</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
@@ -127,9 +127,29 @@ final class ShoeGazeDemoController {
|
|||||||
|
|
||||||
/// Changes the input source policy and triggers a full rebuild.
|
/// Changes the input source policy and triggers a full rebuild.
|
||||||
///
|
///
|
||||||
|
/// Live input requires microphone authorisation first — without it macOS feeds the AUHAL input
|
||||||
|
/// silent zeros. The request is asynchronous, so `.liveInput` is applied only once the grant
|
||||||
|
/// resolves; a denial falls back to the test loop.
|
||||||
|
///
|
||||||
/// - Parameter source: `.testLoop` for the built-in test signal or `.liveInput(channel:)`
|
/// - Parameter source: `.testLoop` for the built-in test signal or `.liveInput(channel:)`
|
||||||
/// for hardware microphone/instrument input on the given channel.
|
/// for hardware microphone/instrument input on the given channel.
|
||||||
func setInputSource(_ source: InputSource) {
|
func setInputSource(_ source: InputSource) {
|
||||||
|
guard case .liveInput = source else {
|
||||||
|
applyInputSource(source)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
MicrophonePermission.request { [weak self] granted in
|
||||||
|
if !granted { self?.microphoneAccessDenied = true }
|
||||||
|
self?.applyInputSource(granted ? source : .testLoop)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set when live input is requested but microphone access is denied/restricted. The UI observes
|
||||||
|
/// this and presents an alert, then clears it.
|
||||||
|
var microphoneAccessDenied: Bool = false
|
||||||
|
|
||||||
|
/// Applies an input-source change and triggers a full rebuild.
|
||||||
|
private func applyInputSource(_ source: InputSource) {
|
||||||
inputSource = source
|
inputSource = source
|
||||||
rebuild()
|
rebuild()
|
||||||
}
|
}
|
||||||
@@ -160,6 +180,34 @@ final class ShoeGazeDemoController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Engine reconfiguration
|
||||||
|
|
||||||
|
/// Applies new engine settings (while stopped) and rebuilds the current mode so the showcase
|
||||||
|
/// is reconstructed at the new sample rate / channel counts. Used by the engine-config UI.
|
||||||
|
///
|
||||||
|
/// Tears the session down BEFORE reconfiguring — changing channel counts re-partitions the bus
|
||||||
|
/// allocator, which would invalidate rig buses still allocated under the old layout.
|
||||||
|
///
|
||||||
|
/// - Throws: `SynthesisEngineConfigError` if the engine is running or a value is invalid.
|
||||||
|
func reconfigure(sampleRate: Double, inputChannels: Int, outputChannels: Int) throws {
|
||||||
|
let wasRunning: Bool = isRunning
|
||||||
|
if wasRunning { stop() }
|
||||||
|
|
||||||
|
tearDownSession()
|
||||||
|
try engine.setSampleRate(sampleRate)
|
||||||
|
try engine.setNumOutputChannels(outputChannels)
|
||||||
|
try engine.setNumInputChannels(inputChannels)
|
||||||
|
// A live-input source past the new channel count would make rebuild fail; fall back.
|
||||||
|
if case .liveInput(let channel) = inputSource, channel >= inputChannels {
|
||||||
|
inputSource = .testLoop
|
||||||
|
}
|
||||||
|
buildSession()
|
||||||
|
// `buildSession()` creates a fresh `ShoeGaze`, whose `init` installs the scope tap for the
|
||||||
|
// new channel layout — no explicit `installScopeTap()` needed here.
|
||||||
|
|
||||||
|
if wasRunning { start() }
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Rebuild
|
// MARK: - Rebuild
|
||||||
|
|
||||||
/// Tears down the current session and rebuilds the active mode.
|
/// Tears down the current session and rebuilds the active mode.
|
||||||
@@ -169,14 +217,22 @@ final class ShoeGazeDemoController {
|
|||||||
private func rebuild() {
|
private func rebuild() {
|
||||||
let wasRunning: Bool = isRunning
|
let wasRunning: Bool = isRunning
|
||||||
if wasRunning { stop() }
|
if wasRunning { stop() }
|
||||||
|
tearDownSession()
|
||||||
|
buildSession()
|
||||||
|
if wasRunning { start() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes the current session's nodes and clears split/router references.
|
||||||
|
private func tearDownSession() {
|
||||||
shoeGaze.teardown()
|
shoeGaze.teardown()
|
||||||
router = nil
|
router = nil
|
||||||
parallelSection = nil
|
parallelSection = nil
|
||||||
stereoSection = nil
|
stereoSection = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a fresh session and builds the active mode's graph.
|
||||||
|
private func buildSession() {
|
||||||
shoeGaze = ShoeGaze(engine: engine, inputSource: inputSource)
|
shoeGaze = ShoeGaze(engine: engine, inputSource: inputSource)
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case .boards: buildBoards()
|
case .boards: buildBoards()
|
||||||
case .editor: buildEditor()
|
case .editor: buildEditor()
|
||||||
@@ -184,8 +240,6 @@ final class ShoeGazeDemoController {
|
|||||||
case .router: buildRouter()
|
case .router: buildRouter()
|
||||||
case .stereo: buildStereo()
|
case .stereo: buildStereo()
|
||||||
}
|
}
|
||||||
|
|
||||||
if wasRunning { start() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Mode builders
|
// MARK: - Mode builders
|
||||||
@@ -194,7 +248,7 @@ final class ShoeGazeDemoController {
|
|||||||
///
|
///
|
||||||
/// Board 1: Overdrive → Delay → Reverb → Modulation
|
/// Board 1: Overdrive → Delay → Reverb → Modulation
|
||||||
/// Board 2: Fuzz → Tremolo → Phaser → Compressor
|
/// Board 2: Fuzz → Tremolo → Phaser → Compressor
|
||||||
/// Board 3: Mu-Tron → Auto-Wah → Feedback Delay → Multi-Tap Delay
|
/// Board 3: Mutant → Auto-Wah → Feedback Delay → Multi-Tap Delay
|
||||||
private func buildBoards() {
|
private func buildBoards() {
|
||||||
do {
|
do {
|
||||||
let board1: PedalBoard = try shoeGaze.addBoard()
|
let board1: PedalBoard = try shoeGaze.addBoard()
|
||||||
@@ -215,7 +269,7 @@ final class ShoeGazeDemoController {
|
|||||||
|
|
||||||
let board3: PedalBoard = try shoeGaze.addBoard()
|
let board3: PedalBoard = try shoeGaze.addBoard()
|
||||||
board3.label = "Board 3"
|
board3.label = "Board 3"
|
||||||
try board3.add(MuTronPedal())
|
try board3.add(MutantPedal())
|
||||||
try board3.add(AutoWahPedal())
|
try board3.add(AutoWahPedal())
|
||||||
try board3.add(FeedbackDelayPedal())
|
try board3.add(FeedbackDelayPedal())
|
||||||
try board3.add(MultiTapDelayPedal())
|
try board3.add(MultiTapDelayPedal())
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
C3C00000000000000000000C /* LyrebirdShoeGazeUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3C00000000000000000001B /* LyrebirdShoeGazeUI */; };
|
C3C00000000000000000000C /* LyrebirdShoeGazeUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3C00000000000000000001B /* LyrebirdShoeGazeUI */; };
|
||||||
C3C00000000000000000000D /* LyrebirdUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3C00000000000000000001C /* LyrebirdUI */; };
|
C3C00000000000000000000D /* LyrebirdUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3C00000000000000000001C /* LyrebirdUI */; };
|
||||||
C3C00000000000000000001D /* Lyrebird in Frameworks */ = {isa = PBXBuildFile; productRef = C3C00000000000000000001E /* Lyrebird */; };
|
C3C00000000000000000001D /* Lyrebird in Frameworks */ = {isa = PBXBuildFile; productRef = C3C00000000000000000001E /* Lyrebird */; };
|
||||||
|
C3C000000000000000000031 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C3C000000000000000000030 /* Assets.xcassets */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
@@ -20,6 +21,7 @@
|
|||||||
C3C000000000000000000006 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
C3C000000000000000000006 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||||
C3C000000000000000000007 /* ShoeGazeiOSDemoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoeGazeiOSDemoApp.swift; sourceTree = "<group>"; };
|
C3C000000000000000000007 /* ShoeGazeiOSDemoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoeGazeiOSDemoApp.swift; sourceTree = "<group>"; };
|
||||||
C3C000000000000000000008 /* ShoeGazeiOSDemoAppModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoeGazeiOSDemoAppModel.swift; sourceTree = "<group>"; };
|
C3C000000000000000000008 /* ShoeGazeiOSDemoAppModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoeGazeiOSDemoAppModel.swift; sourceTree = "<group>"; };
|
||||||
|
C3C000000000000000000030 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
/* Begin PBXFrameworksBuildPhase section */
|
||||||
@@ -58,6 +60,7 @@
|
|||||||
children = (
|
children = (
|
||||||
C3C000000000000000000007 /* ShoeGazeiOSDemoApp.swift */,
|
C3C000000000000000000007 /* ShoeGazeiOSDemoApp.swift */,
|
||||||
C3C000000000000000000008 /* ShoeGazeiOSDemoAppModel.swift */,
|
C3C000000000000000000008 /* ShoeGazeiOSDemoAppModel.swift */,
|
||||||
|
C3C000000000000000000030 /* Assets.xcassets */,
|
||||||
C3C000000000000000000006 /* Info.plist */,
|
C3C000000000000000000006 /* Info.plist */,
|
||||||
);
|
);
|
||||||
path = ShoeGazeiOSDemo;
|
path = ShoeGazeiOSDemo;
|
||||||
@@ -131,6 +134,7 @@
|
|||||||
isa = PBXResourcesBuildPhase;
|
isa = PBXResourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
C3C000000000000000000031 /* Assets.xcassets in Resources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
@@ -152,11 +156,13 @@
|
|||||||
C3C000000000000000000013 /* Debug */ = {
|
C3C000000000000000000013 /* Debug */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
CODE_SIGN_STYLE = Automatic;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGNING_REQUIRED = NO;
|
CODE_SIGNING_REQUIRED = NO;
|
||||||
|
CODE_SIGN_STYLE = Automatic;
|
||||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||||
DEVELOPMENT_TEAM = "";
|
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||||
INFOPLIST_FILE = ShoeGazeiOSDemo/Info.plist;
|
INFOPLIST_FILE = ShoeGazeiOSDemo/Info.plist;
|
||||||
|
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
@@ -168,17 +174,19 @@
|
|||||||
SUPPORTS_MACCATALYST = NO;
|
SUPPORTS_MACCATALYST = NO;
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
SWIFT_VERSION = 6.0;
|
SWIFT_VERSION = 6.0;
|
||||||
TARGETED_DEVICE_FAMILY = "1,2";
|
TARGETED_DEVICE_FAMILY = 2;
|
||||||
};
|
};
|
||||||
name = Debug;
|
name = Debug;
|
||||||
};
|
};
|
||||||
C3C000000000000000000014 /* Release */ = {
|
C3C000000000000000000014 /* Release */ = {
|
||||||
isa = XCBuildConfiguration;
|
isa = XCBuildConfiguration;
|
||||||
buildSettings = {
|
buildSettings = {
|
||||||
CODE_SIGN_STYLE = Automatic;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGNING_REQUIRED = NO;
|
CODE_SIGNING_REQUIRED = NO;
|
||||||
DEVELOPMENT_TEAM = "";
|
CODE_SIGN_STYLE = Automatic;
|
||||||
|
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||||
INFOPLIST_FILE = ShoeGazeiOSDemo/Info.plist;
|
INFOPLIST_FILE = ShoeGazeiOSDemo/Info.plist;
|
||||||
|
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
|
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
LD_RUNPATH_SEARCH_PATHS = (
|
||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
@@ -190,7 +198,7 @@
|
|||||||
SUPPORTS_MACCATALYST = NO;
|
SUPPORTS_MACCATALYST = NO;
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
SWIFT_VERSION = 6.0;
|
SWIFT_VERSION = 6.0;
|
||||||
TARGETED_DEVICE_FAMILY = "1,2";
|
TARGETED_DEVICE_FAMILY = 2;
|
||||||
};
|
};
|
||||||
name = Release;
|
name = Release;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"originHash" : "cfdd71f4b32d744c862bbe26a8265d75aa9e906275b0fb1b63575b7d68be1b6a",
|
||||||
|
"pins" : [
|
||||||
|
{
|
||||||
|
"identity" : "linenoise-swift",
|
||||||
|
"kind" : "remoteSourceControl",
|
||||||
|
"location" : "https://github.com/andybest/linenoise-swift",
|
||||||
|
"state" : {
|
||||||
|
"revision" : "afc897c02b030af7333105c4fedcd843a8339238",
|
||||||
|
"version" : "0.0.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"identity" : "lyrebird",
|
||||||
|
"kind" : "remoteSourceControl",
|
||||||
|
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
|
||||||
|
"state" : {
|
||||||
|
"revision" : "032b7c39d351eba4029e8399e1ab1ee201e8bb5c",
|
||||||
|
"version" : "1.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"identity" : "nimble",
|
||||||
|
"kind" : "remoteSourceControl",
|
||||||
|
"location" : "https://github.com/Quick/Nimble.git",
|
||||||
|
"state" : {
|
||||||
|
"revision" : "e9d769113660769a4d9dd3afb855562c0b7ae7b0",
|
||||||
|
"version" : "7.3.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version" : 3
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{"filename":"icon_1024.png","idiom":"universal","platform":"ios","size":"1024x1024"}
|
||||||
|
],
|
||||||
|
"info" : {"author":"xcode","version":1}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 402 KiB |
@@ -0,0 +1 @@
|
|||||||
|
{ "info" : {"author":"xcode","version":1} }
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSHumanReadableCopyright</key>
|
<key>NSHumanReadableCopyright</key>
|
||||||
<string>Copyright © 2026 Realized Sound. All rights reserved.</string>
|
<string>Copyright © 2026 realizedsound. All rights reserved.</string>
|
||||||
<key>NSMicrophoneUsageDescription</key>
|
<key>NSMicrophoneUsageDescription</key>
|
||||||
<string>ShoeGazeiOSDemo can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode.</string>
|
<string>ShoeGazeiOSDemo can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode.</string>
|
||||||
<key>UIApplicationSceneManifest</key>
|
<key>UIApplicationSceneManifest</key>
|
||||||
@@ -29,16 +29,15 @@
|
|||||||
</dict>
|
</dict>
|
||||||
<key>UILaunchScreen</key>
|
<key>UILaunchScreen</key>
|
||||||
<dict/>
|
<dict/>
|
||||||
|
<key>UIRequiresFullScreen</key>
|
||||||
|
<true/>
|
||||||
<key>UISupportedInterfaceOrientations</key>
|
<key>UISupportedInterfaceOrientations</key>
|
||||||
<array>
|
<array>
|
||||||
<string>UIInterfaceOrientationPortrait</string>
|
|
||||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||||
</array>
|
</array>
|
||||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||||
<array>
|
<array>
|
||||||
<string>UIInterfaceOrientationPortrait</string>
|
|
||||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
|
||||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||||
</array>
|
</array>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ struct ShoeGazeiOSDemoApp: App {
|
|||||||
WindowGroup {
|
WindowGroup {
|
||||||
NavigationStack {
|
NavigationStack {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
ShoeGazeView(shoeGaze: model.shoeGaze)
|
ShoeGazeView(shoeGaze: model.shoeGaze, hardwareSampleRate: { model.hardwareSampleRate })
|
||||||
.padding(.horizontal, 12)
|
.padding(.horizontal, 12)
|
||||||
}
|
}
|
||||||
.navigationTitle("ShoeGaze")
|
.navigationTitle("ShoeGaze")
|
||||||
|
|||||||
@@ -41,6 +41,10 @@ final class ShoeGazeiOSDemoAppModel {
|
|||||||
private(set) var shoeGaze: ShoeGaze
|
private(set) var shoeGaze: ShoeGaze
|
||||||
|
|
||||||
private let engine: SynthesisEngine
|
private let engine: SynthesisEngine
|
||||||
|
private let iosDriver: iOSAudioDriver
|
||||||
|
|
||||||
|
/// The sample rate the audio session actually committed to (for the config mismatch warning).
|
||||||
|
var hardwareSampleRate: Double? { iosDriver.sessionSampleRate }
|
||||||
|
|
||||||
// MARK: - Init
|
// MARK: - Init
|
||||||
|
|
||||||
@@ -54,14 +58,16 @@ final class ShoeGazeiOSDemoAppModel {
|
|||||||
try? session.setActive(true)
|
try? session.setActive(true)
|
||||||
let sampleRate: Double = session.sampleRate
|
let sampleRate: Double = session.sampleRate
|
||||||
|
|
||||||
|
let driver: iOSAudioDriver = iOSAudioDriver()
|
||||||
let eng: SynthesisEngine = SynthesisEngine(
|
let eng: SynthesisEngine = SynthesisEngine(
|
||||||
blockSize: ShoeGazeiOSDemoAppModel.blockSize,
|
blockSize: ShoeGazeiOSDemoAppModel.blockSize,
|
||||||
sampleRate: sampleRate,
|
sampleRate: sampleRate,
|
||||||
numOutputChannels: ShoeGazeiOSDemoAppModel.outputChannels,
|
numOutputChannels: ShoeGazeiOSDemoAppModel.outputChannels,
|
||||||
numInputChannels: 0,
|
numInputChannels: 0,
|
||||||
numAudioBuses: ShoeGazeiOSDemoAppModel.numAudioBuses,
|
numAudioBuses: ShoeGazeiOSDemoAppModel.numAudioBuses,
|
||||||
driver: iOSAudioDriver()
|
driver: driver
|
||||||
)
|
)
|
||||||
|
self.iosDriver = driver
|
||||||
self.engine = eng
|
self.engine = eng
|
||||||
self.shoeGaze = ShoeGaze(engine: eng)
|
self.shoeGaze = ShoeGaze(engine: eng)
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,117 @@
|
|||||||
# ShoeGaze
|
# ShoeGaze
|
||||||
|
|
||||||
A package depenedent on Lyrebird for creating and storing virtual Guitar Pedal Boards
|
**A virtual guitar-pedalboard framework for macOS and iPadOS, built on [Lyrebird](https://realizedsound.mooo.com/josh/Lyrebird).**
|
||||||
|
|
||||||
|
ShoeGaze turns Lyrebird's real-time synthesis engine into a stompbox rig: chain modeled
|
||||||
|
guitar pedals into one or more signal-flow boards, tweak them live with knobs and switches,
|
||||||
|
mix or switch between boards, and save the whole rig to disk. Run it on a synthesized test
|
||||||
|
signal (no hardware needed) or on live guitar through an audio input.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **18 modeled pedals** across drive, dynamics, EQ/filter, modulation, delay/reverb, and
|
||||||
|
pitch — see the catalog below.
|
||||||
|
- **Multi-board rigs** — build several boards and a board-mixer bar to **Solo** one (amp-channel
|
||||||
|
style) or **Blend** any subset, each with its own level and a click-free crossfade.
|
||||||
|
- **Signal-flow editor** — drag pedals in from the palette; reorder, split into parallel or
|
||||||
|
stereo lanes, and merge back to mono.
|
||||||
|
- **Save / load rigs** as JSON, on both platforms.
|
||||||
|
- **Recording** — capture your output to timestamped files.
|
||||||
|
- **Test signal or live input** — a built-in arpeggiated test loop (shared across all boards so
|
||||||
|
they stay phase-locked) or a hardware input channel.
|
||||||
|
- **SwiftUI views** — a complete stompbox UI (`LyrebirdShoeGazeUI`) or just the headless
|
||||||
|
framework (`LyrebirdShoeGaze`) to drive your own interface.
|
||||||
|
|
||||||
|
## Pedal catalog
|
||||||
|
|
||||||
|
| Category | Pedals |
|
||||||
|
|---|---|
|
||||||
|
| Drive & dynamics | Overdrive, Fuzz, Compressor, Limiter, Noise Gate |
|
||||||
|
| EQ & filter | Graphic EQ, Auto-Wah, Mutant, Phaser |
|
||||||
|
| Modulation | Tremolo, Modulation |
|
||||||
|
| Delay & reverb | Delay, Feedback Delay, Multi-Tap Delay, Ping-Pong, Reverb |
|
||||||
|
| Pitch & octave | Octave Splitter, Bass Octaver |
|
||||||
|
|
||||||
|
Every pedal exposes its parameters as knobs/switches and round-trips through the rig save format.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- macOS 15+ / iPadOS 18+ (iPad, landscape)
|
||||||
|
- Swift 6.0 toolchain / Xcode 16+
|
||||||
|
- [Lyrebird](https://realizedsound.mooo.com/josh/Lyrebird) 1.2.0+
|
||||||
|
|
||||||
|
## Packages
|
||||||
|
|
||||||
|
Two library products:
|
||||||
|
|
||||||
|
- **`LyrebirdShoeGaze`** — the core pedal/board framework (no SwiftUI).
|
||||||
|
- **`LyrebirdShoeGazeUI`** — SwiftUI pedalboard views (knobs, switches, faders, board mixer).
|
||||||
|
|
||||||
|
Add the dependency in your `Package.swift`:
|
||||||
|
|
||||||
|
```swift
|
||||||
|
.package(url: "https://realizedsound.mooo.com/josh/ShoeGaze", from: "1.0.0"),
|
||||||
|
```
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
Build a board and start the engine (macOS):
|
||||||
|
|
||||||
|
```swift
|
||||||
|
import Lyrebird
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
let driver = CoreAudioDriver()
|
||||||
|
let engine = SynthesisEngine(
|
||||||
|
blockSize: 512, sampleRate: 48_000,
|
||||||
|
numOutputChannels: 2, numInputChannels: 1,
|
||||||
|
numAudioBuses: 256, driver: driver
|
||||||
|
)
|
||||||
|
|
||||||
|
let shoeGaze = ShoeGaze(engine: engine) // defaults to the test-loop signal
|
||||||
|
let board = try shoeGaze.addBoard()
|
||||||
|
try shoeGaze.appendPedal(.overdrive, to: board)
|
||||||
|
try shoeGaze.appendPedal(.delay, to: board)
|
||||||
|
try shoeGaze.finalizeBoard(board)
|
||||||
|
|
||||||
|
try engine.start()
|
||||||
|
```
|
||||||
|
|
||||||
|
Drop in the full builder UI:
|
||||||
|
|
||||||
|
```swift
|
||||||
|
import SwiftUI
|
||||||
|
import LyrebirdShoeGazeUI
|
||||||
|
|
||||||
|
struct ContentView: View {
|
||||||
|
let shoeGaze: ShoeGaze
|
||||||
|
var body: some View {
|
||||||
|
ShoeGazeBuilderView(shoeGaze: shoeGaze)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Demo apps
|
||||||
|
|
||||||
|
Open `ShoeGaze.xcworkspace` in Xcode and run a scheme from `Demo/`:
|
||||||
|
|
||||||
|
- **ShoeGazeBuilder** (macOS) / **ShoeGazeBuilderiOS** (iPad) — the full palette + board builder.
|
||||||
|
- **ShoeGazeDemo** / **ShoeGazeiOSDemo** — a minimal player view.
|
||||||
|
|
||||||
|
## Screenshots
|
||||||
|
|
||||||
|
| macOS builder | Board mixer |
|
||||||
|
|---|---|
|
||||||
|
|  |  |
|
||||||
|
|
||||||
|
## Built on Lyrebird
|
||||||
|
|
||||||
|
ShoeGaze is a sample project for [Lyrebird](https://realizedsound.mooo.com/josh/Lyrebird), a
|
||||||
|
native Swift audio-synthesis framework. Pedals are Lyrebird `Synthesizer` graphs of `Generator`
|
||||||
|
nodes; the board/engine plumbing handles real-time-safe signal routing and scheduling.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT — see [LICENSE](LICENSE).
|
||||||
|
|||||||
@@ -10,4 +10,10 @@
|
|||||||
<FileRef
|
<FileRef
|
||||||
location = "group:Demo/ShoeGazeiOSDemo.xcodeproj">
|
location = "group:Demo/ShoeGazeiOSDemo.xcodeproj">
|
||||||
</FileRef>
|
</FileRef>
|
||||||
|
<FileRef
|
||||||
|
location = "group:Demo/ShoeGazeBuilder.xcodeproj">
|
||||||
|
</FileRef>
|
||||||
|
<FileRef
|
||||||
|
location = "group:Demo/ShoeGazeBuilderiOS.xcodeproj">
|
||||||
|
</FileRef>
|
||||||
</Workspace>
|
</Workspace>
|
||||||
|
|||||||
@@ -10,7 +10,12 @@
|
|||||||
/// `PedalBoard` records these as pedals and split regions are added, so a board can be
|
/// `PedalBoard` records these as pedals and split regions are added, so a board can be
|
||||||
/// serialized and rebuilt faithfully rather than as a flat pedal list. Branch pedals live
|
/// serialized and rebuilt faithfully rather than as a flat pedal list. Branch pedals live
|
||||||
/// inside their section objects, not as separate segments.
|
/// inside their section objects, not as separate segments.
|
||||||
enum BoardSegment {
|
///
|
||||||
|
/// Public so a UI can walk a board's live structure in signal-flow order (each element carries
|
||||||
|
/// the live `Pedal` / section object). The index of a segment within `PedalBoard.orderedSegments`
|
||||||
|
/// matches its index in `captureState().segments`, which is the region index used by the
|
||||||
|
/// lane-addressed edit API (see ``PedalLane``).
|
||||||
|
public enum BoardSegment {
|
||||||
|
|
||||||
/// A single linear pedal in the main chain.
|
/// A single linear pedal in the main chain.
|
||||||
case pedal(Pedal)
|
case pedal(Pedal)
|
||||||
@@ -21,6 +26,10 @@ enum BoardSegment {
|
|||||||
/// A stereo split region (`splitStereo()` → two branches → `collectStereo()`).
|
/// A stereo split region (`splitStereo()` → two branches → `collectStereo()`).
|
||||||
case stereoSplit(StereoSplitSection)
|
case stereoSplit(StereoSplitSection)
|
||||||
|
|
||||||
|
/// A stereo unzip region (`unzipStereo()` → two branches → `collectStereo()`). Reuses the
|
||||||
|
/// `StereoSplitSection` payload; the distinct case lets capture/rebuild pick the unzip splitter.
|
||||||
|
case stereoUnzip(StereoSplitSection)
|
||||||
|
|
||||||
/// A `mergeToMono()` collapse — narrows a stereo tail back to mono. Carries no state;
|
/// A `mergeToMono()` collapse — narrows a stereo tail back to mono. Carries no state;
|
||||||
/// recorded so the width transition replays on rebuild.
|
/// recorded so the width transition replays on rebuild.
|
||||||
case mergeToMono
|
case mergeToMono
|
||||||
|
|||||||
@@ -0,0 +1,141 @@
|
|||||||
|
// SubOctaveDivider.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
|
||||||
|
/// Shared zero-fill fallback block, allocated once at module load. Returned when an upstream
|
||||||
|
/// input yields no channel for a `_computeSamples` call, so the RT path never allocates.
|
||||||
|
private let subOctaveDividerZeroBlock: [Double] = makeSampleBuffer()
|
||||||
|
|
||||||
|
/// Analog-style sub-octave generator: a hysteresis comparator feeding a T flip-flop chain.
|
||||||
|
///
|
||||||
|
/// This is the core of the classic Boss OC-2 octave-down algorithm. The input is treated
|
||||||
|
/// as a square wave by a Schmitt-trigger comparator around zero; each rising edge clocks a
|
||||||
|
/// toggle flip-flop. Toggling on every rising edge halves the frequency (`divisor: 2`,
|
||||||
|
/// one octave down); toggling on every *second* rising edge quarters it (`divisor: 4`, two
|
||||||
|
/// octaves down). The output is a hard `±1` square wave at `inputFrequency / divisor`.
|
||||||
|
///
|
||||||
|
/// The comparator runs in the time domain, so unlike an FFT pitch tracker it follows low
|
||||||
|
/// bass fundamentals (sub-100 Hz) with no detection floor. It is strictly monophonic — fed
|
||||||
|
/// a chord it tracks the dominant zero-crossing rate and glitches, exactly as the original
|
||||||
|
/// analog divider does.
|
||||||
|
///
|
||||||
|
/// Feed it a band-limited, hard-limited signal (low-pass to isolate the fundamental, then a
|
||||||
|
/// `tanh` limiter to square it up) for clean triggering; the raw guitar signal's upper
|
||||||
|
/// harmonics cause double-triggering an octave too high.
|
||||||
|
///
|
||||||
|
/// Output is mono: only channel 0 of the input is read (a stereo input is mono-summed to its
|
||||||
|
/// first channel before division).
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - input: Signal to divide. Should be pre-conditioned to a near-square `±1` waveform.
|
||||||
|
/// - divisor: Division ratio. `2` = one octave down, `4` = two octaves down. Even values
|
||||||
|
/// only; `init` traps on `divisor < 2`, and odd values truncate toward the next lower
|
||||||
|
/// even ratio (`divisor / 2` rising-edge count).
|
||||||
|
public final class SubOctaveDivider: GeneratorBase, AudioGenerator {
|
||||||
|
|
||||||
|
/// Resolved input signal (classified once at `init`, never on the RT thread).
|
||||||
|
let _input: any ValidGeneratorInput
|
||||||
|
|
||||||
|
/// `true` when `_input` resolved to an `any Generator`; `false` for a scalar constant.
|
||||||
|
/// Classified once at `init` so the RT path never runs an `is`/`as?` type check and never
|
||||||
|
/// hits `Double.calculatedSamples`, which would allocate every block.
|
||||||
|
let _inputIsGenerator: Bool
|
||||||
|
|
||||||
|
/// Number of rising input edges between output toggles: `divisor / 2`. A divide-by-2
|
||||||
|
/// square toggles every rising edge; divide-by-4 toggles every second rising edge.
|
||||||
|
let _toggleEvery: Int
|
||||||
|
|
||||||
|
/// Comparator state: `true` once the input has risen above `compHigh`, `false` once it
|
||||||
|
/// has fallen below `compLow`. The hysteresis band rejects zero-region noise.
|
||||||
|
var _high: Bool = false
|
||||||
|
|
||||||
|
/// Rising edges seen since the last output toggle.
|
||||||
|
var _edgeCount: Int = 0
|
||||||
|
|
||||||
|
/// Current square-wave output level, toggled between `+1` and `-1`.
|
||||||
|
var _outState: Double = 1.0
|
||||||
|
|
||||||
|
/// Comparator switch-on threshold. Input must exceed this (from below) to register a
|
||||||
|
/// rising edge. Small positive value rejects noise around zero for a limited input.
|
||||||
|
private let compHigh: Double = 0.1
|
||||||
|
|
||||||
|
/// Comparator switch-off threshold. Input must fall below this to re-arm the rising-edge
|
||||||
|
/// detector. The `compHigh` / `compLow` gap is the hysteresis band.
|
||||||
|
private let compLow: Double = -0.1
|
||||||
|
|
||||||
|
/// Smallest accepted division ratio (one octave down).
|
||||||
|
private static let minimumDivisor: Int = 2
|
||||||
|
|
||||||
|
/// Creates a sub-octave divider.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - input: Signal to divide. Should be pre-conditioned to a near-square `±1` waveform.
|
||||||
|
/// - divisor: Division ratio. `2` = one octave down, `4` = two octaves down. Even values
|
||||||
|
/// only; traps on `divisor < 2`, and odd values truncate toward the next lower even ratio.
|
||||||
|
public init(
|
||||||
|
input: any ValidGeneratorInput,
|
||||||
|
divisor: Int
|
||||||
|
) {
|
||||||
|
precondition(divisor >= SubOctaveDivider.minimumDivisor,
|
||||||
|
"SubOctaveDivider: divisor must be >= 2; got \(divisor).")
|
||||||
|
let resolvedInput: any ValidGeneratorInput = input._resolvedInput()
|
||||||
|
_input = resolvedInput
|
||||||
|
_inputIsGenerator = resolvedInput is any Generator
|
||||||
|
_toggleEvery = divisor / 2
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
public func _computeSamples(
|
||||||
|
graph: SynthGraph,
|
||||||
|
count: Int
|
||||||
|
) -> [[Double]] {
|
||||||
|
_checkCount(count)
|
||||||
|
|
||||||
|
var high: Bool = _high
|
||||||
|
var edgeCount: Int = _edgeCount
|
||||||
|
var outState: Double = _outState
|
||||||
|
|
||||||
|
// A scalar (constant) input never crosses the comparator thresholds, so no edges fire
|
||||||
|
// and the output holds its current level. Skip the input pull entirely — this also
|
||||||
|
// avoids `Double.calculatedSamples`, which would allocate on the RT thread.
|
||||||
|
guard _inputIsGenerator else {
|
||||||
|
for i: Int in 0..<count {
|
||||||
|
_result[0][i] = outState
|
||||||
|
}
|
||||||
|
_high = high
|
||||||
|
_edgeCount = edgeCount
|
||||||
|
_outState = outState
|
||||||
|
return _result
|
||||||
|
}
|
||||||
|
|
||||||
|
let inputSamples: [Double] = _input.calculatedSamples(
|
||||||
|
graph: graph, count: count).first ?? subOctaveDividerZeroBlock
|
||||||
|
let inputCount: Int = inputSamples.count
|
||||||
|
|
||||||
|
for i: Int in 0..<count {
|
||||||
|
// Bounds-safe read: a short upstream block falls back to silence past its end.
|
||||||
|
let x: Double = i < inputCount ? inputSamples[i] : 0.0
|
||||||
|
if !high && x > compHigh {
|
||||||
|
// Rising edge: clock the flip-flop.
|
||||||
|
high = true
|
||||||
|
edgeCount += 1
|
||||||
|
if edgeCount >= _toggleEvery {
|
||||||
|
edgeCount = 0
|
||||||
|
outState = -outState
|
||||||
|
}
|
||||||
|
} else if high && x < compLow {
|
||||||
|
high = false
|
||||||
|
}
|
||||||
|
_result[0][i] = outState
|
||||||
|
}
|
||||||
|
|
||||||
|
_high = high
|
||||||
|
_edgeCount = edgeCount
|
||||||
|
_outState = outState
|
||||||
|
return _result
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@ import LyrebirdSynth
|
|||||||
/// the zero-based hardware input channel index (`0` = first input). It maps to engine
|
/// the zero-based hardware input channel index (`0` = first input). It maps to engine
|
||||||
/// audio-bus index `numOutputChannels + channel` (hardware input buses follow the
|
/// audio-bus index `numOutputChannels + channel` (hardware input buses follow the
|
||||||
/// output buses). Requires the engine to be created with `numInputChannels > channel`.
|
/// output buses). Requires the engine to be created with `numInputChannels > channel`.
|
||||||
public enum InputSource {
|
public enum InputSource: Equatable {
|
||||||
/// Synthesized test signal — no hardware required.
|
/// Synthesized test signal — no hardware required.
|
||||||
case testLoop
|
case testLoop
|
||||||
/// Live hardware input from the given zero-based input channel. The engine must be
|
/// Live hardware input from the given zero-based input channel. The engine must be
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
// MicrophonePermission.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import AVFoundation
|
||||||
|
|
||||||
|
/// Microphone (audio-input) authorisation helper for live-input mode.
|
||||||
|
///
|
||||||
|
/// On macOS, an AUHAL input unit does **not** reliably trigger the system microphone prompt;
|
||||||
|
/// without an explicit `AVCaptureDevice.requestAccess(for: .audio)` the OS hands the app a stream
|
||||||
|
/// of silent zeros (no error). On iOS the record-permission prompt is likewise required before the
|
||||||
|
/// session delivers input. This helper centralises the cross-platform request so every app routes
|
||||||
|
/// live input through the same gate.
|
||||||
|
///
|
||||||
|
/// The Info.plist must contain `NSMicrophoneUsageDescription`, or the request crashes at runtime.
|
||||||
|
public enum MicrophonePermission {
|
||||||
|
|
||||||
|
/// Current authorisation state for audio capture.
|
||||||
|
public static var status: AVAuthorizationStatus {
|
||||||
|
AVCaptureDevice.authorizationStatus(for: .audio)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `true` only when audio capture is already authorised.
|
||||||
|
public static var isAuthorized: Bool {
|
||||||
|
status == .authorized
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Ensures microphone access, prompting the user once if the state is undetermined.
|
||||||
|
///
|
||||||
|
/// - `authorized` → `completion(true)` immediately (next run loop, on the main actor).
|
||||||
|
/// - `notDetermined` → shows the system prompt; `completion` fires with the user's choice.
|
||||||
|
/// - `denied` / `restricted` → `completion(false)` (the app must direct the user to Settings).
|
||||||
|
///
|
||||||
|
/// `completion` is always delivered on the main actor so callers can drive UI / engine state
|
||||||
|
/// directly without further hops.
|
||||||
|
///
|
||||||
|
/// - Parameter completion: Receives the final grant state.
|
||||||
|
public static func request(_ completion: @escaping @MainActor (Bool) -> Void) {
|
||||||
|
switch status {
|
||||||
|
case .authorized:
|
||||||
|
Task { @MainActor in completion(true) }
|
||||||
|
case .notDetermined:
|
||||||
|
AVCaptureDevice.requestAccess(for: .audio) { granted in
|
||||||
|
Task { @MainActor in completion(granted) }
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
Task { @MainActor in completion(false) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,20 +9,23 @@ import LyrebirdUI
|
|||||||
|
|
||||||
/// A synthesized test signal source that writes to a target audio bus.
|
/// A synthesized test signal source that writes to a target audio bus.
|
||||||
///
|
///
|
||||||
/// Produces two detuned sine oscillators at 110 Hz and 165 Hz — an approximation
|
/// Plays a repeating E-minor arpeggio on a Karplus-Strong plucked string, cycling the open
|
||||||
/// of a guitar's A2 and E3 strings — with a slow amplitude envelope driven by a
|
/// pitches of a guitar's lower four strings — E2, A2, D3, G3 — so the board has a musical,
|
||||||
/// low-frequency sine LFO. This makes the board audible immediately without any
|
/// guitar-like signal to process without any hardware connected. A single ``Impulse`` drives
|
||||||
/// hardware connection.
|
/// both the pluck excitation and a ``Demand``/``DemandSequence`` that advances the pitch one step
|
||||||
|
/// per pluck, keeping note changes locked to the plucks.
|
||||||
///
|
///
|
||||||
/// The output is written to `targetBus` so downstream pedals read it from that bus.
|
/// The output is written to `targetBus` so downstream pedals read it from that bus.
|
||||||
/// `TestLoopSource` should be added to the engine **before** the first pedal in the
|
/// `TestLoopSource` should be added to the engine **before** the first pedal in the chain to
|
||||||
/// chain to ensure signal-order correctness (source evaluates first).
|
/// ensure signal-order correctness (source evaluates first).
|
||||||
///
|
///
|
||||||
/// ## Parameters
|
/// ## Parameters
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - targetBus: Audio bus index to write the test signal to. Typically the
|
/// - targetBus: Audio bus index to write the test signal to. Typically the pedalboard's
|
||||||
/// pedalboard's head bus index.
|
/// head bus index.
|
||||||
|
/// - sampleRate: Engine sample rate, used to size the Karplus-Strong delay line. Defaults to
|
||||||
|
/// `48000`; the pedalboard passes the engine's actual rate so the pitch is accurate.
|
||||||
/// - amplitude: Output amplitude in [0, 1]. Defaults to `0.25`.
|
/// - amplitude: Output amplitude in [0, 1]. Defaults to `0.25`.
|
||||||
public final class TestLoopSource: SynthesizerBase {
|
public final class TestLoopSource: SynthesizerBase {
|
||||||
|
|
||||||
@@ -33,44 +36,68 @@ public final class TestLoopSource: SynthesizerBase {
|
|||||||
|
|
||||||
// MARK: - Constants
|
// MARK: - Constants
|
||||||
|
|
||||||
/// Frequency of the first oscillator in Hz (approximates guitar A2 string).
|
/// Open pitches of the guitar's lower four strings, in Hz: E2, A2, D3, G3. Arpeggiated in
|
||||||
private let freqA: Double = 110.0
|
/// order and repeated — an E-minor flavored figure (all four are in E natural minor).
|
||||||
|
private let arpeggioPitches: [Double] = [82.41, 110.00, 146.83, 196.00]
|
||||||
|
|
||||||
/// Frequency of the second oscillator in Hz (approximates guitar E3 string, slightly detuned).
|
/// Plucks per second (the arpeggio step rate).
|
||||||
private let freqB: Double = 165.75
|
private let pluckRate: Double = 3.0
|
||||||
|
|
||||||
/// LFO frequency in Hz for amplitude modulation (slow tremolo).
|
/// Karplus-Strong feedback gain in [0, 1]; higher = longer sustain (strings ring into the
|
||||||
private let lfoFreq: Double = 0.5
|
/// next pluck like a real arpeggio).
|
||||||
|
private let feedback: Double = 0.99
|
||||||
|
|
||||||
/// LFO depth as a fraction of base amplitude [0, 1].
|
/// Karplus-Strong one-pole damping coefficient (`0.5` = classic natural damping).
|
||||||
private let lfoDepth: Double = 0.3
|
private let damping: Double = 0.5
|
||||||
|
|
||||||
/// Gain for each individual oscillator before summing. Two oscillators × 0.5 = unity.
|
/// Maximum delay time in seconds, sizing the delay line. `0.05 s` covers fundamentals down to
|
||||||
private let oscGain: Double = 0.5
|
/// 20 Hz — well below the lowest arpeggio pitch (E2, ~82 Hz).
|
||||||
|
private let maxDelayTime: Double = 0.05
|
||||||
|
|
||||||
|
/// Fixed seed for the pluck-excitation noise, so the test tone is deterministic and identical
|
||||||
|
/// across instances (two renders of the source produce the same output).
|
||||||
|
private let exciterSeed: UInt64 = 0x5E1E_C7ED_5017_C35A
|
||||||
|
|
||||||
// MARK: - Routing
|
// MARK: - Routing
|
||||||
|
|
||||||
/// The bus this source writes its output to.
|
/// The bus this source writes its output to.
|
||||||
private let targetBus: Int
|
private let targetBus: Int
|
||||||
|
|
||||||
|
/// Engine sample rate used to size the Karplus-Strong delay line.
|
||||||
|
private let sampleRate: Double
|
||||||
|
|
||||||
// MARK: - Init
|
// MARK: - Init
|
||||||
|
|
||||||
/// Creates a test loop source that writes to `targetBus`.
|
/// Creates a test loop source that writes to `targetBus`.
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - targetBus: Audio bus index to write the synthesized test signal to.
|
/// - targetBus: Audio bus index to write the synthesized test signal to.
|
||||||
public init(targetBus: Int) {
|
/// - sampleRate: Engine sample rate (sizes the Karplus-Strong delay line). Defaults to `48000`.
|
||||||
|
public init(targetBus: Int, sampleRate: Double = 48_000.0) {
|
||||||
self.targetBus = targetBus
|
self.targetBus = targetBus
|
||||||
|
self.sampleRate = sampleRate
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Build
|
// MARK: - Build
|
||||||
|
|
||||||
public override func build() {
|
public override func build() {
|
||||||
let oscA: OscSin.Audio = OscSin.Audio(freq: freqA, mul: oscGain)
|
// One impulse drives both the pluck excitation and the pitch-stepping demand, so each
|
||||||
let oscB: OscSin.Audio = OscSin.Audio(freq: freqB, phase: 0.25, mul: oscGain)
|
// pluck lands on the next arpeggio note.
|
||||||
let lfo: OscSin.Audio = OscSin.Audio(freq: lfoFreq, mul: lfoDepth, add: 1.0 - lfoDepth)
|
let pluck: Impulse.Audio = Impulse.Audio(freq: pluckRate)
|
||||||
let signal: any ValidGeneratorInput = (oscA + oscB) * lfo * $amplitude
|
let pitch: Demand.Audio = Demand.Audio(
|
||||||
output(bus: targetBus, source: signal)
|
trig: pluck,
|
||||||
|
demand: DemandSequence(values: arpeggioPitches, repeats: -1)
|
||||||
|
)
|
||||||
|
let string: KarplusStrong.Audio = KarplusStrong.Audio(
|
||||||
|
exciter: WhiteNoise.Audio(seed: exciterSeed),
|
||||||
|
trigger: pluck,
|
||||||
|
freq: pitch,
|
||||||
|
feedback: feedback,
|
||||||
|
coef: damping,
|
||||||
|
sampleRate: sampleRate,
|
||||||
|
maxDelayTime: maxDelayTime
|
||||||
|
)
|
||||||
|
output(bus: targetBus, source: string * $amplitude)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
// TestLoopTap.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
|
||||||
|
/// Internal synthesizer that copies the shared global test-loop bus to a board head bus.
|
||||||
|
///
|
||||||
|
/// In `.testLoop` mode every board reads the **same** global ``TestLoopSource`` (so all boards
|
||||||
|
/// stay phase-locked instead of each running an independently-phased arpeggio). A `TestLoopTap`
|
||||||
|
/// per board reads the global test bus at `inputBusIndex` and writes it to the board's head bus
|
||||||
|
/// at `outputBusIndex`, so the first pedal still reads from a board-owned bus.
|
||||||
|
///
|
||||||
|
/// Added `.after(_:)` the global source so it evaluates once the source has written the test bus
|
||||||
|
/// for the current block.
|
||||||
|
///
|
||||||
|
/// - Note: Must be removed from the engine before the board's `teardown()` releases the head bus.
|
||||||
|
final class TestLoopTap: SynthesizerBase {
|
||||||
|
|
||||||
|
// MARK: - Routing
|
||||||
|
|
||||||
|
/// Index of the shared global test-loop bus to read from.
|
||||||
|
private let inputBusIndex: Int
|
||||||
|
|
||||||
|
/// Index of the board head bus to write to.
|
||||||
|
private let outputBusIndex: Int
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a tap that copies `inputBusIndex` (the global test bus) to `outputBusIndex`
|
||||||
|
/// (a board head bus).
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - inputBusIndex: Shared global test-loop bus index to read from.
|
||||||
|
/// - outputBusIndex: Board head bus index to write to.
|
||||||
|
init(inputBusIndex: Int, outputBusIndex: Int) {
|
||||||
|
self.inputBusIndex = inputBusIndex
|
||||||
|
self.outputBusIndex = outputBusIndex
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Build
|
||||||
|
|
||||||
|
override func build() {
|
||||||
|
output(bus: outputBusIndex, source: input(bus: inputBusIndex))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -147,6 +147,16 @@ open class Pedal: SynthesizerBase {
|
|||||||
[]
|
[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Effect-specific continuous sliders for this pedal, rendered as a row of vertical
|
||||||
|
/// faders beneath the knob grid and switches.
|
||||||
|
///
|
||||||
|
/// Override in subclasses to publish each `@UIParam` parameter that reads best as a
|
||||||
|
/// vertical fader rather than a rotary knob — graphic-EQ band gains, a master output
|
||||||
|
/// fader, and similar bank-style controls. Defaults to empty.
|
||||||
|
open var effectSliders: [PedalSlider] {
|
||||||
|
[]
|
||||||
|
}
|
||||||
|
|
||||||
/// All knobs a generic UI should render for this pedal: effect-specific knobs
|
/// All knobs a generic UI should render for this pedal: effect-specific knobs
|
||||||
/// first, then the common `mix` and `level` knobs. The `bypass` parameter is
|
/// first, then the common `mix` and `level` knobs. The `bypass` parameter is
|
||||||
/// surfaced separately as a header toggle, not as a knob.
|
/// surfaced separately as a header toggle, not as a knob.
|
||||||
|
|||||||
@@ -80,6 +80,10 @@ public final class PedalBoard {
|
|||||||
/// All stereo split sections created via `splitStereo()` (for inspection / UI binding).
|
/// All stereo split sections created via `splitStereo()` (for inspection / UI binding).
|
||||||
public private(set) var stereoSplitSections: [StereoSplitSection] = []
|
public private(set) var stereoSplitSections: [StereoSplitSection] = []
|
||||||
|
|
||||||
|
/// All stereo unzip sections created via ``unzipStereo()``. Same `StereoSplitSection` type as
|
||||||
|
/// ``stereoSplitSections``; tracked separately so a UI can distinguish the two region kinds.
|
||||||
|
public private(set) var stereoUnzipSections: [StereoSplitSection] = []
|
||||||
|
|
||||||
/// The node that writes the head bus (e.g. a `TestLoopSource` or input pass-through).
|
/// The node that writes the head bus (e.g. a `TestLoopSource` or input pass-through).
|
||||||
/// Set by `ShoeGaze` after adding the input source. When non-nil, the first `add(_:)`
|
/// Set by `ShoeGaze` after adding the input source. When non-nil, the first `add(_:)`
|
||||||
/// call chains the first pedal after this node automatically (no `after:` arg needed).
|
/// call chains the first pedal after this node automatically (no `after:` arg needed).
|
||||||
@@ -122,8 +126,10 @@ public final class PedalBoard {
|
|||||||
private var branchChains: [BranchChain] = []
|
private var branchChains: [BranchChain] = []
|
||||||
|
|
||||||
/// Ordered signal-chain segments (pedals + split regions) in signal-flow order. Used to
|
/// Ordered signal-chain segments (pedals + split regions) in signal-flow order. Used to
|
||||||
/// capture full board topology for serialization. Maintained by `add`/`split`/`splitStereo`.
|
/// capture full board topology for serialization and to drive signal-flow UIs. Maintained by
|
||||||
private(set) var orderedSegments: [BoardSegment] = []
|
/// `add`/`split`/`splitStereo`. A segment's index here matches its index in
|
||||||
|
/// `captureState().segments` — the region index used by the lane-addressed edit API.
|
||||||
|
public private(set) var orderedSegments: [BoardSegment] = []
|
||||||
|
|
||||||
// MARK: - Init
|
// MARK: - Init
|
||||||
|
|
||||||
@@ -365,6 +371,78 @@ public final class PedalBoard {
|
|||||||
return section
|
return section
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Splits the current **stereo** tail into two independently authored branch chains — left
|
||||||
|
/// channel into one, right channel into the other — so the channels can be processed
|
||||||
|
/// separately, then recombined to stereo by ``collectStereo(_:)``.
|
||||||
|
///
|
||||||
|
/// The stereo counterpart of ``splitStereo()``: it requires a width-2 tail and uses a
|
||||||
|
/// ``StereoUnzipSplitter`` (which reads both channels) instead of a mono-duplicating
|
||||||
|
/// ``StereoSplitter``. Everything downstream (branch chains, route collector, route control)
|
||||||
|
/// is identical, so it returns the same ``StereoSplitSection`` type.
|
||||||
|
///
|
||||||
|
/// Route semantics for the reused ``StereoRouteCollector`` differ from a mono split, because
|
||||||
|
/// each lane here carries one *original* channel rather than a duplicated mono signal:
|
||||||
|
/// `.stereo` = L lane → left, R lane → right; `.leftOnly` / `.rightOnly` = center the chosen
|
||||||
|
/// lane (so you hear only that original channel, processed, in both speakers); `.bypass` =
|
||||||
|
/// the centered mono sum (`0.5·L + 0.5·R`) of the pre-unzip signal in both speakers.
|
||||||
|
///
|
||||||
|
/// - Returns: A ``StereoSplitSection`` with two empty branch chains; call `collectStereo(_:)`
|
||||||
|
/// after adding branch pedals.
|
||||||
|
/// - Throws:
|
||||||
|
/// - `ShoeGazeError.cannotUnzipMonoChain` if the tail is mono (width 1).
|
||||||
|
/// - `BusAllocatorError.noFreeBus` if no mono audio bus is available.
|
||||||
|
/// - `EngineAddError` if the engine rejects the splitter add.
|
||||||
|
public func unzipStereo() throws -> StereoSplitSection {
|
||||||
|
guard width == 2, let rightTail: AudioBus = outputBusRight else {
|
||||||
|
throw ShoeGazeError.cannotUnzipMonoChain
|
||||||
|
}
|
||||||
|
let preLeft: AudioBus = outputBus
|
||||||
|
let preRight: AudioBus = rightTail
|
||||||
|
|
||||||
|
// Branch input buses are branch-owned (mirroring `splitStereo`); the dry tap is board-owned.
|
||||||
|
let leftInBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
let rightInBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
let dryTapBus: AudioBus = try allocateInterNodeBus()
|
||||||
|
|
||||||
|
let splitter: StereoUnzipSplitter = StereoUnzipSplitter(
|
||||||
|
inputLeft: preLeft.index,
|
||||||
|
inputRight: preRight.index,
|
||||||
|
outputBusLeft: leftInBus.index,
|
||||||
|
outputBusRight: rightInBus.index,
|
||||||
|
dryTapBus: dryTapBus.index
|
||||||
|
)
|
||||||
|
|
||||||
|
let tail: SharedTail = SharedTail(node: splitter)
|
||||||
|
let leftChain: BranchChain = BranchChain(
|
||||||
|
engine: engine,
|
||||||
|
inputBus: leftInBus,
|
||||||
|
sampleRate: engine.sampleRate,
|
||||||
|
sharedTail: tail
|
||||||
|
)
|
||||||
|
let rightChain: BranchChain = BranchChain(
|
||||||
|
engine: engine,
|
||||||
|
inputBus: rightInBus,
|
||||||
|
sampleRate: engine.sampleRate,
|
||||||
|
sharedTail: tail
|
||||||
|
)
|
||||||
|
branchChains.append(leftChain)
|
||||||
|
branchChains.append(rightChain)
|
||||||
|
|
||||||
|
try insertNode(splitter, after: nil)
|
||||||
|
routingNodes.append(splitter)
|
||||||
|
|
||||||
|
let section: StereoSplitSection = StereoSplitSection(
|
||||||
|
splitter: splitter,
|
||||||
|
left: leftChain,
|
||||||
|
right: rightChain,
|
||||||
|
sharedTail: tail,
|
||||||
|
dryTapBus: dryTapBus
|
||||||
|
)
|
||||||
|
stereoUnzipSections.append(section)
|
||||||
|
orderedSegments.append(.stereoUnzip(section))
|
||||||
|
return section
|
||||||
|
}
|
||||||
|
|
||||||
/// Inserts the route collector for a stereo split section and advances the board to width 2.
|
/// Inserts the route collector for a stereo split section and advances the board to width 2.
|
||||||
///
|
///
|
||||||
/// The collector reads both branch tails and the dry tap, and writes the board's new left and
|
/// The collector reads both branch tails and the dry tap, and writes the board's new left and
|
||||||
@@ -563,6 +641,7 @@ public final class PedalBoard {
|
|||||||
lastNode = nil
|
lastNode = nil
|
||||||
orderedSegments.removeAll()
|
orderedSegments.removeAll()
|
||||||
stereoSplitSections.removeAll()
|
stereoSplitSections.removeAll()
|
||||||
|
stereoUnzipSections.removeAll()
|
||||||
|
|
||||||
// Step 4: Release board-owned buses (head bus and main-chain inter-node buses).
|
// Step 4: Release board-owned buses (head bus and main-chain inter-node buses).
|
||||||
for bus: AudioBus in allocatedBuses {
|
for bus: AudioBus in allocatedBuses {
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
// PedalSlider.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// A UI-agnostic description of one continuous vertical pedal fader.
|
||||||
|
///
|
||||||
|
/// Where ``PedalKnob`` describes a rotary control and ``PedalSwitch`` a discrete
|
||||||
|
/// segmented control, `PedalSlider` describes a continuous vertical fader — the control
|
||||||
|
/// a graphic EQ uses for its per-band gains and master output level. A `Pedal` publishes
|
||||||
|
/// an array of these via ``Pedal/effectSliders`` so a generic pedalboard UI can render a
|
||||||
|
/// bank of vertical faders without knowing the concrete pedal type.
|
||||||
|
///
|
||||||
|
/// Each descriptor pairs a display label with the live ``UIParamNode`` (the projected
|
||||||
|
/// value of an `@UIParam` property) and the value range the fader should span.
|
||||||
|
public struct PedalSlider {
|
||||||
|
|
||||||
|
/// Short label shown beneath the fader (e.g. "Low", "Gain").
|
||||||
|
public let label: String
|
||||||
|
|
||||||
|
/// The live parameter node the fader reads and writes. Pass `pedal.$paramName`.
|
||||||
|
public let node: UIParamNode
|
||||||
|
|
||||||
|
/// Inclusive value range the fader spans, in the parameter's own units.
|
||||||
|
public let range: ClosedRange<Double>
|
||||||
|
|
||||||
|
/// Creates a slider descriptor.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - label: Short label shown beneath the fader.
|
||||||
|
/// - node: The `UIParamNode` projected value of an `@UIParam` property
|
||||||
|
/// (`pedal.$lowGain`, `pedal.$globalGain`, …).
|
||||||
|
/// - range: Inclusive value range the fader spans, in the parameter's units.
|
||||||
|
public init(
|
||||||
|
label: String,
|
||||||
|
node: UIParamNode,
|
||||||
|
range: ClosedRange<Double>
|
||||||
|
) {
|
||||||
|
self.label = label
|
||||||
|
self.node = node
|
||||||
|
self.range = range
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
// PedalType.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
/// A type-safe identifier for a pedal type, used by the board-edit API instead of a raw string.
|
||||||
|
///
|
||||||
|
/// `PedalType` is an extensible token (the `RawRepresentable` struct pattern, à la
|
||||||
|
/// `Notification.Name`): the built-in pedals are exposed as static members for discoverable,
|
||||||
|
/// autocompleting call sites —
|
||||||
|
///
|
||||||
|
/// ```swift
|
||||||
|
/// try shoeGaze.appendPedal(.overdrive, to: board)
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// — while staying open for custom pedals, since any `PedalType("My Pedal")` is valid and a
|
||||||
|
/// third party can add their own static members in an extension.
|
||||||
|
///
|
||||||
|
/// `rawValue` is the pedal's `displayName`, which is exactly what the rig save format stores
|
||||||
|
/// (`PedalState.type`) and what ``PedalRegistry`` keys on. `PedalType` therefore changes only the
|
||||||
|
/// authoring call site — the JSON format and load path are unchanged.
|
||||||
|
///
|
||||||
|
/// > Note: named `PedalType` rather than `PedalKind` to avoid colliding with Lyrebird's
|
||||||
|
/// > score-notation `PedalKind` enum, which is visible whenever both modules are imported.
|
||||||
|
public struct PedalType: RawRepresentable, Hashable, Sendable {
|
||||||
|
|
||||||
|
/// The pedal's `displayName`; the key used by ``PedalRegistry`` and stored in saved rigs.
|
||||||
|
public let rawValue: String
|
||||||
|
|
||||||
|
/// Creates a type from a raw `displayName` string.
|
||||||
|
public init(rawValue: String) {
|
||||||
|
self.rawValue = rawValue
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a type from a raw `displayName` string.
|
||||||
|
public init(_ rawValue: String) {
|
||||||
|
self.rawValue = rawValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Built-in pedals
|
||||||
|
|
||||||
|
public extension PedalType {
|
||||||
|
|
||||||
|
// Drive & dynamics
|
||||||
|
static let overdrive = PedalType("Overdrive")
|
||||||
|
static let fuzz = PedalType("Fuzz")
|
||||||
|
static let compressor = PedalType("Compressor")
|
||||||
|
static let limiter = PedalType("Limiter")
|
||||||
|
static let noiseGate = PedalType("Noise Gate")
|
||||||
|
|
||||||
|
// EQ & filter
|
||||||
|
static let graphicEQ = PedalType("Graphic EQ")
|
||||||
|
static let autoWah = PedalType("Auto-Wah")
|
||||||
|
static let mutant = PedalType("Mutant")
|
||||||
|
static let phaser = PedalType("Phaser")
|
||||||
|
|
||||||
|
// Modulation
|
||||||
|
static let tremolo = PedalType("Tremolo")
|
||||||
|
static let modulation = PedalType("Modulation")
|
||||||
|
|
||||||
|
// Delay & reverb
|
||||||
|
static let delay = PedalType("Delay")
|
||||||
|
static let feedbackDelay = PedalType("Feedback Delay")
|
||||||
|
static let multiTapDelay = PedalType("Multi-Tap Delay")
|
||||||
|
static let pingPong = PedalType("Ping-Pong")
|
||||||
|
static let reverb = PedalType("Reverb")
|
||||||
|
|
||||||
|
// Pitch & octave
|
||||||
|
static let octaveSplitter = PedalType("Octave Splitter")
|
||||||
|
static let bassOctaver = PedalType("Bass Octaver")
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ import LyrebirdUI
|
|||||||
|
|
||||||
/// Amplitude-tracked auto-wah pedal built from discrete tracking + filter stages.
|
/// Amplitude-tracked auto-wah pedal built from discrete tracking + filter stages.
|
||||||
///
|
///
|
||||||
/// Unlike `MuTronPedal` (which wraps the single fused `MuTronIII` generator), this pedal
|
/// Unlike `MutantPedal` (which wraps the single fused `MuTronIII` generator), this pedal
|
||||||
/// wires the envelope path explicitly: an `AmplitudeFollower` tracks the dry signal level,
|
/// wires the envelope path explicitly: an `AmplitudeFollower` tracks the dry signal level,
|
||||||
/// the envelope is scaled by `sensitivity` and clamped to `[0, 1]`, then mapped through an
|
/// the envelope is scaled by `sensitivity` and clamped to `[0, 1]`, then mapped through an
|
||||||
/// exponential `LinExp` curve to a cutoff frequency that sweeps a resonant `SVF` bandpass.
|
/// exponential `LinExp` curve to a cutoff frequency that sweeps a resonant `SVF` bandpass.
|
||||||
|
|||||||
@@ -0,0 +1,232 @@
|
|||||||
|
// BassOctaverPedal.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// Monophonic bass octaver modeled on the Boss OC-2 Octave.
|
||||||
|
///
|
||||||
|
/// Adds one and two sub-octaves below the input, mixed against the direct signal — the
|
||||||
|
/// three-knob OC-2 panel layout (OCT1 = −1 octave, OCT2 = −2 octaves, Direct = dry level).
|
||||||
|
///
|
||||||
|
/// Two algorithms share the knobs, picked by the `mode` switch:
|
||||||
|
///
|
||||||
|
/// - **Flip-flop** (default): the authentic OC-2 path. The input is low-passed to isolate
|
||||||
|
/// the fundamental, hard-limited into a square wave, then clocked through a ``SubOctaveDivider``
|
||||||
|
/// T flip-flop chain to produce `±1` square sub-octaves an octave and two octaves down. Those
|
||||||
|
/// squares are amplitude-followed off the dry signal so they track its dynamics, then
|
||||||
|
/// low-passed to tame the square edges. Strictly monophonic; glitches on chords like the
|
||||||
|
/// original. Tracks low bass fundamentals (sub-100 Hz) cleanly because the divider works in
|
||||||
|
/// the time domain.
|
||||||
|
/// - **Tracking**: an FFT pitch tracker (`FreqTracker`) drives square oscillators at half and
|
||||||
|
/// quarter the detected frequency. Cleaner and glitch-free, but limited by the tracker's
|
||||||
|
/// ~90 Hz detection floor — best for notes above the low bass register. Flip-flop is the
|
||||||
|
/// bass mode.
|
||||||
|
///
|
||||||
|
/// ## Knobs
|
||||||
|
/// - `oct1`: −1 octave voice level in `[0, 1]`.
|
||||||
|
/// - `oct2`: −2 octave voice level in `[0, 1]`.
|
||||||
|
/// - `direct`: Dry signal level in `[0, 1]`.
|
||||||
|
///
|
||||||
|
/// ## Switches
|
||||||
|
/// - `mode` (two-state): `0` = Flip-flop (authentic OC-2), `1` = Tracking (pitch-tracked).
|
||||||
|
public final class BassOctaverPedal: Pedal {
|
||||||
|
|
||||||
|
// MARK: - Parameters
|
||||||
|
|
||||||
|
/// −1 octave voice level in `[0, 1]`.
|
||||||
|
@UIParam public var oct1: Double = 0.7
|
||||||
|
|
||||||
|
/// −2 octave voice level in `[0, 1]`.
|
||||||
|
@UIParam public var oct2: Double = 0.0
|
||||||
|
|
||||||
|
/// Dry (direct) signal level in `[0, 1]`.
|
||||||
|
@UIParam public var direct: Double = 1.0
|
||||||
|
|
||||||
|
/// Algorithm selector. `0` = Flip-flop (authentic OC-2), `1` = Tracking. Driven by a two-state switch.
|
||||||
|
@UIParam public var mode: Double = 0.0
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
/// Pedal blends everything internally via the level knobs, so the base wet/dry stays fully wet.
|
||||||
|
private static let defaultMix: Double = 1.0
|
||||||
|
|
||||||
|
/// DC-removal high-pass cutoff in Hz, applied before the divider's comparator.
|
||||||
|
private let dcBlockFreq: Double = 30.0
|
||||||
|
|
||||||
|
/// Pre-divider low-pass cutoff in Hz. Isolates the fundamental so upper harmonics do not
|
||||||
|
/// double-trigger the comparator an octave too high.
|
||||||
|
private let conditionCutoff: Double = 500.0
|
||||||
|
|
||||||
|
/// Pre-gain into the `tanh` limiter. Large enough to square the conditioned signal to `±1`
|
||||||
|
/// so the comparator sees clean edges regardless of input level.
|
||||||
|
private let limiterDrive: Double = 50.0
|
||||||
|
|
||||||
|
/// Low-pass cutoff in Hz applied to each square sub-octave to soften its harsh edges.
|
||||||
|
private let subToneCutoff: Double = 800.0
|
||||||
|
|
||||||
|
/// Butterworth Q (no resonant peak) for all conditioning filters.
|
||||||
|
private let filterQ: Double = 0.707
|
||||||
|
|
||||||
|
/// Envelope-follower attack/release times in seconds; the sub-octaves track the dry dynamics.
|
||||||
|
private let envAttack: Double = 0.005
|
||||||
|
private let envRelease: Double = 0.1
|
||||||
|
|
||||||
|
/// Frequency multipliers for the tracking-mode oscillators (one and two octaves down).
|
||||||
|
private let octave1Ratio: Double = 0.5
|
||||||
|
private let octave2Ratio: Double = 0.25
|
||||||
|
|
||||||
|
/// Pitch-tracker detection bounds in Hz for tracking mode.
|
||||||
|
private let trackMinFreq: Double = 60.0
|
||||||
|
private let trackMaxFreq: Double = 1000.0
|
||||||
|
|
||||||
|
/// Division ratios for the flip-flop divider.
|
||||||
|
private let divisorOctave1: Int = 2
|
||||||
|
private let divisorOctave2: Int = 4
|
||||||
|
|
||||||
|
/// Half-step bias added before `Select`'s truncate-toward-zero index, turning the `mode`
|
||||||
|
/// switch into a round-to-nearest position selector.
|
||||||
|
private let selectRoundingBias: Double = 0.5
|
||||||
|
|
||||||
|
/// Switch position values.
|
||||||
|
private let modeFlipFlopValue: Double = 0.0
|
||||||
|
private let modeTrackingValue: Double = 1.0
|
||||||
|
|
||||||
|
// MARK: - Ranges
|
||||||
|
|
||||||
|
private let levelRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||||
|
|
||||||
|
// MARK: - Knobs
|
||||||
|
|
||||||
|
public override var effectKnobs: [PedalKnob] {
|
||||||
|
[
|
||||||
|
PedalKnob(label: "OCT 1", node: $oct1, range: levelRange),
|
||||||
|
PedalKnob(label: "OCT 2", node: $oct2, range: levelRange),
|
||||||
|
PedalKnob(label: "Direct", node: $direct, range: levelRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Switches
|
||||||
|
|
||||||
|
public override var effectSwitches: [PedalSwitch] {
|
||||||
|
[
|
||||||
|
PedalSwitch(
|
||||||
|
label: "Mode",
|
||||||
|
node: $mode,
|
||||||
|
options: [
|
||||||
|
PedalSwitch.Option(title: "Flip", value: modeFlipFlopValue),
|
||||||
|
PedalSwitch.Option(title: "Track", value: modeTrackingValue),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a bass octaver pedal.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - inputBus: Audio bus index to read the dry input from. Defaults to `0`.
|
||||||
|
/// - outputBus: Audio bus index to write the output to. Defaults to `0`.
|
||||||
|
public init(
|
||||||
|
inputBus: Int = 0,
|
||||||
|
outputBus: Int = 0
|
||||||
|
) {
|
||||||
|
super.init(
|
||||||
|
name: "Bass Octaver",
|
||||||
|
inputBus: inputBus,
|
||||||
|
outputBus: outputBus,
|
||||||
|
initialMix: BassOctaverPedal.defaultMix
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Effect
|
||||||
|
|
||||||
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
|
// Sub-octaves track the dry signal's amplitude envelope.
|
||||||
|
let env: AmplitudeFollower.Audio = AmplitudeFollower.Audio(
|
||||||
|
in: dry,
|
||||||
|
attackTime: envAttack,
|
||||||
|
releaseTime: envRelease
|
||||||
|
)
|
||||||
|
|
||||||
|
// Flip-flop branch: condition → limit → divide.
|
||||||
|
let (oct1Flip, oct2Flip): (any ValidGeneratorInput, any ValidGeneratorInput) =
|
||||||
|
flipFlopVoices(dry: dry, env: env)
|
||||||
|
|
||||||
|
// Tracking branch: pitch-track → square oscillators.
|
||||||
|
let (oct1Track, oct2Track): (any ValidGeneratorInput, any ValidGeneratorInput) =
|
||||||
|
trackingVoices(dry: dry, env: env)
|
||||||
|
|
||||||
|
// Per-voice mode select. `Select` advances both branches each block (warm state).
|
||||||
|
let modeWhich: any ValidGeneratorInput = $mode + selectRoundingBias
|
||||||
|
let oct1Voice: Select.Audio = Select.Audio(
|
||||||
|
which: modeWhich,
|
||||||
|
inputs: [oct1Flip, oct1Track]
|
||||||
|
)
|
||||||
|
let oct2Voice: Select.Audio = Select.Audio(
|
||||||
|
which: modeWhich,
|
||||||
|
inputs: [oct2Flip, oct2Track]
|
||||||
|
)
|
||||||
|
|
||||||
|
// OC-2 mixer: direct + OCT1 + OCT2, each scaled by its level knob.
|
||||||
|
let directVoice: any ValidGeneratorInput = dry * $direct
|
||||||
|
let sub1: any ValidGeneratorInput = oct1Voice * $oct1
|
||||||
|
let sub2: any ValidGeneratorInput = oct2Voice * $oct2
|
||||||
|
return directVoice + sub1 + sub2
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builds the authentic flip-flop sub-octave voices: condition the input to a square,
|
||||||
|
/// clock the divider chain, amplitude-follow, then soften the square edges.
|
||||||
|
private func flipFlopVoices(
|
||||||
|
dry: any ValidGeneratorInput,
|
||||||
|
env: AmplitudeFollower.Audio
|
||||||
|
) -> (any ValidGeneratorInput, any ValidGeneratorInput) {
|
||||||
|
let dcBlocked: RBJHighPass.Audio = RBJHighPass.Audio(
|
||||||
|
input: dry,
|
||||||
|
freq: dcBlockFreq,
|
||||||
|
q: filterQ
|
||||||
|
)
|
||||||
|
let conditioned: RBJLowPass.Audio = RBJLowPass.Audio(
|
||||||
|
input: dcBlocked,
|
||||||
|
freq: conditionCutoff,
|
||||||
|
q: filterQ
|
||||||
|
)
|
||||||
|
let limited: Tanh.Audio = Tanh.Audio(conditioned, mul: limiterDrive)
|
||||||
|
|
||||||
|
let div1: SubOctaveDivider = SubOctaveDivider(input: limited, divisor: divisorOctave1)
|
||||||
|
let div2: SubOctaveDivider = SubOctaveDivider(input: limited, divisor: divisorOctave2)
|
||||||
|
|
||||||
|
let oct1: any ValidGeneratorInput = softened(div1) * env
|
||||||
|
let oct2: any ValidGeneratorInput = softened(div2) * env
|
||||||
|
return (oct1, oct2)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builds the pitch-tracked sub-octave voices: detect the fundamental, run square
|
||||||
|
/// oscillators an octave and two octaves below it, amplitude-follow, then soften.
|
||||||
|
private func trackingVoices(
|
||||||
|
dry: any ValidGeneratorInput,
|
||||||
|
env: AmplitudeFollower.Audio
|
||||||
|
) -> (any ValidGeneratorInput, any ValidGeneratorInput) {
|
||||||
|
let tracker: FreqTracker = FreqTracker(
|
||||||
|
in: dry,
|
||||||
|
minFreq: trackMinFreq,
|
||||||
|
maxFreq: trackMaxFreq
|
||||||
|
)
|
||||||
|
let freq: any ValidGeneratorInput = tracker.freq
|
||||||
|
let osc1: OscSquare.Audio = OscSquare.Audio(freq: freq * octave1Ratio)
|
||||||
|
let osc2: OscSquare.Audio = OscSquare.Audio(freq: freq * octave2Ratio)
|
||||||
|
|
||||||
|
let oct1: any ValidGeneratorInput = softened(osc1) * env
|
||||||
|
let oct2: any ValidGeneratorInput = softened(osc2) * env
|
||||||
|
return (oct1, oct2)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Low-passes a raw square sub-octave to soften its edges before mixing.
|
||||||
|
private func softened(_ square: any ValidGeneratorInput) -> RBJLowPass.Audio {
|
||||||
|
RBJLowPass.Audio(input: square, freq: subToneCutoff, q: filterQ)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,11 +11,13 @@ import LyrebirdUI
|
|||||||
///
|
///
|
||||||
/// Signal chain (inside `effect(_:)`):
|
/// Signal chain (inside `effect(_:)`):
|
||||||
/// ```
|
/// ```
|
||||||
/// dry → Compressor.Audio(threshold:, ratio:, attack:, release:, makeupGain:) → mono out
|
/// dry → × inputGain → Compressor.Audio(threshold:, ratio:, attack:, release:, makeupGain:) → mono out
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Attack, release, knee, and makeup gain are fixed at musically sensible defaults.
|
/// An input gain stage boosts (or cuts) the signal *before* compression, so driving the
|
||||||
/// Knobs expose the two most-musical parameters: threshold and ratio.
|
/// input harder pushes more of the signal past the threshold. Attack, release, knee, and
|
||||||
|
/// makeup gain are fixed at musically sensible defaults; knobs expose input gain, threshold,
|
||||||
|
/// and ratio.
|
||||||
///
|
///
|
||||||
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class.
|
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class.
|
||||||
///
|
///
|
||||||
@@ -24,6 +26,8 @@ import LyrebirdUI
|
|||||||
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
|
/// - inputGain: Pre-compression input gain in dB. `0` = unity. Range `[-12, 24]`.
|
||||||
|
/// Defaults to `0.0`.
|
||||||
/// - threshold: Gain-reduction threshold in dB. Signals above this level are
|
/// - threshold: Gain-reduction threshold in dB. Signals above this level are
|
||||||
/// compressed. Range `[-40, 0]` dB. Defaults to `-12.0`.
|
/// compressed. Range `[-40, 0]` dB. Defaults to `-12.0`.
|
||||||
/// - ratio: Compression ratio `≥ 1.0`. `1.0` = bypass, `4.0` = 4:1 compression.
|
/// - ratio: Compression ratio `≥ 1.0`. `1.0` = bypass, `4.0` = 4:1 compression.
|
||||||
@@ -32,6 +36,9 @@ public final class CompressorPedal: Pedal {
|
|||||||
|
|
||||||
// MARK: - Parameters
|
// MARK: - Parameters
|
||||||
|
|
||||||
|
/// Pre-compression input gain in dB. Range [-12, 24]. `0` = unity.
|
||||||
|
@UIParam public var inputGain: Double = 0.0
|
||||||
|
|
||||||
/// Compression threshold in dB. Range [-40, 0].
|
/// Compression threshold in dB. Range [-40, 0].
|
||||||
@UIParam public var threshold: Double = -12.0
|
@UIParam public var threshold: Double = -12.0
|
||||||
|
|
||||||
@@ -43,6 +50,10 @@ public final class CompressorPedal: Pedal {
|
|||||||
/// Default wet/dry blend — fully wet; the compressor is inserted in-line.
|
/// Default wet/dry blend — fully wet; the compressor is inserted in-line.
|
||||||
private static let defaultMix: Double = 1.0
|
private static let defaultMix: Double = 1.0
|
||||||
|
|
||||||
|
/// dB → natural-exponent scale, `ln(10) / 20`. `exp(dB · scale) == 10^(dB/20)`, the
|
||||||
|
/// linear amplitude multiplier for a dB gain. Applied to the input-gain stage.
|
||||||
|
private let dbToLinExpScale: Double = 0.115_129_254_649_702_28
|
||||||
|
|
||||||
/// Attack time constant in seconds — time to reach full gain reduction on a transient.
|
/// Attack time constant in seconds — time to reach full gain reduction on a transient.
|
||||||
private let attackTime: Double = 0.01
|
private let attackTime: Double = 0.01
|
||||||
|
|
||||||
@@ -57,6 +68,9 @@ public final class CompressorPedal: Pedal {
|
|||||||
|
|
||||||
// MARK: - UI knobs
|
// MARK: - UI knobs
|
||||||
|
|
||||||
|
/// Input-gain knob range in dB.
|
||||||
|
private let inputGainRange: ClosedRange<Double> = -12.0 ... 24.0
|
||||||
|
|
||||||
/// Threshold knob range in dB.
|
/// Threshold knob range in dB.
|
||||||
private let thresholdRange: ClosedRange<Double> = -40.0 ... 0.0
|
private let thresholdRange: ClosedRange<Double> = -40.0 ... 0.0
|
||||||
|
|
||||||
@@ -65,6 +79,7 @@ public final class CompressorPedal: Pedal {
|
|||||||
|
|
||||||
public override var effectKnobs: [PedalKnob] {
|
public override var effectKnobs: [PedalKnob] {
|
||||||
[
|
[
|
||||||
|
PedalKnob(label: "Input", node: $inputGain, range: inputGainRange),
|
||||||
PedalKnob(label: "Threshold", node: $threshold, range: thresholdRange),
|
PedalKnob(label: "Threshold", node: $threshold, range: thresholdRange),
|
||||||
PedalKnob(label: "Ratio", node: $ratio, range: ratioRange),
|
PedalKnob(label: "Ratio", node: $ratio, range: ratioRange),
|
||||||
]
|
]
|
||||||
@@ -91,15 +106,18 @@ public final class CompressorPedal: Pedal {
|
|||||||
|
|
||||||
// MARK: - Effect
|
// MARK: - Effect
|
||||||
|
|
||||||
/// Applies feed-forward dynamic range compression.
|
/// Boosts the input by `inputGain` dB, then applies feed-forward dynamic range compression.
|
||||||
///
|
///
|
||||||
/// Output is mono.
|
/// Output is mono.
|
||||||
///
|
///
|
||||||
/// - Parameter dry: Dry mono input signal.
|
/// - Parameter dry: Dry mono input signal.
|
||||||
/// - Returns: Compressed mono output.
|
/// - Returns: Compressed mono output.
|
||||||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
Compressor.Audio(
|
// Convert the input-gain dB to a linear multiplier (10^(dB/20)) and apply before compression.
|
||||||
in: dry,
|
let inputGainLinear: Exp.Audio = Exp.Audio($inputGain * dbToLinExpScale)
|
||||||
|
let boosted: any ValidGeneratorInput = dry * inputGainLinear
|
||||||
|
return Compressor.Audio(
|
||||||
|
in: boosted,
|
||||||
threshold: $threshold,
|
threshold: $threshold,
|
||||||
ratio: $ratio,
|
ratio: $ratio,
|
||||||
attack: attackTime,
|
attack: attackTime,
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public final class DelayPedal: Pedal {
|
|||||||
public override var effectKnobs: [PedalKnob] {
|
public override var effectKnobs: [PedalKnob] {
|
||||||
[
|
[
|
||||||
PedalKnob(label: "Time", node: $time, range: timeRange),
|
PedalKnob(label: "Time", node: $time, range: timeRange),
|
||||||
PedalKnob(label: "Feedback", node: $feedback, range: feedbackRange),
|
PedalKnob(label: "Decay Time", node: $feedback, range: feedbackRange),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public final class FeedbackDelayPedal: Pedal {
|
|||||||
public override var effectKnobs: [PedalKnob] {
|
public override var effectKnobs: [PedalKnob] {
|
||||||
[
|
[
|
||||||
PedalKnob(label: "Time", node: $time, range: timeRange),
|
PedalKnob(label: "Time", node: $time, range: timeRange),
|
||||||
PedalKnob(label: "Feedback", node: $feedback, range: feedbackRange),
|
PedalKnob(label: "Decay Time", node: $feedback, range: feedbackRange),
|
||||||
PedalKnob(label: "Tone", node: $tone, range: toneRange),
|
PedalKnob(label: "Tone", node: $tone, range: toneRange),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,165 @@
|
|||||||
|
// GraphicEQPedal.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// Five-band graphic EQ pedal built from cascaded RBJ filters, with a master output gain.
|
||||||
|
///
|
||||||
|
/// Signal chain (inside `effect(_:)`):
|
||||||
|
/// ```
|
||||||
|
/// dry → RBJLowShelf(80 Hz) → RBJPeakingEQ(240 Hz) → RBJPeakingEQ(750 Hz)
|
||||||
|
/// → RBJPeakingEQ(2.2 kHz) → RBJHighShelf(6.5 kHz) → × globalGain → mono out
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// Each band's gain is an `@UIParam` in decibels and is published as a vertical fader via
|
||||||
|
/// ``effectSliders`` — the pedalboard UI renders the bank as a row of graphic-EQ sliders.
|
||||||
|
/// The trailing master fader (`globalGain`, a linear multiplier) trims the overall level
|
||||||
|
/// after the EQ curve so boosting several bands need not clip the output.
|
||||||
|
///
|
||||||
|
/// Band centre frequencies and filter Q/slope are fixed; only the per-band gains and the
|
||||||
|
/// master output level are adjustable.
|
||||||
|
///
|
||||||
|
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class.
|
||||||
|
///
|
||||||
|
/// ## Parameters
|
||||||
|
///
|
||||||
|
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - lowGain: Low-shelf gain at 80 Hz, in dB. Range `[-12, 12]`. Defaults to `0.0`.
|
||||||
|
/// - lowMidGain: Peaking gain at 240 Hz, in dB. Range `[-12, 12]`. Defaults to `0.0`.
|
||||||
|
/// - midGain: Peaking gain at 750 Hz, in dB. Range `[-12, 12]`. Defaults to `0.0`.
|
||||||
|
/// - highMidGain: Peaking gain at 2.2 kHz, in dB. Range `[-12, 12]`. Defaults to `0.0`.
|
||||||
|
/// - highGain: High-shelf gain at 6.5 kHz, in dB. Range `[-12, 12]`. Defaults to `0.0`.
|
||||||
|
/// - globalGain: Master output gain in dB. `0` = unity. Range `[-12, 12]`.
|
||||||
|
/// Defaults to `0.0`.
|
||||||
|
public final class GraphicEQPedal: Pedal {
|
||||||
|
|
||||||
|
// MARK: - Parameters
|
||||||
|
|
||||||
|
/// Low-shelf gain in dB. Range [-12, 12].
|
||||||
|
@UIParam public var lowGain: Double = 0.0
|
||||||
|
|
||||||
|
/// Low-mid peaking gain in dB. Range [-12, 12].
|
||||||
|
@UIParam public var lowMidGain: Double = 0.0
|
||||||
|
|
||||||
|
/// Mid peaking gain in dB. Range [-12, 12].
|
||||||
|
@UIParam public var midGain: Double = 0.0
|
||||||
|
|
||||||
|
/// High-mid peaking gain in dB. Range [-12, 12].
|
||||||
|
@UIParam public var highMidGain: Double = 0.0
|
||||||
|
|
||||||
|
/// High-shelf gain in dB. Range [-12, 12].
|
||||||
|
@UIParam public var highGain: Double = 0.0
|
||||||
|
|
||||||
|
/// Master output gain in dB. Range [-12, 12]. `0` = unity.
|
||||||
|
@UIParam public var globalGain: Double = 0.0
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
/// Default wet/dry blend — fully wet; the EQ sits in-line.
|
||||||
|
private static let defaultMix: Double = 1.0
|
||||||
|
|
||||||
|
/// Band centre frequencies in Hz (low shelf, three peaks, high shelf).
|
||||||
|
private let lowFreq: Double = 80.0
|
||||||
|
private let lowMidFreq: Double = 240.0
|
||||||
|
private let midFreq: Double = 750.0
|
||||||
|
private let highMidFreq: Double = 2200.0
|
||||||
|
private let highFreq: Double = 6500.0
|
||||||
|
|
||||||
|
/// Shelf slope. `1.0` = maximum (steepest) shelf with no overshoot.
|
||||||
|
private let shelfSlope: Double = 1.0
|
||||||
|
|
||||||
|
/// Peaking-band quality factor — moderate bandwidth so adjacent bands overlap smoothly.
|
||||||
|
private let peakQ: Double = 0.9
|
||||||
|
|
||||||
|
/// dB → natural-exponent scale, `ln(10) / 20`. `exp(dB · scale) == 10^(dB/20)`, the
|
||||||
|
/// linear amplitude multiplier for a dB gain. Applied to the master output gain.
|
||||||
|
private let dbToLinExpScale: Double = 0.115_129_254_649_702_28
|
||||||
|
|
||||||
|
// MARK: - UI sliders
|
||||||
|
|
||||||
|
/// Per-band gain fader range, in dB.
|
||||||
|
private let bandGainRange: ClosedRange<Double> = -12.0 ... 12.0
|
||||||
|
|
||||||
|
/// Master output fader range, in dB.
|
||||||
|
private let globalGainRange: ClosedRange<Double> = -12.0 ... 12.0
|
||||||
|
|
||||||
|
public override var effectSliders: [PedalSlider] {
|
||||||
|
[
|
||||||
|
PedalSlider(label: "80", node: $lowGain, range: bandGainRange),
|
||||||
|
PedalSlider(label: "240", node: $lowMidGain, range: bandGainRange),
|
||||||
|
PedalSlider(label: "750", node: $midGain, range: bandGainRange),
|
||||||
|
PedalSlider(label: "2.2k", node: $highMidGain, range: bandGainRange),
|
||||||
|
PedalSlider(label: "6.5k", node: $highGain, range: bandGainRange),
|
||||||
|
PedalSlider(label: "Gain", node: $globalGain, range: globalGainRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a five-band graphic EQ pedal.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - inputBus: Audio bus index to read the dry input from. Defaults to `0`.
|
||||||
|
/// - outputBus: Audio bus index to write the processed output to. Defaults to `0`.
|
||||||
|
public init(
|
||||||
|
inputBus: Int = 0,
|
||||||
|
outputBus: Int = 0
|
||||||
|
) {
|
||||||
|
super.init(
|
||||||
|
name: "Graphic EQ",
|
||||||
|
inputBus: inputBus,
|
||||||
|
outputBus: outputBus,
|
||||||
|
initialMix: GraphicEQPedal.defaultMix
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Effect
|
||||||
|
|
||||||
|
/// Applies the cascaded five-band RBJ EQ curve, then the master output gain.
|
||||||
|
///
|
||||||
|
/// Output is mono.
|
||||||
|
///
|
||||||
|
/// - Parameter dry: Dry mono input signal.
|
||||||
|
/// - Returns: Equalised, level-trimmed mono output.
|
||||||
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
|
let lowShelf: RBJLowShelf.Audio = RBJLowShelf.Audio(
|
||||||
|
input: dry,
|
||||||
|
freq: lowFreq,
|
||||||
|
gain: $lowGain,
|
||||||
|
slope: shelfSlope
|
||||||
|
)
|
||||||
|
let lowMid: RBJPeakingEQ.Audio = RBJPeakingEQ.Audio(
|
||||||
|
input: lowShelf,
|
||||||
|
freq: lowMidFreq,
|
||||||
|
gain: $lowMidGain,
|
||||||
|
q: peakQ
|
||||||
|
)
|
||||||
|
let mid: RBJPeakingEQ.Audio = RBJPeakingEQ.Audio(
|
||||||
|
input: lowMid,
|
||||||
|
freq: midFreq,
|
||||||
|
gain: $midGain,
|
||||||
|
q: peakQ
|
||||||
|
)
|
||||||
|
let highMid: RBJPeakingEQ.Audio = RBJPeakingEQ.Audio(
|
||||||
|
input: mid,
|
||||||
|
freq: highMidFreq,
|
||||||
|
gain: $highMidGain,
|
||||||
|
q: peakQ
|
||||||
|
)
|
||||||
|
let highShelf: RBJHighShelf.Audio = RBJHighShelf.Audio(
|
||||||
|
input: highMid,
|
||||||
|
freq: highFreq,
|
||||||
|
gain: $highGain,
|
||||||
|
slope: shelfSlope
|
||||||
|
)
|
||||||
|
// Convert the master dB gain to a linear amplitude multiplier: 10^(dB/20).
|
||||||
|
let masterGain: Exp.Audio = Exp.Audio($globalGain * dbToLinExpScale)
|
||||||
|
return highShelf * masterGain
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
// LimiterPedal.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// Limiter pedal: a clean gain-boost stage feeding a brick-wall look-ahead limiter.
|
||||||
|
///
|
||||||
|
/// Signal chain (inside `effect(_:)`):
|
||||||
|
/// ```
|
||||||
|
/// dry → × boost → LookAheadLimiter(maxAmplitude: ceiling) → mono out
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// The boost stage drives the signal up *before* the limiter, so cranking `boost`
|
||||||
|
/// pushes more of the signal into limiting and raises sustain/perceived loudness while
|
||||||
|
/// the look-ahead limiter guarantees the output peak never exceeds `ceiling`.
|
||||||
|
///
|
||||||
|
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class.
|
||||||
|
///
|
||||||
|
/// ## Parameters
|
||||||
|
///
|
||||||
|
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - boost: Pre-limit input gain as a linear multiplier. `1.0` = unity. Higher values
|
||||||
|
/// drive harder into the limiter. Range `[1, 12]`. Defaults to `1.0`.
|
||||||
|
/// - ceiling: Output peak ceiling as a linear amplitude in `[0, 1]`. The limited output
|
||||||
|
/// never exceeds this absolute value. Range `[0.1, 1.0]`. Defaults to `0.95`.
|
||||||
|
public final class LimiterPedal: Pedal {
|
||||||
|
|
||||||
|
// MARK: - Parameters
|
||||||
|
|
||||||
|
/// Pre-limit input gain (linear multiplier). Range [1, 12].
|
||||||
|
@UIParam public var boost: Double = 1.0
|
||||||
|
|
||||||
|
/// Output peak ceiling (linear amplitude). Range [0.1, 1.0].
|
||||||
|
@UIParam public var ceiling: Double = 0.95
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
/// Default wet/dry blend — fully wet; the limiter sits in-line.
|
||||||
|
private static let defaultMix: Double = 1.0
|
||||||
|
|
||||||
|
/// Look-ahead / output delay in seconds. Fixed at a short window that catches
|
||||||
|
/// transients without smearing attack.
|
||||||
|
private let lookAheadTime: Double = 0.005
|
||||||
|
|
||||||
|
// MARK: - UI knobs
|
||||||
|
|
||||||
|
/// Boost knob range (linear pre-limit gain).
|
||||||
|
private let boostRange: ClosedRange<Double> = 1.0 ... 12.0
|
||||||
|
|
||||||
|
/// Ceiling knob range (linear output peak).
|
||||||
|
private let ceilingRange: ClosedRange<Double> = 0.1 ... 1.0
|
||||||
|
|
||||||
|
public override var effectKnobs: [PedalKnob] {
|
||||||
|
[
|
||||||
|
PedalKnob(label: "Boost", node: $boost, range: boostRange),
|
||||||
|
PedalKnob(label: "Ceiling", node: $ceiling, range: ceilingRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a limiter pedal.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - inputBus: Audio bus index to read the dry input from. Defaults to `0`.
|
||||||
|
/// - outputBus: Audio bus index to write the processed output to. Defaults to `0`.
|
||||||
|
public init(
|
||||||
|
inputBus: Int = 0,
|
||||||
|
outputBus: Int = 0
|
||||||
|
) {
|
||||||
|
super.init(
|
||||||
|
name: "Limiter",
|
||||||
|
inputBus: inputBus,
|
||||||
|
outputBus: outputBus,
|
||||||
|
initialMix: LimiterPedal.defaultMix
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Effect
|
||||||
|
|
||||||
|
/// Boosts the dry signal then constrains its peak with a look-ahead limiter.
|
||||||
|
///
|
||||||
|
/// Output is mono.
|
||||||
|
///
|
||||||
|
/// - Parameter dry: Dry mono input signal.
|
||||||
|
/// - Returns: Boosted, peak-limited mono output.
|
||||||
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
|
let boosted: any ValidGeneratorInput = dry * $boost
|
||||||
|
return LookAheadLimiter(
|
||||||
|
in: boosted,
|
||||||
|
maxAmplitude: $ceiling,
|
||||||
|
lookAheadTime: lookAheadTime,
|
||||||
|
sampleRate: sampleRate
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// MuTronPedal.swift
|
// MutantPedal.swift
|
||||||
// Lyrebird
|
// Lyrebird
|
||||||
//
|
//
|
||||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
import LyrebirdSynth
|
import LyrebirdSynth
|
||||||
import LyrebirdUI
|
import LyrebirdUI
|
||||||
|
|
||||||
/// Envelope-following filter pedal modeled on the Musitronics Mu-Tron III.
|
/// Envelope-following auto-wah / funk-filter pedal.
|
||||||
///
|
///
|
||||||
/// Wraps the Lyrebird `MuTronIII` generator. The input amplitude drives an exponential
|
/// Wraps the Lyrebird `MuTronIII` generator. The input amplitude drives an exponential
|
||||||
/// cutoff sweep through a resonant Chamberlin state-variable filter. Because `MuTronIII`
|
/// cutoff sweep through a resonant Chamberlin state-variable filter. Because `MuTronIII`
|
||||||
@@ -24,7 +24,7 @@ import LyrebirdUI
|
|||||||
/// ## Switches
|
/// ## Switches
|
||||||
/// - `direction` (two-state): `0` = Down (louder closes the filter), `1` = Up (louder opens it).
|
/// - `direction` (two-state): `0` = Down (louder closes the filter), `1` = Up (louder opens it).
|
||||||
/// - `mode` (three-state): `0` = lowpass, `1` = bandpass (classic vowel wah), `2` = highpass.
|
/// - `mode` (three-state): `0` = lowpass, `1` = bandpass (classic vowel wah), `2` = highpass.
|
||||||
public final class MuTronPedal: Pedal {
|
public final class MutantPedal: Pedal {
|
||||||
|
|
||||||
// MARK: - Parameters
|
// MARK: - Parameters
|
||||||
|
|
||||||
@@ -107,10 +107,10 @@ public final class MuTronPedal: Pedal {
|
|||||||
|
|
||||||
public init(inputBus: Int = 0, outputBus: Int = 0) {
|
public init(inputBus: Int = 0, outputBus: Int = 0) {
|
||||||
super.init(
|
super.init(
|
||||||
name: "Mu-Tron",
|
name: "Mutant",
|
||||||
inputBus: inputBus,
|
inputBus: inputBus,
|
||||||
outputBus: outputBus,
|
outputBus: outputBus,
|
||||||
initialMix: MuTronPedal.defaultMix
|
initialMix: MutantPedal.defaultMix
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
// NoiseGatePedal.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// Noise-gate pedal: an amplitude-tracked gate with a tuneable residual floor.
|
||||||
|
///
|
||||||
|
/// Signal chain (inside `effect(_:)`):
|
||||||
|
/// ```
|
||||||
|
/// dry ─┬─────────────────────────────────────────────────────────┐
|
||||||
|
/// └→ AmplitudeFollower → Schmidt(lo: thr, hi: thr×ratio) │
|
||||||
|
/// → LinLin(0…1 → floor…1) │
|
||||||
|
/// → Lag(smooth) ───────────── × ──┴→ mono out
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// An `AmplitudeFollower` tracks the dry signal level. A Schmitt trigger turns that
|
||||||
|
/// envelope into an open/closed gate with hysteresis (opens above `threshold × openRatio`,
|
||||||
|
/// closes below `threshold`) so the gate does not chatter around the threshold. The 0/1
|
||||||
|
/// gate is mapped to a gain in `[floor, 1]` and smoothed before multiplying the dry signal:
|
||||||
|
/// when the gate is closed the signal is attenuated to `floor` rather than hard-muted, so
|
||||||
|
/// `floor` sets how much of the quiet signal/noise tail bleeds through.
|
||||||
|
///
|
||||||
|
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class.
|
||||||
|
///
|
||||||
|
/// ## Parameters
|
||||||
|
///
|
||||||
|
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - threshold: Gate close threshold as a linear amplitude. Envelope below this closes
|
||||||
|
/// the gate. Range `[0, 0.2]`. Defaults to `0.02`.
|
||||||
|
/// - floor: Residual gain applied while the gate is closed, in `[0, 1]`. `0` = full
|
||||||
|
/// mute, `1` = no gating. Range `[0, 1]`. Defaults to `0.0`.
|
||||||
|
public final class NoiseGatePedal: Pedal {
|
||||||
|
|
||||||
|
// MARK: - Parameters
|
||||||
|
|
||||||
|
/// Gate close threshold (linear amplitude). Range [0, 0.2].
|
||||||
|
@UIParam public var threshold: Double = 0.02
|
||||||
|
|
||||||
|
/// Residual gain while closed, [0, 1]. Range [0, 1].
|
||||||
|
@UIParam public var floor: Double = 0.0
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
/// Default wet/dry blend — fully wet; the gate sits in-line.
|
||||||
|
private static let defaultMix: Double = 1.0
|
||||||
|
|
||||||
|
/// Envelope-follower attack time, in seconds — fast so the gate opens promptly on a note.
|
||||||
|
private let detectAttack: Double = 0.002
|
||||||
|
|
||||||
|
/// Envelope-follower release time, in seconds — slower so the gate holds through decay.
|
||||||
|
private let detectRelease: Double = 0.05
|
||||||
|
|
||||||
|
/// Open-threshold multiplier. The gate opens above `threshold × openRatio` and closes
|
||||||
|
/// below `threshold`, giving hysteresis that prevents chatter near the threshold.
|
||||||
|
private let openRatio: Double = 2.0
|
||||||
|
|
||||||
|
/// Gain-smoothing lag time, in seconds — removes the click of an instantaneous 0↔1 gate.
|
||||||
|
private let gainSmoothTime: Double = 0.01
|
||||||
|
|
||||||
|
/// Gate signal bounds for the `LinLin` floor map.
|
||||||
|
private let gateLo: Double = 0.0
|
||||||
|
private let gateHi: Double = 1.0
|
||||||
|
|
||||||
|
/// Upper gain the open gate maps to (unity).
|
||||||
|
private let openGain: Double = 1.0
|
||||||
|
|
||||||
|
// MARK: - UI knobs
|
||||||
|
|
||||||
|
/// Threshold knob range (linear amplitude).
|
||||||
|
private let thresholdRange: ClosedRange<Double> = 0.0 ... 0.2
|
||||||
|
|
||||||
|
/// Floor knob range (residual gain).
|
||||||
|
private let floorRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||||
|
|
||||||
|
public override var effectKnobs: [PedalKnob] {
|
||||||
|
[
|
||||||
|
PedalKnob(label: "Threshold", node: $threshold, range: thresholdRange),
|
||||||
|
PedalKnob(label: "Floor", node: $floor, range: floorRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a noise-gate pedal.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - inputBus: Audio bus index to read the dry input from. Defaults to `0`.
|
||||||
|
/// - outputBus: Audio bus index to write the processed output to. Defaults to `0`.
|
||||||
|
public init(
|
||||||
|
inputBus: Int = 0,
|
||||||
|
outputBus: Int = 0
|
||||||
|
) {
|
||||||
|
super.init(
|
||||||
|
name: "Noise Gate",
|
||||||
|
inputBus: inputBus,
|
||||||
|
outputBus: outputBus,
|
||||||
|
initialMix: NoiseGatePedal.defaultMix
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Effect
|
||||||
|
|
||||||
|
/// Gates the dry signal below `threshold`, attenuating closed passages to `floor`.
|
||||||
|
///
|
||||||
|
/// Output is mono.
|
||||||
|
///
|
||||||
|
/// - Parameter dry: Dry mono input signal.
|
||||||
|
/// - Returns: Gated mono output.
|
||||||
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
|
// Track the dry signal's amplitude envelope.
|
||||||
|
let envelope: AmplitudeFollower.Audio = AmplitudeFollower.Audio(
|
||||||
|
in: dry,
|
||||||
|
attackTime: detectAttack,
|
||||||
|
releaseTime: detectRelease
|
||||||
|
)
|
||||||
|
|
||||||
|
// Hysteretic open/closed gate: opens above threshold×openRatio, closes below threshold.
|
||||||
|
let gate: Schmidt.Audio = Schmidt.Audio(
|
||||||
|
input: envelope,
|
||||||
|
lo: $threshold,
|
||||||
|
hi: $threshold * openRatio
|
||||||
|
)
|
||||||
|
|
||||||
|
// Map the 0/1 gate to a gain in [floor, 1] so closed passages bleed `floor`, not silence.
|
||||||
|
let gain: LinLin.Audio = LinLin.Audio(
|
||||||
|
gate,
|
||||||
|
inLo: gateLo,
|
||||||
|
inHi: gateHi,
|
||||||
|
outLo: $floor,
|
||||||
|
outHi: openGain
|
||||||
|
)
|
||||||
|
|
||||||
|
// Smooth the gain to remove the click of an instantaneous gate transition.
|
||||||
|
let smoothed: Lag.Audio = Lag.Audio(
|
||||||
|
input: gain,
|
||||||
|
time: gainSmoothTime
|
||||||
|
)
|
||||||
|
|
||||||
|
return dry * smoothed
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -94,7 +94,7 @@ public final class PingPongDelayPedal: Pedal {
|
|||||||
public override var effectKnobs: [PedalKnob] {
|
public override var effectKnobs: [PedalKnob] {
|
||||||
[
|
[
|
||||||
PedalKnob(label: "Time", node: $time, range: timeRange),
|
PedalKnob(label: "Time", node: $time, range: timeRange),
|
||||||
PedalKnob(label: "Feedback", node: $feedback, range: feedbackRange),
|
PedalKnob(label: "Decay Time", node: $feedback, range: feedbackRange),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ public enum BoardSegmentState: Codable, Equatable {
|
|||||||
/// A stereo split region (`splitStereo()`/`collectStereo()`). Wire discriminator: `"stereoSplit"`.
|
/// A stereo split region (`splitStereo()`/`collectStereo()`). Wire discriminator: `"stereoSplit"`.
|
||||||
case stereoSplit(StereoSplitState)
|
case stereoSplit(StereoSplitState)
|
||||||
|
|
||||||
|
/// A stereo unzip region (`unzipStereo()`/`collectStereo()`). Wire discriminator: `"stereoUnzip"`.
|
||||||
|
case stereoUnzip(StereoUnzipState)
|
||||||
|
|
||||||
/// A `mergeToMono()` collapse (no payload). Wire discriminator: `"mergeToMono"`.
|
/// A `mergeToMono()` collapse (no payload). Wire discriminator: `"mergeToMono"`.
|
||||||
case mergeToMono
|
case mergeToMono
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,12 @@ extension Pedal {
|
|||||||
public func captureState() -> PedalState {
|
public func captureState() -> PedalState {
|
||||||
let values: [Double] = knobs.map { $0.node.value }
|
let values: [Double] = knobs.map { $0.node.value }
|
||||||
let switchValues: [Double] = effectSwitches.map { $0.node.value }
|
let switchValues: [Double] = effectSwitches.map { $0.node.value }
|
||||||
|
let sliderValues: [Double] = effectSliders.map { $0.node.value }
|
||||||
return PedalState(
|
return PedalState(
|
||||||
type: displayName,
|
type: displayName,
|
||||||
knobValues: values,
|
knobValues: values,
|
||||||
switchValues: switchValues,
|
switchValues: switchValues,
|
||||||
|
sliderValues: sliderValues,
|
||||||
bypass: bypass
|
bypass: bypass
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -46,6 +48,9 @@ extension Pedal {
|
|||||||
for (pedalSwitch, value) in zip(effectSwitches, state.switchValues) {
|
for (pedalSwitch, value) in zip(effectSwitches, state.switchValues) {
|
||||||
pedalSwitch.node.update(value)
|
pedalSwitch.node.update(value)
|
||||||
}
|
}
|
||||||
|
for (slider, value) in zip(effectSliders, state.sliderValues) {
|
||||||
|
slider.node.update(value)
|
||||||
|
}
|
||||||
bypass = state.bypass
|
bypass = state.bypass
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,13 @@ extension PedalBoard {
|
|||||||
route: section.route
|
route: section.route
|
||||||
))
|
))
|
||||||
|
|
||||||
|
case .stereoUnzip(let section):
|
||||||
|
return BoardSegmentState.stereoUnzip(StereoUnzipState(
|
||||||
|
left: section.left.pedals.map { $0.captureState() },
|
||||||
|
right: section.right.pedals.map { $0.captureState() },
|
||||||
|
route: section.route
|
||||||
|
))
|
||||||
|
|
||||||
case .mergeToMono:
|
case .mergeToMono:
|
||||||
return BoardSegmentState.mergeToMono
|
return BoardSegmentState.mergeToMono
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// PedalLane.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
/// Addresses where a linear pedal edit applies: the board's main chain, or one branch of a
|
||||||
|
/// split region (stereo split or parallel section).
|
||||||
|
///
|
||||||
|
/// `region` is the index of the region's segment within the board's top-level segment list
|
||||||
|
/// (`board.captureState().segments`). For a `.stereoSplit` segment, `.left`/`.right` map to its
|
||||||
|
/// left/right branches; for a `.parallel` segment they map to branch A/B.
|
||||||
|
public enum PedalLane: Equatable, Sendable {
|
||||||
|
|
||||||
|
/// The board's top-level linear chain (the `.pedal` segments).
|
||||||
|
case main
|
||||||
|
|
||||||
|
/// The left branch (stereo) / branch A (parallel) of the region segment at `region`.
|
||||||
|
case left(region: Int)
|
||||||
|
|
||||||
|
/// The right branch (stereo) / branch B (parallel) of the region segment at `region`.
|
||||||
|
case right(region: Int)
|
||||||
|
|
||||||
|
/// The region segment index this lane targets, or `nil` for ``main``.
|
||||||
|
public var regionIndex: Int? {
|
||||||
|
switch self {
|
||||||
|
case .main: return nil
|
||||||
|
case .left(let region), .right(let region): return region
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `true` for the left / A branch; `false` for the right / B branch. `false` for ``main``.
|
||||||
|
public var isLeftBranch: Bool {
|
||||||
|
if case .left = self { return true }
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
/// To register custom pedal types, extend `builtIn` by building your own dictionary
|
/// To register custom pedal types, extend `builtIn` by building your own dictionary
|
||||||
/// and merging it before calling `loadRig`. The built-in registry covers the factory
|
/// and merging it before calling `loadRig`. The built-in registry covers the factory
|
||||||
/// pedals: Overdrive, Delay, Reverb, Modulation, Fuzz, Tremolo, Phaser, Compressor,
|
/// pedals: Overdrive, Delay, Reverb, Modulation, Fuzz, Tremolo, Phaser, Compressor,
|
||||||
/// Mu-Tron, Auto-Wah, Feedback Delay, Multi-Tap Delay, Octave Splitter, and Ping-Pong.
|
/// Mutant, Auto-Wah, Feedback Delay, Multi-Tap Delay, Octave Splitter, and Ping-Pong.
|
||||||
///
|
///
|
||||||
/// > Note: A saved rig captures each board's *linear* pedal chain only (see `BoardState`).
|
/// > Note: A saved rig captures each board's *linear* pedal chain only (see `BoardState`).
|
||||||
/// > When a registered widener (e.g. Octave Splitter) or stereo-native pedal (e.g.
|
/// > When a registered widener (e.g. Octave Splitter) or stereo-native pedal (e.g.
|
||||||
@@ -39,12 +39,16 @@ public enum PedalRegistry {
|
|||||||
"Tremolo": { TremoloPedal() },
|
"Tremolo": { TremoloPedal() },
|
||||||
"Phaser": { PhaserPedal() },
|
"Phaser": { PhaserPedal() },
|
||||||
"Compressor": { CompressorPedal() },
|
"Compressor": { CompressorPedal() },
|
||||||
"Mu-Tron": { MuTronPedal() },
|
"Mutant": { MutantPedal() },
|
||||||
"Auto-Wah": { AutoWahPedal() },
|
"Auto-Wah": { AutoWahPedal() },
|
||||||
"Feedback Delay": { FeedbackDelayPedal() },
|
"Feedback Delay": { FeedbackDelayPedal() },
|
||||||
"Multi-Tap Delay": { MultiTapDelayPedal() },
|
"Multi-Tap Delay": { MultiTapDelayPedal() },
|
||||||
"Octave Splitter": { OctaveUpSplitterPedal() },
|
"Octave Splitter": { OctaveUpSplitterPedal() },
|
||||||
|
"Bass Octaver": { BassOctaverPedal() },
|
||||||
"Ping-Pong": { PingPongDelayPedal() },
|
"Ping-Pong": { PingPongDelayPedal() },
|
||||||
|
"Limiter": { LimiterPedal() },
|
||||||
|
"Noise Gate": { NoiseGatePedal() },
|
||||||
|
"Graphic EQ": { GraphicEQPedal() },
|
||||||
]
|
]
|
||||||
|
|
||||||
/// Returns a new `Pedal` instance for the given type string, or `nil` if the type
|
/// Returns a new `Pedal` instance for the given type string, or `nil` if the type
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ public struct PedalState: Codable, Equatable {
|
|||||||
/// no switches. Absent in presets saved before switches existed — decodes to `[]`.
|
/// no switches. Absent in presets saved before switches existed — decodes to `[]`.
|
||||||
public let switchValues: [Double]
|
public let switchValues: [Double]
|
||||||
|
|
||||||
|
/// Slider values in the same order as `Pedal.effectSliders`. Empty for pedals with
|
||||||
|
/// no sliders. Absent in presets saved before sliders existed — decodes to `[]`.
|
||||||
|
public let sliderValues: [Double]
|
||||||
|
|
||||||
/// Bypass parameter value. `0.0` = engaged, `1.0` = bypassed.
|
/// Bypass parameter value. `0.0` = engaged, `1.0` = bypassed.
|
||||||
public let bypass: Double
|
public let bypass: Double
|
||||||
|
|
||||||
@@ -35,16 +39,19 @@ public struct PedalState: Codable, Equatable {
|
|||||||
/// - type: The pedal's `displayName`, used to identify the pedal type on load.
|
/// - type: The pedal's `displayName`, used to identify the pedal type on load.
|
||||||
/// - knobValues: Current knob values in `Pedal.knobs` order.
|
/// - knobValues: Current knob values in `Pedal.knobs` order.
|
||||||
/// - switchValues: Current switch values in `Pedal.effectSwitches` order. Defaults to empty.
|
/// - switchValues: Current switch values in `Pedal.effectSwitches` order. Defaults to empty.
|
||||||
|
/// - sliderValues: Current slider values in `Pedal.effectSliders` order. Defaults to empty.
|
||||||
/// - bypass: Bypass parameter value (`0.0` = engaged, `1.0` = bypassed).
|
/// - bypass: Bypass parameter value (`0.0` = engaged, `1.0` = bypassed).
|
||||||
public init(
|
public init(
|
||||||
type: String,
|
type: String,
|
||||||
knobValues: [Double],
|
knobValues: [Double],
|
||||||
switchValues: [Double] = [],
|
switchValues: [Double] = [],
|
||||||
|
sliderValues: [Double] = [],
|
||||||
bypass: Double
|
bypass: Double
|
||||||
) {
|
) {
|
||||||
self.type = type
|
self.type = type
|
||||||
self.knobValues = knobValues
|
self.knobValues = knobValues
|
||||||
self.switchValues = switchValues
|
self.switchValues = switchValues
|
||||||
|
self.sliderValues = sliderValues
|
||||||
self.bypass = bypass
|
self.bypass = bypass
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,16 +59,18 @@ public struct PedalState: Codable, Equatable {
|
|||||||
case type
|
case type
|
||||||
case knobValues
|
case knobValues
|
||||||
case switchValues
|
case switchValues
|
||||||
|
case sliderValues
|
||||||
case bypass
|
case bypass
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decodes a snapshot, tolerating presets saved before `switchValues` existed by
|
/// Decodes a snapshot, tolerating presets saved before `switchValues` / `sliderValues`
|
||||||
/// defaulting the missing key to an empty array.
|
/// existed by defaulting the missing keys to an empty array.
|
||||||
public init(from decoder: any Decoder) throws {
|
public init(from decoder: any Decoder) throws {
|
||||||
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
|
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
self.type = try container.decode(String.self, forKey: .type)
|
self.type = try container.decode(String.self, forKey: .type)
|
||||||
self.knobValues = try container.decode([Double].self, forKey: .knobValues)
|
self.knobValues = try container.decode([Double].self, forKey: .knobValues)
|
||||||
self.switchValues = try container.decodeIfPresent([Double].self, forKey: .switchValues) ?? []
|
self.switchValues = try container.decodeIfPresent([Double].self, forKey: .switchValues) ?? []
|
||||||
|
self.sliderValues = try container.decodeIfPresent([Double].self, forKey: .sliderValues) ?? []
|
||||||
self.bypass = try container.decode(Double.self, forKey: .bypass)
|
self.bypass = try container.decode(Double.self, forKey: .bypass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,346 @@
|
|||||||
|
// ShoeGaze+Edit.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
extension ShoeGaze {
|
||||||
|
|
||||||
|
// MARK: - Linear pedal editing
|
||||||
|
|
||||||
|
/// Appends a pedal of the given type to the end of a lane.
|
||||||
|
///
|
||||||
|
/// The pedal is created at its constructor defaults (empty saved parameters) and the board is
|
||||||
|
/// rebuilt via ``rebuildBoard(_:from:)``. For ``PedalLane/main`` the pedal joins the top-level
|
||||||
|
/// linear chain (after the last `.pedal` segment), preserving any branch regions; for a branch
|
||||||
|
/// lane it is appended to that branch of the addressed region segment.
|
||||||
|
///
|
||||||
|
/// - Important: Editing rebuilds the board through the same path as preset load; safe on a
|
||||||
|
/// running engine with at most one block of glitch (see ``rebuildBoard(_:from:)``).
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - kind: The pedal type, e.g. ``PedalType/overdrive``. Its `rawValue` must be a key in
|
||||||
|
/// `PedalRegistry.builtIn`.
|
||||||
|
/// - board: The board to edit. Must have been returned by `addBoard()` on this instance.
|
||||||
|
/// - lane: Where to append. Defaults to ``PedalLane/main``.
|
||||||
|
/// - Returns: The rebuilt board occupying the same slot in `boards`.
|
||||||
|
/// - Throws: `ShoeGazeError.unknownPedalType`, `.notABranchRegion`, `.pedalIndexOutOfRange`, or
|
||||||
|
/// any error from ``rebuildBoard(_:from:)``.
|
||||||
|
@discardableResult
|
||||||
|
public func appendPedal(
|
||||||
|
_ kind: PedalType,
|
||||||
|
to board: PedalBoard,
|
||||||
|
lane: PedalLane = .main
|
||||||
|
) throws -> PedalBoard {
|
||||||
|
let type: String = kind.rawValue
|
||||||
|
guard PedalRegistry.builtIn[type] != nil else {
|
||||||
|
throw ShoeGazeError.unknownPedalType(type)
|
||||||
|
}
|
||||||
|
let newState: PedalState = PedalState(type: type, knobValues: [], switchValues: [], bypass: 0.0)
|
||||||
|
|
||||||
|
var segments: [BoardSegmentState] = board.captureState().segments
|
||||||
|
switch lane {
|
||||||
|
case .main:
|
||||||
|
// Insert after the last linear pedal so the new pedal joins the linear chain rather
|
||||||
|
// than landing after a trailing split region; append to the end if there are none.
|
||||||
|
let pedalPositions: [Int] = linearPedalSegmentIndices(segments)
|
||||||
|
if let lastPedalIndex: Int = pedalPositions.last {
|
||||||
|
segments.insert(.pedal(newState), at: lastPedalIndex + 1)
|
||||||
|
} else {
|
||||||
|
segments.append(.pedal(newState))
|
||||||
|
}
|
||||||
|
case .left, .right:
|
||||||
|
try mutateBranch(&segments, lane: lane) { branch in
|
||||||
|
branch.append(newState)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes the pedal at `index` within a lane.
|
||||||
|
///
|
||||||
|
/// `index` addresses the lane's own pedal order (`board.pedals` for ``PedalLane/main``; the
|
||||||
|
/// branch's pedal list for a branch lane). The board is rebuilt, preserving everything else.
|
||||||
|
///
|
||||||
|
/// - Returns: The rebuilt board occupying the same slot in `boards`.
|
||||||
|
/// - Throws: `ShoeGazeError.pedalIndexOutOfRange`, `.notABranchRegion`, or any rebuild error.
|
||||||
|
@discardableResult
|
||||||
|
public func removePedal(
|
||||||
|
at index: Int,
|
||||||
|
from board: PedalBoard,
|
||||||
|
lane: PedalLane = .main
|
||||||
|
) throws -> PedalBoard {
|
||||||
|
var segments: [BoardSegmentState] = board.captureState().segments
|
||||||
|
switch lane {
|
||||||
|
case .main:
|
||||||
|
let pedalPositions: [Int] = linearPedalSegmentIndices(segments)
|
||||||
|
guard index >= 0 && index < pedalPositions.count else {
|
||||||
|
throw ShoeGazeError.pedalIndexOutOfRange(index: index, count: pedalPositions.count)
|
||||||
|
}
|
||||||
|
segments.remove(at: pedalPositions[index])
|
||||||
|
case .left, .right:
|
||||||
|
try mutateBranch(&segments, lane: lane) { branch in
|
||||||
|
guard index >= 0 && index < branch.count else {
|
||||||
|
throw ShoeGazeError.pedalIndexOutOfRange(index: index, count: branch.count)
|
||||||
|
}
|
||||||
|
branch.remove(at: index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Moves the pedal at `sourceIndex` to `destinationIndex` within a lane.
|
||||||
|
///
|
||||||
|
/// Indices address the lane's own pedal order. `destinationIndex` follows SwiftUI
|
||||||
|
/// `List.onMove` semantics (insert-before index in the original coordinate space).
|
||||||
|
///
|
||||||
|
/// - Returns: The rebuilt board occupying the same slot in `boards`.
|
||||||
|
/// - Throws: `ShoeGazeError.pedalIndexOutOfRange`, `.notABranchRegion`, or any rebuild error.
|
||||||
|
@discardableResult
|
||||||
|
public func movePedal(
|
||||||
|
from sourceIndex: Int,
|
||||||
|
to destinationIndex: Int,
|
||||||
|
in board: PedalBoard,
|
||||||
|
lane: PedalLane = .main
|
||||||
|
) throws -> PedalBoard {
|
||||||
|
var segments: [BoardSegmentState] = board.captureState().segments
|
||||||
|
switch lane {
|
||||||
|
case .main:
|
||||||
|
try moveMainPedal(&segments, from: sourceIndex, to: destinationIndex)
|
||||||
|
case .left, .right:
|
||||||
|
try mutateBranch(&segments, lane: lane) { branch in
|
||||||
|
try Self.moveWithinArray(&branch, from: sourceIndex, to: destinationIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Branch regions
|
||||||
|
|
||||||
|
/// Appends an empty stereo split region (two independently authored L/R lanes) to the board.
|
||||||
|
///
|
||||||
|
/// Requires the board's tail to be mono — a stereo split fans a mono signal into two branches
|
||||||
|
/// (see `PedalBoard.splitStereo()`). Add pedals to each lane with `appendPedal(... lane:)`.
|
||||||
|
///
|
||||||
|
/// - Returns: The rebuilt board occupying the same slot in `boards`.
|
||||||
|
/// - Throws: `ShoeGazeError.cannotSplitStereoChain` when the tail is already stereo; any
|
||||||
|
/// rebuild error.
|
||||||
|
@discardableResult
|
||||||
|
public func appendStereoSplit(to board: PedalBoard) throws -> PedalBoard {
|
||||||
|
guard board.width == 1 else { throw ShoeGazeError.cannotSplitStereoChain }
|
||||||
|
var segments: [BoardSegmentState] = board.captureState().segments
|
||||||
|
segments.append(.stereoSplit(StereoSplitState(left: [], right: [], route: .stereo)))
|
||||||
|
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Inserts an empty stereo-unzip region immediately after the segment at `topLevelIndex`,
|
||||||
|
/// splitting the stereo signal at that point into two independently editable L/R lanes.
|
||||||
|
///
|
||||||
|
/// Used by the per-pedal "Split L/R" toggle: pass the stereo pedal's segment index. No board-
|
||||||
|
/// level width guard is needed — `rebuildSegments` replays segments in order, so
|
||||||
|
/// `unzipStereo()`'s own `width == 2` check validates the *local* width at the insertion point;
|
||||||
|
/// an invalid insert throws and the atomic `rebuildBoard` leaves the existing board intact.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - topLevelIndex: Segment index (in `captureState().segments`) after which to insert.
|
||||||
|
/// - board: The board to edit.
|
||||||
|
/// - Returns: The rebuilt board occupying the same slot in `boards`.
|
||||||
|
/// - Throws: `ShoeGazeError.pedalIndexOutOfRange` for a bad index;
|
||||||
|
/// `ShoeGazeError.cannotUnzipMonoChain` if the signal at that point is mono; any rebuild error.
|
||||||
|
@discardableResult
|
||||||
|
public func insertStereoUnzip(afterSegment topLevelIndex: Int, in board: PedalBoard) throws -> PedalBoard {
|
||||||
|
var segments: [BoardSegmentState] = board.captureState().segments
|
||||||
|
guard topLevelIndex >= 0 && topLevelIndex < segments.count else {
|
||||||
|
throw ShoeGazeError.pedalIndexOutOfRange(index: topLevelIndex, count: segments.count)
|
||||||
|
}
|
||||||
|
segments.insert(
|
||||||
|
.stereoUnzip(StereoUnzipState(left: [], right: [], route: .stereo)),
|
||||||
|
at: topLevelIndex + 1
|
||||||
|
)
|
||||||
|
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` when the segment immediately after `topLevelIndex` is a stereo-unzip region —
|
||||||
|
/// i.e. the "Split L/R" toggle for the pedal at `topLevelIndex` is on.
|
||||||
|
public func isStereoUnzip(afterSegment topLevelIndex: Int, in board: PedalBoard) -> Bool {
|
||||||
|
let segments: [BoardSegmentState] = board.captureState().segments
|
||||||
|
let next: Int = topLevelIndex + 1
|
||||||
|
guard next >= 0 && next < segments.count else { return false }
|
||||||
|
if case .stereoUnzip = segments[next] { return true }
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Appends an empty parallel section (two A/B branches summed back to one signal) to the board.
|
||||||
|
///
|
||||||
|
/// - Returns: The rebuilt board occupying the same slot in `boards`.
|
||||||
|
/// - Throws: Any error from ``rebuildBoard(_:from:)``.
|
||||||
|
@discardableResult
|
||||||
|
public func appendParallelSplit(to board: PedalBoard) throws -> PedalBoard {
|
||||||
|
var segments: [BoardSegmentState] = board.captureState().segments
|
||||||
|
segments.append(.parallel(ParallelSectionState(branchA: [], branchB: [], mode: .both)))
|
||||||
|
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Appends a merge-to-mono node, collapsing a stereo tail back to mono.
|
||||||
|
///
|
||||||
|
/// - Returns: The rebuilt board occupying the same slot in `boards`.
|
||||||
|
/// - Throws: `ShoeGazeError.cannotMergeMonoChain` when the tail is already mono; any rebuild error.
|
||||||
|
@discardableResult
|
||||||
|
public func appendMergeToMono(to board: PedalBoard) throws -> PedalBoard {
|
||||||
|
guard board.width == 2 else { throw ShoeGazeError.cannotMergeMonoChain }
|
||||||
|
var segments: [BoardSegmentState] = board.captureState().segments
|
||||||
|
segments.append(.mergeToMono)
|
||||||
|
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes the top-level segment (a linear pedal, a split region, or a merge node) at
|
||||||
|
/// `topLevelIndex` — its index within `board.captureState().segments`.
|
||||||
|
///
|
||||||
|
/// - Returns: The rebuilt board occupying the same slot in `boards`.
|
||||||
|
/// - Throws: `ShoeGazeError.pedalIndexOutOfRange` when the index is invalid; any rebuild error.
|
||||||
|
@discardableResult
|
||||||
|
public func removeSegment(at topLevelIndex: Int, from board: PedalBoard) throws -> PedalBoard {
|
||||||
|
var segments: [BoardSegmentState] = board.captureState().segments
|
||||||
|
guard topLevelIndex >= 0 && topLevelIndex < segments.count else {
|
||||||
|
throw ShoeGazeError.pedalIndexOutOfRange(index: topLevelIndex, count: segments.count)
|
||||||
|
}
|
||||||
|
segments.remove(at: topLevelIndex)
|
||||||
|
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Input source switching
|
||||||
|
|
||||||
|
/// Changes the input source while preserving the current rig.
|
||||||
|
///
|
||||||
|
/// `addBoard()` wires the input source (test loop or hardware pass-through) into each board at
|
||||||
|
/// creation time, so switching the source means recreating that wiring. This captures the full
|
||||||
|
/// rig, tears it down, sets `inputSource`, and rebuilds every board from the snapshot —
|
||||||
|
/// preserving labels, pedals, and split-region topology. No-op when the source is unchanged.
|
||||||
|
///
|
||||||
|
/// - Important: Call with the engine **stopped** (the same teardown/rebuild caveat as
|
||||||
|
/// ``loadRig(from:)``). Switching to `.liveInput` requires enough engine input channels.
|
||||||
|
/// Reconstruction is atomic: on any failure the rig is torn down and the error rethrown.
|
||||||
|
///
|
||||||
|
/// - Parameter newSource: The input source to switch to.
|
||||||
|
/// - Throws: `ShoeGazeError.liveInputRequiresInputChannels` / `inputChannelOutOfRange`,
|
||||||
|
/// `BusAllocatorError.noFreeBus`, or `EngineAddError` from board reconstruction.
|
||||||
|
public func setInputSource(_ newSource: InputSource) throws {
|
||||||
|
if newSource == inputSource { return }
|
||||||
|
|
||||||
|
let snapshot: ShoeGazeState = captureState()
|
||||||
|
teardown()
|
||||||
|
inputSource = newSource
|
||||||
|
try rebuildAllBoards(from: snapshot)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Helpers
|
||||||
|
|
||||||
|
/// Returns the absolute indices, within `segments`, of the `.pedal` segments in order. The
|
||||||
|
/// position of an entry in the returned array is its linear pedal index (`board.pedals` order).
|
||||||
|
private func linearPedalSegmentIndices(_ segments: [BoardSegmentState]) -> [Int] {
|
||||||
|
var indices: [Int] = []
|
||||||
|
for (absoluteIndex, segment) in segments.enumerated() {
|
||||||
|
if case .pedal = segment { indices.append(absoluteIndex) }
|
||||||
|
}
|
||||||
|
return indices
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Mutates the branch pedal list addressed by `lane` in place, rebuilding the region's enum
|
||||||
|
/// case. Throws `notABranchRegion` if the addressed segment is not a split/parallel region.
|
||||||
|
private func mutateBranch(
|
||||||
|
_ segments: inout [BoardSegmentState],
|
||||||
|
lane: PedalLane,
|
||||||
|
_ transform: (inout [PedalState]) throws -> Void
|
||||||
|
) throws {
|
||||||
|
// Callers only reach this for `.left`/`.right`; `.main` has no region and is handled
|
||||||
|
// separately. Treat a `.main` lane here as a programming error rather than a silent no-op.
|
||||||
|
guard let region: Int = lane.regionIndex else {
|
||||||
|
assertionFailure("mutateBranch called with the .main lane")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard region >= 0 && region < segments.count else {
|
||||||
|
throw ShoeGazeError.pedalIndexOutOfRange(index: region, count: segments.count)
|
||||||
|
}
|
||||||
|
let isLeft: Bool = lane.isLeftBranch
|
||||||
|
switch segments[region] {
|
||||||
|
case .stereoSplit(let state):
|
||||||
|
var left: [PedalState] = state.left
|
||||||
|
var right: [PedalState] = state.right
|
||||||
|
if isLeft { try transform(&left) } else { try transform(&right) }
|
||||||
|
segments[region] = .stereoSplit(StereoSplitState(left: left, right: right, route: state.route))
|
||||||
|
case .stereoUnzip(let state):
|
||||||
|
var left: [PedalState] = state.left
|
||||||
|
var right: [PedalState] = state.right
|
||||||
|
if isLeft { try transform(&left) } else { try transform(&right) }
|
||||||
|
segments[region] = .stereoUnzip(StereoUnzipState(left: left, right: right, route: state.route))
|
||||||
|
case .parallel(let state):
|
||||||
|
var branchA: [PedalState] = state.branchA
|
||||||
|
var branchB: [PedalState] = state.branchB
|
||||||
|
if isLeft { try transform(&branchA) } else { try transform(&branchB) }
|
||||||
|
segments[region] = .parallel(
|
||||||
|
ParallelSectionState(branchA: branchA, branchB: branchB, mode: state.mode)
|
||||||
|
)
|
||||||
|
default:
|
||||||
|
throw ShoeGazeError.notABranchRegion(index: region)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Moves a `.pedal` within the top-level chain, preserving interleaved branch regions.
|
||||||
|
private func moveMainPedal(
|
||||||
|
_ segments: inout [BoardSegmentState],
|
||||||
|
from sourceIndex: Int,
|
||||||
|
to destinationIndex: Int
|
||||||
|
) throws {
|
||||||
|
let pedalPositions: [Int] = linearPedalSegmentIndices(segments)
|
||||||
|
let pedalCount: Int = pedalPositions.count
|
||||||
|
guard sourceIndex >= 0 && sourceIndex < pedalCount else {
|
||||||
|
throw ShoeGazeError.pedalIndexOutOfRange(index: sourceIndex, count: pedalCount)
|
||||||
|
}
|
||||||
|
guard destinationIndex >= 0 && destinationIndex <= pedalCount else {
|
||||||
|
throw ShoeGazeError.pedalIndexOutOfRange(index: destinationIndex, count: pedalCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
let movedSegment: BoardSegmentState = segments.remove(at: pedalPositions[sourceIndex])
|
||||||
|
let remainingPositions: [Int] = linearPedalSegmentIndices(segments)
|
||||||
|
// SwiftUI `toOffset` is an insert-before index in the original space; after removing the
|
||||||
|
// source, slots above it shift down by one.
|
||||||
|
let adjustedDestination: Int = destinationIndex > sourceIndex
|
||||||
|
? destinationIndex - 1
|
||||||
|
: destinationIndex
|
||||||
|
let insertionAbsolute: Int
|
||||||
|
if adjustedDestination < remainingPositions.count {
|
||||||
|
insertionAbsolute = remainingPositions[adjustedDestination]
|
||||||
|
} else if let lastPedalAbsolute: Int = remainingPositions.last {
|
||||||
|
// Moving to the end of the linear chain: land immediately after the last linear pedal,
|
||||||
|
// BEFORE any trailing routing nodes (a stereo split or mergeToMono), so a pedal never
|
||||||
|
// jumps past a width-conversion node. Mirrors `appendPedal`'s insert-after-last rule.
|
||||||
|
insertionAbsolute = lastPedalAbsolute + 1
|
||||||
|
} else {
|
||||||
|
insertionAbsolute = segments.count
|
||||||
|
}
|
||||||
|
segments.insert(movedSegment, at: insertionAbsolute)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Moves an element within a contiguous array using SwiftUI `List.onMove` (`toOffset`) semantics.
|
||||||
|
private static func moveWithinArray<T>(
|
||||||
|
_ array: inout [T],
|
||||||
|
from sourceIndex: Int,
|
||||||
|
to destinationIndex: Int
|
||||||
|
) throws {
|
||||||
|
let count: Int = array.count
|
||||||
|
guard sourceIndex >= 0 && sourceIndex < count else {
|
||||||
|
throw ShoeGazeError.pedalIndexOutOfRange(index: sourceIndex, count: count)
|
||||||
|
}
|
||||||
|
guard destinationIndex >= 0 && destinationIndex <= count else {
|
||||||
|
throw ShoeGazeError.pedalIndexOutOfRange(index: destinationIndex, count: count)
|
||||||
|
}
|
||||||
|
// Manual move with SwiftUI `toOffset` semantics (insert-before in the original space):
|
||||||
|
// remove the source, then insert at the destination shifted down by one when it was past
|
||||||
|
// the source. Avoids depending on SwiftUI's `move(fromOffsets:toOffset:)` in the core module.
|
||||||
|
let element: T = array.remove(at: sourceIndex)
|
||||||
|
let insertionIndex: Int = destinationIndex > sourceIndex ? destinationIndex - 1 : destinationIndex
|
||||||
|
array.insert(element, at: insertionIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
// ShoeGaze+Engine.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
|
||||||
|
extension ShoeGaze {
|
||||||
|
|
||||||
|
/// Reconfigures the engine's sample rate and channel counts while preserving the rig.
|
||||||
|
///
|
||||||
|
/// The engine must be **stopped** (the underlying `SynthesisEngine` setters throw
|
||||||
|
/// `SynthesisEngineConfigError.engineIsRunning` otherwise). The current rig is captured,
|
||||||
|
/// the engine is reconfigured, and every board is rebuilt from the snapshot so that
|
||||||
|
/// sample-rate-dependent nodes — e.g. ``TestLoopSource``'s Karplus-Strong delay line, sized at
|
||||||
|
/// init from the engine rate — are recreated at the new rate. Reconstruction reuses the atomic
|
||||||
|
/// ``rebuildAllBoards(from:)`` (teardown-on-failure), so a failure leaves an empty rig rather
|
||||||
|
/// than a half-built one.
|
||||||
|
///
|
||||||
|
/// If the current `inputSource` is `.liveInput(channel:)` and `channel` is no longer valid
|
||||||
|
/// under `inputChannels`, the source is reset to `.testLoop` before rebuilding.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - sampleRate: New engine sample rate in Hz.
|
||||||
|
/// - inputChannels: New hardware input-channel count (`>= 0`).
|
||||||
|
/// - outputChannels: New hardware output-channel count (`>= 1`).
|
||||||
|
/// - Throws: `SynthesisEngineConfigError.engineIsRunning` if the engine is running;
|
||||||
|
/// `SynthesisEngineConfigError.invalidValue` for out-of-range values; or any error from
|
||||||
|
/// board reconstruction.
|
||||||
|
public func reconfigureEngine(
|
||||||
|
sampleRate: Double,
|
||||||
|
inputChannels: Int,
|
||||||
|
outputChannels: Int
|
||||||
|
) throws {
|
||||||
|
guard !engine.isRunning else { throw SynthesisEngineConfigError.engineIsRunning }
|
||||||
|
|
||||||
|
// The tapped bus indices depend on the channel layout (input buses follow the output
|
||||||
|
// buses), so the scope tap must be rebuilt for the final configuration — on every exit
|
||||||
|
// path, including a thrown rebuild, so `engine.scopeTap` never points at a stale layout.
|
||||||
|
defer { installScopeTap() }
|
||||||
|
|
||||||
|
let snapshot: ShoeGazeState = captureState()
|
||||||
|
|
||||||
|
// Tear the rig down BEFORE reconfiguring: changing the channel counts re-partitions the
|
||||||
|
// bus allocator's hardware reservation, which would invalidate (double-free) any rig buses
|
||||||
|
// still allocated under the old layout.
|
||||||
|
teardown()
|
||||||
|
|
||||||
|
try engine.setSampleRate(sampleRate)
|
||||||
|
try engine.setNumOutputChannels(outputChannels)
|
||||||
|
try engine.setNumInputChannels(inputChannels)
|
||||||
|
|
||||||
|
// A live-input source pointing at a channel that no longer exists would make the rebuild's
|
||||||
|
// addBoard() throw; fall back to the test loop.
|
||||||
|
if case .liveInput(let channel) = inputSource, channel >= inputChannels {
|
||||||
|
inputSource = .testLoop
|
||||||
|
}
|
||||||
|
|
||||||
|
try rebuildAllBoards(from: snapshot)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Default samples-per-frame captured by the scope tap.
|
||||||
|
public static let defaultScopeBufferSize: Int = 2_048
|
||||||
|
|
||||||
|
/// (Re)builds the ``scopeTap`` over the current hardware input + output buses and assigns it
|
||||||
|
/// to the engine, so the debug scope view can visualise both the live input signal and the
|
||||||
|
/// board output.
|
||||||
|
///
|
||||||
|
/// Lane order is **inputs first** (`In 0`, `In 1`, …) then **outputs** (`Out L`, `Out R`, …),
|
||||||
|
/// so the input waveform sits at the top of the scope. Must be called while the engine is
|
||||||
|
/// stopped — `SynthesisEngine` caches its scope tap at `start()`. Rebuilt automatically by
|
||||||
|
/// ``reconfigureEngine(sampleRate:inputChannels:outputChannels:)`` and at init.
|
||||||
|
///
|
||||||
|
/// - Parameter bufferSize: Samples per channel per display frame. Defaults to 2048.
|
||||||
|
public func installScopeTap(bufferSize: Int = ShoeGaze.defaultScopeBufferSize) {
|
||||||
|
// `SynthesisEngine` caches its scope tap as `_rtScopeTap` at `start()`; assigning a new tap
|
||||||
|
// while running would silently diverge the RT thread's cached tap from `engine.scopeTap`.
|
||||||
|
precondition(!engine.isRunning, "installScopeTap must be called while the engine is stopped")
|
||||||
|
|
||||||
|
let numOut: Int = engine.numOutputChannels
|
||||||
|
let numIn: Int = engine.numInputChannels
|
||||||
|
|
||||||
|
var buses: [Int] = []
|
||||||
|
for ch: Int in 0..<numIn { buses.append(numOut + ch) } // hardware inputs (top lanes)
|
||||||
|
for ch: Int in 0..<numOut { buses.append(ch) } // outputs (lower lanes)
|
||||||
|
|
||||||
|
guard !buses.isEmpty else {
|
||||||
|
engine.scopeTap = nil
|
||||||
|
scopeTap = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let capture: ScopeCapture = ScopeCapture(buses: buses, bufferSize: bufferSize)
|
||||||
|
engine.scopeTap = capture
|
||||||
|
scopeTap = capture
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Human-readable label for a tapped audio-bus index under the current engine layout.
|
||||||
|
///
|
||||||
|
/// Output buses (`bus < numOutputChannels`) are `Out L` / `Out R` / `Out N`; the remaining
|
||||||
|
/// buses are hardware inputs `In 0`, `In 1`, … Used by the scope view to label each lane.
|
||||||
|
///
|
||||||
|
/// - Parameter bus: An audio-bus index, typically one of ``scopeTap``'s `buses`.
|
||||||
|
public func scopeLaneLabel(forBus bus: Int) -> String {
|
||||||
|
let numOut: Int = engine.numOutputChannels
|
||||||
|
guard bus >= numOut else {
|
||||||
|
let stereoNames: [String] = ["Out L", "Out R"]
|
||||||
|
return bus < stereoNames.count ? stereoNames[bus] : "Out \(bus)"
|
||||||
|
}
|
||||||
|
return "In \(bus - numOut)"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,10 +31,65 @@ extension ShoeGaze {
|
|||||||
/// - Parameter url: Destination file URL. The directory must already exist.
|
/// - Parameter url: Destination file URL. The directory must already exist.
|
||||||
/// - Throws: Any error from `JSONEncoder` or `Data.write(to:options:)`.
|
/// - Throws: Any error from `JSONEncoder` or `Data.write(to:options:)`.
|
||||||
public func saveRig(to url: URL) throws {
|
public func saveRig(to url: URL) throws {
|
||||||
|
try rigData().write(to: url, options: .atomic)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Encodes the current rig to pretty-printed JSON `Data`.
|
||||||
|
///
|
||||||
|
/// Same payload `saveRig(to:)` writes to disk; exposed for callers that need the bytes
|
||||||
|
/// directly (e.g. a SwiftUI `fileExporter` `FileDocument` on iOS).
|
||||||
|
///
|
||||||
|
/// - Returns: The encoded `ShoeGazeState` JSON.
|
||||||
|
/// - Throws: Any error from `JSONEncoder`.
|
||||||
|
public func rigData() throws -> Data {
|
||||||
let encoder: JSONEncoder = JSONEncoder()
|
let encoder: JSONEncoder = JSONEncoder()
|
||||||
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
|
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
|
||||||
let data: Data = try encoder.encode(captureState())
|
return try encoder.encode(captureState())
|
||||||
try data.write(to: url, options: .atomic)
|
}
|
||||||
|
|
||||||
|
/// Loads a rig from in-memory JSON `Data` and rebuilds the engine graph.
|
||||||
|
///
|
||||||
|
/// Identical to ``loadRig(from:)`` but reads from `Data` rather than a file URL — convenient
|
||||||
|
/// for a SwiftUI `fileImporter` that has already read the document, or for tests.
|
||||||
|
///
|
||||||
|
/// - Important: Call with the engine **stopped**, as with ``loadRig(from:)``.
|
||||||
|
/// - Parameter data: JSON produced by ``rigData()`` / ``saveRig(to:)``.
|
||||||
|
/// - Throws: `JSONDecoder` errors, `PresetError.unsupportedVersion`, or any board-build error.
|
||||||
|
public func loadRig(from data: Data) throws {
|
||||||
|
let decoder: JSONDecoder = JSONDecoder()
|
||||||
|
let state: ShoeGazeState = try decoder.decode(ShoeGazeState.self, from: data)
|
||||||
|
guard state.version <= presetFormatVersion else {
|
||||||
|
throw PresetError.unsupportedVersion(state.version)
|
||||||
|
}
|
||||||
|
|
||||||
|
teardown()
|
||||||
|
try rebuildAllBoards(from: state)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Rebuilds every board from a snapshot with all-or-nothing semantics.
|
||||||
|
///
|
||||||
|
/// The caller is responsible for tearing down any existing rig first. On any failure while
|
||||||
|
/// reconstructing a board, the partially-built rig is torn down and the error rethrown, so
|
||||||
|
/// callers never observe a half-built rig — a board that fails on iteration N does not leave
|
||||||
|
/// boards `0..<N` stranded.
|
||||||
|
///
|
||||||
|
/// `internal` so `setInputSource(_:)` in `ShoeGaze+Edit.swift` shares the same atomic path.
|
||||||
|
///
|
||||||
|
/// - Parameter snapshot: The rig snapshot to reconstruct.
|
||||||
|
/// - Throws: `BusAllocatorError`, `EngineAddError`, or `ShoeGazeError` from board construction.
|
||||||
|
func rebuildAllBoards(from snapshot: ShoeGazeState) throws {
|
||||||
|
do {
|
||||||
|
for boardState: BoardState in snapshot.boards {
|
||||||
|
let board: PedalBoard = try addBoard()
|
||||||
|
board.label = boardState.label
|
||||||
|
try rebuildSegments(boardState.segments, into: board)
|
||||||
|
try finalizeBoard(board)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// Leave no partial rig behind: tear down whatever was built, then rethrow.
|
||||||
|
teardown()
|
||||||
|
throw error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Loads a rig from a JSON preset file and rebuilds the engine graph.
|
/// Loads a rig from a JSON preset file and rebuilds the engine graph.
|
||||||
@@ -57,21 +112,7 @@ extension ShoeGaze {
|
|||||||
/// `PresetError.unsupportedVersion` when the file's version exceeds
|
/// `PresetError.unsupportedVersion` when the file's version exceeds
|
||||||
/// `presetFormatVersion`.
|
/// `presetFormatVersion`.
|
||||||
public func loadRig(from url: URL) throws {
|
public func loadRig(from url: URL) throws {
|
||||||
let data: Data = try Data(contentsOf: url)
|
try loadRig(from: try Data(contentsOf: url))
|
||||||
let decoder: JSONDecoder = JSONDecoder()
|
|
||||||
let state: ShoeGazeState = try decoder.decode(ShoeGazeState.self, from: data)
|
|
||||||
guard state.version <= presetFormatVersion else {
|
|
||||||
throw PresetError.unsupportedVersion(state.version)
|
|
||||||
}
|
|
||||||
|
|
||||||
teardown()
|
|
||||||
|
|
||||||
for boardState: BoardState in state.boards {
|
|
||||||
let board: PedalBoard = try addBoard()
|
|
||||||
board.label = boardState.label
|
|
||||||
try rebuildSegments(boardState.segments, into: board)
|
|
||||||
try finalizeBoard(board)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Segment reconstruction
|
// MARK: - Segment reconstruction
|
||||||
@@ -84,7 +125,10 @@ extension ShoeGaze {
|
|||||||
/// - segments: The ordered segment snapshots to reconstruct.
|
/// - segments: The ordered segment snapshots to reconstruct.
|
||||||
/// - board: The board to populate (freshly created, before `finalizeBoard`).
|
/// - board: The board to populate (freshly created, before `finalizeBoard`).
|
||||||
/// - Throws: `BusAllocatorError.noFreeBus` or `EngineAddError` from any node insertion.
|
/// - Throws: `BusAllocatorError.noFreeBus` or `EngineAddError` from any node insertion.
|
||||||
private func rebuildSegments(_ segments: [BoardSegmentState], into board: PedalBoard) throws {
|
///
|
||||||
|
/// `internal` (not `private`) so the linear-edit and input-switch helpers in
|
||||||
|
/// `ShoeGaze+Edit.swift` can replay a captured topology onto a freshly created board.
|
||||||
|
func rebuildSegments(_ segments: [BoardSegmentState], into board: PedalBoard) throws {
|
||||||
for segment: BoardSegmentState in segments {
|
for segment: BoardSegmentState in segments {
|
||||||
switch segment {
|
switch segment {
|
||||||
case .pedal(let state):
|
case .pedal(let state):
|
||||||
@@ -106,6 +150,13 @@ extension ShoeGaze {
|
|||||||
try board.collectStereo(section)
|
try board.collectStereo(section)
|
||||||
section.route = stereoState.route
|
section.route = stereoState.route
|
||||||
|
|
||||||
|
case .stereoUnzip(let unzipState):
|
||||||
|
let section: StereoSplitSection = try board.unzipStereo()
|
||||||
|
try addPedals(unzipState.left, to: section.left)
|
||||||
|
try addPedals(unzipState.right, to: section.right)
|
||||||
|
try board.collectStereo(section)
|
||||||
|
section.route = unzipState.route
|
||||||
|
|
||||||
case .mergeToMono:
|
case .mergeToMono:
|
||||||
try board.mergeToMono()
|
try board.mergeToMono()
|
||||||
}
|
}
|
||||||
@@ -245,6 +296,11 @@ extension ShoeGaze {
|
|||||||
applyBranchParams(stereoState.right, to: section.right.pedals)
|
applyBranchParams(stereoState.right, to: section.right.pedals)
|
||||||
section.route = stereoState.route
|
section.route = stereoState.route
|
||||||
|
|
||||||
|
case let (.stereoUnzip(section), .stereoUnzip(unzipState)):
|
||||||
|
applyBranchParams(unzipState.left, to: section.left.pedals)
|
||||||
|
applyBranchParams(unzipState.right, to: section.right.pedals)
|
||||||
|
section.route = unzipState.route
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Topology mismatch at this position — skip.
|
// Topology mismatch at this position — skip.
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// StereoUnzipState.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
/// Serialisable snapshot of a stereo unzip region (`unzipStereo()` → two branches →
|
||||||
|
/// `collectStereo()`).
|
||||||
|
///
|
||||||
|
/// Captures the left and right branch pedal chains in signal-flow order plus the active
|
||||||
|
/// ``StereoRoute``. Reconstructed by `loadRig`/`rebuildBoard` via `board.unzipStereo()`, adding the
|
||||||
|
/// branch pedals, `board.collectStereo(_:)`, then restoring `route`. Structurally identical to
|
||||||
|
/// ``StereoSplitState`` — the distinct type keeps the unzip vs split distinction in presets so the
|
||||||
|
/// correct splitter (stereo-deinterleave vs mono-duplicate) is rebuilt.
|
||||||
|
public struct StereoUnzipState: Codable, Equatable {
|
||||||
|
|
||||||
|
/// Left-channel branch pedal snapshots in signal-flow order.
|
||||||
|
public let left: [PedalState]
|
||||||
|
|
||||||
|
/// Right-channel branch pedal snapshots in signal-flow order.
|
||||||
|
public let right: [PedalState]
|
||||||
|
|
||||||
|
/// The output route mode (`.stereo` / `.leftOnly` / `.rightOnly` / `.bypass`).
|
||||||
|
public let route: StereoRoute
|
||||||
|
|
||||||
|
/// Creates a stereo unzip snapshot.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - left: Left-branch pedal snapshots in order.
|
||||||
|
/// - right: Right-branch pedal snapshots in order.
|
||||||
|
/// - route: The output route mode.
|
||||||
|
public init(
|
||||||
|
left: [PedalState],
|
||||||
|
right: [PedalState],
|
||||||
|
route: StereoRoute
|
||||||
|
) {
|
||||||
|
self.left = left
|
||||||
|
self.right = right
|
||||||
|
self.route = route
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,8 +32,9 @@ public final class StereoSplitSection {
|
|||||||
|
|
||||||
// MARK: - Nodes and chains
|
// MARK: - Nodes and chains
|
||||||
|
|
||||||
/// The splitter that fans the pre-split mono signal into both branches plus the dry tap.
|
/// The head node that feeds the two branches plus the dry tap — a ``StereoSplitter`` for a
|
||||||
public let splitter: StereoSplitter
|
/// mono split, or a ``StereoUnzipSplitter`` for a stereo unzip. Stored for reference only.
|
||||||
|
public let splitter: any Synthesizer
|
||||||
|
|
||||||
/// The left branch sub-chain. Its tail becomes the left output channel.
|
/// The left branch sub-chain. Its tail becomes the left output channel.
|
||||||
public let left: BranchChain
|
public let left: BranchChain
|
||||||
@@ -60,13 +61,13 @@ public final class StereoSplitSection {
|
|||||||
/// Creates a stereo split section. Called internally by ``PedalBoard/splitStereo()``.
|
/// Creates a stereo split section. Called internally by ``PedalBoard/splitStereo()``.
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - splitter: The ``StereoSplitter`` feeding the two branches and the dry tap.
|
/// - splitter: The head node feeding the two branches and the dry tap.
|
||||||
/// - left: The left branch sub-chain.
|
/// - left: The left branch sub-chain.
|
||||||
/// - right: The right branch sub-chain.
|
/// - right: The right branch sub-chain.
|
||||||
/// - sharedTail: The shared tail tracking pointer used by both branch chains.
|
/// - sharedTail: The shared tail tracking pointer used by both branch chains.
|
||||||
/// - dryTapBus: The clean pre-split tap bus.
|
/// - dryTapBus: The clean pre-split tap bus.
|
||||||
init(
|
init(
|
||||||
splitter: StereoSplitter,
|
splitter: any Synthesizer,
|
||||||
left: BranchChain,
|
left: BranchChain,
|
||||||
right: BranchChain,
|
right: BranchChain,
|
||||||
sharedTail: SharedTail,
|
sharedTail: SharedTail,
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
// StereoUnzipSplitter.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
|
||||||
|
/// Splits an existing stereo signal's two channels into two independent branch inputs, plus a
|
||||||
|
/// centered mono dry tap.
|
||||||
|
///
|
||||||
|
/// This is the head of a *stereo unzip* region (the stereo counterpart of ``StereoSplitter``).
|
||||||
|
/// Where `StereoSplitter` duplicates one mono input into both branches, `StereoUnzipSplitter`
|
||||||
|
/// reads the current left and right tails and routes each into its own branch so the channels can
|
||||||
|
/// be processed independently, then recombined by a ``StereoRouteCollector`` (reused from the
|
||||||
|
/// stereo split). The dry tap carries `0.5·L + 0.5·R` — a centered mono monitor of the pre-unzip
|
||||||
|
/// signal for the collector's `bypass` route.
|
||||||
|
///
|
||||||
|
/// ## Signal graph
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// inputLeft → In.Audio → outputBusLeft (left branch input)
|
||||||
|
/// inputRight → In.Audio → outputBusRight (right branch input)
|
||||||
|
/// (0.5·L + 0.5·R) → dryTapBus (centered mono monitor)
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - inputLeft: Audio bus index of the incoming left channel.
|
||||||
|
/// - inputRight: Audio bus index of the incoming right channel.
|
||||||
|
/// - outputBusLeft: Audio bus index for the left branch input.
|
||||||
|
/// - outputBusRight: Audio bus index for the right branch input.
|
||||||
|
/// - dryTapBus: Audio bus index for the centered mono dry tap.
|
||||||
|
public final class StereoUnzipSplitter: SynthesizerBase {
|
||||||
|
|
||||||
|
// MARK: - Routing
|
||||||
|
|
||||||
|
/// Audio bus index of the incoming left channel.
|
||||||
|
public internal(set) var inputLeft: Int
|
||||||
|
|
||||||
|
/// Audio bus index of the incoming right channel.
|
||||||
|
public internal(set) var inputRight: Int
|
||||||
|
|
||||||
|
/// Audio bus index for the left branch input.
|
||||||
|
public internal(set) var outputBusLeft: Int
|
||||||
|
|
||||||
|
/// Audio bus index for the right branch input.
|
||||||
|
public internal(set) var outputBusRight: Int
|
||||||
|
|
||||||
|
/// Audio bus index for the centered mono dry tap.
|
||||||
|
public internal(set) var dryTapBus: Int
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
/// Per-channel gain for the centered mono dry sum, so two correlated channels do not double.
|
||||||
|
private static let dryChannelGain: Double = 0.5
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a stereo unzip splitter.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - inputLeft: Audio bus index of the incoming left channel.
|
||||||
|
/// - inputRight: Audio bus index of the incoming right channel.
|
||||||
|
/// - outputBusLeft: Audio bus index for the left branch input.
|
||||||
|
/// - outputBusRight: Audio bus index for the right branch input.
|
||||||
|
/// - dryTapBus: Audio bus index for the centered mono dry tap.
|
||||||
|
public init(
|
||||||
|
inputLeft: Int,
|
||||||
|
inputRight: Int,
|
||||||
|
outputBusLeft: Int,
|
||||||
|
outputBusRight: Int,
|
||||||
|
dryTapBus: Int
|
||||||
|
) {
|
||||||
|
self.inputLeft = inputLeft
|
||||||
|
self.inputRight = inputRight
|
||||||
|
self.outputBusLeft = outputBusLeft
|
||||||
|
self.outputBusRight = outputBusRight
|
||||||
|
self.dryTapBus = dryTapBus
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Build
|
||||||
|
|
||||||
|
/// Builds the signal graph: each input channel copied to its branch bus, and a centered mono
|
||||||
|
/// sum written to the dry tap.
|
||||||
|
public override func build() {
|
||||||
|
let leftSig: In.Audio = input(bus: inputLeft)
|
||||||
|
let rightSig: In.Audio = input(bus: inputRight)
|
||||||
|
output(bus: outputBusLeft, source: leftSig)
|
||||||
|
output(bus: outputBusRight, source: rightSig)
|
||||||
|
let gain: Double = StereoUnzipSplitter.dryChannelGain
|
||||||
|
output(bus: dryTapBus, source: (leftSig * gain) + (rightSig * gain))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,9 +34,10 @@ import LyrebirdUI
|
|||||||
///
|
///
|
||||||
/// ## Input routing
|
/// ## Input routing
|
||||||
///
|
///
|
||||||
/// When `inputSource == .testLoop`, a `TestLoopSource` is added to the engine
|
/// When `inputSource == .testLoop`, a **single** shared `TestLoopSource` writes a global
|
||||||
/// **before** the first pedal on each board (plain `engine.add` places it at the
|
/// test bus, and each board gets a `TestLoopTap` (added `.after(_:)` the source) copying that
|
||||||
/// head of `mainGroup`, so it evaluates first).
|
/// bus into the board's head bus. One shared source keeps every board phase-locked and survives
|
||||||
|
/// board add/remove, so the arpeggio never restarts into a polyrhythm.
|
||||||
///
|
///
|
||||||
/// When `inputSource == .liveInput(channel:)`, a `HardwareInputPassThrough` synthesizer
|
/// When `inputSource == .liveInput(channel:)`, a `HardwareInputPassThrough` synthesizer
|
||||||
/// copies hardware input `channel` (engine bus `numOutputChannels + channel`) to the
|
/// copies hardware input `channel` (engine bus `numOutputChannels + channel`) to the
|
||||||
@@ -84,9 +85,26 @@ public final class ShoeGaze {
|
|||||||
/// (same module, different file) can mutate it.
|
/// (same module, different file) can mutate it.
|
||||||
internal var recordTaps: [RecordTap] = []
|
internal var recordTaps: [RecordTap] = []
|
||||||
|
|
||||||
|
// MARK: - Scope state
|
||||||
|
|
||||||
|
/// Scope tap over the hardware input + output buses, feeding the debug scope view.
|
||||||
|
///
|
||||||
|
/// Rebuilt by ``installScopeTap(bufferSize:)`` whenever the engine layout changes (so the
|
||||||
|
/// tapped bus indices follow the current input/output channel counts). `nil` until first
|
||||||
|
/// installed. The setter is `internal` so ``installScopeTap(bufferSize:)`` (same module,
|
||||||
|
/// different file) can assign it; external callers observe it through this `public` getter.
|
||||||
|
public internal(set) var scopeTap: ScopeCapture?
|
||||||
|
|
||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
|
|
||||||
private var testLoopSources: [TestLoopSource] = []
|
/// The single shared test-loop source feeding every board in `.testLoop` mode, and the bus
|
||||||
|
/// it writes. One global source keeps all boards phase-locked (no per-board polyrhythm) and
|
||||||
|
/// survives board add/remove so its arpeggio never restarts. `nil` outside `.testLoop` mode.
|
||||||
|
private var globalTestSource: TestLoopSource?
|
||||||
|
private var globalTestBus: AudioBus?
|
||||||
|
|
||||||
|
/// Per-board taps copying the global test bus into each board's head bus.
|
||||||
|
private var testLoopTaps: [TestLoopTap] = []
|
||||||
private var inputPassThroughs: [HardwareInputPassThrough] = []
|
private var inputPassThroughs: [HardwareInputPassThrough] = []
|
||||||
private var outputMasters: [BoardOutputMaster] = []
|
private var outputMasters: [BoardOutputMaster] = []
|
||||||
|
|
||||||
@@ -110,6 +128,7 @@ public final class ShoeGaze {
|
|||||||
) {
|
) {
|
||||||
self.engine = engine
|
self.engine = engine
|
||||||
self.inputSource = inputSource
|
self.inputSource = inputSource
|
||||||
|
installScopeTap()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Board management
|
// MARK: - Board management
|
||||||
@@ -138,13 +157,19 @@ public final class ShoeGaze {
|
|||||||
// Route the input source to the board head bus.
|
// Route the input source to the board head bus.
|
||||||
switch inputSource {
|
switch inputSource {
|
||||||
case .testLoop:
|
case .testLoop:
|
||||||
let source: TestLoopSource = TestLoopSource(targetBus: board.headBus.index)
|
// All boards share one global test source so they stay phase-locked. Each board
|
||||||
// Plain add → head of mainGroup (evaluates before any pedal).
|
// gets a tap copying the shared test bus into its head bus, added `.after(_:)` the
|
||||||
try engine.add(source)
|
// source so it sees the source's output for the current block.
|
||||||
testLoopSources.append(source)
|
let (source, testBus): (TestLoopSource, AudioBus) = try ensureGlobalTestSource()
|
||||||
// Record the source as the head input node so PedalBoard.add(_:) can chain
|
let tap: TestLoopTap = TestLoopTap(
|
||||||
// the first pedal after it automatically (without needing an explicit `after:`).
|
inputBusIndex: testBus.index,
|
||||||
board.headInputNode = source
|
outputBusIndex: board.headBus.index
|
||||||
|
)
|
||||||
|
try engine.add(tap, position: NodePosition.after(source))
|
||||||
|
testLoopTaps.append(tap)
|
||||||
|
// Record the tap as the head input node so PedalBoard.add(_:) can chain the first
|
||||||
|
// pedal after it automatically (without needing an explicit `after:`).
|
||||||
|
board.headInputNode = tap
|
||||||
|
|
||||||
case .liveInput(let channel):
|
case .liveInput(let channel):
|
||||||
// Hardware input channel `channel` lives at bus numOutputChannels + channel.
|
// Hardware input channel `channel` lives at bus numOutputChannels + channel.
|
||||||
@@ -167,6 +192,36 @@ public final class ShoeGaze {
|
|||||||
return board
|
return board
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Lazily creates the single shared test-loop source and its bus, returning both.
|
||||||
|
///
|
||||||
|
/// Created once per `.testLoop` session and reused by every board's tap, so the arpeggio
|
||||||
|
/// phase is continuous across board add/remove (no per-board polyrhythm). Torn down by
|
||||||
|
/// ``teardown()`` (and thus by ``setInputSource(_:)`` when leaving test-loop mode).
|
||||||
|
///
|
||||||
|
/// The source and bus are committed to `globalTestSource` / `globalTestBus` only after the
|
||||||
|
/// engine add succeeds — if `engine.add` throws, the freshly allocated bus is released so it
|
||||||
|
/// is never orphaned.
|
||||||
|
private func ensureGlobalTestSource() throws -> (source: TestLoopSource, bus: AudioBus) {
|
||||||
|
if let source: TestLoopSource = globalTestSource, let bus: AudioBus = globalTestBus {
|
||||||
|
return (source, bus)
|
||||||
|
}
|
||||||
|
let testBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
|
let source: TestLoopSource = TestLoopSource(
|
||||||
|
targetBus: testBus.index,
|
||||||
|
sampleRate: engine.sampleRate
|
||||||
|
)
|
||||||
|
do {
|
||||||
|
// Plain add → head of mainGroup (evaluates before its taps and any pedal).
|
||||||
|
try engine.add(source)
|
||||||
|
} catch {
|
||||||
|
engine.busAllocator.releaseAudioBus(testBus)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
globalTestBus = testBus
|
||||||
|
globalTestSource = source
|
||||||
|
return (source, testBus)
|
||||||
|
}
|
||||||
|
|
||||||
/// Connects the output master for a previously prepared board and adds it to the engine.
|
/// Connects the output master for a previously prepared board and adds it to the engine.
|
||||||
///
|
///
|
||||||
/// Call this after all pedals have been added to the board via `board.add(_:)`.
|
/// Call this after all pedals have been added to the board via `board.add(_:)`.
|
||||||
@@ -247,6 +302,52 @@ public final class ShoeGaze {
|
|||||||
activeBoardIndex = nil
|
activeBoardIndex = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Solos `board` exclusively — identical to ``selectBoard(_:crossfadeSeconds:)``.
|
||||||
|
///
|
||||||
|
/// Provided as the "Solo" verb alongside ``setBoard(_:audible:crossfadeSeconds:)`` so
|
||||||
|
/// callers can express *make only this board audible* without conflating it with the
|
||||||
|
/// independent per-board enable used by Blend-style mixing.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - board: The board to solo. No-op if not managed by this instance.
|
||||||
|
/// - crossfadeSeconds: Crossfade duration in seconds (`0` = instant).
|
||||||
|
public func soloBoard(_ board: PedalBoard, crossfadeSeconds: Double) {
|
||||||
|
selectBoard(board, crossfadeSeconds: crossfadeSeconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets a single board audible or silent **without** disturbing the others.
|
||||||
|
///
|
||||||
|
/// Unlike ``selectBoard(_:crossfadeSeconds:)`` (which is exclusive), this toggles one
|
||||||
|
/// board's select-gain in place, so arbitrary subsets of boards can play at once — the
|
||||||
|
/// "Blend" mixing model. Because the audible set is no longer a single soloed board,
|
||||||
|
/// ``activeBoardIndex`` is cleared to `nil`.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - board: The board to enable or silence. No-op if not managed by this instance.
|
||||||
|
/// - audible: `true` to fade the board in, `false` to fade it out.
|
||||||
|
/// - crossfadeSeconds: Crossfade duration in seconds (`0` = instant).
|
||||||
|
public func setBoard(_ board: PedalBoard, audible: Bool, crossfadeSeconds: Double) {
|
||||||
|
guard boards.contains(where: { $0 === board }) else { return }
|
||||||
|
board.crossfadeTimeNode?.update(crossfadeSeconds)
|
||||||
|
board.selectGainNode?.update(audible ? 1.0 : 0.0)
|
||||||
|
activeBoardIndex = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether `board`'s output is currently audible (its select-gain target is on).
|
||||||
|
///
|
||||||
|
/// Reads the live select-gain target, so it reflects the latest
|
||||||
|
/// ``selectBoard(_:crossfadeSeconds:)`` / ``setBoard(_:audible:crossfadeSeconds:)`` /
|
||||||
|
/// ``selectAllBoards(crossfadeSeconds:)`` call (the value the crossfade is ramping
|
||||||
|
/// toward), independent of where the crossfade currently sits.
|
||||||
|
///
|
||||||
|
/// - Parameter board: A board managed by this instance.
|
||||||
|
/// - Returns: `true` when the board's select-gain target is on; `false` when silenced
|
||||||
|
/// or when the board has no output master yet.
|
||||||
|
public func isBoardAudible(_ board: PedalBoard) -> Bool {
|
||||||
|
let selectGainOnThreshold: Double = 0.5
|
||||||
|
return (board.selectGainNode?.value ?? 0.0) > selectGainOnThreshold
|
||||||
|
}
|
||||||
|
|
||||||
/// Removes a single board and its associated input source and output master from
|
/// Removes a single board and its associated input source and output master from
|
||||||
/// the engine, then releases the board's buses. The other boards are unaffected.
|
/// the engine, then releases the board's buses. The other boards are unaffected.
|
||||||
///
|
///
|
||||||
@@ -273,10 +374,12 @@ public final class ShoeGaze {
|
|||||||
outputMasters.removeAll { $0 === master }
|
outputMasters.removeAll { $0 === master }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the board's input source (writer of the head bus).
|
// Remove the board's input node (writer of the head bus). In `.testLoop` mode this is a
|
||||||
if let testLoop: TestLoopSource = board.headInputNode as? TestLoopSource {
|
// tap; the shared global source is left running so the remaining boards keep their
|
||||||
engine.remove(testLoop)
|
// phase-locked test signal.
|
||||||
testLoopSources.removeAll { $0 === testLoop }
|
if let tap: TestLoopTap = board.headInputNode as? TestLoopTap {
|
||||||
|
engine.remove(tap)
|
||||||
|
testLoopTaps.removeAll { $0 === tap }
|
||||||
} else if let passThrough: HardwareInputPassThrough = board.headInputNode as? HardwareInputPassThrough {
|
} else if let passThrough: HardwareInputPassThrough = board.headInputNode as? HardwareInputPassThrough {
|
||||||
engine.remove(passThrough)
|
engine.remove(passThrough)
|
||||||
inputPassThroughs.removeAll { $0 === passThrough }
|
inputPassThroughs.removeAll { $0 === passThrough }
|
||||||
@@ -285,6 +388,16 @@ public final class ShoeGaze {
|
|||||||
// Remove the pedals and release the board's buses.
|
// Remove the pedals and release the board's buses.
|
||||||
board.teardown()
|
board.teardown()
|
||||||
boards.remove(at: index)
|
boards.remove(at: index)
|
||||||
|
|
||||||
|
// Keep the soloed-board index valid: clear it if the soloed board was removed,
|
||||||
|
// otherwise shift it down when a board before it was removed.
|
||||||
|
if let active: Int = activeBoardIndex {
|
||||||
|
if active == index {
|
||||||
|
activeBoardIndex = nil
|
||||||
|
} else if active > index {
|
||||||
|
activeBoardIndex = active - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Chain router
|
// MARK: - Chain router
|
||||||
@@ -307,6 +420,13 @@ public final class ShoeGaze {
|
|||||||
/// try engine.start()
|
/// try engine.start()
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
/// > Note: In `.testLoop` mode a `ChainRouter` allocates **its own** test source (shared by
|
||||||
|
/// > the router's two boards via the splitter, so those two stay phase-locked to each other).
|
||||||
|
/// > That source is independent of the global test source used by ``addBoard()``-created
|
||||||
|
/// > boards, so a router's boards are *not* phase-locked to the main board list. Routers are
|
||||||
|
/// > a separate multi-board path (not used by the standard builder UI); unifying them onto the
|
||||||
|
/// > global source is intentionally out of scope here.
|
||||||
|
///
|
||||||
/// - Returns: A ``ChainRouter`` with both boards ready to receive pedals.
|
/// - Returns: A ``ChainRouter`` with both boards ready to receive pedals.
|
||||||
/// - Throws:
|
/// - Throws:
|
||||||
/// - `ShoeGazeError.liveInputRequiresInputChannels` when `inputSource == .liveInput`
|
/// - `ShoeGazeError.liveInputRequiresInputChannels` when `inputSource == .liveInput`
|
||||||
@@ -325,18 +445,26 @@ public final class ShoeGaze {
|
|||||||
/// Moves `board` to `targetIndex` within `boards`, locating it by identity.
|
/// Moves `board` to `targetIndex` within `boards`, locating it by identity.
|
||||||
///
|
///
|
||||||
/// This is an internal helper that mutates `boards` directly — valid only because
|
/// This is an internal helper that mutates `boards` directly — valid only because
|
||||||
/// `ShoeGaze` is `@MainActor` (no concurrent access). The method is `internal` rather than
|
/// `ShoeGaze` is `@MainActor` (no concurrent access). Reordering only permutes the
|
||||||
/// `public` so callers outside the ShoeGaze module cannot disrupt board ordering.
|
/// `boards` array; it does not touch the engine graph, so it is safe to call while the
|
||||||
|
/// engine is running.
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - board: The `PedalBoard` to reposition. No-op if not found in `boards`.
|
/// - board: The `PedalBoard` to reposition. No-op if not found in `boards`.
|
||||||
/// - index: The desired destination index. Clamped to `boards.count` after removal
|
/// - index: The desired destination index. Clamped to `boards.count` after removal
|
||||||
/// so it is always a valid insertion point.
|
/// so it is always a valid insertion point.
|
||||||
internal func moveBoard(_ board: PedalBoard, to index: Int) {
|
public func moveBoard(_ board: PedalBoard, to index: Int) {
|
||||||
guard let sourceIndex: Int = boards.firstIndex(where: { $0 === board }) else { return }
|
guard let sourceIndex: Int = boards.firstIndex(where: { $0 === board }) else { return }
|
||||||
|
// Track the soloed board by identity so its index follows the reorder.
|
||||||
|
let soloedBoard: PedalBoard? = activeBoardIndex.flatMap { idx in
|
||||||
|
idx < boards.count ? boards[idx] : nil
|
||||||
|
}
|
||||||
let removed: PedalBoard = boards.remove(at: sourceIndex)
|
let removed: PedalBoard = boards.remove(at: sourceIndex)
|
||||||
let destination: Int = min(index, boards.count)
|
let destination: Int = min(index, boards.count)
|
||||||
boards.insert(removed, at: destination)
|
boards.insert(removed, at: destination)
|
||||||
|
if let soloedBoard {
|
||||||
|
activeBoardIndex = boards.firstIndex(where: { $0 === soloedBoard })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Teardown
|
// MARK: - Teardown
|
||||||
@@ -362,10 +490,21 @@ public final class ShoeGaze {
|
|||||||
|
|
||||||
// Step 1: Remove all engine nodes that write to board buses.
|
// Step 1: Remove all engine nodes that write to board buses.
|
||||||
// Order within this step does not matter; all must finish before bus release.
|
// Order within this step does not matter; all must finish before bus release.
|
||||||
for source: TestLoopSource in testLoopSources {
|
for tap: TestLoopTap in testLoopTaps {
|
||||||
|
engine.remove(tap)
|
||||||
|
}
|
||||||
|
testLoopTaps.removeAll()
|
||||||
|
|
||||||
|
// Remove the shared global test source and release its bus (after its taps are removed,
|
||||||
|
// preserving remove-before-release ordering).
|
||||||
|
if let source: TestLoopSource = globalTestSource {
|
||||||
engine.remove(source)
|
engine.remove(source)
|
||||||
}
|
}
|
||||||
testLoopSources.removeAll()
|
globalTestSource = nil
|
||||||
|
if let testBus: AudioBus = globalTestBus {
|
||||||
|
engine.busAllocator.releaseAudioBus(testBus)
|
||||||
|
}
|
||||||
|
globalTestBus = nil
|
||||||
|
|
||||||
for passThrough: HardwareInputPassThrough in inputPassThroughs {
|
for passThrough: HardwareInputPassThrough in inputPassThroughs {
|
||||||
engine.remove(passThrough)
|
engine.remove(passThrough)
|
||||||
|
|||||||
@@ -48,6 +48,32 @@ public enum ShoeGazeError: Error, LocalizedError, Equatable, Sendable {
|
|||||||
/// Narrow the chain with `mergeToMono()` before adding another widener.
|
/// Narrow the chain with `mergeToMono()` before adding another widener.
|
||||||
case stereoWidthExceeded
|
case stereoWidthExceeded
|
||||||
|
|
||||||
|
/// Thrown by the linear pedal-edit API (`appendPedal(_:to:)`) when the kind's `rawValue` is
|
||||||
|
/// not a known pedal in `PedalRegistry.builtIn`. The associated value is the requested type string.
|
||||||
|
case unknownPedalType(String)
|
||||||
|
|
||||||
|
/// Thrown by `removePedal(at:from:)` / `movePedal(from:to:in:)` when a linear pedal index is
|
||||||
|
/// negative or `>=` the board's linear pedal count. `index` is the offending index; `count`
|
||||||
|
/// is the number of linear pedals on the board.
|
||||||
|
case pedalIndexOutOfRange(index: Int, count: Int)
|
||||||
|
|
||||||
|
/// Thrown by `appendStereoSplit(to:)` when the board's tail is already stereo (width 2). A
|
||||||
|
/// stereo split fans a mono tail into two branches; narrow the chain with a `Merge to Mono`
|
||||||
|
/// first. (See `PedalBoard.splitStereo()`.)
|
||||||
|
case cannotSplitStereoChain
|
||||||
|
|
||||||
|
/// Thrown by `appendMergeToMono(to:)` when the board's tail is already mono (width 1) — there
|
||||||
|
/// is no stereo signal to collapse.
|
||||||
|
case cannotMergeMonoChain
|
||||||
|
|
||||||
|
/// Thrown by `unzipStereo()` when the tail is mono (width 1) — there is no stereo signal whose
|
||||||
|
/// L/R channels could be split into independent lanes.
|
||||||
|
case cannotUnzipMonoChain
|
||||||
|
|
||||||
|
/// Thrown by the lane-addressed edit API when the segment at the given top-level index is not a
|
||||||
|
/// branch region (stereo split or parallel section). `index` is the offending segment index.
|
||||||
|
case notABranchRegion(index: Int)
|
||||||
|
|
||||||
// MARK: - LocalizedError
|
// MARK: - LocalizedError
|
||||||
|
|
||||||
public var errorDescription: String? {
|
public var errorDescription: String? {
|
||||||
@@ -64,6 +90,18 @@ public enum ShoeGazeError: Error, LocalizedError, Equatable, Sendable {
|
|||||||
return "ShoeGaze: could not open recording file '\(url.lastPathComponent)'."
|
return "ShoeGaze: could not open recording file '\(url.lastPathComponent)'."
|
||||||
case .stereoWidthExceeded:
|
case .stereoWidthExceeded:
|
||||||
return "PedalBoard: chain is already stereo (width 2); cannot add another widener. Use mergeToMono() first."
|
return "PedalBoard: chain is already stereo (width 2); cannot add another widener. Use mergeToMono() first."
|
||||||
|
case .unknownPedalType(let type):
|
||||||
|
return "ShoeGaze: '\(type)' is not a known pedal type; cannot add it to the board."
|
||||||
|
case .pedalIndexOutOfRange(let index, let count):
|
||||||
|
return "ShoeGaze: pedal index \(index) is out of range; the board has \(count) linear pedal(s)."
|
||||||
|
case .cannotSplitStereoChain:
|
||||||
|
return "ShoeGaze: cannot add a stereo split; the chain is already stereo. Merge to mono first."
|
||||||
|
case .cannotMergeMonoChain:
|
||||||
|
return "ShoeGaze: the chain is already mono; there is no stereo signal to merge."
|
||||||
|
case .cannotUnzipMonoChain:
|
||||||
|
return "ShoeGaze: the chain is mono; there is no stereo signal to split into L/R lanes."
|
||||||
|
case .notABranchRegion(let index):
|
||||||
|
return "ShoeGaze: segment \(index) is not a branch region (stereo split or parallel section)."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,310 @@
|
|||||||
|
// BoardBarView.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import LyrebirdUI
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
/// A horizontal board-mixer strip for switching between, or blending, multiple `PedalBoard`s.
|
||||||
|
///
|
||||||
|
/// Each board is a channel cell with an audible LED, a Solo button, and a level fader (the
|
||||||
|
/// board's master gain). A leading **Solo / Blend** mode switch chooses the interaction:
|
||||||
|
///
|
||||||
|
/// - **Solo** — tapping a cell's LED makes that board the only audible one
|
||||||
|
/// (``ShoeGaze/soloBoard(_:crossfadeSeconds:)``); the **All** button returns to the
|
||||||
|
/// summed state (``ShoeGaze/selectAllBoards(crossfadeSeconds:)``). Amp-channel feel.
|
||||||
|
/// - **Blend** — tapping a cell's LED toggles that board in or out of the mix
|
||||||
|
/// independently (``ShoeGaze/setBoard(_:audible:crossfadeSeconds:)``), so any subset can
|
||||||
|
/// play at once — the default summed behaviour, now controllable per board.
|
||||||
|
///
|
||||||
|
/// Tapping a cell's **name** selects it as the edit target (`editingBoardIndex`), which is
|
||||||
|
/// independent of what is audible — you can audition one board while editing another. A
|
||||||
|
/// cell's context menu deletes the board.
|
||||||
|
///
|
||||||
|
/// The same view serves macOS and iOS; on iOS the cell row scrolls horizontally and the
|
||||||
|
/// context-menu delete is reached by long-press.
|
||||||
|
public struct BoardBarView: View {
|
||||||
|
|
||||||
|
// MARK: - Play mode
|
||||||
|
|
||||||
|
/// How a cell's LED tap maps to board audibility.
|
||||||
|
private enum PlayMode: Hashable {
|
||||||
|
/// Tapping a board solos it exclusively.
|
||||||
|
case solo
|
||||||
|
/// Tapping a board toggles it independently in/out of the mix.
|
||||||
|
case blend
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Layout constants
|
||||||
|
|
||||||
|
private static let barSpacing: CGFloat = 10
|
||||||
|
private static let barHeight: CGFloat = 92
|
||||||
|
private static let cellSpacing: CGFloat = 8
|
||||||
|
private static let cellWidth: CGFloat = 104
|
||||||
|
private static let cellInnerSpacing: CGFloat = 5
|
||||||
|
private static let cellPadding: CGFloat = 7
|
||||||
|
private static let cellCornerRadius: CGFloat = 8
|
||||||
|
private static let controlColumnWidth: CGFloat = 188
|
||||||
|
private static let modePickerWidth: CGFloat = 104
|
||||||
|
private static let crossfadeSliderMinWidth: CGFloat = 64
|
||||||
|
private static let ledDiameter: CGFloat = 12
|
||||||
|
private static let ledGlowRadius: CGFloat = 6
|
||||||
|
private static let ledGlowOpacity: Double = 0.75
|
||||||
|
private static let ledDimBrightness: Double = 0.16
|
||||||
|
private static let ledRimOpacity: Double = 0.30
|
||||||
|
private static let soloButtonSize: CGFloat = 22
|
||||||
|
private static let editingBorderWidth: CGFloat = 2
|
||||||
|
private static let idleBorderOpacity: Double = 0.18
|
||||||
|
private static let cellBackgroundBrightness: Double = 0.14
|
||||||
|
private static let labelOpacity: Double = 0.65
|
||||||
|
private static let nameFontSize: CGFloat = 12
|
||||||
|
private static let maxCrossfadeSeconds: Double = 10.0
|
||||||
|
private static let crossfadeStep: Double = 0.1
|
||||||
|
private static let addButtonSize: CGFloat = 30
|
||||||
|
|
||||||
|
// MARK: - Properties
|
||||||
|
|
||||||
|
private let shoeGaze: ShoeGaze
|
||||||
|
@Binding private var editingBoardIndex: Int
|
||||||
|
@Binding private var crossfadeSeconds: Double
|
||||||
|
private let onAddBoard: () -> Void
|
||||||
|
|
||||||
|
@State private var mode: PlayMode = .solo
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a board-mixer bar.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - shoeGaze: The manager whose `boards` are switched / blended.
|
||||||
|
/// - editingBoardIndex: The index of the board currently being edited (a cell's name
|
||||||
|
/// tap writes this).
|
||||||
|
/// - crossfadeSeconds: Crossfade duration applied to every board switch / toggle.
|
||||||
|
/// - onAddBoard: Called when the trailing **+** button is tapped.
|
||||||
|
public init(
|
||||||
|
shoeGaze: ShoeGaze,
|
||||||
|
editingBoardIndex: Binding<Int>,
|
||||||
|
crossfadeSeconds: Binding<Double>,
|
||||||
|
onAddBoard: @escaping () -> Void
|
||||||
|
) {
|
||||||
|
self.shoeGaze = shoeGaze
|
||||||
|
self._editingBoardIndex = editingBoardIndex
|
||||||
|
self._crossfadeSeconds = crossfadeSeconds
|
||||||
|
self.onAddBoard = onAddBoard
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Body
|
||||||
|
|
||||||
|
public var body: some View {
|
||||||
|
// One horizontal scroll group so the whole bar hugs its content and stays a short,
|
||||||
|
// fixed-height band — leaving the canvas below for the pedals.
|
||||||
|
ScrollView(.horizontal, showsIndicators: false) {
|
||||||
|
HStack(alignment: .center, spacing: BoardBarView.barSpacing) {
|
||||||
|
controlColumn
|
||||||
|
Divider().overlay(Color.white.opacity(BoardBarView.idleBorderOpacity))
|
||||||
|
ForEach(Array(shoeGaze.boards.enumerated()), id: \.offset) { pair in
|
||||||
|
boardCell(index: pair.offset, board: pair.element)
|
||||||
|
}
|
||||||
|
addButton
|
||||||
|
}
|
||||||
|
.frame(height: BoardBarView.barHeight)
|
||||||
|
}
|
||||||
|
.frame(height: BoardBarView.barHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Control column
|
||||||
|
|
||||||
|
private var controlColumn: some View {
|
||||||
|
VStack(alignment: .leading, spacing: BoardBarView.cellInnerSpacing) {
|
||||||
|
HStack(spacing: BoardBarView.cellInnerSpacing) {
|
||||||
|
Picker("Mode", selection: $mode) {
|
||||||
|
Text("Solo").tag(PlayMode.solo)
|
||||||
|
Text("Blend").tag(PlayMode.blend)
|
||||||
|
}
|
||||||
|
.pickerStyle(.segmented)
|
||||||
|
.labelsHidden()
|
||||||
|
.frame(width: BoardBarView.modePickerWidth)
|
||||||
|
|
||||||
|
Button("All") {
|
||||||
|
shoeGaze.selectAllBoards(crossfadeSeconds: clampedCrossfade)
|
||||||
|
}
|
||||||
|
.buttonStyle(.bordered)
|
||||||
|
.tint(.orange)
|
||||||
|
.help("Play all boards (summed)")
|
||||||
|
}
|
||||||
|
|
||||||
|
HStack(spacing: BoardBarView.cellInnerSpacing) {
|
||||||
|
Text("XFade")
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundStyle(Color.white.opacity(BoardBarView.labelOpacity))
|
||||||
|
Slider(
|
||||||
|
value: $crossfadeSeconds,
|
||||||
|
in: 0 ... BoardBarView.maxCrossfadeSeconds,
|
||||||
|
step: BoardBarView.crossfadeStep
|
||||||
|
)
|
||||||
|
.frame(minWidth: BoardBarView.crossfadeSliderMinWidth)
|
||||||
|
Text(String(format: "%.1fs", clampedCrossfade))
|
||||||
|
.font(.caption2)
|
||||||
|
.monospacedDigit()
|
||||||
|
.foregroundStyle(Color.white.opacity(BoardBarView.labelOpacity))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(width: BoardBarView.controlColumnWidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Board cell
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func boardCell(index: Int, board: PedalBoard) -> some View {
|
||||||
|
let isEditing: Bool = index == editingBoardIndex
|
||||||
|
let isAudible: Bool = shoeGaze.isBoardAudible(board)
|
||||||
|
let isSoloed: Bool = shoeGaze.activeBoardIndex == index
|
||||||
|
|
||||||
|
VStack(spacing: BoardBarView.cellInnerSpacing) {
|
||||||
|
Text(boardLabel(index: index, board: board))
|
||||||
|
.font(.system(size: BoardBarView.nameFontSize, weight: .semibold))
|
||||||
|
.foregroundStyle(Color.white)
|
||||||
|
.lineLimit(1)
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
.onTapGesture { editingBoardIndex = index }
|
||||||
|
|
||||||
|
HStack(spacing: BoardBarView.cellSpacing) {
|
||||||
|
ledButton(board: board, isAudible: isAudible)
|
||||||
|
soloButton(board: board, isSoloed: isSoloed)
|
||||||
|
}
|
||||||
|
|
||||||
|
levelFader(board: board)
|
||||||
|
}
|
||||||
|
.padding(BoardBarView.cellPadding)
|
||||||
|
.frame(width: BoardBarView.cellWidth)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: BoardBarView.cellCornerRadius)
|
||||||
|
.fill(Color(white: BoardBarView.cellBackgroundBrightness))
|
||||||
|
)
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: BoardBarView.cellCornerRadius)
|
||||||
|
.stroke(
|
||||||
|
isEditing ? Color.orange : Color.white.opacity(BoardBarView.idleBorderOpacity),
|
||||||
|
lineWidth: isEditing ? BoardBarView.editingBorderWidth : 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.contextMenu {
|
||||||
|
Button("Edit This Board") { editingBoardIndex = index }
|
||||||
|
Button(isAudible ? "Silence" : "Enable") {
|
||||||
|
shoeGaze.setBoard(board, audible: !isAudible, crossfadeSeconds: clampedCrossfade)
|
||||||
|
}
|
||||||
|
Divider()
|
||||||
|
Button("Delete Board", role: .destructive) {
|
||||||
|
shoeGaze.removeBoard(board)
|
||||||
|
clampEditingIndex()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The audible LED — tap behaviour depends on the current ``PlayMode``.
|
||||||
|
private func ledButton(board: PedalBoard, isAudible: Bool) -> some View {
|
||||||
|
Button {
|
||||||
|
switch mode {
|
||||||
|
case .solo:
|
||||||
|
shoeGaze.soloBoard(board, crossfadeSeconds: clampedCrossfade)
|
||||||
|
case .blend:
|
||||||
|
shoeGaze.setBoard(board, audible: !isAudible, crossfadeSeconds: clampedCrossfade)
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
ZStack {
|
||||||
|
if isAudible {
|
||||||
|
Circle()
|
||||||
|
.fill(Color.green.opacity(BoardBarView.ledGlowOpacity))
|
||||||
|
.frame(
|
||||||
|
width: BoardBarView.ledDiameter + BoardBarView.ledGlowRadius,
|
||||||
|
height: BoardBarView.ledDiameter + BoardBarView.ledGlowRadius
|
||||||
|
)
|
||||||
|
.blur(radius: BoardBarView.ledGlowRadius / 2)
|
||||||
|
}
|
||||||
|
Circle()
|
||||||
|
.fill(isAudible ? Color.green : Color(white: BoardBarView.ledDimBrightness))
|
||||||
|
.frame(width: BoardBarView.ledDiameter, height: BoardBarView.ledDiameter)
|
||||||
|
.overlay(
|
||||||
|
Circle().stroke(Color.white.opacity(BoardBarView.ledRimOpacity), lineWidth: 0.5)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.frame(width: BoardBarView.ledDiameter + BoardBarView.ledGlowRadius,
|
||||||
|
height: BoardBarView.ledDiameter + BoardBarView.ledGlowRadius)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.help(mode == .solo ? "Solo this board" : (isAudible ? "Silence this board" : "Add this board to the mix"))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Exclusive solo button — lit when this board is the soloed one.
|
||||||
|
private func soloButton(board: PedalBoard, isSoloed: Bool) -> some View {
|
||||||
|
Button {
|
||||||
|
shoeGaze.soloBoard(board, crossfadeSeconds: clampedCrossfade)
|
||||||
|
} label: {
|
||||||
|
Text("S")
|
||||||
|
.font(.system(size: BoardBarView.nameFontSize, weight: .bold))
|
||||||
|
.foregroundStyle(isSoloed ? Color.black : Color.white)
|
||||||
|
.frame(width: BoardBarView.soloButtonSize, height: BoardBarView.soloButtonSize)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: 4)
|
||||||
|
.fill(isSoloed ? Color.yellow : Color(white: BoardBarView.ledDimBrightness))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.help("Solo this board (exclusive)")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Board master-gain fader. Hidden until the board's output master is connected.
|
||||||
|
@ViewBuilder
|
||||||
|
private func levelFader(board: PedalBoard) -> some View {
|
||||||
|
if let gainNode: UIParamNode = board.masterGainNode {
|
||||||
|
Slider(
|
||||||
|
value: Binding(
|
||||||
|
get: { gainNode.value },
|
||||||
|
set: { gainNode.update($0) }
|
||||||
|
),
|
||||||
|
in: 0.0 ... 1.0
|
||||||
|
)
|
||||||
|
.controlSize(.mini)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Add button
|
||||||
|
|
||||||
|
private var addButton: some View {
|
||||||
|
Button(action: onAddBoard) {
|
||||||
|
Image(systemName: "plus")
|
||||||
|
.font(.system(size: BoardBarView.nameFontSize, weight: .bold))
|
||||||
|
.foregroundStyle(Color.white)
|
||||||
|
.frame(width: BoardBarView.addButtonSize, height: BoardBarView.addButtonSize)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: BoardBarView.cellCornerRadius)
|
||||||
|
.stroke(Color.white.opacity(BoardBarView.idleBorderOpacity), lineWidth: 1)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.help("Add a board")
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Helpers
|
||||||
|
|
||||||
|
/// Display label for a board, falling back to a 1-based position when unnamed.
|
||||||
|
private func boardLabel(index: Int, board: PedalBoard) -> String {
|
||||||
|
board.label.isEmpty ? "Board \(index + 1)" : board.label
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `crossfadeSeconds` clamped to the supported range.
|
||||||
|
private var clampedCrossfade: Double {
|
||||||
|
min(max(crossfadeSeconds, 0.0), BoardBarView.maxCrossfadeSeconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Keeps the edit target valid after a delete.
|
||||||
|
private func clampEditingIndex() {
|
||||||
|
let count: Int = shoeGaze.boards.count
|
||||||
|
guard count > 0 else { editingBoardIndex = 0; return }
|
||||||
|
editingBoardIndex = min(editingBoardIndex, count - 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,490 @@
|
|||||||
|
// BoardFlowView.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import LyrebirdUI
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
/// A left→right signal-flow view of one `PedalBoard`: live pedal cards joined by connector lines,
|
||||||
|
/// with split regions shown as two stacked lanes you can fill independently.
|
||||||
|
///
|
||||||
|
/// Binds to `ShoeGaze` (`@Observable`) and reads the live board via `shoeGaze.boards[boardIndex]`.
|
||||||
|
/// All edits go through the lane-addressed API (`appendPedal`/`removePedal`/`movePedal`,
|
||||||
|
/// `appendStereoSplit`/`appendParallelSplit`/`appendMergeToMono`/`removeSegment`), which rebuild
|
||||||
|
/// the board in place — so the index is the stable anchor and the `PedalBoard` reference is never
|
||||||
|
/// cached. Region segments are addressed by their index in `board.orderedSegments`.
|
||||||
|
///
|
||||||
|
/// Interaction:
|
||||||
|
/// - Drag a palette pedal (`"add:<type>"`) onto a lane to append it there; tap a palette pedal to
|
||||||
|
/// append to the main chain.
|
||||||
|
/// - Drag a card onto another card in the same lane to reorder; the corner trash removes it.
|
||||||
|
/// - Connector lines render mono (single) or stereo (double) based on the running channel width.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - shoeGaze: The `ShoeGaze` manager that owns the board.
|
||||||
|
/// - boardIndex: Index into `shoeGaze.boards`. Renders a placeholder when out of range.
|
||||||
|
public struct BoardFlowView: View {
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
private static let placeholderOpacity: Double = 0.55
|
||||||
|
private static let stageSpacing: CGFloat = 0
|
||||||
|
private static let connectorWidth: CGFloat = 26
|
||||||
|
private static let connectorThickness: CGFloat = 2
|
||||||
|
private static let stereoLineGap: CGFloat = 6
|
||||||
|
private static let laneSpacing: CGFloat = 10
|
||||||
|
private static let laneMinWidth: CGFloat = 240
|
||||||
|
private static let laneLabelWidth: CGFloat = 22
|
||||||
|
private static let regionPadding: CGFloat = 10
|
||||||
|
private static let regionCornerRadius: CGFloat = 12
|
||||||
|
private static let regionBrightness: Double = 0.09
|
||||||
|
private static let regionBorderOpacity: Double = 0.35
|
||||||
|
private static let trashPadding: CGFloat = 6
|
||||||
|
private static let trashOpacity: Double = 0.8
|
||||||
|
private static let badgeFontSize: CGFloat = 11
|
||||||
|
private static let badgeOpacity: Double = 0.6
|
||||||
|
private static let dropHighlightWidth: CGFloat = 2
|
||||||
|
private static let splitToggleSpacing: CGFloat = 6
|
||||||
|
private static let splitToggleWidth: CGFloat = 200
|
||||||
|
private static let emptyLaneOpacity: Double = 0.4
|
||||||
|
|
||||||
|
/// Signal-path accent (the pink/magenta connector colour).
|
||||||
|
private static let flowColor: Color = Color(red: 0.92, green: 0.32, blue: 0.70)
|
||||||
|
|
||||||
|
// MARK: - Properties
|
||||||
|
|
||||||
|
private let shoeGaze: ShoeGaze
|
||||||
|
private let boardIndex: Int
|
||||||
|
|
||||||
|
/// Identifier of the lane/card currently hovered as a drop target, for highlight.
|
||||||
|
@State private var dropTarget: String?
|
||||||
|
|
||||||
|
public init(shoeGaze: ShoeGaze, boardIndex: Int) {
|
||||||
|
self.shoeGaze = shoeGaze
|
||||||
|
self.boardIndex = boardIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Body
|
||||||
|
|
||||||
|
public var body: some View {
|
||||||
|
if boardIndex < 0 || boardIndex >= shoeGaze.boards.count {
|
||||||
|
Text("No board at index \(boardIndex).")
|
||||||
|
.foregroundStyle(Color.secondary.opacity(BoardFlowView.placeholderOpacity))
|
||||||
|
} else {
|
||||||
|
let board: PedalBoard = shoeGaze.boards[boardIndex]
|
||||||
|
flow(board: board)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func flow(board: PedalBoard) -> some View {
|
||||||
|
let stages: [StageModel] = stageModels(board: board)
|
||||||
|
return ScrollView([.horizontal, .vertical], showsIndicators: true) {
|
||||||
|
HStack(alignment: .center, spacing: BoardFlowView.stageSpacing) {
|
||||||
|
endpoint("IN")
|
||||||
|
ForEach(stages) { stage in
|
||||||
|
connector(stereo: stage.stereoIn)
|
||||||
|
stageView(stage)
|
||||||
|
}
|
||||||
|
connector(stereo: board.width == 2)
|
||||||
|
endpoint(board.width == 2 ? "OUT ⇒" : "OUT")
|
||||||
|
}
|
||||||
|
.padding(.vertical, BoardFlowView.regionPadding)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Stage model
|
||||||
|
|
||||||
|
/// View-model for one top-level segment: its index (the lane region index), the live segment,
|
||||||
|
/// the main-chain linear index for `.pedal`, and the channel width entering the stage.
|
||||||
|
private struct StageModel: Identifiable {
|
||||||
|
let id: Int
|
||||||
|
let segmentIndex: Int
|
||||||
|
let segment: BoardSegment
|
||||||
|
let linearIndex: Int?
|
||||||
|
let stereoIn: Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Walks `board.orderedSegments`, tagging each with a linear pedal index and the running width.
|
||||||
|
private func stageModels(board: PedalBoard) -> [StageModel] {
|
||||||
|
var models: [StageModel] = []
|
||||||
|
var linearCounter: Int = 0
|
||||||
|
var stereo: Bool = false
|
||||||
|
for (index, segment) in board.orderedSegments.enumerated() {
|
||||||
|
let stereoIn: Bool = stereo
|
||||||
|
var linearIndex: Int?
|
||||||
|
switch segment {
|
||||||
|
case .pedal(let pedal):
|
||||||
|
linearIndex = linearCounter
|
||||||
|
linearCounter += 1
|
||||||
|
if pedal.channelKind != .mono { stereo = true }
|
||||||
|
case .stereoSplit:
|
||||||
|
stereo = true
|
||||||
|
case .stereoUnzip:
|
||||||
|
stereo = true
|
||||||
|
case .parallel:
|
||||||
|
break
|
||||||
|
case .mergeToMono:
|
||||||
|
stereo = false
|
||||||
|
}
|
||||||
|
models.append(
|
||||||
|
StageModel(
|
||||||
|
id: index,
|
||||||
|
segmentIndex: index,
|
||||||
|
segment: segment,
|
||||||
|
linearIndex: linearIndex,
|
||||||
|
stereoIn: stereoIn
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return models
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Stage dispatch
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func stageView(_ stage: StageModel) -> some View {
|
||||||
|
switch stage.segment {
|
||||||
|
case .pedal(let pedal):
|
||||||
|
mainPedalCard(pedal: pedal, linearIndex: stage.linearIndex ?? 0, segmentIndex: stage.segmentIndex)
|
||||||
|
case .stereoSplit(let section):
|
||||||
|
regionNode(
|
||||||
|
title: "STEREO SPLIT",
|
||||||
|
segmentIndex: stage.segmentIndex,
|
||||||
|
leftLabel: "L",
|
||||||
|
rightLabel: "R",
|
||||||
|
leftPedals: section.left.pedals,
|
||||||
|
rightPedals: section.right.pedals,
|
||||||
|
control: AnyView(StereoRouteControlView(section: section))
|
||||||
|
)
|
||||||
|
case .stereoUnzip(let section):
|
||||||
|
regionNode(
|
||||||
|
title: "STEREO UNZIP",
|
||||||
|
segmentIndex: stage.segmentIndex,
|
||||||
|
leftLabel: "L",
|
||||||
|
rightLabel: "R",
|
||||||
|
leftPedals: section.left.pedals,
|
||||||
|
rightPedals: section.right.pedals,
|
||||||
|
control: AnyView(StereoRouteControlView(section: section))
|
||||||
|
)
|
||||||
|
case .parallel(let section):
|
||||||
|
regionNode(
|
||||||
|
title: "PARALLEL",
|
||||||
|
segmentIndex: stage.segmentIndex,
|
||||||
|
leftLabel: "A",
|
||||||
|
rightLabel: "B",
|
||||||
|
leftPedals: section.branchA.pedals,
|
||||||
|
rightPedals: section.branchB.pedals,
|
||||||
|
control: AnyView(SplitterView(splitter: section.splitter))
|
||||||
|
)
|
||||||
|
case .mergeToMono:
|
||||||
|
mergeNode(segmentIndex: stage.segmentIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Connectors
|
||||||
|
|
||||||
|
private func connector(stereo: Bool) -> some View {
|
||||||
|
ZStack {
|
||||||
|
if stereo {
|
||||||
|
VStack(spacing: BoardFlowView.stereoLineGap) {
|
||||||
|
line
|
||||||
|
line
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
line
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(width: BoardFlowView.connectorWidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var line: some View {
|
||||||
|
Capsule()
|
||||||
|
.fill(BoardFlowView.flowColor)
|
||||||
|
.frame(height: BoardFlowView.connectorThickness)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func endpoint(_ text: String) -> some View {
|
||||||
|
Text(text)
|
||||||
|
.font(.system(size: BoardFlowView.badgeFontSize, weight: .semibold).monospaced())
|
||||||
|
.foregroundStyle(BoardFlowView.flowColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Main pedal card
|
||||||
|
|
||||||
|
private func mainPedalCard(pedal: Pedal, linearIndex: Int, segmentIndex: Int) -> some View {
|
||||||
|
let payload: String = "movemain:\(linearIndex)"
|
||||||
|
let card: some View = PedalView(pedal: pedal)
|
||||||
|
.overlay(alignment: .topTrailing) { trashButton { deleteSegment(forLinear: linearIndex) } }
|
||||||
|
.overlay { dropOutline(active: dropTarget == payload) }
|
||||||
|
.draggable(payload)
|
||||||
|
.dropDestination(for: String.self) { items, _ in
|
||||||
|
handleMainDrop(items, ontoLinear: linearIndex)
|
||||||
|
} isTargeted: { hovering in
|
||||||
|
dropTarget = hovering ? payload : (dropTarget == payload ? nil : dropTarget)
|
||||||
|
}
|
||||||
|
return VStack(spacing: BoardFlowView.splitToggleSpacing) {
|
||||||
|
card
|
||||||
|
// Stereo-producing pedals (Ping-Pong, Octave Splitter) offer a choice: keep one stereo
|
||||||
|
// flow downstream, or split the L/R channels into independent lanes (a stereo unzip).
|
||||||
|
if pedal.channelKind != .mono {
|
||||||
|
splitToggle(segmentIndex: segmentIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A "Stereo flow / Split L/R" segmented control for a stereo-producing pedal. "Split L/R"
|
||||||
|
/// inserts a stereo-unzip region right after the pedal; "Stereo flow" removes it.
|
||||||
|
private func splitToggle(segmentIndex: Int) -> some View {
|
||||||
|
let binding: Binding<Bool> = Binding(
|
||||||
|
get: {
|
||||||
|
guard let board: PedalBoard = board else { return false }
|
||||||
|
return shoeGaze.isStereoUnzip(afterSegment: segmentIndex, in: board)
|
||||||
|
},
|
||||||
|
set: { split in
|
||||||
|
guard let board: PedalBoard = board else { return }
|
||||||
|
do {
|
||||||
|
if split {
|
||||||
|
guard !shoeGaze.isStereoUnzip(afterSegment: segmentIndex, in: board) else { return }
|
||||||
|
_ = try shoeGaze.insertStereoUnzip(afterSegment: segmentIndex, in: board)
|
||||||
|
} else {
|
||||||
|
// Only remove the next segment if it is in fact this pedal's unzip region —
|
||||||
|
// it may have been removed via the region's own trash button.
|
||||||
|
guard shoeGaze.isStereoUnzip(afterSegment: segmentIndex, in: board) else { return }
|
||||||
|
_ = try shoeGaze.removeSegment(at: segmentIndex + 1, from: board)
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
print("[BoardFlowView] split toggle failed: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return Picker("", selection: binding) {
|
||||||
|
Text("Stereo flow").tag(false)
|
||||||
|
Text("Split L/R").tag(true)
|
||||||
|
}
|
||||||
|
.pickerStyle(.segmented)
|
||||||
|
.labelsHidden()
|
||||||
|
.frame(maxWidth: BoardFlowView.splitToggleWidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Region node (stereo split / parallel)
|
||||||
|
|
||||||
|
private func regionNode(
|
||||||
|
title: String,
|
||||||
|
segmentIndex: Int,
|
||||||
|
leftLabel: String,
|
||||||
|
rightLabel: String,
|
||||||
|
leftPedals: [Pedal],
|
||||||
|
rightPedals: [Pedal],
|
||||||
|
control: AnyView
|
||||||
|
) -> some View {
|
||||||
|
VStack(alignment: .leading, spacing: BoardFlowView.laneSpacing) {
|
||||||
|
HStack(spacing: 8) {
|
||||||
|
Text(title)
|
||||||
|
.font(.system(size: BoardFlowView.badgeFontSize, weight: .semibold))
|
||||||
|
.foregroundStyle(BoardFlowView.flowColor)
|
||||||
|
Spacer()
|
||||||
|
control
|
||||||
|
trashButton { removeSegment(at: segmentIndex) }
|
||||||
|
}
|
||||||
|
laneRow(label: leftLabel, pedals: leftPedals, lane: .left(region: segmentIndex))
|
||||||
|
laneRow(label: rightLabel, pedals: rightPedals, lane: .right(region: segmentIndex))
|
||||||
|
}
|
||||||
|
.padding(BoardFlowView.regionPadding)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: BoardFlowView.regionCornerRadius)
|
||||||
|
.fill(Color(white: BoardFlowView.regionBrightness))
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: BoardFlowView.regionCornerRadius)
|
||||||
|
.stroke(BoardFlowView.flowColor.opacity(BoardFlowView.regionBorderOpacity), lineWidth: 1)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func laneRow(label: String, pedals: [Pedal], lane: PedalLane) -> some View {
|
||||||
|
let laneID: String = "lane:\(lane.regionIndex ?? -1):\(lane.isLeftBranch ? "L" : "R")"
|
||||||
|
return HStack(alignment: .center, spacing: BoardFlowView.stageSpacing) {
|
||||||
|
Text(label)
|
||||||
|
.font(.system(size: BoardFlowView.badgeFontSize, weight: .bold).monospaced())
|
||||||
|
.foregroundStyle(Color.white.opacity(BoardFlowView.badgeOpacity))
|
||||||
|
.frame(width: BoardFlowView.laneLabelWidth)
|
||||||
|
if pedals.isEmpty {
|
||||||
|
Text("drop a pedal here")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(Color.white.opacity(BoardFlowView.emptyLaneOpacity))
|
||||||
|
.frame(minWidth: BoardFlowView.laneMinWidth, alignment: .leading)
|
||||||
|
.padding(.vertical, BoardFlowView.regionPadding)
|
||||||
|
} else {
|
||||||
|
ForEach(Array(pedals.enumerated()), id: \.offset) { pair in
|
||||||
|
connector(stereo: false)
|
||||||
|
branchPedalCard(pedal: pair.element, lane: lane, index: pair.offset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(minWidth: BoardFlowView.laneMinWidth, alignment: .leading)
|
||||||
|
.overlay { dropOutline(active: dropTarget == laneID) }
|
||||||
|
.dropDestination(for: String.self) { items, _ in
|
||||||
|
handleLaneDrop(items, lane: lane)
|
||||||
|
} isTargeted: { hovering in
|
||||||
|
dropTarget = hovering ? laneID : (dropTarget == laneID ? nil : dropTarget)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func branchPedalCard(pedal: Pedal, lane: PedalLane, index: Int) -> some View {
|
||||||
|
let payload: String = "movebranch:\(lane.regionIndex ?? -1):\(lane.isLeftBranch ? "L" : "R"):\(index)"
|
||||||
|
return PedalView(pedal: pedal)
|
||||||
|
.overlay(alignment: .topTrailing) {
|
||||||
|
trashButton { removePedal(at: index, lane: lane) }
|
||||||
|
}
|
||||||
|
.overlay { dropOutline(active: dropTarget == payload) }
|
||||||
|
.draggable(payload)
|
||||||
|
.dropDestination(for: String.self) { items, _ in
|
||||||
|
handleBranchCardDrop(items, lane: lane, ontoIndex: index)
|
||||||
|
} isTargeted: { hovering in
|
||||||
|
dropTarget = hovering ? payload : (dropTarget == payload ? nil : dropTarget)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func mergeNode(segmentIndex: Int) -> some View {
|
||||||
|
VStack(spacing: 4) {
|
||||||
|
Text("⇒ MONO")
|
||||||
|
.font(.system(size: BoardFlowView.badgeFontSize, weight: .semibold))
|
||||||
|
.foregroundStyle(BoardFlowView.flowColor)
|
||||||
|
trashButton { removeSegment(at: segmentIndex) }
|
||||||
|
}
|
||||||
|
.padding(BoardFlowView.regionPadding)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: BoardFlowView.regionCornerRadius)
|
||||||
|
.stroke(BoardFlowView.flowColor.opacity(BoardFlowView.regionBorderOpacity), lineWidth: 1)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Shared bits
|
||||||
|
|
||||||
|
private func trashButton(_ action: @escaping () -> Void) -> some View {
|
||||||
|
Button(role: .destructive, action: action) {
|
||||||
|
Image(systemName: "trash.circle.fill")
|
||||||
|
.foregroundStyle(Color.white.opacity(BoardFlowView.trashOpacity))
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.padding(BoardFlowView.trashPadding)
|
||||||
|
}
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func dropOutline(active: Bool) -> some View {
|
||||||
|
if active {
|
||||||
|
RoundedRectangle(cornerRadius: 8)
|
||||||
|
.stroke(BoardFlowView.flowColor, lineWidth: BoardFlowView.dropHighlightWidth)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Drop handling
|
||||||
|
|
||||||
|
private func parse(_ items: [String]) -> String? { items.first }
|
||||||
|
|
||||||
|
private func handleMainDrop(_ items: [String], ontoLinear: Int) -> Bool {
|
||||||
|
dropTarget = nil
|
||||||
|
guard let payload: String = parse(items) else { return false }
|
||||||
|
if let type: String = payload.afterPrefix("add:") {
|
||||||
|
append(type: type, lane: .main)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if let src: Int = payload.afterPrefix("movemain:").flatMap(Int.init) {
|
||||||
|
reorderMain(from: src, onto: ontoLinear)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
private func handleLaneDrop(_ items: [String], lane: PedalLane) -> Bool {
|
||||||
|
dropTarget = nil
|
||||||
|
guard let payload: String = parse(items), let type: String = payload.afterPrefix("add:") else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
append(type: type, lane: lane)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private func handleBranchCardDrop(_ items: [String], lane: PedalLane, ontoIndex: Int) -> Bool {
|
||||||
|
dropTarget = nil
|
||||||
|
guard let payload: String = parse(items) else { return false }
|
||||||
|
// Guard against a payload minted before a rebuild changed the segment layout: the encoded
|
||||||
|
// region index must still point at a live region segment.
|
||||||
|
if let region: Int = lane.regionIndex,
|
||||||
|
let liveBoard: PedalBoard = board,
|
||||||
|
region >= liveBoard.orderedSegments.count {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if let type: String = payload.afterPrefix("add:") {
|
||||||
|
append(type: type, lane: lane)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
// Reorder within the same lane only: "movebranch:<region>:<side>:<index>".
|
||||||
|
let parts: [Substring] = payload.split(separator: ":")
|
||||||
|
if parts.count == 4, parts[0] == "movebranch",
|
||||||
|
Int(parts[1]) == lane.regionIndex,
|
||||||
|
(parts[2] == "L") == lane.isLeftBranch,
|
||||||
|
let src: Int = Int(parts[3]) {
|
||||||
|
reorderBranch(from: src, onto: ontoIndex, lane: lane)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Edit actions
|
||||||
|
|
||||||
|
private var board: PedalBoard? {
|
||||||
|
guard boardIndex >= 0, boardIndex < shoeGaze.boards.count else { return nil }
|
||||||
|
return shoeGaze.boards[boardIndex]
|
||||||
|
}
|
||||||
|
|
||||||
|
private func append(type: String, lane: PedalLane) {
|
||||||
|
guard let board: PedalBoard = board else { return }
|
||||||
|
do { _ = try shoeGaze.appendPedal(PedalType(type), to: board, lane: lane) }
|
||||||
|
catch { print("[BoardFlowView] appendPedal failed: \(error)") }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func reorderMain(from source: Int, onto target: Int) {
|
||||||
|
guard source != target, let board: PedalBoard = board else { return }
|
||||||
|
// Convert "dropped ONTO the card at `target`" into movePedal's insert-before `toOffset`:
|
||||||
|
// a forward move lands after the target (target + 1); a backward move lands before it.
|
||||||
|
let destination: Int = source < target ? target + 1 : target
|
||||||
|
do { _ = try shoeGaze.movePedal(from: source, to: destination, in: board, lane: .main) }
|
||||||
|
catch { print("[BoardFlowView] movePedal(main) failed: \(error)") }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func reorderBranch(from source: Int, onto target: Int, lane: PedalLane) {
|
||||||
|
guard source != target, let board: PedalBoard = board else { return }
|
||||||
|
let destination: Int = source < target ? target + 1 : target
|
||||||
|
do { _ = try shoeGaze.movePedal(from: source, to: destination, in: board, lane: lane) }
|
||||||
|
catch { print("[BoardFlowView] movePedal(branch) failed: \(error)") }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func removePedal(at index: Int, lane: PedalLane) {
|
||||||
|
guard let board: PedalBoard = board else { return }
|
||||||
|
do { _ = try shoeGaze.removePedal(at: index, from: board, lane: lane) }
|
||||||
|
catch { print("[BoardFlowView] removePedal failed: \(error)") }
|
||||||
|
}
|
||||||
|
|
||||||
|
private func deleteSegment(forLinear linearIndex: Int) {
|
||||||
|
// A main-chain pedal: remove by its lane index (preserves regions).
|
||||||
|
removePedal(at: linearIndex, lane: .main)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func removeSegment(at segmentIndex: Int) {
|
||||||
|
guard let board: PedalBoard = board else { return }
|
||||||
|
do { _ = try shoeGaze.removeSegment(at: segmentIndex, from: board) }
|
||||||
|
catch { print("[BoardFlowView] removeSegment failed: \(error)") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private extension String {
|
||||||
|
/// Returns the remainder after `prefix`, or `nil` if the string doesn't start with it.
|
||||||
|
func afterPrefix(_ prefix: String) -> String? {
|
||||||
|
guard hasPrefix(prefix) else { return nil }
|
||||||
|
return String(dropFirst(prefix.count))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,243 @@
|
|||||||
|
// BoardsSheetView.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import LyrebirdUI
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
/// A full board manager presented as a sheet — the richer companion to the inline
|
||||||
|
/// ``BoardBarView``.
|
||||||
|
///
|
||||||
|
/// Each board is a `List` row with an audible toggle, a Solo button, a master-gain fader, an
|
||||||
|
/// inline rename field, and an "Edit" action that selects it as the builder's edit target and
|
||||||
|
/// dismisses. Rows reorder by drag (`.onMove`) and delete by swipe (`.onDelete`). A header
|
||||||
|
/// pairs the **Solo / Blend** mode switch with the crossfade slider, mirroring the board bar.
|
||||||
|
///
|
||||||
|
/// Primarily used on iOS/iPadOS (presented with `.presentationDetents`) where the inline bar
|
||||||
|
/// has no room for rename / reorder, but the view is platform-neutral.
|
||||||
|
public struct BoardsSheetView: View {
|
||||||
|
|
||||||
|
// MARK: - Play mode
|
||||||
|
|
||||||
|
private enum PlayMode: Hashable {
|
||||||
|
case solo
|
||||||
|
case blend
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Layout constants
|
||||||
|
|
||||||
|
private static let rowSpacing: CGFloat = 12
|
||||||
|
private static let faderWidth: CGFloat = 120
|
||||||
|
private static let soloButtonSize: CGFloat = 28
|
||||||
|
private static let ledDiameter: CGFloat = 14
|
||||||
|
private static let ledDimBrightness: Double = 0.16
|
||||||
|
private static let ledRimOpacity: Double = 0.30
|
||||||
|
private static let maxCrossfadeSeconds: Double = 10.0
|
||||||
|
private static let crossfadeStep: Double = 0.1
|
||||||
|
private static let headerSpacing: CGFloat = 10
|
||||||
|
|
||||||
|
// MARK: - Properties
|
||||||
|
|
||||||
|
private let shoeGaze: ShoeGaze
|
||||||
|
@Binding private var editingBoardIndex: Int
|
||||||
|
@Binding private var crossfadeSeconds: Double
|
||||||
|
private let onAddBoard: () -> Void
|
||||||
|
|
||||||
|
@Environment(\.dismiss) private var dismiss
|
||||||
|
@State private var mode: PlayMode = .solo
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a board-manager sheet.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - shoeGaze: The manager whose `boards` are edited.
|
||||||
|
/// - editingBoardIndex: The builder's edit target; a row's "Edit" action sets this.
|
||||||
|
/// - crossfadeSeconds: Crossfade duration applied to switches / toggles.
|
||||||
|
/// - onAddBoard: Called when the **Add Board** button is tapped.
|
||||||
|
public init(
|
||||||
|
shoeGaze: ShoeGaze,
|
||||||
|
editingBoardIndex: Binding<Int>,
|
||||||
|
crossfadeSeconds: Binding<Double>,
|
||||||
|
onAddBoard: @escaping () -> Void
|
||||||
|
) {
|
||||||
|
self.shoeGaze = shoeGaze
|
||||||
|
self._editingBoardIndex = editingBoardIndex
|
||||||
|
self._crossfadeSeconds = crossfadeSeconds
|
||||||
|
self.onAddBoard = onAddBoard
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Body
|
||||||
|
|
||||||
|
public var body: some View {
|
||||||
|
NavigationStack {
|
||||||
|
VStack(spacing: BoardsSheetView.headerSpacing) {
|
||||||
|
header
|
||||||
|
List {
|
||||||
|
ForEach(Array(shoeGaze.boards.enumerated()), id: \.offset) { pair in
|
||||||
|
boardRow(index: pair.offset, board: pair.element)
|
||||||
|
}
|
||||||
|
.onMove(perform: moveBoards)
|
||||||
|
.onDelete(perform: deleteBoards)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.top, BoardsSheetView.headerSpacing)
|
||||||
|
.navigationTitle("Boards")
|
||||||
|
.toolbar {
|
||||||
|
ToolbarItem(placement: .confirmationAction) {
|
||||||
|
Button("Done") { dismiss() }
|
||||||
|
}
|
||||||
|
ToolbarItem(placement: .primaryAction) {
|
||||||
|
Button {
|
||||||
|
onAddBoard()
|
||||||
|
} label: {
|
||||||
|
Label("Add Board", systemImage: "plus")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Header
|
||||||
|
|
||||||
|
private var header: some View {
|
||||||
|
HStack(spacing: BoardsSheetView.headerSpacing) {
|
||||||
|
Picker("Mode", selection: $mode) {
|
||||||
|
Text("Solo").tag(PlayMode.solo)
|
||||||
|
Text("Blend").tag(PlayMode.blend)
|
||||||
|
}
|
||||||
|
.pickerStyle(.segmented)
|
||||||
|
.frame(maxWidth: 180)
|
||||||
|
|
||||||
|
Button("All") {
|
||||||
|
shoeGaze.selectAllBoards(crossfadeSeconds: clampedCrossfade)
|
||||||
|
}
|
||||||
|
.buttonStyle(.bordered)
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
Text("XFade")
|
||||||
|
Slider(
|
||||||
|
value: $crossfadeSeconds,
|
||||||
|
in: 0 ... BoardsSheetView.maxCrossfadeSeconds,
|
||||||
|
step: BoardsSheetView.crossfadeStep
|
||||||
|
)
|
||||||
|
.frame(width: BoardsSheetView.faderWidth)
|
||||||
|
Text(String(format: "%.1fs", clampedCrossfade))
|
||||||
|
.monospacedDigit()
|
||||||
|
}
|
||||||
|
.padding(.horizontal)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Board row
|
||||||
|
|
||||||
|
@ViewBuilder
|
||||||
|
private func boardRow(index: Int, board: PedalBoard) -> some View {
|
||||||
|
let isAudible: Bool = shoeGaze.isBoardAudible(board)
|
||||||
|
let isSoloed: Bool = shoeGaze.activeBoardIndex == index
|
||||||
|
|
||||||
|
HStack(spacing: BoardsSheetView.rowSpacing) {
|
||||||
|
ledButton(board: board, isAudible: isAudible)
|
||||||
|
soloButton(board: board, isSoloed: isSoloed)
|
||||||
|
|
||||||
|
TextField(
|
||||||
|
"Board \(index + 1)",
|
||||||
|
text: Binding(
|
||||||
|
get: { board.label },
|
||||||
|
set: { board.label = $0 }
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.textFieldStyle(.roundedBorder)
|
||||||
|
|
||||||
|
if let gainNode: UIParamNode = board.masterGainNode {
|
||||||
|
Slider(
|
||||||
|
value: Binding(
|
||||||
|
get: { gainNode.value },
|
||||||
|
set: { gainNode.update($0) }
|
||||||
|
),
|
||||||
|
in: 0.0 ... 1.0
|
||||||
|
)
|
||||||
|
.frame(width: BoardsSheetView.faderWidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
Button("Edit") {
|
||||||
|
editingBoardIndex = index
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
.buttonStyle(.borderless)
|
||||||
|
}
|
||||||
|
.padding(.vertical, 4)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func ledButton(board: PedalBoard, isAudible: Bool) -> some View {
|
||||||
|
Button {
|
||||||
|
switch mode {
|
||||||
|
case .solo:
|
||||||
|
shoeGaze.soloBoard(board, crossfadeSeconds: clampedCrossfade)
|
||||||
|
case .blend:
|
||||||
|
shoeGaze.setBoard(board, audible: !isAudible, crossfadeSeconds: clampedCrossfade)
|
||||||
|
}
|
||||||
|
} label: {
|
||||||
|
Circle()
|
||||||
|
.fill(isAudible ? Color.green : Color(white: BoardsSheetView.ledDimBrightness))
|
||||||
|
.frame(width: BoardsSheetView.ledDiameter, height: BoardsSheetView.ledDiameter)
|
||||||
|
.overlay(
|
||||||
|
Circle().stroke(Color.white.opacity(BoardsSheetView.ledRimOpacity), lineWidth: 0.5)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func soloButton(board: PedalBoard, isSoloed: Bool) -> some View {
|
||||||
|
Button {
|
||||||
|
shoeGaze.soloBoard(board, crossfadeSeconds: clampedCrossfade)
|
||||||
|
} label: {
|
||||||
|
Text("S")
|
||||||
|
.font(.system(size: 13, weight: .bold))
|
||||||
|
.foregroundStyle(isSoloed ? Color.black : Color.primary)
|
||||||
|
.frame(width: BoardsSheetView.soloButtonSize, height: BoardsSheetView.soloButtonSize)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: 5)
|
||||||
|
.fill(isSoloed ? Color.yellow : Color.secondary.opacity(0.2))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Mutations
|
||||||
|
|
||||||
|
/// Reorders boards, translating SwiftUI's `onMove` offsets to `ShoeGaze.moveBoard`.
|
||||||
|
private func moveBoards(from source: IndexSet, to destination: Int) {
|
||||||
|
// List drag delivers a single source row; ignore any multi-selection move so a
|
||||||
|
// dropped row can never desync `shoeGaze.boards` from the displayed order.
|
||||||
|
guard source.count == 1, let sourceIndex: Int = source.first else { return }
|
||||||
|
let board: PedalBoard = shoeGaze.boards[sourceIndex]
|
||||||
|
// SwiftUI's destination is the insertion point in the pre-move list; moveBoard
|
||||||
|
// removes first, so shift down by one when moving forward.
|
||||||
|
let target: Int = destination > sourceIndex ? destination - 1 : destination
|
||||||
|
shoeGaze.moveBoard(board, to: target)
|
||||||
|
clampEditingIndex()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func deleteBoards(_ offsets: IndexSet) {
|
||||||
|
for index: Int in offsets.sorted(by: >) where index < shoeGaze.boards.count {
|
||||||
|
shoeGaze.removeBoard(shoeGaze.boards[index])
|
||||||
|
}
|
||||||
|
clampEditingIndex()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Helpers
|
||||||
|
|
||||||
|
private var clampedCrossfade: Double {
|
||||||
|
min(max(crossfadeSeconds, 0.0), BoardsSheetView.maxCrossfadeSeconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func clampEditingIndex() {
|
||||||
|
let count: Int = shoeGaze.boards.count
|
||||||
|
guard count > 0 else { editingBoardIndex = 0; return }
|
||||||
|
editingBoardIndex = min(editingBoardIndex, count - 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,194 @@
|
|||||||
|
// EngineConfigView.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
/// Engine configuration + transport: sample rate, input/output channel counts, and a Start/Stop
|
||||||
|
/// toggle, with a sample-rate-mismatch alert on start.
|
||||||
|
///
|
||||||
|
/// The config controls are editable only while the engine is stopped (the underlying
|
||||||
|
/// `SynthesisEngine` setters require it). Pressing Start applies the pending values via
|
||||||
|
/// `ShoeGaze.reconfigureEngine(...)` — which preserves the rig — then starts the engine. On macOS
|
||||||
|
/// a mismatch surfaces as a thrown `CoreAudioError.sampleRateMismatch` (the engine stays stopped);
|
||||||
|
/// on iOS the committed session rate is compared against the request after start. Either way an
|
||||||
|
/// alert reports the requested vs hardware rate; the user picks a matching rate.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - shoeGaze: The session whose engine is configured and started/stopped.
|
||||||
|
/// - hardwareSampleRate: Returns the actual hardware/session rate, or `nil` if unknown. Supplied
|
||||||
|
/// by the host app (macOS: `CoreAudioDriver.deviceSampleRate`; iOS: `iOSAudioDriver.sessionSampleRate`).
|
||||||
|
public struct EngineConfigView: View {
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
/// Standard sample rates offered in the picker.
|
||||||
|
private static let standardRates: [Double] = [44_100, 48_000, 88_200, 96_000]
|
||||||
|
/// Channel-count stepper bounds.
|
||||||
|
private static let maxInputs: Int = 8
|
||||||
|
private static let maxOutputs: Int = 8
|
||||||
|
/// Sample-rate comparison tolerance in Hz.
|
||||||
|
private static let rateEpsilon: Double = 0.5
|
||||||
|
private static let rowSpacing: CGFloat = 12
|
||||||
|
private static let labelOpacity: Double = 0.65
|
||||||
|
|
||||||
|
// MARK: - Properties
|
||||||
|
|
||||||
|
private let shoeGaze: ShoeGaze
|
||||||
|
private let hardwareSampleRate: () -> Double?
|
||||||
|
private let applyConfig: ((Double, Int, Int) throws -> Void)?
|
||||||
|
private let onConfigApplied: () -> Void
|
||||||
|
|
||||||
|
@State private var pendingSampleRate: Double
|
||||||
|
@State private var pendingInputs: Int
|
||||||
|
@State private var pendingOutputs: Int
|
||||||
|
@State private var transportTick: Bool = false
|
||||||
|
@State private var showAlert: Bool = false
|
||||||
|
@State private var alertTitle: String = ""
|
||||||
|
@State private var alertText: String = ""
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// - Parameter applyConfig: Optional override for applying the chosen `(sampleRate, inputs,
|
||||||
|
/// outputs)` while stopped (e.g. a controller that rebuilds a non-board showcase). When `nil`,
|
||||||
|
/// `ShoeGaze.reconfigureEngine(...)` is used, which preserves the board rig.
|
||||||
|
/// - Parameter onConfigApplied: Called after the engine is (re)configured or started/stopped,
|
||||||
|
/// so a host can refresh views that read non-observable engine state (e.g. an input-channel
|
||||||
|
/// picker that lists `0..<engine.numInputChannels`).
|
||||||
|
public init(
|
||||||
|
shoeGaze: ShoeGaze,
|
||||||
|
hardwareSampleRate: @escaping () -> Double? = { nil },
|
||||||
|
applyConfig: ((Double, Int, Int) throws -> Void)? = nil,
|
||||||
|
onConfigApplied: @escaping () -> Void = { }
|
||||||
|
) {
|
||||||
|
self.shoeGaze = shoeGaze
|
||||||
|
self.hardwareSampleRate = hardwareSampleRate
|
||||||
|
self.applyConfig = applyConfig
|
||||||
|
self.onConfigApplied = onConfigApplied
|
||||||
|
_pendingSampleRate = State(initialValue: shoeGaze.engine.sampleRate)
|
||||||
|
_pendingInputs = State(initialValue: shoeGaze.engine.numInputChannels)
|
||||||
|
_pendingOutputs = State(initialValue: shoeGaze.engine.numOutputChannels)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Body
|
||||||
|
|
||||||
|
public var body: some View {
|
||||||
|
_ = transportTick
|
||||||
|
let isRunning: Bool = shoeGaze.engine.isRunning
|
||||||
|
return HStack(spacing: EngineConfigView.rowSpacing) {
|
||||||
|
label("Rate")
|
||||||
|
Picker("Rate", selection: $pendingSampleRate) {
|
||||||
|
ForEach(EngineConfigView.standardRates, id: \.self) { rate in
|
||||||
|
Text("\(Int(rate)) Hz").tag(rate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.labelsHidden()
|
||||||
|
.pickerStyle(.menu)
|
||||||
|
.disabled(isRunning)
|
||||||
|
|
||||||
|
Stepper(value: $pendingInputs, in: 0...EngineConfigView.maxInputs) {
|
||||||
|
Text("In: \(pendingInputs)").foregroundStyle(Color.white)
|
||||||
|
}
|
||||||
|
.disabled(isRunning)
|
||||||
|
.fixedSize()
|
||||||
|
|
||||||
|
Stepper(value: $pendingOutputs, in: 1...EngineConfigView.maxOutputs) {
|
||||||
|
Text("Out: \(pendingOutputs)").foregroundStyle(Color.white)
|
||||||
|
}
|
||||||
|
.disabled(isRunning)
|
||||||
|
.fixedSize()
|
||||||
|
|
||||||
|
Button(isRunning ? "Stop" : "Start") {
|
||||||
|
if isRunning { stopEngine() } else { startEngine() }
|
||||||
|
}
|
||||||
|
.buttonStyle(.borderedProminent)
|
||||||
|
.tint(isRunning ? .red : .green)
|
||||||
|
}
|
||||||
|
.alert(alertTitle, isPresented: $showAlert) {
|
||||||
|
Button("OK", role: .cancel) { }
|
||||||
|
} message: {
|
||||||
|
Text(alertText)
|
||||||
|
}
|
||||||
|
// Resync the pending fields whenever the engine is rebuilt out from under this view (e.g.
|
||||||
|
// the iOS live-input rebuild swaps in a new engine with a different input-channel count).
|
||||||
|
// Keyed on the engine's object identity so it re-runs on every swap; the @State initial
|
||||||
|
// values are seeded only once, so without this the stepper would keep showing the old
|
||||||
|
// engine's channel counts even though audio reads the new one.
|
||||||
|
.task(id: ObjectIdentifier(shoeGaze.engine)) {
|
||||||
|
pendingSampleRate = shoeGaze.engine.sampleRate
|
||||||
|
pendingInputs = shoeGaze.engine.numInputChannels
|
||||||
|
pendingOutputs = shoeGaze.engine.numOutputChannels
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func label(_ text: String) -> some View {
|
||||||
|
Text(text)
|
||||||
|
.font(.subheadline)
|
||||||
|
.foregroundStyle(Color.white.opacity(EngineConfigView.labelOpacity))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Transport
|
||||||
|
|
||||||
|
private func startEngine() {
|
||||||
|
do {
|
||||||
|
if let applyConfig: (Double, Int, Int) throws -> Void = applyConfig {
|
||||||
|
try applyConfig(pendingSampleRate, pendingInputs, pendingOutputs)
|
||||||
|
} else {
|
||||||
|
try shoeGaze.reconfigureEngine(
|
||||||
|
sampleRate: pendingSampleRate,
|
||||||
|
inputChannels: pendingInputs,
|
||||||
|
outputChannels: pendingOutputs
|
||||||
|
)
|
||||||
|
}
|
||||||
|
try shoeGaze.engine.start()
|
||||||
|
} catch {
|
||||||
|
handleStartError(error)
|
||||||
|
transportTick.toggle()
|
||||||
|
onConfigApplied() // config may have applied even if start failed (e.g. rate mismatch)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Started OK. On iOS the session may have committed a different rate than requested — and
|
||||||
|
// `setSampleRate` only stores the logical rate, so leaving the engine running would play
|
||||||
|
// pitch-/time-shifted audio. Stop it (mirroring the macOS thrown-mismatch path) and alert.
|
||||||
|
if let hardware: Double = hardwareSampleRate(),
|
||||||
|
abs(hardware - shoeGaze.engine.sampleRate) > EngineConfigView.rateEpsilon {
|
||||||
|
shoeGaze.engine.stop()
|
||||||
|
presentMismatch(requested: shoeGaze.engine.sampleRate, hardware: hardware)
|
||||||
|
}
|
||||||
|
transportTick.toggle()
|
||||||
|
onConfigApplied()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func stopEngine() {
|
||||||
|
shoeGaze.engine.stop()
|
||||||
|
transportTick.toggle()
|
||||||
|
onConfigApplied()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func handleStartError(_ error: Error) {
|
||||||
|
#if os(macOS)
|
||||||
|
if let coreAudio: CoreAudioError = error as? CoreAudioError,
|
||||||
|
case .sampleRateMismatch(let requested, let deviceRate) = coreAudio {
|
||||||
|
presentMismatch(requested: requested, hardware: deviceRate)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// Any other failure (invalid value, board reconstruction, driver setup) still needs to be
|
||||||
|
// surfaced — otherwise Start appears to do nothing.
|
||||||
|
alertTitle = "Couldn’t Start Engine"
|
||||||
|
alertText = "The engine could not start with the chosen configuration: "
|
||||||
|
+ "\(error.localizedDescription)"
|
||||||
|
showAlert = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private func presentMismatch(requested: Double, hardware: Double) {
|
||||||
|
alertTitle = "Sample Rate Mismatch"
|
||||||
|
alertText = "Requested \(Int(requested)) Hz, but the hardware is running at "
|
||||||
|
+ "\(Int(hardware)) Hz. Set the sample rate to \(Int(hardware)) Hz and start again."
|
||||||
|
showAlert = true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,185 @@
|
|||||||
|
// PedalPaletteView.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
/// A vertical catalog of every available pedal plus a reference list of the routing/branching
|
||||||
|
/// options, sized to sit in a narrow left sidebar.
|
||||||
|
///
|
||||||
|
/// The pedal rows are tappable: selecting one invokes `onAdd(type)` with the pedal's
|
||||||
|
/// `displayName`, which the host wraps in a `PedalType` for `ShoeGaze.appendPedal(_:to:)`. The routing cards
|
||||||
|
/// (Parallel split, Stereo split, Chain router, Merge to mono) are informational only — they
|
||||||
|
/// describe the topologies the engine supports, which are built programmatically rather than via
|
||||||
|
/// linear add (see ``BoardBuilderView`` for the read-only display of existing branches).
|
||||||
|
///
|
||||||
|
/// ## Usage
|
||||||
|
///
|
||||||
|
/// ```swift
|
||||||
|
/// PedalPaletteView { type in
|
||||||
|
/// try? shoeGaze.appendPedal(PedalType(type), to: board)
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
public struct PedalPaletteView: View {
|
||||||
|
|
||||||
|
// MARK: - Layout constants
|
||||||
|
|
||||||
|
private static let sectionSpacing: CGFloat = 14
|
||||||
|
private static let rowSpacing: CGFloat = 6
|
||||||
|
private static let titleFontSize: CGFloat = 12
|
||||||
|
private static let titleOpacity: Double = 0.7
|
||||||
|
private static let cardCornerRadius: CGFloat = 7
|
||||||
|
private static let cardPaddingH: CGFloat = 10
|
||||||
|
private static let cardPaddingV: CGFloat = 7
|
||||||
|
private static let cardBorderOpacity: Double = 0.4
|
||||||
|
private static let cardBorderWidth: CGFloat = 1
|
||||||
|
private static let pedalCardBrightness: Double = 0.18
|
||||||
|
private static let routingCardBrightness: Double = 0.1
|
||||||
|
private static let routingCaptionOpacity: Double = 0.5
|
||||||
|
private static let routingCaptionFontSize: CGFloat = 10
|
||||||
|
private static let addGlyphOpacity: Double = 0.4
|
||||||
|
|
||||||
|
/// Preferred display order for the built-in pedals. Any registered pedal not listed here is
|
||||||
|
/// appended afterwards (sorted) so the palette never silently drops a newly added pedal.
|
||||||
|
private static let preferredOrder: [String] = [
|
||||||
|
"Overdrive", "Compressor", "Limiter", "Noise Gate", "Fuzz",
|
||||||
|
"Graphic EQ", "Tremolo", "Phaser", "Modulation",
|
||||||
|
"Auto-Wah", "Mutant", "Bass Octaver", "Octave Splitter",
|
||||||
|
"Delay", "Feedback Delay", "Multi-Tap Delay", "Ping-Pong", "Reverb",
|
||||||
|
]
|
||||||
|
|
||||||
|
/// Routing/branching topologies the user can insert into the board.
|
||||||
|
private static let routingOptions: [(title: String, caption: String, action: RoutingAction)] = [
|
||||||
|
("Stereo Split", "L/R independent lanes", .stereoSplit),
|
||||||
|
("Parallel Split", "A/B branches, mixed", .parallelSplit),
|
||||||
|
("Merge to Mono", "Collapse stereo → mono", .mergeToMono),
|
||||||
|
]
|
||||||
|
|
||||||
|
/// Routing actions a host can perform from the palette.
|
||||||
|
public enum RoutingAction: Equatable, Sendable {
|
||||||
|
case stereoSplit
|
||||||
|
case parallelSplit
|
||||||
|
case mergeToMono
|
||||||
|
case chainRouter
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Properties
|
||||||
|
|
||||||
|
private let onAdd: (String) -> Void
|
||||||
|
private let onRouting: (RoutingAction) -> Void
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a pedal palette.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - onAdd: Invoked with a pedal's `displayName` when its row is tapped (append to main chain).
|
||||||
|
/// Rows are also `.draggable` carrying `"add:<displayName>"` for drop-onto-lane targeting.
|
||||||
|
/// - onRouting: Invoked when a routing row is tapped. Defaults to a no-op.
|
||||||
|
public init(
|
||||||
|
onAdd: @escaping (String) -> Void,
|
||||||
|
onRouting: @escaping (RoutingAction) -> Void = { _ in }
|
||||||
|
) {
|
||||||
|
self.onAdd = onAdd
|
||||||
|
self.onRouting = onRouting
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Registered pedal names in preferred order, with any unlisted registered pedals appended.
|
||||||
|
private var orderedPedalNames: [String] {
|
||||||
|
let registered: Set<String> = Set(PedalRegistry.builtIn.keys)
|
||||||
|
let ordered: [String] = PedalPaletteView.preferredOrder.filter { registered.contains($0) }
|
||||||
|
let extras: [String] = registered
|
||||||
|
.subtracting(ordered)
|
||||||
|
.sorted()
|
||||||
|
return ordered + extras
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Body
|
||||||
|
|
||||||
|
public var body: some View {
|
||||||
|
VStack(alignment: .leading, spacing: PedalPaletteView.sectionSpacing) {
|
||||||
|
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
|
||||||
|
sectionTitle("PEDALS")
|
||||||
|
ForEach(orderedPedalNames, id: \.self) { name in
|
||||||
|
pedalRow(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
|
||||||
|
sectionTitle("ROUTING")
|
||||||
|
ForEach(PedalPaletteView.routingOptions, id: \.title) { option in
|
||||||
|
routingCard(title: option.title, caption: option.caption, action: option.action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Subviews
|
||||||
|
|
||||||
|
private func sectionTitle(_ text: String) -> some View {
|
||||||
|
Text(text)
|
||||||
|
.font(.system(size: PedalPaletteView.titleFontSize, weight: .semibold))
|
||||||
|
.foregroundStyle(Color.white.opacity(PedalPaletteView.titleOpacity))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A full-width pedal row: tap appends to the main chain; drag carries `"add:<name>"` so it can
|
||||||
|
/// be dropped onto a stereo/parallel lane.
|
||||||
|
private func pedalRow(_ name: String) -> some View {
|
||||||
|
Button {
|
||||||
|
onAdd(name)
|
||||||
|
} label: {
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Text(name)
|
||||||
|
.font(.callout)
|
||||||
|
.foregroundStyle(Color.white)
|
||||||
|
.lineLimit(1)
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
Image(systemName: "plus")
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundStyle(Color.white.opacity(PedalPaletteView.addGlyphOpacity))
|
||||||
|
}
|
||||||
|
.padding(.horizontal, PedalPaletteView.cardPaddingH)
|
||||||
|
.padding(.vertical, PedalPaletteView.cardPaddingV)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
.background(cardBackground(brightness: PedalPaletteView.pedalCardBrightness))
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.draggable("add:\(name)")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A tappable routing row that inserts a region/node into the board.
|
||||||
|
private func routingCard(title: String, caption: String, action: RoutingAction) -> some View {
|
||||||
|
Button {
|
||||||
|
onRouting(action)
|
||||||
|
} label: {
|
||||||
|
VStack(alignment: .leading, spacing: 2) {
|
||||||
|
Text(title)
|
||||||
|
.font(.callout)
|
||||||
|
.foregroundStyle(Color.white)
|
||||||
|
Text(caption)
|
||||||
|
.font(.system(size: PedalPaletteView.routingCaptionFontSize))
|
||||||
|
.foregroundStyle(Color.white.opacity(PedalPaletteView.routingCaptionOpacity))
|
||||||
|
}
|
||||||
|
.padding(.horizontal, PedalPaletteView.cardPaddingH)
|
||||||
|
.padding(.vertical, PedalPaletteView.cardPaddingV)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
.background(cardBackground(brightness: PedalPaletteView.routingCardBrightness))
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func cardBackground(brightness: Double) -> some View {
|
||||||
|
RoundedRectangle(cornerRadius: PedalPaletteView.cardCornerRadius)
|
||||||
|
.fill(Color(white: brightness))
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: PedalPaletteView.cardCornerRadius)
|
||||||
|
.stroke(
|
||||||
|
Color.white.opacity(PedalPaletteView.cardBorderOpacity),
|
||||||
|
lineWidth: PedalPaletteView.cardBorderWidth
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,10 +24,13 @@ private func enclosureColor(for displayName: String) -> Color {
|
|||||||
case "Tremolo": return Color(red: 0.20, green: 0.38, blue: 0.72) // cobalt blue
|
case "Tremolo": return Color(red: 0.20, green: 0.38, blue: 0.72) // cobalt blue
|
||||||
case "Phaser": return Color(red: 0.60, green: 0.22, blue: 0.62) // violet
|
case "Phaser": return Color(red: 0.60, green: 0.22, blue: 0.62) // violet
|
||||||
case "Compressor": return Color(red: 0.18, green: 0.42, blue: 0.32) // forest green
|
case "Compressor": return Color(red: 0.18, green: 0.42, blue: 0.32) // forest green
|
||||||
case "Mu-Tron": return Color(red: 0.70, green: 0.12, blue: 0.48) // magenta / plum
|
case "Mutant": return Color(red: 0.70, green: 0.12, blue: 0.48) // magenta / plum
|
||||||
case "Auto-Wah": return Color(red: 0.80, green: 0.62, blue: 0.10) // gold
|
case "Auto-Wah": return Color(red: 0.80, green: 0.62, blue: 0.10) // gold
|
||||||
case "Feedback Delay": return Color(red: 0.48, green: 0.30, blue: 0.14) // tape sepia
|
case "Feedback Delay": return Color(red: 0.48, green: 0.30, blue: 0.14) // tape sepia
|
||||||
case "Multi-Tap Delay": return Color(red: 0.08, green: 0.48, blue: 0.68) // cyan
|
case "Multi-Tap Delay": return Color(red: 0.08, green: 0.48, blue: 0.68) // cyan
|
||||||
|
case "Limiter": return Color(red: 0.62, green: 0.16, blue: 0.20) // brick red
|
||||||
|
case "Noise Gate": return Color(red: 0.24, green: 0.26, blue: 0.30) // gunmetal
|
||||||
|
case "Graphic EQ": return Color(red: 0.14, green: 0.40, blue: 0.50) // deep teal
|
||||||
default: return Color(red: 0.36, green: 0.36, blue: 0.38) // steel gray
|
default: return Color(red: 0.36, green: 0.36, blue: 0.38) // steel gray
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,6 +187,14 @@ public struct PedalView: View {
|
|||||||
private static let screwInset: CGFloat = 6
|
private static let screwInset: CGFloat = 6
|
||||||
private static let knobColumnCount: Int = 3
|
private static let knobColumnCount: Int = 3
|
||||||
private static let knobSpacing: CGFloat = 10
|
private static let knobSpacing: CGFloat = 10
|
||||||
|
/// Horizontal gap between knobs within a row. Wider than `knobSpacing` so centred
|
||||||
|
/// rows keep a comfortable, touch-friendly gap between adjacent knobs.
|
||||||
|
private static let knobRowItemSpacing: CGFloat = 24
|
||||||
|
/// Horizontal gap between adjacent vertical faders in the slider bank.
|
||||||
|
private static let sliderBankSpacing: CGFloat = 4
|
||||||
|
/// Approximate per-fader footprint (matches `VerticalParameterSlider.controlWidth`),
|
||||||
|
/// used to widen the enclosure so a wide bank (e.g. a 6-band EQ) is never clipped.
|
||||||
|
private static let sliderBankItemWidth: CGFloat = 28
|
||||||
/// Horizontal gap between the Level knob and the bypass control in the bottom row.
|
/// Horizontal gap between the Level knob and the bypass control in the bottom row.
|
||||||
private static let bottomControlsSpacing: CGFloat = 18
|
private static let bottomControlsSpacing: CGFloat = 18
|
||||||
private static let sectionSpacing: CGFloat = 14
|
private static let sectionSpacing: CGFloat = 14
|
||||||
@@ -224,6 +235,9 @@ public struct PedalView: View {
|
|||||||
public var body: some View {
|
public var body: some View {
|
||||||
let accent: Color = enclosureColor(for: pedal.displayName)
|
let accent: Color = enclosureColor(for: pedal.displayName)
|
||||||
let darkAccent: Color = accent.opacity(PedalView.enclosureGradientDarkFraction)
|
let darkAccent: Color = accent.opacity(PedalView.enclosureGradientDarkFraction)
|
||||||
|
// Evaluate the (computed) slider descriptors once per render — both the bank and
|
||||||
|
// the enclosure-width calculation consume the same array.
|
||||||
|
let sliders: [PedalSlider] = pedal.effectSliders
|
||||||
|
|
||||||
ZStack(alignment: .topLeading) {
|
ZStack(alignment: .topLeading) {
|
||||||
// Enclosure fill with top-to-bottom gradient
|
// Enclosure fill with top-to-bottom gradient
|
||||||
@@ -252,6 +266,7 @@ public struct PedalView: View {
|
|||||||
namePlate
|
namePlate
|
||||||
knobGrid
|
knobGrid
|
||||||
switchRow
|
switchRow
|
||||||
|
sliderBank(sliders)
|
||||||
Spacer(minLength: 0)
|
Spacer(minLength: 0)
|
||||||
bottomControls
|
bottomControls
|
||||||
}
|
}
|
||||||
@@ -260,7 +275,7 @@ public struct PedalView: View {
|
|||||||
// Corner screws — overlaid at the four corners
|
// Corner screws — overlaid at the four corners
|
||||||
screwCorners
|
screwCorners
|
||||||
}
|
}
|
||||||
.frame(width: PedalView.enclosureWidth)
|
.frame(width: enclosureWidth(for: sliders))
|
||||||
.shadow(
|
.shadow(
|
||||||
color: Color.black.opacity(PedalView.shadowOpacity),
|
color: Color.black.opacity(PedalView.shadowOpacity),
|
||||||
radius: PedalView.shadowRadius,
|
radius: PedalView.shadowRadius,
|
||||||
@@ -301,18 +316,22 @@ public struct PedalView: View {
|
|||||||
return VStack(spacing: PedalView.knobSpacing) {
|
return VStack(spacing: PedalView.knobSpacing) {
|
||||||
ForEach(Array(rows.enumerated()), id: \.offset) { rowPair in
|
ForEach(Array(rows.enumerated()), id: \.offset) { rowPair in
|
||||||
let row: [PedalKnob] = rowPair.element
|
let row: [PedalKnob] = rowPair.element
|
||||||
HStack(spacing: PedalView.knobSpacing) {
|
// Centre each row: a short row (one or two knobs) sits centred in the
|
||||||
|
// enclosure rather than left-aligned. Symmetric spacers also centre a full
|
||||||
|
// three-knob row, so every row stays horizontally centred.
|
||||||
|
// A full three-knob row keeps the tight spacing so it fits the enclosure;
|
||||||
|
// shorter centred rows use a wider, touch-friendly gap.
|
||||||
|
let rowItemSpacing: CGFloat = row.count >= PedalView.knobColumnCount
|
||||||
|
? PedalView.knobSpacing
|
||||||
|
: PedalView.knobRowItemSpacing
|
||||||
|
HStack(spacing: rowItemSpacing) {
|
||||||
|
Spacer(minLength: 0)
|
||||||
ForEach(Array(row.enumerated()), id: \.offset) { knobPair in
|
ForEach(Array(row.enumerated()), id: \.offset) { knobPair in
|
||||||
let knob: PedalKnob = knobPair.element
|
let knob: PedalKnob = knobPair.element
|
||||||
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
||||||
.foregroundStyle(Color.white)
|
.foregroundStyle(Color.white)
|
||||||
}
|
}
|
||||||
// Pad short rows so knobs stay aligned in their columns.
|
Spacer(minLength: 0)
|
||||||
if row.count < PedalView.knobColumnCount {
|
|
||||||
ForEach(0 ..< (PedalView.knobColumnCount - row.count), id: \.self) { _ in
|
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -332,6 +351,32 @@ public struct PedalView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Row of vertical faders drawn from `pedal.effectSliders`, beneath the switch row.
|
||||||
|
/// Renders nothing when the pedal publishes no sliders.
|
||||||
|
@ViewBuilder
|
||||||
|
private func sliderBank(_ sliders: [PedalSlider]) -> some View {
|
||||||
|
if !sliders.isEmpty {
|
||||||
|
HStack(alignment: .top, spacing: PedalView.sliderBankSpacing) {
|
||||||
|
ForEach(Array(sliders.enumerated()), id: \.offset) { pair in
|
||||||
|
let slider: PedalSlider = pair.element
|
||||||
|
VerticalParameterSlider(slider.label, node: slider.node, range: slider.range)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Enclosure width — the base stompbox width, widened to fit a wide vertical-fader bank
|
||||||
|
/// (e.g. a multi-band graphic EQ) so its faders are never clipped.
|
||||||
|
private func enclosureWidth(for sliders: [PedalSlider]) -> CGFloat {
|
||||||
|
let sliderCount: Int = sliders.count
|
||||||
|
guard sliderCount > 0 else { return PedalView.enclosureWidth }
|
||||||
|
let bankContentWidth: CGFloat =
|
||||||
|
CGFloat(sliderCount) * PedalView.sliderBankItemWidth
|
||||||
|
+ CGFloat(max(0, sliderCount - 1)) * PedalView.sliderBankSpacing
|
||||||
|
let needed: CGFloat = bankContentWidth + 2 * PedalView.enclosurePadding
|
||||||
|
return max(PedalView.enclosureWidth, needed)
|
||||||
|
}
|
||||||
|
|
||||||
/// Bottom control row: the `Level` knob, the bypass switch, and the `Mix` knob,
|
/// Bottom control row: the `Level` knob, the bypass switch, and the `Mix` knob,
|
||||||
/// side-by-side and centred — a symmetric knob-switch-knob footer shared by all pedals.
|
/// side-by-side and centred — a symmetric knob-switch-knob footer shared by all pedals.
|
||||||
private var bottomControls: some View {
|
private var bottomControls: some View {
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// RigFileDocument.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
|
||||||
|
/// A minimal JSON `FileDocument` wrapping a ShoeGaze rig's encoded bytes.
|
||||||
|
///
|
||||||
|
/// Used by ``ShoeGazeBuilderView``'s iOS `.fileExporter` to write the result of
|
||||||
|
/// `ShoeGaze.rigData()` to a user-chosen location. macOS uses an `NSSavePanel` directly and does
|
||||||
|
/// not need this type.
|
||||||
|
struct RigFileDocument: FileDocument {
|
||||||
|
|
||||||
|
/// The rig presets are plain JSON.
|
||||||
|
static var readableContentTypes: [UTType] { [.json] }
|
||||||
|
|
||||||
|
/// Encoded rig JSON.
|
||||||
|
let data: Data
|
||||||
|
|
||||||
|
/// Creates a document from already-encoded rig JSON.
|
||||||
|
init(data: Data) {
|
||||||
|
self.data = data
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Decodes an existing document's bytes (required by `FileDocument`, unused by the exporter).
|
||||||
|
init(configuration: ReadConfiguration) throws {
|
||||||
|
self.data = configuration.file.regularFileContents ?? Data()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Writes the rig JSON into a file wrapper for export.
|
||||||
|
func fileWrapper(configuration: WriteConfiguration) throws -> FileWrapper {
|
||||||
|
FileWrapper(regularFileWithContents: data)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,581 @@
|
|||||||
|
// ShoeGazeBuilderView.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
#if canImport(AppKit)
|
||||||
|
import AppKit
|
||||||
|
#endif
|
||||||
|
import SwiftUI
|
||||||
|
import UniformTypeIdentifiers
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
/// A self-contained pedalboard builder: browse all pedals, build a board by adding / removing /
|
||||||
|
/// reordering pedals, tweak live controls, choose the input source, start the chain, and save or
|
||||||
|
/// load a board setup.
|
||||||
|
///
|
||||||
|
/// This view ties together ``PedalPaletteView`` (the catalog) and ``BoardBuilderView`` (the
|
||||||
|
/// editable chain) with a transport bar, an input-source picker, a board selector, and save/load.
|
||||||
|
/// It is the shared screen hosted by both the macOS and iOS builder app shells.
|
||||||
|
///
|
||||||
|
/// Save/load uses an `NSSavePanel`/`NSOpenPanel` on macOS and `.fileExporter`/`.fileImporter` on
|
||||||
|
/// iOS, both reading/writing the JSON produced by `ShoeGaze.rigData()` / consumed by
|
||||||
|
/// `loadRig(from:)`. Loading and input-source changes stop the engine first (they rebuild the
|
||||||
|
/// graph) and restart it if it was running.
|
||||||
|
///
|
||||||
|
/// ## Usage
|
||||||
|
///
|
||||||
|
/// ```swift
|
||||||
|
/// ShoeGazeBuilderView(shoeGaze: shoeGaze)
|
||||||
|
/// ```
|
||||||
|
public struct ShoeGazeBuilderView: View {
|
||||||
|
|
||||||
|
// MARK: - Layout constants
|
||||||
|
|
||||||
|
private static let outerPadding: CGFloat = 16
|
||||||
|
private static let sectionSpacing: CGFloat = 12
|
||||||
|
private static let rowSpacing: CGFloat = 10
|
||||||
|
private static let dividerOpacity: Double = 0.12
|
||||||
|
private static let labelOpacity: Double = 0.65
|
||||||
|
private static let minWidth: CGFloat = 720
|
||||||
|
private static let minHeight: CGFloat = 460
|
||||||
|
private static let sidebarWidth: CGFloat = 168
|
||||||
|
private static let columnSpacing: CGFloat = 14
|
||||||
|
private static let backgroundRed: Double = 0.08
|
||||||
|
private static let backgroundGreen: Double = 0.07
|
||||||
|
private static let backgroundBlue: Double = 0.06
|
||||||
|
private static let testLoopTag: Int = -1
|
||||||
|
/// UserDefaults key persisting the last input selection (`-1` = test loop, `>= 0` = channel).
|
||||||
|
private static let inputSelectionDefaultsKey: String = "ShoeGaze.inputSelection"
|
||||||
|
/// Maximum crossfade duration honoured by board-switch keyboard shortcuts.
|
||||||
|
private static let maxCrossfadeSeconds: Double = 10.0
|
||||||
|
/// Highest board reachable via a ⌘-number switch shortcut.
|
||||||
|
private static let maxBoardShortcuts: Int = 9
|
||||||
|
private static let defaultRigFileName: String = "ShoeGazeRig"
|
||||||
|
private static let recordDotSize: CGFloat = 9
|
||||||
|
private static let folderLabelOpacity: Double = 0.55
|
||||||
|
|
||||||
|
// MARK: - Properties
|
||||||
|
|
||||||
|
private let shoeGaze: ShoeGaze
|
||||||
|
private let hardwareSampleRate: () -> Double?
|
||||||
|
|
||||||
|
/// Host hook to enable live input when the current engine has no input channel (iOS).
|
||||||
|
/// The host requests microphone access and rebuilds the engine with one input channel,
|
||||||
|
/// preserving the rig, then swaps in a new `ShoeGaze`. `nil` on platforms (macOS) whose
|
||||||
|
/// engine already exposes an input channel, where live input is selected directly.
|
||||||
|
private let onEnableLiveInput: (() -> Void)?
|
||||||
|
|
||||||
|
/// Index of the board currently being edited.
|
||||||
|
@State private var selectedBoardIndex: Int = 0
|
||||||
|
|
||||||
|
/// Crossfade duration (seconds) applied to board switches in the board bar.
|
||||||
|
@State private var crossfadeSeconds: Double = 0.3
|
||||||
|
|
||||||
|
/// Bumped on transport/edit actions to force a re-read of `engine.isRunning`.
|
||||||
|
@State private var transportTick: Bool = false
|
||||||
|
|
||||||
|
/// Shown when live input is selected but microphone access is denied/restricted.
|
||||||
|
@State private var showMicDeniedAlert: Bool = false
|
||||||
|
|
||||||
|
/// Guards the one-time input-source restore in `.onAppear`.
|
||||||
|
@State private var didRestoreInput: Bool = false
|
||||||
|
|
||||||
|
/// Presentation flag for the board-manager sheet (rename / reorder / delete).
|
||||||
|
@State private var showBoardsSheet: Bool = false
|
||||||
|
|
||||||
|
#if !os(macOS)
|
||||||
|
/// iOS file-dialog presentation flags + the document to export. (macOS uses the File menu.)
|
||||||
|
@State private var showImporter: Bool = false
|
||||||
|
@State private var showExporter: Bool = false
|
||||||
|
@State private var exportDocument: RigFileDocument = RigFileDocument(data: Data())
|
||||||
|
/// iOS recording-folder picker presentation flag. (macOS uses the Record menu.)
|
||||||
|
@State private var showRecordingFolderImporter: Bool = false
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a builder view.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - shoeGaze: The `ShoeGaze` manager whose boards and engine are edited. The caller should
|
||||||
|
/// create at least one board before presenting this view.
|
||||||
|
/// - hardwareSampleRate: Returns the actual hardware/session sample rate (or `nil`), used by
|
||||||
|
/// the engine-config Start to warn on a mismatch. Defaults to `nil`.
|
||||||
|
/// - onEnableLiveInput: Host hook invoked when the user requests live input but the engine
|
||||||
|
/// has no input channel (iOS). The host should request microphone access, rebuild the
|
||||||
|
/// engine with one input channel (preserving the rig), and select live input. Defaults to
|
||||||
|
/// `nil` — on macOS the engine already has an input channel, so live input is selected
|
||||||
|
/// directly without a rebuild.
|
||||||
|
public init(
|
||||||
|
shoeGaze: ShoeGaze,
|
||||||
|
hardwareSampleRate: @escaping () -> Double? = { nil },
|
||||||
|
onEnableLiveInput: (() -> Void)? = nil
|
||||||
|
) {
|
||||||
|
self.shoeGaze = shoeGaze
|
||||||
|
self.hardwareSampleRate = hardwareSampleRate
|
||||||
|
self.onEnableLiveInput = onEnableLiveInput
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Body
|
||||||
|
|
||||||
|
public var body: some View {
|
||||||
|
VStack(alignment: .leading, spacing: ShoeGazeBuilderView.sectionSpacing) {
|
||||||
|
transportRow
|
||||||
|
ioRow
|
||||||
|
#if !os(macOS)
|
||||||
|
recordingRow
|
||||||
|
#endif
|
||||||
|
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||||
|
BoardBarView(
|
||||||
|
shoeGaze: shoeGaze,
|
||||||
|
editingBoardIndex: $selectedBoardIndex,
|
||||||
|
crossfadeSeconds: $crossfadeSeconds,
|
||||||
|
onAddBoard: { addBoard() }
|
||||||
|
)
|
||||||
|
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||||
|
HStack(alignment: .top, spacing: ShoeGazeBuilderView.columnSpacing) {
|
||||||
|
paletteSidebar
|
||||||
|
Divider().overlay(Color.white.opacity(ShoeGazeBuilderView.dividerOpacity))
|
||||||
|
boardArea
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||||
|
// Scope + CPU meters sit under the pedal palette, matching its width.
|
||||||
|
ShoeGazeScopeView(shoeGaze: shoeGaze)
|
||||||
|
.frame(width: ShoeGazeBuilderView.sidebarWidth, alignment: .leading)
|
||||||
|
LyrebirdStatusView(engine: shoeGaze.engine)
|
||||||
|
.frame(width: ShoeGazeBuilderView.sidebarWidth, alignment: .leading)
|
||||||
|
}
|
||||||
|
.padding(ShoeGazeBuilderView.outerPadding)
|
||||||
|
.frame(minWidth: ShoeGazeBuilderView.minWidth, minHeight: ShoeGazeBuilderView.minHeight)
|
||||||
|
.background(
|
||||||
|
Color(
|
||||||
|
red: ShoeGazeBuilderView.backgroundRed,
|
||||||
|
green: ShoeGazeBuilderView.backgroundGreen,
|
||||||
|
blue: ShoeGazeBuilderView.backgroundBlue
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.background(boardSwitchShortcuts)
|
||||||
|
.onAppear { restoreInputSelection() }
|
||||||
|
// Each presentation (sheet / importers / exporter / alert) lives on its own anchor
|
||||||
|
// node. SwiftUI reliably drives only one presentation per view node, so stacking them
|
||||||
|
// all on the root view silently swallowed some (e.g. the iOS Load file importer).
|
||||||
|
.background(boardsSheetAnchor)
|
||||||
|
.alert("Microphone Access Needed", isPresented: $showMicDeniedAlert) {
|
||||||
|
Button("OK", role: .cancel) { }
|
||||||
|
} message: {
|
||||||
|
Text("Live input needs microphone access. Enable it in System Settings › Privacy & "
|
||||||
|
+ "Security › Microphone, then select the input again.")
|
||||||
|
}
|
||||||
|
#if !os(macOS)
|
||||||
|
.background(rigImportAnchor)
|
||||||
|
.background(recordingFolderImportAnchor)
|
||||||
|
.background(rigExportAnchor)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Presentation anchors
|
||||||
|
|
||||||
|
/// Hosts the board-manager sheet on its own node so it does not collide with the file
|
||||||
|
/// importers / exporter (one presentation per view node).
|
||||||
|
private var boardsSheetAnchor: some View {
|
||||||
|
Color.clear
|
||||||
|
.sheet(isPresented: $showBoardsSheet) {
|
||||||
|
BoardsSheetView(
|
||||||
|
shoeGaze: shoeGaze,
|
||||||
|
editingBoardIndex: $selectedBoardIndex,
|
||||||
|
crossfadeSeconds: $crossfadeSeconds,
|
||||||
|
onAddBoard: { addBoard() }
|
||||||
|
)
|
||||||
|
.presentationDetents([.medium, .large])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !os(macOS)
|
||||||
|
/// Hosts the rig-load (`.json`) importer on its own node.
|
||||||
|
private var rigImportAnchor: some View {
|
||||||
|
Color.clear
|
||||||
|
.fileImporter(isPresented: $showImporter, allowedContentTypes: [.json]) { result in
|
||||||
|
handleImport(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Hosts the recording-folder importer on its own node.
|
||||||
|
private var recordingFolderImportAnchor: some View {
|
||||||
|
Color.clear
|
||||||
|
.fileImporter(isPresented: $showRecordingFolderImporter, allowedContentTypes: [.folder]) { result in
|
||||||
|
handleRecordingFolderImport(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Hosts the rig-save (`.json`) exporter on its own node.
|
||||||
|
private var rigExportAnchor: some View {
|
||||||
|
Color.clear
|
||||||
|
.fileExporter(
|
||||||
|
isPresented: $showExporter,
|
||||||
|
document: exportDocument,
|
||||||
|
contentType: .json,
|
||||||
|
defaultFilename: ShoeGazeBuilderView.defaultRigFileName
|
||||||
|
) { result in
|
||||||
|
if case .failure(let error) = result {
|
||||||
|
print("[ShoeGazeBuilderView] export failed: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// MARK: - Transport row
|
||||||
|
|
||||||
|
private var transportRow: some View {
|
||||||
|
_ = transportTick
|
||||||
|
return HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||||
|
Text("ShoeGaze Builder")
|
||||||
|
.font(.title2).bold()
|
||||||
|
.foregroundStyle(Color.white)
|
||||||
|
if shoeGaze.isRecording {
|
||||||
|
// Recording indicator (both platforms; recording is driven from the macOS Record
|
||||||
|
// menu or the iOS controls below).
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Circle()
|
||||||
|
.fill(Color.red)
|
||||||
|
.frame(width: ShoeGazeBuilderView.recordDotSize, height: ShoeGazeBuilderView.recordDotSize)
|
||||||
|
Text("REC")
|
||||||
|
.font(.caption.monospaced())
|
||||||
|
.foregroundStyle(Color.red)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Spacer()
|
||||||
|
EngineConfigView(
|
||||||
|
shoeGaze: shoeGaze,
|
||||||
|
hardwareSampleRate: hardwareSampleRate,
|
||||||
|
onConfigApplied: { transportTick.toggle() }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Input + board + save/load row
|
||||||
|
|
||||||
|
private var ioRow: some View {
|
||||||
|
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||||
|
Text("Input:")
|
||||||
|
.font(.subheadline)
|
||||||
|
.foregroundStyle(Color.white.opacity(ShoeGazeBuilderView.labelOpacity))
|
||||||
|
Picker("Input", selection: inputBinding) {
|
||||||
|
Text("Test Loop").tag(ShoeGazeBuilderView.testLoopTag)
|
||||||
|
if shoeGaze.engine.numInputChannels > 0 {
|
||||||
|
ForEach(Array(0..<shoeGaze.engine.numInputChannels), id: \.self) { channel in
|
||||||
|
Text("In \(channel)").tag(channel)
|
||||||
|
}
|
||||||
|
} else if onEnableLiveInput != nil {
|
||||||
|
// No input channel yet: offer live input; selecting it asks the host to
|
||||||
|
// request mic access and rebuild the engine with one (channel 0).
|
||||||
|
Text("Live Input").tag(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.pickerStyle(.menu)
|
||||||
|
.foregroundStyle(Color.white)
|
||||||
|
|
||||||
|
Button("Boards…") { showBoardsSheet = true }
|
||||||
|
.buttonStyle(.bordered).tint(.orange)
|
||||||
|
.help("Rename, reorder, or delete boards")
|
||||||
|
|
||||||
|
Spacer()
|
||||||
|
|
||||||
|
// On macOS, Save/Load live in the app's File menu (see the app shell's AppDelegate);
|
||||||
|
// on iOS they stay in-view, driven by fileExporter/fileImporter.
|
||||||
|
#if !os(macOS)
|
||||||
|
Button("Save…") { saveAction() }
|
||||||
|
.buttonStyle(.bordered).tint(.blue)
|
||||||
|
Button("Load…") { loadAction() }
|
||||||
|
.buttonStyle(.bordered).tint(.blue)
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Palette sidebar
|
||||||
|
|
||||||
|
private var paletteSidebar: some View {
|
||||||
|
ScrollView(.vertical, showsIndicators: true) {
|
||||||
|
PedalPaletteView(
|
||||||
|
onAdd: { type in addPedal(type: type) },
|
||||||
|
onRouting: { action in performRouting(action) }
|
||||||
|
)
|
||||||
|
.padding(.trailing, 2)
|
||||||
|
}
|
||||||
|
.frame(width: ShoeGazeBuilderView.sidebarWidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Board area
|
||||||
|
|
||||||
|
private var boardArea: some View {
|
||||||
|
// Vertically center the signal-flow board in the available space.
|
||||||
|
VStack(spacing: 0) {
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
BoardFlowView(shoeGaze: shoeGaze, boardIndex: clampedBoardIndex)
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Performs a routing action from the palette against the selected board.
|
||||||
|
private func performRouting(_ action: PedalPaletteView.RoutingAction) {
|
||||||
|
guard !shoeGaze.boards.isEmpty else { return }
|
||||||
|
let board: PedalBoard = shoeGaze.boards[clampedBoardIndex]
|
||||||
|
do {
|
||||||
|
switch action {
|
||||||
|
case .stereoSplit: _ = try shoeGaze.appendStereoSplit(to: board)
|
||||||
|
case .parallelSplit: _ = try shoeGaze.appendParallelSplit(to: board)
|
||||||
|
case .mergeToMono: _ = try shoeGaze.appendMergeToMono(to: board)
|
||||||
|
case .chainRouter: break // multi-board routing; not handled in the single-board builder
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
print("[ShoeGazeBuilderView] routing \(action) failed: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `selectedBoardIndex` clamped to a valid board (or `0`); guards against deletes/loads that
|
||||||
|
/// change the board count out from under the picker.
|
||||||
|
private var clampedBoardIndex: Int {
|
||||||
|
guard !shoeGaze.boards.isEmpty else { return 0 }
|
||||||
|
return min(max(selectedBoardIndex, 0), shoeGaze.boards.count - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Input binding
|
||||||
|
|
||||||
|
private var inputBinding: Binding<Int> {
|
||||||
|
Binding(
|
||||||
|
get: {
|
||||||
|
switch shoeGaze.inputSource {
|
||||||
|
case .testLoop: return ShoeGazeBuilderView.testLoopTag
|
||||||
|
case .liveInput(let channel): return channel
|
||||||
|
}
|
||||||
|
},
|
||||||
|
set: { newValue in
|
||||||
|
if newValue == ShoeGazeBuilderView.testLoopTag {
|
||||||
|
switchInput(to: .testLoop)
|
||||||
|
} else if newValue < shoeGaze.engine.numInputChannels {
|
||||||
|
switchInput(to: .liveInput(channel: newValue))
|
||||||
|
} else if let onEnableLiveInput {
|
||||||
|
// Requested a channel the current engine doesn't have (iOS, 0 channels):
|
||||||
|
// hand off to the host to grant mic + rebuild with an input channel.
|
||||||
|
onEnableLiveInput()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Actions
|
||||||
|
|
||||||
|
private func addPedal(type: String) {
|
||||||
|
guard !shoeGaze.boards.isEmpty else { return }
|
||||||
|
let board: PedalBoard = shoeGaze.boards[clampedBoardIndex]
|
||||||
|
do {
|
||||||
|
_ = try shoeGaze.appendPedal(PedalType(type), to: board)
|
||||||
|
} catch {
|
||||||
|
print("[ShoeGazeBuilderView] appendPedal failed: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func addBoard() {
|
||||||
|
var created: PedalBoard?
|
||||||
|
do {
|
||||||
|
let board: PedalBoard = try shoeGaze.addBoard()
|
||||||
|
created = board
|
||||||
|
try shoeGaze.finalizeBoard(board)
|
||||||
|
selectedBoardIndex = shoeGaze.boards.count - 1
|
||||||
|
} catch {
|
||||||
|
if let board: PedalBoard = created { shoeGaze.removeBoard(board) }
|
||||||
|
print("[ShoeGazeBuilderView] addBoard failed: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Switches input source, stopping/restarting the engine around the graph rebuild.
|
||||||
|
///
|
||||||
|
/// Live input requires microphone authorisation first — without it macOS feeds the AUHAL
|
||||||
|
/// input silent zeros. The request is asynchronous, so when the source is `.liveInput` the
|
||||||
|
/// actual switch is deferred until the grant resolves; a denial falls back to the test loop.
|
||||||
|
private func switchInput(to source: InputSource) {
|
||||||
|
guard case .liveInput = source else {
|
||||||
|
applyInputSource(source)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
MicrophonePermission.request { granted in
|
||||||
|
if !granted { showMicDeniedAlert = true }
|
||||||
|
applyInputSource(granted ? source : .testLoop)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Applies an input-source change, stopping/restarting the engine around the graph rebuild.
|
||||||
|
private func applyInputSource(_ source: InputSource) {
|
||||||
|
let wasRunning: Bool = shoeGaze.engine.isRunning
|
||||||
|
if wasRunning { shoeGaze.engine.stop() }
|
||||||
|
do {
|
||||||
|
try shoeGaze.setInputSource(source)
|
||||||
|
persistInputSelection(source)
|
||||||
|
} catch {
|
||||||
|
print("[ShoeGazeBuilderView] setInputSource failed: \(error)")
|
||||||
|
}
|
||||||
|
if wasRunning {
|
||||||
|
try? shoeGaze.engine.start()
|
||||||
|
}
|
||||||
|
transportTick.toggle()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Input persistence
|
||||||
|
|
||||||
|
/// Saves the current input choice so it is restored on the next launch.
|
||||||
|
private func persistInputSelection(_ source: InputSource) {
|
||||||
|
let value: Int
|
||||||
|
switch source {
|
||||||
|
case .testLoop:
|
||||||
|
value = ShoeGazeBuilderView.testLoopTag
|
||||||
|
case .liveInput(let channel):
|
||||||
|
value = channel
|
||||||
|
}
|
||||||
|
UserDefaults.standard.set(value, forKey: ShoeGazeBuilderView.inputSelectionDefaultsKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Restores the saved input choice once on appear. With no saved choice, defaults to live
|
||||||
|
/// input when the microphone is already authorised and the engine has an input channel —
|
||||||
|
/// otherwise stays on the test loop. A saved live channel that no longer fits the engine, or
|
||||||
|
/// a since-revoked permission, falls back to the test loop via `switchInput(to:)`.
|
||||||
|
private func restoreInputSelection() {
|
||||||
|
guard !didRestoreInput else { return }
|
||||||
|
didRestoreInput = true
|
||||||
|
|
||||||
|
let defaults: UserDefaults = UserDefaults.standard
|
||||||
|
if defaults.object(forKey: ShoeGazeBuilderView.inputSelectionDefaultsKey) != nil {
|
||||||
|
let stored: Int = defaults.integer(forKey: ShoeGazeBuilderView.inputSelectionDefaultsKey)
|
||||||
|
if stored >= 0, stored < shoeGaze.engine.numInputChannels {
|
||||||
|
switchInput(to: .liveInput(channel: stored))
|
||||||
|
} else if stored >= 0, shoeGaze.engine.numInputChannels == 0,
|
||||||
|
MicrophonePermission.isAuthorized, let onEnableLiveInput {
|
||||||
|
// iOS: a live choice was saved and the mic is already authorised — rebuild the
|
||||||
|
// engine with an input channel silently (no prompt, since access is granted).
|
||||||
|
onEnableLiveInput()
|
||||||
|
}
|
||||||
|
// A test-loop choice (or live with no host hook / no permission) leaves the test loop.
|
||||||
|
} else if MicrophonePermission.isAuthorized, shoeGaze.engine.numInputChannels > 0 {
|
||||||
|
// First launch with no saved choice but mic already granted → default to live input.
|
||||||
|
switchInput(to: .liveInput(channel: 0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Board-switch shortcuts
|
||||||
|
|
||||||
|
/// Hidden ⌘1…⌘9 buttons that solo (live-switch to) the matching board and select it as the
|
||||||
|
/// edit target. Kept at zero opacity so the shortcuts stay active without showing chrome.
|
||||||
|
private var boardSwitchShortcuts: some View {
|
||||||
|
ZStack {
|
||||||
|
ForEach(0 ..< min(ShoeGazeBuilderView.maxBoardShortcuts, shoeGaze.boards.count), id: \.self) { index in
|
||||||
|
Button("") { switchToBoard(index) }
|
||||||
|
.keyboardShortcut(KeyEquivalent(Character("\(index + 1)")), modifiers: .command)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.opacity(0)
|
||||||
|
.frame(width: 0, height: 0)
|
||||||
|
.accessibilityHidden(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Solos board `index` (a live amp-channel-style switch) and makes it the edit target.
|
||||||
|
private func switchToBoard(_ index: Int) {
|
||||||
|
guard index < shoeGaze.boards.count else { return }
|
||||||
|
selectedBoardIndex = index
|
||||||
|
let seconds: Double = min(max(crossfadeSeconds, 0.0), ShoeGazeBuilderView.maxCrossfadeSeconds)
|
||||||
|
shoeGaze.soloBoard(shoeGaze.boards[index], crossfadeSeconds: seconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Save / Load (iOS)
|
||||||
|
|
||||||
|
// On macOS, Save/Load are driven from the app's File menu (the app shell owns the
|
||||||
|
// NSSavePanel/NSOpenPanel and calls `shoeGaze.saveRig`/`loadRig` directly). On iOS they are
|
||||||
|
// in-view, presenting `fileExporter`/`fileImporter`.
|
||||||
|
#if !os(macOS)
|
||||||
|
/// iOS recording controls: choose an output folder, then start/stop recording.
|
||||||
|
private var recordingRow: some View {
|
||||||
|
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||||
|
Button("Recording Folder…") { showRecordingFolderImporter = true }
|
||||||
|
.buttonStyle(.bordered).tint(.blue)
|
||||||
|
Text(shoeGaze.recordingFolder?.lastPathComponent ?? "No folder")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(Color.white.opacity(ShoeGazeBuilderView.folderLabelOpacity))
|
||||||
|
.lineLimit(1)
|
||||||
|
.truncationMode(.middle)
|
||||||
|
Spacer()
|
||||||
|
Button(shoeGaze.isRecording ? "Stop Recording" : "Record") {
|
||||||
|
toggleRecording()
|
||||||
|
}
|
||||||
|
.buttonStyle(.borderedProminent)
|
||||||
|
.tint(shoeGaze.isRecording ? .red : .accentColor)
|
||||||
|
.disabled(shoeGaze.recordingFolder == nil && !shoeGaze.isRecording)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func toggleRecording() {
|
||||||
|
if shoeGaze.isRecording {
|
||||||
|
shoeGaze.stopRecording()
|
||||||
|
} else {
|
||||||
|
do { try shoeGaze.startRecording() }
|
||||||
|
catch { print("[ShoeGazeBuilderView] startRecording() failed: \(error)") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func handleRecordingFolderImport(_ result: Result<URL, Error>) {
|
||||||
|
switch result {
|
||||||
|
case .success(let url):
|
||||||
|
// A `.fileImporter` folder URL is security-scoped on iOS; keep access open for the
|
||||||
|
// session so the recorder can write into it.
|
||||||
|
if url.startAccessingSecurityScopedResource() {
|
||||||
|
shoeGaze.recordingFolder = url
|
||||||
|
} else {
|
||||||
|
print("[ShoeGazeBuilderView] could not access recording folder")
|
||||||
|
}
|
||||||
|
case .failure(let error):
|
||||||
|
print("[ShoeGazeBuilderView] recording folder pick failed: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func saveAction() {
|
||||||
|
do {
|
||||||
|
exportDocument = RigFileDocument(data: try shoeGaze.rigData())
|
||||||
|
showExporter = true
|
||||||
|
} catch {
|
||||||
|
print("[ShoeGazeBuilderView] rigData failed: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func loadAction() {
|
||||||
|
showImporter = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Loads a rig from a URL, stopping/restarting the engine around the rebuild and resetting the
|
||||||
|
/// board selection to a valid index (load replaces all boards).
|
||||||
|
private func loadRig(from url: URL) {
|
||||||
|
let wasRunning: Bool = shoeGaze.engine.isRunning
|
||||||
|
if wasRunning { shoeGaze.engine.stop() }
|
||||||
|
do {
|
||||||
|
try shoeGaze.loadRig(from: url)
|
||||||
|
selectedBoardIndex = 0
|
||||||
|
} catch {
|
||||||
|
print("[ShoeGazeBuilderView] loadRig failed: \(error)")
|
||||||
|
}
|
||||||
|
if wasRunning { try? shoeGaze.engine.start() }
|
||||||
|
transportTick.toggle()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func handleImport(_ result: Result<URL, Error>) {
|
||||||
|
switch result {
|
||||||
|
case .success(let url):
|
||||||
|
// A `.fileImporter` URL is security-scoped on iOS; access must be started to read it.
|
||||||
|
let scoped: Bool = url.startAccessingSecurityScopedResource()
|
||||||
|
defer { if scoped { url.stopAccessingSecurityScopedResource() } }
|
||||||
|
loadRig(from: url)
|
||||||
|
case .failure(let error):
|
||||||
|
print("[ShoeGazeBuilderView] import failed: \(error)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
// ShoeGazeScopeView.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
/// Oscilloscope panel showing the live input and board-output waveforms.
|
||||||
|
///
|
||||||
|
/// Wraps Lyrebird's `LyrebirdScopeView` bound to ``ShoeGaze/scopeTap`` and adds a labelled
|
||||||
|
/// legend so each lane is identifiable (`In 0`, `Out L`, `Out R`, …) — input lanes on top,
|
||||||
|
/// outputs below. Use it to confirm signal flow: a flat input lane with audible test-tone
|
||||||
|
/// output means the live input never reaches the board head bus; a live input lane with a flat
|
||||||
|
/// output lane points downstream.
|
||||||
|
///
|
||||||
|
/// The lane colours match `LyrebirdScopeView` (cyan, orange, green, yellow, cycling). The view
|
||||||
|
/// keys itself on the tap's object identity so a reconfigure that rebuilds the tap recreates the
|
||||||
|
/// underlying scope.
|
||||||
|
public struct ShoeGazeScopeView: View {
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
/// Colours used by `LyrebirdScopeView`, mirrored here for the legend swatches.
|
||||||
|
private static let laneColors: [Color] = [.cyan, .orange, .green, .yellow]
|
||||||
|
private static let scopeHeight: CGFloat = 120
|
||||||
|
private static let legendSpacing: CGFloat = 14
|
||||||
|
private static let swatchSize: CGFloat = 9
|
||||||
|
private static let panelSpacing: CGFloat = 6
|
||||||
|
private static let labelOpacity: Double = 0.75
|
||||||
|
|
||||||
|
// MARK: - Properties
|
||||||
|
|
||||||
|
private let shoeGaze: ShoeGaze
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// - Parameter shoeGaze: The session whose ``ShoeGaze/scopeTap`` is visualised.
|
||||||
|
public init(shoeGaze: ShoeGaze) {
|
||||||
|
self.shoeGaze = shoeGaze
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Body
|
||||||
|
|
||||||
|
public var body: some View {
|
||||||
|
VStack(alignment: .leading, spacing: ShoeGazeScopeView.panelSpacing) {
|
||||||
|
if let capture: ScopeCapture = shoeGaze.scopeTap {
|
||||||
|
legend(for: capture)
|
||||||
|
LyrebirdScopeView(capture: capture)
|
||||||
|
.frame(height: ShoeGazeScopeView.scopeHeight)
|
||||||
|
.id(ObjectIdentifier(capture))
|
||||||
|
} else {
|
||||||
|
Text("Scope unavailable")
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundStyle(Color.white.opacity(ShoeGazeScopeView.labelOpacity))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Legend
|
||||||
|
|
||||||
|
/// A horizontal legend mapping each lane colour to its bus label.
|
||||||
|
private func legend(for capture: ScopeCapture) -> some View {
|
||||||
|
HStack(spacing: ShoeGazeScopeView.legendSpacing) {
|
||||||
|
ForEach(Array(capture.buses.enumerated()), id: \.offset) { index, bus in
|
||||||
|
HStack(spacing: 4) {
|
||||||
|
Circle()
|
||||||
|
.fill(ShoeGazeScopeView.laneColors[index % ShoeGazeScopeView.laneColors.count])
|
||||||
|
.frame(
|
||||||
|
width: ShoeGazeScopeView.swatchSize,
|
||||||
|
height: ShoeGazeScopeView.swatchSize
|
||||||
|
)
|
||||||
|
Text(shoeGaze.scopeLaneLabel(forBus: bus))
|
||||||
|
.font(.caption2)
|
||||||
|
.foregroundStyle(Color.white.opacity(ShoeGazeScopeView.labelOpacity))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||