Example #1
0
void MidiController::write(int level, Xml& xml) const
{
      ControllerType t = midiControllerType(_num);
      if(t == Velo)
        return;
        
      QString type(int2ctrlType(t));

      int h = (_num >> 8) & 0x7f;
      int l = _num & 0x7f;

      QString sl;
      if (isPerNoteController())
            sl = "pitch";
      else
            sl.setNum(l);

      xml.nput(level, "<Controller name=\"%s\"", Xml::xmlString(_name).toLatin1().constData());
      if(t != Controller7)
        xml.nput(" type=\"%s\"", type.toLatin1().constData());
      
      int mn = 0;
      int mx = 0; 
      switch (t) 
      {
            case RPN:
            case NRPN:
                  xml.nput(" h=\"%d\"", h);
                  xml.nput(" l=\"%s\"", sl.toLatin1().constData());
                  mx = 127;
                  break;
            case Controller7:
                  xml.nput(" l=\"%s\"", sl.toLatin1().constData());
                  mx = 127;
                  break;
            case Controller14:
            case RPN14:
            case NRPN14:
                  xml.nput(" h=\"%d\"", h);
                  xml.nput(" l=\"%s\"", sl.toLatin1().constData());
                  mx = 16383;
                  break;
            case Pitch:
                  mn = -8192;
                  mx = 8191;
                  break;
            case PolyAftertouch:
                  mn = 0;
                  mx = 127;
                  break;
            case Aftertouch: 
                  mn = 0;
                  mx = 127;
                  break;
            case Program:
            case Velo:        // Cannot happen
                  break;
      }
      
      if(t == Program)
      {
        if(_initVal != CTRL_VAL_UNKNOWN && _initVal != 0xffffff)
          xml.nput(" init=\"0x%x\"", _initVal);
      }
      else
      {
        if(_minVal != mn)     
          xml.nput(" min=\"%d\"", _minVal);
        if(_maxVal != mx)     
          xml.nput(" max=\"%d\"", _maxVal);
        
        if(_initVal != CTRL_VAL_UNKNOWN)     
          xml.nput(" init=\"%d\"", _initVal);
      }

      if(_showInTracks != (ShowInDrum | ShowInMidi))
          xml.nput(" showType=\"%d\"", _showInTracks);
        
      xml.put(" />");
}
Example #2
0
int Msg_Define::setAttr(Xml &xml, TiXmlNode *node){
	std::string type, value, comt, sub1, sub2, key;
	std::string label = xml.get_key(node);
	if(label == "arg"){
		type = trans_to_base_name(xml.get_attr_str(node, "type"));
	}
	else if(label == "struct"){
		type = trans_to_base_name(xml.get_attr_str(node, "type"));
	}
	else if(label == "vector"){
		type = trans_to_base_name(label);
		sub1 = trans_to_base_name(xml.get_attr_str(node, "type"));
	}
	else if(label == "map"){
		type = trans_to_base_name(label);
		sub1 = trans_to_base_name(xml.get_attr_str(node, "key_type"));
		sub2 = trans_to_base_name(xml.get_attr_str(node, "type"));
		key = xml.get_attr_str(node, "key_name");
		
	}
	else if(label == "unordered_map"){
		type = trans_to_base_name(label);
		sub1 = trans_to_base_name(xml.get_attr_str(node, "key_type"));
		sub2 = trans_to_base_name(xml.get_attr_str(node, "type"));
		key = xml.get_attr_str(node, "key_name");
	}
	value = xml.get_attr_str(node, "name");
	if((comt = xml.get_attr_str(node, "desc")) != "" )
		comt = "//" + comt;
	typeName_.push_back(type);
	subType1_.push_back(sub1);
	subType2_.push_back(sub2);
	keyName_.push_back(key);
	valueName_.push_back(value);
	comment_.push_back(comt);
	return 0;
}
Example #3
0
Format* GetType(void* file_pointer, size_t file_size, const string& filename) {
  if (depth > max_depth)
    return new Format(file_pointer, file_size);

  if (!filename.empty()) {
    size_t dot = filename.find_last_of('.');
    if (dot != string::npos) {
      string ext = filename.substr(dot + 1);
      // toupper
      for (auto& c : ext)
        c &= ~0x20;

      if (ext == "HTML" || ext == "HTM" || ext == "JS" || ext == "CSS") {
        VerbosePrint(ext, " detected.");
        return new DataURI(file_pointer, file_size);
      }
      if (ext == "VCF" || ext == "VCARD") {
        VerbosePrint(ext, " detected.");
        return new Vcf(file_pointer, file_size);
      }
      if (ext == "MHT" || ext == "MHTML" || ext == "MIM" || ext == "MIME" || ext == "EML") {
        VerbosePrint(ext, " detected.");
        return new Mime(file_pointer, file_size);
      }
    }
  }
  if (memcmp(file_pointer, Png::header_magic, sizeof(Png::header_magic)) == 0) {
    VerbosePrint("PNG detected.");
    return new Png(file_pointer, file_size);
  } else if (memcmp(file_pointer, Jpeg::header_magic, sizeof(Jpeg::header_magic)) == 0) {
    VerbosePrint("JPEG detected.");
    return new Jpeg(file_pointer, file_size);
  } else if (memcmp(file_pointer, Lua::header_magic, sizeof(Lua::header_magic)) == 0) {
    VerbosePrint("Lua detected.");
    return new Lua(file_pointer, file_size);
  } else if (memcmp(file_pointer, Zip::header_magic, sizeof(Zip::header_magic)) == 0) {
    VerbosePrint("ZIP detected.");
    return new Zip(file_pointer, file_size);
  } else if (memcmp(file_pointer, Pe::header_magic, sizeof(Pe::header_magic)) == 0) {
    VerbosePrint("PE detected.");
    return new Pe(file_pointer, file_size);
  } else if (memcmp(file_pointer, Gz::header_magic, sizeof(Gz::header_magic)) == 0) {
    VerbosePrint("GZ detected.");
    return new Gz(file_pointer, file_size);
  } else if (memcmp(file_pointer, Ico::header_magic, sizeof(Ico::header_magic)) == 0) {
    VerbosePrint("ICO detected.");
    return new Ico(file_pointer, file_size);
  } else if (memcmp(file_pointer, Dwf::header_magic, sizeof(Dwf::header_magic)) == 0) {
    VerbosePrint("DWF detected.");
    return new Dwf(file_pointer, file_size);
  } else if (memcmp(file_pointer, Gft::header_magic, sizeof(Gft::header_magic)) == 0) {
    VerbosePrint("GFT detected.");
    return new Gft(file_pointer, file_size);
  } else if (memcmp(file_pointer, Rdb::header_magic, sizeof(Rdb::header_magic)) == 0) {
    VerbosePrint("RDB detected.");
    return new Rdb(file_pointer, file_size);
  } else if (memcmp(file_pointer, Swf::header_magic, sizeof(Swf::header_magic)) == 0 ||
             memcmp(file_pointer, Swf::header_magic_deflate, sizeof(Swf::header_magic_deflate)) == 0 ||
             memcmp(file_pointer, Swf::header_magic_lzma, sizeof(Swf::header_magic_lzma)) == 0) {
    VerbosePrint("SWF detected.");
    return new Swf(file_pointer, file_size);
  } else {
    // Search for vcard magic which might not be at the very beginning.
    const string vcard_magic = "BEGIN:VCARD";
    const char* fp = static_cast<char*>(file_pointer);
    const char* search_end = fp + std::min(static_cast<size_t>(1024), file_size);
    if (std::search(fp, search_end, vcard_magic.begin(), vcard_magic.end()) < search_end) {
      VerbosePrint("VCF detected.");
      return new Vcf(file_pointer, file_size);
    }

    // tar file does not have header magic
    // ustar is optional
    {
      Tar* t = new Tar(file_pointer, file_size);
      // checking first record checksum
      if (t->IsValid()) {
        VerbosePrint("tar detected.");
        return t;
      }
      delete t;
    }

    // XML file does not have header magic
    // have to parse and see if there are any errors.
    {
      Xml* x = new Xml(file_pointer, file_size);
      if (x->IsValid()) {
        VerbosePrint("XML detected.");
        return x;
      }
      delete x;
    }
  }

  VerbosePrint("Format not supported!");
  // for unsupported format, just memmove it.
  return new Format(file_pointer, file_size);
}
Example #4
0
void Patch::read(Xml& xml)
{
    typ = -1;
    hbank = -1;
    lbank = -1;
    prog = 0;
    drum = false;
    keys.clear();
    keyswitches.clear();
    for (;;)
    {
        Xml::Token token = xml.parse();
        const QString& tag = xml.s1();
        switch (token)
        {
        case Xml::Error:
        case Xml::End:
            return;
        case Xml::TagStart:
            xml.unknown("Patch");
            break;
        case Xml::Attribut:
            if (tag == "name")
                name = xml.s2();
            else if (tag == "mode")
                typ = xml.s2().toInt();
            else if (tag == "hbank")
                hbank = xml.s2().toInt();
            else if (tag == "lbank")
                lbank = xml.s2().toInt();
            else if (tag == "prog")
                prog = xml.s2().toInt();
            else if (tag == "drum")
                drum = xml.s2().toInt();
            else if(tag == "keys")
            {
                QStringList klist = ((QString)xml.s2()).split(QString(" "), QString::SkipEmptyParts);
                for (QStringList::Iterator it = klist.begin(); it != klist.end(); ++it)
                {
                    int val = (*it).toInt();
                    keys.append(val);
                }
            }
            else if(tag == "keyswitches")
            {
                QStringList klist = ((QString)xml.s2()).split(QString(" "), QString::SkipEmptyParts);
                for (QStringList::Iterator it = klist.begin(); it != klist.end(); ++it)
                {
                    int val = (*it).toInt();
                    keyswitches.append(val);
                }
            }
            break;
        case Xml::TagEnd:
            if (tag == "Patch")
                return;
        default:
            break;
        }
    }
}
void MindGlobalCircuitRegionDef::createFromXml( Xml xml ) {
	id = xml.getAttribute( "id" );
	role = xml.getAttribute( "role" );
}
Example #6
0
File: ctrl.cpp Project: faesong/oom
void CtrlList::read(Xml& xml)
{
	QLocale loc = QLocale::c();
	bool ok;
	for (;;)
	{
		Xml::Token token = xml.parse();
		const QString& tag = xml.s1();
		switch (token)
		{
			case Xml::Error:
			case Xml::End:
				return;
			case Xml::Attribut:
				if (tag == "id")
				{
					//_id = xml.s2().toInt();
					_id = loc.toInt(xml.s2(), &ok);
					if (!ok)
					{
						printf("CtrlList::read failed reading _id string: %s\n", xml.s2().toLatin1().constData());
						initColor(0); //Set the default color if we have an error
					}
					else {
						initColor(_id);
					}
				}
				else if (tag == "cur")
				{
					//_curVal = xml.s2().toDouble();
					_curVal = loc.toDouble(xml.s2(), &ok);
					if (!ok)
						printf("CtrlList::read failed reading _curVal string: %s\n", xml.s2().toLatin1().constData());
				}
				else if(tag == "visible")
				{
					_visible = (bool)xml.s2().toInt();
				}
				else if(tag == "color")
				{
					;//xml.skip(tag);
				}
				else
					printf("unknown tag %s\n", tag.toLatin1().constData());
				break;
			case Xml::Text:
			{
				// Changed by Tim. Users in some locales reported corrupt reading,
				//  because of the way floating point is represented (2,3456 not 2.3456).
				/*
				QByteArray ba = tag.toLatin1();
				const char* s = ba;.constData();
				int frame;
				double val;

				for (;;) {
					  char* endp;
					  while (*s == ' ' || *s == '\n')
							++s;
					  if (*s == 0)
							break;
					  frame = strtol(s, &endp, 10);
					  s     = endp;
					  while (*s == ' ' || *s == '\n')
							++s;
					  val = strtod(s, &endp);
					  add(frame, val);
					  s = endp;
					  ++s;
					  }
				 */

				// Added by Tim. p3.3.6
				//printf("CtrlList::read tag:%s\n", tag.toLatin1().constData());

				int len = tag.length();
				int frame;
				double val;

				int i = 0;
				for (;;)
				{
					while (i < len && (tag[i] == ',' || tag[i] == ' ' || tag[i] == '\n'))
						++i;
					if (i == len)
						break;

					QString fs;
					while (i < len && tag[i] != ' ')
					{
						fs.append(tag[i]);
						++i;
					}
					if (i == len)
						break;

					// Works OK, but only because if current locale fails it falls back on 'C' locale.
					// So, let's skip the fallback and force use of 'C' locale.
					//frame = fs.toInt(&ok);
					frame = loc.toInt(fs, &ok);
					if (!ok)
					{
						printf("CtrlList::read failed reading frame string: %s\n", fs.toLatin1().constData());
						break;
					}

					while (i < len && (tag[i] == ' ' || tag[i] == '\n'))
						++i;
					if (i == len)
						break;

					QString vs;
					while (i < len && tag[i] != ' ' && tag[i] != ',')
					{
						vs.append(tag[i]);
						++i;
					}

					// Works OK, but only because if current locale fails it falls back on 'C' locale.
					// So, let's skip the fallback and force use of 'C' locale.
					//val = vs.toDouble(&ok);
					val = loc.toDouble(vs, &ok);
					if (!ok)
					{
						printf("CtrlList::read failed reading value string: %s\n", vs.toLatin1().constData());
						break;
					}

					// Added by Tim. p3.3.6
					//printf("CtrlList::read i:%d len:%d fs:%s frame %d: vs:%s val %f \n", i, len, fs.toLatin1().constData(), frame, vs.toLatin1().constData(), val);

					add(frame, val);

					if (i == len)
						break;
				}
			}
				break;
			case Xml::TagEnd:
				if (xml.s1() == "controller")
				{
					// Added by Tim. p3.3.6
					//printf("CtrlList::read _id:%d _curVal:%f\n", _id, _curVal);

					return;
				}
			default:
				break;
		}
	}
}
Example #7
0
void TextLine::writeProperties(Xml& xml, const TextLine* proto) const
      {
      if (_beginHook) {
            if (proto == 0 || proto->beginHookHeight() != _beginHookHeight)
                  xml.tag("beginHookHeight", _beginHookHeight.val());
            if (proto == 0 || proto->beginHookType() != _beginHookType)
                  xml.tag("beginHookType", int(_beginHookType));
            }
      if (_endHook) {
            if (proto == 0 || proto->endHookHeight() != _endHookHeight)
                  xml.tag("endHookHeight", _endHookHeight.val());
            if (proto == 0 || proto->endHookType() != _endHookType)
                  xml.tag("endHookType", int(_endHookType));
            }

      if (proto == 0 || proto->lineWidth() != _lineWidth)
            xml.tag("lineWidth", _lineWidth.val());
      if (proto == 0 || proto->lineStyle() != _lineStyle)
            xml.tag("lineStyle", _lineStyle);
      if (proto == 0 || proto->lineColor() != _lineColor)
            xml.tag("lineColor", _lineColor);
      if (proto == 0 || proto->beginTextPlace() != _beginTextPlace)
            xml.pTag("beginTextPlace", _beginTextPlace);
      if (proto == 0 || proto->continueTextPlace() != _continueTextPlace)
            xml.pTag("continueTextPlace", _continueTextPlace);

      SLine::writeProperties(xml);
      if (_beginText) {
            xml.stag("beginText");
            _beginText->writeProperties(xml);
            xml.etag();
            }
      if (_continueText) {
            xml.stag("continueText");
            _continueText->writeProperties(xml);
            xml.etag();
            }
      if (_beginSymbol != -1) {
            xml.tag("beginSymbol", Sym::id2name(_beginSymbol));
            xml.tag("beginSymbolOffset", _beginSymbolOffset);
            }
      if (_continueSymbol != -1) {
            xml.tag("continueSymbol", Sym::id2name(_continueSymbol));
            xml.tag("continueSymbolOffset", _continueSymbolOffset);
            }
      if (_endSymbol != -1) {
            xml.tag("endSymbol", Sym::id2name(_endSymbol));
            xml.tag("endSymbolOffset", _endSymbolOffset);
            }
      }
Example #8
0
void LOS::importPartToTrack(QString& filename, unsigned tick, Track* track)
{
    bool popenFlag = false;
    FILE* fp = fileOpen(this, filename, ".mpt", "r", popenFlag, false, false);

    if (fp)
    {
        Xml xml = Xml(fp);
        bool firstPart = true;
        int posOffset = 0;
        int notDone = 0;
        int done = 0;

        bool end = false;
        song->startUndo();
        for (;;)
        {
            Xml::Token token = xml.parse();
            const QString& tag = xml.s1();
            switch (token)
            {
                case Xml::Error:
                case Xml::End:
                    end = true;
                    break;
                case Xml::TagStart:
                    if (tag == "part")
                    {

                        // Read the part.
                        Part* p = 0;
                        p = readXmlPart(xml, track);
                        // If it could not be created...
                        if (!p)
                        {
                            // Increment the number of parts not done and break.
                            ++notDone;
                            break;
                        }

                        // Increment the number of parts done.
                        ++done;

                        if (firstPart)
                        {
                            firstPart = false;
                            posOffset = tick - p->tick();
                        }
                        p->setTick(p->tick() + posOffset);
                        p->setColorIndex(track->getDefaultPartColor());
                        audio->msgAddPart(p, false);
                    }
                    else
                        xml.unknown("LOS::importPartToTrack");
                    break;
                case Xml::TagEnd:
                    break;
                default:
                    end = true;
                    break;
            }
            if (end)
                break;
        }
        fclose(fp);
        song->endUndo(SC_PART_INSERTED);

        if (notDone)
        {
            int tot = notDone + done;
            QMessageBox::critical(this, QString("LOS"),
                    QString().setNum(notDone) + (tot > 1 ? (tr(" out of ") + QString().setNum(tot)) : QString("")) +
                    (tot > 1 ? tr(" parts") : tr(" part")) +
                    tr(" could not be imported.\nLikely the track is the wrong type."));
        }

        return;
    }
}
Example #9
0
void NoteDot::write(Xml& xml) const
      {
      xml.stag(name());
      Element::writeProperties(xml);
      xml.etag();
      }
Example #10
0
void TextLine::write(Xml& xml) const
      {
      xml.stag(QString("%1 id=\"%2\"").arg(name()).arg(id()));
      writeProperties(xml);
      xml.etag();
      }
Example #11
0
void StaffTypeTablature::write(Xml& xml, int idx) const
      {
      xml.stag(QString("StaffType idx=\"%1\" group=\"%2\"").arg(idx).arg(groupName()));
      StaffType::writeProperties(xml);
      xml.tag("durations",        _genDurations);
      xml.tag("durationFontName", _durationFontName);
      xml.tag("durationFontSize", _durationFontSize);
      xml.tag("durationFontY",    _durationFontUserY);
      xml.tag("fretFontName",     _fretFontName);
      xml.tag("fretFontSize",     _fretFontSize);
      xml.tag("fretFontY",        _fretFontUserY);
      xml.tag("linesThrough",     _linesThrough);
      xml.tag("onLines",          _onLines);
      xml.tag("timesig",          _genTimesig);
      xml.tag("upsideDown",       _upsideDown);
      xml.tag("useNumbers",       _useNumbers);
      xml.etag();
      }
Example #12
0
void StaffType::write(Xml& xml, int idx) const
      {
      xml.stag(QString("StaffType idx=\"%1\" group=\"%2\"").arg(idx).arg(groupName()));
      writeProperties(xml);
      xml.etag();
      }
Example #13
0
void Audio::write(Xml& xml) const
{
    xml.stag("Audio");
    xml.tag("path", _path);
    xml.etag();
}
void Blaster::gotDoc4 ( void *state, TcpSocket *s){
	StateBD *st=(StateBD *)state;
	st->m_numUrlDocsReceived++;
	if (!s) {
		//Shouldn't happen, but still putting a checkpoint
		log (LOG_WARN,"blaster: Got a null s in gotDoc4."
		     "Happened because ip could not be found for gigablast"
		     "server");
		if (st->m_numUrlDocsReceived==st->m_numUrlDocsSent){
			m_launched--;
			// Free stateBD
			freeStateBD(st);
		}
		return;
	}
	// bail if got cut off
	if ( s->m_readOffset == 0 ) {
		log("blasterDiff : lost the Request in gotDoc4");
		if (st->m_numUrlDocsReceived==st->m_numUrlDocsSent){
			m_launched--;
			freeStateBD(st);
		}
		return;
	}
	char *reply = s->m_readBuf ;
	int32_t  size  = s->m_readOffset;
	HttpMime mime;
	mime.set ( reply , size , NULL );
	char *content    = reply + mime.getMimeLen();
	int32_t  contentLen = size  - mime.getMimeLen();

	//int16_t csEnum = get_iana_charset(mime.getCharset(), 
	//				mime.getCharsetLen());
	/*	if (csEnum == csUnknown)
		log(LOG_DEBUG, "blaster: Unknown charset : %s", mime.getCharset());*/
	
	Xml xml;
	if (!xml.set(
		     content, 
		     contentLen,
		     false,
		     0,
		     false,
		     TITLEREC_CURRENT_VERSION,
		     true, // setparents
		     0, // niceness
		     CT_XML )){
		log(LOG_WARN,"blaster: Couldn't set XML Class in gotDoc4");
	}
	Links links;
	Url *url=mime.getLocationUrl();
	if (!links.set(0,//siterec xml
		       &xml,
		       url,
		       false,
		       NULL,
		       TITLEREC_CURRENT_VERSION,
		       0,
		       false,
		       NULL)){
		log(LOG_WARN, "blaster: Coudn't set Links class in gotDoc4");
	}
	for (int32_t i=0;i<links.getNumLinks();i++){
		char *ss=links.getLink(i);
		char *p;
		// This page *should* always be a gigablast page. So not adding
		// checks for msn or yahoo or google page.
		p=strstr(ss,"google.");
		if(p) continue;
		p=strstr(ss,"cache:");  //googles cache page
		if(p) continue;
		p= strstr(ss,"gigablast.");
		if(p) continue;
		p= strstr(ss,"web.archive.org");//older copies on gigablast
		if(p) continue;
		p= strstr(ss,"search.yahoo.com");//from gigablast search
		if(p) continue;
		p= strstr(ss,"search.msn.com");//from gigablast search
		if(p) continue;
		p= strstr(ss,"s.teoma.com");//from gigablast search
		if(p) continue;
		p= strstr(ss,"search.dmoz.org");//from gigablast search
		if(p) continue;
		p= strstr(ss,"www.answers.com");//from gigablast search
		if(p) continue;
       		if (m_verbose)
			log(LOG_WARN,"blaster: Link Present on server2=%s",ss);
	}
	
	// So if one of the links that is returned is the exact url,
	// then we know that the url is present.So get the url from the
	// mime, search for it in the links that are returned.
	char tmp[1024];
	char *sendBuf=s->m_sendBuf;
	char *p1,*p2;

	// First get the Host, which is the domain. Since socket s is going to
	// be useless after this function, changing m_sendBuf instead of using 
	// more space
	p1=strstr(sendBuf,"%3A");
	if(p1){
		p1+=3;
		p2=strstr(p1," HTTP");
		if (p2){
			//Since I do not care about the sendbuf anymore
			*p2='\0';
		}
	}
	if (!p1 || !p2){
		log(LOG_WARN,"blasterdiff: Could not find search link"
		    "from m_sendBuf in gotdoc4");
	}
	else{
		sprintf(tmp,"%s",p1);
		//log(LOG_WARN,"blaster: tmp in gotDoc4 = %s",tmp);
		bool isFound=false;
		// So now we search for tmp in the links
		for (int32_t i=0;i<links.getNumLinks();i++){
			if(strstr(links.getLink(i),tmp) && 
			   links.getLinkLen(i)==(int)gbstrlen(tmp)){
				isFound=true;
				log(LOG_WARN,"blaster: %s in results1 but not"
				    " in results2 for query %s but does exist"
				    " in server2",tmp,st->m_u1);//->getQuery()
			}
		}
		if (!isFound)
			log(LOG_WARN,"blaster: %s in results1 but not"
			    " in results2 for query %s and does NOT exist"
			    " in server2",tmp,st->m_u1); // ->getQuery()
	}
	

      	if (st->m_numUrlDocsReceived==st->m_numUrlDocsSent){
		m_launched--;
		// Free stateBD
		freeStateBD(st);
	}
	return;
}
Example #15
0
void PageFormat::write(Xml& xml) const
      {
      xml.stag("page-layout");

      // convert inch to 1/10 spatium units
      // 20 - font design size in point
      // SPATIUM = 20/4
      // qreal t = 10 * PPI / (20 / 4);
      qreal t = 2 * PPI;

      xml.tag("page-height", _size.height() * t);
      xml.tag("page-width",  _size.width() * t);

      const char* type = "both";
      if (_twosided) {
            type = "even";
            xml.stag(QString("page-margins type=\"%1\"").arg(type));
            xml.tag("left-margin",   evenLeftMargin() * t);
            xml.tag("right-margin",  evenRightMargin() * t);
            xml.tag("top-margin",    evenTopMargin() * t);
            xml.tag("bottom-margin", evenBottomMargin() * t);
            xml.etag();
            type = "odd";
            }
      xml.stag(QString("page-margins type=\"%1\"").arg(type));
      xml.tag("left-margin",   oddLeftMargin() * t);
      xml.tag("right-margin",  oddRightMargin() * t);
      xml.tag("top-margin",    oddTopMargin() * t);
      xml.tag("bottom-margin", oddBottomMargin() * t);
      xml.etag();

      xml.etag();
      }
Example #16
0
void DurationElement::writeProperties(Xml& xml) const
      {
      Element::writeProperties(xml);
      if (tuplet())
            xml.tag("Tuplet", tuplet()->id());
      }
Example #17
0
void Page::write(Xml& xml) const
      {
      xml.stag("Page");
      foreach(System* system, _systems) {
            system->write(xml);
            }
Example #18
0
void StaffType::write(Xml& xml) const
      {
      xml.stag(QString("StaffType group=\"%1\"").arg(fileGroupNames[(int)_group]));
      if (!_xmlName.isEmpty())
            xml.tag("name", _xmlName);
      if (_lines != 5)
            xml.tag("lines", _lines);
      if (_lineDistance.val() != 1.0)
            xml.tag("lineDistance", _lineDistance.val());
      if (!_genClef)
            xml.tag("clef", _genClef);
      if (_slashStyle)
            xml.tag("slashStyle", _slashStyle);
      if (!_showBarlines)
            xml.tag("barlines", _showBarlines);
      if (!_genTimesig)
            xml.tag("timesig", _genTimesig);
      if (_group == StaffGroup::STANDARD || _group == StaffGroup::PERCUSSION) {
            if (!_genKeysig)
                  xml.tag("keysig", _genKeysig);
            if (!_showLedgerLines)
                  xml.tag("ledgerlines", _showLedgerLines);
            }
      else {
            xml.tag("durations",        _genDurations);
            xml.tag("durationFontName", _durationFonts[_durationFontIdx].displayName);
            xml.tag("durationFontSize", _durationFontSize);
            xml.tag("durationFontY",    _durationFontUserY);
            xml.tag("fretFontName",     _fretFonts[_fretFontIdx].displayName);
            xml.tag("fretFontSize",     _fretFontSize);
            xml.tag("fretFontY",        _fretFontUserY);
            if (_symRepeat != TablatureSymbolRepeat::NEVER)
                  xml.tag("symbolRepeat",     int(_symRepeat));
            xml.tag("linesThrough",     _linesThrough);
            xml.tag("minimStyle",       int(_minimStyle));
            xml.tag("onLines",          _onLines);
            xml.tag("showRests",        _showRests);
            xml.tag("stemsDown",        _stemsDown);
            xml.tag("stemsThrough",     _stemsThrough);
            xml.tag("upsideDown",       _upsideDown);
            xml.tag("useNumbers",       _useNumbers);
            }
      xml.etag();
      }
Example #19
0
bool AudioTrack::readProperties(Xml& xml, const QString& tag)
{
    if (tag == "LadspaPlugin" || tag == "plugin")
    {
         BasePlugin* pi = new LadspaPlugin();
         pi->setTrack(this);
         pi->setId((int)_efxPipe->size());
         if (pi->readConfiguration(xml, false))
            delete pi;
         else
            _efxPipe->addPlugin(pi, -1);
    }
    else if (tag == "Lv2Plugin")
    {
         Lv2Plugin* pi = new Lv2Plugin();
         pi->setTrack(this);
         pi->setId((int)_efxPipe->size());
         if (pi->readConfiguration(xml, false))
            delete pi;
         else
            _efxPipe->addPlugin(pi, -1);
    }
    else if (tag == "VstPlugin")
    {
         VstPlugin* pi = new VstPlugin();
         pi->setTrack(this);
         pi->setId((int)_efxPipe->size());
         if (pi->readConfiguration(xml, false))
            delete pi;
         else
            _efxPipe->addPlugin(pi, -1);
    }
    else if (tag == "auxSend")
        readAuxSend(xml);
    else if (tag == "prefader")
        _prefader = xml.parseInt();
    else if (tag == "sendMetronome")
        _sendMetronome = xml.parseInt();
    else if (tag == "automation")
        setAutomationType(AutomationType(xml.parseInt()));
    else if (tag == "controller")
    {
        CtrlList* l = new CtrlList();
        l->read(xml);

        // Since (until now) oom wrote a 'zero' for plugin controller current value
        //  in the XML file, we can't use that value, now that plugin automation is added.
        // We must take the value from the plugin control value.
        // Otherwise we break all existing .oom files with plugins, because the gui
        //  controls would all be set to zero.
        // But we will allow for the (unintended, useless) possibility of a controller
        //  with no matching plugin control.
        BasePlugin* p = 0;
        bool ctlfound = false;
        int m = l->id() & AC_PLUGIN_CTL_ID_MASK;
        int n = (l->id() >> AC_PLUGIN_CTL_BASE_POW) - 1;
		int pdepth = _efxPipe->size();
        if (n >= 0 && n < pdepth)
        {
            p = (*_efxPipe)[n];
            if (p)
            {
                ParameterPort* cport = p->getParameterPort(m);
                if (cport && cport->type == PARAMETER_INPUT && (cport->hints & PARAMETER_IS_AUTOMABLE) > 0)
                    ctlfound = true;
            }
        }

        iCtrlList icl = _controller.find(l->id());
        if (icl == _controller.end())
            _controller.add(l);
        else
        {
            CtrlList* d = icl->second;
            for (iCtrl i = l->begin(); i != l->end(); ++i)
                d->add(i->second.getFrame(), i->second.val);

            if (!ctlfound)
                d->setCurVal(l->curVal());
            d->setColor(l->color());
            d->setVisible(l->isVisible());

            d->setDefault(l->getDefault());
            delete l;
            l = d;
        }

        if (ctlfound)
        {
            l->setCurVal(p->getParameterValue(m));
            ParameterPort* cport = p->getParameterPort(m);
            if (cport && cport->hints & PARAMETER_IS_TOGGLED)
                l->setMode(CtrlList::DISCRETE);
            else
                l->setMode(CtrlList::INTERPOLATE);
        }
    }
Example #20
0
void Text::write(Xml& xml) const
      {
      xml.stag(name());
      writeProperties(xml, true);
      xml.etag();
      }
Example #21
0
void Rest::write(Xml& xml) const
      {
      xml.stag(name());
      ChordRest::writeProperties(xml);
      xml.etag();
      }
Example #22
0
void MasterEdit::writeConfiguration(int level, Xml& xml)
{
	xml.tag(level++, "masteredit");
	xml.intTag(level, "raster", _rasterInit);
	xml.tag(level, "/masteredit");
}
Example #23
0
void Box::write(Xml& xml) const
      {
      xml.stag(name());
      writeProperties(xml);
      xml.etag();
      }
Example #24
0
void Tie::write(Xml& xml) const
      {
      xml.stag(QString("Tie id=\"%1\"").arg(id()));
      SlurTie::writeProperties(xml);
      xml.etag();
      }
Example #25
0
void gtkui_cheats_fill_tree(char *filename) {
	// Fill the cheat list
	Xml xml;
	
	GtkTreeIter iter;
	
	bool enabled = false;
	
	char codebuf[9];
	char descbuf[512];
	
	gtkui_cheats_clear();
	
	std::ifstream cheatfile(filename, std::ifstream::in|std::ifstream::binary);
	
	if (cheatfile.is_open()) {
		xml.Read(cheatfile);
		
		if (xml.GetRoot().IsType(L"cheats")) {
			
			Xml::Node root(xml.GetRoot());
			Xml::Node node(root.GetFirstChild());
			
			for (int i = 0; i < root.NumChildren(L"cheat"); i++) {
				
				wcstombs(descbuf, node.GetChild(L"description").GetValue(), sizeof(descbuf));
				
				// Check if the cheat is enabled
				node.GetAttribute(L"enabled").IsValue(L"1") ? enabled = true : enabled = false;
				
				// Add the cheats to the list
				if (node.GetChild(L"genie")) { // Game Genie
					wcstombs(codebuf, node.GetChild(L"genie").GetValue(), sizeof(codebuf));
					gtk_tree_store_append(treestore, &iter, NULL);
					gtk_tree_store_set(treestore, &iter,
								0, enabled,
								1, codebuf,
								4, descbuf,
								-1);
					if (enabled) { cheats_code_gg_add(node.GetChild(L"genie").GetValue()); }
				}
				
				else if (node.GetChild(L"rocky")) { // Pro Action Rocky
					wcstombs(codebuf, node.GetChild(L"rocky").GetValue(), sizeof(codebuf));
					gtk_tree_store_append(treestore, &iter, NULL);
					gtk_tree_store_set(treestore, &iter,
								0, enabled,
								2, codebuf,
								4, descbuf,
								-1);
					if (enabled) { cheats_code_par_add(node.GetChild(L"rocky").GetValue()); }
				}
				
				else if (node.GetChild(L"address")) { // Raw
					char rawbuf[11];
					snprintf(rawbuf, sizeof(rawbuf),
								"%04x %02x %02x",
								node.GetChild(L"address").GetUnsignedValue(),
								node.GetChild(L"value").GetUnsignedValue(),
								node.GetChild(L"compare").GetUnsignedValue());
					
					gtk_tree_store_append(treestore, &iter, NULL);
					gtk_tree_store_set(treestore, &iter,
								0, enabled,
								3, rawbuf,
								4, descbuf,
								-1);
					if (enabled) { cheats_code_raw_add(node); }
				}
				
				node = node.GetNextSibling();
			}
		}
		cheatfile.close();
	}	
}
Example #26
0
void MidiInstrument::read(Xml& xml)
{
    bool ok;
    int base = 10;
    _nullvalue = -1;
    for (;;)
    {
        Xml::Token token = xml.parse();
        const QString& tag = xml.s1();
        switch (token)
        {
        case Xml::Error:
        case Xml::End:
            return;
        case Xml::TagStart:
            if (tag == "Patch")
            {
                Patch* patch = new Patch;
                patch->read(xml);
                if (pg.empty())
                {
                    PatchGroup* p = new PatchGroup;
                    p->patches.push_back(patch);
                    pg.push_back(p);
                }
                else
                    pg[0]->patches.push_back(patch);
            }
            else if (tag == "PatchGroup")
            {
                PatchGroup* p = new PatchGroup;
                p->read(xml);
                pg.push_back(p);
            }
            else if (tag == "Controller")
            {
                MidiController* mc = new MidiController();
                mc->read(xml);
                // Added by Tim. Copied from oom 2.
                //
                // HACK: make predefined "Program" controller overloadable
                //
                if (mc->name() == "Program")
                {
                    for (iMidiController i = _controller->begin(); i != _controller->end(); ++i)
                    {
                        if (i->second->name() == mc->name())
                        {
                            delete i->second;
                            _controller->erase(i);
                            break;
                        }
                    }
                }

                _controller->add(mc);
            }
            else if (tag == "Init")
                readEventList(xml, _midiInit, "Init");
            else if (tag == "Reset")
                readEventList(xml, _midiReset, "Reset");
            else if (tag == "State")
                readEventList(xml, _midiState, "State");
            else if (tag == "InitScript")
            {
                if (_initScript)
                    delete _initScript;
                QByteArray ba = xml.parse1().toLatin1();
                const char* istr = ba.constData();
                int len = strlen(istr) + 1;
                if (len > 1)
                {
                    _initScript = new char[len];
                    memcpy(_initScript, istr, len);
                }
            }

            else
                xml.unknown("MidiInstrument");
            break;
        case Xml::Attribut:
            if (tag == "name")
                setIName(xml.s2());
            else if (tag == "nullparam")
            {
                _nullvalue = xml.s2().toInt(&ok, base);
            }
            break;
        case Xml::TagEnd:
            if (tag == "MidiInstrument")
                return;
        default:
            break;
        }
    }
}
Example #27
0
void MarkerView::writeStatus(int level, Xml& xml) const
{
    xml.tag(level++, "marker");
    xml.tag(level, "/marker");
}
Example #28
0
void MidiController::read(Xml& xml)
      {
      ControllerType t = Controller7;
      _initVal = CTRL_VAL_UNKNOWN;
      static const int NOT_SET = 0x100000;
      _minVal  = NOT_SET;
      _maxVal  = NOT_SET;
      int h    = 0;
      int l    = 0;
      bool     ok;
      int base = 10;

      for (;;) {
            Xml::Token token = xml.parse();
            const QString& tag = xml.s1();
            switch (token) {
                  case Xml::Error:
                  case Xml::End:
                        return;
                  case Xml::Attribut:
                        {
                        QString s = xml.s2();
                        if (s.left(2) == "0x")
                              base = 16;
                        if (tag == "name")
                              _name = xml.s2();
                        else if (tag == "type")
                              t = ctrlType2Int(xml.s2());
                        else if (tag == "h")
                              h = xml.s2().toInt(&ok, base);
                        else if (tag == "l") {
                              // Support instrument files with '*' or 'pitch' as wildcard.
                              if ((xml.s2() == "*") || (xml.s2() == "pitch"))
                                    l = 0xff;
                              else
                                    l = xml.s2().toInt(&ok, base);
                              }
                        else if (tag == "min")
                              _minVal = xml.s2().toInt(&ok, base);
                        else if (tag == "max")
                              _maxVal = xml.s2().toInt(&ok, base);
                        else if (tag == "init")
                              _initVal = xml.s2().toInt(&ok, base);
                        else if (tag == "showType")
                              _showInTracks = xml.s2().toInt(&ok, base);
                        }
                        break;
                  case Xml::TagStart:
                        xml.unknown("MidiController");
                        break;
                  case Xml::TagEnd:
                        if (tag == "Controller") {
                              _num = (h << 8) + l;
                              switch (t) {
                                    case RPN:
                                          if (_maxVal == NOT_SET)
                                                _maxVal = 127;
                                          _num |= CTRL_RPN_OFFSET;
                                          break;
                                    case NRPN:
                                          if (_maxVal == NOT_SET)
                                                _maxVal = 127;
                                          _num |= CTRL_NRPN_OFFSET;
                                          break;
                                    case Controller7:
                                          if (_maxVal == NOT_SET)
                                                _maxVal = 127;
                                          break;
                                    case Controller14:
                                          _num |= CTRL_14_OFFSET;
                                          if (_maxVal == NOT_SET)
                                                _maxVal = 16383;
                                          break;
                                    case RPN14:
                                          if (_maxVal == NOT_SET)
                                                _maxVal = 16383;
                                          _num |= CTRL_RPN14_OFFSET;
                                          break;
                                    case NRPN14:
                                          if (_maxVal == NOT_SET)
                                                _maxVal = 16383;
                                          _num |= CTRL_NRPN14_OFFSET;
                                          break;
                                    case Pitch:
                                          if (_maxVal == NOT_SET)
                                                _maxVal = 8191;
                                          if (_minVal == NOT_SET)
                                                _minVal = -8192;
                                          _num = CTRL_PITCH;
                                          break;
                                    case Program:
                                          if (_maxVal == NOT_SET)
                                                _maxVal = 0xffffff;
                                          _num = CTRL_PROGRAM;
                                          break;
                                    case PolyAftertouch:   
                                          if (_maxVal == NOT_SET)
                                                _maxVal = 127;
                                          if (_minVal == NOT_SET)
                                                _minVal = 0;
                                          _num = CTRL_POLYAFTER;
                                          break;
                                    case Aftertouch:       
                                          if (_maxVal == NOT_SET)
                                                _maxVal = 127;
                                          if (_minVal == NOT_SET)
                                                _minVal = 0;
                                          _num = CTRL_AFTERTOUCH;
                                          break;
                                    case Velo:        // cannot happen
                                          break;
                                    }
                              if (_minVal == NOT_SET)
                                    _minVal = 0;
                              updateBias();
                              return;
                              }
                  default:
                        break;
                  }
            }
      }
Example #29
0
Format *GetType(void *file_pointer, size_t file_size, const string& filename)
{
    if (depth > max_depth)
    {
        return new Format(file_pointer, file_size);
    }

    if (!filename.empty())
    {
        size_t dot = filename.find_last_of('.');
        if (dot != string::npos)
        {
            string ext = filename.substr(dot + 1);
            // toupper
            for (auto &c : ext)
                c &= ~0x20;

            if (ext == "HTML" ||
                ext == "HTM" ||
                ext == "JS" ||
                ext == "CSS")
            {
                if (is_verbose)
                {
                    cout << ext << " detected." << endl;
                }
                return new DataURI(file_pointer, file_size);
            }
        }

    }
    if (memcmp(file_pointer, Png::header_magic, sizeof(Png::header_magic)) == 0)
    {
        if (is_verbose)
        {
            cout << "PNG detected." << endl;
        }
        return new Png(file_pointer, file_size);
    }
    else if (memcmp(file_pointer, Jpeg::header_magic, sizeof(Jpeg::header_magic)) == 0)
    {
        if (is_verbose)
        {
            cout << "JPEG detected." << endl;
        }
        return new Jpeg(file_pointer, file_size);
    }
    else if (memcmp(file_pointer, Lua::header_magic, sizeof(Lua::header_magic)) == 0)
    {
        if (is_verbose)
        {
            cout << "Lua detected." << endl;
        }
        return new Lua(file_pointer, file_size);
    }
    else if (memcmp(file_pointer, Zip::header_magic, sizeof(Zip::header_magic)) == 0)
    {
        if (is_verbose)
        {
            cout << "ZIP detected." << endl;
        }
        return new Zip(file_pointer, file_size);
    }
    else if (memcmp(file_pointer, Pe::header_magic, sizeof(Pe::header_magic)) == 0)
    {
        if (is_verbose)
        {
            cout << "PE detected." << endl;
        }
        return new Pe(file_pointer, file_size);
    }
    else if (memcmp(file_pointer, Gz::header_magic, sizeof(Gz::header_magic)) == 0)
    {
        if (is_verbose)
        {
            cout << "GZ detected." << endl;
        }
        return new Gz(file_pointer, file_size);
    }
    else if (memcmp(file_pointer, Ico::header_magic, sizeof(Ico::header_magic)) == 0)
    {
        if (is_verbose)
        {
            cout << "ICO detected." << endl;
        }
        return new Ico(file_pointer, file_size);
    }
    else if (memcmp(file_pointer, Dwf::header_magic, sizeof(Dwf::header_magic)) == 0)
    {
        if (is_verbose)
        {
            cout << "DWF detected." << endl;
        }
        return new Dwf(file_pointer, file_size);
    }
    else if (memcmp(file_pointer, Gft::header_magic, sizeof(Gft::header_magic)) == 0)
    {
        if (is_verbose)
        {
            cout << "GFT detected." << endl;
        }
        return new Gft(file_pointer, file_size);
    }
    else if (memcmp(file_pointer, Rdb::header_magic, sizeof(Rdb::header_magic)) == 0)
    {
        if (is_verbose)
        {
            cout << "RDB detected." << endl;
        }
        return new Rdb(file_pointer, file_size);
    }
    else if (memcmp(file_pointer, Swf::header_magic, sizeof(Swf::header_magic)) == 0 ||
             memcmp(file_pointer, Swf::header_magic_deflate, sizeof(Swf::header_magic_deflate)) == 0 ||
             memcmp(file_pointer, Swf::header_magic_lzma, sizeof(Swf::header_magic_lzma)) == 0)
    {
        if (is_verbose)
        {
            cout << "SWF detected." << endl;
        }
        return new Swf(file_pointer, file_size);
    }
    else
    {
        // tar file does not have header magic
        // ustar is optional
        {
            Tar *t = new Tar(file_pointer, file_size);
            // checking first record checksum
            if (t->IsValid())
            {
                if (is_verbose)
                {
                    cout << "tar detected." << endl;
                }
                return t;
            }
            delete t;
        }

        // XML file does not have header magic
        // have to parse and see if there are any errors.
        {
            Xml *x = new Xml(file_pointer, file_size);
            if (x->IsValid())
            {
                if (is_verbose)
                {
                    cout << "XML detected." << endl;
                }
                return x;
            }
            delete x;
        }
    }

    if (is_verbose)
    {
        cout << "Format not supported!" << endl;
    }
    // for unsupported format, just memmove it.
    return new Format(file_pointer, file_size);
}