Skip to content

Commit 1a5517a

Browse files
committed
MicRecord: Improve UI for mobile, add status label
1 parent 63392a3 commit 1a5517a

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

audio/mic_record/Node2D.gd renamed to audio/mic_record/MicRecord.gd

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
extends Node2D
1+
extends Node
22

33
var effect
44
var recording
@@ -8,17 +8,19 @@ func _ready():
88
effect = AudioServer.get_bus_effect(idx, 0)
99

1010
func _on_RecordButton_pressed():
11-
if (effect.is_recording_active()):
11+
if effect.is_recording_active():
1212
recording = effect.get_recording()
1313
$PlayButton.disabled = false
1414
$SaveButton.disabled = false
1515
effect.set_recording_active(false)
1616
$RecordButton.text = "Record"
17+
$Status.text = ""
1718
else:
1819
$PlayButton.disabled = true
1920
$SaveButton.disabled = true
2021
effect.set_recording_active(true)
2122
$RecordButton.text = "Stop"
23+
$Status.text = "Recording..."
2224

2325
func _on_PlayButton_pressed():
2426
print(recording)
@@ -32,12 +34,14 @@ func _on_PlayButton_pressed():
3234
$AudioStreamPlayer.play()
3335

3436
func _on_Play_Music_pressed():
35-
if ($AudioStreamPlayer2.playing):
37+
if $AudioStreamPlayer2.playing:
3638
$AudioStreamPlayer2.stop()
3739
$PlayMusic.text = "Play Music"
3840
else:
3941
$AudioStreamPlayer2.play()
4042
$PlayMusic.text = "Stop Music"
4143

4244
func _on_SaveButton_pressed():
43-
recording.save_to_wav($SaveButton/Filename.text)
45+
var save_path = $SaveButton/Filename.text
46+
recording.save_to_wav(save_path)
47+
$Status.text = "Saved WAV file to: %s\n(%s)" % [save_path, ProjectSettings.globalize_path(save_path)]

audio/mic_record/Node2D.tscn renamed to audio/mic_record/MicRecord.tscn

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[gd_scene load_steps=4 format=2]
22

3-
[ext_resource path="res://Node2D.gd" type="Script" id=1]
3+
[ext_resource path="res://MicRecord.gd" type="Script" id=1]
44
[ext_resource path="res://Intro.ogg" type="AudioStream" id=2]
55

66
[sub_resource type="AudioStreamMicrophone" id=1]
77

8-
[node name="Node2D" type="Node2D"]
8+
[node name="MicRecord" type="Node"]
99
script = ExtResource( 1 )
1010

1111
[node name="AudioStreamRecord" type="AudioStreamPlayer" parent="."]
@@ -23,33 +23,45 @@ volume_db = -6.0
2323
[node name="RecordButton" type="Button" parent="."]
2424
margin_left = 120.0
2525
margin_top = 60.0
26-
margin_bottom = 78.0
26+
margin_right = 240.0
27+
margin_bottom = 100.0
2728
text = "Record"
2829

2930
[node name="SaveButton" type="Button" parent="."]
30-
editor/display_folded = true
3131
margin_left = 120.0
32-
margin_top = 120.0
32+
margin_top = 140.0
33+
margin_right = 240.0
34+
margin_bottom = 180.0
3335
disabled = true
34-
text = "Save Wav To:"
36+
text = "Save WAV To:"
3537

36-
[node name="Filename" type="Label" parent="SaveButton"]
37-
margin_left = 120.0
38-
margin_right = 440.0
39-
margin_bottom = 20.0
38+
[node name="Filename" type="LineEdit" parent="SaveButton"]
39+
margin_left = 180.0
40+
margin_right = 340.0
41+
margin_bottom = 40.0
4042
text = "user://record.wav"
4143

4244
[node name="PlayButton" type="Button" parent="."]
43-
margin_left = 240.0
45+
margin_left = 300.0
4446
margin_top = 60.0
47+
margin_right = 420.0
48+
margin_bottom = 100.0
4549
disabled = true
4650
text = "Play"
4751

4852
[node name="PlayMusic" type="Button" parent="."]
4953
margin_left = 120.0
50-
margin_top = 180.0
54+
margin_top = 220.0
55+
margin_right = 240.0
56+
margin_bottom = 260.0
5157
text = "Play Music"
5258

59+
[node name="Status" type="Label" parent="."]
60+
margin_left = 120.0
61+
margin_top = 300.0
62+
margin_right = 520.0
63+
margin_bottom = 340.0
64+
5365
[connection signal="pressed" from="RecordButton" to="." method="_on_RecordButton_pressed"]
5466
[connection signal="pressed" from="SaveButton" to="." method="_on_SaveButton_pressed"]
5567
[connection signal="pressed" from="PlayButton" to="." method="_on_PlayButton_pressed"]

audio/mic_record/icon.png.import

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
importer="texture"
44
type="StreamTexture"
55
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
6+
metadata={
7+
"vram_texture": false
8+
}
69

710
[deps]
811

audio/mic_record/project.godot

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ _global_script_class_icons={
1515

1616
[application]
1717

18-
config/name="MicRecord"
19-
run/main_scene="res://Node2D.tscn"
18+
config/name="Mic Record Demo"
19+
run/main_scene="res://MicRecord.tscn"
2020
config/icon="res://icon.png"
2121

2222
[audio]
@@ -27,6 +27,8 @@ enable_audio_input=true
2727

2828
window/size/width=640
2929
window/size/height=480
30+
window/stretch/mode="2d"
31+
window/stretch/aspect="expand"
3032

3133
[rendering]
3234

0 commit comments

Comments
 (0)