Generated MIDI file appears empty in Live

Hi, using the following code to generate a MIDI file. If I read the generated file back in then the data seems correct, but no events appear if I drag the file into Live. I’ve compared the data to a MIDI file I exported from Live and the contents appear to be the same. Any suggestions? thx

File				outf = File( "c:\\temp\\out.mid" );
MidiFile			mf;
MidiMessageSequence	ms;

outf.deleteFile();

int res = 24;
int note = 64;

for ( int i = 0; i < 4; i++ ) {
	float start = i * res;
	float end = ( i * res ) + res;

	MidiMessage mm_on = MidiMessage::noteOn( 1, note + i, (uint8)( 100 ) );
	MidiMessage mm_off = MidiMessage::noteOff( 1, note + i, (uint8)0 );

	mm_on.setTimeStamp( start );
	mm_off.setTimeStamp( end );

	ms.addEvent( mm_on );
	ms.addEvent( mm_off );
}

mf.addTrack( ms );

if ( ScopedPointer<FileOutputStream> p_os = outf.createOutputStream() ) 
	mf.writeTo( *p_os, 0 );

MidiFile::setTicksPerQuarterNote()

Rail

2 Likes

perfect, thx