Package com.tagtraum.beatunes.matchtable
Class ScoreRule
- java.lang.Object
-
- com.tagtraum.beatunes.matchtable.ScoreRule
-
- All Implemented Interfaces:
Serializable
,Comparable<ScoreRule>
- Direct Known Subclasses:
AlbumRule
,AmazonSimilarityRule
,ArtistRule
,BPMRule
,ColorRule
,DanceabilityRule
,GenreRule
,GroupingRule
,InstrumentationRule
,KeyRule
,LanguageRule
,MoodRule
,MPMRule
,PopularityRule
,RatingRule
,SimilarArtistRule
,TagsRule
,TempoTimbreColorRule
,TimeRule
,TimeSignatureRule
,TuningRule
,YearRule
public abstract class ScoreRule extends Object implements Serializable, Comparable<ScoreRule>
Calculates how well a song matches another one (called template).- Author:
- Hendrik Schreiber
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ScoreRule.BasicScoreRuleEditor
protected class
ScoreRule.WeightBoundedRangeModel
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addPropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
int
compareTo(ScoreRule that)
protected ScoreRuleEditor
createEditor()
BeaTunes
getApplication()
abstract String
getDescription()
Description of how this rule works.abstract String
getId()
Returns a unique name for this rule.abstract SongPropertyFilter
getMatchFilter(AudioSong template, Float templateSyncBPM, boolean playMatchAtSyncTempo)
Returns a filter that matches Songs that match this rule at least somewhat.abstract String
getName()
Short name, like "Similar BPM"ScoreRuleEditor
getScoreRuleEditor()
float
getWeight()
SongPropertyFilter
getWeightedMatchFilter(AudioSong template, Float templateSyncBPM, boolean playMatchAtSyncTempo)
Returns a weighted filter.boolean
isIgnoredWhileQuickMatching()
Indicates whether this rule should be ignored in the initial matching and only be used to refine the result in a second round of matching.boolean
isSuitableForSorting()
Indicates whether this rule can be used for sorting a playlist, meaning whether it is cheap enough for for many invocations for many songs.void
load(nu.xom.Element element)
Empty impl.abstract float
score(AudioSong song, AudioSong template, Float syncBPM, boolean playMatchAtSyncTempo)
Returns a score between 0 and 1 for how well the given song matches the given template.void
setApplication(BeaTunes beaTunes)
void
setWeight(float weight)
Sets the weight for this rulevoid
store(nu.xom.Element element)
Empty impl.float
weightedScore(AudioSong song, AudioSong template, Float templateSyncBPM, boolean playMatchAtSyncTempo)
Weighted score computed fromgetWeight()
andscore(AudioSong, AudioSong, Float, boolean)
-
-
-
Method Detail
-
getName
public abstract String getName()
Short name, like "Similar BPM"- Returns:
- short name
-
getDescription
public abstract String getDescription()
Description of how this rule works. May be displayed in tooltips.- Returns:
- description
-
getId
public abstract String getId()
Returns a unique name for this rule.- Returns:
- unique name
-
addPropertyChangeListener
public void addPropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
- Parameters:
propertyName
- propertyNamepropertyChangeListener
- propertyChangeListener
-
score
public abstract float score(AudioSong song, AudioSong template, Float syncBPM, boolean playMatchAtSyncTempo)
Returns a score between 0 and 1 for how well the given song matches the given template. A higher score indicates a better match.- Parameters:
song
- songtemplate
- templatesyncBPM
- sync bpmplayMatchAtSyncTempo
- the given song is meant to be played at the same tempo as the template song- Returns:
- score between 0.0 and 1.0 as a measure for how well the song matches the template.
-
weightedScore
public float weightedScore(AudioSong song, AudioSong template, Float templateSyncBPM, boolean playMatchAtSyncTempo)
Weighted score computed fromgetWeight()
andscore(AudioSong, AudioSong, Float, boolean)
- Parameters:
song
- songtemplate
- templatetemplateSyncBPM
- sync bpm for the template songplayMatchAtSyncTempo
- the given song is meant to be played at the same tempo as the template song- Returns:
- weighted score between 0.0 and
getWeight()
-
getWeight
public float getWeight()
-
setWeight
public void setWeight(float weight)
Sets the weight for this rule- Parameters:
weight
- weight
-
compareTo
public int compareTo(ScoreRule that)
- Specified by:
compareTo
in interfaceComparable<ScoreRule>
-
getApplication
public BeaTunes getApplication()
-
setApplication
public void setApplication(BeaTunes beaTunes)
-
getMatchFilter
public abstract SongPropertyFilter getMatchFilter(AudioSong template, Float templateSyncBPM, boolean playMatchAtSyncTempo)
Returns a filter that matches Songs that match this rule at least somewhat. This should be used to find songs that at least somewhat match the rule.- Parameters:
template
- template song to matchtemplateSyncBPM
- sync bpm for the template songplayMatchAtSyncTempo
- the given song is meant to be played at the same tempo as the template song- Returns:
- a filter (set) that matches this rule or null, if all songs match this rule.
-
getWeightedMatchFilter
public SongPropertyFilter getWeightedMatchFilter(AudioSong template, Float templateSyncBPM, boolean playMatchAtSyncTempo)
Returns a weighted filter. I.e. if the weight of this rule is negative, the filter is negated as well;- Parameters:
template
- templatetemplateSyncBPM
- sync bpm for the template songplayMatchAtSyncTempo
- the given song is meant to be played at the same tempo as the template song- Returns:
- filter or null
- See Also:
getMatchFilter(AudioSong, Float, boolean)
-
isSuitableForSorting
public boolean isSuitableForSorting()
Indicates whether this rule can be used for sorting a playlist, meaning whether it is cheap enough for for many invocations for many songs. The rule can still be used efficiently for matching.- Returns:
- by default this returns true, if an implementation is not suitable this may return false and the rule will be ignored when sorting a playlist.
-
isIgnoredWhileQuickMatching
public boolean isIgnoredWhileQuickMatching()
Indicates whether this rule should be ignored in the initial matching and only be used to refine the result in a second round of matching.- Returns:
- default implementation always returns false
-
getScoreRuleEditor
public ScoreRuleEditor getScoreRuleEditor()
-
load
public void load(nu.xom.Element element) throws ConfigurationException
Empty impl. Override for adding custom initializations.- Parameters:
element
- XML element to initialize this rule with.- Throws:
ConfigurationException
-
store
public void store(nu.xom.Element element) throws ConfigurationException
Empty impl. Override for adding custom attributes.- Parameters:
element
- XML element that is named like the id of this score rule. It's value is equals to weight * 10f- Throws:
ConfigurationException
-
createEditor
protected ScoreRuleEditor createEditor()
-
-