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.gd | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'klangfarb/main.gd') 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