this slowpoke moves

Volume Control Replacement Api

uses MMSystem

private
    { Private-Deklarationen }
    BackupVolumes: array[0..MAX_COMP_TYPES] of DWord;
    
const
  ComponentTypes: array[0..MAX_COMP_TYPES] of DWord =
    (MIXERLINE_COMPONENTTYPE_DST_FIRST, MIXERLINE_COMPONENTTYPE_DST_UNDEFINED,
    MIXERLINE_COMPONENTTYPE_DST_DIGITAL, MIXERLINE_COMPONENTTYPE_DST_LINE,
    MIXERLINE_COMPONENTTYPE_DST_MONITOR, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,
    MIXERLINE_COMPONENTTYPE_DST_HEADPHONES, MIXERLINE_COMPONENTTYPE_DST_TELEPHONE,
    MIXERLINE_COMPONENTTYPE_DST_WAVEIN, MIXERLINE_COMPONENTTYPE_DST_VOICEIN,
    MIXERLINE_COMPONENTTYPE_DST_LAST, MIXERLINE_COMPONENTTYPE_SRC_FIRST,
    MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED, MIXERLINE_COMPONENTTYPE_SRC_DIGITAL,
    MIXERLINE_COMPONENTTYPE_SRC_LINE, MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE,
    MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER, MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC,
    MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE, MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER,
    MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT, MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY,
    MIXERLINE_COMPONENTTYPE_SRC_ANALOG, MIXERLINE_COMPONENTTYPE_SRC_LAST);
    
//

function GetMixerControlID(CompType: DWORD): DWORD;
var
  mxl: MIXERLINE;
  mxc: MIXERCONTROL;
  mxlc: MIXERLINECONTROLS;
begin
  Result := 0;
  mxl.cbStruct := SizeOf(mxl);
  mxl.dwComponentType := CompType;
  if (mixerGetLineInfo(0, @mxl, MIXER_GETLINEINFOF_COMPONENTTYPE) = MMSYSERR_NOERROR) then
  begin
    mxlc.cbStruct := SizeOf(mxlc);
    mxlc.dwLineID := mxl.dwLineID;
    mxlc.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
    mxlc.cControls := mxl.cControls;
    mxlc.cbmxctrl := sizeof(mxc);
    mxlc.pamxctrl := @mxc;
    if (mixerGetLineControls(0, @mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE) = MMSYSERR_NOERROR) then
      Result := mxc.dwControlID;
  end;
end;

function SetVolume(ID, Value: DWord): Boolean;
var
  Volume: array[0..1] of TMixerControlDetails_Unsigned;
  mxcd: TMixerControlDetails;
begin
  Volume[0].dwValue := Value;
  Volume[1].dwValue := Value;
  with mxcd Do
  begin
    cbStruct := SizeOf(mxcd);
    dwControlID := ID;
    cChannels := 2;
    cMultipleItems := 0;
    cbDetails := SizeOf(TMixerControlDetails_Unsigned) * 2;
    paDetails := @Volume;
    Result := (mixerSetControlDetails(0, @mxcd, MIXER_SETCONTROLDETAILSF_VALUE) = MMSYSERR_NOERROR);
  end;
end;

function GetVolume(ID: DWord): DWord;
var
  Volume: array[0..1] of TMixerControlDetails_Unsigned;
  mxcd: TMixerControlDetails;
begin
  Result := 0;
  with mxcd Do
  begin
    cbStruct := SizeOf(mxcd);
    dwControlID := ID;
    cChannels := 2;
    cMultipleItems := 0;
    cbDetails := SizeOf(TMixerControlDetails_Unsigned) * 2;
    paDetails := @Volume;
  end;
  if (mixerGetControlDetails(0, @mxcd, MIXER_GETCONTROLDETAILSF_VALUE) = MMSYSERR_NOERROR) then
  begin
    Result := Volume[0].dwValue;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  MixerCtrlID: DWord;
begin
  MixerCtrlID := GetMixerControlID(ComponentTypes[ComboBox1.ItemIndex]);
  SetVolume(MixerCtrlID, 0);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  MixerCtrlID: DWord;
begin
  MixerCtrlID := GetMixerControlID(ComponentTypes[ComboBox1.ItemIndex]);
  Label1.Caption := IntToStr(GetVolume(MixerCtrlID));
  Trackbar1.Position := 65535 - GetVolume(MixerCtrlID);
end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
  Edit1.Text := IntToStr(65535 - Trackbar1.Position);
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  i: Integer;
  MixerCtrlID: DWord;
begin
  ComboBox1.ItemIndex := 5;
  for i := 0 to Length(BackupVolumes) - 1 do
  begin
    MixerCtrlID := GetMixerControlID(ComponentTypes[i]);
    BackUpVolumes[i] := GetVolume(MixerCtrlID);
  end;
end;

procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Edit1.Text <> '' then Trackbar1.Position := 65535 - StrToInt(Edit1.Text);
end;

procedure TForm1.FormDestroy(Sender: TObject);
var
  i: Integer;
  MixerCtrlID: DWord;
begin
  for i := 0 to Length(BackupVolumes) - 1 do
  begin
    MixerCtrlID := GetMixerControlID(ComponentTypes[i]);
    SetVolume(MixerCtrlID, BackUpVolumes[i]);
  end;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  ShowMessage('Mixer is now resetting all volume levels to the initial values when Mixer was started!');
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate