Resolving a problem with calling _send_midi inside a user.py file

2

Hi,

When calling the _send_midi inside a user.py file an AttributeError is given.

Screenshot of the error below, where css_fhf_nektar_pacer is my CSS script’s name that has the user.py script imported.

I figured out that I could circumvent this problem by creating my own send_midi method inside the CSS script.

def send_midi(self, msg):
  self._send_midi(msg)

A more detailed explanation can be found in the comment I made on this post.

Feature Request

The problem is that this custom added code will disappear whenever the CSS script is re-generated.

Would it be possible to add some similar code to every generation of a CSS script so that user.py users can call _send_midi inside their user.py file?

Thank you!

EDIT:

Sometimes the best ideas come just when you’re falling asleep or wake up. Last night I thought “What if I could add the send_midi method to the class instance from within a Reaction?” and today I found a way. So, this Feature Request might not be so urgent or necessary after all.

Here’s a link to the tutorial I used to figure out the code needed to dynamically add a new method to the class instance of the CSS script. And here’s the way I implemented it:

  1. Made a new Reaction. Named it “Add Send_Midi Method”
  2. Set “Script –> script is initialised” as the Listener
  3. Created an action with the following code below.

from types import MethodType
def send_midi(self, msg):
  self._send_midi(msg)
self.send_midi = MethodType(send_midi, self)

Once this code has run, you’ll be able to use self._send_midi() inside the user.py file.

So make sure this Reaction is run first thing.

mamajuana Answered question December 4, 2024
0

Hi Glenn,

thanks a lot for your efforts! I will try it.

Regards

Dieter

HDV Answered question July 1, 2024
0

Great Job!!   works smooth.. Excellent

mamajuana Answered question December 4, 2024