com.softsynth.jmsl.score
Class Measure

java.lang.Object
  extended by com.softsynth.jmsl.MusicJob
      extended by com.softsynth.jmsl.ParallelCollection
          extended by 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

Author:
Nick Didkovsky , copyright 2000 Nick Didkovsky

Field Summary
static java.lang.String copyright
           
static double FIXED_LEFT_MARGIN
           
 
Fields inherited from class com.softsynth.jmsl.MusicJob
repeatCount
 
Constructor Summary
Measure()
           
Measure(ScoreCollection scoreCollection, Score score, int numStaffs)
           
Measure(ScoreCollection scoreCollection, Score score, int numStaffs, TimeSignature timeSig)
           
 
Method Summary
 void addToWidth(double delta, boolean widthSetByHand)
          change width of measure, addToWidth(1) adds 1 to width.
 void calcMaxDuration()
          calculate max duration of each track in each staff of this measure, used for horizontal layout
 double calcWidth()
          Calculate and set measure width.
 java.lang.Object create()
          XMLCreatable Interface
 void deleteStaff(int position)
          Delete the staff at specified position
 boolean getAnyClefSetByHand()
           
 boolean getDoubleBar()
           
 java.awt.Point getDrawingAnchor()
          drawingAnchor is the (x,y) point at top left of drawable object, set by layout manager, changes as measures stretch, compress, realign, etc
 double getHeight()
           
 java.lang.String getHierarchy()
           
 double getLeftMargin()
           
 double getMaxDuration()
           
 int getMeasureIndex()
           
 double getNoteAreaWidth()
           
 int getNumRepeats()
           
 boolean getRepeatEnd()
           
 boolean getRepeatStart()
           
 Score getScore()
           
 Staff getStaff(int n)
           
 Tempo getTempo()
           
 boolean getTempoSetByHand()
           
 TimeSignature getTimeSig()
           
 boolean getTimeSigSetByHand()
           
 double getWidth()
           
 boolean getWidthSetByHand()
           
 void handleAttribute(java.lang.String name, java.lang.String value)
          XMLCreatable Interface
 void inheritClefsFrom(Measure m)
           
 void inheritFrom(Measure m)
          Inherit time sig, keysigs, and clefs from specified Measure
 void 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 fisnishing early)
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
 void layoutChildren()
          Sets anchor points for all staves, justifies contents using Blostein/Haken CACM '91 paper algorithm
 void realign()
          Calculate width from measure contents.
 void render(java.awt.Graphics g, double zoom)
           
 void renderBars(java.awt.Graphics g, int x, int w, int barTop, int barBottom, double zoom)
           
 void resetLeftMargin()
           
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
 void 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's
 void setDoubleBar(boolean f)
           
 void setDrawingAnchor(java.awt.Point 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 setMeasureNumber(int n)
          for rendering purposes
 void setNumRepeats(int n)
           
 void setRepeatEnd(boolean f)
           
 void setRepeatStart(boolean f)
           
 void 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 it
 void 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 it
 void setTempoSetByHand(boolean flag)
          Mark this measure as having tenmpo set by hand.
 void setTimeSig(int numer, int denom)
           
 void setTimeSig(java.lang.String s)
          Set from a blank delimitted string like "6 8"
 void setTimeSig(TimeSignature ts)
           
 void setTimeSigSetByHand(boolean flag)
           
 void setWidth(double w)
          set layout width
 void setWidth(double w, boolean widthSetByHand)
          set layout width
 void 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.Point p)
           
 void writeXML(java.io.PrintWriter out)
           
 
Methods inherited from class com.softsynth.jmsl.ParallelCollection
get, halt, main, print, printHierarchy, set
 
Methods inherited from class com.softsynth.jmsl.MusicJob
add, addPlayLurker, addRepeatPlayable, addStartPlayable, addStopPlayable, advanceCurrentTime, contains, elements, finish, finishAll, getChild, getChildren, getCurrentTime, getDataTranslator, getDuration, getInstrument, getName, getParent, getPlayLurkers, getRepeatCount, getRepeatPause, getRepeats, getStartDelay, getStartPause, getStartTime, getStopDelay, 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 Detail

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 Detail

Measure

public Measure()

Measure

public Measure(ScoreCollection scoreCollection,
               Score score,
               int numStaffs,
               TimeSignature timeSig)

Measure

public Measure(ScoreCollection scoreCollection,
               Score score,
               int numStaffs)
Method Detail

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 interface Composable
Overrides:
start in class MusicJob
Returns:
endTime

handleAttribute

public void handleAttribute(java.lang.String name,
                            java.lang.String value)
XMLCreatable Interface

Specified by:
handleAttribute in interface XMLCreatable

create

public java.lang.Object create()
XMLCreatable Interface

Specified by:
create in interface XMLCreatable

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.InterruptedException
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 fisnishing early)

Specified by:
internalRepeat in interface Composable
Overrides:
internalRepeat in class ParallelCollection
Returns:
stopTime
Throws:
java.lang.InterruptedException - thrown if Thread.interrupt() called.

inheritClefsFrom

public void inheritClefsFrom(Measure m)

inheritFrom

public void inheritFrom(Measure m)
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

public Tempo getTempo()

setTempo

public void setTempo(double bpm)

setTempo

public void setTempo(Tempo tempo)

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

public 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 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

public TimeSignature getTimeSig()
Returns:
time signature of this measure

setTimeSig

public void setTimeSig(TimeSignature ts)

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()

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()

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()

getLeftMargin

public double getLeftMargin()
Returns:
value of leftMargin (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

public Score getScore()
Returns:
Score to which this Measure belongs

getStaff

public Staff getStaff(int n)
Returns:
Staff element # n

getHierarchy

public java.lang.String getHierarchy()

toString

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

setDrawingAnchor

public void setDrawingAnchor(java.awt.Point 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.Point 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.Point p)
Returns:
true if Point falls within measure's bounding box

renderBars

public void renderBars(java.awt.Graphics g,
                       int x,
                       int w,
                       int barTop,
                       int barBottom,
                       double zoom)

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 interface XMLWritable
Throws:
java.io.IOException

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.