Lesson 5 - SNEX code in a bit more detail.
So I'm by no means an expert in C or C++ - in fact I only just recently started learning it. But here's what I've sussed out in regards to the HISE template.... and template is exactly the right word, because the first line is:
template <int NV> struct audio_loader
Somewhere under the hood, HISE must be setup to send in an integer into any SNEX node, that integer corresponding to a voice. NV = new voice perhaps, or number of voices ????
The line above declares a template that takes this NV integer in, and creates a struct called audio_loader for each instance of NV. Indeed we can prove this by running the following code:
template <int NV> struct audio_loader
{
SNEX_NODE(audio_loader);
ExternalData data;
double note = 0.0;
// Initialise the processing specs here
void prepare(PrepareSpecs ps)
{
}
// Reset the processing pipeline here
void reset()
{
}
// Process the signal here
template <typename ProcessDataType> void process(ProcessDataType& data)
{
}
// Process the signal as frame here
template <int C> void processFrame(span<float, C>& data)
{
}
// Process the MIDI events here
void handleHiseEvent(HiseEvent& e)
{
double note = e.getNoteNumber();
Console.print(note);
}
// Use this function to setup the external data
void setExternalData(const ExternalData& d, int index)
{
data = d;
}
// Set the parameters here
template <int P> void setParameter(double v)
{
}
};
There are only three things happening here:
- We set the ExternalData as in a previous post.
- We establish a variable with the datatype of double called 'note' and we initialise it as 0.0. But this value will never hold because....
- In the handleHiseEvent() method, we use e.getNoteNumber() and we assign this to the note variable. We then print the note variable out inside of the handleHiseEvent() method.
Now when we run this script, any time we play a midi note, the console will show us the note number that we pressed. This is even true if you play chords, or in a scenario where no note off events occur.
That's a long winded way of saying that a SNEX node is run for each active voice; at least when it is within a ScriptNode Synthesiser dsp network.
The next line in the script after the template is established is:
SNEX_NODE(audio_loader);
This is pretty straight forward. The text you pass here has to match the name of the script loaded inside your SNEX node - not the name of the SNEX node itself.
Here you can see my SNEX node is just called: snex_node.
But the script loaded into it is called audio_loader, and so the reference to SNEX_NODE inside the script has to also reference audio_loader.