-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio_stream_player.gd
65 lines (48 loc) · 1.13 KB
/
audio_stream_player.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
extends AudioStreamPlayer
var note: int
var key: int
var octave: int
var accidental: int
var mouse_x: int
var viewport_size_x: int
var pitch_bend_sensitivity: float = 16
const notes := {
'c': 0,
'd': 2,
'e': 4,
'f': 5,
'g': 7,
'a': 9,
'b': 11
}
const octaves := [3, 4, 5]
func _input(event: InputEvent):
if event is InputEventMouseMotion:
volume_db = linear_to_db(event.get_pressure())
# Keys
key = -1
for n: String in notes.keys():
if Input.is_action_pressed("note_%s" % n):
key = notes[n]
# Octaves
for o: int in octaves:
if Input.is_action_pressed("octave_%d" % o):
octave = o * 12
# Accidentals
accidental = 0
if Input.is_action_pressed("flat"):
accidental = -1
if Input.is_action_pressed("sharp"):
accidental = 1
if key == -1:
stop()
else:
note = key + octave + accidental
if !playing:
play()
func _process(_delta: float):
mouse_x = get_viewport().get_mouse_position().x
viewport_size_x = get_viewport().size.x
pitch_scale = pow(2, float(note+((float(mouse_x)/(float(viewport_size_x)/pitch_bend_sensitivity))-pitch_bend_sensitivity/2)-57)/12)
#print(pitch_scale)
print(volume_db)