Overview | DryWetMIDI (original) (raw)

DryWetMIDI Logo

NuGet (full) NuGet (nativeless) Unity asset (full) Unity asset (nativeless)



DryWetMIDI is the .NET library to work with MIDI data and MIDI devices. It allows:

Please see Getting started section below for quick jump into the library.

Warning

If you want to create an issue or a discussion, read this article first – Support.

Projects using DryWetMIDI

Here the list of noticeable projects that use the library:

If you find that DryWetMIDI has been useful for your project, please put a link to the library in your project's About section or something like that.

Getting Started

Let's see small examples of what you can do with the library.

It's possible to read a MIDI file, then collect all notes from it and print their time and length in the metric (hours, minutes, second, ...) format:

var midiFile = MidiFile.Read("MyFile.mid");
var tempoMap = midiFile.GetTempoMap();
 
foreach (var note in midiFile.GetNotes())
{
    var time = note.TimeAs<MetricTimeSpan>(tempoMap);
    var length = note.LengthAs<MetricTimeSpan>(tempoMap);
    Console.WriteLine($"{note} at {time} with length of {length}");
}

Or maybe you want to record data from a MIDI device, then quantize recorded events by the grid with step of 1/8, and play the data via the default Windows synth:

var inputDevice = InputDevice.GetByName("MyMidiKeyboard");
inputDevice.StartEventsListening();

var recording = new Recording(TempoMap.Default, inputDevice);
recording.Start();
 
// ...
 
recording.Stop();
inputDevice.Dispose();
 
var recordedFile = recording.ToFile();
recording.Dispose();
 
recordedFile.QuantizeObjects(
    ObjectType.TimedEvent,
    new SteppedGrid(MusicalTimeSpan.Eighth));
 
var outputDevice = OutputDevice.GetByName("Microsoft GS Wavetable Synth");
var playback = recordedFile.GetPlayback(outputDevice);
playback.Start();
 
// ...
 
playback.Dispose();
outputDevice.Dispose();

You can even build a musical composition:

var pattern = new PatternBuilder()
     
    // Insert a pause of 5 seconds
    .StepForward(new MetricTimeSpan(0, 0, 5))

    // Insert an eighth C# note of the 4th octave
    .Note(Octave.Get(4).CSharp, MusicalTimeSpan.Eighth)

    // Set default note length to triplet eighth and default octave to 5
    .SetNoteLength(MusicalTimeSpan.Eighth.Triplet())
    .SetOctave(Octave.Get(5))

    // Now we can add triplet eighth notes of the 5th octave in a simple way
    .Note(NoteName.A)
    .Note(NoteName.B)
    .Note(NoteName.GSharp)

    // Insert a simple drum pattern
    .PianoRoll(@"
        F#2   ||||||||
        D2    --|---|-
        C2    |---|---")
    .Repeat(9)

    // Get pattern
    .Build();

var midiFile = pattern.ToFile(TempoMap.Create(Tempo.FromBeatsPerMinute(240)));
midiFile.Write("DrumPattern.mid");

Also you can check out sample applications from CIRCE-EYES (see the profile, VB.NET is used)