Author Topic: BASS_MIDI_StreamCreateEvents not working on Ubuntu  (Read 375 times)

Pyrdacor

  • Guest
I create a channel from some MIDI events with BASS_MIDI_StreamCreateEvents. On Windows 10 all works fine. BASS_MIDI_StreamCreateEvents returns a valid handle and I can play the MIDI. On Ubuntu the same code and same data also produces no error (-> BASS_OK) but BASS_MIDI_StreamCreateEvents returns 0. And so I can't play the MIDI. I load the data from memory so it is no file issue.

When BASS_MIDI_StreamCreateEvents returns 0, I expected BASS_ErrorGetCode to return something different from BASS_OK. My guess is that event loading actually succeeds but maybe on linux 0 is treated as a valid handle by mistake or something like that?

Ian @ un4seen

  • Administrator
  • Posts: 23488
Re: BASS_MIDI_StreamCreateEvents not working on Ubuntu
« Reply #1 on: 14 Apr '20 - 17:45 »
That's strange. Are you calling BASS_ErrorGetCode straight after the failed BASS_MIDI_StreamCreateEvents call (no other BASS calls in between), and in the same thread? For reference, are BASS_MIDI_StreamCreate and BASS_MIDI_StreamCreateFile working OK? Please also confirm that you are using the latest BASS and BASSMIDI versions.

Pyrdacor

  • Guest
Re: BASS_MIDI_StreamCreateEvents not working on Ubuntu
« Reply #2 on: 14 Apr '20 - 17:49 »
Yeah I called it right after it. But I found the problem.

It was about DLL loading hell. I use .NET p/invoke and had to pre-load libbass.so with RTLD_GLOBAL manually (cause .NET DllImport uses RTLD_LOCAL which doesn't work with bass/bassmidi). Unfortunately I loaded the one in /usr/lib instead of the one in my application directory. But then the p/invoke (which uses DllImport) loaded libbassmidi.so from my application directory (as it has a different search logic than my manual preload) and I guess that messed up a few things. Now finally MIDI playback is working on linux! Great.

But would be much easier if there would be assemblies which include bass+bassmidi.

Ian @ un4seen

  • Administrator
  • Posts: 23488
Re: BASS_MIDI_StreamCreateEvents not working on Ubuntu
« Reply #3 on: 15 Apr '20 - 15:25 »
Yes. On Linux, the LIBBASS.SO library needs to be loaded before any add-ons are, and it needs to be loaded with global scope to allow the add-ons to see its functions. I'm not a .Net user myself but it seems like it loads libraries with local scope. Doing something like this should fix that:

Code: [Select]
[DllImport("libdl")]
static extern IntPtr dlopen(String filename, int flags);

...

Bass.BASS_GetVersion(); // call/load BASS
dlopen("libbass.so", 0x104); // 0x104 = RTLD_NOLOAD + RTLD_GLOBAL