Logo Search packages:      
Sourcecode: csound version File versions  Download package

PUBLIC void csoundReset ( CSOUND  ) 

Resets all internal memory and state in preparation for a new performance. Enables external software to run successive Csound performances without reloading Csound. Implies csoundCleanup(), unless already called.

Copy everything EXCEPT the function pointers. We do it by saving them and copying them back again...

Definition at line 2223 of file csound.c.

References CSOUND_::ids.

  {
    CSOUND    *saved_env;
    void      *p1, *p2;
    uintptr_t length;

    csoundCleanup(csound);

    /* call registered reset callbacks */
    while (csound->reset_list != NULL) {
      resetCallback_t *p = (resetCallback_t*) csound->reset_list;
      p->func(csound, p->userData);
      csound->reset_list = (void*) p->nxt;
      free(p);
    }

    /* call local destructor routines of external modules */
    /* should check return value... */
    csoundDestroyModules(csound);
    /* IV - Feb 01 2005: clean up configuration variables and */
    /* named dynamic "global" variables of Csound instance */
    csoundDeleteAllConfigurationVariables(csound);
    csoundDeleteAllGlobalVariables(csound);

    cscoreRESET(csound);
    tranRESET(csound);

    csound->oparms_.odebug = 0;
    /* RWD 9:2000 not terribly vital, but good to do this somewhere... */
    pvsys_release(csound);
    close_all_files(csound);
    /* delete temporary files created by this Csound instance */
    remove_tmpfiles(csound);
    rlsmemfiles(csound);
    /**
     * Copy everything EXCEPT the function pointers.
     * We do it by saving them and copying them back again...
     */
    /* hope that this does not fail... */
    saved_env = (CSOUND*) malloc(sizeof(CSOUND));
    memcpy(saved_env, csound, sizeof(CSOUND));
    memcpy(csound, &cenviron_, sizeof(CSOUND));
    length = (uintptr_t) &(csound->ids) - (uintptr_t) csound;
    memcpy((void*) csound, (void*) saved_env, (size_t) length);
    csound->oparms = &(csound->oparms_);
    csound->hostdata = saved_env->hostdata;
    p1 = (void*) &(csound->first_callback_);
    p2 = (void*) &(csound->last_callback_);
    length = (uintptr_t) p2 - (uintptr_t) p1;
    memcpy(p1, (void*) &(saved_env->first_callback_), (size_t) length);
    csound->csoundCallbacks_ = saved_env->csoundCallbacks_;
    memcpy(&(csound->exitjmp), &(saved_env->exitjmp), sizeof(jmp_buf));
    csound->memalloc_db = saved_env->memalloc_db;
    free(saved_env);

    memRESET(csound);       /* this one should be called last */
  }


Generated by  Doxygen 1.6.0   Back to index