[feature] 验证通过set/get接口
This commit is contained in:
parent
04fd71b634
commit
52d7eddf62
@ -1,7 +1,7 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
"path": ".."
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
|
Binary file not shown.
@ -16,6 +16,7 @@ from checkbox_header import SCheckBoxHeaderView
|
||||
from typing import List, Dict, Optional, Any
|
||||
|
||||
# import component.widget_filter.resources
|
||||
import resources
|
||||
|
||||
class ReadOnlyDelegate(QStyledItemDelegate):
|
||||
def createEditor(self, parent, option, index):
|
||||
@ -189,81 +190,58 @@ class AudioFilterWidget(QWidget):
|
||||
|
||||
def get_all_params(self) -> Dict[str, Any]:
|
||||
"""获取所有参数及其映射值"""
|
||||
if not self.current_mapping:
|
||||
return {}
|
||||
|
||||
result = {}
|
||||
|
||||
channel_id = self.channel_id
|
||||
if not channel_id:
|
||||
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
|
||||
|
||||
delay = self.ui.lineEdit_11.text()
|
||||
vol = self.ui.lineEdit_10.text()
|
||||
mix_right = self.ui.lineEdit_13.text()
|
||||
mix_left = self.ui.lineEdit_12.text()
|
||||
|
||||
# 设置基础参数
|
||||
if delay:
|
||||
result[f'delay_data{channel_id}'] = float(delay)
|
||||
if vol:
|
||||
result[f'vol_data{channel_id}'] = float(vol)
|
||||
if mix_right:
|
||||
result[f'mix_right_data{channel_id}'] = float(mix_right)
|
||||
if mix_left:
|
||||
result[f'mix_left_data{channel_id}'] = float(mix_left)
|
||||
|
||||
# 获取滤波器参数
|
||||
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] # 获取参数名称列表
|
||||
filter_num = row + 1 # 滤波器编号从1开始
|
||||
|
||||
# 获取滤波器参数值
|
||||
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
|
||||
|
||||
# 获取 filterType (combobox)
|
||||
filter_type_combo = self.ui.tableWidget.cellWidget(row, 2)
|
||||
if filter_type_combo:
|
||||
result[f'filterType{channel_id}_{filter_num}'] = filter_type_combo.currentIndex()
|
||||
|
||||
# 设置频率参数
|
||||
if freq and freq.text():
|
||||
try:
|
||||
result[param_names[0]] = float(freq.text())
|
||||
except ValueError:
|
||||
result[param_names[0]] = 0.0
|
||||
|
||||
result[f'fc{channel_id}_{filter_num}'] = float(freq.text())
|
||||
|
||||
# 设置Q值参数
|
||||
if q and q.text():
|
||||
try:
|
||||
result[param_names[1]] = float(q.text())
|
||||
except ValueError:
|
||||
result[param_names[1]] = 0.0
|
||||
|
||||
result[f'q{channel_id}_{filter_num}'] = float(q.text())
|
||||
|
||||
# 设置增益参数
|
||||
if gain and gain.text():
|
||||
try:
|
||||
result[param_names[2]] = float(gain.text())
|
||||
except ValueError:
|
||||
result[param_names[2]] = 0.0
|
||||
|
||||
result[f'gain{channel_id}_{filter_num}'] = float(gain.text())
|
||||
|
||||
# 设置斜率参数
|
||||
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()
|
||||
|
||||
result[f'slope{channel_id}_{filter_num}'] = float(slope.text())
|
||||
|
||||
return result
|
||||
|
||||
def set_all_params(self, params: Dict[str, Any]):
|
||||
@ -290,7 +268,8 @@ class AudioFilterWidget(QWidget):
|
||||
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}_']):
|
||||
f'gain{self.channel_id}_', f'slope{self.channel_id}_',
|
||||
f'filterType{self.channel_id}_']):
|
||||
filter_num = int(key.split('_')[-1])
|
||||
if filter_num not in filter_params:
|
||||
filter_params[filter_num] = {}
|
||||
@ -342,6 +321,12 @@ class AudioFilterWidget(QWidget):
|
||||
# 连接复选框信号
|
||||
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:
|
||||
item = QTableWidgetItem(str(filter_data['fc']))
|
||||
@ -700,56 +685,60 @@ if __name__ == "__main__":
|
||||
widget.resize(800, 600)
|
||||
|
||||
# 测试数据
|
||||
widget.set_filters_count(2)
|
||||
widget.set_filter_data(0, {
|
||||
'filter_name': 'peak',
|
||||
'filter_type': 'PEAK',
|
||||
'freq': 100,
|
||||
'q': 1.0,
|
||||
'gain': 0.0,
|
||||
'slope': 1.0,
|
||||
'enabled': True
|
||||
})
|
||||
widget.set_filter_data(1, {
|
||||
'filter_name': 'lowpass',
|
||||
'filter_type': 'LOWPASS',
|
||||
'freq': 1000,
|
||||
'q': 0.7,
|
||||
'gain': 0.0,
|
||||
'slope': 2.0,
|
||||
'enabled': True
|
||||
})
|
||||
# widget.set_filters_count(2)
|
||||
# widget.set_filter_data(0, {
|
||||
# 'filter_name': 'peak',
|
||||
# 'filter_type': 'PEAK',
|
||||
# 'freq': 100,
|
||||
# 'q': 1.0,
|
||||
# 'gain': 0.0,
|
||||
# 'slope': 1.0,
|
||||
# 'enabled': True
|
||||
# })
|
||||
# widget.set_filter_data(1, {
|
||||
# 'filter_name': 'lowpass',
|
||||
# 'filter_type': 'LOWPASS',
|
||||
# 'freq': 1000,
|
||||
# 'q': 0.7,
|
||||
# 'gain': 0.0,
|
||||
# 'slope': 2.0,
|
||||
# 'enabled': True
|
||||
# })
|
||||
|
||||
widget.set_param_data({
|
||||
'delay_data1': 30,
|
||||
'ENT_volume_data1': 2,
|
||||
'ENT_mx_right_data': 3,
|
||||
'ENT_mix_left_data': 4
|
||||
})
|
||||
# widget.set_param_data({
|
||||
# 'delay_data1': 30,
|
||||
# 'ENT_volume_data1': 2,
|
||||
# 'ENT_mx_right_data': 3,
|
||||
# 'ENT_mix_left_data': 4
|
||||
# })
|
||||
|
||||
# widget.set_channel_id(1)
|
||||
widget.set_channel_id(2)
|
||||
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
|
||||
# }# 设置参数
|
||||
test_case_3 = {
|
||||
'delay_data2': 100.0, # 最大延迟
|
||||
'vol_data2': -80.0, # 最小音量
|
||||
'mix_right_data2': 100.0, # 最大混音
|
||||
'mix_left_data2': 0.0, # 最小混音
|
||||
'filterType2_1': 2, # 低架滤波器
|
||||
'fc2_1': 20000.0, # 最大频率
|
||||
'q2_1': 10.0, # 最大Q值
|
||||
'gain2_1': 12.0, # 最大增益
|
||||
'slope2_1': 4.0, # 最大斜率
|
||||
'filterType2_2': 3, # 高架滤波器
|
||||
'fc2_2': 20.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)
|
||||
|
||||
# 获取所有参数
|
||||
# params = widget.get_all_params()
|
||||
# print("aaaa params:", params)
|
||||
params = widget.get_all_params()
|
||||
print("aaaa params:", params)
|
||||
|
||||
widget.show()
|
||||
sys.exit(app.exec())
|
Loading…
Reference in New Issue
Block a user