Update of /cvsroot/audacity/lib-src/libnyquist
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv16552/lib-src/libnyquist

Modified Files:
        nyx.c nyx.h 
Log Message:
Added support for Nyquist plugins written with the SAL syntax.
Added support to the EffectNyquist and the Nyquist bridge for better debug 
handling.
EffectNyquist now yields while the actually nyquist plugin is running (before 
the progress dialog kicks in) to allow window refreshes
Added a module interface to EffectNyquist in preparation for an upcoming module.
Added a couple more module dispatch points.

Index: nyx.c
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyx.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- nyx.c       2 Feb 2009 04:45:43 -0000       1.3
+++ nyx.c       5 Feb 2009 18:12:17 -0000       1.4
@@ -37,9 +37,10 @@
 extern snd_list_type zero_snd_list;
 
 /* globals */
-int                 nyx_output_pos;
-int                 nyx_output_len;
-char               *nyx_output_string;
+nyx_os_callback     nyx_os_cb = NULL;
+void               *nyx_os_ud;
+nyx_output_callback nyx_output_cb;
+void               *nyx_output_ud;
 int                 nyx_expr_pos;
 int                 nyx_expr_len;
 const char         *nyx_expr_string;
@@ -96,9 +97,8 @@
       argv[0] = "nyquist";
       xlisp_main_init(1, argv);
 
-      nyx_output_len = 0;
-      nyx_output_pos = 0;
-      nyx_output_string = NULL;
+      nyx_os_cb = NULL;
+      nyx_output_cb = NULL;
       
       nyx_first_time = 0;
    }
@@ -111,12 +111,8 @@
 
 void nyx_cleanup()
 {
-   if (nyx_output_string) {
-      free(nyx_output_string);
-      nyx_output_string = NULL;
-      nyx_output_pos = 0;
-      nyx_output_len = 0;
-   }
+   nyx_output_cb = NULL;
+   nyx_os_cb = NULL;
 
    xlpop(); /* garbage-collect nyx_result */
    gc(); /* run the garbage-collector now */
@@ -167,22 +163,10 @@
 {
 }
 
-void nyx_capture_output(int max_len)
-{
-   if (nyx_output_string)
-      free(nyx_output_string);
-
-   nyx_output_string = (char *)malloc(max_len);
-   nyx_output_len = max_len;
-   nyx_output_pos = 0;
-}
-
-void nyx_get_captured_output(int *out_len,
-                             const char **out_chars)
+void nyx_capture_output(nyx_output_callback callback, void *userdata)
 {
-   *out_len = nyx_output_pos;
-   *out_chars = (const char *)nyx_output_string;
-   nyx_output_pos = 0;
+   nyx_output_cb = callback;
+   nyx_output_ud = userdata;
 }
 
 void nyx_set_audio_params( double rate )
@@ -441,11 +425,11 @@
 {
    sample_block_type block;
    sound_type snd;
-   sound_type *snds;
-   float *buffer;
-   long bufferlen;
-   long *totals;
-   long *lens;
+   sound_type *snds = NULL;
+   float *buffer = NULL;
+   long bufferlen = 0;
+   long *totals = NULL;
+   long *lens = NULL;
    long cnt;
    int result = 0;
    int num_channels;
@@ -456,9 +440,21 @@
       return;
 
    num_channels = nyx_get_audio_num_channels();
+
    snds = (sound_type *)malloc(num_channels * sizeof(sound_type));
+   if (snds == NULL) {
+      goto finish;
+   }
+
    totals = (long *)malloc(num_channels * sizeof(long));
+   if (totals == NULL) {
+      goto finish;
+   }
+
    lens = (long *)malloc(num_channels * sizeof(long));
+   if (lens == NULL) {
+      goto finish;
+   }
 
    /* setup the error return */
    xlbegin(&nyx_cntxt,CF_TOPLEVEL|CF_CLEANUP|CF_BRKLEVEL,(LVAL)1);
@@ -475,9 +471,6 @@
       lens[ch] = snd_length(snd, snd->stop);
    }
 
-   buffer = NULL;
-   bufferlen = 0;
-
    while(result==0) {
       for(ch=0; ch<num_channels; ch++) {
          snd = snds[ch];
@@ -494,7 +487,12 @@
          if (cnt > bufferlen) {
             if (buffer)
                free(buffer);
+
             buffer = (float *)malloc(cnt * sizeof(float));
+            if (buffer == NULL) {
+               goto finish;
+            }
+
             bufferlen = cnt;
          }
 
@@ -517,13 +515,23 @@
    success = TRUE;
 
  finish:
-   if (buffer)
+   xlend(&nyx_cntxt);
+
+   if (buffer) {
       free(buffer);
-   free(snds);
-   free(totals);
-   free(lens);
+   }
 
-   xlend(&nyx_cntxt);
+   if (lens) {
+      free(lens);
+   }
+
+   if (totals) {
+      free(totals);
+   }
+
+   if (snds) {
+      free(snds);
+   }
 
    return success;
 }
@@ -621,6 +629,29 @@
    return NULL;
 }
 
+void nyx_set_os_callback(nyx_os_callback callback, void *userdata)
+{
+   nyx_os_cb = callback;
+   nyx_os_ud = userdata;
+}
+
+void nyx_stop()
+{
+   xlflush();
+   xltoplevel();
+}
+
+void nyx_break()
+{
+   xlflush();
+   xlbreak("BREAK", s_unbound);
+}
+
+void nyx_continue()
+{
+   xlflush();
+   xlcontinue();
+}
 
 int ostgetc()
 {
@@ -723,8 +754,8 @@
 {     
    oscheck();          /* check for control characters */
    
-   if (nyx_output_pos < nyx_output_len)
-      nyx_output_string[nyx_output_pos++] = (char)ch;
+   if (nyx_output_cb)
+      nyx_output_cb(ch, nyx_output_ud);
    else
       putchar(((char) ch));
 }
@@ -732,7 +763,7 @@
 /* ostoutflush - flush output buffer */
 void ostoutflush()
 {
-   if (nyx_output_pos >= nyx_output_len)
+   if (!nyx_output_cb)
       fflush(stdout);
 }
 
@@ -744,6 +775,9 @@
 /* oscheck - check for control characters during execution */
 void oscheck(void)
 {
+   if (nyx_os_cb) {
+      nyx_os_cb(nyx_os_ud);
+   }
    /* if they hit control-c:
       xflush(); xltoplevel(); return;
    */

Index: nyx.h
===================================================================
RCS file: /cvsroot/audacity/lib-src/libnyquist/nyx.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- nyx.h       31 Jan 2009 19:35:10 -0000      1.2
+++ nyx.h       5 Feb 2009 18:12:17 -0000       1.3
@@ -37,13 +37,23 @@
                                      long totlen,
                                      void *userdata);
 
-   /* Set to 0 to stop capturing output */
-   void        nyx_capture_output(int max_len);
+   typedef void (*nyx_output_callback)(int c,
+                                       void *userdata);
+
+   typedef void (*nyx_os_callback)(void *userdata);
+
+   /* Set to NULL to stop capturing output */
+   void        nyx_capture_output(nyx_output_callback callback,
+                                  void *userdata);
+
+   /* Set to NULL to stop checking */
+   void        nyx_set_os_callback(nyx_os_callback callback,
+                                   void *userdata);
+
+   void        nyx_stop();
+   void        nyx_break();
+   void        nyx_continue();
 
-   /* Returns all output text captured so far, and resets it */
-   void        nyx_get_captured_output(int *out_len,
-                                       const char **out_chars);
-   
    void        nyx_set_audio_params( double rate );
 
    void        nyx_set_input_audio(nyx_audio_callback callback,


------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Audacity-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/audacity-cvs

Reply via email to