Tag Archives: Max/MSP

The Art of the Cron Job

Sound art installations that require digital computing, especially projects that rely on advanced software, demand added insurance of stability in order to remain up in an unattended space for extended periods of time. For exhibitions, this time period can mean a month or more with hours that vary from business hours to a taxing 24-7. One added insurance for artists relying on computers (e.g., Mac Minis) for unattended digital works is the cron job.

A cron is “a time-based job scheduler” that runs periodically (time intervals) to help “maintain software environments” (footnote 1). A software utility for Unix (read Mac), the cron automates processes and tasks, allowing the computer to be used as your personal docent to check on installation software, updating variables as part of the work or fixing issues as they crop up.

I got into cron jobs in 2014 while I was working with John Park on #Carbonfeed (URL), a multimedia installation that leverages Twitter API to transform real-time tweets into physical bubbles in tubes of water as well as a musical composition driven by behavior on Twitter (Figure 1). The piece incorporates a custom node.js script running on a Mac mini. To anticipate power failures, and to even alter hashtag sets on the LCD screens (Figure 2), I needed a way to automate software processes and failsafes. Enter the cron job.

#Carbonfeed (photo by Janelle Rodriguez)
Figure 1. #Carbonfeed (photo by Janelle Rodriguez http://janelleshootsphotos.com)
#Carbonfeed hashtags (photo by Janelle Rodriguez http://janelleshootsphotos.com)
Figure 2. #Carbonfeed hashtags (photo by Janelle Rodriguez http://janelleshootsphotos.com)

In #Carbonfeed, I used the cron to check if the software had crashed and automatically reboot, and every 8 minutes, I altered Twitter hashtag sets on the LCDs, in order to change the dynamic of the work and create new opportunities for discourse. For a how-to on the cron and cron specifics,  please jump to the bottom of this article.

Since #Carbonfeed, whenever I found myself working on a sound installation that required advanced software (e.g., Processing, Max/MSP, Logic Pro X), I inevitably involved a cron. For example, in 2017, I worked with Harmonic Laboratory (URL) on a Mozilla Gigabit Foundation Grant (URL) project called City Synth, which turned the city of Eugene, OR into a musical instrument. The piece involved taking live video feeds from Raspberry Pis (a collaboration completed by the South Eugene Robotics Team, URL) that was mangled by a Processing sketch and subsequently controlled a live synthesizer running in Logic Pro X. The work was up for a month in the Broadway Commerce Center in downtown Eugene, OR.

City Synth signal flow diagram
Figure 3. City Synth signal flow diagram

 

In 2019, my first solo exhibition at the Edith Barrett Gallery in Utica, NY (curated by Megan C. Austin and Sarisha Hogan and supported by funds from the Oregon Arts Commission) had six sound artworks running for three months. Since I was able to borrow Mac minis for the exhibition, I incorporated cron jobs and scripts to transform Mac minis into glorified audio players for two of the works. Sound Memorial for the Veteran of the Vietnam War (URL), ran an Automator script upon startup that opened iTunes and played a playlist holding the six-hour-long work (Figure 4). I mixed the 8-channel work down to a stereo headphone mix in order to account for the bleed of other works inside the space. Relay of Memory (URL) used the same script to output computer audio to an FM transmitter, which played the work through nine radios hung on a wall (Figure 5). Cron jobs checked the status of running software.

Figure 4. Sound Memorial for Veterans of the Vietnam War (photo by Janelle Rodriguez, http://janelleshootsphotos.com)
Figure 5. Relay of Memory (photo by Janelle Rodriguez, http://janelleshootsphotos.com)

The cron utility has been an amazing tool for my sound installation work. I can still recall driving home after installing Aqua•litative (URL) when I received a frantic call from the curator that there was a power outage. In the middle of the call, the power came back on, the computer turned on (setting to automatically start after power failure), and a minute later, the cron kicked in opening up all software. I didn’t need to turn around and drive back or walk the curator through how to turn on computer software. A happy moment.

I have saved countless hours that I know about, and I’m sure many other hours I won’t ever know about thanks to the cron. I even have started to implement the cron in other ways to help with basic tasks in my daily life (see below for code specifics) such that the cron has helped me get closer to what Allan Kaprow describes as the “fluid” and “indistinct” “line between art and life.” Maybe the overseer of digital automatons is what a 21st-century computing artist feels like (footnote 2).

CRON

This is a walkthrough of the crontab on Mac OS using Terminal. I’ve included some code specifics by theme below. If you use, please share your work with me and how you implemented your cron! If you like what you’ve read, sign up for my mailing list (URL), follow my music on Spotify (URL), and please share it with friends.

Setting up a cron

Googling helped me in every way possible for working with crontab, but there are three basic steps. Open up an editor via Terminal, add your cron code (requires setting a time of how often it’ll run), and then saving the file. For more on Terminal, here’s a beginner’s walkthrough, Apple’s user guide, and a command cheat sheet.

1. Open up an editor to add a cron via Terminal

 env EDITOR=nano crontab -e

2. Inside the editor add the executable file to the cron job

 *	*	*	*	*	~/Music/citysynth/cronjobs/citysynth_cron.sh

The asterisks tell how often to run the cron: Minute, Hour, Day of Month, Month, Day of Week. Straight asterisks mean “every” so this is a call to run the cron EVERY minute. The cron after the timer is a call to run a bash script called “citysynth_cron.sh”. The below cron runs every 5 minutes and closes the bash window in Terminal.

*/5	*	*	*	*	osascript -e 'tell application "Terminal" to close (every window whose name contains "bash")';

3. Save and exit the cron.

Ctrl-O, saves the file. Ctrl-X exits the file. You must save the temporary file after editing. When you are done with the cron and want to remove the cron job, follow step 1 to open, but then delete the lines (using Ctrl-K) and save the file. For reference, see
http://www.maclife.com/article/columns/terminal_101_creating_cron_jobs

4. Want to know if you have a cron on your machine? List your crons in Terminal with

crontab -l

Adding a bash script.

If you decide to run a bash script via a cron, you’ll need to make the .sh file executable, that is, give the cron the ability to run the script. In Terminal, navigate to the folder where the .sh file lives and change its permissions with

chmod +x bashfile_name

where “bashfile_name” is the name of the .sh script (make sure to include .sh in the filename).

Below is an example of a .sh script that checks to see if an app is running and if not, reopens the app. I included the initial bash line of the file in the code.

#!/usr/bin/env bash

echo "cron job";

PROCESS=api_hashtags-polyphonic
number=$(ps aux | grep $PROCESS | grep -v grep | wc -l)

if [ $number -gt 0 ]
    then
        echo Running;
else 
	echo "sound is Dead";
	# open music player application
	cd ~/Music/carbonfeed/work/sound/; 
	sleep 2;
	open api_hashtags-polyphonic.app; 
fi

Doing it all in one line of code

For recent projects, I opted to run code directly via the cron instead of relying on bash and AppleScripts. Below is code to start the Chrome web browser at a random time (to the second!) between 855-9p.

55 20 * * * perl -le 'sleep rand 300' && open -a 'Google Chrome'

Remember, the timing of the cron comes first:: Minute, Hour, Day of Month, Month, Day of Week. The cron is fired at 8:55pm, but has a random sleep time (between 0-300 seconds, read between your 8:55–9:00) and THEN opens the web browser.

Adding in an Apple Script

You can use your cron to trigger an Apple Script (.scpt file), just another way to execute commands on your Mac. Here’s an example of telling Safari to hit the spacebar (or could even be iTunes).

tell application "Safari"
	activate
end tell
delay 2
tell application "System Events"
	key code 49 -- space bar
end tell

Automator scripts (triggered by cron or system startup)

If cron and bash aren’t your thing, Apple has the Automator app that allows you to create automated processes straight from a GUI and then save out as an application (Figure 6).  You can also easily trigger the app via a cron or by system startup by going to System Prefs > Users > Login Items. Login items can be set to run Automator scripts upon computer startup, and configuring the computer to power up automatically after power failure will help ensure a work stays running.

Figure 6. Automator Script to open iTunes and play a playlist on repeat.

Hope this was helpful. Please get in touch if you have questions or want to share your work with cron in art.

Footnotes
1. Wikipidea, “Cron”. URL: https://en.wikipedia.org/wiki/Cron accessed August 27, 2020.

2.  Allan Kaprow. Essays on the Blurring Between Art and Life. University of California Press, Los Angeles. 1993. URL

Mixer.* Audio Max/MSP Package

Mixer.* is a Max/MSP package for audio mapping projects. The package contains basic audio mixer objects, like channel strips, eqs, limiters, and aux sends. Mixer.* provides GUI, modular design, and pattr binding for smooth integration into your Max/MSP workflow.

To get started with Mixer.*, place the mixer folder inside your Max > packages directory. Then restart Max. Inside a Max window, simply create a new object, start typing “mixer” and let autocomplete help you do the rest. You may also type shift-M to quickly access any mixer. object as a helpful bpatcher.

Download the Mixer.* Max package.
I also made this package a repository on github.

Max/MSP Package: Korg Nano

Ever since Cycling 74 introduced the idea of packages in Max 6.1, I’ve been pretty excited. Previously, there wasn’t a great way to distribute and install tools, objects, externals, media. And if you wanted to use anyone else’s tools, you had to wade through the murky collection of application directories and dump in single files–an unfailing way to ensure that you’d have to re-install these tools after a Max/MSP update.

With packages, Cycling 74 got rid of the mess. Tool creation, installation, and for me, distribution is clear and simple. Even if I’m developing my own set of abstractions for nobody’s computer but my own, packages provide a platform for a confident working-practice with long-term benefits. This post is meant to outline the pros of Max packages by walking through a working example of how one can set up her/his own Max package.

While I have created several Max packages since 2014, the post will outline my latest Max package, Korg Nano.  It’s a basic example, two objects that comprise a software implementation of the Korg nanoKontrol USB controller, certainly enough to get one started.

Installation
After downloading the Korg Nano package, unzip the file and place the unzipped folder directly into the ‘packages’ directory.  For Mac users, the folder is Applications > Max 6.1 > packages.  Or, you can read a short article by Cycling 74 on packages for installation.

What It Is
In short, packages provide global access. Autocompletion, media in global search paths, extras in the top Extras dropdown menu, option clicking helpfiles, it’s all there. What the Korg Nano package provides is a software listener for the 151 controls on the Korg nanoKontrol USB controller. The package is meant to be a plug ‘n play solution for this hardware device (and I use it for prototyping all the time).

After installation of Korg Nano in the Max packages directory (make sure you restart Max), navigate to the folder.  You will see four folders inside (docs, help, media, patchers) and a README file. Each folder has a unique purpose, and there are many more one can add (extras, javascript, clippings, templates, etc). If you’re curious, there is an “about packages.txt” file in the packages directory that outlines the finer points of Max packages. For now, we’ll unpack these four folders (docs, help, media, patchers).

Max/MSP Autocomplete feature for Korg Nano package.
Max/MSP Autocomplete feature for Korg Nano package.

The patchers folder is where you throw your abstractions and objects (not externals), including any additional bpatchers that you may have used to create your objects. Of course, if your package depends upon third-party objects, you can place them here (and within any named subfolder). For Korg Nano, there are two main objects, korgnano and korgnano.inputmenu.  korgnano is built from several bpatchers, which one will see listed in a subfolder (“patchers > korg_nanoKontrol”).

The media folder allows one to place images, audio, and video. This folder becomes global (after restarting Max), so you can also use packages as a way to manage media instead of worrying about “filepath” when you move from computer to computer. Since Korg Nano is a software implementation of the USB hardware controller, I used image buttons that simulate the look and feel of the hardware controller. Placing images in the media folder ensures they will be found, regardless of what computer I am using.

The help folder is exactly what one would expect. Help files ending with the extension .maxhelp.  While help files are useful (e.g. option-click an object to access its help file), Max packages allows one to provide some serious help to the help files. This helpful power boost comes by way of the docs folder.

Korg Nano help file that looks like a standard Max help file.
Korg Nano help file that looks like a standard Max help file.

The docs folder contains reference files that enable hover tooltips, documentation window text, uniform descriptions, and fancy descriptive break downs and object links from within the reference window. To understand what is happening in the help file screenshot above, let’s dig into the docs folder.  Navigate to the “korgnano-0.0.1 > docs > refpages > korgnano > korgnano.inputmenu.maxref.xml” file.  This xml file contains all the descriptions that get pulled for the help file. While this file contains confusing html/xml style tags, one need only look to two examples to see their power.

The first example comes from the first two xml tags <digest> and <description>.  These two description tags show up in the Autocomplete menu, the documentation window, the reference window (outside any help file), and the help file’s title object (actually, a jsui object that uses an application Max script “helpdetails.js” to parse these xml tags and display them for clean documentation).

The second example of documentation power comes from the <seealsolist> tag near the bottom of the .xml file.  One only needs to place additional object names here (e.g. “<seealso name=’korgnano’/>”) and links automatically appear in the reference documentation window, linking to your objects’ help files. This is handy here, as I want to link the korgnano object and the korgnano.inputmenu object together since these objects are symbiotic. The korgnano object grabs data from your Korg hardware controller and then sends the controller data direct to korgnano.inputmenu objects.

Docs, Help, Media, Patchers. That’s it.  A Max package that enables software listening for the Korg nanoKontrol, neatly bundled for distribution. Clear documentation files to help anyone navigate the tools, even me! when I revisit my tool a few months down the line. However, I do not need to distribute to reap the benefits.  Clippings, templates, patchers, or even externals that I use often in my own work have a place within a Max package, easily searchable and documented so I have a working practice that is efficient and scalable. For anyone working in Max, packages offer a clean way to keep your sh** together.

Korgnano object help file
Korgnano object help file

 

Reference
Korg Nano Max package

Notes
Packages also work with Max 7. While my example was built using Max 6.1, there is no reason why it shouldn’t work in Max 7. Email me if you have issues.

Speaking of issues… if you’re having trouble with autocomplete, try creating a message object in a Max window with the text “; max db.reset”.  This will refresh Max’s preferences, but may take 60 seconds+ to reload. Here’s the original forum post where I found this fix.

Great Speeches

Great Speeches is a computer music composition for any laptop ensemble (10+ performers). The work may be used with any bank of audio samples, but these samples should be generated from a famous/great speech. The work was intended to be used with speech material from famous speeches and to be performed on the anniversary of the greet speech or commemorative occasion of that individual or event. 

Great Speeches is based upon pseudo-random number recall. The many witnesses of a famous speech have various perspectives and vantage points of that event. The work attempts to magnetize these seemingly random perspectives into a new viewpoint through which we can hear. New words, ideas, and rhythms are generated through the synthesis of multiplicity. 

The recording documents a Oct. 30, 2013 performance of the UVa MICE ensemble with 100 players using only their laptops and laptop speakers.

Sound Pong

Sound Pong is a real-time performance composition written in Kyma and Max/MSP for an electronic ensemble. The eight channel piece was co-written by Jon Bellona and Jeremy Schropp for OEDO (Oregon Electronic Device Orchestra). The video is a recording of Feb. 27th, 2011 premiere. Performers: Jeremy Schropp, Jon Bellona, Nathan Asman, and Simon Hutchinson.

Download the Sound Pong source patches (Max, Kyma, and OSCulator). The zip file includes the audio files. @76 MB

Download the Open Source Wii interface (see alsoprojects#wiimote)@200 KB

Download the white paper documentation. @1.1 MB

Download the Sound Pong audio files. @72.3 MB

Running Expressions

Running Expressions is a real-time performance composition using bio-feedback and remote controllers. Written primarily in Kyma and Max/MSP, the piece captures live physiological data to create and control music within an 8-channel and video projection environment. The musical performance narrates a distance run, the psychological and emotional impacts of a running experience.

+ Download Documentation .pdf and the performance software (Max/MSP/Jitter, OSCulator, and Processing) files. (.zip, 11.5 MB)

+ Download Kyma performance audio files. (.zip, 45.3 MB)

+ Download Thesis documentation separately. (.pdf, 11.2 MB)

Kinect-Via- Interface Series

Kinect-Via- is a Max/MSP interface series for composers wanting to route and map user-tracking data from the XBox Kinect. The interface series complements four different OpenNI applications, namely OSCeleton, Synapse, Processing’s simple-openni library, and Delicode’s NIMate. All Max/MSP interfaces communicate using OSC (Open Sound Control) messages and are performance-ready, meaning that all routing and system options may be changed in real time. The Kinect-Via- interfaces offer a tangible solution for anyone wishing to explore user tracking with the Kinect for creative application. The interface currently has over 1000 downloads globally. Note: Tested with Max 5 and OSX 10.6.8.

White paper (.pdf)

Kinect-Via-OSCeleton. (.zip)
OSCeleton application

Kinect-Via-Synapse. (.zip)
Synapse application

Kinect-Via-Processing. (.zip)
Processing library

Kinect-Via-NIMate. (.zip)
NImate application

Projects utilizing Kinect-Via-

Human Chimes. Human Chimes is an interactive public installation. Participating users become triggered sounds that interact with all other participating users inside the space. The Kinect mapping is using Kinect-Via-OSCeleton.

The Beat. The Kinect user’s hand and head movements mapped to filters, and at times, hand gestures actuate sound. The Kinect mapping is using Kinect-Via-Synapse. “The Beat” is a composition by Nathan Asman.

Juggling Music (Arthur Wagenaar). Playing music by juggling with glowballs! Demonstration of this new self made musical instrument, controlled by juggling. Also known (in Dutch) as ‘De Kleurwerper’.

The Goddess Re:Membered

Commissioned for the 2011 Fringe Festival, The Goddess Re:membered is a site specific work and multimedia response to The Goddess, a classic Chinese silent film from 1934. The interactive installation is for video projection, IR camera, Max/MSP and Isadora software. Through public interactions of users inside the space, clues to distant memories are revealed through the triggering of color, sound, and video masks.