Search in sources :

Example 6 with PianoNote

use of blue.soundObject.pianoRoll.PianoNote in project blue by kunstmusik.

the class PianoRoll method generateNotes.

public NoteList generateNotes(double renderStart, double renderEnd) throws SoundObjectException {
    NoteList nl = new NoteList();
    String instrId = instrumentId;
    if (instrId != null) {
        instrId = instrId.trim();
    }
    try {
        Integer.parseInt(instrumentId);
    } catch (NumberFormatException nfe) {
        instrId = "\"" + instrId + "\"";
    }
    for (Iterator<PianoNote> iter = notes.iterator(); iter.hasNext(); ) {
        PianoNote n = iter.next();
        String freq = "";
        int octave = n.getOctave();
        int scaleDegree = n.getScaleDegree() + getTransposition();
        int numScaleDegrees;
        if (getPchGenerationMethod() == GENERATE_MIDI) {
            numScaleDegrees = 12;
        } else {
            numScaleDegrees = scale.getNumScaleDegrees();
        }
        if (scaleDegree >= numScaleDegrees) {
            octave += scaleDegree / numScaleDegrees;
            scaleDegree = scaleDegree % numScaleDegrees;
        }
        if (scaleDegree < 0) {
            int octaveDiff = (scaleDegree * -1) / numScaleDegrees;
            octaveDiff += 1;
            scaleDegree = scaleDegree % numScaleDegrees;
            octave -= octaveDiff;
            scaleDegree = numScaleDegrees + scaleDegree;
        }
        if (this.pchGenerationMethod == GENERATE_FREQUENCY) {
            double f = scale.getFrequency(octave, scaleDegree);
            freq = Double.toString(f);
        } else if (this.pchGenerationMethod == GENERATE_PCH) {
            freq = octave + "." + scaleDegree;
        } else if (this.pchGenerationMethod == GENERATE_MIDI) {
            freq = Integer.toString((octave * 12) + scaleDegree);
        }
        String template = n.getNoteTemplate();
        template = TextUtilities.replaceAll(template, "<INSTR_ID>", instrId);
        template = TextUtilities.replaceAll(template, "<INSTR_NAME>", instrumentId);
        template = TextUtilities.replaceAll(template, "<START>", Double.toString(n.getStart()));
        template = TextUtilities.replaceAll(template, "<DUR>", Double.toString(n.getDuration()));
        template = TextUtilities.replaceAll(template, "<FREQ>", freq);
        Note note = null;
        try {
            note = Note.createNote(template);
        } catch (NoteParseException e) {
            throw new SoundObjectException(this, e);
        }
        nl.add(note);
    }
    try {
        ScoreUtilities.applyNoteProcessorChain(nl, this.npc);
    } catch (NoteProcessorException e) {
        throw new SoundObjectException(this, e);
    }
    ScoreUtilities.applyTimeBehavior(nl, this.getTimeBehavior(), this.getSubjectiveDuration(), this.getRepeatPoint());
    ScoreUtilities.setScoreStart(nl, startTime);
    return nl;
}
Also used : NoteProcessorException(blue.noteProcessor.NoteProcessorException) PianoNote(blue.soundObject.pianoRoll.PianoNote) PianoNote(blue.soundObject.pianoRoll.PianoNote)

Example 7 with PianoNote

use of blue.soundObject.pianoRoll.PianoNote in project blue by kunstmusik.

the class PianoRollRenderer method generateCache.

protected PianoRollValueCache generateCache(PianoRoll pianoRoll) {
    PianoRollValueCache cache = new PianoRollValueCache();
    ArrayList<PianoNote> notes = pianoRoll.getNotes();
    if (notes.size() == 0) {
        cache.min = 0;
        cache.max = 0;
        cache.range = 0;
    } else {
        Collections.sort(notes);
        int scaleDegrees = pianoRoll.getScale().getNumScaleDegrees();
        PianoNote noteMin = notes.get(0);
        PianoNote noteMax = notes.get(notes.size() - 1);
        cache.min = (noteMin.getOctave() * scaleDegrees) + noteMin.getScaleDegree();
        cache.max = (noteMax.getOctave() * scaleDegrees) + noteMax.getScaleDegree();
        cache.range = cache.max - cache.min;
    }
    return cache;
}
Also used : PianoNote(blue.soundObject.pianoRoll.PianoNote)

Aggregations

PianoNote (blue.soundObject.pianoRoll.PianoNote)7 NoteProcessorException (blue.noteProcessor.NoteProcessorException)1 Element (electric.xml.Element)1 Point (java.awt.Point)1