Skip to content

Commit

Permalink
A bit more work in the SNP/XNT parser
Browse files Browse the repository at this point in the history
It seems that the initial tempo is in the xne file and not in the xml file :/
  • Loading branch information
mrcdk committed Jan 28, 2012
1 parent 2c0823f commit 7577e5e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
13 changes: 5 additions & 8 deletions parsers/src/org/open2jam/parsers/SNPParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
*/
public class SNPParser {

/** the signature , "VDISK1.0" in little endian */
private static final int SNP2_SIGNATURE = 0x302E314B;
//private static final int SNP_SIGNATURE = 0x302E314B53494456;
/** the signature, "VDISK1.0" in little endian */
private static final long SNP_SIGNATURE = 0x302E314B53494456L;

private static final int VDISK_HEADER = 24;
private static final int FILE_HEADER = 145;
Expand Down Expand Up @@ -79,10 +78,7 @@ public static ChartList parseFile(File file)

buffer.order(ByteOrder.LITTLE_ENDIAN);

//TODO FIX THIS
buffer.getInt();

if(buffer.getInt() != SNP2_SIGNATURE)
if(buffer.getLong() != SNP_SIGNATURE)
{
Logger.global.log(Level.WARNING, "This isn't a snp file you! {0}", file.getName());
return null;
Expand All @@ -104,11 +100,12 @@ public static ChartList parseFile(File file)
if(fh.isDir < 1) //DO NOT WANT DIRS D:
file_index.put(fh.file_name, fh); //add the file


if(fh.size_packed > 0 && fh.file_name.trim().endsWith(".xnt"))
{
XNTChart chart = new XNTChart();
//TODO Change this with the info in the xml
chart.xnt_filename = fh.file_name.trim();
chart.xne_filename = fh.file_name.trim().substring(0, fh.file_name.trim().lastIndexOf("."))+".xne";
//TODO read the krazyrain.xml file and get the info so we can
//fill with all the data
list.add(chart);
Expand Down
2 changes: 1 addition & 1 deletion parsers/src/org/open2jam/parsers/XNTChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.open2jam.parsers.utils.AudioData;
Expand All @@ -21,6 +20,7 @@ public class XNTChart extends Chart {
Map<String, SNPParser.SNPFileHeader> file_index;

String xnt_filename;
String xne_filename;

Map<Integer, String> samples_index;

Expand Down
21 changes: 17 additions & 4 deletions parsers/src/org/open2jam/parsers/XNTParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,27 @@ public static List<Event> parseChart(XNTChart chart)
SNPFileHeader fh;
try{
f = new RandomAccessFile(chart.source.getAbsolutePath(),"r");
//First, the xne file
if(!chart.file_index.containsKey(chart.xne_filename))
{
Logger.global.log(Level.WARNING, "Where is my xne file? {0}", chart.source.getName());
return null;
}

fh = chart.file_index.get(chart.xne_filename);
buffer = SNPParser.extract(fh, f);
String xne = new String(buffer.array());
String tempo = xne.toLowerCase().split("tempo=\"")[1].split("\"")[0];
//this is the real BPM, the xml bpm isn't it :/
list.add(new Event(Event.Channel.BPM_CHANGE,0,0,Float.parseFloat(tempo),Event.Flag.NONE));

//Then, the xnt file
if(!chart.file_index.containsKey(chart.xnt_filename))
{
Logger.global.log(Level.WARNING, "Where is my xnt file? {0}", chart.source.getName());
return null;
}

fh = chart.file_index.get(chart.xnt_filename);
buffer = SNPParser.extract(fh, f);
}catch(IOException e){
Expand Down Expand Up @@ -64,6 +80,7 @@ public static List<Event> parseChart(XNTChart chart)

chart.samples_index = readSamples(buffer);

Collections.sort(list);
return list;
}

Expand Down Expand Up @@ -118,8 +135,6 @@ private static void readNoteBlock(List<Event> list, ByteBuffer buffer, boolean b
}

}

Collections.sort(list);
}

private static void readBPMChange(List<Event> list, ByteBuffer buffer)
Expand All @@ -138,8 +153,6 @@ private static void readBPMChange(List<Event> list, ByteBuffer buffer)

list.add(new Event(Event.Channel.BPM_CHANGE, measure, position, bpm, Event.Flag.NONE));
}

Collections.sort(list);
}

private static HashMap<Integer, String> readSamples(ByteBuffer buffer)
Expand Down

0 comments on commit 7577e5e

Please sign in to comment.