forked from trav/lintunes
v0.63.0: DJ mode — two decks, sync, keep-pitch speed, scratching, vocal stems
View > DJ Mode (or the turntable button under BPM) parts the window under the transport boxes and opens a dark shelf: a record per deck (drag a song on to load it; drag the record to scratch), play/pause and Sync to other track beside it, a ±8% speed fader on each edge, Keep pitch, the two waveforms stacked around one playhead, a vocals/instrumental slider and the crossfader. Deck A is blue, Deck B orange; loaded songs are tagged in the lists. Its own engine (lintunes/dj): whole-song decode, tempo refined to 0.01 BPM plus the first beat (exact on synthetic kicks), WSOLA time-stretch or varispeed, a QAudioSink on its own thread. Sync matches tempo and, while both play, nudges the beats into line. A missing BPM is calculated and saved. Vocals come from Demucs, run once per song in the background and cached; Demucs lives in its own venv.
This commit is contained in:
+121
-2
@@ -4,8 +4,8 @@ from PyQt6.QtWidgets import (
|
||||
QWidget, QFrame, QHBoxLayout, QVBoxLayout, QLabel, QToolButton, QSlider,
|
||||
QPushButton, QSizePolicy, QStyle, QLayout, QSpacerItem,
|
||||
)
|
||||
from PyQt6.QtCore import Qt, QTimer, QEvent, QPoint, QRect, pyqtSignal
|
||||
from PyQt6.QtGui import QColor, QFont
|
||||
from PyQt6.QtCore import Qt, QTimer, QEvent, QPoint, QPointF, QRect, QSize, pyqtSignal
|
||||
from PyQt6.QtGui import QColor, QFont, QIcon, QPainter, QPen, QPixmap
|
||||
|
||||
from lintunes.tap_tempo import TapTempo
|
||||
from lintunes.gui.icons import transport_icon
|
||||
@@ -50,6 +50,10 @@ def _box_style(bg: QColor) -> str:
|
||||
for kind in ("QToolButton", "QPushButton"):
|
||||
face += theme.button_face_qss(f"QFrame#transportBox > {kind}", bg,
|
||||
radius=8)
|
||||
# Greyed in DJ mode: flat and pale, so it reads as switched off.
|
||||
for kind in ("QToolButton", "QPushButton"):
|
||||
face += (f"QFrame#transportBox > {kind}:disabled {{ background:"
|
||||
f" {bg.lighter(104).name()}; border-color: {bg.darker(112).name()}; }}")
|
||||
return face + TILE_STYLE
|
||||
|
||||
|
||||
@@ -86,6 +90,28 @@ def _clamp_volume(value) -> float:
|
||||
return 0.8
|
||||
|
||||
|
||||
def turntable_icon(color: QColor, size: int = 18) -> QIcon:
|
||||
"""DJ mode's glyph: a small turntable — plinth, platter, tonearm."""
|
||||
from PyQt6.QtCore import QRectF
|
||||
pix = QPixmap(round(size * 4 / 3), size)
|
||||
pix.fill(Qt.GlobalColor.transparent)
|
||||
p = QPainter(pix)
|
||||
p.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
s = size / 18
|
||||
pen = QPen(color, 1.5 * s)
|
||||
p.setPen(pen)
|
||||
p.setBrush(Qt.BrushStyle.NoBrush)
|
||||
p.drawRoundedRect(QRectF(1 * s, 1.5 * s, 22 * s, 15 * s), 2 * s, 2 * s)
|
||||
p.drawEllipse(QRectF(5 * s, 4 * s, 10 * s, 10 * s))
|
||||
p.setBrush(color)
|
||||
p.drawEllipse(QRectF(9.2 * s, 8.2 * s, 1.6 * s, 1.6 * s))
|
||||
p.setBrush(Qt.BrushStyle.NoBrush)
|
||||
p.drawLine(QPointF(19.5 * s, 4 * s), QPointF(19.5 * s, 10.5 * s))
|
||||
p.drawLine(QPointF(19.5 * s, 10.5 * s), QPointF(16 * s, 13 * s))
|
||||
p.end()
|
||||
return QIcon(pix)
|
||||
|
||||
|
||||
class FlashButton(QToolButton):
|
||||
"""Transport button: dark-gray glyph that shows the highlight color
|
||||
while pressed (a quick flash on click, sustained while held). A checkable
|
||||
@@ -109,9 +135,16 @@ class FlashButton(QToolButton):
|
||||
def refresh_icons(self):
|
||||
self._apply_icon(active=self.isDown())
|
||||
|
||||
def changeEvent(self, event):
|
||||
super().changeEvent(event)
|
||||
if event.type() == QEvent.Type.EnabledChange:
|
||||
self._apply_icon()
|
||||
|
||||
def _apply_icon(self, active: bool = False):
|
||||
show_active = active or (self.isCheckable() and self.isChecked())
|
||||
color = self.palette().highlight().color() if show_active else ICON_GRAY
|
||||
if not self.isEnabled():
|
||||
color = QColor(ICON_GRAY).lighter(160)
|
||||
self.setIcon(transport_icon(self._kind, color))
|
||||
|
||||
|
||||
@@ -285,6 +318,8 @@ class HeaderRow(QWidget):
|
||||
self.view_header: QWidget | None = None
|
||||
self._split = (0, 0, 0) # list left, list right, content left
|
||||
self._panel = QRect() # now-playing panel, in our coordinates
|
||||
self.right: QWidget | None = None # the DJ button, under the bpm box
|
||||
self._right = QRect()
|
||||
|
||||
def set_left(self, widget: QWidget):
|
||||
self.left = widget
|
||||
@@ -316,6 +351,15 @@ class HeaderRow(QWidget):
|
||||
self._panel = rect
|
||||
self.place()
|
||||
|
||||
def set_right(self, widget: QWidget, rect: QRect):
|
||||
"""``widget`` sits under the bpm box, ``rect`` its column."""
|
||||
if widget.parent() is not self:
|
||||
widget.setParent(self)
|
||||
widget.show()
|
||||
self.right = widget
|
||||
self._right = rect
|
||||
self.place()
|
||||
|
||||
def resizeEvent(self, event):
|
||||
super().resizeEvent(event)
|
||||
self.place()
|
||||
@@ -337,6 +381,9 @@ class HeaderRow(QWidget):
|
||||
self.seek.setGeometry(seek_left, self.TOP_PAD,
|
||||
max(0, panel.right() + 1 - seek_left),
|
||||
box_h + drop - self.LIFT)
|
||||
if self.right is not None and not self._right.isNull():
|
||||
self.right.setGeometry(self._right.left(), self.TOP_PAD,
|
||||
self._right.width(), box_h)
|
||||
header = self.view_header
|
||||
if header is not None:
|
||||
width = max(0, seek_left - self.GAP - content_left)
|
||||
@@ -359,6 +406,8 @@ class TransportBar(QWidget):
|
||||
now-playing text, seek slider, boxed bpm tap button (right)."""
|
||||
|
||||
play_clicked = pyqtSignal() # MainWindow decides what "play" means
|
||||
dj_toggled = pyqtSignal(bool)
|
||||
volume_level_changed = pyqtSignal(float) # the slider, 0..1 perceptual
|
||||
|
||||
def __init__(self, player, manager, prefs, cast=None, airplay=None,
|
||||
parent=None):
|
||||
@@ -368,6 +417,7 @@ class TransportBar(QWidget):
|
||||
self._cast = cast
|
||||
self._scrubbing = False
|
||||
self._current_track = None
|
||||
self._dj_on = False
|
||||
|
||||
self.setMinimumHeight(BAR_HEIGHT)
|
||||
outer = QVBoxLayout(self)
|
||||
@@ -377,6 +427,7 @@ class TransportBar(QWidget):
|
||||
# bar's minimum must not come from the panel's current width, or a
|
||||
# window could never shrink past the width it last had.
|
||||
outer.setSizeConstraint(QLayout.SizeConstraint.SetNoConstraint)
|
||||
self._outer = outer
|
||||
layout = QHBoxLayout()
|
||||
layout.setContentsMargins(GAP, 0, GAP, 0)
|
||||
layout.setSpacing(0)
|
||||
@@ -542,6 +593,18 @@ class TransportBar(QWidget):
|
||||
self._header_strip = 34
|
||||
self.set_header_height(34)
|
||||
outer.addWidget(self._header_row)
|
||||
|
||||
# DJ mode's button: under the bpm box, in the header row.
|
||||
self.dj_button = QToolButton()
|
||||
self.dj_button.setObjectName("djButton")
|
||||
self.dj_button.setCheckable(True)
|
||||
self.dj_button.setToolTip("DJ mode")
|
||||
self.dj_button.setIcon(turntable_icon(QColor(ICON_GRAY)))
|
||||
self.dj_button.setIconSize(QSize(24, 18))
|
||||
self.dj_button.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
||||
self.dj_button.toggled.connect(self._on_dj_button)
|
||||
self._dj_bpm_box = bpm_box
|
||||
self._apply_dj_button_style()
|
||||
self._split_widgets: tuple = ()
|
||||
|
||||
# Wiring
|
||||
@@ -565,6 +628,56 @@ class TransportBar(QWidget):
|
||||
lambda: (cast.disconnect(),
|
||||
airplay is not None and airplay.disconnect()))
|
||||
|
||||
# ---- DJ mode ----
|
||||
|
||||
def _apply_dj_button_style(self):
|
||||
bg = theme.gray(theme.gray_value(self._prefs, "color_button"))
|
||||
self.dj_button.setStyleSheet(theme.button_face_qss(
|
||||
"QToolButton#djButton", bg, extra="padding: 0;",
|
||||
checked_color=bg.darker(theme.CHECKED_DARKER)))
|
||||
|
||||
def _on_dj_button(self, on: bool):
|
||||
self._on_dj_button_icon(on)
|
||||
self.dj_toggled.emit(on)
|
||||
|
||||
def insert_shelf(self, shelf: QWidget):
|
||||
"""The DJ shelf goes between the row of boxes and the header row,
|
||||
so the window parts there: the boxes stay, the Library button and
|
||||
everything under it slides down."""
|
||||
if self._outer.indexOf(shelf) < 0:
|
||||
self._outer.insertWidget(1, shelf)
|
||||
|
||||
def set_dj_mode(self, on: bool, titles: str = ""):
|
||||
"""Grey what DJ mode doesn't use: each deck has its own play and
|
||||
position, so the main transport and seek bar would only mislead."""
|
||||
for widget in (self._prev_btn, self._play_btn, self._next_btn,
|
||||
self._shuffle_btn, self._repeat_btn, self._slider):
|
||||
widget.setEnabled(not on)
|
||||
for label in (self._elapsed_label, self._remaining_label):
|
||||
label.setEnabled(not on)
|
||||
if self.dj_button.isChecked() != on:
|
||||
self.dj_button.blockSignals(True)
|
||||
self.dj_button.setChecked(on)
|
||||
self.dj_button.blockSignals(False)
|
||||
self._on_dj_button_icon(on)
|
||||
self._dj_on = on
|
||||
if on:
|
||||
self.set_dj_titles(titles)
|
||||
else:
|
||||
self._on_track_changed(self._current_track)
|
||||
|
||||
def _on_dj_button_icon(self, on: bool):
|
||||
color = self.palette().highlight().color() if on else QColor(ICON_GRAY)
|
||||
self.dj_button.setIcon(turntable_icon(color))
|
||||
|
||||
def volume_level(self) -> float:
|
||||
"""The volume slider, 0..1 (perceptual, as Player takes it)."""
|
||||
return self._volume_slider.value() / 100
|
||||
|
||||
def set_dj_titles(self, text: str):
|
||||
self._title_label.setText(text or "DJ mode")
|
||||
self._artist_label.setText("Drag songs onto the records" if not text else "DJ mode")
|
||||
|
||||
# ---- repeat ----
|
||||
|
||||
_REPEAT_TIPS = {"off": "Repeat: off", "all": "Repeat: all",
|
||||
@@ -656,6 +769,8 @@ class TransportBar(QWidget):
|
||||
|
||||
row.set_panel(QRect(x_of(self._now_playing), 0,
|
||||
self._now_playing.width(), row.height()))
|
||||
box = self._dj_bpm_box
|
||||
row.set_right(self.dj_button, QRect(x_of(box), 0, box.width(), row.height()))
|
||||
if self._split_widgets:
|
||||
lists, content = self._split_widgets
|
||||
row.set_split(x_of(lists), x_of(lists, lists.width()),
|
||||
@@ -673,6 +788,7 @@ class TransportBar(QWidget):
|
||||
box.setStyleSheet(_box_style(box_bg))
|
||||
self._apply_now_playing_bg()
|
||||
self._apply_now_playing_font()
|
||||
self._apply_dj_button_style()
|
||||
self._visualizer.update() # dim-mode bar color may have changed
|
||||
|
||||
def _apply_now_playing_bg(self):
|
||||
@@ -682,6 +798,7 @@ class TransportBar(QWidget):
|
||||
def _on_volume_changed(self, value: int):
|
||||
"""Slider moved: update audio live, defer the (theme-reapplying) save."""
|
||||
self._player.set_volume(value / 100)
|
||||
self.volume_level_changed.emit(value / 100)
|
||||
self._volume_save_timer.start()
|
||||
|
||||
def _save_volume(self):
|
||||
@@ -706,6 +823,8 @@ class TransportBar(QWidget):
|
||||
|
||||
def _on_track_changed(self, track):
|
||||
self._current_track = track
|
||||
if self._dj_on:
|
||||
return # the panel names the decks' songs meanwhile
|
||||
if track is None:
|
||||
self._title_label.setText("")
|
||||
self._artist_label.setText("")
|
||||
|
||||
Reference in New Issue
Block a user