1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-29 00:29:34 +00:00

My improvements:

Use synthesized properties for CSMissingROM.
Remove openGLView from the xib: that will quiet a warning.
Add nullability metadata to CSStaticAnalyser.
This commit is contained in:
C.W. Betts 2020-12-31 13:23:46 -07:00
parent 3d79b11f92
commit 3749b7b776
11 changed files with 36 additions and 81 deletions

View File

@ -1332,7 +1332,6 @@
4B9378E322A199C600973513 /* Audio.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Audio.hpp; sourceTree = "<group>"; };
4B95FA9C1F11893B0008E395 /* ZX8081OptionsPanel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZX8081OptionsPanel.swift; sourceTree = "<group>"; };
4B961408222760E0001A7BF2 /* Screenshot.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Screenshot.hpp; sourceTree = "<group>"; };
4B97ADC722C6FD9B00A22A41 /* 68000ArithmeticTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = 68000ArithmeticTests.mm; path = "/Users/thomasharte/Projects/CLK/OSBindings/Mac/Clock SignalTests/68000ArithmeticTests.mm"; sourceTree = "<absolute>"; };
4B98A05C1FFAD3F600ADF63B /* CSROMFetcher.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = CSROMFetcher.hpp; sourceTree = "<group>"; };
4B98A05D1FFAD3F600ADF63B /* CSROMFetcher.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CSROMFetcher.mm; sourceTree = "<group>"; };
4B98A0601FFADCDE00ADF63B /* MSXStaticAnalyserTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MSXStaticAnalyserTests.mm; sourceTree = "<group>"; };
@ -3442,7 +3441,7 @@
children = (
4B85322922778E4200F26553 /* Comparative68000.hpp */,
4B90467222C6FA31000E2074 /* TestRunner68000.hpp */,
4B97ADC722C6FD9B00A22A41 /* 68000ArithmeticTests.mm */,
4B90467522C6FD6E000E2074 /* 68000ArithmeticTests.mm */,
4B9D0C4A22C7D70900DE1AD3 /* 68000BCDTests.mm */,
4B90467322C6FADD000E2074 /* 68000BitwiseTests.mm */,
4B680CE123A5553100451D43 /* 68000ComparativeTests.mm */,
@ -3485,7 +3484,6 @@
4BFCA12A1ECBE7C400AC40C1 /* ZexallTests.swift */,
4B3BA0C41D318B44005DD7A7 /* Bridges */,
4B1414631B588A1100E04248 /* Test Binaries */,
4B90467522C6FD6E000E2074 /* 68000ArithmeticTests.mm */,
);
path = "Clock SignalTests";
sourceTree = "<group>";

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15705" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16097.2"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15705"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
@ -21,15 +21,15 @@
<windowCollectionBehavior key="collectionBehavior" fullScreenPrimary="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="80" y="250" width="600" height="450"/>
<rect key="screenRect" x="0.0" y="0.0" width="3840" height="2137"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<value key="minSize" type="size" width="228" height="171"/>
<view key="contentView" id="gIp-Ho-8D9">
<rect key="frame" x="0.0" y="0.0" width="600" height="450"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<openGLView hidden="YES" wantsLayer="YES" useAuxiliaryDepthBufferStencil="NO" allowOffline="YES" wantsBestResolutionOpenGLSurface="YES" translatesAutoresizingMaskIntoConstraints="NO" id="DEG-fq-cjd" customClass="CSScanTargetView">
<view hidden="YES" wantsLayer="YES" translatesAutoresizingMaskIntoConstraints="NO" id="DEG-fq-cjd" customClass="CSScanTargetView">
<rect key="frame" x="0.0" y="0.0" width="600" height="450"/>
</openGLView>
</view>
<box hidden="YES" boxType="custom" cornerRadius="4" title="Box" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="4ap-Gi-2AO">
<rect key="frame" x="150" y="20" width="300" height="48"/>
<view key="contentView" id="gwO-Ty-LCX">

View File

@ -13,7 +13,7 @@
@class CSApplication;
@protocol CSApplicationEventDelegate
@protocol CSApplicationEventDelegate <NSObject>
- (BOOL)application:(nonnull CSApplication *)application shouldSendEvent:(nonnull NSEvent *)event;
@end

View File

@ -95,7 +95,7 @@ class MachineDocument:
//
// So: MAKE SURE IT'S SAFE TO ENTER THIS FUNCTION TWICE. Hence the non-assumption here about
// any windows still existing.
if self.windowControllers.count > 0, let window = self.windowControllers[0].window {
if let window = self.windowControllers.first?.window {
for sheet in window.sheets {
window.endSheet(sheet)
}
@ -146,10 +146,7 @@ class MachineDocument:
} else {
// Store the selected machine and list of missing ROMs, and
// show the missing ROMs dialogue.
self.missingROMs = []
for untypedMissingROM in missingROMs {
self.missingROMs.append(untypedMissingROM as! CSMissingROM)
}
self.missingROMs = missingROMs.map({$0 as! CSMissingROM})
requestRoms()
}
@ -252,7 +249,7 @@ class MachineDocument:
// TODO: this needs to be threadsafe. FIX!
let maximumSamplingRate = CSAudioQueue.preferredSamplingRate()
let selectedSamplingRate = Float64(self.machine.idealSamplingRate(from: NSRange(location: 0, length: NSInteger(maximumSamplingRate))))
let isStereo = self.machine.isStereo()
let isStereo = self.machine.isStereo
if selectedSamplingRate > 0 {
// [Re]create the audio queue only if necessary.
if self.audioQueue == nil || self.audioQueue.samplingRate != selectedSamplingRate {
@ -284,9 +281,7 @@ class MachineDocument:
/// Delegate message to receive drag and drop files.
final func scanTargetView(_ view: CSScanTargetView, didReceiveFileAt URL: URL) {
let mediaSet = CSMediaSet(fileAt: URL)
if let mediaSet = mediaSet {
mediaSet.apply(to: self.machine)
}
mediaSet.apply(to: self.machine)
}
/// Action for the insert menu command; displays an NSOpenPanel and then segues into the same process
@ -298,9 +293,7 @@ class MachineDocument:
if response == .OK {
for url in openPanel.urls {
let mediaSet = CSMediaSet(fileAt: url)
if let mediaSet = mediaSet {
mediaSet.apply(to: self.machine)
}
mediaSet.apply(to: self.machine)
}
}
}

View File

@ -14,7 +14,7 @@
#import "CSStaticAnalyser.h"
@class CSMachine;
@protocol CSMachineDelegate
@protocol CSMachineDelegate <NSObject>
- (void)machineSpeakerDidChangeInputClock:(nonnull CSMachine *)machine;
- (void)machine:(nonnull CSMachine *)machine led:(nonnull NSString *)led didChangeToLit:(BOOL)isLit;
- (void)machine:(nonnull CSMachine *)machine ledShouldBlink:(nonnull NSString *)led;
@ -59,7 +59,7 @@ typedef NS_ENUM(NSInteger, CSMachineKeyboardInputMode) {
- (nullable instancetype)initWithAnalyser:(nonnull CSStaticAnalyser *)result missingROMs:(nullable inout NSMutableArray<CSMissingROM *> *)missingROMs NS_DESIGNATED_INITIALIZER;
- (float)idealSamplingRateFromRange:(NSRange)range;
- (BOOL)isStereo;
@property (readonly, getter=isStereo) BOOL stereo;
- (void)setAudioSamplingRate:(float)samplingRate bufferSize:(NSUInteger)bufferSize stereo:(BOOL)stereo;
- (void)setView:(nullable CSScanTargetView *)view aspectRatio:(float)aspectRatio;

View File

@ -74,7 +74,7 @@ struct ActivityObserver: public Activity::Observer {
__unsafe_unretained CSMachine *machine;
};
@interface CSMissingROM (Mutability)
@interface CSMissingROM (/*Mutability*/)
@property (nonatomic, nonnull, copy) NSString *machineName;
@property (nonatomic, nonnull, copy) NSString *fileName;
@property (nonatomic, nullable, copy) NSString *descriptiveName;
@ -82,53 +82,13 @@ struct ActivityObserver: public Activity::Observer {
@property (nonatomic, copy) NSArray<NSNumber *> *crc32s;
@end
@implementation CSMissingROM {
NSString *_machineName;
NSString *_fileName;
NSString *_descriptiveName;
NSUInteger _size;
NSArray<NSNumber *> *_crc32s;
}
@implementation CSMissingROM
- (NSString *)machineName {
return _machineName;
}
- (void)setMachineName:(NSString *)machineName {
_machineName = [machineName copy];
}
- (NSString *)fileName {
return _fileName;
}
- (void)setFileName:(NSString *)fileName {
_fileName = [fileName copy];
}
- (NSString *)descriptiveName {
return _descriptiveName;
}
- (void)setDescriptiveName:(NSString *)descriptiveName {
_descriptiveName = [descriptiveName copy];
}
- (NSUInteger)size {
return _size;
}
- (void)setSize:(NSUInteger)size {
_size = size;
}
- (NSArray<NSNumber *> *)crc32s {
return _crc32s;
}
- (void)setCrc32s:(NSArray<NSNumber *> *)crc32s {
_crc32s = [crc32s copy];
}
@synthesize machineName=_machineName;
@synthesize fileName=_fileName;
@synthesize descriptiveName=_descriptiveName;
@synthesize size=_size;
@synthesize crc32s=_crc32s;
- (NSString *)description {
return [NSString stringWithFormat:@"%@/%@, %lu bytes, CRCs: %@", _fileName, _descriptiveName, (unsigned long)_size, _crc32s];
@ -179,17 +139,17 @@ struct ActivityObserver: public Activity::Observer {
CSMissingROM *rom = [[CSMissingROM alloc] init];
// Copy/convert the primitive fields.
rom.machineName = [NSString stringWithUTF8String:missing_rom.machine_name.c_str()];
rom.fileName = [NSString stringWithUTF8String:missing_rom.file_name.c_str()];
rom.descriptiveName = missing_rom.descriptive_name.empty() ? nil : [NSString stringWithUTF8String:missing_rom.descriptive_name.c_str()];
rom.machineName = @(missing_rom.machine_name.c_str());
rom.fileName = @(missing_rom.file_name.c_str());
rom.descriptiveName = missing_rom.descriptive_name.empty() ? nil : @(missing_rom.descriptive_name.c_str());
rom.size = missing_rom.size;
// Convert the CRC list.
NSMutableArray<NSNumber *> *crc32s = [[NSMutableArray alloc] init];
NSMutableArray<NSNumber *> *crc32s = [[NSMutableArray alloc] initWithCapacity:missing_rom.crc32s.size()];
for(const auto &crc : missing_rom.crc32s) {
[crc32s addObject:@(crc)];
}
rom.crc32s = [crc32s copy];
rom.crc32s = crc32s;
// Add to the missing list.
[missingROMs addObject:rom];

View File

@ -8,7 +8,7 @@
#import "CSStaticAnalyser.h"
@interface CSStaticAnalyser (ResultVector)
@interface CSStaticAnalyser ()
- (Analyser::Static::TargetList &)targets;

View File

@ -8,6 +8,8 @@
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class CSMachine;
typedef NS_ENUM(NSInteger, CSMachineAppleIIModel) {
@ -72,7 +74,7 @@ typedef int Kilobytes;
@interface CSStaticAnalyser : NSObject
- (instancetype)initWithFileAtURL:(NSURL *)url;
- (nullable instancetype)initWithFileAtURL:(NSURL *)url;
- (instancetype)initWithElectronDFS:(BOOL)dfs adfs:(BOOL)adfs;
- (instancetype)initWithAmstradCPCModel:(CSMachineCPCModel)model;
@ -85,7 +87,7 @@ typedef int Kilobytes;
- (instancetype)initWithMacintoshModel:(CSMachineMacintoshModel)model;
- (instancetype)initWithAtariSTModel:(CSMachineAtariSTModel)model;
@property(nonatomic, readonly) NSString *optionsPanelNibName;
@property(nonatomic, readonly, nullable) NSString *optionsPanelNibName;
@property(nonatomic, readonly) NSString *displayName;
@end
@ -96,3 +98,5 @@ typedef int Kilobytes;
- (void)applyToMachine:(CSMachine *)machine;
@end
NS_ASSUME_NONNULL_END

View File

@ -39,7 +39,7 @@
// TODO: could this better be supplied by the analyser? A hypothetical file format might
// provide a better name for it contents than the file name?
_displayName = [[url pathComponents] lastObject];
_displayName = [url.lastPathComponent copy];
}
return self;
}

View File

@ -140,7 +140,7 @@ class MachinePicker: NSObject {
switch machineSelector!.selectedTabViewItem!.identifier as! String {
case "electron":
return CSStaticAnalyser(electronDFS: electronDFSButton!.state == .on, adfs: electronADFSButton!.state == .on)!
return CSStaticAnalyser(electronDFS: electronDFSButton!.state == .on, adfs: electronADFSButton!.state == .on)
case "appleii":
var model: CSMachineAppleIIModel = .appleII

View File

@ -10,7 +10,7 @@
@class CSROMReceiverView;
@protocol CSROMReciverViewDelegate
@protocol CSROMReciverViewDelegate <NSObject>
/*!
Announces receipt of a file by drag and drop to the delegate.
@param view The view making the request.