Beispiel #1
0
void
AudioEngine::loadPreviousTrack()
{
    Q_D( AudioEngine );

    tDebug( LOGEXTRA ) << Q_FUNC_INFO;

    if ( d->playlist.isNull() )
    {
        stop();
        return;
    }

    Tomahawk::result_ptr result;
    if ( d->playlist.data()->previousResult() )
    {
        result = d->playlist.data()->setSiblingResult( -1 );
        setCurrentTrackPlaylist( d->playlist );
    }

    if ( !result.isNull() )
        loadTrack( result );
    else
        stop();
}
Beispiel #2
0
void
AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result )
{
    if ( !m_currentTrack.isNull() )
    {
        disconnect( m_currentTrack->album().data(), SIGNAL( updated() ), this, SLOT( onAlbumCoverUpdated() ) );
        disconnect( m_currentTrack->toQuery().data(), SIGNAL( socialActionsLoaded() ), this, SLOT( onSocialActionsLoaded() ) );
    }

    m_currentTrack = result;
    connect( m_currentTrack->album().data(), SIGNAL( updated() ), SLOT( onAlbumCoverUpdated() ) );
    connect( m_currentTrack->toQuery().data(), SIGNAL( socialActionsLoaded() ), SLOT( onSocialActionsLoaded() ) );

    ui->artistTrackLabel->setResult( result );
    ui->albumLabel->setResult( result );
    ui->ownerLabel->setText( result->friendlySource() );

    const QString duration = TomahawkUtils::timeToString( result.data()->duration() );
    ui->timeLabel->setFixedWidth( ui->timeLabel->fontMetrics().width( QString( duration.length(), QChar( '0' ) ) ) );
    ui->timeLabel->setText( TomahawkUtils::timeToString( 0 ) );
    ui->timeLeftLabel->setFixedWidth( ui->timeLeftLabel->fontMetrics().width( QString( duration.length() + 1, QChar( '0' ) ) ) );
    ui->timeLeftLabel->setText( "-" + duration );

    ui->stackedLayout->setCurrentWidget( ui->pauseButton );

    ui->loveButton->setEnabled( true );
    ui->loveButton->setVisible( true );

    setAlbumCover();
    setSocialActions();
}
Beispiel #3
0
void
AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
{
    Q_D( AudioEngine );
    tDebug( LOGEXTRA ) << Q_FUNC_INFO << ( result.isNull() ? QString() : result->url() );

    if ( !result )
    {
        stop();
        return;
    }

    // We do this to stop the audio as soon as a user activated another track
    // If we don't block the audioOutput signals, the state change will trigger
    // loading yet another track
    d->audioOutput->blockSignals( true );
    d->audioOutput->stop();
    d->audioOutput->blockSignals( false );

    setCurrentTrack( result );

    if ( !TomahawkUtils::isLocalResult( d->currentTrack->url() ) && !TomahawkUtils::isHttpResult( d->currentTrack->url() )
         && !TomahawkUtils::isRtmpResult( d->currentTrack->url() ) )
    {
        performLoadIODevice( d->currentTrack, d->currentTrack->url() );
    }
    else
    {
        QSharedPointer< QIODevice > io;
        performLoadTrack( result, result->url(), io );
    }
}
Beispiel #4
0
void
Scrobbler::trackStarted( const Tomahawk::result_ptr& track )
{
    Q_ASSERT( QThread::currentThread() == thread() );
//    qDebug() << Q_FUNC_INFO;

    if( m_reachedScrobblePoint )
    {
        m_reachedScrobblePoint = false;
        scrobble();
    }

    Tomahawk::InfoSystem::InfoCriteriaHash trackInfo;

    trackInfo["title"] = track->track();
    trackInfo["artist"] = track->artist()->name();
    trackInfo["album"] = track->album()->name();
    trackInfo["duration"] = QString::number( track->duration() );

    Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo(
        s_scInfoIdentifier, Tomahawk::InfoSystem::InfoSubmitNowPlaying,
        QVariant::fromValue< Tomahawk::InfoSystem::InfoCriteriaHash >( trackInfo ) );

    m_scrobblePoint = ScrobblePoint( track->duration() / 2 );
}
Beispiel #5
0
void
AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
{
    Q_D( AudioEngine );
    tDebug( LOGEXTRA ) << Q_FUNC_INFO << ( result.isNull() ? QString() : result->url() );

    if ( result.isNull() )
    {
        stop();
        return;
    }

    setCurrentTrack( result );

    if ( !TomahawkUtils::isLocalResult( d->currentTrack->url() ) && !TomahawkUtils::isHttpResult( d->currentTrack->url() )
         && !TomahawkUtils::isRtmpResult( d->currentTrack->url() ) )
    {
        boost::function< void ( QSharedPointer< QIODevice >& ) > callback =
                boost::bind( &AudioEngine::performLoadTrack, this, result, _1 );
        Servent::instance()->getIODeviceForUrl( d->currentTrack, callback );
    }
    else
    {
        QSharedPointer< QIODevice > io;
        performLoadTrack( result, io );
    }
}
void
DatabaseCommand_Resolve::exec( DatabaseImpl* lib )
{
    /*
     *        Resolving is a 2 stage process.
     *        1) find list of trk/art/alb IDs that are reasonable matches to the metadata given
     *        2) find files in database by permitted sources and calculate score, ignoring
     *           results that are less than MINSCORE
     */

    if ( !m_query->resultHint().isEmpty() )
    {
        qDebug() << "Using result-hint to speed up resolving:" << m_query->resultHint();

        Tomahawk::result_ptr result = lib->resultFromHint( m_query );
        if ( !result.isNull() && ( result->collection().isNull() || result->collection()->source()->isOnline() ) )
        {
            QList<Tomahawk::result_ptr> res;
            res << result;
            emit results( m_query->id(), res );
            return;
        }
    }

    if ( m_query->isFullTextQuery() )
        fullTextResolve( lib );
    else
        resolve( lib );
}
Beispiel #7
0
void
PlaylistInterface::onItemsChanged()
{
    if ( QThread::currentThread() != thread() )
    {
        QMetaObject::invokeMethod( this, "onItemsChanged", Qt::QueuedConnection );
        return;
    }

    Tomahawk::result_ptr prevResult = siblingResult( -1, m_currentIndex );
    Tomahawk::result_ptr nextResult = siblingResult( 1, m_currentIndex );

    {
        bool avail = prevResult && prevResult->toQuery()->playable();
        if ( avail != m_prevAvail )
        {
            m_prevAvail = avail;
            emit previousTrackAvailable( avail );
        }
    }

    {
        bool avail = nextResult && nextResult->toQuery()->playable();
        if ( avail != m_nextAvail )
        {
            m_nextAvail = avail;
            emit nextTrackAvailable( avail );
        }
    }
}
Beispiel #8
0
void
AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
{
    Q_D( AudioEngine );
    tDebug( LOGEXTRA ) << Q_FUNC_INFO << ( result.isNull() ? QString() : result->url() );

    if ( !result )
    {
        stop();
        return;
    }

    // We do this to stop the audio as soon as a user activated another track
    // If we don't block the audioOutput signals, the state change will trigger
    // loading yet another track
    d->audioOutput->blockSignals( true );
    d->audioOutput->stop();
    d->audioOutput->blockSignals( false );

    setCurrentTrack( result );

    ScriptJob* job = result->resolvedBy()->getStreamUrl( result );
    connect( job, SIGNAL( done( QVariantMap ) ), SLOT( gotStreamUrl( QVariantMap ) ) );
    job->setProperty( "result", QVariant::fromValue( result ) );
    job->start();
}
Beispiel #9
0
void
AudioControls::onPlaybackStarted( const Tomahawk::result_ptr& result )
{
    if ( result.isNull() )
        return;

    if ( m_currentTrack.isNull() || ( !m_currentTrack.isNull() && m_currentTrack.data()->id() != result.data()->id() ) )
        onPlaybackLoading( result );

    qint64 duration = AudioEngine::instance()->currentTrackTotalTime();

    if ( duration == -1 )
        duration = result.data()->duration() * 1000;

    ui->seekSlider->setRange( 0, duration );
    ui->seekSlider->setValue( 0 );

    m_phononTickCheckTimer.stop();

    m_sliderTimeLine.stop();
    m_sliderTimeLine.setDuration( duration );
    m_sliderTimeLine.setFrameRange( 0, duration );
    m_sliderTimeLine.setCurrentTime( 0 );
    m_seekMsecs = -1;

    ui->seekSlider->setVisible( true );

    m_noTimeChange = false;
    m_lastSliderCheck = 0;
}
Beispiel #10
0
void
QueryLabel::setResult( const Tomahawk::result_ptr& result )
{
    if ( result.isNull() )
        return;

    if ( !m_text.isEmpty() && contentsMargins().left() != 0 ) // FIXME: hacky
        m_textMargins = contentsMargins();

    setContentsMargins( BOXMARGIN * 2, BOXMARGIN / 2, BOXMARGIN * 2, BOXMARGIN / 2);

    if ( m_result.isNull() || m_result.data() != result.data() )
    {
        m_result = result;

        m_query = m_result->toQuery();
        QList<Tomahawk::result_ptr> rl;
        rl << m_result;
        m_query->addResults( rl );

        updateLabel();

        emit textChanged( text() );
        emit resultChanged( m_result );
    }
}
Beispiel #11
0
void
AudioEngine::loadNextTrack()
{
    tDebug( LOGEXTRA ) << Q_FUNC_INFO;

    Tomahawk::result_ptr result;

    if ( m_queue && m_queue->trackCount() )
    {
        result = m_queue->nextItem();
    }

    if ( !m_playlist.isNull() && result.isNull() )
    {
        result = m_playlist.data()->nextItem();
    }

    if ( !result.isNull() )
        loadTrack( result );
    else
    {
        if ( !m_playlist.isNull() && m_playlist.data()->retryMode() == Tomahawk::PlaylistInterface::Retry )
            m_waitingOnNewTrack = true;
        stop();
    }
}
Beispiel #12
0
void
AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
{
    Q_D( AudioEngine );
    tDebug( LOGEXTRA ) << Q_FUNC_INFO << ( result.isNull() ? QString() : result->url() );

    if ( result.isNull() )
    {
        stop();
        return;
    }

    setCurrentTrack( result );

    if ( !TomahawkUtils::isLocalResult( d->currentTrack->url() ) && !TomahawkUtils::isHttpResult( d->currentTrack->url() )
         && !TomahawkUtils::isRtmpResult( d->currentTrack->url() ) )
    {
        performLoadIODevice( d->currentTrack, d->currentTrack->url() );
    }
    else
    {
        QSharedPointer< QIODevice > io;
        performLoadTrack( result, result->url(), io );
    }
}
Beispiel #13
0
void
AudioEngine::playItem( Tomahawk::playlistinterface_ptr playlist, const Tomahawk::result_ptr& result, const Tomahawk::query_ptr& fromQuery )
{
    tDebug( LOGEXTRA ) << Q_FUNC_INFO << ( result.isNull() ? QString() : result->url() );

    if ( !m_playlist.isNull() )
        m_playlist.data()->reset();

    setPlaylist( playlist );

    if ( playlist.isNull() && !fromQuery.isNull() )
        m_currentTrackPlaylist = playlistinterface_ptr( new SingleTrackPlaylistInterface( fromQuery ) );
    else
        m_currentTrackPlaylist = playlist;

    if ( !result.isNull() )
    {
        loadTrack( result );
    }
    else if ( !m_playlist.isNull() && m_playlist.data()->retryMode() == PlaylistModes::Retry )
    {
        m_waitingOnNewTrack = true;
        if ( isStopped() )
            emit sendWaitingNotification();
        else
            stop();
    }
}
Beispiel #14
0
void
AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result )
{
    qDebug() << Q_FUNC_INFO;

    m_currentTrack = result;

    ui->artistTrackLabel->setResult( result );
    ui->albumLabel->setResult( result );
    ui->ownerLabel->setText( result->friendlySource() );
    ui->coverImage->setPixmap( m_defaultCover );

    if ( ui->timeLabel->text().isEmpty() )
        ui->timeLabel->setText( TomahawkUtils::timeToString( 0 ) );

    if ( ui->timeLeftLabel->text().isEmpty() )
        ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( result->duration() ) );

    ui->seekSlider->setRange( 0, m_currentTrack->duration() );
    ui->seekSlider->setVisible( true );

/*    m_playAction->setEnabled( false );
    m_pauseAction->setEnabled( true ); */

    ui->pauseButton->setEnabled( true );
    ui->pauseButton->setVisible( true );
    ui->playPauseButton->setVisible( false );
    ui->playPauseButton->setEnabled( false );
}
Beispiel #15
0
void
AudioControls::onPlaybackStarted( const Tomahawk::result_ptr result )
{
    if ( result.isNull() )
        return;

    if ( m_currentTrack.isNull() || ( !m_currentTrack.isNull() && m_currentTrack.data()->id() != result.data()->id() ) )
        onPlaybackLoading( result );

    qint64 duration = AudioEngine::instance()->currentTrackTotalTime();

    if ( duration <= 0 )
        duration = result.data()->track()->duration() * 1000;

    ui->seekSlider->setRange( 0, duration );
    ui->seekSlider->setValue( 0 );
    ui->seekSlider->setEnabled( AudioEngine::instance()->canSeek() );

    ui->timeLabel->setText( TomahawkUtils::timeToString( 0 ) );
    ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( 0 ) );

    tLog() << Q_FUNC_INFO << duration;
    m_sliderTimeLine.setDuration( duration );
    m_sliderTimeLine.setFrameRange( 0, duration );
    m_sliderTimeLine.setCurveShape( QTimeLine::LinearCurve );
    m_sliderTimeLine.setCurrentTime( 0 );
    m_seeked = false;

    int updateRate = (double)1000 / ( (double)ui->seekSlider->contentsRect().width() / (double)( duration / 1000 ) );
    m_sliderTimeLine.setUpdateInterval( qBound( 40, updateRate, 500 ) );

    m_lastSliderCheck = 0;
    m_phononTickCheckTimer.start( 500 );
}
bool
PlayableProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
{
    PlayableItem* pi = itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) );
    if ( !pi )
        return false;

    if ( m_maxVisibleItems >= 0 && sourceRow > m_maxVisibleItems - 1 )
        return false;

    if ( m_hideDupeItems )
    {
        for ( int i = 0; i < sourceRow; i++ )
        {
            PlayableItem* di = itemFromIndex( sourceModel()->index( i, 0, sourceParent ) );
            if ( !di )
                continue;

            bool b = ( pi->query() && pi->query()->equals( di->query() ) ) ||
                     ( pi->album() && pi->album() == di->album() ) ||
                     ( pi->artist() && pi->artist()->name() == di->artist()->name() );

            if ( b && filterAcceptsRow( i, sourceParent ) )
                return false;
        }
    }

    if ( pi->query() )
    {
        const Tomahawk::query_ptr& q = pi->query()->displayQuery();
        if ( q.isNull() ) // uh oh? filter out invalid queries i guess
            return false;

        Tomahawk::result_ptr r;
        if ( q->numResults() )
            r = q->results().first();

        if ( !m_showOfflineResults && ( r.isNull() || !r->isOnline() ) )
            return false;

        if ( filterRegExp().isEmpty() )
            return true;

        QStringList sl = filterRegExp().pattern().split( " ", QString::SkipEmptyParts );
        foreach( QString s, sl )
        {
            s = s.toLower();
            if ( !q->artist().toLower().contains( s ) &&
                    !q->album().toLower().contains( s ) &&
                    !q->track().toLower().contains( s ) )
            {
                return false;
            }
        }
    }
Beispiel #17
0
void
AudioEngine::loadNextTrack()
{
    Q_D( AudioEngine );

    tDebug( LOGEXTRA ) << Q_FUNC_INFO;

    Tomahawk::result_ptr result;

    if ( d->stopAfterTrack && d->currentTrack )
    {
        if ( d->stopAfterTrack->track()->equals( d->currentTrack->track() ) )
        {
            d->stopAfterTrack.clear();
            stop();
            return;
        }
    }

    if ( d->queue && d->queue->trackCount() )
    {
        query_ptr query = d->queue->tracks().first();
        if ( query && query->numResults() )
            result = query->results().first();
    }

    if ( !d->playlist.isNull() && result.isNull() )
    {
        tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Loading playlist's next item" << d->playlist.data() << d->playlist->shuffled();

        if ( d->playlist.data()->nextResult() )
        {
            result = d->playlist.data()->setSiblingResult( 1 );
            setCurrentTrackPlaylist( d->playlist );
        }
    }

    if ( !result.isNull() )
    {
        tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Got next item, loading track";
        loadTrack( result );
    }
    else
    {
        if ( !d->playlist.isNull() && d->playlist.data()->retryMode() == Tomahawk::PlaylistModes::Retry )
            d->waitingOnNewTrack = true;

        stop();
    }
}
Beispiel #18
0
void
AudioEngine::loadNextTrack()
{
    tDebug( LOGEXTRA ) << Q_FUNC_INFO;

    Tomahawk::result_ptr result;

    if ( !m_stopAfterTrack.isNull() && !m_currentTrack.isNull() )
    {
        if ( m_stopAfterTrack->equals( m_currentTrack->toQuery() ) )
        {
            m_stopAfterTrack.clear();
            stop();
            return;
        }
    }

    if ( m_queue && m_queue->trackCount() )
    {
        query_ptr query = m_queue->tracks().first();
        if ( query && query->numResults() )
            result = query->results().first();
    }

    if ( !m_playlist.isNull() && result.isNull() )
    {
        tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Loading playlist's next item" << m_playlist.data() << m_playlist->shuffled();

        if ( m_playlist.data()->nextResult() )
        {
            result = m_playlist.data()->nextResult();
            m_currentTrackPlaylist = m_playlist;
        }
    }

    if ( !result.isNull() )
    {
        tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "Got next item, loading track";
        loadTrack( result );
    }
    else
    {
        if ( !m_playlist.isNull() && m_playlist.data()->retryMode() == Tomahawk::PlaylistModes::Retry )
            m_waitingOnNewTrack = true;

        stop();
    }
}
void
StreamConnection::startSending( const Tomahawk::result_ptr& result )
{
    if ( result.isNull() )
    {
        qDebug() << "Can't handle invalid result!";
        shutdown();
        return;
    }

    m_result = result;
    qDebug() << "Starting to transmit" << m_result->url();

    QSharedPointer<QIODevice> io = Servent::instance()->getIODeviceForUrl( m_result );
    if( !io )
    {
        qDebug() << "Couldn't read from source:" << m_result->url();
        shutdown();
        return;
    }

    m_readdev = QSharedPointer<QIODevice>( io );
    sendSome();

    emit updated();
}
StreamConnection::StreamConnection( Servent* s, ControlConnection* cc, QString fid, const Tomahawk::result_ptr& result )
    : Connection( s )
    , m_cc( cc )
    , m_fid( fid )
    , m_type( RECEIVING )
    , m_curBlock( 0 )
    , m_badded( 0 )
    , m_bsent( 0 )
    , m_allok( false )
    , m_result( result )
    , m_transferRate( 0 )
{
    qDebug() << Q_FUNC_INFO;

    BufferIODevice* bio = new BufferIODevice( result->size() );
    m_iodev = QSharedPointer<QIODevice>( bio, &QObject::deleteLater ); // device audio data gets written to
    m_iodev->open( QIODevice::ReadWrite );

    Servent::instance()->registerStreamConnection( this );

    // if the audioengine closes the iodev (skip/stop/etc) then kill the connection
    // immediately to avoid unnecessary network transfer
    connect( m_iodev.data(), SIGNAL( aboutToClose() ), SLOT( shutdown() ), Qt::QueuedConnection );
    connect( m_iodev.data(), SIGNAL( blockRequest( int ) ), SLOT( onBlockRequest( int ) ) );

    // auto delete when connection closes:
    connect( this, SIGNAL( finished() ), SLOT( deleteLater() ), Qt::QueuedConnection );

    // don't f**k with our messages at all. No compression, no parsing, nothing:
    this->setMsgProcessorModeIn ( MsgProcessor::NOTHING );
    this->setMsgProcessorModeOut( MsgProcessor::NOTHING );
}
Beispiel #21
0
void
AudioEngine::loadPreviousTrack()
{
    tDebug( LOGEXTRA ) << Q_FUNC_INFO;

    if ( m_playlist.isNull() )
    {
        stop();
        return;
    }

    Tomahawk::result_ptr result = m_playlist.data()->previousItem();
    if ( !result.isNull() )
        loadTrack( result );
    else
        stop();
}
Beispiel #22
0
void
Scrobbler::trackStarted( const Tomahawk::result_ptr& track )
{
    Q_ASSERT( QThread::currentThread() == thread() );

    if ( m_reachedScrobblePoint )
    {
        m_reachedScrobblePoint = false;
        scrobble();
    }

    Tomahawk::InfoSystem::InfoStringHash trackInfo;
    trackInfo["title"] = track->track();
    trackInfo["artist"] = track->artist()->name();
    trackInfo["album"] = track->album()->name();
    trackInfo["duration"] = QString::number( track->duration() );
    trackInfo["albumpos"] = QString::number( track->albumpos() );

    QVariantMap playInfo;
    playInfo["trackinfo"] = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
    playInfo["private"] = TomahawkSettings::instance()->privateListeningMode();

    Tomahawk::InfoSystem::InfoPushData pushData (
        s_scInfoIdentifier, Tomahawk::InfoSystem::InfoSubmitNowPlaying,
        playInfo,
        Tomahawk::InfoSystem::PushNoFlag );

    Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( pushData );

    // liblastfm forces 0-length tracks to scrobble after 4 minutes, stupid.
    if ( track->duration() == 0 )
        m_scrobblePoint = ScrobblePoint( 30 );
    else
        m_scrobblePoint = ScrobblePoint( track->duration() / 2 );
}
Beispiel #23
0
PlayableItem::PlayableItem( const Tomahawk::result_ptr& result, PlayableItem* parent, int row )
    : QObject( parent )
    , m_result( result )
{
    init( parent, row );

    connect( result.data(), SIGNAL( updated() ),
                            SIGNAL( dataChanged() ) );
}
Beispiel #24
0
void
AudioControls::onPlaybackStarted( const Tomahawk::result_ptr& result )
{
    qDebug() << Q_FUNC_INFO;

    onPlaybackLoading( result );

    QString artistName = result->artist()->name();
    QString albumName = result->album()->name();
    
    Tomahawk::InfoSystem::InfoCustomDataHash trackInfo;
    
    trackInfo["artist"] = QVariant::fromValue< QString >( result->artist()->name() );
    trackInfo["album"] = QVariant::fromValue< QString >( result->album()->name() );
    TomahawkApp::instance()->infoSystem()->getInfo(
        s_infoIdentifier, Tomahawk::InfoSystem::InfoAlbumCoverArt,
        QVariant::fromValue< Tomahawk::InfoSystem::InfoCustomDataHash >( trackInfo ), Tomahawk::InfoSystem::InfoCustomDataHash() );
}
Beispiel #25
0
void
AudioControls::onPlaybackStarted( const Tomahawk::result_ptr& result )
{
    tDebug( LOGEXTRA ) << Q_FUNC_INFO;

    if ( result.isNull() )
        return;

    if ( m_currentTrack.isNull() || ( !m_currentTrack.isNull() && m_currentTrack.data()->id() != result.data()->id() ) )
        onPlaybackLoading( result );

    qint64 duration = AudioEngine::instance()->currentTrackTotalTime();

    if ( duration == -1 )
        duration = result.data()->duration() * 1000;

    ui->seekSlider->setRange( 0, duration );
    ui->seekSlider->setValue( 0 );

    m_phononTickCheckTimer.stop();

    m_sliderTimeLine.stop();
    m_sliderTimeLine.setDuration( duration );
    m_sliderTimeLine.setFrameRange( 0, duration );
    m_sliderTimeLine.setCurrentTime( 0 );
    m_seekMsecs = -1;

    ui->seekSlider->setVisible( true );

    m_noTimeChange = false;
    m_lastSliderCheck = 0;

    Tomahawk::InfoSystem::InfoStringHash trackInfo;
    trackInfo["artist"] = result->artist()->name();
    trackInfo["album"] = result->album()->name();

    Tomahawk::InfoSystem::InfoRequestData requestData;
    requestData.caller = s_acInfoIdentifier;
    requestData.type = Tomahawk::InfoSystem::InfoAlbumCoverArt;
    requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( trackInfo );
    requestData.customData = QVariantMap();

    Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
}
Beispiel #26
0
void
AudioEngine::playItem( Tomahawk::PlaylistInterface* playlist, const Tomahawk::result_ptr& result )
{
    tDebug( LOGEXTRA ) << Q_FUNC_INFO << ( result.isNull() ? QString() : result->url() );

    if ( !m_playlist.isNull() )
        m_playlist.data()->reset();

    setPlaylist( playlist );
    m_currentTrackPlaylist = playlist->getSharedPointer();

    if ( !result.isNull() )
        loadTrack( result );
    else if ( !m_playlist.isNull() && m_playlist.data()->retryMode() == PlaylistInterface::Retry )
    {
        m_waitingOnNewTrack = true;
        stop();
    }
}
Beispiel #27
0
bool
TrackProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
{
    PlItem* pi = itemFromIndex( sourceModel()->index( sourceRow, 0, sourceParent ) );
    if ( !pi )
        return false;

    const Tomahawk::query_ptr& q = pi->query();
    Tomahawk::result_ptr r;
    if ( q->numResults() )
        r = q->results().first();

//    if ( !r.isNull() && !r->collection()->source()->isOnline() )
//        return false;

    if ( filterRegExp().isEmpty() )
        return true;

    QStringList sl = filterRegExp().pattern().split( " ", QString::SkipEmptyParts );
    foreach( QString s, sl )
    {
        s = s.toLower();
        if ( !r.isNull() )
        {
            if ( !r->artist()->name().toLower().contains( s ) &&
                 !r->album()->name().toLower().contains( s ) &&
                 !r->track().toLower().contains( s ) )
            {
                return false;
            }
        }
        else
        {
            if ( !q->artist().toLower().contains( s ) &&
                 !q->album().toLower().contains( s ) &&
                 !q->track().toLower().contains( s ) )
            {
                return false;
            }
        }
    }
// TODO make clever (ft. featuring live (stuff) etc)
float
DatabaseCommand_Resolve::how_similar( const Tomahawk::query_ptr& q, const Tomahawk::result_ptr& r )
{
    // query values
    const QString qArtistname = DatabaseImpl::sortname( q->artist() );
    const QString qAlbumname  = DatabaseImpl::sortname( q->album() );
    const QString qTrackname  = DatabaseImpl::sortname( q->track() );

    // result values
    const QString rArtistname = DatabaseImpl::sortname( r->artist()->name() );
    const QString rAlbumname  = DatabaseImpl::sortname( r->album()->name() );
    const QString rTrackname  = DatabaseImpl::sortname( r->track() );

    // normal edit distance
    int artdist = levenshtein( qArtistname, rArtistname );
    int albdist = levenshtein( qAlbumname, rAlbumname );
    int trkdist = levenshtein( qTrackname, rTrackname );

    // max length of name
    int mlart = qMax( qArtistname.length(), rArtistname.length() );
    int mlalb = qMax( qAlbumname.length(), rAlbumname.length() );
    int mltrk = qMax( qTrackname.length(), rTrackname.length() );

    // distance scores
    float dcart = (float)( mlart - artdist ) / mlart;
    float dcalb = (float)( mlalb - albdist ) / mlalb;
    float dctrk = (float)( mltrk - trkdist ) / mltrk;

    // don't penalize for missing album name
    if( qAlbumname.length() == 0 )
        dcalb = 1.0;

    // weighted, so album match is worth less than track title
    float combined = ( dcart*4 + dcalb + dctrk*5 ) / 10;
    return combined;
}
Beispiel #29
0
void
AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result )
{
    tDebug( LOGEXTRA ) << Q_FUNC_INFO;

    m_currentTrack = result;

    ui->artistTrackLabel->setResult( result );
    ui->albumLabel->setResult( result );
    ui->ownerLabel->setText( result->friendlySource() );
    ui->coverImage->setPixmap( m_defaultCover );

    ui->timeLabel->setText( TomahawkUtils::timeToString( 0 ) );
    ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( result.data()->duration() ) );

    ui->stackedLayout->setCurrentWidget( ui->pauseButton );

    ui->loveButton->setEnabled( true );
    ui->loveButton->setVisible( true );

    result->loadSocialActions();

    connect( result.data(), SIGNAL( socialActionsLoaded() ), SLOT( socialActionsLoaded() ) );
}
void
QueueProxyModel::onPlaybackStarted( const Tomahawk::result_ptr& result )
{
    for ( int i = 0; i < rowCount(); i++ )
    {
        QModelIndex idx = index( i, 0 );
        PlayableItem* item = itemFromIndex( mapToSource( idx ) );
        if ( item && item->query() && ( item->query()->results().contains( result ) ||
                                        item->query()->track()->equals( result->track() ) ) )
        {
            removeIndex( idx );
            if ( !rowCount() )
                ViewManager::instance()->hideQueue();
        }
    }
}