Processing

From Bauman National Library
This page was last modified on 8 June 2016, at 19:34.
Processing
Processing logo
Paradigm object-oriented
Designed by Casey Reas, Benjamin Fry
Stable release 3.0.2 / February 13, 2016; 6 years ago (2016-02-13)
Preview release 3.0 beta 7 / September 22, 2015; 7 years ago (2015-09-22)
Typing discipline strong
OS Cross-platform
License GPL, LGPL
Filename extensions .pd
Website processing.org
Influenced by
Design By Numbers, Java, Logo, OpenGL, PostScript, C

Processing relates software concepts to principles of visual form, motion, and interaction. It integrates a programming language, development environment, and teaching methodology into a unified system. Processing was created to teach fundamentals of computer programming within a visual context, to serve as a software sketchbook, and to be used as a production tool for specific contexts. Students, artists, design professionals, and researchers use it for learning, prototyping, and production. The Processing language is a text programming language specifically designed to generate and modify images. Processing strives to achieve a balance between clarity and advanced features. Beginners can write their own programs after only a few minutes of instruction, but more advanced users can employ and write libraries with additional functions. Many computer graphics and interaction techniques can be discussed, including vector/raster drawing, image processing, color models, mouse and keyboard events, network communication, and object-oriented programming. Libraries easily extend Processing’s ability to generate sound, send/receive data in diverse formats, and to import/export 2D and 3D file formats.

Software

A group of beliefs about the software medium combine to set the conceptual foundation for Processing and inform decisions related to designing the software and environment. Software is a unique medium with unique qualities Concepts and emotions that are not possible to express in other media may be expressed in this medium. Software requires its own terminology and discourse and should not be evaluated in relation to prior media such as film, photography, and painting. History shows that technologies such as oil paint, cameras, and film have changed artistic practice and discourse, and while we do not claim that new technologies improve art, we do feel they enable different forms of communication and expression. Software holds a unique position among artistic media because of its ability to produce dynamic form, process gestures, define behavior, simulate natural systems, and integrate various media including sound, image, and text. Every programming language is a distinct material As with any medium, different materials are appropriate for different tasks. When designing a chair, a designer decides to use steel, wood or other materials based on the intended use and on personal ideas and tastes. This scenario transfers to writing software. The abstract animator and programmer Larry Cuba describes his experience this way: “Each of my films has been made on a different system using a different programming language. A programming language gives you the power to express some ideas, while limiting your abilities to express others. There are many programming languages available to choose from, and some are more appropriate than others depending on the project goals. The Processing language utilizes a common computer programming syntax that makes it easy for people to extend the knowledge gained through its use to many diverse programming languages. Sketching is necessary for the development of ideas It is necessary to sketch in a medium related to the final medium so the sketch can approximate the outcome. Painters may construct elaborate drawings and sketches before executing the final work. Architects traditionally work first in cardboard and wood to better understand their forms in space. Musicians often work with a piano before scoring a more complex composition. To sketch electronic media, it’s important to work with electronic materials. Just as each programming language is a distinct material, some are better for sketching than others, and artists working in software need environments for working through their ideas before writing final code. Processing is built to act as a software sketchbook, making it easy to explore and refine many different ideas within a short period of time. Programming is not just for engineers Many people think programming is only for people who are good at math and other technical disciplines. One reason programming remains within the domain of this type of personality is that the technically minded people usually create programming languages. It is possible to create different kinds of programming languages and environments that engage people with visual and spatial minds. Alternative languages such as Processing expand the programming space to people who think differently. An early alternative language was Logo, designed in the late 1960s by Seymour Papert as a language concept for children. Logo made it possible for children to program many different media, including a robotic turtle and graphic images on screen. A more contemporary example is the Max programming environment developed by Miller Puckette in the 1980s. Max is different from typical languages; its programs are created by connecting boxes that represent the program code, rather than lines of text. It has generated enthusiasm from thousands of musicians and visual artists who use it as a base for creating audio and visual software. The same way graphical user interfaces opened up computing for millions of people, alternative programming environments will continue to enable new generations of artists and designers to work directly with software. We hope Processing will encourage many artists and designers to tackle software and that it will stimulate interest in other programming environments built for the arts.

Code Examples

Synthesizer

Sound is generated in real time by summing together harmonically related sine tones. Overall pitch and harmonic detuning is controlled by the mouse. Based on the Spooky Stream Save Ess example

import krister.Ess.*;
int numSines = 5; // Number of oscillators to use
AudioStream myStream; // Audio stream to write into
SineWave[] myWave; // Array of sines
FadeOut myFadeOut; // Amplitude ramp function
FadeIn myFadeIn; // Amplitude ramp function
void setup() {
 size(256, 200);
 Ess.start(this); // Start Ess
 myStream = new AudioStream(); // Create a new AudioStream
 myStream.smoothPan = true;
 myWave = new SineWave[numSines]; // Initialize the oscillators
 for (int i = 0; i < myWave.length; i++) {
 float sinVolume = (1.0 / myWave.length) / (i + 1);
 myWave[i] = new SineWave(0, sinVolume);
 }
 myFadeOut = new FadeOut(); // Create amplitude ramp
 myFadeIn = new FadeIn(); // Create amplitude ramp
 myStream.start(); // Start audio
}
void draw() {
 noStroke();
fill(0, 20);
 rect(0, 0, width, height); // Draw the background
 float offset = millis() - myStream.bufferStartTime;
 int interp = int((offset / myStream.duration) * myStream.size);
 stroke(255);
 for (int i = 0; i < width; i++) {
 float y1 = mouseY;
 float y2 = y1;
 if (i+interp+1 < myStream.buffer2.length) {
 y1 -= myStream.buffer2[i+interp] * height/2;
 y2 -= myStream.buffer2[i+interp+1] * height/2;
 }
 line(i, y1, i+1, y2); // Draw the waves
 }
}
void audioStreamWrite(AudioStream s) {
// Figure out frequencies and detune amounts from the mouse
 // using exponential scaling to approximate pitch perception
 float yoffset = (height-mouseY) / float(height);
 float frequency = pow(1000, yoffset)+150;
 float detune = float(mouseX)/width-0.5;
 myWave[0].generate(myStream); // Generate first sine, replace Stream
 myWave[0].phase += myStream.size; // Increment the phase
 myWave[0].phase %= myStream.sampleRate;
 for (int i = 1; i < myWave.length; i++) { // Add remaining sines into the Stream
 myWave[i].generate(myStream, Ess.ADD);
 myWave[i].phase = myWave[0].phase;
 }
 myFadeOut.filter(myStream); // Fade down the audio
 for (int i = 0; i < myWave.length; i++) { // Set the frequencies
 myWave[i].frequency = round(frequency * (i+1 + i*detune));
 myWave[i].phase = 0;
 }
 myFadeIn.filter(myStream); // Fade up the audio
}

Sample playback

Loads a sound file off disk and plays it in multiple voices at multiple sampling increments (demonstrating voice allocation), panning it back and forth between the speakers. Based on Ping Pong by Krister Olsson <http://tree-axis.com>

import krister.Ess.*;
AudioChannel[] mySound = new AudioChannel[6]; // Six channels of audio playback
Envelope myEnvelope; // Create Envelope
boolean left = true;
boolean middle = false;
boolean right = false;
// Sampling rates to choose from
int[] rates = { 44100, 22050, 29433, 49500, 11025, 37083 };
void setup() {
 size(256,200);
 stroke(255);
 Ess.start(this); // Start Ess
 // Load sounds and set initial panning
 // Sounds must be located in the sketch's "data" folder
 for (int i = 0; i < 6; i++) {
 mySound[i] = new AudioChannel("cela3.aif");
 mySound[i].smoothPan=true;
 mySound[i].pan(Ess.LEFT);
 mySound[i].panTo(1,4000);
 }
 EPoint[] myEnv = new EPoint[3]; // Three-step breakpoint function
 myEnv[0] = new EPoint(0, 0); // Start at 0
 myEnv[1] = new EPoint(0.25, 1); // Attack
 myEnv[2] = new EPoint(2, 0); // Release
 myEnvelope = new Envelope(myEnv); // Bind an Envelope to the breakpoint function
}
void draw() {
 int playSound = 0; // How many sounds do we play on this frame?
 int which = -1; // If so, on which voice?
 noStroke();
 fill(0, 15);
 rect(0, 0, width, height); // Fade background
 stroke(102);
 line(width/2, 0, width/2, height); // Center line
 float interp = lerp(0, width, (mySound[0].pan+1) / 2.0 );
 stroke(255);
 line(interp, 0, interp, height); // Moving line
 // Trigger 1-3 samples when the line passes the center line or hits an edge
 if ((mySound[0].pan < 0) &amp;&amp; (middle == true)) {
 playSound = int(random(1,3));
 middle = false;
 } else if ((mySound[0].pan > 0) &amp;&amp; (middle == false)) {
 playSound = int(random(1,3));
 middle = true;
 } else if ((mySound[0].pan < -0.9) &amp;&amp; (left == true)) {
 playSound = int(random(1,3));
 left = false;
 } else if ((mySound[0].pan > -0.9) &amp;&amp; (left == false)) {
 left = true;
 } else if ((mySound[0].pan > 0.9) &amp;&amp; (right == true)) {
 playSound = int(random(1,3));
 right = false;
 } else if ((mySound[0].pan < 0.9) &amp;&amp; (right == false)) {
 right = true;
 }
// Voice allocation block, figure out which AudioChannels are free
 while (playSound > 0) {
 for (int i = 0; i < mySound.length; i++) {
 if (mySound[i].state == Ess.STOPPED) {
 which = i; // Find a free voice
 }
 }
 // If a voice is available and selected, play it
 if (which != -1) {
 mySound[which].sampleRate(rates[int(random(0,6))], false);
 mySound[which].play();
 myEnvelope.filter(mySound[which]); // Apply envelope
 }
 playSound--;
 }
}
public void stop() {
 Ess.stop(); // When program stops, stop Ess too
 super.stop();
}
void audioOutputPan(AudioOutput c) {
 c.panTo(-c.pan, 4000); // Reverse pan direction
}

External links