"""
Panel for loading/saving presets
"""
from typing import Any, Optional
from PySide6.QtCore import Signal
from PySide6.QtWidgets import QComboBox, QHBoxLayout, QLabel, QPushButton
from jdxi_editor.core.synth.type import JDXiSynth
from jdxi_editor.midi.io.helper import MidiIOHelper
from jdxi_editor.ui.common import JDXi, QWidget
from jdxi_editor.ui.editors.helpers.widgets import create_jdxi_button, create_jdxi_row
from jdxi_editor.ui.editors.preset.editor import PresetEditor
from jdxi_editor.ui.style import JDXiUIDimensions, JDXiUIStyle
[docs]
class PresetPanel(QWidget):
"""Panel for loading/saving presets"""
# Define signals
[docs]
load_clicked = Signal(int) # Emits preset number when load clicked
[docs]
save_clicked = Signal(int) # Emits preset number when save clicked
def __init__(self, midi_helper: MidiIOHelper, parent=None):
super().__init__(parent)
layout = QHBoxLayout(self)
# Preset selector
[docs]
self.preset_combo = QComboBox()
layout.addWidget(self.preset_combo)
# Load (round button + label)
load_row = QHBoxLayout()
layout.addLayout(load_row)
# Save (round button + label)
save_row = QHBoxLayout()
layout.addLayout(save_row)
# Create preset editors for each preset_type
[docs]
self.analog_editor = PresetEditor(midi_helper, self, JDXiSynth.ANALOG_SYNTH)
[docs]
self.digital_1_editor = PresetEditor(
midi_helper, self, JDXiSynth.DIGITAL_SYNTH_1
)
[docs]
self.digital_2_editor = PresetEditor(
midi_helper, self, JDXiSynth.DIGITAL_SYNTH_2
)
[docs]
self.drums_editor = PresetEditor(midi_helper, self, JDXiSynth.DRUM_KIT)
[docs]
def _on_load(self):
"""Handle load button click"""
preset_num = self.preset_combo.currentIndex()
self.load_clicked.emit(preset_num) # convert from 0-based index
[docs]
def _on_save(self):
"""Handle save button click"""
preset_num = self.preset_combo.currentIndex()
self.save_clicked.emit(preset_num)