Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
MusicNoteLib::MusicStringParser Class Reference

Implements a MusicString Parsing functionality More...

#include <MusicStringParser.h>

Inherits MusicNoteLib::CParser.

List of all members.

Classes

struct  NoteContext

Public Member Functions

void ResetDefinitions ()
void SetKeySignature (const KeySignature &keySig)
const KeySignatureGetKeySignature () const
void SetOctaveDefaults (unsigned short nNoteDefOctave=DEFAULT_NONCHORD_OCTAVE, unsigned short nChordDefOctave=DEFAULT_CHORD_OCTAVE)
 Sets the Default values for Note Octaves.
void LoadChords (const Chords &chords)
 Resets the Chord definitions to the supplied values.
bool Parse (const TCHAR *szTokens)

Protected Types

enum  TokenSpecifiers {
  TOKEN_START_VOICE = _T('V'), TOKEN_START_TEMPO = _T('T'), TOKEN_START_INSTRUMENT = _T('I'), TOKEN_START_LAYER = _T('L'),
  TOKEN_START_KEYSIGNATURE = _T('K'), TOKEN_START_CONTROLLER = _T('X'), TOKEN_START_TIME = _T('@'), TOKEN_START_KEYPRESSURE = _T('*'),
  TOKEN_START_CHANNELPRESSURE = _T('+'), TOKEN_START_PITCHBEND = _T('&'), TOKEN_START_MEASURE = _T('|'), TOKEN_START_DICTIONARY = _T('$'),
  TOKEN_START_NOTE = _T('['), TOKEN_DOUBLESPEED_START = _T('('), TOKEN_DOUBLESPEED_END = _T(')'), ASSIGNMENT_SYMBOL = _T('='),
  MACRO_START = _T('['), MACRO_END = _T(']'), WESTERN_REST_NOTE = _T('R'), REST_NOTE1 = _T(','),
  REST_NOTE2 = _T(';')
}
enum  NoteNumbers {
  NOTE_C = _T('C'), NOTE_C_Value = 0, NOTE_D = _T('D'), NOTE_D_Value = 2,
  NOTE_E = _T('E'), NOTE_E_Value = 4, NOTE_F = _T('F'), NOTE_F_Value = 5,
  NOTE_G = _T('G'), NOTE_G_Value = 7, NOTE_A = _T('A'), NOTE_A_Value = 9,
  NOTE_B = _T('B'), NOTE_B_Value = 11, SWARA_S = _T('S'), SWARA_S_Value = 0,
  SWARA_R = _T('R'), SWARA_R_Value = 1, SWARA_G = _T('G'), SWARA_G_Value = 2,
  SWARA_M = _T('M'), SWARA_M_Value = 3, SWARA_P = _T('P'), SWARA_P_Value = 4,
  SWARA_D = _T('D'), SWARA_D_Value = 5, SWARA_N = _T('N'), SWARA_N_Value = 6
}
 Note Numbers
enum  NoteModifiers { NOTE_MODIFIER_SHARP = _T('#'), NOTE_MODIFIER_FLAT = _T('B'), NOTE_MODIFIER_NATURAL = _T('N') }
 Note Modifiers More...
enum  NoteDurations {
  NOTE_TIE = _T('-'), NOTE_DURATION_NUMERIC = _T('/'), NOTE_DURATION_WHOLE = _T('W'), NOTE_DURATION_HALF = _T('H'),
  NOTE_DURATION_QUARTER = _T('Q'), NOTE_DURATION_EIGTH = _T('I'), NOTE_DURATION_SIXTEENTH = _T('S'), NOTE_DURATION_THIRTYSECOND = _T('T'),
  NOTE_DURATION_SIXTYFOURTH = _T('X'), NOTE_DURATION_128 = _T('O'), NOTE_DURATION_DOT = _T('.'), NOTE_TUPLET_START = _T('*'),
  NOTE_TUPLET_RATIOMARK = _T(':'), SWARA_DURATION_ONE_EXTRA = _T(','), SWARA_DURATION_TWO_EXTRA = _T(';')
}
 Note Durations More...
enum  NoteVelocities { NOTE_VELOCITY = _T('V'), NOTE_VELOCITY_ATTACK = _T('A'), NOTE_VELOCITY_DECAY = _T('D') }
 Note Velocities More...
enum  NoteConnectors { NOTE_CONNECTOR_SEQUENTIAL = _T('_'), NOTE_CONNECTOR_PARALLEL = _T('+') }
 Note Connectors More...
enum  DefaultOctaves { DEFAULT_CHORD_OCTAVE = 3, DEFAULT_NONCHORD_OCTAVE = 5 }
 Default Octave Values More...
enum  NoteShrutis { NOTE_SHRUTI_UP = _T('\''), NOTE_SHRUTI_DOWN = _T('.') }
 Note Shruti Modifiers More...

Protected Member Functions

bool ParseToken (TCHAR *szToken, bool *pbNonContinuableErrorOccured=NULL)

Protected Attributes

const Chordsm_pChords
DICTIONARY m_Dictionary
KeySignature m_KeySig
unsigned short m_nDefNoteOctave
unsigned short m_nDefChordOctave

Detailed Description

Implements a MusicString Parsing functionality


Member Enumeration Documentation

Default Octave Values

Enumerator:
DEFAULT_CHORD_OCTAVE 

Default chord octave value.

DEFAULT_NONCHORD_OCTAVE 

Default non-chord note octave value.

Note Connectors

Enumerator:
NOTE_CONNECTOR_SEQUENTIAL 

Note Sequential connector symbol.

NOTE_CONNECTOR_PARALLEL 

Note Parallel connector symbol.

Note Durations

Enumerator:
NOTE_TIE 

Used when decorating durations for ties.

NOTE_DURATION_NUMERIC 

Used when Duration is to be expressed as a numeric value.

NOTE_DURATION_WHOLE 

Specifies Whole Note.

NOTE_DURATION_HALF 

Specifies Half Note.

NOTE_DURATION_QUARTER 

Specifies Quarter Note.

NOTE_DURATION_EIGTH 

Specifies One-Eight Note.

NOTE_DURATION_SIXTEENTH 

Specifies One-Sixteenth Note.

NOTE_DURATION_THIRTYSECOND 

Specifies One-ThirtySecond Note.

NOTE_DURATION_SIXTYFOURTH 

Specifies One-SixtyFourth Note.

NOTE_DURATION_128 

Specifies 1/128th Note.

NOTE_DURATION_DOT 

Specifies 1.5 times the normal duration.

NOTE_TUPLET_START 

Indicates a Tuplet start.

NOTE_TUPLET_RATIOMARK 

Indicates the Tuplet Ratio.

SWARA_DURATION_ONE_EXTRA 

Indicates one extra time unit [Carnatic Music Only].

SWARA_DURATION_TWO_EXTRA 

Indicates two extra time units [Carnatic Music Only].

Note Modifiers

Enumerator:
NOTE_MODIFIER_SHARP 

Note Sharp symbol.

NOTE_MODIFIER_FLAT 

Note Flat symbol.

NOTE_MODIFIER_NATURAL 

Note Natural symbol.

Note Shruti Modifiers

Enumerator:
NOTE_SHRUTI_UP 

Increments Note Shruti one level upward the Tara Sthayi.

NOTE_SHRUTI_DOWN 

Decrements Note Shruti one level downward the Mandra Sthayi.

Note Velocities

Enumerator:
NOTE_VELOCITY 

Note Attack Velocity specifier (Carnatic Mode)

NOTE_VELOCITY_ATTACK 

Note Attack Velocity specifier (Obsolete. only for compatability with JFugue)

NOTE_VELOCITY_DECAY 

Note Decay Velocity specifier.

Token constants used in the parsing for classifying their types

Enumerator:
TOKEN_START_VOICE 

Specifies a Voice token.

TOKEN_START_TEMPO 

Specifies a Tempo token.

TOKEN_START_INSTRUMENT 

Specifies a Instrument token.

TOKEN_START_LAYER 

Specifies a Layer token.

TOKEN_START_KEYSIGNATURE 

Specifies a KeySignature token.

TOKEN_START_CONTROLLER 

Specifies a Controller token.

TOKEN_START_TIME 

Specifies a Time token.

TOKEN_START_KEYPRESSURE 

Specifies a Keypressure token.

TOKEN_START_CHANNELPRESSURE 

Specifies a Channel pressure token.

TOKEN_START_PITCHBEND 

Specifies a Pitchbend token.

TOKEN_START_MEASURE 

Specifies a Measure token.

TOKEN_START_DICTIONARY 

Specifies a Dictionary token.

TOKEN_START_NOTE 

Specifies a Note token.

TOKEN_DOUBLESPEED_START 

Specifies the start of 2x speed.

TOKEN_DOUBLESPEED_END 

Specifies the end of 2x speed.

MACRO_START 

Signifies a Macro start symbol.

MACRO_END 

Signifies the Macro end symbol.

WESTERN_REST_NOTE 

Specifies a Rest Note token [Western Music Only].

REST_NOTE1 

Specifies a Rest Note of one duration.

REST_NOTE2 

Specifies a Rest Note of two durations.


Member Function Documentation

Returns the KeySignature being used

Returns:
the KeySignature being used

Resets the Chord definitions to the supplied values.

A refernce to the supplied Chords object is stored by the Parser. So, make sure the supplied Chords object stays valid as long as this Parser object is valid.

Since a reference is stored by the Parser, any modification you do for the supplied Chords object will get refelected in the Parser too.

See Chords::LoadDefinitions() and Chords::AddDefinitions() for more details.

bool MusicNoteLib::MusicStringParser::Parse ( const TCHAR *  szTokens)

Parses a string that contains multiple tokens. Raises appropriate events as and when the tokens are parsed. We consider the input string to be having multiple tokens seperated with whitespace charactes such as \n \t or Space. If there are no whitespace characters, the whole string will be considered as a single token.

Use MusicStringParser::AddListener method to get notified about the token events.

Parameters:
szTokensThe string to be parsed.
Returns:
True if success, False in case of any failures.

Example Usage:

            #include "MusicNoteLib.h"
           void OnParseTrace(const MusicNoteLib::CParser*, MusicNoteLib::CParser::TraceEventHandlerArgs* pEvArgs)
            {
                OutputDebugString(_T("\n"));
                OutputDebugString(pEvArgs->szTraceMsg);
            }
           void OnParseError(const MusicNoteLib::CParser*, MusicNoteLib::CParser::ErrorEventHandlerArgs* pEvArgs)
            {
                OutputDebugString(_T("\nError --> "));
                OutputDebugString(pEvArgs->szErrMsg);
                if(pEvArgs->szToken)
                {
                    OutputDebugString(_T("\t Token: "));     
                    OutputDebugString(pEvArgs->szToken);
                }
            }
           MusicNoteLib::MusicStringParser Parser; // Create the Parser Object
             Parser.evTrace.Subscribe(&OnParseTrace); // To get notified about the Parse Trace Events
              Parser.evError.Subscribe(&OnParseError); // To get notified about the Parse Error Events
           MIDIRenderer Renderer; // Create the Listener Object, in this case a MIDI Renderer
            Parser.AddListener(&Renderer);  // Add Renderer as a listener to get notified about the Tokens encountered during the Parse
           Parser.Parse(_T("I[Flute] C D E F G A B")); // Do the Parsing. Notifies the listeners during the process
         

References MusicNoteLib::CParser::CRITICAL_ERROR_MEMORY_ALLOCATION, MusicNoteLib::CParser::Error(), and ParseToken().

Referenced by MusicNoteLib::Player::PlayAsync(), and MusicNoteLib::Player::SaveAsMidiFile().

bool MusicNoteLib::MusicStringParser::ParseToken ( TCHAR *  szToken,
bool *  pbNonContinuableErrorOccured = NULL 
) [protected]

Parses a single token. To Parse a string that contains multiple tokens, use the Parse method. We consider a string to be having multiple tokens if there are whitespace charactes in it such as \n \t or Space.

Parameters:
szTokenThe token to be parsed. We expect this to be a single token free of any whitespace characters, such as \t \n or Space. If the input token contains any of these characters, results are undefined.
pbNonContinuableErrorOccuredIndicates the event handlers' response to the errors, if any. While calling ParseToken in a loop, when the return value is false, use this value to check if you should continue further or exit now. This usually will be the preference of errors handler procedures for the error. You can ignore this parameter if you are not doing any error handling or if the ParseToken is not called multiple times.
Returns:
True if success, False in case of any failures.

Note that it is possible to have a return value of False, and *pbNonContinuableErrorOccured as True or False. This happens when an event handler responding to the error modifies the error continuability. In any case, return value of false indicates there was an error, but if *pbNonContinuableErrorOccured is false, then an error event hanlder is asking you to ignore it.

References TOKEN_DOUBLESPEED_END, TOKEN_DOUBLESPEED_START, TOKEN_START_CHANNELPRESSURE, TOKEN_START_CONTROLLER, TOKEN_START_DICTIONARY, TOKEN_START_INSTRUMENT, TOKEN_START_KEYPRESSURE, TOKEN_START_KEYSIGNATURE, TOKEN_START_LAYER, TOKEN_START_MEASURE, TOKEN_START_NOTE, TOKEN_START_PITCHBEND, TOKEN_START_TEMPO, TOKEN_START_TIME, and TOKEN_START_VOICE.

Referenced by Parse().

Macros defined in the Music Strings are remembered across the Parse() method calls. Call ResetDefinitions() before calling Parse() to clear the previous definitions.

References MusicNoteLib::PopulateStandardDefinitions(), SetKeySignature(), and SetOctaveDefaults().

Sets the KeySignature to be used for further Note parsing

Parameters:
keySigthe KeySignature to be used

Referenced by ResetDefinitions().


The documentation for this class was generated from the following files:

CFugue, the C++ Music Programming Library © Copyright 2009 CineFx Digital Media Pvt Ltd. Gopalakrishna Palem