Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Java by david ( 15 years ago )
package edpmg.audio.engine;
import javax.swing.text.GapContent;
import jm.JMC;
import jm.audio.Instrument;
import jm.audio.RTMixer;
import jm.music.data.*;
import jm.music.rt.RTLine;
import jm.music.rt.RTPhrase;
import jm.util.*;
public class GABassLine extends RTLine implements JMC {
private Note n = new Note(36, 0.5);
Phrase bassLine1 = new Phrase(0.0);
Phrase bassLine2 = new Phrase(0.0);
Phrase resultBassLine = new Phrase(0.0);
int phraseGenotypeSize = 16;
int[] availablePitches = {36, 36, 40, 43, 45, 48, 52, 55};
private Note[] notesArray;
private int pitch = 36;
private double panPosition = 0.5;
public GABassLine(Instrument[] instArray) {
super(instArray);
Part bassPart = new Part(SYNTH_BASS);
bassPart.setTempo(132.0);
//parent phrase 1
for (int i=0;i<phraseGenotypeSize;i++) {
int pitch = availablePitches[(int)(Math.random() * availablePitches.length)];
bassLine1.add(new Note(pitch, 0.25));
}
//parent phrase 2
for (int i=0;i<phraseGenotypeSize;i++) {
int pitch = availablePitches[(int)(Math.random() * availablePitches.length)];
bassLine2.add(new Note(pitch, 0.25));
}
for (int i=0; i<8; i++) {
Phrase childBassLine1 = createChild();
Phrase childBassLine2 = createChild();
childBassLine1.setStartTime(8.0 * i);
childBassLine2.setStartTime(8.0 * i + 4.0);
bassPart.add(childBassLine1);
bassPart.add(childBassLine2);
bassLine1 = childBassLine1;
bassLine2 = childBassLine2;
}
View.show(bassPart);
//Play.midi(bassPart);
// this is clearly wrong, in that I thought it would turn the bassPart Part into a Phrase, but it does not
// when debugging, all elementData inside noteList inside resultBassLine shows as null (each of the 9 elements
// in the array show null value)
//
// must find different way of turning the output of mutation and crossover above into RTPhrase
resultBassLine = bassPart.createPhrase();
}
/**
* Generate the next note when requested.
*/
public synchronized Note getNote() {
//traversing the resultBassLine array to get values for n, which is Note getNote wants
//however (read comments above), this may be full of null, as I can't seem to parse bassPart into a Phrase
for (int j1=0; j1 < resultBassLine.getSize(); j1++) {
n.equals(resultBassLine.getNote(j1));
}
n.setDynamic((int)(Math.random()* 80 + 45));
n.setRhythmValue((int)(Math.random() * 2 + 1) * 0.25);
n.setDuration(n.getRhythmValue() * 0.9);
return n;
}
@Override
public Note getNextNote() {
for (int j1=0; j1 < resultBassLine.getSize(); j1++) {
n.equals(resultBassLine.getNote(j1));
}
n.setDynamic((int)(Math.random()* 80 + 45));
n.setRhythmValue((int)(Math.random() * 2 + 1) * 0.25);
n.setDuration(n.getRhythmValue() * 0.9);
return n;
}
private Phrase createChild() {
Phrase tempPhrase = new Phrase();
// crossover
int crossOverPoint = (int)(Math.random() * phraseGenotypeSize);
for (int j=0; j<crossOverPoint; j++) {
tempPhrase.add(bassLine1.getNote(j).copy());
}
for (int j=crossOverPoint; j<phraseGenotypeSize; j++) {
tempPhrase.add(bassLine2.getNote(j).copy());
}
// mutation
Note n = tempPhrase.getNote((int)(Math.random() * phraseGenotypeSize));
int pitch = availablePitches[(int)(Math.random() * availablePitches.length)];
n.setPitch(pitch);
return tempPhrase;
}
/** Allow other classes to set the notes pan value */
public void setPanValue(double p) {
this.panPosition = p;
}
public void SetPitch(int newPitch)
{
pitch=newPitch;
}
}
Revise this Paste