Skip to content

Commit 5fc6564

Browse files
committed
Added support for exporting as MCSP2 and TXT
1 parent 50c9ba7 commit 5fc6564

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/main/java/net/raphimc/noteblocktool/frames/ExportFrame.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import net.lenni0451.commons.swing.layouts.VerticalLayout;
2424
import net.raphimc.audiomixer.util.io.SoundIO;
2525
import net.raphimc.noteblocklib.NoteBlockLib;
26-
import net.raphimc.noteblocklib.format.nbs.NbsConverter;
26+
import net.raphimc.noteblocklib.format.SongFormat;
2727
import net.raphimc.noteblocklib.model.Song;
2828
import net.raphimc.noteblocktool.audio.export.AudioExporter;
2929
import net.raphimc.noteblocktool.audio.export.LameLibrary;
@@ -59,7 +59,7 @@ public class ExportFrame extends JFrame {
5959

6060
private final ListFrame parent;
6161
private final List<ListFrame.LoadedSong> loadedSongs;
62-
private final JComboBox<String> format = new JComboBox<>(new String[]{"NBS", "MP3 (Using LAME encoder)", "WAV", "AIF"});
62+
private final JComboBox<String> format = new JComboBox<>(new String[]{"NBS", "MCSP2", "TXT", "MP3 (Using LAME encoder)", "WAV", "AIF"});
6363
private final JLabel soundSystemLabel = new JLabel("Sound System:");
6464
private final JComboBox<String> soundSystem = new JComboBox<>(new String[]{"OpenAL (best sound quality, fastest)", "AudioMixer", "AudioMixer (global normalized)", "Un4seen BASS"});
6565
private final JLabel sampleRateLabel = new JLabel("Sample Rate:");
@@ -152,8 +152,8 @@ private void initComponents() {
152152
}
153153

154154
private void updateVisibility() {
155-
final boolean isAudioFile = this.format.getSelectedIndex() != 0;
156-
final boolean isMp3 = this.format.getSelectedIndex() == 1;
155+
final boolean isAudioFile = this.format.getSelectedIndex() >= 3;
156+
final boolean isMp3 = this.format.getSelectedIndex() == 3;
157157

158158
this.soundSystemLabel.setVisible(isAudioFile);
159159
this.soundSystem.setVisible(isAudioFile);
@@ -258,8 +258,8 @@ private File openFileChooser() {
258258
}
259259

260260
private void doExport(final File outFile) {
261-
final boolean isAudioFile = this.format.getSelectedIndex() != 0;
262-
final boolean isMp3 = this.format.getSelectedIndex() == 1;
261+
final boolean isAudioFile = this.format.getSelectedIndex() >= 3;
262+
final boolean isMp3 = this.format.getSelectedIndex() == 3;
263263
final boolean bassSoundSystem = this.soundSystem.getSelectedIndex() == 3;
264264
final AudioFormat format = new AudioFormat(
265265
((Number) this.sampleRate.getValue()).floatValue(),
@@ -395,7 +395,11 @@ private void doExport(final File outFile) {
395395

396396
private void exportSong(final ListFrame.LoadedSong song, final AudioFormat format, final File file, final Consumer<Float> progressConsumer) throws InterruptedException, IOException {
397397
if (this.format.getSelectedIndex() == 0) {
398-
this.writeNbsSong(song, file);
398+
this.writeSong(song, file, SongFormat.NBS);
399+
} else if (this.format.getSelectedIndex() == 1) {
400+
this.writeSong(song, file, SongFormat.MCSP2);
401+
} else if (this.format.getSelectedIndex() == 2) {
402+
this.writeSong(song, file, SongFormat.TXT);
399403
} else {
400404
final AudioExporter exporter;
401405
if (this.soundSystem.getSelectedIndex() == 0) {
@@ -413,12 +417,12 @@ private void exportSong(final ListFrame.LoadedSong song, final AudioFormat forma
413417
exporter.render();
414418
final byte[] samples = SoundIO.writeSamples(exporter.getSamples(), format);
415419

416-
if (this.format.getSelectedIndex() == 2 || this.format.getSelectedIndex() == 3) {
420+
if (this.format.getSelectedIndex() == 4 || this.format.getSelectedIndex() == 5) {
417421
progressConsumer.accept(10F);
418422
final AudioInputStream audioInputStream = new AudioInputStream(new ByteArrayInputStream(samples), format, samples.length);
419-
AudioSystem.write(audioInputStream, this.format.getSelectedIndex() == 2 ? AudioFileFormat.Type.WAVE : AudioFileFormat.Type.AIFF, file);
423+
AudioSystem.write(audioInputStream, this.format.getSelectedIndex() == 4 ? AudioFileFormat.Type.WAVE : AudioFileFormat.Type.AIFF, file);
420424
audioInputStream.close();
421-
} else if (this.format.getSelectedIndex() == 1) {
425+
} else if (this.format.getSelectedIndex() == 3) {
422426
progressConsumer.accept(2F);
423427
final FileOutputStream fos = new FileOutputStream(file);
424428
final int numSamples = samples.length / format.getFrameSize();
@@ -458,9 +462,9 @@ private void exportSong(final ListFrame.LoadedSong song, final AudioFormat forma
458462
}
459463
}
460464

461-
private void writeNbsSong(final ListFrame.LoadedSong song, final File file) {
465+
private void writeSong(final ListFrame.LoadedSong song, final File file, final SongFormat format) {
462466
try {
463-
final Song exportSong = NbsConverter.createSong(song.song());
467+
final Song exportSong = NoteBlockLib.convertSong(song.song(), format);
464468
NoteBlockLib.writeSong(exportSong, file);
465469
} catch (Throwable t) {
466470
t.printStackTrace();

0 commit comments

Comments
 (0)