Module: Ruby2Faust::Live
- Defined in:
- lib/ruby2faust/live.rb
Overview
Live reload support: graph diffing, compilation, crossfade.
Class Method Summary collapse
-
.changed?(old_graph, new_graph) ⇒ Boolean
Check if two graphs have different structure.
-
.compile(graph, output:, imports: Emitter::DEFAULT_IMPORTS) ⇒ String
Compile a DSP graph to a Faust file.
-
.crossfade_dsp(old_process, new_process, duration: 0.05) ⇒ String
Generate crossfade DSP code for smooth transitions Creates a Faust program that crossfades between old and new DSP.
-
.faust_compile(dsp_file, target: :cpp, output_dir: nil) ⇒ Boolean
Run the Faust compiler on a .dsp file Requires faust to be in PATH.
Class Method Details
.changed?(old_graph, new_graph) ⇒ Boolean
Check if two graphs have different structure
16 17 18 19 20 |
# File 'lib/ruby2faust/live.rb', line 16 def changed?(old_graph, new_graph) old_node = old_graph.is_a?(DSP) ? old_graph.node : old_graph new_node = new_graph.is_a?(DSP) ? new_graph.node : new_graph !old_node.same_structure?(new_node) end |
.compile(graph, output:, imports: Emitter::DEFAULT_IMPORTS) ⇒ String
Compile a DSP graph to a Faust file
28 29 30 31 32 |
# File 'lib/ruby2faust/live.rb', line 28 def compile(graph, output:, imports: Emitter::DEFAULT_IMPORTS) code = Emitter.program(graph, imports: imports) File.write(output, code) output end |
.crossfade_dsp(old_process, new_process, duration: 0.05) ⇒ String
Generate crossfade DSP code for smooth transitions Creates a Faust program that crossfades between old and new DSP
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ruby2faust/live.rb', line 41 def crossfade_dsp(old_process, new_process, duration: 0.05) " import(\"stdfaust.lib\");\n\n // Crossfade envelope\n xfade = hslider(\"xfade\", 0, 0, 1, 0.001) : si.smoo;\n\n // Old and new processes\n old = \#{old_process};\n new = \#{new_process};\n\n // Crossfade: (1-x)*old + x*new\n process = old * (1 - xfade), new * xfade :> _;\n FAUST\nend\n" |
.faust_compile(dsp_file, target: :cpp, output_dir: nil) ⇒ Boolean
Run the Faust compiler on a .dsp file Requires faust to be in PATH
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ruby2faust/live.rb', line 64 def faust_compile(dsp_file, target: :cpp, output_dir: nil) output_dir ||= File.dirname(dsp_file) basename = File.basename(dsp_file, ".dsp") cmd = case target when :wasm "faust2wasm #{dsp_file} -o #{output_dir}/#{basename}.wasm" when :cpp "faust -a minimal.cpp #{dsp_file} -o #{output_dir}/#{basename}.cpp" when :llvm "faust -lang llvm #{dsp_file} -o #{output_dir}/#{basename}.ll" else raise ArgumentError, "Unknown target: #{target}" end system(cmd) end |