iOS 0.3.0: card editors like Android's for every plugin (knobs, switches, tabs, drawings)
Layouts exported from Android's DeviceLayouts (DeviceLayouts.json), iOS layouts for the devices with hand-built Android editors, SwiftUI editor shared by the extension and the app, Mac snapshot tool for the editors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
47588990ce
commit
b6589ee792
@@ -2,31 +2,26 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
// The extension's principal class: the factory for every device listed in
|
||||
// components.txt (picked by subtype; instruments and effects) and a generic editor
|
||||
// for its parameters
|
||||
// (sliders, segmented switches for short choice lists, menus for long ones).
|
||||
// The card-style editors of the Android app come later; this keeps every
|
||||
// parameter reachable meanwhile.
|
||||
// components.txt (picked by subtype; instruments and effects), and its editor:
|
||||
// the SwiftUI card editor (Editor/DeviceEditor.swift), as in the Android app.
|
||||
// The app hosts the same editor for the devices it plays itself.
|
||||
|
||||
#import <CoreAudioKit/CoreAudioKit.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "Components.gen.h"
|
||||
#import "SizzleFXViewController.h"
|
||||
|
||||
static UIColor *Amber(void) { return [UIColor colorWithRed:0.96 green:0.76 blue:0.29 alpha:1]; }
|
||||
static UIColor *Dim(void) { return [UIColor colorWithWhite:0.62 alpha:1]; }
|
||||
// The Swift side's generated header: named after the target that compiles this file.
|
||||
#if __has_include("SizzleFX-Swift.h")
|
||||
#import "SizzleFX-Swift.h"
|
||||
#else
|
||||
#import "Sizzle-Swift.h"
|
||||
#endif
|
||||
|
||||
@implementation SizzleFXViewController {
|
||||
SizzleDeviceAU *_au;
|
||||
UIStackView *_stack;
|
||||
NSMutableDictionary<NSNumber *, UIControl *> *_controls;
|
||||
NSMutableDictionary<NSNumber *, UILabel *> *_valueLabels;
|
||||
AUParameterObserverToken _token;
|
||||
BOOL _built;
|
||||
}
|
||||
|
||||
#pragma mark - factory
|
||||
|
||||
- (AUAudioUnit *)createAudioUnitWithComponentDescription:(AudioComponentDescription)desc error:(NSError **)error {
|
||||
_au = [[[SizzleDeviceAU classForComponentType:desc.componentType] alloc]
|
||||
initWithComponentDescription:desc options:0 error:error];
|
||||
@@ -39,158 +34,28 @@ static UIColor *Dim(void) { return [UIColor colorWithWhite:0.62 alpha:1]; }
|
||||
[self buildIfReady];
|
||||
}
|
||||
|
||||
#pragma mark - view
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.preferredContentSize = CGSizeMake(520, 420);
|
||||
self.preferredContentSize = CGSizeMake(560, 460);
|
||||
self.view.backgroundColor = [UIColor colorWithRed:0.07 green:0.08 blue:0.09 alpha:1];
|
||||
UIScrollView *scroll = [UIScrollView new];
|
||||
scroll.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self.view addSubview:scroll];
|
||||
_stack = [UIStackView new];
|
||||
_stack.axis = UILayoutConstraintAxisVertical;
|
||||
_stack.spacing = 10;
|
||||
_stack.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[scroll addSubview:_stack];
|
||||
UILayoutGuide *g = self.view.safeAreaLayoutGuide;
|
||||
[NSLayoutConstraint activateConstraints:@[
|
||||
[scroll.leadingAnchor constraintEqualToAnchor:g.leadingAnchor],
|
||||
[scroll.trailingAnchor constraintEqualToAnchor:g.trailingAnchor],
|
||||
[scroll.topAnchor constraintEqualToAnchor:g.topAnchor],
|
||||
[scroll.bottomAnchor constraintEqualToAnchor:g.bottomAnchor],
|
||||
[_stack.leadingAnchor constraintEqualToAnchor:scroll.contentLayoutGuide.leadingAnchor constant:14],
|
||||
[_stack.trailingAnchor constraintEqualToAnchor:scroll.contentLayoutGuide.trailingAnchor constant:-14],
|
||||
[_stack.topAnchor constraintEqualToAnchor:scroll.contentLayoutGuide.topAnchor constant:12],
|
||||
[_stack.bottomAnchor constraintEqualToAnchor:scroll.contentLayoutGuide.bottomAnchor constant:-12],
|
||||
[_stack.widthAnchor constraintEqualToAnchor:scroll.frameLayoutGuide.widthAnchor constant:-28],
|
||||
]];
|
||||
[self buildIfReady];
|
||||
}
|
||||
|
||||
- (UILabel *)label:(NSString *)text size:(CGFloat)size color:(UIColor *)color {
|
||||
UILabel *l = [UILabel new];
|
||||
l.text = text;
|
||||
l.font = [UIFont monospacedSystemFontOfSize:size weight:UIFontWeightRegular];
|
||||
l.textColor = color;
|
||||
return l;
|
||||
}
|
||||
|
||||
- (void)buildIfReady {
|
||||
if (_built || !_au || !_stack) return;
|
||||
if (_built || !_au || !self.isViewLoaded) return;
|
||||
_built = YES;
|
||||
_controls = [NSMutableDictionary dictionary];
|
||||
_valueLabels = [NSMutableDictionary dictionary];
|
||||
|
||||
[_stack addArrangedSubview:[self label:_au.displayName.uppercaseString size:15 color:Amber()]];
|
||||
|
||||
if (_au.factoryPresets.count > 0) {
|
||||
UIButton *presets = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
[presets setTitle:@"PRESET ▾" forState:UIControlStateNormal];
|
||||
presets.titleLabel.font = [UIFont monospacedSystemFontOfSize:13 weight:UIFontWeightRegular];
|
||||
presets.tintColor = Amber();
|
||||
presets.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
|
||||
NSMutableArray<UIAction *> *items = [NSMutableArray array];
|
||||
__weak SizzleDeviceAU *au = _au;
|
||||
__weak UIButton *weakButton = presets;
|
||||
for (AUAudioUnitPreset *p in _au.factoryPresets) {
|
||||
[items addObject:[UIAction actionWithTitle:p.name image:nil identifier:nil handler:^(UIAction *a) {
|
||||
au.currentPreset = p;
|
||||
[weakButton setTitle:[NSString stringWithFormat:@"PRESET: %@ ▾", p.name] forState:UIControlStateNormal];
|
||||
}]];
|
||||
}
|
||||
presets.menu = [UIMenu menuWithChildren:items];
|
||||
presets.showsMenuAsPrimaryAction = YES;
|
||||
[_stack addArrangedSubview:presets];
|
||||
}
|
||||
|
||||
for (AUParameter *p in _au.parameterTree.allParameters) [self addRowFor:p];
|
||||
|
||||
__weak SizzleFXViewController *weakSelf = self;
|
||||
_token = [_au.parameterTree tokenByAddingParameterObserver:^(AUParameterAddress address, AUValue value) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf show:address value:value]; });
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)addRowFor:(AUParameter *)p {
|
||||
NSNumber *addr = @(p.address);
|
||||
UIStackView *head = [UIStackView new];
|
||||
head.axis = UILayoutConstraintAxisHorizontal;
|
||||
[head addArrangedSubview:[self label:p.displayName.uppercaseString size:11 color:Dim()]];
|
||||
UILabel *value = [self label:[_au stringForParameter:p value:p.value] size:11 color:UIColor.whiteColor];
|
||||
value.textAlignment = NSTextAlignmentRight;
|
||||
[head addArrangedSubview:value];
|
||||
_valueLabels[addr] = value;
|
||||
|
||||
UIControl *control;
|
||||
NSArray<NSString *> *choices = p.valueStrings;
|
||||
NSUInteger chars = [[choices componentsJoinedByString:@""] length];
|
||||
__weak SizzleFXViewController *weakSelf = self;
|
||||
if (choices.count > 0 && choices.count <= 6 && chars <= 34) {
|
||||
UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:choices];
|
||||
seg.selectedSegmentIndex = (NSInteger)lroundf(p.value);
|
||||
seg.selectedSegmentTintColor = Amber();
|
||||
[seg addAction:[UIAction actionWithHandler:^(UIAction *a) {
|
||||
[weakSelf set:p value:(AUValue)seg.selectedSegmentIndex];
|
||||
}] forControlEvents:UIControlEventValueChanged];
|
||||
control = seg;
|
||||
} else if (choices.count > 0) {
|
||||
UIButton *b = [UIButton buttonWithType:UIButtonTypeSystem];
|
||||
b.tintColor = Amber();
|
||||
b.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
|
||||
NSMutableArray<UIAction *> *items = [NSMutableArray array];
|
||||
[choices enumerateObjectsUsingBlock:^(NSString *name, NSUInteger i, BOOL *stop) {
|
||||
[items addObject:[UIAction actionWithTitle:name image:nil identifier:nil handler:^(UIAction *a) {
|
||||
[weakSelf set:p value:(AUValue)i];
|
||||
}]];
|
||||
}];
|
||||
b.menu = [UIMenu menuWithChildren:items];
|
||||
b.showsMenuAsPrimaryAction = YES;
|
||||
[b setTitle:[NSString stringWithFormat:@"%@ ▾", choices[(NSUInteger)lroundf(p.value)]] forState:UIControlStateNormal];
|
||||
control = b;
|
||||
} else {
|
||||
UISlider *s = [UISlider new];
|
||||
s.minimumValue = p.minValue;
|
||||
s.maximumValue = p.maxValue;
|
||||
s.value = p.value;
|
||||
s.minimumTrackTintColor = Amber();
|
||||
BOOL isInt = p.unit == kAudioUnitParameterUnit_Indexed;
|
||||
[s addAction:[UIAction actionWithHandler:^(UIAction *a) {
|
||||
AUValue v = isInt ? roundf(s.value) : s.value;
|
||||
[weakSelf set:p value:v];
|
||||
}] forControlEvents:UIControlEventValueChanged];
|
||||
control = s;
|
||||
}
|
||||
_controls[addr] = control;
|
||||
|
||||
UIStackView *row = [[UIStackView alloc] initWithArrangedSubviews:@[head, control]];
|
||||
row.axis = UILayoutConstraintAxisVertical;
|
||||
row.spacing = 4;
|
||||
[_stack addArrangedSubview:row];
|
||||
}
|
||||
|
||||
- (void)set:(AUParameter *)p value:(AUValue)v {
|
||||
[p setValue:v originator:_token];
|
||||
[self show:p.address value:v];
|
||||
}
|
||||
|
||||
- (void)show:(AUParameterAddress)address value:(AUValue)value {
|
||||
AUParameter *p = [_au.parameterTree parameterWithAddress:address];
|
||||
if (!p) return;
|
||||
_valueLabels[@(address)].text = [_au stringForParameter:p value:value];
|
||||
UIControl *c = _controls[@(address)];
|
||||
if ([c isKindOfClass:[UISlider class]]) {
|
||||
if (!c.isTracking) ((UISlider *)c).value = value;
|
||||
} else if ([c isKindOfClass:[UISegmentedControl class]]) {
|
||||
((UISegmentedControl *)c).selectedSegmentIndex = (NSInteger)lroundf(value);
|
||||
} else if ([c isKindOfClass:[UIButton class]] && p.valueStrings.count) {
|
||||
NSUInteger i = MIN((NSUInteger)lroundf(value), p.valueStrings.count - 1);
|
||||
[(UIButton *)c setTitle:[NSString stringWithFormat:@"%@ ▾", p.valueStrings[i]] forState:UIControlStateNormal];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
if (_token && _au) [_au.parameterTree removeParameterObserver:_token];
|
||||
UIViewController *editor = [SizzleEditorFactory makeEditorFor:_au];
|
||||
[self addChildViewController:editor];
|
||||
editor.view.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[self.view addSubview:editor.view];
|
||||
UILayoutGuide *g = self.view.safeAreaLayoutGuide;
|
||||
[NSLayoutConstraint activateConstraints:@[
|
||||
[editor.view.leadingAnchor constraintEqualToAnchor:g.leadingAnchor],
|
||||
[editor.view.trailingAnchor constraintEqualToAnchor:g.trailingAnchor],
|
||||
[editor.view.topAnchor constraintEqualToAnchor:g.topAnchor],
|
||||
[editor.view.bottomAnchor constraintEqualToAnchor:g.bottomAnchor],
|
||||
]];
|
||||
[editor didMoveToParentViewController:self];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user