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

PUBLIC int csoundCleanup ( CSOUND *   ) 

Prints information about the end of a performance, and closes audio and MIDI devices. Note: after calling csoundCleanup(), the operation of the perform functions is undefined.

Definition at line 365 of file musmon.c.

{
    void    *p;
    MYFLT   *maxp;
    int32    *rngp;
    int     n;

    while (csound->evtFuncChain != NULL) {
      p = (void*) csound->evtFuncChain;
      csound->evtFuncChain = ((EVT_CB_FUNC*) p)->nxt;
      free(p);
    }

    /* check if we have already cleaned up */
    if (!(csound->engineState & CS_STATE_CLN))
      return 0;
    /* will not clean up more than once */
    csound->engineState &= ~(CS_STATE_CLN);

    deactivate_all_notes(csound);
    if (csound->instrtxtp &&
        csound->instrtxtp[0] &&
        csound->instrtxtp[0]->instance &&
        csound->instrtxtp[0]->instance->actflg)
      xturnoff_now(csound, csound->instrtxtp[0]->instance);
    delete_pending_rt_events(csound);
    while (csound->freeEvtNodes != NULL) {
      p = (void*) csound->freeEvtNodes;
      csound->freeEvtNodes = ((EVTNODE*) p)->nxt;
      free(p);
    }
    orcompact(csound);
    if (csound->scfp) {
      fclose(csound->scfp); csound->scfp = NULL;
    }

    /* print stats only if musmon was actually run */
    if (UNLIKELY(csound->musmonGlobals != NULL)) {
      csound->Message(csound, Str("end of score.\t\t   overall amps:"));
      for (n = 0; n < csound->nchnls; n++) {
        if (csound->smaxamp[n] > csound->omaxamp[n])
          csound->omaxamp[n] = csound->smaxamp[n];
        if (csound->maxamp[n] > csound->omaxamp[n])
          csound->omaxamp[n] = csound->maxamp[n];
        ST(orngcnt)[n] += (ST(srngcnt)[n] + csound->rngcnt[n]);
      }
      for (maxp = csound->omaxamp, n = csound->nchnls; n--; )
        print_maxamp(csound, *maxp++);
      if (csound->oparms->outformat != AE_FLOAT) {
        csound->Message(csound, Str("\n\t   overall samples out of range:"));
        for (rngp = ST(orngcnt), n = csound->nchnls; n--; )
          csound->Message(csound, "%9d", *rngp++);
      }
      csound->Message(csound, Str("\n%d errors in performance\n"),
                              csound->perferrcnt);
      print_benchmark_info(csound, Str("end of performance"));
    }
    /* close line input (-L) */
    RTclose(csound);
    /* close MIDI input */
    MidiClose(csound);
    /* IV - Feb 03 2005: do not need to call rtclose from here, */
    /* as sfclosein/sfcloseout will do that. */
    if (!csound->enableHostImplementedAudioIO) {
      sfclosein(csound);
      sfcloseout(csound);
      if (!csound->oparms->sfwrite)
        csound->Message(csound, Str("no sound written to disk\n"));
    }
    /* close any remote.c sockets */
    if (csound->remoteGlobals) remote_Cleanup(csound);
    if (csound->oparms->ringbell)
      cs_beep(csound);
    return dispexit(csound);    /* hold or terminate the display output     */
}


Generated by  Doxygen 1.6.0   Back to index