Docs CHOPs & sensing

TopToMidi

Samples an image at points you define and turns the pixel values into MIDI notes in a musical scale, with trigger gating, retrigger control, a MIDI-learned custom scale and output to a MIDI Out or VST CHOP.

∿ CHOPs & sensing ◆ Patreon · Base

Why use it

Turning an image into music in TouchDesigner usually means a TOP to CHOP, some maths to turn brightness into note numbers, a lookup that keeps those notes in a key, and a CHOP Execute DAT that sends note-ons and note-offs without leaving any hanging. Each part is simple. Together they are an afternoon, and the note-off bookkeeping is where it tends to go wrong.

TopToMidi plays your visuals. You decide where the image is read, with a SOP's points or a TOP's pixels, and every sample point becomes a note in the scale you choose. The notes go to a MIDI Out CHOP, an Audio VST CHOP or both, and also come out as a CHOP for anything else.

Features

  • Sample an image at pointsA SOP's points or a TOP's pixels say where the input image is read, and each sample point becomes a note.
  • Index modeEach sample point plays its own note whenever its pixel passes the threshold, so a pattern sweeping across the picture plays an arpeggio.
  • Value modeThe pixel's brightness picks the note, quantised to a number of steps.
  • Scale mappingMaps every note into a scale from a root note and octave, from major and minor to the church modes.
  • Trigger gatingGate lengths, a minimum sustain and a retrigger delay keep a busy picture from spraying notes.
  • Custom scalesType your own scales into a table and they join the Scale menu.
  • Learn a scale from a MIDI keyboardWith MIDI Scale Learn on, the notes you play one by one become the scale.
  • Play along on a MIDI keyboardWith MIDI Live on, the scale follows the keys you hold, so you can duet with the picture.
  • Send notes to MIDI Out or a VSTSends the notes to a MIDI Out CHOP, an Audio VST CHOP or both, and outputs them as a CHOP for anything else.
  • Sampling previewShows the sample points over the image in a window where you can drag, scale and reset them.
  • Install the mingus dependencyInstall mingus writes a requirements file and hands it to the Python Environment Manager, which installs it into the linked environment in the background.

How to use it

  1. Create it from the FNS tab of the OP Create dialog and wire the image into its input.
  2. Look at Status on the Setup page. Every scale except MIDI Scale needs the Python package mingus; if Status says it is missing, see Installing mingus.
  3. Set Sampler to a SOP or a TOP that says where to read the image, for example a Grid SOP for a regular grid of points. Many SOPs sit around the origin, and Offset 0.5 moves them onto the image. Pulse Sample Preview to see the points over the picture and drag them into place.
  4. Pick a Mapping Mode:
    • Index: each sample point plays its own note while its pixel passes Threshold, so a bright bar sweeping across a grid plays an arpeggio. Steps follows the number of points, so keep the count modest: MIDI has 128 notes.
    • Value: the brightness at each point picks the note, quantised to Steps. Two points with the same value play the same note. Keep Re-Range on in this mode.
  5. Choose the music on the Scale page: Scale, Key and Octave. With more steps than the scale has notes, Extend Mode carries on into the octaves above.
  6. Send the notes. Drop a MIDI Out CHOP beside the tool and name it in MIDI Out CHOP, or name an Audio VST CHOP in VST CHOP and switch on VST Active. Reference the CHOP itself, with no Null after it.

Notes are only worked out while a MIDI Out or VST CHOP is set or the outputs are wired, so a copy with nothing attached does no note work.

A few things people adjust once it plays:

  • A busy picture sprays notes: the Trigger Options on the Input page are for this. Trigger Gate Length makes a point stay above the threshold for a moment before its note starts, Re-Trigger Delay stops one note repeating too fast, and Min Sustain Length keeps short notes audible.
  • Velocity by pitch: point Keytrack Lookup at a multi-sample CHOP and it sets how hard each note plays from its pitch.
  • A note hangs: run All Notes Off from quick-launch. It sends a note-off for every note on the MIDI and VST outputs.

Your own scales and playing along

  • Your own scale: pulse Edit Custom Scales. A table opens where each column is one scale, its name on top and its notes below in standard notation, such as C#3. Your scales then show up in the Scale menu.
  • A scale from your keyboard: set Scale to MIDI Scale, name a MIDI In CHOP in MIDI In CHOP, switch on MIDI Scale Learn and play the notes of the scale one by one.
  • Duet with the picture: with MIDI Live on, the scale follows the keys you are holding right now, so the picture plays in whatever chord your hands are on. Live Octave Offset moves it above or below them, and Sync Steps matches the number of steps to the number of keys held (not available while Extend Mode is on).

MIDI learning runs only while a MIDI In CHOP is set.

Installing mingus

Every scale except MIDI Scale is computed with the Python package mingus, which TouchDesigner does not bundle. The tool ships its own pip requirements file (the requirements DAT inside it) and installs it through TouchDesigner's Python Environment Manager. The Setup page's Status says whether mingus is available. When it is missing:

  • With a Python vEnv or Conda environment linked through the Python Environment Manager, pulse Install mingus, or run Install Mingus from quick-launch. The tool writes TopToMidi.requirements.txt beside your .toe and hands it to the environment manager, which installs it into the linked environment in the background; Status reports the result. When the project has an environment context file, the requirements file is also registered in it, so a machine that opens the project with Auto Setup On Startup installs it on its own.
  • With no environment, create one in the Python Environment Manager (palette: tdPyEnvManager), then pulse Install mingus. Python Env Manager Help opens its documentation.
  • If you installed mingus some other way, pulse Re-check.

Nothing blocks TouchDesigner while this happens, and the tool never installs anything until you ask. If Status says mingus is installed but this session cannot see it yet, restart TouchDesigner.

Inputs and outputs

  • in2 (TOP): the image to sample.
  • out_viz (TOP): the sampling points drawn over the input.
  • out_sampled (TOP) and out_sampled_CHOP (CHOP): the sampled values.
  • out_notes (CHOP): the generated notes.

Get it

This tool unlocks with Patreon. It installs through the same picker as everything else and unlocks with the Patreon Base tier or higher, connected from inside TouchDesigner. Everything else in the toolkit stays free and MIT, and the membership is what keeps that work moving.

Join on Patreon → How unlocking works →

Parameters

Input

ControlType / defaultWhat it does
SamplerSampler operatorempty TOP or SOP operator to define the pixel positions for sampling. These can be animated too, of course!
Offset 0.5Origo on / offoff By default many SOPs are centered around the origin. This quick toggle shifts the Sampler’s center to (0.5, 0.5).
Sample PreviewOpen2 button Opens a UI window to visualize and manually adjust the sampling points. Move them around with Left-Click+Dragging ; Scale with Scroll-Wheel (or +-), Reset with Middle-Click. It also has some options on the bottom left to always show the points, toggle Offset 0.5 and Reset the adjustments
Sample ChannelRgb menuLuminance Which attribute of the input image to perform further processing on.
Options: Luminance, Red, Green, Blue, Alpha, RGB Average, RGBA Average, RGB Maximum and 1 more
ThresholdThresh number0 Pre-processes the input image by thresholding between two values. This will also have an effect on when a note is triggered in Index Mapping Mode.
Re-RangeRerange on / offoff Re-ranges the thresholded image to 0-1. This parameter is only interesting in Value Mapping Mode.
Mapping ModeMode menu0 This is the most important parameter to determine the mapping of pixel values to MIDI notes, before assigning to a Scale. Index: The point/pixel indices of the Sampler determine the pitch of the notes, upon triggered by the sampled value reaching the Threshold. Notes are sustained while in the range. It is important to set a good Threshold with Index mode. Important to note that the number of Steps is determined by the number of points. Be careful not to use big textures or SOPs with many points (anyway MIDI is limited to 128 notes). Value: The sampled values determine the pitch of the notes, where the quantization is determined by the Steps parameter. It means if you have identical sampled values they will trigged the same note twice. Re-Range of the Threshold is suggested to be kept on usually. In this mode you are more free to set more sampling points!
Options: Index, Value
Trigger Options
Re-Trigger Gate LengthRetriggergatelen number0.2 Overall gate window in seconds. At 0 every trigger passes straight through. Above 0 the sampled pattern is held for this long after a trigger, so a new trigger (or a release) can happen at most once per window; changes that arrive inside the window are applied when it closes.
Trigger Gate LengthTriggergatelength number0.2 Seconds a sample point has to stay above the threshold before its note turns on. 0 = immediately.
Min Sustain LengthMinsustain number0 Minimum seconds a note stays on once triggered, even if the sample point drops below the threshold sooner.
Re-Trigger DelayRetrigger number0 Minimum seconds between two triggers of the same note. A new trigger inside this time is ignored.

Scale

ControlType / defaultWhat it does
ScaleScale menuMajor Determines the Scale Mode the triggered notes are mapped to. Scales determine a number of notes in a Scale, starting from a root note (Key). You can also define Custom Scales which will also show up in the dropdown! MIDI Scale is a special one, see later.
Options: Major, NaturalMinor, Chromatic, WholeTone, HarmonicMajor, HarmonicMinor, MelodicMinor, Bachian and 11 more
KeyRootnote menu, editableempty Sets the musical root note of the Scale. Can type any musical note notation, even wild things like A#bbb## (thanks to the mingus library). But usually the drop-down list should be more reasonable :)
Options: C, C#, D, D#, E, F, F#, G and 4 more
OctaveOctave number4 The octave of the root note.
StepsSteps number1 Number of MIDI notes to generate. In Index mode it is fixed to the number of sampling points. In Value mode it is the "quantization" of the pitch determined by the sampled pixel values.
Extend ModeExtendmode on / offoff When having more steps than the number of notes in the Scale, having this on will extend subsequent steps to the next octaves. Otherwise the same scale notes in the starting octave are repeated.
Edit Custom ScalesOpen button Opens a Table DAT where in each column you can define a custom scale name where each note can be defined in the rows below using standard musical notation. For example: C#3.
Keytrack LookupVelocitylookup operatorempty A multi-sample CHOP reference which can define the MIDI velocity based on the pitch.
MIDI Scale
MIDI In CHOPMidiref operatorempty Optional MIDI In CHOP (a MIDI keyboard) for MIDI Scale learn and live mode. Empty by default; name a sibling MIDI In CHOP, e.g. midiin1.
MIDI Scale LearnMidilearn on / offoff Can define a Custom Scale by hitting notes one-by-one on your MIDI In instrument.
MIDI LiveMidilive on / offoff Follows the keys currently held on the MIDI In CHOP as the scale, in real time (MIDI Scale only), instead of the learned one.
Live Octave OffsetLiveoctaveoffset number0 Octaves added to the notes taken live from the MIDI In CHOP while MIDI Live is on, so the tool can play along above (or below) the keys you hold.
Sync StepsSyncsteps on / offoff Syncs the number of steps to the number of incoming notes. This is not available when Extend Mode is on.
RandomizeRandomize on / offoff Randomize the order of notes.
SeedSeed number0 Seed of the randomization.

Output

ControlType / defaultWhat it does
MIDI ActiveActive on / offon Activates MIDI Out CHOP.
MIDI Out CHOPMidioutchop operatorempty MIDI Out CHOP to send notes to, referenced directly (no Null after it). Empty by default: drop a MIDI Out CHOP beside this tool and name it here, e.g. midiout1 for a sibling.
ChannelCh number0 MIDI channel to output notes on.
VST ActiveVstactive on / offoff Activates VST CHOP.
VST CHOPVstchop operatorempty Optional Audio VST CHOP to play notes on, referenced directly (no Null after it). Empty by default; name a sibling Audio VST CHOP, e.g. audiovst1.
ChannelVstchannel number1 VST channel to output notes on.

Setup

ControlType / defaultWhat it does
StatusStatusread-only textempty Read-only. Whether the Python package mingus (needed for every scale except MIDI Scale) is available, and what to do if it is not.
Install mingusInstall button Installs mingus into the Python environment linked by TouchDesigner's Python Environment Manager, in the background. Needs a linked Python vEnv; the Status line says when one is missing.
Re-checkRecheck button Looks for mingus again, e.g. after installing it by hand from the Python Environment Manager CLI.
Python Env Manager HelpEnvhelp button Opens the documentation of TouchDesigner's Python Environment Manager (tdPyEnvManager).

About

ControlType / defaultWhat it does
HelpTestopenhelp button Opens documentation.