#  sfzen/cleaners/liquidsfz.py
#
#  Copyright 2025 Leon Dionne <ldionne@dridesign.sh.cn>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#
"""
Cleanup opcodes that LiquidSFZ does not understand.
"""
from sfzen.sfz_elems import Header, normal_opcode

SUPPORTED_OPCODES = [
	'amp_random',
	'amp_velcurve_N',
	'amp_veltrack',
	'ampeg_attack',
	'ampeg_attack_onccN',
	'ampeg_attackccN',
	'ampeg_decay',
	'ampeg_decay_curveccN',
	'ampeg_decay_onccN',
	'ampeg_decayccN',
	'ampeg_delay',
	'ampeg_delay_onccN',
	'ampeg_delayccN',
	'ampeg_hold',
	'ampeg_hold_curveccN',
	'ampeg_hold_onccN',
	'ampeg_holdccN',
	'ampeg_release',
	'ampeg_release_onccN',
	'ampeg_releaseccN',
	'ampeg_sustain',
	'ampeg_sustain_curveccN',
	'ampeg_sustain_onccN',
	'ampeg_sustainccN',
	'ampeg_vel2attack',
	'ampeg_vel2decay',
	'ampeg_vel2delay',
	'ampeg_vel2hold',
	'ampeg_vel2release',
	'ampeg_vel2sustain',
	'amplfo_delay',
	'amplfo_depth',
	'amplfo_depthccN',
	'amplfo_fade',
	'amplfo_freq',
	'amplfo_freqccN',
	'amplitude',
	'amplitude_ccN',
	'amplitude_curveccN',
	'amplitude_onccN',
	'bend_down',
	'bend_up',
	'cutoff',
	'cutoff2',
	'cutoff2_curveccN',
	'cutoff2_onccN',
	'cutoff_ccN',
	'cutoff_curveccN',
	'cutoff_onccN',
	'default_path',
	'delay',
	'delay_ccN',
	'delay_curveccN',
	'delay_onccN',
	'fil2_keycenter',
	'fil2_keytrack',
	'fil2_veltrack',
	'fil_keycenter',
	'fil_keytrack',
	'fil_veltrack',
	'fileg_attack',
	'fileg_attack_onccN',
	'fileg_attackccN',
	'fileg_decay',
	'fileg_decay_onccN',
	'fileg_decayccN',
	'fileg_delay',
	'fileg_delay_onccN',
	'fileg_delayccN',
	'fileg_depth',
	'fileg_depth_onccN',
	'fileg_depthccN',
	'fileg_hold',
	'fileg_hold_onccN',
	'fileg_holdccN',
	'fileg_release',
	'fileg_release_onccN',
	'fileg_releaseccN',
	'fileg_sustain',
	'fileg_sustain_onccN',
	'fileg_sustainccN',
	'fileg_vel2attack',
	'fileg_vel2decay',
	'fileg_vel2delay',
	'fileg_vel2depth',
	'fileg_vel2hold',
	'fileg_vel2release',
	'fileg_vel2sustain',
	'fillfo_delay',
	'fillfo_depth',
	'fillfo_depthccN',
	'fillfo_fade',
	'fillfo_freq',
	'fillfo_freqccN',
	'gain_ccN',
	'group',
	'hiccN',
	'hikey',
	'hirand',
	'hivel',
	'key',
	'label_ccN',
	'label_keyN',
	'lfoN_cutoff',
	'lfoN_cutoff_onccN',
	'lfoN_delay',
	'lfoN_delay_onccN',
	'lfoN_fade',
	'lfoN_fade_onccN',
	'lfoN_freq',
	'lfoN_freq_lfoN',
	'lfoN_freq_lfoN_onccN',
	'lfoN_freq_onccN',
	'lfoN_phase',
	'lfoN_phase_onccN',
	'lfoN_pitch',
	'lfoN_pitch_curveccN',
	'lfoN_pitch_onccN',
	'lfoN_volume',
	'lfoN_volume_onccN',
	'lfoN_wave',
	'loccN',
	'lokey',
	'loop_end',
	'loop_mode',
	'loop_start',
	'loopend',
	'loopmode',
	'loopstart',
	'lorand',
	'lovel',
	'off_by',
	'off_mode',
	'off_time',
	'offby',
	'offset',
	'offset_ccN',
	'offset_onccN',
	'offset_random',
	'on_hiccN',
	'on_loccN',
	'pan',
	'pan_ccN',
	'pan_curveccN',
	'pan_onccN',
	'pitch',
	'pitch_curveccN',
	'pitch_keycenter',
	'pitch_keytrack',
	'pitch_onccN',
	'pitch_random',
	'pitchlfo_delay',
	'pitchlfo_depth',
	'pitchlfo_depthccN',
	'pitchlfo_fade',
	'pitchlfo_freq',
	'pitchlfo_freqccN',
	'resonance',
	'resonance2',
	'resonance2_ccN',
	'resonance2_curveccN',
	'resonance2_onccN',
	'resonance_ccN',
	'resonance_curveccN',
	'resonance_onccN',
	'rt_decay',
	'sample',
	'seq_length',
	'seq_position',
	'set_ccN',
	'set_hdccN',
	'set_realccN',
	'sw_default',
	'sw_hikey',
	'sw_hilast',
	'sw_label',
	'sw_last',
	'sw_lokey',
	'sw_lolast',
	'transpose',
	'trigger',
	'tune',
	'tune_ccN',
	'tune_curveccN',
	'tune_onccN',
	'volume',
	'volume_curveccN',
	'volume_onccN',
	'xf_cccurve',
	'xf_keycurve',
	'xf_velcurve',
	'xfin_hiccN',
	'xfin_hikey',
	'xfin_hivel',
	'xfin_loccN',
	'xfin_lokey',
	'xfin_lovel',
	'xfout_hiccN',
	'xfout_hikey',
	'xfout_hivel',
	'xfout_loccN',
	'xfout_lokey',
	'xfout_lovel'
]

def clean(sfz):
	for elem, _ in sfz.walk():
		if isinstance(elem, Header):
			elem._opcodes = { key:opcode \
				for key, opcode in elem._opcodes.items() \
				if normal_opcode(key) in SUPPORTED_OPCODES }


#  end sfzen/cleaners/liquidsfz.py
