Godot first attempt

This commit is contained in:
Martyn 2020-09-19 17:21:40 +02:00
parent fa10e27083
commit 3805679ec4
24 changed files with 697 additions and 1 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
*.exe *.exe
.import

22
godot/Globals.gd Normal file
View File

@ -0,0 +1,22 @@
extends Node2D
var pid_of_dlserver = 0
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _notification(what):
if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
print("Killing dl-server, pid ",pid_of_dlserver)
OS.kill(pid_of_dlserver)
get_tree().quit() # default behavior

6
godot/Globals.tscn Normal file
View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://Globals.gd" type="Script" id=1]
[node name="Globals" type="Node2D"]
script = ExtResource( 1 )

BIN
godot/Intro.ogg Normal file

Binary file not shown.

15
godot/Intro.ogg.import Normal file
View File

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

56
godot/MicRecord.gd Normal file
View File

@ -0,0 +1,56 @@
extends Control
var effect
var recording
func _ready():
var idx = AudioServer.get_bus_index("Record")
effect = AudioServer.get_bus_effect(idx, 0)
print("We have ",AudioServer.bus_count," busses.")
for i in range(0,2):
print("Bus ",i," is called ",AudioServer.get_bus_name(i))
print("index of `Record` is ",idx)
print("effect is", effect)
func _on_RecordButton_pressed():
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)
print(recording.format)
print(recording.mix_rate)
print(recording.stereo)
var data = recording.get_data()
print(data)
print(data.size())
$AudioStreamPlayer.stream = recording
$AudioStreamPlayer.play()
func _on_Play_Music_pressed():
if $AudioStreamPlayer2.playing:
$AudioStreamPlayer2.stop()
$PlayMusic.text = "Play Music"
else:
$AudioStreamPlayer2.play()
$PlayMusic.text = "Stop Music"
func _on_SaveButton_pressed():
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)]

80
godot/MicRecord.tscn Normal file
View File

@ -0,0 +1,80 @@
[gd_scene load_steps=4 format=2]
[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="MicRecord" type="Control"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -320.0
margin_top = -240.0
margin_right = 320.0
margin_bottom = 240.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="AudioStreamRecord" type="AudioStreamPlayer" parent="."]
stream = SubResource( 1 )
autoplay = true
bus = "Record"
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
autoplay = true
[node name="AudioStreamPlayer2" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 2 )
volume_db = -6.0
[node name="RecordButton" type="Button" parent="."]
margin_left = 120.0
margin_top = 100.0
margin_right = 240.0
margin_bottom = 140.0
text = "Record"
[node name="SaveButton" type="Button" parent="."]
margin_left = 120.0
margin_top = 180.0
margin_right = 240.0
margin_bottom = 220.0
disabled = true
text = "Save WAV To:"
[node name="Filename" type="LineEdit" parent="SaveButton"]
margin_left = 180.0
margin_right = 340.0
margin_bottom = 40.0
text = "user://record.wav"
caret_blink = true
caret_blink_speed = 0.5
[node name="PlayButton" type="Button" parent="."]
margin_left = 300.0
margin_top = 100.0
margin_right = 420.0
margin_bottom = 140.0
disabled = true
text = "Play"
[node name="PlayMusic" type="Button" parent="."]
margin_left = 120.0
margin_top = 260.0
margin_right = 240.0
margin_bottom = 300.0
text = "Play Music"
[node name="Status" type="Label" parent="."]
margin_left = 120.0
margin_top = 340.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"]
[connection signal="pressed" from="PlayMusic" to="." method="_on_Play_Music_pressed"]

20
godot/VPMain.gd Normal file
View File

@ -0,0 +1,20 @@
extends VideoPlayer
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_VPMain_finished():
play()

24
godot/VideoPlayer.gd Normal file
View File

@ -0,0 +1,24 @@
extends VideoPlayer
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_VideoPlayer_ready():
pass
func _on_Control_ready():
pass # Replace with function body.

14
godot/audio.tres Normal file
View File

@ -0,0 +1,14 @@
[gd_resource type="AudioBusLayout" load_steps=2 format=2]
[sub_resource type="AudioEffectRecord" id=1]
resource_name = "Record"
[resource]
bus/1/name = "Record"
bus/1/solo = false
bus/1/mute = true
bus/1/bypass_fx = false
bus/1/volume_db = 0.0
bus/1/send = "Master"
bus/1/effect/0/effect = SubResource( 1 )
bus/1/effect/0/enabled = true

14
godot/default_env.tres Normal file
View File

@ -0,0 +1,14 @@
[gd_resource type="AudioBusLayout" load_steps=2 format=2]
[sub_resource type="AudioEffectRecord" id=1]
resource_name = "Record"
[resource]
bus/1/name = "Record"
bus/1/solo = false
bus/1/mute = true
bus/1/bypass_fx = false
bus/1/volume_db = 0.0
bus/1/send = "Master"
bus/1/effect/0/effect = SubResource( 1 )
bus/1/effect/0/enabled = true

60
godot/download_video.gd Normal file
View File

@ -0,0 +1,60 @@
extends Control
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var lastcheck = 0
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
lastcheck += delta
if lastcheck > 1:
print("Last check > 1...")
lastcheck = 0;
$HTTPRequest.request("http://127.0.0.1:10435/status/")
# #$HTTPRequest.request("http://www.mocky.io/v2/5185415ba171ea3a00704eed")
func _on_Control_ready():
# TODO: cross-platform how?
#var command = OS.get_user_data_dir()+"/youtube-dl.exe -o "+OS.get_user_data_dir()+"/temp https://www.youtube.com/watch?v=x1T6QFpd0J4 > "+OS.get_user_data_dir()+"/ytdl.log"
#print(command)
#OS.execute("CMD.exe", ["/C", command], false, output)
#for line in output:
# print(line)
#o.open(OS.get_user_data_dir()+"/ytdl.log", File.READ)
#var line = ""
#while !o.eof_reached():
# line = o.get_line()
# print(line)
#print(OS.get_user_data_dir())
$HTTPRequest.request("http://127.0.0.1:10435/get?url=https://www.youtube.com/watch?v=x1T6QFpd0J4")
#$HTTPRequest.request("http://127.0.0.1:10435/get?url=https://player.vimeo.com/video/459151338")
#https://www.youtube.com/watch?v=x1T6QFpd0J4
func _on_HTTPRequest_request_completed(result, response_code, headers, body):
#print(result)
#print(response_code)
#print(headers)
#print(body.get_string_from_utf8())
var json = JSON.parse(body.get_string_from_utf8())
if json.result != null:
$VBoxContainer2/DownloadProgress.value = json.result["percentage"]
if json.result["percentage"] == 100:
get_tree().change_scene("res://justplayer.tscn")
#print(json.result)
#print(json.result["percentage"])
#pass
func _on_DownloadProgress_changed():
pass # Replace with function body.

51
godot/download_video.tscn Normal file
View File

@ -0,0 +1,51 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://download_video.gd" type="Script" id=1]
[node name="Control" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -0.890956
margin_top = -1.7818
margin_right = -0.890991
margin_bottom = -1.7818
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_left = 1.0
margin_top = 300.0
margin_right = 1023.0
margin_bottom = 316.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="RichTextLabel" type="RichTextLabel" parent="VBoxContainer"]
margin_right = 1022.0
margin_bottom = 16.0
size_flags_horizontal = 3
size_flags_vertical = 3
bbcode_enabled = true
bbcode_text = "[center]Downloading and converting video[/center]"
text = "Downloading and converting video"
[node name="VBoxContainer2" type="VBoxContainer" parent="."]
margin_left = 213.816
margin_top = 320.724
margin_right = 837.816
margin_bottom = 334.724
__meta__ = {
"_edit_use_anchors_": false
}
[node name="DownloadProgress" type="ProgressBar" parent="VBoxContainer2"]
margin_right = 624.0
margin_bottom = 14.0
[node name="HTTPRequest" type="HTTPRequest" parent="."]
[connection signal="ready" from="." to="." method="_on_Control_ready"]
[connection signal="changed" from="VBoxContainer2/DownloadProgress" to="." method="_on_DownloadProgress_changed"]
[connection signal="request_completed" from="HTTPRequest" to="." method="_on_HTTPRequest_request_completed"]

BIN
godot/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

34
godot/icon.png.import Normal file
View File

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

23
godot/justplayer.gd Normal file
View File

@ -0,0 +1,23 @@
extends Control
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_Control_ready():
$vp.set_stream(load(OS.get_user_data_dir()+"/test.webm"))
print($vp.get_stream_name())
$vp.play()
pass # Replace with function body.

19
godot/justplayer.tscn Normal file
View File

@ -0,0 +1,19 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://VideoPlayer.gd" type="Script" id=1]
[ext_resource path="res://justplayer.gd" type="Script" id=2]
[node name="Control" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="vp" type="VideoPlayer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
[connection signal="ready" from="." to="." method="_on_Control_ready"]
[connection signal="ready" from="vp" to="vp" method="_on_VideoPlayer_ready"]

BIN
godot/loadscreen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

View File

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

27
godot/main_menu.gd Normal file
View File

@ -0,0 +1,27 @@
extends Control
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_Quit_pressed():
get_tree().quit()
func _on_Button_pressed():
get_tree().change_scene("res://download_video.tscn")
func _on_MicTest_pressed():
get_tree().change_scene("res://MicRecord.tscn")

67
godot/main_menu.tscn Normal file
View File

@ -0,0 +1,67 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://main_menu.gd" type="Script" id=1]
[node name="Control" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="HBoxContainer" type="HBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 0.033
margin_bottom = 0.200001
alignment = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer"]
margin_right = 1000.0
margin_bottom = 20.0
size_flags_horizontal = 3
alignment = 1
[node name="RichTextLabel" type="RichTextLabel" parent="HBoxContainer/VBoxContainer"]
margin_top = 2.0
margin_right = 1000.0
margin_bottom = 17.0
size_flags_horizontal = 3
bbcode_enabled = true
bbcode_text = "[center]MAIN MENU[/center]"
text = "MAIN MENU"
fit_content_height = true
scroll_active = false
[node name="Quit" type="Button" parent="HBoxContainer"]
margin_left = 1004.0
margin_right = 1024.0
margin_bottom = 20.0
text = "X"
script = ExtResource( 1 )
[node name="GridContainer" type="GridContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 0.815
margin_top = 50.0
margin_bottom = -3.05176e-05
__meta__ = {
"_edit_use_anchors_": false
}
[node name="DownloadPlayVid" type="Button" parent="GridContainer"]
margin_right = 109.0
margin_bottom = 20.0
text = "Test scenario 1"
[node name="MicTest" type="Button" parent="GridContainer"]
margin_top = 24.0
margin_right = 109.0
margin_bottom = 44.0
text = "Mic Test"
[connection signal="pressed" from="HBoxContainer/Quit" to="HBoxContainer/Quit" method="_on_Quit_pressed"]
[connection signal="pressed" from="GridContainer/DownloadPlayVid" to="." method="_on_Button_pressed"]
[connection signal="pressed" from="GridContainer/MicTest" to="." method="_on_MicTest_pressed"]

35
godot/project.godot Normal file
View File

@ -0,0 +1,35 @@
; 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]
config/name="ASingCrow"
run/main_scene="res://startup.tscn"
config/icon="res://icon.png"
[audio]
default_bus_layout="res://default_env.tres"
enable_audio_input=true
[autoload]
Globals="*res://Globals.tscn"
[rendering]
quality/driver/driver_name="GLES2"
vram_compression/import_etc=true
vram_compression/import_etc2=false

45
godot/startup.gd Normal file
View File

@ -0,0 +1,45 @@
extends Control
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_Timer_timeout():
get_tree().change_scene("res://main_menu.tscn")
func _on_Timer2_timeout():
var output = []
var o = File.new()
var dir = Directory.new()
if !o.file_exists('user://youtube-dl.exe'):
print("Need youtube-dl")
dir.copy("./youtube-dl.exe", "user://youtube-dl.exe")
if !o.file_exists('user://ffmpeg.exe'):
print("Need ffmpeg")
dir.copy("./ffmpeg.exe", "user://ffmpeg.exe")
if !o.file_exists('user://dlserver.exe'):
print("Need dlserver")
dir.copy("./dlserver.exe", "user://dlserver.exe")
Globals.pid_of_dlserver = OS.execute(".\\dlserver.exe", [OS.get_user_data_dir()], false)
print("Started dl-server, pid ", Globals.pid_of_dlserver)
$ValidateServerRunningTimer.start()
func _on_ValidateServerRunningTimer_timeout():
$HTTPRequest.request("http://127.0.0.1:10435/")
func _on_HTTPRequest_request_completed(result, response_code, headers, body):
print("Received ",response_code," response from server, good enough!")
$SceneChangeTimer.start()

49
godot/startup.tscn Normal file
View File

@ -0,0 +1,49 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://loadscreen.png" type="Texture" id=1]
[ext_resource path="res://startup.gd" type="Script" id=2]
[node name="Control" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 2 )
__meta__ = {
"_edit_use_anchors_": true
}
[node name="HBoxContainer" type="HBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_bottom = 25.0
alignment = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="HBoxContainer"]
margin_right = 1024.0
margin_bottom = 625.0
alignment = 1
[node name="TextureRect" type="TextureRect" parent="HBoxContainer/VBoxContainer"]
margin_top = 12.0
margin_right = 1024.0
margin_bottom = 612.0
texture = ExtResource( 1 )
[node name="SceneChangeTimer" type="Timer" parent="."]
wait_time = 5.0
one_shot = true
[node name="StartDlServerTimer" type="Timer" parent="."]
one_shot = true
autostart = true
[node name="ValidateServerRunningTimer" type="Timer" parent="."]
one_shot = true
[node name="HTTPRequest" type="HTTPRequest" parent="."]
[connection signal="timeout" from="SceneChangeTimer" to="." method="_on_Timer_timeout"]
[connection signal="timeout" from="StartDlServerTimer" to="." method="_on_Timer2_timeout"]
[connection signal="timeout" from="ValidateServerRunningTimer" to="." method="_on_ValidateServerRunningTimer_timeout"]
[connection signal="request_completed" from="HTTPRequest" to="." method="_on_HTTPRequest_request_completed"]