Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple sound node #27

Merged
merged 2 commits into from
Jun 19, 2024
Merged

Add simple sound node #27

merged 2 commits into from
Jun 19, 2024

Conversation

starnight
Copy link
Contributor

@starnight starnight commented Jun 14, 2024

@starnight starnight requested review from manuq and wnbaum June 14, 2024 10:35
@starnight starnight marked this pull request as draft June 14, 2024 10:35
@starnight
Copy link
Contributor Author

I do not know the path addons/block_code/simple_nodes/simple_sound is appropriate, or not. Suggestion is welcomed.

Other questions:

  • stream is an exposed property. Should it be set in ready()? Or, user can set it within Godot?
  • Does the block programming support a parameter's default value? For example the Volume dB.
  • Does the block programming support multiple parameters?

Set this as a draft, due to the questions

@wnbaum
Copy link
Contributor

wnbaum commented Jun 14, 2024

I do not know the path addons/block_code/simple_nodes/simple_sound is appropriate, or not. Suggestion is welcomed.

Other questions:

  • stream is an exposed property. Should it be set in ready()? Or, user can set it within Godot?
  • Does the block programming support a parameter's default value? For example the Volume dB.
  • Does the block programming support multiple parameters?

Set this as a draft, due to the questions

  • The path is correct, so that's good.
  • I think eventually we could have a way for the user to set the stream/sound via blocks, but setting it from the inspector is fine for now, so you don't have to expose stream.
  • Default parameters aren't implemented yet, but we are working on it.
  • Yes, you can add multiple parameters to a block, for example this "Add NODE to GROUP" block:
b = BLOCKS["statement_block"].instantiate()
b.block_format = "Add {node: NODE} to group {group: STRING}"
b.statement = "{node}.add_to_group({group})"
signal_list.append(b)

@starnight starnight marked this pull request as ready for review June 17, 2024 06:15
@starnight starnight requested a review from wnbaum June 17, 2024 06:15
@manuq
Copy link
Contributor

manuq commented Jun 17, 2024

This will need an AudioStreamPlayer node with a BlockCode node attached to it with a single "Play the sound" block attached.

Maybe it's better to have the "Play sound" in every node and instantiate AudioStreamPlayer programatically. Something like:

var sound = AudioStreamPlayer.new()
add_child(sound)
var stream = load("res://../some.ogg")
sound.set_stream(stream)
# optionally parameters for volume and pitch:
# sound.volume_db = 1
# sound.pitch_scale = 1
sound.play()

@starnight
Copy link
Contributor Author

#36 (comment) gives me a good direction! :)

I think we can have 2 blocks:

  • Load the audio file as the sound and add the sound as a child of the node: This can be used in _ready().
  • Find the child node sound, then play the sound with dB and pitch: This can be used in a signal handler, for example.

The sound can be passed by add_child() and find_child(). The node's name is the key for finding.

Screenshot from 2024-06-18 17-51-13

Copy link
Contributor

@manuq manuq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the UI these blocks should look with knobs at the top and bottom. So they need to instantiate "statement_block".

@manuq
Copy link
Contributor

manuq commented Jun 18, 2024

The sound can be passed by add_child() and find_child(). The node's name is the key for finding.

This is looking great, but I wasn't able to make it work. Here is my attempt. I get a runtime error setting volume_db in a null instance.
Captura desde 2024-06-18 10-17-56

Add blocks:
* Load the audio file as the sound
* Play the sound with dB and pitch

https://phabricator.endlessm.com/T35501
@starnight
Copy link
Contributor Author

Hmm! I forget set the child node's owner: sound.set_owner(self)

Here is the test, and works now!
image

extends SimpleCharacter

var VAR_DICT := {}

func _ready():
	print('Hi Manuel!')
	add_to_group('Player')
	var signal_manager = get_tree().root.get_node_or_null("SignalManager")
	if signal_manager:
		signal_manager.broadcast_signal('Player', 'will_hi')
	var sound = AudioStreamPlayer.new()
	sound.name = 'testsound'
	sound.set_stream(load('res://test_game/score.ogg'))
	add_child(sound)
	sound.set_owner(self)

func _physics_process(delta):
	velocity = Input.get_vector("player_2_left", "player_2_right", "player_2_up", "player_2_down")*600
	move_and_slide()
	if Input.is_action_pressed("ui_right"):
		var sound = find_child('testsound')
		sound.volume_db = 0
		sound.pitch_scale = 1
		sound.play()


Debug script! (not saved)

@starnight starnight requested a review from manuq June 19, 2024 04:43
@manuq manuq merged commit 2772a46 into main Jun 19, 2024
2 checks passed
@manuq manuq deleted the add-sound-block branch June 19, 2024 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants