Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving a very simple MusicSequence into MIDI doesn't reproduce sound

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;
}
like image 898
fdiaz Avatar asked Aug 03 '12 21:08

fdiaz


1 Answers

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.

like image 137
spring Avatar answered Oct 18 '22 15:10

spring