Skip to content

Receive decorator events inside of class #8

@frederikbrammer

Description

@frederikbrammer

Hey there,

I would like to organize everything related to the Ableton Push interaction inside of a class named PushService. However, when the decorated function is called, I need to have access to the object's properties. How can I access self property inside of that function?

Here's my class definition:

class PushService():
    def __init__(self, eventQueueService: EventQueueService):
        self.eventQueueService = eventQueueService

        print("Initializing push service...")
        self.push = push2_python.Push2(run_simulator=True)

        # Start by setting all pad colors to white
        self.push.pads.set_all_pads_to_color('white')

    @push2_python.on_pad_pressed()
    def on_pad_pressed(push, pad_n, pad_ij, velocity):
        if pad_ij == (7,7):
            self.eventQueueService.registerBeat()     # <= Here I need access to the self property to call the registerBeat function

        # Set pressed pad color to green
        print('Pad', pad_ij, 'pressed with velocity', velocity)
        push.pads.set_pad_color(pad_ij, 'green')

Thanks a lot in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions