[feature] 新增get接口

This commit is contained in:
Sam 2025-02-19 21:57:42 +08:00
parent 57753b4477
commit 04fd71b634
8 changed files with 381 additions and 8 deletions

View File

@ -5,14 +5,17 @@ from PySide6.QtCore import Qt, Signal, QEvent
from PySide6.QtGui import QPainter, QColor, QPen, QBrush, QPainterPath, QIcon, QPixmap from PySide6.QtGui import QPainter, QColor, QPen, QBrush, QPainterPath, QIcon, QPixmap
from PySide6.QtCore import QFile from PySide6.QtCore import QFile
from component.widget_filter.Ui_widget import Ui_Widget # from component.widget_filter.Ui_widget import Ui_Widget
# from Ui_widget import Ui_Widget from Ui_widget import Ui_Widget
from component.widget_filter.checkbox_header import SCheckBoxHeaderView # from component.widget_filter.checkbox_header import SCheckBoxHeaderView
from checkbox_header import SCheckBoxHeaderView
from typing import List, Dict, Optional, Any from typing import List, Dict, Optional, Any
import component.widget_filter.resources # import component.widget_filter.resources
class ReadOnlyDelegate(QStyledItemDelegate): class ReadOnlyDelegate(QStyledItemDelegate):
def createEditor(self, parent, option, index): def createEditor(self, parent, option, index):
@ -162,6 +165,10 @@ class AudioFilterWidget(QWidget):
self.filter_types = ["PEAK", "LOWPASS", "HIGHPASS", "ALLPASS"] self.filter_types = ["PEAK", "LOWPASS", "HIGHPASS", "ALLPASS"]
# 添加配置映射字典
self.current_mapping = {}
self.current_channel = None
# 初始化UI # 初始化UI
self.setup_table() self.setup_table()
self.setup_connections() self.setup_connections()
@ -172,6 +179,190 @@ class AudioFilterWidget(QWidget):
def set_channel_name(self, channel_name: str): def set_channel_name(self, channel_name: str):
self.channel_name = channel_name self.channel_name = channel_name
def set_channel(self, channel_name: str):
"""设置当前通道并更新映射"""
from list_table_config import table_config
if channel_name in table_config:
self.current_channel = channel_name
self.current_mapping = table_config[channel_name]
def get_all_params(self) -> Dict[str, Any]:
"""获取所有参数及其映射值"""
if not self.current_mapping:
return {}
result = {}
# 获取基础参数
base_params = {
'delay_data1': self.ui.lineEdit_11.text(),
'vol_data1': self.ui.lineEdit_10.text(),
'mix_right_data1': self.ui.lineEdit_13.text(),
'mix_left_data1': self.ui.lineEdit_12.text()
}
# 遍历前4个映射项基础参数
for item in self.current_mapping[:4]:
param_name = list(item.values())[0] # 获取映射名称
param_key = list(item.keys())[0] # 获取原始键名
if param_key in base_params:
result[param_name] = float(base_params[param_key]) if base_params[param_key] else 0.0
# 获取滤波器参数
for row in range(self.ui.tableWidget.rowCount()):
map_index = row + 4 # 前4项是基础参数
if map_index >= len(self.current_mapping):
break
filter_map = self.current_mapping[map_index]
print(f"aaaa filter_map: {filter_map}")
filter_key = list(filter_map.keys())[0] # 获取 Filter_X
param_names = filter_map[filter_key] # 获取参数名称列表
# 获取滤波器参数值
freq = self.ui.tableWidget.item(row, 3)
q = self.ui.tableWidget.item(row, 4)
gain = self.ui.tableWidget.item(row, 5)
slope = self.ui.tableWidget.item(row, 6)
filter_type_combo = self.ui.tableWidget.cellWidget(row, 2)
# 确保参数名称列表长度正确
if len(param_names) != 5:
print(f"Warning: Invalid parameter names list for {filter_key}: {param_names}")
continue
# 设置频率参数
if freq and freq.text():
try:
result[param_names[0]] = float(freq.text())
except ValueError:
result[param_names[0]] = 0.0
# 设置Q值参数
if q and q.text():
try:
result[param_names[1]] = float(q.text())
except ValueError:
result[param_names[1]] = 0.0
# 设置增益参数
if gain and gain.text():
try:
result[param_names[2]] = float(gain.text())
except ValueError:
result[param_names[2]] = 0.0
# 设置斜率参数
if slope and slope.text():
try:
result[param_names[3]] = float(slope.text())
except ValueError:
result[param_names[3]] = 0.0
# 设置滤波器类型
if filter_type_combo:
result[param_names[4]] = filter_type_combo.currentText()
return result
def set_all_params(self, params: Dict[str, Any]):
"""设置所有参数"""
if not self.channel_id:
return
# 设置基础参数
delay_key = f'delay_data{self.channel_id}'
vol_key = f'vol_data{self.channel_id}'
mix_right_key = f'mix_right_data{self.channel_id}'
mix_left_key = f'mix_left_data{self.channel_id}'
if delay_key in params:
self.ui.lineEdit_11.setText(str(params[delay_key]))
if vol_key in params:
self.ui.lineEdit_10.setText(str(params[vol_key]))
if mix_right_key in params:
self.ui.lineEdit_13.setText(str(params[mix_right_key]))
if mix_left_key in params:
self.ui.lineEdit_12.setText(str(params[mix_left_key]))
# 获取所有滤波器参数的键
filter_params = {}
for key in params:
if any(key.startswith(prefix) for prefix in [f'fc{self.channel_id}_', f'q{self.channel_id}_',
f'gain{self.channel_id}_', f'slope{self.channel_id}_']):
filter_num = int(key.split('_')[-1])
if filter_num not in filter_params:
filter_params[filter_num] = {}
param_type = key.split('_')[0][:-len(str(self.channel_id))] # 移除channel_id
filter_params[filter_num][param_type] = params[key]
# 设置滤波器参数
for filter_num, filter_data in filter_params.items():
row = filter_num - 1 # 转换为0基索引
# 确保表格有足够的行
while self.ui.tableWidget.rowCount() <= row:
self._on_add_filter_clicked()
# 创建并设置复选框
container = QWidget()
layout = QHBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.setAlignment(Qt.AlignCenter)
checkbox = QCheckBox()
checkbox.setChecked(True) # 默认选中
# 添加复选框样式
checkbox_style = """
QCheckBox {
background-color: transparent;
spacing: 0px;
}
QCheckBox::indicator {
width: 24px;
height: 24px;
border: none;
background: transparent;
}
QCheckBox::indicator:checked {
background-color: #346792;
image: url(:/images/checkbox_checked.png);
}
QCheckBox::indicator:unchecked {
border-color: #FFFFFF;
image: url(:/images/checkbox_unchecked.png);
}
"""
checkbox.setStyleSheet(checkbox_style)
layout.addWidget(checkbox)
container.setLayout(layout)
self.ui.tableWidget.setCellWidget(row, 0, container)
# 连接复选框信号
checkbox.clicked.connect(lambda checked, r=row: self._on_checkbox_clicked(r, checked))
# 设置滤波器参数
if 'fc' in filter_data:
item = QTableWidgetItem(str(filter_data['fc']))
item.setTextAlignment(Qt.AlignCenter)
self.ui.tableWidget.setItem(row, 3, item)
if 'q' in filter_data:
item = QTableWidgetItem(str(filter_data['q']))
item.setTextAlignment(Qt.AlignCenter)
self.ui.tableWidget.setItem(row, 4, item)
if 'gain' in filter_data:
item = QTableWidgetItem(str(filter_data['gain']))
item.setTextAlignment(Qt.AlignCenter)
self.ui.tableWidget.setItem(row, 5, item)
if 'slope' in filter_data:
item = QTableWidgetItem(str(filter_data['slope']))
item.setTextAlignment(Qt.AlignCenter)
self.ui.tableWidget.setItem(row, 6, item)
def setup_connections(self): def setup_connections(self):
"""设置信号连接""" """设置信号连接"""
# 表格选择变化 # 表格选择变化
@ -530,11 +721,35 @@ if __name__ == "__main__":
}) })
widget.set_param_data({ widget.set_param_data({
'delay_data1': 0.0, 'delay_data1': 30,
'ENT_volume_data1': 0.0, 'ENT_volume_data1': 2,
'ENT_mx_right_data': 0.0, 'ENT_mx_right_data': 3,
'ENT_mix_left_data': 0.0 'ENT_mix_left_data': 4
}) })
# widget.set_channel_id(1)
widget.set_channel("channel_2")
# test_params = {
# 'delay_data2': 30.0,
# 'vol_data2': 2.0,
# 'mix_right_data2': 3.0,
# 'mix_left_data2': 4.0,
# 'fc2_1': 100.0,
# 'q2_1': 1.0,
# 'gain2_1': 0.0,
# 'slope2_1': 1.0,
# 'fc2_2': 1000.0,
# 'q2_2': 0.7,
# 'gain2_2': 0.0,
# 'slope2_2': 2.0
# }# 设置参数
# widget.set_all_params(test_params)
# 获取所有参数
# params = widget.get_all_params()
# print("aaaa params:", params)
widget.show() widget.show()
sys.exit(app.exec()) sys.exit(app.exec())

View File

@ -0,0 +1,158 @@
table_config = {
"channel_1": [
{"delay_data1": "delay_data1"},
{"vol_data1": "vol_data1"},
{"mix_right_data1": "mix_right_data1"},
{"mix_left_data1": "mix_left_data1"},
{"Filter_1": ["fc1_1", "q1_1", "gain1_1", "slope1_1", "filterType1_1"]},
{"Filter_2": ["fc1_2", "q1_2", "gain1_2", "slope1_2", "filterType1_2"]},
{"Filter_3": ["fc1_3", "q1_3", "gain1_3", "slope1_3", "filterType1_3"]},
{"Filter_4": ["fc1_4", "q1_4", "gain1_4", "slope1_4", "filterType1_4"]},
{"Filter_5": ["fc1_5", "q1_5", "gain1_5", "slope1_5", "filterType1_5"]},
{"Filter_6": ["fc1_6", "q1_6", "gain1_6", "slope1_6", "filterType1_6"]},
{"Filter_7": ["fc1_7", "q1_7", "gain1_7", "slope1_7", "filterType1_7"]},
{"Filter_8": ["fc1_8", "q1_8", "gain1_8", "slope1_8", "filterType1_8"]},
{"Filter_9": ["fc1_9", "q1_9", "gain1_9", "slope1_9", "filterType1_9"]},
{"Filter_10": ["fc1_10", "q1_10", "gain1_10", "slope1_10", "filterType1_10"]},
{"Filter_11": ["fc1_11", "q1_11", "gain1_11", "slope1_11", "filterType1_11"]},
{"Filter_12": ["fc1_12", "q1_12", "gain1_12", "slope1_12", "filterType1_12"]},
{"Filter_13": ["fc1_13", "q1_13", "gain1_13", "slope1_13", "filterType1_13"]},
{"Filter_14": ["fc1_14", "q1_14", "gain1_14", "slope1_14", "filterType1_14"]},
{"Filter_15": ["fc1_15", "q1_15", "gain1_15", "slope1_15", "filterType1_15"]},
{"Filter_16": ["fc1_16", "q1_16", "gain1_16", "slope1_16", "filterType1_16"]},
{"Filter_17": ["fc1_17", "q1_17", "gain1_17", "slope1_17", "filterType1_17"]},
{"Filter_18": ["fc1_18", "q1_18", "gain1_18", "slope1_18", "filterType1_18"]},
{"Filter_19": ["fc1_19", "q1_19", "gain1_19", "slope1_19", "filterType1_19"]},
{"Filter_20": ["fc1_20", "q1_20", "gain1_20", "slope1_20", "filterType1_20"]}
],
"channel_2": [
{"delay_data1": "delay_data2"},
{"vol_data1": "vol_data2"},
{"mix_right_data1": "mix_right_data2"},
{"mix_left_data1": "mix_left_data2"},
{"Filter_1": ["fc2_1", "q2_1", "gain2_1", "slope2_1", "filterType2_1"]},
{"Filter_2": ["fc2_2", "q2_2", "gain2_2", "slope2_2", "filterType2_2"]},
{"Filter_3": ["fc2_3", "q2_3", "gain2_3", "slope2_3", "filterType2_3"]},
{"Filter_4": ["fc2_4", "q2_4", "gain2_4", "slope2_4", "filterType2_4"]},
{"Filter_5": ["fc2_5", "q2_5", "gain2_5", "slope2_5", "filterType2_5"]},
{"Filter_6": ["fc2_6", "q2_6", "gain2_6", "slope2_6", "filterType2_6"]},
{"Filter_7": ["fc2_7", "q2_7", "gain2_7", "slope2_7", "filterType2_7"]},
{"Filter_8": ["fc2_8", "q2_8", "gain2_8", "slope2_8", "filterType2_8"]},
{"Filter_9": ["fc2_9", "q2_9", "gain2_9", "slope2_9", "filterType2_9"]},
{"Filter_10": ["fc2_10", "q2_10", "gain2_10", "slope2_10", "filterType2_10"]},
{"Filter_11": ["fc2_11", "q2_11", "gain2_11", "slope2_11", "filterType2_11"]},
{"Filter_12": ["fc2_12", "q2_12", "gain2_12", "slope2_12", "filterType2_12"]},
{"Filter_13": ["fc2_13", "q2_13", "gain2_13", "slope2_13", "filterType2_13"]},
{"Filter_14": ["fc2_14", "q2_14", "gain2_14", "slope2_14", "filterType2_14"]},
{"Filter_15": ["fc2_15", "q2_15", "gain2_15", "slope2_15", "filterType2_15"]},
{"Filter_16": ["fc2_16", "q2_16", "gain2_16", "slope2_16", "filterType2_16"]},
{"Filter_17": ["fc2_17", "q2_17", "gain2_17", "slope2_17", "filterType2_17"]},
{"Filter_18": ["fc2_18", "q2_18", "gain2_18", "slope2_18", "filterType2_18"]},
{"Filter_19": ["fc2_19", "q2_19", "gain2_19", "slope2_19", "filterType2_19"]},
{"Filter_20": ["fc2_20", "q2_20", "gain2_20", "slope2_20", "filterType2_20"]}
],
"channel_3": [
{"delay_data1": "delay_data3"},
{"vol_data1": "vol_data3"},
{"mix_right_data1": "mix_right_data3"},
{"mix_left_data1": "mix_left_data3"},
{"Filter_1": ["fc3_1", "q3_1", "gain3_1", "slope3_1", "filterType3_1"]},
{"Filter_2": ["fc3_2", "q3_2", "gain3_2", "slope3_2", "filterType3_2"]},
{"Filter_3": ["fc3_3", "q3_3", "gain3_3", "slope3_3", "filterType3_3"]},
{"Filter_4": ["fc3_4", "q3_4", "gain3_4", "slope3_4", "filterType3_4"]},
{"Filter_5": ["fc3_5", "q3_5", "gain3_5", "slope3_5", "filterType3_5"]},
{"Filter_6": ["fc3_6", "q3_6", "gain3_6", "slope3_6", "filterType3_6"]},
{"Filter_7": ["fc3_7", "q3_7", "gain3_7", "slope3_7", "filterType3_7"]},
{"Filter_8": ["fc3_8", "q3_8", "gain3_8", "slope3_8", "filterType3_8"]},
{"Filter_9": ["fc3_9", "q3_9", "gain3_9", "slope3_9", "filterType3_9"]},
{"Filter_10": ["fc3_10", "q3_10", "gain3_10", "slope3_10", "filterType3_10"]},
{"Filter_11": ["fc3_11", "q3_11", "gain3_11", "slope3_11", "filterType3_11"]},
{"Filter_12": ["fc3_12", "q3_12", "gain3_12", "slope3_12", "filterType3_12"]},
{"Filter_13": ["fc3_13", "q3_13", "gain3_13", "slope3_13", "filterType3_13"]},
{"Filter_14": ["fc3_14", "q3_14", "gain3_14", "slope3_14", "filterType3_14"]},
{"Filter_15": ["fc3_15", "q3_15", "gain3_15", "slope3_15", "filterType3_15"]},
{"Filter_16": ["fc3_16", "q3_16", "gain3_16", "slope3_16", "filterType3_16"]},
{"Filter_17": ["fc3_17", "q3_17", "gain3_17", "slope3_17", "filterType3_17"]},
{"Filter_18": ["fc3_18", "q3_18", "gain3_18", "slope3_18", "filterType3_18"]},
{"Filter_19": ["fc3_19", "q3_19", "gain3_19", "slope3_19", "filterType3_19"]},
{"Filter_20": ["fc3_20", "q3_20", "gain3_20", "slope3_20", "filterType3_20"]}
],
"channel_4": [
{"delay_data1": "delay_data4"},
{"vol_data1": "vol_data4"},
{"mix_right_data1": "mix_right_data4"},
{"mix_left_data1": "mix_left_data4"},
{"Filter_1": ["fc4_1", "q4_1", "gain4_1", "slope4_1", "filterType4_1"]},
{"Filter_2": ["fc4_2", "q4_2", "gain4_2", "slope4_2", "filterType4_2"]},
{"Filter_3": ["fc4_3", "q4_3", "gain4_3", "slope4_3", "filterType4_3"]},
{"Filter_4": ["fc4_4", "q4_4", "gain4_4", "slope4_4", "filterType4_4"]},
{"Filter_5": ["fc4_5", "q4_5", "gain4_5", "slope4_5", "filterType4_5"]},
{"Filter_6": ["fc4_6", "q4_6", "gain4_6", "slope4_6", "filterType4_6"]},
{"Filter_7": ["fc4_7", "q4_7", "gain4_7", "slope4_7", "filterType4_7"]},
{"Filter_8": ["fc4_8", "q4_8", "gain4_8", "slope4_8", "filterType4_8"]},
{"Filter_9": ["fc4_9", "q4_9", "gain4_9", "slope4_9", "filterType4_9"]},
{"Filter_10": ["fc4_10", "q4_10", "gain4_10", "slope4_10", "filterType4_10"]},
{"Filter_11": ["fc4_11", "q4_11", "gain4_11", "slope4_11", "filterType4_11"]},
{"Filter_12": ["fc4_12", "q4_12", "gain4_12", "slope4_12", "filterType4_12"]},
{"Filter_13": ["fc4_13", "q4_13", "gain4_13", "slope4_13", "filterType4_13"]},
{"Filter_14": ["fc4_14", "q4_14", "gain4_14", "slope4_14", "filterType4_14"]},
{"Filter_15": ["fc4_15", "q4_15", "gain4_15", "slope4_15", "filterType4_15"]},
{"Filter_16": ["fc4_16", "q4_16", "gain4_16", "slope4_16", "filterType4_16"]},
{"Filter_17": ["fc4_17", "q4_17", "gain4_17", "slope4_17", "filterType4_17"]},
{"Filter_18": ["fc4_18", "q4_18", "gain4_18", "slope4_18", "filterType4_18"]},
{"Filter_19": ["fc4_19", "q4_19", "gain4_19", "slope4_19", "filterType4_19"]},
{"Filter_20": ["fc4_20", "q4_20", "gain4_20", "slope4_20", "filterType4_20"]}
],
"channel_5": [
{"delay_data1": "delay_data5"},
{"vol_data1": "vol_data5"},
{"mix_right_data1": "mix_right_data5"},
{"mix_left_data1": "mix_left_data5"},
{"Filter_1": ["fc5_1", "q5_1", "gain5_1", "slope5_1", "filterType5_1"]},
{"Filter_2": ["fc5_2", "q5_2", "gain5_2", "slope5_2", "filterType5_2"]},
{"Filter_3": ["fc5_3", "q5_3", "gain5_3", "slope5_3", "filterType5_3"]},
{"Filter_4": ["fc5_4", "q5_4", "gain5_4", "slope5_4", "filterType5_4"]},
{"Filter_5": ["fc5_5", "q5_5", "gain5_5", "slope5_5", "filterType5_5"]},
{"Filter_6": ["fc5_6", "q5_6", "gain5_6", "slope5_6", "filterType5_6"]},
{"Filter_7": ["fc5_7", "q5_7", "gain5_7", "slope5_7", "filterType5_7"]},
{"Filter_8": ["fc5_8", "q5_8", "gain5_8", "slope5_8", "filterType5_8"]},
{"Filter_9": ["fc5_9", "q5_9", "gain5_9", "slope5_9", "filterType5_9"]},
{"Filter_10": ["fc5_10", "q5_10", "gain5_10", "slope5_10", "filterType5_10"]},
{"Filter_11": ["fc5_11", "q5_11", "gain5_11", "slope5_11", "filterType5_11"]},
{"Filter_12": ["fc5_12", "q5_12", "gain5_12", "slope5_12", "filterType5_12"]},
{"Filter_13": ["fc5_13", "q5_13", "gain5_13", "slope5_13", "filterType5_13"]},
{"Filter_14": ["fc5_14", "q5_14", "gain5_14", "slope5_14", "filterType5_14"]},
{"Filter_15": ["fc5_15", "q5_15", "gain5_15", "slope5_15", "filterType5_15"]},
{"Filter_16": ["fc5_16", "q5_16", "gain5_16", "slope5_16", "filterType5_16"]},
{"Filter_17": ["fc5_17", "q5_17", "gain5_17", "slope5_17", "filterType5_17"]},
{"Filter_18": ["fc5_18", "q5_18", "gain5_18", "slope5_18", "filterType5_18"]},
{"Filter_19": ["fc5_19", "q5_19", "gain5_19", "slope5_19", "filterType5_19"]},
{"Filter_20": ["fc5_20", "q5_20", "gain5_20", "slope5_20", "filterType5_20"]}
],
"channel_6": [
{"delay_data1": "delay_data6"},
{"vol_data1": "vol_data6"},
{"mix_right_data1": "mix_right_data6"},
{"mix_left_data1": "mix_left_data6"},
{"Filter_1": ["fc6_1", "q6_1", "gain6_1", "slope6_1", "filterType6_1"]},
{"Filter_2": ["fc6_2", "q6_2", "gain6_2", "slope6_2", "filterType6_2"]},
{"Filter_3": ["fc6_3", "q6_3", "gain6_3", "slope6_3", "filterType6_3"]},
{"Filter_4": ["fc6_4", "q6_4", "gain6_4", "slope6_4", "filterType6_4"]},
{"Filter_5": ["fc6_5", "q6_5", "gain6_5", "slope6_5", "filterType6_5"]},
{"Filter_6": ["fc6_6", "q6_6", "gain6_6", "slope6_6", "filterType6_6"]},
{"Filter_7": ["fc6_7", "q6_7", "gain6_7", "slope6_7", "filterType6_7"]},
{"Filter_8": ["fc6_8", "q6_8", "gain6_8", "slope6_8", "filterType6_8"]},
{"Filter_9": ["fc6_9", "q6_9", "gain6_9", "slope6_9", "filterType6_9"]},
{"Filter_10": ["fc6_10", "q6_10", "gain6_10", "slope6_10", "filterType6_10"]},
{"Filter_11": ["fc6_11", "q6_11", "gain6_11", "slope6_11", "filterType6_11"]},
{"Filter_12": ["fc6_12", "q6_12", "gain6_12", "slope6_12", "filterType6_12"]},
{"Filter_13": ["fc6_13", "q6_13", "gain6_13", "slope6_13", "filterType6_13"]},
{"Filter_14": ["fc6_14", "q6_14", "gain6_14", "slope6_14", "filterType6_14"]},
{"Filter_15": ["fc6_15", "q6_15", "gain6_15", "slope6_15", "filterType6_15"]},
{"Filter_16": ["fc6_16", "q6_16", "gain6_16", "slope6_16", "filterType6_16"]},
{"Filter_17": ["fc6_17", "q6_17", "gain6_17", "slope6_17", "filterType6_17"]},
{"Filter_18": ["fc6_18", "q6_18", "gain6_18", "slope6_18", "filterType6_18"]},
{"Filter_19": ["fc6_19", "q6_19", "gain6_19", "slope6_19", "filterType6_19"]},
{"Filter_20": ["fc6_20", "q6_20", "gain6_20", "slope6_20", "filterType6_20"]}
]
}