InputDevice* InputDeviceManager::createInputDevice(const char* deviceName,int trackType,int numButtons,int numValuators,bool physicalDevice) { /* Get the length of the given device name's prefix: */ int deviceNamePrefixLength=getPrefixLength(deviceName); /* Check if a device of the same name prefix already exists: */ bool exists=false; int maxAliasIndex=0; for(InputDevices::iterator devIt=inputDevices.begin();devIt!=inputDevices.end();++devIt) { /* Compare the two prefixes: */ if(getPrefixLength(devIt->getDeviceName())==deviceNamePrefixLength&&strncmp(deviceName,devIt->getDeviceName(),deviceNamePrefixLength)==0) { exists=true; if(devIt->getDeviceName()[deviceNamePrefixLength]==':') { int aliasIndex=atoi(devIt->getDeviceName()+deviceNamePrefixLength); if(maxAliasIndex<aliasIndex) maxAliasIndex=aliasIndex; } } } /* Create a new (uninitialized) input device: */ InputDevices::iterator newDevice=inputDevices.insert(inputDevices.end(),InputDevice()); InputDevice* newDevicePtr=&(*newDevice); // This looks iffy, but I don't know of a better way /* Initialize the new input device: */ if(exists) { /* Create a new alias name for the new device: */ char newDeviceNameBuffer[256]; strncpy(newDeviceNameBuffer,deviceName,deviceNamePrefixLength); snprintf(newDeviceNameBuffer+deviceNamePrefixLength,sizeof(newDeviceNameBuffer)-deviceNamePrefixLength,":%d",maxAliasIndex+1); newDevicePtr->set(newDeviceNameBuffer,trackType,numButtons,numValuators); } else newDevicePtr->set(deviceName,trackType,numButtons,numValuators); /* Add the new input device to the input graph: */ inputGraphManager->addInputDevice(newDevicePtr); /* If it's a physical device, grab it permanently: */ if(physicalDevice) inputGraphManager->grabInputDevice(newDevicePtr,0); // Passing in null as grabber grabs for the physical layer /* Call the input device creation callbacks: */ InputDeviceCreationCallbackData cbData(this,newDevicePtr); inputDeviceCreationCallbacks.call(&cbData); /* Return a pointer to the new input device: */ return newDevicePtr; }
void setAddress(const char* addr){ if(getPrefixLength() > 0 && types != address){ // save old types int len = getPrefixLength(); char saved[len]; stpncpy(saved, (char*)types, len); types = address + writeOscString(address, addr); data = types + writeOscString(types, saved); }else{ types = address + writeOscString(address, addr); data = types; } }
int calculateMessageLength(){ int size = getPrefixLength(); for(int i=0; i<getSize(); ++i) size += getDataSize(i); return size; // return size+calculateDataLength(); }
//============================================================================== String FileSystem::normalize(const String& path) const { if(path.empty()) { return path; } else { String ret = path; // // Replace separator characters with the appropriate type // const CharType sep = getSeparatorChar(); const CharType badSep = (sep == '/') ? '\\' : '/'; std::replace(ret.begin(), ret.end(), badSep, sep); // Replace strings of separators with a single separator // starting at position 0 for UNIX and 1 for Windows! size_t pos = (sep == '\\') ? 1 : 0; const CharType doubleSep[] = {sep, sep, 0}; while(pos != String::npos) { pos = ret.find(doubleSep, pos); if(pos != String::npos) { ret.erase(pos, 1); } } // // Remove terminating separator if any // if(sep == ret[ret.length()-1] && getPrefixLength(ret) < ret.length()) { ret = ret.erase(ret.length()-1); } return ret; } }
// If the child is absolute, then we do not resolve the child against // the parent. This seems to make the most logical sense, even though // that is not the apparent behaviour of the JDK. // // If the parent directory is empty, this is not treated as the current // working directory, but simply as the empty string. // This allows this class to be used in URL resolution where the current // directory has no meaning. //============================================================================== String FileSystem::resolve(const String& parent, const String& child) const { String normalizedChild = normalize(child); if(isAbsolute(normalizedChild)) { return normalizedChild; } else { size_t prefixLen = getPrefixLength(normalizedChild); String normalizedParent = normalize(parent); const CharType lastChar = normalizedParent[normalizedParent.length()-1]; if(lastChar == getSeparatorChar()) { return normalizedParent + normalizedChild.substr(prefixLen); } else { return normalizedParent + getSeparator() + normalizedChild.substr(prefixLen); } } }