Browse Source

added utility for converting between different time units

Jonathan Higgins 6 months ago
parent
commit
fffbe230b6
4 changed files with 478 additions and 1 deletions
  1. 164 0
      scenes/Nodes/convert_time.gd
  2. 1 0
      scenes/Nodes/convert_time.gd.uid
  3. 189 1
      scenes/Nodes/nodes.tscn
  4. 124 0
      scenes/main/process_help.json

+ 164 - 0
scenes/Nodes/convert_time.gd

@@ -0,0 +1,164 @@
+extends GraphNode
+
+var ms = 1000.0
+var seconds
+var beats
+var hz
+var MIDI
+var samples
+var percent
+var bpm = 120.0
+var samplerate = 44100
+var length = 60.0
+
+signal open_help
+
+
+func _ready() -> void:
+	#add button to title bar
+	var titlebar = self.get_titlebar_hbox()
+	var btn = Button.new()
+	btn.text = "?"
+	btn.tooltip_text = "Open help for " + self.title
+	btn.connect("pressed", Callable(self, "_open_help")) #pass key (process name) when button is pressed
+	titlebar.add_child(btn)
+	
+	$VBoxContainer/HBoxContainer7/BPMEdit.text = str(bpm)
+	$VBoxContainer/HBoxContainer5/SampleRateEdit.text = str(samplerate)
+	$VBoxContainer/HBoxContainer6/LengthEdit.text = str(length)
+	
+	calculate()
+
+func _open_help():
+	open_help.emit(self.get_meta("command"), self.title)
+
+func calculate():
+	seconds = ms / 1000
+	beats = (seconds * bpm) / 60
+	hz = 1000.0 / ms
+	MIDI = 12 * (log(hz / 440) / log(2)) + 69
+	samples = seconds * samplerate
+	percent = (seconds / length) * 100
+	
+	$VBoxContainer/HBoxContainer/MsEdit.text = str(ms)
+	$VBoxContainer/HBoxContainer2/SEdit.text = str(seconds)
+	$VBoxContainer/HBoxContainer7/CrotchetEdit.text = str(beats)
+	$VBoxContainer/HBoxContainer3/HzEdit.text = str(hz)
+	$VBoxContainer/HBoxContainer4/MIDIEdit.text = str(MIDI)
+	$VBoxContainer/HBoxContainer5/SampleNoEdit.text = str(samples)
+	$VBoxContainer/HBoxContainer6/PercentEdit.text = str(percent)
+	
+
+func _on_ms_edit_text_submitted(new_text: String) -> void:
+	if new_text.is_valid_float():
+		ms = new_text.to_float()
+		calculate()
+	else:
+		$VBoxContainer/HBoxContainer/MsEdit.text = str(ms)
+
+func _on_ms_edit_focus_exited() -> void:
+	_on_ms_edit_text_submitted($VBoxContainer/HBoxContainer/MsEdit.text)
+
+func _on_s_edit_text_submitted(new_text: String) -> void:
+	if new_text.is_valid_float():
+		ms = new_text.to_float() * 1000
+		calculate()
+	else:
+		$VBoxContainer/HBoxContainer2/SEdit.text = str(seconds)
+		
+
+func _on_s_edit_focus_exited() -> void:
+	_on_s_edit_text_submitted($VBoxContainer/HBoxContainer2/SEdit.text)
+	
+
+func _on_crotchet_edit_text_submitted(new_text: String) -> void:
+	if new_text.is_valid_float():
+		ms = (new_text.to_float() * 60000.0) / bpm
+		calculate()
+	else:
+		$VBoxContainer/HBoxContainer7/CrotchetEdit.text = str(beats)
+		
+
+func _on_crotchet_edit_focus_exited() -> void:
+	_on_crotchet_edit_text_submitted($VBoxContainer/HBoxContainer7/CrotchetEdit.text)
+	
+func _on_bpm_edit_text_submitted(new_text: String) -> void:
+	if new_text.is_valid_float():
+		bpm = new_text.to_float()
+		ms = (beats * 60000.0) / bpm
+		calculate()
+	else:
+		$VBoxContainer/HBoxContainer7/BPMEdit.text = str(bpm)
+		
+func _on_bpm_edit_focus_exited() -> void:
+	_on_bpm_edit_text_submitted($VBoxContainer/HBoxContainer7/BPMEdit.text)
+	
+func _on_hz_edit_text_submitted(new_text: String) -> void:
+	if new_text.is_valid_float():
+		ms = (1.0 / new_text.to_float()) * 1000
+		calculate()
+	else:
+		$VBoxContainer/HBoxContainer3/HzEdit.text = str(hz)
+
+
+func _on_hz_edit_focus_exited() -> void:
+	_on_hz_edit_text_submitted($VBoxContainer/HBoxContainer3/HzEdit.text)
+	
+
+func _on_midi_edit_text_submitted(new_text: String) -> void:
+	if new_text.is_valid_float():
+		var freq = 440.0 * pow(2, (new_text.to_float() - 69) / 12.0)
+		ms = (1.0 / freq) * 1000
+		calculate()
+	else:
+		$VBoxContainer/HBoxContainer4/MIDIEdit.text = str(MIDI)
+		
+
+func _on_midi_edit_focus_exited() -> void:
+	_on_midi_edit_text_submitted($VBoxContainer/HBoxContainer4/MIDIEdit.text)
+	
+
+func _on_sample_no_edit_text_submitted(new_text: String) -> void:
+	if new_text.is_valid_float():
+		ms = (new_text.to_float() / samplerate) * 1000
+		calculate()
+	else:
+		$VBoxContainer/HBoxContainer5/SampleNoEdit.text = str(samples)
+		
+
+func _on_sample_no_edit_focus_exited() -> void:
+	_on_sample_no_edit_text_submitted($VBoxContainer/HBoxContainer5/SampleNoEdit.text)
+	
+func _on_sample_rate_edit_text_submitted(new_text: String) -> void:
+	if new_text.is_valid_float():
+		samplerate = new_text.to_float()
+		ms = (samples / samplerate) * 1000
+		calculate()
+	else:
+		$VBoxContainer/HBoxContainer5/SampleRateEdit.text = str(samplerate)
+		
+func _on_sample_rate_edit_focus_exited() -> void:
+	_on_sample_rate_edit_text_submitted($VBoxContainer/HBoxContainer5/SampleRateEdit.text)
+	
+func _on_percent_edit_text_submitted(new_text: String) -> void:
+	if new_text.is_valid_float():
+		ms = (new_text.to_float() / 100.0) * (length * 1000)
+		calculate()
+	else:
+		$VBoxContainer/HBoxContainer6/PercentEdit.text = str(percent)
+		
+
+func _on_percent_edit_focus_exited() -> void:
+	_on_percent_edit_text_submitted($VBoxContainer/HBoxContainer6/PercentEdit.text)
+	
+func _on_length_edit_text_submitted(new_text: String) -> void:
+	if new_text.is_valid_float():
+		length = new_text.to_float()
+		ms = (percent / 100.0) * (length * 1000)
+		calculate()
+	else:
+		$VBoxContainer/HBoxContainer6/LengthEdit.text = str(length)
+		
+
+func _on_length_edit_focus_exited() -> void:
+	_on_length_edit_text_submitted($VBoxContainer/HBoxContainer6/LengthEdit.text)

+ 1 - 0
scenes/Nodes/convert_time.gd.uid

@@ -0,0 +1 @@
+uid://cuk68115uw1ge

+ 189 - 1
scenes/Nodes/nodes.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=7 format=3 uid="uid://duy5epq25pj8u"]
+[gd_scene load_steps=8 format=3 uid="uid://duy5epq25pj8u"]
 
 [ext_resource type="Script" uid="uid://bifsyv5gxrddm" path="res://scenes/Nodes/inputfile.gd" id="1_8x08j"]
 [ext_resource type="PackedScene" uid="uid://csapiqka522fh" path="res://scenes/Nodes/audioplayer.tscn" id="2_b6nw4"]
@@ -6,6 +6,7 @@
 [ext_resource type="Script" uid="uid://cdbx1dt3ohqte" path="res://scenes/Nodes/node_logic.gd" id="3_uv17x"]
 [ext_resource type="Script" uid="uid://cy8x5wubj2kr6" path="res://scenes/Nodes/notes_to_hz.gd" id="4_0jqh0"]
 [ext_resource type="FontFile" uid="uid://bfnlymfdfb0e7" path="res://theme/BravuraText_SoundThread.otf" id="5_0jqh0"]
+[ext_resource type="Script" uid="uid://cuk68115uw1ge" path="res://scenes/Nodes/convert_time.gd" id="7_w2x51"]
 
 [node name="Control" type="Control"]
 layout_mode = 3
@@ -370,9 +371,196 @@ size_flags_vertical = 3
 editable = false
 wrap_mode = 1
 
+[node name="convert_time" type="GraphNode" parent="."]
+layout_mode = 0
+offset_left = 1982.0
+offset_top = 34.0
+offset_right = 2365.0
+offset_bottom = 293.0
+tooltip_text = "Converts between various units of time"
+title = "Convert Time Units"
+slot/0/left_enabled = false
+slot/0/left_type = 1
+slot/0/left_color = Color(0, 0, 0, 1)
+slot/0/left_icon = null
+slot/0/right_enabled = false
+slot/0/right_type = 1
+slot/0/right_color = Color(0, 0, 0, 1)
+slot/0/right_icon = null
+slot/0/draw_stylebox = true
+script = ExtResource("7_w2x51")
+metadata/command = "convert_time"
+metadata/utility = true
+metadata/input = false
+
+[node name="VBoxContainer" type="VBoxContainer" parent="convert_time"]
+layout_mode = 2
+
+[node name="HBoxContainer" type="HBoxContainer" parent="convert_time/VBoxContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="convert_time/VBoxContainer/HBoxContainer"]
+custom_minimum_size = Vector2(120, 0)
+layout_mode = 2
+text = "Milliseconds"
+
+[node name="MsEdit" type="LineEdit" parent="convert_time/VBoxContainer/HBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 3
+tooltip_text = "The length of time in ms"
+
+[node name="MarginContainer5" type="MarginContainer" parent="convert_time/VBoxContainer"]
+layout_mode = 2
+theme_override_constants/margin_bottom = 2
+
+[node name="HBoxContainer2" type="HBoxContainer" parent="convert_time/VBoxContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="convert_time/VBoxContainer/HBoxContainer2"]
+custom_minimum_size = Vector2(120, 0)
+layout_mode = 2
+text = "Seconds"
+
+[node name="SEdit" type="LineEdit" parent="convert_time/VBoxContainer/HBoxContainer2"]
+layout_mode = 2
+size_flags_horizontal = 3
+tooltip_text = "The length of time in seconds"
+
+[node name="MarginContainer4" type="MarginContainer" parent="convert_time/VBoxContainer"]
+layout_mode = 2
+theme_override_constants/margin_bottom = 2
+
+[node name="HBoxContainer7" type="HBoxContainer" parent="convert_time/VBoxContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="convert_time/VBoxContainer/HBoxContainer7"]
+custom_minimum_size = Vector2(120, 0)
+layout_mode = 2
+text = "1/4 Notes"
+
+[node name="CrotchetEdit" type="LineEdit" parent="convert_time/VBoxContainer/HBoxContainer7"]
+layout_mode = 2
+size_flags_horizontal = 3
+tooltip_text = "The length of time as a number of 1/4 notes at the given BPM"
+
+[node name="Label2" type="Label" parent="convert_time/VBoxContainer/HBoxContainer7"]
+layout_mode = 2
+text = "at"
+
+[node name="BPMEdit" type="LineEdit" parent="convert_time/VBoxContainer/HBoxContainer7"]
+layout_mode = 2
+size_flags_horizontal = 3
+tooltip_text = "The BPM to calculate 1/4 notes at"
+
+[node name="MarginContainer6" type="MarginContainer" parent="convert_time/VBoxContainer"]
+layout_mode = 2
+theme_override_constants/margin_bottom = 2
+
+[node name="HBoxContainer3" type="HBoxContainer" parent="convert_time/VBoxContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="convert_time/VBoxContainer/HBoxContainer3"]
+custom_minimum_size = Vector2(120, 0)
+layout_mode = 2
+text = "Hertz"
+
+[node name="HzEdit" type="LineEdit" parent="convert_time/VBoxContainer/HBoxContainer3"]
+layout_mode = 2
+size_flags_horizontal = 3
+tooltip_text = "The length of time in Hz"
+
+[node name="MarginContainer3" type="MarginContainer" parent="convert_time/VBoxContainer"]
+layout_mode = 2
+theme_override_constants/margin_bottom = 2
+
+[node name="HBoxContainer4" type="HBoxContainer" parent="convert_time/VBoxContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="convert_time/VBoxContainer/HBoxContainer4"]
+custom_minimum_size = Vector2(120, 0)
+layout_mode = 2
+text = "MIDI Note"
+
+[node name="MIDIEdit" type="LineEdit" parent="convert_time/VBoxContainer/HBoxContainer4"]
+layout_mode = 2
+size_flags_horizontal = 3
+tooltip_text = "The length of time as a MIDI note number"
+
+[node name="MarginContainer2" type="MarginContainer" parent="convert_time/VBoxContainer"]
+layout_mode = 2
+theme_override_constants/margin_bottom = 2
+
+[node name="HBoxContainer5" type="HBoxContainer" parent="convert_time/VBoxContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="convert_time/VBoxContainer/HBoxContainer5"]
+custom_minimum_size = Vector2(120, 0)
+layout_mode = 2
+text = "Samples"
+
+[node name="SampleNoEdit" type="LineEdit" parent="convert_time/VBoxContainer/HBoxContainer5"]
+layout_mode = 2
+size_flags_horizontal = 3
+tooltip_text = "The length of time as a number of samples at the given sample rate"
+
+[node name="Label2" type="Label" parent="convert_time/VBoxContainer/HBoxContainer5"]
+layout_mode = 2
+text = "at"
+
+[node name="SampleRateEdit" type="LineEdit" parent="convert_time/VBoxContainer/HBoxContainer5"]
+layout_mode = 2
+size_flags_horizontal = 3
+tooltip_text = "The sample rate to calculate samples at"
+
+[node name="MarginContainer" type="MarginContainer" parent="convert_time/VBoxContainer"]
+layout_mode = 2
+theme_override_constants/margin_bottom = 2
+
+[node name="HBoxContainer6" type="HBoxContainer" parent="convert_time/VBoxContainer"]
+layout_mode = 2
+
+[node name="Label" type="Label" parent="convert_time/VBoxContainer/HBoxContainer6"]
+custom_minimum_size = Vector2(120, 0)
+layout_mode = 2
+text = "% of Time (s)"
+
+[node name="PercentEdit" type="LineEdit" parent="convert_time/VBoxContainer/HBoxContainer6"]
+layout_mode = 2
+size_flags_horizontal = 3
+tooltip_text = "The length of time as a percentage of the given time in seconds"
+
+[node name="Label3" type="Label" parent="convert_time/VBoxContainer/HBoxContainer6"]
+layout_mode = 2
+text = "of"
+
+[node name="LengthEdit" type="LineEdit" parent="convert_time/VBoxContainer/HBoxContainer6"]
+layout_mode = 2
+size_flags_horizontal = 3
+tooltip_text = "The length of time in seconds to a percentage of"
+
 [connection signal="text_submitted" from="outputfile/FileNameField" to="outputfile" method="_on_file_name_field_text_submitted"]
 [connection signal="toggled" from="outputfile/DeleteIntermediateFilesToggle" to="outputfile" method="_on_delete_intermediate_files_toggle_toggled"]
 [connection signal="toggled" from="outputfile/ReuseFolderToggle" to="outputfile" method="_on_reuse_folder_toggle_toggled"]
 [connection signal="toggled" from="outputfile/HBoxContainer/Autoplay" to="outputfile" method="_on_autoplay_toggled"]
 [connection signal="item_selected" from="note_to_hz/Note" to="note_to_hz" method="_on_item_list_item_selected"]
 [connection signal="item_selected" from="note_to_hz/Accidental" to="note_to_hz" method="_on_item_list_2_item_selected"]
+[connection signal="focus_exited" from="convert_time/VBoxContainer/HBoxContainer/MsEdit" to="convert_time" method="_on_ms_edit_focus_exited"]
+[connection signal="text_submitted" from="convert_time/VBoxContainer/HBoxContainer/MsEdit" to="convert_time" method="_on_ms_edit_text_submitted"]
+[connection signal="focus_exited" from="convert_time/VBoxContainer/HBoxContainer2/SEdit" to="convert_time" method="_on_s_edit_focus_exited"]
+[connection signal="text_submitted" from="convert_time/VBoxContainer/HBoxContainer2/SEdit" to="convert_time" method="_on_s_edit_text_submitted"]
+[connection signal="focus_exited" from="convert_time/VBoxContainer/HBoxContainer7/CrotchetEdit" to="convert_time" method="_on_crotchet_edit_focus_exited"]
+[connection signal="text_submitted" from="convert_time/VBoxContainer/HBoxContainer7/CrotchetEdit" to="convert_time" method="_on_crotchet_edit_text_submitted"]
+[connection signal="focus_exited" from="convert_time/VBoxContainer/HBoxContainer7/BPMEdit" to="convert_time" method="_on_bpm_edit_focus_exited"]
+[connection signal="text_submitted" from="convert_time/VBoxContainer/HBoxContainer7/BPMEdit" to="convert_time" method="_on_bpm_edit_text_submitted"]
+[connection signal="focus_exited" from="convert_time/VBoxContainer/HBoxContainer3/HzEdit" to="convert_time" method="_on_hz_edit_focus_exited"]
+[connection signal="text_submitted" from="convert_time/VBoxContainer/HBoxContainer3/HzEdit" to="convert_time" method="_on_hz_edit_text_submitted"]
+[connection signal="focus_exited" from="convert_time/VBoxContainer/HBoxContainer4/MIDIEdit" to="convert_time" method="_on_midi_edit_focus_exited"]
+[connection signal="text_submitted" from="convert_time/VBoxContainer/HBoxContainer4/MIDIEdit" to="convert_time" method="_on_midi_edit_text_submitted"]
+[connection signal="focus_exited" from="convert_time/VBoxContainer/HBoxContainer5/SampleNoEdit" to="convert_time" method="_on_sample_no_edit_focus_exited"]
+[connection signal="text_submitted" from="convert_time/VBoxContainer/HBoxContainer5/SampleNoEdit" to="convert_time" method="_on_sample_no_edit_text_submitted"]
+[connection signal="focus_exited" from="convert_time/VBoxContainer/HBoxContainer5/SampleRateEdit" to="convert_time" method="_on_sample_rate_edit_focus_exited"]
+[connection signal="text_submitted" from="convert_time/VBoxContainer/HBoxContainer5/SampleRateEdit" to="convert_time" method="_on_sample_rate_edit_text_submitted"]
+[connection signal="focus_exited" from="convert_time/VBoxContainer/HBoxContainer6/PercentEdit" to="convert_time" method="_on_percent_edit_focus_exited"]
+[connection signal="text_submitted" from="convert_time/VBoxContainer/HBoxContainer6/PercentEdit" to="convert_time" method="_on_percent_edit_text_submitted"]
+[connection signal="focus_exited" from="convert_time/VBoxContainer/HBoxContainer6/LengthEdit" to="convert_time" method="_on_length_edit_focus_exited"]
+[connection signal="text_submitted" from="convert_time/VBoxContainer/HBoxContainer6/LengthEdit" to="convert_time" method="_on_length_edit_text_submitted"]

+ 124 - 0
scenes/main/process_help.json

@@ -5249,6 +5249,130 @@
 	"subcategory": "utility",
 	"title": "Convert Note to Hz"
   },
+  "convert_time": {
+	"category": "utility",
+	"description": "Utility for quickly getting various units of time from another unit of time.",
+	"inputtype": "",
+	"outputtype": "",
+	"parameters": {
+	  "param1": {
+		"paramname": "Milliseconds",
+		"paramdescription": "The length of time in ms",
+		"automatable": false,
+		"outputduration": false,
+		"time": false,
+		"min": false,
+		"max": false,
+		"flag": "",
+		"minrange": "",
+		"maxrange": "",
+		"step": "",
+		"value": "",
+		"exponential": false,
+		"uitype": ""
+	  },
+	  "param2": {
+		"paramname": "Seconds",
+		"paramdescription": "The length of time in seconds",
+		"automatable": false,
+		"outputduration": false,
+		"time": false,
+		"min": false,
+		"max": false,
+		"flag": "",
+		"minrange": "",
+		"maxrange": "",
+		"step": "",
+		"value": "",
+		"exponential": false,
+		"uitype": ""
+	  },
+	  "param3": {
+		"paramname": "1/4 Notes",
+		"paramdescription": "The length of time as a number of 1/4 notes at a given BPM",
+		"automatable": false,
+		"outputduration": false,
+		"time": false,
+		"min": false,
+		"max": false,
+		"flag": "",
+		"minrange": "",
+		"maxrange": "",
+		"step": "",
+		"value": "",
+		"exponential": false,
+		"uitype": ""
+	  },
+	  "param4": {
+		"paramname": "Hertz",
+		"paramdescription": "The length of time in Hz",
+		"automatable": false,
+		"outputduration": false,
+		"time": false,
+		"min": false,
+		"max": false,
+		"flag": "",
+		"minrange": "",
+		"maxrange": "",
+		"step": "",
+		"value": "",
+		"exponential": false,
+		"uitype": ""
+	  },
+	  "param5": {
+		"paramname": "MIDI",
+		"paramdescription": "The length of time as a MIDI note number",
+		"automatable": false,
+		"outputduration": false,
+		"time": false,
+		"min": false,
+		"max": false,
+		"flag": "",
+		"minrange": "",
+		"maxrange": "",
+		"step": "",
+		"value": "",
+		"exponential": false,
+		"uitype": ""
+	  },
+	  "param6": {
+		"paramname": "Samples",
+		"paramdescription": "The length of time as a number of samples at a given sample rate",
+		"automatable": false,
+		"outputduration": false,
+		"time": false,
+		"min": false,
+		"max": false,
+		"flag": "",
+		"minrange": "",
+		"maxrange": "",
+		"step": "",
+		"value": "",
+		"exponential": false,
+		"uitype": ""
+	  },
+	  "param7": {
+		"paramname": "% of Time (s)",
+		"paramdescription": "The length of time as a percentage of a given time in seconds",
+		"automatable": false,
+		"outputduration": false,
+		"time": false,
+		"min": false,
+		"max": false,
+		"flag": "",
+		"minrange": "",
+		"maxrange": "",
+		"step": "",
+		"value": "",
+		"exponential": false,
+		"uitype": ""
+	  }
+	},
+	"short_description": "Converts between various units of time",
+	"stereo": false,
+	"subcategory": "utility",
+	"title": "Convert Time Units"
+  },
   "notes": {
 	"category": "utility",
 	"description": "Doesn't do anything other than giving you a space to take notes. You can right click in the text box to copy and paste and use special characters like emojis 😊.\n",