MeasureDragData::MeasureDragData(const QByteArray & data) : QObject() { QString stringData(data); QDomDocument doc; doc.setContent(stringData); QDomElement measureDragDataElement = doc.documentElement(); // Source Enum QDomElement sourceEnumElement = measureDragDataElement.firstChildElement("Source"); QString sourceEnumString = sourceEnumElement.text(); if( sourceEnumString == "BCL" ) { m_sourceEnum = LocalLibrary::BCL; } else if( sourceEnumString == "USER" ) { m_sourceEnum = LocalLibrary::USER; } // ID QDomElement idElement = measureDragDataElement.firstChildElement("ID"); QString idString = idElement.text(); m_id = UUID(idString); }
void EditStaff::editStringDataClicked() { int frets = instrument.stringData()->frets(); QList<instrString> stringList = instrument.stringData()->stringList(); EditStringData* esd = new EditStringData(this, &stringList, &frets); esd->setWindowModality(Qt::WindowModal); if (esd->exec()) { StringData stringData(frets, stringList); // update instrument pitch ranges as necessary if (stringList.size() > 0) { // get new string range bottom and top // as we have to choose an int size, INT16 are surely beyond midi pitch limits int oldHighestStringPitch = INT16_MIN; int highestStringPitch = INT16_MIN; int lowestStringPitch = INT16_MAX; for (const instrString& str : stringList) { if (str.pitch > highestStringPitch) highestStringPitch = str.pitch; if (str.pitch < lowestStringPitch) lowestStringPitch = str.pitch; } // get old string range bottom for (const instrString& str : instrument.stringData()->stringList()) if (str.pitch > oldHighestStringPitch) oldHighestStringPitch = str.pitch; // if there were no string, arbitrarely set old top to maxPitchA if (oldHighestStringPitch == INT16_MIN) oldHighestStringPitch = instrument.maxPitchA(); // range bottom is surely the pitch of the lowest string instrument.setMinPitchA(lowestStringPitch); instrument.setMinPitchP(lowestStringPitch); // range top should keep the same interval with the highest string it has now instrument.setMaxPitchA(instrument.maxPitchA() + highestStringPitch - oldHighestStringPitch); instrument.setMaxPitchP(instrument.maxPitchP() + highestStringPitch - oldHighestStringPitch); // update dlg controls minPitchA->setText(midiCodeToStr(instrument.minPitchA())); maxPitchA->setText(midiCodeToStr(instrument.maxPitchA())); minPitchP->setText(midiCodeToStr(instrument.minPitchP())); maxPitchP->setText(midiCodeToStr(instrument.maxPitchP())); // if no longer there is any string, leave everything as it is now } // update instrument data and dlg controls instrument.setStringData(stringData); numOfStrings->setText(QString::number(stringData.strings())); } }
void SharedVariant::dump(std::string &out) { out += "ref("; out += boost::lexical_cast<string>(m_count); out += ") "; switch (m_type) { case KindOfBoolean: out += "boolean: "; out += m_data.num ? "true" : "false"; break; case KindOfInt64: out += "int: "; out += boost::lexical_cast<string>(m_data.num); break; case KindOfDouble: out += "double: "; out += boost::lexical_cast<string>(m_data.dbl); break; case KindOfStaticString: case KindOfString: out += "string("; out += boost::lexical_cast<string>(stringLength()); out += "): "; out += stringData(); break; case KindOfArray: if (getSerializedArray()) { out += "array: "; out += m_data.str->data(); } else { auto sm = SharedArray::Make(this); SCOPE_EXIT { sm->release(); }; sm->dump(out); } break; case KindOfUninit: case KindOfNull: out += "null"; break; default: out += "object: "; out += m_data.str->data(); break; } out += "\n"; }
void FSClient::HandleFileSaveMessage(Networking::Message message) { static s32 packetCount = 0; static istring filename; Encoder encode(true, (u08*)message.GetBuffer(), message.GetSize()); u32 seq; encode.StartReading(); encode.Read(seq); if(seq == 0) { istring con = encode.ReadData(message.GetSize() - sizeof(u32)); LOG("Final File Transfer Packet -- Disconnecting"); net->Disconnect(atoi(con.c_str())); packetCount = 0; filename = ""; lastSeqTaken = 0; return; } c08* data = encode.ReadData(message.GetSize() - sizeof(u32)); istring stringData(data, message.GetSize() - sizeof(u32)); u32 fileNameLen = stringData.find_first_of('\n', 0); istring thisFile = stringData.substr(0, fileNameLen); if(thisFile == filename) { ++packetCount; } else { packetCount = 0; filename = thisFile; } ++fileNameLen; std::cout << packetCount << ": Receiving file " << filename << " Chunk Size: " << stringData.size() - fileNameLen << std::endl; std::ofstream out("Received\\" + filename, std::ios::out | std::ios::binary | std::ios::app); if(fileNameLen < stringData.size()) out << stringData.substr(fileNameLen); }
void ThreadSharedVariant::dump(std::string &out) { out += "ref("; out += boost::lexical_cast<string>(m_ref); out += ") "; switch (m_type) { case KindOfBoolean: out += "boolean: "; out += m_data.num ? "true" : "false"; break; case KindOfInt64: out += "int: "; out += boost::lexical_cast<string>(m_data.num); break; case KindOfDouble: out += "double: "; out += boost::lexical_cast<string>(m_data.dbl); break; case KindOfString: out += "string("; out += boost::lexical_cast<string>(stringLength()); out += "): "; out += stringData(); break; case KindOfArray: if (getSerializedArray()) { out += "array: "; out += m_data.str->data(); } else { SharedMap(this).dump(out); } break; case KindOfNull: out += "null"; break; default: out += "object: "; out += m_data.str->data(); break; } out += "\n"; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void _WriteStringDataTest ( const std::string &recName, IDataFile::Pointer dataFile) { IDataModel::Pointer model = dataFile->getDataModel(); IDataRecord::Pointer rec = model->getDataRecordByNamedPath(recName, NULL); MXA_REQUIRE(rec.get() != NULL); std::vector<int32_t> mxaDims; mxaDims.push_back(2); // This data set is for index '2' of the 'Data Container' MXA Data Dimension std::string dsPath = H5MXAUtilities::generateH5PathToDataset(model, mxaDims, rec); int32_t err = 1; std::string stringData ("This is some string data"); IMXAArray::Pointer strData = MXAAsciiStringData::Create(stringData); // Create the dataset that will hold the data and associated attributes IDataset::Pointer ds = H5Dataset::CreateDatasetPtr(dsPath, strData); //Create Attributes for each primitive type MakeAttribute<int8_t>(dsPath, ds ); MakeAttribute<uint8_t>( dsPath, ds ); MakeAttribute<int16_t>( dsPath, ds ); MakeAttribute<uint16_t>( dsPath, ds ); MakeAttribute<int32_t>( dsPath, ds ); MakeAttribute<uint32_t>(dsPath, ds ); MakeAttribute<int64_t>( dsPath, ds ); MakeAttribute<uint64_t>(dsPath, ds ); MakeAttribute<float>(dsPath, ds ); MakeAttribute<double>( dsPath, ds ); MakeStringAttribute(dsPath, ds); // Write the data to the file err = ds->writeToFile(dataFile); MXA_REQUIRE(err >= 0); }
// Add : OLD=NULL, NEW=COLLECTION // Remove : OLD=COLLECTION, NEW=NULL // Apply change (old -> new) bool EditState::makeChanges(bool revert) { // What is the target data type? bool result = false; switch (targetObject_.type()) { case (ObjectTypes::AxesObject): msg.print(Messenger::UndoRedo, "EDITSTATE: Axes - %s change type %i.\n", revert ? "reversing" : "applying", targetQuantity_); result = changeAxes(revert ? oldData_ : newData_, revert); break; case (ObjectTypes::CollectionObject): msg.print(Messenger::UndoRedo, "EDITSTATE: Collection - %s change type %i.\n", revert ? "reversing" : "applying", targetQuantity_); // Check whether we need to add or remove collection if ((targetQuantity_ == EditState::CollectionAddQuantity) || (targetQuantity_ == EditState::CollectionRemoveQuantity)) { // If we are 'applying' the change, we need to add the Collection in the newData_ list back into UChroma // If we are 'reversing' the change, we must find and remove the Collection specified bool add = targetQuantity_ == EditState::CollectionAddQuantity; if ( (add && revert) || ((!add) && (!revert)) ) { msg.print(Messenger::UndoRedo, "EDITSTATE: Collection - remove collection with id %i\n", targetObject_.id()); Collection* toDelete = Collection::object(targetObject_.id()); if (toDelete == NULL) { printf("Internal Error - Couldn't find collection with id %i, in order to delete it.\n", targetObject_.id()); return false; } msg.print(Messenger::UndoRedo, "EDITSTATE: Collection - removing collection '%s'\n", qPrintable(toDelete->name())); UChromaSession::removeCollection(toDelete); } else { msg.print(Messenger::UndoRedo, "EDITSTATE: Collection - add collection with id %i\n", targetObject_.id()); // Create new Collection in the correct place, and copy our stored data to it... Collection& collection = collectionData("collection", add ? newData_ : oldData_, result); if (!result) { msg.print(Messenger::UndoRedo, "Internal Error - Couldn't retrieve collection data for recreation.\n"); return false; } int position; QString locator = stringData("locator", add ? newData_ : oldData_, result); if (result) position = integerData("position", add ? newData_ : oldData_, result); if (!result) { msg.print(Messenger::UndoRedo, "Internal Error - Couldn't retrieve locator string or position for recreation of collection.\n"); return false; } Collection* newCollection = UChromaSession::addCollectionFromLocator(locator, collection.type(), position); (*newCollection) = collection; msg.print(Messenger::UndoRedo, "EDITSTATE: Collection - changing object id to %i\n", targetObject_.id()); Collection::setObjectId(newCollection, targetObject_.id()); printf("Recreated collection is now id %i\n", newCollection->objectId()); } result = true; } else result = changeCollection(revert ? oldData_ : newData_, revert); break; case (ObjectTypes::ViewPaneObject): msg.print(Messenger::UndoRedo, "EDITSTATE: ViewPane - %s change type %i.\n", revert ? "reversing" : "applying", targetQuantity_); result = changeViewPane(revert ? oldData_ : newData_, revert); break; default: msg.print(Messenger::UndoRedo, "Internal Error: Type of targetObject_ (%i) in EditState::makeChanges() not accounted for.\n", targetObject_.type()); return false; } return result; }
void GuitarPro5::readTracks() { for (int i = 0; i < staves; ++i) { int tuning[GP_MAX_STRING_NUMBER]; Staff* staff = score->staff(i); Part* part = staff->part(); uchar c = readUChar(); // simulations bitmask if (c & 0x2) { // 12 stringed guitar } if (c & 0x4) { // banjo track } if (i == 0 || version == 500) skip(1); QString name = readPascalString(40); int strings = readInt(); if (strings <= 0 || strings > GP_MAX_STRING_NUMBER) throw GuitarProError::GP_BAD_NUMBER_OF_STRINGS ; for (int j = 0; j < strings; ++j) { tuning[j] = readInt(); } for (int j = strings; j < GP_MAX_STRING_NUMBER; ++j) readInt(); /*int midiPort =*/ readInt(); // -1 int midiChannel = readInt() - 1; /*int midiChannel2 =*/ readInt(); // -1 int frets = readInt(); int capo = readInt(); /*int color =*/ readInt(); skip(version > 500 ? 49 : 44); if (version > 500) { // british stack clean / amp tone readDelphiString(); readDelphiString(); } int tuning2[strings]; for (int k = 0; k < strings; ++k) tuning2[strings-k-1] = tuning[k]; StringData stringData(frets, strings, tuning2); Instrument* instr = part->instr(); instr->setStringData(stringData); part->setPartName(name); part->setLongName(name); instr->setTranspose(Interval(capo)); // // determine clef // int patch = channelDefaults[midiChannel].patch; ClefType clefId = ClefType::G; if (midiChannel == GP_DEFAULT_PERCUSSION_CHANNEL) { clefId = ClefType::PERC; // instr->setUseDrumset(DrumsetKind::GUITAR_PRO); instr->setDrumset(gpDrumset); staff->setStaffType(StaffType::preset(StaffTypes::PERC_DEFAULT)); } else if (patch >= 24 && patch < 32) clefId = ClefType::G3; else if (patch >= 32 && patch < 40) clefId = ClefType::F8; Measure* measure = score->firstMeasure(); Clef* clef = new Clef(score); clef->setClefType(clefId); clef->setTrack(i * VOICES); Segment* segment = measure->getSegment(Segment::Type::Clef, 0); segment->add(clef); Channel& ch = instr->channel(0); if (midiChannel == GP_DEFAULT_PERCUSSION_CHANNEL) { ch.program = 0; ch.bank = 128; } else { ch.program = patch; ch.bank = 0; } ch.volume = channelDefaults[midiChannel].volume; ch.pan = channelDefaults[midiChannel].pan; ch.chorus = channelDefaults[midiChannel].chorus; ch.reverb = channelDefaults[midiChannel].reverb; //qDebug("default2: %d", channelDefaults[i].reverb); // missing: phase, tremolo ch.updateInitList(); } skip(version == 500 ? 2 : 1); }
NS_IMETHODIMP sbClipboardHelper::CopyImageFromClipboard(nsAString &aMimeType, PRUint32 *aDataLen, PRUint8 **aData) { nsresult rv; *aDataLen = 0; nsCOMPtr<nsIClipboard> nsClipboard = do_GetService("@mozilla.org/widget/clipboard;1", &rv); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsITransferable> xferable = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv); NS_ENSURE_SUCCESS(rv, rv); /* * Load up the flavors we support */ const char *flavorTypes[] = { kPNGImageMime, kJPEGImageMime, "image/jpeg", kGIFImageMime, kFileMime, kUnicodeMime }; const int flavorTypesLen = NS_ARRAY_LENGTH(flavorTypes); for (int iIndex = 0; iIndex < flavorTypesLen; iIndex++) { rv = xferable->AddDataFlavor(flavorTypes[iIndex]); NS_ENSURE_SUCCESS(rv, rv); } // Check the clipboard if it has one of those flavors bool clipboardHasData = PR_FALSE; rv = nsClipboard->HasDataMatchingFlavors(flavorTypes, flavorTypesLen, nsIClipboard::kGlobalClipboard, &clipboardHasData); NS_ENSURE_SUCCESS(rv, rv); if (clipboardHasData) { // Grab the data as a nsITransferable rv = nsClipboard->GetData(xferable, nsIClipboard::kGlobalClipboard); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsISupports> clipboardData; char *clipboardDataFlavor = 0; PRUint32 clipboardDataLen = 0; rv = xferable->GetAnyTransferData(&clipboardDataFlavor, getter_AddRefs(clipboardData), &clipboardDataLen); NS_ENSURE_SUCCESS(rv, rv); // Once we get a stream we can grab the data nsCOMPtr<nsIInputStream> dataStream; // First check if this is a file/url flavor if (!strcmp(clipboardDataFlavor, kUnicodeMime) || !strcmp(clipboardDataFlavor, kFileMime)) { // This is a file we are copying from nsCOMPtr<nsILocalFile> imageFile; if (!strcmp(clipboardDataFlavor, kUnicodeMime)) { nsAutoString url; nsCOMPtr<nsISupportsString> stringData(do_QueryInterface(clipboardData)); if (stringData) { stringData->GetData(url); } if (url.IsEmpty()) { // Nothing to work with so abort return NS_OK; } imageFile = do_CreateInstance("@mozilla.org/file/local;1", &rv); NS_ENSURE_SUCCESS(rv, rv); rv = imageFile->InitWithPath(url); if (NS_FAILED(rv)) { return NS_OK; } } else { // it already is a file :) imageFile = do_QueryInterface(clipboardData); if (!imageFile) { return NS_OK; } } // Get the mime type from the file nsCOMPtr<nsIMIMEService> mimeService = do_CreateInstance("@mozilla.org/mime;1", &rv); NS_ENSURE_SUCCESS(rv, rv); nsCAutoString mimeType; rv = mimeService->GetTypeFromFile(imageFile, mimeType); NS_ENSURE_SUCCESS(rv, rv); aMimeType.Assign(NS_ConvertUTF8toUTF16(mimeType)); // Now set up an input stream for the file nsCOMPtr<nsIFileInputStream> fileStream = do_CreateInstance("@mozilla.org/network/file-input-stream;1", &rv); NS_ENSURE_SUCCESS(rv, rv); rv = fileStream->Init(imageFile, 0x01, 0600, 0); NS_ENSURE_SUCCESS(rv, rv); dataStream = do_QueryInterface(fileStream, &rv); NS_ENSURE_SUCCESS(rv, rv); } else { // Assume it is a image then // Here we have to force the image/jpg mime type as image/jpeg because // the windows clipboard does not like image/jpg. The other systems work // either way. if(strcmp(clipboardDataFlavor, kJPEGImageMime)) { aMimeType.AssignLiteral(clipboardDataFlavor); } else { aMimeType.AssignLiteral("image/jpeg"); } dataStream = do_QueryInterface(clipboardData, &rv); NS_ENSURE_SUCCESS(rv, rv); } // Now read in the data from the stream PRUint32 dataSize; rv = dataStream->Available(&dataSize); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIBinaryInputStream> imageDataStream = do_CreateInstance(kBinaryInputStream, &rv); NS_ENSURE_SUCCESS(rv, rv); rv = imageDataStream->SetInputStream(dataStream); NS_ENSURE_SUCCESS(rv, rv); rv = imageDataStream->ReadByteArray(dataSize, aData); NS_ENSURE_SUCCESS(rv, rv); *aDataLen = dataSize; } return NS_OK; }