Class NoteFactory

java.lang.Object
com.softsynth.jmsl.score.NoteFactory

public class NoteFactory
extends java.lang.Object
NoteFactory
Feed in a double duration and get out a Note. Durations this handles include WHOLE, QUARTER ... 64th, 128th, as well as their single dotted versions, and their 3, 5, 7, and 11 tuplets
JMSL Notation Project
Author:
Nick Didkovsky , copyright 2000 Nick Didkovsky
  • Field Summary

    Fields
    Modifier and Type Field Description
    static java.lang.String copyright  
    static int LEVEL_OF_MIDDLE_C  
    static int MIDDLE_C  
    static int[] TUPLETS  
  • Constructor Summary

    Constructors
    Constructor Description
    NoteFactory()  
  • Method Summary

    Modifier and Type Method Description
    static void calcAndSetDurationData​(Note note, int coreDur, int tuplet, int dots)
    Calc duration based on a core duration 0..7, tuplet, and # dots
    static void calcAndSetNoteHeadStemTailInfo​(Note note, int coreDur)
    Based on the core duration 0..8, set the notehead type, stem info and number of tails for a note .
    static int calcLevel​(Staff staff, double pitch)
    calculate the level on the staff for pitch and staff.
    static double findClosestDur​(double dur)
    compare dur argument to each duration in NoteHashTable's keys.
    static double getHoldScaler()  
    static java.util.Hashtable getNoteHashTable()  
    static void init()
    Builds HashTable of double precision durations mapped to notes.
    static boolean isIntervalWithoutAccidental​(int interval)  
    static boolean isMultiTrack​(Note note)  
    static double levelToPitch​(int accInfo, int level, Clef clef)  
    static void main​(java.lang.String[] args)  
    static Note makeNote​(double dur)
    Clone and return a new Note whose duration matches the argument.
    static Note makeNote​(double[] data)
    Clone a new note with closest duration.
    static Note makeNote​(double dur, double pitch, double vel, double hold)  
    static Note makeNote​(int coreDuration, double pitch, int tuplet, int numDots)
    Make a Note
    static Note makeNote​(int coreDur, int tuplet, int dots, int accInfo, int level, Clef clef)
    Build a note based on duration, tuplet, #dots, level on staff, and accidental.
    static Note makeNote​(DimensionNameSpace dns, double[] data)
    Clone a new note with closest duration.
    static boolean noteExistsForDuration​(double dur)  
    static void setHoldScaler​(double holdScaler)  
    static void setLevelPitch​(Note note, double pitch)
    Major workhorse.
    static double truncPrecision​(double value)
    truncate precision of arg to 5 decimal places.
    static void update​(Note note)
    Given a Note, update its properties based on its pitch and duration data, one or both of which might have changed algorithmically.
    static void updateFromDur​(Note note)
    Given a Note, update its properties based on its double duration data.
    static void updateFromPitch​(Note note)
    Given a Note, calc and set the level on the staff where it should be drawn based on its pitch.
    static boolean useQuarterToneAccidentals()
    if true, pitches equal to int+0.5 will be assigned a quarter tone accidental
    static void useQuarterToneAccidentals​(boolean useQuarterToneAccidentals)
    if true, pitches equal to int+0.5 will be assigned a quarter tone accidental

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • NoteFactory

      public NoteFactory()
  • Method Details

    • init

      public static void init()
      Builds HashTable of double precision durations mapped to notes. Called automatically by a new Score constructor
    • truncPrecision

      public static double truncPrecision​(double value)
      truncate precision of arg to 5 decimal places. Use this to prepare your algorithmically generated duration to match a duration in this factory class
    • isIntervalWithoutAccidental

      public static boolean isIntervalWithoutAccidental​(int interval)
    • calcAndSetDurationData

      public static void calcAndSetDurationData​(Note note, int coreDur, int tuplet, int dots)
      Calc duration based on a core duration 0..7, tuplet, and # dots
    • getNoteHashTable

      public static java.util.Hashtable getNoteHashTable()
    • makeNote

      public static Note makeNote​(double dur)
      Clone and return a new Note whose duration matches the argument. This dur must be found in the Note hashtable, or the closest dur will be chosen, (to 5 decimal places of precision, use NoteFactory.truncPrecision(yourDur) )
      For a listing of all durations and their Note properties, run the main method of this class.
      The Note returned by this method is a clone of the note, you may do with it what you like, safely.
      You may generate durations algorithmically by whatever method you like. As long as the duration is found in this table, you can notate it in a straightforward manner.
      Returns:
      a new Note based on the dur arg.
    • makeNote

      public static Note makeNote​(double[] data)
      Clone a new note with closest duration. Set note's data to a copy of the specified array
    • makeNote

      public static Note makeNote​(DimensionNameSpace dns, double[] data)
      Clone a new note with closest duration. Set note's data to a copy of the specified array and set its DimensionNameSpace to the one specified
    • makeNote

      public static Note makeNote​(double dur, double pitch, double vel, double hold)
    • makeNote

      public static Note makeNote​(int coreDuration, double pitch, int tuplet, int numDots)
      Make a Note
      Parameters:
      coreDuration - is an index 0..7 standing for WHOLE, HALF, QUARTER, EIGHTH, 16TH, 32ND, 64, 128TH
      pitch - is midi style, where 60 == middle C
      tuplet - is an int where 3 is triplet for example
      numDots - is 0, 1, or 2
      Returns:
      Note with these attributes
    • noteExistsForDuration

      public static boolean noteExistsForDuration​(double dur)
      Returns:
      true if dur matches table of recognized durations 'exactly' (ie within trunc precision limits )
    • findClosestDur

      public static double findClosestDur​(double dur)
      compare dur argument to each duration in NoteHashTable's keys. FIXME: Later add allowance flags so user can disallow 32nd note 11-tuplets for example
      Returns:
      the duration in NoteHashTable closest to dur.
    • update

      public static void update​(Note note)
      Given a Note, update its properties based on its pitch and duration data, one or both of which might have changed algorithmically. Just calls updateFromPitch() followed by updateFromDur()
    • updateFromDur

      public static void updateFromDur​(Note note)
      Given a Note, update its properties based on its double duration data. Use this after algorithmically changing the duration of a Note with setDurationData(double dur). This finds the closest duration in NoteFactory's noteHashtable, and sets the Note's note duration (w, h, q, 8, etc),tuplet, dots, notehead type, number of tails, and stem info by pulling these properties from the Note in NoteHashtable with the matching dur.
    • makeNote

      public static Note makeNote​(int coreDur, int tuplet, int dots, int accInfo, int level, Clef clef)
      Build a note based on duration, tuplet, #dots, level on staff, and accidental. Esp. good for gui insertion. Pitch is calculated from level. Preferred accidental (should it need one) set to ACC_PREFER_FLAT if accInfo = ACC_FLAT, else set to ACC_PREFER_SHARP. This is a preference only, used if note gets transposed and respelled later for example
    • getHoldScaler

      public static double getHoldScaler()
      Returns:
      Returns the holdScaler.
    • setHoldScaler

      public static void setHoldScaler​(double holdScaler)
      Parameters:
      holdScaler - The holdScaler to set.
    • levelToPitch

      public static double levelToPitch​(int accInfo, int level, Clef clef)
      Parameters:
      accInfo -
      level -
      clef -
      Returns:
      pitch given level, clef, and accidental
    • updateFromPitch

      public static void updateFromPitch​(Note note)
      Given a Note, calc and set the level on the staff where it should be drawn based on its pitch. This is just call to setLevelPitch(note, note.getPitchData(). Use this after algorithmically changing a Note's pitch with setPitchData(double p). If the pitch is 0 the note will be a rest.
    • calcLevel

      public static int calcLevel​(Staff staff, double pitch)
      calculate the level on the staff for pitch and staff. Staff is referenced to get Clef
      Returns:
      level of pitch on steff 0..127
    • setLevelPitch

      public static void setLevelPitch​(Note note, double pitch)
      Major workhorse. Given a Note and a pitch, find the level on the staff where it should be drawn. Refers to Staff's clef to adjust level.
      Sets the Note's accidental based on its accidental preferences and its pitch relative to MIDDLE_C.
      Sets Note's stem direction based on level.
      Sets performable pitch of Note to pitch arg. Pitch may be fractional. If exactly 0.5 above integer, will assign quarter tone accidentals
    • isMultiTrack

      public static boolean isMultiTrack​(Note note)
      Returns:
      true if note is in a staff that contains more than one non-empty track
    • calcAndSetNoteHeadStemTailInfo

      public static void calcAndSetNoteHeadStemTailInfo​(Note note, int coreDur)
      Based on the core duration 0..8, set the notehead type, stem info and number of tails for a note . If the note already has X or diamond notehead, adjust to oval/non-oval, black/white diamond based on core duration being less than 2. No longer set num tails, which is calculated directly in getNumTails()
    • useQuarterToneAccidentals

      public static boolean useQuarterToneAccidentals()
      if true, pitches equal to int+0.5 will be assigned a quarter tone accidental
      Returns:
      Returns the useQuarterToneAccidentals.
    • useQuarterToneAccidentals

      public static void useQuarterToneAccidentals​(boolean useQuarterToneAccidentals)
      if true, pitches equal to int+0.5 will be assigned a quarter tone accidental
      Parameters:
      useQuarterToneAccidentals - The useQuarterToneAccidentals to set.
    • main

      public static void main​(java.lang.String[] args)