Add in more QoL features, threading for loading maps. Drag-and-drop
importing for maps.
This commit is contained in:
parent
72650e875c
commit
947b604e81
Binary file not shown.
@ -4,8 +4,30 @@ import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.SwingWorker;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
|
||||
class Task extends SwingWorker<Void,Void>{
|
||||
File f;
|
||||
Task(File f) {
|
||||
this.f=f;
|
||||
}
|
||||
/*
|
||||
* Main task. Executed in background thread.
|
||||
*/
|
||||
@Override
|
||||
public Void doInBackground() {
|
||||
ListItem temp = new ListItem(f);
|
||||
if (!temp.failed) {
|
||||
osuMapCombiner.model.addElement(temp);
|
||||
if (osuMapCombiner.model.getSize()>=2) {
|
||||
osuMapCombiner.main.button2.setEnabled(true);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class AddMap {
|
||||
JFileChooser chooser = new JFileChooser();
|
||||
|
||||
@ -19,14 +41,13 @@ public class AddMap {
|
||||
public void openDialog() {
|
||||
int val = chooser.showOpenDialog(null);
|
||||
if (val==JFileChooser.APPROVE_OPTION) {
|
||||
ListItem temp = new ListItem(chooser.getSelectedFile());
|
||||
if (!temp.failed) {
|
||||
osuMapCombiner.model.addElement(temp);
|
||||
if (osuMapCombiner.model.getSize()>=2) {
|
||||
osuMapCombiner.main.button2.setEnabled(true);
|
||||
}
|
||||
}
|
||||
AddMap(chooser.getSelectedFile());
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddMap(File f) {
|
||||
Task task = new Task(f);
|
||||
task.execute();
|
||||
}
|
||||
|
||||
}
|
@ -155,8 +155,10 @@ BeatmapSetID:-1
|
||||
*
|
||||
*/
|
||||
marathonMap.add("[Events]");
|
||||
marathonMap.add("//Background and Video events\r\n" +
|
||||
"//Break Periods\r\n");
|
||||
marathonMap.add("//Background and Video events\r\n");
|
||||
ListItem firstmap = maps.get(0);
|
||||
marathonMap.add("0,0,\""+firstmap.songTitle+"_BG.png\"");
|
||||
marathonMap.add("//Break Periods\r\n");
|
||||
|
||||
timePoint=0;
|
||||
remainder=0;
|
||||
@ -187,8 +189,24 @@ BeatmapSetID:-1
|
||||
}
|
||||
int breaksEndIndex = marathonMap.size()-1; // Store the last break so we can append to it a little later.
|
||||
|
||||
marathonMap.add("//Storyboard Layer 0 (Background)\r\n" +
|
||||
"//Storyboard Layer 1 (Fail)\r\n" +
|
||||
marathonMap.add("//Storyboard Layer 0 (Background)\r\n");
|
||||
timePoint=firstmap.songDuration;
|
||||
remainder=0;
|
||||
for (int i=1;i<maps.size();i++) {
|
||||
ListItem map = maps.get(i);
|
||||
while (remainder>=1) {
|
||||
timePoint++;
|
||||
remainder--;
|
||||
}
|
||||
|
||||
marathonMap.add("Sprite,Background,Centre,\""+map.songTitle+"_BG.png\",320,240");
|
||||
marathonMap.add(" F,0,"+(int)(timePoint-5000)+","+(int)(timePoint)+",0,1");
|
||||
marathonMap.add(" F,0,"+(int)(timePoint)+","+(int)(timePoint+map.songDuration-5000)+",1");
|
||||
marathonMap.add(" F,0,"+(int)(timePoint+map.songDuration-5000)+","+(int)(timePoint+map.songDuration)+",1,0");
|
||||
|
||||
timePoint += map.songDuration;
|
||||
}
|
||||
marathonMap.add("//Storyboard Layer 1 (Fail)\r\n" +
|
||||
"//Storyboard Layer 2 (Pass)\r\n" +
|
||||
"//Storyboard Layer 3 (Foreground)\r\n" +
|
||||
"//Storyboard Layer 4 (Overlay)\r\n" +
|
||||
@ -276,6 +294,9 @@ BeatmapSetID:-1
|
||||
File filer = new File(maps.get(i).songLoc.getName());
|
||||
utils.copyFile(maps.get(i).songLoc, filer);
|
||||
filer.deleteOnExit();
|
||||
filer = new File(maps.get(i).songTitle+"_BG.png");
|
||||
utils.copyFile(filer, new File(targetDir,maps.get(i).songTitle+"_BG.png"));
|
||||
filer.deleteOnExit();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ public class ListItem{
|
||||
String songTitle;
|
||||
File file;
|
||||
File songLoc;
|
||||
File bgloc;
|
||||
double songDuration=0;
|
||||
double hpDrainRate=7;
|
||||
double circleSize=7;
|
||||
@ -30,7 +31,12 @@ public class ListItem{
|
||||
List<String> breaks;
|
||||
boolean failed=false;
|
||||
public ListItem(File f) {
|
||||
|
||||
final int taskAmt = 5;
|
||||
osuMapCombiner.updateProgressBarAmt(0,5);
|
||||
|
||||
//this.songTitle=s;
|
||||
this.file=f;
|
||||
timingPoints = new ArrayList<String>();
|
||||
hitObjects = new ArrayList<String>();
|
||||
breaks = new ArrayList<String>();
|
||||
@ -41,7 +47,8 @@ public class ListItem{
|
||||
int i =0 ;
|
||||
|
||||
String targetString = "AudioFilename: ";
|
||||
|
||||
///////
|
||||
osuMapCombiner.updateProgressBarAmt(1,5);
|
||||
do {
|
||||
line = data[i++];
|
||||
} while (!line.contains(targetString));
|
||||
@ -49,9 +56,28 @@ public class ListItem{
|
||||
System.out.println("SongLoc: "+songLoc);
|
||||
|
||||
File filer = new File(songTitle.replace(".osu", ".mp3"));
|
||||
if (!new File(songTitle.replace(".osu", ".mp3")).exists()) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
|
||||
String command = "ffmpeg -i \""+songLoc.getAbsolutePath()+"\" -f mp3 -b:a 128k -ar 44100 -ac 2 \""+songTitle.replace(".osu", ".mp3")+"\"";
|
||||
CommandLine cmdLine = CommandLine.parse(command);
|
||||
DefaultExecutor exec = new DefaultExecutor();
|
||||
exec.setStreamHandler(streamHandler);
|
||||
try {
|
||||
exec.execute(cmdLine);
|
||||
//System.out.println(filer.getName()+": "+mp3utils.GetSongDuration(filer.getAbsolutePath()));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
filer.deleteOnExit();
|
||||
|
||||
ParseTimestamp(outputStream);
|
||||
}
|
||||
//////
|
||||
osuMapCombiner.updateProgressBarAmt(2,5);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
|
||||
String command = "ffmpeg -i \""+songLoc.getAbsolutePath()+"\" -f mp3 -b:a 128k -ar 44100 -ac 2 \""+songTitle.replace(".osu", ".mp3")+"\"";
|
||||
String command = "ffmpeg -i \""+songTitle.replace(".osu", ".mp3")+"\"";
|
||||
CommandLine cmdLine = CommandLine.parse(command);
|
||||
DefaultExecutor exec = new DefaultExecutor();
|
||||
exec.setStreamHandler(streamHandler);
|
||||
@ -61,24 +87,19 @@ public class ListItem{
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
filer.deleteOnExit();
|
||||
|
||||
String[] data2 = outputStream.toString().split("\n");
|
||||
for (int h=0;h<data2.length;h++) {
|
||||
if (data2[h].contains("Duration:")) {
|
||||
String[] s = data2[h].split(",");
|
||||
String timestamp = s[0].replace("Duration: ", "").trim();
|
||||
String[] timestamp_s = timestamp.split(":");
|
||||
int hrs = Integer.parseInt(timestamp_s[0]);
|
||||
int min = Integer.parseInt(timestamp_s[1]);
|
||||
double sec = Double.parseDouble(timestamp_s[2]);
|
||||
|
||||
songDuration += hrs*60*60*1000;
|
||||
songDuration += min*60*1000;
|
||||
songDuration += sec*1000;
|
||||
}
|
||||
ParseTimestamp(outputStream);
|
||||
//////
|
||||
osuMapCombiner.updateProgressBarAmt(3,5);
|
||||
command = "mp3val \""+songTitle.replace(".osu", ".mp3")+"\" -f -nb";
|
||||
cmdLine = CommandLine.parse(command);
|
||||
exec = new DefaultExecutor();
|
||||
try {
|
||||
exec.execute(cmdLine);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//////
|
||||
osuMapCombiner.updateProgressBarAmt(4,5);
|
||||
osuMapCombiner.duration += songDuration;
|
||||
//osuMapCombiner.duration += songDuration = mp3utils.GetSongDuration(songLoc.getAbsolutePath());
|
||||
System.out.println("Song duration of "+songTitle+" : "+songDuration+"ms");
|
||||
@ -133,6 +154,20 @@ public class ListItem{
|
||||
if (line.trim().length()>3) {
|
||||
if (line.trim().startsWith("2,") && line.split(",").length==3) {
|
||||
breaks.add(line);
|
||||
} else
|
||||
if (line.trim().startsWith("0,0,")/* && line.split(",").length==5*/) {
|
||||
bgloc = new File(f.getParent()+File.separatorChar+line.split(",")[2].replace("\"", ""));
|
||||
try {
|
||||
utils.copyFile(bgloc, new File(songTitle+"_BG.png"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//System.out.println("Background location found: "+bgloc);
|
||||
/*File temp = new File(songTitle.split(".")[0]);
|
||||
System.out.println(temp.getAbsolutePath());
|
||||
if (!(temp.exists())) {
|
||||
System.out.println("Does not exist");
|
||||
}*/
|
||||
}
|
||||
}
|
||||
} while (line.trim().length()>3);
|
||||
@ -165,6 +200,26 @@ public class ListItem{
|
||||
}
|
||||
}
|
||||
} while (i<data.length && line.trim().length()>3);
|
||||
////////
|
||||
osuMapCombiner.updateProgressBarAmt(5,5);
|
||||
}
|
||||
private void ParseTimestamp(ByteArrayOutputStream outputStream) {
|
||||
String[] data2 = outputStream.toString().split("\n");
|
||||
songDuration=0;
|
||||
for (int h=0;h<data2.length;h++) {
|
||||
if (data2[h].contains("Duration:")) {
|
||||
String[] s = data2[h].split(",");
|
||||
String timestamp = s[0].replace("Duration: ", "").trim();
|
||||
String[] timestamp_s = timestamp.split(":");
|
||||
int hrs = Integer.parseInt(timestamp_s[0]);
|
||||
int min = Integer.parseInt(timestamp_s[1]);
|
||||
double sec = Double.parseDouble(timestamp_s[2]);
|
||||
|
||||
songDuration += hrs*60*60*1000;
|
||||
songDuration += min*60*1000;
|
||||
songDuration += sec*1000;
|
||||
}
|
||||
}
|
||||
}
|
||||
public String getData() {
|
||||
return songTitle;
|
||||
|
@ -3,7 +3,9 @@ package osuMapCombiner;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JComponent;
|
||||
@ -20,8 +22,7 @@ public class ListTransferHandler extends TransferHandler {
|
||||
* We only support importing strings.
|
||||
*/
|
||||
public boolean canImport(TransferHandler.TransferSupport info) {
|
||||
// Check for String flavor
|
||||
if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
|
||||
if (!info.isDataFlavorSupported(DataFlavor.stringFlavor) && !info.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -73,6 +74,19 @@ public class ListTransferHandler extends TransferHandler {
|
||||
JList.DropLocation dl = (JList.DropLocation)info.getDropLocation();
|
||||
int index = dl.getIndex();
|
||||
boolean insert = dl.isInsert();
|
||||
|
||||
//Try to get a file.
|
||||
List l;
|
||||
try {
|
||||
l = (List)info.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
|
||||
for (int i=0;i<l.size();i++) {
|
||||
//System.out.println(l.get(i));
|
||||
//Attempt to import each file.
|
||||
AddMap.AddMap((File)l.get(i));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (Exception e) {}
|
||||
|
||||
// Get the string that is being dropped.
|
||||
Transferable t = info.getTransferable();
|
||||
|
@ -10,6 +10,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.swing.Box;
|
||||
@ -21,9 +22,12 @@ import javax.swing.JFrame;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import javax.swing.ScrollPaneConstants;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import org.apache.commons.exec.CommandLine;
|
||||
import org.apache.commons.exec.DefaultExecutor;
|
||||
@ -32,7 +36,7 @@ import javazoom.jl.decoder.Bitstream;
|
||||
import javazoom.jl.decoder.BitstreamException;
|
||||
import javazoom.jl.decoder.Header;
|
||||
|
||||
public class osuMapCombiner extends JPanel implements ActionListener{
|
||||
public class osuMapCombiner extends JPanel implements ActionListener, ListSelectionListener{
|
||||
|
||||
AddMap mapdialog = new AddMap();
|
||||
public static DefaultListModel model = new DefaultListModel();
|
||||
@ -43,6 +47,9 @@ public class osuMapCombiner extends JPanel implements ActionListener{
|
||||
public static osuMapCombiner main;
|
||||
public JButton button = new JButton("+");
|
||||
public JButton button2 = new JButton("Combine");
|
||||
public JButton button3 = new JButton("Remove");
|
||||
public JButton button4 = new JButton("Duplicate");
|
||||
public static JProgressBar progressBar = new JProgressBar();
|
||||
|
||||
osuMapCombiner() {
|
||||
osuMapCombiner.main = this;
|
||||
@ -54,7 +61,8 @@ public class osuMapCombiner extends JPanel implements ActionListener{
|
||||
l.setDropMode(DropMode.INSERT);
|
||||
l.setTransferHandler(new ListTransferHandler());
|
||||
|
||||
l.setPreferredSize(new Dimension(280,400));
|
||||
l.setPreferredSize(new Dimension(280,360));
|
||||
l.addListSelectionListener(this);
|
||||
|
||||
Component c = Box.createRigidArea(new Dimension(240,32));
|
||||
|
||||
@ -64,6 +72,18 @@ public class osuMapCombiner extends JPanel implements ActionListener{
|
||||
button2.setActionCommand("Combine");
|
||||
button2.setPreferredSize(new Dimension(360,24));
|
||||
button2.addActionListener(this);
|
||||
button3.setActionCommand("Remove");
|
||||
button3.setPreferredSize(new Dimension(120,24));
|
||||
button3.addActionListener(this);
|
||||
button3.setEnabled(false);
|
||||
button4.setActionCommand("Duplicate");
|
||||
button4.setPreferredSize(new Dimension(120,24));
|
||||
button4.addActionListener(this);
|
||||
button4.setEnabled(false);
|
||||
|
||||
progressBar.setStringPainted(true);
|
||||
progressBar.setValue(0);
|
||||
progressBar.setSize(240, 32);
|
||||
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
f.setResizable(false);
|
||||
@ -73,7 +93,10 @@ public class osuMapCombiner extends JPanel implements ActionListener{
|
||||
f.setLayout(layout);
|
||||
|
||||
f.add(l);
|
||||
f.add(c);
|
||||
f.add(button3);
|
||||
f.add(button4);
|
||||
//f.add(c);
|
||||
f.add(progressBar);
|
||||
f.add(button);
|
||||
f.add(button2);
|
||||
f.pack();
|
||||
@ -84,7 +107,11 @@ public class osuMapCombiner extends JPanel implements ActionListener{
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
osuMapCombiner program = new osuMapCombiner();
|
||||
javax.swing.SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
osuMapCombiner program = new osuMapCombiner();
|
||||
}
|
||||
});
|
||||
/*
|
||||
* DETECT SONG DURATION
|
||||
Header h = null;
|
||||
@ -127,6 +154,17 @@ public class osuMapCombiner extends JPanel implements ActionListener{
|
||||
case "Add": {
|
||||
mapdialog.openDialog();
|
||||
}break;
|
||||
case "Duplicate": {
|
||||
for (int i=0;i<l.getSelectedIndices().length;i++) {
|
||||
AddMap.AddMap(((ListItem)model.getElementAt(l.getSelectedIndices()[i])).file);
|
||||
}
|
||||
}break;
|
||||
case "Remove": {
|
||||
for (int i=0;i<l.getSelectedIndices().length;i++) {
|
||||
//System.out.println(Arrays.toString(l.getSelectedIndices()));
|
||||
model.removeElementAt(l.getSelectedIndices()[i--]);
|
||||
}
|
||||
}break;
|
||||
case "Combine":{
|
||||
if (model.getSize()>=2) {
|
||||
int pane = JOptionPane.showConfirmDialog(f,"A marathon map with all "+model.getSize()+" maps will be created. The total duration of the marathon map will be "+
|
||||
@ -142,4 +180,16 @@ public class osuMapCombiner extends JPanel implements ActionListener{
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
button3.setEnabled(l.getSelectedIndex()!=-1);
|
||||
button4.setEnabled(l.getSelectedIndex()!=-1);
|
||||
}
|
||||
|
||||
public static void updateProgressBarAmt(int i, int j) {
|
||||
progressBar.setMaximum(j);
|
||||
progressBar.setMinimum(0);
|
||||
progressBar.setValue(i);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user