Skip to content

Commit e22a46f

Browse files
committed
Add a BPM sync tutorial.
1 parent c819e3b commit e22a46f

File tree

10 files changed

+176
-0
lines changed

10 files changed

+176
-0
lines changed

audio/bpm_sync/Control.gd

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
extends Panel
2+
3+
const BPM = 116
4+
const BARS = 4
5+
6+
var playing = false
7+
const COMPENSATE_FRAMES = 2
8+
const COMPENSATE_HZ = 60.0
9+
10+
func strsec(secs):
11+
var s = str(secs)
12+
if (s.length()==1):
13+
s="0"+s
14+
return s
15+
16+
# warning-ignore:unused_argument
17+
func _process(delta):
18+
if (!playing or !$Player.playing):
19+
return
20+
21+
var time = $Player.get_mix_time() + AudioServer.get_time_since_last_mix() - AudioServer.get_output_latency() + (1/COMPENSATE_HZ)*COMPENSATE_FRAMES
22+
23+
var beat = int(time * BPM / 60.0)
24+
var seconds = int(time)
25+
var seconds_total = int($Player.stream.get_length())
26+
$Label.text = str("BEAT: ",beat % BARS +1,"/",BARS," TIME: ",seconds/60,":",strsec(seconds%60)," / ",seconds_total/60,":",strsec(seconds_total%60))
27+
28+
29+
func _on_Button_pressed():
30+
print(AudioServer.get_output_latency())
31+
playing=true
32+
$Player.play()
33+

audio/bpm_sync/lcd.ttf

30.7 KB
Binary file not shown.

audio/bpm_sync/play_button.png

2.41 KB
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="StreamTexture"
5+
path="res://.import/play_button.png-c6659eb2fbf2022d9e670864776e465a.stex"
6+
metadata={
7+
"vram_texture": false
8+
}
9+
10+
[deps]
11+
12+
source_file="res://play_button.png"
13+
dest_files=[ "res://.import/play_button.png-c6659eb2fbf2022d9e670864776e465a.stex" ]
14+
15+
[params]
16+
17+
compress/mode=0
18+
compress/lossy_quality=0.7
19+
compress/hdr_mode=0
20+
compress/bptc_ldr=0
21+
compress/normal_map=0
22+
flags/repeat=0
23+
flags/filter=true
24+
flags/mipmaps=false
25+
flags/anisotropic=false
26+
flags/srgb=2
27+
process/fix_alpha_border=true
28+
process/premult_alpha=false
29+
process/HDR_as_SRGB=false
30+
process/invert_color=false
31+
stream=false
32+
size_limit=0
33+
detect_3d=true
34+
svg/scale=1.0

audio/bpm_sync/play_button_hl.png

2.11 KB
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="StreamTexture"
5+
path="res://.import/play_button_hl.png-63644aa33cad39ca169b518c7eed7ae2.stex"
6+
metadata={
7+
"vram_texture": false
8+
}
9+
10+
[deps]
11+
12+
source_file="res://play_button_hl.png"
13+
dest_files=[ "res://.import/play_button_hl.png-63644aa33cad39ca169b518c7eed7ae2.stex" ]
14+
15+
[params]
16+
17+
compress/mode=0
18+
compress/lossy_quality=0.7
19+
compress/hdr_mode=0
20+
compress/bptc_ldr=0
21+
compress/normal_map=0
22+
flags/repeat=0
23+
flags/filter=true
24+
flags/mipmaps=false
25+
flags/anisotropic=false
26+
flags/srgb=2
27+
process/fix_alpha_border=true
28+
process/premult_alpha=false
29+
process/HDR_as_SRGB=false
30+
process/invert_color=false
31+
stream=false
32+
size_limit=0
33+
detect_3d=true
34+
svg/scale=1.0

audio/bpm_sync/player.tscn

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[gd_scene load_steps=7 format=2]
2+
3+
[ext_resource path="res://the_comeback2.ogg" type="AudioStream" id=1]
4+
[ext_resource path="res://Control.gd" type="Script" id=2]
5+
[ext_resource path="res://lcd.ttf" type="DynamicFontData" id=3]
6+
[ext_resource path="res://play_button.png" type="Texture" id=4]
7+
8+
[sub_resource type="StyleBoxFlat" id=1]
9+
bg_color = Color( 0, 0, 0, 1 )
10+
11+
[sub_resource type="DynamicFont" id=2]
12+
size = 40
13+
outline_size = 2
14+
outline_color = Color( 0.588235, 0.886275, 0.435294, 0.239216 )
15+
font_data = ExtResource( 3 )
16+
17+
[node name="Control" type="Panel"]
18+
anchor_right = 1.0
19+
anchor_bottom = 1.0
20+
custom_styles/panel = SubResource( 1 )
21+
script = ExtResource( 2 )
22+
23+
[node name="Label" type="Label" parent="."]
24+
margin_left = 106.895
25+
margin_top = 427.158
26+
margin_right = 914.895
27+
margin_bottom = 488.158
28+
custom_fonts/font = SubResource( 2 )
29+
custom_colors/font_color = Color( 0.552941, 0.984314, 0.501961, 1 )
30+
align = 1
31+
32+
[node name="Button" type="TextureButton" parent="."]
33+
margin_left = 433.316
34+
margin_top = 244.158
35+
margin_right = 561.316
36+
margin_bottom = 372.158
37+
texture_normal = ExtResource( 4 )
38+
texture_pressed = ExtResource( 4 )
39+
40+
[node name="Player" type="AudioStreamPlayer" parent="."]
41+
stream = ExtResource( 1 )
42+
[connection signal="pressed" from="Button" to="." method="_on_Button_pressed"]

audio/bpm_sync/project.godot

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; Engine configuration file.
2+
; It's best edited using the editor UI and not directly,
3+
; since the parameters that go here are not all obvious.
4+
;
5+
; Format:
6+
; [section] ; section goes between []
7+
; param=value ; assign values to parameters
8+
9+
config_version=4
10+
11+
_global_script_classes=[ ]
12+
_global_script_class_icons={
13+
14+
}
15+
16+
[application]
17+
18+
run/main_scene="res://player.tscn"

audio/bpm_sync/the_comeback2.ogg

2.55 MB
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[remap]
2+
3+
importer="ogg_vorbis"
4+
type="AudioStreamOGGVorbis"
5+
path="res://.import/the_comeback2.ogg-4b85e06ff00ff611cbd6022fc43aade8.oggstr"
6+
7+
[deps]
8+
9+
source_file="res://the_comeback2.ogg"
10+
dest_files=[ "res://.import/the_comeback2.ogg-4b85e06ff00ff611cbd6022fc43aade8.oggstr" ]
11+
12+
[params]
13+
14+
loop=true
15+
loop_offset=0

0 commit comments

Comments
 (0)