📄 jclmultimedia.pas
字号:
Item: TJclMixerLineControl;
begin
GetMem(Controls, SizeOf(TMixerControl) * FLineInfo.cControls);
try
MixerControls.cbStruct := SizeOf(MixerControls);
MixerControls.dwLineID := FLineInfo.dwLineID;
MixerControls.cControls := FLineInfo.cControls;
MixerControls.cbmxctrl := SizeOf(TMixerControl);
MixerControls.pamxctrl := Controls;
if mixerGetLineControls(FMixerDevice.Handle, @MixerControls, MIXER_GETLINECONTROLSF_ALL) = MMSYSERR_NOERROR then
begin
P := Controls;
for I := 1 to FLineInfo.cControls do
begin
Item := TJclMixerLineControl.Create(Self, P^);
FLineControls.Add(Item);
Inc(P);
end;
end;
finally
FreeMem(Controls);
end;
end;
class function TJclMixerLine.ComponentTypeToString(const ComponentType: DWORD): string;
begin
case ComponentType of
MIXERLINE_COMPONENTTYPE_DST_UNDEFINED:
Result := RsMmMixerUndefined;
MIXERLINE_COMPONENTTYPE_DST_DIGITAL, MIXERLINE_COMPONENTTYPE_SRC_DIGITAL:
Result := RsMmMixerDigital;
MIXERLINE_COMPONENTTYPE_DST_LINE, MIXERLINE_COMPONENTTYPE_SRC_LINE:
Result := RsMmMixerLine;
MIXERLINE_COMPONENTTYPE_DST_MONITOR:
Result := RsMmMixerMonitor;
MIXERLINE_COMPONENTTYPE_DST_SPEAKERS:
Result := RsMmMixerSpeakers;
MIXERLINE_COMPONENTTYPE_DST_HEADPHONES:
Result := RsMmMixerHeadphones;
MIXERLINE_COMPONENTTYPE_DST_TELEPHONE, MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE:
Result := RsMmMixerTelephone;
MIXERLINE_COMPONENTTYPE_DST_WAVEIN:
Result := RsMmMixerWaveIn;
MIXERLINE_COMPONENTTYPE_DST_VOICEIN:
Result := RsMmMixerVoiceIn;
MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE:
Result := RsMmMixerMicrophone;
MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER:
Result := RsMmMixerSynthesizer;
MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC:
Result := RsMmMixerCompactDisc;
MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER:
Result := RsMmMixerPcSpeaker;
MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT:
Result := RsMmMixerWaveOut;
MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY:
Result := RsMmMixerAuxiliary;
MIXERLINE_COMPONENTTYPE_SRC_ANALOG:
Result := RsMmMixerAnalog;
else
Result := '';
end;
end;
function TJclMixerLine.GetComponentString: string;
begin
Result := ComponentTypeToString(FLineInfo.dwComponentType);
end;
function TJclMixerLine.GetHasControlType(ControlType: DWORD): Boolean;
begin
Result := LineControlByType[ControlType] <> nil;
end;
function TJclMixerLine.GetID: DWORD;
begin
Result := LineInfo.dwLineID;
end;
function TJclMixerLine.GetLineControlByType(ControlType: DWORD): TJclMixerLineControl;
var
I: Integer;
begin
Result := nil;
for I := 0 to LineControlCount - 1 do
if LineControls[I].ControlInfo.dwControlType = ControlType then
begin
Result := LineControls[I];
Break;
end;
end;
function TJclMixerLine.GetLineControlCount: Integer;
begin
Result := FLineControls.Count;
if Result = 0 then
begin
BuildLineControls;
Result := FLineControls.Count;
end;
end;
function TJclMixerLine.GetLineControls(Index: Integer): TJclMixerLineControl;
begin
Result := TJclMixerLineControl(FLineControls[Index]);
end;
function TJclMixerLine.GetName: string;
begin
Result := FLineInfo.szName;
end;
//=== { TJclMixerSource } ====================================================
constructor TJclMixerSource.Create(AMixerDestination: TJclMixerDestination; ASourceIndex: Cardinal);
begin
inherited Create(AMixerDestination.MixerDevice);
FMixerDestination := AMixerDestination;
FLineInfo.cbStruct := SizeOf(FLineInfo);
FLineInfo.dwDestination := FMixerDestination.LineInfo.dwDestination;
FLineInfo.dwSource := ASourceIndex;
MMCheck(mixerGetLineInfo(FMixerDestination.MixerDevice.Handle, @FLineInfo, MIXER_GETLINEINFOF_SOURCE));
end;
//=== { TJclMixerDestination } ===============================================
constructor TJclMixerDestination.Create(AMixerDevice: TJclMixerDevice; ADestinationIndex: Cardinal);
begin
inherited Create(AMixerDevice);
FLineInfo.cbStruct := SizeOf(FLineInfo);
FLineInfo.dwDestination := ADestinationIndex;
MMCheck(mixerGetLineInfo(AMixerDevice.Handle, @FLineInfo, MIXER_GETLINEINFOF_DESTINATION));
FSources := TObjectList.Create;
end;
destructor TJclMixerDestination.Destroy;
begin
FreeAndNil(FSources);
inherited Destroy;
end;
procedure TJclMixerDestination.BuildSources;
var
I: Cardinal;
Item: TJclMixerSource;
begin
for I := 1 to LineInfo.cConnections do
begin
Item := TJclMixerSource.Create(Self, I - 1);
FSources.Add(Item);
end;
end;
function TJclMixerDestination.GetSourceCount: Integer;
begin
Result := FSources.Count;
if Result = 0 then
begin
BuildSources;
Result := FSources.Count;
end;
end;
function TJclMixerDestination.GetSources(Index: Integer): TJclMixerSource;
begin
Result := TJclMixerSource(FSources[Index]);
end;
//=== { TJclMixerDevice } ====================================================
constructor TJclMixerDevice.Create(ADeviceIndex: Cardinal; ACallBackWnd: HWND);
begin
FDeviceIndex := ADeviceIndex;
FHandle := -1;
FDestinations := TObjectList.Create;
FLines := TList.Create;
MMCheck(mixerGetDevCaps(ADeviceIndex, @FCapabilities, SizeOf(FCapabilities)));
Open(ACallBackWnd);
BuildDestinations;
end;
destructor TJclMixerDevice.Destroy;
begin
Close;
FreeAndNil(FDestinations);
FreeAndNil(FLines);
inherited Destroy;
end;
procedure TJclMixerDevice.BuildDestinations;
var
I: Cardinal;
Item: TJclMixerDestination;
begin
for I := 1 to FCapabilities.cDestinations do
begin
Item := TJclMixerDestination.Create(Self, I - 1);
FDestinations.Add(Item);
end;
end;
procedure TJclMixerDevice.BuildLines;
var
D, I: Integer;
Dest: TJclMixerDestination;
begin
for D := 0 to DestinationCount - 1 do
begin
Dest := Destinations[D];
FLines.Add(Dest);
for I := 0 to Dest.SourceCount - 1 do
FLines.Add(Dest.Sources[I]);
end;
FLines.Sort(MixerLineCompareID);
end;
procedure TJclMixerDevice.Close;
begin
if FHandle <> -1 then
begin
mixerClose(FHandle);
FHandle := -1;
end;
end;
function TJclMixerDevice.FindLineControl(ComponentType, ControlType: DWORD): TJclMixerLineControl;
var
TempLine: TJclMixerLine;
begin
Result := nil;
TempLine := LineByComponentType[ComponentType];
if TempLine <> nil then
Result := TempLine.LineControlByType[ControlType];
end;
function TJclMixerDevice.GetDestinationCount: Integer;
begin
Result := FDestinations.Count;
end;
function TJclMixerDevice.GetDestinations(Index: Integer): TJclMixerDestination;
begin
Result := TJclMixerDestination(FDestinations[Index]);
end;
function TJclMixerDevice.GetLineByComponentType(ComponentType: DWORD): TJclMixerLine;
var
I: Integer;
begin
Result := nil;
for I := 0 to LineCount - 1 do
if Lines[I].LineInfo.dwComponentType = ComponentType then
begin
Result := Lines[I];
Break;
end;
end;
function TJclMixerDevice.GetLineByID(LineID: DWORD): TJclMixerLine;
var
I: Integer;
begin
I := SearchSortedUntyped(Self, LineCount, MixerLineSearchID, Pointer(LineID));
if I = -1 then
Result := nil
else
Result := Lines[I];
end;
function TJclMixerDevice.GetLineControlByID(ControlID: DWORD): TJclMixerLineControl;
var
L, C: Integer;
TempLine: TJclMixerLine;
begin
Result := nil;
for L := 0 to LineCount - 1 do
begin
TempLine := Lines[L];
for C := 0 to TempLine.LineControlCount - 1 do
if TempLine.LineControls[C].ID = ControlID then
begin
Result := TempLine.LineControls[C];
Break;
end;
end;
end;
function TJclMixerDevice.GetLineCount: Integer;
begin
Result := FLines.Count;
if Result = 0 then
begin
BuildLines;
Result := FLines.Count;
end;
end;
function TJclMixerDevice.GetLines(Index: Integer): TJclMixerLine;
begin
Result := TJclMixerLine(FLines[Index]);
end;
function TJclMixerDevice.GetLineUniformValue(ComponentType, ControlType: DWORD): Cardinal;
var
LineControl: TJclMixerLineControl;
begin
LineControl := FindLineControl(ComponentType, ControlType);
if LineControl <> nil then
Result := LineControl.UniformValue
else
Result := 0;
end;
function TJclMixerDevice.GetProductName: string;
begin
Result := FCapabilities.szPname;
end;
procedure TJclMixerDevice.Open(ACallBackWnd: HWND);
var
Flags: DWORD;
begin
if FHandle = -1 then
begin
Flags := MIXER_OBJECTF_HMIXER;
if ACallBackWnd <> 0 then
Inc(Flags, CALLBACK_WINDOW);
MMCheck(mixerOpen(@FHandle, DeviceIndex, ACallBackWnd, 0, Flags));
end;
end;
procedure TJclMixerDevice.SetLineUniformValue(ComponentType, ControlType: DWORD; const Value: Cardinal);
var
LineControl: TJclMixerLineControl;
begin
LineControl := FindLineControl(ComponentType, ControlType);
if LineControl <> nil then
LineControl.UniformValue := Value
else
raise EJclMixerError.CreateResFmt(@RsMmMixerCtlNotFound,
[TJclMixerLine.ComponentTypeToString(ComponentType), ControlType]);
end;
//=== { TJclMixer } ==========================================================
constructor TJclMixer.Create(ACallBackWnd: HWND);
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -