parent
70d986f4ac
commit
c5f094443a
@ -1,3 +1,6 @@
|
|||||||
|
import os
|
||||||
|
import psutil
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from PyQt5.QtWidgets import QMessageBox
|
from PyQt5.QtWidgets import QMessageBox
|
||||||
|
|
||||||
@ -37,6 +40,48 @@ def get_relative_date(past_date, reference_date=None):
|
|||||||
return f"{weeks} {weeks_str}, {days} {days_str} ago"
|
return f"{weeks} {weeks_str}, {days} {days_str} ago"
|
||||||
|
|
||||||
|
|
||||||
|
def open_in_audacity(path):
|
||||||
|
"""
|
||||||
|
Open passed file in Audacity
|
||||||
|
|
||||||
|
Return True if apparently opened successfully, else False
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Return if audacity not running
|
||||||
|
if "audacity" not in [i.name() for i in psutil.process_iter()]:
|
||||||
|
return False
|
||||||
|
|
||||||
|
to_pipe = '/tmp/audacity_script_pipe.to.' + str(os.getuid())
|
||||||
|
from_pipe = '/tmp/audacity_script_pipe.from.' + str(os.getuid())
|
||||||
|
EOL = '\n'
|
||||||
|
|
||||||
|
def send_command(command):
|
||||||
|
"""Send a single command."""
|
||||||
|
to_audacity.write(command + EOL)
|
||||||
|
to_audacity.flush()
|
||||||
|
|
||||||
|
def get_response():
|
||||||
|
"""Return the command response."""
|
||||||
|
result = ''
|
||||||
|
line = ''
|
||||||
|
while True:
|
||||||
|
result += line
|
||||||
|
line = from_audacity.readline()
|
||||||
|
if line == '\n' and len(result) > 0:
|
||||||
|
break
|
||||||
|
return result
|
||||||
|
|
||||||
|
def do_command(command):
|
||||||
|
"""Send one command, and return the response."""
|
||||||
|
send_command(command)
|
||||||
|
response = get_response()
|
||||||
|
return response
|
||||||
|
|
||||||
|
with open(to_pipe, 'w') as to_audacity, open(
|
||||||
|
from_pipe, 'rt') as from_audacity:
|
||||||
|
do_command(f'Import2: Filename="{path}"')
|
||||||
|
|
||||||
|
|
||||||
def show_warning(title, msg):
|
def show_warning(title, msg):
|
||||||
"Display a warning to user"
|
"Display a warning to user"
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import os
|
import os
|
||||||
|
import psutil
|
||||||
import sys
|
import sys
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
@ -80,6 +81,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
self.load_last_playlists()
|
self.load_last_playlists()
|
||||||
self.enable_play_next_controls()
|
self.enable_play_next_controls()
|
||||||
|
self.check_audacity()
|
||||||
self.timer.start(Config.TIMER_MS)
|
self.timer.start(Config.TIMER_MS)
|
||||||
|
|
||||||
def add_file(self):
|
def add_file(self):
|
||||||
@ -112,6 +114,14 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
height = record.f_int or 981
|
height = record.f_int or 981
|
||||||
self.setGeometry(x, y, width, height)
|
self.setGeometry(x, y, width, height)
|
||||||
|
|
||||||
|
def check_audacity(self):
|
||||||
|
"Warn user if Audacity not running"
|
||||||
|
|
||||||
|
if "audacity" in [i.name() for i in psutil.process_iter()]:
|
||||||
|
return
|
||||||
|
|
||||||
|
helpers.show_warning("Audacity check", "Audacity is not running")
|
||||||
|
|
||||||
def clear_selection(self):
|
def clear_selection(self):
|
||||||
if self.visible_playlist_tab():
|
if self.visible_playlist_tab():
|
||||||
self.visible_playlist_tab().clearSelection()
|
self.visible_playlist_tab().clearSelection()
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import os
|
|||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from helpers import get_relative_date, show_warning
|
from helpers import get_relative_date, open_in_audacity, show_warning
|
||||||
from log import DEBUG, ERROR
|
from log import DEBUG, ERROR
|
||||||
from model import (
|
from model import (
|
||||||
Notes, Playdates, Playlists, PlaylistTracks, Session, Settings, Tracks
|
Notes, Playdates, Playlists, PlaylistTracks, Session, Settings, Tracks
|
||||||
@ -181,6 +181,9 @@ class PlaylistTab(QTableWidget):
|
|||||||
lambda: self._copy_path(row))
|
lambda: self._copy_path(row))
|
||||||
act_rescan = self.menu.addAction("Rescan track")
|
act_rescan = self.menu.addAction("Rescan track")
|
||||||
act_rescan.triggered.connect(lambda: self._rescan(row))
|
act_rescan.triggered.connect(lambda: self._rescan(row))
|
||||||
|
act_audacity = self.menu.addAction(
|
||||||
|
"Open track in Audacity")
|
||||||
|
act_audacity.triggered.connect(lambda: self._audacity(row))
|
||||||
self.menu.addSeparator()
|
self.menu.addSeparator()
|
||||||
act_delete = self.menu.addAction('Delete')
|
act_delete = self.menu.addAction('Delete')
|
||||||
act_delete.triggered.connect(self._delete_rows)
|
act_delete.triggered.connect(self._delete_rows)
|
||||||
@ -551,6 +554,20 @@ class PlaylistTab(QTableWidget):
|
|||||||
|
|
||||||
# ########## Internally called functions ##########
|
# ########## Internally called functions ##########
|
||||||
|
|
||||||
|
def _audacity(self, row):
|
||||||
|
"Open track in Audacity. Audacity must be already running"
|
||||||
|
|
||||||
|
DEBUG(f"_audacity({row})")
|
||||||
|
|
||||||
|
if row in self._meta_get_notes():
|
||||||
|
return None
|
||||||
|
|
||||||
|
track_id = self._get_row_id(row)
|
||||||
|
if track_id:
|
||||||
|
with Session() as session:
|
||||||
|
track = Tracks.get_track(session, track_id)
|
||||||
|
open_in_audacity(track.path)
|
||||||
|
|
||||||
def _calculate_next_start_time(self, session, row, start):
|
def _calculate_next_start_time(self, session, row, start):
|
||||||
"Return this row's end time given its start time"
|
"Return this row's end time given its start time"
|
||||||
|
|
||||||
|
|||||||
0
audacity_control.py
Normal file → Executable file
0
audacity_control.py
Normal file → Executable file
@ -17,6 +17,7 @@ parso==0.8.2
|
|||||||
pexpect==4.8.0
|
pexpect==4.8.0
|
||||||
pickleshare==0.7.5
|
pickleshare==0.7.5
|
||||||
prompt-toolkit==3.0.18
|
prompt-toolkit==3.0.18
|
||||||
|
psutil==5.8.0
|
||||||
ptyprocess==0.7.0
|
ptyprocess==0.7.0
|
||||||
pycodestyle==2.7.0
|
pycodestyle==2.7.0
|
||||||
pydub==0.25.1
|
pydub==0.25.1
|
||||||
@ -25,6 +26,8 @@ Pygments==2.8.1
|
|||||||
PyQt5==5.15.4
|
PyQt5==5.15.4
|
||||||
PyQt5-Qt5==5.15.2
|
PyQt5-Qt5==5.15.2
|
||||||
PyQt5-sip==12.8.1
|
PyQt5-sip==12.8.1
|
||||||
|
PyQtWebEngine==5.15.4
|
||||||
|
PyQtWebEngine-Qt5==5.15.2
|
||||||
python-dateutil==2.8.1
|
python-dateutil==2.8.1
|
||||||
python-editor==1.0.4
|
python-editor==1.0.4
|
||||||
python-slugify==5.0.0
|
python-slugify==5.0.0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user