コード例 #1
0
ファイル: GMTrack.cpp プロジェクト: AenBleidd/gogglesmm
FXbool GMTrack::saveTag(const FXString & filename,FXuint /*opts=0*/) {
  GMFileTag filetags;

  if (!FXStat::isWritable(filename))
    return false;

  if (!filetags.open(filename,FILETAG_TAGS))
    return false;

  filetags.setTitle(title);
  filetags.setArtist(artist);
  filetags.setAlbum(album);
  filetags.setYear(year);
  filetags.setTrackNumber(getTrackNumber());
  filetags.setDiscNumber(getDiscNumber());
  filetags.setComposer(composer);
  filetags.setConductor(conductor);
  filetags.setTags(tags);
  if (album_artist!=artist && !album_artist.empty())
    filetags.setAlbumArtist(album_artist);
  else
    filetags.setAlbumArtist(FXString::null);

  return filetags.save();
  }
コード例 #2
0
void Track::writeData( QByteArray& data) const {
    QBuffer buffer( data);
    buffer.open(IO_WriteOnly);
    QDataStream stream( &buffer);
    stream.setByteOrder( QDataStream::LittleEndian);

    /** Write the track header **/
    stream << (Q_UINT32) 0x7469686D;        // 0x00 mhit
    stream << (Q_UINT32) 0xf4;              // 0x04 headerlen
    stream << (Q_UINT32) 0x0;               // 0x08 length - set later
    stream << (Q_UINT32) 0x0;               // 0x0C number of mhods
    stream << (Q_UINT32) getID();           // 0x10
    stream << (Q_UINT32) 1;                 // 0x14
    //stream << (Q_UINT32) 0;                 // 0x18
    stream << (Q_UINT32) 0x4d503320;        // ipod shiffle wants a "MP3 " here
    stream << vbr;                          // 0x1C
    stream << type;                         // 0x1D
    stream << compilation;                  // 0x1E
    stream << rating;                       // 0x1F
    stream << (Q_UINT32) getLastModified()+ MAC_EPOCH_DELTA; // 0x20
    stream << (Q_UINT32) getFileSize();     // 0x24
    stream << (Q_UINT32) getTrackLength();  // 0x28
    stream << (Q_UINT32) getTrackNumber();  // 0x2C
    stream << (Q_UINT32) getTrackCount();   // 0x30
    stream << (Q_UINT32) getYear();         // 0x34
    stream << (Q_UINT32) getBitrate();      // 0x38
    stream << (Q_UINT32) getSamplerate();   // 0x3C
    stream << (Q_UINT32) getVolumeAdjust(); // 0x40
    stream << (Q_UINT32) 0;                 // 0x44 empty space
    //stream << (Q_UINT32) getTrackLength();  // 0x48 empty space
    stream << (Q_UINT32) 0;  // 0x48 empty space
    stream << (Q_UINT32) 0;                 // 0x4C empty space
    stream << (Q_UINT32) getPlayCount();    // 0x50
    stream << (Q_UINT32) getPlayCount();    // 0x54
    stream << (Q_UINT32) getLastPlayed();   // 0x58
    stream << (Q_UINT32) getCdNumber();     // 0x5C
    stream << (Q_UINT32) getCdCount();      // 0x60
    stream << (Q_UINT32) 0;                 // 0x64 empty space //userid from apple store
    stream << (Q_UINT32) date_added;        // 0x68
    stream << (Q_UINT32) 0;                 // boockmarktime
    stream << (Q_UINT64) dbid;              // unique bit (64 bit)
    stream << (Q_UINT8) 0;                 // checked in iTZnes
    stream << (Q_UINT8) 0;                 // application rating
    stream << (Q_UINT16) 0;                 // BPM
    stream << (Q_UINT16) 0;                 // artworkcount
    stream << (Q_UINT16) 0xffff;            // unkown
    stream << (Q_UINT32) 0;                 // artwork size
    stream << (Q_UINT32) 0;                 // unkown
    stream << (float) -getSamplerate();      // samplerate as floating point "-"?!?
    stream << (Q_UINT32) 0;                 // date/time added
    stream << (Q_UINT32) file_format_code;  // unkown, but 0x0000000c for MP3 ?
    stream << (Q_UINT32) 0;                 // unkown
    stream << (Q_UINT32) 0;                 // unkown
    stream << (Q_UINT32) 0;                 // unkown
    stream << (Q_UINT32) 0;                 // unkown
    stream << (Q_UINT32) 0x02;              // unknown
    stream << (Q_UINT64) dbid; // same unique id as above
    for( int i= 0; i< 17; i++)
        stream << (Q_UINT32) 0;
    
    /** Write Track contents **/
    Q_UINT32 num_mhods = 0;
    for( PropertyMap::const_iterator element= properties.begin(); element!= properties.end(); ++element) {
        if( (*element).isEmpty())
            continue;

        const char *data= (const char *)(*element).ucs2();
        if( data == NULL)
            continue;

        int datalen= 2* (*element).length();

        stream << (Q_UINT32) 0x646F686D;    // mhod
        stream << (Q_UINT32) 0x18;    // headerlen
        stream << (Q_UINT32) 40+ datalen;
        stream << (Q_UINT32) element.key();
        stream << (Q_UINT32) 0;
        stream << (Q_UINT32) 0;
        stream << (Q_UINT32) 1;    // dummy - would refer to the trackID if used in playlist
        stream << (Q_UINT32) datalen;
        stream << (Q_UINT32) 0;
        stream << (Q_UINT32) 0;
        stream.writeRawBytes( data, datalen);
        num_mhods++;
    }
    buffer.at( 8);
    stream << (Q_UINT32)data.size();	// set content length
    stream << (Q_UINT32)num_mhods;	// set real mhod count
    buffer.close();
}
コード例 #3
0
ファイル: browsethread.cpp プロジェクト: Drakeo/mixxx
void BrowseThread::populateModel() {
    m_path_mutex.lock();
    MDir thisPath = m_path;
    BrowseTableModel* thisModelObserver = m_model_observer;
    m_path_mutex.unlock();

    // Refresh the name filters in case we loaded new SoundSource plugins.
    QStringList nameFilters(SoundSourceProxy::getSupportedFileNamePatterns());

    QDirIterator fileIt(thisPath.dir().absolutePath(), nameFilters,
                        QDir::Files | QDir::NoDotAndDotDot);

    // remove all rows
    // This is a blocking operation
    // see signal/slot connection in BrowseTableModel
    emit(clearModel(thisModelObserver));

    QList< QList<QStandardItem*> > rows;

    int row = 0;
    // Iterate over the files
    while (fileIt.hasNext()) {
        // If a user quickly jumps through the folders
        // the current task becomes "dirty"
        m_path_mutex.lock();
        MDir newPath = m_path;
        m_path_mutex.unlock();

        if (thisPath.dir() != newPath.dir()) {
            qDebug() << "Abort populateModel()";
            return populateModel();
        }

        QString filepath = fileIt.next();
        auto pTrack = Track::newTemporary(filepath, thisPath.token());
        SoundSourceProxy(pTrack).updateTrackFromSource();

        QList<QStandardItem*> row_data;

        QStandardItem* item = new QStandardItem("0");
        item->setData("0", Qt::UserRole);
        row_data.insert(COLUMN_PREVIEW, item);

        item = new QStandardItem(pTrack->getFileName());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_FILENAME, item);

        item = new QStandardItem(pTrack->getArtist());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_ARTIST, item);

        item = new QStandardItem(pTrack->getTitle());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_TITLE, item);

        item = new QStandardItem(pTrack->getAlbum());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_ALBUM, item);

        item = new QStandardItem(pTrack->getAlbumArtist());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_ALBUMARTIST, item);

        item = new QStandardItem(pTrack->getTrackNumber());
        item->setToolTip(item->text());
        item->setData(item->text().toInt(), Qt::UserRole);
        row_data.insert(COLUMN_TRACK_NUMBER, item);

        const QString year(pTrack->getYear());
        item = new YearItem(year);
        item->setToolTip(year);
        // The year column is sorted according to the numeric calendar year
        item->setData(mixxx::TrackMetadata::parseCalendarYear(year), Qt::UserRole);
        row_data.insert(COLUMN_YEAR, item);

        item = new QStandardItem(pTrack->getGenre());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_GENRE, item);

        item = new QStandardItem(pTrack->getComposer());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_COMPOSER, item);

        item = new QStandardItem(pTrack->getGrouping());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_GROUPING, item);

        item = new QStandardItem(pTrack->getComment());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_COMMENT, item);

        QString duration = pTrack->getDurationText(mixxx::Duration::Precision::SECONDS);
        item = new QStandardItem(duration);
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_DURATION, item);

        item = new QStandardItem(pTrack->getBpmText());
        item->setToolTip(item->text());
        item->setData(pTrack->getBpm(), Qt::UserRole);
        row_data.insert(COLUMN_BPM, item);

        item = new QStandardItem(pTrack->getKeyText());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_KEY, item);

        item = new QStandardItem(pTrack->getType());
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_TYPE, item);

        item = new QStandardItem(pTrack->getBitrateText());
        item->setToolTip(item->text());
        item->setData(pTrack->getBitrate(), Qt::UserRole);
        row_data.insert(COLUMN_BITRATE, item);

        QString location = pTrack->getLocation();
        QString nativeLocation = QDir::toNativeSeparators(location);
        item = new QStandardItem(nativeLocation);
        item->setToolTip(nativeLocation);
        item->setData(location, Qt::UserRole);
        row_data.insert(COLUMN_NATIVELOCATION, item);

        QDateTime modifiedTime = pTrack->getFileModifiedTime().toLocalTime();
        item = new QStandardItem(modifiedTime.toString(Qt::DefaultLocaleShortDate));
        item->setToolTip(item->text());
        item->setData(modifiedTime, Qt::UserRole);
        row_data.insert(COLUMN_FILE_MODIFIED_TIME, item);

        QDateTime creationTime = pTrack->getFileCreationTime().toLocalTime();
        item = new QStandardItem(creationTime.toString(Qt::DefaultLocaleShortDate));
        item->setToolTip(item->text());
        item->setData(creationTime, Qt::UserRole);
        row_data.insert(COLUMN_FILE_CREATION_TIME, item);

        const mixxx::ReplayGain replayGain(pTrack->getReplayGain());
        item = new QStandardItem(
                mixxx::ReplayGain::ratioToString(replayGain.getRatio()));
        item->setToolTip(item->text());
        item->setData(item->text(), Qt::UserRole);
        row_data.insert(COLUMN_REPLAYGAIN, item);

        rows.append(row_data);
        ++row;
        // If 10 tracks have been analyzed, send it to GUI
        // Will limit GUI freezing
        if (row % 10 == 0) {
            // this is a blocking operation
            emit(rowsAppended(rows, thisModelObserver));
            qDebug() << "Append " << rows.count() << " from " << filepath;
            rows.clear();
        }
        // Sleep additionally for 10ms which prevents us from GUI freezes
        msleep(20);
    }
    emit(rowsAppended(rows, thisModelObserver));
    qDebug() << "Append last " << rows.count();
}
コード例 #4
0
void createMidiFile(MidiFile& midifile, HumdrumFile& infile) {

   Array<int>    millitimes;
   Array<double> velocities;
   Array<int>    keynum;
   Array<int>    track;

   millitimes.setSize(infile.getNumLines());
   velocities.setSize(infile.getNumLines());
   keynum.setSize(infile.getNumLines());
   track.setSize(infile.getNumLines());

   millitimes.setSize(0);
   velocities.setSize(0);
   keynum.setSize(0);
   track.setSize(0);

   int    intval;
   double floatval;
   double dmax = -100000;
   double dmin = +100000;

   int i;
   for (i=0; i<infile.getNumLines(); i++) {
      if (!infile[i].isData()) {
         continue;
      }
      sscanf(infile[i][0], "%lf", &floatval);
      intval = int(floatval * 1000.0 + 0.5);
      millitimes.append(intval);

      sscanf(infile[i][1], "%lf", &floatval);
      velocities.append(floatval);
      if (floatval < dmin) { dmin = floatval; }
      if (floatval > dmax) { dmax = floatval; }

      intval = getMIDIKeyNum(infile[i][2]);
      keynum.append(intval);

      intval = getTrackNumber(infile[i][2]);
      track.append(intval);
   }
   millitimes.allowGrowth(0);
   velocities.allowGrowth(0);
   keynum.allowGrowth(0);
   track.allowGrowth(0);

   // normalize the dynamics data into the range from 0 to 1
   double diff = dmax - dmin;
   for (i=0; i<velocities.getSize(); i++) {
      if (diff > 0.0) {
         velocities[i] = (velocities[i] - dmin) / diff;
      } else {
         velocities[i] = 0.5;
      }
   }


   // now ready to write the data to the MIDI file:

   midifile.setMillisecondDelta();   // SMPTE 25 frames & 40 subframes
   midifile.absoluteTime();          // Time values inserted are absolute
   midifile.addTrack(2);             // Right and Left hands

   Array<uchar> event;
   event.setSize(3);

   int intdur  = int(duration * 1000.0 + 0.5);
   int lasttime = 0;
   int dyndiff = maxdyn - mindyn;
   int vel;
   for (i=0; i<millitimes.getSize(); i++) {
      if ((keynum[i] <= 10) || (keynum[i] > 127)) {
         continue;
      }
      vel = int(velocities[i] * dyndiff + mindyn + 0.5);
      if (vel < 1) { vel = 1; }
      if (vel > 127) { vel = 127; }

      event[0] = 0x90; // note-on
      event[1] = keynum[i];
      event[2] = vel;
      midifile.addEvent(track[i], millitimes[i], event);
      event[2] = 0;
      lasttime = millitimes[i] + intdur;
      midifile.addEvent(track[i], lasttime, event);
   }

   // write the end of track marker
   event[0] = 0xff;
   event[1] = 0x2f;
   event[2] = 0;
   for (i=0; i<midifile.getTrackCount(); i++) {
	
      if (i>0) {
         // have to lengthen the last note in track due to bugs
         // in various MIDI playback programs which clip
         // the last chord of a file
         midifile.getEvent(i, midifile.getNumEvents(i)-1).time += 1500;
      }
      midifile.addEvent(i, lasttime+2000, event);
   }

   // add comments from header
   for (i=0; i<infile.getNumLines() && i<lasttime; i++) {
      if (infile[i].isBibliographic() || infile[i].isGlobalComment()) {
         // 0x01 is a text event
         midifile.addMetaEvent(0, i, 0x01, infile[i].getLine());
      }
   }

   // sort the ontimes and offtimes so they are in correct time order:
   midifile.sortTracks();

}