[Duplex] no static "xxx" in "yyy" Class

Hi everybody :slight_smile:

I started to write a driver for the M-Audio Axiom but something get me mad too often, i’m unable to use the class function, there’s something here i can’t understand ^^

For the moment i use a lot of MidiDevice class function, so as my driver is derived from this class, i’ve found some trick to use the function i needed. But now i try to use some Scheduler function, always get that error : no static function in class !
As there’s no documentation on the lua class implementation (in renoise), it’s hard to find something…

I think i’m too used to other language and what’s seem’s logic to me aren’t for LUA ^^
So basically, could someone give me an exemple on how to use a class function in user lua driver ?

I’ve tried Class.function as Class:function, passing self as first argument, nothing work ^^

Is there a way to use it or i must write my code directly in the class i want to use ? Or is there manual/doc about the use of class in Renoise ?
From now, i find more easy to write my code on one file with all the function copy paste from the class but i’m sure there’s a way to do better. My code start to have a lot of lines, i can’t continue like this otherwise it will be unreadable later ^^

Thanks to all and to Danoise for this fantastic tool !

So, for example if your class is called Axiom you add methods to that class, or use existing methods (which will then override the ones in the MidiDevice class).

If you do choose to override a MidiDevice class method, you might want to call the original methods - this really depend on whether your method is meant to completely replace the MidiDevice method or not. But in such a case, calling the parent (or “super”) class would be done like this:

function Axiom:some_method(arg1,arg2)  
  
 -- do some stuff...  
 print("Hello World!")  
  
 -- call the parent method with the same arguments  
 MidiDevice.some_method(self,arg1,arg2)  
  
end  

Like you have already discovered, “self” is needed when calling a class method statically. Otherwise, it would not know that you are in fact calling from an extended method of itself.

Since all of Duplex is simply a tool like any other tool, you would have to consult the documentation that come with Duplex itself. Look in the “Docs” folder of the tool, the Scheduler is covered (briefly) there as well.
Also, try searching for “Scheduler” in the Duplex source code. You will find plenty of examples where it is being used for different things. For example, the standard UIButton class has a “flash” method which will animate the color - this could be useful for your purpose, I think?

The Renoise API is using luabind to achieve native object-oriented functionality. You can read about it here (although that documentation mostly deals with C++ bindings and not the lua part itself). One big drawback of luabind is that classes have limited control of meta-table methods, something that confused me a bit. Chances are that you won’t need such a thing, but nevertheless nice to know.

Hmm, no wonder. Diving head-first into a new language and writing a driver class for a framework like Duplex isn’t for the faint of heart. It takes time to learn what the different classes do, and even more time to add new functionality on top of it (which, unfortunately, is the case with Axiom).
At this stage, I would recommend that you share your progress somehow - I could take a look at the code and possibly come up with some ideas on how to streamline it.

Whow, thanks for all the explanation.
I’d have a look a the luabind doc yesterday but as you said, it’s mostly on c++… there’s a little paragraph about inheritance of class in lua but not so much.
I’ve read the duplex manual too, really good one that get me into duplex quickly but as soon as you want to write your own class, it’s limited (and it’s most lua learning at this point so it make sens ^^)
Need to look at the doc folder…

I was not sure about the overriding process as sometime with different code i’ve tested i have the same action repeated 2 times so i assume there must be a duplication somewhere. Now i see how to overrride or just share, that’s more clear, thanks !

I need to go more in deep with lua and duplex possibility, when i look at the different class and their functions, it seem’s really fantastic with endless possibility.
I’ll have a lot more time soon so i will not capitulate ^^

I start to imagine what we could do with a big driver with plenty of function and duplex is really THE tool for that.
I remember when i’ve started to fear that duplex couldn’t achieve more than what i can without it but now i only start to discover that it could acheive far more stuff than i could dream of if you have the skill to code it ^^

Will comeback in duplex topic with the lua file, thanks a lot. I need to refresh it, it’s a real mess now with plenty of comment, print, the list of directlink implementation etc… ^^