[feature] 验证通过set/get接口

This commit is contained in:
Sam 2025-02-19 22:23:34 +08:00
parent 04fd71b634
commit 52d7eddf62
3 changed files with 89 additions and 100 deletions

View File

@ -1,7 +1,7 @@
{ {
"folders": [ "folders": [
{ {
"path": "." "path": ".."
} }
], ],
"settings": {} "settings": {}

View File

@ -16,6 +16,7 @@ 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
import resources
class ReadOnlyDelegate(QStyledItemDelegate): class ReadOnlyDelegate(QStyledItemDelegate):
def createEditor(self, parent, option, index): def createEditor(self, parent, option, index):
@ -189,81 +190,58 @@ class AudioFilterWidget(QWidget):
def get_all_params(self) -> Dict[str, Any]: def get_all_params(self) -> Dict[str, Any]:
"""获取所有参数及其映射值""" """获取所有参数及其映射值"""
if not self.current_mapping:
return {}
result = {} result = {}
channel_id = self.channel_id
if not channel_id:
return result
# 获取基础参数 # 获取基础参数
base_params = { delay = self.ui.lineEdit_11.text()
'delay_data1': self.ui.lineEdit_11.text(), vol = self.ui.lineEdit_10.text()
'vol_data1': self.ui.lineEdit_10.text(), mix_right = self.ui.lineEdit_13.text()
'mix_right_data1': self.ui.lineEdit_13.text(), mix_left = self.ui.lineEdit_12.text()
'mix_left_data1': self.ui.lineEdit_12.text()
} # 设置基础参数
if delay:
# 遍历前4个映射项基础参数 result[f'delay_data{channel_id}'] = float(delay)
for item in self.current_mapping[:4]: if vol:
param_name = list(item.values())[0] # 获取映射名称 result[f'vol_data{channel_id}'] = float(vol)
param_key = list(item.keys())[0] # 获取原始键名 if mix_right:
if param_key in base_params: result[f'mix_right_data{channel_id}'] = float(mix_right)
result[param_name] = float(base_params[param_key]) if base_params[param_key] else 0.0 if mix_left:
result[f'mix_left_data{channel_id}'] = float(mix_left)
# 获取滤波器参数 # 获取滤波器参数
for row in range(self.ui.tableWidget.rowCount()): for row in range(self.ui.tableWidget.rowCount()):
map_index = row + 4 # 前4项是基础参数 filter_num = row + 1 # 滤波器编号从1开始
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) freq = self.ui.tableWidget.item(row, 3)
q = self.ui.tableWidget.item(row, 4) q = self.ui.tableWidget.item(row, 4)
gain = self.ui.tableWidget.item(row, 5) gain = self.ui.tableWidget.item(row, 5)
slope = self.ui.tableWidget.item(row, 6) slope = self.ui.tableWidget.item(row, 6)
filter_type_combo = self.ui.tableWidget.cellWidget(row, 2)
# 确保参数名称列表长度正确 # 获取 filterType (combobox)
if len(param_names) != 5: filter_type_combo = self.ui.tableWidget.cellWidget(row, 2)
print(f"Warning: Invalid parameter names list for {filter_key}: {param_names}") if filter_type_combo:
continue result[f'filterType{channel_id}_{filter_num}'] = filter_type_combo.currentIndex()
# 设置频率参数 # 设置频率参数
if freq and freq.text(): if freq and freq.text():
try: result[f'fc{channel_id}_{filter_num}'] = float(freq.text())
result[param_names[0]] = float(freq.text())
except ValueError:
result[param_names[0]] = 0.0
# 设置Q值参数 # 设置Q值参数
if q and q.text(): if q and q.text():
try: result[f'q{channel_id}_{filter_num}'] = float(q.text())
result[param_names[1]] = float(q.text())
except ValueError:
result[param_names[1]] = 0.0
# 设置增益参数 # 设置增益参数
if gain and gain.text(): if gain and gain.text():
try: result[f'gain{channel_id}_{filter_num}'] = float(gain.text())
result[param_names[2]] = float(gain.text())
except ValueError:
result[param_names[2]] = 0.0
# 设置斜率参数 # 设置斜率参数
if slope and slope.text(): if slope and slope.text():
try: result[f'slope{channel_id}_{filter_num}'] = float(slope.text())
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 return result
def set_all_params(self, params: Dict[str, Any]): def set_all_params(self, params: Dict[str, Any]):
@ -290,7 +268,8 @@ class AudioFilterWidget(QWidget):
filter_params = {} filter_params = {}
for key in params: for key in params:
if any(key.startswith(prefix) for prefix in [f'fc{self.channel_id}_', f'q{self.channel_id}_', 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}_']): f'gain{self.channel_id}_', f'slope{self.channel_id}_',
f'filterType{self.channel_id}_']):
filter_num = int(key.split('_')[-1]) filter_num = int(key.split('_')[-1])
if filter_num not in filter_params: if filter_num not in filter_params:
filter_params[filter_num] = {} filter_params[filter_num] = {}
@ -342,6 +321,12 @@ class AudioFilterWidget(QWidget):
# 连接复选框信号 # 连接复选框信号
checkbox.clicked.connect(lambda checked, r=row: self._on_checkbox_clicked(r, checked)) checkbox.clicked.connect(lambda checked, r=row: self._on_checkbox_clicked(r, checked))
# 设置滤波器类型 (combobox)
if 'filterType' in filter_data:
combo = self.ui.tableWidget.cellWidget(row, 2)
if combo:
combo.setCurrentIndex(int(filter_data['filterType']))
# 设置滤波器参数 # 设置滤波器参数
if 'fc' in filter_data: if 'fc' in filter_data:
item = QTableWidgetItem(str(filter_data['fc'])) item = QTableWidgetItem(str(filter_data['fc']))
@ -700,56 +685,60 @@ if __name__ == "__main__":
widget.resize(800, 600) widget.resize(800, 600)
# 测试数据 # 测试数据
widget.set_filters_count(2) # widget.set_filters_count(2)
widget.set_filter_data(0, { # widget.set_filter_data(0, {
'filter_name': 'peak', # 'filter_name': 'peak',
'filter_type': 'PEAK', # 'filter_type': 'PEAK',
'freq': 100, # 'freq': 100,
'q': 1.0, # 'q': 1.0,
'gain': 0.0, # 'gain': 0.0,
'slope': 1.0, # 'slope': 1.0,
'enabled': True # 'enabled': True
}) # })
widget.set_filter_data(1, { # widget.set_filter_data(1, {
'filter_name': 'lowpass', # 'filter_name': 'lowpass',
'filter_type': 'LOWPASS', # 'filter_type': 'LOWPASS',
'freq': 1000, # 'freq': 1000,
'q': 0.7, # 'q': 0.7,
'gain': 0.0, # 'gain': 0.0,
'slope': 2.0, # 'slope': 2.0,
'enabled': True # 'enabled': True
}) # })
widget.set_param_data({ # widget.set_param_data({
'delay_data1': 30, # 'delay_data1': 30,
'ENT_volume_data1': 2, # 'ENT_volume_data1': 2,
'ENT_mx_right_data': 3, # 'ENT_mx_right_data': 3,
'ENT_mix_left_data': 4 # 'ENT_mix_left_data': 4
}) # })
# widget.set_channel_id(1) widget.set_channel_id(2)
widget.set_channel("channel_2") widget.set_channel("channel_2")
# test_params = { test_case_3 = {
# 'delay_data2': 30.0, 'delay_data2': 100.0, # 最大延迟
# 'vol_data2': 2.0, 'vol_data2': -80.0, # 最小音量
# 'mix_right_data2': 3.0, 'mix_right_data2': 100.0, # 最大混音
# 'mix_left_data2': 4.0, 'mix_left_data2': 0.0, # 最小混音
# 'fc2_1': 100.0, 'filterType2_1': 2, # 低架滤波器
# 'q2_1': 1.0, 'fc2_1': 20000.0, # 最大频率
# 'gain2_1': 0.0, 'q2_1': 10.0, # 最大Q值
# 'slope2_1': 1.0, 'gain2_1': 12.0, # 最大增益
# 'fc2_2': 1000.0, 'slope2_1': 4.0, # 最大斜率
# 'q2_2': 0.7, 'filterType2_2': 3, # 高架滤波器
# 'gain2_2': 0.0, 'fc2_2': 20.0, # 最小频率
# 'slope2_2': 2.0 'q2_2': 0.1, # 最小Q值
# }# 设置参数 'gain2_2': -12.0, # 最小增益
'slope2_2': 1.0 # 最小斜率
}
widget.set_all_params(test_case_3)
# widget.set_all_params(test_params) # widget.set_all_params(test_params)
# 获取所有参数 # 获取所有参数
# params = widget.get_all_params() params = widget.get_all_params()
# print("aaaa params:", params) print("aaaa params:", params)
widget.show() widget.show()
sys.exit(app.exec()) sys.exit(app.exec())