LIMUNIMI / pycarla

Synthesize music in Python using any audio plugins, both realtime and offline (batch-processing)
https://federicosimonetta.eu.org
GNU General Public License v3.0
11 stars 1 forks source link

[INFO] Cant get pycarla to work #6

Open miehae0815 opened 1 year ago

miehae0815 commented 1 year ago

I try to use pycarla to have a python script create and control midi output over the systems audio out.

I'm not very experienced with linux and this might cause the problem. Sorry for that... :)

However, I used the usage examples to have carla output a downloaded midifile. at the moment I'm using lubuntu 22.10. Its a fresh install and I just did

sudo apt-get install jackd2
sudo apt-get install carla

However, Carla is not be able to start the engine if QjackCtl is not startet and running first. Maybe the wrong place to ask here? Furthermore, I had to connect carla and systems out not only in the carla patchbay but also in the QjackCtl Patchcontrol have to connect them? I had a try earlier, where both of these steps worked flawlessly, but just cant reproduce it.. Then I installed pip and python 3.10.7 and followed the installation instructions. If I do all of that, created a carla project in the same folder and have carla up and running opening that project I used the following code:

from pycarla import Carla, MIDIPlayer, AudioRecorder, get_smf_duration
carla = Carla("A.carxp", ['-R', '-d', 'alsa'], min_wait=4)
carla.start()

player = MIDIPlayer()

with MIDIPlayer() as player:
    #print("Playing full file using freewheeling mode..")
    duration = get_smf_duration("test.mid")
    # in the following, `condition` ensures that both the recorder and player
    # start in the same cycle
    player.synthesize_midi_file("test.mid", in_fw=True, out_fw=True)
    # or asynchronously:
    # player.synthesize_midi_file("filename.mid", sync=False)
    # in this case, use
    # player.wait(in_fw=True, out_fw=True)
    player.close()
    server.close()
    #pass

try:
    carla.kill()
except Exception as e:
    print("Processes already closed!")

I get the following error:

Carla ready!
Traceback (most recent call last):
  File "/home/mane/test1.py", line 12, in <module>
    player.synthesize_midi_file("test.mid", in_fw=True, out_fw=True)
  File "/usr/local/lib/python3.10/dist-packages/pycarla/midiplayer.py", line 193, in synthesize_midi_file
    return self.synthesize_messages(messages, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/pycarla/midiplayer.py", line 118, in synthesize_messages
    self.activate()
  File "/usr/local/lib/python3.10/dist-packages/pycarla/midiplayer.py", line 36, in activate
    raise RuntimeWarning(
RuntimeWarning: Cannot find the Carla instance, Retry later!

I would really appreciate any help with that! This package is exactly what I need, if only I could get it running! :)

I also (at least I think I did) solved the following problems so far, maybe it makes sense to add this to the documentation?:

00sapo commented 1 year ago

Hi, thank you very much for your interest in pycarla and for your suggestions!

I will try to improve the documentation in these days...

Coming to your issue:

Could you please try the above steps 2. and 3. and report again?

Also, could you tell me the version of Carla that you're using? If it's not working in patchbay mode, than install it as in point 1.

miehae0815 commented 1 year ago

Thank you for your help! I tried to follow the instructions step by step. Here is what I did:

fresh lubuntu 22.10 install sudo apt-get update sudo apt-get upgrade sudo apt-get install python3-pip pip install --upgrade pip pycarla

Here I got the first question. I do this not with sudo? I got a warning "Defaulting to user installation......WARNING: the scripts pip, pip3 and... ,,,not added to PATH...". Should I not install pip first?

sudo apt-get install jackd2 (here I got a prompt about using Realtime priority and selected yes) sudo usermod -a -G audio UserID python -m pycarla.carla --download

Actually, I have no idea how this installs carla. anyways tried to start carla in the shell, did not work. So I installed carla now. Or am I missing somethin here?

sudo apt-get install carla

Is the "get" wrong because it will download a version of carla instead of using the one provided with the --download earlier? I tried to remove carla and go again python -m pycarla.carla --download sudo apt install carla

In both versions I tried to initialize carla in Qjackctl and save the project. When I then start Jack and Carla and run my pycarla script I got an error: CarlaEngine::loadProjectInternal() - Unhandled option 'JSFX_PATH' ... RuntimeWarning: Cannot find the Carla instance, Retry later!

Furthermore, I checked again the patch in Jack and ther now is one Carla instance for every test run I do? I'm not sure how I should wire up in Jack, if the Carla instance is created by my script?

Sorry, if my mistake is somewhere obvious... Thank you for your assistance! :)

00sapo commented 1 year ago

Hello, in general, don't use the system python for developing, because this will soon end with package conflicts. Those packages should only be used for system software. Instead, use python virtual environments and local python indtallations; there are several ways to do this, for instance:

With this systems you can install anything.

Btw, what error throws the command python -m pycarla.carla --download?

About the error regarding Carla, it looks like a plugin path is set up uncorrectly. Try asking to the Carla community...

About the jack connections, just start Carla with GUI, set up everything, try closing Carla and reopening. Does it restore the connections? Sorry, but this package is mainly intended for recording and not for making sound from the speakers. The setup for this use-case is a little painful. If only want to send MIDI messages stored in one file to some other external synthesizer via jack, check out pyo. If you also want to create the MIDI messages live, check out some live coding system...

00sapo commented 1 year ago

Also, have you set Carla engine in patchbay mode?