mirror of
https://github.com/TomHarte/CLK.git
synced 2025-02-08 11:32:02 +00:00
Merge pull request #775 from TomHarte/SavedVolume
Ensures the macOS version retains volume.
This commit is contained in:
commit
d1d14ba9a0
@ -9,6 +9,7 @@
|
|||||||
<customObject id="-2" userLabel="File's Owner" customClass="MachineDocument" customModule="Clock_Signal" customModuleProvider="target">
|
<customObject id="-2" userLabel="File's Owner" customClass="MachineDocument" customModule="Clock_Signal" customModuleProvider="target">
|
||||||
<connections>
|
<connections>
|
||||||
<outlet property="openGLView" destination="DEG-fq-cjd" id="Gxs-2u-n7B"/>
|
<outlet property="openGLView" destination="DEG-fq-cjd" id="Gxs-2u-n7B"/>
|
||||||
|
<outlet property="volumeSlider" destination="zaz-lB-Iyt" id="flY-Th-oG4"/>
|
||||||
<outlet property="volumeView" destination="4ap-Gi-2AO" id="v4e-k6-Fqf"/>
|
<outlet property="volumeView" destination="4ap-Gi-2AO" id="v4e-k6-Fqf"/>
|
||||||
<outlet property="window" destination="xOd-HO-29H" id="JIz-fz-R2o"/>
|
<outlet property="window" destination="xOd-HO-29H" id="JIz-fz-R2o"/>
|
||||||
</connections>
|
</connections>
|
||||||
|
@ -64,7 +64,8 @@ class MachineDocument:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The volume view.
|
/// The volume view.
|
||||||
@IBOutlet var volumeView: NSView!
|
@IBOutlet var volumeView: NSBox!
|
||||||
|
@IBOutlet var volumeSlider: NSSlider!
|
||||||
|
|
||||||
// MARK: - NSDocument Overrides and NSWindowDelegate methods.
|
// MARK: - NSDocument Overrides and NSWindowDelegate methods.
|
||||||
|
|
||||||
@ -114,6 +115,7 @@ class MachineDocument:
|
|||||||
override func windowControllerDidLoadNib(_ aController: NSWindowController) {
|
override func windowControllerDidLoadNib(_ aController: NSWindowController) {
|
||||||
super.windowControllerDidLoadNib(aController)
|
super.windowControllerDidLoadNib(aController)
|
||||||
aController.window?.contentAspectRatio = self.aspectRatio()
|
aController.window?.contentAspectRatio = self.aspectRatio()
|
||||||
|
volumeSlider.floatValue = userDefaultsVolume()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var missingROMs: [CSMissingROM] = []
|
private var missingROMs: [CSMissingROM] = []
|
||||||
@ -125,6 +127,7 @@ class MachineDocument:
|
|||||||
self.machine = machine
|
self.machine = machine
|
||||||
setupMachineOutput()
|
setupMachineOutput()
|
||||||
setupActivityDisplay()
|
setupActivityDisplay()
|
||||||
|
machine.setVolume(userDefaultsVolume())
|
||||||
} else {
|
} else {
|
||||||
// Store the selected machine and list of missing ROMs, and
|
// Store the selected machine and list of missing ROMs, and
|
||||||
// show the missing ROMs dialogue.
|
// show the missing ROMs dialogue.
|
||||||
@ -720,7 +723,8 @@ class MachineDocument:
|
|||||||
// MARK: - Volume Control.
|
// MARK: - Volume Control.
|
||||||
@IBAction func setVolume(_ sender: NSSlider!) {
|
@IBAction func setVolume(_ sender: NSSlider!) {
|
||||||
if let machine = self.machine {
|
if let machine = self.machine {
|
||||||
machine.setVolume(sender.floatValue);
|
machine.setVolume(sender.floatValue)
|
||||||
|
setUserDefaultsVolume(sender.floatValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -767,4 +771,14 @@ class MachineDocument:
|
|||||||
volumeView.layer?.opacity = 0.0
|
volumeView.layer?.opacity = 0.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The user's selected volume is stored as 1 - volume in the user defaults in order
|
||||||
|
// to take advantage of the default value being 0.
|
||||||
|
private func userDefaultsVolume() -> Float {
|
||||||
|
return 1.0 - UserDefaults.standard.float(forKey: "defaultVolume")
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setUserDefaultsVolume(_ volume: Float) {
|
||||||
|
UserDefaults.standard.set(1.0 - volume, forKey: "defaultVolume")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user