2020-09-23 21:09:49 +00:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
|
|
|
|
# Declare member variables here. Examples:
|
|
|
|
# var a = 2
|
|
|
|
# var b = "text"
|
|
|
|
|
|
|
|
var spectrum_play
|
|
|
|
var spectrum_record
|
|
|
|
var recorder
|
2020-09-24 21:00:40 +00:00
|
|
|
var raw_recording
|
|
|
|
var raw_recording_data
|
|
|
|
var playable_recording_data
|
2020-09-25 22:38:08 +00:00
|
|
|
var playing = false
|
|
|
|
var current_stream_added = false
|
|
|
|
var recorded_streams = 0
|
2020-09-26 12:59:15 +00:00
|
|
|
var streams_recorded_here = []
|
|
|
|
var stream_data = []
|
2020-09-24 21:00:40 +00:00
|
|
|
var position_changing_by_code
|
2020-09-23 21:09:49 +00:00
|
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2020-09-25 18:55:30 +00:00
|
|
|
Globals.loadConfig() # noop if startup has done it.
|
|
|
|
## This SHOULD be how the native support works :
|
|
|
|
#var stream = VideoStreamGDNative.new()
|
|
|
|
#$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/VideoPlayer.set_stream(load(OS.get_user_data_dir()+"/converted.webm"))
|
|
|
|
#var file = $MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/VideoPlayer.stream.get_file()
|
|
|
|
#print(file)
|
|
|
|
#stream.set_file(file)
|
|
|
|
#var vp = $MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/VideoPlayer
|
|
|
|
#vp.stream = stream
|
|
|
|
#print(vp.stream.to_string())
|
|
|
|
#vp.stream_position = -1
|
|
|
|
#var duration = vp.stream_position
|
|
|
|
#vp.stream_position = 0
|
|
|
|
#$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/VideoPosSlider.max_value = duration
|
|
|
|
|
|
|
|
## So we're back to VideoStreamWebM
|
2020-09-25 22:38:08 +00:00
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.set_VideoStream(load(OS.get_user_data_dir()+"/converted.webm"))
|
2020-09-25 18:55:30 +00:00
|
|
|
var duration = 313.701
|
2020-09-25 22:38:08 +00:00
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.set_VideoDurationSeconds(duration)
|
2020-09-25 18:55:30 +00:00
|
|
|
|
|
|
|
# And set up the recording bus and meters
|
2020-09-23 21:09:49 +00:00
|
|
|
var idx = AudioServer.get_bus_index("Record")
|
|
|
|
recorder = AudioServer.get_bus_effect(idx, 0)
|
|
|
|
spectrum_play = AudioServer.get_bus_effect_instance(0,0)
|
|
|
|
spectrum_record = AudioServer.get_bus_effect_instance(1,1)
|
2020-09-24 21:00:40 +00:00
|
|
|
position_changing_by_code = false
|
2020-09-27 20:58:03 +00:00
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer4/SaveButton.get_popup().add_item("Save separate streams")
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer4/SaveButton.get_popup().add_item("Save mixed down")
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer4/SaveButton.get_popup().add_item("Publish")
|
2020-09-23 21:09:49 +00:00
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _process(delta):
|
|
|
|
var magnitude: float = spectrum_play.get_magnitude_for_frequency_range(0,11050.0).length()
|
|
|
|
var energy = clamp((60 + linear2db(magnitude)) / 60, 0, 1)
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/HBoxContainer/PlaybackMeter.value = energy * 100
|
|
|
|
magnitude = spectrum_record.get_magnitude_for_frequency_range(0,11050.0).length()
|
|
|
|
energy = clamp((60 + linear2db(magnitude)) / 60, 0, 1)
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/HBoxContainer2/RecordMeter.value = energy * 100
|
2020-09-24 21:00:40 +00:00
|
|
|
|
2020-09-23 21:09:49 +00:00
|
|
|
|
|
|
|
func _on_RecButton_pressed():
|
|
|
|
if recorder.is_recording_active():
|
2020-09-25 22:38:08 +00:00
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.stop()
|
2020-09-24 21:00:40 +00:00
|
|
|
raw_recording = recorder.get_recording()
|
2020-09-26 12:59:15 +00:00
|
|
|
stream_data.append(raw_recording)
|
2020-09-25 22:38:08 +00:00
|
|
|
current_stream_added = false
|
2020-09-23 21:09:49 +00:00
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/PlayButton.disabled = false
|
|
|
|
recorder.set_recording_active(false)
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/RecordButton.text = "Record"
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/Status.text = ""
|
2020-09-26 12:59:15 +00:00
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/HBoxContainer3/HBoxContainer/MultiVolumeSlider.set_count(recorded_streams)
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/HBoxContainer3/HBoxContainer/VBoxContainer/MultiDelaySlider.set_count(recorded_streams)
|
2020-09-25 22:38:08 +00:00
|
|
|
|
2020-09-23 21:09:49 +00:00
|
|
|
else:
|
2020-09-25 22:38:08 +00:00
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.play_combined()
|
|
|
|
if $MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/RecordButton.text != "Record":
|
|
|
|
recorded_streams += 1
|
|
|
|
if recorded_streams == 0:
|
|
|
|
recorded_streams = 1
|
2020-09-23 21:09:49 +00:00
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/PlayButton.disabled = true
|
|
|
|
recorder.set_recording_active(true)
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/RecordButton.text = "Stop"
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/Status.text = "Recording..."
|
|
|
|
|
|
|
|
|
|
|
|
func _on_PlayButton_pressed():
|
2020-09-24 21:00:40 +00:00
|
|
|
var data = raw_recording.get_data()
|
2020-09-25 22:38:08 +00:00
|
|
|
if playing:
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.stop()
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/PlayButton.text = "Play"
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/RecordButton.disabled = false
|
|
|
|
playing = false
|
|
|
|
else:
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/PlayButton.text = "Stop"
|
2020-09-26 12:59:15 +00:00
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/RecordButton.text = "Record another layer (part)"
|
2020-09-25 22:38:08 +00:00
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/RecordButton.disabled = true
|
|
|
|
if !current_stream_added:
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.add_audio_stream(raw_recording,$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/HBoxContainer3/HBoxContainer/VBoxContainer/DelaySlider.value/1000)
|
|
|
|
current_stream_added = true
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.play_combined()
|
|
|
|
playing = true
|
|
|
|
#$AudioStreamPlayer.stream = raw_recording
|
|
|
|
#$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.play()
|
|
|
|
#$AudioStreamPlayer.play()
|
|
|
|
#$AudioStreamPlayer.stream_paused = true
|
|
|
|
#$AudioStreamPlayer.seek($MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/HBoxContainer3/HBoxContainer/VBoxContainer/DelaySlider.value/1000)
|
|
|
|
#$AudioStreamPlayer.stream_paused = false
|
|
|
|
|
|
|
|
|
2020-09-24 21:00:40 +00:00
|
|
|
#$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/VideoPosSlider.editable = true
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/HBoxContainer3/HBoxContainer/VBoxContainer/DelaySlider.editable = true
|
|
|
|
|
|
|
|
func _on_BackgroundaudioSlider_changed(value):
|
2020-09-25 22:38:08 +00:00
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.set_volume_db(linear2db(value/100))
|
2020-09-24 21:00:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_VocalSlider_value_changed(value):
|
|
|
|
$AudioStreamPlayer.volume_db = linear2db(value/100)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_DelaySlider_value_changed(value):
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/HBoxContainer3/HBoxContainer/VBoxContainer/Label.text = "Audio Delay: "+String(value/1000)+"s"
|
2020-09-25 22:38:08 +00:00
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.set_paused(true)
|
2020-09-24 21:00:40 +00:00
|
|
|
$AudioStreamPlayer.stream_paused = true
|
2020-09-25 22:38:08 +00:00
|
|
|
$AudioStreamPlayer.seek($MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.get_stream_position() + value/1000)
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.set_paused(false)
|
2020-09-24 21:00:40 +00:00
|
|
|
$AudioStreamPlayer.stream_paused = false
|
2020-09-25 18:55:30 +00:00
|
|
|
Globals.audio_delay_seconds = value/1000
|
|
|
|
Globals.saveConfig()
|
2020-09-24 21:00:40 +00:00
|
|
|
|
2020-09-25 22:38:08 +00:00
|
|
|
func _on_Quit_pressed():
|
|
|
|
get_tree().change_scene("res://main_menu.tscn")
|
|
|
|
|
|
|
|
func _on_MultiStreamVideoPlayer_finished():
|
|
|
|
if recorder.is_recording_active():
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.stop()
|
|
|
|
raw_recording = recorder.get_recording()
|
2020-09-26 12:59:15 +00:00
|
|
|
stream_data.append(raw_recording)
|
2020-09-25 22:38:08 +00:00
|
|
|
current_stream_added = false
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/PlayButton.disabled = false
|
|
|
|
recorder.set_recording_active(false)
|
2020-09-26 12:59:15 +00:00
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/RecordButton.text = "Record"
|
2020-09-25 22:38:08 +00:00
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/Status.text = ""
|
|
|
|
if playing:
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.stop()
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer3/VBoxContainer/PlayButton.text = "Play"
|
|
|
|
playing = false
|
2020-09-25 18:55:30 +00:00
|
|
|
|
2020-09-25 22:38:08 +00:00
|
|
|
func _on_VBoxContainer2_volume_changed(slider, value):
|
|
|
|
print("Slider "+String(slider)+" changed to "+String(value))
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.set_audio_volume_db(slider,linear2db(value/100))
|
|
|
|
pass # Replace with function body.
|
2020-09-26 12:59:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_MultiDelaySlider_delay_changed(slider, value):
|
|
|
|
$MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/MultiStreamVideoPlayer.set_stream_delay(slider,value/1000)
|
|
|
|
Globals.audio_delay_seconds = value/1000
|
|
|
|
Globals.saveConfig()
|
|
|
|
pass # Replace with function body.
|
|
|
|
|
|
|
|
|
|
|
|
func _on_SaveButton_pressed():
|
|
|
|
for streamid in range(0,len(stream_data)):
|
|
|
|
stream_data[streamid].save_to_wav("user://part"+String(streamid+1)+".wav")
|
|
|
|
pass # Replace with function body.
|