/** Creates a new Rest with the given parameters. * * @param shape the Shape constant. This must not be null. * @param staffStep see getStaffStep() * @param duration see getDuration() * @param tags the tags for this music symbol. If this is null, * then this uses an empty Tags object. */ public Rest(Shape shape, int staffStep, Rational duration, Tags tags) : base(tags) { _shape = shape; _staffStep = staffStep; _duration = duration; }
/** Creates a new MeasureStartTimeSlice with the given start time and * tags, and an empty TimeSlice list. * The type is MEASURE_START. * * @param startTime see getStartTime() * @param tags the tags for this time slice. If this is null, * then this uses an empty Tags object. */ public MeasureStartTimeSlice(Rational startTime, Tags tags) { if (tags == null) tags = new Tags(); _startTime = startTime; _tags = tags; }
/** Add a new entry to the positions list for the given startTime, with * the given symbolsToLeft. If a position already exists for the given * startTime, then set its symbols to left value to the max of the existing * value and the given symbolsToLeft. */ public void add(Rational startTime, int symbolsToLeft) { _positionTester.startTime = startTime; int index = _positions.IndexOf(_positionTester); if (index < 0) { // No entry yet for the startTime, so add _positions.Add(new SymbolPosition(startTime, symbolsToLeft)); _isSorted = false; _symbolCount += 1 + symbolsToLeft; } else { // A position already exists for this startTime var symbolPosition = _positions[index]; int maxSymbolsToLeft = (symbolsToLeft > symbolPosition.symbolsToLeft) ? symbolsToLeft : symbolPosition.symbolsToLeft; // Increment _symbolCount if necessary _symbolCount += (maxSymbolsToLeft - symbolPosition.symbolsToLeft); symbolPosition.symbolsToLeft = maxSymbolsToLeft; } }
/** Return the duration of this measure. If this MeasureStartTimeSlice has * a following MeasureStartTimeSlice in the Staff, the duration is the start time * difference of this measure start and the following measure start. * If no following measure start, the duration of this measure is * the start time of the last event TimeSlice. Note that this assumes * the last event TimeSlice has zero duration, but this is reasonable * since the last event TimeSlice usually just holds a bar line. */ public Rational getDuration() { if (_duration != null) return _duration; if ((getIndex() + 1) >= getParentStaff().getMeasureStartCount()) { // This is the last measure start if (getTimeSliceCount() == 0) // No time slices, just set duration to zero _duration = new Rational(0, 1); else // DEBUG: This assumes the event time slices are ordered. Maybe check this. _duration = getTimeSlice(getTimeSliceCount() - 1).getStartTime(); } else { // Compute the start time difference between the next measure and this // DEBUG: This assumes that the measure start time slices are ordered. Maybe check this. IntRatio result = new IntRatio (getParentStaff().getMeasureStart(getIndex() + 1).getStartTime()); result.sub(getStartTime()); _duration = new Rational(result); } return _duration; }
/** This is automatically called after the object is modified to force * this and all child objects to recompute their values when the "get" * method is called for the value. */ public void invalidate() { for (int i = 0; i < getTimeSliceCount(); ++i) getTimeSlice(i).invalidate(); _screenHotspot = null; _duration = null; _width = null; _symbolPositioner = null; }
public int getSymbolPosition(Rational startTime) { // This will compute _symbolPositioner if it is not already. getSymbolCount(); return _symbolPositioner.getSymbolPosition(startTime); }
public int getSymbolCount() { if (_symbolPositioner != null) return _symbolPositioner.getSymbolCount(); // Create a new SymbolPositioner and add a position at each quarter note. _symbolPositioner = new SymbolPositioner(); Rational quarter = new Rational(1, 4); for (IntRatio r = new IntRatio(0, 1); r.compareTo(getDuration()) < 0; r.add(quarter)) { _symbolPositioner.add(new Rational(r), 0); } // Go through the entire staff system and for every measure which // has the same start time and duration as this, set its // SymbolPositioner to the new one and call its addToSymbolPositioner StaffSystem system = getParentStaff().getParentSystem(); for (int staffIndex = 0; staffIndex < system.getStaffCount(); ++staffIndex) { Staff staff = system.getStaff(staffIndex); for (int measureIndex = 0; measureIndex < staff.getMeasureStartCount(); ++measureIndex) { MeasureStartTimeSlice measure = staff.getMeasureStart(measureIndex); if (measure.getStartTime().Equals(getStartTime()) && measure.getDuration().Equals(getDuration())) { // This is an equivalent measure to this one in another // staff (or it is this same measure. measure._symbolPositioner = _symbolPositioner; measure.addToSymbolPositioner(); // There should not be any more measures in this staff // with the same start time. break; } } } return _symbolPositioner.getSymbolCount(); }
/** Creates new IntRatio from the given Rational. */ public IntRatio(Rational r) { n = r.getN(); d = r.getD(); }
/** Set this ratio to this - r */ public void sub(Rational r) { n = n * r.getD() - r.getN() * d; d = d * r.getD(); // simplify now to avoid overflow problems _simplified = false; simplify(); // Must recalculate the double value. _gotDoubleValue = false; }
/** Set the value of this IntRatio to the given Ratioanal. */ public void set(Rational r) { n = r.getN(); d = r.getD(); // Must recalculate the double value. _gotDoubleValue = false; // No need to simplify until necessary. _simplified = false; }
/** Returns a copy of this Tags, with graceNote * changed to the given value, which may be null if the tag * is not present. */ public Tags cloneWithGraceNote(Rational graceNote) { Tags tags = (Tags)clone(); tags._graceNote = graceNote; return tags; }
/** Get the position of the symbol for the given startTime. The * position is between 0 and getSymbolCount() and includes all of * the previous symbols plus their corresponding symbolsToLeft. * If there is no symbol in the symbol position list with the * given start time, return -1. */ public int getSymbolPosition(Rational startTime) { // Sort if not already sorted. This also sets the position for each. sort(); _positionTester.startTime = startTime; int index = _positions.IndexOf(_positionTester); if (index < 0) return -1; return _positions[index].position; }
public SymbolPosition(Rational startTime, int symbolsToLeft) { this.startTime = startTime; this.symbolsToLeft = symbolsToLeft; }
/** Return the duration of this staff system. This is the start time * difference between the first and last measure start time slices in the * first staff plus the duration of the last measure. (It is assumed that all * staves in the staff system have the same duration.) * This is used to compute the screen hotspots of the measure starts. */ public Rational getDuration() { if (_duration != null) return _duration; if (getStaffCount() == 0 || getStaff(0).getMeasureStartCount() == 0) { // There are no staffs or time slices! This is unexpected. Just return 0. // DEBUG: maybe this should be handled more gracefully. _duration = new Rational(0, 1); return _duration; } Staff staff = getStaff(0); MeasureStartTimeSlice lastMeasureStart = staff.getMeasureStart(staff.getMeasureStartCount() - 1); IntRatio result = new IntRatio(lastMeasureStart.getStartTime()); result.sub(getStartTime()); result.add(lastMeasureStart.getDuration()); _duration = new Rational(result); return _duration; }
/** This is automatically called after the object is modified to force * this and all child objects to recompute their values when the "get" * method is called for the value. */ public void invalidate() { for (int i = 0; i < getStaffCount(); ++i) getStaff(i).invalidate(); _screenHotspot = null; _startTime = null; _duration = null; }
/** Return the global start time of this staff system. * This is the start time of the first measure start time slice in the first * staff. */ public Rational getStartTime() { if (_startTime != null) return _startTime; if (getStaffCount() == 0 || getStaff(0).getMeasureStartCount() == 0) { // There are no staffs or time slices! This is unexpected. Just return 0. // DEBUG: maybe this should be handled more gracefully. _startTime = new Rational(0, 1); return _startTime; } _startTime = getStaff(0).getMeasureStart(0).getStartTime(); return _startTime; }