📄 mmacmdlg.pas
字号:
{========================================================================}
function acmGetFilterDescription(pwfltr: PWaveFilter;var sFilterTag,sFilter: String): Boolean;
var
mmr : MMRESULT;
aftd: TACMFilterTagDetails;
afd : TACMFilterDetails;
begin
{ get the name for the filter tag of the specified filter }
Result := False;
if acmDLLLoaded and (HiWord(acmGetVersion) >= $0200) and (pwfltr <> nil) then
begin
{ initialize all unused members of the TACMFILTERTAGDETAILS }
{ structure to zero }
FillChar(aftd, sizeOf(aftd), 0);
{ fill in the required members of the TACMFILTERTAGDETAILS }
{ structure for the ACM_FILTERTAGDETAILSF_FILTERTAG query }
aftd.cbStruct := sizeOf(aftd);
aftd.dwFilterTag := pwfltr^.dwFilterTag;
{ ask the ACM to find the first available driver that }
{ supports the specified filter tag }
mmr := acmFilterTagDetails(0, @aftd, ACM_FILTERTAGDETAILSF_FILTERTAG);
if (mmr <> 0) then
{ no ACM driver is available that supports the specified filter tag }
sFilterTag := LoadResStr(IDS_WAVEUNKNOWN) + ' FilterTag'
else
{ copy the filter tag name into the caller's buffer }
sFilterTag := StrPas(aftd.szFilterTag);
{ get the description of the attributes for the specified filter }
{ initialize all unused members of the TACMFILTERDETAILS }
{ structure to zero }
FillChar(afd, sizeOf(afd), 0);
{ fill in the required members of the TACMFILTERDETAILS }
{ structure for the ACM_FILTERDETAILSF_FILTER query }
afd.cbStruct := sizeOf(afd);
afd.dwFilterTag := pwfltr^.dwFilterTag;
afd.pwfltr := pwfltr;
afd.cbwfltr := pwfltr^.cbStruct;
{ ask the ACM to find the first available driver that }
{ supports the specified filter }
mmr := acmFilterDetails(0, @afd, ACM_FILTERDETAILSF_FILTER);
if (mmr <> 0) then
{ no ACM driver is available that supports the specified filter }
sFilter := LoadResStr(IDS_WAVEUNKNOWN)+ ' Filter'
else
{ copy the filter attributes description into the caller's buffer }
sFilter := StrPas(afd.szFilter);
Result := True;
end;
end;
{========================================================================}
procedure acmSaveFormatToRegistry(pwfx: PWaveFormatEx;
RootKey: integer; const LocalKey,Field: String);
begin
SaveInRegistryBinary(RootKey,LocalKey,Field,pwfx^,wioSizeOfWaveFormat(pwfx));
end;
{========================================================================}
function acmGetFormatFromRegistry(RootKey: integer; const LocalKey,Field: String): PWaveFormatEx;
var
wfx: array[0..1024] of Char;
begin
if GetFromRegistryBinary(RootKey,LocalKey,Field,wfx,sizeOf(wfx)) > 0 then
Result := wioCopyWaveFormat(@wfx)
else
Result := nil;
end;
{== TMMACM =============================================================}
constructor TMMACM.Create(aOwner:TComponent);
begin
inherited Create(aOwner);
FACMPresent := False;
FEnumFormats := efAll;
FSource := nil;
FTitle := LoadResStr(IDS_ACMSELECT);
if (not acmDLLLoaded) then
begin
MessageDlg(LoadResStr(IDS_ACMNOACM), mtInformation, [mbOk], 0);
end
else
begin
FacmVersion := acmGetVersion;
if HiWord(FacmVersion) < $0200 then
begin
MessageDlg(Format(LoadResStr(IDS_ACMBADVERSION),
[HiWord(FacmVersion) shr 8,HiWord(FacmVersion) and $FF]),
mtInformation, [mbOk], 0);
exit;
end;
FACMPresent := True;
acmMetrics(0, ACM_METRIC_COUNT_DRIVERS, @FNumDrivers);
acmMetrics(0, ACM_METRIC_COUNT_CODECS, @FNumCodecs);
acmMetrics(0, ACM_METRIC_COUNT_CONVERTERS, @FNumConverters);
acmMetrics(0, ACM_METRIC_COUNT_FILTERS, @FNumFilters);
acmMetrics(0, ACM_METRIC_MAX_SIZE_FORMAT, @FMaxFormatSize);
acmMetrics(0, ACM_METRIC_MAX_SIZE_FILTER, @FMaxFilterSize);
AllocWaveHeader(FPWaveFormatEx);
AllocWaveFilter(FPWaveFilter);
end;
ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
end;
{-- TMMACM -------------------------------------------------------------}
Destructor TMMACM.Destroy;
begin
FreeWaveHeader(FPWaveFormatEx);
FreeWaveFilter(FPWaveFilter);
inherited Destroy;
end;
{-- TMMACM -------------------------------------------------------------}
procedure TMMACM.SetACMPresent(aValue: Boolean);
begin
{ dummy }
end;
{-- TMMACM -------------------------------------------------------------}
procedure TMMACM.SetNumDrivers(aValue: Longint);
begin
{ dummy }
end;
{-- TMMACM -------------------------------------------------------------}
procedure TMMACM.SetSource(aSource: TMMCustomWaveFile);
begin
if (aSource is TMMCustomWaveFile) or (aSource = Nil) then
begin
if (FSource <> aSource) then
begin
FSource := aSource;
end;
end;
end;
{-- TMMACM -------------------------------------------------------------}
procedure TMMACM.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FSource) then
FSource := Nil;
end;
{-- TMMACM -------------------------------------------------------------}
procedure TMMACM.SetPWaveFormat(aValue: PWaveFormatEx);
begin
if (aValue <> nil) then
move(aValue^, FPWaveFormatEx^, sizeOf(TWaveFormatEx) + aValue^.cbSize);
end;
{-- TMMACM -------------------------------------------------------------}
procedure TMMACM.SetPWaveFilter(aValue: PWaveFilter);
begin
if (aValue <> nil) then
move(aValue^, FPWaveFilter^, aValue^.cbStruct);
end;
{-- TMMACM -------------------------------------------------------------}
function TMMACM.GetWave: TMMWave;
begin
Result := nil;
if assigned(FSource) then
begin
Result := (FSource as TMMCustomWaveFile).Wave;
end;
end;
{-- TMMACM -------------------------------------------------------------}
procedure TMMACM.AllocWaveHeader(var pwfx: PWaveFormatEx);
begin
if ACMPresent and (FMaxFormatSize > 0) then
pwfx := GlobalAllocMem(FMaxFormatSize)
else
pwfx := nil;
end;
{-- TMMACM -------------------------------------------------------------}
procedure TMMACM.FreeWaveHeader(var pwfx: PWaveFormatEx);
begin
if ACMPresent then
GlobalFreeMem(pointer(pwfx));
end;
{-- TMMACM -------------------------------------------------------------}
procedure TMMACM.AllocWaveFilter(var pwfltr: PWaveFilter);
begin
if ACMPresent and (FMaxFilterSize > 0) then
pwfltr := GlobalAllocMem(FMaxFilterSize)
else
pwfltr := nil;
end;
{-- TMMACM -------------------------------------------------------------}
procedure TMMACM.FreeWaveFilter(var pwfltr: PWaveFilter);
begin
if ACMPresent then
GlobalFreeMem(pointer(pwfltr));
end;
{-- TMMACM -------------------------------------------------------------}
function TMMACM.GetFormatDescription(pwfx: PWaveFormatEx;var sFormatTag,sFormat: String): Boolean;
begin
Result := acmGetFormatDescription(pwfx,sFormatTag,sFormat);
end;
{-- TMMACM -------------------------------------------------------------}
function TMMACM.GetFilterDescription(pwfltr: PWaveFilter;var sFilterTag,sFilter: String): Boolean;
begin
Result := acmGetFilterDescription(pwfltr,sFilterTag,sFilter);
end;
{-----------------------------------------------------------------------}
function acmDriverEnumCallback(hadid: THACMDRIVERID; dwInstance, fdwSupport: DWORD): Boolean; stdcall;
begin
if (fdwSupport and ACMDRIVERDETAILS_SUPPORTF_CODEC <> 0) or
(fdwSupport and ACMDRIVERDETAILS_SUPPORTF_CONVERTER <> 0) then
begin
TList(dwInstance).Add(Pointer(hadid));
end;
end;
{-----------------------------------------------------------------------}
function acmFormatEnumTagCallback(hadid: THACMDRIVERID; paftd: PACMFORMATTAGDETAILS;
dwInstance, fdwSupport: DWORD): Boolean; stdcall;
begin
Result := False;
if (dwInstance <> 0) then
with TMMACM(dwInstance) do
begin
if assigned(FOnCodecEnum) then
FOnCodecEnum(TMMACM(dwInstance), paftd.dwFormatTag, StrPas(paftd.szFormatTag), Result);
end;
end;
{-----------------------------------------------------------------------}
function acmFormatEnumCallback(hadid: THACMDRIVERID; pafd: PACMFORMATDETAILS;
dwInstance, fdwSupport: DWORD): Boolean; stdcall;
begin
Result := False;
if (dwInstance <> 0) then
with TMMACM(dwInstance) do
begin
if assigned(FOnFormatEnum) then
FOnFormatEnum(TMMACM(dwInstance), pafd.pwfx, StrPas(pafd.szFormat), Result);
end;
end;
{-- TMMACM -------------------------------------------------------------}
function TMMACM.EnumerateCodecs: Boolean;
var
aftd: TACMFORMATTAGDETAILS;
begin
Result := False;
if not ACMPresent then exit;
FillChar(aftd,sizeOf(aftd),0);
aftd.cbStruct := sizeOf(aftd);
Result := acmFormatTagEnum(0, @aftd, acmFormatEnumTagCallback, Longint(Self), 0) = 0;
if not Result then // Bug Fix for Win98, some times the first call fails...
Result := acmFormatTagEnum(0, @aftd, acmFormatEnumTagCallback, Longint(Self), 0) = 0;
end;
{-- TMMACM -------------------------------------------------------------}
function TMMACM.EnumerateFormats(wFormatTag: integer): Boolean;
var
afd: TACMFORMATDETAILS;
fdwEnum: DWORD;
begin
Result := False;
if not ACMPresent then exit;
FillChar(afd,sizeOf(afd),0);
afd.cbStruct := sizeOf(afd);
afd.pwfx := GlobalAllocMem(FMaxFormatSize);
try
afd.pwfx.wFormatTag := wFormatTag;
afd.dwFormatTag := wFormatTag;
afd.cbwfx := FMaxFormatSize;
fdwEnum := ACM_FORMATENUMF_WFORMATTAG;
case FEnumFormats of
efInput : fdwEnum := fdwEnum or ACM_FORMATENUMF_INPUT;
efOutput : fdwEnum := fdwEnum or ACM_FORMATENUMF_OUTPUT;
end;
Result := acmFormatEnum(0, @afd, acmFormatEnumCallback, Longint(Self), fdwEnum) = 0;
finally
GlobalFreeMem(Pointer(afd.pwfx));
end;
end;
{-- TMMACM -------------------------------------------------------------}
function TMMACM.SuggestFormat(pwfxSrc: PWaveFormatEx; dwSuggest: Longint): Boolean;
var
mmr: MMRESULT;
cbwfx,cbwfxSrc: Longint;
begin
Result := False;
if not ACMPresent or (pwfxSrc = nil) then exit;
{ just in case no ACM driver is installed for the source format and }
{ the source has a larger format size than the largest enabled ACM }
{ driver... }
cbwfxSrc := wioSizeOfWaveFormat(pwfxSrc);
cbwfx := Max(FMaxFormatSize, cbwfxSrc);
if (cbwfx > FMaxFormatSize) then
begin
FMaxFormatSize := cbwfx;
FreeWaveHeader(FPWaveFormatEx);
AllocWaveHeader(FPWaveFormatEx);
end;
{$IFDEF WIN32}
{$IFDEF TRIAL}
{$DEFINE _HACK2}
{$I MMHACK.INC}
{$ENDIF}
{$ENDIF}
{ 'suggest anything' }
mmr := acmFormatSuggest(0, pwfxSrc, FPWaveFormatEx, cbwfx, dwSuggest);
if (mmr <> 0) then
move(pwfxSrc^, FPWaveFormatEx^, cbwfxSrc);
Result := True;
end;
{-- TMMACM -------------------------------------------------------------}
function TMMACM.ChooseFormat(pwfxSrc: PWaveFormatEx; Title: String): Boolean;
Label Again;
var
mmr : MMRESULT;
aBuf: array[0..255] of char;
afc : TACMFORMATCHOOSE;
cbwfx,cbwfxSrc: Longint;
TryCount: integer;
begin
Result := False;
if not ACMPresent then exit;
{ initialize the TACMFORMATCHOOSE members }
FillChar(afc, sizeOf(afc), 0);
if pwfxSrc <> nil then
begin
{ just in case no ACM driver is installed for the source format and }
{ the source has a larger format size than the largest enabled ACM }
{ driver... }
cbwfxSrc := wioSizeOfWaveFormat(pwfxSrc);
cbwfx := Max(FMaxFormatSize, cbwfxSrc);
if (cbwfx > FMaxFormatSize) then
begin
FMaxFormatSize := cbwfx;
FreeWaveHeader(FPWaveFormatEx);
AllocWaveHeader(FPWaveFormatEx);
end;
{ copy to our struc to init the dialog }
move(pwfxSrc^, FPWaveFormatEx^, cbwfxSrc);
afc.fdwStyle := afc.fdwStyle or ACMFORMATCHOOSE_STYLEF_INITTOWFXSTRUCT;
end;
afc.cbStruct := sizeof(afc);
if (Owner <> nil) then
afc.hwndOwner := (Owner as TWinControl).Handle;
afc.pwfx := FPWaveFormatEx;
afc.cbwfx := FMaxFormatSize;
if (Title <> '') then
afc.pszTitle := StrPCopy(aBuf, Title);
afc.szFormatTag[0] := #0;
afc.szFormat[0] := #0;
afc.pszName := nil;
afc.cchName := 0;
afc.pwfxEnum := nil;
afc.fdwEnum := 0;
{$IFDEF WIN32}
{$IFDEF TRIAL}
{$DEFINE _HACK3}
{$I MMHACK.INC}
{$ENDIF}
{$ENDIF}
case FEnumFormats of
efInput : afc.fdwEnum := ACM_FORMATENUMF_INPUT;
efOutput : afc.fdwEnum := ACM_FORMATENUMF_OUTPUT;
efConvert: if (pwfxSrc <> nil) then
begin
afc.fdwEnum := ACM_FORMATENUMF_CONVERT;
afc.pwfxEnum:= pwfxSrc;
end;
efSuggest: if (pwfxSrc <> nil) then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -