From 168cd85284ff7c19d0e8bc598dbca89911c86534 Mon Sep 17 00:00:00 2001 From: Diego Stamigni Date: Thu, 21 Mar 2019 10:04:53 +0000 Subject: [PATCH] Small macOS sample app UI improvements --- ExampleAppMac/ExampleAppMac/AppDelegate.m | 73 ++- .../ExampleAppMac/Base.lproj/MainMenu.xib | 484 +++++++++++++----- 2 files changed, 402 insertions(+), 155 deletions(-) diff --git a/ExampleAppMac/ExampleAppMac/AppDelegate.m b/ExampleAppMac/ExampleAppMac/AppDelegate.m index 4705410..49b9cc2 100644 --- a/ExampleAppMac/ExampleAppMac/AppDelegate.m +++ b/ExampleAppMac/ExampleAppMac/AppDelegate.m @@ -14,6 +14,7 @@ NSView* meter; NSSlider* slider; STKAudioPlayer* audioPlayer; + NSTextField* textField; } @end @@ -21,26 +22,67 @@ -(void) applicationDidFinishLaunching:(NSNotification *)aNotification { - CGRect frame = [self.window.contentView frame]; - - NSButton* playFromHTTPButton = [[NSButton alloc] initWithFrame:CGRectMake(10, 10, frame.size.width - 20, 100)]; - + NSButton* playFromHTTPButton = [[NSButton alloc] init]; [playFromHTTPButton setTitle:@"Play from HTTP"]; [playFromHTTPButton setAction:@selector(playFromHTTP)]; + + NSButton* stopButton = [[NSButton alloc] init]; + [stopButton setTitle:@"Stop"]; + [stopButton setAction:@selector(stopPlaying)]; + + NSStackView *buttonStackView = [[NSStackView alloc] initWithFrame:self.window.contentView.frame]; + [buttonStackView setDistribution:NSStackViewDistributionFillEqually]; + [buttonStackView setSpacing:8]; + [buttonStackView setOrientation:NSUserInterfaceLayoutOrientationHorizontal]; + + [buttonStackView addArrangedSubview:playFromHTTPButton]; + [buttonStackView addArrangedSubview:stopButton]; - slider = [[NSSlider alloc] initWithFrame:CGRectMake(10, 140, frame.size.width - 20, 20)]; + slider = [[NSSlider alloc] init]; + [slider setTranslatesAutoresizingMaskIntoConstraints:false]; [slider setAction:@selector(sliderChanged:)]; - meter = [[NSView alloc] initWithFrame:CGRectMake(10, 200, 0, 20)]; + meter = [[NSView alloc] init]; + [meter setTranslatesAutoresizingMaskIntoConstraints:false]; [meter setLayer:[CALayer new]]; [meter setWantsLayer:YES]; meter.layer.backgroundColor = [NSColor greenColor].CGColor; - - [[self.window contentView] addSubview:slider]; - [[self.window contentView] addSubview:playFromHTTPButton]; - [[self.window contentView] addSubview:meter]; - - audioPlayer = [[STKAudioPlayer alloc] initWithOptions:(STKAudioPlayerOptions){ .enableVolumeMixer = NO, .equalizerBandFrequencies = {50, 100, 200, 400, 800, 1600, 2600, 16000} } ]; + + NSView *meterWrapper = [[NSView alloc] init]; + [meterWrapper setTranslatesAutoresizingMaskIntoConstraints:false]; + [meterWrapper addSubview:meter]; + + textField = [[NSTextField alloc] init]; + [textField setTranslatesAutoresizingMaskIntoConstraints:false]; + textField.stringValue = @"http://www.abstractpath.com/files/audiosamples/sample.mp3"; + + NSStackView *stackView = [[NSStackView alloc] initWithFrame:self.window.contentView.frame]; + [stackView setTranslatesAutoresizingMaskIntoConstraints:false]; + [stackView setDistribution:NSStackViewDistributionEqualSpacing]; + [stackView setSpacing:8]; + [stackView setOrientation:NSUserInterfaceLayoutOrientationVertical]; + + [stackView addArrangedSubview:textField]; + [stackView addArrangedSubview:meterWrapper]; + [stackView addArrangedSubview:slider]; + [stackView addArrangedSubview:buttonStackView]; + + [[self.window contentView] addSubview:stackView]; + + [stackView.topAnchor constraintEqualToAnchor:self.window.contentView.topAnchor constant:16].active = true; + [stackView.bottomAnchor constraintEqualToAnchor:self.window.contentView.bottomAnchor constant:-16].active = true; + [stackView.rightAnchor constraintEqualToAnchor:self.window.contentView.rightAnchor constant:-16].active = true; + [stackView.leftAnchor constraintEqualToAnchor:self.window.contentView.leftAnchor constant:16].active = true; + + [meter.topAnchor constraintEqualToAnchor:meterWrapper.topAnchor].active = true; + [meter.bottomAnchor constraintEqualToAnchor:meterWrapper.bottomAnchor].active = true; + [meter.leadingAnchor constraintEqualToAnchor:meterWrapper.leadingAnchor].active = true; + + audioPlayer = [[STKAudioPlayer alloc] initWithOptions:(STKAudioPlayerOptions) + { + .enableVolumeMixer = NO, + .equalizerBandFrequencies = {50, 100, 200, 400, 800, 1600, 2600, 16000} + }]; audioPlayer.delegate = self; audioPlayer.meteringEnabled = YES; audioPlayer.volume = 0.1; @@ -58,10 +100,15 @@ -(void) playFromHTTP { - [audioPlayer play:@"http://www.abstractpath.com/files/audiosamples/sample.mp3"]; + [audioPlayer play:textField.stringValue]; audioPlayer.rate = 2; } +- (void) stopPlaying +{ + [audioPlayer stop]; +} + -(void) tick:(NSTimer*)timer { if (!audioPlayer) diff --git a/ExampleAppMac/ExampleAppMac/Base.lproj/MainMenu.xib b/ExampleAppMac/ExampleAppMac/Base.lproj/MainMenu.xib index eefd534..f6ebc53 100644 --- a/ExampleAppMac/ExampleAppMac/Base.lproj/MainMenu.xib +++ b/ExampleAppMac/ExampleAppMac/Base.lproj/MainMenu.xib @@ -1,100 +1,17 @@ - - + + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + @@ -102,6 +19,9 @@ + + + @@ -116,95 +36,211 @@ - + + + + + + + + + + + + + - - + + + + + - - + + + + + + + + + + - + + + + + - - + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + - + + + + + + + + + + + + + - - - - + + + + + + + + + + - - + + + + + + + + + + + + + @@ -214,18 +250,38 @@ + + + - - + + + + + + + + + + + + + + + + + + + @@ -236,12 +292,21 @@ + + + + + + + + + @@ -249,8 +314,16 @@ - - + + + + + + + + + + @@ -265,13 +338,37 @@ - - - - + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + @@ -279,15 +376,27 @@ + + + + + + + + + + + + @@ -298,12 +407,21 @@ + + + + + + + + + @@ -314,30 +432,55 @@ + + + + + + + + + + + + + + + - + + + + + + + + + + + @@ -346,12 +489,27 @@ - - + + + + + + + + + + + + + + + + + + - @@ -363,14 +521,23 @@ Default + + + Left to Right + + + Right to Left + + + @@ -379,14 +546,23 @@ Default + + + Left to Right + + + Right to Left + + + @@ -394,12 +570,21 @@ + + + + + + + + + @@ -412,20 +597,39 @@ + + + + + + + + - - - + + + + + + + + + + - + + + + + @@ -433,17 +637,21 @@ - + + + + + - + - + @@ -454,14 +662,6 @@ - - - - - - - - - +