Compare commits

..

3 Commits

3 changed files with 138 additions and 51 deletions

View File

@ -24,7 +24,7 @@
<borderPainted value="false"/>
<foreground color="-2271221"/>
<indeterminate value="false"/>
<stringPainted value="true"/>
<stringPainted value="false"/>
<value value="0"/>
</properties>
</component>

View File

@ -125,7 +125,9 @@
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
<properties>
<disabledTextColor color="-10124141"/>
</properties>
</component>
<component id="f7802" class="javax.swing.JLabel">
<constraints>
@ -143,7 +145,9 @@
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
<properties>
<disabledTextColor color="-10124141"/>
</properties>
</component>
<grid id="27515" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
@ -337,7 +341,7 @@
<text value="no track"/>
</properties>
</component>
<component id="c11e8" class="javax.swing.JLabel" binding="dSSize">
<component id="c11e8" class="javax.swing.JLabel" binding="dSSize">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
@ -347,7 +351,7 @@
<text value="no size"/>
</properties>
</component>
<component id="8480f" class="javax.swing.JLabel" binding="dMSize">
<component id="8480f" class="javax.swing.JLabel" binding="dMSize">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>

View File

@ -19,6 +19,8 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
@ -27,7 +29,6 @@ import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
@ -86,6 +87,23 @@ public class Suggs implements ActionListener, ListSelectionListener {
private File sptrack;
private File mptrack;
DocumentListener id3TagEditorHandler = new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent documentEvent) {
updateSelectionToMatchTextFields();
}
@Override
public void removeUpdate(DocumentEvent documentEvent) {
updateSelectionToMatchTextFields();
}
@Override
public void changedUpdate(DocumentEvent documentEvent) {
updateSelectionToMatchTextFields();
}
};
public Suggs(JFrame parent) {
this.parent = parent;
parent.setEnabled(false);
@ -118,14 +136,25 @@ public class Suggs implements ActionListener, ListSelectionListener {
@Override
public void windowClosing(WindowEvent e)
{
int result = JOptionPane.showConfirmDialog(frame, "Are you sure?\nAll unsaved changes will be lost.", "Soundtrack Mod Generator", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (result == JOptionPane.YES_OPTION) {
parent.setEnabled(true);
e.getWindow().dispose();
if (!tracklist.isEmpty() || sptrack != null || mptrack != null) {
int result = JOptionPane.showConfirmDialog(frame, "Are you sure?\nAll unsaved changes will be lost.", "Soundtrack Mod Generator", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (result == JOptionPane.NO_OPTION) {return;}
}
parent.setEnabled(true);
e.getWindow().dispose();
}
});
fTitle.setText("");
fArtist.setText("");
dTrackNo.setText("\u200E");
dFileSize.setText("\u200E");
fTitle.setEnabled(false);
fArtist.setEnabled(false);
fTitle.getDocument().addDocumentListener(id3TagEditorHandler);
fArtist.getDocument().addDocumentListener(id3TagEditorHandler);
frame.setVisible(true);
}
@ -136,17 +165,12 @@ public class Suggs implements ActionListener, ListSelectionListener {
@Override
public void actionPerformed(ActionEvent actionEvent) {
if (actionEvent.getSource() == cancelBtn) {
int result = JOptionPane.showConfirmDialog(frame, "Are you sure?\nAll unsaved changes will be lost.", "Soundtrack Mod Generator", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (result == JOptionPane.YES_OPTION) {
parent.setEnabled(true);
frame.dispose();
if (!tracklist.isEmpty() || sptrack != null || mptrack != null) {
int result = JOptionPane.showConfirmDialog(frame, "Are you sure?\nAll unsaved changes will be lost.", "Soundtrack Mod Generator", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (result == JOptionPane.NO_OPTION) {return;}
}
} else
if (actionEvent.getSource() == fTitle || actionEvent.getSource() == fArtist) {
tracklist.get(curIndex).title = fTitle.getText();
tracklist.get(curIndex).artist = fArtist.getText();
InitializeSongListInGUI();
dSongList.setSelectedIndex(curIndex);
parent.setEnabled(true);
frame.dispose();
} else
if (actionEvent.getSource() == addSongBtn) {addSong();} else
if (actionEvent.getSource() == deleteSongBtn) {remove(curIndex);} else
@ -182,20 +206,43 @@ public class Suggs implements ActionListener, ListSelectionListener {
@Override
public void valueChanged(ListSelectionEvent listSelectionEvent) {
fTitle.getDocument().removeDocumentListener(id3TagEditorHandler);
fArtist.getDocument().removeDocumentListener(id3TagEditorHandler);
curIndex = dSongList.getSelectedIndex();
if (curIndex >= 0) {
fTitle.setEnabled(true);
fArtist.setEnabled(true);
AudioTrack at = tracklist.get(curIndex);
fTitle.setText(at.title);
fArtist.setText(at.artist);
dTrackNo.setText(String.format("MT_%02d", curIndex+1));
dFileSize.setText((at.size / 1000) + "kb");
dFileSize.setText(at.size + " B");
if (at.size > 1023) {
dFileSize.setText((at.size / 1024) + " KB");
}
if (at.size > 1048575) {
dFileSize.setText((at.size / 1048576) + " MB");
}
fTitle.getDocument().addDocumentListener(id3TagEditorHandler);
fArtist.getDocument().addDocumentListener(id3TagEditorHandler);
} else {
fTitle.setEnabled(false);
fArtist.setEnabled(false);
fTitle.setText("");
fArtist.setText("");
dTrackNo.setText("--");
dFileSize.setText("-kb");
dTrackNo.setText("\u200E");
dFileSize.setText("\u200E");
fTitle.getDocument().addDocumentListener(id3TagEditorHandler);
fArtist.getDocument().addDocumentListener(id3TagEditorHandler);
}
}
private void updateSelectionToMatchTextFields() {
tracklist.get(curIndex).title = fTitle.getText();
tracklist.get(curIndex).artist = fArtist.getText();
InitializeSongListInGUI();
dSongList.setSelectedIndex(curIndex);
}
private void remove(int index) {
if (index >= 0) {
@ -219,6 +266,7 @@ public class Suggs implements ActionListener, ListSelectionListener {
}
private void InitializeSongListInGUI() {
dSongList.removeListSelectionListener(this); // prevent weird bullshit
dSongList.clearSelection();
dSongList.removeAll();
dSongList.setVisibleRowCount(tracklist.size());
@ -228,39 +276,55 @@ public class Suggs implements ActionListener, ListSelectionListener {
int i = 0;
String[] contents = new String[tracklist.size()];
while (i < tracklist.size()) {
String dTitleInList; // avoid editing the actual list
String dArtistInList; // otherwise we cause weird JTextField behavior
if (tracklist.get(i).title == null || tracklist.get(i).title.isEmpty())
{tracklist.get(i).title = tracklist.get(i).path.getName();}
{dTitleInList = tracklist.get(i).path.getName();} else {dTitleInList = tracklist.get(i).title;}
if (tracklist.get(i).artist == null || tracklist.get(i).artist.isEmpty())
{tracklist.get(i).artist = "???";}
contents[i] = tracklist.get(i).artist + " - " + tracklist.get(i).title;
{dArtistInList = "Unknown Artist";} else {dArtistInList = tracklist.get(i).artist;}
contents[i] = dArtistInList + " - " + dTitleInList;
i++;
}
dSongList.setListData(contents);
dSongList.setSelectedIndex(curIndex);
dSongList.setSelectedIndex(curIndex);
dSongList.addListSelectionListener(this);
}
private JFileChooser commonSoundFilePicker(boolean multiselect) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setMultiSelectionEnabled(multiselect);
fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
fileChooser.setFileFilter(new FileNameExtensionFilter("All Compatible Files", "mp3", "ogg", "oga", "opus", "m4a", "3gp", "wav", "wave", "aif", "aiff", "aifc", "flac", "at9"));
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("MPEG Audio Layer 3", "mp3"));
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Ogg Audio", "ogg", "oga", "opus"));
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("AAC or MPEG-4 Audio", "m4a", "3gp"));
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("IBM/Microsoft WAVE", "wav", "wave"));
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Apple AIFF", "aif", "aiff", "aifc"));
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Free Lossless Audio Codec", "flac"));
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Sony ATRAC9", "at9"));
return fileChooser;
}
private void setSPMusic() {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("WAVE", "wav"));
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("ATRAC9", "at9"));
JFileChooser fileChooser = commonSoundFilePicker(false);
int result = fileChooser.showOpenDialog(frame);
if (result == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
sptrack = selectedFile;
dSTitle.setText(selectedFile.getName());
dSSize.setText((selectedFile.length() / 1000) + "kb");
if (result == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
sptrack = selectedFile;
dSTitle.setText(selectedFile.getName());
dSSize.setText(selectedFile.length() + " B");
if (selectedFile.length() > 1023) {
dSSize.setText((selectedFile.length() / 1024) + " KB");
}
if (selectedFile.length() > 1048575) {
dSSize.setText((selectedFile.length() / 1048576) + " MB");
}
}
}
private void setMPMusic() {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("WAVE", "wav"));
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("ATRAC9", "at9"));
JFileChooser fileChooser = commonSoundFilePicker(false);
int result = fileChooser.showOpenDialog(frame);
if (result == JFileChooser.APPROVE_OPTION) {
File selectedFile = fileChooser.getSelectedFile();
@ -271,11 +335,7 @@ public class Suggs implements ActionListener, ListSelectionListener {
}
private void addSong() {
JFileChooser fileChooser = new JFileChooser();
fileChooser.setMultiSelectionEnabled(true);
fileChooser.setCurrentDirectory(new File(System.getProperty("user.home")));
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("WAVE", "wav"));
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("ATRAC9", "at9"));
JFileChooser fileChooser = commonSoundFilePicker(true);
int result = fileChooser.showOpenDialog(frame);
if (result == JFileChooser.APPROVE_OPTION) {
@ -303,23 +363,29 @@ public class Suggs implements ActionListener, ListSelectionListener {
frame.setAlwaysOnTop(false);
Main.deleteDir(new File(System.getProperty("user.home") + "/.firestar/temp/")); // starts with clean temp
new Thread(() -> {
int progressSize = tracklist.size()+(sptrack != null?1:0)+(mptrack != null?1:0)+3; // Accounting for processes
int progressSize = tracklist.size()+(sptrack != null?1:0)+(mptrack != null?1:0)+1; // Accounting for processes
progressDialog = new Scooter();
progressDialog.showDialog("Soundtrack Mod Generator");
progressDialog.setText("Generating audio files...");
progressDialog.setProgressMax(progressSize);
progressDialog.setProgressValue(0);
progressDialog.progressBar.setStringPainted(false);
try {
new File(Main.inpath + "temp/data/audio/music").mkdirs();
FileOutputStream fos = new FileOutputStream(new File(Main.inpath + "temp/fscript"));
PrintStream ps = new PrintStream(fos);
ps.println("fscript 1");
ps.println("# AUTOGENERATED BY FIRESTAR");
new File(Main.inpath + "temp/ffmpeg/").mkdirs();
for (int i = 0; i < tracklist.size(); i++) {
AudioTrack at = tracklist.get(i);
String trackno = String.format("%02d", i+1);
String oTitle;
if (at.title == null) {oTitle = "";} else {oTitle = at.title;}
String oArtist;
if (at.artist == null) {oArtist = "";} else {oArtist = at.artist;}
new File(Main.inpath + "temp/data/audio/music/" + trackno).mkdirs();
if (at.path.getName().endsWith(".at9")) {
progressDialog.setText("Copying track " + (i+1) + " out of " + tracklist.size() + "...");
@ -333,7 +399,12 @@ public class Suggs implements ActionListener, ListSelectionListener {
} else {
progressDialog.setText("Encoding track " + (i+1) + " out of " + tracklist.size() + "...");
try {
System.out.println("Encoding track #" + (i+1) + " \"" + at.artist + " - " + at.title + "\"...");
System.out.println("Encoding track #" + (i+1) + " \"" + oArtist + " - " + oTitle + "\"...");
if (!at.path.getName().endsWith(".wav") && !at.path.getName().endsWith(".wave")) { // convert to WAV first if it's not readable by at9tool yet
Process p = Main.exec(new String[]{Main.inpath + "ffmpeg.exe", "-i", at.path.getPath(), "ffmpeg/" + at.path.getName() + ".wav"}, Main.inpath + "temp/");
p.waitFor();
at.path = new File(Main.inpath + "temp/ffmpeg/" + at.path.getName() + ".wav");
}
Process p = Main.exec(new String[]{Main.inpath + "at9tool.exe", "-e", "-br", "144", at.path.getPath(), "data/audio/music/" + trackno + "/music_stereo.at9"}, Main.inpath + "temp/");
p.waitFor();
} catch (IOException | InterruptedException ex) {
@ -342,7 +413,8 @@ public class Suggs implements ActionListener, ListSelectionListener {
}
String ocmd = "modify";
if (i >= 12) ocmd = "create";
ps.println("file \"data/plugins/languages/american/entries.xml\" xml "+ocmd+" StringTable.entry#MT_"+trackno+" set attribute \"string\" \""+at.artist.replace("\"", "\\\"")+"\\n"+at.title.replace("\"", "\\\"")+"\"");
String oArtistLine = oArtist.replace("\"", "\\\"")+"\\n";
ps.println("file \"data/plugins/languages/american/entries.xml\" xml "+ocmd+" StringTable.entry#MT_"+trackno+" set attribute \"string\" \""+oArtistLine+oTitle.replace("\"", "\\\"")+"\"");
ps.println("file \"data/audio/music/"+trackno+"/music_stereo.fft\" delete");
progressDialog.setProgressValue(i+1);
}
@ -354,6 +426,11 @@ public class Suggs implements ActionListener, ListSelectionListener {
if (sptrack.exists()) {
try {
System.out.println("Encoding singleplayer frontend track...");
if (!sptrack.getName().endsWith(".wav") && !sptrack.getName().endsWith(".wave")) { // convert to WAV first if it's not readable by at9tool yet
Process p = Main.exec(new String[]{Main.inpath + "ffmpeg.exe", "-i", sptrack.getPath(), "ffmpeg/" + sptrack.getName() + ".wav"}, Main.inpath + "temp/");
p.waitFor();
sptrack = new File(Main.inpath + "temp/ffmpeg/" + sptrack.getName() + ".wav");
}
new File(Main.inpath + "temp/data/audio/music/FEMusic").mkdirs();
Process p = Main.exec(new String[]{Main.inpath + "at9tool.exe", "-e", "-br", "144", sptrack.getPath(), "data/audio/music/FEMusic/frontend_stereo.at9"}, System.getProperty("user.home") + "/.firestar/temp/");
p.waitFor();
@ -369,6 +446,11 @@ public class Suggs implements ActionListener, ListSelectionListener {
try {
assert(mptrack.exists());
System.out.println("Encoding multiplayer frontend track...");
if (!mptrack.getName().endsWith(".wav") && !mptrack.getName().endsWith(".wave")) { // convert to WAV first if it's not readable by at9tool yet
Process p = Main.exec(new String[]{Main.inpath + "ffmpeg.exe", "-i", mptrack.getPath(), "ffmpeg/" + mptrack.getName() + ".wav"}, Main.inpath + "temp/");
p.waitFor();
mptrack = new File(Main.inpath + "temp/ffmpeg/" + mptrack.getName() + ".wav");
}
new File(Main.inpath + "temp/data/audio/music/FEDemoMusic").mkdirs();
Process p = Main.exec(new String[]{Main.inpath + "at9tool.exe", "-e", "-br", "144", mptrack.getPath(), "data/audio/music/FEDemoMusic/frontend_stereo.at9"}, System.getProperty("user.home") + "/.firestar/temp/");
p.waitFor();
@ -438,6 +520,7 @@ public class Suggs implements ActionListener, ListSelectionListener {
progressDialog.destroyDialog();
frame.dispose();
Main.deleteDir(new File(Main.inpath + "temp/ffmpeg/"));
Clifford saveDialog = new Clifford();
saveDialog.isSoundtrack = true;
saveDialog.Action(frame, new File(Main.inpath + "temp/"));