2727
2828import javax .swing .JPanel ;
2929import java .util .HashMap ;
30+ import java .util .HashSet ;
3031import java .util .List ;
3132import java .util .Map ;
3233import java .util .Set ;
@@ -48,17 +49,22 @@ protected void initComponents(final JPanel center) {
4849 this .add (new FastScrollPane (this .table ));
4950 this .usedInstruments = SongUtil .getUsedNbsCustomInstruments (this .songs .get (0 ).song ());
5051 for (NbsCustomInstrument customInstrument : this .usedInstruments ) {
51- this .table .addRow (customInstrument .getNameOr ("No Name" ) + " (" + customInstrument .getSoundFilePathOr ("No Sound File" ) + ")" , null );
52+ this .table .addRow (customInstrument .getNameOr ("No Name" ) + " (" + customInstrument .getSoundFilePathOr ("No Sound File" ) + ")" );
5253 }
5354 }
5455
5556 @ Override
5657 public void apply (final Song song ) {
5758 final Map <NbsCustomInstrument , MinecraftInstrument > replacements = new HashMap <>();
59+ final Set <NbsCustomInstrument > remove = new HashSet <>();
5860 int i = 0 ;
5961 for (NbsCustomInstrument customInstrument : this .usedInstruments ) {
60- final MinecraftInstrument replacement = (MinecraftInstrument ) this .table .getValueAt (i , 1 );
61- replacements .put (customInstrument , replacement );
62+ Object rawReplacement = this .table .getValueAt (i , 1 );
63+ if (rawReplacement instanceof MinecraftInstrument replacement ) {
64+ replacements .put (customInstrument , replacement );
65+ } else if (rawReplacement == InstrumentsTable .REMOVE ) {
66+ remove .add (customInstrument );
67+ }
6268 i ++;
6369 }
6470 song .getNotes ().forEach (note -> {
@@ -67,6 +73,7 @@ public void apply(final Song song) {
6773 note .setInstrument (replacement );
6874 }
6975 });
76+ song .getNotes ().removeIf (note -> remove .contains (note .getInstrument ()));
7077 }
7178
7279}
0 commit comments