Search in sources :

Example 36 with NoteList

use of blue.soundObject.NoteList in project blue by kunstmusik.

the class ClojureObject method generateNotes.

protected final NoteList generateNotes(double renderStart, double renderEnd) throws SoundObjectException {
    String tempScore = null;
    File currentDirFile = BlueSystem.getCurrentProjectDirectory();
    HashMap<String, Object> initObjects = new HashMap<>();
    initObjects.put("score", "");
    initObjects.put("blueDuration", getSubjectiveDuration());
    initObjects.put("blueProjectDir", currentDirFile);
    try {
        tempScore = BlueClojureEngine.getInstance().processScript(clojureCode, initObjects, "score");
    } catch (ScriptException scriptEx) {
        String msg = "Clojure Error:\n" + getRootCauseException(scriptEx).toString();
        throw new SoundObjectException(this, msg);
    }
    NoteList nl;
    try {
        nl = ScoreUtilities.getNotes(tempScore);
    } catch (NoteParseException e) {
        throw new SoundObjectException(this, e);
    }
    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 : ScriptException(javax.script.ScriptException) NoteProcessorException(blue.noteProcessor.NoteProcessorException) NoteList(blue.soundObject.NoteList) HashMap(java.util.HashMap) NoteParseException(blue.soundObject.NoteParseException) SoundObject(blue.soundObject.SoundObject) AbstractSoundObject(blue.soundObject.AbstractSoundObject) SoundObjectException(blue.soundObject.SoundObjectException) File(java.io.File)

Example 37 with NoteList

use of blue.soundObject.NoteList in project blue by kunstmusik.

the class MidiImportUtilities method convertMidiFile.

/**
 * Converts a MIDI file to a blue polyObject. Will return null if unable to
 * open or process the file.
 *
 * @param midiFile
 * @return
 * @throws NoteParseException
 */
public static PolyObject convertMidiFile(Frame root, File midiFile) throws NoteParseException {
    if (midiFile == null || !midiFile.exists()) {
        return null;
    }
    Sequence sequence = null;
    try {
        sequence = MidiSystem.getSequence(midiFile);
    } catch (InvalidMidiDataException imde) {
        imde.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    if (sequence == null) {
        return null;
    }
    PolyObject pObj = new PolyObject(true);
    Track[] tracks = sequence.getTracks();
    double divType = sequence.getDivisionType();
    if (divType == Sequence.PPQ) {
        divType = 1.0f;
    }
    double ticksLength = (double) sequence.getResolution();
    MidiImportSettings settings = getMidiImportSettings(tracks);
    if (settings.getRowCount() == 0) {
        return null;
    }
    boolean retVal = MidiImportSettingsDialog.ask(root, settings);
    if (!retVal) {
        return null;
    }
    for (int i = 0; i < tracks.length; i++) {
        TrackImportSettings trSettings = settings.getTrackSettingsForTrackNum(i);
        if (trSettings == null) {
            continue;
        }
        Track track = tracks[i];
        NoteList nl = getNoteListForTrack(track, divType, ticksLength, trSettings.getNoteTemplate(), trSettings.getInstrId());
        if (nl == null || nl.size() == 0) {
            continue;
        }
        GenericScore genSco = new GenericScore();
        if (trSettings.isTrim()) {
            // Assumes NoteList is already sorted
            double start = nl.get(0).getStartTime();
            genSco.setStartTime(start);
            ScoreUtilities.normalizeNoteList(nl);
        } else {
            genSco.setStartTime(0.0f);
        }
        genSco.setSubjectiveDuration(ScoreUtilities.getTotalDuration(nl));
        genSco.setText(nl.toString());
        genSco.setName("Track " + i);
        SoundLayer sLayer = pObj.newLayerAt(-1);
        sLayer.add(genSco);
    }
    return pObj;
}
Also used : InvalidMidiDataException(javax.sound.midi.InvalidMidiDataException) NoteList(blue.soundObject.NoteList) GenericScore(blue.soundObject.GenericScore) Sequence(javax.sound.midi.Sequence) IOException(java.io.IOException) SoundLayer(blue.SoundLayer) PolyObject(blue.soundObject.PolyObject) Track(javax.sound.midi.Track)

Example 38 with NoteList

use of blue.soundObject.NoteList in project blue by kunstmusik.

the class MidiImportUtilities method getNoteListForTrack.

private static NoteList getNoteListForTrack(Track track, double divType, double ticksLength, String template, String instrId) throws NoteParseException {
    if (track.size() == 0) {
        return null;
    }
    MNote[] notes = new MNote[128];
    for (int j = 0; j < notes.length; j++) {
        notes[j] = new MNote();
    }
    NoteList nl = new NoteList();
    for (int j = 0; j < track.size(); j++) {
        MidiEvent me = track.get(j);
        MidiMessage message = me.getMessage();
        if (message instanceof ShortMessage) {
            ShortMessage shortMsg = (ShortMessage) message;
            int noteNum, velocity;
            MNote n;
            double time = (me.getTick() / ticksLength) * divType;
            switch(shortMsg.getCommand()) {
                case ShortMessage.NOTE_ON:
                    noteNum = shortMsg.getData1();
                    velocity = shortMsg.getData2();
                    n = notes[noteNum];
                    if (velocity > 0) {
                        n.start = time;
                        n.velocity = velocity;
                    } else {
                        double start = n.start;
                        double duration = time - n.start;
                        String note = MidiUtilities.processNoteTemplate(template, instrId, start, duration, noteNum, n.velocity);
                        nl.add(Note.createNote(note));
                        n.clear();
                    }
                    break;
                case ShortMessage.NOTE_OFF:
                    noteNum = shortMsg.getData1();
                    velocity = shortMsg.getData2();
                    n = notes[noteNum];
                    double start = n.start;
                    double duration = time - n.start;
                    String note = MidiUtilities.processNoteTemplate(template, instrId, start, duration, noteNum, n.velocity);
                    nl.add(Note.createNote(note));
                    n.clear();
                    break;
            }
        }
    }
    return nl;
}
Also used : NoteList(blue.soundObject.NoteList) MidiMessage(javax.sound.midi.MidiMessage) ShortMessage(javax.sound.midi.ShortMessage) MidiEvent(javax.sound.midi.MidiEvent)

Example 39 with NoteList

use of blue.soundObject.NoteList in project blue by kunstmusik.

the class EqualsProcessor method main.

public static void main(String[] args) {
    NoteList n = new NoteList();
    for (int i = 0; i < 10; i++) {
        try {
            n.add(Note.createNote("i1 " + (i * 2) + " 2 3 4"));
        } catch (NoteParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    System.out.println("before: \n\n" + n + "\n\n");
    EqualsProcessor ep = new EqualsProcessor();
    ep.setPfield("4");
    ep.setVal("17");
    try {
        ep.processNotes(n);
    } catch (NoteProcessorException ex) {
        System.out.println("Error: " + ex.getMessage());
    }
    System.out.println("a after: \n\n" + n + "\n\n");
}
Also used : NoteList(blue.soundObject.NoteList) NoteParseException(blue.soundObject.NoteParseException)

Example 40 with NoteList

use of blue.soundObject.NoteList in project blue by kunstmusik.

the class PchInversionProcessor method main.

public static void main(String[] args) {
    NoteList n = new NoteList();
    for (int i = 0; i < 10; i++) {
        try {
            n.add(Note.createNote("i1 " + i + " 2 6.0" + i + " 4"));
        } catch (NoteParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    System.out.println("before: \n\n" + n + "\n\n");
    PchInversionProcessor ap = new PchInversionProcessor();
    ap.setPfield("4");
    ap.setVal("5.00");
    try {
        ap.processNotes(n);
    } catch (NoteProcessorException ex) {
        System.out.println("Exception: " + ex.getMessage());
    }
    System.out.println("after: \n\n" + n + "\n\n");
}
Also used : NoteList(blue.soundObject.NoteList) NoteParseException(blue.soundObject.NoteParseException)

Aggregations

NoteList (blue.soundObject.NoteList)50 NoteParseException (blue.soundObject.NoteParseException)25 Note (blue.soundObject.Note)11 CompileData (blue.CompileData)6 SoundObject (blue.soundObject.SoundObject)6 GenericScore (blue.soundObject.GenericScore)4 Arrangement (blue.Arrangement)3 GlobalOrcSco (blue.GlobalOrcSco)3 Tables (blue.Tables)3 NoteProcessorException (blue.noteProcessor.NoteProcessorException)3 SoundObjectException (blue.soundObject.SoundObjectException)3 OpcodeList (blue.udo.OpcodeList)3 ParameterNameManager (blue.automation.ParameterNameManager)2 LiveObject (blue.blueLive.LiveObject)2 LiveObjectSet (blue.blueLive.LiveObjectSet)2 LinePoint (blue.components.lines.LinePoint)2 Mixer (blue.mixer.Mixer)2 TempoMapper (blue.noteProcessor.TempoMapper)2 GenericInstrument (blue.orchestra.GenericInstrument)2 Instrument (blue.orchestra.Instrument)2