9

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).

TylerH
  • 20,799
  • 66
  • 75
  • 101
fdiaz
  • 2,600
  • 21
  • 27

1 Answers1

6

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

Nikolozi
  • 2,212
  • 2
  • 19
  • 29
  • 2
    Remember to first clear the Tempo Track or you'll end up with 2 Time Signatures in your MIDI file. `code`MusicTrack tempoTrack; MusicSequenceGetTempoTrack(sequence, &tempoTrack); MusicTrackClear(tempoTrack, 0, 1); `code` – fdiaz Jan 04 '13 at 15:09
  • MIDIMetaEvent only allocates 1 byte for data, who knows what memory you are writing the other 3 bytes to. – voidref Mar 13 '15 at 18:00
  • 1
    Time signature is expressed as 4 numbers. nn and dd represent the "numerator" and "denominator" of the signature as notated on sheet music. The denominator is a negative power of 2: 2 = quarter note, 3 = eighth, 4 = 16 etc. http://www.blitter.com/~russtopia/MIDI/~jglatt/tech/midifile/time.htm – johndpope May 19 '15 at 14:47