Update bell

- Don't add the bell to the archive to keep it small a simplify
  licensing. Also bells seem to be rarely used with terminal emulators.
- Don't play the bell directly from the Terminal node by adding an
  AudioStreamPlayer, but make it easy to tune the "bell" signal behavior
  from the Terminal node so that only an AudioStreamPlayer node's play()
  method needs to be connected to it.
- Keep the bell.wav sound around for testing/demo.
This commit is contained in:
Leroy Hopson 2021-07-21 22:58:20 +07:00
parent d702021d02
commit 55b0a0577d
No known key found for this signature in database
GPG key ID: D2747312A6DB51AA
8 changed files with 42 additions and 30 deletions

View file

@ -24,4 +24,7 @@ env = {
"TERM": "xterm-256color" "TERM": "xterm-256color"
} }
[node name="Bell" type="AudioStreamPlayer" parent="."]
[connection signal="bell" from="." to="Bell" method="play"]
[connection signal="exited" from="PTY" to="." method="_on_PTY_exited"] [connection signal="exited" from="PTY" to="." method="_on_PTY_exited"]

View file

@ -41,7 +41,7 @@ export var ctrl_scroll_to_resize_font := true
# Bell settings. # Bell settings.
export var visual_bell := true export var visual_bell := true
export var audio_bell := true export var audio_bell := true
export var bell_sound: AudioStream = preload("../../../themes/audio/bell.wav") export var bell_sound: AudioStream
# Exec args. # Exec args.
export (FileType) var file_type := FileType.USE_SHELL_ENV export (FileType) var file_type := FileType.USE_SHELL_ENV

View file

@ -35,14 +35,16 @@ var rows = 2
export (bool) var copy_on_selection export (bool) var copy_on_selection
# Bell # Bell
# If enabled, bell_sound will play when the ASCII BELL "\u0007" character is printed. # If muted, the "bell" signal will not be emitted when the bell "\u0007" character
export var bell_enabled := true # is written to the terminal.
export var bell_sound: AudioStream export var bell_muted := false
# Number of milliseconds that must pass before emitting a new bell sound. # Amount of time in seconds that must pass before emitting a new "bell" signal.
# This important in cases where the bell character is being printed frequently # This can be useful in cases where the bell character is being written too
# such as `while true; do echo -e "\a"; done`, as adding additional AudioStreamPlayer # frequently such as `while true; do echo -e "\a"; done`.
# nodes too frequently has a negative performance impact. export var bell_cooldown: float = 0.1
export var bell_cooldown_msec: int = 100
export var blink_on_time: float = 0.6
export var blink_off_time: float = 0.3
var _viewport: Viewport = preload("./viewport.tscn").instance() var _viewport: Viewport = preload("./viewport.tscn").instance()
var _native_terminal: Control = _viewport.get_node("Terminal") var _native_terminal: Control = _viewport.get_node("Terminal")
@ -229,20 +231,10 @@ func _on_size_changed(new_size: Vector2):
func _on_bell(): func _on_bell():
if bell_enabled and bell_sound and _bell_timer.time_left == 0: if not bell_muted and (bell_cooldown == 0 or _bell_timer.time_left == 0):
var player := AudioStreamPlayer.new() emit_signal("bell")
player.stream = bell_sound if bell_cooldown > 0:
player.autoplay = true _bell_timer.start(bell_cooldown)
player.playing = true
player.connect("finished", self, "_on_player_finished", [player])
add_child(player)
_bell_timer.start(0.001 * bell_cooldown_msec)
emit_signal("bell")
func _on_player_finished(player: AudioStreamPlayer):
player.queue_free()
func _mouse_to_cell(pos: Vector2) -> Vector2: func _mouse_to_cell(pos: Vector2) -> Vector2:

View file

@ -1,8 +1,7 @@
[gd_scene load_steps=4 format=2] [gd_scene load_steps=3 format=2]
[ext_resource path="res://addons/godot_xterm/nodes/terminal/terminal.gd" type="Script" id=1] [ext_resource path="res://addons/godot_xterm/nodes/terminal/terminal.gd" type="Script" id=1]
[ext_resource path="res://examples/menu/menu.gd" type="Script" id=2] [ext_resource path="res://examples/menu/menu.gd" type="Script" id=2]
[ext_resource path="res://addons/godot_xterm/themes/audio/bell.wav" type="AudioStream" id=3]
[node name="Menu" type="Control"] [node name="Menu" type="Control"]
anchor_right = 1.0 anchor_right = 1.0
@ -21,6 +20,5 @@ script = ExtResource( 1 )
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
bell_sound = ExtResource( 3 )
[connection signal="key_pressed" from="Terminal" to="." method="_on_Terminal_key_pressed"] [connection signal="key_pressed" from="Terminal" to="." method="_on_Terminal_key_pressed"]

View file

@ -1,5 +1,6 @@
[gd_scene load_steps=3 format=2] [gd_scene load_steps=4 format=2]
[ext_resource path="res://themes/audio/bell.wav" type="AudioStream" id=1]
[ext_resource path="res://addons/godot_xterm/nodes/pty/unix/pty_unix.gd" type="Script" id=2] [ext_resource path="res://addons/godot_xterm/nodes/pty/unix/pty_unix.gd" type="Script" id=2]
[ext_resource path="res://examples/terminal/terminal.gd" type="Script" id=3] [ext_resource path="res://examples/terminal/terminal.gd" type="Script" id=3]
@ -12,6 +13,7 @@ __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }
copy_on_selection = true copy_on_selection = true
bell_cooldown = 0.1
[node name="PTY" type="Node" parent="."] [node name="PTY" type="Node" parent="."]
script = ExtResource( 2 ) script = ExtResource( 2 )
@ -20,3 +22,8 @@ env = {
"COLORTERM": "truecolor", "COLORTERM": "truecolor",
"TERM": "xterm-256color" "TERM": "xterm-256color"
} }
[node name="Bell" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 1 )
[connection signal="bell" from="." to="Bell" method="play"]

View file

@ -10,6 +10,7 @@ func before_each():
func test_bell() -> void: func test_bell() -> void:
term.bell_cooldown = 0
term.write(char(7)) term.write(char(7))
term.write(char(0x07)) term.write(char(0x07))
term.write("\a") term.write("\a")
@ -17,3 +18,14 @@ func test_bell() -> void:
term.write("'Ask not for whom the \a tolls; it tolls for thee' - John Donne") term.write("'Ask not for whom the \a tolls; it tolls for thee' - John Donne")
yield(yield_to(term, "bell", 1), YIELD) yield(yield_to(term, "bell", 1), YIELD)
assert_signal_emit_count(term, "bell", 5) assert_signal_emit_count(term, "bell", 5)
func test_bell_cooldown() -> void:
watch_signals(term)
term.bell_cooldown = 0.5
term.write("\a")
term.write("\a")
yield(yield_for(0.5), YIELD)
term.write("\a")
yield(yield_to(term, "bell", 1), YIELD)
assert_signal_emit_count(term, "bell", 2)

View file

@ -2,12 +2,12 @@
importer="wav" importer="wav"
type="AudioStreamSample" type="AudioStreamSample"
path="res://.import/bell.wav-54a2dcec0c35ce7bf9aa23071616df00.sample" path="res://.import/bell.wav-0bb68f27c3e29a9aad676dc03d89b163.sample"
[deps] [deps]
source_file="res://addons/godot_xterm/themes/audio/bell.wav" source_file="res://themes/audio/bell.wav"
dest_files=[ "res://.import/bell.wav-54a2dcec0c35ce7bf9aa23071616df00.sample" ] dest_files=[ "res://.import/bell.wav-0bb68f27c3e29a9aad676dc03d89b163.sample" ]
[params] [params]