net.charlesames.music.ensemble
Class MusicXmlPart

java.lang.Object
  extended by net.charlesames.utility.common.Disposable
      extended by net.charlesames.utility.entity.Entity
          extended by net.charlesames.utility.entity.WriteableEntity
              extended by net.charlesames.music.ensemble.EnsembleEntity
                  extended by net.charlesames.music.ensemble.MusicXmlPart
All Implemented Interfaces:
EntityContainer

public class MusicXmlPart
extends EnsembleEntity

MusicXmlPart objects together define the coarse vertical structure of a MusicXML score.

Author:
Charles Ames

Nested Class Summary
 
Nested classes/interfaces inherited from class net.charlesames.music.ensemble.EnsembleEntity
EnsembleEntity.AttributeTable
 
Method Summary
 boolean check(HtmlBuilder builder)
          Check this component for errors and inconsistencies
 void checkNewStaffID(int value)
          Check if the indicated value is suitable as a new staff id.
 void checkNewStaffName(java.lang.String value)
          Check if the indicated name is suitable as a new staff name.
 void checkVoiceCount(int value)
          Check if the indicated value is suitable as a MusicXML voice count.
 MusicXmlStaff createStaff(int id, java.lang.String name)
          Create a new MusicXmlStaff and attach it to this MusicXmlPart.
 MusicXmlStaff createStaff(java.lang.String name)
          Create a new MusicXmlStaff and attach it to this MusicXmlPart.
static XmlSpec createXmlSpec()
          Create an XML specification for the MusicXmlPart class.
 boolean equals(EnsembleEntity other)
          Check if this entity has the same class and content as another entity.
static MusicXmlPart fromXmlNode(org.w3c.dom.Element element, EnsembleChoir choir)
          Create a new MusicXmlPart instance and fill it with loaded data.
static MusicXmlPart fromXmlRefNode(org.w3c.dom.Element element, Ensemble ensemble)
          Use information in an XML reference node to dereference a MusicXmlPart.
 EnsembleChoir getContainer()
          Getter for the Container property.
 int getDefaultStaffID()
          Generate an unused staff id.
 Ensemble getEnsemble()
          Get the Ensemble which sits on top of the current object hierarchy.
 PartInScore getPartInScore()
          Getter for the PartInScore property.
 java.lang.String getPath()
          Return a description of this entity and its containers.
 java.lang.String getScorePartID()
           
 int getStaffCount()
          Getter for the StaffCount property.
 java.util.SortedMap<java.lang.Integer,MusicXmlStaff> getStavesByID()
          Get the collection of MusicXmlStaff instances defined under this MusicXmlPart.
 java.util.SortedMap<java.lang.String,MusicXmlStaff> getStavesByName()
          Get the collection of MusicXmlStaff instances defined under this MusicXmlPart.
 int getVoiceCount()
          Getter for the VoiceCount property.
 boolean isCompatibleWithVoice(EnsembleVoice voice)
          Test if this MusicXmlPart resides within the indicated voice's choir hierarchy.
 void removeStaff(MusicXmlStaff staff)
          Remove an existing MusicXmlStaff from a MusicXmlPart.
 void resequenceStaves()
          Rebuild the sequence of MusicXmlStaff id's so that the first id is 1 and the sequence proceeds without gaps.
 void setChoir(EnsembleChoir choir)
          Move a EnsembleVoice from its current parent EnsembleChoir to a different EnsembleChoir.
 boolean setID(int id)
          Setter for the ID property.
 boolean setName(java.lang.String name)
          Setter for the Name property.
 void setPartInScore(PartInScore partInScore)
          Getter for the PartInScore property.
 void setVoiceCount(int voiceCount)
          Setter for the VoiceCount property.
 void shiftPartDown(int id)
          Move a specified MusicXmlStaff down within the collection (i.e.
 void shiftPartsDown(int id, int increment)
          Move a block of MusicXmlStaffs down within the collection.
 void shiftPartUp(int id)
          Move a specified MusicXmlStaff up within the collection (i.e.
 java.lang.String toString()
           
 org.w3c.dom.Element toXmlRefNode(org.w3c.dom.Element parent)
          Create an XML node that references this MusicXMLPart.
 void wipe()
          Clear all data in this Entity instance.
 
Methods inherited from class net.charlesames.music.ensemble.EnsembleEntity
buildDescription, copyToClipboard, createIndentCell, createXmlSpec, describeFeature, logError, predecessor
 
Methods inherited from class net.charlesames.utility.entity.WriteableEntity
clearXmlSpecs, createXmlSpec, getTagName, getXmlData, getXmlSpec, getXmlSpec, initializeXsd, isPersistent, logError, logError, makeDirty, putXmlData, save, setPersistent, setStatus, toXmlNode
 
Methods inherited from class net.charlesames.utility.entity.Entity
decrementReferenceCount, dereferenceHandle, dispose, equals, getHandle, getID, getName, getReferenceCount, getStatus, getText, hasContainer, incrementReferenceCount, isModifiable, methodHasOverride, predecessor, resequenceEntities, setContainer, setModifiable, shiftEntitiesDown, shiftEntityDown, shiftEntityUp, successor
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getContainer

public EnsembleChoir getContainer()
Description copied from class: Entity
Getter for the Container property.

Overrides:
getContainer in class EnsembleEntity
Returns:
The assigned Container value.

setChoir

public void setChoir(EnsembleChoir choir)
Move a EnsembleVoice from its current parent EnsembleChoir to a different EnsembleChoir.

Parameters:
choir - The destination {link Choir} instance.

setID

public boolean setID(int id)
Description copied from class: Entity
Setter for the ID property.

Overrides:
setID in class WriteableEntity
Parameters:
id - The intended ID value.
Returns:
True if an ID change actually happened; false otherwise.

setName

public boolean setName(java.lang.String name)
Description copied from class: Entity
Setter for the Name property.

Overrides:
setName in class WriteableEntity
Parameters:
name - The intended Name value.
Returns:
True if a Name change actually happened; false otherwise.

getPath

public java.lang.String getPath()
Description copied from class: Entity
Return a description of this entity and its containers.

Specified by:
getPath in interface EntityContainer
Overrides:
getPath in class Entity
Returns:
A description of this entity and its containers.

getEnsemble

public Ensemble getEnsemble()
Description copied from class: EnsembleEntity
Get the Ensemble which sits on top of the current object hierarchy.

Overrides:
getEnsemble in class EnsembleEntity
Returns:
The Ensemble which sits on top of the current object hierarchy.

getStaffCount

public int getStaffCount()
Getter for the StaffCount property. The StaffCount sets the maximum MusicXmlStaffID for EnsembleVoice instances which reference this MusicXmlPart.

Returns:
The current maximum staff count.

getScorePartID

public java.lang.String getScorePartID()
Returns:
A MusicXML "score part id" fabricated by joining the letter P with the entity ID.

getVoiceCount

public int getVoiceCount()
Getter for the VoiceCount property. The VoiceCount sets the maximum MusicXmlVoiceID for EnsembleVoice instances which reference this MusicXmlPart.

Returns:
The current maximum voice count.

checkVoiceCount

public void checkVoiceCount(int value)
Check if the indicated value is suitable as a MusicXML voice count.

Parameters:
value -

setVoiceCount

public void setVoiceCount(int voiceCount)
Setter for the VoiceCount property. The VoiceCount sets the maximum MusicXmlVoiceID for EnsembleVoice instances which reference this MusicXmlPart.

Parameters:
voiceCount - The intended maximum voice count.

getStavesByID

public java.util.SortedMap<java.lang.Integer,MusicXmlStaff> getStavesByID()
Get the collection of MusicXmlStaff instances defined under this MusicXmlPart.

Returns:
A collection of MusicXmlStaff instances, indexed by staff id.

getStavesByName

public java.util.SortedMap<java.lang.String,MusicXmlStaff> getStavesByName()
Get the collection of MusicXmlStaff instances defined under this MusicXmlPart.

Returns:
A collection of MusicXmlStaff instances, indexed by staff name.

getPartInScore

public PartInScore getPartInScore()
Getter for the PartInScore property.

At the outset of a MusicXML export, a PartInScore instance is allocated for each MusicXmlPart. The Score is processed one ScoreVoice at a time. Score events for the indicated voice cause MusicXML instances to be created within the corresponding

Returns:
The current PartInScore instance.

setPartInScore

public void setPartInScore(PartInScore partInScore)
Getter for the PartInScore property. This property is only used during a MusicXML export; it

Parameters:
partInScore - The intended PartInScore instance.

getDefaultStaffID

public int getDefaultStaffID()
Generate an unused staff id.

Returns:
An unused staff id.

checkNewStaffID

public void checkNewStaffID(int value)
Check if the indicated value is suitable as a new staff id.

Parameters:
value - The indicated value.

checkNewStaffName

public void checkNewStaffName(java.lang.String value)
Check if the indicated name is suitable as a new staff name.

Parameters:
value -

createStaff

public MusicXmlStaff createStaff(int id,
                                 java.lang.String name)
Create a new MusicXmlStaff and attach it to this MusicXmlPart.

Parameters:
id - The intended staff id. Must be positive and unused by any other staff in this part. May not exceed the voice limit.
name - The staff name. Must be unused by any other staff in this part.
Returns:
The newly created MusicXmlStaff instance.

createStaff

public MusicXmlStaff createStaff(java.lang.String name)
Create a new MusicXmlStaff and attach it to this MusicXmlPart. A staff ID is automatically selected.

Parameters:
name - The staff name. Must be unused by any other staff in this part.
Returns:
The newly created MusicXmlStaff instance.

removeStaff

public void removeStaff(MusicXmlStaff staff)
Remove an existing MusicXmlStaff from a MusicXmlPart.

Parameters:
staff - The indicated staff must presently be attached to the current MusicXML part.

check

public boolean check(HtmlBuilder builder)
Check this component for errors and inconsistencies

Overrides:
check in class WriteableEntity
Parameters:
builder - Accumulates an HTML formatted record of each error or inconsistency found.
Returns:
False if any errors or inconsistencies are found; true otherwise.

fromXmlNode

public static MusicXmlPart fromXmlNode(org.w3c.dom.Element element,
                                       EnsembleChoir choir)
Create a new MusicXmlPart instance and fill it with loaded data.

Parameters:
element - The XML element that provides the MusicXmlPart data
choir - The choir which will contain the new MusicXmlPart instance.
Returns:
The newly created MusicXmlPart instance.

fromXmlRefNode

public static MusicXmlPart fromXmlRefNode(org.w3c.dom.Element element,
                                          Ensemble ensemble)
Use information in an XML reference node to dereference a MusicXmlPart.

Parameters:
element - Contains the information necessary to look up the MusicXmlPart instance.
ensemble - The Ensemble which holds the MusicXmlPart.
Returns:
The dereferenced MusicXmlPart.

toXmlRefNode

public org.w3c.dom.Element toXmlRefNode(org.w3c.dom.Element parent)
Create an XML node that references this MusicXMLPart.

Parameters:
parent - The XML node to which the new reference node will be appended.
Returns:
The newly created XML node.

wipe

public void wipe()
Description copied from class: Entity
Clear all data in this Entity instance.

Overrides:
wipe in class Entity

resequenceStaves

public void resequenceStaves()
Rebuild the sequence of MusicXmlStaff id's so that the first id is 1 and the sequence proceeds without gaps.


shiftPartUp

public void shiftPartUp(int id)
Move a specified MusicXmlStaff up within the collection (i.e. decrement its id).

Parameters:
id - The current part id

shiftPartDown

public void shiftPartDown(int id)
Move a specified MusicXmlStaff down within the collection (i.e. increment its id).

Parameters:
id - The current instrument id

shiftPartsDown

public void shiftPartsDown(int id,
                           int increment)
Move a block of MusicXmlStaffs down within the collection.

Parameters:
id - All MusicXmlStaff instances in the collection with id's greater than or equal to the startingID will be shifted down.
increment - Number of positions to shift.

toString

public java.lang.String toString()
Overrides:
toString in class EnsembleEntity

createXmlSpec

public static XmlSpec createXmlSpec()
Create an XML specification for the MusicXmlPart class.

Returns:
The newly created XmlSpec instance.
Throws:
java.lang.RuntimeException - when an XmlSpec instance already exists for the MusicXmlPart class.

equals

public boolean equals(EnsembleEntity other)
Description copied from class: EnsembleEntity
Check if this entity has the same class and content as another entity.

Overrides:
equals in class EnsembleEntity
Parameters:
other - The other entity.
Returns:
True if the two entities have the same class and content; false otherwise.

isCompatibleWithVoice

public boolean isCompatibleWithVoice(EnsembleVoice voice)
Test if this MusicXmlPart resides within the indicated voice's choir hierarchy.

Parameters:
voice - The indicated voice.
Returns:
True if this MusicXmlPart resides within the indicated voice's choir hierarchy; false otherwise.