lib/minim/src/ddf/minim/ugens/Frequency.java
/**
	 * Construct a Frequency from a pitch name, such as A4 or Bb2.
	 * 
	 * @param pitchName 
	 * 		String: the name of the pitch to convert to a Frequency.
	 * 
	 * @return a new Frequency object
	 * 
	 * @example Synthesis/frequencyExample
	 * 
	 * @related Frequency
	 */
Construct a Frequency from a pitch name, such as A4 or Bb2.

@param pitchName
String: the name of the pitch to convert to a Frequency.

@return a new Frequency object

@example Synthesis/frequencyExample

@related Frequency
Construct a Frequency from a pitch name such as A4 or Bb2 . @param pitchName String : the name of the pitch to convert to a Frequency . @return a new Frequency object @example Synthesis / frequencyExample @related Frequency
public static Frequency ofPitch(String pitchName)
	{
		float midiNote;
		pitchName = pitchName.trim();
		if ( pitchName.matches( pitchRegex ) )
		{
			Minim.debug(pitchName + " matches the pitchRegex.");
			float noteOctave;
			Pattern pattern = Pattern.compile( noteOctaveRegex );
			Matcher matcher = pattern.matcher( pitchName );
			if ( matcher.find() )
			{
				String octaveString = pitchName.substring( matcher.start(), matcher.end() );
				noteOctave = Float.valueOf( octaveString.trim() ).floatValue();
			} else  
			{
				noteOctave = 4.0f;
			}
			midiNote = noteOctave*12.0f + 12.0f;
			Minim.debug("midiNote based on octave = " + midiNote );
			pattern = Pattern.compile( noteNaturalnessRegex );
			matcher = pattern.matcher( pitchName );
			while( matcher.find() )
			{
				String naturalnessString = pitchName.substring(matcher.start(), matcher.end() );
				if ( naturalnessString.equals("#") )
				{
					midiNote += 1.0f;
				} else  
				{
					midiNote -= 1.0f;
				}
			}
			Minim.debug("midiNote based on naturalness = " + midiNote );
			pattern = Pattern.compile( noteNameRegex );
			matcher = pattern.matcher( pitchName );
			if ( matcher.find() )
			{	
				String noteNameString = pitchName.substring(matcher.start(), matcher.end() );
				float noteOffset = (float) noteNameOffsets.get( noteNameString );
				midiNote += noteOffset;
			}
			Minim.debug("midiNote based on noteName = " + midiNote );
			return new Frequency( ofMidiNote( midiNote ).asHz() );
		} else  
		{
			Minim.debug(pitchName + " DOES NOT MATCH.");			
			return new Frequency( 0.0f );
		}
	}
public static Frequency ofPitch ( String pitchName ) { float midiNote ; pitchName = pitchName . trim ( ) ; if ( pitchName . matches ( pitchRegex ) ) { Minim . debug ( pitchName + " matches the pitchRegex." ) ; float noteOctave ; Pattern pattern = Pattern . compile ( noteOctaveRegex ) ; Matcher matcher = pattern . matcher ( pitchName ) ; if ( matcher . find ( ) ) { String octaveString = pitchName . substring ( matcher . start ( ) , matcher . end ( ) ) ; noteOctave = Float . valueOf ( octaveString . trim ( ) ) . floatValue ( ) ; } else { noteOctave = 4.0f ; } midiNote = noteOctave * 12.0f + 12.0f ; Minim . debug ( "midiNote based on octave = " + midiNote ) ; pattern = Pattern . compile ( noteNaturalnessRegex ) ; matcher = pattern . matcher ( pitchName ) ; while ( matcher . find ( ) ) { String naturalnessString = pitchName . substring ( matcher . start ( ) , matcher . end ( ) ) ; if ( naturalnessString . equals ( "#" ) ) { midiNote += 1.0f ; } else { midiNote -= 1.0f ; } } Minim . debug ( "midiNote based on naturalness = " + midiNote ) ; pattern = Pattern . compile ( noteNameRegex ) ; matcher = pattern . matcher ( pitchName ) ; if ( matcher . find ( ) ) { String noteNameString = pitchName . substring ( matcher . start ( ) , matcher . end ( ) ) ; float noteOffset = ( float ) noteNameOffsets . get ( noteNameString ) ; midiNote += noteOffset ; } Minim . debug ( "midiNote based on noteName = " + midiNote ) ; return new Frequency ( ofMidiNote ( midiNote ) . asHz ( ) ) ; } else { Minim . debug ( pitchName + " DOES NOT MATCH." ) ; return new Frequency ( 0.0f ) ; } }
Construct a Frequency from a pitch name, such as A4 or Bb2.
Construct a Frequency from a pitch name such as A4 or Bb2 .
// builds up the value of a midiNote used to create the returned Frequency // trim off any white space before or after // check to see if this is a note		 // get octave // default octave of 4 // get naturalness			 // must be a "b" // get note // return a Frequency object with this midiNote // string does not conform to note name syntax // return a Frequency object of 0.0 Hz.