No issues found
1 /*
2 * Copyright (C) 2003 Jeffrey Yasskin <jyasskin@mail.utexas.edu>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * The Rhythmbox authors hereby grant permission for non-GPL compatible
10 * GStreamer plugins to be used and distributed together with GStreamer
11 * and Rhythmbox. This permission is above and beyond the permissions granted
12 * by the GPL license by which Rhythmbox is covered. If you modify this code
13 * you may extend this exception to your version of the code, but you are not
14 * obligated to do so. If you do not wish to do so, delete this exception
15 * statement from your version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25 *
26 */
27
28 #include "config.h"
29
30 #include "rb-play-order-random-by-rating.h"
31
32 #include "rhythmdb.h"
33 #include <time.h>
34 #include <math.h>
35
36 static void rb_random_play_order_by_rating_class_init (RBRandomPlayOrderByRatingClass *klass);
37
38 static double rb_random_by_rating_get_entry_weight (RBRandomPlayOrder *rorder,
39 RhythmDB *db, RhythmDBEntry *entry);
40
41 G_DEFINE_TYPE (RBRandomPlayOrderByRating, rb_random_play_order_by_rating, RB_TYPE_RANDOM_PLAY_ORDER)
42
43 static void
44 rb_random_play_order_by_rating_class_init (RBRandomPlayOrderByRatingClass *klass)
45 {
46 RBRandomPlayOrderClass *rorder;
47
48 rorder = RB_RANDOM_PLAY_ORDER_CLASS (klass);
49 rorder->get_entry_weight = rb_random_by_rating_get_entry_weight;
50 }
51
52 RBPlayOrder *
53 rb_random_play_order_by_rating_new (RBShellPlayer *player)
54 {
55 RBRandomPlayOrderByRating *rorder;
56
57 rorder = g_object_new (RB_TYPE_RANDOM_PLAY_ORDER_BY_RATING,
58 "player", player,
59 NULL);
60
61 return RB_PLAY_ORDER (rorder);
62 }
63
64 static void
65 rb_random_play_order_by_rating_init (RBRandomPlayOrderByRating *porder)
66 {
67 }
68
69 static double
70 rb_random_by_rating_get_entry_weight (RBRandomPlayOrder *rorder, RhythmDB *db, RhythmDBEntry *entry)
71 {
72 double rating;
73
74 rating = rhythmdb_entry_get_double (entry, RHYTHMDB_PROP_RATING);
75 if (rating < 0.01)
76 rating = 2.5;
77
78 return rating;
79 }