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.String
copyright
static java.lang.String
DOUBLE_BARLINE
static double
FIXED_LEFT_MARGIN
static java.lang.String
NONE_BARLINE
static java.lang.String
PERIOD_BARLINE
static java.lang.String
SINGLE_BARLINE
Fields 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 void
addToWidth(double delta, boolean widthSetByHand)
change width of measure, addToWidth(1) adds 1 to width.void
addUserBean(java.lang.Object bean)
Add a bean to a Measure.void
calcMaxDuration()
calculate max duration of each track in each staff of this measure, used for horizontal layoutdouble
calcWidth()
Calculate and set measure width.void
closeMeasurePropertiesXML(java.io.PrintWriter out)
java.lang.Object
create()
XMLCreatable Interfacevoid
deleteStaff(int position)
Delete the staff at specified positionvoid
finish()
Finish playing ASAP.boolean
getAnyClefSetByHand()
boolean
getBarNone()
java.util.Properties
getBoundingInfo()
boolean
getDoubleBar()
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, etcdouble
getHeight()
java.lang.String
getHierarchy()
double
getLeftMargin()
double
getMaxDuration()
int
getMeasureIndex()
double
getMeasureLeftMargin()
java.lang.String
getMeasureText()
int
getMeasureTextX()
int
getMeasureTextY()
double
getNoteAreaWidth()
int
getNumRepeats()
boolean
getPeriodDoubleBar()
boolean
getRepeatEnd()
boolean
getRepeatStart()
Score
getScore()
boolean
getSingleBar()
Staff
getStaff(int n)
Tempo
getTempo()
boolean
getTempoSetByHand()
TimeSignature
getTimeSig()
boolean
getTimeSigSetByHand()
java.util.Vector
getUserBeans()
A Measure can have a vector of custom user-defined beans attached to it.double
getWidth()
boolean
getWidthSetByHand()
void
halt()
Stop all children.void
handleAttribute(java.lang.String name, java.lang.String value)
XMLCreatable Interfacevoid
inheritClefsFrom(Measure m)
void
inheritFrom(Measure m)
Inherit time sig, keysigs, and clefs from specified Measurevoid
insertStaff(int position)
Insert a new staff at specified position, all other staves with index >= position shift up one.double
internalRepeat(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)boolean
isBeginningOfLine()
does this measure begin a layout line?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 contentsvoid
layoutChildren()
Sets anchor points for all staves, justifies contents using Blostein/Haken CACM '91 paper algorithmvoid
realign()
Calculate width from measure contents.void
removeUserBean(java.lang.Object bean)
void
render(java.awt.Graphics g, double zoom)
void
renderBars(java.awt.Graphics g, double x, double w, double leftBarTop, double leftBarBottom, double rightBarTop, double rightBarBottom, double unsharedLeftBarTop, double unsharedLeftBarBottom, double zoom)
void
resetLeftMargin()
void
setBarNone(boolean f)
Set barline to a single linestatic 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 contentsvoid
setDisplayClef(boolean flag)
notify all children whether or not to render their clefs, and make space for it.void
setDisplayKeySignature(boolean flag)
notify all children whether or not to render their keysignatures, and updates left margin to make space.void
setDisplayTimeSig(boolean flag)
notify all children whether or not to render their timesig'svoid
setDoubleBar(boolean f)
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.void
setMeasureLeftMargin(double lm)
void
setMeasureNumber(int n)
for rendering purposesvoid
setMeasureText(java.lang.String measureText)
void
setMeasureTextX(int x)
void
setMeasureTextY(int y)
void
setNumRepeats(int n)
void
setPeriodDoubleBar(boolean periodDoubleBar)
void
setRepeatEnd(boolean f)
void
setRepeatStart(boolean f)
void
setSingleBar()
Set barline to a single linevoid
setTempo(double bpm)
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 itvoid
setTempo(Tempo tempo)
void
setTempo(Tempo tempo, boolean setByHand)
Set tempo and mark measure so it displays tempo graphically and blocks previous tempo changes made in GUI from clobbering itvoid
setTempoSetByHand(boolean flag)
Mark this measure as having tenmpo set by hand.void
setTimeSig(int numer, int denom)
void
setTimeSig(TimeSignature ts)
void
setTimeSig(java.lang.String s)
Set from a blank delimitted string like "6 8"void
setTimeSigSetByHand(boolean flag)
void
setWidth(double w)
set layout widthvoid
setWidth(double w, boolean widthSetByHand)
set layout widthvoid
setWidthSetByHand(boolean flag)
Mark this measure as having width set by hand.double
start(double startTime)
Setup method called once when run() begins.java.lang.String
toString()
boolean
within(java.awt.geom.Point2D p)
void
writeMeasurePropertiesXML(java.io.PrintWriter out)
void
writeXML(java.io.PrintWriter out)
Methods inherited from class com.softsynth.jmsl.ParallelCollection
get, main, print, printHierarchy, set
Methods 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, waitForDone
Methods 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:MusicJob
Setup method called once when run() begins. Override this for custom setup.- Specified by:
start
in interfaceComposable
- Overrides:
start
in classMusicJob
- Returns:
- endTime
-
handleAttribute
public void handleAttribute(java.lang.String name, java.lang.String value)XMLCreatable Interface- Specified by:
handleAttribute
in interfaceXMLCreatable
-
create
public java.lang.Object create()XMLCreatable Interface- Specified by:
create
in 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:
internalRepeat
in interfaceComposable
- Overrides:
internalRepeat
in 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:
toString
in 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:
writeXML
in 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:ParallelCollection
Stop all children.- Specified by:
halt
in interfaceComposable
- Overrides:
halt
in classParallelCollection
-
finish
public void finish()Description copied from interface:Composable
Finish playing ASAP.- Specified by:
finish
in interfaceComposable
- Overrides:
finish
in classMusicJob
-