Class Measure

java.lang.Object
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 Details

  • Constructor Details

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

      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.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 interface XMLWritable
      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 interface Composable
      Overrides:
      halt in class ParallelCollection
    • finish

      public void finish()
      Description copied from interface: Composable
      Finish playing ASAP.
      Specified by:
      finish in interface Composable
      Overrides:
      finish in class MusicJob