Use match case instead of if else in Audio Mic Record demo (#1053)

* Use match case instead of if else

This is my first pull request.

* Apply suggestions from code review

---------

Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
This commit is contained in:
Sectonidse
2024-05-13 20:57:04 +03:00
committed by GitHub
parent 3859c66f0e
commit 8e9c180278

View File

@@ -59,29 +59,31 @@ func _on_SaveButton_pressed():
func _on_MixRateOptionButton_item_selected(index: int) -> void:
if index == 0:
mix_rate = 11025
elif index == 1:
mix_rate = 16000
elif index == 2:
mix_rate = 22050
elif index == 3:
mix_rate = 32000
elif index == 4:
mix_rate = 44100
elif index == 5:
mix_rate = 48000
match index:
0:
mix_rate = 11025
1:
mix_rate = 16000
2:
mix_rate = 22050
3:
mix_rate = 32000
4:
mix_rate = 44100
5:
mix_rate = 48000
if recording != null:
recording.set_mix_rate(mix_rate)
func _on_FormatOptionButton_item_selected(index: int) -> void:
if index == 0:
format = AudioStreamWAV.FORMAT_8_BITS
elif index == 1:
format = AudioStreamWAV.FORMAT_16_BITS
elif index == 2:
format = AudioStreamWAV.FORMAT_IMA_ADPCM
match index:
0:
format = AudioStreamWAV.FORMAT_8_BITS
1:
format = AudioStreamWAV.FORMAT_16_BITS
2:
format = AudioStreamWAV.FORMAT_IMA_ADPCM
if recording != null:
recording.set_format(format)