CFugue
|
Implements a MusicString Parsing functionality More...
#include <MusicStringParser.h>
Inherits CFugue::CParser.
Public Member Functions | |
void | ResetDefinitions () |
void | SetKeySignature (const KeySignature &keySig) |
const KeySignature & | GetKeySignature () 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. More... | |
bool | Parse (const TCHAR *szTokens) |
Public Member Functions inherited from CFugue::CParser | |
void | AddListener (CParserListener *pListener) |
Subscribes a Listener object for all events | |
void | RemoveListener (CParserListener *pListener) |
UnSubscribes the Listener Object from the events | |
void | SetUserData (void *pData) |
const void * | GetUserData () const |
Protected Types | |
enum | TokenSpecifiers : TCHAR { 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_SEPERATOR = _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 : unsigned short { 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 : TCHAR { NOTE_MODIFIER_SHARP = _T('#'), NOTE_MODIFIER_FLAT = _T('B'), NOTE_MODIFIER_NATURAL = _T('N') } |
Note Modifiers More... | |
enum | NoteDurations : TCHAR { 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 : TCHAR { NOTE_VELOCITY = _T('V'), NOTE_VELOCITY_ATTACK = _T('A'), NOTE_VELOCITY_DECAY = _T('D') } |
Note Velocities More... | |
enum | NoteConnectors : TCHAR { NOTE_CONNECTOR_SEQUENTIAL = _T('_'), NOTE_CONNECTOR_PARALLEL = _T('+') } |
Note Connectors More... | |
enum | DefaultOctaves : long { DEFAULT_CHORD_OCTAVE = 3, DEFAULT_NONCHORD_OCTAVE = 5 } |
Default Octave Values More... | |
enum | NoteShrutis : TCHAR { NOTE_SHRUTI_UP = _T('\''), NOTE_SHRUTI_DOWN = _T('.') } |
Note Shruti Modifiers More... | |
Protected Member Functions | |
int | ParseToken (TCHAR *szToken, bool *pbNonContinuableErrorOccured=NULL) |
Protected Member Functions inherited from CFugue::CParser | |
virtual bool | Error (ErrorCode argErrCode, const TCHAR *szTraceMsg, const TCHAR *szToken) |
Protected Member Functions inherited from OIL::CEventSource | |
template<typename TEventSource , typename TEventHandlerArgs > | |
void | RaiseEvent (CEventT< TEventSource, TEventHandlerArgs > *pEvent, TEventHandlerArgs *pArgs) |
template<typename TEventSource , typename TEventHandlerArgs > | |
void | RaiseEvent (CEventT< TEventSource, const TEventHandlerArgs > *pEvent, const TEventHandlerArgs *pArgs) |
Protected Attributes | |
const Chords * | m_pChords |
DICTIONARY | m_Dictionary |
KeySignature | m_KeySig |
unsigned short | m_nDefNoteOctave |
unsigned short | m_nDefChordOctave |
Implements a MusicString Parsing functionality
Definition at line 24 of file MusicStringParser.h.
|
protected |
Default Octave Values
Enumerator | |
---|---|
DEFAULT_CHORD_OCTAVE |
Default chord octave value. |
DEFAULT_NONCHORD_OCTAVE |
Default non-chord note octave value. |
Definition at line 142 of file MusicStringParser.h.
|
protected |
Note Connectors
Enumerator | |
---|---|
NOTE_CONNECTOR_SEQUENTIAL |
Note Sequential connector symbol. |
NOTE_CONNECTOR_PARALLEL |
Note Parallel connector symbol. |
Definition at line 135 of file MusicStringParser.h.
|
protected |
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]. |
Definition at line 107 of file MusicStringParser.h.
|
protected |
|
protected |
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. |
Definition at line 149 of file MusicStringParser.h.
|
protected |
|
protected |
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_SEPERATOR |
Specifies a seperator token for readability. |
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. |
Definition at line 30 of file MusicStringParser.h.
const KeySignature& CFugue::MusicStringParser::GetKeySignature | ( | ) | const |
Returns the KeySignature being used
Definition at line 222 of file MusicStringParser.h.
void CFugue::MusicStringParser::LoadChords | ( | const Chords & | chords | ) |
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.
Definition at line 243 of file MusicStringParser.h.
bool CFugue::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.
szTokens | The string to be parsed. |
Example Usage:
#include "CFugueLib.h"
void OnParseTrace(const CFugue::CParser*, CFugue::CParser::TraceEventHandlerArgs* pEvArgs) { OutputDebugString(_T("\n")); OutputDebugString(pEvArgs->szTraceMsg); }
void OnParseError(const CFugue::CParser*, CFugue::CParser::ErrorEventHandlerArgs* pEvArgs) { OutputDebugString(_T("\nError --> ")); OutputDebugString(pEvArgs->szErrMsg); if(pEvArgs->szToken) { OutputDebugString(_T("\t Token: ")); OutputDebugString(pEvArgs->szToken); } }
CFugue::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
Definition at line 188 of file MusicStringParser.cpp.
References ParseToken().
Referenced by CFugue::Player::PlayAsync(), and CFugue::Player::SaveAsMidiFile().
|
protected |
Parses a single token. To Parse a string that contains multiple tokens, use the
method. We consider a string to be having multiple tokens if there are whitespace charactes in it such as \n \t or Space.
szToken | The 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. |
pbNonContinuableErrorOccured | Indicates 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 is not called multiple times. |
Note that it is possible to have a return value of -1, 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 -1 indicates there was an error, but if *pbNonContinuableErrorOccured is false, then an error event hanlder is asking you to ignore it.
Definition at line 227 of file MusicStringParser.cpp.
References TOKEN_DOUBLESPEED_END, TOKEN_DOUBLESPEED_START, TOKEN_SEPERATOR, 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().
void CFugue::MusicStringParser::ResetDefinitions | ( | ) |
Macros defined in the Music Strings are remembered across the Parse() method calls. Call ResetDefinitions() before calling Parse() to clear the previous definitions.
Definition at line 208 of file MusicStringParser.h.
References CFugue::PopulateStandardDefinitions(), SetKeySignature(), and SetOctaveDefaults().
void CFugue::MusicStringParser::SetKeySignature | ( | const KeySignature & | keySig | ) |
Sets the KeySignature to be used for further Note parsing
keySig | the KeySignature to be used |
Definition at line 219 of file MusicStringParser.h.
Referenced by ResetDefinitions().
CFugue, the C++ Music Programming Library | © Copyright 2009 Cenacle Research India Private Limited | Gopalakrishna Palem |