"""
Fit to the JD-Xi group: what of the file the JD-Xi plays, assign tracks to parts, starting sounds.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
from decologr import Decologr as log
from PySide6.QtCore import QMargins
from PySide6.QtWidgets import QGroupBox, QLabel, QPushButton, QVBoxLayout
from jdxi_editor.core.jdxi import JDXi
from jdxi_editor.midi.playback.state import MidiPlaybackState
from jdxi_editor.ui.editors.helpers.widgets import create_round_button_with_label
from jdxi_editor.ui.widgets.editor.helper import create_group_with_layout
from jdxi_editor.ui.widgets.jdxi.midi_group import JDXiMidiGroup
from picoui.helpers import create_layout_with_items
from picoui.specs.widgets import ButtonSpec
if TYPE_CHECKING:
from jdxi_editor.ui.editors.midi_player.editor import MidiFilePlayer
[docs]
class ClassificationGroup(JDXiMidiGroup):
"""Track Classification group: Detect Drums, Classify Tracks, Apply Presets (track edits apply immediately)."""
def __init__(
self,
parent: "MidiFilePlayer",
midi_state: MidiPlaybackState | None = None,
):
super().__init__(parent=parent, midi_state=midi_state)
[docs]
self.summary_label: QLabel | None = None
self.setup_ui()
[docs]
def _build_group(self) -> QGroupBox:
"""Fit to the JD-Xi: what of the file the JD-Xi plays, then one row of
actions (propose the parts for the tracks; the parts' sounds)."""
mp = JDXi.UI.MidiPlayer
self.summary_label = QLabel("Load a MIDI file: this says which of its tracks the JD-Xi plays.")
self.summary_label.setWordWrap(True)
self.summary_label.setObjectName("fitSummary")
self.summary_label.setToolTip((
"The JD-Xi plays four parts, each on its channel: Digital 1 (1), Digital 2 (2), "
"Analog (3), Drums (10). Notes on other channels are not heard."))
buttons, items = [], []
for key in ("fit_tracks", "apply_presets"):
spec = self.specs["buttons"][key]
item, button = create_round_button_with_label(
spec.label, spec.icon, spec.slot, spec.tooltip
)
buttons.append(button)
items.append(item)
self.fit_tracks_button, self.apply_presets_button = buttons
row = create_layout_with_items(
items=items,
vertical=False,
start_stretch=False,
end_stretch=True,
margins=QMargins(0, 0, 0, 0),
spacing=mp.SPACING_RELATED,
)
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(mp.SPACING_RELATED)
layout.addWidget(self.summary_label)
layout.addLayout(row)
group, _ = create_group_with_layout(label="Fit to the JD-Xi", layout=layout)
return group
[docs]
def set_summary(self, text: str, ready: bool) -> None:
"""What the JD-Xi plays of the file (green when it plays all of it)."""
self.summary_label.setText(text)
self.summary_label.setStyleSheet("color: #6fcf8f;" if ready else "")
[docs]
def _on_apply_presets_clicked(self) -> None:
"""Log and delegate to parent.apply_channel_presets."""
log.message(
scope=self.__class__.__name__,
message="Apply Presets button clicked",
)
log.parameter(
scope=self.__class__.__name__,
message="parent",
parameter=self.parent,
)
self.parent.apply_channel_presets()