NNdef is a child class of Ndef that attaches an FRP event network onto every Ndef source. The event network is recreated every time the Ndef source is changed. If the new event network has the same topology of the old one, then the state of the network is preserved: state values (e.g. from inject) and the current value of signals are kept and only the pure functions (e.g. from collect) are changed. The connection of the elements of the FRP event network to the audio UGens is done using the FPSignal: enKr and EventSource: enKr (as well as enAr and enTr). These methods return a NamedControl which the frp element will automatically update. Using myfpsignal.enKr
is therefore analogous to \freq.kr
.
Set value in FRP state dictionary (key value pairs in flat array). Value is sent to corresponing Store node.
Set value in FRP state dictionary (key value pairs in flat array). Value is not sent to corresponing Store node.
Get value from FRP state dictionary. Value is updated when FRP graph fires by corresponing Store method.
Remove key-value pair from dictionary.
Get audio and FRP node maps.
These examples use the Kork NanoKontrol. If you don't have one available, a gui will be automatically created.
Let's start with normal NNdef without midi controls:
We will now control the amplitude with the first slider of the first page of the nanokontrol. First we get the MKtlElement for the slider with k[\sl][page][column]
. Then we create an frp signal element with enInSig. A signal contains a current value. In this case it is better to use a signal as then there will a be start value which is the current value of the slider. Finally we connect the FPSignal to a NamedControl using .enKr
.
First create the Modality object representing a real or virtual Korg Nanokontrol:
We can also control the frequency of the oscilator with a second slider. In this case we will specify a spec to be applied to the values.
We can post values for debugging by supplying a label to FPSignal: enDebug :
It's also possible to explicitly set the name of the controls. This is useful for storing presets with NdefMixer.
Using the buttons as a sequencer.Although every time the nndef is re-evaluated the FRP network is recreated, if the network has has the same shape (for instance you only made changes in the function passed to EventSource: collect) then the state from the previous version of the networked is copied over to the new network, in particular the values stored in the inject and signal nodes are copied. That means that after re-evaluating the NNdef below the last button pressed and its frequency value is remembered.
Percussive version using EventSource: enTr which creates a TrigControl:
Adding sliders for the LFNoise1 range. enKrUni is used as the value should be automatically mapped from [0,1] to the range in spec.
if play button is pressed we use higher octave. { |octave, e| octave*freq0 } <%> octaveSig <@> mktlElement.enInES;
works such that it only fires an event when mktlElement.enInES
changes.
Use arrow keys to switch octave:
When the FRP graph is the same after re-evaluation and only the pure functions were changed the NNdef will be copy the state from the previous FRP graph to the new one. In this case the value in injectFSig will be copied and the current value of the octave will be kept. Try using the buttons until the octave is for instance 3, then run the code below and notice how pressing forward again will change the octave to 2:
To dispose of the current value in all nodes with state use clear:
If play is pressed amp slider is in 'zoom' mode:
Now with pick up when in zoom mode
Another way of doing the same using FPSignal: if :
State can exist in the FRP network in the FPSignal nodes and inject, injectSig, injectF and injectFSig nodes. To save and recall this state use the store methods: injectStore, injectSigStore, injectFStore and injectFSigStore. These methods will associtate the node with a name and save incoming values to a dictionary in the NNdef. The dictionary can be queried with enGet and enSet. The whole NNdef can be persisted to disk using asCode.
This will include on enSet instruction for the octave parameter.