top of page

Arbitrary Expression Node for Metasounds (C++, Unreal Engine)

  • Writer: Niccolo Abate
    Niccolo Abate
  • Nov 11, 2023
  • 2 min read

Intro:

This code sample covers the definition and implementation (.h and .cpp) of an arbitrary expression node for Metasounds, in a custom Unreal Engine plugin. This code creates a node which parses a string and then computes the expression for a variable argument type (float or audio buffer) with a variable number of arguments (0-8), for use within Metasounds, Unreal Engine’s node-based procedural audio scripting engine.


Though the specifics of Unreal Engine and Metasounds are not important, note that the code is written effectively within these complex codebases, leveraging advanced C++, including templates, macros, polymorphism, namespacing, and more. This ensures clarity within the codebase, and increases the code reusability.


The full Unreal Engine plugin repository is available on github, including the two files in question: MetasoundExpressionNode.h and MetasoundExpressionNode.cpp.


Code Overview:

The code is broken into helper functions and meta-data functions, an operator class (defining the functionality of the node), and a node class (a simple wrapper of the operator class which contains the actual data of the instantiated node in the graph). All the code is templated and generalized so that it can handle variable type and number of arguments, allowing the macro calls at the bottom of the cpp file to quickly generate and register the desired types and arguments we wish to make available to the Metasounds editor.


As for the function of the code, at the center of the structure, the actual processing is fairly simple:

  1. Given a new expression string, compile the expression (calling on an external expression library).

  2. If the expression is valid, continue; otherwise, trigger an error message.

  3. Compute the expression on the given input arguments and output the result (sample by sample in the case of an audio buffer).


Code:


MetasoundExpressionNode.h:



MetasoundExpressionNode.cpp:


Related Posts

See All
K-D Tree (C++)

Intro: This code sample covers a generalized K-D Tree class I implemented for use in two audio plugins at Red Timbre Audio, both of which...

 
 
 

Коментарі


bottom of page