5

I'm trying to save a very basic one note MusicSequence (MusicSequence Reference) into a MIDI file. The file is being written right now and the duration of the note also (if I put duration 4 then the MIDI file lasts 2 secs, if I change it to 2 then it lasts 1 sec as it should) but there's no sound being reproduced and if I look at the MIDI file in Logic there's no information neither. Seems like the note duration gets written but the note's note isn't.

What could be happening?

+ (MusicSequence)getSequence
{
    MusicSequence mySequence;
    MusicTrack myTrack;
    NewMusicSequence(&mySequence);
    MusicSequenceNewTrack(mySequence, &myTrack);

    MIDINoteMessage noteMessage;
    MusicTimeStamp timestamp = 0;
    noteMessage.channel = 0;
    noteMessage.note = 4;
    noteMessage.velocity = 90;
    noteMessage.releaseVelocity = 0;
    noteMessage.duration = 4;

    if (MusicTrackNewMIDINoteEvent(myTrack, timestamp, &noteMessage) != noErr) NSLog(@"ERROR creating the note");
    else NSLog(@"Note added");

    return mySequence;
}
TylerH
  • 20,799
  • 66
  • 75
  • 101
fdiaz
  • 2,600
  • 21
  • 27
  • Uhm, what library is `MusicSequence` from? Without further information, we cannot help you. -1 for unanswerable question (for now). – Richard J. Ross III Aug 03 '12 at 21:44
  • MusicSequence is from the framework AudioToolbox/MusicPlayer.h http://developer.apple.com/library/mac/#documentation/AudioToolbox/Reference/MusicSequence_Reference/Reference/reference.html sorry about not clarifying that. Edited the original post to incude it. – fdiaz Aug 03 '12 at 22:02

1 Answers1

5

Try writing a note that is > 20 and < 109 (midi note range). While 4 may be technically valid, it is outside the range of normal midi notes.

Also, a useful function working with Core Audio/MusicPlayer etc. is CAShow() - so try CAShow(sequence) to view the sequence data.

spring
  • 18,009
  • 15
  • 80
  • 160