/** * chordComposer.java * * abstract implementation of abstract composer class. * Composes a midi sequence of bent pitches * derived from equal tempered scales with user specified number * of division to the octave, * Writes the sequernce to a standard midi file. * * This module is part of Karl Brown's MIDI programming project. * */ package MidiApps; import java.io.*; import java.util.*; import javax.sound.midi.*; /** * * @author Karl Brown * @version 1.0 * last updated 2/16/2003 */ public abstract class equalTemperComposer extends composer { int numDivisions; bentScale myBentScale; public void setNumDivisions(int num) { if (num > 0 && num <= 1200) { numDivisions = num; } } public int getNumDivisions() { return numDivisions; } public void setBentScale(bentScale bs) { if (bs != null) { myBentScale = bs; } } public bentScale getBentScale() { if (myBentScale != null) { return myBentScale; } else { return null; } } /** * * Builds an equal tempered scale of bent pitches. * Instantiates an equalTemperedBentPitchFactory which * calculates the values for each bentPitch object * which is then added to the equalTemperedScale. * * */ public void buildScale() { try { bentPitch bh; // tr.trace("creating scale..."); equalTemperedBentPitchFactory fact = new equalTemperedBentPitchFactory(); fact.setTracer(tr); // fact.setBaseMidiPitch((byte)C_DOWN_3); fact.setBaseMidiPitch((byte)getBaseMidiPitch()); fact.setDivisions((short)getNumDivisions()); fact.setStepPosition((short)0); bentScale bs; equalTemperedScale ets = new equalTemperedScale(); bs = (bentScale)ets; bs.setTracer(tr); setBentScale(bs); int numNotes = getNumOctaves() * getNumDivisions() + 1; for (short i = 0; i <= numNotes; i++) { fact.setStepPosition(i); fact.calculateBendAmount(); fact.calculateBendBytes(); bh = fact.getBentPitch(); bs.addBentPitch(bh); } } //try catch(Exception e) { tr.trace("chordComposer::buildScale: Exception caught:"); tr.trace(e.toString()); } //catch } }