Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change time signature in MusicSequence

I'm trying to change the time signature (default to 4/4) in a MusicSequence but I don't seem to understand how to do this. I have 2 MusicTracks inside the sequence and a MusicPlayer also to reproduce the music. How can I change this value?

EDIT:

I know now that I need to add a Time Sig event to the MusicSequence Tempo Track. I know that I can get this track with MusicSequenceGetTempoTrack, but how do I add a time sig event to it?

EDIT 2:

Researching I realized that i need to create an MusicTrackExtendedMetaEvent to the Music Tempo Track. Now I need to know how to correctly format MIDIMetaEvent (I know that 88 is the metaEventType but don't know how to add the rest of the information).

like image 508
fdiaz Avatar asked Aug 31 '12 20:08

fdiaz


1 Answers

After 4 wasting 4 hours on this I figured out how to do it. Here the code:

//Getting the tempo track
MusicTrack tempoTrack;
MusicSequenceGetTempoTrack (musicSequence, &tempoTrack);

//Set time signature to 7/16
MIDIMetaEvent timeSignatureMetaEvent;
timeSignatureMetaEvent.metaEventType = 0x58;
timeSignatureMetaEvent.dataLength = 4;
timeSignatureMetaEvent.data[0] = 0x07;
timeSignatureMetaEvent.data[1] = 0x04;
timeSignatureMetaEvent.data[2] = 0x18;
timeSignatureMetaEvent.data[3] = 0x08;
MusicTrackNewMetaEvent(tempoTrack, 0, &timeSignatureMetaEvent);

Here's a reference to MIDI file spec to look up time signature codes to http://www.somascape.org/midi/tech/mfile.html

like image 86
Nikolozi Avatar answered Sep 18 '22 07:09

Nikolozi