Update Audio demos for Godot 3.1.1

This commit is contained in:
Aaron Franke
2019-09-01 01:03:32 -04:00
parent 50d5a118c9
commit 617896737e
13 changed files with 67 additions and 68 deletions

View File

@@ -12,48 +12,46 @@ const SYNC_SOURCE_SOUND_CLOCK = 1
var sync_source = SYNC_SOURCE_SYSTEM_CLOCK
# Used by system clock.
var time_begin
var time_delay
func strsec(secs):
var s = str(secs)
if (s.length()==1):
s="0"+s
if (secs < 10):
s = "0" + s
return s
# used by system clock
var time_begin
var time_delay
func _process(delta):
func _process(_delta):
if (!playing or !$Player.playing):
return
var time
var time = 0.0
if (sync_source == SYNC_SOURCE_SYSTEM_CLOCK):
# obtain from ticks
# Obtain from ticks.
time = (OS.get_ticks_usec() - time_begin) / 1000000.0
# compensate
time -= time_delay
elif (sync_source == SYNC_SOURCE_SOUND_CLOCK):
time = $Player.get_playback_position() + AudioServer.get_time_since_last_mix() - AudioServer.get_output_latency() + (1/COMPENSATE_HZ)*COMPENSATE_FRAMES
# Compensate.
time -= time_delay
elif (sync_source == SYNC_SOURCE_SOUND_CLOCK):
time = $Player.get_playback_position() + AudioServer.get_time_since_last_mix() - AudioServer.get_output_latency() + (1 / COMPENSATE_HZ) * COMPENSATE_FRAMES
var beat = int(time * BPM / 60.0)
var seconds = int(time)
var seconds_total = int($Player.stream.get_length())
$Label.text = str("BEAT: ",beat % BARS +1,"/",BARS," TIME: ",seconds/60,":",strsec(seconds%60)," / ",seconds_total/60,":",strsec(seconds_total%60))
$Label.text = str("BEAT: ", beat % BARS + 1, "/", BARS, " TIME: ", seconds / 60, ":", strsec(seconds % 60), " / ", seconds_total / 60, ":", strsec(seconds_total % 60))
func _on_PlaySystem_pressed():
pass # Replace with function body.
sync_source = SYNC_SOURCE_SYSTEM_CLOCK
time_begin = OS.get_ticks_usec()
time_delay = AudioServer.get_time_to_next_mix() + AudioServer.get_output_latency()
playing=true
playing = true
$Player.play()
func _on_PlaySound_pressed():
sync_source = SYNC_SOURCE_SOUND_CLOCK
playing=true
playing = true
$Player.play()

View File

@@ -1,11 +1,11 @@
[gd_scene load_steps=10 format=2]
[ext_resource path="res://the_comeback2.ogg" type="AudioStream" id=1]
[ext_resource path="res://Control.gd" type="Script" id=2]
[ext_resource path="res://lcd.ttf" type="DynamicFontData" id=3]
[ext_resource path="res://Control.gd" type="Script" id=1]
[ext_resource path="res://lcd.ttf" type="DynamicFontData" id=2]
[ext_resource path="res://the_comeback2.ogg" type="AudioStream" id=3]
[ext_resource path="res://play_system_button.png" type="Texture" id=4]
[ext_resource path="res://play_sound_button.png" type="Texture" id=5]
[ext_resource path="res://play_system_button_hl.png" type="Texture" id=6]
[ext_resource path="res://play_system_button_hl.png" type="Texture" id=5]
[ext_resource path="res://play_sound_button.png" type="Texture" id=6]
[ext_resource path="res://play_sound_button_hl.png" type="Texture" id=7]
[sub_resource type="StyleBoxFlat" id=1]
@@ -15,13 +15,16 @@ bg_color = Color( 0, 0, 0, 1 )
size = 40
outline_size = 2
outline_color = Color( 0.588235, 0.886275, 0.435294, 0.239216 )
font_data = ExtResource( 3 )
font_data = ExtResource( 2 )
[node name="Control" type="Panel"]
anchor_right = 1.0
anchor_bottom = 1.0
custom_styles/panel = SubResource( 1 )
script = ExtResource( 2 )
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="."]
margin_left = 106.895
@@ -33,7 +36,7 @@ custom_colors/font_color = Color( 0.552941, 0.984314, 0.501961, 1 )
align = 1
[node name="Player" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 1 )
stream = ExtResource( 3 )
[node name="PlaySystem" type="TextureButton" parent="."]
margin_left = 214.737
@@ -42,15 +45,15 @@ margin_right = 342.737
margin_bottom = 315.368
texture_normal = ExtResource( 4 )
texture_pressed = ExtResource( 4 )
texture_hover = ExtResource( 6 )
texture_hover = ExtResource( 5 )
[node name="PlaySound" type="TextureButton" parent="."]
margin_left = 622.105
margin_top = 183.158
margin_right = 750.105
margin_bottom = 311.158
texture_normal = ExtResource( 5 )
texture_pressed = ExtResource( 5 )
texture_normal = ExtResource( 6 )
texture_pressed = ExtResource( 6 )
texture_hover = ExtResource( 7 )
[connection signal="pressed" from="PlaySystem" to="." method="_on_PlaySystem_pressed"]
[connection signal="pressed" from="PlaySound" to="." method="_on_PlaySound_pressed"]

View File

@@ -15,4 +15,5 @@ _global_script_class_icons={
[application]
config/name="BPM Sync Demo"
run/main_scene="res://player.tscn"