⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unamsmixer.pas

📁 Voice Commnucation Components for Delphi
💻 PAS
📖 第 1 页 / 共 4 页
字号:
    result := 0;
end;

// --  --
function unaMsMixerLine.getControl(index: unsigned): unaMsMixerControl;
begin
  result := f_controls[index];
end;

// --  --
function unaMsMixerLine.getControlCount(): unsigned;
begin
  Result := f_controls.count;
end;

// --  --
function unaMsMixerLine.getID(): unsigned;
begin
  result := caps.dwLineID;
end;

// --  --
function unaMsMixerLine.getIsLineType(index: int): bool;
begin
  if (-1 = index) then
    index := int(MIXERLINE_LINEF_SOURCE);
  //
  result := (0 <> (caps.fdwLine and index));
end;

// --  --
function unaMsMixerLine.locateLine(componentType: unsigned): unaMsMixerLine;
var
  i: unsigned;
begin
  result := nil;
  i := 0;
  while (i < getConnectionCount()) do begin
    result := connections[i];
    if (componentType = result.caps.dwComponentType) then
      // got it
      break
    else
      result := nil;
    //
    inc(i);
  end;
end;

{ unaMsMixerDevice }

// --  --
procedure unaMsMixerDevice.close();
begin
  active := false;
end;

// --  --
constructor unaMsMixerDevice.create(master: unaMsMixerSystem; index: unsigned);
begin
  inherited create();
  //
  f_master := master;
  f_lines := unaObjectList.create();
  f_index := index;
  f_caps := malloc(sizeOf(f_caps^), true, 0);
  getCaps();
  //
  enumLines();
end;

// --  --
destructor unaMsMixerDevice.destroy();
begin
  inherited;
  //
  close();
  freeAndNil(f_lines);
end;

// --  --
procedure unaMsMixerDevice.doClose();
begin
  if (active) then begin
    if (checkError(mixerClose(f_handle){$IFDEF DEBUG}, 'doClose.mixerClose'{$ENDIF})) then
      f_handle := 0;
  end;
end;

// --  --
procedure unaMsMixerDevice.doOpen();
var
  flags: unsigned;
begin
  if (not active) then begin
    if (f_winHandle = 0) then
      flags := 0
    else
      flags := CALLBACK_WINDOW;
    //
    checkError(mixerOpen(@f_handle, f_index, f_winHandle, unsigned(self), flags + MIXER_OBJECTF_MIXER){$IFDEF DEBUG}, 'doOpen.mixerOpen'{$ENDIF});
  end;
end;

// --  --
procedure unaMsMixerDevice.enumLines();
var
  i: unsigned;
begin
  f_lines.clear();
  //
  if (0 < caps.cDestinations) then
    for i := 0 to caps.cDestinations - 1 do
      f_lines.add(unaMsMixerLine.create(self, i));
end;

// --  --
function unaMsMixerDevice.getActive(): bool;
begin
  result := (f_handle <> 0);
end;

// --  --
function unaMsMixerDevice.getCaps(): pMixerCapsW;
var
  ok: bool;
{$IFNDEF NO_ANSI_SUPPORT }
  capsA: MIXERCAPSA;
{$ENDIF}
begin
{$IFNDEF NO_ANSI_SUPPORT }
  if (not g_wideApiSupported) then begin
    //
    ok := checkError(mixerGetDevCapsA(f_index, @capsA, sizeOf(capsA)){$IFDEF DEBUG}, 'getCaps.mixerGetDevCapsA'{$ENDIF});
    //
    if (ok) then begin
      //
      with f_caps^ do begin
	wMid := capsA.wMid;
	wPid := capsA.wPid;
	vDriverVersion := capsA.vDriverVersion;
	wStr2Array(capsA.szPname, szPname); 
	fdwSupport := capsA.fdwSupport;
	cDestinations := capsA.cDestinations;
      end;
    end;
  end
  else
{$ENDIF}
    ok := checkError(mixerGetDevCapsW(f_index, f_caps, sizeOf(f_caps^)){$IFDEF DEBUG}, 'getCaps.mixerGetDevCapsW'{$ENDIF});
  //
  if (ok) then
    result := f_caps
  else
    result := nil;
end;

// --  --
function unaMsMixerDevice.getID(): unsigned;
begin
  checkError(mixerGetID(f_index, result, MIXER_OBJECTF_MIXER){$IFDEF DEBUG}, 'getID.mixerGetID'{$ENDIF});
end;

// --  --
function unaMsMixerDevice.getLine(index: unsigned): unaMsMixerLine;
begin
  result := f_lines[index]
end;

// --  --
function unaMsMixerDevice.getLineCount(): unsigned;
begin
  result := f_lines.count;
end;

// --  --
function unaMsMixerDevice.locateComponentLine(componentType: unsigned): unaMsMixerLine;
var
  i: unsigned;
begin
  result := nil;
  //
  i := 0;
  while (i < getLineCount()) do begin
    //
    if (componentType = line[i].caps.dwComponentType) then begin
      // got it
      result := line[i];
      break;
    end;
    //
    inc(i);
  end;
end;

// --  --
function unaMsMixerDevice.locateDestLine(destination: unsigned): unaMsMixerLine;
var
  i: unsigned;
begin
  result := nil;
  //
  i := 0;
  while (i < getLineCount()) do begin
    //
    if (destination = line[i].caps.dwDestination) then begin
      // got it
      result := line[i];
      break;
    end;
    //
    inc(i);
  end;
end;

// --  --
function unaMsMixerDevice.locateTargetLine(targetType: unsigned): unaMsMixerLine;
var
  i: unsigned;
begin
  result := nil;
  i := 0;
  while (i < getLineCount()) do begin
    //
    if (targetType = line[i].caps.Target.dwType) then begin
      // got it
      result := line[i];
      break;
    end;
    //
    inc(i);
  end;
end;

// --  --
procedure unaMsMixerDevice.open();
begin
  active := true;
end;

// --  --
procedure unaMsMixerDevice.setActive(value: bool);
begin
  if (active <> value) then
    if value then
      doOpen()
    else
      doClose();
end;

{ unaMsMixerSystem }

// --  --
procedure unaMsMixerSystem.AfterConstruction();
begin
  inherited;
  //
  if (f_enumOnCreate) then
    enumDevices();
end;

// --  --
constructor unaMsMixerSystem.create(enumOnCreate: bool);
begin
  inherited create();
  //
  f_mixers := unaObjectList.create();
  //
  f_enumOnCreate := enumOnCreate;
end;

// --  --
destructor unaMsMixerSystem.destroy();
begin
  inherited;
  //
  selectMixer($FFFFFFFF);	// ensure we close the selected mixer (if any)
  //
  freeAndNil(f_mixers);
end;

// --  --
procedure unaMsMixerSystem.enumDevices();
begin
  if (not f_enumComplete) then begin
    //
    f_enumComplete := true;
    enumMixers();
  end;
end;

// --  --
procedure unaMsMixerSystem.enumMixers();
var
  i: unsigned;
  C: unsigned;
begin
  f_mixers.clear();
  //
  C := MMSystem.mixerGetNumDevs();
  i := 0;
  while (i < C) do begin
    f_mixers.add(unaMsMixerDevice.create(self, i));
    inc(i);
  end;
end;

// --  --
function unaMsMixerSystem.getConnection(iline: unsigned; iconn: int): unaMsMixerLine;
begin
  result := nil;
  //
  if ((nil <> f_selectedMixer) and (nil <> f_selectedMixer.line[iline])) then begin
    //
    if (0 <= iconn) then
      result := f_selectedMixer.line[iline].connections[iconn]
    else
      result := f_selectedMixer.line[iline];
  end;
end;

// --  --
function unaMsMixerSystem.getConnectionControl(iline: unsigned; iconn: int; cclass, ctype: unsigned): unaMsMixerControl;
var
  i: unsigned;
  conn: unaMsMixerLine;
  control: unaMsMixerControl;
begin
  result := nil;
  //
  conn := getConnection(iline, iconn);
  if (nil <> conn) then begin
    //
    i := 0;
    while (i < conn.getControlCount()) do begin
      //
      control := conn.getControl(i);
      if ((control.f_controlClass = cclass) and (control.f_controlType = ctype)) then begin
	result := control;
	break;
      end;
      //
      inc(i);
    end;
  end;
end;

// --  --
function unaMsMixerSystem.getDeviceId(isInDevice: bool; alsoCheckMapper: bool): int;
var
  count: unsigned;
  i: unsigned;
begin
  if (nil <> selectedMixer) then begin
    //
    if (isInDevice) then
      count := waveInGetNumDevs()
    else
      count := waveOutGetNumDevs();
    //
    result := -3;	// no device for this mixer
    if (0 < count) then
      for i := 0 to count - 1 do
	if (getMixerId(i, isInDevice) = int(selectedMixer.getID())) then begin
	  result := i;
	  break;
	end;
    //
    if (alsoCheckMapper and (0 <= result)) then begin
      if (getMixerId(WAVE_MAPPER, isInDevice) = int(selectedMixer.getID())) then
	result := int(WAVE_MAPPER);
    end;
    //
  end
  else
    result := -2;	// no mixer was selected  
end;

// --  --
function unaMsMixerSystem.getLineConnectionByType(iline, itype: unsigned; checkControlsNum: bool): int;
var
  i: unsigned;
  line: unaMsMixerLine;
  //
  maxControls: int;
  preResult: int;
begin
  result := -1;
  preResult := -1;
  //
  if ((nil <> f_selectedMixer) and (nil <> f_selectedMixer.line[iline])) then begin
    //
    line := f_selectedMixer.line[iline];
    //
    maxControls := -1;
    i := 0;
    while (i < line.getConnectionCount()) do begin
      //
      if (itype = line.connections[i].caps.dwComponentType) then begin
	//
	if (checkControlsNum) then begin
	  //
	  if (maxControls < int(line.connections[i].caps.cControls)) then begin
	    //
	    preResult := i;
	    maxControls := line.connections[i].caps.cControls;
	  end;
	end
	else begin
	  //
	  result := i;
	  break;
	end;
      end;
      //
      inc(i);
    end;
  end;
  //
  if (checkControlsNum) then
    result := preResult;
end;

// --  --
function unaMsMixerSystem.getLineConnectionCount(iline: unsigned): unsigned;
begin
  if ((nil <> f_selectedMixer) and (nil <> f_selectedMixer.line[iline])) then
    result := f_selectedMixer.line[iline].getConnectionCount()
  else
    result := 0;
end;

// --  --
function unaMsMixerSystem.getLineConnectionName(iline, iconn: unsigned; shortName: bool): wideString;
var
  conn: unaMsMixerLine;
begin
  result := '';
  //
  conn := getConnection(iline, iconn);
  if (nil <> conn) then begin
    //
    if (shortName) then
      result := conn.caps.szShortName
    else
      result := conn.caps.szName;
  end;    
end;

// --  --
function unaMsMixerSystem.getLineConnectionType(iline: unsigned; iconn: int): unsigned;
var
  conn: unaMsMixerLine;
begin
  conn := getConnection(iline, iconn);
  //
  if (nil <> conn) then
    result := conn.caps.dwComponentType
  else
    result := 0;
end;

// --  --
function unaMsMixerSystem.getLineCount(): unsigned;
begin
  if (nil <> f_selectedMixer) then
    result := f_selectedMixer.getLineCount()
  else
    result := 0;
end;

// --  --
function unaMsMixerSystem.getLineIndex(isOut: bool; recLevel: int): int;
var
  line: unaMsMixerLine;
begin
  result := -1;
  //
  if (nil <> f_selectedMixer) then begin
    //
    line := f_selectedMixer.locateComponentLine(choice(isOut, MIXERLINE_COMPONENTTYPE_DST_SPEAKERS, unsigned(MIXERLINE_COMPONENTTYPE_DST_WAVEIN)));
    //
    if (nil = line) then
      // try other DST
      line := f_selectedMixer.locateComponentLine(choice(isOut, MIXERLINE_COMPONENTTYPE_DST_HEADPHONES, unsigned(MIXERLINE_COMPONENTTYPE_DST_LINE)));
    //
    if (nil = line) then
      // try selecting by target
      line := f_selectedMixer.locateTargetLine(choice(isOut, MIXERLINE_TARGETTYPE_WAVEOUT, unsigned(MIXERLINE_TARGETTYPE_WAVEIN)));
    //
    if ((nil = line) and (1 > recLevel)) then begin
      // try to locate other type and then return opposite index

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -