Compare commits
4 Commits
c5c5c28583
...
fe338aaf4a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fe338aaf4a | ||
|
|
a923f32070 | ||
|
|
7dac80dcf6 | ||
|
|
c0e1732bbc |
@ -67,6 +67,9 @@ class Config(object):
|
|||||||
MINIMUM_ROW_HEIGHT = 30
|
MINIMUM_ROW_HEIGHT = 30
|
||||||
MYSQL_CONNECT = os.environ.get('MYSQL_CONNECT') or "mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_v2" # noqa E501
|
MYSQL_CONNECT = os.environ.get('MYSQL_CONNECT') or "mysql+mysqldb://musicmuster:musicmuster@localhost/musicmuster_v2" # noqa E501
|
||||||
NOTE_TIME_FORMAT = "%H:%M:%S"
|
NOTE_TIME_FORMAT = "%H:%M:%S"
|
||||||
|
OBS_HOST = "localhost"
|
||||||
|
OBS_PASSWORD = "auster"
|
||||||
|
OBS_PORT = 4455
|
||||||
PLAY_SETTLE = 500000
|
PLAY_SETTLE = 500000
|
||||||
ROOT = os.environ.get('ROOT') or "/home/kae/music"
|
ROOT = os.environ.get('ROOT') or "/home/kae/music"
|
||||||
IMPORT_DESTINATION = os.path.join(ROOT, "Singles")
|
IMPORT_DESTINATION = os.path.join(ROOT, "Singles")
|
||||||
|
|||||||
100
app/music.py
100
app/music.py
@ -10,9 +10,53 @@ from time import sleep
|
|||||||
|
|
||||||
from log import log
|
from log import log
|
||||||
|
|
||||||
|
from PyQt5.QtCore import (
|
||||||
|
QRunnable,
|
||||||
|
QThreadPool,
|
||||||
|
)
|
||||||
|
|
||||||
lock = threading.Lock()
|
lock = threading.Lock()
|
||||||
|
|
||||||
|
|
||||||
|
class FadeTrack(QRunnable):
|
||||||
|
|
||||||
|
def __init__(self, player: vlc.MediaPlayer) -> None:
|
||||||
|
super().__init__()
|
||||||
|
self.player = player
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
"""
|
||||||
|
Implementation of fading the player
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not self.player:
|
||||||
|
return
|
||||||
|
|
||||||
|
fade_time = Config.FADE_TIME / 1000
|
||||||
|
steps = Config.FADE_STEPS
|
||||||
|
sleep_time = fade_time / steps
|
||||||
|
original_volume = self.player.audio_get_volume()
|
||||||
|
|
||||||
|
# We reduce volume by one mesure first, then by two measures,
|
||||||
|
# then three, and so on.
|
||||||
|
# The sum of the arithmetic sequence 1, 2, 3, ..n is
|
||||||
|
# (n**2 + n) / 2
|
||||||
|
total_measures_count = (steps**2 + steps) / 2
|
||||||
|
|
||||||
|
measures_to_reduce_by = 0
|
||||||
|
|
||||||
|
for i in range(1, steps + 1):
|
||||||
|
measures_to_reduce_by += i
|
||||||
|
volume_factor = 1 - (
|
||||||
|
measures_to_reduce_by / total_measures_count)
|
||||||
|
self.player.audio_set_volume(int(original_volume * volume_factor))
|
||||||
|
sleep(sleep_time)
|
||||||
|
|
||||||
|
self.player.stop()
|
||||||
|
log.debug(f"Releasing player {self.player=}")
|
||||||
|
self.player.release()
|
||||||
|
|
||||||
|
|
||||||
class Music:
|
class Music:
|
||||||
"""
|
"""
|
||||||
Manage the playing of music tracks
|
Manage the playing of music tracks
|
||||||
@ -37,46 +81,15 @@ class Music:
|
|||||||
if not self.player.get_position() > 0 and self.player.is_playing():
|
if not self.player.get_position() > 0 and self.player.is_playing():
|
||||||
return
|
return
|
||||||
|
|
||||||
thread = threading.Thread(target=self._fade)
|
|
||||||
thread.start()
|
|
||||||
|
|
||||||
def _fade(self) -> None:
|
|
||||||
"""
|
|
||||||
Implementation of fading the current track in a separate thread.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# Take a copy of current player to allow another track to be
|
# Take a copy of current player to allow another track to be
|
||||||
# started without interfering here
|
# started without interfering here
|
||||||
with lock:
|
with lock:
|
||||||
p = self.player
|
p = self.player
|
||||||
self.player = None
|
self.player = None
|
||||||
|
|
||||||
# Sanity check
|
pool = QThreadPool.globalInstance()
|
||||||
if not p:
|
fader = FadeTrack(p)
|
||||||
return
|
pool.start(fader)
|
||||||
|
|
||||||
fade_time = Config.FADE_TIME / 1000
|
|
||||||
steps = Config.FADE_STEPS
|
|
||||||
sleep_time = fade_time / steps
|
|
||||||
|
|
||||||
# We reduce volume by one mesure first, then by two measures,
|
|
||||||
# then three, and so on.
|
|
||||||
# The sum of the arithmetic sequence 1, 2, 3, ..n is
|
|
||||||
# (n**2 + n) / 2
|
|
||||||
total_measures_count = (steps**2 + steps) / 2
|
|
||||||
|
|
||||||
measures_to_reduce_by = 0
|
|
||||||
for i in range(1, steps + 1):
|
|
||||||
measures_to_reduce_by += i
|
|
||||||
volume_factor = 1 - (
|
|
||||||
measures_to_reduce_by / total_measures_count)
|
|
||||||
p.audio_set_volume(int(self.max_volume * volume_factor))
|
|
||||||
sleep(sleep_time)
|
|
||||||
|
|
||||||
with lock:
|
|
||||||
p.stop()
|
|
||||||
log.debug(f"Releasing player {p=}")
|
|
||||||
p.release()
|
|
||||||
|
|
||||||
def get_playtime(self) -> Optional[int]:
|
def get_playtime(self) -> Optional[int]:
|
||||||
"""Return elapsed play time"""
|
"""Return elapsed play time"""
|
||||||
@ -117,13 +130,6 @@ class Music:
|
|||||||
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
#
|
|
||||||
# def set_position(self, ms):
|
|
||||||
# """Set current play time in milliseconds from start"""
|
|
||||||
#
|
|
||||||
# with lock:
|
|
||||||
# return self.player.set_time(ms)
|
|
||||||
|
|
||||||
def set_volume(self, volume, set_default=True):
|
def set_volume(self, volume, set_default=True):
|
||||||
"""Set maximum volume used for player"""
|
"""Set maximum volume used for player"""
|
||||||
|
|
||||||
@ -138,13 +144,15 @@ class Music:
|
|||||||
def stop(self) -> float:
|
def stop(self) -> float:
|
||||||
"""Immediately stop playing"""
|
"""Immediately stop playing"""
|
||||||
|
|
||||||
with lock:
|
|
||||||
if not self.player:
|
if not self.player:
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
position = self.player.get_position()
|
p = self.player
|
||||||
self.player.stop()
|
|
||||||
self.player.release()
|
|
||||||
# Ensure we don't reference player after release
|
|
||||||
self.player = None
|
self.player = None
|
||||||
|
|
||||||
|
with lock:
|
||||||
|
position = p.get_position()
|
||||||
|
p.stop()
|
||||||
|
p.release()
|
||||||
|
p = None
|
||||||
return position
|
return position
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import stackprinter # type: ignore
|
|||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
import obsws_python as obs
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Callable, cast, List, Optional, TYPE_CHECKING, Union
|
from typing import Callable, cast, List, Optional, TYPE_CHECKING, Union
|
||||||
@ -63,8 +65,10 @@ from models import (
|
|||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from musicmuster import Window, MusicMusterSignals
|
from musicmuster import Window, MusicMusterSignals
|
||||||
|
|
||||||
start_time_re = re.compile(r"@\d\d:\d\d:\d\d")
|
scene_change_re = re.compile(r"SetScene=\[([^[\]]*)\]")
|
||||||
section_header_cleanup_re = re.compile(r"(@\d\d:\d\d:\d\d.*)?(\+)?")
|
section_header_cleanup_re = re.compile(r"(@\d\d:\d\d:\d\d.*)?(\+)?")
|
||||||
|
start_time_re = re.compile(r"@\d\d:\d\d:\d\d")
|
||||||
|
|
||||||
HEADER_NOTES_COLUMN = 2
|
HEADER_NOTES_COLUMN = 2
|
||||||
|
|
||||||
# Columns
|
# Columns
|
||||||
@ -632,6 +636,8 @@ class PlaylistTab(QTableWidget):
|
|||||||
- Set next track
|
- Set next track
|
||||||
- Display track as current
|
- Display track as current
|
||||||
- Update start/stop times
|
- Update start/stop times
|
||||||
|
- Change OBS scene if needed
|
||||||
|
- Update hidden tracks
|
||||||
"""
|
"""
|
||||||
|
|
||||||
current_row = self._get_current_track_row_number()
|
current_row = self._get_current_track_row_number()
|
||||||
@ -661,6 +667,9 @@ class PlaylistTab(QTableWidget):
|
|||||||
# Update start/stop times
|
# Update start/stop times
|
||||||
self._update_start_end_times(session)
|
self._update_start_end_times(session)
|
||||||
|
|
||||||
|
# Change OBS scene if needed
|
||||||
|
self._obs_change_scene(current_row)
|
||||||
|
|
||||||
# Update hidden tracks
|
# Update hidden tracks
|
||||||
QTimer.singleShot(Config.HIDE_AFTER_PLAYING_OFFSET,
|
QTimer.singleShot(Config.HIDE_AFTER_PLAYING_OFFSET,
|
||||||
self.hide_or_show_played_tracks)
|
self.hide_or_show_played_tracks)
|
||||||
@ -1440,6 +1449,44 @@ class PlaylistTab(QTableWidget):
|
|||||||
target=self._run_subprocess, args=(cmd_list,))
|
target=self._run_subprocess, args=(cmd_list,))
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|
||||||
|
def _obs_change_scene(self, current_row: int) -> None:
|
||||||
|
"""
|
||||||
|
Try to change OBS scene to the name passed
|
||||||
|
"""
|
||||||
|
|
||||||
|
check_row = current_row
|
||||||
|
while True:
|
||||||
|
# If we have a note and it has a scene change command,
|
||||||
|
# execute it
|
||||||
|
note_text = self._get_row_note(check_row)
|
||||||
|
if note_text:
|
||||||
|
match_obj = scene_change_re.search(note_text)
|
||||||
|
if match_obj:
|
||||||
|
scene_name = match_obj.group(1)
|
||||||
|
if scene_name:
|
||||||
|
try:
|
||||||
|
cl = obs.ReqClient(host=Config.OBS_HOST,
|
||||||
|
port=Config.OBS_PORT,
|
||||||
|
password=Config.OBS_PASSWORD)
|
||||||
|
except ConnectionRefusedError:
|
||||||
|
log.error(f"OBS connection refused")
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
cl.set_current_program_scene(scene_name)
|
||||||
|
log.info(f"OBS scene changed to '{scene_name}'")
|
||||||
|
return
|
||||||
|
except obs.error.OBSSDKError as e:
|
||||||
|
log.error(f"OBS SDK error ({e})")
|
||||||
|
return
|
||||||
|
# After current track row, only check header rows and stop
|
||||||
|
# at first non-header row
|
||||||
|
check_row -= 1
|
||||||
|
if check_row < 0:
|
||||||
|
break
|
||||||
|
if self._get_row_track_id(check_row):
|
||||||
|
break
|
||||||
|
|
||||||
def _open_in_audacity(self, row_number: int) -> None:
|
def _open_in_audacity(self, row_number: int) -> None:
|
||||||
"""Open track in Audacity. Audacity must be already running"""
|
"""Open track in Audacity. Audacity must be already running"""
|
||||||
|
|
||||||
|
|||||||
@ -126,9 +126,9 @@ def main():
|
|||||||
# Try to find a near match
|
# Try to find a near match
|
||||||
|
|
||||||
if process_no_matches:
|
if process_no_matches:
|
||||||
prompt = f"\n file={new_fname}\n title={new_title}\n artist={new_artist}: "
|
prompt = f"file={new_fname}\n title={new_title}\n artist={new_artist}: "
|
||||||
# Use fzf to search
|
# Use fzf to search
|
||||||
choice = pydymenu.fzf(parent_fnames, prompt)
|
choice = pydymenu.fzf(parent_fnames, prompt=prompt)
|
||||||
if choice:
|
if choice:
|
||||||
old_file = os.path.join(parent_dir, choice[0])
|
old_file = os.path.join(parent_dir, choice[0])
|
||||||
oldtags = get_tags(old_file)
|
oldtags = get_tags(old_file)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user