Please help a python newbie with his remote script

Discussion of music production, audio, equipment and any related topics, either with or without Ableton Live
Post Reply
Coupe70
Posts: 1097
Joined: Fri Jul 23, 2004 7:25 am
Location: Mainz / Germany
Contact:

Please help a python newbie with his remote script

Post by Coupe70 » Mon Feb 21, 2011 10:56 pm

Hi,

I had an idea for a remote script that uses a module called
SendKeys or SendKeyCtypes. I got this module working in the
normal Python interpreter, but Live crashes as soon as I
load my script -> Runtime Error.

I found out that Live crashes every time the script tries
to import an .pyd file (_sendkeys.pyd or _ctypes.pyd). Is
there something I'm doing wrong or does Live not allow this ?

Is there another possibility to do
from ctypes import windll
?

In fact I'm nearly trying all this blind as I know very little
about Python. Even my starting point, __init__.py and a mini-script
that should run but do nothing throws errors in the log file:

44807 ms. RemoteScriptError: AttributeError
44807 ms. RemoteScriptError: :
44807 ms. RemoteScriptError: erster instance has no attribute 'refresh_state'
44807 ms. RemoteScriptError:
44807 ms. RemoteScriptError: AttributeError
44808 ms. RemoteScriptError: :
44808 ms. RemoteScriptError: erster instance has no attribute 'connect_script_instances'
44808 ms. RemoteScriptError:
44815 ms. RemoteScriptError: AttributeError
44816 ms. RemoteScriptError: :
44816 ms. RemoteScriptError: erster instance has no attribute 'can_lock_to_devices'
44816 ms. RemoteScriptError:
44871 ms. RemoteScriptError: AttributeError
44871 ms. RemoteScriptError: :
44872 ms. RemoteScriptError: erster instance has no attribute 'build_midi_map'
44872 ms. RemoteScriptError:
44887 ms. RemoteScriptError: AttributeError
44887 ms. RemoteScriptError: :
44888 ms. RemoteScriptError: erster instance has no attribute 'suggest_input_port'
44888 ms. RemoteScriptError:
44888 ms. RemoteScriptError: AttributeError
44889 ms. RemoteScriptError: :
44889 ms. RemoteScriptError: erster instance has no attribute 'suggest_output_port'
44889 ms. RemoteScriptError:
44998 ms. RemoteScriptError: AttributeError
44999 ms. RemoteScriptError: :
44999 ms. RemoteScriptError: erster instance has no attribute 'update_display'




Could somebody please provide me with an working script that does nothing or
simply mutes track 1 or something so I know it's working ?

Thanks.
Phongemeinschaft (Live-ElectroJazz / NuJazz)
Homepage - youtube - Like! :-)
Live 9 (32Bit), HP DV7, i5 2,53GHz, 8 GB RAM, Win7 (64Bit)

Hanz_Petrov
Posts: 119
Joined: Sat Feb 06, 2010 2:39 pm
Contact:

Re: Please help a python newbie with his remote script

Post by Hanz_Petrov » Tue Feb 22, 2011 2:20 am

Here's an example of a remote script which does nothing (needs to be saved as 2 separate files in the MIDI Remote Scripts directory - see my blog for details):

Code: Select all

#__init__.py
from Spam import Spam
def create_instance(c_instance):
    return Spam(c_instance)
and:

Code: Select all

#Spam.py 
#This is a stripped-down Framework script
from _Framework.ControlSurface import ControlSurface
class Spam(ControlSurface):
    def __init__(self, c_instance):
        ControlSurface.__init__(self, c_instance)
It's also been my experience that a remote script cannot import a Python DLL (.pyd). In fact, I tried briefly to do exactly the same thing with SendKeys about a year ago, but never got back to it seriously. It would indeed be cool to be able to send keystokes from a remote script...

Best,

Hanz

PS: SendKeys is Windows only, is it not?
http://remotescripts.blogspot.com/ - an introduction to the Framework classes

Coupe70
Posts: 1097
Joined: Fri Jul 23, 2004 7:25 am
Location: Mainz / Germany
Contact:

Re: Please help a python newbie with his remote script

Post by Coupe70 » Tue Feb 22, 2011 2:42 am

Hi Hanz,

thanks for your help !
Hanz_Petrov wrote:

Code: Select all

#Spam.py 
#This is a stripped-down Framework script
from _Framework.ControlSurface import ControlSurface
class Spam(ControlSurface):
    def __init__(self, c_instance):
        ControlSurface.__init__(self, c_instance)
So the ControlSurface lines are a MUST even when doing nothing ?
I guess that's what I missed.
It's also been my experience that a remote script cannot import a Python DLL (.pyd).
In fact, I tried briefly to do exactly the same thing with SendKeys about a year ago,
but never got back to it seriously. It would indeed be cool to be able to send keystokes
from a remote script...
That's a pity, would be great to have it integrated in ClyphX, but Stray
could not find a way to directely implement it, either. It works well from
the interpreter. I was able to toggle detail view on/off with

Code: Select all

        sleep(5)
        SendKeys.SendKeys("^%l")  # Ctrl+Alt*L
by starting the .py and then switching to Live as SendKeys always sends
to the active window. So to get this keystroke feature it seems that it needs
the SendKey part to run in the interpreter, triggered from a remote script,
perhaps via local network or MIDI Yoke..?
SendKeys is Windows only, is it not?
I found this for Mac:
http://stackoverflow.com/questions/1770 ... -in-python

Cheers, Rick
Phongemeinschaft (Live-ElectroJazz / NuJazz)
Homepage - youtube - Like! :-)
Live 9 (32Bit), HP DV7, i5 2,53GHz, 8 GB RAM, Win7 (64Bit)

Coupe70
Posts: 1097
Joined: Fri Jul 23, 2004 7:25 am
Location: Mainz / Germany
Contact:

Re: Please help a python newbie with his remote script

Post by Coupe70 » Wed Feb 23, 2011 4:55 pm

Hi Hanz, hi all other remote script experts,

I'm having a hard time finding out how to use the
basic functions of the Live API in remote scripts.
I found different sites with a documentation or parts
of it and tried to read some remote scripts, but most
parts of it are too complicated for me and I can't
match them with what I found in the documentation.

I'm really trying to learn, but it would be great
to have a starting point. Perhaps someone can set
up a script for me that

- starts a clip on e.g. track 2, slot 2
- sets the volume of a track to a certain level
- reads the value of a knob (e.g. a rack macro) or listens to it
- receives / sends a midi cc or note

Or can you point me to more / better documentation I can learn from ?
So far I found
http://hanzoffsystems.tech.officelive.com/default.aspx
and some scripts and discussions here at the forum.

And of course I read your tutorials, Hanz, but they start
to be too complicated for me very soon...
Phongemeinschaft (Live-ElectroJazz / NuJazz)
Homepage - youtube - Like! :-)
Live 9 (32Bit), HP DV7, i5 2,53GHz, 8 GB RAM, Win7 (64Bit)

Post Reply