Source code for jdxi_editor.ui.editors.digital.randomize_dialog

"""
Randomize a Digital tone: a section of the partial shown, the partial, or the
whole tone, by a little, a medium amount or much. Each press is one Undo step.
"""

from __future__ import annotations

from PySide6.QtWidgets import (
    QButtonGroup,
    QComboBox,
    QDialog,
    QHBoxLayout,
    QLabel,
    QPushButton,
    QRadioButton,
    QVBoxLayout,
)

from jdxi_editor.ui.editors.digital import partial_tools as tools


[docs] class RandomizeDialog(QDialog): def __init__(self, editor, partial: int, parent=None): super().__init__(parent or editor)
[docs] self.editor = editor
[docs] self.partial = partial
self.setWindowTitle("Randomize") self.setMinimumWidth(460) root = QVBoxLayout(self) root.addWidget(QLabel("What"))
[docs] self.scope = QButtonGroup(self)
line = QHBoxLayout()
[docs] self.section_radio = QRadioButton("Section")
line.addWidget(self.section_radio)
[docs] self.section = QComboBox()
for key, label in tools.SECTION_LABELS.items(): self.section.addItem(label, key) self.section.currentIndexChanged.connect( lambda _index: self.section_radio.setChecked(True) ) line.addWidget(self.section) line.addWidget(QLabel(f"of partial {partial}")) line.addStretch() root.addLayout(line)
[docs] self.partial_radio = QRadioButton(f"Partial {partial}")
[docs] self.tone_radio = QRadioButton( "The whole tone (three partials, Wave Shape, Analog Feel)" )
for button, key in ( (self.section_radio, "section"), (self.partial_radio, "partial"), (self.tone_radio, "tone"), ): button.setProperty("scope", key) self.scope.addButton(button) root.addWidget(self.partial_radio) root.addWidget(self.tone_radio) self.section_radio.setChecked(True) root.addWidget(QLabel("How much"))
[docs] self.amount = QButtonGroup(self)
amounts = QHBoxLayout() for key, label, tip in ( ("little", "A little", "Each value moves by up to 10% of its range."), ("medium", "Medium", "Up to 30%: the same character, clearly different."), ( "much", "Much", "Anything, including the waveforms, filter types and LFO shapes.", ), ): button = QRadioButton(label) button.setToolTip(tip) button.setProperty("amount", key) self.amount.addButton(button) amounts.addWidget(button) if key == "medium": button.setChecked(True) amounts.addStretch() root.addLayout(amounts) note = QLabel( "The name, category, playing style and which partials are on stay as they are. " "A partial randomized stays audible. Each press is one Undo step." ) note.setWordWrap(True) root.addWidget(note)
[docs] self.result = QLabel("")
root.addWidget(self.result) buttons = QHBoxLayout() buttons.addStretch() go = QPushButton("Randomize") go.setDefault(True) go.clicked.connect(self.randomize) buttons.addWidget(go) undo = QPushButton("Undo") undo.clicked.connect(self.undo) buttons.addWidget(undo) close = QPushButton("Close") close.clicked.connect(self.accept) buttons.addWidget(close) root.addLayout(buttons)
[docs] def chosen_scope(self) -> str: button = self.scope.checkedButton() return button.property("scope") if button is not None else "section"
[docs] def chosen_amount(self) -> str: button = self.amount.checkedButton() return button.property("amount") if button is not None else "medium"
[docs] def randomize(self) -> int: changed = tools.randomize( self.editor, self.chosen_scope(), self.chosen_amount(), self.partial, self.section.currentData(), ) self.result.setText(f"{changed} values changed.") return changed
[docs] def undo(self) -> None: history = getattr(self.editor, "history", None) if history is not None and history.undo(): self.result.setText("Taken back.")