Remotely open and save files in Audacity
This commit is contained in:
parent
540846223b
commit
83a817234d
@ -27,7 +27,7 @@ class AudacityManager:
|
|||||||
Manage comms with Audacity
|
Manage comms with Audacity
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, path: str) -> None:
|
def __init__(self) -> None:
|
||||||
"""
|
"""
|
||||||
Open passed file in Audacity
|
Open passed file in Audacity
|
||||||
|
|
||||||
@ -37,15 +37,34 @@ class AudacityManager:
|
|||||||
self.to_pipe: str = "/tmp/audacity_script_pipe.to." + str(os.getuid())
|
self.to_pipe: str = "/tmp/audacity_script_pipe.to." + str(os.getuid())
|
||||||
self.from_pipe: str = "/tmp/audacity_script_pipe.from." + str(os.getuid())
|
self.from_pipe: str = "/tmp/audacity_script_pipe.from." + str(os.getuid())
|
||||||
self.eol: str = "\n"
|
self.eol: str = "\n"
|
||||||
self.path = path
|
self.path = None
|
||||||
self.do_command(f'Import2: Filename="{self.path}"')
|
|
||||||
|
|
||||||
def send_command(self, command: str) -> None:
|
def open_file(self, path):
|
||||||
|
"""Open passed file in Audacity"""
|
||||||
|
|
||||||
|
self.path = path
|
||||||
|
response = self._do_command(f'Import2: Filename="{self.path}"')
|
||||||
|
return response
|
||||||
|
|
||||||
|
def export_file(self):
|
||||||
|
"""Export current file"""
|
||||||
|
|
||||||
|
if not self.path:
|
||||||
|
return
|
||||||
|
|
||||||
|
sa_response = self._do_command("SelectAll:")
|
||||||
|
if sa_response == '\nBatchCommand finished: OK\n':
|
||||||
|
exp_response = self._do_command(f'Export2: Filename="{self.path}" NumChannels=2')
|
||||||
|
return exp_response
|
||||||
|
else:
|
||||||
|
print("SelectAll response: " + sa_response)
|
||||||
|
|
||||||
|
def _send_command(self, command: str) -> None:
|
||||||
"""Send a single command."""
|
"""Send a single command."""
|
||||||
self.to_audacity.write(command + self.eol)
|
self.to_audacity.write(command + self.eol)
|
||||||
self.to_audacity.flush()
|
self.to_audacity.flush()
|
||||||
|
|
||||||
def get_response(self) -> str:
|
def _get_response(self) -> str:
|
||||||
"""Return the command response."""
|
"""Return the command response."""
|
||||||
|
|
||||||
result: str = ""
|
result: str = ""
|
||||||
@ -58,14 +77,14 @@ class AudacityManager:
|
|||||||
break
|
break
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def do_command(self, command: str) -> str:
|
def _do_command(self, command: str) -> str:
|
||||||
"""Send one command, and return the response."""
|
"""Send one command, and return the response."""
|
||||||
|
|
||||||
with open(self.to_pipe, "w") as self.to_audacity, open(
|
with open(self.to_pipe, "w") as self.to_audacity, open(
|
||||||
self.from_pipe, "rt"
|
self.from_pipe, "rt"
|
||||||
) as self.from_audacity:
|
) as self.from_audacity:
|
||||||
self.send_command(command)
|
self._send_command(command)
|
||||||
response = self.get_response()
|
response = self._get_response()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,6 @@ from helpers import (
|
|||||||
file_is_unreadable,
|
file_is_unreadable,
|
||||||
get_embedded_time,
|
get_embedded_time,
|
||||||
get_relative_date,
|
get_relative_date,
|
||||||
open_in_audacity,
|
|
||||||
ms_to_mmss,
|
ms_to_mmss,
|
||||||
set_track_metadata,
|
set_track_metadata,
|
||||||
)
|
)
|
||||||
@ -1518,9 +1517,6 @@ class PlaylistProxyModel(QSortFilterProxyModel):
|
|||||||
header_row_number, existing_prd, note
|
header_row_number, existing_prd, note
|
||||||
)
|
)
|
||||||
|
|
||||||
def open_in_audacity(self, row_number: int) -> None:
|
|
||||||
return self.data_model.open_in_audacity(row_number)
|
|
||||||
|
|
||||||
def previous_track_ended(self) -> None:
|
def previous_track_ended(self) -> None:
|
||||||
return self.data_model.previous_track_ended()
|
return self.data_model.previous_track_ended()
|
||||||
|
|
||||||
|
|||||||
@ -34,8 +34,8 @@ from classes import MusicMusterSignals, track_sequence
|
|||||||
from config import Config
|
from config import Config
|
||||||
from helpers import (
|
from helpers import (
|
||||||
ask_yes_no,
|
ask_yes_no,
|
||||||
|
AudacityManager,
|
||||||
ms_to_mmss,
|
ms_to_mmss,
|
||||||
open_file_in_audacity,
|
|
||||||
show_OK,
|
show_OK,
|
||||||
show_warning,
|
show_warning,
|
||||||
)
|
)
|
||||||
@ -569,13 +569,10 @@ class PlaylistTab(QTableView):
|
|||||||
if not path:
|
if not path:
|
||||||
return
|
return
|
||||||
|
|
||||||
open_file_in_audacity(path)
|
audacity = AudacityManager()
|
||||||
|
audacity.open_file(path)
|
||||||
if ask_yes_no("Reimport file", "Click yes to reimport file, No to ignore"):
|
if ask_yes_no("Export file", "Click yes to export file, no to ignore"):
|
||||||
|
audacity.export_file()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _rescan(self, row_number: int) -> None:
|
def _rescan(self, row_number: int) -> None:
|
||||||
"""Rescan track"""
|
"""Rescan track"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user