package jmsltutorial; import java.util.Enumeration; import com.softsynth.jmsl.score.*; import com.softsynth.jmsl.util.BeanEditor; /** MutationMeanTransform
The resulting melody is the pitch mean and duration mean of the two sources, specifically: @author Nick Didkovsky, copyright 2000 Nick Didkovsky, all rights reserved */ public class MutationMeanTransform extends BinaryCopyBufferTransform { double mutationIndex = 0.5; public MutationMeanTransform() { setName("MutationMean"); } public void setMutationIndex(double m) { mutationIndex = m; } public double getMutationIndex() { return mutationIndex; } public void operate(CopyBuffer fromBuffer1, CopyBuffer fromBuffer2, CopyBuffer toBuffer) { try { BeanEditor beanEditor = new BeanEditor(new java.awt.Frame(), null, this, true); beanEditor.setVisible(true); toBuffer.removeAllElements(); Enumeration e1 = fromBuffer1.elements(); // load all of aux1 into result buffer while (e1.hasMoreElements()) { toBuffer.addElement(e1.nextElement()); } // now enumerate through again and calculate new pitch and dur, stop when either buffer has no more elements Enumeration e2 = toBuffer.elements(); Enumeration e3 = fromBuffer2.elements(); while (e2.hasMoreElements() && e3.hasMoreElements()) { Note n1 = (Note) e2.nextElement(); Note n2 = (Note) e3.nextElement(); n1.setPitchData((int) (n1.getPitchData() * (1 - mutationIndex) + n2.getPitchData() * mutationIndex)); NoteFactory.updateFromPitch(n1); n1.setDurationData((n1.getDurationData() * (1 - mutationIndex) + n2.getDurationData() * mutationIndex)); NoteFactory.updateFromDur(n1); } } catch (Exception e) { System.out.println("ERROR: " + e); } } public static final String copyright = "copyright (C) 2000 Nick Didkovsky, all rights reserved"; }