MicRecord: Improve UI for mobile, add status label

This commit is contained in:
Rémi Verschelde
2019-03-08 15:39:49 +01:00
parent 63392a3574
commit 1a5517ae1a
4 changed files with 39 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
extends Node2D
extends Node
var effect
var recording
@@ -8,17 +8,19 @@ func _ready():
effect = AudioServer.get_bus_effect(idx, 0)
func _on_RecordButton_pressed():
if (effect.is_recording_active()):
if effect.is_recording_active():
recording = effect.get_recording()
$PlayButton.disabled = false
$SaveButton.disabled = false
effect.set_recording_active(false)
$RecordButton.text = "Record"
$Status.text = ""
else:
$PlayButton.disabled = true
$SaveButton.disabled = true
effect.set_recording_active(true)
$RecordButton.text = "Stop"
$Status.text = "Recording..."
func _on_PlayButton_pressed():
print(recording)
@@ -32,7 +34,7 @@ func _on_PlayButton_pressed():
$AudioStreamPlayer.play()
func _on_Play_Music_pressed():
if ($AudioStreamPlayer2.playing):
if $AudioStreamPlayer2.playing:
$AudioStreamPlayer2.stop()
$PlayMusic.text = "Play Music"
else:
@@ -40,4 +42,6 @@ func _on_Play_Music_pressed():
$PlayMusic.text = "Stop Music"
func _on_SaveButton_pressed():
recording.save_to_wav($SaveButton/Filename.text)
var save_path = $SaveButton/Filename.text
recording.save_to_wav(save_path)
$Status.text = "Saved WAV file to: %s\n(%s)" % [save_path, ProjectSettings.globalize_path(save_path)]

View File

@@ -1,11 +1,11 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://Node2D.gd" type="Script" id=1]
[ext_resource path="res://MicRecord.gd" type="Script" id=1]
[ext_resource path="res://Intro.ogg" type="AudioStream" id=2]
[sub_resource type="AudioStreamMicrophone" id=1]
[node name="Node2D" type="Node2D"]
[node name="MicRecord" type="Node"]
script = ExtResource( 1 )
[node name="AudioStreamRecord" type="AudioStreamPlayer" parent="."]
@@ -23,33 +23,45 @@ volume_db = -6.0
[node name="RecordButton" type="Button" parent="."]
margin_left = 120.0
margin_top = 60.0
margin_bottom = 78.0
margin_right = 240.0
margin_bottom = 100.0
text = "Record"
[node name="SaveButton" type="Button" parent="."]
editor/display_folded = true
margin_left = 120.0
margin_top = 120.0
margin_top = 140.0
margin_right = 240.0
margin_bottom = 180.0
disabled = true
text = "Save Wav To:"
text = "Save WAV To:"
[node name="Filename" type="Label" parent="SaveButton"]
margin_left = 120.0
margin_right = 440.0
margin_bottom = 20.0
[node name="Filename" type="LineEdit" parent="SaveButton"]
margin_left = 180.0
margin_right = 340.0
margin_bottom = 40.0
text = "user://record.wav"
[node name="PlayButton" type="Button" parent="."]
margin_left = 240.0
margin_left = 300.0
margin_top = 60.0
margin_right = 420.0
margin_bottom = 100.0
disabled = true
text = "Play"
[node name="PlayMusic" type="Button" parent="."]
margin_left = 120.0
margin_top = 180.0
margin_top = 220.0
margin_right = 240.0
margin_bottom = 260.0
text = "Play Music"
[node name="Status" type="Label" parent="."]
margin_left = 120.0
margin_top = 300.0
margin_right = 520.0
margin_bottom = 340.0
[connection signal="pressed" from="RecordButton" to="." method="_on_RecordButton_pressed"]
[connection signal="pressed" from="SaveButton" to="." method="_on_SaveButton_pressed"]
[connection signal="pressed" from="PlayButton" to="." method="_on_PlayButton_pressed"]

View File

@@ -3,6 +3,9 @@
importer="texture"
type="StreamTexture"
path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
metadata={
"vram_texture": false
}
[deps]

View File

@@ -15,8 +15,8 @@ _global_script_class_icons={
[application]
config/name="MicRecord"
run/main_scene="res://Node2D.tscn"
config/name="Mic Record Demo"
run/main_scene="res://MicRecord.tscn"
config/icon="res://icon.png"
[audio]
@@ -27,6 +27,8 @@ enable_audio_input=true
window/size/width=640
window/size/height=480
window/stretch/mode="2d"
window/stretch/aspect="expand"
[rendering]