Skip to content

Commit

Permalink
Adding an instrument now returns the instrument's index
Browse files Browse the repository at this point in the history
  • Loading branch information
Kermalis committed Aug 29, 2018
1 parent 89d5554 commit 4c1a2de
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions SoundFont2/SF2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ public uint AddSample(short[] pcm16, string name, bool bLoop, uint loopPos, uint

return AddSampleHeader(name, start, end, loopStart, loopEnd, sampleRate, originalKey, pitchCorrection);
}
public void AddInstrument(string name)
// Returns instrument index
public uint AddInstrument(string name)
{
hydraChunk.INSTSubChunk.AddInstrument(new SF2Instrument(this)
return hydraChunk.INSTSubChunk.AddInstrument(new SF2Instrument(this)
{
InstrumentName = name,
InstrumentBagIndex = (ushort)IBAGCount
Expand Down
3 changes: 2 additions & 1 deletion SoundFont2/SF2Chunks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,12 @@ internal override void Write(BinaryWriter writer)
instruments[i].Write(writer);
}

internal void AddInstrument(SF2Instrument instrument)
internal uint AddInstrument(SF2Instrument instrument)
{
instruments.Add(instrument);
Size = Count * SF2Instrument.Size;
sf2.UpdateSize();
return Count - 1;
}

public override string ToString() => $"Instrument Chunk - Instrument count = {Count}";
Expand Down

0 comments on commit 4c1a2de

Please sign in to comment.