Skip to content

Commit

Permalink
Should fix the following problems in issue #18:
Browse files Browse the repository at this point in the history
* Added STOP to bms files
* Time signature should be fixed
  • Loading branch information
mrcdk committed Jun 2, 2012
1 parent 5c35cac commit 24f232b
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 31 deletions.
6 changes: 5 additions & 1 deletion parsers/src/org/open2jam/parsers/BMSChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@
import org.open2jam.parsers.utils.SampleData;

public class BMSChart extends Chart
{
{
int lntype;
int lnobj;

boolean o2mania_style;

public BMSChart() {
type = TYPE.BMS;
}

public File getSource() {
return source;
Expand Down
73 changes: 50 additions & 23 deletions parsers/src/org/open2jam/parsers/BMSParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class BMSParser

private static final Pattern note_line = Pattern.compile("^#(\\d\\d\\d)(\\d\\d):(.+)$");
private static final Pattern bpm_line = Pattern.compile("^#BPM(\\w\\w)\\s+(.+)$");
private static final Pattern stop_line = Pattern.compile("^#STOP(\\w\\w)\\s+(.+)$");

private static final FileFilter bms_filter = new FileFilter(){
public boolean accept(File f){
Expand Down Expand Up @@ -242,36 +243,51 @@ public static EventList parseChart(BMSChart chart)
}

HashMap<Integer, Double> bpm_map = new HashMap<Integer, Double>();
HashMap<Integer, Integer> stop_map = new HashMap<Integer, Integer>();
HashMap<Integer, Boolean> ln_buffer = new HashMap<Integer, Boolean>();
HashMap<Integer, Event> lnobj_buffer = new HashMap<Integer, Event>();

//This will help us to sort the lines by measure
Map<Integer, List<String>> lines = new TreeMap<Integer, List<String>>();

try {
while ((line = r.readLine()) != null) {
line = line.trim().toUpperCase();
if (!line.startsWith("#"))continue;
try {
while ((line = r.readLine()) != null) {
line = line.trim().toUpperCase();
if (!line.startsWith("#")) {
continue;
}

Matcher matcher = note_line.matcher(line);
if (!matcher.find()) {
Matcher bpm_match = bpm_line.matcher(line);
if (bpm_match.find()) {
int code = Integer.parseInt(bpm_match.group(1), 36);
double value = Double.parseDouble(bpm_match.group(2).replace(",", "."));
bpm_map.put(code, value);
}
continue;
}
int measure = Integer.parseInt(matcher.group(1));
Matcher matcher = note_line.matcher(line);
if (!matcher.find()) {
if (line.startsWith("#BPM")) {
Matcher bpm_match = bpm_line.matcher(line);
if (bpm_match.find()) {
int code = Integer.parseInt(bpm_match.group(1), 36);
double value = Double.parseDouble(bpm_match.group(2).replace(",", "."));
bpm_map.put(code, value);
}
} else if (line.startsWith(("#STOP"))) {
Matcher stop_match = stop_line.matcher(line);
if (stop_match.find()) {
int code = Integer.parseInt(stop_match.group(1), 36);
int value = Integer.parseInt(stop_match.group(2));
stop_map.put(code, value);
}
}

continue;
}

int measure = Integer.parseInt(matcher.group(1));
//Let's add the line
if(!lines.containsKey(measure))
if (!lines.containsKey(measure)) {
lines.put(measure, new ArrayList<String>());
}
lines.get(measure).add(line);
}
} catch (IOException ex) {
Logger.global.log(Level.SEVERE, null, ex);
}
}
} catch (IOException ex) {
Logger.global.log(Level.SEVERE, null, ex);
}

Iterator<List<String>> it = lines.values().iterator();
//now iterate by all the lines and add the events
Expand All @@ -289,7 +305,8 @@ public static EventList parseChart(BMSChart chart)
continue;
}
String[] events = matcher.group(3).split("(?<=\\G.{2})");
if (channel == 3) {

if (channel == 3) { //INLINE BPM CHANGE
for (int i = 0; i < events.length; i++) {
int value = Integer.parseInt(events[i], 16);
if (value == 0) {
Expand All @@ -299,7 +316,7 @@ public static EventList parseChart(BMSChart chart)
event_list.add(new Event(Event.Channel.BPM_CHANGE, measure, p, value, Event.Flag.NONE));
}
continue;
} else if (channel == 8) {
} else if (channel == 8) { //BPM TAG BPM CHANGE
for (int i = 0; i < events.length; i++) {
if (events[i].equals("00")) {
continue;
Expand All @@ -309,7 +326,7 @@ public static EventList parseChart(BMSChart chart)
event_list.add(new Event(Event.Channel.BPM_CHANGE, measure, p, value, Event.Flag.NONE));
}
continue;
} else if (channel == 4) {
} else if (channel == 4) { //BGA DATA
for (int i = 0; i < events.length; i++) {
int value = Integer.parseInt(events[i], 36);
if (value == 0) {
Expand All @@ -319,6 +336,16 @@ public static EventList parseChart(BMSChart chart)
event_list.add(new Event(Event.Channel.BGA, measure, p, value, Event.Flag.NONE));
}
continue;
} else if (channel == 9) { //STOP DATA
for (int i = 0; i < events.length; i++) {
if (events[i].equals("00")) {
continue;
}
double value = stop_map.get(Integer.parseInt(events[i], 36));
double p = ((double) i) / events.length;
event_list.add(new Event(Event.Channel.STOP, measure, p, value, Event.Flag.NONE));
}
continue;
}
Event.Channel ec;
if (chart.o2mania_style) {
Expand Down
4 changes: 4 additions & 0 deletions parsers/src/org/open2jam/parsers/Chart.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
*/
public abstract class Chart implements Comparable<Chart>, java.io.Serializable
{
public static enum TYPE {NONE, BMS, OJN, SM, XNT};

public TYPE type = TYPE.NONE;

protected File source;
protected int level = 0;
protected int keys = 7;
Expand Down
15 changes: 14 additions & 1 deletion parsers/src/org/open2jam/parsers/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,20 @@ public Event(Channel channel, int measure, double position,
}

public int compareTo(Event e) {
return ((measure + position) < (e.getMeasure() + e.getPosition())) ? -1 : 1;
double a = measure + position;
double b = e.getMeasure() + e.getPosition();

if (a < b) {
return -1;
} else if (a == b) {
if (channel == Channel.STOP) {
return 1;
}
return 0;
} else {
return 1;
}

}

public void setChannel(Channel chan) {
Expand Down
6 changes: 5 additions & 1 deletion parsers/src/org/open2jam/parsers/OJNChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public class OJNChart extends Chart {
int note_offset_end;
int cover_offset;
int cover_size;


public OJNChart() {
type = TYPE.OJN;
}

public File getSource() {
return source;
}
Expand Down
4 changes: 4 additions & 0 deletions parsers/src/org/open2jam/parsers/SMChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

public class SMChart extends Chart {

public SMChart() {
type = TYPE.SM;
}

public File getSource() {
return source;
}
Expand Down
6 changes: 5 additions & 1 deletion parsers/src/org/open2jam/parsers/XNTChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
public class XNTChart extends Chart {

Map<String, SNPParser.SNPFileHeader> file_index;


public XNTChart() {
type = TYPE.XNT;
}

String xnt_filename = "";
public String getXNTFile() {
return xnt_filename;
Expand Down
21 changes: 17 additions & 4 deletions src/org/open2jam/render/Render.java
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public void frameRendering()
if(SoundManager.isPlaying(source)){
last_sound.clear();
return;
}
}
}
// all sources have finished playing
window.destroy();
Expand Down Expand Up @@ -933,13 +933,18 @@ private EventList construct_velocity_tree(EventList list)
double my_note_speed = (my_bpm * measure_size) / BEATS_PER_MSEC;

EventList new_list = new EventList();

//there is always a 1st measure
Event m = new Event(Event.Channel.MEASURE, measure, 0, 0, Event.Flag.NONE);
m.setTime(timer);
new_list.add(m);

for(Event e : list)
{
while(e.getMeasure() > measure)
{
timer += (BEATS_PER_MSEC * (frac_measure-measure_pointer)) / my_bpm;
Event m = new Event(Event.Channel.MEASURE, measure, 0, 0, Event.Flag.NONE);
m = new Event(Event.Channel.MEASURE, measure, 0, 0, Event.Flag.NONE);
m.setTime(timer);
new_list.add(m);
measure++;
Expand All @@ -954,8 +959,16 @@ private EventList construct_velocity_tree(EventList list)
{
case STOP:
velocity_tree.addInterval(last_bpm_change, timer, my_note_speed);
velocity_tree.addInterval(timer, timer+e.getValue(), 0d);
last_bpm_change = timer = timer + e.getValue();
double stop_time = e.getValue();
if(chart.type == Chart.TYPE.BMS) {
//convert the bms stop values to a time value
stop_time = (e.getValue() / 192) * BEATS_PER_MSEC / my_bpm;
System.out.println(stop_time);
velocity_tree.addInterval(timer, timer+stop_time, 0d);
} else {
velocity_tree.addInterval(timer, timer+stop_time, 0d);
}
last_bpm_change = timer = timer + stop_time;
break;
case BPM_CHANGE:
velocity_tree.addInterval(last_bpm_change, timer, my_note_speed);
Expand Down

0 comments on commit 24f232b

Please sign in to comment.