Skip to content

Commit

Permalink
Fix issue with instrument type reading, change format slightly
Browse files Browse the repository at this point in the history
Reduce the size of some things and reorder a few bytes
  • Loading branch information
mdsitton committed May 20, 2022
1 parent 0ed04e0 commit 41ebab6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
20 changes: 10 additions & 10 deletions BChartConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ public static class DrumNotes
public const uint NOTE_MOD_KICK_2 = 8;
}

public const uint INSTRUMENT_GUITAR = 0;
public const uint INSTRUMENT_GUITAR_SIX = 1;
public const uint INSTRUMENT_BASS = 2;
public const uint INSTRUMENT_BASS_SIX = 3;
public const uint INSTRUMENT_RHYTHM = 4;
public const uint INSTRUMENT_COOP = 5;
public const uint INSTRUMENT_KEYS = 6;
public const uint INSTRUMENT_DRUMS = 7;
public const uint INSTRUMENT_VOCALS = 8;
public const uint INSTRUMENT_UKN = 0xFFFF;
public const byte INSTRUMENT_GUITAR = 0;
public const byte INSTRUMENT_GUITAR_SIX = 1;
public const byte INSTRUMENT_BASS = 2;
public const byte INSTRUMENT_BASS_SIX = 3;
public const byte INSTRUMENT_RHYTHM = 4;
public const byte INSTRUMENT_COOP = 5;
public const byte INSTRUMENT_KEYS = 6;
public const byte INSTRUMENT_DRUMS = 7;
public const byte INSTRUMENT_VOCALS = 8;
public const byte INSTRUMENT_UKN = 0xFF;

public static uint HeaderChunkName = BChartUtils.GetChunkNameToInt("BCHF");
public static uint TempoChunkName = BChartUtils.GetChunkNameToInt("SYNC");
Expand Down
5 changes: 4 additions & 1 deletion BChartReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ public static void ReadDifficulty(Span<byte> data, Song song, Instrument inst)
public static (Instrument inst, byte count) ReadInstrument(Span<byte> data)
{
int pos = 0;
return ((Instrument)data.ReadUInt32LE(ref pos), data.ReadByte(ref pos));
Instrument inst = BChartUtils.BChartToMoonInstrument(data.ReadByte(ref pos));
byte count = data.ReadByte(ref pos);

return (inst, count);
}

public static Song ReadBChart(string path)
Expand Down
23 changes: 22 additions & 1 deletion BChartUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static Difficulty BChartToMoonDiff(byte difficulty)
/// </summary>
/// <param name="instrument">Moonscraper instrument enum</param>
/// <returns>BChart output instrument id</returns>
public static uint MoonInstrumentToBChart(Instrument instrument)
public static byte MoonInstrumentToBChart(Instrument instrument)
{
return instrument switch
{
Expand All @@ -116,6 +116,27 @@ public static uint MoonInstrumentToBChart(Instrument instrument)
};
}

/// <summary>
/// Convert bchart instrument track id to the moonscraper instrument enum
/// </summary>
/// <param name="instrument">BChart instrument id</param>
/// <returns>Moonscraper instrument enum</returns>
public static Instrument BChartToMoonInstrument(byte instrument)
{
return instrument switch
{
BChartConsts.INSTRUMENT_GUITAR => Instrument.Guitar,
BChartConsts.INSTRUMENT_COOP => Instrument.GuitarCoop,
BChartConsts.INSTRUMENT_BASS => Instrument.Bass,
BChartConsts.INSTRUMENT_RHYTHM => Instrument.Rhythm,
BChartConsts.INSTRUMENT_KEYS => Instrument.Keys,
BChartConsts.INSTRUMENT_DRUMS => Instrument.Drums,
BChartConsts.INSTRUMENT_GUITAR_SIX => Instrument.GHLiveGuitar,
BChartConsts.INSTRUMENT_BASS_SIX => Instrument.GHLiveBass,
_ => Instrument.Unrecognised,
};
}

// Internal to external conversion
private static byte MoonSixFretToBChart(GHLiveGuitarFret note)
{
Expand Down
2 changes: 1 addition & 1 deletion BChartWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public static void WriteInstrument(Stream stream, Instrument inst, Dictionary<Di
{
void WriteData(Stream stre)
{
stre.WriteUInt32LE(BChartUtils.MoonInstrumentToBChart(inst));
stre.WriteByte(BChartUtils.MoonInstrumentToBChart(inst));
stre.WriteByte((byte)diffs.Count);
// TODO per instrument events track?
}
Expand Down
6 changes: 3 additions & 3 deletions chartFormat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ bchart format:
Instrument:
uint32/byte[4] - INST 0x54534E49 / 0x49 0x4E 0x53 0x54
int32 - byteLength
uint32 instrumentID
byte diffCount
byte - instrumentID
byte - diffCount
InstrumentDiffEvents

InstrumentDiffEvents: - Required to come after an instrument chunk
uint32/byte[4] - DIFF 0x46464944 / 0x44 0x49 0x46 0x46
int32 - byteLength
byte - difficultyID
int32 - eventCount
[deltaTickEncoding tickPos] [uint32 eventByteLength] [event data]
[uint32 tickPos] [uint32 eventByteLength] [event data]

AnimationEvents: Not yet fully defined but reserved for future use! - Required to come after an instrument chunk
uint32/byte[4] - ANIM
Expand Down

0 comments on commit 41ebab6

Please sign in to comment.