/*
- * Copyright (C) 2007-2012 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2007-2013 Andre Noll <maan@systemlinux.org>
*
* Licensed under the GPL v2. For licencing details see COPYING.
*/
if (!*mood_name)
return -E_DUMMY_ROW;
mlpd.m = alloc_new_mood(mood_name);
- ret = for_each_line_ro(mood_def.data, mood_def.size,
+ ret = for_each_line(FELF_READ_ONLY, mood_def.data, mood_def.size,
parse_mood_line, &mlpd);
osl_close_disk_object(&mood_def);
if (ret < 0) {
ret = para_printf(pb, "checking mood %s...\n", mood_name);
if (ret < 0)
goto out;
- ret = for_each_line_ro(mood_def.data, mood_def.size,
+ ret = for_each_line(FELF_READ_ONLY, mood_def.data, mood_def.size,
parse_mood_line, &mlpd);
if (ret < 0)
para_printf(pb, "%s line %u: %s\n", mood_name, mlpd.line_num,
free(pb.buf);
}
-#if 0
-static unsigned int_log2(uint64_t x)
-{
- unsigned res = 0;
-
- while (x) {
- x /= 2;
- res++;
- }
- return res;
-}
-#endif
-
static int64_t normalized_value(int64_t x, int64_t n, int64_t sum, int64_t qd)
{
if (!n || !qd)
statistics.last_played_sum, statistics.last_played_qd);
}
-static long compute_dynamic_score(const struct osl_row *aft_row)
+static long compute_dynamic_score(struct afs_info *afsi)
{
- struct afs_info afsi;
- int64_t score, nscore = 0, lscore = 0;
- int ret;
-
- ret = get_afsi_of_row(aft_row, &afsi);
- if (ret < 0)
- return -100;
- nscore = compute_num_played_score(&afsi);
- lscore = compute_last_played_score(&afsi);
- score = nscore + lscore;
- return score;
+ return compute_num_played_score(afsi) + compute_last_played_score(afsi);
}
static int add_afs_statistics(const struct osl_row *row)
static int add_to_score_table(const struct osl_row *aft_row, long mood_score)
{
- long score = (compute_dynamic_score(aft_row) + mood_score) / 3;
+ long score;
+ struct afs_info afsi;
+ int ret = get_afsi_of_row(aft_row, &afsi);
+
+ if (ret < 0)
+ return ret;
+ score = (compute_dynamic_score(&afsi) + mood_score) / 3;
return score_add(aft_row, score);
}
if (ret < 0)
return ret;
}
- score += compute_num_played_score(&afsi);
- score += compute_last_played_score(&afsi);
+ score += compute_dynamic_score(&afsi);
score /= 3;
PARA_DEBUG_LOG("score: %li\n", score);
percent = (score + 100) / 3;
* This function performs actions required due to the occurrence of the given
* event. Possible actions include reload of the current mood and update of the
* score of an audio file.
+ *
+ * \return Standard.
*/
int moods_event_handler(enum afs_events event, __a_unused struct para_buffer *pb,
void *data)