Search in sources :

Example 1 with Pattern

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);
}
Also used : Pattern(blue.soundObject.pattern.Pattern) PropertyChangeEvent(java.beans.PropertyChangeEvent) Iterator(java.util.Iterator)

Example 2 with Pattern

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;
}
Also used : Pattern(blue.soundObject.pattern.Pattern) Element(electric.xml.Element) Iterator(java.util.Iterator)

Example 3 with Pattern

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();
}
Also used : Pattern(blue.soundObject.pattern.Pattern)

Example 4 with Pattern

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;
}
Also used : Pattern(blue.soundObject.pattern.Pattern) Element(electric.xml.Element) Elements(electric.xml.Elements)

Example 5 with 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());
}
Also used : Pattern(blue.soundObject.pattern.Pattern) ToStringBuilder(org.apache.commons.lang3.builder.ToStringBuilder)

Aggregations

Pattern (blue.soundObject.pattern.Pattern)11 Element (electric.xml.Element)2 Iterator (java.util.Iterator)2 NoteProcessorException (blue.noteProcessor.NoteProcessorException)1 Elements (electric.xml.Elements)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 ToStringBuilder (org.apache.commons.lang3.builder.ToStringBuilder)1