2

.NET Framework 4.6, C#.

Using nAudio to read a MIDI file to convert the below into a notation structure that shows a single column with 16th notes and multiple sustain values if the note needs to be a quarter/half/full. So the result would start to look like this to display "C6" as a quarter note:

C6
S
S
S

I don't nuderstand how to read the Velocity and NoteLength properties/fields to get note duration values. Can someone point me in the right direction?

/*
Format 0, Tracks 1, Delta Ticks Per Quarter Note 480
1:1:0 0 MidiChannel
00
1:1:0 0 SequenceTrackName Classic Electric Piano
1:1:0 0 TrackInstrumentName Classic Electric Piano
1:1:0 0 SetTempo 89bpm (666667)
1:1:0 0 TimeSignature 4/4 TicksInClick:24 32ndsInQuarterNote:8
1:1:0 0 KeySignature 0 0
1:1:0 0 SmpteOffset 33:0:0:0:0
1:1:0 0 NoteOn Ch: 1 C6 Vel:87 Len: 167
1:1:240 240 NoteOn Ch: 1 C6 Vel:69 Len: 199
1:2:0 480 NoteOn Ch: 1 G6 Vel:74 Len: 149
1:2:240 720 NoteOn Ch: 1 G6 Vel:49 Len: 191
1:3:0 960 NoteOn Ch: 1 A6 Vel:65 Len: 165
1:3:240 1200 NoteOn Ch: 1 A6 Vel:50 Len: 171
1:4:0 1440 NoteOn Ch: 1 G6 Vel:89 Len: 401
*/

var dede = midiFile.DeltaTicksPerQuarterNote;
var tempolist = new List<TempoEvent>();
foreach (MidiEvent note in midiFile.Events[0])
{
    if ( note.CommandCode == MidiCommandCode.NoteOn )
    {
        var nono = (NoteOnEvent)note;
        var noname = nono.NoteName;
        var notime= nono.AbsoluteTime;
        double realtime = ( note.AbsoluteTime / dede ) * tempo[ tempo.Count() - 1 ].Tempo;
        var nonum = nono.NoteNumber;
        var nolen = nono.NoteLength;

    }
}

Thanks.

Snowy
  • 5,942
  • 19
  • 65
  • 119
  • Where do these `1:2:240` values come from? – CL. Aug 10 '15 at 14:32
  • Note: the `realtime` calculation is wrong; see [Reading notes from MIDI file using NAudio](http://stackoverflow.com/q/23888692/11654). – CL. Aug 10 '15 at 14:34
  • @CL values came from Console Writeline ( new MidiFileInspector().Describe("mysong.mid") ); – Snowy Aug 11 '15 at 00:32

0 Answers0