example-sk / audvis

GNU General Public License v2.0
53 stars 1 forks source link

Midi Realtime Device not found #8

Open mertakbal opened 8 months ago

mertakbal commented 8 months ago

I really enjoy the capabilities of Audvis it is amazing! But now I wanted also try to directly controlling animations with my midi device. Unfortunately in "midi realtime" tab my midi keyboard is not listed as input device, in fact the list is empty.

example-sk commented 8 months ago

Thanks for reporting. I am affected by this bug too.

It looks like this stopped working somewhere between Blender 3.4.1 (works on my pc) and Blender 3.6 (doesn't work). I'm going to investigate it deeper.

example-sk commented 8 months ago

this bug is affecting AudVis, because AudVis uses mido library with pygame backend: https://github.com/pygame/pygame/issues/3756

mertakbal commented 7 months ago

What would be the best solution or a workaround?

example-sk commented 7 months ago

It took me some time to find the correct combination of paths, so use this just as an inspiration. It's possible you will need to find the experiment with the paths. Fix the one of the "missing" folders by symlinking: sudo ln -s /usr/lib/x86_64-linux-gnu/alsa-lib /usr/local/lib/alsa-lib Start blender with this command (just change the path to blender): ALSA_CONFIG_PATH=/usr/share/alsa/alsa.conf /path/to/blender/4.1/blender

It looks like there is a long history of alsa's bugs like this.

mertakbal commented 6 months ago

I just found the opportunity to try your solution. And it worked on first try! thank you very much. I just now have the question how to find out how to map the keys. If I find this out then I will do a video tutorial that also other people can enjoy controlling animations with the midi controller.

example-sk commented 6 months ago

Good question. I will prepare UI to show last MIDI message.

example-sk commented 6 months ago

Done. Please try the new version: https://github.com/example-sk/audvis/releases/tag/4.9.0 image

mertakbal commented 6 months ago

Wonderful! Thank you! Now I get the debug information and know which key is which. But unfortunately the driver does not change the value. Maybe I am entering something wrong? I tried as device name both the name displayed in debug as well as the default name "MIDI Device 1"

Screenshot from 2024-03-13 11-28-12 Screenshot from 2024-03-13 11-28-01

example-sk commented 6 months ago

I guess the problem is with ch="0". Try ch=0

mertakbal commented 6 months ago

Yes! That works perfect!
Is there also a way to use the knobs and sliders? Like getting a continuous flow of value between 0-1?

example-sk commented 6 months ago

Not yet. I will add a new parameter, probably midi_control=... (similar to midi_note=...)

mertakbal commented 6 months ago

This would be really great. Using live midi controller will make Blender a live visual tool not only for VJing but also for theater and opera settings.

example-sk commented 6 months ago

It took me some time to find the correct combination of paths, so use this just as an inspiration. It's possible you will need to find the experiment with the paths. Fix the one of the "missing" folders by symlinking: sudo ln -s /usr/lib/x86_64-linux-gnu/alsa-lib /usr/local/lib/alsa-lib Start blender with this command (just change the path to blender): ALSA_CONFIG_PATH=/usr/share/alsa/alsa.conf /path/to/blender/4.1/blender

It looks like there is a long history of alsa's bugs like this.

To make it easier, you can also make a new file in /etc/profile.d/, for example /etc/profile.d/custom-alsa-path-fix.sh with this content: ALSA_CONFIG_PATH=/usr/share/alsa/alsa.conf Then execute chmod +x /etc/profile.d/custom-alsa-path-fix.sh

mertakbal commented 5 months ago

Not yet. I will add a new parameter, probably midi_control=... (similar to midi_note=...)

Thank you very much. Do you think the integration of sliders and knobs is something doable in near future?

example-sk commented 5 months ago

Thank you very much. Do you think the integration of sliders and knobs is something doable in near future?

It's almost done :) You can test it: audvis-5.0.0.zip

example-sk commented 5 months ago

Example driver: audvis(midi_control=83) You can obtain the number of your knobs with the "Debug Realtime Midi Messages" button.

mertakbal commented 5 months ago

It took me some time to find the correct combination of paths, so use this just as an inspiration. It's possible you will need to find the experiment with the paths. Fix the one of the "missing" folders by symlinking: sudo ln -s /usr/lib/x86_64-linux-gnu/alsa-lib /usr/local/lib/alsa-lib Start blender with this command (just change the path to blender): ALSA_CONFIG_PATH=/usr/share/alsa/alsa.conf /path/to/blender/4.1/blender It looks like there is a long history of alsa's bugs like this.

To make it easier, you can also make a new file in /etc/profile.d/, for example /etc/profile.d/custom-alsa-path-fix.sh with this content: ALSA_CONFIG_PATH=/usr/share/alsa/alsa.conf Then execute chmod +x /etc/profile.d/custom-alsa-path-fix.sh

Yes, that works! But it wont be possible to start my simply running my Blender by default with the new alsa configuration, right? For this probably Blender needs to be edited. Maybe at least the UPBGE developers can integrate this alsa fix :)

mertakbal commented 5 months ago

Example driver: audvis(midi_control=83) You can obtain the number of your knobs with the "Debug Realtime Midi Messages" button.

Works perfectly! Thank you very very much! As promised, I will make a tutorial in coming weeks which covers different functions of audvis including this realtime midi controllers. This makes Blender a serious competition for many live visualisation software. Some further improvement suggestions:

A more efficient webcam image streaming, without writing the images to the hard disk. Streaming live images to a Blender texture would be really incredible! In fact, the NI mate team, who used OSC stream for Microsoft Kinect, did something similar in BGE 12 years ago: link Improvements to the party mode. Blender can easily play multiple HD videos wrapped around 3D objects in real-time. This could be very effectively used in projection mapping projects. One of the most important things would be to fix the size of the party mode image to the screen. At the moment, you see a differing image size, the borders, and passe-partout of the camera, relative to your zooming level in camera view. This makes it impossible to work with projection mapping, as every time I go into party mode, the image would be at a different zoom level and screen position. If the party mode would create an image with absolute dimensions and positions, then this would also make the projections more stable.

In any case it is already really amazing to use the controller for playing live for stage visualisations and performances! Thank you very very much!

example-sk commented 5 months ago

Thanks for your kind words and for using AudVis :)

centomila commented 5 months ago

I have the same MIDI problem on Windows. No MIDI device on the list. I tried running blender as administrator. Mido and all the other python packages are installed correctly. There is some workaround for Windows too?

Wonderful project btw ❤️

example-sk commented 5 months ago

@centomila please, take a look into console (Toggle System Console) if there is any info

centomila commented 5 months ago

Sorry. You are right. My post isn't really useful without log.

Blender 3.6 LTS Traceback (most recent call last): File "C:\Users\Bach\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\audvis\ui\midi\realtime.py", line 22, in input_device_options for name in mido.get_input_names(): File "C:\Users\Bach\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\modules\_audvis_modules\a_1712566510\mido\backends\backend.py", line 174, in get_input_names devices = self._get_devices(**self._add_api(kwargs)) File "C:\Users\Bach\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\modules\_audvis_modules\a_1712566510\mido\backends\backend.py", line 167, in _get_devices if hasattr(self.module, 'get_devices'): File "C:\Users\Bach\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\modules\_audvis_modules\a_1712566510\mido\backends\backend.py", line 47, in module self.load() File "C:\Users\Bach\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\modules\_audvis_modules\a_1712566510\mido\backends\backend.py", line 63, in load self._module = importlib.import_module(self.name) File "C:\Program Files\Blender Foundation\Blender 3.6\3.6\python\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 688, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 883, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "C:\Users\Bach\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\modules\_audvis_modules\a_1712566510\mido\backends\pygame.py", line 13, in <module> from pygame import midi File "C:\Users\Bach\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\modules\_audvis_modules\a_1712566510\pygame\__init__.py", line 92, in <module> from pygame.base import * # pylint: disable=wildcard-import; lgtm[py/polluting-import] RuntimeError: Dynamic linking causes SDL downgrade! (compiled with version 2.28.3, linked to 2.0.20) File "C:\Users\Bach\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\audvis\ui\midi\realtime.py", line 15, in input_device_options WARN (bpy.rna): C:\Users\blender\git\blender-v360\blender.git\source\blender\python\intern\bpy_rna.c:1343 pyrna_enum_to_py: current value '0' matches no enum in 'AudvisMidiInputProperties', 'MIDI Device 1', 'input_name'

Blender 4.1

Traceback (most recent call last): File "C:\Users\Bach\AppData\Roaming\Blender Foundation\Blender\4.1\scripts\addons\audvis\ui\midi\realtime.py", line 22, in input_device_options for name in mido.get_input_names(): ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bach\AppData\Roaming\Python\Python311\site-packages\mido\backends\backend.py", line 174, in get_input_names devices = self._get_devices(**self._add_api(kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Bach\AppData\Roaming\Python\Python311\site-packages\mido\backends\backend.py", line 167, in _get_devices if hasattr(self.module, 'get_devices'): ^^^^^^^^^^^ File "C:\Users\Bach\AppData\Roaming\Python\Python311\site-packages\mido\backends\backend.py", line 47, in module self.load() File "C:\Users\Bach\AppData\Roaming\Python\Python311\site-packages\mido\backends\backend.py", line 63, in load self._module = importlib.import_module(self.name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Program Files\Blender Foundation\Blender 4.1\4.1\python\Lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1204, in _gcd_import File "<frozen importlib._bootstrap>", line 1176, in _find_and_load File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 690, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 940, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "C:\Users\Bach\AppData\Roaming\Python\Python311\site-packages\mido\backends\pygame.py", line 13, in <module> from pygame import midi File "C:\Users\Bach\AppData\Roaming\Python\Python311\site-packages\pygame\__init__.py", line 92, in <module> from pygame.base import * # pylint: disable=wildcard-import; lgtm[py/polluting-import] ^^^^^^^^^^^^^^^^^^^^^^^^^ RuntimeError: Dynamic linking causes SDL downgrade! (compiled with version 2.28.3, linked to 2.28.2) File "C:\Users\Bach\AppData\Roaming\Blender Foundation\Blender\4.1\scripts\addons\audvis\ui\midi\realtime.py", line 15, in input_device_options WARN (bpy.rna): C:\Users\blender\git\blender-v410\blender.git\source\blender\python\intern\bpy_rna.cc:1366 pyrna_enum_to_py: current value '0' matches no enum in 'AudvisMidiInputProperties', 'MIDI Device 1', 'input_name'

example-sk commented 5 months ago

@centomila please, try it again and look if there is something else in the very beginning. This error message is just saying that you have empty list of available devices. If there is any serious reason for the list being empty, it should be on the first lines of the log.

centomila commented 5 months ago

blender error log.txt

In this log i started blender, activated "MIDI Realtime" and pressed "Add Midi Input".

example-sk commented 5 months ago

@centomila

blender error log.txt

I'm almost sure the key error message is: RuntimeError: Dynamic linking causes SDL downgrade! (compiled with version 2.28.3, linked to 2.28.2)

My first guess is: there is some other add-on which installed some python package colliding with pygame.

My second guess: you can try to reinstall AudVis python packages and then restart Blender.

Screenshot from 2024-04-09 08-18-03

I'm not sure how to reproduce this error... Please let me know if this somehow helped to solve your problem.

centomila commented 5 months ago

Your analysis was correct. The issue lies with the SDL Library.

In the directory C:\Program Files\Blender Foundation\Blender 4.1\blender.shared, there is an SDL2.dll file, version 2.28.2.0.

image

I manually replaced it with version 2.28.3.0 from the directory C:\Users\Bach\AppData\Roaming\Blender Foundation\Blender\4.1\scripts\addons\modules\_audvis_modules\a_1712678594\pygame\SDL2.dll.

Now, I can see my list of MIDI controllers without any errors 🎉. I'm not certain if this is the best solution, but it works :D


Previously, I also tried this on my laptop, where Blender has never been installed. Could this issue be related to the MSI version of Blender?

example-sk commented 5 months ago

Disclaimer: I'm not a Windows user, so I may be wrong. I would suggest using Blender Portable (.zip). This gives you some freedom and maybe prevent some problems. On Linux, I have one folder with all Blender versions since 2.79 to newest development versions. I think this is not possible with Blender installer(s).

centomila commented 5 months ago

[OT] Blender on Windows supports multiple installations. Most of the settings are in the user folder. Like on Linux where you can have the same app installed as deb, snap, flatpak, appimage on Windows you have MSI, Windows Store, Steam and portable. Obligatory link to XKCD Standars Vignette: https://xkcd.com/927/ Blender Directories: https://docs.blender.org/manual/en/latest/advanced/blender_directory_layout.html [/OT]

I experimented with the portable version 4.1.0, and nothing changed. Replacing the DLL in "Blender\blender-4.1.0-windows-x64\blender.shared\" worked just as well as it did with the installer version.

I've noticed a significant size difference between the two files. Perhaps the version distributed with Blender has been recompiled or optimized in some way.

image

Let me know if I you need any additional Windows testing.

example-sk commented 5 months ago

Good news - no more manual fixing of SDL2 on Windows in the new version of AudVis - 5.1.0

centomila commented 5 months ago

Great! It Works! Thank you very very much!

https://github.com/example-sk/audvis/assets/26800547/f4f29b51-daaa-4a51-8844-254e2d6666cb