⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit2.pas

📁 delphi 多媒体声音控制控件 AMixer
💻 PAS
字号:
unit Unit2;

interface

{This is not probably absolutely universal, but all meters
 what I have in my system are controls of type
 MIXERCONTROL_CONTROLTYPE_PEAKMETER and this controls works
 good in this example.}

{Note: My Wave Output meter shows still zero values, when
 I am playing some wave file over ActiveMovie. (that's not
 fault of my component, this shows also MS Volume Control)
 If the same file is played in Sound Recorder, it is OK.}

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  AMixer, StdCtrls, MMSystem, ComCtrls, ExtCtrls;

const MaxMixers=10; {Maximum number of sound cards (10 cards in
                     one computer ????)}

type
  TForm1 = class(TForm)
    ListView: TListView;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    LastT:Integer;
    procedure DoIdle (Sender:TObject; var Done:Boolean);
  public
    Mixers:Array [0..MaxMixers] of TAudioMixer; {max. 10 mixers + one nil}
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var A,B,C,MC:Integer;

  procedure MeterCheck (Dest,Con,Cntr:Integer);
    {This procedure checks if specified control is
     volume meter. If yes - add it to ListView}
  var Ct:PMixerControl;
      LI:TListItem;
  begin
    If Con=-1 then
      Ct:=Mixers[MC].Destinations[Dest].Controls[Cntr]
    else
      Ct:=Mixers[MC].Destinations[Dest].Connections[Con].Controls[Cntr];
    If Ct.dwControlType AND MIXERCONTROL_CT_CLASS_MASK=MIXERCONTROL_CT_CLASS_METER then
    begin
      LI:=ListView.Items.Add;
      If Ct.dwControlType AND MIXERCONTROL_CONTROLF_DISABLED=MIXERCONTROL_CONTROLF_DISABLED then
        LI.Caption:='Disabled : '+Ct.szName
      else
        LI.Caption:=Ct.szName;
      LI.SubItems.Add ('');
      LI.SubItems.Add ('');      
      LI.SubItems.Add (IntToStr(MC));
      LI.SubItems.Add (IntToStr(Dest));
      LI.SubItems.Add (IntToStr(Con));
      LI.SubItems.Add (IntToStr(Cntr));
    end;
  end;

begin
  Mixers[0]:=TAudioMixer.Create (Self);
  MC:=0;
  while (MC<MaxMixers) AND (MC<Mixers[0].MixerCount) do
  begin
    If MC>0 then
    begin
      Mixers[MC]:=TAudioMixer.Create (Self);
      Mixers[MC].MixerID:=MC;
    end;
    For A:=0 to Mixers[MC].Destinations.Count-1 do
    begin
      For C:=0 to Mixers[MC].Destinations[A].Controls.Count-1 do
        MeterCheck (A,-1,C);
      For B:=0 to Mixers[MC].Destinations[A].Connections.Count-1 do
        For C:=0 to Mixers[MC].Destinations[A].Connections[B].Controls.Count-1 do
          MeterCheck (A,B,C);
    end;
    Inc (MC);
  end;
  If Mixers[0].MixerCount=0 then
  begin
    Mixers[0].Free;
    Mixers[0]:=nil;
  end
  else
    Mixers[MC]:=nil;
  LastT:=0;
  Application.OnIdle:=DoIdle;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var A:Integer;
begin
  A:=0;
  while Mixers[A]<>nil do
  begin
    Mixers[A].Free;
    Inc (A);
  end;
end;

procedure TForm1.DoIdle (Sender:TObject; var Done:Boolean);
var A,B:Integer;
    Ct:PMixerControl;
    MC,Dest,Con,Cntr:Integer;
    MCD:TMixerControlDetails;
    Details:Array [0..10] of Integer;
    S:String[40];
begin
  Done:=False;
  A:=GetTickCount;
  If A<LastT+10 then
    Exit;
  LastT:=A;
  For A:=0 to ListView.Items.Count-1 do
  begin
    MC:=StrToInt(ListView.Items[A].SubItems[2]);
    Dest:=StrToInt(ListView.Items[A].SubItems[3]);
    Con:=StrToInt(ListView.Items[A].SubItems[4]);
    Cntr:=StrToInt(ListView.Items[A].SubItems[5]);
    If Con=-1 then
    begin
      Ct:=Mixers[MC].Destinations[Dest].Controls[Cntr];
      MCD.cChannels:=Mixers[MC].Destinations[Dest].Data.cChannels;
    end
    else
    begin
      Ct:=Mixers[MC].Destinations[Dest].Connections[Con].Controls[Cntr];
      MCD.cChannels:=Mixers[MC].Destinations[Dest].Connections[Con].Data.cChannels;
    end;
    MCD.cbStruct:=SizeOf(TMixerControlDetails);
    MCD.dwControlID:=Ct.dwControlID;
    If Ct.fdwControl AND MIXERCONTROL_CONTROLF_MULTIPLE=MIXERCONTROL_CONTROLF_MULTIPLE then
      MCD.cMultipleItems:=Ct.cMultipleItems
    else
      MCD.cMultipleItems:=0;
    MCD.cbDetails:=4;
    MCD.paDetails:=@Details;
    B:=mixerGetControlDetails (Mixers[MC].MixerHandle,@MCD,MIXER_GETCONTROLDETAILSF_VALUE);
    If B=MMSYSERR_NOERROR then
    begin
      S:='';
      For B:=1 to Abs(Details[0]) div 2000 do
        S:=S+'|';
      If ListView.Items[A].SubItems[0]<>S then
        ListView.Items[A].SubItems[0]:=S;
      If MCD.cChannels>1 then
      begin
        S:='';
        For B:=1 to Abs(Details[1]) div 2000 do
          S:=S+'|';
        If ListView.Items[A].SubItems[1]<>S then
          ListView.Items[A].SubItems[1]:=S;
      end;
    end;
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -