arousal and valence to grouping
Hi there,
I want to have the arousal and valence values to be written in the grouping field.
I already searched everywhere and the only thing coming near is "TagsToGrouping.groovy".
Although I am not a developer I understand a tiny little bit of programming - so if the tags can be copied to grouping then arousal and valence can be copied there as well.
- Is there already a solution for this topic? If so, please provide me with the necessary information.
-
If not it would probably be necessary to modify the "TagsToGrouping.groovy" to "MoodToGrouping.groovy" and place that file in the plugin directory. I already found two mood-methods getArousal() and getValence() which should deliver the information I need.
But as I am no programmer I have some difficulties in rewriting the code. I think the topic can be narrowed on this part of the code:
` def void process(AudioSong song, int index) {Set<String> tags = song.getTags() if (tags != null && !tags.isEmpty()) { final StringBuilder sb = new StringBuilder() for (s in tags) { sb.append(s).append(',') } final String content = sb.toString().endsWith(",") ? sb.substring(0, sb.length() - 1) : sb.toString() log.info "Writing tags (${content}) to ${song.getName()}" song.setGrouping(content)`
Any suggestions how this can be done?
Cheers, Björn
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by hendrik on 21 Feb, 2016 04:15 AM
Hey Björn,
Yes—you're exactly right. From the top of my head, this should work (untested):
[...] Mood mood = song.getMood() if (mood != null) { song.setGrouping("valence=${mood.getValence()}, arousal=${mood.getArousal()}") } [...]
If you're calling the file
MoodToGrouping.groovy
, you should call the classMoodToGrouping
. Also, you may need to add an import statement for the Mood class. I.e.If you get this to work, please attach the resulting beaTlet to this discussion, so that other may benefit. Thank you!
Hope this helps,
-hendrik
2 Posted by justb72 on 21 Feb, 2016 09:25 AM
Thanks Hendrik,
what is the best way to test my plugin?
I don't want to mess my whole library.
Cheers Björn
3 Posted by justb72 on 21 Feb, 2016 10:37 AM
I modified the class as suggested:
You think this is correct?
Support Staff 4 Posted by hendrik on 21 Feb, 2016 11:53 AM
The
MoodWriter
part looks good to me. You can test it by not callingsetGrouping
and just doing log statements.Anyhow. In the
MoodToGrouping
class you have to make sure that you adjust the factory method to create aMoodWriter
instance.So:
-hendrik
Support Staff 5 Posted by hendrik on 01 Mar, 2016 10:44 AM
Hey Björn,
just wanted to follow-up: Did you get this to work satisfactorily? If not, what's not working? If you did get it to work, would you attach the source file (as attachment, not inline)?
Thanks,
-hendrik
6 Posted by justb72 on 01 Mar, 2016 09:59 PM
Hey Hendrik,
indeed I succeeded.
With your help it was quite easy to read the arousal and valence out of the mood and to write the values in the grouping field.
But then I discovered, that I would not be able to sort my tracks based on the arousal because the lowest arousal values range from -90 to 90 and the grouping field is of text type and therefore iTunes and beatunes would sort it in the wrong way.
So I rewrote the code, so it would write -90 of arousal to a00 and +90 of arousal to a20. Same with valence (v00 to v20).
I am sure you can write the code much better (probably extracting the functionality to transfer the mood values in a seperate function) - but it works for me.
Additional information on how I get my dj-tool Traktor DJ to display the arousal and valence values:
In the tool mp3tag I have written an "action" to copy the grouping tag to the label tag - something like:
format tag field "PUBLISHER": %contentgroup%
So now I am finally able to sort my tracks in my dj-tool according to the arousal of the tracks. This is a big advantage for me.
Thank you again for your great support.
Björn
Support Staff 7 Posted by hendrik on 02 Mar, 2016 07:39 AM
Very cool! :-)
And thanks for posting the code. Hopefully someone else finds this useful.
BTW: In beaTunes 4.5.9, you can translate mood values into verbal descriptions with the following method:
For this to work, you first need to import
AbstractSongTableModel
:Just as additional info—the method in
AbstractSongTableModel
is defined like this:Cheers,
-hendrik
8 Posted by justb72 on 04 Mar, 2016 05:28 PM
Just discovered that I attached a version containing errors.
Find attached the latest version.
Support Staff 9 Posted by hendrik on 06 Mar, 2016 07:21 PM
Great. Thanks!