CFugue
CFugueLib.cpp
1 /*
2  This is part of CFugue, a C++ Runtime for MIDI Score Programming
3  Copyright (C) 2009 Gopalakrishna Palem
4 
5  For links to further information, or to contact the author,
6  see <http://cfugue.sourceforge.net/>.
7 */
8 
9 #include "stdafx.h"
10 
11 #ifdef _USRDLL
12 #define MUSICNOTELIB_API __declspec(dllexport)
13 #endif
14 #include "CFugueLib.h"
15 
16 namespace CFugue
17 {
19  {
20  LPFNTRACEPROC lpfnTraceProc;
21  LPFNERRORPROC lpfnErrorProc;
22  void* lpUserData;
23  };
24 
25  static void OnParseTrace(const CFugue::CParser* pParser, CFugue::CParser::TraceEventHandlerArgs* pEvArgs)
26  {
27  const PARSETRACEARGS* pCallbackData = (const PARSETRACEARGS*) pParser->GetUserData();
28  pCallbackData->lpfnTraceProc(pCallbackData->lpUserData, pEvArgs->szTraceMsg);
29  }
30 
31  static void OnParseError(const CFugue::CParser* pParser, CFugue::CParser::ErrorEventHandlerArgs* pEvArgs)
32  {
33  const PARSETRACEARGS* pCallbackData = (const PARSETRACEARGS*) pParser->GetUserData();
34  pCallbackData->lpfnErrorProc(pCallbackData->lpUserData, pEvArgs->errCode, pEvArgs->szErrMsg, pEvArgs->szToken);
35  }
36 
37 extern "C"
38 {
39  MUSICNOTELIB_API void* GetCarnaticMusicNoteReader()
40  {
42 
43  return NULL;
44  }
45 
47  {
48  return NULL;
49  }
50 
51  MUSICNOTELIB_API bool SaveAsMidiFile(const TCHAR* szMusicNotes, const char* szOutputFilePath)
52  {
53  Player playerObj;
54  return playerObj.SaveAsMidiFile(szMusicNotes, szOutputFilePath);
55  }
56 
57  //static void OnParseError(const CFugue::CParser* pParser, CFugue::CParser::ErrorEventHandlerArgs* pEvArgs)
58  //{
59  // OutputDebugString(_T("\nError --> "));
60  // OutputDebugString(pEvArgs->szErrMsg);
61  // if(pEvArgs->szToken)
62  // {
63  // OutputDebugString(_T("\t Token: "));
64  // OutputDebugString(pEvArgs->szToken);
65  // }
66  //}
67 
68  MUSICNOTELIB_API bool PlayMusicString(const TCHAR* szNotes)
69  {
70  return Player().Play(szNotes);
71  }
72 
73  MUSICNOTELIB_API bool PlayMusicStringCB(const TCHAR* szNotes,
74  LPFNTRACEPROC traceCallbackProc,
75  LPFNERRORPROC errorCallbackProc,
76  void* pCallbackData)
77  {
78  PARSETRACEARGS callbackArgs;
79  callbackArgs.lpfnTraceProc = traceCallbackProc;
80  callbackArgs.lpfnErrorProc = errorCallbackProc;
81  callbackArgs.lpUserData = pCallbackData;
82 
83  Player playerObj;
84  playerObj.Parser().SetUserData(&callbackArgs);
85  playerObj.Parser().evTrace.Subscribe(OnParseTrace);
86  playerObj.Parser().evError.Subscribe(OnParseError);
87  return playerObj.Play(szNotes);
88  }
89 
90  MUSICNOTELIB_API bool PlayMusicStringWithOpts(const TCHAR* szMusicNotes, int nMidiOutPortID, unsigned int nTimerResMS)
91  {
92  Player playerObj(nMidiOutPortID, nTimerResMS);
93  return playerObj.Play(szMusicNotes);
94  }
95 
96  MUSICNOTELIB_API bool PlayMusicStringWithOptsCB(const TCHAR* szMusicNotes,
97  int nMidiOutPortID,
98  unsigned int nTimerResMS,
99  LPFNTRACEPROC traceCallbackProc,
100  LPFNERRORPROC errorCallbackProc,
101  void* pCallbackData)
102  {
103  PARSETRACEARGS callbackArgs;
104  callbackArgs.lpfnTraceProc = traceCallbackProc;
105  callbackArgs.lpfnErrorProc = errorCallbackProc;
106  callbackArgs.lpUserData = pCallbackData;
107 
108  Player playerObj(nMidiOutPortID, nTimerResMS);
109  playerObj.Parser().SetUserData(&callbackArgs);
110  playerObj.Parser().evTrace.Subscribe(OnParseTrace);
111  playerObj.Parser().evError.Subscribe(OnParseError);
112  return playerObj.Play(szMusicNotes);
113  }
114 } // extern "C"
115 
116 } // namespace CFugue
MUSICNOTELIB_API bool PlayMusicString(const TCHAR *szMusicNotes)
Definition: CFugueLib.cpp:68
MUSICNOTELIB_API MStringPlayer * CreateMusicStringPlayer()
Definition: CFugueLib.cpp:46
#define MUSICNOTELIB_API
Definition: CFugueLib.h:27
Implements a MusicString Parsing functionality
bool Play(const MString &strMusicNotes)
Definition: Player.cpp:28
MIDI Player for Music Strings
Definition: Player.h:22
OIL::CEventT< const CParser, TraceEventHandlerArgs > evTrace
Raised by Parser during the Parsing.
Definition: Parser.h:215
OIL::CEventT< const CParser, ErrorEventHandlerArgs > evError
Raised when a parse error happens.
Definition: Parser.h:181
const TCHAR * szToken
Token the error is applicable for.
Definition: Parser.h:174
Main header file for accessing the CFugue Library.
const ErrorCode errCode
Error Code.
Definition: Parser.h:172
const TCHAR * szTraceMsg
The Error message sent by Parser.
Definition: Parser.h:211
Base class that represents a Parser Object.
Definition: Parser.h:63
bool SaveAsMidiFile(const MString &strMusicNotes, const char *szOutputFilePath)
Definition: Player.cpp:60
MusicStringParser & Parser()
Returns the associated Parser object.
Definition: Player.h:40
MUSICNOTELIB_API bool PlayMusicStringWithOpts(const TCHAR *szMusicNotes, int nMidiOutPortID, unsigned int nTimerResMS)
Definition: CFugueLib.cpp:90
const TCHAR * szErrMsg
The Error message sent by Parser.
Definition: Parser.h:173
MUSICNOTELIB_API bool PlayMusicStringCB(const TCHAR *szMusicNotes, LPFNTRACEPROC traceCallbackProc, LPFNERRORPROC errorCallbackProc, void *pUserData)
Definition: CFugueLib.cpp:73
MUSICNOTELIB_API bool PlayMusicStringWithOptsCB(const TCHAR *szMusicNotes, int nMidiOutPortID, unsigned int nTimerResMS, LPFNTRACEPROC traceCallbackProc, LPFNERRORPROC errorCallbackProc, void *pUserData)
Definition: CFugueLib.cpp:96
MUSICNOTELIB_API bool SaveAsMidiFile(const TCHAR *szMusicNotes, const char *szOutputFilePath)
Definition: CFugueLib.cpp:51

CFugue, the C++ Music Programming Library © Copyright 2009 Cenacle Research India Private Limited Gopalakrishna Palem