Beispiel #1
0
// -------------------------------------------------------------------------------- //
void guPLSoListBox::RandomizeTracks( void )
{
    int Index;
    int Pos;
    int NewPos;
    int Count = m_Items.Count();
    guTrack SavedItem;

    if( Count > 2 )
    {
        for( Index = 0; Index < Count; Index++ )
        {
            do {
                Pos = guRandom( Count );
                NewPos = guRandom( Count );
            } while( Pos == NewPos );
            SavedItem = m_Items[ Pos ];
            m_Items[ Pos ] = m_Items[ NewPos ];
            m_Items[ NewPos ] = SavedItem;

            RefreshRow( Pos );
            RefreshRow( NewPos );
        }
        ClearSelectedItems();
    }
}
Beispiel #2
0
// -------------------------------------------------------------------------------- //
bool guDbCache::SetContent( const wxString &url, const wxString &content, const int type )
{
  wxString query = wxString::Format( wxT( "INSERT INTO cache( cache_id, cache_key, cache_data, " \
                "cache_type, cache_time, cache_size ) VALUES( NULL, '%s', '%s', %u, %lu, %u );" ),
          escape_query_str( url ).c_str(),
          escape_query_str( content ).c_str(),
          type,
          wxDateTime::Now().GetTicks(),
          0 );

  ExecuteUpdate( query );

  // delete the expired entries but call it only 2% of the times
  if( guRandom( 1000 ) < 7 )
    ClearExpired();

  return true;
}
Beispiel #3
0
// -------------------------------------------------------------------------------- //
bool guDbCache::SetImage( const wxString &url, wxImage * img, const wxBitmapType imgtype )
{
  wxImage TmpImg( * img );
//  int Width = 150;
//  int Height = 150;
//  int ImageSize = guDBCACHE_TYPE_IMAGE_SIZE_BIG;
//  TmpImg.Rescale( Width, Height, wxIMAGE_QUALITY_HIGH );
  guImageResize( &TmpImg, 150 );
  if( !DoSetImage( url, &TmpImg, imgtype, guDBCACHE_TYPE_IMAGE_SIZE_BIG ) )
    return false;


  TmpImg = * img;
//  Width = 100;
//  Height = 100;
//  ImageSize = guDBCACHE_TYPE_IMAGE_SIZE_MID;
//  TmpImg.Rescale( Width, Height, wxIMAGE_QUALITY_HIGH );
  guImageResize( &TmpImg, 100 );
  if( !DoSetImage( url, &TmpImg, imgtype, guDBCACHE_TYPE_IMAGE_SIZE_MID ) )
    return false;

  TmpImg = * img;
//  Width = 50;
//  Height = 50;
//  ImageSize = guDBCACHE_TYPE_IMAGE_SIZE_TINY;
//  TmpImg.Rescale( Width, Height, wxIMAGE_QUALITY_HIGH );
  guImageResize( &TmpImg, 50 );
  if( !DoSetImage( url, &TmpImg, imgtype, guDBCACHE_TYPE_IMAGE_SIZE_TINY ) )
    return false;

  // delete the expired entries but call it only 5% of the times
  if( guRandom( 1000 ) < 20 )
    ClearExpired();

  return true;
}
Beispiel #4
0
// -------------------------------------------------------------------------------- //
int guSmartModeThread::AddSimilarTracks( const wxString &artist, const wxString &track, guTrackArray * tracks )
{
    //guLogMessage( wxT( "Searching for %s - %s" ), artist.c_str(), track.c_str() );
    int AddedTracks = 0;
    guTrackArray FoundTracks;
    guSimilarTrackInfoArray SimilarTracks = m_LastFM->TrackGetSimilar( artist, track );
    if( SimilarTracks.Count() )
    {
        int Index;
        int Count = SimilarTracks.Count();
        for( Index = 0; Index < Count; Index++ )
        {
            double Match = MatchStr2Double( SimilarTracks[ Index ].m_Match );
            //guLogMessage( wxT( "Match: %f" ), Match );
            if( Match >= guSMARTMODE_MIN_TRACK_MATCH )
            {
                CheckAddTrack( SimilarTracks[ Index ].m_ArtistName, SimilarTracks[ Index ].m_TrackName, &FoundTracks );
            }
            else    // Results comes sorted by match
            {
                break;
            }
            // TODO: CHANGE LIMIT
            if( TestDestroy() )
                break;
        }
    }

    if( FoundTracks.Count() < 4 )
    {
        guSimilarArtistInfoArray SimilarArtists = m_LastFM->ArtistGetSimilar( artist );
        int Index;
        int Count = SimilarArtists.Count();
        for( Index = 0; Index < Count; Index++ )
        {
            if( !m_SmartAddedArtists || ( m_SmartAddedArtists->Index( SimilarArtists[ Index ].m_Name.Upper() ) == wxNOT_FOUND ) )
            {
                double Match = MatchStr2Double( SimilarArtists[ Index ].m_Match );
                if( Match >= guSMARTMODE_MIN_ARTIST_MATCH )
                {
                    if( m_Db->GetArtistId( SimilarArtists[ Index ].m_Name, false ) != wxNOT_FOUND )
                    {
                        //guLogMessage( wxT( "Found similar artist: '%s'" ), SimilarArtists[ Index ].m_Name.c_str() );
                        guTopTrackInfoArray ArtistTopTracks = m_LastFM->ArtistGetTopTracks( SimilarArtists[ Index ].m_Name );
                        int TTIndex;
                        int TTCount = ArtistTopTracks.Count();
                        for( TTIndex = 0; TTIndex < TTCount; TTIndex++ )
                        {
                            if( TestDestroy() ||
                                CheckAddTrack( ArtistTopTracks[ TTIndex ].m_ArtistName, ArtistTopTracks[ TTIndex ].m_TrackName, &FoundTracks ) )
                                break;
                        }
                    }
                }
                else
                {
                    break;
                }
            }
            if( TestDestroy() )
                break;
        }
    }

    // Select some random tracks from the available
    while( !TestDestroy() && FoundTracks.Count() )
    {
        int TrackIndex = guRandom( FoundTracks.Count() );

        const guTrack & RandomTrack = FoundTracks[ TrackIndex ];

        if( !m_SmartAddedArtists || ( m_SmartAddedArtists->Index( RandomTrack.m_ArtistName.Upper() ) == wxNOT_FOUND ) )
        {
            if( !m_SmartAddedTracks || ( m_SmartAddedTracks->Index( RandomTrack.m_SongId ) == wxNOT_FOUND ) )
            {
                if( !CheckLimit( &RandomTrack ) )
                {
                    tracks->Add( new guTrack( RandomTrack ) );

                    if( m_SmartAddedArtists )
                    {
                        m_SmartAddedArtists->Add( RandomTrack.m_ArtistName.Upper() );
                    }
                    if( m_SmartAddedTracks )
                    {
                        m_SmartAddedTracks->Add( RandomTrack.m_SongId );
                    }
                    AddedTracks++;
                }
                else
                {
                    break;
                }
            }
        }

        FoundTracks.RemoveAt( TrackIndex );
    }

    return AddedTracks;
}