Get "rests" with the musical symbol format (e.g., quarter rests) #179
-
Hello, Would anyone know if it's possible to get the length of "rests" with the musical symbol format (e.g., whole/half/quarter rests)? I tried to do so with "GetObjects", but it seems to extract all the silent sections between notes rather than the rests described on music sheets. Also, I'd like to know in which measure/bar the rests are. Array<track/channel> I'd be appreciated it if anyone could help with that. Many thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi, First of all, there is no such term as "rest" in MIDI. More than that, there is no "note" term there. MIDI file contains events. Pair of Note On and Note Off events we call a note. Silence between such pairs we call a rest. What you see in a sheet music editor is not what will be stored in a MIDI file. MIDI file is just a set of instructions for a synth. But your task looks pretty easy to solve: var tempoMap = midiFile.GetTempoMap();
var notesAndRests = midiFile
.GetTrackChunks()
.Select((trackChunk, i) => new
{
Index = i,
Objects = trackChunk
.GetObjects(
ObjectType.Note | ObjectType.Rest,
new ObjectDetectionSettings
{
RestDetectionSettings = new RestDetectionSettings
{
RestSeparationPolicy = RestSeparationPolicy.NoSeparation
}
})
.Select(obj => new
{
Object = obj,
Time = obj.TimeAs<BarBeatTicksTimeSpan>(tempoMap),
Length = ((ILengthedObject)obj).LengthAs<MusicalTimeSpan>(tempoMap)
})
.ToArray()
})
.ToArray();
Of course you can add other properties, modify parameters and so on. It's just a quick example of how you can get what you want. Please see the library documentation: https://melanchall.github.io/drywetmidi. Here articles on time spans: https://melanchall.github.io/drywetmidi/articles/high-level-managing/Time-and-length-overview.html. |
Beta Was this translation helpful? Give feedback.
-
Hi melanchall, Thanks a lot for your help! I understand that MIDI data is not meant for that purpose, but I wanted to extract as much information as possible described on a sheet music for my project...! Best, |
Beta Was this translation helpful? Give feedback.
Hi,
First of all, there is no such term as "rest" in MIDI. More than that, there is no "note" term there. MIDI file contains events. Pair of Note On and Note Off events we call a note. Silence between such pairs we call a rest. What you see in a sheet music editor is not what will be stored in a MIDI file. MIDI file is just a set of instructions for a synth.
But your task looks pretty easy to solve: