// Copyright (C) 2005 Dave Griffiths -interpreter class // 2007 yosuke hayashi -map sounds and use Ess sound library // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import controlP5.*; import krister.Ess.*; ControlP5 controlP5; // stops us creating HUGE strings that take hours to process :) int MAX_STRING = 4096; public String textValue = ""; void setup() { size(220, 150); PFont myfont = loadFont("CourierNew36.vlw"); controlP5 = new ControlP5(this); controlP5.addTextfield("setText",10,40,200,20); textFont(myfont,12); Ess.start(this); interpreter.initialise(); frameRate(10); } void draw() { background(0); play(); } void setText(String theValue) { textValue = theValue; } // the interpreter reads the output strings //and understands how the symbols map to music commands. class Interpreter { AudioChannel sounds[]; SineWave sine; SawtoothWave saw; TriangleWave tri; SquareWave square; WhiteNoise wNoise; int pos; int dur = 500; int sampRate = 44100; float panPos = 0; float vol = 0.5; Interpreter() { pos=0; sounds=new AudioChannel[5]; } void initialise() { Ess.masterVolume(vol); sounds[0]=new AudioChannel(); sounds[0].initChannel(sounds[0].frames(dur)); sine = new SineWave(440, .5); sine.generate(sounds[0],1); sounds[1]=new AudioChannel(); sounds[1].initChannel(sounds[1].frames(dur)); saw = new SawtoothWave(440, .5); saw.generate(sounds[1],1); sounds[2]=new AudioChannel(); sounds[2].initChannel(sounds[2].frames(dur)); tri = new TriangleWave(440, .5); tri.generate(sounds[2],1); sounds[3]=new AudioChannel(); sounds[3].initChannel(sounds[3].frames(dur)); square = new SquareWave(440, .5); square.generate(sounds[3],1); sounds[4]=new AudioChannel(); sounds[4].initChannel(sounds[4].frames(dur)); wNoise = new WhiteNoise(.5); wNoise.generate(sounds[4],1); } void parse(String t) { boolean finished=false; while(pos=1) { vol = 1; } Ess.masterVolume(vol); break; case '-': vol-=0.1; if(vol<=0) { vol = 0; } Ess.masterVolume(vol); break; case '>': panPos += 0.1; if(panPos>=1) { panPos = 1; } for(int i=0;i=t.length()) { pos=0; } } } /////////////////////////////////////////////////////////////////////// Interpreter interpreter = new Interpreter(); int picked=0; int swidth=400, sheight=400; int hw=swidth/2, hh=sheight/2; void renderString(String s, int x, int y) { String RenderStr=""; int linelen=25; int maxlines=14; int count=0; int lines=0; for (int n=0; nlinelen) { RenderStr+="\n"; count=0; lines++; if (lines>maxlines) break; } } fill(255); text(RenderStr, x, y); } void play() { String lines = textValue; interpreter.parse(lines); renderString(lines, 10, 90); } public void stop() { Ess.stop(); super.stop(); }