Browse Source

Added utility for quickly getting frequencies for tuning filter banks

Jonathan Higgins 6 months ago
parent
commit
681f25b6f4

+ 1 - 1
dev_tools/json_editor/json_editor.gd

@@ -2,7 +2,7 @@ extends Control
 
 
 var node_data = {} #stores json file
 var node_data = {} #stores json file
 @onready var parameter_container = $HBoxContainer/VBoxContainer2/ScrollContainer/parameter_container
 @onready var parameter_container = $HBoxContainer/VBoxContainer2/ScrollContainer/parameter_container
-var json = "res://dev_tools/json_editor/process_help_copy.json"
+var json = "res://scenes/main/process_help.json"
 
 
 func _ready() -> void:
 func _ready() -> void:
 	Nodes.hide()
 	Nodes.hide()

+ 89 - 1
scenes/Nodes/nodes.tscn

@@ -1,8 +1,10 @@
-[gd_scene load_steps=4 format=3 uid="uid://duy5epq25pj8u"]
+[gd_scene load_steps=6 format=3 uid="uid://duy5epq25pj8u"]
 
 
 [ext_resource type="PackedScene" uid="uid://csapiqka522fh" path="res://scenes/Nodes/audioplayer.tscn" id="2_b6nw4"]
 [ext_resource type="PackedScene" uid="uid://csapiqka522fh" path="res://scenes/Nodes/audioplayer.tscn" id="2_b6nw4"]
 [ext_resource type="PackedScene" uid="uid://dya5kxx132fgp" path="res://scenes/Nodes/valueslider.tscn" id="3_b6nw4"]
 [ext_resource type="PackedScene" uid="uid://dya5kxx132fgp" path="res://scenes/Nodes/valueslider.tscn" id="3_b6nw4"]
 [ext_resource type="Script" uid="uid://cdbx1dt3ohqte" path="res://scenes/Nodes/node_logic.gd" id="3_uv17x"]
 [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"]
 
 
 [node name="Control" type="Control"]
 [node name="Control" type="Control"]
 layout_mode = 3
 layout_mode = 3
@@ -3606,7 +3608,93 @@ layout_mode = 2
 size_flags_vertical = 3
 size_flags_vertical = 3
 wrap_mode = 1
 wrap_mode = 1
 
 
+[node name="note_to_hz" type="GraphNode" parent="."]
+layout_mode = 0
+offset_left = 1528.0
+offset_top = 31.0
+offset_right = 1911.0
+offset_bottom = 257.0
+tooltip_text = "Converts from a musical note to Hz"
+title = "Convert Note to Hz"
+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
+slot/1/left_enabled = false
+slot/1/left_type = 0
+slot/1/left_color = Color(1, 1, 1, 1)
+slot/1/left_icon = null
+slot/1/right_enabled = false
+slot/1/right_type = 0
+slot/1/right_color = Color(1, 1, 1, 1)
+slot/1/right_icon = null
+slot/1/draw_stylebox = true
+slot/2/left_enabled = false
+slot/2/left_type = 0
+slot/2/left_color = Color(1, 1, 1, 1)
+slot/2/left_icon = null
+slot/2/right_enabled = false
+slot/2/right_type = 0
+slot/2/right_color = Color(1, 1, 1, 1)
+slot/2/right_icon = null
+slot/2/draw_stylebox = true
+script = ExtResource("4_0jqh0")
+metadata/command = "note_to_hz"
+metadata/utility = true
+
+[node name="Note" type="ItemList" parent="note_to_hz"]
+layout_mode = 2
+theme_override_font_sizes/font_size = 20
+allow_search = false
+auto_height = true
+item_count = 7
+max_columns = 7
+same_column_width = true
+fixed_column_width = 45
+icon_mode = 0
+item_0/text = "A"
+item_1/text = "B"
+item_2/text = "C"
+item_3/text = "D"
+item_4/text = "E"
+item_5/text = "F"
+item_6/text = "G"
+
+[node name="Accidental" type="ItemList" parent="note_to_hz"]
+custom_minimum_size = Vector2(0, 40)
+layout_mode = 2
+theme_override_fonts/font = ExtResource("5_0jqh0")
+theme_override_font_sizes/font_size = 30
+allow_search = false
+auto_height = true
+item_count = 7
+max_columns = 7
+same_column_width = true
+fixed_column_width = 45
+icon_mode = 0
+item_0/text = ""
+item_1/text = ""
+item_2/text = ""
+item_3/text = ""
+item_4/text = ""
+item_5/text = ""
+item_6/text = ""
+
+[node name="FreqOutput" type="CodeEdit" parent="note_to_hz"]
+custom_minimum_size = Vector2(0, 10)
+layout_mode = 2
+size_flags_vertical = 3
+editable = false
+wrap_mode = 1
+
 [connection signal="text_submitted" from="outputfile/FileNameField" to="outputfile" method="_on_file_name_field_text_submitted"]
 [connection signal="text_submitted" from="outputfile/FileNameField" to="outputfile" method="_on_file_name_field_text_submitted"]
+[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"]
 
 
 [editable path="distort_average/VBoxContainer"]
 [editable path="distort_average/VBoxContainer"]
 [editable path="clip_clip_2/VBoxContainer"]
 [editable path="clip_clip_2/VBoxContainer"]

+ 76 - 0
scenes/Nodes/notes_to_hz.gd

@@ -0,0 +1,76 @@
+extends GraphNode
+
+@export var min_gap: float = 0.5  # editable value in inspector for the minimum gap between min and max
+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)
+	
+	var i = 0
+	while i <= 6:
+		$Note.set_item_tooltip_enabled(i, false)
+		i += 1
+	$Accidental.set_item_tooltip(0, "3/4 Flat")
+	$Accidental.set_item_tooltip(1, "Flat")
+	$Accidental.set_item_tooltip(2, "1/4 Flat")
+	$Accidental.set_item_tooltip(3, "Natural")
+	$Accidental.set_item_tooltip(4, "1/4 Sharp")
+	$Accidental.set_item_tooltip(5, "Sharp")
+	$Accidental.set_item_tooltip(6, "3/4 Sharp")
+	
+	$Note.select(0, true)
+	$Accidental.select(3, true)
+	calculate_freq()
+
+
+
+
+func _open_help():
+	open_help.emit(self.get_meta("command"), self.title)
+	
+
+
+func _on_item_list_item_selected(index: int) -> void:
+	calculate_freq()
+
+
+
+func _on_item_list_2_item_selected(index: int) -> void:
+	calculate_freq()
+	
+const NOTE_TO_MIDI = {
+	0: 9, 1: 11, 2: 12, 3: 14, 4: 16, 5: 17, 6: 19,
+}
+const ACCIDENTAL_TO_MODIFIER = {
+	0: -1.5, 1: -1, 2: -0.5, 3: 0, 4: 0.5, 5: 1, 6: 1.5,
+}
+
+func calculate_freq():
+	var note = $Note.get_selected_items()[0]
+	var accidental = $Accidental.get_selected_items()[0]
+	var freq
+	var textout = ""
+	
+	$FreqOutput.text = ""
+	
+	note = NOTE_TO_MIDI.get(note, null)
+	accidental = ACCIDENTAL_TO_MODIFIER.get(accidental, null)
+	
+	note = note + accidental
+	
+	freq = 440.0 * pow(2, (note - 69) / 12.0)
+	
+	var count = 0
+	
+	while count < 11:
+		textout += "%.2f, " % freq
+		freq = freq * 2
+		count +=1
+	
+	$FreqOutput.text = textout

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

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

File diff suppressed because it is too large
+ 219 - 303
scenes/main/process_help.json


BIN
theme/BravuraText_SoundThread.otf


+ 35 - 0
theme/BravuraText_SoundThread.otf.import

@@ -0,0 +1,35 @@
+[remap]
+
+importer="font_data_dynamic"
+type="FontFile"
+uid="uid://bfnlymfdfb0e7"
+path="res://.godot/imported/BravuraText_SoundThread.otf-55e13dd91c45a176dab959803cbd11ec.fontdata"
+
+[deps]
+
+source_file="res://theme/BravuraText_SoundThread.otf"
+dest_files=["res://.godot/imported/BravuraText_SoundThread.otf-55e13dd91c45a176dab959803cbd11ec.fontdata"]
+
+[params]
+
+Rendering=null
+antialiasing=1
+generate_mipmaps=false
+disable_embedded_bitmaps=true
+multichannel_signed_distance_field=false
+msdf_pixel_range=8
+msdf_size=48
+allow_system_fallback=true
+force_autohinter=false
+hinting=1
+subpixel_positioning=4
+keep_rounding_remainders=true
+oversampling=0.0
+Fallbacks=null
+fallbacks=[]
+Compress=null
+compress=true
+preload=[]
+language_support={}
+script_support={}
+opentype_features={}

Some files were not shown because too many files changed in this diff