1717 */
1818package net .raphimc .noteblocklib .format .mcsp2 ;
1919
20- import net . raphimc . noteblocklib . data . MinecraftDefinitions ;
20+ import com . google . common . collect . Sets ;
2121import net .raphimc .noteblocklib .data .MinecraftInstrument ;
2222import net .raphimc .noteblocklib .format .mcsp2 .model .McSp2Layer ;
2323import net .raphimc .noteblocklib .format .mcsp2 .model .McSp2Note ;
2727import net .raphimc .noteblocklib .model .Song ;
2828import net .raphimc .noteblocklib .util .SongResampler ;
2929
30- import java .util .Arrays ;
3130import java .util .List ;
31+ import java .util .Set ;
3232
3333public class McSp2Converter {
3434
35- private static final List <MinecraftInstrument > SUPPORTED_INSTRUMENTS = Arrays . asList (MinecraftInstrument .HARP , MinecraftInstrument .BASS , MinecraftInstrument .BASS_DRUM , MinecraftInstrument .SNARE , MinecraftInstrument .HAT );
35+ public static final Set <MinecraftInstrument > SUPPORTED_INSTRUMENTS = Sets . immutableEnumSet (MinecraftInstrument .HARP , MinecraftInstrument .BASS , MinecraftInstrument .BASS_DRUM , MinecraftInstrument .SNARE , MinecraftInstrument .HAT );
3636
3737 /**
3838 * Creates a new MCSP2 song from the general data of the given song (Also copies some format specific fields if applicable).
@@ -42,7 +42,7 @@ public class McSp2Converter {
4242 */
4343 public static McSp2Song createSong (Song song ) {
4444 song = song .copy ();
45- SongResampler .changeTickSpeed (song , Math .max (McSp2Definitions .MIN_TEMPO , Math .min (McSp2Definitions . MAX_TEMPO , Math .round (song .getTempoEvents ().get (0 )))));
45+ SongResampler .changeTickSpeed (song , Math .max (McSp2Definitions .MIN_TEMPO , Math .min (Math .round (song .getTempoEvents ().get (0 )), McSp2Definitions . MAX_TEMPO )));
4646
4747 final McSp2Song newSong = new McSp2Song ();
4848 newSong .copyGeneralData (song );
@@ -52,10 +52,10 @@ public static McSp2Song createSong(Song song) {
5252 final List <Note > notes = song .getNotes ().get (tick );
5353 for (int i = 0 ; i < notes .size (); i ++) {
5454 final Note note = notes .get (i );
55- if (note .getInstrument () instanceof MinecraftInstrument && SUPPORTED_INSTRUMENTS . contains (( MinecraftInstrument ) note . getInstrument ()) && note .getVolume () > 0 ) {
55+ if (note .getInstrument () instanceof MinecraftInstrument && note .getVolume () > 0 ) {
5656 final McSp2Note mcSp2Note = new McSp2Note ();
5757 mcSp2Note .setInstrument (((MinecraftInstrument ) note .getInstrument ()).nbsId ());
58- mcSp2Note .setKey (( byte ) Math . max ( MinecraftDefinitions . MC_LOWEST_KEY , Math . min ( MinecraftDefinitions . MC_HIGHEST_KEY , note .getMcKey ()) ));
58+ mcSp2Note .setKey (note .getMcKey ());
5959
6060 final McSp2Layer mcSp2Layer = newSong .getLayers ().computeIfAbsent (i , k -> new McSp2Layer ());
6161 mcSp2Layer .getNotes ().put (tick , mcSp2Note );
@@ -66,15 +66,14 @@ public static McSp2Song createSong(Song song) {
6666 if (song instanceof McSp2Song ) {
6767 final McSp2Song mcSp2Song = (McSp2Song ) song ;
6868 newSong .setAutoSaveInterval (mcSp2Song .getAutoSaveInterval ());
69- newSong .setAutoSaveInterval ((byte ) mcSp2Song .getAutoSaveInterval ());
7069 newSong .setMinutesSpent (mcSp2Song .getMinutesSpent ());
7170 newSong .setLeftClicks (mcSp2Song .getLeftClicks ());
7271 newSong .setRightClicks (mcSp2Song .getRightClicks ());
7372 newSong .setNoteBlocksAdded (mcSp2Song .getNoteBlocksAdded ());
7473 newSong .setNoteBlocksRemoved (mcSp2Song .getNoteBlocksRemoved ());
7574 } else if (song instanceof NbsSong ) {
7675 final NbsSong nbsSong = (NbsSong ) song ;
77- newSong .setAutoSaveInterval (nbsSong .isAutoSave () ? nbsSong .getAutoSaveInterval () : ( byte ) 0 );
76+ newSong .setAutoSaveInterval (nbsSong .isAutoSave () ? nbsSong .getAutoSaveInterval () : 0 );
7877 newSong .setMinutesSpent (nbsSong .getMinutesSpent ());
7978 newSong .setLeftClicks (nbsSong .getLeftClicks ());
8079 newSong .setRightClicks (nbsSong .getRightClicks ());
0 commit comments