MMPlgVis.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:14k
- {========================================================================}
- {= (c) 1995-98 SwiftSoft Ronald Dittrich =}
- {========================================================================}
- {= All Rights Reserved =}
- {========================================================================}
- {= D 01099 Dresden = Fax.: +49 (0)351-8037944 =}
- {= Loewenstr.7a = info@swiftsoft.de =}
- {========================================================================}
- {= Actual versions on http://www.swiftsoft.de/mmtools.html =}
- {========================================================================}
- {= This code is for reference purposes only and may not be copied or =}
- {= distributed in any format electronic or otherwise except one copy =}
- {= for backup purposes. =}
- {= =}
- {= No Delphi Component Kit or Component individually or in a collection=}
- {= subclassed or otherwise from the code in this unit, or associated =}
- {= .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed =}
- {= without express permission from SwiftSoft. =}
- {= =}
- {= For more licence informations please refer to the associated =}
- {= HelpFile. =}
- {========================================================================}
- {= $Date: 09.04.98 - 03:48:33 $ =}
- {========================================================================}
- unit MMPlgVis;
- {$I COMPILER.INC}
- interface
- uses
- Windows,
- Messages,
- SysUtils,
- Forms,
- MMUtils,
- MMSystem,
- MMRegs;
- { === Version of current module ($101 = 1.01) ================================ }
- const
- VIS_HDRVER = $101; { checks this }
- { === Structures ============================================================= }
- type
- TPlugInCBAction = (paActivate,paQuit);
- TPlugInCallBack = procedure(User: Longint; Action: TPlugInCBAction); stdcall;
- PSpectrumDataShort = ^TSpectrumDataShort;
- TSpectrumDataShort = array[0..1,0..575] of Byte; { 0=Left;1=Right }
- PWaveFormDataShort = ^TWaveFormDataShort;
- TWaveformDataShort = array[0..1,0..575] of ShortInt;{ 0=Left;1=Right }
- PPlugInVISModule = ^TPlugInVISModule;
- TPlugInVISModule = record
- Description : PChar; { description of module }
- hWNDParent : HWND; { parent window (filled in by Application) }
- hDLLInstance : HINST; { instance handle to this DLL (filled in by Application) }
- sRate : integer; { sample rate (filled in by Application) }
- nCh : integer; { number of channels (filled in by Application) }
- LatencyMs : integer; { latency from call of RenderFrame to actual drawing }
- { (PlugIn looks at this value when getting data) }
- DelayMs : integer; { delay between calls in milliSeconds }
- SpectrumNch : integer; { number of channels for FFT data }
- WaveformNch : integer; { number of channels for PCM data }
- {The data is filled in according to the respective Nch entry}
- SpectrumData : TSpectrumDataShort;
- WaveformData : TWaveFormDataShort;
- { configuration method }
- Config : procedure(This_Mod: PPlugInVISModule); cdecl;
- { Create window, etc.; 0=success }
- Init : function(This_Mod : PPlugInVISModule): integer; cdecl;
- {1=Plug-in should end; 0=success }
- Render : function(This_Mod : PPlugInVISModule): integer; cdecl;
- { call when done}
- Quit : procedure(This_Mod: PPlugInVISModule); cdecl;
- { pointer to user data (optional) }
- UserData : Pointer;
- end;
- PPlugInVISHeader = ^TPlugInVISHeader;
- TPlugInVISHeader = record
- Version : integer; { VIS_HDRVER }
- Description : PChar; { description of library }
- GetModule : function(Idx: integer): PPlugInVISModule; cdecl;
- { Gets a module pointer based on idx }
- end;
- PPlugInVIS = ^TPlugInVIS;
- PVISModule = ^TVISModule;
- TVISModule = packed record
- Description : string;
- Active : Boolean;
- PlugIn : PPlugInVIS;
- ModuleData : PPlugInVISModule;
- end;
- TPlugInVIS = packed record
- DLLName : string;
- DLLInstance : THandle;
- Description : string;
- Modules : array[0..99] of TVISModule;
- NumModules : integer;
- Open : Boolean;
- Header : PPlugInVISHeader;
- Callback : TPlugInCallBack;
- User : Longint;
- end;
- function ReadPlugInVIS(FileName: string): PPlugInVIS;
- procedure FreePlugInVIS(var PlugIn: PPlugInVIS);
- function OpenPlugInVIS(PlugIn: PPlugInVIS; ParentWindow: HWND): Boolean;
- procedure ClosePlugInVIS(PlugIn: PPlugInVIS);
- procedure ConfigPlugInVISModule(Module: TVISModule);
- function InitPlugInVISModule(var Module: TVISModule; pwfx: PWaveFormatEx): Boolean;
- function RenderPlugInVISModule(var Module: TVISModule): Boolean;
- procedure QuitPlugInVISModule(var Module: TVISModule);
- procedure SetCallback(PlugIn: PPlugInVIS; Callback: TPlugInCallBack; User: Longint);
- implementation
- type
- TGetHeader = function : PPlugInVISHeader; cdecl;
- TGetModule = function (Which: integer): PPlugInVISModule; cdecl;
- TConfig = procedure(This_Mod: PPlugInVISModule); cdecl;
- TInit = function (This_Mod: PPlugInVISModule): Integer; cdecl;
- TRender = function (This_Mod: PPlugInVISModule): Integer; cdecl;
- TQuit = procedure(This_Mod: PPlugInVISModule); cdecl;
- {==============================================================================}
- function ReadPlugInVIS(FileName: string): PPlugInVIS;
- var
- hPlugIn : THandle;
- EntryPoint: TFarProc;
- GetHeader : TGetHeader;
- GetModule : TGetModule;
- Hdr : PPlugInVISHeader;
- Module : PPlugInVISModule;
- begin
- Result := nil;
- hPlugIn := LoadLibrary(PChar(FileName));
- if (hPlugIn <> 0) then
- begin
- try
- EntryPoint := GetProcAddress(hPlugIn, 'winampVisGetHeader');
- if (EntryPoint = nil) then
- EntryPoint := GetProcAddress(hPlugIn, 'MMPlugInVisGetHeader');
- if (EntryPoint <> nil) then
- begin
- @GetHeader := EntryPoint;
- Hdr := GetHeader; { Get PlugIn-header }
- if (Hdr <> nil) and (Hdr.Version >= VIS_HDRVER) then
- begin
- New(Result);
- with Result^ do
- begin
- DLLName := UpperCase(FileName);
- DLLInstance := 0;
- Callback := nil;
- Description := StrPas(Hdr.Description);
- Header := nil;
- Open := False;
- GetModule := Hdr^.GetModule;
- NumModules := 0;
- repeat
- Module := GetModule(NumModules);
- if (Module <> nil) then
- begin
- Modules[NumModules].Description := StrPas(Module.Description);
- Modules[NumModules].ModuleData := nil;
- Modules[NumModules].Active := False;
- Modules[NumModules].Plugin := Result;
- inc(NumModules);
- end;
- until (Module = nil) or (NumModules = 100);
- end;
- end;
- end;
- finally
- FreeLibrary(hPlugIn);
- end;
- end;
- end;
- {==============================================================================}
- function OpenPlugInVIS(PlugIn: PPlugInVIS; ParentWindow: HWND): Boolean;
- var
- EntryPoint: TFarProc;
- GetHeader : TGetHeader;
- GetModule : TGetModule;
- Hdr : PPlugInVISHeader;
- Module : PPlugInVISModule;
- begin
- if (PlugIn <> nil) and not PlugIn.Open then
- begin
- PlugIn.DLLInstance := LoadLibrary(PChar(PlugIn.DLLname));
- if (PlugIn.DLLInstance <> 0) then
- begin
- try
- EntryPoint := GetProcAddress(PlugIn.DLLInstance, 'winampVisGetHeader');
- if (EntryPoint = nil) then
- EntryPoint := GetProcAddress(PlugIn.DLLInstance, 'MMPlugInVisGetHeader');
- if (EntryPoint <> nil) then
- begin
- @GetHeader := EntryPoint;
- Hdr := GetHeader; { Get PlugIn-header }
- if (Hdr <> nil) and (Hdr.Version >= VIS_HDRVER) then
- begin
- with PlugIn^ do
- begin
- Header := Hdr;
- GetModule := Header^.GetModule;
- NumModules := 0;
- repeat
- Module := GetModule(NumModules);
- if (Module <> nil) then
- begin
- Module.HWNDParent := ParentWindow;
- Module.hDLLInstance := PlugIn.DLLInstance;
- Modules[NumModules].ModuleData := Module;
- Modules[NumModules].Active := False;
- Modules[NumModules].PlugIn := PlugIn;
- inc(NumModules);
- end;
- until (Module = nil) or (NumModules = 100);
- end;
- PlugIn.Open := True;
- end;
- end;
- finally
- if not PlugIn.Open then
- begin
- FreeLibrary(PlugIn.DLLInstance);
- PlugIn.DLLInstance := 0;
- end;
- end;
- end;
- end;
- Result := (PlugIn <> nil) and PlugIn.Open;
- end;
- {==============================================================================}
- procedure ClosePlugInVIS(PlugIn: PPlugInVIS);
- var
- i: integer;
- begin
- try
- if (PlugIn <> nil) and PlugIn.Open then
- with PlugIn^ do
- begin
- for i := 0 to NumModules-1 do
- begin
- QuitPlugInVISModule(Modules[i]);
- Modules[i].ModuleData := nil;
- end;
- Header := nil;
- PlugIn.Open := False;
- if (DLLInstance <> 0) then
- begin
- FreeLibrary(DLLInstance);
- DLLInstance := 0;
- end;
- end;
- except
- // no exception please !!!
- end;
- end;
- {==============================================================================}
- procedure FreePlugInVIS(var PlugIn: PPlugInVIS);
- begin
- try
- if (PlugIn <> nil) then
- begin
- ClosePlugInVIS(PlugIn);
- Dispose(PlugIn);
- PlugIn := nil;
- end;
- except
- // no exception please !!!
- end;
- end;
- {==============================================================================}
- procedure SetCallback(PlugIn: PPlugInVIS; Callback: TPlugInCallBack; User: Longint);
- begin
- if (PlugIn <> nil) then
- begin
- PlugIn.Callback := CallBack;
- PlugIn.User := User;
- end;
- end;
- {==============================================================================}
- procedure ConfigPlugInVISModule(Module: TVISModule);
- begin
- try
- if (Module.ModuleData <> nil) and assigned(Module.ModuleData.Config) then
- Module.ModuleData.Config(Module.ModuleData);
- except
- // no exception please !!!
- end;
- end;
- {==============================================================================}
- function InitPlugInVISModule(var Module: TVISModule; pwfx: PWaveFormatEx): Boolean;
- begin
- try
- if (Module.ModuleData <> nil) and not Module.Active then
- with Module.ModuleData^ do
- begin
- if (pwfx = nil) then
- begin
- sRate := 44100;
- nCh := 2;
- end
- else
- begin
- sRate := pwfx.nSamplesPerSec;
- nCh := pwfx^.nChannels;
- end;
- //LatencyMS := 25;
- //DelayMS := 25;
- //SpectrumNch := 2;
- //WaveFormNch := 2;
- if assigned(Module.ModuleData.Init) then
- begin
- Module.Active := Module.ModuleData.Init(Module.ModuleData) = 0;
- if Module.Active and assigned(Module.PlugIn) and assigned(Module.PlugIn.Callback) then
- Module.PlugIn.Callback(Module.PlugIn.User,paActivate);
- end;
- end;
- Result := Module.Active;
- except
- Result := False;
- // no exception please !!!
- end;
- end;
- {==============================================================================}
- function RenderPlugInVISModule(var Module: TVISModule): Boolean;
- begin
- try
- if (Module.ModuleData <> nil) and Module.Active and assigned(Module.ModuleData.Render) then
- Result := Module.ModuleData.Render(Module.ModuleData) = 0
- else
- Result := True;
- except
- Result := False;
- // no exception please !!!
- end;
- end;
- {==============================================================================}
- procedure QuitPlugInVISModule(var Module: TVISModule);
- begin
- try
- if (Module.ModuleData <> nil) and Module.Active and assigned(Module.ModuleData.Quit) then
- begin
- Module.ModuleData.Quit(Module.ModuleData);
- if assigned(Module.PlugIn) and assigned(Module.PlugIn.Callback) then
- Module.PlugIn.Callback(Module.PlugIn.User,paQuit);
- end;
- Module.Active := False;
- except
- // no exception please !!!
- end;
- end;
- end.