示例#1
0
K3b::AudioRippingDialog::AudioRippingDialog( const K3b::Medium& medium,
                                              const KCDDB::CDInfo& entry,
                                              const QList<int>& tracks,
                                              QWidget *parent )
    : K3b::InteractionDialog( parent,
                            QString(),
                            QString(),
                            START_BUTTON|CANCEL_BUTTON,
                            START_BUTTON,
                            "Audio Ripping" ), // config group
      m_medium( medium ),
      m_cddbEntry( entry ),
      m_trackNumbers( tracks )
{
    d = new Private();

    setupGui();
    setupContextHelp();

    K3b::Msf length;
    K3b::Device::Toc toc = medium.toc();
    for( QList<int>::const_iterator it = m_trackNumbers.constBegin();
         it != m_trackNumbers.constEnd(); ++it ) {
        length += toc[*it].length();
    }
    setTitle( i18n("CD Ripping"),
              i18np("1 track (%2)", "%1 tracks (%2)",
                    m_trackNumbers.count(),length.toString()) );
}
示例#2
0
void K3b::AudioRippingDialog::refresh()
{
    d->viewTracks->clear();
    d->filenames.clear();

    QString baseDir = K3b::prepareDir( m_optionWidget->baseDir() );
    d->fsInfo.setPath( baseDir );

    KIO::filesize_t overallSize = 0;

    K3b::Device::Toc toc = m_medium.toc();

    if( m_optionWidget->createSingleFile() ) {
        long length = 0;
        for( QList<int>::const_iterator it = m_trackNumbers.constBegin();
             it != m_trackNumbers.constEnd(); ++it ) {
            length += ( m_checkUseIndex0->isChecked()
                        ? toc[*it].realAudioLength().lba()
                        : toc[*it].length().lba() );
        }

        QString filename;
        QString extension;
        long long fileSize = 0;
        if( m_optionWidget->encoder() == 0 ) {
            extension = "wav";
            fileSize = length * 2352 + 44;
        }
        else {
            extension = m_optionWidget->extension();
            fileSize = m_optionWidget->encoder()->fileSize( extension, length );
        }

        if( fileSize > 0 )
            overallSize = fileSize;

        filename = d->fsInfo.fixupPath( K3b::PatternParser::parsePattern( m_cddbEntry, 1,
                                                                          extension,
                                                                          m_patternWidget->playlistPattern(),
                                                                          m_patternWidget->replaceBlanks(),
                                                                          m_patternWidget->blankReplaceString() ) );

        d->addTrack( filename,
                     K3b::Msf(length).toString(),
                     fileSize < 0 ? i18n("unknown") : KIO::convertSize( fileSize ),
                     i18n("Audio") );

        d->filenames.append( baseDir + filename );

        if( m_optionWidget->createCueFile() ) {
            QString cueFileName = d->fsInfo.fixupPath( K3b::PatternParser::parsePattern( m_cddbEntry, 1,
                                                                                         QLatin1String( "cue" ),
                                                                                         m_patternWidget->playlistPattern(),
                                                                                         m_patternWidget->replaceBlanks(),
                                                                                         m_patternWidget->blankReplaceString() ) );
            d->addTrack( cueFileName, "-", "-", i18n("Cue-file") );
        }
    }
    else {
        for( int i = 0; i < m_trackNumbers.count(); ++i ) {
            int trackIndex = m_trackNumbers[i];

            QString extension;
            long long fileSize = 0;
            K3b::Msf trackLength = ( m_checkUseIndex0->isChecked()
                                     ? toc[trackIndex].realAudioLength()
                                     : toc[trackIndex].length() );
            if( m_optionWidget->encoder() == 0 ) {
                extension = "wav";
                fileSize = trackLength.audioBytes() + 44;
            }
            else {
                extension = m_optionWidget->extension();
                fileSize = m_optionWidget->encoder()->fileSize( extension, trackLength );
            }

            if( fileSize > 0 )
                overallSize += fileSize;

            if( toc[trackIndex].type() == K3b::Device::Track::TYPE_DATA ) {
                extension = ".iso";
                continue;  // TODO: find out how to rip the iso data
            }


            QString filename;

            filename = K3b::PatternParser::parsePattern( m_cddbEntry, trackIndex+1,
                                                         extension,
                                                         m_patternWidget->filenamePattern(),
                                                         m_patternWidget->replaceBlanks(),
                                                         m_patternWidget->blankReplaceString() );
            if ( filename.isEmpty() ){
                filename = i18n("Track%1", QString::number( trackIndex+1 ).rightJustified( 2, '0' ) ) + '.' + extension;
            }
            filename = d->fsInfo.fixupPath( filename );

            d->addTrack( filename,
                         trackLength.toString(),
                         fileSize < 0 ? i18n("unknown") : KIO::convertSize( fileSize ),
                         toc[trackIndex].type() == K3b::Device::Track::TYPE_AUDIO ? i18n("Audio") : i18n("Data") );

            d->filenames.append( baseDir + filename );
        }
    }

    // create playlist item
    if( m_optionWidget->createPlaylist() ) {
        QString filename = K3b::PatternParser::parsePattern( m_cddbEntry, 1,
                                                             QLatin1String( "m3u" ),
                                                             m_patternWidget->playlistPattern(),
                                                             m_patternWidget->replaceBlanks(),
                                                             m_patternWidget->blankReplaceString() );

        d->addTrack( filename, "-", "-", i18n("Playlist") );

        d->playlistFilename = d->fsInfo.fixupPath( baseDir + '/' + filename );
    }

    if( overallSize > 0 )
        m_optionWidget->setNeededSize( overallSize );
    else
        m_optionWidget->setNeededSize( 0 );
}
示例#3
0
bool K3b::TocFileWriter::save( QTextStream& t )
{
    writeHeader(t);

    if( !m_cdText.isEmpty() )
        writeGlobalCdText(t);

    //
    // see if we have multiple sessions
    //
    int sessions = 1;
    for( K3b::Device::Toc::iterator it = m_toc.begin(); it != m_toc.end(); ++it ) {
        if( (*it).session() > 1 )
            sessions = (*it).session();
    }

    if( m_sessionToWrite > sessions )
        m_sessionToWrite = 1;

    //
    // We can only hide the first track if both the first and the second track are
    // audio tracks.
    // We also can only hide the first track in the first session.
    //
    bool hideFirstTrack = m_hideFirstTrack;
    if( m_toc.count() < 2 ||
            m_toc[0].type() != K3b::Device::Track::TYPE_AUDIO ||
            m_toc[1].type() != K3b::Device::Track::TYPE_AUDIO ||
            (sessions > 1 && m_sessionToWrite != 1 ) )
        hideFirstTrack = false;


    // the dataStart will be the offset in case we do not write the first session
    K3b::Msf dataStart;

    int trackIndex = 0;
    if( hideFirstTrack ) {
        const K3b::Device::Track& hiddenTrack = m_toc[0];
        const K3b::Device::Track& track = m_toc[1];

        t << "// Track number 1 (hidden) and track number 2 (as track 1)" << endl;
        t << "TRACK AUDIO" << endl;

        if( track.copyPermitted() )
            t << "COPY" << endl;
        else
            t << "NO COPY" << endl;

        if( track.preEmphasis() )
            t << "PRE_EMPHASIS" << endl;
        else
            t << "NO PRE_EMPHASIS" << endl;

        if( !m_cdText.isEmpty() )
            writeTrackCdText( m_cdText[0], t );

        // the "hidden" file will be used as pregap for the "first" track
        t << "AUDIOFILE ";
        writeDataSource( 0, t );
        if( readFromStdin() )
            t << hiddenTrack.firstSector().toString();
        else
            t << " 0";
        t << " " << hiddenTrack.length().toString() << endl;
        t << "START" << endl; // use the whole hidden file as pregap

        // now comes the "real" first track
        t << "AUDIOFILE ";
        writeDataSource( 1, t );
        if( readFromStdin() )
            t << track.firstSector().toString() << " ";
        else
            t << "0 ";
        // no index 0 for the last track. Or should we allow this???
        if( m_toc.count() == 2 )
            t << track.length().toString();
        else
            t << track.realAudioLength().toString();
        t << endl << endl;

        trackIndex+=2;
    }
    else {
        //
        // Seek to the first track to write.
        // In case we hid the first track above it was the first track anyway.
        //
        while( m_toc[trackIndex].session() < m_sessionToWrite &&
                m_toc[trackIndex].session() > 0 )
            ++trackIndex;

        dataStart = m_toc[trackIndex].firstSector();
    }

    kDebug() << "(K3b::TocFileWriter) using offset of: " << dataStart.toString();

    while( trackIndex < m_toc.count() ) {
        if( m_toc[trackIndex].session() == 0 || m_toc[trackIndex].session() == m_sessionToWrite )
            writeTrack( trackIndex, dataStart, t );
        trackIndex++;
    }

    return ( t.status() == QTextStream::Ok );
}