/** Nick Didkovsky, 10/5/98 12:28PM GUI for GrainMaker */ package jmslexamples; import java.awt.*; import java.awt.event.*; import com.softsynth.jmsl.*; public class GrainMakerApplet extends java.applet.Applet implements ActionListener { public void init() { setLayout(new BorderLayout()); textArea = new TextArea(20, 80); Panel p = new Panel(); p.setLayout(new GridLayout(0, 2)); numSplatters = new TextField("1"); numGrains = new TextField("100"); spread = new TextField("0.5"); outDur = new TextField("10.0"); inDur = new TextField("0.126"); maxGrainDur = new TextField("0.01"); minGrainDur = new TextField("0.001"); useGauss = new TextField("1"); p.add(new Label("Number of Grain Blasts")); p.add(numSplatters); p.add(new Label("Grains per Blast")); p.add(numGrains); p.add(new Label("Blast Scatter (sec)")); p.add(spread); p.add(new Label("Dur of output audio file (sec)")); p.add(outDur); p.add(new Label("Dur of input audio file (sec)")); p.add(inDur); p.add(new Label("Max grain dur (sec)")); p.add(maxGrainDur); p.add(new Label("Min grain dur (sec)")); p.add(minGrainDur); p.add(new Label("Granular Distribution: Uniform Linear (0), Gaussian (1)")); p.add(useGauss); goButton = new Button("GO"); goButton.addActionListener(this); add("South", textArea); add("Center", goButton); add("North", p); JMSLRandom.randomize(); buildMisc(); } void buildMisc() { JMSL.setSTDOut(new com.softsynth.jmsl.view.TextAreaOut(textArea)); } void harvestValues() { grainMaker.setNumSplatters((new Integer(numSplatters.getText())).intValue()); grainMaker.setNumGrains((new Integer(numGrains.getText())).intValue()); grainMaker.setSpread((new Double(spread.getText())).doubleValue()); grainMaker.setOutDur((new Double(outDur.getText())).doubleValue()); grainMaker.setInDur((new Double(inDur.getText())).doubleValue()); grainMaker.setMaxGrainDur((new Double(maxGrainDur.getText())).doubleValue()); grainMaker.setMinGrainDur((new Double(minGrainDur.getText())).doubleValue()); boolean b = 0 != (new Integer(useGauss.getText())).intValue(); grainMaker.setUseGauss(b); } void writeScore() { grainMaker = new GrainMaker(); harvestValues(); textArea.setText(""); grainMaker.makeGrains(); } public void actionPerformed(ActionEvent event) { Object source = event.getSource(); if (source == goButton) writeScore(); } public static void main(String args[]) { GrainMakerApplet applet = new GrainMakerApplet(); Frame f = new Frame("GrainMaker"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.add(applet, BorderLayout.CENTER); applet.init(); applet.start(); f.setSize(800, 600); f.setVisible(true); } TextArea textArea; TextField numSplatters; // How many blasts of grains TextField numGrains; // How many grains to splatter each time TextField spread; // Time spread "left" and "right" of target time, controls Gauss bell TextField outDur; // Duration of output sound file TextField inDur; // Duration of input sound file, you must set properly by checking your file!!! TextField maxGrainDur; // Max width of grain, chosen 0..max TextField minGrainDur; TextField useGauss; Button goButton; GrainMaker grainMaker; }