Solved

Getting the volume and changing of volume

Posted on 1998-05-10
13
284 Views
Last Modified: 2010-04-06
hi,

How do I get the Windows volume, for MasterVolume, Wav volume and Midi volume, and set it up so I can change it with a Slider, I think I will need to make use of Onformcreate and Onsliderchange

So the Code for
Procedure TForm1.onformcreate....
begin
Slider1.Max := ...
Slider1.min := ...
Slider1.Position := ...
end;

and for Sliderchange

Procedure TForm1.onslider1change...
begin
....
end;

Please make it cut and paste code as much as possible, and comment it. So I can follow.
Lot's of points so make it good.
0
Comment
Question by:degraef
  • 6
  • 5
  • 2
13 Comments
 
LVL 4

Accepted Solution

by:
BoRiS earned 500 total points
ID: 1344065
hey degraef

Here is a pas file on how to retrieve the volumes ect...

I got it from one of the best components I've used in a long time it's called cdplayer
by Anton Bil check his page for updates: http://www.HZeeland.nl/~abil/download/download.hml)

unit Volume;

interface

uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls, Buttons,
  StdCtrls, Slider, ExtCtrls, mmsystem; //add this to uses clause

const AuxDev:byte=2;
      Step : integer = 1000; {volume step}

type
  TChangeVol = (cvUp, cvDown);//to change vol
  TVolType = (vtLeft, vtRight);//type of vol right left etc...
  TVol = array[vtLeft..vtRight]of word;//array for left right
  TVolumeDlg = class(TForm)//form with following comp's on it
    OKBtn: TBitBtn;
    Bevel1: TBevel;
    LeftSlider: TSlider;
    RightSlider: TSlider;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    MainSlider: TSlider;
    Label4: TLabel;
    ComboBox1: TComboBox;
    Panel1: TPanel;
    Help: TBitBtn;
    procedure FormActivate(Sender: TObject);
    procedure RightSliderValueChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure MainSliderValueChange(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure RightSliderMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure RightSliderKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure LeftSliderKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure LeftSliderMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure MainSliderMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure MainSliderKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
    Vol : TVol;
    procedure GetVolume;
    procedure SetVolume;
    procedure initActivate;
    procedure GetVolumes(DevId : word;
                         var VolLeft, VolRight : word);
  end;

var
  VolumeDlg: TVolumeDlg;

implementation

{$R *.DFM}

procedure TVolumeDlg.GetVolume;
var myvolume:longint;
begin
  auxgetvolume(AuxDev,addr(myvolume));
  LeftSlider.value:=myvolume mod 65536;
  RightSlider.value:=myvolume div 65536;
end;

procedure TVolumeDlg.initActivate;
var s:string;
begin
  GetVolumes(auxdev, Vol[vtLeft], Vol[vtRight]);
{  ChangeVol(cvup);
  ChangeVol(cvdown);}
  LeftSlider.value:=vol[vtLeft];
  RightSlider.value:=vol[vtRight];
  ComboBox1.itemindex:=AuxDev;
  str(auxdev:1,s);
  Caption:='Volume aux'+s;
end;


procedure TVolumeDlg.FormActivate(Sender: TObject);
begin
  InitActivate;
end;

procedure TVolumeDlg.SetVolume;
begin
  auxsetvolume(AuxDev,longint(RightSlider.value)*65536+longint(LeftSlider.value));
end;

procedure TVolumeDlg.RightSliderValueChange(Sender: TObject);
begin
 with sender as TSlider do
 begin
  SetVolume;
  if MainSlider.Value<value then
  MainSlider.Value:=value;
  if (MainSlider.Value>LeftSlider.value) and
      (MainSlider.Value>RightSlider.value) then
    if RightSlider.value>LeftSlider.value then
    MainSlider.Value:=RightSlider.value else
     MainSlider.Value:=LeftSlider.value;
 end;
end;

procedure TVolumeDlg.FormCreate(Sender: TObject);
begin
  GetVolume;
end;

procedure TVolumeDlg.MainSliderValueChange(Sender: TObject);
var previous,diff:longint;
    RG:boolean;
begin
  RG:=RightSlider.value>LeftSlider.Value;
  if RG then
  previous:=RightSlider.value else
  previous:=LeftSlider.Value;
  diff:=MainSlider.value-previous;
  RightSlider.value:=RightSlider.value+diff;
  LeftSlider.value:=LeftSlider.value+diff;
end;

procedure TVolumeDlg.ComboBox1Change(Sender: TObject);
begin
  AuxDev:=ComboBox1.itemindex;
  InitActivate;
end;

procedure TVolumeDlg.RightSliderMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  RightSliderValueChange(Self);
end;

procedure TVolumeDlg.RightSliderKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  RightSliderValueChange(Self);
end;

procedure TVolumeDlg.LeftSliderKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  RightSliderValueChange(Self);
end;

procedure TVolumeDlg.LeftSliderMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  RightSliderValueChange(Self);
end;

procedure TVolumeDlg.MainSliderMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  MainSliderValueChange(Self);
end;

procedure TVolumeDlg.MainSliderKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  MainSliderValueChange(Self);
end;

procedure TVolumeDlg.GetVolumes(DevId : word;
                            var VolLeft, VolRight : word);
{volume is returned as a pointer to a DWord with the most
 significant word for the left channel. The channels are
 extracted by treating the DWord as a two element  array and
 accessing the two array elements for the Lt and Rt volumes}
var
  Error : integer;
  TempVol : TVol;
begin
  Error := AuxGetVolume(DevId, @TempVol);
  if Error <> 0 then begin
    Exit;
  end;
  VolLeft := TempVol[vtLeft];
  VolRight := TempVol[vtRight];
end;

end.  

this component is freeware so check it out...

Later
BoRiS
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1344066
here is another one to checkout also very good its form the delphideli

www.delphideli.com

then goto components and then audio its called volumes.zip

excellent

Later
BoRiS
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344067
Hi degraef,

For these things I use an excellent freeware component, it can change everything from volume to the balance ....

Look at there delphi pages :

http://web.access.net.au/%7Egchandle/

TVolumeControl: Want your own Win95 volume control in your applications? Then use this. And link it to the
        TBalanceControl component for a complete package. Control the Master, CD, Mic, Auxillary, Midi, Wave, Line-In volume
        levels.
       
        TBalanceControl: Link the balance control to the TVolumeControl to have your own volume and balance control package in
        your applications. Control the Master, CD, Mic, Auxillary, Midi, Wave, Line-In balance levels.

Offcourse, I haven't saw BoRiS components, so if they are better, please NOTIFY me about them.... (so I become also better of this question ;-) )

Regards, ZiF.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:degraef
ID: 1344068
hi,

I downloaded the volumes.zip, haven't looked at it yet, but I suspect it is a slider.
The GrabBag which zifnab suggested I already have.
I should explain I am using the Rxslider from the rxlibrary, because I use a futuristic display I cannot use those W95 looking sliders, with the Rxslider I can choose the layout of the slider with pictures, so I need to use it. I tried linking the rxslider with the volumecontrol from the grabbag but that didn't work, I'll check out the volumes.zip and try the code suggested, will keep you updated
0
 

Author Comment

by:degraef
ID: 1344069
No, on both accounts. The volumes.zip requires a trackbar and does not work with rxSlider. Besides it did not have a master volume

And the code, it didn't do anything except with the sliders, they moved together, that is not what I need.

Better ideas please
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1344070
degraef

The reason for the code was to show you how to get the volume and set the volume

I have edited the volumes.zip and allowed it accept the rxslider and master volume controls etc.

So I'm sure you can do the same, the component comes with the source just add what you need and recompile it...

any problems let me know

Later
BoRiS
0
 

Author Comment

by:degraef
ID: 1344071
I havent got a clue how to make a component, let alone change it. The point of me giving 500 points was that someone could give me an example of how to do it. So If you have already made it, then please post the edited pas file here.
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1344072
I tell you what give me your mail address and i'll mail it you with a description on what is happening...

Then we can grade the answer...

Later
BoRiS
0
 

Author Comment

by:degraef
ID: 1344073
E-Mail = bs130956@skynet.be

Thanks, if it works, it will be worth it.
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1344074
K will send it you

Later
BoRiS
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1344075
hi all, if you still got problems tomorrow, I'm willing to make a working piece for you. But I guess BoRiS source code will work just fine. Regards, ZiF.
0
 

Author Comment

by:degraef
ID: 1344076
At the moment, I am unable to install the new volumes.dcu, because it is compiled under a different version of rxslider, so i'm still waiting, no pressure take your time to make it. :-)
0
 
LVL 4

Expert Comment

by:BoRiS
ID: 1344077
degaef

K I'll check it out, what version of the Rx lib are you using, O I'll change the name to I checkout the the component Zifnab suggested (hmmmm, not bad) but I see they use a volumes unit to.

Well I'll mail you the new Now-Now

Later
BoRiS
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question