use of blue.components.lines.SoundObjectParameterLine in project blue by kunstmusik.
the class Sound method adjustLineType.
protected void adjustLineType(Parameter param) {
final Line line = param.getLine();
if (!(line instanceof SoundObjectParameterLine)) {
final SoundObjectParameterLine soundObjectParameterLine = new SoundObjectParameterLine(Sound.this, line);
param.setLine(soundObjectParameterLine);
}
}
use of blue.components.lines.SoundObjectParameterLine in project blue by kunstmusik.
the class CSDRender method appendParameterScore.
private void appendParameterScore(Parameter param, int instrId, StrBuilder paramScore, double renderStart, double renderEnd) {
Line line = param.getLine();
if (line.size() < 2) {
return;
}
// TODO - re-evaluate this strategy for generating values
double resolution = param.getResolution().doubleValue();
double startAdj = 0;
double durationAdj = 1.0;
boolean adjustPoints = (line instanceof SoundObjectParameterLine);
if (adjustPoints) {
SoundObjectParameterLine paramLine = (SoundObjectParameterLine) line;
startAdj = paramLine.getSourceStart();
durationAdj = paramLine.getSourceDuration();
}
if (resolution > 0.0f) {
for (int i = 1; i < line.size(); i++) {
LinePoint p1 = line.getLinePoint(i - 1);
LinePoint p2 = line.getLinePoint(i);
double startTime = p1.getX();
double endTime = p2.getX();
if (adjustPoints) {
startTime = (startTime * durationAdj) + startAdj;
endTime = (endTime * durationAdj) + startAdj;
}
if (renderEnd > 0 && startTime >= renderEnd) {
return;
}
if (endTime <= renderStart) {
continue;
}
double startVal = p1.getY();
double endVal = p2.getY();
// to skip points that don't contribute to end value
if (startTime == endTime) {
if (i == line.size() - 1) {
createParamNote(paramScore, instrId, endTime, .0001f, p2.getY(), p2.getY());
}
continue;
}
if (startVal == endVal) {
continue;
}
double dur = endTime - startTime;
double currentVal = startVal;
int numSteps = (int) Math.abs(Math.round((endVal - startVal) / resolution));
double step = dur / numSteps;
double start = startTime;
double valStep = resolution;
if (endVal < startVal) {
valStep = -valStep;
}
// skip the first value as it will be already defined
for (int j = 0; j < numSteps - 1; j++) {
currentVal += valStep;
start += step;
if (start <= renderStart) {
continue;
}
if (renderEnd > 0 && start >= renderEnd) {
return;
}
paramScore.append("i");
paramScore.append(instrId).append("\t");
paramScore.append(NumberUtilities.formatDouble(start - renderStart)).append("\t");
paramScore.append(".0001\t");
paramScore.append(NumberUtilities.formatDouble(currentVal)).append("\n");
}
start += step;
if (renderEnd > 0 && start >= renderEnd) {
return;
}
paramScore.append("i");
paramScore.append(instrId).append("\t");
paramScore.append(NumberUtilities.formatDouble(start - renderStart)).append("\t");
paramScore.append(".0001\t");
paramScore.append(NumberUtilities.formatDouble(endVal)).append("\n");
}
} else {
double lastValue = line.getLinePoint(0).getY();
for (int i = 1; i < line.size(); i++) {
LinePoint p1 = line.getLinePoint(i - 1);
LinePoint p2 = line.getLinePoint(i);
double startTime = p1.getX();
double endTime = p2.getX();
if (adjustPoints) {
startTime = (startTime * durationAdj) + startAdj;
endTime = (endTime * durationAdj) + startAdj;
}
if (renderEnd > 0 && startTime >= renderEnd) {
return;
}
if (endTime <= renderStart) {
lastValue = p2.getY();
continue;
}
if (p1.getX() == p2.getX()) {
if (i == line.size() - 1) {
createParamNote(paramScore, instrId, p2.getX(), .0001f, p2.getY(), p2.getY());
}
continue;
}
// if (p1.getY() == p2.getY() && p1.getY() == lastValue) {
// continue;
// }
double startVal = p1.getY();
double endVal = p2.getY();
if (startTime < renderStart) {
startVal = line.getValue(renderStart);
startTime = renderStart;
}
if (renderEnd > 0 && endTime > renderEnd) {
endVal = line.getValue(renderEnd);
endTime = renderEnd;
}
lastValue = endVal;
double dur;
if (p1.getY() == p2.getY()) {
dur = .0001f;
} else {
dur = endTime - startTime;
}
startTime -= renderStart;
createParamNote(paramScore, instrId, startTime, dur, startVal, endVal);
if (i == line.size() - 1) {
createParamNote(paramScore, instrId, startTime + dur, .0001f, endVal, endVal);
}
}
}
}
Aggregations