Minor Audacity interface cleanups
This commit is contained in:
parent
28897500c8
commit
5d5277b028
@ -37,11 +37,6 @@ class AudacityController:
|
|||||||
user_uid = os.getuid() # Get the user's UID
|
user_uid = os.getuid() # Get the user's UID
|
||||||
self.pipe_to = f"/tmp/audacity_script_pipe.to.{user_uid}"
|
self.pipe_to = f"/tmp/audacity_script_pipe.to.{user_uid}"
|
||||||
self.pipe_from = f"/tmp/audacity_script_pipe.from.{user_uid}"
|
self.pipe_from = f"/tmp/audacity_script_pipe.from.{user_uid}"
|
||||||
if not (os.path.exists(self.pipe_to) and os.path.exists(self.pipe_from)):
|
|
||||||
raise ApplicationError(
|
|
||||||
"AudacityController: Audacity pipes not found. Ensure scripting is enabled "
|
|
||||||
f"and pipes exist at {self.pipe_to} and {self.pipe_from}."
|
|
||||||
)
|
|
||||||
elif method == "socket":
|
elif method == "socket":
|
||||||
self.socket_host = socket_host
|
self.socket_host = socket_host
|
||||||
self.socket_port = socket_port
|
self.socket_port = socket_port
|
||||||
@ -54,6 +49,8 @@ class AudacityController:
|
|||||||
else:
|
else:
|
||||||
raise ApplicationError("Invalid method. Use 'pipe' or 'socket'.")
|
raise ApplicationError("Invalid method. Use 'pipe' or 'socket'.")
|
||||||
|
|
||||||
|
self._sanity_check()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""
|
"""
|
||||||
Close the connection (for sockets).
|
Close the connection (for sockets).
|
||||||
@ -66,16 +63,14 @@ class AudacityController:
|
|||||||
Export file from Audacity
|
Export file from Audacity
|
||||||
"""
|
"""
|
||||||
|
|
||||||
log.info("export()")
|
|
||||||
|
|
||||||
self._sanity_check()
|
self._sanity_check()
|
||||||
|
|
||||||
select_status = self._send_command("SelectAll")
|
select_status = self._send_command("SelectAll")
|
||||||
log.info(f"{select_status=}")
|
log.debug(f"{select_status=}")
|
||||||
|
|
||||||
export_cmd = f'Export2: Filename="{self.path}" NumChannels=2'
|
export_cmd = f'Export2: Filename="{self.path}" NumChannels=2'
|
||||||
export_status = self._send_command(export_cmd)
|
export_status = self._send_command(export_cmd)
|
||||||
log.info(f"{export_status=}")
|
log.debug(f"{export_status=}")
|
||||||
self.path = ""
|
self.path = ""
|
||||||
if not export_status.startswith("Exported"):
|
if not export_status.startswith("Exported"):
|
||||||
raise ApplicationError(f"Error writing from Audacity: {export_status=}")
|
raise ApplicationError(f"Error writing from Audacity: {export_status=}")
|
||||||
@ -85,8 +80,6 @@ class AudacityController:
|
|||||||
Open path in Audacity. Escape filename.
|
Open path in Audacity. Escape filename.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
log.info(f"open({path=})")
|
|
||||||
|
|
||||||
self._sanity_check()
|
self._sanity_check()
|
||||||
|
|
||||||
escaped_path = path.replace('"', '\\"')
|
escaped_path = path.replace('"', '\\"')
|
||||||
@ -94,15 +87,13 @@ class AudacityController:
|
|||||||
status = self._send_command(cmd)
|
status = self._send_command(cmd)
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
log.info(f"_open_in_audacity {path=}, {status=}")
|
log.debug(f"_open_in_audacity {path=}, {status=}")
|
||||||
|
|
||||||
def _sanity_check(self) -> None:
|
def _sanity_check(self) -> None:
|
||||||
"""
|
"""
|
||||||
Check Audactity running and basic connectivity.
|
Check Audactity running and basic connectivity.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
log.info("_sanity_check")
|
|
||||||
|
|
||||||
# Check Audacity is running
|
# Check Audacity is running
|
||||||
if "audacity" not in [i.name() for i in psutil.process_iter()]:
|
if "audacity" not in [i.name() for i in psutil.process_iter()]:
|
||||||
log.warning("Audactity not running")
|
log.warning("Audactity not running")
|
||||||
@ -131,7 +122,7 @@ class AudacityController:
|
|||||||
:param command: Command to send (e.g., 'SelectAll').
|
:param command: Command to send (e.g., 'SelectAll').
|
||||||
:return: Response from Audacity.
|
:return: Response from Audacity.
|
||||||
"""
|
"""
|
||||||
log.info(f"_send_command({command=})")
|
log.debug(f"_send_command({command=})")
|
||||||
|
|
||||||
if self.method == "pipe":
|
if self.method == "pipe":
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -434,7 +434,7 @@ class PlaylistTab(QTableView):
|
|||||||
|
|
||||||
# Open/import in/from Audacity
|
# Open/import in/from Audacity
|
||||||
if track_row and not this_is_current_row:
|
if track_row and not this_is_current_row:
|
||||||
if track_path == self.ac.path:
|
if self.ac and track_path == self.ac.path:
|
||||||
# This track was opened in Audacity
|
# This track was opened in Audacity
|
||||||
self._add_context_menu(
|
self._add_context_menu(
|
||||||
"Update from Audacity",
|
"Update from Audacity",
|
||||||
@ -722,6 +722,8 @@ class PlaylistTab(QTableView):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
if not self.ac:
|
||||||
|
self.ac = AudacityController()
|
||||||
self.ac.open(path)
|
self.ac.open(path)
|
||||||
except ApplicationError as e:
|
except ApplicationError as e:
|
||||||
show_warning(self.musicmuster, "Audacity error", str(e))
|
show_warning(self.musicmuster, "Audacity error", str(e))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user