Recent

Author Topic: Mic mute status  (Read 6755 times)

pirat3k

  • Newbie
  • Posts: 1
Mic mute status
« on: May 18, 2014, 08:54:40 pm »
Hello. I'm new to Lazarus so I need some help.
I want to make an application to show me my microphone mute status.
I have created a macro on my keyboard to mute my headset microphone. But there is a problem, I don't know when the microphone is muted and when not.
Now I want to create an application which would display the microphone status (in a window, taskbar... doesen't matter, just so I can see the status). I am using Windows 8.1.

I would really apretiate your help with this.

Evochrome

  • New Member
  • *
  • Posts: 25
Re: Mic mute status
« Reply #1 on: May 20, 2014, 09:32:32 pm »
You can possibly use this:

http://www.swissdelphicenter.ch/en/showcode.php?id=1204
or search google for: *Subject* + 'Delphi'.
This way you'll probably get more results ;)

Cheers,
Windows 8 64 bit. Lazarus 1.2.2 32 bit.
Windows 7 64 bit. Lazarus 1.2.2 32 bit.
Mac OS X Mavericks with lazarus

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Mic mute status
« Reply #2 on: May 21, 2014, 12:13:24 am »
Assuming you know how to find out if a line is muted or not, your target is MM_MIXM_LINE_CHANGE message from mmsystem. You'll receive that message if you register your window as a callback window when you open the mixer that you care to track.

To track all of them you need placeholders for their number and handles:
Code: [Select]
uses
..., Windows, mmsystem;
..
    mixerCount: uint;
    mixers: array of HMIXER;

In your form constructor, or wherever you prefer, open the mixers and make your window a callback window:
Code: [Select]
  mixerCount := mixerGetNumDevs;
  SetLength(mixers, mixerCount);

  for i := 0 to mixerCount - 1 do
  begin
    res := mixerOpen(@mixers[i] {pMixerHandle}, i {MixerId}, Handle {Callback},0 {HInstance}, CALLBACK_WINDOW {OpenFlags});
    if (res <> MMSYSERR_NOERROR) then
//your reaction to a failure
  end;

Change your window procedure to handle MM_MIXM_LINE_CHANGE:
Code: [Select]
  OrgWndProc: Windows.WNDPROC;
..
  OrgWndProc := Windows.WNDPROC(SetWindowLong(Handle, GWL_WNDPROC, PtrInt(@NewWndProc)));

That's not the only way but I prefer it. Your NewWndProc is something like:
Code: [Select]
function NewWndProc(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam):LRESULT;stdcall;
begin
  case uMsg of
  MM_MIXM_CONTROL_CHANGE: ;
  MM_MIXM_LINE_CHANGE: //Check if mute status changed - here comes your assumed knowledge;
  end;

  Result := CallWindowProc(OrgWndProc, Ahwnd, uMsg, wParam, lParam);
end;

When you are done, don't forget to clean up:
Code: [Select]
  for i := 0 to mixerCount - 1 do
    mixerClose(mixers[i]);

  SetLength(mixers, 0);

And maybe return the original window procedure.

 

TinyPortal © 2005-2018