clsSFX // Use AVFoundation in lieu of NSSound.
This commit is contained in:
parent
7bf58ed61f
commit
455495c2fc
2
AUTHORS
2
AUTHORS
|
@ -2,7 +2,7 @@ $ Main contributors and volunteers of this repository (vChewing for macOS):
|
|||
|
||||
- Shiki Suen // Main developer of vChewing for macOS, Megrez language engine, and Tekkon syllable composer engine.
|
||||
- Hiraku Wang // Technical reinforcement in Cocoa during the Object-Cpp dev period of this project.
|
||||
- Isaac Xen // Technical reinforcement in Swift: SFX Module and StringView Ranges Extension.
|
||||
- Isaac Xen // Technical reinforcement in Swift: SFX Module (NSSound ver.) and StringView Ranges Extension.
|
||||
|
||||
$ Contributors and volunteeres of the upstream repo, having no responsibility in discussing anything in the current repo:
|
||||
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
// Copyright (c) 2022 and onwards Isaac Xen (MIT License).
|
||||
// All possible vChewing-specific modifications are of:
|
||||
// (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
||||
// Copyright (c) 2021 and onwards The vChewing Project (MIT-NTL License).
|
||||
/*
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
|
@ -24,52 +22,15 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import Cocoa
|
||||
|
||||
public class clsSFX: NSObject, NSSoundDelegate {
|
||||
private static let shared = clsSFX()
|
||||
override private init() {
|
||||
super.init()
|
||||
}
|
||||
|
||||
private var currentBeep: NSSound?
|
||||
private func beep() {
|
||||
let defaultVolume: Float = 0.4
|
||||
// Stop existing beep
|
||||
if let beep = currentBeep {
|
||||
if beep.isPlaying {
|
||||
for i in 1..<30 {
|
||||
beep.volume = (defaultVolume / Float(i))
|
||||
usleep(1000)
|
||||
}
|
||||
beep.stop()
|
||||
beep.volume = defaultVolume
|
||||
}
|
||||
}
|
||||
// Create a new beep sound if possible
|
||||
var sndBeep: String
|
||||
if mgrPrefs.shouldNotFartInLieuOfBeep == false {
|
||||
sndBeep = "Fart"
|
||||
} else {
|
||||
sndBeep = "Beep"
|
||||
}
|
||||
guard
|
||||
let beep = NSSound(named: sndBeep)
|
||||
else {
|
||||
NSSound.beep()
|
||||
return
|
||||
}
|
||||
beep.delegate = self
|
||||
beep.volume = defaultVolume
|
||||
beep.play()
|
||||
currentBeep = beep
|
||||
}
|
||||
|
||||
public func sound(_: NSSound, didFinishPlaying _: Bool) {
|
||||
currentBeep = nil
|
||||
}
|
||||
import AVFoundation
|
||||
import Foundation
|
||||
|
||||
public class clsSFX {
|
||||
static func beep() {
|
||||
shared.beep()
|
||||
let filePath = Bundle.main.path(forResource: mgrPrefs.shouldNotFartInLieuOfBeep ? "Beep" : "Fart", ofType: "m4a")!
|
||||
let fileURL = URL(fileURLWithPath: filePath)
|
||||
var soundID: SystemSoundID = 0
|
||||
AudioServicesCreateSystemSoundID(fileURL as CFURL, &soundID)
|
||||
AudioServicesPlaySystemSound(soundID)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue