import javax.swing.Action import java.awt.*; import java.io.IOException; import java.util.SortedSet; import org.slf4j.LoggerFactory import com.tagtraum.beatunes.action.standard.LibraryBatchAction import com.tagtraum.beatunes.action.standard.LibraryBatchAction.EachSongProcessor import com.tagtraum.audiokern.AudioSong import com.tagtraum.audiokern.mood.Mood import com.tagtraum.core.OperatingSystem; class MoodToGrouping extends LibraryBatchAction { class MoodWriter implements EachSongProcessor { static log = LoggerFactory.getLogger("MoodToGrouping.groovy") // Called once, before processing starts. def void startProcessing(int count) { log.info "Starting processing..." } // Called for each song. def void process(AudioSong song, int index) { Mood mood = song.getMood() if (mood != null) { String arousalNew String valenceNew int arousalOld = mood.getArousal() int valenceOld = mood.getValence() //mapping new arousal value (for better sorting) if (arousalOld < -90) { arousalNew = "a00" } if (arousalOld >= -90 && arousalOld < -80) { arousalNew = "a01" } if (arousalOld >= -80 && arousalOld < -70) { arousalNew = "a02" } if (arousalOld >= -70 && arousalOld < -60) { arousalNew = "a03" } if (arousalOld >= -60 && arousalOld < -50) { arousalNew = "a04" } if (arousalOld >= -50 && arousalOld < -40) { arousalNew = "a05" } if (arousalOld >= -40 && arousalOld < -30) { arousalNew = "a06" } if (arousalOld >= -30 && arousalOld < -20) { arousalNew = "a07" } if (arousalOld >= -20 && arousalOld < -10) { arousalNew = "a08" } if (arousalOld >= -10 && arousalOld < 0) { arousalNew = "a09" } if (arousalOld == 0) { arousalNew = "a10" } if (arousalOld > 0 && arousalOld < 10) { arousalNew = "a11" } if (arousalOld >= 10 && arousalOld < 20) { arousalNew = "a12" } if (arousalOld >= 20 && arousalOld < 30) { arousalNew = "a13" } if (arousalOld >= 30 && arousalOld < 40) { arousalNew = "a14" } if (arousalOld >= 40 && arousalOld < 50) { arousalNew = "a15" } if (arousalOld >= 50 && arousalOld < 60) { arousalNew = "a16" } if (arousalOld >= 60 && arousalOld < 70) { arousalNew = "a17" } if (arousalOld >= 70 && arousalOld < 80) { arousalNew = "a18" } if (arousalOld >= 80 && arousalOld < 90) { arousalNew = "a19" } if (arousalOld >= 90) { arousalNew = "a20" } //mapping new valence value (for better sorting) if (valenceOld < -90) { valenceNew = "v00" } if (valenceOld >= -90 && valenceOld < -80) { valenceNew = "v01" } if (valenceOld >= -80 && valenceOld < -70) { valenceNew = "v02" } if (valenceOld >= -70 && valenceOld < -60) { valenceNew = "v03" } if (valenceOld >= -60 && valenceOld < -50) { valenceNew = "v04" } if (valenceOld >= -50 && valenceOld < -40) { valenceNew = "v05" } if (valenceOld >= -40 && valenceOld < -30) { valenceNew = "v06" } if (valenceOld >= -30 && valenceOld < -20) { valenceNew = "v07" } if (valenceOld >= -20 && valenceOld < -10) { valenceNew = "v08" } if (valenceOld >= -10 && valenceOld < 0) { valenceNew = "v09" } if (valenceOld == 0) { valenceNew = "v10" } if (valenceOld > 0 && valenceOld < 10) { valenceNew = "v11" } if (valenceOld >= 10 && valenceOld < 20) { valenceNew = "v12" } if (valenceOld >= 20 && valenceOld < 30) { valenceNew = "v13" } if (valenceOld >= 30 && valenceOld < 40) { valenceNew = "v14" } if (valenceOld >= 40 && valenceOld < 50) { valenceNew = "v15" } if (valenceOld >= 50 && valenceOld < 60) { valenceNew = "v16" } if (valenceOld >= 60 && valenceOld < 70) { valenceNew = "v17" } if (valenceOld >= 70 && valenceOld < 80) { valenceNew = "v18" } if (valenceOld >= 80 && valenceOld < 90) { valenceNew = "v19" } if (valenceOld >= 90) { valenceNew = "v20" } // write arousal and valence into the grouping field song.setGrouping(arousalNew + " " + valenceNew) log.info "Writing mood " + arousalNew + " " + valenceNew + " to ${song.getName()}, overwriting ${song.getGrouping()}" } } // Called once all songs were processed. def void finishProcessing() { log.info "Done." } // Message to be shown in progress dialog. def String getProgressDialogMessage(AudioSong song) { "Copying mood for ${song.getName()}" } // Title for progress dialog. def String getProgressDialogTitle() { "Copying mood ..." } } // Unique id def String getId() { "Groovy.MoodToGrouping" } // Is called by beaTunes as part of the lifecycle after instantiation. // At this point all other plugins are instantiated and registered. // We use this to set the menu item's (i.e. action's) name. def void init() { putValue(Action.NAME, "Copy Mood to Grouping") } // We need to ask the user, whether he really wants to do this. // How we ask is defined here. def String getConfirmationMessage() { "Do you really want to overwrite the grouping field with the mood in your whole library?" } // Factory method that creates the processor for each song. def EachSongProcessor createEachSongProcessor() { new MoodWriter() } }