From 715f8440e68fea6a7cfcedd409053d0579523e14 Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Fri, 5 Nov 2021 23:56:09 -0400 Subject: Refactor complete --- klangfarb/Main.tscn | 1 - klangfarb/MonoSynth.gdns | 8 ++++++++ klangfarb/Osc.gdns | 8 -------- klangfarb/main.gd | 32 ++++++++++++++++++++++++-------- 4 files changed, 32 insertions(+), 17 deletions(-) create mode 100644 klangfarb/MonoSynth.gdns delete mode 100644 klangfarb/Osc.gdns (limited to 'klangfarb') diff --git a/klangfarb/Main.tscn b/klangfarb/Main.tscn index 896aa8c..e7a1b90 100644 --- a/klangfarb/Main.tscn +++ b/klangfarb/Main.tscn @@ -8,4 +8,3 @@ stream = SubResource( 1 ) volume_db = -13.216 script = ExtResource( 2 ) -freq = 130.0 diff --git a/klangfarb/MonoSynth.gdns b/klangfarb/MonoSynth.gdns new file mode 100644 index 0000000..d795047 --- /dev/null +++ b/klangfarb/MonoSynth.gdns @@ -0,0 +1,8 @@ +[gd_resource type="NativeScript" load_steps=2 format=2] + +[ext_resource path="res://klangfarbrs.gdnlib" type="GDNativeLibrary" id=1] + +[resource] +resource_name = "MonoSynth" +class_name = "MonoSynth" +library = ExtResource( 1 ) diff --git a/klangfarb/Osc.gdns b/klangfarb/Osc.gdns deleted file mode 100644 index 65d44ef..0000000 --- a/klangfarb/Osc.gdns +++ /dev/null @@ -1,8 +0,0 @@ -[gd_resource type="NativeScript" load_steps=2 format=2] - -[ext_resource path="res://klangfarbrs.gdnlib" type="GDNativeLibrary" id=1] - -[resource] -resource_name = "Osc" -class_name = "Osc" -library = ExtResource( 1 ) diff --git a/klangfarb/main.gd b/klangfarb/main.gd index 439bb50..95c0f8f 100644 --- a/klangfarb/main.gd +++ b/klangfarb/main.gd @@ -1,16 +1,28 @@ extends AudioStreamPlayer -# controllable frequency interface -export(float, 20, 8000, 5) var freq = 440.0 -export(float, 0, 1, 0.1) var bend = 0.5 # control wave form export(String, "sine", "square", "triangle", "sawtooth") var waveform = "sine" +# controllable frequency interface +export(float, 20, 8000, 5) var freq = 440.0 +# bending the waveform +export(bool) var apply_bend = false +export(Vector2) var phasor_bend = Vector2(0.5, 0.5) +# duration related +export(bool) var continuous = true +export(int, 0, 5000, 100) var duration = 3000 +#Attack/Decay/Release/Sustain +export(int, 0, 5000, 100) var attack = 100 +export(int, 0, 5000, 100) var decay = 100 +export(int, 0, 5000, 100) var release = 100 +export(float, 0.0, 1.0, 0.1) var sustain = 0.5 +#Cutoff +export(float, 20, 8000, 5) var cutoff = 6000 # load the GDNative script connected to the rust lib -var Osc = preload("res://Osc.gdns") +var MonoSynth = preload("res://MonoSynth.gdns") # make an instance of our one "class" in rust lib -var wave = Osc.new() +var wave = MonoSynth.new() # initialize the Godot stream we fill up with samples var playback: AudioStreamPlayback = null @@ -22,7 +34,7 @@ func _fill_buffer() -> void: # ask Rust to generate N frames at freq # Array gets pushed to the # playback stream buffer - playback.push_buffer(wave.frames(freq, to_fill, bend)) + playback.push_buffer(wave.frames(to_fill)) func _check_waveform(): if waveform == "square": @@ -36,6 +48,9 @@ func _check_waveform(): func _process(_delta): if self.is_playing(): + wave.apply_bend(apply_bend) + wave.frequency(freq) + wave.phasor_bend(phasor_bend) _check_waveform() _fill_buffer() @@ -55,5 +70,6 @@ func _input(event): if event is InputEventMouseButton: print("Mouse Click/Unclick at: ", event.position) elif event is InputEventMouseMotion: - freq = event.position.x - print("Mouse Motion at: ", event.position) +# freq = event.position.x + phasor_bend.x = event.position.x / 1024 + phasor_bend.y = event.position.y / 600 -- cgit v1.2.3