diff --git a/audio/bpm_sync/Control.gd b/audio/bpm_sync/Control.gd index e537f75b..7499dd55 100644 --- a/audio/bpm_sync/Control.gd +++ b/audio/bpm_sync/Control.gd @@ -7,18 +7,34 @@ var playing = false const COMPENSATE_FRAMES = 2 const COMPENSATE_HZ = 60.0 +const SYNC_SOURCE_SYSTEM_CLOCK = 0 +const SYNC_SOURCE_SOUND_CLOCK = 1 + +var sync_source = SYNC_SOURCE_SYSTEM_CLOCK + + func strsec(secs): var s = str(secs) if (s.length()==1): s="0"+s return s -# warning-ignore:unused_argument +# used by system clock +var time_begin +var time_delay + func _process(delta): if (!playing or !$Player.playing): return - var time = $Player.get_mix_time() + AudioServer.get_time_since_last_mix() - AudioServer.get_output_latency() + (1/COMPENSATE_HZ)*COMPENSATE_FRAMES + var time + if (sync_source == SYNC_SOURCE_SYSTEM_CLOCK): + # 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 var beat = int(time * BPM / 60.0) var seconds = int(time) @@ -26,8 +42,18 @@ func _process(delta): $Label.text = str("BEAT: ",beat % BARS +1,"/",BARS," TIME: ",seconds/60,":",strsec(seconds%60)," / ",seconds_total/60,":",strsec(seconds_total%60)) -func _on_Button_pressed(): - print(AudioServer.get_output_latency()) + +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 $Player.play() + +func _on_PlaySound_pressed(): + sync_source = SYNC_SOURCE_SOUND_CLOCK + playing=true + $Player.play() + diff --git a/audio/bpm_sync/play_button.png b/audio/bpm_sync/play_button.png deleted file mode 100644 index b400aebb..00000000 Binary files a/audio/bpm_sync/play_button.png and /dev/null differ diff --git a/audio/bpm_sync/play_button_hl.png b/audio/bpm_sync/play_button_hl.png deleted file mode 100644 index a8d7feaa..00000000 Binary files a/audio/bpm_sync/play_button_hl.png and /dev/null differ diff --git a/audio/bpm_sync/play_sound_button.png b/audio/bpm_sync/play_sound_button.png new file mode 100644 index 00000000..0e53247b Binary files /dev/null and b/audio/bpm_sync/play_sound_button.png differ diff --git a/audio/bpm_sync/play_button.png.import b/audio/bpm_sync/play_sound_button.png.import similarity index 68% rename from audio/bpm_sync/play_button.png.import rename to audio/bpm_sync/play_sound_button.png.import index e6614754..c83cac2d 100644 --- a/audio/bpm_sync/play_button.png.import +++ b/audio/bpm_sync/play_sound_button.png.import @@ -2,15 +2,15 @@ importer="texture" type="StreamTexture" -path="res://.import/play_button.png-c6659eb2fbf2022d9e670864776e465a.stex" +path="res://.import/play_sound_button.png-7e88216154de1a5cb6304cbd3751ed46.stex" metadata={ "vram_texture": false } [deps] -source_file="res://play_button.png" -dest_files=[ "res://.import/play_button.png-c6659eb2fbf2022d9e670864776e465a.stex" ] +source_file="res://play_sound_button.png" +dest_files=[ "res://.import/play_sound_button.png-7e88216154de1a5cb6304cbd3751ed46.stex" ] [params] diff --git a/audio/bpm_sync/play_sound_button_hl.png b/audio/bpm_sync/play_sound_button_hl.png new file mode 100644 index 00000000..c9934f16 Binary files /dev/null and b/audio/bpm_sync/play_sound_button_hl.png differ diff --git a/audio/bpm_sync/play_sound_button_hl.png.import b/audio/bpm_sync/play_sound_button_hl.png.import new file mode 100644 index 00000000..11227315 --- /dev/null +++ b/audio/bpm_sync/play_sound_button_hl.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/play_sound_button_hl.png-8d86f81fe37a5f2959088b0948283133.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://play_sound_button_hl.png" +dest_files=[ "res://.import/play_sound_button_hl.png-8d86f81fe37a5f2959088b0948283133.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/audio/bpm_sync/play_system_button.png b/audio/bpm_sync/play_system_button.png new file mode 100644 index 00000000..7689f179 Binary files /dev/null and b/audio/bpm_sync/play_system_button.png differ diff --git a/audio/bpm_sync/play_button_hl.png.import b/audio/bpm_sync/play_system_button.png.import similarity index 68% rename from audio/bpm_sync/play_button_hl.png.import rename to audio/bpm_sync/play_system_button.png.import index c977dcc2..5e0072ba 100644 --- a/audio/bpm_sync/play_button_hl.png.import +++ b/audio/bpm_sync/play_system_button.png.import @@ -2,15 +2,15 @@ importer="texture" type="StreamTexture" -path="res://.import/play_button_hl.png-63644aa33cad39ca169b518c7eed7ae2.stex" +path="res://.import/play_system_button.png-683c51b4d13189b67bb57e75cbb8ef56.stex" metadata={ "vram_texture": false } [deps] -source_file="res://play_button_hl.png" -dest_files=[ "res://.import/play_button_hl.png-63644aa33cad39ca169b518c7eed7ae2.stex" ] +source_file="res://play_system_button.png" +dest_files=[ "res://.import/play_system_button.png-683c51b4d13189b67bb57e75cbb8ef56.stex" ] [params] diff --git a/audio/bpm_sync/play_system_button_hl.png b/audio/bpm_sync/play_system_button_hl.png new file mode 100644 index 00000000..947dde92 Binary files /dev/null and b/audio/bpm_sync/play_system_button_hl.png differ diff --git a/audio/bpm_sync/play_system_button_hl.png.import b/audio/bpm_sync/play_system_button_hl.png.import new file mode 100644 index 00000000..8b257209 --- /dev/null +++ b/audio/bpm_sync/play_system_button_hl.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/play_system_button_hl.png-1e926e5d1be4f71f60454646aaa44d20.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://play_system_button_hl.png" +dest_files=[ "res://.import/play_system_button_hl.png-1e926e5d1be4f71f60454646aaa44d20.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=true +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/audio/bpm_sync/player.tscn b/audio/bpm_sync/player.tscn index ac119e29..00ef28a6 100644 --- a/audio/bpm_sync/player.tscn +++ b/audio/bpm_sync/player.tscn @@ -1,9 +1,12 @@ -[gd_scene load_steps=7 format=2] +[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://play_button.png" type="Texture" id=4] +[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_sound_button_hl.png" type="Texture" id=7] [sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0, 0, 0, 1 ) @@ -29,14 +32,25 @@ custom_fonts/font = SubResource( 2 ) custom_colors/font_color = Color( 0.552941, 0.984314, 0.501961, 1 ) align = 1 -[node name="Button" type="TextureButton" parent="."] -margin_left = 433.316 -margin_top = 244.158 -margin_right = 561.316 -margin_bottom = 372.158 -texture_normal = ExtResource( 4 ) -texture_pressed = ExtResource( 4 ) - [node name="Player" type="AudioStreamPlayer" parent="."] stream = ExtResource( 1 ) -[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"] + +[node name="PlaySystem" type="TextureButton" parent="."] +margin_left = 214.737 +margin_top = 187.368 +margin_right = 342.737 +margin_bottom = 315.368 +texture_normal = ExtResource( 4 ) +texture_pressed = ExtResource( 4 ) +texture_hover = ExtResource( 6 ) + +[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_hover = ExtResource( 7 ) +[connection signal="pressed" from="PlaySystem" to="." method="_on_PlaySystem_pressed"] +[connection signal="pressed" from="PlaySound" to="." method="_on_PlaySound_pressed"]