Ejemplo n.º 1
0
Dynamic::TrackSet
Dynamic::AlbumPlayBias::matchingTracks( const Meta::TrackList& playlist,
                                        int contextCount, int finalCount,
                                        Dynamic::TrackCollectionPtr universe ) const
{
    Q_UNUSED( contextCount );
    Q_UNUSED( finalCount );

    if( playlist.isEmpty() ) // no track means we can't find any tracks in the same album
        return Dynamic::TrackSet( universe, false );

    Meta::TrackPtr track = playlist.last();
    Meta::AlbumPtr album = track->album();

    if( !album ) // no album means we can't find any tracks in the same album
        return Dynamic::TrackSet( universe, false );

    Meta::TrackList albumTracks = album->tracks();

    if( ( albumTracks.count() <= 1 ) || // the album has only one track (or even less) so there can't be any other tracks in the same album
        ( m_follow != DontCare && sameTrack( track, albumTracks.last() ) ) ) // track is the last one and we want to find a later one.
        return Dynamic::TrackSet( universe, false );

    // we assume that the album tracks are sorted by cd and track number which
    // is at least true for the SqlCollection
    TrackSet result( universe, false );
    if( m_follow == DirectlyFollow )
    {
        for( int i = 1; i < albumTracks.count(); i++ )
            if( sameTrack( albumTracks[i-1], track ) )
                result.unite( albumTracks[i] );
    }
    else if( m_follow == Follow )
    {
        bool found = false;
        for( int i = 0; i < albumTracks.count(); i++ )
        {
            if( found )
                result.unite( albumTracks[i] );
            if( sameTrack( albumTracks[i], track ) )
                found = true;
        }
    }
    else if( m_follow == DontCare )
    {
        for( int i = 0; i < albumTracks.count(); i++ )
        {
            if( !sameTrack( albumTracks[i], track ) )
                result.unite( albumTracks[i] );
        }
    }

    return result;
}
Ejemplo n.º 2
0
void
IpodCopyTracksJob::slotDuplicateTrackSearchNewResult( const Meta::TrackList &tracks )
{
    if( !tracks.isEmpty() )
        // we don't really know which one, but be sure to allow multiple results
        m_duplicateTrack = tracks.last();
}
Ejemplo n.º 3
0
Dynamic::TrackSet
Dynamic::AlbumPlayBias::matchingTracks( int position,
                                       const Meta::TrackList& playlist, int contextCount,
                                       Dynamic::TrackCollectionPtr universe ) const
{
    Q_UNUSED( contextCount );

    if( position < 1 || position >= playlist.count() )
        return Dynamic::TrackSet( universe, false );

    Meta::TrackPtr track = playlist[position-1];
    Meta::AlbumPtr album = track->album();

    if( !album )
        return Dynamic::TrackSet( universe, false );

    Meta::TrackList albumTracks = album->tracks();
    if( albumTracks.count() == 1 ||
        (track == albumTracks.last() && m_follow != DontCare) )
        return Dynamic::TrackSet( universe, false );

    // we assume that the album tracks are sorted by cd and track number which
    // is at least true for the SqlCollection
    TrackSet result( universe, false );
    if( m_follow == DirectlyFollow )
    {
        for( int i = 1; i < albumTracks.count(); i++ )
            if( albumTracks[i-1] == track )
                result.unite( albumTracks[i] );
    }
    else if( m_follow == Follow )
    {
        bool found = false;
        for( int i = 0; i < albumTracks.count(); i++ )
        {
            if( found )
                result.unite( albumTracks[i] );
            if( albumTracks[i] == track )
                found = true;
        }
    }
    else if( m_follow == DontCare )
    {
        for( int i = 0; i < albumTracks.count(); i++ )
        {
            if( albumTracks[i] != track )
                result.unite( albumTracks[i] );
        }
    }

    return result;
}
Ejemplo n.º 4
0
bool
Dynamic::AlbumPlayBias::trackMatches( int position,
                                      const Meta::TrackList& playlist,
                                      int contextCount ) const
{
    Q_UNUSED( contextCount );

    if( position <= 0 || playlist.count() <= position )
        return true;

    Meta::TrackPtr track = playlist[position-1];
    Meta::AlbumPtr album = track->album();
    Meta::TrackPtr currentTrack = playlist[position];
    Meta::AlbumPtr currentAlbum = currentTrack->album();

    if( !album || album->tracks().isEmpty() )
        return false;

    Meta::TrackList albumTracks = album->tracks();
    if( sameTrack( track, albumTracks.last() ) && m_follow != DontCare )
        return false;

    // we assume that the album tracks are sorted by cd and track number which
    // is at least true for the SqlCollection
    if( m_follow == DirectlyFollow )
    {
        for( int i = 1; i < albumTracks.count(); i++ )
            if( sameTrack( albumTracks[i-1], track ) )
                return sameTrack( albumTracks[i], currentTrack );
        return false;
    }
    else if( m_follow == Follow )
    {
        bool found = false;
        for( int i = 0; i < albumTracks.count(); i++ )
        {
            if( found && sameTrack( albumTracks[i], currentTrack ) )
                return true;
            if( sameTrack( albumTracks[i], track ) )
                found = true;
        }
        return false;
    }
    else if( m_follow == DontCare )
    {
        return album == currentAlbum;
    }
    return false;
}
Ejemplo n.º 5
0
Dynamic::TrackSet
Dynamic::LastFmBias::matchingTracks( const Meta::TrackList& playlist,
                                     int contextCount, int finalCount,
                                     Dynamic::TrackCollectionPtr universe ) const
{
    Q_UNUSED( contextCount );
    Q_UNUSED( finalCount );

    if( playlist.isEmpty() )
        return Dynamic::TrackSet( universe, true );

    // determine the last track and artist
    Meta::TrackPtr lastTrack = playlist.last();
    Meta::ArtistPtr lastArtist = lastTrack->artist();

    m_currentTrack = lastTrack->name();
    m_currentArtist = lastArtist ? lastArtist->name() : QString();

    {
        QMutexLocker locker( &m_mutex );

        if( m_match == SimilarArtist )
        {
            if( m_currentArtist.isEmpty() )
                return Dynamic::TrackSet( universe, true );
            if( m_tracksMap.contains( m_currentArtist ) )
                return m_tracksMap.value( m_currentArtist );
        }
        else if( m_match == SimilarTrack )
        {
            if( m_currentTrack.isEmpty() )
                return Dynamic::TrackSet( universe, true );
            QString key = m_currentTrack + '|' + m_currentArtist;
            if( m_tracksMap.contains( key ) )
                return m_tracksMap.value( key );
        }
    }

    m_tracks = Dynamic::TrackSet( universe, false );
    QTimer::singleShot(0,
                       const_cast<LastFmBias*>(this),
                       SLOT(newQuery())); // create the new query from my parent thread

    return Dynamic::TrackSet();
}