Изменение громкости

Советы » Аудио » Изменение громкости

Данный пример уж очень расширен. Зато все очень выглядит красиво.

unit

svol; interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, MMsystem, Buttons; type

TSetVol = class(TForm) VolBar: TProgressBar; SpeedButton1: TSpeedButton; SpeedButton2: TSpeedButton; procedure FormCreate(Sender: TObject); procedure VolBarMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); procedure FormDestroy(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); procedure SpeedButton2Click(Sender: TObject); private { Private declarations } procedure MixCtrlChange(var mess : TMessage); message MM_MIXM_CONTROL_CHANGE; public { Public declarations } end; var

SetVol: TSetVol; hmix:integer; mixcaps:TMixerCaps; volumeID,volmin,volmax:integer; details:TMixerControlDetails; mixctrl:TMixerControl; valdets:TMixerControlDetailsUnsigned; curvolume:dword; svEnable : boolean; implementation

{$R *.DFM} procedure

TSetVol.MixCtrlChange(var mess : TMessage); begin

if not svEnable then exit; if SetVol.WindowState=wsMinimized then exit; details.cbStruct:=sizeof(details); details.dwControlID:=VolumeID; details.cChannels:=1; details.cMultipleItems:=0; details.cbDetails:=sizeof(valdets); details.paDetails:=@valdets; mixerGetControlDetails(hmix,@details,MIXER_GETCONTROLDETAILSF_VALUE); curvolume:=valdets.dwValue; SetVol.VolBar.Position:=curvolume; end

; procedure

TSetVol.FormCreate(Sender: TObject); var

i:integer; mixline:TMixerLine; mixlinectrl:TMixerLineControls; mixctrl:TMixerControl; begin

inherited; hVolForm:=Handle; Left:=80; Top:=TBHeight+2; mixerOpen(@hmix,0,Handle,0,MIXER_OBJECTF_MIXER or CALLBACK_WINDOW); mixerGetDevCaps(0,@mixcaps,sizeof(mixcaps)) for i:=0 to mixcaps.cDestinations-1 do begin mixline.dwDestination:=i; mixline.cbStruct:=sizeof(mixline); mixerGetLineInfo(hmix,@mixline,MIXER_GETLINEINFOF_DESTINATION); if mixline.dwComponentType=MIXERLINE_COMPONENTTYPE_DST_SPEAKERS then break; end; if mixline.dwComponentType<>MIXERLINE_COMPONENTTYPE_DST_SPEAKERSthen begin ShowMessage('Hет миксера!!!'); svEnable:=False; exit; end else svEnable:=true; mixlinectrl.cbStruct:=sizeof(mixlinectrl); mixlinectrl.dwControlType:=MIXERCONTROL_CONTROLTYPE_VOLUME; mixlinectrl.dwLineID:=mixline.dwLineID; mixlinectrl.cControls:=2; mixlinectrl.cbmxctrl:=sizeof(mixctrl); mixctrl.dwControlType:=MIXERCONTROL_CONTROLTYPE_VOLUME; mixlinectrl.pamxctrl:=@mixctrl; mixerGetLineControls(hmix,@mixlinectrl,MIXER_GETLINECONTROLSF_ONEBYTYPE); VolumeID:=mixctrl.dwControlID; volmin:=mixctrl.Bounds.dwMinimum; volmax:=mixctrl.Bounds.dwMaximum; details.cbStruct:=sizeof(details); details.dwControlID:=VolumeID; details.cChannels:=1; details.cMultipleItems:=0; details.cbDetails:=sizeof(valdets); details.paDetails:=@valdets; mixerGetControlDetails(hmix,@details,MIXER_GETCONTROLDETAILSF_VALUE); curvolume:=valdets.dwValue; VolBar.Min:=volmin; VolBar.Max:=volmax; VolBar.Position:=curvolume; end

; procedure

TSetVol.VolBarMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin

if not svEnable then exit; X:=Round(X/VolBar.Width*(VolBar.Max-VolBar.Min)+VolBar.Min); VolBar.Position:=X; details.cbStruct:=sizeof(details); details.dwControlID:=VolumeID; details.cChannels:=1; details.cMultipleItems:=0; details.cbDetails:=sizeof(valdets); details.paDetails:=@valdets; if X>4000 then valdets.dwValue:=VolBar.Position else valdets.dwValue:=0; mixerSetControlDetails(hmix,@details,MIXER_SETCONTROLDETAILSF_VALUE); end

; procedure

TSetVol.FormDestroy(Sender: TObject); begin

hVolForm:=0; if not svEnable then exit; mixerClose(hmix); inherited; end

; procedure

TSetVol.SpeedButton1Click(Sender: TObject); begin

if not svEnable then exit; VolBar.Position:=VolBar.Position-(VolBar.Max-VolBar.Min)div 10; if VolBar.Position4000then valdets.dwValue:=VolBar.Position else valdets.dwValue:=0; mixerSetControlDetails(hmix,@details,MIXER_SETCONTROLDETAILSF_VALUE); end

; procedure

TSetVol.SpeedButton2Click(Sender: TObject); begin

if not svEnable then exit; VolBar.Position:=VolBar.Position+(VolBar.Max-VolBar.Min)div 10; if VolBar.Position>VolBar.Maxthen VolBar.Position:=VolBar.Max; details.cbStruct:=sizeof(details); details.dwControlID:=VolumeID; details.cChannels:=1; details.cMultipleItems:=0; details.cbDetails:=sizeof(valdets); details.paDetails:=@valdets; if VolBar.Position>4000then valdets.dwValue:=VolBar.Position else valdets.dwValue:=0; mixerSetControlDetails(hmix,@details,MIXER_SETCONTROLDETAILSF_VALUE); end

; end

.

Другое по теме:

Категории

Статьи

Советы

Copyright © 2022 - All Rights Reserved - www.delphirus.com