/// Undo deleting the selection. void UndoBuffer::undoDeleteSelection(Undo* u) { Project* p; p = u->getProject(); GState *s, *ph; GTransition* t; GITransition* it=NULL; QListIterator<GState*> si(*u->getSList()); QListIterator<dtlist*> i(*u->getDoubleTList()); QListIterator<GTransition*> j(*u->getTList()); ph = p->machine->getPhantomState(); // undo delete states for(; si.hasNext();) { s = si.next(); QListIterator<GTransition*> ti1(i.peekNext()->tlist); QListIterator<GTransition*> ti2(i.next()->rlist); for(; ti1.hasNext();) { t = ti1.next(); t->setStart(s); s->tlist.append(t); // ph->tlist.setAutoDelete(FALSE); // ph->tlist.removeRef(t); ph->tlist.removeAll(t); } for(; ti2.hasNext();) { t = ti2.next(); t->setEnd(s); s->reflist.append(t); } s->setDeleted(FALSE); } // undo delete transitions for(; j.hasNext();) { t = j.next(); t->setDeleted(FALSE); } it = u->getInitialTransition(); if (it) { project->machine->setInitialTransition(it); project->machine->setInitialState(u->getInitialState()); // delete it; } }
void PackageUpdateList::TreeItem::add(const InstallablePackageP& package, const String& path, int level) { // this node this->level = level; PackageType new_type = package_type(*package->description); int new_hint = package->description->position_hint; if (new_type < position_type || (new_type == position_type && new_hint < position_hint)) { // this is a lower position hint, use it position_type = new_type; position_hint = new_hint; } // end of the path? if (path.empty()) { assert(!this->package); this->package = package; return; } // split path size_t pos = path.find_first_of(_('/')); String name = path.substr(0,pos); String rest = pos == String::npos ? _("") : path.substr(pos+1); // find/add child FOR_EACH(ti, children) { if (ti->label == name) { // already have this child if (pos == String::npos && ti->package) { // two packages with the same path TreeItemP ti2(new TreeItem); ti2->label = name; children.insert(ti_IT.first, ti2); ti2->add(package, rest, level + 1); } else { ti->add(package, rest, level + 1); } return; } } // don't have this child TreeItemP ti(new TreeItem); children.push_back(ti); ti->label = name; ti->add(package, rest, level + 1); }
void ParseOBJ::processCommand(const Command command) { switch (command) { case VERTEX: maybeReadWhitespace(); vertexArray.append(readVector3()); // Consume anything else on this line readUntilNewline(); break; case TEXCOORD: maybeReadWhitespace(); texCoord0Array.append(readVector2()); if (m_objOptions.texCoord1Mode == ParseOBJ::Options::UNPACK_FROM_TEXCOORD0_Z) { float w = readFloat(); Vector2 texCoord1; texCoord1.x = floor(w / (2.0f * 2048.0f)) / 2048.0f; texCoord1.y = (w - 2.0f * 2048.0f * floor(w / (2.0f * 2048.0f))) / 2048.0f; texCoord1Array.append(texCoord1); } else if (m_objOptions.texCoord1Mode == ParseOBJ::Options::TEXCOORD0_ZW) { texCoord1Array.append(readVector2()); } // Consume anything else on this line readUntilNewline(); break; case NORMAL: maybeReadWhitespace(); normalArray.append(readVector3()); // Consume anything else on this line readUntilNewline(); break; case FACE: readFace(); // Faces consume newlines by themselves break; case GROUP: { // Change group const String& groupName = readName(); shared_ptr<Group>& g = groupTable.getCreate(groupName); if (isNull(g)) { // Newly created g = Group::create(); g->name = groupName; } m_currentGroup = g; } // Consume anything else on this line readUntilNewline(); break; case USEMTL: { // Change the mesh within the group const String& materialName = readName(); m_currentMaterial = getMaterial(materialName); // Force re-obtaining or creating of the appropriate mesh m_currentMesh.reset(); } // Consume anything else on this line readUntilNewline(); break; case MTLLIB: { // Specify material library String mtlFilename = readName(); mtlArray.append(mtlFilename); mtlFilename = FilePath::concat(m_basePath, mtlFilename); TextInput ti2(mtlFilename); m_currentMaterialLibrary.parse(ti2); } // Consume anything else on this line readUntilNewline(); break; case UNKNOWN: // Nothing to do readUntilNewline(); break; } }
void WriteWav:: rewriteNormalized() { _sndfile.reset(); std::string tempfilename; { QTemporaryFile tempname("XXXXXX.wav"); tempname.open(); tempfilename = tempname.fileName().toStdString(); } bool renamestatus = QFile::rename( _filename.c_str(), tempfilename.c_str() ); TaskInfo ti("renaming '%s' to '%s': %s", _filename.c_str(), tempfilename.c_str(), renamestatus?"success":"failed"); if (!renamestatus) return; try { SndfileHandle inputfile(tempfilename); if (!inputfile || 0 == inputfile.frames()) { TaskInfo("ERROR: Couldn't read from %s", tempfilename.c_str()); return; } SndfileHandle outputfile(_filename, SFM_WRITE, inputfile.format(), inputfile.channels(), inputfile.samplerate()); if (!outputfile) { TaskInfo("ERROR: Couldn't write to %s", _filename.c_str()); return; } long double mean = _sum/_sumsamples; // -1 + 2*(v - low)/(high-low); // -1 + (v - low)/std::max(_high-mean, mean-_low) long double k = std::max(_high-mean, mean-_low); float affine_s = 1/k; float affine_d = -1 - _low/k; if (!_normalize) { affine_d = mean; affine_s = k; } // when sndfile converts float to 16-bit integers it doesn't bother with rounding to nearest. Adding an offset in advance accomodates for that. affine_d += 1.f/(1<<16); sf_count_t frames = inputfile.frames(); TaskInfo ti2("rewriting %u frames", (unsigned)frames); int num_channels = inputfile.channels(); size_t frames_per_buffer = (4 << 20)/sizeof(float)/num_channels; // 4 MB buffer std::vector<float> buffer(num_channels * frames_per_buffer); float* p = &buffer[0]; while (true) { sf_count_t items_read = inputfile.read(p, buffer.size()); if (0 == items_read) break; for (int x=0; x<items_read; ++x) p[x] = affine_d + affine_s*p[x]; outputfile.write(p, items_read ); } } catch (...) { QFile::remove(tempfilename.c_str()); throw; } QFile::remove(tempfilename.c_str()); }