From 73c4360b1de82b6fc068cb250a87bc3dad84319d Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Thu, 30 Jun 2022 00:28:03 -0700 Subject: [PATCH] [Info Inspector] Improve formatting of sample rate Sample rate now has a locale independent formatting, and no longer uses scientific notation for large numbers. Signed-off-by: Christopher Snowhill --- Application/AppController.m | 4 +++ Base.lproj/InfoInspector.xib | 6 +++- Cog.xcodeproj/project.pbxproj | 4 +++ .../NumberHertzToStringTransformer.swift | 31 +++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 Transformers/NumberHertzToStringTransformer.swift diff --git a/Application/AppController.m b/Application/AppController.m index 811587d8b..a16da9cf2 100644 --- a/Application/AppController.m +++ b/Application/AppController.m @@ -65,6 +65,10 @@ static AppController *kAppController = nil; NSValueTransformer *totalTimeTransformer = [[TotalTimeTransformer alloc] init]; [NSValueTransformer setValueTransformer:totalTimeTransformer forName:@"TotalTimeTransformer"]; + + NSValueTransformer *numberHertzToStringTransformer = [[NumberHertzToStringTransformer alloc] init]; + [NSValueTransformer setValueTransformer:numberHertzToStringTransformer + forName:@"NumberHertzToStringTransformer"]; } - (id)init { self = [super init]; diff --git a/Base.lproj/InfoInspector.xib b/Base.lproj/InfoInspector.xib index 7450018f0..5878c361e 100644 --- a/Base.lproj/InfoInspector.xib +++ b/Base.lproj/InfoInspector.xib @@ -215,7 +215,11 @@ - + + + NumberHertzToStringTransformer + + diff --git a/Cog.xcodeproj/project.pbxproj b/Cog.xcodeproj/project.pbxproj index f947d1517..64d123d8b 100644 --- a/Cog.xcodeproj/project.pbxproj +++ b/Cog.xcodeproj/project.pbxproj @@ -171,6 +171,7 @@ 83978E29285C5C0A0076ED21 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 83978E28285C5C0A0076ED21 /* GoogleService-Info.plist */; }; 83988F0E27BE0A5900A0E89A /* RedundantPlaylistDataStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 83988F0D27BE0A5900A0E89A /* RedundantPlaylistDataStore.m */; }; 8399D4E21805A55000B503B1 /* XmlContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = 8399D4E01805A55000B503B1 /* XmlContainer.m */; }; + 839B837F286D7F8D00F529EE /* NumberHertzToStringTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 839B837E286D7F8D00F529EE /* NumberHertzToStringTransformer.swift */; }; 839DA7CF274A2D4C001B18E5 /* NSDictionary+Merge.m in Sources */ = {isa = PBXBuildFile; fileRef = 839DA7CE274A2D4C001B18E5 /* NSDictionary+Merge.m */; }; 83A360B220E4E81D00192DAB /* Flac.bundle in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8303A30C20E4E3D000951EF8 /* Flac.bundle */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 83A3B734283AE89000CC6593 /* ColorToValueTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 83A3B72F283AE6AA00CC6593 /* ColorToValueTransformer.m */; }; @@ -993,6 +994,7 @@ 83988F0D27BE0A5900A0E89A /* RedundantPlaylistDataStore.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RedundantPlaylistDataStore.m; sourceTree = ""; }; 8399D4E01805A55000B503B1 /* XmlContainer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XmlContainer.m; sourceTree = ""; }; 8399D4E11805A55000B503B1 /* XmlContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XmlContainer.h; sourceTree = ""; }; + 839B837E286D7F8D00F529EE /* NumberHertzToStringTransformer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = NumberHertzToStringTransformer.swift; path = Transformers/NumberHertzToStringTransformer.swift; sourceTree = ""; }; 839DA7CB274A2D4C001B18E5 /* NSDictionary+Merge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSDictionary+Merge.h"; sourceTree = ""; }; 839DA7CE274A2D4C001B18E5 /* NSDictionary+Merge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSDictionary+Merge.m"; sourceTree = ""; }; 839E3B53286595D700880EA2 /* GeneralPane.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GeneralPane.h; path = Preferences/Preferences/GeneralPane.h; sourceTree = ""; }; @@ -1406,6 +1408,7 @@ 838F84FF25687C5C00C3E614 /* Cog-Bridging-Header.h */, 834B05E82859C006000B7DC0 /* TotalTimeTransformer.h */, 834B05E92859C006000B7DC0 /* TotalTimeTransformer.m */, + 839B837E286D7F8D00F529EE /* NumberHertzToStringTransformer.swift */, ); name = Transformers; sourceTree = ""; @@ -2580,6 +2583,7 @@ 17E0D5ED0F520F02005B6FED /* TimeField.m in Sources */, 17E0D6160F520F87005B6FED /* FontSizetoLineHeightTransformer.m in Sources */, 17E0D6170F520F87005B6FED /* StringToURLTransformer.m in Sources */, + 839B837F286D7F8D00F529EE /* NumberHertzToStringTransformer.swift in Sources */, 17E0D61C0F520F9F005B6FED /* VolumeButton.m in Sources */, 17E0D61D0F520F9F005B6FED /* VolumeSlider.m in Sources */, 172A12330F5911D20078EF0C /* RepeatTransformers.m in Sources */, diff --git a/Transformers/NumberHertzToStringTransformer.swift b/Transformers/NumberHertzToStringTransformer.swift new file mode 100644 index 000000000..b2064741a --- /dev/null +++ b/Transformers/NumberHertzToStringTransformer.swift @@ -0,0 +1,31 @@ +// +// NumberHertzToStringTransformer.swift +// Cog +// +// Created by Christopher Snowhill on 6/29/22. +// + +import Cocoa + +@objc(NumberHertzToStringTransformer) +public final class NumberHertzToStringTransformer: ValueTransformer { + fileprivate static var floatFormatter: NumberFormatter { + let formatter = NumberFormatter() + formatter.maximumFractionDigits = 2 + formatter.minimumFractionDigits = 0 + formatter.minimumIntegerDigits = 1 + formatter.roundingIncrement = 0.5 + formatter.usesGroupingSeparator = true + formatter.groupingSeparator = "," + formatter.groupingSize = 3 + return formatter + } + + override public func transformedValue(_ value: Any?) -> Any? { + if let value = value as? NSNumber { + return "\(NumberHertzToStringTransformer.floatFormatter.string(from: value)!) Hz" + } + + return nil + } +}