KMIDI 1.0.0
dotnet add package KMIDI --version 1.0.0
NuGet\Install-Package KMIDI -Version 1.0.0
<PackageReference Include="KMIDI" Version="1.0.0" />
paket add KMIDI --version 1.0.0
#r "nuget: KMIDI, 1.0.0"
// Install KMIDI as a Cake Addin #addin nuget:?package=KMIDI&version=1.0.0 // Install KMIDI as a Cake Tool #tool nuget:?package=KMIDI&version=1.0.0
📖 KMIDI
This .NET library allows you to simply read and write MIDI files. There is no functionality for playing or listening to MIDIs, so it's purely for handling the file data itself. You can even add custom chunks to the MIDI file! You can read MIDIs and then edit them slightly before saving them again.
It handles all MIDI formats because it tries to adhere to the MIDI specification. The specification isn't fully respected because some invalid MIDIs are not detected at the moment. However, the library will catch most invalid MIDIs!
🚀 Usage:
Add the KMIDI NuGet package to your project or download the .dll from the releases tab.
Examples:
Reading MIDI:
MIDIFile inMIDI;
using (FileStream fs = File.OpenRead(@"C:\Folder\PathToMIDI.mid"))
{
inMIDI = new MIDIFile(fs);
}
MIDIFormat format = inMIDI.HeaderChunk.Format;
ushort numTracks = inMIDI.HeaderChunk.NumTracks;
TimeDivisionValue timeDiv = inMIDI.HeaderChunk.TimeDivision;
foreach (MIDITrackChunk track in inMIDI.EnumerateTrackChunks())
{
for (IMIDIEvent? e = track.First; e is not null; e = e.Next)
{
switch (ev)
{
case IMIDIEvent<NoteOnMessage> note:
{
NoteOnMessage msg = note.Msg;
Console.WriteLine("Note on @{0} ticks: Channel {1}, Note {2}, Velocity {3}",
e.Ticks, msg.Channel, msg.Note, msg.Velocity);
break;
}
default:
{
MIDIMessage msg = e.Msg;
Console.WriteLine("Other message @{0} ticks: {1}",
e.Ticks, msg);
break;
}
}
}
}
Writing MIDI:
ushort ticksPerQuarterNote = 48;
int tracksInitialCapacity = 2;
var newMIDI = new MIDIFile(MIDIFormat.Format1, TimeDivisionValue.CreatePPQN(ticksPerQuarterNote), tracksInitialCapacity);
var metaTrack = new MIDITrackChunk();
newMIDI.AddChunk(metaTrack);
double bpm = 180;
metaTrack.InsertMessage(0, MetaMessage.CreateTempoMessage(bpm));
metaTrack.InsertMessage(480, MetaMessage.CreateTextMessage(MetaMessageType.Marker, "Halfway!"));
metaTrack.InsertMessage(960, new MetaMessage(MetaMessageType.EndOfTrack, Array.Empty<byte>()));
var chanTrack = new MIDITrackChunk();
newMIDI.AddChunk(chanTrack);
byte chan = 0;
chanTrack.InsertMessage(0, MetaMessage.CreateTextMessage(MetaMessageType.TrackName, "First Track"));
chanTrack.InsertMessage(0, new ProgramChangeMessage(chan, MIDIProgram.FrenchHorn));
chanTrack.InsertMessage(0, new ControllerMessage(chan, ControllerType.Pan, 80));
chanTrack.InsertMessage(0, new NoteOnMessage(chan, MIDINote.C_4, 110));
chanTrack.InsertMessage(48, new NoteOffMessage(chan, MIDINote.C_4, 0));
chanTrack.InsertMessage(96, new NoteOnMessage(chan, MIDINote.D_4, 120));
chanTrack.InsertMessage(480, new NoteOffMessage(chan, MIDINote.D_4, 0));
chanTrack.InsertMessage(480, new NoteOnMessage(chan, MIDINote.G_4, 127));
chanTrack.InsertMessage(480, new NoteOnMessage(chan, MIDINote.C_5, 127));
chanTrack.InsertMessage(960, new NoteOffMessage(chan, MIDINote.G_4, 0));
chanTrack.InsertMessage(960, new NoteOffMessage(chan, MIDINote.C_5, 0));
chanTrack.InsertMessage(960, new MetaMessage(MetaMessageType.EndOfTrack, Array.Empty<byte>()));
using (FileStream fs = File.Create(@"C:\Folder\PathToMIDI.mid"))
{
newMIDI.Save(fs);
}
KMIDI Uses:
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- EndianBinaryIO (>= 2.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 204 | 5/17/2023 |