-
Notifications
You must be signed in to change notification settings - Fork 0
Increase visual footprint, stop idle AudioLines when silent, and sync floating controls with window state #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
userlg
wants to merge
2
commits into
main
Choose a base branch
from
codex/adjust-spectrum-bar-size-and-settings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,108 +1,129 @@ | ||
| from __future__ import annotations | ||
| import math | ||
| import numpy as np | ||
| from PySide6.QtGui import QPainter, QPen, QPainterPath, QColor, QRadialGradient, QBrush | ||
| from PySide6.QtGui import ( | ||
| QPainter, | ||
| QPen, | ||
| QColor, | ||
| QRadialGradient, | ||
| QBrush, | ||
| QPolygonF, | ||
| ) | ||
| from PySide6.QtCore import Qt, QPointF | ||
| from visualizer import BaseVisualizer | ||
|
|
||
|
|
||
| class Oscilloscope(BaseVisualizer): | ||
| """Oscilloscope optimizado para máxima fluidez y rendimiento cinemático.""" | ||
|
|
||
| def __init__(self): | ||
| super().__init__("Oscilloscope") | ||
| self.line_width = 3 | ||
| self.flicker_intensity = 0.0 | ||
| self.glitch_timer = 0 | ||
| # Variables de suavizado (Smoothing) | ||
| self.glitch_timer = 0.0 | ||
|
|
||
| # Variables de suavizado | ||
| self.smooth_scale = 1.0 | ||
| self.smooth_flicker = 0.0 | ||
| self.interpolation_factor = 0.15 # Determina la inercia del movimiento | ||
| self.interpolation_factor = 0.18 | ||
|
|
||
| # Estado para estabilidad de frame-time | ||
| self.phase = 0.0 | ||
| self.max_points = 360 | ||
| self.min_points = 180 | ||
|
|
||
| def _build_polyline(self, waveform: np.ndarray, center_x: float, center_y: float) -> QPolygonF: | ||
| """Construye la polilínea principal minimizando costo por frame.""" | ||
| wf = np.nan_to_num(waveform, nan=0.0, posinf=0.0, neginf=0.0) | ||
|
|
||
| # Puntos adaptativos según tamaño de waveform para evitar sobrecarga | ||
| num_points = int(np.clip(len(wf) // 6, self.min_points, self.max_points)) | ||
| indices = np.linspace(0, len(wf) - 1, num_points, dtype=np.int32) | ||
|
|
||
| x_vals = wf[indices] | ||
| y_indices = (indices + len(wf) // 3) % len(wf) | ||
| y_vals = wf[y_indices] | ||
|
|
||
| # Jitter determinista (sin np.random por frame -> más estable) | ||
| jitter_amount = 2.5 * self.smooth_flicker | ||
| t = self.phase + np.linspace(0.0, 6.0, num_points) | ||
| jitter_x = np.sin(t * 1.7) * jitter_amount | ||
| jitter_y = np.cos(t * 2.1) * jitter_amount | ||
|
|
||
| px = center_x + x_vals * self.smooth_scale + jitter_x | ||
| py = center_y + y_vals * self.smooth_scale + jitter_y | ||
|
|
||
| poly = QPolygonF() | ||
| poly.reserve(num_points) | ||
| for x, y in zip(px, py): | ||
| poly.append(QPointF(float(x), float(y))) | ||
|
|
||
| return poly | ||
|
|
||
| def render(self, painter: QPainter, waveform: np.ndarray, fft_data: np.ndarray): | ||
| if self.theme is None or len(waveform) < 2: | ||
| return | ||
|
|
||
| painter.setRenderHint(QPainter.Antialiasing, True) | ||
|
|
||
| # 1. Procesamiento de Energía con Suavizado | ||
| avg_energy = np.mean(np.abs(waveform)) | ||
|
|
||
| # Suavizado de la intensidad del parpadeo (flicker) | ||
| target_flicker = min(1.0, self.flicker_intensity + 0.2) if avg_energy > 0.4 else self.flicker_intensity * 0.8 | ||
|
|
||
| avg_energy = float(np.mean(np.abs(waveform))) | ||
|
|
||
| # Flicker suave y acotado | ||
| target_flicker = min(1.0, avg_energy * 2.4) | ||
| self.smooth_flicker += (target_flicker - self.smooth_flicker) * self.interpolation_factor | ||
|
|
||
| center_x = self.width / 2 | ||
| center_y = self.height / 2 | ||
|
|
||
| # 2. Retícula de Enfoque | ||
| # Retícula ligera | ||
| grid_color = QColor(self.theme.get_color(0)) | ||
| grid_color.setAlpha(40) | ||
| grid_color.setAlpha(34) | ||
| painter.setPen(QPen(grid_color, 1)) | ||
|
|
||
| base_r = min(self.width, self.height) | ||
| for r_factor in [0.2, 0.4, 0.6]: | ||
| for r_factor in (0.22, 0.44, 0.66): | ||
| r = base_r * r_factor | ||
| painter.drawEllipse(QPointF(center_x, center_y), r, r) | ||
|
|
||
| painter.drawLine(0, int(center_y), self.width, int(center_y)) | ||
| painter.drawLine(int(center_x), 0, int(center_x), self.height) | ||
|
|
||
| # 3. Construcción del Núcleo (Optimización NumPy) | ||
| num_points = 500 # Un poco menos de puntos para mayor fluidez | ||
|
|
||
| # Suavizado de la escala dinámica para evitar saltos | ||
| target_scale = (base_r * 0.4) * (1.0 + avg_energy * 2.0) | ||
| # Escala dinámica con inercia | ||
| target_scale = (base_r * 0.34) * (1.0 + avg_energy * 1.8) | ||
| self.smooth_scale += (target_scale - self.smooth_scale) * self.interpolation_factor | ||
|
|
||
| # Vectorización: Calculamos todos los índices y posiciones de una vez con NumPy | ||
| indices = np.linspace(0, len(waveform) - 1, num_points).astype(int) | ||
| x_vals = waveform[indices] | ||
|
|
||
| y_indices = (indices + len(waveform) // 3) % len(waveform) | ||
| y_vals = waveform[y_indices] | ||
|
|
||
| # Generamos el Jitter (temblor) de forma masiva | ||
| jitter_amount = 5 * self.smooth_flicker | ||
| jitters = np.random.uniform(-jitter_amount, jitter_amount, (num_points, 2)) if jitter_amount > 0.1 else np.zeros((num_points, 2)) | ||
|
|
||
| # Coordenadas finales calculadas por NumPy (mucho más rápido que un bucle for) | ||
| px = center_x + x_vals * self.smooth_scale + jitters[:, 0] | ||
| py = center_y + y_vals * self.smooth_scale + jitters[:, 1] | ||
|
|
||
| # Creación del Path (Aún requiere un bucle, pero sin cálculos matemáticos dentro) | ||
| path = QPainterPath() | ||
| path.moveTo(px[0], py[0]) | ||
| for i in range(1, num_points): | ||
| path.lineTo(px[i], py[i]) | ||
|
|
||
| # 4. Renderizado de "Rastro de Gloria" | ||
| main_color = self.theme.get_color(0) | ||
|
|
||
| polyline = self._build_polyline(waveform, center_x, center_y) | ||
|
|
||
| # Glow | ||
| main_color = self.theme.get_color(0) | ||
| glow_color = QColor(main_color) | ||
| glow_color.setAlpha(int(60 * self.smooth_flicker + 20)) | ||
| painter.setPen(QPen(glow_color, self.line_width + 10, Qt.SolidLine, Qt.RoundCap)) | ||
| painter.drawPath(path) | ||
| glow_color.setAlpha(int(24 + 56 * self.smooth_flicker)) | ||
| painter.setPen(QPen(glow_color, self.line_width + 8, Qt.SolidLine, Qt.RoundCap)) | ||
| painter.drawPolyline(polyline) | ||
|
|
||
| # Núcleo | ||
| core_color = QColor(main_color) | ||
| if self.smooth_flicker > 0.6: | ||
| core_color = core_color.lighter(140) | ||
| if self.smooth_flicker > 0.65: | ||
| core_color = core_color.lighter(135) | ||
|
|
||
| painter.setPen(QPen(core_color, self.line_width, Qt.SolidLine, Qt.RoundCap)) | ||
| painter.drawPath(path) | ||
|
|
||
| # 5. Efectos Finales (Scanline y Viñeta) | ||
| self.glitch_timer += 2 | ||
| scanline_y = (self.glitch_timer % 100) / 100.0 * self.height | ||
|
|
||
| scan_color = QColor(255, 255, 255, 25) | ||
| painter.setPen(QPen(scan_color, 2)) | ||
| painter.drawPolyline(polyline) | ||
|
|
||
| # Scanline más barata | ||
| self.glitch_timer += 1.8 | ||
| scanline_y = (self.glitch_timer % 100.0) / 100.0 * self.height | ||
| painter.setPen(QPen(QColor(255, 255, 255, 20), 2)) | ||
| painter.drawLine(0, int(scanline_y), self.width, int(scanline_y)) | ||
|
|
||
| vignette = QRadialGradient(QPointF(center_x, center_y), self.width * 0.7) | ||
|
|
||
| # Viñeta | ||
| vignette = QRadialGradient(QPointF(center_x, center_y), self.width * 0.72) | ||
| vignette.setColorAt(0, Qt.transparent) | ||
| vignette.setColorAt(1, QColor(0, 0, 0, 160)) | ||
| vignette.setColorAt(1, QColor(0, 0, 0, 145)) | ||
| painter.setBrush(QBrush(vignette)) | ||
| painter.setPen(Qt.NoPen) | ||
| painter.drawRect(0, 0, self.width, self.height) | ||
| painter.drawRect(0, 0, self.width, self.height) | ||
|
|
||
| # Fase temporal para jitter determinista | ||
| self.phase += 0.025 + (0.03 * self.smooth_flicker) | ||
| if self.phase > math.tau: | ||
| self.phase -= math.tau |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the main window is minimized,
changeEventforcibly callsself.settings_dialog.hide(), but unlike the control panel there is no state tracking to restore it; because_show_settingsopens this dialog withexec(), minimizing while settings are open can terminate that modal session and drop the user's in-progress edits after restore. This affects users who open Settings, adjust values, then minimize the app before applying.Useful? React with 👍 / 👎.