use of blue.soundObject.SoundObjectException in project blue by kunstmusik.
the class CSDRender method getGlobalDuration.
/**
* @param globalSco
* @return
* @throws SoundObjectException
*/
private double getGlobalDuration(String globalSco) throws SoundObjectException {
NoteList globalNotes;
try {
globalNotes = ScoreUtilities.getNotes(globalSco);
} catch (NoteParseException e) {
GenericScore gs = new GenericScore();
gs.setName("Global Orchestra Text");
throw new SoundObjectException(gs, e);
}
double globalDur = ScoreUtilities.getTotalDuration(globalNotes);
return globalDur;
}
use of blue.soundObject.SoundObjectException in project blue by kunstmusik.
the class CSDRender method generateCSDImpl.
@Override
protected CsdRenderResult generateCSDImpl(BlueData data, double startTime, double endTime, boolean isRealTime, boolean _usingAPI) {
ProjectPluginManager.getInstance().preRender(data);
StringChannelNameManager scnm = new StringChannelNameManager();
ParameterNameManager pnm = new ParameterNameManager();
ArrayList<StringChannel> stringChannels = getStringChannels(data.getArrangement(), scnm);
ParameterHelper.clearCompilationVarNames(data);
boolean usingAPI = isRealTime && _usingAPI;
double renderStartTime = data.getRenderStartTime();
// making copies to use for adding compileTime tables and instruments
Tables tables = new Tables(data.getTableSet());
ArrayList originalParameters;
// if (usingAPI) {
originalParameters = ParameterHelper.getAllParameters(data.getArrangement(), data.getMixer());
// } else {
// originalParameters = ParameterHelper.getActiveParameters(
// data.getArrangement(), data.getMixer());
// }
assignParameterNames(originalParameters, pnm);
Arrangement arrangement = new Arrangement(data.getArrangement());
arrangement.clearUnusedInstrAssignments();
boolean hasInstruments = arrangement.size() > 0;
CompileData compileData = new CompileData(arrangement, tables, stringChannels, originalParameters, scnm, pnm);
Mixer mixer = null;
boolean mixerEnabled = data.getMixer().isEnabled();
if (mixerEnabled) {
mixer = new Mixer(data.getMixer());
assignChannelIds(compileData, mixer);
}
NoteList generatedNotes;
try {
generatedNotes = data.getScore().generateForCSD(compileData, startTime, endTime);
} catch (ScoreGenerationException ex) {
throw new RuntimeException(ex);
}
compileData.setHandleParametersAndChannels(false);
// assignParameterNames(originalParameters);
// get parameters
// ArrayList parameters;
// if (usingAPI) {
// parameters = ParameterHelper.getAllParameters(
// arrangement, mixer);
// } else {
// parameters = ParameterHelper.getActiveParameters(
// arrangement, mixer);
// }
GlobalOrcSco globalOrcSco = new GlobalOrcSco(data.getGlobalOrcSco());
OpcodeList udos = new OpcodeList(data.getOpcodeList());
// add all UDO's from instruments and effects
arrangement.generateUserDefinedOpcodes(udos);
// adding all compile-time instruments from soundObjects to arrangement
appendFtgenTableNumbers(globalOrcSco.getGlobalOrc(), tables);
// generating ftables
arrangement.generateFTables(tables);
String ftables = tables.getTables();
// Handle Render End Instrument and Note
if (endTime > 0.0f && endTime > startTime) {
Instrument instr = createRenderEndInstrument();
int instrId = arrangement.addInstrument(instr);
double endStartTime = endTime - startTime;
try {
Note renderEndNote = Note.createNote("i" + instrId + " " + endStartTime + " 0.1");
generatedNotes.add(renderEndNote);
} catch (NoteParseException e1) {
}
}
Tempo tempo = data.getScore().getTempo();
TempoMapper tempoMapper = null;
if (tempo.isEnabled()) {
tempoMapper = getTempoMapper(tempo);
globalOrcSco.appendGlobalSco(getTempoScore(tempo, renderStartTime, endTime));
} else {
tempoMapper = getTempoMapper(globalOrcSco.getGlobalSco());
}
double totalDur = blue.utility.ScoreUtilities.getTotalDuration(generatedNotes);
// double processingStart = blue.utility.ScoreUtilities.getProcessingStartTime(
// tempPObj);
// FIXME - figure out what to do about PROCESSING_START
double processingStart = renderStartTime;
System.out.println("<TOTAL_DUR> = " + totalDur);
System.out.println("<RENDER_START> = " + renderStartTime);
System.out.println("<PROCESSING_START> = " + processingStart);
int nchnls = getNchnls(data, isRealTime);
ArrayList<Instrument> alwaysOnInstruments = new ArrayList<>();
// boolean generateMixer = mixerEnabled && (hasInstruments || mixer.hasSubChannelDependencies());
arrangement.preGenerateOrchestra(compileData, mixer, nchnls, alwaysOnInstruments);
String globalSco = globalOrcSco.getGlobalSco() + "\n";
globalSco += arrangement.generateGlobalSco(compileData) + "\n";
globalSco = preprocessSco(globalSco, totalDur, renderStartTime, processingStart, tempoMapper);
double globalDur;
try {
globalDur = getGlobalDuration(globalSco);
} catch (SoundObjectException ex) {
throw new RuntimeException(ex);
}
if (globalDur < totalDur) {
globalDur = totalDur;
}
System.out.println("Global Duration = " + globalDur);
if (mixerEnabled) {
globalDur += mixer.getExtraRenderTime();
}
for (Instrument instrument : alwaysOnInstruments) {
String sourceId = compileData.getInstrSourceId(instrument);
String noteStr;
if (StringUtils.isNumeric(sourceId)) {
int instrId = arrangement.addInstrumentAtEnd(instrument);
noteStr = "i" + instrId + " 0 " + totalDur;
} else {
String instrId = sourceId + "_alwaysOn";
arrangement.addInstrumentWithId(instrument, instrId, false);
noteStr = "i \"" + instrId + "\" 0 " + totalDur;
}
try {
Note n = Note.createNote(noteStr);
generatedNotes.add(n);
} catch (NoteParseException ex) {
ex.printStackTrace();
}
}
if (mixerEnabled) {
final String mixerId = "BlueMixer";
// globalDur += mixer.getExtraRenderTime();
clearUnusedMixerChannels(mixer, arrangement);
globalOrcSco.appendGlobalOrc(mixer.getInitStatements(compileData, nchnls) + "\n");
arrangement.addInstrumentWithId(mixer.getMixerInstrument(compileData, udos, nchnls), mixerId, false);
try {
Note n = Note.createNote("i \"BlueMixer\" 0 " + globalDur);
generatedNotes.add(n);
} catch (NoteParseException ex) {
ex.printStackTrace();
}
}
handleParameters(originalParameters, stringChannels, globalOrcSco, generatedNotes, arrangement, startTime, startTime + globalDur, isRealTime, _usingAPI);
if (isRealTime && !usingAPI) {
Instrument instr = createBlueTimePointerInstrument();
int instrId = arrangement.addInstrument(instr);
try {
Note n = Note.createNote("i" + instrId + " 0 " + globalDur);
generatedNotes.add(n);
} catch (NoteParseException ex) {
ex.printStackTrace();
}
}
String tempGlobalOrc = compileData.getGlobalOrc();
if (tempGlobalOrc != null && tempGlobalOrc.length() > 0) {
globalOrcSco.appendGlobalOrc(tempGlobalOrc);
}
StrBuilder csd = new StrBuilder();
appendProjectInfo(data, csd);
csd.append("<CsoundSynthesizer>\n\n");
appendCsInstruments(compileData, data, udos, arrangement, globalOrcSco, csd, mixer, isRealTime);
appendCsScore(globalSco, ftables, generatedNotes, totalDur, csd);
csd.append("</CsoundSynthesizer>");
CsdRenderResult renderResult = new CsdRenderResult(csd.toString(), tempoMapper, originalParameters, stringChannels);
return renderResult;
}
use of blue.soundObject.SoundObjectException 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.SoundObjectException in project blue by kunstmusik.
the class CommandlineRunner method playModeChanged.
@Override
public void playModeChanged(int playMode) {
if (playMode == PlayModeListener.PLAY_MODE_STOP) {
if (console.getLastExitValue() != 0) {
final GeneralSettings generalSettings = GeneralSettings.getInstance();
if (generalSettings.isCsoundErrorWarningEnabled()) {
if (errorPanel == null) {
errorPanel = new JPanel(new BorderLayout());
errorPanel.add(new JLabel("<html>There was an error in " + "running Csound.<br>" + "Please view the Csound Output Dialog for " + "more information.<br><br></html>"), BorderLayout.CENTER);
disableMessagesBox = new JCheckBox("Disable Error Message Dialog");
errorPanel.add(disableMessagesBox, BorderLayout.SOUTH);
}
disableMessagesBox.setSelected(false);
SwingUtilities.invokeLater(() -> {
JOptionPane.showMessageDialog(null, errorPanel, "Csound Error", JOptionPane.ERROR_MESSAGE);
if (disableMessagesBox.isSelected()) {
generalSettings.setCsoundErrorWarningEnabled(false);
generalSettings.save();
}
});
}
notifyPlayModeListeners(playMode);
return;
}
if (data.isLoopRendering() && !shouldStop) {
try {
render();
} catch (SoundObjectException e) {
Exceptions.printStackTrace(e);
// ExceptionDialog.showExceptionDialog(parent, e);
notifyPlayModeListeners(PlayModeListener.PLAY_MODE_STOP);
}
} else {
notifyPlayModeListeners(playMode);
}
} else {
notifyPlayModeListeners(playMode);
}
}
use of blue.soundObject.SoundObjectException in project blue by kunstmusik.
the class CommandlineRunner method render.
@Override
public void render() throws SoundObjectException {
if (this.data == null) {
return;
}
shouldStop = false;
String command;
try {
// String osName = System.getProperty("os.name");
command = ProjectPropertiesUtil.getRealtimeCommandLine(data.getProjectProperties());
// if (command.trim().length() == 0) {
// command = ProgramOptions.getDefaultCommandline();
// JOptionPane.showMessageDialog(null, BlueSystem
// .getString("message.noCommandLineSet")
// + " " + command);
//
// }
String globalSco = data.getGlobalOrcSco().getGlobalSco();
globalSco = TextUtilities.stripMultiLineComments(globalSco);
globalSco = TextUtilities.stripSingleLineComments(globalSco);
// System.out.println(tempoMapper);
// FIXME
// timeManager.setRootPolyObject(data.getPolyObject());
double startTime = data.getRenderStartTime();
double endTime = data.getRenderEndTime();
CsdRenderResult result = CSDRenderService.getDefault().generateCSD(data, startTime, endTime, true, false);
RenderTimeManager timeManager = Lookup.getDefault().lookup(RenderTimeManager.class);
timeManager.setTempoMapper(result.getTempoMapper());
String csd = result.getCsdText();
File temp = FileUtilities.createTempTextFile("tempCsd", ".csd", BlueSystem.getCurrentProjectDirectory(), csd);
// if (osName.indexOf("Windows") >= 0) {
command += " \"" + temp.getAbsolutePath() + "\"";
// } else {
// command += " " + temp.getAbsolutePath().replaceAll(" ", "\\\\ ");
// }
play(command, BlueSystem.getCurrentProjectDirectory(), data.getRenderStartTime());
} catch (SoundObjectException soe) {
throw soe;
} catch (ScoreGenerationException ex) {
NotificationDisplayer.getDefault().notify("Error", NotificationDisplayer.Priority.HIGH.getIcon(), BlueSystem.getString("message.generateScore.error") + "\n" + ex.getLocalizedMessage(), null);
System.err.println("[" + BlueSystem.getString("message.error") + "] " + ex.getLocalizedMessage());
}
}
Aggregations