mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 11:48:02 -04:00
Add async option to beep function for non-blocking audio feedback to fix #3789
This commit is contained in:
parent
7d9eac5584
commit
eeef7a062a
@ -443,7 +443,7 @@ class Machine(val host: MachineHost) extends AbstractManagedEnvironment with mac
|
|||||||
def isRunning(context: Context, args: Arguments): Array[AnyRef] =
|
def isRunning(context: Context, args: Arguments): Array[AnyRef] =
|
||||||
result(isRunning)
|
result(isRunning)
|
||||||
|
|
||||||
@Callback(doc = """function([frequency:string or number[, duration:number]]) -- Plays a tone, useful to alert users via audible feedback.""")
|
@Callback(doc = """function([frequency:string or number[, duration:number[, async:boolean]]]) -- Plays a tone, useful to alert users via audible feedback.""")
|
||||||
def beep(context: Context, args: Arguments): Array[AnyRef] = {
|
def beep(context: Context, args: Arguments): Array[AnyRef] = {
|
||||||
if (args.count == 1 && args.isString(0)) {
|
if (args.count == 1 && args.isString(0)) {
|
||||||
beep(args.checkString(0))
|
beep(args.checkString(0))
|
||||||
@ -454,7 +454,10 @@ class Machine(val host: MachineHost) extends AbstractManagedEnvironment with mac
|
|||||||
}
|
}
|
||||||
val duration = args.optDouble(1, 0.1)
|
val duration = args.optDouble(1, 0.1)
|
||||||
val durationInMilliseconds = math.max(50, math.min(5000, (duration * 1000).toInt))
|
val durationInMilliseconds = math.max(50, math.min(5000, (duration * 1000).toInt))
|
||||||
context.pause(durationInMilliseconds / 1000.0)
|
val async = args.optBoolean(2, false)
|
||||||
|
if (!async) {
|
||||||
|
context.pause(durationInMilliseconds / 1000.0)
|
||||||
|
}
|
||||||
beep(frequency.toShort, durationInMilliseconds.toShort)
|
beep(frequency.toShort, durationInMilliseconds.toShort)
|
||||||
}
|
}
|
||||||
null
|
null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user