MAX/MSP CPG Externals
Note - this is currently under construction. I’ll try to add explanatory images and maybe a tutorial video in the coming weeks
This page documents a set of externals which allow people to explore the use of Central Pattern Generator (CPG) neural networks. For an intro to CPGs see this page or my paper here.
Download the MAX/MSP package from GitHub..
No building is required: just download the repository and put it in your MAX packages folder. The package comprises three objects and a hackable MAX/MSP implementation of my CPG sequencer/ rhythm generator Neurythmic, including a standalone GUI application. The CPG objects for max are documented in the usual fashion, with help patches inside MAX/MSP, below is a quick intro to the neurythmic patch and GUI.
Neurythmic for MAX
The MAX package includes a MAX/MSP port and update of Neurythmic - a rhythm sequencer/ drum machine/ rhythm generator built on Central Pattern Generators. Inside the NeurythmicApp folder in the MAX package, there is a max patch “neurythmic.maxpat”. In the “gui” subfolder you will find an executable “NeurythmicGUI.exe”.
At present the GUI only works on Windows, but even for macOS users the MAX patch is a good starting point for working with my cpg.network~ object, and developing alternative interfaces: whether that’s a simple gui, some kind of algorithmic control system, or a physical installation.
To use neurythmic, first load the max patch and switch on DSP in MAX, then load the GUI: NeurythmicGUI.exe. The GUI sends OSC messages to max, and the patch interprets them, sends them to the cpg.network~ object, and uses the output signals to trigger sounds.
You might want to begin by clicking the cog icon on the top right, and loading a preset, then playing around. There is a basic guide below, and this video may also be helpful
Basics:
- Each circle on screen is a node in the network
- Arrows show connections
- The root node is the largest double-ring node - this defines the base tempo for the whole system, and sets the pulse for the quantiser system
- Right click on a node to open its control menu (see NODE MENU BELOW).
- Right click on a connection to control the basic strength of a connection (like turning up the power on its transmitter) (you will see the arrow grow fatter and more orange). The more signal gets to a node, the more it is affected by the signal. Nodes try to synchronise to the incoming signal (a process called “entrainment”). But weaker signals, and multiple connections can mean the synchronisation becomes more complicated and more interesting rhythms are created.
- Click and drag nodes to move them. Moving nodes closer together means the connection is stronger: more signal gets to the destination just like if you walk closer to a speaker, it gets louder. Moving nodes further away weakens the connection. Again, as signals get stronger, the arrows get fatter and more orange.
- If you move nodes far enough apart, or turn the signal strength to 0, the arrow will turn into a pale dotted line: no signal is being sent, so the nodes are not affecting each other.
Node Menu (right click on node)
Tab 1 - Node menu
This controls the node’s basic behaviour: you can set its natural pulse frequency (a multiple of the base tempo”) via “Rate” or “fine tune”. You can add a new node as “child” of this node. If the current node has no children you can delete the node.
Tab 2 - Rhythmic Manipulation
This controls “filters” applied to the raw rhythmic output of the nodes: there is a quantiser system, and you can also apply timing offsets. Freedom sets the strength of the quantiser If you increase freedom this means less (and ultimately 0) quantisation. If you decrease freedom then the notes generated by the network are pushed towards the quantiser gridlines. At 0 freedom, notes only appear at quantiser gridlines.
You can also set details of the rhythmic grid - either 3/4 or 4/4, or turn the quantiser off (to use the “raw” rhythmic output of the node. “Resolution” sets the number of beats per bar. “Raw mode” bypasses the quantiser altogether, and does not use note triggers, but uses the raw waveform of the node to envelope a simple synthesizer voice.
Finally you can apply timing offset to the beats of the node. Simply click on the slider in the bottom panel - If the quantiser shows you where beats are allowed to fall The root node does not have quantiser controls, since the quantiser is synchronised to this node. The root node still has a “freedom” control - this sets the overall freedom for the system
Tab 3 - Sound Output
The last tab lets you choose the sound which is triggered by the node, and also its pitch and volume. “SIN” is a simple sine-wave synthesizer voice (envelope controlled by Attack, decay). The other options are drum machine sounds. You can replace these with any samples of your choice in the max patch.
Again you can select “RAW MODE”. “Raw mode” bypasses the quantiser altogether, and does not use note triggers, but uses the raw waveform of the node to envelope a simple synthesizer voice. You can still set the pitch. Decay now acts as a kind of envelope waveshaper.
Other Menus
At the top right there are three icons, in order Sound / Settings / Close menu;
Sound Menu
mixer and volume
Settings Menu
Load and restore presets, save a preset bank to a file, load a preset bank from file. I’ve found it can be too easy to accidentally overwrite a preset, and a better UI could easily be imagined. This is a pain, but I haven’t had time to fix it. Warning: there is a slight bug with preset loading - sometimes networks initialise with all the right parameters, but the behaviour is not quite the same. This is no doubt due to the sensitivity of the networks to initial conditions - although we are initialising with internal values for all nodes. It is possible something is off here. I need to find the source of the issue for a future update.
You can also reload the settings file (for ease of hacking: see hacking below) but not all settings options can be changed without a reload. The GUI sends OSC messages to MAX (or potentially any OSC receiving system, if you can imagine another use for this GUI). You can change IP of the OSC host and the in/out ports in this menu too
Max patch Hacking
You can easily make changes to the max patch - look at the help file for cpg.network~ for other options which are not used.
Some ideas:
- You can sync to an external sequencer using a phasor as in the max help file
- You could use cpg.network~ as weird oscillator bank (disconnect the frequency control coming from the GUI). This may eat your CPU at the moment - In future updates I’ll add an external optimised for signal rate usage.
- You could also use external signals, to make the network entrain to other sounds - e.g. low frequency control signals, or audio signals. Some sources of control signal will need to be conditioned before use to get good results. some thoughts here:
You will probably want to scale input signals to within a -1 to 1 range (and possibly smaller than that).
Persistent non-zero signals will affect node cycles, and if high enough cause nodes to halt.
As such you may wish to do some waveshaping (e.g. sigmoid function). t might be helpful to test ideas out with node_basic, or node_freq first and observe the effects on the waveform.
Other hacking:
In the assets folder there are settings files you can change, alongside the max patch. Make sure you back up first. After altering any of these files just reload the exe.
- It is possible to change the labels for the synth voices, (and the number of synth voices and other details) by changing the synthPresets.xml file in your text editor of choice.
- Other GUI settings (colours, node sizes, some labels, etc.) can be changed by editing the settings.pre file.