Godot Version
4.7.1 stable
Question
Trying to find out if I can generate sound instead of pitching the sample in Godot?
More specifically I mean: different instruments like strings, drums, bass etc.
Godot have way to read midi info, but what about generate them?
Example code from docs
func _ready():
OS.open_midi_inputs()
print(OS.get_connected_midi_inputs())
func _input(input_event):
if input_event is InputEventMIDI:
_print_midi_info(input_event)
func _print_midi_info(midi_event):
print(midi_event)
print("Channel ", midi_event.channel)
print("Message ", midi_event.message)
print("Pitch ", midi_event.pitch)
print("Velocity ", midi_event.velocity)
print("Instrument ", midi_event.instrument)
print("Pressure ", midi_event.pressure)
print("Controller number: ", midi_event.controller_number)
print("Controller value: ", midi_event.controller_value)
I have looked inside MIDI Piano Demo, and this using sample to produce sound - A440.wav
func activate() -> void:
key.color = (Color.YELLOW + start_color) / 2
var audio := AudioStreamPlayer.new()
add_child(audio)
audio.stream = preload("res://piano_keys/A440.wav")
audio.pitch_scale = pitch_scale
audio.play()
color_timer.start()
await get_tree().create_timer(8.0).timeout
audio.queue_free()
