Multiple fixes to indentation beep code, including volume for lower ranged beeps using the gstreamer driver.

This commit is contained in:
Storm Dragon
2025-08-04 12:38:14 -04:00
parent 9ef9d762f4
commit 73f67c2a04
4 changed files with 55 additions and 34 deletions

View File

@ -60,9 +60,10 @@ class command:
if self.env["runtime"]["SettingsManager"].get_setting_as_int( if self.env["runtime"]["SettingsManager"].get_setting_as_int(
"general", "autoPresentIndentMode" "general", "autoPresentIndentMode"
) in [0, 1]: ) in [0, 1]:
self.env["runtime"]["OutputManager"].play_frequence( if self.lastIdent != curr_ident:
curr_ident * 50, 0.1, interrupt=do_interrupt self.env["runtime"]["OutputManager"].play_frequence(
) curr_ident * 50, 0.1, interrupt=do_interrupt
)
if self.env["runtime"]["SettingsManager"].get_setting_as_int( if self.env["runtime"]["SettingsManager"].get_setting_as_int(
"general", "autoPresentIndentMode" "general", "autoPresentIndentMode"
) in [0, 2]: ) in [0, 2]:

View File

@ -31,10 +31,9 @@ class command:
self.lastIdent = 0 self.lastIdent = 0
return return
# is a vertical change? # Skip if no cursor movement at all
if not self.env["runtime"][ if (not self.env["runtime"]["CursorManager"].is_cursor_horizontal_move() and
"CursorManager" not self.env["runtime"]["CursorManager"].is_cursor_vertical_move()):
].is_cursor_horizontal_move():
return return
x, y, curr_line = line_utils.get_current_line( x, y, curr_line = line_utils.get_current_line(
self.env["screen"]["new_cursor"]["x"], self.env["screen"]["new_cursor"]["x"],
@ -43,27 +42,34 @@ class command:
) )
curr_ident = self.env["screen"]["new_cursor"]["x"] curr_ident = self.env["screen"]["new_cursor"]["x"]
if not curr_line.isspace(): if curr_line.isspace():
# ident # Don't beep for lines with only spaces - no meaningful indentation
lastIdent, lastY, last_line = line_utils.get_current_line( return
self.env["screen"]["new_cursor"]["x"],
self.env["screen"]["new_cursor"]["y"],
self.env["screen"]["old_content_text"],
)
if curr_line.strip() != last_line.strip():
return
if len(curr_line.lstrip()) == len(last_line.lstrip()):
return
curr_ident = len(curr_line) - len(curr_line.lstrip()) # Lines with actual content - calculate proper indentation
lastIdent, lastY, last_line = line_utils.get_current_line(
self.env["screen"]["new_cursor"]["x"],
self.env["screen"]["new_cursor"]["y"],
self.env["screen"]["old_content_text"],
)
if curr_line.strip() != last_line.strip():
return
if len(curr_line.lstrip()) == len(last_line.lstrip()):
return
if self.lastIdent == -1: curr_ident = len(curr_line) - len(curr_line.lstrip())
self.lastIdent = curr_ident
if curr_ident <= 0: if curr_ident <= 0:
return return
# Initialize lastIdent if needed
if self.lastIdent == -1:
self.lastIdent = curr_ident
# Only beep/announce if indentation level has changed
if self.env["runtime"]["SettingsManager"].get_setting_as_bool( if self.env["runtime"]["SettingsManager"].get_setting_as_bool(
"general", "autoPresentIndent" "general", "autoPresentIndent"
): ) and self.lastIdent != curr_ident:
if self.env["runtime"]["SettingsManager"].get_setting_as_int( if self.env["runtime"]["SettingsManager"].get_setting_as_int(
"general", "autoPresentIndentMode" "general", "autoPresentIndentMode"
) in [0, 1]: ) in [0, 1]:
@ -71,14 +77,15 @@ class command:
curr_ident * 50, 0.1, interrupt=False curr_ident * 50, 0.1, interrupt=False
) )
if self.env["runtime"]["SettingsManager"].get_setting_as_int( if self.env["runtime"]["SettingsManager"].get_setting_as_int(
"general", "autoPresentIndentMode" "general", "autePresentIndentMode"
) in [0, 2]: ) in [0, 2]:
if self.lastIdent != curr_ident: self.env["runtime"]["OutputManager"].present_text(
self.env["runtime"]["OutputManager"].present_text( _("indented ") + str(curr_ident) + " ",
_("indented ") + str(curr_ident) + " ", interrupt=False,
interrupt=False, flush=False,
flush=False, )
)
# Always update lastIdent for next comparison
self.lastIdent = curr_ident self.lastIdent = curr_ident
def set_callback(self, callback): def set_callback(self, callback):

View File

@ -4,6 +4,6 @@
# Fenrir TTY screen reader # Fenrir TTY screen reader
# By Chrys, Storm Dragon, and contributors. # By Chrys, Storm Dragon, and contributors.
version = "2025.07.31" version = "2025.08.04"
codeName = "testing" codeName = "testing"
code_name = "testing" code_name = "testing"

View File

@ -52,10 +52,13 @@ class driver(sound_driver):
bus.connect("message", self._on_pipeline_message) bus.connect("message", self._on_pipeline_message)
self._source = Gst.ElementFactory.make("audiotestsrc", "src") self._source = Gst.ElementFactory.make("audiotestsrc", "src")
self._volume = Gst.ElementFactory.make("volume", "volume")
self._sink = Gst.ElementFactory.make("autoaudiosink", "output") self._sink = Gst.ElementFactory.make("autoaudiosink", "output")
self._pipeline.add(self._source) self._pipeline.add(self._source)
self._pipeline.add(self._volume)
self._pipeline.add(self._sink) self._pipeline.add(self._sink)
self._source.link(self._sink) self._source.link(self._volume)
self._volume.link(self._sink)
self.mainloop = GLib.MainLoop() self.mainloop = GLib.MainLoop()
self.thread = threading.Thread(target=self.mainloop.run) self.thread = threading.Thread(target=self.mainloop.run)
self.thread.start() self.thread.start()
@ -117,8 +120,18 @@ class driver(sound_driver):
return return
if interrupt: if interrupt:
self.cancel() self.cancel()
# Always reset pipeline to prevent volume accumulation
self._pipeline.set_state(Gst.State.NULL)
duration = duration * 1000 duration = duration * 1000
self._source.set_property("volume", self.volume * adjust_volume) # Use dedicated volume element for better control
# GStreamer volume property behaves very differently than sox for low frequencies
if adjust_volume > 0.8: # This indicates low frequency indentation beeps
# Extremely aggressive boost - GStreamer really struggles with low frequencies
effective_volume = self.volume * adjust_volume * 50.0 # Ridiculous multiplier to match sox
else:
effective_volume = self.volume * adjust_volume * 3.0
self._volume.set_property("volume", effective_volume)
self._source.set_property("volume", 1.0) # Set source to full, control via volume element
self._source.set_property("freq", frequence) self._source.set_property("freq", frequence)
self._pipeline.set_state(Gst.State.PLAYING) self._pipeline.set_state(Gst.State.PLAYING)
GLib.timeout_add(duration, self._on_timeout, self._pipeline) GLib.timeout_add(duration, self._on_timeout, self._pipeline)