AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Projekte TAudioVolume Komponente incl. System Mixer
Thema durchsuchen
Ansicht
Themen-Optionen

TAudioVolume Komponente incl. System Mixer

Ein Thema von EWeiss · begonnen am 6. Mai 2018 · letzter Beitrag vom 24. Jul 2019
 
EWeiss
(Gast)

n/a Beiträge
 
#11

AW: TAudioVolume Komponente incl. System Mixer

  Alt 10. Mai 2018, 07:27
Jetzt kannst du das Postmessage weglassen und direkt reagieren.
OK nur mein bestreben ist das gerade keine unnötigen externen Funktionen ausgeführt werden müssen.
Die Komponente soll so einfach wie möglich gehalten werden.

zu dem basiert das komplette Control auf diesen Event.
Delphi-Quellcode:
    if not(csDesigning in ComponentState) then
      FEventHandle := AllocateHWnd(ProcessMsg);
Delphi-Quellcode:
procedure TAudioVolume.ProcessMsg(var Msg: TMessage);
var
  PVolMuteRec: PVolMute;
  Volume: single;
  Muted: boolean;
  Device: IMMDevice;
  DeviceId: WideString;
  DeviceInfo: TDeviceInfo;
  HR: HResult;
  NewState: DWORD;
  MyRegistry: TRegistry;
begin
  case Msg.Msg of

    WM_EndpointVolume:
      begin
        PVolMuteRec := PVolMute(Msg.WPARAM);
        if Assigned(tbMasterVolume) then
        begin
          tbMasterVolume.Position := round((1.0 - PVolMuteRec^.Volume) * tbMasterVolume.Max);
          ckMasterMute.Checked := PVolMuteRec^.Muted;
        end;
        if Assigned(tbMasterBalance) then
          AdjustMasterBalancePos;

        if Assigned(FOnMasterVolumeEvent) then
          FOnMasterVolumeEvent(MyVolSet, PVolMuteRec^.Volume, PVolMuteRec^.Muted);
      end;

    WM_VolumeEvent:
      begin
        PVolMuteRec := PVolMute(Msg.WPARAM);

        if MySessionVolSet or Assigned(FOnSessionVolumeEvent) then
        begin
          if Assigned(tbSessionVolume) or Assigned(FOnSessionVolumeEvent) then
          begin
            tbSessionVolume.Position := round((1.0 - PVolMuteRec^.Volume) * tbSessionVolume.Max);
            ckSessionMute.Checked := PVolMuteRec^.Muted;
          end;

          if (MySessionVolSet and (abs(PVolMuteRec^.Volume - MyVolVal) < 0.0001)) then
            MySessionVolSet := false
          else if (MyMuteSet and (PVolMuteRec^.Muted = MyMuteVal)) then
            MyMuteSet := false;

          if Assigned(tbSessionBalance) then
            AdjustSessionBalancePos;
        end;
      end;

    WM_SessionStateEvent:
      begin
        if Assigned(FOnSessionStateEvent) then
          FOnSessionStateEvent(self, Msg.WPARAM);
      end;

    WM_DeviceStateChange, WM_DeviceAdded, WM_DeviceRemoved:
      begin
        DeviceId := WideString(PWideChar(Msg.WPARAM));
        NewState := Msg.LPARAM;
        // Just refresh device list to simplify the logic.
        RefreshDeviceList(DeviceEnumerator);
        // SetupDefaultAudioEndpoint(DeviceEnumerator);
        if Assigned(FOnDeviceStateChange) then
        begin
          if Msg.Msg = WM_DeviceStateChange then
            FOnDeviceStateChange(DeviceId, NewState)
          else if Msg.Msg = WM_DeviceAdded then
            FOnDeviceStateChange(DeviceId, DEVICE_STATE_ADDED)
          else if Msg.Msg = WM_DeviceRemoved then
            FOnDeviceStateChange(DeviceId, DEVICE_STATE_REMOVED);
        end;
      end;

    WM_SessionDisconnected:
      begin
        FAudioSessionList.SessionDisconnected := cAudioSessionDisconnected
          [TAudioSessionDisconnected(Msg.WPARAM)];

        if Assigned(FOnSessionDisconnected) then
          FOnSessionDisconnected(self, Msg.WPARAM);
      end;

    WM_SessionCreate:
      begin
        if Assigned(FOnSessionCreated) then
          FOnSessionCreated(IAudioSessionControl(@Msg.WPARAM));
      end;

    WM_DefaultDeviceChange:
      begin
        HR := DeviceEnumerator.GetDefaultAudioEndpoint(eRender, eMultimedia, Device);
        if HR <> S_OK then
          raise Exception.Create('Error : Unable to get DefaultAudioEndpoint Device');
        DeviceInfo := GetDeviceInfo(Device);
        if DeviceInfo.DeviceId <> FDefaultDevice.DeviceId then
        begin
          FDefaultDevice := DeviceInfo;
          if Assigned(FOnDefaultDeviceChange) then
            FOnDefaultDeviceChange(DeviceInfo);
        end;
      end;

    MM_MIXM_LINE_CHANGE:
      begin
        // wParam = (WPARAM) hMixer lParam = (LPARAM) dwLineID

      end;

    MM_MIXM_CONTROL_CHANGE:
      begin
        // wParam = (WPARAM) hMixer lParam = (LPARAM) dwControlID
        if (DWORD(Msg.LPARAM) <> MasterMute.dwControlID) and
          (DWORD(Msg.LPARAM) <> MasterVol.dwControlID) then
          exit;

        Muted := IsMasterMuted;
        Volume := GetMasterVolume;
        if (DWORD(Msg.LPARAM) = MasterMute.dwControlID) then
        begin
          if (MyMuteSet and (Muted = MyMuteVal)) then
            MyMuteSet := false;
        end
        else
        // for (Msg.LParam = MasterVol.dwControlID)
          if (MyVolSet and (abs(Volume - MyVolVal) < 0.0001)) then
          MyVolSet := false;

        if Assigned(tbMasterVolume) then
        begin
          tbMasterVolume.Position := round((1.0 - Volume) * tbMasterVolume.Max);
          ckMasterMute.Checked := Muted;
        end;

        if Assigned(tbMasterBalance) then
          AdjustMasterBalancePos;
      end;
  else
    if Msg.Msg = WINMM_DEVICECHANGE then
    begin
      MyRegistry := TRegistry.Create;
      MyRegistry.RootKey := HKEY_CURRENT_USER;
      if MyRegistry.KeyExists('Software\Microsoft\Multimedia\Sound Mapper') then
        if MyRegistry.OpenKey('Software\Microsoft\Multimedia\Sound Mapper', true) then
          FDefaultDevice.DeviceName := MyRegistry.ReadString('Playback');
      MyRegistry.free;
    end
    else
      Msg.Result := DefWindowProc(FEventHandle, Msg.Msg, Msg.WPARAM, Msg.LPARAM);
  end;
end;
Kannst du dir vorstellen was ich dann alles ändern müsste?
Das ist nicht mal eben, mache die Events Public in TAudioVolume da hängt noch viel mehr von ab.

gruss

Geändert von EWeiss (10. Mai 2018 um 07:35 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:43 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz