This repository contains custom external objects for the Max/MSP programming language, written in C.
The repository is organized into several directories:
buildspans/,createproject/,crossfade~/,stemversion/,whichoffset/: Each of these directories contains the source code for a single Max external object.shared/: Contains common C code modules that can be shared across multiple external objects.max-sdk/: Contains the Max SDK, which is required for building the external objects.gui.py: A Python-based GUI for visualizing data from the objects.
Each external object's directory typically contains:
<object-name>.c: The C source code for the object.<object-name>.maxref.xml: The XML documentation file for the object's inlets, outlets, and methods.<object-name>.mxe64: The compiled 64-bit Windows binary for the object.Makefile: The build script for compiling the object.
-
Max SDK: The project requires the Cycling '74 Max SDK. It must be cloned into the
max-sdkdirectory at the repository root.git clone https://github.com/Cycling74/max-sdk.git --recursive
-
MinGW-w64: The
x86_64-w64-mingw32-gcccompiler is used for building the 64-bit Windows binaries (.mxe64). The recommended way to install it on Windows is via MSYS2.Installation Steps:
- Download and install MSYS2 from https://www.msys2.org/. Follow the instructions on the site.
- Open the MSYS2 terminal after installation and run the following command to install the toolchain:
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain- Press
Enterto accept the default package selection. - Type
Yand pressEnterto proceed with the installation.
- Press
- Add the MSYS2 tools to your Windows PATH. This is a critical step to ensure both the compiler (
gcc) and themakecommand can be found in your Command Prompt.- Search for "Edit the system environment variables" in the Windows search bar and open it.
- Click "Environment Variables..."
- In the "User variables" section, select the
Pathvariable and click "Edit..." - You will need to add two new entries. Click "New" and add each of the following paths:
C:\msys64\ucrt64\bin(this is for the compiler, gcc.exe)C:\msys64\usr\bin(this is for build tools like make.exe)
- Click
OKon all windows to save the changes.
- Verify the installation. Open a new Command Prompt and run
gcc --version. If it's installed correctly, you will see the compiler version information.
To build an individual external object, navigate into its specific directory and run the make command from a standard Windows Command Prompt or PowerShell:
cd buildspans/
makeThe crossfade~ object implements a dynamic crossfading algorithm between two input signals based on a control signal. It is a translation of a GenExpr algorithm provided by the user.
- Dynamic Ramping: The ramp length is dynamically adjusted based on the signal amplitude.
- Busy Signal: A dedicated outlet indicates when a crossfade is in progress.
- High Performance: Implemented in C using a shared DSP module for maximum efficiency.
- Variable Parameters: Customizable
lowandhighlimits for the ramp length via object attributes.
The buildspans object is designed to process musical note data and group it into "spans."
- Span: A span is a contiguous sequence of musical "bars." A bar is a time interval defined by the
bar_lengthattribute. A span is considered contiguous if the time gap between consecutive bars is no greater thanbar_length. - Working Memory: The object's primary internal data structure is a
t_dictionarycalledbuilding.- The keys of this dictionary are hierarchical:
palette::track-rounded_offset::bar_timestamp::property.
- The keys of this dictionary are hierarchical:
- Bar Dictionary: Each bar's data includes:
absolutes: At_atomarrayof the absolute millisecond timestamps of the notes in that bar.scores: A parallelt_atomarrayof the scores for each note.mean: The calculated mean of the scores.offset: A copy of the global offset at the time the bar was created.palette: A copy of the global palette symbol at the time the bar was created.span: At_atomarraythat contains the timestamps of all bars in the current span for that track. This is back-propagated to all bars in the span whenever a new bar is added.
It is critical to distinguish between global properties of the object and the per-bar data that is stored.
- Global Properties: These are stored as members of the main
_buildspansC struct and persist until they are changed by the user.current_track: The currently active track number.
current_offset: The global offset value.current_palette: The currently active palette symbol.local_bar_length: The length of a bar in milliseconds.
- Automatic Offset Initialization: If the offset has not yet been set (since instantiation or the last
clearmessage) and a note list is received in Inlet 1, the first timestamp in that list is used to automatically initialize the global offset. - Persistence after Flush: When a span is flushed via a
bang, only thelocal_bar_lengthis reset to 0. Thecurrent_track,current_offset, andcurrent_palettepersist at their last received values.
A span is "flushed" (i.e., ended and output) under several conditions:
- Manual Flush: Receiving a
bangin the first inlet triggers a flush of all active spans for all palettes. - Discontinuity: If a new timestamp is received that would create a bar that is not contiguous with the existing span, the object automatically flushes the existing span for that track.
- Rating-Based End: A deferred rating check occurs when a new bar starts. If including the previous bar would have decreased the overall span rating, the span is ended before that bar.
The flushing process handles:
- Outputting the span data, track number, and detailed bar properties to the outlets.
- Deleting the entries for that track from the
buildingdictionary.
When making changes to an object's C code:
- Modify the C source file (
<object-name>.c). - Update documentation and assist messages:
- Update the corresponding
.maxref.xmlfile to reflect any changes to the object's functionality. - Update the in-code
assistmessages to keep the inlet/outlet help text accurate.
- Update the corresponding
- Recompile the object by running
makein the object's directory to produce a new.mxe64binary. - Submit all modified files for review, including the
.c,.maxref.xml, and the newly compiled.mxe64files.