On Sunday 11 December 2005 20:12, Victor Lazzarini wrote: > Could you post an example? Here is a simple Java example that works with the current CVS sources (note that this is not implemented for other languages yet, and may be changed or removed later). The C++ class it uses is also included below. // CallbackExample.java import csnd.*; public class CallbackExample { // JavaCallbacks is a subclass of CsoundCallbackWrapper that // can override the methods MessageCallback(), InputValueCallback(), // OutputValueCallback(), and YieldCallback() for defining callbacks static class JavaCallbacks extends CsoundCallbackWrapper { JavaCallbacks(Csound cs) { super(cs); } public int YieldCallback() { java.lang.System.err.println("Yield called for " + GetCsound() + " !"); return 1; } public void MessageCallback(int attr, String msg) { if (msg.endsWith("\n")) java.lang.System.err.print("ATTR: " + attr + " MSG: " + msg); else java.lang.System.err.println("ATTR: " + attr + " MSG: " + msg); } } public static void main(String argv[]) { Csound cs = new Csound(); // create a callback wrapper object for this instance of Csound // note that this will use the host data pointer of 'cs', so the // host data cannot be used for other purposes JavaCallbacks cb = new JavaCallbacks(cs); // enable the callbacks for which there are definitions above cb.SetYieldCallback(); cb.SetMessageCallback(); // build an argument list from the command line options CsoundArgVList args = new CsoundArgVList(); args.Append("csound"); for (int i = 0; i < argv.length; i++) args.Append(argv[i]); // call Compile() to see if the callbacks work cs.Compile(args.argc(), args.argv()); // Reset() must be called before 'cs' or 'cb' is possibly // garbage collected, otherwise a crash may occur cs.Reset(); // free memory used by the argument list; this is optional, and // would be done automatically when 'args' is garbage collected args.Clear(); } }; // end of CallbackExample.java --------------------------------------------------------------------- // callback wrapper class declared in interfaces/cs_glue.hpp class CsoundCallbackWrapper { private: CSOUND *csound_; public: virtual void MessageCallback(int attr, char *msg) { } virtual MYFLT InputValueCallback(const char *chnName) { return (MYFLT) 0; } virtual void OutputValueCallback(const char *chnName, MYFLT value) { } virtual int YieldCallback() { return 1; } void SetMessageCallback(); void SetInputValueCallback(); void SetOutputValueCallback(); void SetYieldCallback(); CSOUND *GetCsound() { return csound_; } // -------- CsoundCallbackWrapper(Csound *csound); CsoundCallbackWrapper(CSOUND *csound); virtual ~CsoundCallbackWrapper() { } }; ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ Csound-devel mailing list Csound-devel@lists.sourceforge.net