BASS_MIDI_StreamEvent in zero position

462 views Asked by At

I'm use BASS_MIDI in iPhone development. I create midiStream from file like this

midiStream = BASS_MIDI_StreamCreateFile(false, filePath, 0, 0, 0, 44100);

Then i play/position/pause it, changing volume and tempo. I change tempo(for playback speed control) before playing like this

BASS_MIDI_StreamEvent(midiStream, 0, MIDI_EVENT_TEMPO, currentTempo);//microseconds per quarter note
BASS_ChannelPlay(midiStream, false);

It works good, but i have one problem. If position of midistream is 0, then tempo not changed(volume, and another BASS_MIDI_StreamEvent's don't works too). If change call order like this

BASS_ChannelPlay(midiStream, false);
BASS_MIDI_StreamEvent(midiStream, 0, MIDI_EVENT_TEMPO, currentTempo);//microseconds per quarter note

then i have some lag(playback starts with incorrect speed and it change after a half of second, or less. How can i fix it? Is there a way to call events before playing in zero position?

P.S. Sorry for bad English.

1

There are 1 answers

0
Padavan On BEST ANSWER

Answer was founded on offecial BASS forum.

The problem there is that your events are being overridden by events in the MIDI file. To avoid that, you can use "mixtime" BASS_SYNC_MIDI_EVENT syncs to override the file's events. A demonstration of this can be found in the MIDITEST example (get it from one of the other platform BASSMIDI packages)...

{ // override the initial tempo, and set a sync to override tempo events and another to override after seeking
    SetTempo(TRUE);
    BASS_ChannelSetSync(chan,BASS_SYNC_MIDI_EVENT|BASS_SYNC_MIXTIME,MIDI_EVENT_TEMPO,TempoSync,0);
    BASS_ChannelSetSync(chan,BASS_SYNC_SETPOS|BASS_SYNC_MIXTIME,0,TempoSync,0);
}

Note it's also setting a BASS_SYNC_SETPOS sync because the events are reset to the MIDI file's values when seeking too.