Skip to content

Commit fbc7672

Browse files
committed
fix: update to use toBeats() with new time units
1 parent 5ccba09 commit fbc7672

File tree

4 files changed

+78
-11
lines changed

4 files changed

+78
-11
lines changed

blue-core/src/main/java/blue/soundObject/ObjectBuilder.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,9 @@ public NoteList generateNotes(TimeContext context, BSBCompilationUnit bsbCompila
9292
String tempScore = null;
9393
NoteList nl;
9494

95-
Map<String, Object> initVals = new HashMap<>();
96-
9795
File currentDirFile = BlueSystem.getCurrentProjectDirectory();
98-
99-
initVals.put("score", "");
100-
initVals.put("blueDuration", getSubjectiveDuration());
101-
initVals.put("commandline", this.commandLine);
102-
initVals.put("blueProjectDir", currentDirFile);
96+
Map<String, Object> initVals = createScoreScriptInitValues(context,
97+
currentDirFile);
10398

10499
ScoreScriptEngine engine
105100
= ScoreScriptEngineManager.getInstance().getEngine(
@@ -137,6 +132,16 @@ public NoteList generateNotes(TimeContext context, BSBCompilationUnit bsbCompila
137132
return nl;
138133
}
139134

135+
Map<String, Object> createScoreScriptInitValues(TimeContext context,
136+
File currentDirFile) {
137+
Map<String, Object> initVals = new HashMap<>();
138+
initVals.put("score", "");
139+
initVals.put("blueDuration", getSubjectiveDuration().toBeats(context));
140+
initVals.put("commandline", this.commandLine);
141+
initVals.put("blueProjectDir", currentDirFile);
142+
return initVals;
143+
}
144+
140145
private String getIOExceptionMessage() {
141146
System.out
142147
.println("[Error] Score Generation failed in ObjectBuilder soundObject labeled "

blue-core/src/main/java/blue/soundObject/Sound.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,22 @@ public final StringProperty commentProperty() {
124124
return comment;
125125
}
126126

127-
public NoteList generateNotes(int instrumentNumber, double renderStart, double renderEnd) throws SoundObjectException {
127+
public NoteList generateNotes(TimeContext context, int instrumentNumber,
128+
double renderStart, double renderEnd) throws SoundObjectException {
128129
NoteList n = new NoteList();
129130

130-
String noteText = "i" + instrumentNumber + "\t" + getStartTime() + "\t"
131-
+ getSubjectiveDuration();
131+
final double subjectiveDuration = getSubjectiveDuration().toBeats(context);
132+
double newDur = subjectiveDuration;
133+
134+
if (renderEnd > 0 && renderEnd < subjectiveDuration) {
135+
newDur = renderEnd;
136+
}
137+
138+
newDur = newDur - renderStart;
139+
140+
String noteText = "i" + instrumentNumber + "\t"
141+
+ (getStartTime().toBeats(context) + renderStart) + "\t"
142+
+ newDur;
132143

133144
Note tempNote = null;
134145

@@ -217,7 +228,7 @@ public NoteList generateForCSD(TimeContext context, CompileData compileData, dou
217228
bsbObj.getParameterList().clearCompilationVarNames();
218229
int instrNum = compileData.addInstrument(bsbObj);
219230

220-
return generateNotes(instrNum, startTime, endTime);
231+
return generateNotes(context, instrNum, startTime, endTime);
221232

222233
}
223234

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package blue.soundObject;
2+
3+
import blue.time.TimeContext;
4+
import blue.time.TimeDuration;
5+
import java.io.File;
6+
import java.util.Map;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
9+
import org.junit.jupiter.api.Test;
10+
11+
class ObjectBuilderTest {
12+
13+
@Test
14+
void testCreateScoreScriptInitValuesUsesNumericBlueDuration() {
15+
TimeContext context = new TimeContext();
16+
ObjectBuilder objectBuilder = new ObjectBuilder();
17+
objectBuilder.setSubjectiveDuration(TimeDuration.bbt(1, 0, 0));
18+
19+
Map<String, Object> initValues = objectBuilder.createScoreScriptInitValues(
20+
context, new File("."));
21+
22+
assertInstanceOf(Double.class, initValues.get("blueDuration"));
23+
assertEquals(4.0, (Double) initValues.get("blueDuration"), 0.0001);
24+
}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package blue.soundObject;
2+
3+
import blue.CompileData;
4+
import blue.time.TimeContext;
5+
import blue.time.TimeDuration;
6+
import blue.time.TimePosition;
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import org.junit.jupiter.api.Test;
9+
10+
class SoundTest {
11+
12+
@Test
13+
void testGenerateForCSDConvertsTimeUnitsAndClipsPartialRender() throws Exception {
14+
TimeContext context = new TimeContext();
15+
Sound sound = new Sound();
16+
sound.setStartTime(TimePosition.bbt(2, 1, 0));
17+
sound.setSubjectiveDuration(TimeDuration.bbt(1, 0, 0));
18+
19+
NoteList notes = sound.generateForCSD(context,
20+
CompileData.createEmptyCompileData(), 1.0, 3.0);
21+
22+
assertEquals(1, notes.size());
23+
assertEquals(5.0, notes.get(0).getStartTime(), 0.0001);
24+
assertEquals(2.0, notes.get(0).getSubjectiveDuration(), 0.0001);
25+
}
26+
}

0 commit comments

Comments
 (0)