public static Attributes CreateAttribute(AttributeProperties ai) { ObjectFactory factory = new ObjectFactory(); Attributes attributes = factory.createAttributes(); //create a key Key key = factory.createKey(); //create a time element Time time = factory.createTime(); //create a clef element Clef clef = factory.createClef(); //set the staffs attributes.setStaves(new BigInteger(ai.staves.ToString())); //now add the elements to the attributes if (ai.divisions != 0) { //set the divisions attributes.setDivisions(new BigDecimal(ai.divisions)); } if (ai.fifths != "") { //set the key key.setFifths(new BigInteger(ai.fifths)); key.setMode(ai.mode); //add the key attributes.getKey().add(key); } if (ai.BeatsPerMeasure != "") { //set the time signature time.getTimeSignature().add(factory.createTimeBeats(ai.BeatsPerMeasure)); time.getTimeSignature().add(factory.createTimeBeatType(ai.BeatType)); // add the time signature attributes.getTime().add(time); } // add the cleff if (ai.ClefSign != "") { //set the clef clef.setSign(ClefSign.fromValue(ai.ClefSign)); clef.setLine(new BigInteger(ai.ClefLine)); clef.setNumber(new BigInteger(ai.ClefStaff.ToString())); attributes.getClef().add(clef); } return(attributes); }
public static Attributes EditAttributes(ScorePartwise.Part.Measure measure, AttributeProperties editprop) { AttributeProperties attprop = ReadDS.ReadAttributes(measure); //if the edited properties are other than the default than assign them to the scoreprop attprop.fifths = editprop.fifths == ""? attprop.fifths: editprop.fifths; attprop.mode = editprop.mode == ""? attprop.mode: editprop.mode; attprop.BeatsPerMeasure = editprop.BeatsPerMeasure == ""? attprop.BeatsPerMeasure: editprop.BeatsPerMeasure; attprop.BeatType = editprop.BeatType == ""? attprop.BeatType: editprop.BeatType; attprop.ClefSign = editprop.ClefSign == ""? attprop.ClefSign: editprop.ClefSign; attprop.ClefLine = editprop.ClefLine == ""? attprop.ClefLine: editprop.ClefLine; attprop.divisions = editprop.divisions == 0? attprop.divisions: editprop.divisions; attprop.staves = editprop.staves == 1? attprop.staves:editprop.staves; return(CreateDS.CreateAttribute(attprop)); }
//Read the attribute public static AttributeProperties ReadAttributes(ScorePartwise.Part.Measure measure) { /* get the attributes Initialization properties */ for (int i = 0; i < measure.getNoteOrBackupOrForward().size(); i++) { if (measure.getNoteOrBackupOrForward().get(i) is Attributes) { Attributes attribute = (Attributes)measure.getNoteOrBackupOrForward().get(i); AttributeProperties attprop = new AttributeProperties(); if (attribute.getKey().size() > 0) { Key key = (Key)attribute.getKey().get(0); attprop.fifths = key.getFifths().toString(); attprop.mode = key.getMode(); } if (attribute.getClef().size() > 0) { Clef clef = (Clef)attribute.getClef().get(0); attprop.ClefSign = clef.getSign().name(); attprop.ClefLine = clef.getLine().toString(); } if (attribute.getTime().size() > 0) { Time time = (Time)attribute.getTime().get(0); javax.xml.bind.JAXBElement x = (javax.xml.bind.JAXBElement)time.getTimeSignature().get(0); attprop.BeatsPerMeasure = (string)x.getValue(); x = (javax.xml.bind.JAXBElement)time.getTimeSignature().get(1); attprop.BeatType = (string)x.getValue(); } if (attribute.getDivisions() is BigDecimal) { attprop.divisions = attribute.getDivisions().intValue(); } attprop.staves = attribute.getStaves() is BigInteger?attribute.getStaves().intValue() : 1; return(attprop); } } return(null); }