Skip to content

Commit

Permalink
Modified mixer generation code to handle situations where generated i…
Browse files Browse the repository at this point in the history
…nstruments do not have corresponding mixer channels, as is the case with Sound SoundObjects [fixes #337]
  • Loading branch information
kunstmusik committed Feb 21, 2017
1 parent ce22692 commit 95575f4
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 40 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ FIX
* Issue #352 - MIDI import was not updated correctly newer ScoreLayer system,
also, velocity was not processed correctly yielding only zeros

# Issue #337 - Fixed Mixer generation when no instruments found in Orchestra;
condition appears when using only Sound SoundObjects in project

INTERNAL

* Replaced use of Cloneable and Serializable with copy constructors and new
Expand Down
103 changes: 63 additions & 40 deletions blue-core/src/blue/Arrangement.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ public class Arrangement implements TableModel {
public Arrangement() {
}

/** Copy Constructor */
public Arrangement(Arrangement arr){
for(InstrumentAssignment ia :arr.getArrangement()) {
/**
* Copy Constructor
*/
public Arrangement(Arrangement arr) {
for (InstrumentAssignment ia : arr.getArrangement()) {
arrangement.add(new InstrumentAssignment(ia));
}
}
}

public int addInstrument(Instrument instrument) {
Expand Down Expand Up @@ -377,7 +379,7 @@ public String generateGlobalSco(CompileData data) {
if ((assignmentId = data.getInstrSourceId(instr)) == null) {
assignmentId = ia.arrangementId;
}

String transformed = replaceInstrumentId(assignmentId, globalSco);

retVal.append(transformed);
Expand Down Expand Up @@ -561,31 +563,27 @@ private String replaceInstrumentId(String arrangementId, String input) {
return transformed;
}

private Channel getChannelForArrangementId(Mixer mixer, String arrangementId) {
if (mixer != null) {
for (Channel channel : mixer.getAllSourceChannels()) {
if (channel.getName().equals(arrangementId)) {
return channel;
}
}

}
return null;
}

// TODO - Make this more efficient (made this way in case blueMixerOut is in
// comments
private String convertBlueMixerOut(CompileData data, Mixer mixer, String arrangementId,
String input, int nchnls) {

Channel c = null;

if (!input.contains("blueMixerOut") && !input.contains("blueMixerIn")) {
return input;
}

if (mixer != null) {
for (Channel channel : mixer.getAllSourceChannels()) {
if (channel.getName().equals(arrangementId)) {
c = channel;
break;
}
}

if (c == null) {
throw new RuntimeException(
"Unable to find channel for instrument: " + arrangementId);
}
}

StrBuilder buffer = new StrBuilder();
String[] lines = NEW_LINES.split(input);

Expand Down Expand Up @@ -615,12 +613,19 @@ private String convertBlueMixerOut(CompileData data, Mixer mixer, String arrange
String argText = noCommentLine.substring(0, mixerInIndex).trim();

String[] args = argText.split(",");
Channel c = getChannelForArrangementId(mixer, arrangementId);

for (int i = 0; i < nchnls && i < args.length; i++) {
String arg = args[i];

String var = Mixer.getChannelVar(
data.getChannelIdAssignments().get(c), i);
String var;

if (c == null) {
var = Mixer.getSubChannelVar(Channel.MASTER, i);
} else {
var = Mixer.getChannelVar(
data.getChannelIdAssignments().get(c), i);
}

buffer.append(arg).append(" = ");
buffer.append(var).append("\n");
Expand Down Expand Up @@ -648,9 +653,20 @@ private String convertBlueMixerOut(CompileData data, Mixer mixer, String arrange

buffer.append("\n");
} else {
String subChannelName = args[0].trim();
subChannelName = subChannelName.substring(1,
subChannelName.length() - 1);
String subChanBase = args[0].trim();
final String subChannelName = subChanBase.substring(1,
subChanBase.length() - 1);

Optional<Channel> found = mixer.getSubChannels().stream()
.filter(chn -> subChannelName.equals(chn.getName()))
.findFirst();

if (!found.isPresent()) {
throw new RuntimeException(
"Unable to find subchannel with name: "
+ subChannelName);
}

mixer.addSubChannelDependency(subChannelName);

for (int i = 1; i < nchnls + 1 && i < args.length; i++) {
Expand All @@ -659,13 +675,13 @@ private String convertBlueMixerOut(CompileData data, Mixer mixer, String arrange
String var = Mixer.getSubChannelVar(subChannelName,
i - 1);

buffer.append(var);
buffer.append(var);

if (!blueMixerInFound) {
buffer.append(" += ");
buffer.append(" += ");
} else {
buffer.append(" = ");
}
buffer.append(" = ");
}

buffer.append(arg).append("\n");

Expand All @@ -676,21 +692,28 @@ private String convertBlueMixerOut(CompileData data, Mixer mixer, String arrange
buffer.append(line.replaceAll("blueMixerOut", "outc"));
buffer.append("\n");
} else {

Channel c = getChannelForArrangementId(mixer, arrangementId);
for (int i = 0; i < nchnls && i < args.length; i++) {
String arg = args[i];

String var = Mixer.getChannelVar(
data.getChannelIdAssignments().get(c), i);
String var;

if (c == null) {
var = Mixer.getSubChannelVar(Channel.MASTER, i);
} else {
var = Mixer.getChannelVar(
data.getChannelIdAssignments().get(c), i);
}

buffer.append(var);

if (!blueMixerInFound) {
buffer.append(" += ");
} else {
buffer.append(" = ");
}
if (!blueMixerInFound) {
buffer.append(" += ");
} else {
buffer.append(" = ");
}

buffer.append(arg).append("\n");
buffer.append(arg).append("\n");

}
}
Expand Down Expand Up @@ -747,7 +770,7 @@ public static Arrangement loadFromXML(Element data,
}

return arr;
}
}

public Element saveAsXML() {
Element retVal = new Element("arrangement");
Expand Down

0 comments on commit 95575f4

Please sign in to comment.