コード例 #1
0
bool QgsGPXFeatureIterator::fetchFeature( QgsFeature& feature )
{
  feature.setValid( false );

  if ( mClosed )
    return false;

  if ( mRequest.filterType() == QgsFeatureRequest::FilterFid )
  {
    bool res = readFid( feature );
    close();
    return res;
  }

  if ( mSource->mFeatureType == QgsGPXProvider::WaypointType )
  {
    // go through the list of waypoints and return the first one that is in
    // the bounds rectangle
    for ( ; mWptIter != mSource->data->waypointsEnd(); ++mWptIter )
    {
      if ( readWaypoint( *mWptIter, feature ) )
      {
        ++mWptIter;
        return true;
      }
    }
  }
  else if ( mSource->mFeatureType == QgsGPXProvider::RouteType )
  {
    // go through the routes and return the first one that is in the bounds
    // rectangle
    for ( ; mRteIter != mSource->data->routesEnd(); ++mRteIter )
    {
      if ( readRoute( *mRteIter, feature ) )
      {
        ++mRteIter;
        return true;
      }
    }
  }
  else if ( mSource->mFeatureType == QgsGPXProvider::TrackType )
  {
    // go through the tracks and return the first one that is in the bounds
    // rectangle
    for ( ; mTrkIter != mSource->data->tracksEnd(); ++mTrkIter )
    {
      if ( readTrack( *mTrkIter, feature ) )
      {
        ++mTrkIter;
        return true;
      }
    }
  }

  close();
  return false;
}
コード例 #2
0
ファイル: k3bverificationjob.cpp プロジェクト: franhaufer/k3b
void K3b::VerificationJob::slotDiskInfoReady( K3b::Device::DeviceHandler* dh )
{
    if( d->canceled ) {
        // signal already emitted in cancel()
        return;
    }

    if ( !dh->success() ) {
        blockingInformation( i18n("Please reload the medium and press 'OK'"),
                             i18n("Failed to reload the medium") );
    }

    d->diskInfo = dh->diskInfo();
    d->toc = dh->toc();
    d->totalSectors = 0;

    // just to be sure check if we actually have all the tracks
    for( TrackEntries::iterator it = d->trackEntries.begin(); it != d->trackEntries.end(); ++it ) {

        // 0 means "last track"
        if( it->trackNumber == 0 )
            it->trackNumber = d->toc.count();

        if( it->trackNumber <= 0 || it->trackNumber > d->toc.count() ) {
            if ( d->mediumHasBeenReloaded ) {
                emit infoMessage( i18n("Internal Error: Verification job improperly initialized (%1)",
                                       i18n("specified track number '%1' not found on medium", it->trackNumber) ), MessageError );
                jobFinished( false );
                return;
            }
            else {
                d->reloadMedium();
                return;
            }
        }

        d->totalSectors += d->trackLength( *it );
    }

    Q_ASSERT( d->currentTrackEntry != d->trackEntries.end() );

    if( d->currentTrackEntry->trackNumber >= d->toc.count() ) {
        readTrack();
    }
    else if( !d->mediumHasBeenReloaded ) {
        d->reloadMedium();
    }
    else {
        emit infoMessage( i18n("Internal Error: Verification job improperly initialized (%1)",
                               i18n("specified track number '%1' not found on medium", d->currentTrackEntry->trackNumber) ), MessageError );
        jobFinished( false );
    }
}
コード例 #3
0
bool MidiFile::read(QIODevice* in)
     {
      fp = in;
      _tracks.clear();
      curPos    = 0;

      char tmp[4];

      read(tmp, 4);
      int len = readLong();
      if (memcmp(tmp, "MThd", 4) || len < 6)
            throw(QString("bad midifile: MThd expected"));

      _format     = readShort();
      int ntracks = readShort();
      _division   = readShort();

      if (_division < 0)
            _division = (-(_division/256)) * (_division & 0xff);
      if (len > 6)
            skip(len-6); // skip the excess

      switch (_format) {
            case 0:
                  if (readTrack())
                        return false;
                  break;
            case 1:
                  for (int i = 0; i < ntracks; i++) {
                        if (readTrack())
                              return false;
                        }
                  break;
            default:
                  throw(QString("midi file format %1 not implemented").arg(_format));
                  return false;
            }
      return true;
      }
コード例 #4
0
bool QgsGPXFeatureIterator::readFid( QgsFeature& feature )
{
  if ( mFetchedFid )
    return false;

  mFetchedFid = true;
  QgsFeatureId fid = mRequest.filterFid();

  if ( mSource->mFeatureType == QgsGPXProvider::WaypointType )
  {
    for ( QgsGPSData::WaypointIterator it = mSource->data->waypointsBegin() ; it != mSource->data->waypointsEnd(); ++it )
    {
      if ( it->id == fid )
      {
        readWaypoint( *it, feature );
        return true;
      }
    }
  }
  else if ( mSource->mFeatureType == QgsGPXProvider::RouteType )
  {
    for ( QgsGPSData::RouteIterator it = mSource->data->routesBegin() ; it != mSource->data->routesEnd(); ++it )
    {
      if ( it->id == fid )
      {
        readRoute( *it, feature );
        return true;
      }
    }
  }
  else if ( mSource->mFeatureType == QgsGPXProvider::TrackType )
  {
    for ( QgsGPSData::TrackIterator it = mSource->data->tracksBegin() ; it != mSource->data->tracksEnd(); ++it )
    {
      if ( it->id == fid )
      {
        readTrack( *it, feature );
        return true;
      }
    }
  }

  return false;
}
コード例 #5
0
ファイル: clipboard.cpp プロジェクト: hftom/MachinTruc
QList< QList<Clip*>* >* ClipBoard::getClips( QList<Source*> sourcesList, Scene *scene )
{
    QDomElement rootElement = document.documentElement();
    QDomNodeList nodes = rootElement.childNodes();

    QList< QList<Clip*>* > *list = new QList< QList<Clip*>* >();

    for ( int i = 0; i < nodes.count(); ++i ) {
        QDomElement e = nodes.at( i ).toElement();
        if ( e.isNull() )
            continue;

        if ( e.tagName().startsWith( "Track" ) ) {
            QList<Clip*> *track = new QList<Clip*>();
            readTrack( e, track, &sourcesList, scene );
            list->append(track);
        }
    }

    return list;
}
コード例 #6
0
ファイル: tcxreader.cpp プロジェクト: Nikoli/qlandkartegt
void TcxReader::readCourse()
{
    Q_ASSERT(isStartElement() && name() == "Course");

    CTrack *track = new CTrack(parent);
    //track->setTraineeData();
    while (!atEnd())
    {
        readNext();

        if (isEndElement())
            break;

        if (isStartElement())
        {
            if (name() == "Name")
            {
                track->setName(readElementText());
            }
            else if (name() == "Track")
            {
                readTrack(track,1);
            }
            else
                readUnknownElement();
        }
    }
    if (track->getTrackPoints().count() > 0)
    {
        track->rebuild(true);
        track->sortByTimestamp();
        CTrackDB::self().addTrack(track, false);
    }
    else
    {
        delete track;
    }
}
コード例 #7
0
ファイル: midi.cpp プロジェクト: bmahlbrand/midization
int
MidiFile::read(const char *fileName) {
	if (fileName == NULL)
		return 1;
	
	setFileName(fileName);
	_target = openFile(fileName);
	
	if (!_target)
		return 1;

	readFileHeader();
	setType();
	setTrackCount();
	setBPM();
	for (int i = 0; i < _fileHeader._tracks; i++) {
		_curTrack = i;
		readTrack();
		printContour();
	}

	fclose(_target);
   	return 0;
}		
コード例 #8
0
ファイル: tcxreader.cpp プロジェクト: Nikoli/qlandkartegt
void TcxReader::readLap(CTrack *track)
{
    Q_ASSERT(isStartElement() && name() == "Lap");

    int lap = 1;
    while (!atEnd())
    {
        readNext();

        if (isEndElement())
            break;

        if (isStartElement())
        {
            if (name() == "Track")
            {
                readTrack(track, lap);
            }
            else
                readUnknownElement();
        }
    }

}
コード例 #9
0
ファイル: midifile.c プロジェクト: BurntBrunch/rockbox-fft
struct MIDIfile * loadFile(const char * filename)
{
    struct MIDIfile * mfload;
    int file = rb->open (filename, O_RDONLY);

    if(file < 0)
    {
        printf("Could not open file");
        return NULL;
    }

    mfload = &midi_file;

    rb->memset(mfload, 0, sizeof(struct MIDIfile));

    int fileID = readID(file);
    if(fileID != ID_MTHD)
    {
        if(fileID == ID_RIFF)
        {
            printf("Detected RMID file");
            printf("Looking for MThd header");
            char dummy[17];
            rb->read(file, &dummy, 16);
            if(readID(file) != ID_MTHD)
            {
                rb->close(file);
                printf("Invalid MIDI header within RIFF.");
                return NULL;
            }

        } else
        {
            rb->close(file);
            printf("Invalid file header chunk.");
            return NULL;
        }
    }

    if(readFourBytes(file)!=6)
    {
        rb->close(file);
        printf("Header chunk size invalid.");
        return NULL;
    }

    if(readTwoBytes(file)==2)
    {
        rb->close(file);
        printf("MIDI file type 2 not supported");
        return NULL;
    }

    mfload->numTracks = readTwoBytes(file);
    mfload->div = readTwoBytes(file);

    int track=0;

    printf("File has %d tracks.", mfload->numTracks);

    while(! eof(file) && track < mfload->numTracks)
    {
        unsigned char id = readID(file);


        if(id == ID_EOF)
        {
            if(mfload->numTracks != track)
            {
                printf("Warning: file claims to have %d tracks. I only see %d here.", mfload->numTracks, track);
                mfload->numTracks = track;
            }
            rb->close(file);
            return mfload;
        }

        if(id == ID_MTRK)
        {
            mfload->tracks[track] = readTrack(file);
            track++;
        } else
        {
            printf("SKIPPING TRACK");
            int len = readFourBytes(file);
            while(--len)
                readChar(file);
        }
    }

    rb->close(file);
    return mfload;

}
コード例 #10
0
bool QLandmarkFileHandlerGpx::readGpx()
{
    /*
    <xsd:complexType name="gpxType">
        <xsd:sequence>
             <xsd:element name="metadata" type="metadataType" minOccurs="0" />
             <xsd:element name="wpt" type="wptType" minOccurs="0" maxOccurs="unbounded" />
             <xsd:element name="rte" type="rteType" minOccurs="0" maxOccurs="unbounded" />
             <xsd:element name="trk" type="trkType"	minOccurs="0" maxOccurs="unbounded" />
             <xsd:element name="extensions" type="extensionsType" minOccurs="0" />
        </xsd:sequence>
        <xsd:attribute name="version" type="xsd:string" use="required" fixed="1.1" />
        <xsd:attribute name="creator" type="xsd:string" use="required" />
    </xsd:complexType>
    */

    if (!m_reader->readNextStartElement()) {
        m_reader->raiseError("Expected a root element named \"gpx\" (no root element found).");
        return false;
    }

    if (m_reader->name() != "gpx") {
        m_reader->raiseError(QString("The root element is expected to have the name \"gpx\" (root element was named \"%1\").").arg(m_reader->name().toString()));
        return false;
    }

    if (m_reader->attributes().hasAttribute("version")) {
        QString version = m_reader->attributes().value("version").toString();
        if (version != "1.1") {
            m_reader->raiseError(QString("Only version 1.1. of the GPX schema is supported (version found was \"%1\").").arg(version));
            return false;
        }
    } else {
        m_reader->raiseError("The element \"gpx\" did not have the required attribute \"version\".");
        return false;
    }

    if (m_reader->attributes().hasAttribute("creator")) {
        // Not used outside of schema compliance check
    } else {
        m_reader->raiseError("The element \"gpx\" did not have the required attribute \"creator\".");
        return false;
    }

    if (!m_reader->readNextStartElement()) {
        m_reader->skipCurrentElement();
        return true;
    }

    if (m_reader->name() == "metadata") {
        // Not used outside of schema compliance check
        m_reader->skipCurrentElement();
        if (!m_reader->readNextStartElement()) {
            m_reader->skipCurrentElement();
            return true;
        }
    }

    while (m_reader->name() == "wpt") {
        if (m_cancel && (*m_cancel==true)) {
            m_errorCode = QLandmarkManager::CancelError;
            m_errorString = "Import of gpx file was canceled";
            return false;
        }

        QLandmark landmark;

        if (!readWaypoint(landmark, "wpt")) {
            return false;
        }

        m_waypoints.append(landmark);

        if(!m_reader->readNextStartElement()) {
            m_reader->skipCurrentElement();
            return true;
        }
    }

    while (m_reader->name() == "rte") {
        if (m_cancel && (*m_cancel==true)) {
            m_errorCode = QLandmarkManager::CancelError;
            m_errorString = "Import of gpx file was canceled";
            return false;
        }

        QList<QLandmark> route;
        if (!readRoute(route))
            return false;

        m_routes.append(route);

        if(!m_reader->readNextStartElement()) {
            m_reader->skipCurrentElement();
            return true;
        }
    }

    while (m_reader->name() == "trk") {
        if (m_cancel && (*m_cancel==true)) {
            m_errorCode = QLandmarkManager::CancelError;
            m_errorString = "Import of gpx file was canceled";
            return false;
        }

        QList<QLandmark> track;
        if (!readTrack(track))
            return false;

        m_tracks.append(track);

        if(!m_reader->readNextStartElement()) {
            m_reader->skipCurrentElement();
            return true;
        }
    }

    if (m_reader->name() == "extensions") {
        // Not used outside of schema compliance check
        m_reader->skipCurrentElement();
        if (!m_reader->readNextStartElement()) {
            m_reader->skipCurrentElement();
            return true;
        }
    }

    m_reader->raiseError(QString("The element \"gpx\" did not expect a child element named \"%1\" at this point (unknown child element or child element out of order).").arg(m_reader->name().toString()));
    return false;
}
コード例 #11
0
ファイル: midifile.cpp プロジェクト: Angeldude/MuseScore
bool MidiFile::read(QIODevice* in)
     {
      fp = in;
      _tracks.clear();
      curPos    = 0;

      char tmp[4];

      read(tmp, 4);
      int len = readLong();
      if (memcmp(tmp, "MThd", 4) || len < 6)
            throw(QString("bad midifile: MThd expected"));

      _format     = readShort();
      int ntracks = readShort();

      // ================ Read MIDI division =================
      //
      //                        2 bytes
      //  +-------+---+-------------------+-----------------+
      //  |  bit  |15 | 14              8 | 7             0 |
      //  +-------+---+-------------------------------------+
      //  |       | 0 |       ticks per quarter note        |
      //  | value +---+-------------------------------------+
      //  |       | 1 |  -frames/second   |   ticks/frame   |
      //  +-------+---+-------------------+-----------------+

      char firstByte;
      fp->getChar(&firstByte);
      char secondByte;
      fp->getChar(&secondByte);
      const char topBit = (firstByte & 0x80) >> 7;

      if (topBit == 0) {            // ticks per beat
            _isDivisionInTps = false;
            _division = (firstByte << 8) | (secondByte & 0xff);
            }
      else {                        // ticks per second = fps * ticks per frame
            _isDivisionInTps = true;
            const int framesPerSecond = -((signed char) firstByte);
            const int ticksPerFrame = secondByte;
            if (framesPerSecond == 29)
                  _division = qRound(29.97 * ticksPerFrame);
            else
                  _division = framesPerSecond * ticksPerFrame;
            }

      // =====================================================

      if (len > 6)
            skip(len-6); // skip the excess

      switch (_format) {
            case 0:
                  if (readTrack())
                        return false;
                  break;
            case 1:
                  for (int i = 0; i < ntracks; i++) {
                        if (readTrack())
                              return false;
                        }
                  break;
            default:
                  throw(QString("midi file format %1 not implemented").arg(_format));
                  return false;
            }
      return true;
      }
コード例 #12
0
void XSPFParser::load() {
	QTime timeElapsed;
	timeElapsed.start();

	_stop = false;

	QList<MediaInfo> files;

	qDebug() << __FUNCTION__ << "Playlist:" << _filename;

	QFile file(_filename);
	if (file.open(QIODevice::ReadOnly)) {
		MediaInfo mediaInfo;

		QXmlStreamReader xml(&file);
		while (!xml.atEnd() && !_stop) {
			xml.readNext();

			switch (xml.tokenType()) {

			case QXmlStreamReader::StartElement: {
				QString element(xml.name().toString());

				if (element == XSPF_TRACK) {
					readTrack(xml, mediaInfo);

					if (!mediaInfo.fileName().isEmpty()) {
						//Add file to the list of files
						files << mediaInfo;

						//Clear the MediaInfo
						mediaInfo.clear();

						if (files.size() > FILES_FOUND_LIMIT) {
							//Emits the signal every FILES_FOUND_LIMIT files found
							emit filesFound(files);
							files.clear();
						}
					}
				}

				//Otherwise won't read the track end element
				break;
			}

			}
		}

		if (xml.hasError()) {
			qCritical() << __FUNCTION__ << "Error:" << xml.errorString()
				<< "line:" << xml.lineNumber()
				<< "column:" << xml.columnNumber();
		}
	}

	file.close();

	if (!files.isEmpty()) {
		//Emits the signal for the remaining files found (< FILES_FOUND_LIMIT)
		emit filesFound(files);
	}

	//Emits the last signal
	emit finished(timeElapsed.elapsed());
}
コード例 #13
0
uint8_t amvHeader::open(char *name)
{
  uint32_t prevLen, type, size, pts,pos=0;
  
  _isvideopresent=0;
  _isaudiopresent=0;
  memset(&_mainaviheader,0,sizeof(_mainaviheader));
  _filename=ADM_strdup(name);
  _fd=fopen(name,"rb");
  if(!_fd)
  {
    printf("[AMV] Cannot open %s\n",name);
    return 0; 
  }
  // Get size
  uint32_t fileSize=0;
  fseeko(_fd,0,SEEK_END);
  fileSize=ftello(_fd);
  fseeko(_fd,0,SEEK_SET);
  printf("[AMV] file size :%u bytes\n",fileSize);
  // It must begin by F L V 01
  uint32_t four=read32();
  
  if(four!=MKFCC('R','I','F','F'))
  {
    printf("[AMV] Not a riff file\n");
    return 0; 
  }
  uint32_t s=read32(); // size;
  if(s<fileSize) fileSize=s;
  
  if(read32()!=MKFCC('A','M','V',' '))
  {
    // Not an AMV file
     printf("[AMV] Not an AMV file\n");
    return 0; 
  }
  int hdr,list,nbTrack=0;
  while((list=read32())==MKFCC('L','I','S','T'))
  {
    printf("[AMV] List\n");
    read32();
    hdr=read32();
    
    switch(hdr)
    {
      case MKFCC('h','d','r','l'):
          printf("\t[AMV] Header\n");
          if(!readHeader()) return 0;
          printf("\t[AMV] Header Ok\n");
          break;
      case MKFCC('s','t','r','l'):
          printf("\t[AMV] Track\n");
          if(!readTrack(nbTrack)) return 0;
          nbTrack++;
          printf("\t[AMV] Track Ok\n");
          break;
      case MKFCC('m','o','v','i'):
            printf("\t[AMV] Indexing\n");
            if(!index()) return 0;
            printf("\t[AMV] Indexing Ok\n");
            break;
      default:
          printf("[AMV] Last :%s",fourCC::tostring(hdr));
          ADM_assert(0);
    }
  }
  if(videoTrack.index) videoTrack.index[0].flags=AVI_KEY_FRAME;
  else return 0;
  _isvideopresent=1;
  // Build a fake stream/bih bih
#define ENTRY(x,y) _videostream.x=y
  uint32_t codec=MKFCC('A','M','V',' ');
    ENTRY(	fccType,MKFCC('v','i','d','s'));
    ENTRY(	fccHandler,codec);
    ENTRY(	dwInitialFrames,0);
    ENTRY(	dwScale,1000);
    ENTRY(	dwRate,8000);		/* dwRate / dwScale == samples/second */
  // _video_bih
#undef ENTRY
#define ENTRY(x,y) _video_bih.x=y
    
     
    ENTRY(biWidth,_mainaviheader.dwWidth);
    ENTRY(biHeight,_mainaviheader.dwHeight);
    ENTRY(biCompression,codec);
    printf("[AMV] Dimension %u * %u\n",_video_bih.biWidth,_video_bih.biHeight);
    
    // If audio...
    if(audioTrack.index)
    {
      _isaudiopresent=1;
      _audio=new amvAudio(name,&audioTrack,&wavHeader);
    }
  return 1;
}