Skip to content

Commit 5f5c145

Browse files
committed
Fix drum lane mid -> rbmid conversion to limit the number of lanes
Untested compile, trying appveyor
1 parent 331e48d commit 5f5c145

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

LibForge/LibForge/Midi/RBMid.cs

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public struct MARKER {
8383
public uint StartTick;
8484
public uint EndTick;
8585
public int Lanes;
86+
// added to keep track of rb3 -> rb4 lane conversion
87+
public int MidiLaneCount;
8688
}
8789
// First dimension: difficulty
8890
public MARKER[][] Markers;

LibForge/LibForge/Midi/RBMidConverter.cs

+17-4
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,22 @@ bool AddGem(MidiNote e)
428428
return false;
429429
}
430430

431-
if (diff == 3 && rolls.Count > 0 && rolls[rolls.Count - 1].EndTick > e.StartTicks && lane != 0 /* MT: don't emit kick lanes */)
431+
if (diff == 3 && rolls.Count > 0 && rolls[rolls.Count - 1].EndTick > e.StartTicks && lane != 0 /* don't emit kick lanes */)
432432
{
433433
var tmp = rolls[rolls.Count - 1];
434-
tmp.Lanes |= 1 << lane;
434+
// see if any more colors need to be added to this lane
435+
int CurrentLaneCount = 0;
436+
int n = tmp.Lanes;
437+
// count set bits in tmp.Lanes (by MAK, https://stackoverflow.com/a/2709482)
438+
while (n != 0)
439+
{
440+
n &= (n - 1);
441+
CurrentLaneCount++;
442+
}
443+
if (CurrentLaneCount < tmp.MidiLaneCount)
444+
{
445+
tmp.Lanes |= 1 << lane;
446+
}
435447
rolls[rolls.Count - 1] = tmp;
436448
}
437449
if (gem_tracks[diff] == null) gem_tracks[diff] = new List<RBMid.GEMTRACK.GEM>();
@@ -523,7 +535,8 @@ bool AddGem(MidiNote e)
523535
{
524536
StartTick = e.StartTicks,
525537
EndTick = e.StartTicks + e.LengthTicks,
526-
Lanes = 0
538+
Lanes = 0,
539+
MidiLaneCount = (e.Key == Roll1 ? 1 : 2)
527540
});
528541
}
529542
else if (e.Key == 105 || e.Key == 106 || e.Key == 12 || e.Key == 13 || e.Key == 14 || e.Key == 15)
@@ -579,7 +592,7 @@ bool AddGem(MidiNote e)
579592
{
580593
new RBMid.LANEMARKER.MARKER[0],
581594
new RBMid.LANEMARKER.MARKER[0],
582-
new RBMid.LANEMARKER.MARKER[0],
595+
new RBMid.LANEMARKER.MARKER[0], // TODO rb3 midi lanes can be applied to hard if velocity is low enough
583596
rolls.ToArray()
584597
}
585598
});

LibForge/LibForge/Midi/RBMidReader.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ public override RBMid Read()
130130
{
131131
StartTick = UInt(),
132132
EndTick = UInt(),
133-
Lanes = Int()
133+
Lanes = Int(),
134+
MidiLaneCount = 0
134135
}))
135136
};
136137
private RBMid.GTRTRILLS ReadUnktrack2() => new RBMid.GTRTRILLS

0 commit comments

Comments
 (0)