use of blue.soundObject.pattern.Pattern in project blue by kunstmusik.
the class PatternObject method setTime.
public void setTime(int beats, int subDivisions) {
if (this.beats == beats && this.subDivisions == subDivisions) {
return;
}
this.beats = beats;
this.subDivisions = subDivisions;
int numBeats = beats * subDivisions;
for (Iterator iter = patterns.iterator(); iter.hasNext(); ) {
Pattern p = (Pattern) iter.next();
p.values = new boolean[numBeats];
for (int i = 0; i < p.values.length; i++) {
p.values[i] = false;
}
}
PropertyChangeEvent pce = new PropertyChangeEvent(this, "time", null, null);
firePropertyChangeEvent(pce);
}
use of blue.soundObject.pattern.Pattern in project blue by kunstmusik.
the class PatternObject method saveAsXML.
@Override
public Element saveAsXML(Map<Object, String> objRefMap) {
Element retVal = SoundObjectUtilities.getBasicXML(this);
retVal.addElement("beats").setText(Integer.toString(beats));
retVal.addElement("subDivisions").setText(Integer.toString(subDivisions));
Element patternsNode = new Element("patterns");
retVal.addElement(patternsNode);
for (Iterator iter = patterns.iterator(); iter.hasNext(); ) {
Pattern element = (Pattern) iter.next();
patternsNode.addElement(element.saveAsXML());
}
return retVal;
}
use of blue.soundObject.pattern.Pattern in project blue by kunstmusik.
the class PatternObject method pushUpPatternLayers.
public void pushUpPatternLayers(int[] rows) {
Pattern a = patterns.remove(rows[0] - 1);
patterns.add(rows[rows.length - 1], a);
this.fireTableDataChanged();
}
use of blue.soundObject.pattern.Pattern in project blue by kunstmusik.
the class PatternObject method loadFromXML.
/* SERIALIZATION */
public static SoundObject loadFromXML(Element data, Map<String, Object> objRefMap) throws Exception {
PatternObject pattern = new PatternObject();
SoundObjectUtilities.initBasicFromXML(data, pattern);
Elements nodes = data.getElements();
while (nodes.hasMoreElements()) {
Element node = nodes.next();
String nodeName = node.getName();
switch(nodeName) {
case "beats":
pattern.setBeats(Integer.parseInt(node.getTextString()));
break;
case "subDivisions":
pattern.setSubDivisions(Integer.parseInt(node.getTextString()));
break;
case "patterns":
Elements patternNodes = node.getElements();
while (patternNodes.hasMoreElements()) {
Pattern p = Pattern.loadFromXML(patternNodes.next());
pattern.addPattern(p);
}
break;
}
}
return pattern;
}
use of blue.soundObject.pattern.Pattern in project blue by kunstmusik.
the class PatternObjectTest method testClone.
public void testClone() {
PatternObject p = new PatternObject();
p.addPattern(0);
p.addPattern(0);
p.addPattern(0);
for (int i = 0; i < p.size(); i++) {
Pattern pat = p.getPattern(i);
for (int j = 0; j < pat.values.length; j++) {
pat.values[j] = (Math.random() > 0.5d);
}
}
SoundObject clone = p.deepCopy();
boolean isEqual = EqualsBuilder.reflectionEquals(p, clone);
if (!isEqual) {
StringBuilder buffer = new StringBuilder();
buffer.append("Problem with Pattern\n");
buffer.append("Original Object\n");
buffer.append(ToStringBuilder.reflectionToString(p)).append("\n");
buffer.append("Cloned Object\n");
buffer.append(ToStringBuilder.reflectionToString(clone)).append("\n");
System.out.println(buffer.toString());
}
assertTrue(isEqual);
assertEquals(p.saveAsXML(null).toString(), clone.saveAsXML(null).toString());
}
Aggregations