.NET Framework 4.6,C#。
使用nAudio读取MIDI文件,将下面的内容转换为符号结构,如果音符需要为四分之一/一半/满,则显示一个包含16个音符和多个延音值的列。因此,结果将开始显示为" C6"作为四分音符:
C6
S
S
S
我不了解如何阅读Velocity和NoteLength属性/字段以获取音符持续时间值。有人能指出我正确的方向吗?
/*
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;
}
}
感谢。