This commit is contained in:
Chayapak 2023-09-25 09:45:06 +07:00
parent 7d16d0aa3c
commit 6cb8248975

View file

@ -11,6 +11,7 @@ import java.util.HashMap;
// Author: hhhzzzsss // Author: hhhzzzsss
public class MidiConverter implements Converter { public class MidiConverter implements Converter {
public static final int TEXT = 0x01;
public static final int TRACK_NAME = 0x03; public static final int TRACK_NAME = 0x03;
public static final int SET_INSTRUMENT = 0xC0; public static final int SET_INSTRUMENT = 0xC0;
public static final int SET_TEMPO = 0x51; public static final int SET_TEMPO = 0x51;
@ -28,6 +29,8 @@ public class MidiConverter implements Converter {
String songName = null; String songName = null;
final StringBuilder text = new StringBuilder();
boolean isFirst = true; boolean isFirst = true;
ArrayList<MidiEvent> tempoEvents = new ArrayList<>(); ArrayList<MidiEvent> tempoEvents = new ArrayList<>();
@ -48,12 +51,18 @@ public class MidiConverter implements Converter {
isFirst = false; isFirst = false;
} }
} else if (mm.getType() == TEXT) {
text.append(new String(mm.getData()));
text.append('\n');
} }
} }
} }
} }
final Song song = new Song(name, bot, songName, null, null, null, false); String stringText = text.toString();
if (stringText.endsWith("\n")) stringText = stringText.substring(0, stringText.length() - 1);
final Song song = new Song(name, bot, songName, null, null, stringText, false);
tempoEvents.sort(Comparator.comparingLong(MidiEvent::getTick)); tempoEvents.sort(Comparator.comparingLong(MidiEvent::getTick));