1 /* gmpc-dynamic-playlist (GMPC plugin)
2 * Copyright (C) 2010 Andre Klitzing <andre@incubo.de>
3 * Homepage: http://www.incubo.de
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <gmpc/plugin.h>
24 static gint8 m_artist
= -1;
25 static gint8 m_title
= -1;
29 m_artist
= (gint8
) cfg_get_single_value_as_int_with_default(config
, "dynamic-playlist", "fuzzy_artist", 80);
30 m_title
= (gint8
) cfg_get_single_value_as_int_with_default(config
, "dynamic-playlist", "fuzzy_title", 80);
33 static inline gboolean
fuzzy_exact_compare(const gchar
* l_first
, const gchar
* l_second
)
35 return strcasecmp(l_first
, l_second
) == 0;
38 static gint8
fuzzy_match(const gchar
* l_search
, const gchar
* l_text
)
40 /* TODO: Add a fuzzy string matching algorithm */
45 gboolean
fuzzy_match_value(const gchar
* l_search
, const gchar
* l_text
, gint8 l_value
)
47 g_assert(l_value
<= 100 && l_value
>= 0);
48 g_assert(l_search
!= NULL
);
49 g_assert(l_text
!= NULL
);
51 return fuzzy_exact_compare(l_search
, l_text
) || fuzzy_match(l_search
, l_text
) >= l_value
;
54 gboolean
fuzzy_match_artist(const gchar
* l_search
, const gchar
* l_text
)
56 return fuzzy_match_value(l_search
, l_text
, m_artist
);
59 gboolean
fuzzy_match_title(const gchar
* l_search
, const gchar
* l_text
)
61 return fuzzy_match_value(l_search
, l_text
, m_title
);
64 void set_fuzzy_artist(gint8 l_value
)
67 cfg_set_single_value_as_int(config
, "dynamic-playlist", "fuzzy_artist", m_artist
);
70 gint8
get_fuzzy_artist()
75 void set_fuzzy_title(gint8 l_value
)
78 cfg_set_single_value_as_int(config
, "dynamic-playlist", "fuzzy_title", m_title
);
81 gint8
get_fuzzy_title()
86 /* vim:set ts=4 sw=4: */