Class MeasureExtractor
java.lang.Object
com.softsynth.jmsl.score.transcribe.MeasureExtractor
public class MeasureExtractor
extends java.lang.Object
Given a source MusicShape where dimension 0 stores absolute times for events (as opposed to
relative durations), pull out a subset of the MusicShape that fall within a measure's time
window.
Assumes ontimes have already been adjusted for tempo, so that 1.0=quarter note.
Resulting extracted MusicShape contains on-times normalized relative to start time of measure.
Note: don't expect the on-time of the first element to be 0, since it may not have landed on a measure boundary.
Note: don't expect the on-time of the first element to be 0, since it may not have landed on a measure boundary.
- Author:
- Nick Didkovsky Feb 3, 2002 , (c) 2002 Nick Didkovsky, All Rights reserved.
-
Constructor Summary
Constructors Constructor Description MeasureExtractor()
-
Method Summary
Modifier and Type Method Description double
extract()
Pull out a subrange of the source shape.MusicShape
getExtractedMusicShape()
double
getStartTime()
static void
main(java.lang.String[] args)
Test a few simple cases.void
setSourceShape(MusicShape s)
This is the MusicShape from which one measure's worth of elements are extractedvoid
setStartTime(double startTime)
Set the start time within the source shape to begin pulling eventsvoid
setTempo(Tempo tempo)
Used to scale the calculate time span within which elements are extractedvoid
setTimeSignature(TimeSignature ts)
Used to calculate time span within which elements are extractedMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
MeasureExtractor
public MeasureExtractor()
-
-
Method Details
-
setSourceShape
This is the MusicShape from which one measure's worth of elements are extracted -
setTimeSignature
Used to calculate time span within which elements are extracted -
setTempo
Used to scale the calculate time span within which elements are extracted -
setStartTime
public void setStartTime(double startTime)Set the start time within the source shape to begin pulling events -
getStartTime
public double getStartTime() -
extract
public double extract()Pull out a subrange of the source shape. Call getExtractedMusicShape() to retrieve the resulting MusicShape. See docs for main() for an example of a loop which processes an entire source shape.- Returns:
- the absolute end time of the measure's time span.
- Throws:
TimeWindowNotFoundException
- if all elements in the source music shape are earlier than the requested start time.
-
getExtractedMusicShape
- Returns:
- the MusicShape extracted by the most recent call to extract()
-
main
public static void main(java.lang.String[] args)Test a few simple cases. Note a simple loop structure that keeps extracting from a MusicShape until done might look like this:
boolean keepExtracting = true; while (keepExtracting) { try { extractor.setTimeSignature(new TimeSignature(3, 4)); extractor.setStartTime(extractor.extract()); MusicShape extractedMeasure = extractor.getExtractedMusicShape(); extractedMeasure.print(); } catch (TimeWindowNotFoundException e) { System.out.println("Done"); keepExtracting = false; } }
-