Csound Csound-dev Csound-tekno Search About

MIDI and timeinsts

Date2015-09-27 04:23
FromBeinan Li
SubjectMIDI and timeinsts
AttachmentsNone  None  
Hi Csound,

I'm using the fprintks sample code to convert MIDI message from a MIDI file to Csound score.
The sample code is this one:

My problem is that after running it on a .mid file of mine. 
The timing of the events doesn't make sense to me. 
I know that the channels and the NoteOn/Off events are mixed up and requires post-processing if I insist to see the correct Note event flow in time by MIDI channels. But even after sorting them out, the time fields recorded by timeinsts still don't make sense to me.

Below is the immediate output score from the sample code mentioned above:
; p2 =  timeinsts output, p3 = 1/kr, p4 = MIDI event type   p5 = channel   p6= data1    p7= data2
i1 0.000333 0.000333 144 1 40 98
i1 1.125333 0.000333 144 1 43 98
i1 1.125333 0.000333 144 1 43 98
i1 0.000333 0.000333 144 2 43 98
i1 1.125667 0.000333 144 2 43 98
i1 1.125667 0.000333 144 2 43 98
i1 1.238000 0.000333 128 1 40 64
i1 0.113000 0.000333 128 1 40 64
i1 0.113000 0.000333 128 1 40 64
i1 2.125333 0.000333 144 1 47 98
i1 1.000333 0.000333 144 1 47 98
i1 1.000333 0.000333 144 1 47 98
i1 2.136667 0.000333 128 2 43 64
i1 1.011667 0.000333 128 2 43 64
i1 0.011667 0.000333 128 2 43 64
i1 2.146333 0.000333 128 1 43 64
i1 0.021333 0.000333 128 1 43 64
i1 2.375333 0.000333 144 2 40 98
i1 0.250333 0.000333 144 2 40 98
i1 3.375333 0.000333 144 1 50 98
i1 1.250333 0.000333 144 1 50 98
i1 1.000333 0.000333 144 1 50 98
i1 3.407667 0.000333 128 1 47 64
i1 1.032667 0.000333 128 1 47 64
i1 0.032667 0.000333 128 1 47 64
i1 3.591000 0.000333 128 2 40 64
i1 0.216000 0.000333 128 2 40 64
i1 3.625333 0.000333 144 2 36 98
i1 0.250333 0.000333 144 2 36 98
i1 4.705667 0.000333 128 2 36 64
i1 1.330667 0.000333 128 2 36 64
i1 5.738000 0.000333 128 1 50 64

Here is the version sorted by channel and order of occurrences, the instruments are reassigned to the channel numbers for easier viewing; the event order within each channel is the same as above:
i1 0.000333 0.000333 144 1 40 98
i1 1.125333 0.000333 144 1 43 98
i1 1.125333 0.000333 144 1 43 98
i1 1.238000 0.000333 128 1 40 64
i1 0.113000 0.000333 128 1 40 64
i1 0.113000 0.000333 128 1 40 64
i1 2.125333 0.000333 144 1 47 98
i1 1.000333 0.000333 144 1 47 98
i1 1.000333 0.000333 144 1 47 98
i1 2.146333 0.000333 128 1 43 64
i1 0.021333 0.000333 128 1 43 64
i1 3.375333 0.000333 144 1 50 98
i1 1.250333 0.000333 144 1 50 98
i1 1.000333 0.000333 144 1 50 98
i1 3.407667 0.000333 128 1 47 64
i1 1.032667 0.000333 128 1 47 64
i1 0.032667 0.000333 128 1 47 64
i1 5.738000 0.000333 128 1 50 64

i2 0.000333 0.000333 144 2 43 98
i2 1.125667 0.000333 144 2 43 98
i2 1.125667 0.000333 144 2 43 98
i2 2.136667 0.000333 128 2 43 64
i2 1.011667 0.000333 128 2 43 64
i2 0.011667 0.000333 128 2 43 64
i2 2.375333 0.000333 144 2 40 98
i2 0.250333 0.000333 144 2 40 98
i2 3.591000 0.000333 128 2 40 64
i2 0.216000 0.000333 128 2 40 64
i2 3.625333 0.000333 144 2 36 98
i2 0.250333 0.000333 144 2 36 98
i2 4.705667 0.000333 128 2 36 64
i2 1.330667 0.000333 128 2 36 64

I had thought that p2 would have simply been increasing along the list but it turns out that they are not. 

This makes me wonder if my understanding of how timeinsts works is wrong.
I thought "Read absolute time, in seconds, since the start of an instance of an instrument." means that the opcode is just a linear timer, and the reading from it should linearly increase, no? Am I missing something?


Thanks,
Beinan