Example #1
0
File: stat.c Project: empeg/squash
/*
 * When a song is skipped or played successfully, song feedback
 * should occur.  This routine alters these statistics and also
 * ensures that the global statistics are kept up to date.
 */
void feedback( song_info_t *song, short direction ) {
    double rating = get_rating( song->stat );

    database_info.sum -= rating;
    database_info.sqr_sum -= rating * rating;

    if( direction < 0 ) {
        database_info.skip_sqr_sum -= song->stat.skip_count * song->stat.skip_count;
        song->stat.skip_count++;
        database_info.skip_sum++;
        database_info.skip_sqr_sum += song->stat.skip_count * song->stat.skip_count;
    } else {
        database_info.play_sqr_sum -= song->stat.play_count * song->stat.play_count;
        song->stat.play_count++;
        database_info.play_sum++;
        database_info.play_sqr_sum += song->stat.play_count * song->stat.play_count;
    }
    song->stat.changed = 1;

    rating = get_rating( song->stat );
    database_info.sum += rating;
    database_info.sqr_sum += rating * rating;

    save_song( song );
}
Example #2
0
void
init_song ( void )
{
    if ( ! midi_is_active() )
        setup_jack();

    if ( !( nsm && nsm->is_active() ) )
        song.filename = NULL;

    clear_song();

    if ( nsm && nsm->is_active() )
        save_song( song.filename );
}
Example #3
0
/** process any queued events */
void
Lash::process ( void )
{
    lash_event_t *e;

    char *name;

    while ( ( e = lash_get_event( _client ) ) )
    {
        asprintf( &name, "%s/%s", lash_event_get_string( e ), "song.non" );

        const int t = lash_event_get_type ( e );

        switch ( t )
        {
            case LASH_Save_File:
            {
                MESSAGE( "LASH wants us to save \"%s\"", name );

                save_song( name );

                lash_send_event( _client, lash_event_new_with_type( LASH_Save_File ) );

                break;

            }
            case LASH_Restore_File:
            {
                MESSAGE( "LASH wants us to load \"%s\"", name );

                if ( ! load_song( name ) )
                    /* FIXME: should we tell lash that we couldn't load the song? */;

                lash_send_event( _client, lash_event_new_with_type( LASH_Restore_File ) );

                break;
            }
            case LASH_Quit:
                MESSAGE( "LASH wants us to quit" );
                quit();
                break;
            default:
                WARNING( "unhandled LASH event (%d)", t );
        }

        lash_event_destroy( e );
    }
}