From 52d7eddf6252d825bc9e9d996d5dca5f80fc2569 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 19 Feb 2025 22:23:34 +0800 Subject: [PATCH] =?UTF-8?q?[feature]=20=E9=AA=8C=E8=AF=81=E9=80=9A?= =?UTF-8?q?=E8=BF=87set/get=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Avas_System.code-workspace | 2 +- .../list_table_config.cpython-313.pyc | Bin 9717 -> 9717 bytes .../widget_filter/audio_filter_componet.py | 187 +++++++++--------- 3 files changed, 89 insertions(+), 100 deletions(-) diff --git a/Avas_System.code-workspace b/Avas_System.code-workspace index 876a149..bab1b7f 100644 --- a/Avas_System.code-workspace +++ b/Avas_System.code-workspace @@ -1,7 +1,7 @@ { "folders": [ { - "path": "." + "path": ".." } ], "settings": {} diff --git a/component/widget_filter/__pycache__/list_table_config.cpython-313.pyc b/component/widget_filter/__pycache__/list_table_config.cpython-313.pyc index 9e78fb14f86f2eb68fb25a2b749c89d7bfd155e2..38700d93635f4c537ea2eec91f350cac1c89fc23 100644 GIT binary patch delta 19 ZcmezB{neZ6GcPX}0}xz!ypij*Dga7U2P6Oh delta 19 ZcmezB{neZ6GcPX}0}!0KwUO(!Dga6M2NM7Q diff --git a/component/widget_filter/audio_filter_componet.py b/component/widget_filter/audio_filter_componet.py index a9c229a..0267bc8 100644 --- a/component/widget_filter/audio_filter_componet.py +++ b/component/widget_filter/audio_filter_componet.py @@ -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()) \ No newline at end of file