v0.66.0: DJ mode's djay layout, loops, a sync that sets once, a real horn, a smooth slide
- Records in the top corners, each deck's controls beside them facing the middle, the zoomed A-over-B waveforms in the centre, and a whole-song overview per deck below (click to jump, drag to move) with the crossfader between them. - Loops per deck: Loop plus a 1/32 to 8 beat stepper; a loop starts on the next beat and shows on both waveforms. - Sync sets this deck to the other's tempo once, and stays lit only while that still holds. - The air horn plays like a real one: every press a fresh blast, held it carries the note, let go it stops. - Opening and closing DJ mode slides a picture over the final layout instead of re-laying-out the window every frame (the flicker). - Tests: garbage is collected on the main thread after each test, which stops a rare segfault in the full run.
This commit is contained in:
@@ -422,6 +422,28 @@ persistence) → GUI (Qt widgets that read the manager and connect to its signal
|
|||||||
while a deck is paused or held. The sink reopens when the system's
|
while a deck is paused or held. The sink reopens when the system's
|
||||||
default output changes (`output._Pump`: `audioOutputsChanged`, a device
|
default output changes (`output._Pump`: `audioOutputsChanged`, a device
|
||||||
id check, an error check) — it used to go silent until DJ mode reopened.
|
id check, an error check) — it used to go silent until DJ mode reopened.
|
||||||
|
**Round 96**: the layout is djay's — records in the top corners, each
|
||||||
|
deck's controls beside its record facing the middle (title, tempo, |◀ ⏯
|
||||||
|
Sync, ½×/1×/2×, Keep pitch, Loop, vocals), the horn and the zoomed A-over-
|
||||||
|
B lanes in the centre, and below them each deck's **whole-song overview**
|
||||||
|
(`OverviewWave`: played part shaded, playhead, loop band; click jumps,
|
||||||
|
drag moves) with the crossfader between. **Loops**: Loop + a ‹ size ›
|
||||||
|
stepper (1/32 … 8 beats); a loop starts on the *next* beat; the engine
|
||||||
|
renders up to the loop end in pieces and wraps (`Deck.loop`), shown on
|
||||||
|
both waveforms. **Sync sets once** (trav's call): it puts this deck at the
|
||||||
|
other's tempo and stays lit only while that holds (`_check_sync`: same
|
||||||
|
song on the other deck, tempos still equal) — nothing follows anything.
|
||||||
|
**The horn** plays like a real DJ horn: every press a fresh blast (older
|
||||||
|
ones fade under it), held = the first blast's steady middle looped, let
|
||||||
|
go = a 90 ms fade. **Opening/closing slides a picture** (`SlideOverlay`):
|
||||||
|
the window jumps to its final layout once and a grab of what was below
|
||||||
|
the transport boxes moves over it — animating the real shelf height
|
||||||
|
re-laid-out the window every frame, which flickered.
|
||||||
|
The suite collects garbage on the main thread after every test (conftest
|
||||||
|
`_collect_on_the_main_thread`): Python's GC runs on whatever thread
|
||||||
|
triggers it, and a Qt object a test left behind, collected on a worker,
|
||||||
|
segfaulted a later test (always test_round72's maximized window, only in
|
||||||
|
the full run).
|
||||||
|
|
||||||
- **`lintunes/importers/itunes_importer.py`** — parses the iTunes XML plist.
|
- **`lintunes/importers/itunes_importer.py`** — parses the iTunes XML plist.
|
||||||
Remaps Mac `file:///Volumes/...` paths to the local `--music-root` with
|
Remaps Mac `file:///Volumes/...` paths to the local `--music-root` with
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
"""LinTunes — iTunes-style music library manager and player for Linux."""
|
||||||
|
|
||||||
__version__ = "0.65.0"
|
__version__ = "0.66.0"
|
||||||
|
|||||||
+70
-36
@@ -89,6 +89,7 @@ class Deck:
|
|||||||
self.vocal_mix = 0.0
|
self.vocal_mix = 0.0
|
||||||
self.scratch_rate: float | None = None
|
self.scratch_rate: float | None = None
|
||||||
self.volume = 1.0 # the deck's own fader, before the crossfader
|
self.volume = 1.0 # the deck's own fader, before the crossfader
|
||||||
|
self.loop: tuple[int, int] | None = None # (start, end) source frames
|
||||||
self.ended = False # reached the end by playing (GUI clears)
|
self.ended = False # reached the end by playing (GUI clears)
|
||||||
self._ola: np.ndarray | None = None # overlap-add tail
|
self._ola: np.ndarray | None = None # overlap-add tail
|
||||||
self._last: int | None = None # where the last window was read
|
self._last: int | None = None # where the last window was read
|
||||||
@@ -97,6 +98,7 @@ class Deck:
|
|||||||
|
|
||||||
def load(self, source: Source | None):
|
def load(self, source: Source | None):
|
||||||
self.playing = False
|
self.playing = False
|
||||||
|
self.loop = None
|
||||||
self.source = source
|
self.source = source
|
||||||
self.position = 0.0
|
self.position = 0.0
|
||||||
self.ended = False
|
self.ended = False
|
||||||
@@ -117,6 +119,34 @@ class Deck:
|
|||||||
# ---- rendering ----
|
# ---- rendering ----
|
||||||
|
|
||||||
def render(self, count: int) -> np.ndarray:
|
def render(self, count: int) -> np.ndarray:
|
||||||
|
"""``count`` frames out. With a loop set, playback that crosses its
|
||||||
|
end jumps back to its start — rendered in pieces that stop at the
|
||||||
|
end, so even a 1/32-beat loop lands where it should."""
|
||||||
|
loop = self.loop
|
||||||
|
if loop is None or self.scratch_rate is not None or not self.playing:
|
||||||
|
return self._render(count)
|
||||||
|
start, end = loop
|
||||||
|
pieces = []
|
||||||
|
left = count
|
||||||
|
while left > 0:
|
||||||
|
speed = max(self.speed, 1e-3)
|
||||||
|
n = left
|
||||||
|
if self.position < end:
|
||||||
|
to_end = int(np.ceil((end - self.position) / speed))
|
||||||
|
n = max(1, min(left, to_end))
|
||||||
|
before = self.position
|
||||||
|
pieces.append(self._render(n))
|
||||||
|
left -= n
|
||||||
|
if before < end <= self.position:
|
||||||
|
self.position -= (end - start)
|
||||||
|
if not self.playing:
|
||||||
|
break
|
||||||
|
out = np.concatenate(pieces) if pieces else np.zeros((0, CHANNELS), np.float32)
|
||||||
|
if len(out) < count:
|
||||||
|
out = np.concatenate([out, np.zeros((count - len(out), CHANNELS), np.float32)])
|
||||||
|
return out
|
||||||
|
|
||||||
|
def _render(self, count: int) -> np.ndarray:
|
||||||
src = self.source
|
src = self.source
|
||||||
if src is None:
|
if src is None:
|
||||||
return np.zeros((count, CHANNELS), np.float32)
|
return np.zeros((count, CHANNELS), np.float32)
|
||||||
@@ -231,22 +261,24 @@ def crossfade_gains(x: float) -> tuple[float, float]:
|
|||||||
|
|
||||||
|
|
||||||
class Horn:
|
class Horn:
|
||||||
"""The air horn: a real recording ("Air Horn Hype", CC0 — see
|
"""The air horn, played like the real thing: a real recording ("Air
|
||||||
lintunes/sounds/CREDITS.md), the classic BWAAH-bwah-bwah-BWAAAH.
|
Horn Hype", CC0 — see lintunes/sounds/CREDITS.md). Every press is a
|
||||||
Pressed, it plays from the top; *held*, the first long blast is
|
fresh blast from the top; held, it carries the note (the first blast's
|
||||||
stretched for as long as the button stays down (its steady middle,
|
steady middle, ``LOOP``, looped with a crossfade); let go, it stops,
|
||||||
``LOOP``, looped with a crossfade so the seam can't be heard); let go,
|
with a short natural fade — so rapid taps give BWAH-BWAH-BWAH and a
|
||||||
the rest of the phrase plays out. A tap is simply the whole phrase."""
|
hold gives one long BWAAAAAH. A press while a blast is still ringing
|
||||||
|
starts a new one and lets the old one fade under it (no click)."""
|
||||||
|
|
||||||
LOOP = (0.10, 0.40) # seconds: inside the first blast (0–0.48 s)
|
LOOP = (0.10, 0.40) # seconds: inside the first blast (0–0.48 s)
|
||||||
CROSSFADE = 0.03
|
CROSSFADE = 0.03
|
||||||
|
RELEASE = 0.09 # the fade once the button comes up
|
||||||
|
VOICES = 3
|
||||||
LEVEL = 1.0
|
LEVEL = 1.0
|
||||||
|
|
||||||
def __init__(self, sample: np.ndarray | None = None):
|
def __init__(self, sample: np.ndarray | None = None):
|
||||||
self.on = False
|
self.on = False
|
||||||
self._src = None
|
|
||||||
self._held = None
|
self._held = None
|
||||||
self._pos = None # None = silent
|
self._voices: list[dict] = [] # {"pos", "gain", "fading"}
|
||||||
if sample is not None:
|
if sample is not None:
|
||||||
self.set_sample(sample)
|
self.set_sample(sample)
|
||||||
|
|
||||||
@@ -255,7 +287,6 @@ class Horn:
|
|||||||
src = sample.astype(np.float32)
|
src = sample.astype(np.float32)
|
||||||
if sample.dtype == np.int16:
|
if sample.dtype == np.int16:
|
||||||
src /= 32768.0
|
src /= 32768.0
|
||||||
self._src = src
|
|
||||||
l0, l1 = (int(t * RATE) for t in self.LOOP)
|
l0, l1 = (int(t * RATE) for t in self.LOOP)
|
||||||
xf = int(self.CROSSFADE * RATE)
|
xf = int(self.CROSSFADE * RATE)
|
||||||
l1 = min(l1, len(src))
|
l1 = min(l1, len(src))
|
||||||
@@ -266,43 +297,46 @@ class Horn:
|
|||||||
# its start, so jumping back to l0 continues seamlessly
|
# its start, so jumping back to l0 continues seamlessly
|
||||||
held[l1 - xf:l1] = src[l1 - xf:l1] * (1 - ramp) + src[l0 - xf:l0] * ramp
|
held[l1 - xf:l1] = src[l1 - xf:l1] * (1 - ramp) + src[l0 - xf:l0] * ramp
|
||||||
self._held = held
|
self._held = held
|
||||||
self._loop = (l0, l1, xf)
|
self._loop = (l0, l1)
|
||||||
|
|
||||||
def press(self):
|
def press(self):
|
||||||
self.on = True
|
self.on = True
|
||||||
self._pos = 0
|
for voice in self._voices:
|
||||||
|
voice["fading"] = True
|
||||||
|
self._voices.append({"pos": 0, "gain": 1.0, "fading": False})
|
||||||
|
del self._voices[:-self.VOICES]
|
||||||
|
|
||||||
def release(self):
|
def release(self):
|
||||||
self.on = False
|
self.on = False
|
||||||
|
for voice in self._voices:
|
||||||
|
voice["fading"] = True
|
||||||
|
|
||||||
def render(self, count: int) -> np.ndarray | None:
|
def render(self, count: int) -> np.ndarray | None:
|
||||||
if self._src is None or self._pos is None:
|
if self._held is None or not self._voices:
|
||||||
return None
|
return None
|
||||||
l0, l1, xf = self._loop
|
l0, l1 = self._loop
|
||||||
out = np.zeros((count, CHANNELS), np.float32)
|
out = np.zeros((count, CHANNELS), np.float32)
|
||||||
made = 0
|
step = 1.0 / (self.RELEASE * RATE)
|
||||||
while made < count:
|
kept = []
|
||||||
pos = self._pos
|
for voice in self._voices:
|
||||||
if pos >= len(self._src):
|
# the frames this voice plays: the loop while it's held
|
||||||
self._pos = None
|
index = voice["pos"] + np.arange(count)
|
||||||
break
|
if not voice["fading"]:
|
||||||
if self.on or l1 - xf <= pos < l1 and pos >= l0:
|
over = index >= l1
|
||||||
# held (or finishing the crossfade lap): play the looped
|
index[over] = l0 + (index[over] - l1) % (l1 - l0)
|
||||||
# version, wrapping at the loop's end
|
alive = index < len(self._held)
|
||||||
take = min(count - made, (l1 - pos) if pos < l1 else len(self._src) - pos)
|
frames = np.zeros((count, CHANNELS), np.float32)
|
||||||
if pos < l1:
|
frames[alive] = self._held[index[alive]]
|
||||||
out[made:made + take] = self._held[pos:pos + take]
|
if voice["fading"]:
|
||||||
self._pos = pos + take
|
gain = voice["gain"] - step * np.arange(1, count + 1)
|
||||||
if self._pos >= l1 and self.on:
|
gain = np.clip(gain, 0.0, 1.0)
|
||||||
self._pos = l0
|
voice["gain"] = float(gain[-1])
|
||||||
else:
|
frames *= gain[:, None]
|
||||||
out[made:made + take] = self._src[pos:pos + take]
|
out += frames
|
||||||
self._pos = pos + take
|
voice["pos"] = int(index[-1]) + 1
|
||||||
else:
|
if voice["gain"] > 0 and voice["pos"] < len(self._held):
|
||||||
take = min(count - made, len(self._src) - pos)
|
kept.append(voice)
|
||||||
out[made:made + take] = self._src[pos:pos + take]
|
self._voices = kept
|
||||||
self._pos = pos + take
|
|
||||||
made += take
|
|
||||||
return out * self.LEVEL
|
return out * self.LEVEL
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+392
-110
@@ -51,7 +51,9 @@ COMPACT_HEIGHT = 200
|
|||||||
DEFAULT_ROWS_BELOW = 15
|
DEFAULT_ROWS_BELOW = 15
|
||||||
MIN_ROWS_BELOW, MAX_ROWS_BELOW = 5, 28
|
MIN_ROWS_BELOW, MAX_ROWS_BELOW = 5, 28
|
||||||
GRIP = 8
|
GRIP = 8
|
||||||
DECK_WIDTH = 250 # a record's column: |◀ ⏯ and "Sync to other track" fit
|
RECORD_SIZE = 170 # the records, top corners
|
||||||
|
CONTROLS_WIDTH = 236 # a deck's controls, beside its record
|
||||||
|
CROSSFADER_WIDTH = 280
|
||||||
WARN_GAIN = 0.5
|
WARN_GAIN = 0.5
|
||||||
|
|
||||||
|
|
||||||
@@ -69,7 +71,9 @@ class DeckView:
|
|||||||
self.bpm_saved = False
|
self.bpm_saved = False
|
||||||
self.counted = False
|
self.counted = False
|
||||||
self.mult = 1.0 # the ½× / 1× / 2× switch
|
self.mult = 1.0 # the ½× / 1× / 2× switch
|
||||||
self.synced = False # following the other deck's tempo
|
self.synced = False # set to the other deck's tempo, and still is
|
||||||
|
self.synced_to = None # …the track it was set to
|
||||||
|
self.loop_beats = 4.0
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color(self) -> QColor:
|
def color(self) -> QColor:
|
||||||
@@ -513,6 +517,17 @@ class WaveLanes(QWidget):
|
|||||||
p.setPen(QPen(color, 1))
|
p.setPen(QPen(color, 1))
|
||||||
for x, a, b in lines:
|
for x, a, b in lines:
|
||||||
p.drawLine(QPointF(x + 0.5, a), QPointF(x + 0.5, b))
|
p.drawLine(QPointF(x + 0.5, a), QPointF(x + 0.5, b))
|
||||||
|
loop = deck.loop
|
||||||
|
if loop is not None:
|
||||||
|
span_s = window * speed
|
||||||
|
x0 = (loop[0] / RATE - heard) / span_s * w + w / 2
|
||||||
|
x1 = (loop[1] / RATE - heard) / span_s * w + w / 2
|
||||||
|
band = QColor(view.color)
|
||||||
|
band.setAlpha(60)
|
||||||
|
p.fillRect(QRectF(x0, lane.top(), max(2.0, x1 - x0), lane.height()), band)
|
||||||
|
p.setPen(QPen(view.color.lighter(130), 1))
|
||||||
|
p.drawLine(QPointF(x0, lane.top()), QPointF(x0, lane.bottom()))
|
||||||
|
p.drawLine(QPointF(x1, lane.top()), QPointF(x1, lane.bottom()))
|
||||||
if view.beat_bpm:
|
if view.beat_bpm:
|
||||||
beat = 60.0 / view.beat_bpm
|
beat = 60.0 / view.beat_bpm
|
||||||
first = math.ceil((edges[0] - view.offset) / beat)
|
first = math.ceil((edges[0] - view.offset) / beat)
|
||||||
@@ -807,6 +822,148 @@ class VocalSlider(SnapSlider):
|
|||||||
p.drawPixmap(QPointF(x, 0), pix)
|
p.drawPixmap(QPointF(x, 0), pix)
|
||||||
|
|
||||||
|
|
||||||
|
class OverviewWave(QWidget):
|
||||||
|
"""A deck's whole song, start to end: the peaks, the part already
|
||||||
|
played shaded, the loop (if any), and the playhead moving along it.
|
||||||
|
Click to jump; drag to move the playhead through the song."""
|
||||||
|
|
||||||
|
def __init__(self, view: "DeckView", shelf, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.view = view
|
||||||
|
self.shelf = shelf
|
||||||
|
self._cache = None # (peaks id, width) -> values
|
||||||
|
self._dragging = False
|
||||||
|
self.setMinimumHeight(56)
|
||||||
|
self.setMaximumHeight(80)
|
||||||
|
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Fixed)
|
||||||
|
self.setFixedHeight(64)
|
||||||
|
self.setCursor(Qt.CursorShape.PointingHandCursor)
|
||||||
|
self.setToolTip(f"Deck {view.name}: the whole song — click to jump, drag to move")
|
||||||
|
|
||||||
|
def _values(self, w: int) -> np.ndarray:
|
||||||
|
peaks = self.view.peaks
|
||||||
|
key = (id(peaks), w)
|
||||||
|
if self._cache is None or self._cache[0] != key:
|
||||||
|
idx = np.linspace(0, len(peaks), w + 1).astype(np.int64)
|
||||||
|
self._cache = (key, _pixel_max(peaks, idx, widest=max(1, len(peaks) // max(1, w) + 1)))
|
||||||
|
return self._cache[1]
|
||||||
|
|
||||||
|
def _seconds_at(self, x: float) -> float:
|
||||||
|
src = self.view.deck.source
|
||||||
|
return max(0.0, min(1.0, x / max(1, self.width()))) * src.seconds
|
||||||
|
|
||||||
|
def mousePressEvent(self, event):
|
||||||
|
if event.button() == Qt.MouseButton.LeftButton and self.view.deck.source is not None:
|
||||||
|
self._dragging = True
|
||||||
|
self.shelf.jump(self.view, self._seconds_at(event.position().x()))
|
||||||
|
|
||||||
|
def mouseMoveEvent(self, event):
|
||||||
|
if self._dragging:
|
||||||
|
self.shelf.jump(self.view, self._seconds_at(event.position().x()))
|
||||||
|
|
||||||
|
def mouseReleaseEvent(self, event):
|
||||||
|
self._dragging = False
|
||||||
|
|
||||||
|
def paintEvent(self, event):
|
||||||
|
p = QPainter(self)
|
||||||
|
rect = QRectF(self.rect())
|
||||||
|
path = QPainterPath()
|
||||||
|
path.addRoundedRect(rect, 6, 6)
|
||||||
|
p.fillPath(path, QColor("#1d1e20"))
|
||||||
|
view = self.view
|
||||||
|
src = view.deck.source
|
||||||
|
if src is None or view.peaks is None or len(view.peaks) == 0:
|
||||||
|
p.setPen(QColor("#5a5a5a"))
|
||||||
|
p.drawText(rect, int(Qt.AlignmentFlag.AlignCenter), f"Deck {view.name}")
|
||||||
|
return
|
||||||
|
w = max(1, self.width())
|
||||||
|
values = self._values(w)
|
||||||
|
mid = rect.center().y()
|
||||||
|
half = rect.height() / 2 - 6
|
||||||
|
heard = self.shelf.heard_seconds(view)
|
||||||
|
at = heard / max(src.seconds, 1e-6) * w
|
||||||
|
played, ahead = QColor(view.color), QColor(view.color).darker(150)
|
||||||
|
for x in range(w):
|
||||||
|
y = float(values[x]) * half
|
||||||
|
if y <= 0.4:
|
||||||
|
continue
|
||||||
|
p.setPen(played if x < at else ahead)
|
||||||
|
p.drawLine(QPointF(x + 0.5, mid - y), QPointF(x + 0.5, mid + y))
|
||||||
|
loop = view.deck.loop
|
||||||
|
if loop is not None:
|
||||||
|
x0 = loop[0] / RATE / src.seconds * w
|
||||||
|
x1 = loop[1] / RATE / src.seconds * w
|
||||||
|
band = QColor(view.color)
|
||||||
|
band.setAlpha(70)
|
||||||
|
p.fillRect(QRectF(x0, 0, max(2.0, x1 - x0), rect.height()), band)
|
||||||
|
p.setPen(QPen(QColor("white"), 2))
|
||||||
|
p.drawLine(QPointF(at, 0), QPointF(at, rect.height()))
|
||||||
|
p.setPen(QColor(view.color))
|
||||||
|
p.drawText(rect.adjusted(8, 3, -8, -3),
|
||||||
|
int(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignTop),
|
||||||
|
f"{_clock(heard)}")
|
||||||
|
p.drawText(rect.adjusted(8, 3, -8, -3),
|
||||||
|
int(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignTop),
|
||||||
|
f"-{_clock(max(0.0, src.seconds - heard))}")
|
||||||
|
|
||||||
|
|
||||||
|
def _clock(seconds: float) -> str:
|
||||||
|
seconds = int(seconds)
|
||||||
|
return f"{seconds // 60}:{seconds % 60:02d}"
|
||||||
|
|
||||||
|
|
||||||
|
LOOP_SIZES = (1 / 32, 1 / 16, 1 / 8, 1 / 4, 1 / 2, 1, 2, 4, 8)
|
||||||
|
|
||||||
|
|
||||||
|
def _loop_label(beats: float) -> str:
|
||||||
|
return f"1/{round(1 / beats)}" if beats < 1 else f"{int(beats)}"
|
||||||
|
|
||||||
|
|
||||||
|
class SlideOverlay(QWidget):
|
||||||
|
"""The DJ shelf's open/close animation: a picture sliding over the real,
|
||||||
|
already-final window. Opening, the old lists picture slides down by
|
||||||
|
``shift``, uncovering the live decks above it. Closing, the picture's
|
||||||
|
top ``shift`` (the shelf) stays put while the rest (the lists) slides
|
||||||
|
up over it, uncovering the real lists below."""
|
||||||
|
|
||||||
|
def __init__(self, parent, picture, shift: int, opening: bool):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.picture = picture
|
||||||
|
self.shift = shift
|
||||||
|
self.opening = opening
|
||||||
|
self.progress = 0.0
|
||||||
|
self.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents)
|
||||||
|
|
||||||
|
def set_progress(self, value):
|
||||||
|
self.progress = float(value)
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def paintEvent(self, event):
|
||||||
|
p = QPainter(self)
|
||||||
|
pic = self.picture
|
||||||
|
ratio = pic.devicePixelRatio() or 1.0
|
||||||
|
w = pic.width() / ratio
|
||||||
|
h = pic.height() / ratio
|
||||||
|
if self.opening:
|
||||||
|
y = round(self.shift * self.progress)
|
||||||
|
p.drawPixmap(QPointF(0, y), pic)
|
||||||
|
# the top half's shadow, cast on the decks as they appear
|
||||||
|
if y > 0:
|
||||||
|
shade = QLinearGradient(0, 0, 0, 12)
|
||||||
|
shade.setColorAt(0, QColor(0, 0, 0, 140))
|
||||||
|
shade.setColorAt(1, QColor(0, 0, 0, 0))
|
||||||
|
p.fillRect(QRectF(0, 0, w, min(12, y)), QBrush(shade))
|
||||||
|
else:
|
||||||
|
top = int(self.shift * ratio)
|
||||||
|
shelf = pic.copy(0, 0, pic.width(), top)
|
||||||
|
rest = pic.copy(0, top, pic.width(), pic.height() - top)
|
||||||
|
shelf.setDevicePixelRatio(ratio)
|
||||||
|
rest.setDevicePixelRatio(ratio)
|
||||||
|
y = round(self.shift * (1.0 - self.progress))
|
||||||
|
p.drawPixmap(QPointF(0, 0), shelf)
|
||||||
|
p.drawPixmap(QPointF(0, y), rest)
|
||||||
|
|
||||||
|
|
||||||
class Grip(QWidget):
|
class Grip(QWidget):
|
||||||
"""The shelf's bottom edge: drag to resize, double-click for the default."""
|
"""The shelf's bottom edge: drag to resize, double-click for the default."""
|
||||||
|
|
||||||
@@ -939,13 +1096,15 @@ class DjShelf(QWidget):
|
|||||||
self.pitch_boxes = {}
|
self.pitch_boxes = {}
|
||||||
self.mult_buttons = {}
|
self.mult_buttons = {}
|
||||||
self.start_buttons = {}
|
self.start_buttons = {}
|
||||||
|
self.loop_buttons = {}
|
||||||
|
self.loop_sizes = {}
|
||||||
self._compact_hidden = []
|
self._compact_hidden = []
|
||||||
self._big_records = {}
|
self._big_records = {}
|
||||||
|
|
||||||
def fader_title(text, v):
|
def fader_title(text, v):
|
||||||
label = QLabel(text)
|
label = QLabel(text)
|
||||||
label.setStyleSheet(f"color: {v.color.name()}; font-size: 10px;"
|
label.setStyleSheet(f"color: {v.color.name()}; font-size: 9px;"
|
||||||
" font-weight: bold; letter-spacing: 1px;")
|
" font-weight: bold;")
|
||||||
return label
|
return label
|
||||||
|
|
||||||
def volume_col(v):
|
def volume_col(v):
|
||||||
@@ -975,7 +1134,7 @@ class DjShelf(QWidget):
|
|||||||
col.addWidget(label, alignment=Qt.AlignmentFlag.AlignHCenter)
|
col.addWidget(label, alignment=Qt.AlignmentFlag.AlignHCenter)
|
||||||
holder = QWidget()
|
holder = QWidget()
|
||||||
holder.setLayout(col)
|
holder.setLayout(col)
|
||||||
holder.setFixedWidth(64)
|
holder.setFixedWidth(58)
|
||||||
self.volume[v.name] = slider
|
self.volume[v.name] = slider
|
||||||
self._compact_hidden.append(holder)
|
self._compact_hidden.append(holder)
|
||||||
return holder
|
return holder
|
||||||
@@ -995,7 +1154,7 @@ class DjShelf(QWidget):
|
|||||||
label = QLabel("+0.0%")
|
label = QLabel("+0.0%")
|
||||||
label.setStyleSheet(f"color: {v.color.name()}; font-size: 11px;")
|
label.setStyleSheet(f"color: {v.color.name()}; font-size: 11px;")
|
||||||
label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||||
label.setMinimumWidth(60)
|
label.setMinimumWidth(54)
|
||||||
for w in (top, bottom):
|
for w in (top, bottom):
|
||||||
w.setStyleSheet(f"color: {DIM}; font-size: 10px;")
|
w.setStyleSheet(f"color: {DIM}; font-size: 10px;")
|
||||||
for w in (top, slider, bottom, label):
|
for w in (top, slider, bottom, label):
|
||||||
@@ -1003,98 +1162,84 @@ class DjShelf(QWidget):
|
|||||||
col.setStretch(2, 1)
|
col.setStretch(2, 1)
|
||||||
holder = QWidget()
|
holder = QWidget()
|
||||||
holder.setLayout(col)
|
holder.setLayout(col)
|
||||||
holder.setFixedWidth(64)
|
holder.setFixedWidth(58)
|
||||||
self.speed[v.name] = slider
|
self.speed[v.name] = slider
|
||||||
self.speed_label[v.name] = label
|
self.speed_label[v.name] = label
|
||||||
self._compact_hidden.append(holder)
|
self._compact_hidden.append(holder)
|
||||||
return holder
|
return holder
|
||||||
|
|
||||||
def deck_col(v):
|
def record_col(v):
|
||||||
holder = QWidget()
|
|
||||||
col = QVBoxLayout(holder)
|
|
||||||
col.setContentsMargins(0, 0, 0, 0)
|
|
||||||
col.setSpacing(8)
|
|
||||||
record = RecordWidget(v, self)
|
record = RecordWidget(v, self)
|
||||||
record.dropped.connect(lambda tid, v=v: self._on_drop(v, tid))
|
record.dropped.connect(lambda tid, v=v: self._on_drop(v, tid))
|
||||||
record.toggled.connect(lambda v=v: self.toggle(v))
|
record.toggled.connect(lambda v=v: self.toggle(v))
|
||||||
self.records[v.name] = record
|
self.records[v.name] = record
|
||||||
col.addWidget(record, stretch=1)
|
record.setFixedWidth(RECORD_SIZE)
|
||||||
controls = QWidget()
|
self._big_records[v.name] = record
|
||||||
buttons = QHBoxLayout(controls)
|
return record
|
||||||
buttons.setContentsMargins(0, 0, 0, 0)
|
|
||||||
buttons.setSpacing(8)
|
|
||||||
back = QToolButton()
|
|
||||||
back.setIcon(QIcon(_start_icon()))
|
|
||||||
back.setIconSize(QSize(16, 16))
|
|
||||||
back.setFixedSize(34, 34)
|
|
||||||
back.setToolTip(f"Deck {v.name}: back to the beginning")
|
|
||||||
back.clicked.connect(lambda _=False, v=v: self.to_start(v))
|
|
||||||
back.setStyleSheet(_deck_button_qss(v.name))
|
|
||||||
back.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
|
||||||
buttons.addWidget(back)
|
|
||||||
self.start_buttons[v.name] = back
|
|
||||||
play = QToolButton()
|
|
||||||
play.setIcon(QIcon(_play_icon(False)))
|
|
||||||
play.setIconSize(QSize(16, 16))
|
|
||||||
play.setFixedSize(46, 34)
|
|
||||||
play.setToolTip(f"Play / pause Deck {v.name}")
|
|
||||||
play.clicked.connect(lambda _=False, v=v: self.toggle(v))
|
|
||||||
sync = QPushButton("Sync to other track")
|
|
||||||
sync.setFixedHeight(34)
|
|
||||||
sync.setToolTip("Match the other deck's tempo; while both play, "
|
|
||||||
"also line up the beats (the smallest nudge)")
|
|
||||||
sync.clicked.connect(lambda _=False, v=v: self.sync(v))
|
|
||||||
for w in (play, sync):
|
|
||||||
w.setStyleSheet(_deck_button_qss(v.name))
|
|
||||||
w.setFocusPolicy(Qt.FocusPolicy.NoFocus) # Space/Return mean nothing here
|
|
||||||
buttons.addWidget(play)
|
|
||||||
buttons.addWidget(sync, stretch=1)
|
|
||||||
self.play_buttons[v.name] = play
|
|
||||||
self.sync_buttons[v.name] = sync
|
|
||||||
col.addWidget(controls)
|
|
||||||
vocals = QWidget()
|
|
||||||
vcol = QVBoxLayout(vocals)
|
|
||||||
vcol.setContentsMargins(0, 0, 0, 0)
|
|
||||||
vcol.setSpacing(2)
|
|
||||||
slider = VocalSlider(v.color)
|
|
||||||
slider.valueChanged.connect(lambda value, v=v: setattr(v.deck, "vocal_mix", value / 100))
|
|
||||||
vcol.addWidget(slider)
|
|
||||||
note = QLabel("")
|
|
||||||
note.setStyleSheet(f"color: {DIM}; font-size: 10px;")
|
|
||||||
vcol.addWidget(note)
|
|
||||||
self.vocal_sliders[v.name] = slider
|
|
||||||
self.stem_labels[v.name] = note
|
|
||||||
col.addWidget(vocals)
|
|
||||||
self._compact_hidden += [controls, vocals]
|
|
||||||
holder.setFixedWidth(DECK_WIDTH)
|
|
||||||
self._big_records[v.name] = holder
|
|
||||||
return holder
|
|
||||||
|
|
||||||
def info_row(v):
|
def controls_col(v, right: bool):
|
||||||
line = QHBoxLayout()
|
"""Everything a deck has besides its record and faders, facing
|
||||||
line.setSpacing(12)
|
the middle: what's loaded, its tempo, the transport, loops,
|
||||||
texts = QVBoxLayout()
|
vocals."""
|
||||||
texts.setSpacing(0)
|
align = Qt.AlignmentFlag.AlignRight if right else Qt.AlignmentFlag.AlignLeft
|
||||||
|
holder = QWidget()
|
||||||
|
col = QVBoxLayout(holder)
|
||||||
|
col.setContentsMargins(0, 0, 0, 0)
|
||||||
|
col.setSpacing(5)
|
||||||
state = QLabel(f"DECK {v.name}")
|
state = QLabel(f"DECK {v.name}")
|
||||||
state.setStyleSheet(f"color: {v.color.name()}; font-size: 10px; letter-spacing: 1px;")
|
state.setStyleSheet(f"color: {v.color.name()}; font-size: 10px; letter-spacing: 1px;")
|
||||||
title = QLabel("")
|
title = QLabel("")
|
||||||
title.setStyleSheet(f"color: {TEXT}; font-size: 14px;")
|
title.setStyleSheet(f"color: {TEXT}; font-size: 14px;")
|
||||||
title.setTextFormat(Qt.TextFormat.RichText)
|
title.setTextFormat(Qt.TextFormat.RichText)
|
||||||
texts.addWidget(state)
|
for w in (state, title):
|
||||||
texts.addWidget(title)
|
w.setAlignment(align)
|
||||||
line.addLayout(texts, stretch=1)
|
col.addWidget(w)
|
||||||
nums = QVBoxLayout()
|
nums = QHBoxLayout()
|
||||||
nums.setSpacing(0)
|
nums.setSpacing(8)
|
||||||
bpm = QLabel("–")
|
bpm = QLabel("–")
|
||||||
bpm.setAlignment(Qt.AlignmentFlag.AlignRight)
|
|
||||||
bpm.setStyleSheet(f"color: {v.color.name()}; font-size: 22px; font-weight: bold;")
|
bpm.setStyleSheet(f"color: {v.color.name()}; font-size: 22px; font-weight: bold;")
|
||||||
note = QLabel("BPM")
|
note = QLabel("BPM")
|
||||||
note.setAlignment(Qt.AlignmentFlag.AlignRight)
|
|
||||||
note.setStyleSheet(f"color: {DIM}; font-size: 10px;")
|
note.setStyleSheet(f"color: {DIM}; font-size: 10px;")
|
||||||
|
note.setAlignment(Qt.AlignmentFlag.AlignBottom)
|
||||||
|
if right:
|
||||||
|
nums.addStretch(1)
|
||||||
|
nums.addWidget(note)
|
||||||
|
nums.addWidget(bpm)
|
||||||
|
else:
|
||||||
nums.addWidget(bpm)
|
nums.addWidget(bpm)
|
||||||
nums.addWidget(note)
|
nums.addWidget(note)
|
||||||
line.addLayout(nums)
|
nums.addStretch(1)
|
||||||
line.addWidget(self._mult_switch(v))
|
col.addLayout(nums)
|
||||||
|
|
||||||
|
buttons = QHBoxLayout()
|
||||||
|
buttons.setSpacing(6)
|
||||||
|
back = QToolButton()
|
||||||
|
back.setIcon(QIcon(_start_icon()))
|
||||||
|
back.setIconSize(QSize(16, 16))
|
||||||
|
back.setFixedSize(34, 32)
|
||||||
|
back.setToolTip(f"Deck {v.name}: back to the beginning")
|
||||||
|
back.clicked.connect(lambda _=False, v=v: self.to_start(v))
|
||||||
|
play = QToolButton()
|
||||||
|
play.setIcon(QIcon(_play_icon(False)))
|
||||||
|
play.setIconSize(QSize(16, 16))
|
||||||
|
play.setFixedSize(44, 32)
|
||||||
|
play.setToolTip(f"Play / pause Deck {v.name}")
|
||||||
|
play.clicked.connect(lambda _=False, v=v: self.toggle(v))
|
||||||
|
sync = QPushButton("Sync to other track")
|
||||||
|
sync.setFixedHeight(32)
|
||||||
|
sync.setToolTip("Set this deck to the other deck's tempo now; while "
|
||||||
|
"both play, line the beats up too (the smallest nudge)")
|
||||||
|
sync.clicked.connect(lambda _=False, v=v: self.sync(v))
|
||||||
|
for w in (back, play, sync):
|
||||||
|
w.setStyleSheet(_deck_button_qss(v.name))
|
||||||
|
w.setFocusPolicy(Qt.FocusPolicy.NoFocus) # Space/Return mean nothing here
|
||||||
|
row_widgets = [back, play, sync]
|
||||||
|
for w in (reversed(row_widgets) if right else row_widgets):
|
||||||
|
buttons.addWidget(w, stretch=1 if w is sync else 0)
|
||||||
|
col.addLayout(buttons)
|
||||||
|
|
||||||
|
extras = QHBoxLayout()
|
||||||
|
extras.setSpacing(8)
|
||||||
pitch = QCheckBox("Keep pitch")
|
pitch = QCheckBox("Keep pitch")
|
||||||
pitch.setChecked(True)
|
pitch.setChecked(True)
|
||||||
pitch.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
pitch.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
||||||
@@ -1102,19 +1247,51 @@ class DjShelf(QWidget):
|
|||||||
pitch.setToolTip("On: a faster song stays in its key. Off: pitch "
|
pitch.setToolTip("On: a faster song stays in its key. Off: pitch "
|
||||||
"follows speed, like a turntable")
|
"follows speed, like a turntable")
|
||||||
pitch.toggled.connect(lambda on, v=v: setattr(v.deck, "keep_pitch", on))
|
pitch.toggled.connect(lambda on, v=v: setattr(v.deck, "keep_pitch", on))
|
||||||
line.addWidget(pitch)
|
mult = self._mult_switch(v)
|
||||||
|
loop = self._loop_controls(v)
|
||||||
|
for line, parts in ((extras, [mult, pitch]), (QHBoxLayout(), [loop])):
|
||||||
|
line.setSpacing(8)
|
||||||
|
if right:
|
||||||
|
line.addStretch(1)
|
||||||
|
parts.reverse()
|
||||||
|
for w in parts:
|
||||||
|
line.addWidget(w)
|
||||||
|
if not right:
|
||||||
|
line.addStretch(1)
|
||||||
|
col.addLayout(line)
|
||||||
|
|
||||||
|
slider = VocalSlider(v.color)
|
||||||
|
slider.valueChanged.connect(lambda value, v=v: setattr(v.deck, "vocal_mix", value / 100))
|
||||||
|
col.addWidget(slider)
|
||||||
|
stem = QLabel("")
|
||||||
|
stem.setStyleSheet(f"color: {DIM}; font-size: 10px;")
|
||||||
|
stem.setAlignment(align)
|
||||||
|
col.addWidget(stem)
|
||||||
|
col.addStretch(1)
|
||||||
|
|
||||||
self.titles[v.name] = title
|
self.titles[v.name] = title
|
||||||
self.states[v.name] = state
|
self.states[v.name] = state
|
||||||
self.bpm_labels[v.name] = bpm
|
self.bpm_labels[v.name] = bpm
|
||||||
self.bpm_notes[v.name] = note
|
self.bpm_notes[v.name] = note
|
||||||
self.pitch_boxes[v.name] = pitch
|
self.pitch_boxes[v.name] = pitch
|
||||||
self._compact_hidden += [pitch, note]
|
self.start_buttons[v.name] = back
|
||||||
return line
|
self.play_buttons[v.name] = play
|
||||||
|
self.sync_buttons[v.name] = sync
|
||||||
|
self.vocal_sliders[v.name] = slider
|
||||||
|
self.stem_labels[v.name] = stem
|
||||||
|
holder.setFixedWidth(CONTROLS_WIDTH)
|
||||||
|
self._compact_hidden.append(holder)
|
||||||
|
return holder
|
||||||
|
|
||||||
a, b = self.views
|
a, b = self.views
|
||||||
row.addWidget(volume_col(a))
|
row.addWidget(volume_col(a))
|
||||||
row.addWidget(speed_col(a))
|
row.addWidget(speed_col(a))
|
||||||
row.addWidget(deck_col(a))
|
middle = QVBoxLayout()
|
||||||
|
middle.setSpacing(10)
|
||||||
|
top = QHBoxLayout()
|
||||||
|
top.setSpacing(14)
|
||||||
|
top.addWidget(record_col(a))
|
||||||
|
top.addWidget(controls_col(a, right=False))
|
||||||
centre = QVBoxLayout()
|
centre = QVBoxLayout()
|
||||||
centre.setSpacing(6)
|
centre.setSpacing(6)
|
||||||
horn_row = QHBoxLayout()
|
horn_row = QHBoxLayout()
|
||||||
@@ -1124,29 +1301,36 @@ class DjShelf(QWidget):
|
|||||||
horn_row.addStretch(1)
|
horn_row.addStretch(1)
|
||||||
centre.addLayout(horn_row)
|
centre.addLayout(horn_row)
|
||||||
self._compact_hidden.append(self.horn)
|
self._compact_hidden.append(self.horn)
|
||||||
centre.addLayout(info_row(a))
|
|
||||||
self.lanes = WaveLanes(self)
|
self.lanes = WaveLanes(self)
|
||||||
centre.addWidget(self.lanes, stretch=1)
|
centre.addWidget(self.lanes, stretch=1)
|
||||||
centre.addLayout(info_row(b))
|
top.addLayout(centre, stretch=1)
|
||||||
fader = QHBoxLayout()
|
top.addWidget(controls_col(b, right=True))
|
||||||
fader.setContentsMargins(0, 2, 0, 4)
|
top.addWidget(record_col(b))
|
||||||
fader.addStretch(1)
|
middle.addLayout(top, stretch=1)
|
||||||
|
|
||||||
|
bottom = QHBoxLayout()
|
||||||
|
bottom.setSpacing(14)
|
||||||
|
self.overviews = {}
|
||||||
|
for v in (a, b):
|
||||||
|
ov = OverviewWave(v, self)
|
||||||
|
self.overviews[v.name] = ov
|
||||||
|
self._compact_hidden.append(ov)
|
||||||
|
bottom.addWidget(self.overviews["A"], stretch=1)
|
||||||
left = QLabel("A")
|
left = QLabel("A")
|
||||||
left.setStyleSheet(f"color: {COLORS['A'].name()}; font-weight: bold;")
|
left.setStyleSheet(f"color: {COLORS['A'].name()}; font-weight: bold;")
|
||||||
right = QLabel("B")
|
right_label = QLabel("B")
|
||||||
right.setStyleSheet(f"color: {COLORS['B'].name()}; font-weight: bold;")
|
right_label.setStyleSheet(f"color: {COLORS['B'].name()}; font-weight: bold;")
|
||||||
self.crossfader = Crossfader()
|
self.crossfader = Crossfader()
|
||||||
|
self.crossfader.setFixedWidth(CROSSFADER_WIDTH)
|
||||||
self.crossfader.valueChanged.connect(lambda value: setattr(self.mixer, "crossfader", value / 1000))
|
self.crossfader.valueChanged.connect(lambda value: setattr(self.mixer, "crossfader", value / 1000))
|
||||||
fader.addWidget(left)
|
bottom.addWidget(left)
|
||||||
fader.addWidget(self.crossfader, stretch=3)
|
bottom.addWidget(self.crossfader)
|
||||||
fader.addWidget(right)
|
bottom.addWidget(right_label)
|
||||||
fader.addStretch(1)
|
bottom.addWidget(self.overviews["B"], stretch=1)
|
||||||
centre.addLayout(fader)
|
middle.addLayout(bottom)
|
||||||
row.addLayout(centre, stretch=1)
|
row.addLayout(middle, stretch=1)
|
||||||
row.addWidget(deck_col(b))
|
|
||||||
row.addWidget(speed_col(b))
|
row.addWidget(speed_col(b))
|
||||||
row.addWidget(volume_col(b))
|
row.addWidget(volume_col(b))
|
||||||
self._small_records = {}
|
|
||||||
for v in self.views:
|
for v in self.views:
|
||||||
self._refresh_deck(v)
|
self._refresh_deck(v)
|
||||||
|
|
||||||
@@ -1189,6 +1373,95 @@ class DjShelf(QWidget):
|
|||||||
self.mult_buttons[v.name] = group
|
self.mult_buttons[v.name] = group
|
||||||
return box
|
return box
|
||||||
|
|
||||||
|
def _loop_controls(self, v):
|
||||||
|
"""Loop (on/off) and ‹ size › in beats: 1/32 … 8."""
|
||||||
|
box = QWidget()
|
||||||
|
row = QHBoxLayout(box)
|
||||||
|
row.setContentsMargins(0, 0, 0, 0)
|
||||||
|
row.setSpacing(0)
|
||||||
|
loop = QToolButton()
|
||||||
|
loop.setText("Loop")
|
||||||
|
loop.setCheckable(True)
|
||||||
|
loop.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
||||||
|
loop.setToolTip("Loop from the next beat, for the length beside it; "
|
||||||
|
"click again to play on past it")
|
||||||
|
loop.setFixedHeight(24)
|
||||||
|
loop.setMinimumWidth(52)
|
||||||
|
loop.clicked.connect(lambda on, v=v: self.set_loop(v, on))
|
||||||
|
less = QToolButton()
|
||||||
|
less.setText("‹")
|
||||||
|
more = QToolButton()
|
||||||
|
more.setText("›")
|
||||||
|
size = QLabel(_loop_label(v.loop_beats))
|
||||||
|
size.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
||||||
|
size.setFixedWidth(30)
|
||||||
|
size.setStyleSheet(f"color: {TEXT}; background: #1b1b1c; font-size: 11px;"
|
||||||
|
" border-top: 1px solid #111; border-bottom: 1px solid #111;")
|
||||||
|
size.setFixedHeight(24)
|
||||||
|
for b, step in ((less, -1), (more, 1)):
|
||||||
|
b.setFixedSize(18, 24)
|
||||||
|
b.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
||||||
|
b.clicked.connect(lambda _=False, v=v, step=step: self.step_loop(v, step))
|
||||||
|
top, bottom = FACES[v.name]
|
||||||
|
loop.setStyleSheet(
|
||||||
|
f"QToolButton {{ color: #e8e8e8; border: 1px solid #111; border-radius: 5px;"
|
||||||
|
f" background: #3a3b3d; padding: 0 8px; margin-right: 4px; }}"
|
||||||
|
f"QToolButton:hover {{ background: #46474a; }}"
|
||||||
|
f"QToolButton:checked {{ color: white; font-weight: bold; background: qlineargradient("
|
||||||
|
f"x1:0,y1:0,x2:0,y2:1, stop:0 {COLORS[v.name].name()}, stop:1 {bottom});"
|
||||||
|
f" border: 1px solid {COLORS[v.name].lighter(140).name()}; }}")
|
||||||
|
stepper = ("QToolButton {{ color: #cfcfcf; border: 1px solid #111; background: #3a3b3d;"
|
||||||
|
" padding: 0; {0} }} QToolButton:hover {{ background: #46474a; }}"
|
||||||
|
" QToolButton:pressed {{ background: #2a2b2d; }}")
|
||||||
|
less.setStyleSheet(stepper.format("border-top-left-radius: 5px; border-bottom-left-radius: 5px;"))
|
||||||
|
more.setStyleSheet(stepper.format("border-top-right-radius: 5px; border-bottom-right-radius: 5px;"))
|
||||||
|
for w in (loop, less, size, more):
|
||||||
|
row.addWidget(w)
|
||||||
|
self.loop_buttons[v.name] = loop
|
||||||
|
self.loop_sizes[v.name] = size
|
||||||
|
return box
|
||||||
|
|
||||||
|
def _beat(self, view: DeckView) -> float | None:
|
||||||
|
return 60.0 / view.beat_bpm if view.beat_bpm else None
|
||||||
|
|
||||||
|
def set_loop(self, view: DeckView, on: bool):
|
||||||
|
"""Loop on: from the next beat, ``loop_beats`` long. Off: playback
|
||||||
|
carries on past the loop's end."""
|
||||||
|
deck = view.deck
|
||||||
|
beat = self._beat(view)
|
||||||
|
if not on or deck.source is None or beat is None:
|
||||||
|
deck.loop = None
|
||||||
|
self.loop_buttons[view.name].setChecked(False)
|
||||||
|
if on and beat is None and deck.source is not None:
|
||||||
|
self.message.emit("A loop needs the song's beat, and none was found.")
|
||||||
|
return
|
||||||
|
now = self.heard_seconds(view)
|
||||||
|
k = math.ceil((now - view.offset) / beat - 1e-6)
|
||||||
|
start = view.offset + k * beat
|
||||||
|
self._place_loop(view, start)
|
||||||
|
self.loop_buttons[view.name].setChecked(True)
|
||||||
|
|
||||||
|
def _place_loop(self, view: DeckView, start_s: float):
|
||||||
|
beat = self._beat(view)
|
||||||
|
length = view.loop_beats * beat
|
||||||
|
view.deck.loop = (int(round(start_s * RATE)), int(round((start_s + length) * RATE)))
|
||||||
|
|
||||||
|
def step_loop(self, view: DeckView, step: int):
|
||||||
|
i = LOOP_SIZES.index(view.loop_beats) if view.loop_beats in LOOP_SIZES else 7
|
||||||
|
view.loop_beats = LOOP_SIZES[max(0, min(len(LOOP_SIZES) - 1, i + step))]
|
||||||
|
self.loop_sizes[view.name].setText(_loop_label(view.loop_beats))
|
||||||
|
if view.deck.loop is not None and self._beat(view):
|
||||||
|
# a running loop keeps its start and takes the new length
|
||||||
|
self._place_loop(view, view.deck.loop[0] / RATE)
|
||||||
|
|
||||||
|
def jump(self, view: DeckView, seconds: float):
|
||||||
|
"""Move the playhead to ``seconds`` (the overview's click/drag)."""
|
||||||
|
deck = view.deck
|
||||||
|
if deck.source is None:
|
||||||
|
return
|
||||||
|
deck.seek(seconds * RATE)
|
||||||
|
deck.ended = False
|
||||||
|
|
||||||
def set_mult(self, view: DeckView, mult: float):
|
def set_mult(self, view: DeckView, mult: float):
|
||||||
changed = mult != view.mult
|
changed = mult != view.mult
|
||||||
view.mult = mult
|
view.mult = mult
|
||||||
@@ -1222,8 +1495,8 @@ class DjShelf(QWidget):
|
|||||||
self._compact = compact
|
self._compact = compact
|
||||||
for w in self._compact_hidden:
|
for w in self._compact_hidden:
|
||||||
w.setVisible(not compact)
|
w.setVisible(not compact)
|
||||||
for holder in self._big_records.values():
|
for record in self._big_records.values():
|
||||||
holder.setFixedWidth(max(60, height - 30) if compact else DECK_WIDTH)
|
record.setFixedWidth(max(60, height - 30) if compact else RECORD_SIZE)
|
||||||
|
|
||||||
def resizeEvent(self, event):
|
def resizeEvent(self, event):
|
||||||
super().resizeEvent(event)
|
super().resizeEvent(event)
|
||||||
@@ -1334,6 +1607,8 @@ class DjShelf(QWidget):
|
|||||||
self.speed[view.name].setValue(0)
|
self.speed[view.name].setValue(0)
|
||||||
self.vocal_sliders[view.name].setValue(0)
|
self.vocal_sliders[view.name].setValue(0)
|
||||||
self.set_mult(view, 1.0)
|
self.set_mult(view, 1.0)
|
||||||
|
if view.name in self.loop_buttons:
|
||||||
|
self.loop_buttons[view.name].setChecked(False)
|
||||||
try:
|
try:
|
||||||
art = tagging.read_embedded_artwork(track.location)
|
art = tagging.read_embedded_artwork(track.location)
|
||||||
except Exception: # noqa: BLE001 — art is never worth a failure
|
except Exception: # noqa: BLE001 — art is never worth a failure
|
||||||
@@ -1440,9 +1715,11 @@ class DjShelf(QWidget):
|
|||||||
target = other.beat_bpm * other.deck.speed
|
target = other.beat_bpm * other.deck.speed
|
||||||
view.deck.speed = analysis.sync_speed(view.beat_bpm, target)
|
view.deck.speed = analysis.sync_speed(view.beat_bpm, target)
|
||||||
self._show_speed(view)
|
self._show_speed(view)
|
||||||
# Sync stays on: this deck follows the other's tempo until its own
|
# Sync *sets* this deck to the other's tempo, once. It stays lit
|
||||||
# tempo fader is moved. Only one deck follows the other.
|
# while that still holds; the other deck loading a new song, or
|
||||||
|
# either tempo moving, leaves this tempo where it is, unlit.
|
||||||
view.synced = True
|
view.synced = True
|
||||||
|
view.synced_to = other.track.track_id if other.track else None
|
||||||
if other.synced:
|
if other.synced:
|
||||||
other.synced = False
|
other.synced = False
|
||||||
self._refresh_deck(other)
|
self._refresh_deck(other)
|
||||||
@@ -1464,15 +1741,18 @@ class DjShelf(QWidget):
|
|||||||
view.synced = False # taken out of sync by hand
|
view.synced = False # taken out of sync by hand
|
||||||
self._refresh_deck(view)
|
self._refresh_deck(view)
|
||||||
|
|
||||||
def _follow(self, view: DeckView):
|
def _check_sync(self, view: DeckView):
|
||||||
"""A synced deck keeps the other's tempo as that one changes."""
|
"""Unlight Sync once it no longer holds: the other deck has another
|
||||||
other = self.other(view)
|
song, or the tempos have drifted apart."""
|
||||||
if not view.synced or not view.beat_bpm or not other.beat_bpm:
|
if not view.synced:
|
||||||
return
|
return
|
||||||
speed = analysis.sync_speed(view.beat_bpm, other.beat_bpm * other.deck.speed)
|
other = self.other(view)
|
||||||
if abs(speed - view.deck.speed) > 1e-5:
|
same_song = other.track is not None and other.track.track_id == view.synced_to
|
||||||
view.deck.speed = speed
|
matches = (view.beat_bpm and other.beat_bpm and abs(
|
||||||
self._show_speed(view)
|
analysis.sync_speed(view.beat_bpm, other.beat_bpm * other.deck.speed)
|
||||||
|
- view.deck.speed) < 1e-4)
|
||||||
|
if not (same_song and matches):
|
||||||
|
view.synced = False
|
||||||
self._refresh_deck(view)
|
self._refresh_deck(view)
|
||||||
|
|
||||||
def to_start(self, view: DeckView):
|
def to_start(self, view: DeckView):
|
||||||
@@ -1552,7 +1832,7 @@ class DjShelf(QWidget):
|
|||||||
viz.dj_playing_changed()
|
viz.dj_playing_changed()
|
||||||
self._sounding = sounding
|
self._sounding = sounding
|
||||||
for v in self.views:
|
for v in self.views:
|
||||||
self._follow(v)
|
self._check_sync(v)
|
||||||
for v in self.views:
|
for v in self.views:
|
||||||
deck = v.deck
|
deck = v.deck
|
||||||
if deck.ended and not v.counted and v.track is not None:
|
if deck.ended and not v.counted and v.track is not None:
|
||||||
@@ -1565,6 +1845,8 @@ class DjShelf(QWidget):
|
|||||||
if deck.playing or deck.scratch_rate is not None:
|
if deck.playing or deck.scratch_rate is not None:
|
||||||
self._refresh_bpm_only(v)
|
self._refresh_bpm_only(v)
|
||||||
self.lanes.update()
|
self.lanes.update()
|
||||||
|
for overview in self.overviews.values():
|
||||||
|
overview.update()
|
||||||
|
|
||||||
def _refresh_bpm_only(self, view: DeckView):
|
def _refresh_bpm_only(self, view: DeckView):
|
||||||
if view.beat_bpm:
|
if view.beat_bpm:
|
||||||
@@ -1593,7 +1875,7 @@ def _esc(text: str) -> str:
|
|||||||
return (text or "").replace("&", "&").replace("<", "<").replace(">", ">")
|
return (text or "").replace("&", "&").replace("<", "<").replace(">", ">")
|
||||||
|
|
||||||
|
|
||||||
FULL_HEIGHT = 320 # the whole layout, comfortably
|
FULL_HEIGHT = 380 # the whole layout, comfortably
|
||||||
|
|
||||||
|
|
||||||
def default_height(viewport_height: int, row_height: int, rows_below=DEFAULT_ROWS_BELOW) -> int:
|
def default_height(viewport_height: int, row_height: int, rows_below=DEFAULT_ROWS_BELOW) -> int:
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from PyQt6.QtWidgets import (
|
|||||||
QPlainTextEdit, QTextEdit, QAbstractSpinBox, QComboBox, QApplication,
|
QPlainTextEdit, QTextEdit, QAbstractSpinBox, QComboBox, QApplication,
|
||||||
QLabel, QMessageBox, QFileDialog, QProgressBar, QPushButton,
|
QLabel, QMessageBox, QFileDialog, QProgressBar, QPushButton,
|
||||||
)
|
)
|
||||||
from PyQt6.QtCore import Qt, QEvent, QObject, QTimer, pyqtSignal
|
from PyQt6.QtCore import QRect, Qt, QEvent, QObject, QTimer, pyqtSignal
|
||||||
from PyQt6.QtGui import QAction, QKeySequence
|
from PyQt6.QtGui import QAction, QKeySequence
|
||||||
|
|
||||||
from lintunes import bpm_detect, device_sync, loudness, music_folder, theme, url_import
|
from lintunes import bpm_detect, device_sync, loudness, music_folder, theme, url_import
|
||||||
@@ -2399,17 +2399,21 @@ class MainWindow(QMainWindow):
|
|||||||
track_table.deck_tag = self._deck_tag
|
track_table.deck_tag = self._deck_tag
|
||||||
shelf.set_master(self._dj_master())
|
shelf.set_master(self._dj_master())
|
||||||
shelf.set_layout_height(target) # laid out full size, revealed
|
shelf.set_layout_height(target) # laid out full size, revealed
|
||||||
shelf.setFixedHeight(0)
|
split, before = self._snapshot_below_boxes()
|
||||||
|
shelf.setFixedHeight(target)
|
||||||
shelf.show()
|
shelf.show()
|
||||||
shelf.start()
|
shelf.start()
|
||||||
shelf.set_visualizer(self._transport._visualizer)
|
shelf.set_visualizer(self._transport._visualizer)
|
||||||
self._sidebar.art.hide() # room for the lists instead
|
self._sidebar.art.hide() # room for the lists instead
|
||||||
self._animate_shelf(0, target)
|
self._slide(split, before, shift=target + self._row_gap(), opening=True)
|
||||||
else:
|
else:
|
||||||
shelf = self._dj
|
shelf = self._dj
|
||||||
track_table.deck_tag = None
|
track_table.deck_tag = None
|
||||||
shelf.set_layout_height(shelf.height()) # covered, not squeezed
|
shelf.set_layout_height(shelf.height()) # covered, not squeezed
|
||||||
self._animate_shelf(shelf.height(), 0, done=self._dj_closed)
|
split, before = self._snapshot_below_boxes(shelf)
|
||||||
|
shift = shelf.height() + self._row_gap()
|
||||||
|
self._dj_closed_now()
|
||||||
|
self._slide(split, before, shift=shift, opening=False)
|
||||||
self._refresh_tables()
|
self._refresh_tables()
|
||||||
|
|
||||||
def _ensure_dj(self):
|
def _ensure_dj(self):
|
||||||
@@ -2473,6 +2477,68 @@ class MainWindow(QMainWindow):
|
|||||||
self._dj_anim = anim
|
self._dj_anim = anim
|
||||||
anim.start()
|
anim.start()
|
||||||
|
|
||||||
|
# ---- the slide (Round 96) ----
|
||||||
|
# Animating the shelf's real height re-laid-out the whole window every
|
||||||
|
# frame — the flicker. Instead the window goes straight to its final
|
||||||
|
# layout and a picture of what was below the transport boxes slides
|
||||||
|
# over it: opening, the old lists slide down off the decks (which are
|
||||||
|
# live underneath); closing, a picture of the shelf stays put while the
|
||||||
|
# lists' picture slides up over it. Only an image moves.
|
||||||
|
|
||||||
|
def _row_gap(self) -> int:
|
||||||
|
from lintunes.gui.transport import ROW_GAP
|
||||||
|
return ROW_GAP
|
||||||
|
|
||||||
|
def _snapshot_below_boxes(self, shelf=None):
|
||||||
|
"""(y in the central widget where the window parts, a picture of
|
||||||
|
everything from there down)."""
|
||||||
|
central = self.centralWidget()
|
||||||
|
anchor = shelf if shelf is not None and shelf.isVisible() else \
|
||||||
|
self._transport._header_row
|
||||||
|
split = anchor.mapTo(central, anchor.rect().topLeft()).y()
|
||||||
|
picture = central.grab(QRect(0, split, central.width(), central.height() - split))
|
||||||
|
return split, picture
|
||||||
|
|
||||||
|
def _slide(self, split: int, picture, shift: int, opening: bool):
|
||||||
|
from PyQt6.QtCore import QEasingCurve, QVariantAnimation
|
||||||
|
from lintunes.gui.dj_shelf import SlideOverlay
|
||||||
|
if self._dj_anim is not None:
|
||||||
|
self._dj_anim.stop()
|
||||||
|
old = getattr(self, "_dj_overlay", None)
|
||||||
|
if old is not None:
|
||||||
|
old.deleteLater()
|
||||||
|
central = self.centralWidget()
|
||||||
|
overlay = SlideOverlay(central, picture, shift, opening)
|
||||||
|
overlay.setGeometry(0, split, central.width(), central.height() - split)
|
||||||
|
overlay.show()
|
||||||
|
overlay.raise_()
|
||||||
|
self._dj_overlay = overlay
|
||||||
|
anim = QVariantAnimation(self)
|
||||||
|
anim.setStartValue(0.0)
|
||||||
|
anim.setEndValue(1.0)
|
||||||
|
anim.setDuration(self.ANIMATE_MS)
|
||||||
|
anim.setEasingCurve(QEasingCurve.Type.OutCubic if opening
|
||||||
|
else QEasingCurve.Type.InOutCubic)
|
||||||
|
anim.valueChanged.connect(overlay.set_progress)
|
||||||
|
|
||||||
|
def finished():
|
||||||
|
overlay.hide()
|
||||||
|
overlay.deleteLater()
|
||||||
|
if getattr(self, "_dj_overlay", None) is overlay:
|
||||||
|
self._dj_overlay = None
|
||||||
|
anim.finished.connect(finished)
|
||||||
|
self._dj_anim = anim
|
||||||
|
anim.start()
|
||||||
|
|
||||||
|
def _dj_closed_now(self):
|
||||||
|
"""Closing, for real (the slide only shows it)."""
|
||||||
|
self._dj.set_visualizer(None)
|
||||||
|
self._dj.stop()
|
||||||
|
self._dj.hide()
|
||||||
|
self._sidebar.art.show()
|
||||||
|
self.player.set_suspended(False)
|
||||||
|
self._transport.set_dj_mode(False)
|
||||||
|
|
||||||
def _dj_closed(self):
|
def _dj_closed(self):
|
||||||
if self._dj_on:
|
if self._dj_on:
|
||||||
return # reopened mid-close
|
return # reopened mid-close
|
||||||
|
|||||||
@@ -155,3 +155,15 @@ def syncthing_pair(tmp_path):
|
|||||||
yield instances
|
yield instances
|
||||||
finally:
|
finally:
|
||||||
pair.stop(out)
|
pair.stop(out)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def _collect_on_the_main_thread():
|
||||||
|
"""Python's garbage collector runs on whichever thread happens to
|
||||||
|
trigger it — a worker's included — and a Qt object left over from a
|
||||||
|
test, destroyed off the GUI thread, segfaults later (the rare crash in
|
||||||
|
test_round72's maximized window, Rounds 94–96). Collecting here, after
|
||||||
|
every test, on this thread, leaves workers nothing Qt to collect."""
|
||||||
|
yield
|
||||||
|
import gc
|
||||||
|
gc.collect(1) # the young generations: what a test just left
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ def test_height_bounds():
|
|||||||
low, high = height_bounds(1000, 22)
|
low, high = height_bounds(1000, 22)
|
||||||
assert (low, high) == (1000 - 28 * 22, 1000 - 5 * 22)
|
assert (low, high) == (1000 - 28 * 22, 1000 - 5 * 22)
|
||||||
assert default_height(1000, 22) == 1000 - 15 * 22
|
assert default_height(1000, 22) == 1000 - 15 * 22
|
||||||
assert default_height(400, 22) == 320 # the full layout at least
|
assert default_height(400, 22) == 380 # the full layout at least (Round 96)
|
||||||
|
|
||||||
|
|
||||||
# ---- the window ----
|
# ---- the window ----
|
||||||
|
|||||||
+5
-34
@@ -57,13 +57,10 @@ class TestSync:
|
|||||||
_loaded(shelf, b, shelf.tracks[1], _clicks(118, 0.05, 20), 118.0, 0.05)
|
_loaded(shelf, b, shelf.tracks[1], _clicks(118, 0.05, 20), 118.0, 0.05)
|
||||||
return a, b
|
return a, b
|
||||||
|
|
||||||
def test_sync_sticks_glows_and_follows(self, shelf):
|
def test_sync_glows_while_it_holds(self, shelf):
|
||||||
a, b = self._pair(shelf)
|
a, b = self._pair(shelf)
|
||||||
shelf.sync(b)
|
shelf.sync(b)
|
||||||
assert b.synced and shelf.sync_buttons["B"].text() == "Synced"
|
assert b.synced and shelf.sync_buttons["B"].text() == "Synced"
|
||||||
shelf.speed["A"].setValue(200) # A +2 %: B follows
|
|
||||||
shelf._tick()
|
|
||||||
assert b.deck.speed == pytest.approx(124 * 1.02 / 118)
|
|
||||||
shelf.speed["B"].setValue(0) # B moved by hand: unsynced
|
shelf.speed["B"].setValue(0) # B moved by hand: unsynced
|
||||||
assert not b.synced
|
assert not b.synced
|
||||||
assert shelf.sync_buttons["B"].text() == "Sync to other track"
|
assert shelf.sync_buttons["B"].text() == "Sync to other track"
|
||||||
@@ -93,39 +90,13 @@ class TestSync:
|
|||||||
assert a.deck.position == 0 and not a.deck.ended
|
assert a.deck.position == 0 and not a.deck.ended
|
||||||
|
|
||||||
|
|
||||||
class TestHorn:
|
def test_the_bundled_horn_recording_loads(qapp):
|
||||||
def _horn(self):
|
# (Round 96 replaced "a tap plays the whole phrase" with the way a DJ
|
||||||
x = (np.sin(np.arange(RATE * 2) / RATE * 2 * np.pi * 400) * 20000).astype(np.int16)
|
# horn really plays — see test_round96.TestHorn.)
|
||||||
return Horn(np.stack([x, x], axis=1))
|
|
||||||
|
|
||||||
def _drain(self, horn):
|
|
||||||
total = 0
|
|
||||||
while True:
|
|
||||||
block = horn.render(4096)
|
|
||||||
if block is None:
|
|
||||||
return total / RATE
|
|
||||||
total += len(block)
|
|
||||||
|
|
||||||
def test_a_tap_plays_the_whole_recording(self):
|
|
||||||
horn = self._horn()
|
|
||||||
horn.press()
|
|
||||||
horn.render(441)
|
|
||||||
horn.release()
|
|
||||||
assert 0.01 + self._drain(horn) == pytest.approx(2.0, abs=0.1)
|
|
||||||
|
|
||||||
def test_holding_stretches_it(self):
|
|
||||||
horn = self._horn()
|
|
||||||
horn.press()
|
|
||||||
held = sum(len(horn.render(4096)) for _ in range(int(4 * RATE / 4096))) / RATE
|
|
||||||
horn.release()
|
|
||||||
assert held > 3.9
|
|
||||||
assert self._drain(horn) <= 2.0 # then the rest plays out
|
|
||||||
|
|
||||||
def test_the_bundled_recording_loads(self, qapp):
|
|
||||||
from lintunes.gui.dj_shelf import _load_horn
|
from lintunes.gui.dj_shelf import _load_horn
|
||||||
horn = Horn()
|
horn = Horn()
|
||||||
_load_horn(horn)
|
_load_horn(horn)
|
||||||
assert horn._src is not None and len(horn._src) > RATE
|
assert horn._held is not None and len(horn._held) > RATE
|
||||||
|
|
||||||
|
|
||||||
def test_the_waveform_zooms_out_while_paused(shelf):
|
def test_the_waveform_zooms_out_while_paused(shelf):
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
"""Round 96: the DJ shelf's new layout (records in the corners, controls
|
||||||
|
facing the middle, whole-song overviews below the zoomed pair), loops, a
|
||||||
|
sync that sets once, the air horn as a real one plays, and the open/close
|
||||||
|
slide."""
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from lintunes.dj.audio import RATE, Deck, Horn, Source
|
||||||
|
from tests.test_round93 import _clicks, _loaded, shelf # noqa: F401 — the fixture
|
||||||
|
|
||||||
|
|
||||||
|
def _pair(shelf):
|
||||||
|
a, b = shelf.views
|
||||||
|
_loaded(shelf, a, shelf.tracks[0], _clicks(124, 0.15, 20), 124.0, 0.15)
|
||||||
|
_loaded(shelf, b, shelf.tracks[1], _clicks(118, 0.05, 20), 118.0, 0.05)
|
||||||
|
return a, b
|
||||||
|
|
||||||
|
|
||||||
|
class TestSyncSetsOnce:
|
||||||
|
def test_the_other_deck_moving_leaves_this_tempo(self, shelf):
|
||||||
|
a, b = _pair(shelf)
|
||||||
|
shelf.sync(b)
|
||||||
|
speed = b.deck.speed
|
||||||
|
shelf.speed["A"].setValue(200) # A +2 %
|
||||||
|
shelf._tick()
|
||||||
|
assert b.deck.speed == pytest.approx(speed) # B stays where it was set
|
||||||
|
assert not b.synced # …and is no longer lit
|
||||||
|
|
||||||
|
def test_a_new_song_on_the_other_deck_unlights_it(self, shelf):
|
||||||
|
a, b = _pair(shelf)
|
||||||
|
shelf.sync(b)
|
||||||
|
_loaded(shelf, a, shelf.tracks[1], _clicks(118, 0.05, 20), 118.0, 0.05)
|
||||||
|
shelf._tick()
|
||||||
|
assert not b.synced and b.deck.speed == pytest.approx(124 / 118)
|
||||||
|
|
||||||
|
|
||||||
|
class TestLoops:
|
||||||
|
def test_engine_wraps_at_the_loop_end(self):
|
||||||
|
x = np.arange(RATE * 10)
|
||||||
|
tone = np.stack([(np.sin(x / RATE * 2 * np.pi * 200) * 10000).astype(np.int16)] * 2, 1)
|
||||||
|
deck = Deck("A")
|
||||||
|
deck.load(Source(tone))
|
||||||
|
deck.playing = True
|
||||||
|
deck.position = RATE * 1.0
|
||||||
|
deck.loop = (RATE, RATE + 11025)
|
||||||
|
for _ in range(100):
|
||||||
|
deck.render(1024)
|
||||||
|
assert RATE <= deck.position < RATE + 11025 + 1024
|
||||||
|
|
||||||
|
def test_starts_on_the_next_beat_and_shows_its_size(self, shelf):
|
||||||
|
a, _ = _pair(shelf)
|
||||||
|
a.deck.position = RATE * 3.0
|
||||||
|
shelf.set_loop(a, True)
|
||||||
|
start, end = a.deck.loop
|
||||||
|
beat = 60 / 124
|
||||||
|
k = (start / RATE - 0.15) / beat
|
||||||
|
assert k == pytest.approx(round(k), abs=1e-3) # on a beat
|
||||||
|
assert start / RATE >= 3.0 - 1e-3 # the next one
|
||||||
|
assert (end - start) / RATE == pytest.approx(4 * beat, abs=1e-3)
|
||||||
|
shelf.step_loop(a, -2) # 4 → 1 beat
|
||||||
|
assert shelf.loop_sizes["A"].text() == "1"
|
||||||
|
assert (a.deck.loop[1] - a.deck.loop[0]) / RATE == pytest.approx(beat, abs=1e-3)
|
||||||
|
shelf.step_loop(a, -5) # → 1/32
|
||||||
|
assert shelf.loop_sizes["A"].text() == "1/32"
|
||||||
|
shelf.set_loop(a, False)
|
||||||
|
assert a.deck.loop is None
|
||||||
|
|
||||||
|
def test_loading_a_song_drops_the_loop(self, shelf):
|
||||||
|
a, _ = _pair(shelf)
|
||||||
|
shelf.set_loop(a, True)
|
||||||
|
_loaded(shelf, a, shelf.tracks[1], _clicks(118, 0.05, 20), 118.0, 0.05)
|
||||||
|
assert a.deck.loop is None and not shelf.loop_buttons["A"].isChecked()
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_overview_jumps(shelf):
|
||||||
|
from PyQt6.QtCore import QEvent, QPointF, Qt
|
||||||
|
from PyQt6.QtGui import QMouseEvent
|
||||||
|
a, _ = _pair(shelf)
|
||||||
|
ov = shelf.overviews["A"]
|
||||||
|
ov.resize(400, 64)
|
||||||
|
event = QMouseEvent(QEvent.Type.MouseButtonPress, QPointF(200, 30), QPointF(200, 30),
|
||||||
|
Qt.MouseButton.LeftButton, Qt.MouseButton.LeftButton,
|
||||||
|
Qt.KeyboardModifier.NoModifier)
|
||||||
|
ov.mousePressEvent(event)
|
||||||
|
assert a.deck.position / RATE == pytest.approx(a.deck.source.seconds / 2, abs=0.1)
|
||||||
|
ov.grab() # paints without trouble
|
||||||
|
|
||||||
|
|
||||||
|
class TestHorn:
|
||||||
|
def _horn(self):
|
||||||
|
x = (np.sin(np.arange(RATE * 2) / RATE * 2 * np.pi * 400) * 20000).astype(np.int16)
|
||||||
|
return Horn(np.stack([x, x], axis=1))
|
||||||
|
|
||||||
|
def _drain(self, horn):
|
||||||
|
total = 0
|
||||||
|
while True:
|
||||||
|
block = horn.render(1024)
|
||||||
|
if block is None:
|
||||||
|
return total / RATE
|
||||||
|
total += len(block)
|
||||||
|
|
||||||
|
def test_a_tap_is_short(self):
|
||||||
|
horn = self._horn()
|
||||||
|
horn.press()
|
||||||
|
horn.render(2205)
|
||||||
|
horn.release()
|
||||||
|
assert self._drain(horn) < 0.15
|
||||||
|
|
||||||
|
def test_holding_carries_the_note_even_after_taps(self):
|
||||||
|
horn = self._horn()
|
||||||
|
for _ in range(6):
|
||||||
|
horn.press()
|
||||||
|
horn.render(1024)
|
||||||
|
horn.release()
|
||||||
|
horn.render(1024)
|
||||||
|
horn.press()
|
||||||
|
for _ in range(int(3 * RATE / 1024)):
|
||||||
|
block = horn.render(1024)
|
||||||
|
assert np.abs(block).max() > 0.1 # still blaring at 3 s
|
||||||
|
horn.release()
|
||||||
|
assert self._drain(horn) < 0.15
|
||||||
|
|
||||||
|
def test_a_press_while_ringing_starts_a_new_blast(self):
|
||||||
|
horn = self._horn()
|
||||||
|
horn.press()
|
||||||
|
horn.render(4410)
|
||||||
|
horn.press()
|
||||||
|
assert len(horn._voices) == 2 and horn._voices[0]["fading"]
|
||||||
|
assert horn._voices[-1]["pos"] == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_dj_mode_slides(qapp, tmp_path, monkeypatch):
|
||||||
|
from lintunes.gui.main_window import MainWindow
|
||||||
|
from lintunes.library_manager import LibraryManager
|
||||||
|
from lintunes.models.library import Library
|
||||||
|
from lintunes.preferences import Preferences
|
||||||
|
monkeypatch.setattr("lintunes.gui.main_window.load_config", lambda: {})
|
||||||
|
monkeypatch.setattr("lintunes.gui.main_window.save_config", lambda c: None)
|
||||||
|
window = MainWindow(LibraryManager(Library(), tmp_path), Preferences(tmp_path))
|
||||||
|
try:
|
||||||
|
window.resize(1100, 760)
|
||||||
|
window.show()
|
||||||
|
qapp.processEvents()
|
||||||
|
window.set_dj_mode(True)
|
||||||
|
overlay = window._dj_overlay
|
||||||
|
assert overlay is not None and overlay.opening
|
||||||
|
# the real window is already in its final layout under the picture
|
||||||
|
assert window._dj.height() == window._dj.layout_height() > 0
|
||||||
|
window._dj_anim.stop()
|
||||||
|
window.set_dj_mode(False)
|
||||||
|
assert not window._dj.isVisible() # final layout at once
|
||||||
|
assert window._dj_overlay is not None and not window._dj_overlay.opening
|
||||||
|
window._dj_anim.stop()
|
||||||
|
finally:
|
||||||
|
window.close()
|
||||||
Reference in New Issue
Block a user