Recording – Overview
To capture MIDI data from an input MIDI device (see Input device article) you can use Recording class which will collect incoming MIDI events. To start recording you need create an instance of the Recording
class passing tempo map and input device to its constructor:
using Melanchall.DryWetMidi.Multimedia;
using Melanchall.DryWetMidi.Interaction;
// ...
using (var inputDevice = InputDevice.GetByName("Input MIDI device"))
{
var recording = new Recording(TempoMap.Default, inputDevice);
// ...
}
Don't forget to call StartEventsListening on IInputDevice before you start recording since Recording
do nothing with the device you've specified.
To start recording call Start method. To stop it call Stop method. You can resume recording after it has been stopped by calling Start
again. To check whether recording is currently running or not, get a value of the IsRunning property. Start
and Stop
methods fire Started and Stopped events respectively.
You can get recorded events as with GetEvents method.
Take a look at small example of MIDI data recording:
using (var inputDevice = InputDevice.GetByName("Input MIDI device"))
{
var recording = new Recording(TempoMap.Default, inputDevice);
inputDevice.StartEventsListening();
recording.Start();
// ...
recording.Stop();
var recordedFile = recording.ToFile();
recording.Dispose();
recordedFile.Write("Recorded data.mid");
}