[flocking] How to trigger an envelope from JavaScript?

aBe abe at hamoid.com
Fri Apr 15 09:32:50 UTC 2016


It does help a lot. Got it working! Thank you!! :)

On 04/15/2016 10:31 AM, Andri Pétur Þrastarson wrote:
> If it helps, here's a short code example of using a function to trigger
> notes on a flocking synth. 
>  
> 
>     var environment = flock.init();
>     environment.start(); 
> 
>      
> 
>     var synth = flock.synth({
>       nickName: "square-synth",
>       synthDef: {
>         ugen: "flock.ugen.filter.moog",
>          cutoff: {
>              ugen: "flock.ugen.sinOsc",
>              freq: 1/8,
>              mul: 5000,
>              add: 6000
>          },
>          resonance: 2,
>          source: {
>              id: 'osc',
>              ugen: "flock.ugen.square",
>              mul: {
>                  id: "env",
>                  ugen: "flock.ugen.asr",
>                  attack: 0.001,
>                  sustain: 0.5,
>                  release: 0.4,
>                  gate: 0,
>              }
>            },
>          },
>        });
>     var playNote = function (f) {
>       synth.set("osc.freq", f); //<<set note
>       synth.set("env.gate", 1); // turn env on
>       setTimeout(function(){ // put note out
>         synth.set("env.gate", 0);
>       }, 100)
>     }
>     playNote( 2000 ) // plays note at freq 2000
> 
> 
> 
> 2016-04-15 7:34 GMT+02:00 Colin Clark <colin at colinclark.org
> <mailto:colin at colinclark.org>>:
> 
>     I'm traveling at the moment so I can only respond quickly, but can
>     add more later when I land.
> 
>     I'd recommend letting the synth sit there, and retrigger it each
>     time you get an event from the web socket. So you can receive an
>     event and then toggle the envelope's gate to open and close each
>     time with a call to Synth.set().
> 
>     Does this help?
> 
>     Good luck with your installation!
> 
>     Colin
> 
>     > On Apr 14, 2016, at 10:37 PM, aBe <abe at hamoid.com
>     <mailto:abe at hamoid.com>> wrote:
>     >
>     > Thanks, I'll share code when I have some :)
>     >
>     > I've seen the mouse click event. But I had no idea how to apply
>     that to
>     > be able to play a sound when I receive events via web-sockets.
>     >
>     > To make a more specific question, how would you change this example:
>     >
>     >
>     https://github.com/colinbdclark/Flocking/blob/master/demos/playground/demos/custom-envelope.js
>     >
>     > so I'm able to trigger that envelope once every time I receive a
>     > web-socket event? (or just any event coming from my JavaScript code).
>     >
>     > Should I create a new synth for each event, play it, and destroy it?
>     >
>     > Or let the synth sit there instead, and just restart the envelope each
>     > time I receive an event?
>     >
>     > Thank you!
>     >
>     > aBe
>     >
>     >> On 04/14/2016 09:38 PM, Meta wrote:
>     >> ahh yes I know the feeling, I am super newb as well :D
>     >>
>     >> If you share some more information or better still some code I could
>     >> spend some time trying help you to approach this in an efficient way.
>     >>
>     >> But from what I understand you want to achieve this particular
>     example
>     >> has the basic functionality you want so maybe could be the base
>     for your
>     >> synth?
>     >> http://flockingjs.org/next/demos/playground/#mouse-click
>     >>
>     >> also what exactly do you mean by "start a quick and short amplitude
>     >> envelope from JavaScript"??
>     >>
>     >> B
>     >>
>     >>
>     >>> On 14/04/2016 22:02, aBe wrote:
>     >>> Hi! Thanks for answering so quick.
>     >>>
>     >>> In one sentence, I have no idea what I'm doing :) I'm
>     comfortable with
>     >>> SuperCollider, but I'm still trying to understand how Flocking
>     works.
>     >>>
>     >>> I did not know I could play individual sounds, because the
>     Playground
>     >>> examples I've seen play one synth forever.
>     >>>
>     >>> Based on your response, I assume I could create (and destroy)
>     synths on
>     >>> the fly? I thought it would be more efficient to just create one
>     synth,
>     >>> and then manipulate all the envelope values. But I'm open to try any
>     >>> approaches.
>     >>>
>     >>> What I'm trying to do is to create some kind of bird like
>     sounds. The
>     >>> sounds last about 3 seconds and have 15 envelope points for
>     amplitudes
>     >>> and frequencies.
>     >>>
>     >>> ps. I don't have much (Flocking) code to show yet, I've been
>     just trying
>     >>> to tweak the existing examples before I port the SuperCollider code.
>     >>>
>     >>> Cheers!
>     >>>
>     >>> a
>     >>>
>     >>>
>     >>>
>     >>>> On 04/14/2016 08:50 PM, Meta wrote:
>     >>>> Hello there,
>     >>>>
>     >>>> I am sure someone with better understanding will answer you
>     soon but in
>     >>>> the mean time can I ask for some code example and why exactly
>     you take
>     >>>> this approach?
>     >>>> For example you could trigger multiple sounds individually, why
>     keep one
>     >>>> particular sound muted but "running" using an envelop?
>     >>>>
>     >>>> B
>     >>>>
>     >>>>> On 14/04/2016 21:43, aBe wrote:
>     >>>>> Hi hi,
>     >>>>>
>     >>>>> I'm preparing a mobile based collaborative sound installation
>     using
>     >>>>> Flocking, which I hope it's ready next Friday :)
>     >>>>>
>     >>>>> I need to play sounds with fast envelopes based on JavaScript
>     events. In
>     >>>>> the Flocking repo I see examples for:
>     >>>>>
>     >>>>> * Automatic regular retriggering of envelopes
>     (custom-envelope.js, uses
>     >>>>> lfPulse on a gate).
>     >>>>> * Playing sounds on mouse click events.
>     >>>>> * Using valueChangeTrigger, but that seems to be for playing
>     buffers only.
>     >>>>>
>     >>>>> How can I start a quick and short amplitude envelope from
>     JavaScript,
>     >>>>> and then keep it silent, until another event happens?
>     >>>>>
>     >>>>> Is there something like a "valueChangeGate"?
>     >>>>>
>     >>>>> Thank you!
>     >>>>>
>     >>>>> aBe
>     >>>>> _______________________________________________
>     >>>>> flocking mailing list
>     >>>>> flocking at lists.idrc.ocad.ca <mailto:flocking at lists.idrc.ocad.ca>
>     >>>>> http://lists.idrc.ocad.ca/mailman/listinfo/flocking
>     >>>> _______________________________________________
>     >>>> flocking mailing list
>     >>>> flocking at lists.idrc.ocad.ca <mailto:flocking at lists.idrc.ocad.ca>
>     >>>> http://lists.idrc.ocad.ca/mailman/listinfo/flocking
>     >>> _______________________________________________
>     >>> flocking mailing list
>     >>> flocking at lists.idrc.ocad.ca <mailto:flocking at lists.idrc.ocad.ca>
>     >>> http://lists.idrc.ocad.ca/mailman/listinfo/flocking
>     >>
>     >> _______________________________________________
>     >> flocking mailing list
>     >> flocking at lists.idrc.ocad.ca <mailto:flocking at lists.idrc.ocad.ca>
>     >> http://lists.idrc.ocad.ca/mailman/listinfo/flocking
>     > _______________________________________________
>     > flocking mailing list
>     > flocking at lists.idrc.ocad.ca <mailto:flocking at lists.idrc.ocad.ca>
>     > http://lists.idrc.ocad.ca/mailman/listinfo/flocking
> 
>     _______________________________________________
>     flocking mailing list
>     flocking at lists.idrc.ocad.ca <mailto:flocking at lists.idrc.ocad.ca>
>     http://lists.idrc.ocad.ca/mailman/listinfo/flocking
> 
> 


More information about the flocking mailing list