Author Topic: Retrieve of tempo from MIDI stream failing  (Read 281 times)

Wayne McHugh

  • Posts: 58
Retrieve of tempo from MIDI stream failing
« on: 25 May '23 - 21:54 »
I am having a strange problem with tempo. I'm working on a huge upgrade to my MIDI player, including change to x64 and involving VSTi using BASS_VST.  I'm investigating the reason why all my tempos are reporting 120bpm, which tracks back to BASS_MIDI_StreamGetEvent(chan, 0, MIDI_EVENT_TEMPO) returning 500000 every time.  The MIDI file still plays at the right speed.  I checked back against my previous version, and the same line returns 750000 for the particular MIDI file I'm using to investigate this.  Because there are so many changes I've made, I edited my startup code in both versions to  ...
Code: [Select]
chan = BASS_MIDI_StreamCreateFile(FALSE, lpszMIDIFile, 0, 0, BASS_MIDI_DECAYEND | floatable | (pCurrentSong->getEffects() ? 0 : BASS_MIDI_NOFX) | BASS_MIDI_SINCINTER, 44100);
tempobase = BASS_MIDI_StreamGetEvent(chan, 0, MIDI_EVENT_TEMPO);
For the same MIDI file, my old version returns 750000 but my new version returns 500000.  I've changed from x32 (old version) to x64. I've linked in BASS_VST, but in this code sequence it isn't referenced. Any thoughts on what could explain this behaviour?

Wayne McHugh

  • Posts: 58
Re: Retrieve of tempo from MIDI stream failing
« Reply #1 on: 25 May '23 - 23:21 »
I meant to write previously - all other queries through BASS_MIDI_StreamGetEvent - program, volume, reverb, chorus, etc are all working as they always have.  It is just tempo that is the issue.

Ian @ un4seen

  • Administrator
  • Posts: 25287
Re: Retrieve of tempo from MIDI stream failing
« Reply #2 on: 26 May '23 - 14:32 »
Did you change BASSMIDI version too, not just from 32-bit to 64-bit? If so, what version is returning 750000 and what version is returning 500000, and which is the correct value? Is there a difference in the values during playback too or only before?

Wayne McHugh

  • Posts: 58
Re: Retrieve of tempo from MIDI stream failing
« Reply #3 on: 26 May '23 - 21:15 »
750000 is the correct value for that Midi file. 500000 equates to 120bpm which is the MIDI default if none is specified so I'm guessing this means the tempo event is not being found. The BASSMIDI x64 version is 2.4.14.1, and this is the one which is returning 500000 for every MIDI file. The x32 build that works is using BASSMIDI 2.4.8.0.

The original symptom was my visual display of the BPM which is now displaying 120 for every MIDI file. I tracked this back to the BASS_MIDI_StreamGetEvent(chan, 0, MIDI_EVENT_TEMPO) call returning 500000 every time.  In order to eliminate all other complexities I then added this call to immediately after the stream create, and it still returns 500000 (incorrect) from x64 2.4.14.1 and 750000 (correct) from x32 2.4.8.0 when testing against the same MIDI file.  Wider testing shows x32 2.4.8.0 is always returning the right tempo value, and x64 2.4.14.1 always 500000.

Both versions play the song at the correct tempo.

Ian @ un4seen

  • Administrator
  • Posts: 25287
Re: Retrieve of tempo from MIDI stream failing
« Reply #4 on: 29 May '23 - 16:49 »
I compared the tempo initialization code in BASSMIDI 2.4.8 with the latest, and it seems the same; if the file has a tempo event in the first tick then BASS_MIDI_StreamGetEvent should return that immediately, otherwise 500000 is the default. If a tempo event is after the first tick then it wouldn't be seen until playback starts (or after seeking). If there's definitely a difference, please post an affected MIDI file to have a look at.

Wayne McHugh

  • Posts: 58
Re: Retrieve of tempo from MIDI stream failing
« Reply #5 on: 31 May '23 - 01:20 »
I've attached 2 screenshots.
Image 1: Show the code where the MIDI stream is created, and a call to find the tempo immediately following. I've stopped the debugger, and you can see the return value is 500000.
Image 2: I've placed a check for tempo events in the event filter callback, and it stops with the data displayed - tick 0, channel 0, value 750000.

I didn't imagine you'd have messed with tempo code - it isn't exactly cutting edge stuff.  But I did wonder if something was going on between x32 and x64, perhaps a compiler setting at my end that I don't know about, or some consideration at your end.  But this happens (500000 is returned from BASS_MIDI_StreamGetEvent) on every one of my MIDI files that I've checked, and I've checked quite a few.

Is there an x64 debug lib/dll for BASSMIDI that would allow me to step through and see what is happening?

I can't see a way to upload the MIDI file that I'm demonstrating, so (Ian) I've tried emailing you.

Ian @ un4seen

  • Administrator
  • Posts: 25287
Re: Retrieve of tempo from MIDI stream failing
« Reply #6 on: 31 May '23 - 17:43 »
Ah! There is indeed a problem with this in the current BASSMIDI release, as you said. Here's an update that should fix it:

   www.un4seen.com/stuff/bassmidi.zip

Wayne McHugh

  • Posts: 58
Re: Retrieve of tempo from MIDI stream failing
« Reply #7 on: 1 Jun '23 - 01:12 »
That is a relief, because I couldn't imagine anything else to test at my end.  Sadly, my program doesn't run with that dll copied in. Is it x64, and has the lib file not changed?  It just reports that the program can't start, without giving a reason.
« Last Edit: 1 Jun '23 - 13:39 by Wayne McHugh »

Ian @ un4seen

  • Administrator
  • Posts: 25287
Re: Retrieve of tempo from MIDI stream failing
« Reply #8 on: 1 Jun '23 - 13:52 »
The DLL in the root folder is 32-bit, while a 64-bit DLL is in the "x64" folder. There are no function signature changes in the update, so the existing LIB files can still be used. Are you having the problem with both DLLs? If so, does running under the debugger give any clues, eg. an error message in the console?

Wayne McHugh

  • Posts: 58
Re: Retrieve of tempo from MIDI stream failing
« Reply #9 on: 2 Jun '23 - 00:42 »
Of course it is, and it works perfectly.  I got put off by a windows weirdo, that in the unzipped folder it listed the x32 dll as recent and the x64 folder as a long time ago. Why I let that distract me I don't know, but I did.  Now creating beautiful music with the correct tempo  ;D