Author Topic: Stereo vol/pan slider  (Read 2288 times)

3delite

  • Posts: 895
Stereo vol/pan slider
« on: 6 Jul '04 - 14:40 »
I'm a bit confused about making a working slider for setting volume and panning at the same time. I mean how to do that??? There is a checkbox to control both sliders, the same as setting the volume, but unchecked it should work as a panning control like setting the volume of the left or the right channel. The same time it should get the parameters too (to see as the stream channel fades out). Any ideas?  ???
I could post my code, but it doesn't quite work like it should and don't want to spoil some good thoughts, if there are any.  ;)

Irrational86

  • Posts: 960
Re:Stereo vol/pan slider
« Reply #1 on: 7 Jul '04 - 06:23 »
This is my untested code, please give it a try...

make both slider max to 0 and min to -100, that way it works down-side up...in other words, runs from below to the top.
Quote
if SliderLeft.Position > SliderRight.Position then
begin
  SetBassVolume(-1 * SliderLeft.Position); // 0 to 100 ...multiply by -1 since its from 0 to -100
  SetBassPan(SliderLeft.Position - SliderRight.Position) // -100 to 100 ...difference in chan vols = pan (right?)
end
else
begin

  SetBassVolume(-1 * SliderRight.Position); // 0 to 100 ...multiply by -1 since its from 0 to -100
  SetBassPan(SliderRight.Position - SliderLeft.Position) // -100 to 100 ...difference in chan vols = pan (right?)
end;

3delite

  • Posts: 895
Re:Stereo vol/pan slider
« Reply #2 on: 7 Jul '04 - 15:56 »
Thanks XMinioNX!  :)

My idea was similar, so finally this works nice:

Code: [Select]
procedure TMainForm.TrackBarSVolRChange(Sender: TObject);
begin
    if CheckBoxStreamVolS.Checked then begin
        if (Sender as TTRackBar).Name = 'TrackBarSVolL'
            then TrackBarSVolR.Position := TrackBarSVolL.Position;
        if (Sender as TTRackBar).Name = 'TrackBarSVolR'
            then TrackBarSVolL.Position := TrackBarSVolR.Position;
    end;
    if (Sender as TTrackBar).Tag <> 1
        then ChangeVolStream;
end;

procedure TMainForm.ChangeVolStream;
begin
    with Streams.Index[Index] do begin
        if (100 - TrackBarSVolL.Position) > (100 - TrackBarSVolR.Position)
            then ChannelVol := (100 - TrackBarSVolL.Position)
            else ChannelVol := (100 - TrackBarSVolR.Position);
        BASS_ChannelSetAttributes(Channel,  -1, ChannelVol, TrackBarSVolL.Position - TrackBarSVolR.Position);
    end;
end;

//* This needs to be called periodiacaly to update the sliders
procedure TMainForm.StreamRefreshBassStatusInfo(Index:Integer);
var
  pan: Integer;
  vol, smpl: Cardinal;
begin
    BASS_ChannelGetAttributes(Channel, smpl, vol, pan);
    //* This turns off updateing BASS_ChannelSetAttributes() so only the slider positions are updated
    TrackBarSVolL.Tag := 1;
    TrackBarSVolR.Tag := 1;
    if pan > 0 then begin
        TrackBarSVolR.Position := 100 - vol;
        TrackBarSVolL.Position := TrackBarSVolR.Position + pan;
    end else begin
        TrackBarSVolL.Position := 100 - vol;
        TrackBarSVolR.Position := TrackBarSVolL.Position - pan;
    end;
    TrackBarSVolL.Tag := 0;
    TrackBarSVolR.Tag := 0;
end;        


Excerpt code only for the logic! You need to adapt it to your app to work!  :-*