SwarmErhu: the Max patch
========================

This folder goes with the paper "SwarmErhu: From Oscillator Swarm to
Heterophonic Ensemble". The paper explains the instrument. This note says
what is in the folder, how to open the patch and how to try it without the
instrument. Numbers in square brackets are sections of the paper; [Table 1]
is the table of the players in Section 5.2.


What is here
------------

SwarmErhu_paper.pdf       the paper
SwarmErhu_Max_patch/      the instrument's Max patch and the files it loads
    swarmcore.maxpat      the patch (open this one)

The other files in SwarmErhu_Max_patch are listed at the end.


Opening the patch
-----------------

- Made with Max 9.0.3 on macOS.
- Keep the files of SwarmErhu_Max_patch together in their folder and open
  swarmcore.maxpat. Open only one copy at a time.
- The instrument itself is not needed. Without the Arduino, the Leap Motion
  and the Car Thing, the patch opens and can be played with the mouse.
- One object, [ultraleap] inside the mapping window's subpatch
  [p sensors], reads the Leap Motion and belongs to the Ultraleap package
  for Max. Without that package Max reports this one object as missing.
  Nothing else depends on it.
- The patch opens with the reverb off: the sound is dry and needs no
  plug-in. The reverb is a third-party VST3 plug-in. Ticking "On" beside
  the "REVERB plug-in" menu in the OUTPUT zone loads the plug-in the menu
  shows (FabFilter Pro-R, the one used on the instrument) and sends the
  sound through it. If that plug-in is not installed, choose another from
  the menu ("Browse..." opens a file dialog for a plug-in), or untick
  "On" again. "Plug-in" opens the plug-in's own window once one is
  loaded.
- The panel is about 1330 by 870 points. On a small screen, zoom out in
  Max's View menu.


Trying it without the instrument
--------------------------------

1. Open swarmcore.maxpat. It opens as the playing panel, with preset
   1 (Strings).
2. Turn the audio on: the speaker button in the SYSTEM zone, top right.
3. Press and drag on the long ribbon in the RIBBON zone (the wide strip
   marked "pitch"; low notes are on the left). The "Touch" toggle holds a
   note. The short strip below sets how far the swarm spreads [5.1].
4. The PRESETS menu recalls the other sounds.
5. Heterophony [5.2, 5.3]: choose preset 7 ("heterophony"), which switches
   heterophony on with the players' dials set. (The "On" toggle in the
   HETEROPHONY zone switches it on in any preset, but the other presets
   leave those dials at zero, so the players sound alike.) All eight
   voices play from the start. To build the ensemble up one player at a
   time, as Section 5.3 describes, open the mapping window ("Control
   panel" in the SYSTEM zone) and tick "On" beside "Layers
   (heterophony):". The ensemble then starts from the lead alone. The
   "FSR press" slider of the RIBBON zone stands in for the pressure
   sensor: drag it fully to the right and back to add the next player;
   leave it at the right for two seconds to take the newest player away.
   The window saves this setting; untick it to hear all eight again.
   With the layers on or off, the same slider also raises the filter's
   resonance and drive while it is up, as on the instrument.
6. Harmony and the chord walk [5.4]: with heterophony off, set the switch
   in the SWARM zone to "Harmony", its last position. The long ribbon then
   walks through the chords on the chord lane above it. Eight chords are
   stored. Double-click an empty part of the lane to add a chord, click a
   chord to select it and drag it to move it; the CHORD zone edits the
   selected chord, and "Delete" removes it.
7. Beat [5.5]: set the switch in the SWARM zone back to "Swarm", then
   choose Pulse, Poly or Phase in the BEAT zone and hold a note.
8. Projection [4.6]: "Projection" in the SYSTEM zone opens a window that
   draws each of the eight voices as a column of light while a note
   sounds; "Fullscreen" fills the screen with it, and the Esc key leaves
   the full screen. In section 10 of the edit view (see below), the
   message boxes "look 0" and "look 1", the five "palette" boxes and the
   three "edge" boxes change its look; click one to try it.

Option-Command-E (Ctrl+Alt+E on Windows) switches between the panel and
the edit view. The edit view is laid out in ten numbered sections. The
code of the sound engine is inside the [gen~] of section 4; double-click
it to read it.


The panel, zone by zone
-----------------------

PRESETS            recall the seven presets; "Store" and "writeagain" save
                   them [4.4, 6.1]
SYSTEM             audio on and off; the projection [4.6]; "Control panel"
                   opens the mapping window [4.5]; whether the Car Thing
                   is connected [4.4]
PITCH              lowest note and range of the ribbon, linear or erhu
                   layout [4.2]; pitch from a MIDI keyboard
OSCILLATORS        waveform, detune and drift of the eight voices
                   [4.5, 5.1]
FILTER             cutoff (F), resonance (Q), envelope amount (N), drive
                   (D) and key tracking (T); the filter type [4.5]
ENVELOPE (s)       attack, decay, sustain and release, and what starts a
                   note
OUTPUT             volume and mute; the reverb plug-in and the limiter
                   [4.5]
SWARM              the switch between swarm, the four fixed intervals and
                   harmony; the spread of the swarm [5.1, 5.4]
BEAT               pattern, rate and sync [5.5]
HETEROPHONY        the switch, the octave lineup, the scale and tonic of
                   the ornaments, the high and low limits, and the dials
                   that act on all seven players together [5.2, 5.3]
RIBBON             the chord lane, the long ribbon and its "Touch"
                   toggle, the swarm strip and the pressure slider
                   [4.2, 5.1, 5.3, 5.4]
CHORD              root, octave and type of the selected chord, and
                   "Delete"; just or equal tuning of all chords [5.4]
DISPLAY            spectrum, waveform, envelope and a table of the eight
                   voices
FREQUENCY AXIS     where the eight voices lie between 20 Hz and 20 kHz
MIXER              level, solo and mute for each voice [4.4, 5.3]
SENSORS (Arduino)  the serial connection to the Arduino and its
                   calibration [4.1, 4.2]; not used without the instrument

The mapping window ("Control panel" in the SYSTEM zone) has a row for each
sensor reading (the ribbon, the pressure sensor, the two knobs and seven
readings of the right hand) and two extra rows. Every row but the ribbon's
has a menu for what it controls and its low and high values [4.5]. The two
lines at its top say whether the Leap Motion and the Arduino are sending
data. Its lower part holds the settings for building the ensemble [5.3].


Names that differ from the paper
--------------------------------

In the patch            In the paper
"Control panel"         the mapping window [4.5]
"Car Thing"             the control panel [4.4]
"Freedom"               individuality [5.2]
"Slide"                 glide [5.2]
"Grace"                 ornament amount [Table 1]
"FSR press"             the pressure sensor [4.1]
"Layers (heterophony)"  layering [5.3]
"Poly"                  polyrhythm [5.5]

Harmony has no button of its own on this panel: it is the last position of
the switch in the SWARM zone. On the Car Thing it has its own button.


The files in SwarmErhu_Max_patch
--------------------------------

swarmcore.maxpat          the patch
ribbon.js                 the two on-screen ribbons
chords.js                 the chord lane and the voicing of the chord
                          walk [5.4]
voices.js                 the displays of the eight voices
swarmcore_io.js           readings from the Arduino; MIDI notes (its
                          recording functions are not used here)
sensor_map.js             the mapping window: what each sensor controls,
                          and building the ensemble [4.5, 5.3]
sensor_view.js            the displays of the mapping window
rh_lab.js                 readings of the right hand from the Leap Motion
                          [4.3]
carthing.js               the link to the Car Thing [4.4]
projection.js             the projection [4.6]
projection.jxs            the shader of the projection
swarmcore_presets.json    the seven presets
swarmcore_sensors.json    the sensor assignments described in Sections
                          4.2 to 4.4 and the settings for building the
                          ensemble [5.3]
swarmcore_chords.json     the chords on the chord lane
swarmcore_carthing.json   which presets the Car Thing's keys recall

The patch rewrites swarmcore_sensors.json and swarmcore_chords.json when
their settings are changed in it, and swarmcore_presets.json when
"writeagain" is clicked.

Not in this folder: the Arduino firmware, the software of the Car Thing,
and the development files (the tests with the reference model of
Section 4.5 and the build scripts). The patch does not need them.
