Resolving a problem with calling _send_midi inside a file



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

Screenshot of the error below, where css_fhf_nektar_pacer is my CSS script’s name that has the 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):

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 users can call _send_midi inside their file?

Thank you!


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 = MethodType(send_midi, self)

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

So make sure this Reaction is run first thing.

HDV Answered question July 1, 2024

Hi Glenn,

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



HDV Answered question July 1, 2024