Package com.softsynth.jmsl.score
Class Measure
java.lang.Object
com.softsynth.jmsl.MusicJob
com.softsynth.jmsl.ParallelCollection
com.softsynth.jmsl.score.Measure
- All Implemented Interfaces:
Composable,Playable,XMLCreatable,XMLWritable,java.lang.Runnable
public class Measure extends ParallelCollection implements XMLWritable, XMLCreatable
Measure
A ParallelCollection of Staff
JMSL Notation Project
A ParallelCollection of Staff
JMSL Notation Project
- Author:
- Nick Didkovsky , copyright 2000 Nick Didkovsky
-
Field Summary
Fields Modifier and Type Field Description static java.lang.Stringcopyrightstatic java.lang.StringDOUBLE_BARLINEstatic doubleFIXED_LEFT_MARGINstatic java.lang.StringNONE_BARLINEstatic java.lang.StringPERIOD_BARLINEstatic java.lang.StringSINGLE_BARLINEFields inherited from class com.softsynth.jmsl.MusicJob
repeatCount -
Constructor Summary
Constructors Constructor Description Measure()Measure(ScoreCollection scoreCollection, Score score, int numStaffs)Measure(ScoreCollection scoreCollection, Score score, int numStaffs, TimeSignature timeSig) -
Method Summary
Modifier and Type Method Description voidaddToWidth(double delta, boolean widthSetByHand)change width of measure, addToWidth(1) adds 1 to width.voidaddUserBean(java.lang.Object bean)Add a bean to a Measure.voidcalcMaxDuration()calculate max duration of each track in each staff of this measure, used for horizontal layoutdoublecalcWidth()Calculate and set measure width.voidcloseMeasurePropertiesXML(java.io.PrintWriter out)java.lang.Objectcreate()XMLCreatable InterfacevoiddeleteStaff(int position)Delete the staff at specified positionvoidfinish()Finish playing ASAP.booleangetAnyClefSetByHand()booleangetBarNone()java.util.PropertiesgetBoundingInfo()booleangetDoubleBar()java.awt.geom.Point2DgetDrawingAnchor()drawingAnchor is the (x,y) point at top left of drawable object, set by layout manager, changes as measures stretch, compress, realign, etcdoublegetHeight()java.lang.StringgetHierarchy()doublegetLeftMargin()doublegetMaxDuration()intgetMeasureIndex()doublegetMeasureLeftMargin()java.lang.StringgetMeasureText()intgetMeasureTextX()intgetMeasureTextY()doublegetNoteAreaWidth()intgetNumRepeats()booleangetPeriodDoubleBar()booleangetRepeatEnd()booleangetRepeatStart()ScoregetScore()booleangetSingleBar()StaffgetStaff(int n)TempogetTempo()booleangetTempoSetByHand()TimeSignaturegetTimeSig()booleangetTimeSigSetByHand()java.util.VectorgetUserBeans()A Measure can have a vector of custom user-defined beans attached to it.doublegetWidth()booleangetWidthSetByHand()voidhalt()Stop all children.voidhandleAttribute(java.lang.String name, java.lang.String value)XMLCreatable InterfacevoidinheritClefsFrom(Measure m)voidinheritFrom(Measure m)Inherit time sig, keysigs, and clefs from specified MeasurevoidinsertStaff(int position)Insert a new staff at specified position, all other staves with index >= position shift up one.doubleinternalRepeat(double playTime)override internalRepeat of ParallelCollection to wait at leat as long as the time sig of this measure requires (keeps empty or incompletely full measures from finishing early)booleanisBeginningOfLine()does this measure begin a layout line?static booleanisConstantMeasureWidth()if true, a measure of 4/4 at a scale of 1.0 will fully occupy the width of a score instead of calculating its width from its contentsvoidlayoutChildren()Sets anchor points for all staves, justifies contents using Blostein/Haken CACM '91 paper algorithmvoidrealign()Calculate width from measure contents.voidremoveUserBean(java.lang.Object bean)voidrender(java.awt.Graphics g, double zoom)voidrenderBars(java.awt.Graphics g, double x, double w, double leftBarTop, double leftBarBottom, double rightBarTop, double rightBarBottom, double unsharedLeftBarTop, double unsharedLeftBarBottom, double zoom)voidresetLeftMargin()voidsetBarNone(boolean f)Set barline to a single linestatic voidsetConstantMeasureWidth(boolean useConstantMeasureWidth)if true, a measure of 4/4 at a scale of 1.0 will fully occupy the width of a score instead of calculating its width from its contentsvoidsetDisplayClef(boolean flag)notify all children whether or not to render their clefs, and make space for it.voidsetDisplayKeySignature(boolean flag)notify all children whether or not to render their keysignatures, and updates left margin to make space.voidsetDisplayTimeSig(boolean flag)notify all children whether or not to render their timesig'svoidsetDoubleBar(boolean f)voidsetDrawingAnchor(java.awt.geom.Point2D p)drawingAnchor is the (x,y) point at top left of drawable object, set by layout manager, changes as measures stretch, compress, realign, etc
Note that drawingAnchor's location is copied from the location of the argument.voidsetMeasureLeftMargin(double lm)voidsetMeasureNumber(int n)for rendering purposesvoidsetMeasureText(java.lang.String measureText)voidsetMeasureTextX(int x)voidsetMeasureTextY(int y)voidsetNumRepeats(int n)voidsetPeriodDoubleBar(boolean periodDoubleBar)voidsetRepeatEnd(boolean f)voidsetRepeatStart(boolean f)voidsetSingleBar()Set barline to a single linevoidsetTempo(double bpm)voidsetTempo(int bpm, boolean setByHand)Set tempo and mark measure so it displays tempo graphically and blocks previous tempo changes made in GUI from clobbering itvoidsetTempo(Tempo tempo)voidsetTempo(Tempo tempo, boolean setByHand)Set tempo and mark measure so it displays tempo graphically and blocks previous tempo changes made in GUI from clobbering itvoidsetTempoSetByHand(boolean flag)Mark this measure as having tenmpo set by hand.voidsetTimeSig(int numer, int denom)voidsetTimeSig(TimeSignature ts)voidsetTimeSig(java.lang.String s)Set from a blank delimitted string like "6 8"voidsetTimeSigSetByHand(boolean flag)voidsetWidth(double w)set layout widthvoidsetWidth(double w, boolean widthSetByHand)set layout widthvoidsetWidthSetByHand(boolean flag)Mark this measure as having width set by hand.doublestart(double startTime)Setup method called once when run() begins.java.lang.StringtoString()booleanwithin(java.awt.geom.Point2D p)voidwriteMeasurePropertiesXML(java.io.PrintWriter out)voidwriteXML(java.io.PrintWriter out)Methods inherited from class com.softsynth.jmsl.ParallelCollection
get, main, print, printHierarchy, setMethods inherited from class com.softsynth.jmsl.MusicJob
add, addPlayLurker, addRepeatPlayable, addStartPlayable, addStopPlayable, advanceCurrentTime, contains, elements, finishAll, getChild, getChildren, getCurrentTime, getDataTranslator, getDuration, getInstrument, getName, getParent, getPlayLurkers, getRepeatCount, getRepeatPause, getRepeatPlayables, getRepeats, getStartDelay, getStartPause, getStartPlayables, getStartTime, getStopDelay, getStopPlayables, getTimeStretch, getTransposition, indexOf, insert, isRunning, launch, launch, play, play, printHierarchy, remove, remove, removeAll, removeAllPlayLurkers, removeAllRepeatPlayables, removeAllStartPlayables, removeAllStopPlayables, removePlayLurker, removeRepeatPlayable, removeStartPlayable, removeStopPlayable, repeat, run, setCurrentTime, setDataTranslator, setDuration, setInstrument, setName, setParent, setRepeatPause, setRepeats, setStartDelay, setStartPause, setStartTime, setStopDelay, setTimeStretch, setTransposition, size, stop, timeStretch, transposition, waitForDoneMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
SINGLE_BARLINE
public static final java.lang.String SINGLE_BARLINE- See Also:
- Constant Field Values
-
DOUBLE_BARLINE
public static final java.lang.String DOUBLE_BARLINE- See Also:
- Constant Field Values
-
PERIOD_BARLINE
public static final java.lang.String PERIOD_BARLINE- See Also:
- Constant Field Values
-
NONE_BARLINE
public static final java.lang.String NONE_BARLINE- See Also:
- Constant Field Values
-
FIXED_LEFT_MARGIN
public static final double FIXED_LEFT_MARGIN- See Also:
- Constant Field Values
-
copyright
public static final java.lang.String copyright- See Also:
- Constant Field Values
-
-
Constructor Details
-
Measure
public Measure() -
Measure
-
Measure
-
-
Method Details
-
start
public double start(double startTime)Description copied from class:MusicJobSetup method called once when run() begins. Override this for custom setup.- Specified by:
startin interfaceComposable- Overrides:
startin classMusicJob- Returns:
- endTime
-
handleAttribute
public void handleAttribute(java.lang.String name, java.lang.String value)XMLCreatable Interface- Specified by:
handleAttributein interfaceXMLCreatable
-
create
public java.lang.Object create()XMLCreatable Interface- Specified by:
createin interfaceXMLCreatable
-
insertStaff
public void insertStaff(int position)Insert a new staff at specified position, all other staves with index >= position shift up one. If position == size(), append. -
deleteStaff
public void deleteStaff(int position)Delete the staff at specified position -
internalRepeat
public double internalRepeat(double playTime) throws java.lang.InterruptedExceptionoverride internalRepeat of ParallelCollection to wait at leat as long as the time sig of this measure requires (keeps empty or incompletely full measures from finishing early)- Specified by:
internalRepeatin interfaceComposable- Overrides:
internalRepeatin classParallelCollection- Returns:
- stopTime
- Throws:
java.lang.InterruptedException- thrown if Thread.interrupt() called.
-
inheritClefsFrom
-
inheritFrom
Inherit time sig, keysigs, and clefs from specified Measure -
calcWidth
public double calcWidth()Calculate and set measure width. If isConstantMeasureWidth, then set width linearly from time signature, else set width from contents- Returns:
- width
-
realign
public void realign()Calculate width from measure contents. Set "by hand" flag to false -
getTempo
-
setTempo
public void setTempo(double bpm) -
setTempo
-
setTempo
public void setTempo(int bpm, boolean setByHand)Set tempo and mark measure so it displays tempo graphically and blocks previous tempo changes made in GUI from clobbering it -
setTempo
Set tempo and mark measure so it displays tempo graphically and blocks previous tempo changes made in GUI from clobbering it -
setTempoSetByHand
public void setTempoSetByHand(boolean flag)Mark this measure as having tenmpo set by hand. This results in the tempo being displayed graphically instead of hidden. -
getTempoSetByHand
public boolean getTempoSetByHand() -
setWidthSetByHand
public void setWidthSetByHand(boolean flag)Mark this measure as having width set by hand. This prevents recalculating width from measure's contents -
getWidthSetByHand
public boolean getWidthSetByHand() -
getAnyClefSetByHand
public boolean getAnyClefSetByHand()- Returns:
- true if any staff's clef had been set by hand
-
setTimeSigSetByHand
public void setTimeSigSetByHand(boolean flag) -
getTimeSigSetByHand
public boolean getTimeSigSetByHand() -
calcMaxDuration
public void calcMaxDuration()calculate max duration of each track in each staff of this measure, used for horizontal layout -
getMaxDuration
public double getMaxDuration() -
getTimeSig
- Returns:
- time signature of this measure
-
setTimeSig
-
setTimeSig
public void setTimeSig(int numer, int denom) -
setTimeSig
public void setTimeSig(java.lang.String s)Set from a blank delimitted string like "6 8" -
resetLeftMargin
public void resetLeftMargin() -
setMeasureLeftMargin
public void setMeasureLeftMargin(double lm) -
getMeasureLeftMargin
public double getMeasureLeftMargin() -
setDisplayClef
public void setDisplayClef(boolean flag)notify all children whether or not to render their clefs, and make space for it. -
setDisplayTimeSig
public void setDisplayTimeSig(boolean flag)notify all children whether or not to render their timesig's -
setDisplayKeySignature
public void setDisplayKeySignature(boolean flag)notify all children whether or not to render their keysignatures, and updates left margin to make space. -
setRepeatStart
public void setRepeatStart(boolean f) -
setRepeatEnd
public void setRepeatEnd(boolean f) -
setDoubleBar
public void setDoubleBar(boolean f) -
getDoubleBar
public boolean getDoubleBar() -
getPeriodDoubleBar
public boolean getPeriodDoubleBar()- Returns:
- true if measure has "period" double bar (ie end of piece, one thick and one thin line)
-
setPeriodDoubleBar
public void setPeriodDoubleBar(boolean periodDoubleBar)- Parameters:
periodDoubleBar- true if measure has "period" double bar (ie end of piece, one thick and one thin line)
-
getSingleBar
public boolean getSingleBar()- Returns:
- true if measure has "single" bar (ie one line)
-
setSingleBar
public void setSingleBar()Set barline to a single line -
getBarNone
public boolean getBarNone()- Returns:
- true if measure has "none" bar (ie invisible)
-
setBarNone
public void setBarNone(boolean f)Set barline to a single line -
getRepeatStart
public boolean getRepeatStart()- Returns:
- true if this measure is a start repeat
-
getRepeatEnd
public boolean getRepeatEnd()- Returns:
- true if this measure is end repeat
-
setNumRepeats
public void setNumRepeats(int n) -
getNumRepeats
public int getNumRepeats() -
isBeginningOfLine
public boolean isBeginningOfLine()does this measure begin a layout line?- Returns:
- true if measure is the first measure in a system
-
getLeftMargin
public double getLeftMargin()- Returns:
- value of leftPositionCursor (larger if timesig is displayed for example)
-
getNoteAreaWidth
public double getNoteAreaWidth()- Returns:
- total drawable width for notes
-
getHeight
public double getHeight()- Returns:
- the total height of this measure, ie sum of all staffs plus space above plus space below each
-
getWidth
public double getWidth()- Returns:
- layout width off measure
-
setWidth
public void setWidth(double w)set layout width -
setWidth
public void setWidth(double w, boolean widthSetByHand)set layout width -
addToWidth
public void addToWidth(double delta, boolean widthSetByHand)change width of measure, addToWidth(1) adds 1 to width. Set flag to indicate "by hand" or not. Measures set by hand do not grow and shrink as contents changes. -
getScore
- Returns:
- Score to which this Measure belongs
-
getStaff
- Returns:
- Staff element # n
-
getHierarchy
public java.lang.String getHierarchy() -
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
setDrawingAnchor
public void setDrawingAnchor(java.awt.geom.Point2D p)drawingAnchor is the (x,y) point at top left of drawable object, set by layout manager, changes as measures stretch, compress, realign, etc
Note that drawingAnchor's location is copied from the location of the argument. -
setMeasureNumber
public void setMeasureNumber(int n)for rendering purposes -
getMeasureIndex
public int getMeasureIndex()- Returns:
- index of this measure.
-
getDrawingAnchor
public java.awt.geom.Point2D getDrawingAnchor()drawingAnchor is the (x,y) point at top left of drawable object, set by layout manager, changes as measures stretch, compress, realign, etc -
layoutChildren
public void layoutChildren()Sets anchor points for all staves, justifies contents using Blostein/Haken CACM '91 paper algorithm -
within
public boolean within(java.awt.geom.Point2D p)- Returns:
- true if Point falls within measure's bounding box
-
renderBars
public void renderBars(java.awt.Graphics g, double x, double w, double leftBarTop, double leftBarBottom, double rightBarTop, double rightBarBottom, double unsharedLeftBarTop, double unsharedLeftBarBottom, double zoom) -
getBoundingInfo
public java.util.Properties getBoundingInfo() -
render
public void render(java.awt.Graphics g, double zoom) -
writeXML
public void writeXML(java.io.PrintWriter out) throws java.io.IOException- Specified by:
writeXMLin interfaceXMLWritable- Throws:
java.io.IOException
-
closeMeasurePropertiesXML
public void closeMeasurePropertiesXML(java.io.PrintWriter out)- Parameters:
out-
-
writeMeasurePropertiesXML
public void writeMeasurePropertiesXML(java.io.PrintWriter out)- Parameters:
out-
-
getUserBeans
public java.util.Vector getUserBeans()A Measure can have a vector of custom user-defined beans attached to it. These will be saved to a file with a Score and reloaded as well. The objects must be beans (ie have private simple data types with matching getters and setters.- Returns:
- Returns vector of beans.
-
addUserBean
public void addUserBean(java.lang.Object bean)Add a bean to a Measure. A bean is an object with primitive fields and matching getters and setters. These will be restored when loaded.- Parameters:
bean- The bean to add.
-
removeUserBean
public void removeUserBean(java.lang.Object bean) -
isConstantMeasureWidth
public static boolean isConstantMeasureWidth()if true, a measure of 4/4 at a scale of 1.0 will fully occupy the width of a score instead of calculating its width from its contents- Returns:
- Returns the useConstantMeasureWidth.
-
setConstantMeasureWidth
public static void setConstantMeasureWidth(boolean useConstantMeasureWidth)if true, a measure of 4/4 at a scale of 1.0 will fully occupy the width of a score instead of calculating its width from its contents- Parameters:
useConstantMeasureWidth- The useConstantMeasureWidth to set.
-
getMeasureText
public java.lang.String getMeasureText()- Returns:
- Returns the measureText.
-
setMeasureText
public void setMeasureText(java.lang.String measureText)- Parameters:
measureText- The measureText to set.
-
getMeasureTextX
public int getMeasureTextX()- Returns:
- Returns the measureTextX.
-
setMeasureTextX
public void setMeasureTextX(int x)- Parameters:
measureTextX- The measureText x Location to set.
-
getMeasureTextY
public int getMeasureTextY()- Returns:
- Returns the measureTextY
-
setMeasureTextY
public void setMeasureTextY(int y)- Parameters:
measureTextY- The measureText y Location to set.
-
halt
public void halt()Description copied from class:ParallelCollectionStop all children.- Specified by:
haltin interfaceComposable- Overrides:
haltin classParallelCollection
-
finish
public void finish()Description copied from interface:ComposableFinish playing ASAP.- Specified by:
finishin interfaceComposable- Overrides:
finishin classMusicJob
-