示例#1
0
KeyMapType getDetailsForQtKey(int qtKey, Qt::KeyboardModifiers modifiers)
{
	initializeIfNecessary();

	KeyMapType result;
	result.devicekey = 0;
	result.normal	= Key_Null;
	result.shift	= Key_Null;
	result.opt		= Key_Null;
	result.qtKey	= Qt::Key_unknown;
	result.qtKeyOpt	= Qt::Key_unknown;
	result.virtualkeycode = Vk_NULL;

	if (modifiers & Qt::AltModifier) {
		std::map<int, int>::const_iterator it = s_qtOptKeyMap.find(qtKey);
		if (it != s_qtOptKeyMap.end()) {
			int index = it->second;
			result = s_deviceKeyMap[index];
		}
	}
	else {
		std::map<int, int>::const_iterator it = s_qtKeyMap.find(qtKey);
		if (it != s_qtKeyMap.end()) {
			int index = it->second;
			result = s_deviceKeyMap[index];
		}
	}

	return result;
}
Boolean WindowsAudioInputDevice::setInputPort(int portIndex) {
  initializeIfNecessary();

  if (portIndex < 0 || portIndex >= (int)numAudioInputPorts) { // bad index
    envir().setResultMsg("Bad input port index\n");
    return False;
  }

  // Check that this port is allowed:
  if (allowedDeviceNames != NULL) {
	  int i;
	  for (i = 0; allowedDeviceNames[i] != NULL; ++i) {
		  if (strncmp(ourAudioInputPorts[portIndex].name, allowedDeviceNames[i],
			  strlen(allowedDeviceNames[i])) == 0) {
			  // The allowed device name is a prefix of this port's name
			  break; // this port is allowed
		  }
	  }
	  if (allowedDeviceNames[i] == NULL) { // this port is not on the allowed list
		envir().setResultMsg("Access to this audio device is not allowed\n");
		return False;
	  }
  }

  if (portIndex != fCurPortIndex) {
    // The port has changed, so close the old one and open the new one:
    if (fCurPortIndex >= 0) ourAudioInputPorts[fCurPortIndex].close();;
    fCurPortIndex = portIndex;
    ourAudioInputPorts[fCurPortIndex].open(fNumChannels, fSamplingFrequency, fGranularityInMS);
  }
  fCurPortIndex = portIndex;
  return True;
}
Boolean WindowsAudioInputDevice::setInputPort(int portIndex) {
  initializeIfNecessary();

  if (portIndex < 0 || portIndex >= (int)numInputPortsTotal) { // bad index
    envir().setResultMsg("Bad input port index\n");
    return False;
  }

  // Find the mixer and port that corresponds to "portIndex":
  int newMixerId, portWithinMixer, portIndexCount = 0;
  for (newMixerId = 0; newMixerId < (int)numMixers; ++newMixerId) {
    int prevPortIndexCount = portIndexCount;
    portIndexCount += ourMixers[newMixerId].numPorts;
    if (portIndexCount > portIndex) { // it's with this mixer
      portWithinMixer = portIndex - prevPortIndexCount;
      break;
    }
  }

  // Check that this mixer is allowed:
  if (allowedDeviceNames != NULL) {
	  int i;
	  for (i = 0; allowedDeviceNames[i] != NULL; ++i) {
		  if (strncmp(ourMixers[newMixerId].name, allowedDeviceNames[i],
			  strlen(allowedDeviceNames[i])) == 0) {
			  // The allowed device name is a prefix of this mixer's name
			  break; // this mixer is allowed
		  }
	  }
	  if (allowedDeviceNames[i] == NULL) { // this mixer is not on the allowed list
		envir().setResultMsg("Access to this audio device is not allowed\n");
		return False;
	  }
  }

  if (newMixerId != fCurMixerId) {
    // The mixer has changed, so close the old one and open the new one:
    if (fCurMixerId >= 0) ourMixers[fCurMixerId].close();
    fCurMixerId = newMixerId;
    ourMixers[fCurMixerId].open(fNumChannels, fSamplingFrequency, fGranularityInMS);
  }
  if (portIndex != fCurPortIndex) {
    // Change the input port:
    fCurPortIndex = portIndex;
    char const* errReason;
    MMRESULT errCode;
    if (!ourMixers[newMixerId].enableInputPort(portWithinMixer, errReason, errCode)) {
      char resultMsg[100];
      sprintf(resultMsg, "Failed to enable input port: %s failed (0x%08x)\n", errReason, errCode);
      envir().setResultMsg(resultMsg);
      return False;
    }
    // Later, may also need to transfer 'gain' to new port #####
  }
  return True;
}
示例#4
0
KeyMapType getDetailsForKey(int key)
{
	initializeIfNecessary();
	
	KeyMapType result;
	result.devicekey = 0;
	result.normal	= Key_Null;
	result.shift	= Key_Null;
	result.opt		= Key_Null;
	result.qtKey	= Qt::Key_unknown;
	result.qtKeyOpt	= Qt::Key_unknown;
	result.virtualkeycode = Vk_NULL;
	
	std::map<int, int>::const_iterator it;

	it = s_normalKeyMap.find(key);
	if (it != s_normalKeyMap.end()) {
		int index = it->second;
		result = s_deviceKeyMap[index];
	}
	else {

		it = s_shiftKeyMap.find(key);
		if (it != s_shiftKeyMap.end()) {
			int index = it->second;
			result = s_deviceKeyMap[index];
		}
		else {

			it = s_optKeyMap.find(key);
			if (it != s_optKeyMap.end()) {
				int index = it->second;
				result = s_deviceKeyMap[index];
			}
		}
	}

	return result;
}