Add a BPM sync tutorial.

This commit is contained in:
Juan Linietsky
2019-04-27 14:14:17 -03:00
parent c819e3b276
commit e22a46f301
10 changed files with 176 additions and 0 deletions

33
audio/bpm_sync/Control.gd Normal file
View File

@@ -0,0 +1,33 @@
extends Panel
const BPM = 116
const BARS = 4
var playing = false
const COMPENSATE_FRAMES = 2
const COMPENSATE_HZ = 60.0
func strsec(secs):
var s = str(secs)
if (s.length()==1):
s="0"+s
return s
# warning-ignore:unused_argument
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 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))
func _on_Button_pressed():
print(AudioServer.get_output_latency())
playing=true
$Player.play()

BIN
audio/bpm_sync/lcd.ttf Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/play_button.png-c6659eb2fbf2022d9e670864776e465a.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://play_button.png"
dest_files=[ "res://.import/play_button.png-c6659eb2fbf2022d9e670864776e465a.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/play_button_hl.png-63644aa33cad39ca169b518c7eed7ae2.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://play_button_hl.png"
dest_files=[ "res://.import/play_button_hl.png-63644aa33cad39ca169b518c7eed7ae2.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

View File

@@ -0,0 +1,42 @@
[gd_scene load_steps=7 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]
[sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0, 0, 0, 1 )
[sub_resource type="DynamicFont" id=2]
size = 40
outline_size = 2
outline_color = Color( 0.588235, 0.886275, 0.435294, 0.239216 )
font_data = ExtResource( 3 )
[node name="Control" type="Panel"]
anchor_right = 1.0
anchor_bottom = 1.0
custom_styles/panel = SubResource( 1 )
script = ExtResource( 2 )
[node name="Label" type="Label" parent="."]
margin_left = 106.895
margin_top = 427.158
margin_right = 914.895
margin_bottom = 488.158
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"]

View File

@@ -0,0 +1,18 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
_global_script_classes=[ ]
_global_script_class_icons={
}
[application]
run/main_scene="res://player.tscn"

Binary file not shown.

View File

@@ -0,0 +1,15 @@
[remap]
importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/the_comeback2.ogg-4b85e06ff00ff611cbd6022fc43aade8.oggstr"
[deps]
source_file="res://the_comeback2.ogg"
dest_files=[ "res://.import/the_comeback2.ogg-4b85e06ff00ff611cbd6022fc43aade8.oggstr" ]
[params]
loop=true
loop_offset=0