Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
5.2 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Declaration of CDirectMusicScript.
  4. //
  5. // CDirectMusicScript is the script object. A script object is loaded from a script file
  6. // using the loader's GetObject method. A script file contains source code in VBScript
  7. // or another activeX scripting language. Once loaded, the script object can be used
  8. // to set and get the value of variables and to call routines inside the script. The
  9. // script routines can in turn call DirectMusic's automation model (or any other
  10. // IDispatch-based API's).
  11. //
  12. // This allows programmers to separate the application's core C++ code from the
  13. // API calls that to manipulate the musical score. The application core loads
  14. // scripts and calls routines at the appropriate times. Sound designers implement
  15. // those routines using any activeX scripting language. The resulting scripts can
  16. // be modified and auditioned without changing any code in the core application and
  17. // without recompiling.
  18. #pragma once
  19. #include "scriptthread.h"
  20. #include "containerdisp.h"
  21. #include "dmusicf.h"
  22. #include "..\shared\dmusicp.h"
  23. #include "trackshared.h"
  24. class CGlobalDispatch;
  25. class CDirectMusicScript
  26. : public IDirectMusicScript,
  27. public IDirectMusicScriptPrivate,
  28. public IPersistStream,
  29. public IDirectMusicObject,
  30. public IDirectMusicObjectP,
  31. public IDispatch
  32. {
  33. friend class CGlobalDispatch;
  34. public:
  35. static HRESULT CreateInstance(IUnknown* pUnknownOuter, const IID& iid, void** ppv);
  36. // IUnknown
  37. STDMETHOD(QueryInterface)(const IID &iid, void **ppv);
  38. STDMETHOD_(ULONG, AddRef)();
  39. STDMETHOD_(ULONG, Release)();
  40. // IPersistStream functions (only Load is implemented)
  41. STDMETHOD(GetClassID)(CLSID* pClassID) {return E_NOTIMPL;}
  42. STDMETHOD(IsDirty)() {return S_FALSE;}
  43. STDMETHOD(Load)(IStream* pStream);
  44. STDMETHOD(Save)(IStream* pStream, BOOL fClearDirty) {return E_NOTIMPL;}
  45. STDMETHOD(GetSizeMax)(ULARGE_INTEGER* pcbSize) {return E_NOTIMPL;}
  46. // IDirectMusicObject
  47. STDMETHOD(GetDescriptor)(LPDMUS_OBJECTDESC pDesc);
  48. STDMETHOD(SetDescriptor)(LPDMUS_OBJECTDESC pDesc);
  49. STDMETHOD(ParseDescriptor)(LPSTREAM pStream, LPDMUS_OBJECTDESC pDesc);
  50. // IDirectMusicObjectP
  51. STDMETHOD_(void, Zombie)();
  52. // IDirectMusicScript
  53. STDMETHOD(Init)(IDirectMusicPerformance *pPerformance, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  54. STDMETHOD(CallRoutine)(WCHAR *pwszRoutineName, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  55. STDMETHOD(SetVariableVariant)(WCHAR *pwszVariableName, VARIANT varValue, BOOL fSetRef, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  56. STDMETHOD(GetVariableVariant)(WCHAR *pwszVariableName, VARIANT *pvarValue, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  57. STDMETHOD(SetVariableNumber)(WCHAR *pwszVariableName, LONG lValue, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  58. STDMETHOD(GetVariableNumber)(WCHAR *pwszVariableName, LONG *plValue, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  59. STDMETHOD(SetVariableObject)(WCHAR *pwszVariableName, IUnknown *punkValue, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  60. STDMETHOD(GetVariableObject)(WCHAR *pwszVariableName, REFIID riid, LPVOID FAR *ppv, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  61. STDMETHOD(EnumRoutine)(DWORD dwIndex, WCHAR *pwszName);
  62. STDMETHOD(EnumVariable)(DWORD dwIndex, WCHAR *pwszName);
  63. // IDirectMusicScriptPrivate
  64. STDMETHOD(ScriptTrackCallRoutine)(
  65. WCHAR *pwszRoutineName,
  66. IDirectMusicSegmentState *pSegSt,
  67. DWORD dwVirtualTrackID,
  68. bool fErrorPMsgsEnabled,
  69. __int64 i64IntendedStartTime,
  70. DWORD dwIntendedStartTimeFlags);
  71. // IDispatch
  72. STDMETHOD(GetTypeInfoCount)(UINT *pctinfo);
  73. STDMETHOD(GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo);
  74. STDMETHOD(GetIDsOfNames)(
  75. REFIID riid,
  76. LPOLESTR __RPC_FAR *rgszNames,
  77. UINT cNames,
  78. LCID lcid,
  79. DISPID __RPC_FAR *rgDispId);
  80. STDMETHOD(Invoke)(
  81. DISPID dispIdMember,
  82. REFIID riid,
  83. LCID lcid,
  84. WORD wFlags,
  85. DISPPARAMS __RPC_FAR *pDispParams,
  86. VARIANT __RPC_FAR *pVarResult,
  87. EXCEPINFO __RPC_FAR *pExcepInfo,
  88. UINT __RPC_FAR *puArgErr);
  89. // Methods that allow CActiveScriptManager access to private script interfaces
  90. IDispatch *GetGlobalDispatch();
  91. IDirectMusicPerformance8 *GetPerformance() { assert(m_pPerformance8); return m_pPerformance8; }
  92. IDirectMusicLoader8P *GetLoader8P() { return m_pLoader8P; }
  93. IDirectMusicComposer8 *GetComposer() { return m_pComposer8; }
  94. const WCHAR *GetFilename() { return m_info.wstrFilename; }
  95. private:
  96. // Methods
  97. CDirectMusicScript();
  98. void ReleaseObjects();
  99. // Data
  100. CRITICAL_SECTION m_CriticalSection;
  101. bool m_fCriticalSectionInitialized;
  102. long m_cRef;
  103. bool m_fZombie;
  104. IDirectMusicPerformance8 *m_pPerformance8;
  105. IDirectMusicLoader8P *m_pLoader8P; // NULL if loader doesn't support private interface. Use AddRefP/ReleaseP.
  106. IDispatch *m_pDispPerformance;
  107. IDirectMusicComposer8 *m_pComposer8;
  108. // Standard object info
  109. struct HeaderInfo
  110. {
  111. // Descriptor info
  112. SmartRef::RiffIter::ObjectInfo oinfo;
  113. SmartRef::WString wstrFilename;
  114. bool fLoaded;
  115. } m_info;
  116. // Properties of the script
  117. DMUS_IO_SCRIPT_HEADER m_iohead;
  118. SmartRef::WString m_wstrLanguage;
  119. DMUS_VERSION m_vDirectMusicVersion;
  120. // Active Scripting
  121. bool m_fUseOleAut;
  122. ScriptManager *m_pScriptManager; // Reference-counted
  123. CContainerDispatch *m_pContainerDispatch;
  124. CGlobalDispatch *m_pGlobalDispatch;
  125. bool m_fInitError;
  126. DMUS_SCRIPT_ERRORINFO m_InitErrorInfo;
  127. };