public class PadsGenerator implements ScoreManipulator {
private Random random = new Random();
@Override
public void handleScore(Score score, ScoreContext ctx) {
Part pad1 = ctx.getParts().get(PartType.PAD1);
Part pad2 = ctx.getParts().get(PartType.PAD2);
if (pad1 == null) {
return;
}
Phrase pad1Phrase = new Phrase();
pad1Phrase.setInstrument(pad1.getInstrument());
pad1.add(pad1Phrase);
Phrase pad2Phrase = null;
if (pad2 != null) {
pad2Phrase = new Phrase();
pad2Phrase.setInstrument(pad2.getInstrument());
pad2.add(pad2Phrase);
}
boolean pad1Long = Chance.test(40);
boolean pad2Long = Chance.test(40);
int nextContinuationChangeMeasurePad1 = 0;
int nextContinuationChangeMeasurePad2 = 0;
Part mainPart = ctx.getParts().get(PartType.MAIN);
for (Phrase phrase : mainPart.getPhraseArray()) {
ExtendedPhrase ePhrase = (ExtendedPhrase) phrase;
for (int i = 0; i < ePhrase.getMeasures(); i++) {
nextContinuationChangeMeasurePad1 = handlePads(ctx, ePhrase.getScale(), pad1Phrase, i, nextContinuationChangeMeasurePad1, pad1Long);
if (pad2 != null) {
nextContinuationChangeMeasurePad2 = handlePads(ctx, ePhrase.getScale(), pad2Phrase, i, nextContinuationChangeMeasurePad2, pad2Long);