[Cs-dev] how do i get host data from a dynamically loaded instance of csound via the c api?
Date | 2009-08-23 02:02 |
From | Andy Fillebrown |
Subject | [Cs-dev] how do i get host data from a dynamically loaded instance of csound via the c api? |
Attachments | None None |
maybe this has a simple C++ specific solution that doesn't concern Csound, but it is beyond me at the moment... I'm dynamically loading both the floats and doubles version of the C api simultaneously and wrapping them in C++ classes. The problem I'm running into is I can't retrieve host data from the CSOUND pointer passed in the callbacks because I don't know which library made the call. Is there a way to know which library has called the callback so that I can get the correct address of "csoundGetHostData"? My current solution is to track each wrapper class's creation and destruction using a static hash table with the CSOUND pointer as the key. This works well enough, but the additional access time leaves me wondering if there's a better way. Usually when working with callbacks I'm able to specify my own address that will be passed back, too, but I do not see a way of doing this in the Csound api -- and from the projects I've browsed it appears the api is not designed with dynamic loading in mind. I can't help but wonder if I'm missing something, though, or if maybe someone else is using the Csound libraries this way and has resolved similar issues already. Regards, ~ andy.f |
Date | 2009-08-23 16:30 |
From | Michael Gogins |
Subject | Re: [Cs-dev] how do i get host data from a dynamically loaded instance of csound via the c api? |
Why don't you use the existing C++ wrappers -- because of this business of loading both the float and the double version? Are you using one wrapper for each library, or one wrapper for both libraries? The hashtable access time should not be a real problem. You can reduce it further by using a std::vector |
Date | 2009-08-23 19:44 |
From | Andy Fillebrown |
Subject | Re: [Cs-dev] how do i get host data from a dynamically loaded instance of csound via the c api? |
----- "Michael Gogins" |
Date | 2009-08-23 20:18 |
From | Michael Gogins |
Subject | Re: [Cs-dev] how do i get host data from a dynamically loaded instance of csound via the c api? |
Let's say you have callback: int mycallback(CSOUND *csound,...); You have in your wrapper: CSOUND *floatCsound; CSOUND *doubleCsound; Your callback is called: int mycallback(CSOUND *csound,...) { // NOT!!!! csoundGetHostData(csound); void *myHostData = csound->GetHostData(csound); } The CSOUND:GetHostData function is csoundGetHostData from the same library as CSOUND *floatCsound or doublecsound was created from. If the callback is called from the float library, the CSOUND::GetHostData function here is the one from the float library. If the callback is called from the double library, the CSOUND::GetHostData here is the one from the double library. This kind of thing is the whole reason why all the API functions are members of the CSOUND structure. I don't get what your problem is with this -- send me your code? Regards, Mike On 8/23/09, Andy Fillebrown |
Date | 2009-08-24 01:05 |
From | Andy Fillebrown |
Subject | Re: [Cs-dev] how do i get host data from a dynamically loaded instance of csound via the c api? |
Are you recommending including csoundCore.h and making the CSOUND pointer transparent? I was under the impression that leaving the CSOUND pointer opaque was more flexible when loading the libraries dynamically, allowing users to specify in the host app which csound library to use instead of having to recompile and relink to a different one each time ...and AFAIK I can't resolve csound->GetHostData dynamically by function name only like I can with csoundGetHostData, and by being able to load and link the wrapper to the Csound API library at runtime it allows users to specify not only which float version of the API to use but also which release version as long as the "csoundXXX" function names remained the same across releases. Where the function pointers are located in the struct alignment would then be a non-issue. If I include any particular version of csoundCore.h wouldn 't I lose the benefit of being able to late-bind to different versions of the Csound API simultaneously? ----- "Michael Gogins" |