jdkoftinoff / jdksmidi

c++ MIDI library
http://github.com/jdkoftinoff/jdksmidi/wiki
Other
116 stars 34 forks source link

Create event with MIDIDeltaTimedMessage doesn't work?! #2

Closed mpflanzer closed 13 years ago

mpflanzer commented 13 years ago

If I use the example "create_midifile.cpp" to create a midifile and everything works correct but I would like to use a MIDIDeltaTimedMessage instead of MIDITimedMessage. The problem is if I change all SetTime( t += dt ) to SetDeltaTime( dt ) and of course the MIDITimedMessage to MIDIDeltaTimedMessage leaving all the rest of the code untouched I cannot play the midifile anymore. While searching for my mistake I took a closer look at the PutEvent-method and realized that there is only a version for the TimedMessage and none for a DeltaTimed one. So is there at the moment no possibility to create a track with DeltaTimedMessages or is there a mistake in my code?

vadimrm commented 13 years ago

Please get me yours code first.

mpflanzer commented 13 years ago

The code in comments produces a playable file, the file created with the deltatimed event isn't playable.

MIDIClockTime length = 100;
MIDIClockTime time = 0;

MIDIMultiTrack *track = new MIDIMultiTrack(2);

//MIDITimedMessage event;
MIDIDeltaTimedMessage event;

// add some events to the second track
for(unsigned int i = 0; i < 10; ++i)
{
    //event.SetTime(time);
    event.SetDeltaTime(100);
    event.SetNoteOn(0, note, 127);
    this->track->GetTrack(1)->PutEvent(event);

    //event.SetTime(time += length);
    event.SetDeltaTime(100);
    event.SetNoteOff(0, note, 0);
    this->track->GetTrack(1)->PutEvent(event);
}

(new MIDIFileWriteMultiTrack(track, new MIDIFileWriteStreamFileName("filename.mid")))->Write(2, 100);
vadimrm commented 13 years ago

Yours code is right. I make update the lib near end of this week.

mpflanzer commented 13 years ago

Thank you for your quick help. Just don't rush yourself. For the moment I will take the version with the absolute times and when you updated I will change to the relative one.

vadimrm commented 13 years ago

It's ok, please test new version and close issue if all work.

mpflanzer commented 13 years ago

It's all fine now. Thanks :)