I've came to use mingus to try to reproduce some notes in python. Based on what was answered here, I've tried with:
from mingus.midi import fluidsynth
fluidsynth.init('/home/btc/Escritorio/SinestesiaRCB/gfx/ViolinsLong.sf2',"alsa")
fluidsynth.play_Note(64,0,100)
#Also tried with Note("C-5") and so forth
Using among others, one of this sf2 files. But then I got the error:
fluidsynth: warning: Failed to set thread to high priority
fluidsynth: warning: No preset found on channel 9 [bank=128 prog=0]
Researching a bit, this answer said:
For General MIDI compatibility, the default sound font instrument assignments are bank 0, program 0 ("Acoustic Grand Piano") for channels 0–8 and 10–15, and bank 128, program 0 ("Default Drum Set") for channel 9. Apparently, your sound font does not have the latter. This does not matter if your MIDI file does not assume General MIDI compatible instruments and does not try to play drum sounds on channel 9.
But aside of this, that may made things a bit clearer, I still don't know how to solve it.
Plus, if I use the same file that the answer of the very first link, then the error I get is this one (and don't know how to solve it neither):
fluidsynth: warning: Failed to set thread to high priority
fluidsynth: warning: Failed to pin the sample data to RAM; swapping is possible.
Update
Running the program with sudo permissions removes this errors, but it doesn't sound. This way, the error I get is:
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root'
I thought it may be a problem with the selected driver mode in fluidsynth
driver, but I've tried with them all (alsa, oss, and so forth) with the same result. Just for the sake of completeness, I'm running it within a VM, and other sounds inside it are correctly reproduced in my host speakers.
However based on this answer, I guess it should be solved by passing to it the right sound environment variable. Which I don't know. I've tried with:
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY python3 /home/btc/Escritorio/SinestesiaRCB/SinestesiaRCB.py
Where the complete path to the file is needed since this needs sudo permissions and changes its working directory, and in the end the same error came: XDG_RUNTIME_DIR
.
Update 2
If I run it with sudo -E
option, the error is replaced by a new one:
QStandardPaths: wrong ownership on runtime directory /run/user/1000, 1000 instead of 0
I'm reading in some webs, that the 1000
user is supposed to be the default user instead of root.
Therefore, I've done a:
sudo chown root:root /run/user/1000
Just to try, and then the app runs without fails, but it still doesn't sound.
Update 3
Based on this example and this Q&A, I've tried both to use time sleep with several times, and using raw_input
as well after (also before) doing a play_note, but it still doesn't sound.
I'll answer my own question, but the very big part of the debug/solving process is in the question itself done with updates.
The last part was to get it to sound, when not even waiting with sleep
was making it work. Not even doing it before and after the play_note
function. May I say that this function always returned True
, so the note was expected to sound from the very beginning. The thing is, that the SF2 file (almost 150MB) was loaded successfully, or at least it seemed like it, since it returned True
as well and was for sure pretty fast.
The solution
Let's continue after reaching the point where no errors were printed when executing my script (just before Update 3 in the Question).
I wanted to check how much CPU percent usage was doing my script, so I used top
on my Linux terminal and found pulseaudio
running from several days ago:
Killing this process allowed it to sound finally. However, I must say that a time.sleep()
with about 0.25
seconds was added after the play_Note()
function, in order to let it play the note completely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With