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;
}
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;
}
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;
}
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");
}
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");
}
Aggregations