added db meter, beat meter; unsure of accuracy

This commit is contained in:
Adam Burns 2026-03-12 20:37:09 -04:00
parent 99fec4d07d
commit 6cedd51ec1
2 changed files with 72 additions and 9 deletions

View File

@ -18,45 +18,51 @@ var seconds_per_beat: float
var useconds_per_beat: float
var song_time_elapsed: float = 0.0
var total_time_elapsed: float = 0.0
#var fmod: float
var is_running: bool = false
var start_time: float
var end_time: float
var ready_time: float
var delay_time: float
var click_track_stream: AudioStream
#var delay_time: float
@onready var beat_bar: ProgressBar = %BeatBar
@onready var click_track: AudioStreamPlayer2D = %ClickTrack
@onready var beat_time_value: Label = %BeatTimeValue
@onready var volume_bar_left: ProgressBar = %VolumeBarLeft
@onready var volume_bar_right: ProgressBar = %VolumeBarRight
## OVERRIDES
func _ready() -> void:
click_track_stream = click_track.stream
ready_time = Time.get_ticks_usec()
print("Ready time: %s" % ready_time)
print("Buses at index 0: %s" % AudioServer.get_bus_name(0))
print("Channels on Bus 0: %s" % AudioServer.get_bus_channels(0))
#var time_to_next_mix: float = AudioServer.get_time_to_next_mix()
#print(time_to_next_mix)
#var output_latency: float = AudioServer.get_output_latency()
#print(output_latency)
#var mix_rate: float = AudioServer.get_mix_rate()
#print(mix_rate)
#delay_time = time_to_next_mix + output_latency
#print(delay_time)
seconds_per_beat = 60.0/float(tempo)
useconds_per_beat = seconds_per_beat * 1000000.0
#print(useconds_per_beat)
beat_bar.max_value = useconds_per_beat
func _process(_delta: float) -> void:
total_time_elapsed = Time.get_ticks_usec()
#print("total time: %s" % total_time_elapsed)
if is_running:
volume_bar_left.value = AudioServer.get_bus_peak_volume_left_db(0, 0)
volume_bar_right.value = AudioServer.get_bus_peak_volume_right_db(0, 0)
song_time_elapsed = total_time_elapsed - start_time
#print("song time elapsed: %s" % song_time_elapsed)
beat_time_elapsed = song_time_elapsed - beat_time_start
beat_time_value.text = str(beat_time_elapsed) + " usec"
beat_bar.value = beat_time_elapsed
#print("beat time elapsed: %s" % beat_time_elapsed)
#fmod = fmod(total_time_elapsed, useconds_per_beat)
#print(fmod)
if beat_time_elapsed >= useconds_per_beat:
#print("This beat took %s useconds" % beat_time_elapsed)
beats_elapsed += 1
print("that's beat %s in the books" % beats_elapsed)
beat_time_elapsed = 0.0
beat_time_start = song_time_elapsed

View File

@ -21,6 +21,63 @@ offset_bottom = 40.0
layout_mode = 2
text = "To start the song, press the space bar"
[node name="CenterContainer" type="CenterContainer" parent="RhythmUI/VBoxContainer" unique_id=1786697862]
layout_mode = 2
[node name="BeatBar" type="ProgressBar" parent="RhythmUI/VBoxContainer/CenterContainer" unique_id=689113732]
unique_name_in_owner = true
custom_minimum_size = Vector2(25, 100)
layout_mode = 2
step = 1000.0
fill_mode = 3
show_percentage = false
[node name="BeatTimeContainer" type="HBoxContainer" parent="RhythmUI/VBoxContainer" unique_id=939740311]
layout_mode = 2
[node name="BeatTimeLabel" type="Label" parent="RhythmUI/VBoxContainer/BeatTimeContainer" unique_id=1501410183]
layout_mode = 2
text = "Beat time elapsed: "
[node name="BeatTimeValue" type="Label" parent="RhythmUI/VBoxContainer/BeatTimeContainer" unique_id=1689122612]
unique_name_in_owner = true
layout_mode = 2
text = "00000"
[node name="VolumeContainer" type="HBoxContainer" parent="RhythmUI/VBoxContainer" unique_id=845038304]
layout_mode = 2
[node name="VolumeLabel" type="Label" parent="RhythmUI/VBoxContainer/VolumeContainer" unique_id=1552250086]
layout_mode = 2
text = "Volume L: "
[node name="VolumeBarLeft" type="ProgressBar" parent="RhythmUI/VBoxContainer/VolumeContainer" unique_id=1551568889]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 24)
layout_mode = 2
size_flags_horizontal = 3
min_value = -200.0
max_value = 0.0
fill_mode = 1
show_percentage = false
[node name="VolumeContainerRight" type="HBoxContainer" parent="RhythmUI/VBoxContainer" unique_id=1505527639]
layout_mode = 2
[node name="VolumeLabel" type="Label" parent="RhythmUI/VBoxContainer/VolumeContainerRight" unique_id=96518109]
layout_mode = 2
text = "Volume R: "
[node name="VolumeBarRight" type="ProgressBar" parent="RhythmUI/VBoxContainer/VolumeContainerRight" unique_id=61396610]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 24)
layout_mode = 2
size_flags_horizontal = 3
min_value = -200.0
max_value = 0.0
fill_mode = 1
show_percentage = false
[node name="ClickTrack" type="AudioStreamPlayer2D" parent="." unique_id=875092300]
unique_name_in_owner = true
stream = ExtResource("2_6v8l0")