Last active
February 1, 2025 20:43
-
-
Save catfact/0441990d762657c4a9c02c062ba77f9c to your computer and use it in GitHub Desktop.
norns engine switching test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- engine switching test | |
| -- key 2: select TestSine | |
| -- key 3: select TestNoise | |
| -- enc 2 up: auto-switch (as fast as possible) | |
| -- enc 2 down: stop auto-switching | |
| local engine_loading_flag = true | |
| local autoswitch = false | |
| function init() | |
| engine_loading_flag = false | |
| end | |
| function engine_loaded() | |
| engine_loading_flag = false | |
| if autoswitch then | |
| if engine.name == 'TestSine' then | |
| load_engine('TestNoise') | |
| else | |
| load_engine('TestSine') | |
| end | |
| end -- autoswitch | |
| end | |
| local load_engine = function(name) | |
| if engine_loading_flag then | |
| print("---------------------------------") | |
| print("--- engine is already loading ---") | |
| print("---------------------------------") | |
| else | |
| engine_loading_flag = true | |
| engine.load(name, engine_loaded) | |
| engine.name = name | |
| end | |
| end | |
| function key(n,z) | |
| if z == 1 then | |
| if n == 2 then | |
| load_engine('TestSine') | |
| end | |
| if n == 3 then | |
| load_engine('TestNoise') | |
| end | |
| end | |
| end | |
| function enc(n, z) | |
| if n == 2 then | |
| if z > 0 then | |
| autoswitch = true | |
| print("autoswitch on") | |
| else | |
| autoswitch = false | |
| print("autoswitch off") | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // CroneEngine_TestNoise | |
| // variante of TestSine, for switching | |
| // Inherit methods from CroneEngine | |
| Engine_TestNoise : CroneEngine { | |
| var <synth; | |
| *new { arg context, doneCallback; | |
| ^super.new(context, doneCallback); | |
| } | |
| alloc { | |
| synth = { | |
| arg out, hz=220, amp=0.5, amplag=0.02, hzlag=0.01; | |
| var amp_, hz_; | |
| amp_ = Lag.ar(K2A.ar(amp), amplag); | |
| hz_ = Lag.ar(K2A.ar(hz), hzlag); | |
| Out.ar(out, (LPF.ar(WhiteNoise.ar, hz_) * amp_).dup); | |
| }.play(args: [\out, context.out_b], target: context.xg); | |
| this.addCommand("hz", "f", { arg msg; | |
| synth.set(\hz, msg[1]); | |
| }); | |
| this.addCommand("amp", "f", { arg msg; | |
| synth.set(\amp, msg[1]); | |
| }); | |
| } | |
| free { | |
| synth.free; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // CroneEngine_TestSine | |
| // dumbest possible test: a single, mono sinewave | |
| Engine_TestSine : CroneEngine { | |
| var <synth; | |
| *new { arg context, doneCallback; | |
| ^super.new(context, doneCallback); | |
| } | |
| alloc { | |
| synth = { | |
| arg out, hz=220, amp=0.5, amplag=0.02, hzlag=0.01; | |
| var amp_, hz_; | |
| amp_ = Lag.ar(K2A.ar(amp), amplag); | |
| hz_ = Lag.ar(K2A.ar(hz), hzlag); | |
| Out.ar(out, (SinOsc.ar(hz_) * amp_).dup); | |
| }.play(args: [\out, context.out_b], target: context.xg); | |
| this.addCommand("hz", "f", { arg msg; | |
| synth.set(\hz, msg[1]); | |
| }); | |
| this.addCommand("amp", "f", { arg msg; | |
| synth.set(\amp, msg[1]); | |
| }); | |
| } | |
| free { | |
| synth.free; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test switching norns engines within a script.
the supecollider classes can't handle the edge case of loading an engine before the previous one is done lodaing.
this demonstrates a workaround; lua tracks the state of engine loading and doesn't initiate a new load if one is pending.
keys 2, 3 select engines
encoder 2 engages / disengages 'autoswitch' mode, in which pressing k2 or k3 will begin toggling between the two engines as fast as possible. (this is not a pleasant sound.)
note that
Engine_TestSinecan't be duplicated, and is provided by thewerepo already.Engine_TestNoiseis new here,