浏览代码

initial commit

richarddobson 3 年之前
父节点
当前提交
bb72c618f6

二进制
dev/texture/prevsrc/prev-src.zip


+ 0 - 889
dev/texture/prevsrc/prev-src/ap_texture.c

@@ -1,889 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
-
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-
-/* 03/2020: TW/RWD: corrected usage message argument lists */
-
-/* floatsam version: no changes */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <structures.h>
-#include <cdpmain.h>
-#include <tkglobals.h>
-#include <pnames.h>
-#include <texture.h>
-#include <processno.h>
-#include <modeno.h>
-#include <globcon.h>
-#include <logic.h>
-#include <filetype.h>
-#include <mixxcon.h>
-#include <flags.h>
-#include <speccon.h>
-#include <arrays.h>
-#include <special.h>
-#include <formants.h>
-#include <sfsys.h>
-#include <osbind.h>
-
-#include <srates.h>
-
-/********************************************************************************************/
-/********************************** FORMERLY IN pconsistency.c ******************************/
-/********************************************************************************************/
-
-static int  texture_pconsistency(dataptr dz);
-
-/********************************************************************************************/
-/********************************** FORMERLY IN specialin.c *********************************/
-/********************************************************************************************/
-
-static int  get_the_notedatafile(char *filename,dataptr dz);
-
-/***************************************************************************************/
-/****************************** FORMERLY IN aplinit.c **********************************/
-/***************************************************************************************/
-
-/***************************** ESTABLISH_BUFPTRS_AND_EXTRA_BUFFERS **************************/
-
-int establish_bufptrs_and_extra_buffers(dataptr dz)
-{
-    /*int is_spec = FALSE;*/
-    dz->bptrcnt = 0;
-    dz->bufcnt  = 0;
-    switch(dz->process) {
-    case(SIMPLE_TEX):
-    case(TIMED):
-    case(GROUPS):
-    case(TGROUPS):
-    case(DECORATED):
-    case(PREDECOR):
-    case(POSTDECOR):
-    case(ORNATE):
-    case(PREORNATE):
-    case(POSTORNATE):
-    case(MOTIFS):
-    case(TMOTIFS):
-    case(MOTIFSIN):
-    case(TMOTIFSIN):
-        dz->extra_bufcnt = 0;   dz->bufcnt = 1;
-        break;
-    default:
-        sprintf(errstr,"Unknown program type [%d] in establish_bufptrs_and_extra_buffers()\n",dz->process);
-        return(PROGRAM_ERROR);
-    }
-    return establish_groucho_bufptrs_and_extra_buffers(dz);
-}
-
-/***************************** SETUP_INTERNAL_ARRAYS_AND_ARRAY_POINTERS **************************/
-
-int setup_internal_arrays_and_array_pointers(dataptr dz)
-{
-    int n;
-    dz->ptr_cnt    = -1;            /* base constructor...process */
-    dz->array_cnt  = -1;
-    dz->iarray_cnt = -1;
-    dz->larray_cnt = -1;
-    switch(dz->process) {
-    case(SIMPLE_TEX):
-    case(TIMED):
-    case(GROUPS):
-    case(TGROUPS):
-    case(DECORATED):
-    case(PREDECOR):
-    case(POSTDECOR):
-    case(ORNATE):
-    case(PREORNATE):
-    case(POSTORNATE):
-    case(MOTIFS):
-    case(TMOTIFS):
-    case(MOTIFSIN):
-    case(TMOTIFSIN):
-        dz->array_cnt = 1; dz->iarray_cnt = 6; dz->larray_cnt = 0; dz->ptr_cnt = 0;     dz->fptr_cnt = 0;
-        break;
-    }
-
-    /*** WARNING ***
-         ANY APPLICATION DEALING WITH A NUMLIST INPUT: MUST establish AT LEAST 1 double array: i.e. dz->array_cnt = at least 1
-         **** WARNING ***/
-
-
-    if(dz->array_cnt < 0 || dz->iarray_cnt < 0 || dz->larray_cnt < 0 || dz->ptr_cnt < 0 || dz->fptr_cnt < 0) {
-        sprintf(errstr,"array_cnt not set in setup_internal_arrays_and_array_pointers()\n");
-        return(PROGRAM_ERROR);
-    }
-
-    if(dz->array_cnt > 0) {
-        if((dz->parray  = (double **)malloc(dz->array_cnt * sizeof(double *)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for internal double arrays.\n");
-            return(MEMORY_ERROR);
-        }
-        for(n=0;n<dz->array_cnt;n++)
-            dz->parray[n] = NULL;
-    }
-    if(dz->iarray_cnt > 0) {
-        if((dz->iparray = (int     **)malloc(dz->iarray_cnt * sizeof(int *)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for internal int arrays.\n");
-            return(MEMORY_ERROR);
-        }
-        for(n=0;n<dz->iarray_cnt;n++)
-            dz->iparray[n] = NULL;
-    }
-    if(dz->larray_cnt > 0) {
-        if((dz->lparray = (int    **)malloc(dz->larray_cnt * sizeof(int *)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for internal long arrays.\n");
-            return(MEMORY_ERROR);
-        }
-        for(n=0;n<dz->larray_cnt;n++)
-            dz->lparray[n] = NULL;
-    }
-    if(dz->ptr_cnt > 0)   {
-        if((dz->ptr     = (double  **)malloc(dz->ptr_cnt  * sizeof(double *)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for internal pointer arrays.\n");
-            return(MEMORY_ERROR);
-        }
-        for(n=0;n<dz->ptr_cnt;n++)
-            dz->ptr[n] = NULL;
-    }
-    if(dz->fptr_cnt > 0)   {
-        if((dz->fptr = (float **)malloc(dz->fptr_cnt * sizeof(float *)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for internal float-pointer arrays.\n");
-            return(MEMORY_ERROR);
-        }
-        for(n=0;n<dz->fptr_cnt;n++)
-            dz->fptr[n] = NULL;
-    }
-    return(FINISHED);
-}
-
-/****************************** ASSIGN_PROCESS_LOGIC *********************************/
-
-int assign_process_logic(dataptr dz)
-{
-    switch(dz->process) {
-    case(SIMPLE_TEX):
-    case(TIMED):
-    case(GROUPS):
-    case(TGROUPS):
-    case(DECORATED):
-    case(PREDECOR):
-    case(POSTDECOR):
-    case(ORNATE):
-    case(PREORNATE):
-    case(POSTORNATE):
-    case(MOTIFS):
-    case(TMOTIFS):
-    case(MOTIFSIN):
-    case(TMOTIFSIN):
-        setup_process_logic(ONE_OR_MANY_SNDFILES,       UNEQUAL_SNDFILE,        SNDFILE_OUT,    dz);
-        break;
-    default:
-        sprintf(errstr,"Unknown process: assign_process_logic()\n");
-        return(PROGRAM_ERROR);
-        break;
-    }
-    if(dz->has_otherfile) {
-        switch(dz->input_data_type) {
-        case(ALL_FILES):
-        case(TWO_SNDFILES):
-        case(SNDFILE_AND_ENVFILE):
-        case(SNDFILE_AND_BRKFILE):
-        case(SNDFILE_AND_UNRANGED_BRKFILE):
-        case(SNDFILE_AND_DB_BRKFILE):
-            break;
-        case(MANY_SNDFILES):
-            if(dz->process==INFO_TIMELIST)
-                break;
-            /* fall thro */
-        default:
-            sprintf(errstr,"Most processes accepting files with different properties\n"
-                    "can only take 2 sound infiles.\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    return(FINISHED);
-}
-
-/***************************** SET_LEGAL_INFILE_STRUCTURE **************************
- *
- * Allows 2nd infile to have different props to first infile.
- */
-
-void set_legal_infile_structure(dataptr dz)
-{
-    switch(dz->process) {
-    default:
-        dz->has_otherfile = FALSE;
-        break;
-    }
-}
-
-/***************************************************************************************/
-/****************************** FORMERLY IN internal.c *********************************/
-/***************************************************************************************/
-
-/****************************** SET_LEGAL_INTERNALPARAM_STRUCTURE *********************************/
-
-int set_legal_internalparam_structure(int process,int mode,aplptr ap)
-{
-    int exit_status = FINISHED;
-    switch(process) {
-    case(SIMPLE_TEX):       case(TIMED):    case(GROUPS):   case(TGROUPS):
-    case(DECORATED):        case(PREDECOR): case(POSTDECOR):
-    case(ORNATE):           case(PREORNATE):case(POSTORNATE):
-    case(MOTIFS):           case(TMOTIFS):  case(MOTIFSIN): case(TMOTIFSIN):
-        exit_status = set_internalparam_data("iiidddi",ap);                     break;
-    default:
-        sprintf(errstr,"Unknown process in set_legal_internalparam_structure()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(exit_status);
-}
-
-/********************************************************************************************/
-/********************************** FORMERLY IN specialin.c *********************************/
-/********************************************************************************************/
-
-/********************** READ_SPECIAL_DATA ************************/
-
-int read_special_data(char *str,dataptr dz)
-{
-    /*      int exit_status = FINISHED;*/
-    aplptr ap = dz->application;
-    switch(ap->special_data) {
-    case(TEX_NOTEDATA):                     return get_the_notedatafile(str,dz);
-    default:
-        sprintf(errstr,"Unknown special_data type: read_special_data()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);       /* NOTREACHED */
-}
-
-/***************************** GET_THE_NOTEDATAFILE ****************************/
-
-int get_the_notedatafile(char *filename,dataptr dz)
-{
-    if((dz->fp = fopen(filename,"r"))==NULL) {
-        sprintf(errstr,"Failed to open notedata file %s\n",filename);
-        return(DATA_ERROR);
-    }
-    return(FINISHED);
-}
-
-/********************************************************************************************/
-/********************************** FORMERLY IN preprocess.c ********************************/
-/********************************************************************************************/
-
-/****************************** PARAM_PREPROCESS *********************************/
-
-int param_preprocess(dataptr dz)
-{
-    /*      int exit_status = FINISHED;*/
-
-    switch(dz->process) {
-    case(SIMPLE_TEX):       case(TIMED):    case(GROUPS):   case(TGROUPS):
-    case(DECORATED):        case(PREDECOR): case(POSTDECOR):
-    case(ORNATE):           case(PREORNATE):case(POSTORNATE):
-    case(MOTIFS):           case(TMOTIFS):  case(MOTIFSIN): case(TMOTIFSIN):
-        return texture_preprocess(dz);
-    default:
-        sprintf(errstr,"PROGRAMMING PROBLEM: Unknown process in param_preprocess()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);       /* NOTREACHED */
-}
-
-/********************************************************************************************/
-/********************************** FORMERLY IN procgrou.c **********************************/
-/********************************************************************************************/
-
-/**************************** GROUCHO_PROCESS_FILE ****************************/
-
-int groucho_process_file(dataptr dz)   /* FUNCTIONS FOUND IN PROCESS.C */
-{
-    int exit_status = FINISHED;
-
-    switch(dz->process) {
-    case(SIMPLE_TEX):       case(TIMED):    case(GROUPS):   case(TGROUPS):
-    case(DECORATED):        case(PREDECOR): case(POSTDECOR):
-    case(ORNATE):           case(PREORNATE):case(POSTORNATE):
-    case(MOTIFS):           case(MOTIFSIN): case(TMOTIFS):  case(TMOTIFSIN):
-        if((exit_status = make_texture(dz))<0)
-            return(exit_status);
-        if((exit_status = produce_texture_sound(dz))<0)
-            return(exit_status);
-        break;
-    default:
-        sprintf(errstr,"Unknown case in process_file()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/********************************************************************************************/
-/********************************** FORMERLY IN pconsistency.c ******************************/
-/********************************************************************************************/
-
-/****************************** CHECK_PARAM_VALIDITY_AND_CONSISTENCY *********************************/
-
-int check_param_validity_and_consistency(dataptr dz)
-{
-    /*      int exit_status = FINISHED;*/
-    handle_pitch_zeros(dz);
-    switch(dz->process) {
-    case(SIMPLE_TEX): case(TIMED):          case(GROUPS):   case(TGROUPS):
-    case(DECORATED):  case(PREDECOR):       case(POSTDECOR):
-    case(ORNATE):     case(PREORNATE):      case(POSTORNATE):
-    case(MOTIFS):     case(TMOTIFS):        case(MOTIFSIN): case(TMOTIFSIN):
-        return texture_pconsistency(dz);
-    }
-    return(FINISHED);
-}
-
-/***************************** PREPARE_TEXTURE_PARAMETERS ****************************/
-
-int texture_pconsistency(dataptr dz)
-{
-    double *p, *end;
-    int OK = TRUE;
-    if(dz->brksize[TEXTURE_INSLO]) {
-        p = dz->brk[TEXTURE_INSLO] + 1;
-        end = dz->brk[TEXTURE_INSLO] + (dz->brksize[TEXTURE_INSLO] * 2);
-        while(p < end) {
-            if(*p  > (double)dz->infilecnt) {
-                OK = FALSE;
-                break;
-            }
-            p += 2;
-        }
-    } else if(dz->iparam[TEXTURE_INSLO] > dz->infilecnt)
-        OK  = FALSE;
-    if(!OK) {
-        sprintf(errstr,"FIRST SND-IN-LIST TO USE > count of files entered: cannot proceed.\n");
-        return(DATA_ERROR);
-    }
-    OK = TRUE;
-    if(dz->brksize[TEXTURE_INSHI]) {
-        p = dz->brk[TEXTURE_INSHI] + 1;
-        end = dz->brk[TEXTURE_INSHI] + (dz->brksize[TEXTURE_INSHI] * 2);
-        while(p < end) {
-            if(*p  > (double)dz->infilecnt) {
-                OK = FALSE;
-                break;
-            }
-            p += 2;
-        }
-    } else if(dz->iparam[TEXTURE_INSHI] > dz->infilecnt)
-        OK  = FALSE;
-    if(!OK) {
-        sprintf(errstr,"LAST SND-IN-LIST TO USE > count of files entered: cannot proceed.\n");
-        return(DATA_ERROR);
-    }
-    return(FINISHED);
-}
-
-
-
-/********************************************************************************************/
-/********************************** FORMERLY IN buffers.c ***********************************/
-/********************************************************************************************/
-
-/**************************** ALLOCATE_LARGE_BUFFERS ******************************/
-
-int allocate_large_buffers(dataptr dz)
-{
-    switch(dz->process) {
-    case(SIMPLE_TEX):
-    case(TIMED):            case(GROUPS):           case(TGROUPS):
-    case(DECORATED):        case(PREDECOR):         case(POSTDECOR):
-    case(ORNATE):           case(PREORNATE):        case(POSTORNATE):
-    case(MOTIFS):           case(TMOTIFS):          case(MOTIFSIN):
-    case(TMOTIFSIN):
-        return create_sndbufs(dz);
-    default:
-        sprintf(errstr,"Unknown program no. in allocate_large_buffers()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);       /* NOTREACHED */
-}
-
-/********************************************************************************************/
-/********************************** FORMERLY IN cmdline.c ***********************************/
-/********************************************************************************************/
-
-int get_process_no(char *prog_identifier_from_cmdline,dataptr dz)
-{
-    if     (!strcmp(prog_identifier_from_cmdline,"simple"))         dz->process = SIMPLE_TEX;
-    else if(!strcmp(prog_identifier_from_cmdline,"grouped"))        dz->process = GROUPS;
-    else if(!strcmp(prog_identifier_from_cmdline,"motifs"))         dz->process = MOTIFS;
-    else if(!strcmp(prog_identifier_from_cmdline,"motifsin"))       dz->process = MOTIFSIN;
-    else if(!strcmp(prog_identifier_from_cmdline,"decorated"))      dz->process = DECORATED;
-    else if(!strcmp(prog_identifier_from_cmdline,"predecor"))       dz->process = PREDECOR;
-    else if(!strcmp(prog_identifier_from_cmdline,"postdecor"))      dz->process = POSTDECOR;
-    else if(!strcmp(prog_identifier_from_cmdline,"ornate"))         dz->process = ORNATE;
-    else if(!strcmp(prog_identifier_from_cmdline,"preornate"))      dz->process = PREORNATE;
-    else if(!strcmp(prog_identifier_from_cmdline,"postornate"))     dz->process = POSTORNATE;
-    else if(!strcmp(prog_identifier_from_cmdline,"timed"))                  dz->process = TIMED;
-    else if(!strcmp(prog_identifier_from_cmdline,"tgrouped"))               dz->process = TGROUPS;
-    else if(!strcmp(prog_identifier_from_cmdline,"tmotifs"))                dz->process = TMOTIFS;
-    else if(!strcmp(prog_identifier_from_cmdline,"tmotifsin"))              dz->process = TMOTIFSIN;
-    else {
-        sprintf(errstr,"Unknown program identification string '%s'\n",prog_identifier_from_cmdline);
-        return(USAGE_ONLY);
-    }
-
-    return FINISHED;
-}
-
-/********************************************************************************************/
-/********************************** FORMERLY IN usage.c *************************************/
-/********************************************************************************************/
-
-/******************************** USAGE1 ********************************/
-
-int usage1(void)
-{
-    fprintf(stdout, /* HAs to use fprintf because of kbhit */
-            "\n"
-            "USAGE:\ntexture NAME (mode) infile (infile2..etc) outfile notedata params:\n"
-            "\n"
-            "\nwhere NAME can be any one of\n"
-            "\n"
-            "\tTEXTURE MADE FROM ONE OR SEVERAL SOUND FILES\n"
-            "\n"
-            "simple   grouped    decorated    ornate       motifs\n"
-            "                    predecor     preornate    motifsin\n"
-            "                    postdecor    postornate\n"
-            "\n"
-            "\tTIMED TEXTURES MADE FROM ONE OR SEVERAL SOUND FILES\n"
-            "\n"
-            "timed     tmotifs   tmotifsin   tgrouped\n"
-            "\n"
-            "ORNAMENTS & MOTIFS   have user-specified pitch-shapes.\n"
-            "DECORATIONS & GROUPS have random pitch-shapes.\n"
-            "\n"
-            "Type 'texture simple' for more info on simple texture option.... etc.\n"
-            "\n"
-#ifdef IS_PC
-            "MORE??? ----- (hit keyboard)\n"
-            "\n");
-
-    while(!kbhit())
-        ;
-    if(kbhit()) {
-#else
-        "\n");
-#endif
-    fprintf(stdout,
-            "\n"
-            "*********************************************************************\n"
-            "SOME SPECIAL PARAMETER VALUES\n"
-            "*********************************************************************\n"
-            "GPSPACE: spatialisation of event-groups\n"
-            "\n"
-            "     0:still            1:scattered(default) 2:towards-texture-centre\n"
-            "     3:away-from-centre 4:follow-texmotion   5:contrary-to-motion\n"
-            "     4 & 5 only function if spatial position varies in time..\n"
-            "*********************************************************************\n"
-            "CONTOUR: amplitude contour of groups\n"
-            "\n"
-            "     0:mixed(default) 1:cresc     2:flat   3:decresc    4:c_or_fl\n"
-            "     5:c_or_d         6:d_or_fl  [7:directed_to_event   8:dir_or_flat]\n"
-            "*********************************************************************\n"
-            "CENTRING: how decoration pitches centre on decorated line pitches\n"
-            "\n"
-            "     0: centred(default) 1: above       2: below\n"
-            "     3: c_and_a          4: c_and_b     5: a_and_b     6: c_and_a_and_b\n"
-            "     In all cases except 0, pitchrange shifted to tally with line pitch\n\n"
-            "\n"
-            "*********************************************************************\n"
-            "       ALL OTHER PARAMS, except outdur, MAY VARY IN TIME.\n"
-            "*********************************************************************\n"
-            "\n"
-
-#ifdef IS_PC
-            "MORE??? ----- (hit keyboard)\n");
-}
-_getch();
-while(!kbhit())
-    ;
-if(kbhit()) {
-#else
-    "\n");
-#endif
-
-fprintf(stdout,
-        "\n"
-        "*********************************************************************\n"
-        "HARMONIC SETS   use only the pitches specified.\n"
-        "\n"
-        "HARMONIC FIELDS duplicate the specified pitches in all 8vas.\n"
-        "*********************************************************************\n"
-        "NOTEDATA is in a textfile containing.....\n"
-        "*********************************************************************\n"
-        "     assumed MIDI 'pitch' of each input snd, specified on 1st line.\n"
-        "\n"
-        "   FOLLOWED BY, where ness,  NOTELIST(S), SPECIFIED THUS:-\n"
-        "\n"
-        "     #N (where N = no. of notes in notelist: follows by N lines of...)\n"
-        "     time(SECS)   infile_no    pitch(MIDI)    amp(MIDI)   dur(SECS)\n"
-        "\n"
-        "where times within motif must increase (or remain same, during chords)\n"
-        "*********************************************************************\n"
-        "NOTELISTS REPRESENT: IN THIS ORDER..\n"
-        "*********************************************************************\n"
-        "Notelist of notes in any timed, ornamented or decorated line in texture.\n"
-        "Notelist of notes in any harmonic field(s) or set(s) specified.\n"
-        "      (For more than one  hfield(hset),\n"
-        "      data should specify chords, placed at appropriae times.)\n"
-        "Notelist(s) of notes in any ornament(s) or motif(s) specified.\n"
-        "*********************************************************************\n");
-
-#ifdef IS_PC
-}
-#endif
-return(USAGE_ONLY);
-}
-
-/******************************** USAGE2 ********************************/
-
-int usage2(char *str)
-{
-    if(!strcmp(str,"simple")) {
-        fprintf(stdout,
-                "USAGE:\n"
-                "texture simple mode infile [infile2...] outfile notedata outdur packing scatter\n"
-                "        tgrid sndfirst sndlast  mingain maxgain  mindur maxdur  minpich maxpich\n"
-                "             [-aatten] [-pposition] [-sspread] [-rseed] [-w -c -p]\n"
-                "MODES:-\n"
-                "1)  ON A GIVEN HARMONIC-FIELD        3)  ON A GIVEN HARMONIC-SET\n"
-                "2)  ON CHANGING HARMONIC-FIELDS      4)  ON CHANGING HARMONIC-SETS\n"
-                "5)  NONE\n"
-                "notedata: infofile, insnd 'pitches',harmonic fields pitches etc.\n"
-                "outdur:           (min) duration of outfile\n"
-                "packing:          (average) time between event onsets.\n"
-                "scatter:          randomisation of event-onsets (0 - %.0lf)\n"
-                "tgrid:            minstep(MS) quantised timegrid(for grp starttimes)(default 0)\n"
-                "sndfirst,sndlast: 1st,last snd to use,from list of insnds(range:1 - no.of snds)\n"
-                "mingain,maxgain:  minimum & maximum level of input events (1-127:default 64,64)\n"
-                "mindur,maxdur:    minimum & maximum duration of events in texture\n"
-                "minpich,maxpich:  minimum & maximum pitch (MIDI VALUE):\n"
-                "atten:            overall attenuation of the output\n"
-                "position:         centre of output sound-image (0(Left) 1(Right): default 0.5)\n"
-                "spread:           spatial-spread of texture events (0 - 1(full-spread))\n"
-                "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-                "-w:               always play whole input-sound (ignoring duration values).\n"
-                "-c:               Choose files cyclically in listed order (ignore 'sndfirst','last').\n"
-                "-p:               Random permute each cycle (only when -c flag set).\n",MAX_SCAT_TEXTURE);
-    } else if(!strcmp(str,"timed")) {
-        fprintf(stdout,
-                "TIMED TEXTURE:  USAGE:\n"
-                "texture timed mode infile [infile2...]  outfile  notedata     outdur skiptime\n"
-                "             sndfirst sndlast mingain maxgain mindur maxdur minpitch maxpitch\n"
-                "             [-aatten] [-pposition] [-sspread] [-rseed] [-w]\n"
-                "MODES:-\n"
-                "1)  ON A GIVEN HARMONIC-FIELD        3)  ON A GIVEN HARMONIC-SET\n"
-                "2)  ON CHANGING HARMONIC-FIELDS      4)  ON CHANGING HARMONIC-SETS\n"
-                "5)  NONE\n"
-                "notedata: infofile, insnd 'pitches',texture timing,harmonic fields pitches etc.\n"
-                "outdur:            (min) duration of outfile\n"
-                "skiptime:          time between repetitions of timing motif in notedata\n"
-                "sndfirst,sndlast:  1st,last snd to use,from list of insnds(range:1 - all)\n"
-                "mingain,maxgain:   min & max level of input events (1-127:default 64,64)\n"
-                "mindur,maxdur:     min & max duration of events in texture\n"
-                "minpitch,maxpitch: min & max pitch (MIDI VALUE)\n"
-                "atten:             overall attenuation of the output\n"
-                "position:          centre of output sound-image (0(Left) 1(Right):default 0.5)\n"
-                "spread:            spatial-spread of texture events (0 - 1(full-spread))\n"
-                "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-                "-w:                always play whole input-sound (ignoring duration values).\n");
-    } else if(!strcmp(str,"grouped")) {
-        fprintf(stdout,
-                "TEXTURE OF EVENT-GROUPS: USAGE: texture grouped mode infile [infile2..] outfile\n"
-                "notedata outdur packing scatter tgrid\n"
-                "sndfirst sndlast mingain maxgain mindur maxdur minpitch maxpitch phgrid gpspace\n"
-                "gpsprange amprise contour gpsizelo gpsizehi gppaklo gppakhi gpranglo gpranghi\n"
-                "                   [-aatten] [-pposition] [-sspread] [-rseed] [-w] [-d] [-i]\n"
-                "MODES:-\n"
-                "1)ON HARMONIC-FIELD 2)CHANGING HFLDS 3)HARMONIC-SET 4)CHANGING HSETS 5)NONE\n"
-                "notedata:   infofile, 'pitch' of insnds, harmonic fields etc.\n"
-                "outdur:     (min) duration of outfile\n"
-                "packing:    (average) time between group onsets.\n"
-                "scatter:    randomisation of event-onsets (0 - %.0lf)\n"
-                "tgrid:      minstep(MS) quantised timegrid(for grp starttimes)(default 0)\n"
-                "sndfirst,sndlast: 1st,last snd to use, from list of insnds(range:1 - all)\n"
-                "mingain,maxgain:  min & max level of input events (1-127:default 64,64)\n"
-                "mindur,maxdur:    min & max duration of events in texture\n"
-                "minpitch,maxpitch:min & max pitch (MIDI VALUE)\n"
-                "phgrid:     a timegrid (MS) applying WITHIN the groups\n"
-                "gpspace:    spatialisation of event-groups (Range 0-5: default 1)\n"
-                "gpsprange:  spatial range of event-groups (Range 0-1: default 1)\n"
-                "amprise:    amplitude change within groups: (0-127: default 0)\n"
-                "contour:    amplitude contour of groups (Range 0-6: default 0)\n"
-                /* NOTE : CARE all_types is 7 AND NOT 8 here */
-                "gpsizelo,gpsizehi:smallest,largest no. of events in groups\n"
-                "gppaklo,gppakhi:  shortest,longest time between event-onsets in groups (MS)\n"
-                "gpranglo,gpranghi:min,max pitchrange grps OR (hfields) no.of hf-notes range\n"
-                "atten:      overall attenuation of output\n"
-                "position:   centre of output sound-image (0(Left) 1(Right): default 0.5)\n"
-                "spread:     spatial-spread of texture events (0 - 1(full-spread))\n"
-                "seed:       same seed-no: same output on rerun(dflt 0: differs each time)\n"
-                "-w:         always play whole input-sound (ignore maxdur,mindur vals).\n"
-                "-d:             fixed timestep between groupnotes.\n"
-                "-i:         each group not confined to a fixed instr (default:fixed)\n",MAX_SCAT_TEXTURE);
-    } else if(!strcmp(str,"tgrouped")) {
-        fprintf(stdout,
-                "TIMED TEXTURE OF EVENT-GROUPS: USAGE: texture tgrouped mode infile [infile2..]\n"
-                "outfile notedata outdur skip sndfirst sndlast mingain maxgain mindur maxdur\n"
-                "minpitch maxpitch phgrid gpspace gpsprange amprise contour gpsizelo gpsizehi\n"
-                "gppacklo gppackhi gpranglo gpranghi\n"
-                "                   [-aatten] [-pposition] [-sspread] [-rseed] [-w] [-d] [-i]\n"
-                "MODES:-\n"
-                "1)  ON A GIVEN HARMONIC-FIELD        3)  ON A GIVEN HARMONIC-SET\n"
-                "2)  ON CHANGING HARMONIC-FIELDS      4)  ON CHANGING HARMONIC-SETS\n"
-                "5)  NONE\n"
-                "notedata: infofile, 'pitch' of insnds, timings for timed textures, hfields etc\n"
-                "outdur:           (min) duration of outfile\n"
-                "skip:             time between repetitions of timing motif in notedata\n"
-                "sndfirst,sndlast: 1st,last snd to use from list of insnds(range:1 - all)\n"
-                "mingain,maxgain:  min & max level of input events (1-127:default 64,64)\n"
-                "mindur,maxdur:    min & max duration of events in texture\n"
-                "minpitch,maxpitch:min & max pitch (MIDI VALUE)\n"
-                "phgrid:           timegrid (MS) applying WITHIN the groups\n"
-                "gpspace:          spatialisation of event-groups (Range 0-5: default 1)\n"
-                "gpsprange:        spatial range of event-groups (Range 0-1: default 1)\n"
-                "amprise:          amplitude change within groups: (0-127: default 0)\n"
-                "contour:          amplitude contour of groups (Range 0-6: default 0)\n"
-                /* NOTE : CARE all_types is 7 AND NOT 8 here */
-                "gpsizelo,gpsizehi:smallest & largest numbers of events in groups\n"
-                "gppacklo,gppackhi:shortest & longest time between event-onsets in groups (MS)\n"
-                "gpranglo,gpranghi:min,max pitchrange grps OR (hfields) no.of hf-notes range\n"
-                "atten:            overall attenuation of output\n"
-                "position:         centre of output sound-image (0(Left) 1(Right): default 0.5)\n"
-                "spread:           spatial-spread of texture events (0 - 1(full-spread))\n"
-                "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-                "-w:               always play whole input-sound (ignoring duration values).\n"
-                "-d:                            fixed timestep between groupnotes.\n"
-                "-i:               each group not confined to a fixed instr (default:fixed)\n");
-    } else if(!strcmp(str,"decorated") || !strcmp(str,"predecor") || !strcmp(str,"postdecor")) {
-        fprintf(stdout,
-                "TEXTURE WITH DECORATIONS:USAGE:texture decorated|predecor|postdecor mode infile\n"
-                "[infile2..] outfile notedata outdur skiptime sndfirst sndlast mingain maxgain\n"
-                "mindur maxdur phgrid gpspace gpsprange amprise contour gpsizlo gpsizhi\n"
-                "gppaklo gppakhi gpranglo gpranghi centring\n"
-                "              [-aatten] [-ppos] [-ssprd] [-rseed] [-w] [-d] [-i] [-h] [-e] [-k]\n"
-                "MODES:-\n"
-                "1)ON HARMONIC-FIELD 2)CHANGING HFLDS 3)HARMONIC-SET 4)CHANGING HSETS 5)NONE\n"
-                "notedata:         infofile, 'pitch' of insnds, decoration shape etc.\n"
-                "outdur:           (min) duration outfile\n"
-                "skiptime:         time between repets of motif-to-decorate in notedata\n"
-                "sndfirst,sndlast: 1st,last snd to use, from input snds (range 1 - all)\n"
-                "mingain,maxgain:  min & max gain on input events (MIDI)\n"
-                "mindur,maxdur:    min & max duration of events in texture\n"
-                "phgrid:           timegrid (MS) applying WITHIN decors\n"
-                "gpspace:          spatialisation decor-groups (Range 0-5: default 1)\n"
-                "gpsprange:        spatial range decor-groups (Range 0-1: default 1)\n"
-                "amprise:          amplitude change within decors: (0-127: default 0)\n"
-                "contour:          amplitude contour of decors (Range 0-8: default 0)\n"
-                "gpsizlo,gpsizhi:  smallest,largest no. events in decors\n"
-                "gppaklo,gppakhi:  shortest,longest time between event-onsets in decors(MS)\n"
-                "gpranglo,gpranghi:min,max pitchrange decors OR (hfields) no.of hf-notes range\n"
-                "centring:         how decor pitches centre on line pitches(Range 0-7:default 0)\n"
-                "atten:            overall attenuation of output\n"
-                "pos:              centre of output sound-image (-1(Left) 1(Right): default 0)\n"
-                "sprd:             spatial-spread of texture events (0 - 1(full-spread))\n"
-                "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-                "-w: play all insnd(ignore min,maxdur) -h: dec TOPnote chord:(dflt:1st listed)\n"
-                "-d: fixed timestep btwn decornotes    -e: dec all notes of chords\n"
-                "-i: instrs vary in decor(dflt:fixed)  -k: discard orig line, after decor\n");
-    } else if(!strcmp(str,"ornate") || !strcmp(str,"preornate") || !strcmp(str,"postornate")) {
-        fprintf(stdout,
-                "TEXTURE WITH ORNAMENTS: USAGE:\n"
-                "texture ornate|preornate|postornate mode infile [infile2...] outfile notedata\n"
-                "outdur skiptime sndfirst sndlast   mingain maxgain  mindur maxdur\n"
-                "phgrid gpspace gpsprange  amprise  contour   multlo   multhi\n"
-                "          [-aatten] [-pposition] [-sspread] [-rseed] [-w] [-d] [-i] [-h] [-e]\n"
-                "MODES:-\n"
-                "1)ON HARMONIC-FIELD 2)CHANGING HFLDS 3)HARMONIC-SET 4)CHANGING HSETS 5)NONE\n"
-                "notedata:   infofile, 'pitch' of insnds, notes in ornaments, hfields etc.\n"
-                "outdur:           (min) duration of outfile\n"
-                "skiptime:         time between repetitions of motif-to-ornament in notedata\n"
-                "sndfirst,sndlast: 1st,last snd to use, from input snds (range 1 - all)\n"
-                "mingain,maxgain:  min & max level of input events (1-127:default 64,64)\n"
-                "mindur,maxdur:    min & max duration of events in texture\n"
-                "phgrid:           a timegrid (MS) applying WITHIN the ornaments\n"
-                "gpspace:          spatialisation of event-groups (Range 0-5: default 1)\n"
-                "gpsprange:        spatial range of event-groups (Range 0-1: default 1)\n"
-                "amprise:          amplitude change within ornaments: (0-127: default 0)\n"
-                "contour:          amplitude contour of groups (Range 0-8: default 0)\n"
-                "multlo, multhi:   min & max multiplier of total input duration of motif\n"
-                "atten:            overall attenuation of the output\n"
-                "position:         centre of output sound-image (0(Left) 1(Right):default 0.5)\n"
-                "spread:           spatial-spread of texture events (0 - 1(full-spread))\n"
-                "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-                "-w:               always play whole input-sound (ignoring duration values).\n"
-                "-d:               ornament notes all have same duration as ornamented note\n"
-                "-i:               orns not confined to instr of ornd-note (default:same note)\n"
-                "-h:               orns on highest note of any chord:(default:1st note listed)\n"
-                "-e:               ornaments on all notes of any chord.\n");
-    } else if(!strcmp(str,"motifsin")) {
-        fprintf(stdout,
-                "TEXTURE OF MOTIFS, FORCED ONTO A HARMONIC FIELD: USAGE:\n"
-                "texture motifsin mode infile [infile2..] outfile notedata outdur packing\n"
-                "scatter tgrid sndfirst sndlast mingain maxgain\n"
-                "minpitch maxpitch phgrid gpspace gpsprange amprise  contour multlo multhi\n"
-                "                [-aatten] [-pposition] [-sspread] [-rseed] [-w] [-d] [-i]\n"
-                "MODES:-\n"
-                "1) ON HARMONIC-FIELD 2) CHANGING HFLDS 3) HARMONIC-SET 4) CHANGING HSETS\n"
-                "notedata: infofile,'pitch' of insnds, timings for timed textures, hfields etc\n"
-                "outdur:             (min) duration of outfile\n"
-                "packing:            (average) time between motif onsets.\n"
-                "scatter:            randomisation of event-onsets (0 - %.0lf)\n"
-                "tgrid:              minstep(MS) quantised timegrid (for mtf starttimes)(dflt 0)\n"
-                "sndfirst,sndlast:   1st,last snd to use, from input snds (range 1 - all)\n"
-                "mingain,maxgain:    min & max level of input events (1-127:default 64,64)\n"
-                "minpitch,maxpitch:  min & max pitch (MIDI VALUE)\n"
-                "phgrid:             a timegrid (MS) applying WITHIN the motifs\n"
-                "gpspace:            spatialisation of event-groups (Range 0-5: default 1)\n"
-                "gpsprange:          spatial range of event-groups (Range 0-1: default 1)\n"
-                "amprise:            amplitude change within motifs: (0-127: default 0)\n"
-                "contour:            amplitude contour of groups (Range 0-6: default 0)\n"
-                /* NOTE : CARE all_types is 7 AND NOT 8 here */
-                "multlo, multhi:     min & max multiplier of total input duration of motif\n"
-                "atten:              overall attenuation of the output\n"
-                "position:           centre of output sound-image (0(Left) 1(Right):default 0.5)\n"
-                "spread:             spatial-spread of texture events (0 - 1(full-spread))\n"
-                "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-                "-w:                 always play whole input-sound (ignoring duration values).\n"
-                "-d                  notes within any one motif all have same duration.\n"
-                "-i:                 motif not each confined to fixed instr (default:fixed)\n",MAX_SCAT_TEXTURE);
-    } else if(!strcmp(str,"tmotifsin")) {
-        fprintf(stdout,
-                "TIMED TEXTURE OF MOTIFS, FORCED ONTO A HARMONIC FIELD: USAGE:\n"
-                "texture tmotifsin mode infile [infile2...] outfile notedata sndfirst sndlast\n"
-                "mingain maxgain minpich maxpich phgrid gpspace gpsprange\n"
-                "amprise contour multlo multhi [-aatten] [-ppos] [-sspread] [-rseed] [-w] [-d]\n"
-                "MODES:-\n"
-                "1) ON HARMONIC-FIELD 2) CHANGING HFLDS 3) HARMONIC-SET 4) CHANGING HSETS\n"
-                "notedata:    infofile, 'pitch' of insnds,motifs,texture timings,hfields etc..\n"
-                "outdur:           (min) duration of outfile\n"
-                "skiptime:         time between repetitions of timing motif in notedata\n"
-                "sndfirst,sndlast: 1st,last snd to use, from input snds (range 1 - all)\n"
-                "mingain,maxgain:  minimum & maximum level of input events (1-127:default 64,64)\n"
-                "minpich,maxpich:  min & max pitch (MIDI VALUE)\n"
-                "phgrid:           a timegrid (MS) applying WITHIN the motifs\n"
-                "gpspace:          spatialisation of event-groups (Range 0-5: default 1)\n"
-                "gpsprange:        spatial range of event-groups (Range 0-1: default 1)\n"
-                "amprise:          amplitude change within motifs: (0-127: default 0)\n"
-                "contour:          amplitude contour of groups (Range 0-6: default 0)\n"
-                /* NOTE : CARE all_types is 7 AND NOT 8 here */
-                "multlo, multhi:   min & max multiplier of total input duration of motif\n"
-                "atten:            overall attenuation of the output\n"
-                "pos:              centre of output sound-image (0(Left) 1(Right):default 0.5)\n"
-                "spread:           spatial-spread of texture events (0 - 1(full-spread))\n"
-                "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-                "-w:               always play whole input-sound (ignoring duration values).\n"
-                "-d:               notes in any one motif all have same duration as timing note.\n"
-                "-i:               motifs not each confined to a fixed instrument (default: fixed)\n");
-    } else if(!strcmp(str,"motifs")) {
-        fprintf(stdout,
-                "TEXTURE OF MOTIFS, (1ST NOTES ONLY, FORCED ONTO HARMONIC FIELD/SET, IF USED)\n"
-                "USAGE: texture motifs mode infile [infile2...] outfile notedata outdur packing\n"
-                "scatter tgrid sndfirst sndlast mingain maxgain minpich maxpich\n"
-                "phgrid gpspace gpsprange amprise contour multlo multhi\n"
-                "                 [-aatten] [-pposition] [-sspread] [-rseed] [-w] [-d]\n"
-                "MODES:-\n"
-                "1)ON HARMONIC-FIELD 2)CHANGING HFLDS 3)HARMONIC-SET 4)CHANGING HSETS 5)NONE\n"
-                "notedata: infofile, 'pitch' of insnds, timings for timed textures,hfields etc.\n"
-                "outdur:             (min) duration of outfile\n"
-                "packing:            (average) time between motif onsets.\n"
-                "scatter:            randomisation of event-onsets (0 - %.0lf)\n"
-                "tgrid:              minstep(MS) quantised timegrid (for mtf starttimes)(dflt 0)\n"
-                "sndfirst,sndlast:   1st,last snd to use, from input snds (range 1 - all)\n"
-                "mingain,maxgain:    min & max level of input events (1-127:default 64,64)\n"
-                "minpich,maxpich:    min & max pitch (MIDI VALUE)\n"
-                "phgrid:             a timegrid (MS) applying WITHIN the motifs\n"
-                "gpspace:            spatialisation of event-groups (Range 0-5: default 1)\n"
-                "gpsprange:          spatial range of event-groups (Range 0-1: default 1)\n"
-                "amprise:            amplitude change within motifs: (0-127: default 0)\n"
-                "contour:            amplitude contour of groups (Range 0-6: default 0)\n"
-                /* NOTE : CARE all_types is 7 AND NOT 8 here */
-                "multlo, multhi:     min & max multiplier of total input duration of motif\n"
-                "atten:              overall attenuation of the output\n"
-                "position:           centre of output sound-image (0(Left) 1(Right):default 0.5)\n"
-                "spread:             spatial-spread of texture events (0 - 1(full-spread))\n"
-                "seed:               same seed-no: same output on rerun(dflt 0: differs each time)\n"
-                "-w:                 always play whole input-sound (ignoring duration values).\n"
-                "-d                  notes of any one motif all have same duration.\n"
-                "-i:                 motif not each confined to fixed instr (default:fixed)\n",MAX_SCAT_TEXTURE);
-    } else if(!strcmp(str,"tmotifs")) {
-        fprintf(stdout,
-                "TIMED TEXTURE OF MOTIFS, THEMSELVES NOT FORCED ONTO HARMONIC FIELD: USAGE:\n"
-                "texture tmotifs mode infile [infile2...] outfile notedata outdur skip\n"
-                "sndfirst sndlast mingain maxgain minpitch maxpitch phgrid\n"
-                "gpspace gpsprange amprise contour multlo multhi\n"
-                "                    [-aatten] [-pposition] [-sspread] [-rseed] [-w] [-d]\n"
-                "MODES:-\n"
-                "1)ON HARMONIC-FIELD 2)CHANGING HFLDS 3)HARMONIC-SET 4)CHANGING HSETS 5)NONE\n"
-                "notedata:  infofile, 'pitch' of insnds,texture timings,motifs,hfields etc....\n"
-                "outdur:             (min) duration of outfile\n"
-                "skip:               time between repetitions of timing motif in notedata\n"
-                "sndfirst,sndlast:   1st,last snd to use, from input snds (range 1 - all)\n"
-                "mingain,maxgain:    min & max level of input events (1-127:default 64,64)\n"
-                "minpitch,maxpitch:  min & max pitch (MIDI VALUE)\n"
-                "phgrid:             a timegrid (MS) applying WITHIN the motifs\n"
-                "gpspace:            spatialisation of event-groups (Range 0-5: default 1)\n"
-                "gpsprange:          spatial range of event-groups (Range 0-1: default 1)\n"
-                "amprise:            amplitude change within motifs: (0-127: default 0)\n"
-                "contour:            amplitude contour of groups (Range 0-6: default 0)\n"
-                /* NOTE : CARE all_types is 7 AND NOT 8 here */
-                "multlo, multhi:     min & max multiplier of total input duration of motif\n"
-                "atten:              overall attenuation of the output\n"
-                "position:           centre of output sound-image (0(Left) 1(Right):default 0.5)\n"
-                "spread:             spatial-spread of texture events (0 - 1(full-spread))\n"
-                "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-                "-w:                 always play whole input-sound (ignoring duration values).\n"
-                "-d:                 motif notes all have same duration as ornamented note\n"
-                "-i:                 motif not each confined to fixed instr (default:fixed)\n");
-    } else
-        fprintf(stdout,"Unknown option '%s'\n",str);
-    return(USAGE_ONLY);
-}
-
-/******************************** USAGE3 ********************************/
-
-int usage3(char *str1,char *str2)
-{
-    sprintf(errstr,"Insufficient parameters on command line.\n");
-    return(USAGE_ONLY);
-}
-
-/******************************** INNER_LOOP (redundant)  ********************************/
-
-int inner_loop
-(int *peakscore,int *descnt,int *in_start_portion,int *least,int *pitchcnt,int windows_in_buf,dataptr dz)
-{
-    return(FINISHED);
-}

+ 0 - 236
dev/texture/prevsrc/prev-src/main.c

@@ -1,236 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
-
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-
-
-
-/* floatsam version: no changes */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <structures.h>
-#include <tkglobals.h>
-#include <texture.h>
-#include <filetype.h>
-#include <processno.h>
-#include <modeno.h>
-#include <formants.h>
-#include <cdpmain.h>
-#include <special.h>
-#include <logic.h>
-#include <globcon.h>
-#include <cdpmain.h>
-#include <sfsys.h>
-#include <ctype.h>
-
-char errstr[6000];
-
-/*extern*/ int sloom = 0;
-/*extern*/ int sloombatch = 0;
-/*extern*/ int anal_infiles = 0;
-/*extern*/ int is_converted_to_stereo = -1;
-const char* cdp_version = "7.1.1";
-
-/**************************************** MAIN *********************************************/
-
-int main(int argc,char *argv[])
-{
-    int exit_status;
-    dataptr dz = NULL;
-    /*      char *special_data_string = NULL;*/
-    char **cmdline;
-    int  cmdlinecnt;
-    //aplptr ap;
-    int *valid = NULL;
-    int is_launched = FALSE;
-    int  validcnt;
-
-    if(argc==2 && (strcmp(argv[1],"--version") == 0)) {
-        fprintf(stdout,"%s\n",cdp_version);
-        fflush(stdout);
-        return 0;
-    }
-    /* CHECK FOR SOUNDLOOM */
-    //TW UPDATE
-    if((sloom = sound_loom_in_use(&argc,&argv)) > 1) {
-        sloom = 0;
-        sloombatch = 1;
-    }
-
-    if(!sloom) {
-        if((exit_status = allocate_and_initialise_validity_flags(&valid,&validcnt))<0) {
-            print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-            return(FAILED);
-        }
-    }
-
-    if(sflinit("cdp")){
-        sfperror("cdp: initialisation\n");
-        return(FAILED);
-    }
-
-    /* SET UP THE PRINCIPLE DATASTRUCTURE */
-    if((exit_status = establish_datastructure(&dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-
-    if(!sloom) {
-        /* INITIAL CHECK OF CMDLINE DATA */
-        if((exit_status = make_initial_cmdline_check(&argc,&argv))<0) {
-            print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-            return(FAILED);
-        }
-        cmdline    = argv;      /* GET PRE_DATA, ALLOCATE THE APPLICATION, CHECK FOR EXTRA INFILES */
-        cmdlinecnt = argc;
-        if((exit_status = get_process_and_mode_from_cmdline(&cmdlinecnt,&cmdline,dz))<0) {
-            print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-            return(FAILED);
-        }
-        if((exit_status = setup_particular_application(dz))<0) {
-            print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-            return(FAILED);
-        }
-        if((exit_status = count_and_allocate_for_infiles(cmdlinecnt,cmdline,dz))<0) {
-            print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-            return(FAILED);
-        }
-    } else {
-        if((exit_status = parse_tk_data(argc,argv,&cmdline,&cmdlinecnt,dz))<0) {        /* includes setup_particular_application()      */
-            exit_status = print_messages_and_close_sndfiles(exit_status,is_launched,dz);/* and cmdlinelength check = sees extra-infiles */
-            return(exit_status);
-        }
-    }
-
-    //ap = dz->application;
-
-    /*********************************************************************************************************************
-           cmdline[0]                                             2 vals                                                          ACTIVE
-TK              (infile) (more-infiles) (outfile) (flag val) (formantsqksrch) (special) params  options   variant-params  flags
-CMDLINE (infile) (more-infiles) (outfile) (formants) (formantsqksrch) (special) params  POSSIBLY  POSSIBLY              POSSIBLY
-                                                                                  1 val
-    *********************************************************************************************************************/
-
-    if((exit_status = parse_infile_and_hone_type(cmdline[0],valid,dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-
-    if((exit_status = setup_param_ranges_and_defaults(dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-
-    /* OPEN FIRST INFILE AND STORE DATA, AND INFORMATION, APPROPRIATELY */
-
-    if(dz->input_data_type!=NO_FILE_AT_ALL) {
-        if((exit_status = open_first_infile(cmdline[0],dz))<0) {
-            print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-            return(FAILED);
-        }
-        //TW UPDATE
-        cmdlinecnt--;
-        cmdline++;
-    }
-
-    /*********************************************************************************************************************
-                cmdline[0]                                 2 vals                                                          ACTIVE
-TK              (more-infiles) (outfile) (flag val) (formantsqksrch) (special) params  options   variant-params  flags
-CMDLINE (more-infiles) (outfile) (formants) (formantsqksrch) (special) params  POSSIBLY  POSSIBLY                 POSSIBLY
-                                                                   1 val
-    *********************************************************************************************************************/
-
-    if((exit_status = handle_extra_infiles(&cmdline,&cmdlinecnt,dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-
-    /*********************************************************************************************************************
-                cmdline[0]        2                                                                 ACTIVE
-TK              (outfile) (flag val) (formantsqksrch) (special) params  options   variant-params  flags
-CMDLINE (outfile) (formants) (formantsqksrch) (special) params  POSSIBLY  POSSIBLY                 POSSIBLY
-                                          1
-    *********************************************************************************************************************/
-
-    if((exit_status = handle_outfile(&cmdlinecnt,&cmdline,is_launched,dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-
-    /****************************************************************************************
-                cmdline[0]                                                     ACTIVE
-TK              (flag val) (formantsqksrch) (special) params  options   variant-params  flags
-CMDLINE (formants) (formantsqksrch) (special) params  POSSIBLY  POSSIBLY                POSSIBLY
-    *****************************************************************************************/
-
-    if((exit_status = handle_formants(&cmdlinecnt,&cmdline,dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-    if((exit_status = handle_formant_quiksearch(&cmdlinecnt,&cmdline,dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-    if((exit_status = handle_special_data(&cmdlinecnt,&cmdline,dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-
-    /****************************************************************************************
-                cmdline[0]
-TK              active_params   options                 variant-params  flags
-CMDLINE active_params   POSSIBLY                POSSIBLY                POSSIBLY
-    *****************************************************************************************/
-
-    if((exit_status = read_parameters_and_flags(&cmdline,&cmdlinecnt,dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-
-    if((exit_status = check_param_validity_and_consistency(dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-
-    is_launched = TRUE;
-
-    if((exit_status = allocate_large_buffers(dz))<0){
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-    if((exit_status = param_preprocess(dz))<0){
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-    if((exit_status = groucho_process_file(dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-    if((exit_status = complete_output(dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-    exit_status = print_messages_and_close_sndfiles(FINISHED,is_launched,dz);
-    free(dz);
-    return(SUCCEEDED);
-}

+ 0 - 194
dev/texture/prevsrc/prev-src/texperm.c

@@ -1,194 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
-
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-
-
-
-/* floatsam version: no changes */
-#include <stdio.h>
-#include <stdlib.h>
-#include <structures.h>
-#include <tkglobals.h>
-#include <texture.h>
-#include <globcon.h>
-#include <arrays.h>
-
-#include <osbind.h>
-
-static void rndpermm(int k,int pindex,int **permm,dataptr dz);
-static void insert(int m,int t,int pindex,int **permm,dataptr dz);
-static void prefix(int m,int pindex,int **permm,dataptr dz);
-static void shuflup(int k,int pindex, int **permm,dataptr dz);
-
-/******************************** DOPERM *********************************
- *
- * Either deliver next item in a permuted set, or (if set exhausted)
- * generate a randon permutation of the set and deliver its first
- * element.
- *
- * (1)  If this permset does not have the same length as the last...
- * (2)    Set a new permset length.
- * (3)    If a permset already exists (i.e. this is not first)
- *        Free the permset space, and malloc a new space of correct size,
- * (4)    Create a random permutation of elements into the permset.
- * (5)    Set the pointer-to-the-set to 0.
- * (6)    Set the size of the previous perm (which will be this one,
- *        next time!) to this permset size.
- * (6a) Whether or not a new perm set has been set up...
- * (7)    Get the value of the next item in the current permset,
- *        incrementing the set pointer in the process.
- * (8)    If this has the same value as the previous-one-output-from-doperm
- *        increment the repetition counter.
- * (9)    Otherwise set the repetition counter to 1.
- * (10)   If the set pointer has run beyond the permset.
- * (11)     reset the pointer to 0.
- * (12)     generate a new random perm (of same length).
- * (13) Continue this process if the number of permissible repetitions
- *      is exceeded.
- * (14) Set the value for lastpermval, for next call.
- * (15) Return the value.
- */
-
-int doperm(int k,int pindex,int *val,dataptr dz)
-{
-    int i, OK;
-    int **permm = dz->tex->perm;
-    if(pindex >= PERMCNT) {
-        sprintf(errstr,"doperm(): Perm index %d too big (max = %d)\n",pindex,PERMCNT);
-        return(PROGRAM_ERROR);
-    }
-    if(k <= 1) {
-        if(k>=0) {
-            *val = 0;
-            return(FINISHED);
-        } else {
-            sprintf(errstr,"doperm(): Invalid perm count %d\n",k);
-            return(PROGRAM_ERROR);
-        }
-    }
-    if((k*dz->iparray[TXRPT][pindex])!=dz->iparray[TXLASTPERMLEN][pindex]) {        /* 1 */
-        dz->iparray[TXPERMLEN][pindex] = (int)(k * dz->iparray[TXRPT][pindex]); /* 2 */
-        if(permm[pindex]   != (int *)0)                                                                                 /* 3 */
-            free(permm[pindex]);
-        if((permm[pindex] = (int *)malloc(dz->iparray[TXPERMLEN][pindex] * sizeof(int)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for permutation %d\n",pindex+1);
-            return(MEMORY_ERROR);
-        }
-        rndpermm(k,pindex,permm,dz);                                                                                    /* 4 */
-        dz->iparray[TXPERMINDEX][pindex]   = 0;                                                                 /* 5 */
-        dz->iparray[TXLASTPERMLEN][pindex] = dz->iparray[TXPERMLEN][pindex];    /* 6 */
-    }
-    do {                                            /* 6a */
-        OK = 1;
-        i = *(permm[pindex] + (dz->iparray[TXPERMINDEX][pindex]++));                    /* 7 */
-        if(i==dz->iparray[TXLASTPERMVAL][pindex]) {                                                             /* 8 */
-            dz->iparray[TXREPETCNT][pindex]++;
-            if(dz->iparray[TXREPETCNT][pindex]>dz->iparray[TXRPT][pindex]) {
-                dz->iparray[TXREPETCNT][pindex] = dz->iparray[TXRPT][pindex];
-                OK = 0;
-            }
-        } else {
-            dz->iparray[TXREPETCNT][pindex]=1;
-        }
-        if(dz->iparray[TXPERMINDEX][pindex]>=dz->iparray[TXPERMLEN][pindex]) {  /* 10 */
-            dz->iparray[TXPERMINDEX][pindex] = 0;                                                           /* 11 */
-            rndpermm(k,pindex,permm,dz);                                                                            /* 12 */
-        }
-    }while(!OK);                                                                                                                            /* 13 */
-    dz->iparray[TXLASTPERMVAL][pindex] = i;                                                                         /* 14 */
-    *val = i;
-    return(FINISHED);                                                                                                                       /* 15 */
-}
-
-/*************************** RNDPERMM *******************************
- *
- * Produce a permutation of k objects and store it in permutation-store
- * number 'pindex'.
- *
- * (1)  permlen is the number of objects (k) times the number of repetitions
- *          permitted (rpt[pindex]) = N.
- * (2)  This is the efficient algorithm for distributing N objects into
- *              a random perm.
- * (3)  As we really only have k objects, we take the value%rpt in each
- *              permutation location.
- *              e.g. 3 objects repeated 3 times would give us a random perm of
- *              nine objects such as
- *              5 6 2 8 3 0 1 7 4
- *              applying %3 to this we get
- *              2 0 2 2 0 0 1 1 1
- *              i.e. a perm of 3 objects with no more than 3 consecutive repets
- *              of any one object!!
- */
-
-void rndpermm(int k,int pindex,int **permm,dataptr dz)
-{
-    int n, t;
-    for(n=0;n<dz->iparray[TXPERMLEN][pindex];n++) {         /* 1 */
-        t = (int)(drand48() * (double)(n+1));           /* 2 */
-        if(t==n) {
-            prefix(n,pindex,permm,dz);
-        } else {
-            insert(n,t,pindex,permm,dz);
-        }
-    }
-    for(n=0;n<dz->iparray[TXPERMLEN][pindex];n++)           /* 3 */
-        *(permm[pindex]+n) = (int)(*(permm[pindex]+n) % k);
-}
-
-/***************************** INSERT **********************************
- *
- * Insert the value m AFTER the T-th element in permm[pindex].
- */
-
-void insert(int m,int t,int pindex,int **permm,dataptr dz)
-{
-    shuflup(t+1,pindex,permm,dz);
-    *(permm[pindex]+t+1) = m;
-}
-
-/***************************** PREFIX ************************************
- *
- * Insert the value m at start of the permutation permm[pindex].
- */
-
-void prefix(int m,int pindex,int **permm,dataptr dz)
-{
-    shuflup(0,pindex,permm,dz);
-    *permm[pindex] = m;
-}
-
-/****************************** SHUFLUP ***********************************
- *
- * move set members in permm[pindex] upwards, starting from element k.
- */
-
-void shuflup(int k,int pindex, int **permm,dataptr dz)
-{
-    int n, *i;
-    int z = dz->iparray[TXPERMLEN][pindex] - 1;
-    i = permm[pindex] + z;
-    for(n = z;n > k;n--) {
-        *i = *(i-1);
-        i--;
-    }
-}

+ 0 - 1527
dev/texture/prevsrc/prev-src/texprepro.c

@@ -1,1527 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
-
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-
-
-
-/* floatsam version */
-#include <stdio.h>
-#include <stdlib.h>
-#include <memory.h>
-#include <structures.h>
-#include <tkglobals.h>
-#include <globcon.h>
-#include <processno.h>
-#include <modeno.h>
-#include <arrays.h>
-#include <texture.h>
-#include <ctype.h>
-#include <sfsys.h>
-#include <osbind.h>
-#include <cdpmain.h>
-
-#if defined unix || defined __GNUC__
-#define round(x) lround((x))
-#endif
-
-#define SQUASH    (2.0) /* non-linearity factor */
-#define MAXPOSCNT (512) /* max no. of spatial positions between lspkrs */
-
-static int  initialise_texture_structure(dataptr dz);
-static int  set_up_and_fill_insample_buffers(insamptr **insound,dataptr dz);
-static int  setup_texflag(texptr tex,dataptr dz);
-static int  adjust_some_input_params(dataptr dz);
-static int  preset_some_internal_texture_params(dataptr dz);
-static int  install_unused_texture_flags(int *total_flags,int unused_flags,dataptr dz);
-static int  install_the_internal_flags(int total_flags,int internal_flags,dataptr dz);
-static int  get_the_notedata(texptr tex,dataptr dz);
-static int  extend_timeset(dataptr dz);
-static int  generate_timeset(dataptr dz);
-static int  do_prespace(motifptr tset,dataptr dz);
-static int  get_sample_pitches(FILE *fp,dataptr dz);
-static int  get_motifs(FILE *fp,int *motifcnt,dataptr dz);
-static int  motifchek(motifptr thismotif);
-static void convert_cmdline_instrnos_to_internal_representation(dataptr dz);
-static int  check_max_transpos_compatible_with_splicelen(dataptr dz);
-static int  set_amptype_params(dataptr dz);
-static int  set_decor_pitchposition_params(dataptr dz);
-static void copy_note(noteptr thisnote,noteptr orignote);
-static int  add_motif_to_end_of_motiflist(motifptr *new,dataptr dz);
-static int  scatter_and_quantise_tset_times(double *lasttime,noteptr *thisnote,dataptr dz);
-static int  pre_space(noteptr thisnote,dataptr dz);
-static int  getpos(double thistime,double *position,dataptr dz);
-static int  spread_and_set_cpos(double *position,double given_position,double spread,dataptr dz);
-static int  chekrang(double *val);
-static int  read_a_note_from_notedata_file
-(noteptr thisnote,int noteno,int motifno,double *lasttime,dataptr dz);
-static int  generate_tset_times(double *thistime,noteptr *thisnote,dataptr dz);
-static int  un_link_note(noteptr thisnote);
-static int  new_motif(motifptr *thismotif);
-static int  unlink_last_motif(motifptr thismotif);
-static void subtract_one_from_brkvals(int paramno,dataptr dz);
-static int  bigscatter(noteptr *thisnote,double thistime,double timestep,double scatter,double *lasttime,dataptr dz);
-static int  get_data_item(char *q,char **p,double *val);
-static int  init_note(noteptr *thisnote);
-static void put_znote(noteptr thisnote);
-static int  assign_timeset_hfset_motifsets(dataptr dz);
-static int  massage_params(dataptr dz);
-static int  init_motifs(dataptr dz);
-
-/************************* TEXTURE_PREPROCESS ****************************
- *
- * (1)  Establish the bitflag which characterises the texture process.
- * (2)  For consistency across all texture processes, all unused flags are mallocd.
- *              This ensures that the numbering of the INTERNAL flags is consistent across all applics.
- * (3)  Convert some input parameters to form used internally, and check some against insnd lengths.
- */
-
-int texture_preprocess(dataptr dz)
-{
-    int exit_status;
-    int total_flags, unused_flags, n;
-    unsigned int texflag;
-
-    initialise_random_sequence(IS_TEX_RSEED,TEXTURE_SEED,dz);
-    if((exit_status = initialise_texture_structure(dz))<0)
-        return(exit_status);
-
-    if((exit_status = set_up_and_fill_insample_buffers(&(dz->tex->insnd),dz))<0)
-        return(exit_status);
-
-    if((exit_status = initperm(&(dz->tex->perm),dz))<0)
-        return(exit_status);
-
-    if((exit_status = setup_texflag(dz->tex,dz))<0)                                         /* 1 */
-        return(exit_status);
-
-    texflag = dz->tex->txflag;
-
-    if((exit_status = adjust_some_input_params(dz))<0)
-        return(exit_status);
-
-    if((exit_status = preset_some_internal_texture_params(dz))<0)
-        return(exit_status);
-    /* 2 */
-    unused_flags = TOTAL_POSSIBLE_USER_FLAGS - dz->application->vflag_cnt;
-
-    if((exit_status = install_unused_texture_flags(&total_flags,unused_flags,dz))<0)
-        return(exit_status);
-
-    if((exit_status = install_the_internal_flags(total_flags,INTERNAL_FLAGS_CNT,dz))<0)
-        return(exit_status);
-
-    if((exit_status = get_the_notedata(dz->tex,dz))<0)
-        return(exit_status);
-
-    if((exit_status = assign_timeset_hfset_motifsets(dz))<0)
-        return(exit_status);
-
-    if((exit_status = massage_params(dz))<0)                                                        /* 3 */
-        return(exit_status);
-    if(texflag & ORN_DEC_OR_TIMED) {
-        if((exit_status = extend_timeset(dz))<0)                                                /* 7 */
-            return(exit_status);
-    } else {
-        if((exit_status = generate_timeset(dz))<0)                                              /* 8 */
-            return(exit_status);
-    }
-    if((exit_status = do_prespace(dz->tex->timeset,dz))<0)
-        return(exit_status);
-
-    if(dz->process == SIMPLE_TEX && dz->vflag[CYCLIC_TEXFLAG]) {
-        if(dz->infilecnt < 2)
-            dz->vflag[CYCLIC_TEXFLAG] = 0;
-        else if (dz->vflag[PERM_TEXFLAG]) {
-            if((dz->peakno = (int *)malloc(dz->infilecnt * sizeof(int))) == NULL) {
-                sprintf(errstr,"Insufficient memory for clyclic permutations of input files.\n");
-                return(MEMORY_ERROR);
-            }
-            if((dz->lastpeakno = (int *)malloc(dz->infilecnt * sizeof(int))) == NULL) {
-                sprintf(errstr,"Insufficient memory for clyclic permutations of input files.\n");
-                return(MEMORY_ERROR);
-            }
-            for(n=0;n<dz->infilecnt;n++) {
-                dz->peakno[n] = n;
-                dz->lastpeakno[n] = n;
-            }
-        }
-    }
-    /* create stereo outfile here! */
-    /* RWD 4:2002  now we can open outfile with corect params! */
-    //TW UPDATE to use stereo input means that dz->infile->channels must be retained for now
-    //TW Open outfile later (texture5.c)
-    return(FINISHED);
-}
-
-/*********************** INITIALISE_TEXTURE_STRUCTURE ******************************/
-
-int initialise_texture_structure(dataptr dz)
-{
-    int n;
-    if((dz->tex = (texptr)malloc(sizeof(struct textural)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for texture structure.\n");
-        return(MEMORY_ERROR);
-    }
-
-    dz->tex->txflag     = 0;
-    dz->tex->motifhead  = (motifptr)0;
-    dz->tex->insnd      = (insamptr *)0;
-    dz->tex->timeset    = (motifptr)0;
-    dz->tex->hfldmotif  = (motifptr)0;
-    dz->tex->phrase     = (motifptr *)0;
-    dz->tex->perm       = (int **)0;
-    dz->tex->dectypstor = 0;
-    dz->tex->dectypcnt      = 0;
-    dz->tex->amptypstor = 0;
-    dz->tex->amptypcnt  = 0;
-    dz->tex->phrasecnt  = 0;
-    dz->tex->ampdirectd = FALSE;
-
-    if((dz->tex->insnd      = (insamptr *)malloc(dz->infilecnt * sizeof(insamptr)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for texture insound structure.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n<dz->infilecnt;n++) {
-        dz->tex->insnd[n] = (insamptr)0;
-        if((dz->tex->insnd[n]= (insamptr)malloc(sizeof(struct insample)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for texture insound[%d] structure.\n",n+1);
-            return(MEMORY_ERROR);
-        }
-    }
-    return(FINISHED);
-}
-
-/************************** SET_UP_AND_FILL_INSAMPLE_BUFFERS ****************************
- *
- * 1) Set buffer pointer to zero, until it has been malloced.
- *        This make freeing of tex structure possible.
- */
-
-int set_up_and_fill_insample_buffers(insamptr **insound,dataptr dz)
-{
-    int n;
-    int samps_read;
-    int thisbufsize;
-    int wrap_around_samps = 1;
-    for(n=0;n<dz->infilecnt;n++) {
-        ((*insound)[n])->buffer = /*(float *)0*/NULL;                                   /* 1 */
-        thisbufsize = dz->insams[n];
-        thisbufsize += wrap_around_samps;
-        if((((*insound)[n])->buffer  = (float *)malloc(thisbufsize * sizeof(float)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for texture insound buffer pointer %d.\n",n+1);
-            return(MEMORY_ERROR);
-        }
-        memset((char *)((*insound)[n])->buffer,0,thisbufsize * sizeof(float));
-        if((samps_read = fgetfbufEx(((*insound)[n])->buffer,thisbufsize,dz->ifd[n],0)) < 0) {
-            sprintf(errstr,"Can't read sndfile %d to buffer: set_up_and_fill_insample_buffers()\n",n+1);
-            return(SYSTEM_ERROR);
-        }
-        if(samps_read != dz->insams[n]) {
-            sprintf(errstr,"Error reading sndfile %d to buf: set_up_and_fill_insample_buffers()\n",n+1);
-            return(PROGRAM_ERROR);
-        }
-    }
-    return(FINISHED);
-}
-
-/***************************** SETUP_TEXFLAG ****************************/
-
-int setup_texflag(texptr tex,dataptr dz)
-{
-    tex->txflag = 0;
-    switch(dz->process) {
-    case(SIMPLE_TEX): break;
-    case(GROUPS):     tex->txflag |= IS_GROUPS;                                                                                                         break;
-    case(DECORATED):  tex->txflag |= IS_DECOR;                                                                                                              break;
-    case(PREDECOR):   tex->txflag |= IS_DECOR;      tex->txflag |= ISPRE_DECORORN;                                          break;
-    case(POSTDECOR):  tex->txflag |= IS_DECOR;      tex->txflag |= ISPOST_DECORORN;                                     break;
-    case(ORNATE):     tex->txflag |= IS_ORNATE;                                                                                                         break;
-    case(PREORNATE):  tex->txflag |= IS_ORNATE; tex->txflag |= ISPRE_DECORORN;                                              break;
-    case(POSTORNATE): tex->txflag |= IS_ORNATE; tex->txflag |= ISPOST_DECORORN;                                         break;
-    case(MOTIFS):     tex->txflag |= IS_MOTIFS;                                                                                                         break;
-    case(MOTIFSIN):   tex->txflag |= IS_MOTIFS; tex->txflag |= MOTIF_IN_HF;                                             break;
-    case(TIMED):                                                                                                                    tex->txflag |= ISTIMED; break;
-    case(TGROUPS):    tex->txflag |= IS_GROUPS;                                                             tex->txflag |= ISTIMED; break;
-    case(TMOTIFS):    tex->txflag |= IS_MOTIFS;                                                             tex->txflag |= ISTIMED; break;
-    case(TMOTIFSIN):  tex->txflag |= IS_MOTIFS; tex->txflag |= MOTIF_IN_HF; tex->txflag |= ISTIMED; break;
-    default:
-        sprintf(errstr,"Unknown process in setup_texflag()\n");
-        return(PROGRAM_ERROR);
-    }
-    switch(dz->mode) {
-    case(TEX_NEUTRAL):      break;
-    case(TEX_HFIELD):       tex->txflag |= ISHARM;                                                                                                                  break;
-    case(TEX_HFIELDS):      tex->txflag |= ISHARM;                                                  tex->txflag |= ISMANY_HFLDS;    break;
-    case(TEX_HSET):         tex->txflag |= ISHARM;  tex->txflag |= IS_HS;                                                                   break;
-    case(TEX_HSETS):        tex->txflag |= ISHARM;  tex->txflag |= IS_HS;   tex->txflag |= ISMANY_HFLDS;    break;
-    default:
-        sprintf(errstr,"Unknown mode in setup_texflag()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/************************** ADJUST_SOME_INPUT_PARAMS ****************************
- *
- * (1)  dz->vflag[WHICH_CHORDNOTE] internally carries all 3 vals (first,highest,every).
- *
- * (2)  Gprange, in cases with Hfields, is an integer count of HF-field notes to use.
- */
-
-int adjust_some_input_params(dataptr dz)
-{
-    int texflag = dz->tex->txflag;
-    if((texflag & IS_ORN_OR_DEC) && dz->vflag[FORCE_EVERY]==TRUE)
-        dz->vflag[WHICH_CHORDNOTE] = DECOR_EVERY;                                               /* 1 */
-
-    if((texflag & IS_DEC_OR_GRP) && (texflag & ISHARM)) {                           /* 2 */
-        dz->is_int[TEX_GPRANGLO] = TRUE;
-        dz->is_int[TEX_GPRANGHI] = TRUE;
-        dz->iparam[TEX_GPRANGLO] = round(dz->param[TEX_GPRANGLO]);
-        dz->iparam[TEX_GPRANGHI] = round(dz->param[TEX_GPRANGHI]);
-    }
-    return(FINISHED);
-}
-
-/***************************** PRESET_SOME_INTERNAL_TEXTURE_PARAMS ****************************/
-
-int preset_some_internal_texture_params(dataptr dz)
-{
-    int cnt = 0;
-    dz->iparam[SPINIT]    = 0;       cnt++; /* ALL CLUMPS */
-    dz->iparam[SPCNT]     = 0;       cnt++;
-    dz->iparam[DIRECTION] = 0;       cnt++;
-    dz->param[CPOS]       = 0.5; cnt++; /* for safety only */       /* SPATIALISATION */
-    dz->param[TPOSITION]  = 0.5; cnt++; /* for safety only */
-    dz->param[THISSPRANGE]= 1.0; cnt++; /* full range */
-    /*dz->iparam[TEX_MAXOUT]= 0.0;   cnt++; *//* min value */
-    dz->param[TEX_MAXOUT] = 0.0;   cnt++;             /*RWD*/
-    if(cnt != dz->application->internal_param_cnt) {
-        sprintf(errstr,"preset_some_internal_texture_params() has false count\n");
-        return(PROGRAM_ERROR);
-    }
-    dz->itemcnt = 0;
-    return(FINISHED);
-}
-
-/***************************** INSTALL_UNUSED_TEXTURE_FLAGS ****************************/
-
-int install_unused_texture_flags(int *total_flags,int unused_flags,dataptr dz)
-{
-    int n;
-    *total_flags = dz->application->vflag_cnt + unused_flags;
-    if(unused_flags > 0) {
-        if((dz->vflag  =
-            (char *)realloc(dz->vflag,(*total_flags) * sizeof(char)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for internal flags.\n");
-            return(MEMORY_ERROR);
-        }
-        for(n=0;n<unused_flags;n++) {
-            switch(n) {
-            case(4):        dz->vflag[2] = FALSE;   break;
-            case(3):        dz->vflag[3] = FALSE;   break;
-            case(2):        dz->vflag[4] = FALSE;   break;
-            case(1):        dz->vflag[5] = FALSE;   break;
-            case(0):        dz->vflag[6] = FALSE;   break;
-            }
-        }
-    }
-    return(FINISHED);
-}
-
-/***************************** INSTALL_THE_INTERNAL_FLAGS ****************************/
-
-int install_the_internal_flags(int total_flags,int internal_flags,dataptr dz)
-{
-    /* THESE FLAGS ARE NOT AVAILABLE TO USER : but they are used in the code */
-    total_flags += internal_flags;
-    if((dz->vflag  =
-        (char *)realloc(dz->vflag,total_flags * sizeof(char)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate internal flags.\n");
-        return(MEMORY_ERROR);
-    }
-    dz->iparam[DECCENTRE] = FALSE;
-    return(FINISHED);
-}
-
-/***************************** GET_THE_NOTEDATA ****************************/
-
-int get_the_notedata(texptr tex,dataptr dz)
-{
-    int exit_status;
-    unsigned int texflag = tex->txflag;
-    int motifcnt, expected_motifcnt = 0;
-
-    if(dz->fp==NULL) {
-        sprintf(errstr,"notedata fileptr not initialised: get_the_notedata()\n");
-        return(PROGRAM_ERROR);
-    }
-    if((exit_status = get_sample_pitches(dz->fp,dz))<0) {
-        sprintf(errstr,"Insufficient pitch values in notedata file.\n");
-        return(DATA_ERROR);
-    }
-    if((exit_status = get_motifs(dz->fp,&motifcnt,dz))<0)
-        return(exit_status);
-    if(texflag & ORN_DEC_OR_TIMED)  expected_motifcnt++;    /* Line to work on */
-    if(texflag & ISHARM)                    expected_motifcnt++;    /* HF data                 */
-    if(texflag & IS_ORN_OR_MTF)             expected_motifcnt++;    /* Ornmnts or mtfs */
-
-    if(texflag & IS_ORN_OR_MTF)     {
-        if(motifcnt < expected_motifcnt) {
-            sprintf(errstr,"Insufficient motifs in notedata file.\n");
-            return(DATA_ERROR);
-        }
-    } else {
-        if(motifcnt!=expected_motifcnt) {
-            sprintf(errstr,"Incorrect number [%d] of motifs in notedata file (expected %d).\n",
-                    motifcnt,expected_motifcnt);
-            return(DATA_ERROR);
-        }
-    }
-    return(FINISHED);
-}
-
-/**************************** EXTEND_TIMESET *******************************/
-
-int extend_timeset(dataptr dz)
-{
-    int exit_status;
-    int origcnt = 0, n;
-    noteptr startnote = dz->tex->motifhead->firstnote;
-    noteptr orignote, thisnote  = startnote;
-    double *timediff;
-
-    if(startnote==(noteptr)0) {
-        sprintf(errstr,"Problem in note timings: extend_timeset()\n");
-        return(PROGRAM_ERROR);
-    }
-    while(thisnote!=(noteptr)0) {
-        if(thisnote->ntime > dz->param[TEXTURE_DUR]) {
-            delete_notes_here_and_beyond(thisnote);
-            return(FINISHED);
-        }
-        thisnote = thisnote->next;
-        origcnt++;
-    }
-
-    if((timediff = (double *)malloc(origcnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for timegaps array.\n");
-        return(MEMORY_ERROR);
-    }
-    n = 1;
-    thisnote = startnote;
-    while(thisnote->next !=(noteptr)0) {
-        thisnote = thisnote->next;
-        timediff[n++] = thisnote->ntime - thisnote->last->ntime;
-    }
-    if(dz->brksize[TEXTURE_SKIP]) {
-        if((exit_status = read_value_from_brktable(thisnote->ntime,TEXTURE_SKIP,dz))<0) {
-            free(timediff);
-            return(exit_status);
-        }
-    }
-    timediff[0] = dz->param[TEXTURE_SKIP];
-    n = 0;
-    orignote = startnote;
-
-    for(;;) {
-        if(thisnote->ntime > dz->param[TEXTURE_DUR] && timediff[n] > 0.0)
-            break;
-        if((exit_status = make_new_note(&thisnote))<0) {
-            free(timediff);
-            return(exit_status);
-        }
-        copy_note(thisnote,orignote);
-        thisnote->ntime = (float)(thisnote->last->ntime + timediff[n]);
-        if(++n>=origcnt) {
-            if(dz->brksize[TEXTURE_SKIP]) {
-                if((exit_status = read_value_from_brktable(thisnote->ntime,TEXTURE_SKIP,dz))<0) {
-                    free(timediff);
-                    return(exit_status);
-                }
-                timediff[0] = dz->param[TEXTURE_SKIP];
-            }
-            n = 0;
-            orignote = startnote;
-        } else
-            orignote = orignote->next;
-    }
-    dz->brksize[TEXTURE_SKIP] = 0;  /* prevent future reads */
-    free(timediff);
-    return(FINISHED);
-}
-
-
-/*********************************************************************
- *
- * (1)  Generating the tset (set of timed values on or around which the
- *              texture is to be generated).
- */
-/************************** GENERATE_TIMESET ******************************
- *
- * (A)  Zero all other parameters besides time.
- */
-
-int generate_timeset(dataptr dz)
-{
-    int exit_status;
-    double lasttime, thistime = 0.0;
-    noteptr thisnote;
-    motifptr tset;
-    if((exit_status = add_motif_to_end_of_motiflist(&(dz->tex->timeset),dz))<0)
-        return(exit_status);
-    tset =  dz->tex->timeset;
-    if((thisnote = tset->firstnote)==(noteptr)0) {
-        sprintf(errstr,"Failure to find 1st note in motif: generate_timeset()\n");
-        return(PROGRAM_ERROR);
-    }
-    put_znote(thisnote);                    /* A */
-    thisnote->ntime = (float)thistime;
-    if(dz->brksize[TEXTURE_PACK]) {
-        if((exit_status = read_value_from_brktable(thistime,TEXTURE_PACK,dz))<0)
-            return(exit_status);
-    }
-    thistime += dz->param[TEXTURE_PACK];
-    while(thistime<dz->param[TEXTURE_DUR]) {
-        if((exit_status = generate_tset_times(&thistime,&thisnote,dz))<0)
-            return(exit_status);
-        put_znote(thisnote);                            /* A */
-    }
-    thisnote = tset->firstnote;
-    lasttime = thisnote->ntime;
-    thisnote = thisnote->next;
-    while(thisnote!=(noteptr)0) {
-        if((exit_status = scatter_and_quantise_tset_times(&lasttime,&thisnote,dz))<0)
-            return(exit_status);
-    }
-    dz->brksize[TEXTURE_PACK]  = 0; /* set these brktables to appear empty, so no read attempts later */
-    dz->brksize[TEXTURE_SCAT]  = 0;
-    dz->brksize[TEXTURE_TGRID] = 0;
-    return(FINISHED);
-}
-
-/***************************** DO_PRESPACE ******************************
- *
- * Spatialise the time set, prior to output phase&/or ornamentation.
- */
-
-int do_prespace(motifptr tset,dataptr dz)
-{
-    int exit_status;
-    noteptr thisnote = tset->firstnote;
-    while(thisnote!=(noteptr)0) {
-        if((exit_status = pre_space(thisnote,dz))<0)
-            return(exit_status);
-        thisnote = thisnote->next;
-    }
-    return(FINISHED);
-}
-
-/**************************** GET_SAMPLE_PITCHES *****************************/
-
-int get_sample_pitches(FILE *fp,dataptr dz)
-{
-    int exit_status;
-    /* TW AUGUST 2006: 200--> 2000 */
-    char temp[2000], *q;
-    int pitchcnt = 0;
-    double *p;
-    int got_all_pitches = FALSE;
-    /* TW AUGUST 2006: 200--> 2000 */
-    while(!got_all_pitches && (fgets(temp,2000,fp)!=NULL)) {
-        q = temp;
-        p = &(((dz->tex->insnd)[pitchcnt])->pitch);
-        while((exit_status = get_float_from_within_string(&q,p))==TRUE) {
-            if(++pitchcnt >= dz->infilecnt) {
-                got_all_pitches = TRUE;
-                break;
-            }
-            p = &(((dz->tex->insnd)[pitchcnt])->pitch);
-        }
-        if(exit_status==FALSE)
-            return(DATA_ERROR);
-    }
-    if(!got_all_pitches)
-        return(DATA_ERROR);
-    return(FINISHED);
-}
-
-/**************************** GET_MOTIFS *****************************
- *
- * Read data from an ascii file to notelist.
- */
-
-int get_motifs(FILE *fp,int *motifcnt,dataptr dz)
-{
-    int exit_status;
-    motifptr thismotif;
-    noteptr thisnote;
-    char *p, temp[200];
-    double lasttime = 0.0;
-    int datalen, noteno, motifno = 0;
-    if((exit_status = init_motifs(dz))<0)               /* 8 */
-        return(exit_status);
-    thismotif = dz->tex->motifhead;
-    while(fgets(temp,200,fp)!=NULL) {
-        p = temp;
-        while(isspace(*p))
-            p++;
-        if(*p==ENDOFSTR)
-            continue;
-        if(*p!=TEXTURE_SEPARATOR) {
-            //TW UPDATE
-            sprintf(errstr,"'%c' missing before datacount in notedata file: motif %d (or more notes listed than indicated by %cN)\n"
-                    "check datalen is correct\n",TEXTURE_SEPARATOR,motifno+1,TEXTURE_SEPARATOR);
-            return(DATA_ERROR);
-        }
-        p++;
-        if(!isdigit(*p) || sscanf(p,"%d",&datalen)!=1) {
-            sprintf(errstr,"No datalength given: motif %d\n",motifno+1);
-            return(DATA_ERROR);
-        }
-        if(datalen <= 0) {
-            sprintf(errstr,"Invalid data length %d in notedata: motif %d\n",datalen,motifno+1);
-            return(DATA_ERROR);
-        }
-        motifno++;
-        thisnote = thismotif->firstnote;
-        for(noteno=1;noteno<=datalen;noteno++) {
-            if((exit_status = read_a_note_from_notedata_file(thisnote,noteno,motifno,&lasttime,dz))<0)
-                return(exit_status);
-            if(exit_status==CONTINUE) {
-                noteno--;
-                continue;
-            }
-            if((exit_status = make_new_note(&thisnote))<0)
-                return(exit_status);
-        }
-        if((exit_status = un_link_note(thisnote))<0)
-            return(exit_status);
-        if((exit_status = new_motif(&thismotif))<0)
-            return(exit_status);
-    }
-    *motifcnt = motifno;
-    if(motifno > 0)
-        return unlink_last_motif(thismotif);
-    return(FINISHED);
-}
-
-/************************** MOTIFCHEK ********************************
- *
- * Check we've not run out of motifs.
- */
-
-int motifchek(motifptr thismotif)
-{
-    if(thismotif == (motifptr)0) {
-        sprintf(errstr,"motifchek(): Insufficient motifs: even though correctly counted.\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/***************************** CONVERT_CMDLINE_INSTRNOS_TO_INTERNAL_REPRESENTATION ****************************/
-
-void convert_cmdline_instrnos_to_internal_representation(dataptr dz)
-{
-    if(dz->brksize[TEXTURE_INSLO])
-        subtract_one_from_brkvals(TEXTURE_INSLO,dz);
-    else
-        dz->iparam[TEXTURE_INSLO]--;
-
-    if(dz->brksize[TEXTURE_INSHI])
-        subtract_one_from_brkvals(TEXTURE_INSHI,dz);
-    else
-        dz->iparam[TEXTURE_INSHI]--;
-}
-
-/***************************** CHECK_MAX_TRANSPOS_COMPATIBLE_WITH_SPLICELEN ****************************/
-
-int check_max_transpos_compatible_with_splicelen(dataptr dz)
-{
-    int n, exit_status;
-    double max_maxpitch, max_minpitch, max_transpospitch, maxupshift, upratio, minlen;
-    double min_sndlength = (TEXTURE_SPLICELEN + TEXTURE_SAFETY) * MS_TO_SECS * (double)dz->infile->srate;
-    dz->frametime = TEXTURE_SPLICELEN;
-
-    if(dz->brksize[TEXTURE_MAXPICH]) {
-        if((exit_status = get_maxvalue_in_brktable(&max_maxpitch,TEXTURE_MAXPICH,dz))<0)
-            return(exit_status);
-    } else
-        max_maxpitch = dz->param[TEXTURE_MAXPICH];
-
-    if(dz->brksize[TEXTURE_MINPICH]) {
-        if((exit_status = get_maxvalue_in_brktable(&max_minpitch,TEXTURE_MINPICH,dz))<0)
-            return(exit_status);
-    } else
-        max_minpitch = dz->param[TEXTURE_MINPICH];
-
-    max_transpospitch = max(max_minpitch,max_maxpitch);
-
-    dz->zeroset = 0;        /* use as flag re splicelen change */
-    for(n=0;n<dz->infilecnt;n++) {
-        maxupshift = max_transpospitch - ((dz->tex->insnd)[n])->pitch;
-        upratio    = pow(2.0,(maxupshift/SEMITONES_PER_OCTAVE));
-        minlen     = (double)dz->insams[n]/upratio;
-        if(minlen < min_sndlength) {
-            dz->frametime = 2.0;
-            min_sndlength = (dz->frametime + TEXTURE_SAFETY) * MS_TO_SECS * (double)dz->infile->srate;
-            if(minlen < min_sndlength) {
-                dz->frametime = 1.0;
-                min_sndlength = (dz->frametime + TEXTURE_SAFETY) * MS_TO_SECS * (double)dz->infile->srate;
-                if(minlen < min_sndlength) {
-                    sprintf(errstr,"sndfile %d [%.3lf secs] too short for max upward transposition [ratio %.2lf].\n",
-                            n+1,(double)dz->insams[n]/(double)dz->infile->srate,upratio);
-                    return(DATA_ERROR);
-                }
-            }
-        }
-    }
-    return(FINISHED);
-}
-
-/************************* SET_AMPTYPE_PARAMS *******************************/
-
-int set_amptype_params(dataptr dz)
-{   int mask = 1, n;
-    dz->tex->amptypcnt  = 0;
-    dz->tex->amptypstor = 0;
-    switch(dz->iparam[TEX_AMPCONT]) {
-    case(IS_MIXED):                          dz->tex->amptypstor |= 1;      dz->tex->amptypstor |= 2;                                                       break;
-    case(IS_CRESC):                                                                                 dz->tex->amptypstor |= 2;                                                       break;
-    case(IS_FLAT):                           dz->tex->amptypstor |= 1;                                                                                                              break;
-    case(IS_DECRESC):                                                                                                                                 dz->tex->amptypstor |= 4;     break;
-    case(IS_FLAT_AND_CRESC):         dz->tex->amptypstor |= 1;      dz->tex->amptypstor |= 2;                                                       break;
-    case(IS_CRESC_AND_DECRESC):                                                             dz->tex->amptypstor |= 2; dz->tex->amptypstor |= 4;     break;
-    case(IS_FLAT_AND_DECRESC):       dz->tex->amptypstor |= 1;                                                        dz->tex->amptypstor |= 4;     break;
-
-    case(IS_DIRECTIONAL):            dz->tex->ampdirectd = TRUE;    dz->tex->amptypcnt = 1;                                                 break;
-    case(IS_DIREC_OR_FLAT):          dz->tex->ampdirectd = TRUE;    dz->tex->amptypcnt = 2;                                                 break;
-    default:
-        sprintf(errstr,"Unknown case in set_amptype_params()\n");
-        return(PROGRAM_ERROR);
-    }
-    if(dz->tex->amptypstor > 0) {
-        for(n=0;n<3;n++) {
-            if(mask & dz->tex->amptypstor)
-                dz->tex->amptypcnt++;
-            mask <<= 1;
-        }
-    }
-    return(FINISHED);
-}
-
-/************************* SET_DECOR_PITCHPOSITION_PARAMS ******************************/
-
-int set_decor_pitchposition_params(dataptr dz)
-{
-    int n, mask = 1;
-    dz->tex->dectypstor = 0;
-    dz->tex->dectypcnt  = 0;
-    switch(dz->iparam[TEX_DECPCENTRE]) {
-    case(DEC_CENTRED): dz->tex->dectypstor |= 1;                                                                                                            break;
-    case(DEC_ABOVE):                                                         dz->tex->dectypstor |= 2;                                                              break;
-    case(DEC_BELOW):                                                                                                                dz->tex->dectypstor |= 4;       break;
-    case(DEC_C_A):     dz->tex->dectypstor |= 1; dz->tex->dectypstor |= 2;                                                          break;
-    case(DEC_C_B):     dz->tex->dectypstor |= 1;                                                    dz->tex->dectypstor |= 4;       break;
-    case(DEC_A_B):                                                           dz->tex->dectypstor |= 2;      dz->tex->dectypstor |= 4;       break;
-    case(DEC_C_A_B):   dz->tex->dectypstor |= 1; dz->tex->dectypstor |= 2;  dz->tex->dectypstor |= 4;       break;
-    default:
-        sprintf(errstr,"Unknown case in set_decor_pitchposition_params()\n");
-        return(PROGRAM_ERROR);
-    }
-    if(dz->tex->dectypstor > 0) {
-        for(n=0;n<3;n++) {
-            if(mask & dz->tex->dectypstor)
-                dz->tex->dectypcnt++;
-            mask <<= 1;
-        }
-    }
-    return(FINISHED);
-}
-
-/********************** DELETE_NOTES_HERE_AND_BEYOND *******************************
-
-void delete_notes_here_and_beyond(noteptr startnote)
-{
-        noteptr here = startnote;
-        if(here==(noteptr)0)
-                return;
-        while(here->next!=(noteptr)0)
-                here=here->next;
-        while(here!=startnote) {
-                here=here->last;
-                free(here->next);
-        }
-        if(startnote->last!=(noteptr)0)
-                startnote->last->next = (noteptr)0;
-        free(startnote);
-}
-****/
-
-/********************** MAKE_NEW_NOTE ****************************
- *
- * Create new link in note list.
- */
-
-int make_new_note(noteptr *thisnote)
-{
-    if(((*thisnote)->next = (noteptr)malloc(sizeof(struct nnote)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for a further note store.\n");
-        return(MEMORY_ERROR);
-    }
-    (*thisnote)->next->last = *thisnote;
-    *thisnote = (*thisnote)->next;
-    (*thisnote)->next = (noteptr)0;
-    return(FINISHED);
-}
-
-/**************************** COPY_NOTE *******************************/
-
-void copy_note(noteptr thisnote,noteptr orignote)
-{
-    thisnote->ntime = orignote->ntime;
-    thisnote->amp   = orignote->amp;
-    thisnote->pitch = orignote->pitch;
-    thisnote->dur   = orignote->dur;
-    thisnote->instr = orignote->instr;
-    thisnote->spacepos = orignote->spacepos;
-    thisnote->motioncentre = orignote->motioncentre;
-}
-
-/************************** ADD_MOTIF_TO_END_OF_MOTIFLIST ******************************
- *
- * Create new motif at end of list.
- */
-
-int add_motif_to_end_of_motiflist(motifptr *new,dataptr dz)
-{
-    int exit_status;
-    motifptr here = dz->tex->motifhead;
-    while(here->next!=(motifptr)0)
-        here = here->next;
-    if((exit_status =  new_motif(&here))<0)
-        return(exit_status);
-    *new = here;
-    return(FINISHED);
-}
-
-/************************* SCATTER_AND_QUANTISE_TSET_TIMES ******************************/
-
-int scatter_and_quantise_tset_times(double *lasttime,noteptr *thisnote,dataptr dz)
-{
-    int exit_status;
-    double thistime = (*thisnote)->ntime;                   /* 1 */
-    double timestep = thistime - *lasttime;                 /* 2 */
-    *lasttime = thistime;                                                   /* 2a */
-    if(dz->brksize[TEXTURE_SCAT]) {
-        if((exit_status = read_value_from_brktable(thistime,TEXTURE_SCAT,dz))<0)
-            return(exit_status);
-    }
-    if(dz->param[TEXTURE_SCAT]>1.0) {                               /* 3a */
-        //TW UPDATE (original code error)
-        if((exit_status = bigscatter(thisnote,thistime,timestep,dz->param[TEXTURE_SCAT],lasttime,dz))<0)
-            return(exit_status);
-    } else {
-        if(!flteq(dz->param[TEXTURE_SCAT],0.0))                         /* 4 */
-            thistime -= (float)(drand48() * dz->param[TEXTURE_SCAT] * timestep);
-
-        if(dz->param[TEXTURE_TGRID]>0.0)
-            thistime  = quantise(thistime,dz->param[TEXTURE_TGRID]);        /* 6 */
-        (*thisnote)->ntime = (float)thistime;
-    }
-    *thisnote = (*thisnote)->next;
-    return(FINISHED);                               /* 8a */
-}
-
-/************************** PRE_SPACE ********************************
- *
- * Store spatial data in the tsetnote spacepos and motioncentre.
- */
-
-int pre_space(noteptr thisnote,dataptr dz)
-{
-    int exit_status;
-    double position;
-    if((exit_status = getpos((double)thisnote->ntime,&position,dz))<0)
-        return(exit_status);
-    thisnote->spacepos     = (float)position;
-    thisnote->motioncentre = (float)dz->param[CPOS];
-    return(FINISHED);
-}
-
-/************************** GETPOS ****************************
- *
- * Calculate spatial position of event from it's time.
- */
-
-int getpos(double thistime,double *position,dataptr dz)
-{
-    int exit_status;
-    if(dz->brksize[TEXTURE_POS] && (exit_status = read_value_from_brktable(thistime,TEXTURE_POS,dz))<0)
-        return(exit_status);
-    if(dz->brksize[TEXTURE_SPRD] && (exit_status = read_value_from_brktable(thistime,TEXTURE_SPRD,dz))<0)
-        return(exit_status);
-    if(dz->param[TEXTURE_SPRD] > 0.0) {
-        if((exit_status = spread_and_set_cpos(position,dz->param[TEXTURE_POS],dz->param[TEXTURE_SPRD],dz))<0)
-            return(exit_status);
-    } else {
-        /* NOV 1997--> */
-        dz->param[CPOS] = dz->param[TEXTURE_POS];
-        /* <--NOV 1997 */
-        *position       = dz->param[TEXTURE_POS];
-    }
-    return(FINISHED);
-}
-
-/***************************** SPREAD_AND_SET_CPOS *****************************/
-
-int spread_and_set_cpos(double *position,double given_position,double spread,dataptr dz)
-{
-    int exit_status;
-    int        posno, spswitch;
-    int    poscnt,hposcnt;
-    double hspread,spacing, closeness, squash;
-
-    /* total stereospace has MAXPOSCNT positions: calc no. & spacing of positions available at given spread */
-    poscnt  = round(spread * (double)MAXPOSCNT);
-    hposcnt = poscnt/2;
-    hspread = spread/(double)2.0;
-    if(hposcnt != 0)
-        spacing = hspread/(double)hposcnt;
-    else {
-        /* bandwidth effectively zero: return given position */
-        dz->param[CPOS] = given_position;
-        *position       = given_position;
-        return(FINISHED);
-    }
-    /* randomly select leftwards/rightwards of the given position */
-    if((exit_status = doperm(2,PM_SPACE,&spswitch,dz))<0)
-        return(exit_status);
-    if(!spswitch)
-        spswitch = -1;
-
-    /* randomly chose a pos (to left or right) around centre pos */
-    posno  = round(drand48() * hposcnt);
-    posno *= spswitch;
-
-    /* calculate warping coefficient to avoid position-spread leaking over edges of stereo-space */
-    if(spread>(double)1.0/SQUASH)
-        squash = (double)1.0/spread;
-    else
-        squash = SQUASH;
-
-    /* If (position+spread) leaks to right of stereo-space : squeeze position */
-    if(given_position>=0.5 && (given_position + spread) > 1.0) {
-        closeness = (given_position - 0.5)/(double)0.5;
-        dz->param[CPOS] = given_position - (hspread*pow(closeness,squash));
-        /* If (position+spread) leaks to left of stereo-space : squeeze position */
-    } else if(given_position<0.5 && given_position < spread) {
-        closeness = (0.5 - given_position)/(double)0.5;
-        dz->param[CPOS] = given_position + (hspread*pow(closeness,squash));
-    } else
-        dz->param[CPOS] = given_position;
-
-    /* generate true position, around central position */
-    *position = dz->param[CPOS] + ((double)posno * spacing);
-    return chekrang(position);
-}
-
-/*************************** CHEKRANG **************************
- *
- * Check variable lies within range 0.0 to 1.0.
- */
-
-int chekrang(double *val)
-{
-    if(flteq(*val,1.0))
-        *val = 1.0;
-    if(flteq(*val,0.0))
-        *val = 0.0;
-    if(*val<0.0 || *val>1.0) {
-        sprintf(errstr,"value [%f] outside range 0-1: chekrang()\n",*val);
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/************************** READ_A_NOTE_FROM_NOTEDATA_FILE ********************************/
-
-int read_a_note_from_notedata_file(noteptr thisnote,int noteno,int motifno,double *lasttime,dataptr dz)
-{
-    int exit_status;
-    unsigned int texflag = dz->tex->txflag;
-    char temp[200], *p, *q;
-    double val;
-    int start;
-    if(dz->fp==NULL) {
-        sprintf(errstr,"Note datafile descriptor not initialised: read_a_note_from_notedata_file()\n");
-        return(PROGRAM_ERROR);
-    }
-    if(fgets(temp,200,dz->fp)==NULL){
-        sprintf(errstr,"Note data line for note %d, motif %d missing in notedatafile\n",noteno,motifno);
-        return(DATA_ERROR);
-    }
-    p =temp;
-    while(isspace(*p))
-        p++;
-    q = p;
-    if(*q==ENDOFSTR)
-        return(CONTINUE);
-    if((exit_status = get_data_item(q,&p,&val))<0) {
-        sprintf(errstr,"No time data for note %d, motif %d in notedatafile\n",noteno,motifno);
-        return(DATA_ERROR);
-    }
-    if(exit_status==FINISHED) {
-        sprintf(errstr,"No data after time for note %d, motif %d in notedatafile\n",noteno,motifno);
-        return(DATA_ERROR);
-    }
-    thisnote->ntime = (float)val;
-    if((noteno > 1) && (*lasttime > thisnote->ntime)) {
-        sprintf(errstr,"Notes in reverse time order: notedata file : motif %d: notes %d & %d\n",
-                motifno,noteno,noteno-1);
-        return(DATA_ERROR);
-    }
-    *lasttime = thisnote->ntime;
-    p++;
-    q = p;
-    if((exit_status = get_data_item(q,&p,&val))<0) {
-        sprintf(errstr,"No instr_no for note %d, motif %d in notedatafile\n",noteno,motifno);
-        return(DATA_ERROR);
-    }
-    if(exit_status==FINISHED) {
-        sprintf(errstr,"No data after instr_no for note %d, motif %d in notedatafile\n",noteno,motifno);
-        return(DATA_ERROR);
-    }
-    //instr_no = round(val);
-
-    p++;
-    q = p;
-    if((exit_status = get_data_item(q,&p,&val))<0) {
-        sprintf(errstr,"No pitch data for note %d, motif %d in notedatafile\n",noteno,motifno);
-        return(DATA_ERROR);
-    }
-    if(exit_status==FINISHED) {
-        sprintf(errstr,"No data after pitch for note %d, motif %d in notedatafile\n",noteno,motifno);
-        return(DATA_ERROR);
-    }
-    thisnote->pitch = (float)val;
-
-    /* NEEDS TESTING FOR MIDIRANGE: EXCEPT IN TIMING SET CASE */
-    if(!(texflag & ISTIMED) || motifno!=1) {
-        if(val < MIDIMIN || val > MIDIMAX) {
-            sprintf(errstr,"pitch value [%lf] out of range (%d to %d): motif %d: note %d\n",
-                    val,MIDIMIN,MIDIMAX,motifno,noteno);
-            return(DATA_ERROR);
-        }
-    }
-    p++;
-    q = p;
-    if((exit_status = get_data_item(q,&p,&val))<0) {
-        sprintf(errstr,"No amplitude data for note %d, motif %d in notedatafile\n",noteno,motifno);
-        return(DATA_ERROR);
-    }
-    if(exit_status==FINISHED) {
-        sprintf(errstr,"No data after amp for note %d, motif %d in notedatafile\n",noteno,motifno);
-        return(DATA_ERROR);
-    }
-    thisnote->amp = (float)val;
-    /* 1999 THIS NEEDS TESTING FOR MIDIRANGE EXCEPT IN TIMING SET CASE */
-    if(!(texflag & ISTIMED) || motifno!=1) {
-        if(val < MIDIMIN || val > MIDIMAX) {
-            sprintf(errstr,"amplitude value [%lf] out of range (%d to %d): motif %d: note %d\n",
-                    val,MIDIMIN,MIDIMAX,motifno,noteno);
-            return(DATA_ERROR);
-        }
-    }
-    p++;
-    q = p;
-    if((exit_status = get_data_item(q,&p,&val))<0) {
-        sprintf(errstr,"No duration data for note %d, motif %d in notedatafile\n",noteno,motifno);
-        return(DATA_ERROR);
-    }
-    thisnote->dur = (float)val;
-    if(texflag & IS_ORN_OR_MTF) {
-        if(texflag & IS_ORNATE) {
-            start = 2;
-        } else {
-            start = 1;
-            if(texflag & ISTIMED)
-                start++;
-        }
-        if(texflag & ISHARM)
-            start++;
-        if(motifno >= start) {
-            if(val <= FLTERR) {
-                sprintf(errstr,"Duration value [%lf] is too small: motif %d: note %d\n",val,motifno,noteno);
-                return(DATA_ERROR);
-            }
-        }
-    } else {
-        thisnote->dur = 1.0f;   /* default ; redundant */
-    }
-    return(FINISHED);
-}
-
-/***************************** GENERATE_TSET_TIMES **********************************
- *
- * Store time initially as SECONDS.
- *
- * (1)  Create location for a new note.
- * (2)  Go to that new note.
- * (3)  Store the current time at this note.
- * (4)  Find note-density at this time, and generate time of next event.
- * (5)  Return nextnote.
- */
-
-int generate_tset_times(double *thistime,noteptr *thisnote,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = make_new_note(thisnote))<0)
-        return(exit_status);                                            /* 1 */
-    (*thisnote)->ntime = (float)(*thistime);                        /* 3 */
-    if(dz->brksize[TEXTURE_PACK]) {
-        if((exit_status = read_value_from_brktable(*thistime,TEXTURE_PACK,dz))<0)
-            return(exit_status);
-    }
-    *thistime  += dz->param[TEXTURE_PACK];                  /* 4 */
-    return(FINISHED);                                                               /* 5 */
-}
-
-/********************** UN_LINK_NOTE ******************************
- *
- * Deletes empty address space at end of notelist.
- */
-
-int un_link_note(noteptr thisnote)
-{
-    if(thisnote->last==(noteptr)0) {
-        sprintf(errstr,"Problem in un_link_note()\n");
-        return(PROGRAM_ERROR);
-    }
-    thisnote = thisnote->last;
-    free(thisnote->next);
-    thisnote->next = (noteptr)0;
-    return(FINISHED);
-}
-
-/************************ NEW_MOTIF *****************************
- *
- * Set up next motif in a list of musical-motifs.
- * Set up location of first note of this motif.
- */
-
-int new_motif(motifptr *thismotif)
-{
-    int exit_status;
-    motifptr newmotif;
-    noteptr  thisnote;
-
-    if((newmotif = (motifptr)malloc(sizeof (struct motif)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY to store next motif.\n");
-        return(MEMORY_ERROR);
-    }
-    (*thismotif)->next = newmotif;
-    newmotif->last = *thismotif;
-    newmotif->next = (motifptr)0;
-    if((exit_status = init_note(&thisnote))<0)
-        return(exit_status);
-    thisnote->next = (noteptr)0;
-    thisnote->last = (noteptr)0;
-    newmotif->firstnote = thisnote;
-    *thismotif = newmotif;
-    return(FINISHED);
-}
-
-/********************** UNLINK_LAST_MOTIF ******************************
- *
- * Deletes empty address space at end of motiflist.
- */
-
-int unlink_last_motif(motifptr thismotif)
-{
-    if(thismotif->last==(motifptr)0) {
-        sprintf(errstr,"Problem in unlink_last_motif()\n");
-        return(PROGRAM_ERROR);
-    }
-    thismotif = thismotif->last;
-    free(thismotif->next);
-    thismotif->next = (motifptr)0;
-    return(FINISHED);
-}
-
-/**************************** SUBTRACT_ONE_FROM_BRKVALS ****************************/
-
-void subtract_one_from_brkvals(int paramno,dataptr dz)
-{
-    double *p = dz->brk[paramno] + 1;
-    double *pend = dz->brk[paramno] + (dz->brksize[paramno] * 2);
-    while(p < pend) {
-        *p -= 1.0;
-        p += 2;
-    }
-}
-
-/************************ BIGSCATTER *************************************
- *
- * (1)  The number of time-points to be randomly scattered as a group is
- *      scatcnt.
- * (1a) Base time is the time from which these new scattered times are offset.
- * (2)  Save the current position in note list as 'here'.
- * (3)  Go forward in note list until there are scatcnt notes inclusive
- *      between here and there, or until list runs out.
- * (3a) If the list runs out, modify scatcnt accordingly.
- * (4)  Note the (original) time of the last of these events. This will
- *      be returned as the new 'lasttime' for the next cycle of the
- *      program.
- * (5)  Make the time-step include the total duration of all these
- *      events.
- * (5a) Generate a set of times AT RANDOM within this large timestep,
-        sort them and store them.
-        * (6)  Replace existing times by scattered times, relative to basetime.
-        * (6a) Convert to MIDitime.
-        * (6b) Quantise if necessary.
-        * (7)  Replace the last time.
-        * (9)  Return the last note we worked on.
-        */
-
-int bigscatter(noteptr *thisnote,double thistime,double timestep,double scatter,double *lasttime,dataptr dz)
-{
-    int n, scatcnt = round(scatter);                /* 1 */
-    double *sct, *scti;
-    double basetime = thistime - timestep;  /* 1a */
-    noteptr here  = *thisnote;                              /* 2 */
-    noteptr there = *thisnote;                              /* 2 */
-    if((scti = (double *)malloc(scatcnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for scattering structure.\n");
-        return(MEMORY_ERROR);
-    }
-    sct = scti;
-    for(n=0;n < scatcnt-1; n++) {                   /* 3 */
-        if(there->next==(noteptr)0) {
-            scatcnt = n+1;                                  /* 3a */
-            break;
-        }
-        there = there->next;
-    }
-    *lasttime = there->ntime;                               /* 4 */
-    timestep += *lasttime - thistime;               /* 5 */
-    for(n= 0;n<scatcnt;n++)                                 /* 5a */
-        *sct++ = drand48() * timestep;
-    upsort(scti,scatcnt);
-    sct = scti;
-    while(here!=there) {                                    /* 6 */
-        thistime = basetime + (*sct++);
-        if(dz->param[TEXTURE_TGRID]>0.0)
-            thistime  = quantise(thistime,dz->param[TEXTURE_TGRID]);        /* 6b */
-        here->ntime = (float)thistime;
-        here = here->next;
-    }
-    thistime = basetime + *sct;                             /* 7 */
-    if(dz->param[TEXTURE_TGRID]>0.0)
-        thistime  = quantise(thistime,dz->param[TEXTURE_TGRID]);
-    there->ntime = (float)thistime;
-    free(scti);
-    *thisnote = there;
-    return(FINISHED);                                       /* 9 */
-}
-
-/************************** QUANTISE *************************************
- *
- * Quantise time point onto a grid.
- */
-
-double quantise(double thistime,double timegrid)
-{
-    int gridpoint;
-    timegrid *= MS_TO_SECS;
-    gridpoint = round(thistime/timegrid);
-    return((double)gridpoint * timegrid);
-}
-
-/************************* GET_DATA_ITEM ****************************/
-
-int get_data_item(char *q,char **p,double *val)
-{
-    int exit_status = CONTINUE;
-    if(*q==ENDOFSTR)
-        return(DATA_ERROR);
-    while(isspace(**p)) {
-        (*p)++;
-        if(**p == ENDOFSTR)
-            return(DATA_ERROR);
-    }
-    if(**p==TEXTURE_SEPARATOR)
-        return(DATA_ERROR);
-    while(!isspace(**p) && **p!=ENDOFSTR) {
-        (*p)++;
-    }
-    if(**p==ENDOFSTR)
-        exit_status = FINISHED;
-    **p = ENDOFSTR;
-    if(sscanf(q,"%lf",val)!=1)
-        return(DATA_ERROR);
-    return(exit_status);
-}
-
-/************************* INIT_NOTE ****************************
- *
- * Initialise notelist.
- */
-
-int init_note(noteptr *thisnote)
-{
-    if((*thisnote = (noteptr)malloc(sizeof(struct nnote)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for another note.\n");
-        return(MEMORY_ERROR);
-    }
-    (*thisnote)->next = (noteptr)0;
-    (*thisnote)->last = (noteptr)0;
-    return(FINISHED);
-}
-
-/********************** UPSORT *******************************
- *
- * Sort set of doubles into ascending order.
- */
-
-void upsort(double *scti,int scatcnt)
-{
-    double sct;
-    int n, m;
-    for(n=0;n<(scatcnt-1);n++) {
-        for(m=n+1;m<scatcnt;m++) {
-            if(*(scti+m)<*(scti+n)) {
-                sct       = *(scti+m);
-                *(scti+m) = *(scti+n);
-                *(scti+n) = sct;
-            }
-        }
-    }
-}
-
-/*********************** PUT_ZNOTE ********************************
- *
- * Put zero values in all parameters except time.
- */
-
-void put_znote(noteptr thisnote)
-{
-    thisnote->amp   = 0.0f;
-    thisnote->pitch  = 0.0f;
-    thisnote->dur   = 0.0f;
-    thisnote->instr = 0;
-    thisnote->spacepos = 0.0f;
-    thisnote->motioncentre = 0.0f;
-}
-
-/************************* ASSIGN_TIMESET_HFSET_MOTIFSETS ******************************
- *
- * Assign appropriate pointers to input motifs.
- *
- * (1)  If it's a timed texture, indicate first motif in list as that
- *              which defines the set of times (tset).
- *              Similarly, if texture is ornamented or decorated, point to first
- *              motif as that to BE ornamented or decorated (tset).
- * (2)  If the texture restricted to HF(s) or HS(s), indicate next motif
- *              as the HF-set (hfldmotif). It may be read in different ways (as HF, as
- *              HS, or as time-varying of either type) at a later time.
- * (3)  If texture consists of motifs, or is to use specific ornaments...
- * (4)  count the number of motifs remaining.
- * (5)  Set up the array of phrases to point to the appropriate motifs.
- */
-
-int assign_timeset_hfset_motifsets(dataptr dz)
-{
-    int exit_status;
-    unsigned int texflag = dz->tex->txflag;
-    motifptr here, thismotif = dz->tex->motifhead;
-    int n;
-    dz->tex->phrasecnt = 0;
-    if(texflag & ORN_DEC_OR_TIMED) {
-        if((exit_status = motifchek(thismotif))<0)
-            return(exit_status);
-        dz->tex->timeset = thismotif;                                   /* 1 */
-        thismotif = thismotif->next;
-    }
-    if(texflag & ISHARM) {                                                          /* 2 */
-        if((exit_status = motifchek(thismotif))<0)
-            return(exit_status);
-        dz->tex->hfldmotif = thismotif;
-        thismotif = thismotif->next;
-    }
-    if((texflag & IS_ORNATE) || (texflag & IS_MOTIFS)) {    /* 3 */
-        if((exit_status = motifchek(thismotif))<0)
-            return(exit_status);
-        here = thismotif;
-        while(thismotif!=(motifptr)0) {                                 /* 4 */
-            dz->tex->phrasecnt++;
-            thismotif = thismotif->next;
-        }                                                                                               /* 5 */
-        if((dz->tex->phrase = (motifptr *)malloc(dz->tex->phrasecnt * sizeof(motifptr)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for phrase array.\n");
-            return(MEMORY_ERROR);
-        }
-        thismotif = here;
-        n = -1;
-        while(thismotif!=(motifptr)0) {
-            dz->tex->phrase[++n] = thismotif;
-            thismotif = thismotif->next;
-        }
-    }
-    return(FINISHED);
-}
-
-/***************************** MASSAGE_PARAMS ****************************/
-
-int massage_params(dataptr dz)
-{
-    int exit_status;
-    unsigned int texflag = dz->tex->txflag;
-    convert_cmdline_instrnos_to_internal_representation(dz);
-    if((exit_status = check_max_transpos_compatible_with_splicelen(dz))<0)
-        return(exit_status);
-    if(texflag & IS_CLUMPED) {
-        if((exit_status = set_amptype_params(dz))<0)
-            return(exit_status);
-    }
-    if(texflag & IS_DECOR) {
-        if((exit_status = set_decor_pitchposition_params(dz))<0)
-            return(exit_status);
-    }
-    return(FINISHED);
-}
-
-/************************* INIT_MOTIFS *****************************
- *
- * Set up head item of a list of musical-motifs.
- * Set up location of first note of first motif.
- */
-
-int init_motifs(dataptr dz)
-{
-    int exit_status;
-    noteptr thisnote;
-    if((dz->tex->motifhead = (motifptr)malloc(sizeof (struct motif)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY to store any motifs.\n");
-        return(MEMORY_ERROR);
-    }
-    dz->tex->motifhead->next  = (motifptr)0;
-    dz->tex->motifhead->last  = (motifptr)0;
-    if((exit_status = init_note(&thisnote))<0)
-        return(exit_status);
-    dz->tex->motifhead->firstnote = thisnote;
-    thisnote->next = (noteptr)0;
-    thisnote->last = (noteptr)0;
-    return(FINISHED);
-}
-
-/******************************** INITPERM *********************************
- *
- * Establish storage space for permutation parameters.
- *
- * (1)  create pointers to the items within the permuted sets.          Initialise to zero.
- * (2)  Create storage for current length of each perm.                         Initialise to zero.
- * (3)  Create storage for previous length of each perm.                        Initialise to -1 (impossible).
- *              If new perm different length to old, space for permuted elements will need to be re-malloced.
- * (4)  Create pointers to storage areas for each permuted set.         Initialise to point nowhere.
- *              These will be malloced when the size of each set-to-permute is known.
- * (5)  Create storage for previous outputed val in each perm.          Initialise to -1 (impossible).
- *              This is useful at permutation boundaries, when a particular element may be repeated more
- *              than permitted no. of times if there's no check. These constants allow no. of repets to be counted.
- * (6)  Create counter of current no. of consecutive repets of an element in each of the (output) perms.
- *              Initialise to 0, though this is arbitrary, as repetcnt should always be set on any call of do_perm.
- * (7)  Create storage for max no. of allowed consecutive repets of an element in each perm-set.
- *              Initialise to 1, which is the default if no info is given to the contrary.
- */
-
-int initperm(int ***permm,dataptr dz)
-{
-    int n;
-    if((dz->iparray[TXPERMINDEX] = (int *)malloc(PERMCNT * sizeof(int)))==NULL) {   /* 1 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for permutation indeces.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n<PERMCNT;n++)
-        dz->iparray[TXPERMINDEX][n] = 0;
-
-    if((dz->iparray[TXPERMLEN] = (int *)malloc(PERMCNT * sizeof(int)))==NULL) {   /* 2 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for permutation lengths.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n<PERMCNT;n++)
-        dz->iparray[TXPERMLEN][n] = 0;
-
-    if((dz->iparray[TXLASTPERMLEN] = (int *)malloc(PERMCNT * sizeof(int)))==NULL) {   /* 3 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for last permutation lengths.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n<PERMCNT;n++)
-        dz->iparray[TXLASTPERMLEN][n] = -1;
-
-    if((*permm = (int **)malloc(PERMCNT * sizeof(int *)))==NULL) {   /* 4 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for permutations.\n");
-        return(MEMORY_ERROR);
-    }
-
-    for(n=0;n<PERMCNT;n++)
-        (*permm)[n] = (int *)0;
-
-    if((dz->iparray[TXLASTPERMVAL] = (int *)malloc(PERMCNT * sizeof(int)))==NULL) {   /* 5 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for last permutation values.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n<PERMCNT;n++)
-        dz->iparray[TXLASTPERMVAL][n] = -1;
-
-    if((dz->iparray[TXREPETCNT] = (int *)malloc(PERMCNT * sizeof(int)))==NULL) {   /* 6 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for permutation repetition counts.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n<PERMCNT;n++)
-        dz->iparray[TXREPETCNT][n] = 1;
-
-    if((dz->iparray[TXRPT] = (int *)malloc(PERMCNT * sizeof(int)))==NULL) {   /* 7 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for permutation repetitions.\n");
-        return(MEMORY_ERROR);
-    }
-    /* THESE ARE THE DEFAULT NUMBER OF REPETITIONS-OF-AN-ENTITY ALLOWED IN A PERM */
-    dz->iparray[TXRPT][PM_SPACE]  = SPACE_REPETS;
-    dz->iparray[TXRPT][PM_PITCH]  = PITCH_REPETS;
-    dz->iparray[TXRPT][PM_AMP]    = AMP_REPETS;
-    dz->iparray[TXRPT][PM_DUR]    = DUR_REPETS;
-    dz->iparray[TXRPT][PM_INSNO]  = INSNO_REPETS;
-    dz->iparray[TXRPT][PM_GPRANG] = GPRANG_REPETS;
-    dz->iparray[TXRPT][PM_GPSIZE] = GPSIZE_REPETS;
-    dz->iparray[TXRPT][PM_GPDENS] = GPDENS_REPETS;
-    dz->iparray[TXRPT][PM_GPCNTR] = GPCNTR_REPETS;
-    dz->iparray[TXRPT][PM_GPPICH] = GPPICH_REPETS;
-    dz->iparray[TXRPT][PM_ORNPOS] = ORNPOS_REPETS;
-    dz->iparray[TXRPT][PM_GPSPAC] = GPSPAC_REPETS;
-    dz->iparray[TXRPT][PM_ORIENT] = ORIENT_REPETS;
-    dz->iparray[TXRPT][PM_DECABV] = DECABV_REPETS;
-    dz->iparray[TXRPT][PM_MULT]   = MULT_REPETS;
-    dz->iparray[TXRPT][PM_WHICH]  = WHICH_REPETS;
-    dz->iparray[TXRPT][PM_GPPICH2]= GPPICH2_REPETS;
-    return(FINISHED);
-}

+ 0 - 223
dev/texture/prevsrc/prev-src/texture1.c

@@ -1,223 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
-
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-
-
-
-/* floatsam version: no changes */
-#include <stdio.h>
-#include <stdlib.h>
-#include <structures.h>
-#include <tkglobals.h>
-#include <globcon.h>
-#include <processno.h>
-#include <modeno.h>
-#include <arrays.h>
-#include <texture.h>
-#include <cdpmain.h>
-
-#include <sfsys.h>
-
-/********************* GETTING DATA VALUES VIA RAND PERMUTATIONS *************/
-
-
-
-static int  delete_all_other_motifs(motifptr thismotif,dataptr dz);
-static int  delete_motifs_before(motifptr thismotif,dataptr dz);
-static int  delete_motifs_beyond(motifptr thismotif);
-
-/***************************** TEXTURE 1 ********************************
- * (1)  Generating random permutations of sets of values, and delivering
- *              the next value from one of these.
- * (2)  Scattering values within a range.
- */
-
-/*************************** MAKE_TEXTURE *********************************/
-
-int make_texture(dataptr dz)
-{
-    int exit_status;
-    unsigned int texflag = dz->tex->txflag;
-    display_virtual_time(0,dz);
-    if(texflag & ISHARM) {
-        if(texflag & IS_CLUMPED) {
-            if((exit_status = do_clumped_hftexture(dz))<0)
-                return(exit_status);
-        } else {
-            if((exit_status = do_simple_hftexture(dz))<0)
-                return(exit_status);
-        }
-    } else {
-        if((exit_status = do_texture(dz))<0)
-            return(exit_status);
-    }
-    if((exit_status = delete_all_other_motifs(dz->tex->timeset,dz))<0)
-        return(exit_status);
-    return(FINISHED);
-}
-
-/****************************** GETVALUE **********************************
- *
- * Get value of a parameter, either from table, or fixed value.
- */
-
-int getvalue(int paramhi,int paramlo,double thistime,int z,double *val,dataptr dz)
-{
-    int exit_status;
-    double range;
-    int is_swap = 0;
-    if(dz->is_int[paramhi] || dz->is_int[paramlo]) {
-        sprintf(errstr,"getvalue() called on integer parameter %d or %d\n",paramhi,paramlo);
-        return(PROGRAM_ERROR);
-    }
-    if(dz->brk[paramhi]) {
-        if((exit_status = read_value_from_brktable(thistime,paramhi,dz))<0)
-            return(exit_status);
-    }
-    if(dz->brk[paramlo]) {
-        if((exit_status = read_value_from_brktable(thistime,paramlo,dz))<0)
-            return(exit_status);
-    }
-    if((range = dz->param[paramhi] - dz->param[paramlo])<0.0) {
-        swap(&dz->param[paramhi],&dz->param[paramlo]);
-        range = -range;
-        is_swap = 1;
-    }
-    if(flteq(range,0.0)) {
-        *val = dz->param[paramhi];
-        if(is_swap)
-            swap(&dz->param[paramhi],&dz->param[paramlo]);
-        return(FINISHED);
-    }
-    if((exit_status = pscatx(range,dz->param[paramlo],z,val,dz))<0)
-        return(exit_status);
-    if(is_swap)
-        swap(&dz->param[paramhi],&dz->param[paramlo]);
-    return(FINISHED);
-}
-
-/****************************** IGETVALUE **********************************
- *
- * Get integer value of a parameter, either from table, or fixed value.
- */
-
-int igetvalue(int paramhi,int paramlo,double thistime,int z,int *ival,dataptr dz)
-{
-    int   exit_status;
-    int  irange;
-    int   a, is_swap = 0;
-
-    if(!dz->is_int[paramhi] || !dz->is_int[paramlo]) {
-        sprintf(errstr,"igetvalue() called on non-integer parameter %d or %d\n",paramhi,paramlo);
-        return(PROGRAM_ERROR);
-    }
-    if(dz->brk[paramhi]) {
-        if((exit_status = read_value_from_brktable(thistime,paramhi,dz))<0)
-            return(exit_status);
-    }
-    if(dz->brk[paramlo]) {
-        if((exit_status = read_value_from_brktable(thistime,paramlo,dz))<0)
-            return(exit_status);
-    }
-
-    if((irange = dz->iparam[paramhi] - dz->iparam[paramlo])<0) {
-        iiswap(&dz->iparam[paramhi],&dz->iparam[paramlo]);
-        irange = -irange;
-        is_swap = 1;
-    }
-    if(irange==0) {
-        *ival = (int)dz->iparam[paramlo];
-        if(is_swap)
-            iiswap(&dz->iparam[paramhi],&dz->iparam[paramlo]);
-        return(FINISHED);
-        /* OCT 1997 replace ****
-           } else if((exit_status = doperm(irange,z,&a,dz))<0)
-        */
-        /* BY */
-    } else if((exit_status = doperm(irange+1,z,&a,dz))<0)
-        /* because the range of an integer variable between(say) 3 & 7 is INCLUSIVELY 5, not 7-3) */
-        return(exit_status);
-    a = (int)(a + dz->iparam[paramlo]);
-    *ival = a;
-    if(is_swap)
-        iiswap(&dz->iparam[paramhi],&dz->iparam[paramlo]);
-    return(FINISHED);
-}
-
-/*************************** DELETE_ALL_OTHER_MOTIFS **********************************
- *
- * Deletes all other motifs in motif list.
- */
-
-int delete_all_other_motifs(motifptr thismotif,dataptr dz)
-{
-    int exit_status;
-    motifptr here = thismotif->next;
-    if((exit_status = delete_motifs_before(thismotif,dz))<0)
-        return(exit_status);
-    if(here!=(motifptr)0) {
-        if((exit_status = delete_motifs_beyond(here))<0)
-            return(exit_status);
-    }
-    dz->tex->motifhead = thismotif;
-    return(exit_status);
-}
-
-/********************** DELETE_MOTIFS_BEYOND ******************************
- *
- * Deletes motif-space from this space onwards.
- */
-
-int delete_motifs_beyond(motifptr thismotif)
-{
-    motifptr start = thismotif;
-    while(thismotif->next!=(motifptr)0)
-        thismotif = thismotif->next;
-    while(thismotif!=start) {
-        thismotif = thismotif->last;
-        free(thismotif->next);
-    }
-    thismotif->next = (motifptr)0;
-    return(FINISHED);
-}
-
-/*********************** DELETE_MOTIFS_BEFORE ***************************
- *
- * Kill all motifs BEFORE this one in the motif list.
- */
-
-int delete_motifs_before(motifptr thismotif,dataptr dz)
-{
-    motifptr here = dz->tex->motifhead;
-    while(here!=thismotif) {
-        if((here = here->next)==(motifptr)0) {
-            sprintf(errstr,"Problem in delete_motifs_before()\n");
-            return(PROGRAM_ERROR);
-        }
-        delete_notes_here_and_beyond(here->last->firstnote);
-        free(here->last);
-        here->last = (motifptr)0;
-    }
-    dz->tex->motifhead = thismotif;
-    return(FINISHED);
-}

+ 0 - 520
dev/texture/prevsrc/prev-src/texture2.c

@@ -1,520 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
-
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-
-
-
-/* floatsam version: no changes */
-#include <stdio.h>
-#include <stdlib.h>
-#include <structures.h>
-#include <tkglobals.h>
-#include <globcon.h>
-#include <processno.h>
-#include <modeno.h>
-#include <arrays.h>
-#include <texture.h>
-#include <cdpmain.h>
-#include <sfsys.h>
-#include <osbind.h>
-
-/***************************** GENERATING TEXTURES WITH NO HFIELD(S) ******************************/
-
-static int  setup_motif_params
-(noteptr phrasenote,double tsettime,double *thisamp,double ampstep,double *phraseamp,
- int phrno,double rangemult,noteptr thisnote,noteptr tsetnote,
- double multiplier,double timeadjust,dataptr dz);
-static void gen_orn_pitch(noteptr thisnote,noteptr tsetnote,noteptr phrasenote,
-                          float phrlpitch,float phrfirstpitch,dataptr dz);
-static void gen_mtf_pitch(noteptr thisnote,noteptr tsetnote,noteptr phrasenote,float phrfirstpitch);
-static int  dec_centre(double tsetpitch,float *val,int gpsize,double gprlow,double gprange,dataptr dz);
-static int  pscat(double range,double bottom,int pindex,double *val,dataptr dz);
-static int  initialise_phrases
-(int **phrnotecnt,double **phraseamp,double **phrange,noteptr **phrlastnote,dataptr dz);
-static int  do_ev_pch
-(double *thispitch,double thistime,double *pptop,double *ppbot,dataptr dz);
-static int  get_gpparams
-(double thistime,double thispitch,unsigned char dectypecnt,double *gprange,double *gprlow,int *gpsize,
- double *gpdense,double pptop,double ppbot,unsigned char dectypestor,int mingrpsize,dataptr dz);
-static int orientrange
-(double thispitch,double pptop, double ppbot,double *gprange, double *gprlow,
- unsigned char dectypestor,unsigned char dectypecnt,dataptr dz);
-static void squeezrange(double thispitch,double *gprange,double *gprlow, double pptop, double ppbot);
-
-/**************************** DO_TEXTURE *****************************/
-
-int do_texture(dataptr dz)
-{
-    int exit_status;
-    noteptr tsetnote = dz->tex->timeset->firstnote;
-    unsigned int texflag     = dz->tex->txflag;
-    unsigned char dectypestor = dz->tex->dectypstor;
-    unsigned char dectypecnt  = dz->tex->dectypcnt;
-    unsigned char amptypestor = dz->tex->amptypstor;
-    unsigned char amptypecnt  = dz->tex->amptypcnt;
-    int ampdirected           = dz->tex->ampdirectd;
-    motifptr tset                     = dz->tex->timeset;
-    motifptr *phrase                  = dz->tex->phrase;
-    int phrcount                      = dz->tex->phrasecnt;
-    int *phrnotecnt=NULL;
-    double *phraseamp=NULL, *phrange=NULL;
-    noteptr thisnote=NULL, nextnote=NULL, phrasenote=NULL, nextevent=NULL, *phrlastnote=NULL, *shadow=NULL;
-    float phrlpitch=0.0, phrfirstpitch=0.0;
-    unsigned char thisinstr, amptype=0;
-    double  tsettime=0.0, thistime=0.0, thispitch=0.0, ampstep=0.0, thepitch=0.0, thisamp=0.0, thisdur=0.0;
-    double  rangemult=0.0, gpdense=0.0, gprange=0.0, gprlow=0.0, multiplier=0.0;
-    double timeadjust = 0.0; /* default */
-    int phrno=0, n=0, shadowsize=0, gpsize=0, mingrpsize = 0;
-    double pptop=0.0, ppbot=0.0;
-    int shadindex = 0;
-
-    dz->iparam[SPINIT] = 0;
-    if(texflag & IS_CLUMPED) {
-        if((dz->tex->phrasecnt > 0)
-           && (exit_status = initialise_phrases(&phrnotecnt,&phraseamp,&phrange,&phrlastnote,dz))<0)
-            return(exit_status);
-
-        if(texflag & IS_GROUPS)
-            mingrpsize = 1;
-
-        if((exit_status= make_shadow(tset,&shadowsize,&shadow))<0)
-            return(exit_status);
-
-        if(texflag & IS_DECOR) {
-            setup_decor(&pptop,&ppbot,&shadindex,&tsetnote,dz);
-        } else if(texflag & IS_MOTIFS)  {
-            if((exit_status = set_motifs(phrcount,phrase,phrnotecnt,phraseamp,phrange,phrlastnote))<0)
-                return(exit_status);
-        } else if(texflag & IS_ORNATE) {
-            if((exit_status = set_motifs(phrcount,phrase,phrnotecnt,phraseamp,phrange,phrlastnote))<0)
-                return(exit_status);
-            if(dz->vflag[WHICH_CHORDNOTE]==DECOR_HIGHEST)
-                tsetnote = gethipitch(tsetnote,&shadindex);
-        }
-    }
-
-    while(tsetnote!=(noteptr)0) {
-        tsettime  = (double)tsetnote->ntime;
-        thistime  = tsettime;
-        if((exit_status = read_values_from_all_existing_brktables(thistime,dz))<0)
-            return(exit_status);
-        if(texflag & IS_DECOR)
-            thispitch = tsetnote->pitch;
-        if(texflag & IS_ORN_OR_MTF) {
-            if((exit_status =
-                setup_motif_or_ornament(thistime,&multiplier,&phrno,&phrasenote,phrase,dz))<0)
-                return(exit_status);
-        }
-        if(!(texflag & IS_ORN_OR_DEC)) {
-            if((exit_status = do_ev_pch(&thispitch,thistime,&pptop,&ppbot,dz))<0)
-                return(exit_status);
-            tsetnote->pitch = (float)thispitch;
-        }
-        if((exit_status = do_amp_instr_dur(&thisamp,&thisinstr,&thisdur,tsetnote,thistime,dz))<0)
-            return(exit_status);
-        if(texflag & IS_CLUMPED) {
-            if(texflag & IS_MOTIFS) {
-                if((exit_status = getmtfdur(tsetnote,phrasenote,&thisdur,multiplier,dz))<0)
-                    return(exit_status);
-                tsetnote->dur = (float)thisdur;
-            }
-            if(texflag & IS_ORN_OR_MTF) {
-                gpsize = phrnotecnt[phrno];
-                phrfirstpitch = phrasenote->pitch;
-            } else {
-                if((exit_status = get_gpparams(thistime,thispitch,dectypecnt,
-                                               &gprange,&gprlow,&gpsize,&gpdense,pptop,ppbot,dectypestor,mingrpsize,dz))<0)
-                    return(exit_status);
-            }
-            if(texflag & IS_DECOR) {
-                if((exit_status = position_and_size_decoration(&thistime,tsettime,gpdense,&gpsize,dz))<0)
-                    return(exit_status);
-            } else
-                gpsize--;
-            if(texflag & IS_ORNATE) {
-                phrlpitch = (phrlastnote[phrno])->pitch;
-                if((exit_status = setup_ornament
-                    (&timeadjust,&thistime,&gpsize,phrlastnote,multiplier,&phrasenote,phrno,dz))<0)
-                    return(exit_status);
-            }
-            if(!(texflag & IS_DECOR))
-                nextnote = tsetnote->next;
-            if(gpsize>0) {                                          /* 3b */
-                if(texflag & IS_ORN_OR_MTF) {
-                    if((exit_status = orn_or_mtf_amp_setup
-                        (ampdirected,phrange,phrno,thisamp,gpsize,&rangemult,&ampstep,&amptype,amptypestor,amptypecnt,dz))<0)
-                        return(exit_status);
-                }
-                if(texflag & IS_MOTIFS) {
-                    if((exit_status = set_motif_amp
-                        (tsetnote,&thisamp,gpsize,ampstep,phrasenote,rangemult,phraseamp,phrno,amptype))<0)
-                        return(exit_status);
-                } else if(texflag & IS_ORNATE) {
-                    if((exit_status = set_ornament_amp
-                        (phraseamp,phrlastnote,&thisamp,phrasenote,phrno,tsetnote,ampstep,rangemult,gpsize,dz))<0)
-                        return(exit_status);
-                } else if(texflag & IS_GROUPS) {
-                    if((exit_status = set_group_amp
-                        (tsetnote,&thisamp,&amptype,&ampstep,gpsize,amptypecnt,amptypestor,dz))<0)
-                        return(exit_status);
-                } else if(texflag & IS_DECOR) {
-                    if((exit_status = set_decor_amp
-                        (ampdirected,&thisamp,&ampstep,gpsize,&amptype,amptypecnt,amptypestor,dz))<0)
-                        return(exit_status);
-                }
-                if(dz->iparam[TEX_GPSPACE]!=IS_STILL) {
-                    if((exit_status = init_group_spatialisation(tsetnote,shadindex,shadow,shadowsize,dz))<0)
-                        return(exit_status);
-                }
-                thisnote  = tsetnote;
-                if(texflag & IS_DECOR)
-                    nextnote = tsetnote->next;
-                else if(texflag & IS_ORNATE) {
-                    if(!dz->vflag[IS_PRE])
-                        phrasenote = phrasenote->next;
-                }
-                if(texflag & IS_ORN_OR_DEC)
-                    nextevent = getnextevent_to_decorate(tsetnote,&shadindex,dz);
-                for(n=0;n<gpsize;n++) {
-                    if((exit_status = make_new_note(&thisnote))<0)
-                        return(exit_status);
-                    if(texflag & IS_DEC_OR_GRP) {
-                        if((exit_status = set_group_params
-                            (tsetnote,thisnote,gpdense,ampstep,&thisamp,&thistime,thisdur,dz))<0)
-                            return(exit_status);
-                        if((exit_status = do_grp_ins(tsetnote->instr,&(thisnote->instr),dz))<0)
-                            return(exit_status);
-                        thisnote->motioncentre = tsetnote->motioncentre;
-                        if(texflag & IS_DECOR) {
-                            if((exit_status = dec_centre
-                                (thispitch,&(thisnote->pitch),gpsize,gprlow,gprange,dz))<0)
-                                return(exit_status);
-                        } else {
-                            if((exit_status = pscat(gprange,gprlow,PM_GPPICH,&thepitch,dz))<0)
-                                return(exit_status);
-                            thisnote->pitch = (float)thepitch;
-                        }
-                        thisnote->ntime  = (float)thistime;
-                    } else {
-                        if((exit_status = check_next_phrasenote_exists(&phrasenote,texflag,dz))<0)
-                            return(exit_status);
-                        if((exit_status = setup_motif_params(phrasenote,thistime,&thisamp,ampstep,phraseamp,phrno,
-                                                             rangemult,thisnote,tsetnote,multiplier,timeadjust,dz))<0)
-                            return(exit_status);
-                        if(texflag & IS_MOTIFS) {
-                            gen_mtf_pitch(thisnote,tsetnote,phrasenote,phrfirstpitch);
-                        } else {
-                            gen_orn_pitch(thisnote,tsetnote,phrasenote,phrlpitch,phrfirstpitch,dz);
-                            phrasenote = phrasenote->next;
-                        }
-                    }
-                    if((exit_status = setspace(tsetnote,thisnote,gpsize,dz))<0)
-                        return(exit_status);
-                }
-                thisnote->next = nextnote;
-                if(nextnote!=(noteptr)0)
-                    nextnote->last = thisnote;
-                if(texflag & IS_ORN_OR_DEC)
-                    tsetnote = nextevent;
-
-            } else if(texflag & IS_ORN_OR_DEC)
-                tsetnote = getnextevent_to_decorate(tsetnote,&shadindex,dz);
-
-        } else
-            tsetnote = tsetnote->next;
-
-        if(texflag & IS_MTF_OR_GRP) {
-            tsetnote = nextnote;
-            shadindex++;
-        }
-    }
-    if((texflag & IS_DECOR) && dz->vflag[DISCARD_ORIGLINE]) {
-        if((exit_status = erase_shadow(shadowsize,shadow,tset))<0)
-            return(exit_status);
-    }
-    if(texflag & IS_CLUMPED)
-        return arrange_notes_in_timeorder(tset);
-    return(FINISHED);
-}
-
-/**************************** SETUP_MOTIF_PARAMS ****************************/
-
-int setup_motif_params
-(noteptr phrasenote,double tsettime,double *thisamp,double ampstep,double *phraseamp, int phrno,
- double rangemult,noteptr thisnote,noteptr tsetnote,double multiplier,double timeadjust,dataptr dz)
-{
-    double notetime, ampdif;
-    notetime = getnotetime(phrasenote,tsettime,multiplier,timeadjust,dz);
-    *thisamp  += ampstep;
-    ampdif    =(phraseamp[phrno] - phrasenote->amp)*rangemult;/* e */
-    return do_mtf_params(thisnote,*thisamp,phrasenote,tsetnote,ampdif,notetime,multiplier,dz);
-}
-
-/**************************** GEN_ORN_PITCH ****************************/
-
-void gen_orn_pitch
-(noteptr thisnote,noteptr tsetnote,noteptr phrasenote,float phrlpitch,float phrfirstpitch,dataptr dz)
-{
-    if(dz->vflag[IS_PRE])
-        thisnote->pitch = (float)(tsetnote->pitch + phrasenote->pitch - phrlpitch);
-    else
-        thisnote->pitch = (float)(tsetnote->pitch + phrasenote->pitch - phrfirstpitch);
-}
-
-/**************************** GEN_MTF_PITCH ****************************/
-
-void gen_mtf_pitch(noteptr thisnote,noteptr tsetnote,noteptr phrasenote,float phrfirstpitch)
-{
-    thisnote->pitch = (float)(tsetnote->pitch + phrasenote->pitch - phrfirstpitch);
-    thisnote->pitch = (float)octadjust((double)thisnote->pitch);
-}
-
-/************************* DEC_CENTRE ******************************
- *
- * Centre a decoration on the decorated pitch.
- *
- * (1)  For groupsize 1 or 2, k=1
- *              For groupsize 3 or 4, k=2
- *              For groupsize 5 or 6, k=3 etc
- * (2)  Scatter pitches as normally.
- * (3)  If range is NOT one-sided, proceed..otherwise return in normal way.
- * (4)  Find ratio of upper half of range to lower.
- * (5)  Find distance from decorated note.
- * (6)  Save the current value of allowed repetitions.
- *              THese are number of times a note occurs above the decorated pitch,
- *              before it can do so again (same for below).
- * (7)  If the allowed repetitions are bigger than k, replace it by k.
- *              This means that if we allow 3 repetitions but there are only
- *              1,2,3 or 4 notes, we force, 1 repetition for 2 notes, 2 repetitions
- *              for 3 or 4 notes etc. but allow 3 repetitions for 5,6 etc notes.
- * (8)  Select above or below decorated pitch.
- * (9)  If meant to be above note, but is below it, put note in other
- *              half of range, with appropriate adjustment for relative sizes
- *              of half-ranges.
- * (10) If meant to be below note, but is above it, put note in other
- *              half of range, with appropriate adjustment for relative sizes
- *              of half-ranges.
- * (11) Restore the repetcnt value!!
- */
-
-int dec_centre(double tsetpitch,float *val,int gpsize,double gprlow,double gprange,dataptr dz)
-{
-    int exit_status;
-    double a, q, w, gprhi = gprlow + gprange, ulratio;
-    int s, save, k = (gpsize+1)/2;                                                          /* 1 */
-    if((exit_status = pscat(gprange,gprlow,PM_GPPICH,&a,dz))<0) /* 2 */
-        return(exit_status);
-    if((w=tsetpitch-gprlow)>FLTERR && !flteq(tsetpitch,gprhi)) {/* 3 */
-        ulratio = (gprhi-tsetpitch)/w;                                                  /* 4 */
-        q       = a-tsetpitch;                                                                  /* 5 */
-        save    = dz->iparray[TXREPETCNT][PM_DECABV];                   /* 6 */
-        if(dz->iparray[TXREPETCNT][PM_DECABV]>k)                                /* 7 */
-            dz->iparray[TXREPETCNT][PM_DECABV] = k;
-        if((exit_status = doperm((int)2,PM_DECABV,&s,dz))<0)                    /* 8 */
-            return(exit_status);
-        if(s && q<0.0)                                                                                  /* 9 */
-            a = tsetpitch - (q*ulratio);
-        if(!s && q>0.0)                                                                                 /* 10 */
-            a = tsetpitch - (q/ulratio);
-        dz->iparray[TXREPETCNT][PM_DECABV] = save;                              /* 11 */
-        if(a<MIDIBOT || a>MIDITOP) {
-            sprintf(errstr,"TEXTURE: Problem in dec_centre()\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    *val = (float)a;
-    return(FINISHED);
-}
-
-/***************************** PSCAT ************************************
- *
- * A weighted version of pscatx().
- *
- * Select a random value within 'range', by permuting one of BANDCNT UNequal
- * ranges, and selecting a random value within the chosen range. The upper
- * and lower band are half as wide as the inner 3 bands, ensuring that
- * values within these outer bands are squeezed into a narrow-range-of-values
- * near the boundaries of the total range.
- */
-
-int pscat(double range,double bottom,int pindex,double *val,dataptr dz)
-{
-    int exit_status;
-    double bandbottom, bandwidth, x;
-    int k;
-    if((exit_status = doperm((int)BANDCNT,pindex,&k,dz))<0)
-        return(exit_status);
-    bandwidth = range/(double)LAYERCNT;
-    switch(k) {
-    case(0):
-        bandbottom = 0.0;
-        break;
-    case(BANDCNT-1):
-        bandbottom = (LAYERCNT-1) * bandwidth;
-        break;
-    default:
-        bandbottom = bandwidth + ((double)((k-1) * 2) * bandwidth);
-        bandwidth *= 2.0;
-        break;
-    }
-    x  = (drand48() * bandwidth);
-    x += bandbottom;
-    *val = x + bottom;
-    return(FINISHED);
-}
-
-/**************************** INITIALISE_PHRASES *******************************/
-
-int initialise_phrases(int **phrnotecnt,double **phraseamp,double **phrange,noteptr **phrlastnote,dataptr dz)
-{
-    if((*phrnotecnt = (int *)malloc(dz->tex->phrasecnt * sizeof(int)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for phrase notecnt array.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*phraseamp = (double *)malloc(dz->tex->phrasecnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for phrase amplitude array.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*phrange = (double *)malloc(dz->tex->phrasecnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for phrase range array.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*phrlastnote = (noteptr *)malloc(dz->tex->phrasecnt * sizeof(noteptr)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for phrase lastnote array.\n");
-        return(MEMORY_ERROR);
-    }
-    return(FINISHED);
-}
-
-/********************** DO_EV_PCH *******************************
- *
- * Set pitch of event (not group etc.).
- */
-
-int do_ev_pch
-(double *thispitch,double thistime,double *pptop,double *ppbot,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getvalue(TEXTURE_MAXPICH,TEXTURE_MINPICH,thistime,PM_PITCH,thispitch,dz))<0)
-        return(exit_status);
-    if(*thispitch > MIDITOP || *thispitch < MIDIBOT) {
-        sprintf(errstr,"TEXTURE: pitch [%.1f] out of midirange at time %.2f\n",*thispitch,thistime);
-        return(DATA_ERROR);
-    }
-    *pptop = dz->param[TEXTURE_MAXPICH];
-    *ppbot = dz->param[TEXTURE_MINPICH];
-    return(FINISHED);
-}
-
-/************************** GET_GPPARMAS **************************
- *
- * Get the parameters for a group of notes.
- *
- * (1)  Get gprange in normal way.
- * (2)  Don't adjust range.
- * (3)  For decorations, the range may be oriented, above, below
- *              or centred on the initial note. So range is adjusted here.
- */
-
-int get_gpparams(double thistime,double thispitch,unsigned char dectypecnt,
-                 double *gprange,double *gprlow,int *gpsize,double *gpdense,double pptop,double ppbot,
-                 unsigned char dectypestor,int mingrpsize,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getvalue(TEX_GPRANGHI,TEX_GPRANGLO,thistime,PM_GPRANG,gprange,dz))<0)
-        return(exit_status);                                                                                            /* 1 */
-    if(!dectypecnt)
-        squeezrange(thispitch,gprange,gprlow,pptop,ppbot);
-    else {
-        if((exit_status = orientrange
-            (thispitch,pptop,ppbot,gprange,gprlow,dectypestor,dectypecnt,dz))<0)/* 3 */
-            return(exit_status);
-    }
-    if((exit_status = igetvalue(TEX_GPSIZEHI,TEX_GPSIZELO,thistime,PM_GPSIZE,gpsize,dz))<0)
-        return(PROGRAM_ERROR);
-
-    if(*gpsize < mingrpsize) {
-        sprintf(errstr,"Impossible GROUP SIZE value [%d]\n",*gpsize);
-        return(PROGRAM_ERROR);
-    }
-    return get_density_val(thistime,gpdense,dz);
-}
-
-/***************************  ORIENTRANGE ******************************
- *
- */
-
-int orientrange
-(double thispitch,double pptop, double ppbot,double *gprange, double *gprlow,
- unsigned char dectypestor,unsigned char dectypecnt,dataptr dz)
-{
-    int exit_status;
-    unsigned char dectype;
-    double top;
-    int k;
-    if((exit_status = doperm((int)dectypecnt,PM_ORIENT,&k,dz))<0)
-        return(exit_status);
-    if((exit_status = gettritype(k,dectypestor,&dectype))<0)
-        return(exit_status);
-    switch(dectype) {
-    case(0):                        /* centred range */
-        squeezrange(thispitch,gprange,gprlow,pptop,ppbot);
-        dz->vflag[DECCENTRE] = TRUE;
-        break;
-    case(1):                        /* range above note */
-        top      = min((thispitch + *gprange),pptop);
-        *gprlow  = max((top - *gprange),ppbot);
-        *gprange = top - *gprlow;
-        dz->vflag[DECCENTRE] = FALSE;
-        break;
-    case(2):                        /* range below note */
-        top      = thispitch;
-        *gprlow  = max((top - *gprange),ppbot);
-        *gprange = top - *gprlow;
-        dz->vflag[DECCENTRE] = FALSE;
-        break;
-    default:
-        sprintf(errstr,"TEXTURE: Problem in orientrange()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/***************************  SQUEEZRANGE ******************************
- *
- * Adjust range to lie within texture limits.
- *
- * (2)  Top of range is at current pitch plus half range. If this is
- *      above current top-of-texture range (pptop) move top down.
- * (3)  Bottom of range is gprange below top. If this is below
- *      bottom-of-texture range (ppbot), move gprangelo up.
- * (4)  Recalculate the true gprange within true limits.
- */
-
-void squeezrange(double thispitch,double *gprange,double *gprlow, double pptop, double ppbot)
-{
-    double top;
-    top     = min((thispitch + (*gprange/2.0)),pptop);              /* 2 */
-    *gprlow  = max((top-*gprange),ppbot);                                   /* 3 */
-    *gprange = top - *gprlow;                                                               /* 4 */
-}

+ 0 - 2362
dev/texture/prevsrc/prev-src/texture3.c

@@ -1,2362 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
-
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-
-
-
-/* floatsam version: no changes */
-#include <stdio.h>
-#include <stdlib.h>
-#include <float.h>
-#include <structures.h>
-#include <tkglobals.h>
-#include <globcon.h>
-#include <processno.h>
-#include <modeno.h>
-#include <arrays.h>
-#include <texture.h>
-#include <cdpmain.h>
-
-#include <sfsys.h>
-#include <osbind.h>
-
-#if defined unix || defined __GNUC__
-#define round(x) lround((x))
-#endif
-
-#define CHARBITSIZE (8)         /* number of bits in a char                  */
-
-struct ffit {                           /* Structure for FIT of motif to HS  */
-    float transpose;
-    float fit;
-    struct ffit *next;
-    struct ffit *last;
-};
-
-typedef struct ffit *fitptr;
-
-/***************************** GENERATING TEXTURES WITH HFIELD(S) ******************************/
-/* RWD Feb 2014: now in sfsys,h, differently! */
-#ifdef MAXINT
-# undef MAXINT
-#endif
-#define MAXINT (2147483647)
-
-static int set_hfmotifs(double *hs,motifptr *phrase,int *phrnotecnt,double *phraseamp,
-                        double *phrange, noteptr *phrlastnote,int *endhsindex,int **hfphrase,
-                        int hsnotecnt,fitptr fithead,double **notestor,dataptr dz);
-static int gethfphrase
-(double *hs,double **notestor,int z,double lopitch,double hipitch,int **hfphrase,
- int hsnotecnt,int *phrnotecnt,motifptr *phrase,fitptr fithead);
-static int shrink_to_hs
-(int z,int hsnotecnt,double hipitch,double lopitch,double hstop,double hsbot,
- double *hs, int *hfphrase,motifptr *phrase,int *phrnotecnt);
-static int findhfphrase
-(int z,double *hs,double hstop,int hsnotecnt,double lopitch,
- double origlo,motifptr *phrase,int **hfphrase,int *phrnotecnt,fitptr fithead,double **notestor);
-static int getmtfindeces
-(double transpose,int z,int hsnotecnt,double *hs,motifptr *phrase,int *phrnotecnt,int **hfphrase);
-static int get_fit(double *notestor,fitptr thisfit,double lopitch,double origlo,int z,
-                   int hsnotecnt,int *phrnotecnt,double *hs,fitptr *newfit);
-static int put_fit(fitptr thisfit,double transval,double fitval,fitptr *newfit);
-static int best_fit(fitptr fithead,double *transpose);
-static void free_fitlist(fitptr fithead);
-static double hfadjust(double thispitch,double *hs,int x1,int x2,int texflag,int hsnotecnt);
-static int convert_pitch_to_nearest_hset_pitch(double thispitch,double *hs,int hsnotecnt);
-static int hfadj2(int hsi,int hfnotecnt,int hsnotecnt);
-static int setup_hfield(noteptr thisnote,double **hs,int *hsnotecnt,double **hf,int *hfnotecnt,int texflag);
-static int get_next_hfield
-(double **hf,double **hs,double inputtime,int *hf_cnt,int *hs_cnt,int *hfnotecnt,
- noteptr *thishfnote,double *thishftime,double *nexthftime,int hfdatacnt,int *hsnotecnt,
- noteptr *thishsnote,double *thishstime,double *nexthstime,double *hft,int texflag);
-static int setup_motif_note
-(double thisamp,int thisinstr,double thisdur,noteptr tsetnote,noteptr phrasenote,
- double *thispitch,double thistime,int *hsindex,int hsnotecnt,double *hs,
- double *pptop,double *ppbot,int *shadindex,char *shadbits,double multiplier,dataptr dz);
-static int setup_group_note
-(double thisamp,int thisinstr,double thisdur,noteptr tsetnote,
- double *thispitch,double thistime,int *hsindex,int hsnotecnt,double *hs,
- double *pptop,double *ppbot,int *shadindex,char *shadbits,dataptr dz);
-static int setup_ornamentation
-(int *starthsi,int *endhsi,noteptr *nextevent,noteptr tsetnote,noteptr *phrasenote,
- int *shadindex, int *endhsindex,int *hfphrase,int phrno,dataptr dz);
-static int generate_motifin_note_pitch
-(int n,int hsindex,int starthsindex,int hsnotecnt,double thispitch,
- int *hfphrase,noteptr *thisnote,double *hs,int texflag);
-static int generate_motif_note_pitch
-(noteptr tsetnote,noteptr phrasenote,double phrfirstnote,noteptr thisnote);
-static int generate_ornament_note_pitch
-(int n,double *hs, int hsi, int endhsi,int starthsi,noteptr *thisnote,noteptr *phrasenote,
- int *hfphrase,int hfnotecnt,int hsnotecnt,dataptr dz);
-static int do_ev_hfpch
-(double thistime,int *hsindex,double *val,
- int hsnotecnt,double *hs,double *pptop,double *ppbot,dataptr dz);
-static int getp_as_index
-(double thistime,int *val,int hsnotecnt,double *hs,double *pptop,double *ppbot,dataptr dz);
-static int init_shadbits(int shadowsize,int *shshsize,char **shadbits);
-static int geths(noteptr thisnote,double **hs,int *hsnotecnt);
-static int gethf(noteptr thisnote,double **hf,int *hfnotecnt);
-static int gen_hs(double **hf,double **hs, int *hsnotecnt, int hfnotecnt);
-static int chekrepeat(noteptr thisnote,double lastpitch);
-static void set_shadbit(int k,char *shadbits);
-static int      geths_lobnd(double thispitch,double *hs,int hsnotecnt);
-static int      gethfnote(double thispitch,double *hf,int *hfnotecnt);
-static int      setmtfparams
-(noteptr thisnote,double thisamp,noteptr phrasenote,noteptr tsetnote,double ampdif,
- double notetime,int gpsize,double multiplier,dataptr dz);
-static int      initialise_hfphrases
-(int ***hfphrase,int **endhsindex,int **phrnotecnt,double **phraseamp,double **phrange,
- noteptr **phrlastnote,dataptr dz);
-static int      readhftimes(noteptr firstnote, int *hfdatacnt,double **hft);
-static int      init_fits(fitptr *thisfit);
-static int      get_hfgpparams(double thistime,double thispitch,double *hs,int hsnotecnt,
-                               int *gpsize,int *hfrange,int *hfgpranglo,int *hfgpranghi,
-                               double *gprange,double *gpdense,int mingrpsize,
-                               double *gprlow, int dectypecnt,unsigned char dectypestor,dataptr dz);
-static int      generate_group_note(noteptr thisnote,noteptr testnote,double thistime,
-                                    int hfrange,int hfgpranglo,double *hs,int *hsindex,int gpsize,dataptr dz);
-static int      generate_decor_note(noteptr thisnote,noteptr tsetnote,
-                                    double thispitch,double thistime,int hfrange,int hfgpranghi,int hfgpranglo,
-                                    double *hs,int *hsindex,int hsnotecnt,double gprlow,double gprange,int gpsize,dataptr dz);
-static void del_ghosts(int shshsize,char *shadbits,noteptr *shadow,int shadowsize,motifptr tset);
-static int  geths_hibnd(double thispitch,int hsnotecnt,double *hs);
-static int  geths_above(double thispitch,double *hs,int hsnotecnt);
-static int  fit_unlink(fitptr thisfit);
-static int  new_fit(fitptr thisfit,fitptr *newfit);
-static int      getnexths(double **hs,double inputtime,int *hs_cnt,int *hsnotecnt,noteptr *thishsnote,
-                          double *thishstime,double *nexthstime,int hfdatacnt,double *hft);
-static int      getnexthf(double **hf,double **hs, int *hsnotecnt,double inputtime,int *hf_cnt,
-                          int *hfnotecnt,noteptr *thishfnote,double *thishftime,double *nexthftime,int hfdatacnt,double *hft);
-static int      hfscat(int prange,int pbottom,int permindex,int *val,dataptr dz);
-static int      gethsnote(double thispitch,double *thishs,int *hsnotecnt);
-static void hfsqueezrange
-(double thispitch,int *hfrange,int *hfgpranghi,int *hfgpranglo,int hsnotecnt,double *hs);
-static int  hforientrange(double thispitch,int *hfrange,int *hfgpranghi,int *hfgpranglo,
-                          int hsnotecnt,double *hs,int dectypecnt,unsigned char dectypestor,dataptr dz);
-static int  dec_hfcentre(double tsetpitch,double *hs,int hsnotecnt,
-                         int hfrange,int hfgpranghi,int hfgpranglo,double gprlow,double gprange,int gpsize,
-                         double *val,dataptr dz);
-static int  hfscatx(int prange,int pbottom,int permindex,int *val,dataptr dz);
-static int  get_first_hs(noteptr thisnote,double **hs,int *hsnotecnt);
-static int  get_first_hf(noteptr thisnote,double **hf,int *hfnotecnt);
-static int  setup_first_hfield
-(noteptr thisnote,double **hs,int *hsnotecnt,double **hf,int *hfnotecnt,int texflag);
-static int octeq(double a,double b);
-
-/**************************** DO_SIMPLE_HFTEXTURE ****************************/
-
-int do_simple_hftexture(dataptr dz)
-{
-    int exit_status;
-    unsigned int texflag     = dz->tex->txflag;
-    motifptr tset                     = dz->tex->timeset;
-    motifptr hfmotif                  = dz->tex->hfldmotif;
-    int hsindex;
-    noteptr tsetnote = tset->firstnote;
-    noteptr nextnote;
-    double thistime, thispitch, lastpitch = -1.0;
-    noteptr thishfnote = hfmotif->firstnote;
-    noteptr thishsnote = hfmotif->firstnote;
-    double thishftime,nexthftime,thishstime,nexthstime,thisamp,thisdur;
-    unsigned char thisinstr;
-    int hf_cnt = 1, hfnotecnt = 0;
-    int hs_cnt = 1, hsnotecnt = 0;
-    int hfdatacnt = 0;
-    double *hft, pptop, ppbot;
-    double *hs = (double *)0, *hf = (double *)0;
-    dz->iparam[SPINIT] = 0;
-
-    if((exit_status = readhftimes(hfmotif->firstnote,&hfdatacnt,&hft))<0)
-        return(exit_status);
-    thishftime = nexthftime = thishstime = nexthstime = hft[0];
-
-    if(texflag & ISMANY_HFLDS) {
-        if((exit_status = setup_first_hfield(hfmotif->firstnote,&hs,&hsnotecnt,&hf,&hfnotecnt,texflag))<0)
-            return(exit_status);
-    } else {
-        if((exit_status = setup_hfield(hfmotif->firstnote,&hs,&hsnotecnt,&hf,&hfnotecnt,texflag))<0)
-            return(exit_status);
-    }
-    while(tsetnote!=(noteptr)0) {                               /* 3 */
-        /*repeated  = */(void) chekrepeat(tsetnote,lastpitch);
-        lastpitch = tsetnote->pitch;
-        thistime  = (double)tsetnote->ntime;        /* 5 */
-        if((exit_status = read_values_from_all_existing_brktables(thistime,dz))<0)
-            return(exit_status);
-        if(texflag & ISMANY_HFLDS) {
-            if((exit_status = get_next_hfield(&hf,&hs,thistime,&hf_cnt,&hs_cnt,
-                                              &hfnotecnt,&thishfnote,&thishftime,&nexthftime,hfdatacnt,
-                                              &hsnotecnt,&thishsnote,&thishstime,&nexthstime,hft,texflag))<0)
-                return(exit_status);
-        }
-        if((exit_status = do_amp_instr_dur(&thisamp,&thisinstr,&thisdur,tsetnote,thistime,dz))<0)
-            return(exit_status);
-        if((exit_status = do_ev_hfpch(thistime,&hsindex,&thispitch,hsnotecnt,hs,&pptop,&ppbot,dz))<0)
-            return(exit_status);
-        tsetnote->pitch = (float)thispitch;
-        if(exit_status == CONTINUE) {
-            nextnote = tsetnote->next;
-            del_note(tsetnote,tset);
-            tsetnote = nextnote;
-        } else
-            tsetnote = tsetnote->next;
-    }
-    if(tset->firstnote==(noteptr)0) {
-        sprintf(errstr,"The harmonic set specified does not tally with the range.\n");
-        return(DATA_ERROR);
-    }
-    return(FINISHED);
-}
-
-/**************************** DO_CLUMPED_HFTEXTURE ****************************/
-
-int do_clumped_hftexture(dataptr dz)
-{
-    int exit_status;
-    unsigned int texflag     = dz->tex->txflag;
-    unsigned char dectypestor = dz->tex->dectypstor;
-    unsigned char dectypecnt  = dz->tex->dectypcnt;
-    unsigned char amptypestor = dz->tex->amptypstor;
-    unsigned char amptypecnt  = dz->tex->amptypcnt;
-    int ampdirected           = dz->tex->ampdirectd;
-    motifptr tset                     = dz->tex->timeset;
-    motifptr hfmotif                  = dz->tex->hfldmotif;
-    motifptr *phrase                  = dz->tex->phrase;
-    int **hfphrase = NULL;
-    int *endhsindex=NULL, *phrnotecnt=NULL;
-    double *phraseamp=NULL, *phrange=NULL;
-    unsigned char amptype = 0;
-    fitptr fithead = NULL;
-    noteptr tsetnote = tset->firstnote;
-    noteptr thisnote=NULL, nextnote=NULL, phrasenote=NULL, nextevent=NULL, *shadow=NULL;
-    double thispitch = 0.0, lastpitch = -1.0, ampstep = 0.0, ampdif = 0.0, notetime = 0.0, thisamp = 0.0, thisdur = 0.0;
-    unsigned char thisinstr;
-    double phrfirstnote = 0.0, thistime = 0.0, rangemult = 0.0, gprlow = 0.0;
-    double timeadjust = 0.0; /* default */
-    noteptr thishfnote = hfmotif->firstnote;
-    noteptr thishsnote = hfmotif->firstnote;
-    noteptr *phrlastnote = NULL;
-    double thishftime = 0.0,nexthftime = 0.0,thishstime = 0.0,nexthstime = 0.0,tsettime = 0.0;
-    int hf_cnt = 1, hfnotecnt = 0, mingrpsize = 0, shadindex = 0, shadowsize=0;
-    double gprange = 0.0,gpdense = 0.0,multiplier = 0.0;
-    double *notestor=NULL;
-    int hfgpranglo=0,hfgpranghi=0;
-    int hs_cnt = 1, hsnotecnt = 0;
-    int hfdatacnt = 0, hfrange = 0, gpsize,shshsize = 0;
-    int phrno = 0, n=0,  hsindex=0, starthsindex=0, hfchanged=0;
-    int hsi=0, starthsi = 0, endhsi=0;
-    char *shadbits = NULL;
-    double *hft=NULL, pptop=0.0, ppbot=0.0;
-    double *hs = (double *)0, *hf = (double *)0;
-
-    if((dz->tex->phrasecnt > 0) && (exit_status = initialise_hfphrases
-                                    (&hfphrase,&endhsindex,&phrnotecnt,&phraseamp,&phrange,&phrlastnote,dz))<0)
-        return(exit_status);
-    dz->iparam[SPINIT] = 0;
-    if(texflag & IS_GROUPS)
-        mingrpsize = 1;
-
-    if((exit_status = readhftimes(hfmotif->firstnote,&hfdatacnt,&hft))<0)
-        return(exit_status);
-    thishftime = nexthftime = thishstime = nexthstime = hft[0];
-
-    if((exit_status = make_shadow(tset,&shadowsize,&shadow))<0)
-        return(exit_status);
-
-    if((texflag & MOTIF_IN_HF) || (texflag & IS_ORNATE)) {
-        if((exit_status = init_fits(&fithead))<0)
-            return(exit_status);
-    }
-    if(texflag & IS_DECOR)
-        setup_decor(&pptop,&ppbot,&shadindex,&tsetnote,dz);
-    else {
-        if((exit_status = init_shadbits(shadowsize,&shshsize,&shadbits))<0)
-            return(exit_status);
-    }
-    if(texflag & ISMANY_HFLDS) {
-        if((exit_status = setup_first_hfield(hfmotif->firstnote,&hs,&hsnotecnt,&hf,&hfnotecnt,texflag))<0)
-            return(exit_status);
-    } else {
-        if((exit_status = setup_hfield(hfmotif->firstnote,&hs,&hsnotecnt,&hf,&hfnotecnt,texflag))<0)
-            return(exit_status);
-    }
-    if((texflag & MOTIF_IN_HF) || ((texflag & IS_ORNATE) && !(texflag & ISMANY_HFLDS))) {
-        if((exit_status = set_hfmotifs
-            (hs,phrase,phrnotecnt,phraseamp,phrange,phrlastnote,endhsindex,hfphrase,hsnotecnt,fithead,&notestor,dz))<0)
-            return(exit_status);
-    } else if(texflag & IS_MOTIFS) {
-        if((exit_status = set_motifs
-            (dz->tex->phrasecnt,phrase,phrnotecnt,phraseamp,phrange,phrlastnote))<0)
-            return(exit_status);
-    }
-    while(tsetnote!=(noteptr)0) {
-        if(!(texflag & IS_ORNATE)) {
-            /*repeated =*/ (void) chekrepeat(tsetnote,lastpitch);
-            lastpitch = tsetnote->pitch;
-        }
-        tsettime = thistime = (double)tsetnote->ntime;
-        if((exit_status = read_values_from_all_existing_brktables(thistime,dz))<0)
-            return(exit_status);
-        if(texflag & ISMANY_HFLDS) {
-            if((exit_status = get_next_hfield(&hf,&hs,thistime,&hf_cnt,&hs_cnt,
-                                              &hfnotecnt,&thishfnote,&thishftime,&nexthftime,hfdatacnt,
-                                              &hsnotecnt,&thishsnote,&thishstime,&nexthstime,hft,texflag))<0)
-                return(exit_status);
-            hfchanged = exit_status;
-            if(((texflag & MOTIF_IN_HF) || (texflag & IS_ORNATE)) && hfchanged) {
-                if((exit_status = set_hfmotifs
-                    (hs,phrase,phrnotecnt,phraseamp,phrange,phrlastnote,endhsindex,hfphrase,hsnotecnt,fithead,&notestor,dz))<0)
-                    return(exit_status);
-            }
-        }
-        if(texflag & IS_ORN_OR_MTF) {
-            if((exit_status = setup_motif_or_ornament(thistime,&multiplier,&phrno,&phrasenote,phrase,dz))<0)
-                return(exit_status);
-        }
-        if((exit_status = do_amp_instr_dur(&thisamp,&thisinstr,&thisdur,tsetnote,thistime,dz))<0)
-            return(exit_status);
-        if(texflag & IS_DECOR)
-            thispitch = tsetnote->pitch;
-        if(texflag & IS_MTF_OR_GRP) {
-            if(texflag & IS_GROUPS)
-                exit_status = setup_group_note
-                    (thisamp,thisinstr,thisdur,tsetnote,&thispitch,
-                     thistime,&hsindex,hsnotecnt,hs,&pptop,&ppbot,&shadindex,shadbits,dz);
-            else
-                exit_status = setup_motif_note
-                    (thisamp,thisinstr,thisdur,tsetnote,phrasenote,&thispitch,
-                     thistime,&hsindex,hsnotecnt,hs,&pptop,&ppbot,&shadindex,shadbits,multiplier,dz);
-            if(exit_status==CONTINUE)
-                continue;
-        }
-        if(texflag & IS_ORN_OR_MTF)
-            gpsize = phrnotecnt[phrno];
-        else {
-            if((exit_status = get_hfgpparams
-                (thistime,thispitch,hs,hsnotecnt,&gpsize,&hfrange,&hfgpranglo,&hfgpranghi,
-                 &gprange,&gpdense,mingrpsize,&gprlow,dectypecnt,dectypestor,dz))<0)
-                return(exit_status);
-        }
-        if(texflag & IS_DECOR) {
-            if((exit_status = position_and_size_decoration(&thistime,tsettime,gpdense,&gpsize,dz))<0)
-                return(exit_status);
-        } else
-            gpsize--;
-        if(texflag & IS_MOTIFS)
-            phrfirstnote = phrasenote->pitch;
-        else if(texflag & IS_ORNATE) {
-            if((hsi = convert_pitch_to_nearest_hset_pitch((double)tsetnote->pitch,hs,hsnotecnt))<0)
-                gpsize = 0;                     /* note out of bounds, ornament omitted  */
-            if((exit_status = setup_ornament
-                (&timeadjust,&thistime,&gpsize,phrlastnote,multiplier,&phrasenote,phrno,dz))<0)
-                return(exit_status);
-        }
-        if(!(texflag & IS_DECOR))
-            nextnote  = tsetnote->next;
-        if(gpsize>0) {
-            if(texflag & IS_ORN_OR_MTF) {
-                if((exit_status = orn_or_mtf_amp_setup
-                    (ampdirected,phrange,phrno,thisamp,gpsize,&rangemult,&ampstep,&amptype,amptypestor,amptypecnt,dz))<0)
-                    return(exit_status);
-            }
-            if(texflag & IS_MOTIFS) {
-                if((exit_status = set_motif_amp
-                    (tsetnote,&thisamp,gpsize,ampstep,phrasenote,rangemult,phraseamp,phrno,amptype))<0)
-                    return(exit_status);
-            } else if(texflag & IS_ORNATE) {
-                if((exit_status = set_ornament_amp
-                    (phraseamp,phrlastnote,&thisamp,phrasenote,phrno,tsetnote,ampstep,rangemult,gpsize,dz))<0)
-                    return(exit_status);
-            } else if (texflag & IS_GROUPS) {
-                if((exit_status = set_group_amp
-                    (tsetnote,&thisamp,&amptype,&ampstep,gpsize,amptypecnt,amptypestor,dz))<0)
-                    return(exit_status);
-            } else if (texflag & IS_DECOR) {
-                if((exit_status = set_decor_amp
-                    (ampdirected,&thisamp,&ampstep,gpsize,&amptype,amptypecnt,amptypestor,dz))<0)
-                    return(exit_status);
-            }
-            if(dz->iparam[TEX_GPSPACE]!=IS_STILL) {
-                if((exit_status = init_group_spatialisation(tsetnote,shadindex,shadow,shadowsize,dz))<0)
-                    return(exit_status);
-            }
-            thisnote  = tsetnote;
-            if(texflag & MOTIF_IN_HF)
-                starthsindex =  *(hfphrase[phrno]);
-            else if(texflag & IS_ORNATE) {
-                if((exit_status = setup_ornamentation
-                    (&starthsi,&endhsi,&nextevent,tsetnote,&phrasenote,&shadindex,endhsindex,hfphrase[phrno],phrno,dz))<0)
-                    return(exit_status);
-            } else if(texflag & IS_DECOR) {
-                nextnote = tsetnote->next;
-                nextevent = getnextevent_to_decorate(tsetnote,&shadindex,dz);
-            }
-            for(n=0;n<gpsize;n++) {
-                if((exit_status = make_new_note(&thisnote))<0)
-                    return(exit_status);
-                if(texflag & IS_ORN_OR_MTF) {
-                    if((exit_status = check_next_phrasenote_exists(&phrasenote,texflag,dz))<0)
-                        return(exit_status);
-                    notetime = getnotetime(phrasenote,thistime,multiplier,timeadjust,dz);
-                    thisamp += ampstep;
-                    ampdif   = (phraseamp[phrno]-phrasenote->amp)*rangemult;
-                    if((exit_status = setmtfparams
-                        (thisnote,thisamp,phrasenote,tsetnote,ampdif,notetime,gpsize,multiplier,dz))<0)
-                        return(exit_status);
-                } else  {
-                    if((exit_status = set_group_params
-                        (tsetnote,thisnote,gpdense,ampstep,&thisamp,&thistime,thisdur,dz))<0)
-                        return(exit_status);
-                }
-                if(texflag & MOTIF_IN_HF) {
-                    if((exit_status = generate_motifin_note_pitch
-                        (n,hsindex,starthsindex,hsnotecnt,thispitch,hfphrase[phrno],&thisnote,hs,texflag))<0)
-                        return(exit_status);
-                } else if(texflag & IS_MOTIFS) {
-                    if((exit_status = generate_motif_note_pitch(tsetnote,phrasenote,phrfirstnote,thisnote))<0)
-                        return(exit_status);
-                } else if (texflag & IS_ORNATE) {
-                    if((exit_status = generate_ornament_note_pitch
-                        (n,hs,hsi,endhsi,starthsi,&thisnote,&phrasenote,hfphrase[phrno],hfnotecnt,hsnotecnt,dz))<0)
-                        return(exit_status);
-                } else if(texflag & IS_GROUPS) {
-                    if((exit_status = generate_group_note
-                        (thisnote,tsetnote,thistime,hfrange,hfgpranglo,hs,&hsindex,gpsize,dz))<0)
-                        return(exit_status);
-                } else if(texflag & IS_DECOR) {
-                    if((exit_status = generate_decor_note
-                        (thisnote,tsetnote,thispitch,thistime,hfrange,hfgpranghi,hfgpranglo,
-                         hs,&hsindex,hsnotecnt,gprlow,gprange,gpsize,dz))<0)
-                        return(exit_status);
-                }
-                if(exit_status==CONTINUE)
-                    continue;
-            }
-            thisnote->next = nextnote;
-            if(nextnote!=(noteptr)0)
-                nextnote->last = thisnote;
-            if(texflag & IS_ORN_OR_DEC)
-                tsetnote = nextevent;
-        } else if(texflag & IS_ORN_OR_DEC)
-            tsetnote = getnextevent_to_decorate(tsetnote,&shadindex,dz);
-
-        if(texflag & IS_MTF_OR_GRP) {
-            tsetnote = nextnote;
-            shadindex++;
-        }
-    }
-    if(texflag & IS_MTF_OR_GRP)
-        del_ghosts(shshsize,shadbits,shadow,shadowsize,tset);           /* 5 */
-
-    if(texflag & IS_DECOR) {
-        if(dz->vflag[DISCARD_ORIGLINE] && (exit_status = erase_shadow(shadowsize,shadow,tset))<0)
-            return(exit_status);
-    } else
-        free(shadbits);
-    if((texflag & MOTIF_IN_HF) || (texflag & IS_ORNATE))
-        free(fithead);
-    return arrange_notes_in_timeorder(tset);
-}
-
-/**************************** SET_HFMOTIFS *******************************
- *
- * initialise all parameters of input motifs to be used for MOTIFS or
- * ORNAMENTS, including their HS indexing!!!
- *
- * (1)For each input motif (called a 'phrase').
- *    phrnotecnt[n] = 0;
- * (2)  Initialise count of number of notes to 0, maximum amplitude
- *      of phrase to 0.0, and lowest pitch-index to hsnotecnt.
- * (3)  Go through each note of the motif.
- * (4)  Add up the number of notes in it.
- * (5)  Find it's lowest pitch.
- * (6)  Find it's loudest note (and set as phraseamp).
- * (7)  Establish dynamic range of phrase.
- * (9)  Ensure motif starts at zero time.
- * (10) Generate the corresponding HS indices, in their lowest configuration.
- * (11) Store hfindex of last note of phrase.
- */
-
-int set_hfmotifs
-(double *hs,motifptr *phrase,int *phrnotecnt,double *phraseamp,double *phrange,noteptr *phrlastnote,
- int *endhsindex,int **hfphrase,int hsnotecnt,fitptr fithead,double **notestor,dataptr dz)
-{
-    int exit_status;
-    int n;
-    double mintime, minamp, minpitch, maxpitch;
-    noteptr thisnote, lastnote = (noteptr)0;
-    for(n=0;n<dz->tex->phrasecnt;n++) {                                             /* 1 */
-        if((exit_status = arrange_notes_in_timeorder(phrase[n]))<0)
-            return(exit_status);
-        phrnotecnt[n] = 0;
-        phraseamp[n] = 0.0;                                                     /* 2 */
-        minamp   = DBL_MAX;
-        minpitch = DBL_MAX;
-        maxpitch = -2.0f;
-        mintime  = DBL_MAX;
-        thisnote = phrase[n]->firstnote;                        /* 3 */
-        while(thisnote!=(noteptr)0) {
-            phrnotecnt[n]++;                                                        /* 4 */
-            if((double)thisnote->pitch<minpitch)
-                minpitch = thisnote->pitch;                     /* 5 */
-            if((double)thisnote->pitch>maxpitch)
-                maxpitch = thisnote->pitch;                     /* 5 */
-            if(thisnote->ntime<mintime)
-                mintime  = thisnote->ntime;                     /* 5 */
-            if((double)thisnote->amp>phraseamp[n])
-                phraseamp[n] = (double)thisnote->amp;/* 6 */
-            if(thisnote->amp<minamp)
-                minamp = thisnote->amp;                         /* 6 */
-            thisnote = thisnote->next;
-        }
-        if(minamp   == DBL_MAX
-           || minpitch == DBL_MAX
-           || maxpitch == -2.0f
-           || mintime  == DBL_MAX) {
-            sprintf(errstr,"Error parsing notelist: set_hfmotifs()\n");
-            return(PROGRAM_ERROR);
-        }
-        thisnote = phrase[n]->firstnote;
-        phrange[n] = phraseamp[n] - (double)minamp;     /* 7 */
-        while(thisnote!=(noteptr)0) {
-            thisnote->ntime = (float)(thisnote->ntime - mintime);                           /* 9 */
-            lastnote = thisnote;
-            thisnote = thisnote->next;
-        }
-        if((phrlastnote[n] = lastnote)==(noteptr)0) {
-            sprintf(errstr,"Encountered an empty motif: set_hfmotifs()\n");
-            return(PROGRAM_ERROR);
-        }
-        if((exit_status = gethfphrase(hs,notestor,n,minpitch,maxpitch,hfphrase,hsnotecnt,phrnotecnt,phrase,fithead))<0) /* 10 */
-            return(exit_status);
-        endhsindex[n]  = *(hfphrase[n]+phrnotecnt[n]-1);                        /* 11 */
-    }
-    return(FINISHED);
-}
-
-/*********************** GETHFPHRASE *********************************
- *
- * Get the hfphrase best corresponding to the input motif.
- *
- * (0)  Create storage space to store HS-indices of phrase.
- * (1)  HIpitch of phrase higher than top of HS
- *      AND LOpitch of phrase lower than bottom of HS.
- *      ..Shrink the motif to size of HS, and establish hfphrase.
- * (2)  HIpitch of phrase higher than top of HS
- *      BUT LOpitch within HS range.
- *      .. transpose phraselimits down onto bottom pitch of HS.
- * (a)  If HIpitch of phrase STILL higher than top of HS
- *      ..Shrink the motif to size of HS, and establish hfphrase.
- * (3)  LOpitch of phrase lower than bottom of HS
- *      BUT HIpitch within HS range.
- *      .. transpose phraselimits up onto bottom pitch of HS.
- * (a)  If HIpitch of phrase is NOW higher than top of HS
- *      ..Shrink the motif to size of HS, and establish hfphrase.
- * (4)  Phrase lies with the limits of HS.
- *      .. transpose phraselimits down onto bottom pitch of HS.
- * (5)  Find appropriate hfphrase.
- */
-
-int gethfphrase
-(double *hs,double **notestor,int z,double lopitch,double hipitch,
- int **hfphrase,int hsnotecnt,int *phrnotecnt,motifptr *phrase,fitptr fithead)
-{
-    double origlo = lopitch, hstop = hs[hsnotecnt-1], hsbot = hs[0];
-    double stepdown, stepup;
-    if((hfphrase[z] = (int *)malloc(phrnotecnt[z] * sizeof(int)))==NULL) {  /* 0 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic field phrase array.\n");
-        return(MEMORY_ERROR);
-    }
-    if(hipitch>=hstop) {
-        if(lopitch<=hsbot)                              /* 1 */
-            return shrink_to_hs(z,hsnotecnt,hipitch,lopitch,hstop,hsbot,hs,hfphrase[z],phrase,phrnotecnt);
-        else  {
-            stepdown = lopitch - hsbot;                     /* 2 */
-            hipitch -= stepdown;
-            lopitch -= stepdown;
-            if(hipitch>hstop)                               /* a */
-                return shrink_to_hs(z,hsnotecnt,hipitch,lopitch,hstop,hsbot,hs,hfphrase[z],phrase,phrnotecnt);
-        }
-    } else {
-        if(lopitch<=hsbot) {                            /* 3 */
-            stepup  = hsbot - lopitch;
-            hipitch += stepup;
-            lopitch += stepup;
-            if(hipitch>hstop)                               /*a */
-                return shrink_to_hs(z,hsnotecnt,hipitch,lopitch,hstop,hsbot,hs,hfphrase[z],phrase,phrnotecnt);
-        } else {                                        /* 4 */
-            stepdown = lopitch - hsbot;
-            hipitch -= stepdown;
-            lopitch -= stepdown;
-        }
-    }
-    return findhfphrase(z,hs,hstop,hsnotecnt,lopitch,origlo,phrase,hfphrase,phrnotecnt,fithead,notestor);
-}                                                                                       /* 5 */
-
-
-/************************* SHRINK_TO_HS **************************
- *
- * Shrink motif so it fits with HS, then find best HS fit.
- *
- * (1)  Establish pitch-shrinking ratio.
- * (2)  For every note...
- * (3)  Shrink intervals and thus move pitch to appropriate position inside
- *      range of HS.
- * (4)  Find index of the next lowest HS notes.
- * (4a) If note falls outside field, set distance to note to maximum poss.
- * (4b) Else find pitch distances of this note from original pitch.
- * (5)  Find index of the next highest HS notes.
- * (5a) If note falls outside field, set distance to note to maximum poss.
- * (5b) Else find pitch distances of this note from original pitch.
- * (6)  Select HSindex of nearest pitch and store in hfphrase.
- * (7)  Save the lowest such index.
- * (8)  Transpose all indices down to lowest possible values.
- */
-
-int shrink_to_hs(int z,int hsnotecnt,double hipitch,double lopitch,double hstop,
-                 double hsbot,double *hs, int *hfphrase, motifptr *phrase,int *phrnotecnt)
-{
-    noteptr thisnote = phrase[z]->firstnote;
-    double shrink ,thispitch, x, y;
-    int minindex = MAXINT, xx, yy, q, n = 0;
-    shrink = (hstop - hsbot)/(hipitch-lopitch);                     /* 1 */
-    for(;;) {                                                       /* 2 */
-        thispitch = thisnote->pitch;
-        thispitch = ((thispitch - lopitch) * shrink) + hsbot;   /* 3 */
-        if((xx = geths_lobnd(thispitch,hs,hsnotecnt))<0)                        /* 4 */
-            x = DBL_MAX;                                            /* 4a */
-        else
-            x = fabs(hs[xx] - thispitch);                   /* 4b */
-        if((yy = geths_hibnd(thispitch,hsnotecnt,hs))>=hsnotecnt)               /* 5 */
-            y = DBL_MAX;                                            /* 5a */
-        else
-            y = fabs(hs[yy] - thispitch);                   /* 5b */
-        if(x<y)
-            q = xx;                                         /* 6 */
-        else
-            q = yy;
-        *(hfphrase+n) = q;
-        if(q<minindex)
-            minindex = q;                                   /* 7 */
-        if((thisnote = thisnote->next)==(noteptr)0)
-            break;
-        if(++n >= phrnotecnt[z]) {
-            sprintf(errstr,"accounting problem in shrink_to_hs()\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    for(n=0;n<phrnotecnt[z];n++)                                    /* 8 */
-        *(hfphrase+n) -= minindex;
-    return(FINISHED);
-}
-
-/*********************** FINDHFPHRASE *********************************
- *
- * Extract the best fit onto the HS, and transpose it down to bottom
- * of indices.
- *
- * (1)  Set the FIT-pointer to head of fits-list.
- * (2)  Set up a store for the note values to be tested.
- * (3)  Get interval of transposition to take motif to bottom of HS range.
- * (4)  Store original note values of phrase transposed down to bottom of HS range.
- * (5)  Find the fit-value for motif in its start position.
- * (6)  Outer loop will transpose the phrase through a range...
- *              (7)     Set amount to transpose phrase (shift) to max.
-                        Then for every note of the phrase.....
-                        *              (8) Find the HSindex of the nearest note above the current note.
-                        *              (If there isn't one break out completely).
-                        *              (9)  If the difference in pitch between this and the current note
-                        *              is smaller than the minimum shift, reset minimum shift.
-                        *              (10)Then, for every note of the phrase...
-                        *              (11)transpose it up by this minimum transposition.
-                        *                      If this takes any note of the phrase outside the range of HS
-                        *                      break out completely.
-                        *      (12)Back in outer loop, find the fitting-value for this transposition
-                        *                      of the motif, which is a measure of how far its notes are from
-                        *                      the closest HS values.
-                        * (13) Outside the outer loop, unlink the last unwanted member iof fitlist.
-                        * (14) Find the best fitvalue, and return the amount by which orig motif
-                        *              should be transposed to get onto this best fit.
-                        * (15) Free the fit-list (retains fithead).
-                        * (16) Get the appropriate HS indices.
-                        */
-
-int findhfphrase
-(int z,double *hs,double hstop,int hsnotecnt,double lopitch,double origlo,
- motifptr *phrase,int **hfphrase,int *phrnotecnt,fitptr fithead,double **notestor)
-{
-    int exit_status;
-    int hsindex, OK = 1, n, got_transpose = 0;
-    noteptr thisnote = phrase[z]->firstnote;
-    fitptr thisfit = fithead;                                                                       /* 1 */
-    double shift, thisshift, transpose = 0.0, stepdown, *noteval;
-    if(*notestor!=NULL)
-        free(*notestor);                                                                                /* 2 */
-    if((noteval = *notestor = (double *)malloc(phrnotecnt[z] * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for note value array.\n");
-        return(MEMORY_ERROR);
-    }
-    stepdown = origlo - lopitch;                                                            /* 3 */
-    while(thisnote!=(noteptr)0) {
-        *noteval = (double)thisnote->pitch - stepdown;                  /* 4 */
-        noteval++;
-        thisnote = thisnote->next;
-    }
-    if((exit_status = get_fit(*notestor,thisfit,lopitch,origlo,z,hsnotecnt,phrnotecnt,hs,&thisfit))<0)
-        return(exit_status);                                                                    /* 5 */
-    if(exit_status == CONTINUE) {
-        transpose = thisfit->last->transpose;
-        got_transpose = 1;
-        OK  = 0;
-    }
-    while(OK) {                                                                                                     /* 6 */
-        shift = DBL_MAX;                                                                                /* 7 */
-        noteval = *notestor;
-        for(n=0;n<phrnotecnt[z];n++) {
-            if((hsindex = geths_above(*noteval,hs,hsnotecnt))>=hsnotecnt) { /* 8 */
-                OK = 0;
-                break;
-            }
-            if((thisshift  = hs[hsindex] - *noteval)<shift)
-                shift = thisshift;                                                              /* 9 */
-            noteval++;
-        }
-        if(shift==DBL_MAX) {
-            sprintf(errstr,"Error parsing phrase: findhfphrase()\n");
-            return(PROGRAM_ERROR);
-        }
-        if(!OK)
-            break;
-        noteval = *notestor;
-        for(n=0;n<phrnotecnt[z];n++) {                                                  /* 10 */
-            if((*noteval++  += (float)shift)>hstop) {
-                OK = 0;                                                                                 /* 11 */
-                break;
-            }
-        }
-        lopitch += shift;
-        if((exit_status = get_fit(*notestor,thisfit,lopitch,origlo,z,hsnotecnt,phrnotecnt,hs,&thisfit))<0)
-            return(exit_status);                                                            /* 12 */
-        if(exit_status == CONTINUE) {
-            transpose = thisfit->last->transpose;
-            got_transpose = 1;
-            break;
-        }
-    }
-    if((exit_status = fit_unlink(thisfit))<0)                                       /* 13 */
-        return(exit_status);
-    if (!got_transpose) {
-        if((exit_status = best_fit(fithead,&transpose))<0)              /* 14 */
-            return(exit_status);
-    }
-    free_fitlist(fithead);                                                                          /* 15 */
-    return getmtfindeces(transpose,z,hsnotecnt,hs,phrase,phrnotecnt,hfphrase);
-}                                                                                                                               /* 16 */
-
-/*************************** GETMTFINDECES *****************************
- *
- * Get the HS indices of the phrase, transposed to lowest position in HS.
- *
- * (0)  Point to start of storage space for the HS-indices of the phrase.
- * (1)  Mark end of this storage space (for accounting purposes).
- * (2)  For every note of the phrase...
- *   (3)  Get the pitch..
- *   (4)  Transpose the pitch by the input transposition.
- *   (5)  Find the nearest HS set members above and below the note.
- *   (6)  Decide which is nearest.
- *   (7)  Assign index of nearest value to the HS-index store.
- *   (8)  Keep a note of the smallest index.
- *   (9)  Increment the index-store pointer.
- * (10) Decrement all the indeces to tranpose them all to lowest values
- *      in the hfphrase store.
- */
-
-int getmtfindeces(double transpose,int z,int hsnotecnt,double *hs,motifptr *phrase,int *phrnotecnt,int **hfphrase)
-{
-    noteptr thisnote = phrase[z]->firstnote;
-    int *thisindex, xx, yy, minindex = MAXINT, *indexend;
-    double x, y, thispitch;
-    thisindex = hfphrase[z];                                                /* 0 */
-    indexend  = hfphrase[z] + phrnotecnt[z];                /* 1 */
-    for(;;) {                                                                               /* 2 */
-        thispitch  = thisnote->pitch;                           /* 3 */
-        thispitch += transpose;                                         /* 4 */
-        xx = geths_lobnd(thispitch,hs,hsnotecnt);       /* 5 */
-        yy = geths_hibnd(thispitch,hsnotecnt,hs);
-        x = fabs(hs[xx] - thispitch);                           /* 6 */
-        y = fabs(hs[yy] - thispitch);
-        if(x<y)
-            *thisindex = xx;                                                /* 7 */
-        else
-            *thisindex = yy;
-        if(*thisindex<minindex)
-            minindex = *thisindex;                                  /* 8 */
-        if((thisnote = thisnote->next)==(noteptr)0)
-            break;
-        if(++thisindex>=indexend) {                                     /* 9 */
-            sprintf(errstr,"TEXTURE: Problem in getmtfindices()\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    for(thisindex = hfphrase[z];thisindex<indexend;thisindex++)
-        *thisindex -= minindex;                                         /* 10 */
-    return(FINISHED);
-}
-
-/****************************** GET_FIT ************************************
- *
- * Create list of fit_values for motif over HS.
- *
- * (1)  For every note of the phrase.
- * (3)  Find the index of the next lowest HS note. If there is not one
- *      something is wrong!
- * (4)  Find the index of the next highest HS note. If there is not one
- *      something is wrong!
- * (5)  Find the pitch distance between these notes on the original pitch.
- * (6)  Add the minimum of these two, to a running sum of such differences.
- * (7)  Store the fit-value and the associated ttansposition, creating a
- *      new storage space in the fit list, in the process.
- */
-
-int get_fit(double *notestor,fitptr thisfit,double lopitch,double origlo,int z,
-            int hsnotecnt,int *phrnotecnt,double *hs,fitptr *newfit)
-{
-    int exit_status;
-    double x, y, sum = 0.0, *noteval = notestor;
-    int xx, yy, n;
-    for(n=0;n<phrnotecnt[z];n++) {                                                          /* 1 */
-        if((xx = geths_lobnd(*noteval,hs,hsnotecnt))<0) {               /* 3 */
-            sprintf(errstr,"Problem 1 in get_fit()\n");
-            return(PROGRAM_ERROR);
-        }
-        if((yy=geths_hibnd(*noteval,hsnotecnt,hs))>=hsnotecnt) {/* 4 */
-            sprintf(errstr,"Problem 2 in get_fit()\n");
-            return(PROGRAM_ERROR);
-        }
-        x = fabs(hs[xx] - *noteval);                                                    /* 5 */
-        y = fabs(hs[yy] - *noteval);
-        sum += min(x,y);                                                                                /* 6 */
-        noteval++;
-    }
-    if((exit_status = put_fit(thisfit,lopitch - origlo,sum,newfit))<0)
-        return(exit_status);
-    if(flteq(sum,0.0))
-        return(CONTINUE);
-    return(FINISHED);                                                                                       /* 7 */
-}
-
-/************************* PUT_FIT *****************************
- *
- * Put fit value in motif-fits list.
- */
-
-int put_fit(fitptr thisfit,double transval,double fitval,fitptr *newfit)
-{
-    int exit_status;
-    thisfit->transpose = (float)transval;
-    thisfit->fit       = (float)fitval;
-    if((exit_status = new_fit(thisfit,newfit))<0)
-        return(exit_status);
-    return(FINISHED);
-}
-
-/************************* BEST_FIT *****************************
- *
- * Find the appropriate transposition to move the current motif
- * to a pitch where it has the best fit with the HS.
- *
- * (1)  From all available transpositions, find best (lowest) fit value.
- * (2)  From all available transpositions, find all those which have
- *      this bestfit value, and select the one which involves the
- *      least transposition.
- * (3)  Once the transpositions begin to increase, we are moving away from
- *      the smallest transposition, so quit.
- * (4)  Return the best transposition.
- */
-
-int best_fit(fitptr fithead,double *transpose)
-{
-    fitptr thisfit = fithead;
-    double bestfit = DBL_MAX, besttranspose = DBL_MAX;
-    double abstranspose = DBL_MAX, thistranspose;
-    while(thisfit!=(fitptr)0) {                             /* 1 */
-        if(thisfit->fit<(float)bestfit)
-            bestfit = (double)thisfit->fit;
-        thisfit = thisfit->next;
-    }
-    thisfit = fithead;
-    while(thisfit!=(fitptr)0) {                             /* 2 */
-        thistranspose = fabs((double)thisfit->transpose);
-        if(flteq((double)thisfit->fit,bestfit)) {
-            if(thistranspose<abstranspose) {
-                besttranspose = (double)thisfit->transpose;
-                abstranspose = fabs(besttranspose);
-            }
-        }
-        if(thistranspose>abstranspose+FLTERR)
-            break;                                  /* 3 */
-        thisfit = thisfit->next;
-    }
-    if(besttranspose==DBL_MAX) {
-        sprintf(errstr,"Problem in best_fit()\n");
-        return(PROGRAM_ERROR);
-    }
-    *transpose = besttranspose;
-    return(FINISHED);                               /* 4 */
-}
-
-/************************* INIT_FITS() *****************************
- *
- * Set up head item of a list of motif-fits.
- */
-
-int init_fits(fitptr *thisfit)
-{
-    if((*thisfit = (fitptr)malloc(sizeof (struct ffit)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for fitting array.\n");
-        return(MEMORY_ERROR);
-    }
-    (*thisfit)->next  = (fitptr)0;
-    (*thisfit)->last  = (fitptr)0;
-    return(FINISHED);
-}
-
-/************************* NEW_FIT() *****************************
- *
- * Set up next fit in a list of motif-fits.
- */
-
-int new_fit(fitptr thisfit,fitptr *newfit)
-{
-    if((*newfit = (fitptr)malloc(sizeof (struct ffit)))==NULL) {
-        sprintf(errstr,"new_fit()\n");
-        return(PROGRAM_ERROR);
-    }
-    thisfit->next   = *newfit;
-    (*newfit)->last = thisfit;
-    (*newfit)->next = (fitptr)0;
-    return(FINISHED);
-}
-
-/********************** FIT_UNLINK() ******************************
- *
- * Deletes empty address space at end of fitlist.
- */
-
-int fit_unlink(fitptr thisfit)
-{
-    if(thisfit->last==(fitptr)0) {
-        sprintf(errstr,"Problem in fit_unlink()\n");
-        return(PROGRAM_ERROR);
-    }
-    thisfit = thisfit->last;
-    free(thisfit->next);
-    thisfit->next = (fitptr)0;
-    return(FINISHED);
-}
-
-/********************** FREE_FITLIST() ******************************
- *
- * Deletes fitlist, retaining head.
- */
-
-void free_fitlist(fitptr fithead)
-{
-    fitptr thisfit;
-    if((thisfit = fithead->next)==(fitptr)0)
-        return;
-    while(thisfit->next!=(fitptr)0) {
-        thisfit = thisfit->next;
-        free(thisfit->last);
-    }
-    free(thisfit);
-}
-
-/**************************** HFADJUST *********************************
- *
- * Pitch outside HS range. Adjust it.
- *
- * (1)  If this is a HS, there's nothing we can do about it. Return -1.0
- *      which will cause note to be deleted in calling environment.
- * (2)  If it's an HF however....
- *      Set newpitch at appropriate interval from original pitch.
- * (3)  If it's now above the HS
- * (4)  transpose it down by octaves until it is in the HS.
- * (5)  If still not in HS, mark for deletion.
- * (6)  If it's BELOW the HS.
- * (7)  transpose it up by octaves until it is in the HS.
- * (8)  If still not in HS, mark for deletion.
- * (9)  Return new pitch.
- */
-
-double hfadjust(double thispitch,double *hs,int x1,int x2,int texflag,int hsnotecnt)
-{
-    double newpitch;
-    if(texflag & IS_HS)
-        return(-1.0);                                                           /* 1 */
-    else {
-        newpitch = thispitch+hs[x1]-hs[x2];                     /* 2 */
-        if(newpitch > hs[hsnotecnt-1]) {                        /* 3 */
-            while(newpitch>hs[hsnotecnt-1])
-                newpitch -= SEMITONES_PER_OCTAVE;       /* 4 */
-            if(newpitch<hs[0])                                              /* 5 */
-                return(-1.0);
-        } else {
-            if(newpitch<hs[0]) {                                    /* 6 */
-                while(newpitch <hs[0])
-                    newpitch += SEMITONES_PER_OCTAVE;/* 7 */
-                if(newpitch>hs[hsnotecnt-1])
-                    return(-1.0);                                   /* 8 */
-            }
-        }
-    }
-    return(newpitch);                                                               /* 9 */
-}
-
-/**************************** CONVERT_PITCH_TO_NEAREST_HSET_PITCH *********************************
- *
- * Convert pitch value to nearest HS value.
- *
- * ignores the problem of note repetitions in the tset.
- * Note repetitions were only important where the tset notes were being
- * forced onto an HS. Here the HS values are being extracted so the notes
- * can be ornamented. The pitch values of the tset are NOT themselves altered.
- */
-
-int convert_pitch_to_nearest_hset_pitch(double thispitch,double *hs,int hsnotecnt)
-{
-    int n, m;
-    if(thispitch<hs[0]) {
-        if(hs[0] - thispitch > hs[1] - hs[0])
-            return(-1);
-        else
-            return(0);
-    }
-    n = 1;
-    m = n-1;
-    while(n<hsnotecnt) {
-        if(flteq(hs[n],thispitch))
-            return(n);
-        if(hs[n]>thispitch) {
-            if(hs[n] - thispitch > thispitch - hs[m])
-                return(m);
-            else
-                return(n);
-        }
-        n++;
-        m++;
-    }
-    if(hsnotecnt>1 && (thispitch - hs[hsnotecnt-1] > hs[hsnotecnt-1] - hs[hsnotecnt-2]))
-        return(-1);
-    return(hsnotecnt-1);
-}
-
-/**************************** HFADJ2 *********************************
- *
- * HFindex outside HS range. Adjust it.
- * Applies only to HF (i.e. an HS containing octave transpositions)
- * not to HS.
- */
-
-int hfadj2(int hsi,int hfnotecnt,int hsnotecnt)
-{
-    if(hsi<0) {
-        while(hsi<0)
-            hsi += hfnotecnt;
-    } else {
-        while(hsi>=hsnotecnt)
-            hsi -= hfnotecnt;
-    }
-    if(hsi<0 || hsi>=hsnotecnt)
-        return(-1);
-    return(hsi);
-}
-
-/**************************** SETUP_HFIELD *********************************/
-
-int setup_hfield(noteptr thisnote,double **hs,int *hsnotecnt,double **hf,int *hfnotecnt,int texflag)
-{
-    int exit_status;
-    if(texflag & IS_HS) {
-        if((exit_status = geths(thisnote,hs,hsnotecnt))<0)
-            return(exit_status);
-    } else {
-        if((exit_status = gethf(thisnote,hf,hfnotecnt))<0)                                      /* 2 */
-            return(exit_status);
-        if((exit_status = gen_hs(hf,hs,hsnotecnt,*hfnotecnt))<0)
-            return(exit_status);
-    }
-    return(FINISHED);
-}
-
-/**************************** SETUP_FIRST_HFIELD *********************************/
-
-int setup_first_hfield(noteptr thisnote,double **hs,int *hsnotecnt,double **hf,int *hfnotecnt,int texflag)
-{
-    int exit_status;
-    if(texflag & IS_HS) {
-        if((exit_status = get_first_hs(thisnote,hs,hsnotecnt))<0)
-            return(exit_status);
-    } else {
-        if((exit_status = get_first_hf(thisnote,hf,hfnotecnt))<0)                                       /* 2 */
-            return(exit_status);
-        if((exit_status = gen_hs(hf,hs,hsnotecnt,*hfnotecnt))<0)
-            return(exit_status);
-    }
-    return(FINISHED);
-}
-
-/**************************** GET_NEXT_HFIELD *********************************/
-
-int get_next_hfield(double **hf,double **hs,double inputtime,
-                    int *hf_cnt,int *hs_cnt,int *hfnotecnt,noteptr *thishfnote,double *thishftime,double *nexthftime,int hfdatacnt,
-                    int *hsnotecnt,noteptr *thishsnote,double *thishstime,double *nexthstime,double *hft,int texflag)
-{
-    if(texflag & IS_HS)
-        return getnexths(hs,inputtime,hs_cnt,hsnotecnt,thishsnote,thishstime,nexthstime,hfdatacnt,hft);
-    else
-        return getnexthf(hf,hs,hsnotecnt,inputtime,hf_cnt,hfnotecnt,thishfnote,thishftime,nexthftime,hfdatacnt,hft);
-}
-
-/**************************** SETUP_MOTIF_NOTE *********************************
- *
- * (1)  If the program is given a pitchrange OUTSIDE the bounds of the
- *              specified HF or HS, do_ev_hfpch() returns a -ve value. In this
- *              case, the associated tset note is marked for DELETION by setting
- *              the bitflag associated with the shadow (address) of the tset note.
- *              It will be deleted at the very end, by del_ghosts().
- */
-
-int setup_motif_note
-(double thisamp,int thisinstr,double thisdur,noteptr tsetnote,noteptr phrasenote,
- double *thispitch,double thistime,int *hsindex,int hsnotecnt,double *hs,
- double *pptop,double *ppbot,int *shadindex,char *shadbits,double multiplier,dataptr dz)
-{
-    int exit_status;
-    tsetnote->amp = (float)thisamp;
-    tsetnote->instr = (unsigned char)thisinstr;
-    if(dz->vflag[DONT_KEEP_MTFDUR])
-        tsetnote->dur = (float)thisdur;
-    else
-        tsetnote->dur = (float)(phrasenote->dur * multiplier);
-    if(flteq((double)tsetnote->dur,0.0)) {
-        sprintf(errstr,"setup_motif_note(): Zero duration\n");
-        return(PROGRAM_ERROR);
-    }
-    if((exit_status = do_ev_hfpch(thistime,hsindex,thispitch,hsnotecnt,hs,pptop,ppbot,dz))<0)
-        return(exit_status);
-    if(exit_status==CONTINUE) {
-        set_shadbit(*shadindex,shadbits);    /* 1 */
-        tsetnote = tsetnote->next;
-        (*shadindex)++;
-        return(CONTINUE);
-    }
-    tsetnote->pitch = (float)(*thispitch);
-    return(FINISHED);
-}
-
-/**************************** SETUP_GROUP_NOTE *********************************/
-
-int setup_group_note
-(double thisamp,int thisinstr,double thisdur,noteptr tsetnote,
- double *thispitch,double thistime,int *hsindex,int hsnotecnt,double *hs,
- double *pptop,double *ppbot,int *shadindex,char *shadbits,dataptr dz)
-{
-    int exit_status;
-    tsetnote->amp = (float)thisamp;
-    tsetnote->instr = (unsigned char)thisinstr;
-    tsetnote->dur = (float)thisdur;
-    if((exit_status = do_ev_hfpch(thistime,hsindex,thispitch,hsnotecnt,hs,pptop,ppbot,dz))<0)   /* 1 */
-        return(exit_status);
-    if(exit_status==CONTINUE) {
-        set_shadbit(*shadindex,shadbits);
-        tsetnote = tsetnote->next;
-        (*shadindex)++;
-        return(CONTINUE);
-    }
-    tsetnote->pitch = (float)(*thispitch);
-    return(FINISHED);
-}
-
-/**************************** SETUP_ORNAMENTATION *********************************/
-
-int setup_ornamentation
-(int *starthsi,int *endhsi,noteptr *nextevent,noteptr tsetnote,
- noteptr *phrasenote,int *shadindex,int *endhsindex,int *hfphrase,int phrno,dataptr dz)
-{
-    *starthsi  =  *hfphrase;
-    *endhsi    =  endhsindex[phrno];
-    *nextevent = getnextevent_to_decorate(tsetnote,shadindex,dz);
-    if(!dz->vflag[IS_PRE])
-        *phrasenote = (*phrasenote)->next;
-    return(FINISHED);
-}
-
-/**************************** GENERATE_MOTIF_NOTE_PITCH *********************************/
-
-int generate_motifin_note_pitch(int n,int hsindex,int starthsindex,int hsnotecnt,double thispitch,
-                                int *hfphrase,noteptr *thisnote,double *hs,int texflag)
-{
-    int notehsindex, thishsindex;
-    double newpitch;
-    notehsindex = *(hfphrase+n+1);
-    thishsindex = hsindex + notehsindex - starthsindex;
-    if(thishsindex<0 || thishsindex>=hsnotecnt) {
-        if((newpitch = hfadjust(thispitch,hs,notehsindex,starthsindex,texflag,hsnotecnt))<0.0) {
-            *thisnote = (*thisnote)->last;
-            free((*thisnote)->next);
-            return(CONTINUE);
-        } else
-            (*thisnote)->pitch = (float)newpitch;
-    } else
-        (*thisnote)->pitch=(float)hs[thishsindex];
-    return(FINISHED);
-}
-
-/**************************** GENERATE_MOTIF_NOTE_PITCH *********************************/
-
-int generate_motif_note_pitch(noteptr tsetnote,noteptr phrasenote,double phrfirstnote,noteptr thisnote)
-{
-    thisnote->pitch=(float)(tsetnote->pitch + phrasenote->pitch - phrfirstnote);
-    thisnote->pitch=(float)octadjust((double)thisnote->pitch);
-    return(FINISHED);
-}
-
-/**************************** GENERATE_ORNAMENT_NOTE_PITCH *********************************
- *
- * hsi = harmonic-set index.
- */
-
-int generate_ornament_note_pitch
-(int n,double *hs,int hsi, int endhsi,int starthsi,noteptr *thisnote,
- noteptr *phrasenote,int *hfphrase,int hfnotecnt,int hsnotecnt,dataptr dz)
-{
-    unsigned int texflag = dz->tex->txflag;
-    int thishsi, refhsi, notehsi;
-
-    if(dz->vflag[IS_PRE]) {
-        refhsi = endhsi;
-        notehsi = *(hfphrase+n);
-    } else {
-        refhsi = starthsi;
-        notehsi = *(hfphrase+n+1);
-    }
-    thishsi = hsi + notehsi - refhsi;
-    *phrasenote = (*phrasenote)->next;
-    if(thishsi<0 || thishsi>=hsnotecnt) {
-        if((texflag & IS_HS) || (thishsi=hfadj2(thishsi,hfnotecnt,hsnotecnt))<0) {
-            *thisnote = (*thisnote)->last;
-            free((*thisnote)->next);
-            return(CONTINUE);
-        }
-    }
-    (*thisnote)->pitch=(float)hs[thishsi];
-    return(FINISHED);
-}
-
-/********************** DO_EV_HFPCH *******************************
- *
- * Generate pitch of event (note group etc.) within HS.
- *
- * (2)  If getp_as_index() returns -1 , this means
- *      that the pitch range specified is outside the HS, so a value of
- *      -1.0 is returned to calling environment and tset note is DELETED!!
- */
-
-int do_ev_hfpch(double thistime,int *hsindex,double *val,int hsnotecnt,double *hs,double *pptop,double *ppbot,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getp_as_index(thistime,hsindex,hsnotecnt,hs,pptop,ppbot,dz))<0)
-        return(exit_status);
-    if(*hsindex==-1)                                /* a */
-        return(CONTINUE);                       /* 2 */
-    *val = hs[*hsindex];
-    return(FINISHED);
-}
-
-/****************************** GETP_AS_INDEX *********************************
- *
- * Get integer value of a hf-pitch index, using pitch either from table,
- * or fixed value.
- *
- * (1)  Read values of pitch-range limits from tables (or fixed vals).
- * (2)  If either of pitch values is negative, if it's from a table,
- *      reject it....
- * (3)  But otherwise it can be regarded as a flag. Return -1 causing
- *      the INPUT pitch to be converted to a HS pitch and returned.
- * (4)  Check that range is not inverted.
- * (5)  Get the note in HS which is >  upper pitch boundary. If all HS notes
- *      are above this (function returns 0) return -1.
- *      If all HS notes are BELOW this pitch, function returns hsnotecnt,
- *      wehich forces upper limit of HSindex generated by doperm() to be
- *      hsnotecnt-1, the highest pitch in the HS.
- * (6)  Get the note in HS which is >= lower pitch boundary. If there
- *      is no such note (function returns hsnotecnt) return -1.
- * (7)  Return a weighted scattered value of hf-index, within the
- *      defined range.
- */
-
-int getp_as_index(double thistime,int *val,int hsnotecnt,double *hs,double *pptop,double *ppbot,dataptr dz)
-{
-    int exit_status;
-    int  a, b;
-    double range;
-    if(dz->brk[TEXTURE_MAXPICH]) {                                          /* 1 */
-        if((exit_status = read_value_from_brktable(thistime,TEXTURE_MAXPICH,dz))<0)
-            return(exit_status);
-    }
-    if(dz->brk[TEXTURE_MINPICH]) {
-        if((exit_status = read_value_from_brktable(thistime,TEXTURE_MINPICH,dz))<0)
-            return(exit_status);
-    }
-    *pptop = dz->param[TEXTURE_MAXPICH];
-    *ppbot = dz->param[TEXTURE_MINPICH];
-    if((range = dz->param[TEXTURE_MAXPICH] - dz->param[TEXTURE_MINPICH])<0.0)               /* 4 */
-        swap (&dz->param[TEXTURE_MAXPICH],&dz->param[TEXTURE_MINPICH]);
-    if((a = geths_above(dz->param[TEXTURE_MAXPICH],hs,hsnotecnt))==0) {                             /* 5 */
-        *val = -1;
-        return(FINISHED);
-    }
-    if((b = geths_hibnd(dz->param[TEXTURE_MINPICH],hsnotecnt,hs))>=hsnotecnt) {             /* 6 */
-        *val = -1;
-        return(FINISHED);
-    }
-    if((exit_status = hfscat(a-b,b,PM_PITCH,&a,dz))<0)      /* 7 */
-        return(exit_status);
-    if( a < 0 || a >= hsnotecnt) {                  /* 7 */
-        sprintf(errstr,"TEXTURE: getp_as_index(): TW's logic of index generation wrong\n");
-        return(DATA_ERROR);
-    }
-    *val = a;
-    return(FINISHED);
-}
-
-/**************************** INIT_SHADBITS ****************************
- *
- * Set up, and initialise to zero, a bitflag with one bit for each shadow
- * (tset address).
- */
-
-int init_shadbits(int shadowsize,int *shshsize,char **shadbits)
-{
-    int n = shadowsize;
-    *shshsize = 1;
-    while((n -= CHARBITSIZE)>0)
-        (*shshsize)++;
-    if((*shadbits = (char *)malloc((size_t)(*shshsize)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for shadwoing array.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0; n<(*shshsize); n++)
-        (*shadbits)[n] = 0;
-    return(FINISHED);
-}
-
-/****************************** GETHS ***********************************
- *
- * Extract HS from input data.
- */
-
-int geths(noteptr thisnote,double **hs,int *hsnotecnt)
-{
-    int exit_status;
-    int size = BIGARRAY;
-    if((*hs = (double *)malloc(BIGARRAY * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic set array.\n");
-        return(MEMORY_ERROR);
-    }
-    while(thisnote!=(noteptr)0) {
-        if((exit_status = gethsnote(thisnote->pitch,*hs,hsnotecnt))<0)
-            return(exit_status);
-        if(*hsnotecnt >= BIGARRAY) {
-            size += BIGARRAY;
-            if((*hs=(double *)realloc((char *)(*hs),size * sizeof(double)))==NULL){
-                sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic set array.\n");
-                return(MEMORY_ERROR);
-            }
-        }
-        thisnote = thisnote->next;
-    }
-    if((*hs=(double *)realloc((char *)(*hs),*hsnotecnt*sizeof(double)))==NULL){
-        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic set array.\n");
-        return(MEMORY_ERROR);
-    }
-    upsort(*hs,*hsnotecnt);
-    return(FINISHED);
-}
-
-/****************************** GETHF ***********************************
- *
- * Extract HF from input data.
- */
-
-int gethf(noteptr thisnote,double **hf,int *hfnotecnt)
-{
-    int exit_status;
-    int size = BIGARRAY;
-    if((*hf = (double *)malloc(size * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic field array.\n");
-        return(MEMORY_ERROR);
-    }
-    while(thisnote!=(noteptr)0) {
-        if((exit_status = gethfnote(thisnote->pitch,*hf,hfnotecnt))<0)
-            return(exit_status);
-        if(*hfnotecnt >= size) {
-            size += BIGARRAY;
-            if((*hf = (double *)realloc((char *)(*hf),size * sizeof(double)))==NULL){
-                sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic field array.\n");
-                return(MEMORY_ERROR);
-            }
-        }
-        thisnote = thisnote->next;
-    }
-    if((*hf=(double *)realloc((char *)(*hf),*hfnotecnt * sizeof(double)))==NULL){
-        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic field array.\n");
-        return(MEMORY_ERROR);
-    }
-    upsort(*hf,*hfnotecnt);
-    return(FINISHED);
-}
-
-/****************************** GEN_HS ***********************************
- *
- * Generate HS from a HF.
- *
- * NB This function assumes thas HF is ordered in ascending pitch order.
- *
- * (1)  Eliminate octave dupliates in hf.
- * (2)  Initialise the HS count to zero.
- * (3)  Start in the lowest octave.
- * (4)  Go round loop generating HS, until we're out of (MIDI) range.
- * (5)  Each time round loop, point to start of HF.
- * (6)  And for all HF members, put them in HS + a (loop) number of 8ves,
- *      counting the HS as we go.
- * (7)  Once the pitch of any note exceeds MIDI upper limit (MIDITOP), break
- *      from inner and (OK=0) outer loops.
- * (8)  Each time round outer loop, increment octave.
- * (9)  Reallocate the HS to the store 'hs'
- */
-
-int gen_hs(double **hf,double **hs, int *hsnotecnt, int hfnotecnt)
-{
-    int n, m, k, thisoct, OK = 1;
-    int size = BIGARRAY;
-    double nextpitch;
-    double *thishf;
-    if((*hs)!=(double *)0)
-        free(*hs);
-    if((*hs = (double *)malloc(size * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic set array.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n<hfnotecnt-1;n++) {            /* 1 */
-        for(m=n+1;m<hfnotecnt;m++) {
-            if(octeq((*hf)[n],(*hf)[m])) {
-                k = m + 1;
-                while(k < hfnotecnt) {
-                    (*hf)[k-1] = (*hf)[k];
-                    k++;
-                }
-                hfnotecnt--;
-                m--;
-            }
-        }
-    }
-    *hsnotecnt = 0;                                                 /* 2 */
-    thisoct = 0;                                            /* 3 */
-    while(OK) {                                                     /* 4 */
-        thishf = *hf;                                           /* 5 */
-        for(n=0;n<hfnotecnt;n++) {                                      /* 6 */
-            if((nextpitch = (*thishf++)+((double)thisoct*SEMITONES_PER_OCTAVE))<=MIDITOP) {
-                (*hs)[(*hsnotecnt)++] = nextpitch;
-                if(*hsnotecnt>=size) {
-                    size += BIGARRAY;
-                    if((*hs =(double *)realloc((char *)(*hs),size * sizeof(double)))==NULL) {
-                        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic set array.\n");
-                        return(MEMORY_ERROR);
-                    }
-                }
-            } else {
-                OK = 0;                                         /* 7 */
-                break;
-            }
-        }
-        thisoct++;                                              /* 8 */
-    }
-    if((*hs=(double *)realloc((char *)(*hs),*hsnotecnt * sizeof(double)))==NULL){
-        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic set array.\n");
-        return(MEMORY_ERROR);
-    }
-    return(FINISHED);
-}
-
-/**************************** CHEKREPEAT *********************************
- *
- * Flag if there is a repeated note in the source data.
- */
-
-int chekrepeat(noteptr thisnote,double lastpitch)
-{
-    if(flteq((double)thisnote->pitch,lastpitch))
-        return(TRUE);
-    return(FALSE);
-}
-
-/****************************** GETNEXTHF ***********************************
- *
- * Get the harmonic field pertaining to this time, + 'hfnotecnt'.
- *
- * NB 2: THIS FUNCTION ASSUMES IN WILL BE ACCESSED IN TIME-INCREASING ORDER.
- *
- * (1)  Current time preset to zero.
- * (2)  Nexttime to time of next hf in hf_data_motif.
- * (3)  Static pointer points into current place in hf_data_motif.
- * (3a) If noteptr points to zero w'ere
-        EITHER  we're at end of notelist: therefore no more HF data,
-                hence retain existing data.
-        OR      we have not initialised the noteptr, which should happen
-                on first call to this function, BUT in this case the
-                hfnotecnt will be zero as we have not yet created an HF.
-                In this case, error, exit.
-                * (4)  If time of function access still less than time of entry of next
-                *      harmonic field, do nothing (i.e. stay with current hf returning
-                *      current hfnotecnt).
-                * (5)  If time of function access is after time of next harmonic field
-                *      advance down hfs, until TOFA is before next hf (NB last time in
-                *      the hft[] is AFTER end of texture duration).
-                * (6)  Establish temporary storage space to read a new hf, and set the
-                *      hf pointer 'thishf' to point to it.
-                * (7)  Walk through the input notes until we get to notes corresponding
-                *      to time of the hf we want.
-                * (8)  Store the harmonic field in the temporary array.
-                * (9)  Free any existing hf.
-                * (10) Reallocate the new hf to the array hf[], and set the hf pointer
-                *      'thishf' to point at it.
-                * (11) Generate the associated HS !!!
-                */
-
-int getnexthf
-(double **hf,double **hs, int *hsnotecnt,double inputtime,int *hf_cnt,int *hfnotecnt,
- noteptr *thishfnote,double *thishftime,double *nexthftime,int hfdatacnt,double *hft)
-{
-    int exit_status;
-    int size = BIGARRAY;
-    if(*thishfnote==(noteptr)0) {                                   /* 3a */
-        if(*hfnotecnt==0) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for hfield notecount array.\n");
-            return(PROGRAM_ERROR);
-        }
-        return(TRUE);
-    }
-    if(inputtime<*nexthftime)                                       /* 4 */
-        return(FALSE);
-    while(*nexthftime<=inputtime) {                         /* 5 */
-        if(*hf_cnt>=hfdatacnt) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for hfield count array.\n");
-            return(PROGRAM_ERROR);
-        }
-        *thishftime = *nexthftime;
-        *nexthftime = hft[*hf_cnt];
-        (*hf_cnt)++;
-    }
-    if(*hf!=(double *)0)                                            /* 9 */
-        free(*hf);
-    if((*hf = (double *)malloc(size * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for hfield array.\n");
-        return(MEMORY_ERROR);
-    }
-    while(!flteq((double)(*thishfnote)->ntime,*thishftime)) {               /* 7 */
-        if((*thishfnote = (*thishfnote)->next)==(noteptr)0) {
-            sprintf(errstr,"TEXTURE: Search problem in getnexthf()\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    *hfnotecnt = 0;
-    while(flteq((double)(*thishfnote)->ntime,*thishftime)) {                /* 8 */
-        if((exit_status = gethfnote((*thishfnote)->pitch,*hf,hfnotecnt))<0)
-            return(exit_status);
-        if(*hfnotecnt >= size) {
-            size += BIGARRAY;
-            if((*hf = (double *)realloc((char *)(*hf),size * sizeof(double)))==NULL) {
-                sprintf(errstr,"TEXTURE: realloc failed in getnexthf()\n");
-                return(PROGRAM_ERROR);
-            }
-        }
-        if((*thishfnote = (*thishfnote)->next)==(noteptr)0)
-            break;
-    }
-    if((*hf=(double *)realloc((char *)(*hf),*hfnotecnt * sizeof(double)))==NULL){
-        sprintf(errstr,"TEXTURE: getnexthf(): realloc() failed\n");     /* 10 */
-        return(PROGRAM_ERROR);
-    }
-    upsort(*hf,*hfnotecnt);
-    if((exit_status = gen_hs(hf,hs,hsnotecnt,*hfnotecnt))<0)  /* 11 */
-        return(exit_status);
-    return(TRUE);
-}
-
-/****************************** GETNEXTHS ***********************************
- *
- * Get the harmonic set pertaining to this time.
- *
- * NB 2: THIS FUNCTION ASSUMES IT WILL BE ACCESSED IN TIME-INCREASING ORDER.
- *
- * (3)  Static pointer points into current place in hf_data_motif.
- * (3a) If noteptr points to zero w'ere
-        EITHER  we're at end of notelist: therefore no more HF data,
-                hence retain existing data.
-        OR      we have not initialised the noteptr, which should happen
-                on first call to this function, BUT in this case the
-                hsnotecnt will be zero as we have not yet created an HS.
-                In this case, error, exit.
-                * (4)  If time of function access still less than time of entry of next
-                *      harmonic set, do nothing (i.e. stay with current hs returning
-                *      current harmonic set cnt hsnotecnt).
-                * (5)  If time of function access is after time of next harmonic set
-                *      advance down HSs, until TOFA is before next hs (NB last time in
-                *      the hft[] is AFTER end of texture duration).
-                * (6)  Establish temporary storage space to read a new hs, and set the
-                *      hs pointer 'thishs' to point to it.
-                * (7)  Walk through the input notes until we get to notes corresponding
-                *      to time of the hs we want.
-                * (8)  Store the harmonic set in the temporary array.
-                * (9)  Free any existing hs.
-                * (10) Reallocate the new hs to the array hs[], and set the hs pointer
-                *      'thishs' to point at it.
-                */
-
-int getnexths
-(double **hs,double inputtime,int *hs_cnt,int *hsnotecnt,noteptr *thishsnote,
- double *thishstime,double *nexthstime,int hfdatacnt,double *hft)
-{
-    int exit_status;
-    int size = BIGARRAY;
-    if(*thishsnote==(noteptr)0) {                           /* 3a */
-        if(*hsnotecnt==0) {
-            sprintf(errstr,"getnexths() not initialised\n");
-            return(PROGRAM_ERROR);
-        }
-        return(TRUE);
-    }
-    if(inputtime<*nexthstime)                                       /* 4 */
-        return(FALSE);
-    while(*nexthstime<=inputtime) {                         /* 5 */
-        if(*hs_cnt>=hfdatacnt) {
-            sprintf(errstr,"Timing problem in getnexths()\n");
-            return(PROGRAM_ERROR);
-        }
-        *thishstime = *nexthstime;
-        *nexthstime = hft[*hs_cnt];
-        (*hs_cnt)++;
-    }
-    if(*hs!=(double *)0)                                            /* 9 */
-        free(*hs);
-    if((*hs = (double *)malloc(size * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic set array.\n");
-        return(MEMORY_ERROR);
-    }
-
-    while(!flteq((double)(*thishsnote)->ntime,*thishstime)) {                       /* 7 */
-        if((*thishsnote = (*thishsnote)->next)==(noteptr)0) {
-            sprintf(errstr,"TEXTURE: Search problem in getnexths()\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    *hsnotecnt = 0;
-    while(flteq((double)(*thishsnote)->ntime,*thishstime)) {                        /* 8 */
-        if((exit_status = gethsnote((*thishsnote)->pitch,*hs,hsnotecnt))<0)
-            return(exit_status);
-        if(*hsnotecnt >= size) {
-            size += BIGARRAY;
-            if((*hs =(double *)realloc((char *)(*hs),size * sizeof(double)))==NULL) {
-                sprintf(errstr,"TEXTURE: realloc failed in getnexths()\n");
-                return(PROGRAM_ERROR);
-            }
-        }
-        if((*thishsnote = (*thishsnote)->next)==(noteptr)0)
-            break;
-    }
-    if((*hs=(double *)realloc((char *)(*hs),*hsnotecnt * sizeof(double)))==NULL){
-        sprintf(errstr,"TEXTURE: getnexths(): realloc() failed\n");/* 10 */
-        return(PROGRAM_ERROR);
-    }
-    upsort(*hs,*hsnotecnt);
-    return(TRUE);
-}
-
-/***************************** GETHSNOTE ************************************
- *
- * Read a note and store in harmonic SET,  IF not already there.
- */
-
-int gethsnote(double thispitch,double *thishs,int *hsnotecnt)
-{
-    int n, OK = 0;
-    for(n=0;n<*hsnotecnt;n++) {
-        if(flteq(thispitch,thishs[n])) {
-            OK = 1;
-            break;
-        }
-    }
-    if(!OK)
-        thishs[*hsnotecnt] = (double)thispitch;
-    (*hsnotecnt)++;
-    return(FINISHED);
-}
-
-/***************************** READHFTIMES ************************************
- *
- * Read times at which successive harmonic fields(sets) enter, and store as list.
- */
-
-int readhftimes(noteptr firstnote, int *hfdatacnt,double **hft)
-{
-    double lasttime, firsttime;
-    int arraysize = BIGARRAY;
-    noteptr thisnote = firstnote;
-    *hfdatacnt = 0;
-    if((*hft = (double *)malloc(arraysize * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic field times array.\n");
-        return(MEMORY_ERROR);
-    }
-    lasttime = thisnote->ntime;
-    (*hft)[0] = lasttime;
-    while(thisnote!=(noteptr)0) {
-        if(!flteq((double)thisnote->ntime,lasttime)) {
-            if(++(*hfdatacnt)>=arraysize-1) {
-                arraysize += BIGARRAY;
-                if((*hft = (double *)realloc((char *)(*hft),arraysize * sizeof(double)))==NULL) {
-                    sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic field times array.\n");
-                    return(PROGRAM_ERROR);
-                }
-            }
-            (*hft)[*hfdatacnt] = thisnote->ntime;
-            lasttime = thisnote->ntime;
-        }
-        thisnote = thisnote->next;
-    }
-    (*hft)[++(*hfdatacnt)] = DBL_MAX;                                       /* 1 */
-    (*hfdatacnt)++;
-    if((*hft = (double *)realloc((char *)(*hft),(*hfdatacnt) * sizeof(double)))==NULL){
-        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic field times array.\n");
-        return(PROGRAM_ERROR);
-    }
-    if(!flteq(**hft,0.0)) {
-        fprintf(stdout,"WARNING: Harmonic Field Data: No field at ZERO time.\n"
-                "ADJUSTING FIRST FIELD TO ZERO TIME\n");
-        fflush(stdout);
-        thisnote  = firstnote;
-        firsttime = thisnote->ntime;
-        while(flteq(firsttime,**hft)) {
-            thisnote->ntime = 0.0f;
-            if((thisnote = thisnote->next)==(noteptr)0)
-                break;
-        }
-        **hft = 0.0;
-    }
-    return(FINISHED);
-}
-
-/***************************** DEL_GHOSTS ******************************
- *
- * Delete all tset notes MARKED for deletion in shadbits bitflag.
- *
- * (1)  For each byte in the bitflag...
- * (2)  Set the bitmask to the first bit.
- *   (3)  For every bit in this byte....
- *   (4)  If this bit is set, delete the associated shadow (tset) note.
- *   (5)  Advance the bitflag internal to the byte leftwards.
- *   (6)  Advance the count of shadows, and if it reaches the total number
- *        of shadows, exit, because remaining bits in this byte (if any)
- *        have no meaning.
- */
-
-void del_ghosts(int shshsize,char *shadbits,noteptr *shadow,int shadowsize,motifptr tset)
-{
-    int n,m,mask,k = 0;
-    for(n=0;n<shshsize;n++) {                               /* 1 */
-        mask = 1;                                                       /* 2 */
-        for(m=0;m<CHARBITSIZE;m++) {            /* 3 */
-            if(shadbits[n] & mask)                  /* 4 */
-                del_note(shadow[k],tset);
-            mask <<= 1;                                             /* 5 */
-            if(++k >= shadowsize)                   /* 6 */
-                return;
-        }
-    }
-}
-
-/************************** GET_HFGPPARAMS **************************
- *
- * Get the parameters for a group of notes.
- *
- * (0)  If pitch to decorate lies outside the HF range, return with gpsize
- *      set to zero.
- * (1)  If group range is expressed in HS-note units..
- *   (a) Read the gprange as an integer number of (HS) notes.
- *   (b) If HS-range exceeds HS limits, squeeze it.
- *   (c) If HS-range is to be oriented about note, orient it appropriately.
- * (2)  Otherwise...
- *   (a) Read group range in normal way.
- *   (b) If range exceeds HS limits, squeeze it.
- *   (c) If range is to be oriented about note, orient it appropriately.
- *   (d) If the range lies outside range of the HS,
- *       set the groupsize to ZERO and return.
- *   (e) Otherwise set the HS-range.
- * (3)  Read group size.
- * (4)  Read group density.
- * (5)  number of midicliks in a gpdense time-interval.
- * (6)  number of quantisation units, rounded.
- * (7)  readjust gpdense to be number of units * length of units,
- *      and reconvert to seconds.
- */
-
-int get_hfgpparams(double thistime,double thispitch,double *hs,int hsnotecnt,
-                   int *gpsize,int *hfrange,int *hfgpranglo,int *hfgpranghi,double *gprange,double *gpdense,int mingrpsize,
-                   double *gprlow, int dectypecnt,unsigned char dectypestor,dataptr dz)
-{
-    int exit_status;
-    if(thispitch<hs[0] || thispitch>hs[hsnotecnt-1]) {
-        *gpsize = 0;                                            /* 0 */
-        return(FINISHED);
-    }
-    if((exit_status = igetvalue(TEX_GPRANGHI,TEX_GPRANGLO,thistime,PM_GPRANG,hfrange,dz))<0)
-        return(exit_status);
-
-    if(!dectypecnt) {
-        hfsqueezrange(thispitch,hfrange,hfgpranghi,hfgpranglo,hsnotecnt,hs);                                    /* b */
-        dz->vflag[DECCENTRE] = FALSE;
-    } else {
-        if((exit_status = hforientrange
-            (thispitch,hfrange,hfgpranghi,hfgpranglo,hsnotecnt,hs,dectypecnt,dectypestor,dz))<0) /* c */
-            return(exit_status);
-    }
-    /* OCT 17 : hfgpranghi,lo are max & min INDECES within the harmonic field */
-
-    *hfrange = *hfgpranghi - *hfgpranglo;                   /* e */
-
-    /* OCT 17 : FROM hfgpranghi,lo the actual PITCH values can be deduced */
-    *gprlow  = hs[*hfgpranglo];
-    *gprange = hs[*hfgpranghi] - hs[*hfgpranglo];
-
-    if((exit_status  = igetvalue(TEX_GPSIZEHI,TEX_GPSIZELO,thistime,PM_GPSIZE,gpsize,dz))<0)
-        return(exit_status);
-
-    if(*gpsize  < mingrpsize) {
-        sprintf(errstr,"TEXTURE: Impossible GROUP SIZE value [%d]: get_hfgpparams()\n",*gpsize);
-        return(PROGRAM_ERROR);
-    }
-
-    if((exit_status = getvalue(TEX_GPPACKHI,TEX_GPPACKLO,thistime,PM_GPDENS,gpdense,dz))<0)
-        return(exit_status);
-    /* NEW MAR 2000 */
-    *gpdense *= MS_TO_SECS;
-
-    if(dz->param[TEX_PHGRID]>0.0)
-        *gpdense = quantise(*gpdense,dz->param[TEX_PHGRID]);
-    return(FINISHED);
-}
-
-/***************************  HFSQUEEZRANGE ******************************
- *
- * Adjust range to lie within HF limits.
- *
- * (2)  Top of range is at current pitch's HF index (approx). If this is
- *      above current top-of-HF range (hsnotecnt) move top down.
- * (3)  Bottom of range is igprange below top. If this is below
- *      bottom-of-HF (0), move igprlow up.
- * (4)  Recalculate the true igprange within true limits.
- */
-
-void hfsqueezrange(double thispitch,int *hfrange,int *hfgpranghi,int *hfgpranglo,int hsnotecnt,double *hs)
-{
-    int halfrange = *hfrange/2;
-    if(halfrange * 2 != *hfrange)
-        halfrange++;
-    *hfgpranghi = min((geths_hibnd(thispitch,hsnotecnt,hs)+halfrange),hsnotecnt);   /* 2 */
-    *hfgpranglo = max((*hfgpranghi - *hfrange),0);                                                  /* 3 */
-    *hfrange = *hfgpranghi - *hfgpranglo;                                                                   /* 4 */
-}
-
-/****************************** GETHS_HIBND **********************************
- *
- *      hibnd >= pitch
- *
- * Find the index of the harmonic-set note that is immediately above or
- * equal to the input pitch.
- *
- * NB CALL WITH geths_hibnd((double)thisnote->pitch);
- *
- * If the pitch is beyond the HS, n returns the value 'hsnotecnt'.
- */
-
-int geths_hibnd(double thispitch,int hsnotecnt,double *hs)
-{
-    int n;
-    for(n=0;n<hsnotecnt;n++) {
-        if(hs[n]>thispitch || flteq(hs[n],thispitch))
-            break;
-    }
-    return(n);                              /* 1 */
-}
-
-/***************************  HFORIENTRANGE ******************************
- *
- * As orientrange() but applied to HF/HS case.
- */
-
-int hforientrange
-(double thispitch,int *hfrange,
- int *hfgpranghi,int *hfgpranglo,int hsnotecnt,double *hs,int dectypecnt,unsigned char dectypestor,dataptr dz)
-{
-    int exit_status;
-    unsigned char dectype;
-    int k;
-    if((exit_status=doperm((int)dectypecnt,PM_ORIENT,&k,dz))<0)
-        return(exit_status);
-    if((exit_status=gettritype(k,dectypestor,&dectype))<0)
-        return(exit_status);
-    switch(dectype) {
-    case(0):                        /* centred range */
-        hfsqueezrange(thispitch,hfrange,hfgpranghi,hfgpranglo,hsnotecnt,hs);
-        dz->vflag[DECCENTRE] = TRUE;
-        break;
-    case(1):                        /* range above note */
-        *hfgpranghi = min((geths_hibnd(thispitch,hsnotecnt,hs) + *hfrange),hsnotecnt);
-        *hfgpranglo = max((*hfgpranghi - *hfrange),0);
-        *hfrange    = *hfgpranghi - *hfgpranglo;
-        dz->vflag[DECCENTRE] = FALSE;
-        break;
-    case(2):                        /* range below note */
-        *hfgpranghi = geths_hibnd(thispitch,hsnotecnt,hs);
-        *hfgpranglo = max((*hfgpranghi - *hfrange),0);
-        *hfrange    = *hfgpranghi - *hfgpranglo;
-        dz->vflag[DECCENTRE] = FALSE;
-        break;
-    default:
-        sprintf(errstr,"TEXTURE: Problem in hforientrange()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/****************************** GETHS_ABOVE **********************************
- *
- *      above > pitch
- *
- * Find the index of the harmonic-set note that is immediately above
- * the input pitch.
- *
- * NB CALL WITH geths_above((double)thisnote->pitch);
- *
- * If the pitch is beyond the HS, n gets the value 'hsnotecnt', which becomes
- * the upper limit of the search range for doperm() ensuring that highest
- * possible HSindex val is hsnotecnt-1, the highest pitch in the HS.
- */
-
-int geths_above(double thispitch,double *hs,int hsnotecnt)
-{
-    int n;
-    for(n=0;n<hsnotecnt;n++) {
-        if(hs[n]>thispitch)
-            break;
-    }
-    return(n);                                      /* 1 */
-}
-
-/****************************** GENERATE_GROUP_NOTE **********************************/
-
-int generate_group_note
-(noteptr thisnote,noteptr tsetnote,double thistime,int hfrange,int hfgpranglo,
- double *hs,int *hsindex,int gpsize,dataptr dz)
-{
-    int exit_status;
-    unsigned char thisinstr;
-    if((exit_status = do_grp_ins(tsetnote->instr,&thisinstr,dz))<0)
-        return(exit_status);
-    thisnote->instr = thisinstr;
-    thisnote->motioncentre = tsetnote->motioncentre;
-    if((exit_status = hfscat(hfrange,hfgpranglo,PM_GPPICH,hsindex,dz))<0)
-        return(exit_status);
-    thisnote->pitch  = (float)hs[*hsindex];         /* 7 */
-    thisnote->ntime  = (float)thistime;
-    return setspace(tsetnote,thisnote,gpsize,dz);
-}
-
-/******************************* HFSCAT ***********************************
- *
- * A weighted version of hfscatx().
- */
-
-int hfscat(int prange,int pbottom,int permindex,int *val,dataptr dz)
-{
-    int exit_status;
-    double bandbottom,  bandtop,  bandwidth;
-    int   ibandbottom, ibandtop, ibandwidth, k;
-    if(prange<=LAYERCNT) {
-        if((exit_status = doperm((int)prange,permindex,&k,dz))<0)
-            return(exit_status);
-        *val = k + pbottom;
-        return(FINISHED);
-
-    }
-    if((exit_status = doperm((int)BANDCNT,permindex,&k,dz))<0)
-        return(exit_status);
-    bandwidth = (double)prange/(double)LAYERCNT;
-    switch(k) {
-    case(0):
-        bandbottom = 0;
-        break;
-    case(BANDCNT-1):
-        bandbottom = (double)(LAYERCNT-1) * bandwidth;
-        break;
-    default:
-        bandbottom = bandwidth + ((double)((k-1) * 2) * bandwidth);
-        bandwidth *= 2.0;
-        break;
-    }
-    bandtop     = bandbottom + bandwidth;
-    ibandtop    = round(bandtop);
-    ibandbottom = round(bandbottom);
-    ibandwidth  = ibandtop - ibandbottom;
-    k  = (int)(drand48() * (double)ibandwidth);
-    k += ibandbottom;
-    k += pbottom;
-    *val = k;
-    return(FINISHED);
-}
-
-/****************************** GENERATE_DECOR_NOTE **********************************/
-
-int generate_decor_note(noteptr thisnote,noteptr tsetnote,
-                        double thispitch,double thistime,int hfrange,int hfgpranghi,int hfgpranglo,double *hs,int *hsindex,
-                        int hsnotecnt,double gprlow,double gprange,int gpsize,dataptr dz)
-{
-    int exit_status;
-    double val;
-    if((exit_status = do_grp_ins(tsetnote->instr,&thisnote->instr,dz))<0)
-        return(exit_status);
-    thisnote->motioncentre = tsetnote->motioncentre;
-    if(dz->vflag[DECCENTRE]) {
-        if((exit_status = dec_hfcentre
-            (thispitch,hs,hsnotecnt,hfrange,hfgpranghi,hfgpranglo,gprlow,gprange,gpsize,&val,dz))<0)
-            return(exit_status);
-        thisnote->pitch = (float)val;
-    } else {
-        if((exit_status = hfscat(hfrange,hfgpranglo,PM_GPPICH,hsindex,dz))<0)
-            return(exit_status);
-        thisnote->pitch  = (float)hs[*hsindex];
-    }
-    thisnote->ntime  = (float)(thistime);
-    return setspace(tsetnote,thisnote,gpsize,dz);
-}
-
-/************************* DEC_HFCENTRE *******************************/
-
-int dec_hfcentre(double tsetpitch,double *hs,int hsnotecnt,int hfrange,int hfgpranghi,int hfgpranglo,
-                 double gprlow,double gprange,int gpsize,double *val,dataptr dz)
-{
-    int exit_status;
-    double a, gprhi = gprlow + gprange;
-    int s, save, k, hfcentre, n_above, n_below, hsindex;
-    if(tsetpitch-gprlow<=FLTERR || flteq(tsetpitch,gprhi)) {
-        if((exit_status = hfscatx(hfrange,hfgpranglo,PM_GPPICH,&hsindex,dz))<0)
-            return(exit_status);
-        *val = hs[hsindex];
-        return(FINISHED);                                       /* 1 */
-    }
-    n_below = hfrange/2;                                    /* 2 */
-    if(((n_above=n_below)+n_below)!=hfrange)
-        n_above++;
-    if(((hfcentre =geths_hibnd(tsetpitch,hsnotecnt,hs)) + n_above) > hsnotecnt)
-        n_above = hsnotecnt - hfcentre;                         /* 3 */
-    if(hfcentre - n_below < 0)
-        n_below = hfcentre;                                     /* 4 */
-    if(n_above<=0 || n_below<=0) {
-        if((exit_status = hfscatx(hfrange,hfgpranglo,PM_GPPICH,&hsindex,dz))<0)
-            return(exit_status);
-        else {
-            *val = hs[hsindex];
-            return(FINISHED);                                       /* 5 */
-        }
-    }
-    save = dz->iparray[TXREPETCNT][PM_DECABV];                                              /* 6 */
-    k = (gpsize+1)/2;
-    if(dz->iparray[TXREPETCNT][PM_DECABV]>k)
-        dz->iparray[TXREPETCNT][PM_DECABV] = k;
-    if((exit_status = doperm((int)2,PM_DECABV,&s,dz))<0)
-        return(exit_status);
-    if(s) {
-        if((exit_status = hfscatx(n_above,hfgpranghi - n_above,PM_GPPICH,&hsindex,dz))<0)
-            return(exit_status);
-    } else {
-        if((exit_status = hfscatx(n_below,hfgpranglo,PM_GPPICH2,&hsindex,dz))<0)
-            return(exit_status);
-    }
-    dz->iparray[TXREPETCNT][PM_DECABV] = save;
-    a = hs[hsindex];
-    if(a<MIDIBOT || a>MIDITOP) {
-        sprintf(errstr,"TEXTURE: Problem in dec_hfcentre()\n");
-        return(PROGRAM_ERROR);
-    }
-    *val = a;
-    return(FINISHED);
-}
-
-/******************************* HFSCATX ***********************************
- *
- * As pscat, but working with ranges of integers, especially the indeces
- * of an HS.
- */
-
-int hfscatx(int prange,int pbottom,int permindex,int *val,dataptr dz)
-{
-    int exit_status;
-    double bandbottom,  bandtop,  bandwidth;
-    int   ibandbottom, ibandtop, ibandwidth, k;
-    if(prange<=BANDCNT) {
-        if((exit_status = doperm((int)prange,permindex,val,dz))<0)
-            return(exit_status);
-        *val += pbottom;
-        return(FINISHED);
-    }
-    if((exit_status = doperm((int)BANDCNT,permindex,val,dz))<0)
-        return(exit_status);
-    k = *val;
-    bandwidth   = (double)prange/(double)BANDCNT;
-    bandbottom  = (double)k     * bandwidth;
-    bandtop     = (double)(k+1) * bandwidth;
-    ibandbottom = round(bandbottom);
-    ibandtop    = round(bandtop);
-    ibandwidth  = ibandtop - ibandbottom;
-    k  = (int)(drand48() * (double)ibandwidth);
-    k += ibandbottom;
-    *val = k + pbottom;
-    return(FINISHED);
-}
-
-/******************************** SET_SHADBIT ****************************
- *
- * Set a bit in the shadow's bitfag.
- */
-
-void set_shadbit(int k,char *shadbits)
-{
-    int bitunit  = k/CHARBITSIZE;
-    int bitshift = k % 8;
-    int mask = 1;
-    mask <<= bitshift;
-    shadbits[bitunit] |= mask;
-}
-
-/****************************** GETHS_LOBND **********************************
- *
- *      lobnd =< pitch
- *
- * Find the index of the harmonic-set note that is immediately below, or
- * equal to the input pitch.
- *
- * NB CALL WITH geths_lobnd((double)thisnote->pitch);
- *
- * NB: If the entered pitch is lower than the entire HS, function returns -1.
- */
-
-int geths_lobnd(double thispitch,double *hs,int hsnotecnt)
-{
-    int n;
-    for(n=0;n<hsnotecnt;n++) {
-        if(hs[n]>thispitch)
-            break;
-    }
-    return(--n);                                    /* 1 */
-}
-
-/***************************** GETHFNOTE ************************************
- *
- * Read a note and store in harmonic field IF not already there.
- */
-
-int gethfnote(double thispitch,double *hf,int *hfnotecnt)
-{
-    int n, OK  = 0;
-    float notetransp = (float)fmod(thispitch,SEMITONES_PER_OCTAVE);
-    if(flteq((double)notetransp,0.0))
-        notetransp = (float)(notetransp + SEMITONES_PER_OCTAVE);
-    for(n=0;n<*hfnotecnt;n++) {
-        if(flteq((double)notetransp,hf[n])) {
-            OK = 1;
-            break;
-        }
-    }
-    if(!OK)
-        hf[*hfnotecnt] = (double)notetransp;
-    (*hfnotecnt)++;
-    return(FINISHED);
-}
-
-/**************************** SETMTFPARAMS *******************************
- *
- * Establish easy parameters of motif or ornament.
- */
-
-int setmtfparams
-(noteptr thisnote,double thisamp,noteptr phrasenote,noteptr tsetnote,double ampdif,double notetime,
- int gpsize,double multiplier,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = do_mtf_params(thisnote,thisamp,phrasenote,tsetnote,ampdif,notetime,multiplier,dz))<0)
-        return(exit_status);
-    return setspace(tsetnote,thisnote,gpsize,dz);
-}
-
-/**************************** INITIALISE_HFPHRASES *******************************/
-
-int initialise_hfphrases
-(int ***hfphrase,int **endhsindex,int **phrnotecnt,double **phraseamp,double **phrange,
- noteptr **phrlastnote,dataptr dz)
-{
-    if((*hfphrase = (int **)malloc(dz->tex->phrasecnt * sizeof(int *)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic field phrases.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*endhsindex = (int *)malloc(dz->tex->phrasecnt * sizeof(int)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic set indices.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*phrnotecnt = (int *)malloc(dz->tex->phrasecnt * sizeof(int)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic field phrase notecnt.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*phraseamp = (double *)malloc(dz->tex->phrasecnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for phrase amplitude array.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*phrange  = (double *)malloc(dz->tex->phrasecnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for phrase range array.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*phrlastnote = (noteptr *)malloc(dz->tex->phrasecnt * sizeof(noteptr)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for phrase lastnote array.\n");
-        return(MEMORY_ERROR);
-    }
-    return(FINISHED);
-}
-
-/****************************** GET_FIRST_HS ***********************************
- *
- * Extract HS from input data.
- */
-
-int get_first_hs(noteptr thisnote,double **hs,int *hsnotecnt)
-{
-    int exit_status;
-    int size = BIGARRAY;
-    noteptr startnote = thisnote;
-    double thistime = 0.0;
-    if((*hs = (double *)malloc(BIGARRAY * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic set array.\n");
-        return(MEMORY_ERROR);
-    }
-    while(thisnote!=(noteptr)0) {
-        if((exit_status = gethsnote(thisnote->pitch,*hs,hsnotecnt))<0)
-            return(exit_status);
-        if(thisnote==startnote)
-            thistime = thisnote->ntime;
-        else {
-            if(!flteq((double)thisnote->ntime,thistime)) {
-                (*hsnotecnt)--;
-                break;
-            }
-        }
-        if(*hsnotecnt >= BIGARRAY) {
-            size += BIGARRAY;
-            if((*hs=(double *)realloc((char *)(*hs),size * sizeof(double)))==NULL){
-                sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic set array.\n");
-                return(MEMORY_ERROR);
-            }
-        }
-        thisnote = thisnote->next;
-    }
-    if((*hs=(double *)realloc((char *)(*hs),*hsnotecnt*sizeof(double)))==NULL){
-        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic set array.\n");
-        return(MEMORY_ERROR);
-    }
-    upsort(*hs,*hsnotecnt);
-    return(FINISHED);
-}
-
-/****************************** GET_FIRST_HF ***********************************
- *
- * Extract first HF from input data.
- */
-
-int get_first_hf(noteptr thisnote,double **hf,int *hfnotecnt)
-{
-    int exit_status;
-    int size = BIGARRAY;
-    noteptr startnote = thisnote;
-    double thistime = 0.0;
-
-    if((*hf = (double *)malloc(size * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic field array.\n");
-        return(MEMORY_ERROR);
-    }
-    while(thisnote!=(noteptr)0) {
-        if((exit_status = gethfnote(thisnote->pitch,*hf,hfnotecnt))<0)
-            return(exit_status);
-        if(thisnote==startnote)
-            thistime = thisnote->ntime;
-        else {
-            if(!flteq((double)thisnote->ntime,thistime)) {
-                (*hfnotecnt)--;
-                break;
-            }
-        }
-        if(*hfnotecnt >= size) {
-            size += BIGARRAY;
-            if((*hf = (double *)realloc((char *)(*hf),size * sizeof(double)))==NULL){
-                sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic field array.\n");
-                return(MEMORY_ERROR);
-            }
-        }
-        thisnote = thisnote->next;
-    }
-    if((*hf=(double *)realloc((char *)(*hf),*hfnotecnt * sizeof(double)))==NULL){
-        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic field array.\n");
-        return(MEMORY_ERROR);
-    }
-    upsort(*hf,*hfnotecnt);
-    return(FINISHED);
-}
-
-/******************************** OCTEQ *************************************/
-
-int octeq(double a,double b)
-{
-    a = fmod(a,12.0);
-    b = fmod(b,12.0);
-    if(flteq(a,b)) {
-        return(1);
-    }
-    return(0);
-}

+ 0 - 1477
dev/texture/prevsrc/prev-src/texture4.c

@@ -1,1477 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
-
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-
-
-
-/* floatsam version : no changes */
-#include <stdio.h>
-#include <stdlib.h>
-#include <float.h>
-#include <structures.h>
-#include <tkglobals.h>
-#include <globcon.h>
-#include <processno.h>
-#include <modeno.h>
-#include <arrays.h>
-#include <texture.h>
-#include <cdpmain.h>
-
-#include <sfsys.h>
-#include <osbind.h>
-
-#if defined unix || defined __GNUC__
-#define round(x) lround((x))
-#endif
-
-/**** ALL FUNCTIONS WHICH ARE GLOBAL TO ALL PROCESS FUNCTIONS TYPES ***/
-
-/* Functions which are global to all texture applications.
- */
-static void orn_subzero(double *thistime,noteptr phrlastnote,noteptr *phrasenote,
-                        double *timeadjust,double multiplier,int *gpsize);
-static int  getmtfampstep
-(double amp,double framp,double *ampstep,unsigned char *amptype,
- unsigned char amptypestor,unsigned char amptypecnt,int gpsize,dataptr dz);
-static int  space_gpnote(noteptr thisnote,int gpsize,dataptr dz);
-static int  sp_scatter(noteptr mnote,dataptr dz);
-static int  pre_place(noteptr thisnote,int gpsize,dataptr dz);
-static int  post_place(noteptr thisnote,int gpsize,dataptr dz);
-static int  read_direction(int shi,noteptr *shadow,int shadowsize);
-
-static int  do_ev_ins(unsigned char *thisinstr,double thistime,dataptr dz);
-static int  do_ev_amp(double *thisamp,double thistime,dataptr dz);
-static int  do_ev_dur(double *thisdur,double thistime,dataptr dz);
-static int  getdirampstep
-(double amp,unsigned char amptypecnt,double *ampstep,int gpsize,dataptr dz);
-static int  getampstep
-(double *ampstep,double amp,unsigned char *amptype,int gpsize,unsigned char amptypecnt,
- unsigned char amptypestor,dataptr dz);
-static int  get_dec_or_orn_pos(dataptr dz);
-
-static int  subzero(double *thistime,double gpdense,int *gpsize);
-
-static noteptr reverse_search_for_time(noteptr start,double reftime);
-static void    move_notelist_item(noteptr a,noteptr b);
-static double  setup_first_notelist_time(noteptr *base);
-static int     reset_mtfhead(motifptr mtf);
-static int         post_place(noteptr thisnote,int gpsize,dataptr dz);
-static int     getmtfdirampstep
-(double amp,double framp,unsigned char amptypecnt,double *ampstep,int gpsize,dataptr dz);
-static void cyclicperm(dataptr dz);
-static void hinsert(int m,int t,int *perm,int permlen);
-static void hprefix(int m,int *perm,int permlen);
-static void hshuflup(int k,int *perm,int permlen);
-
-/***************************** OCTADJUST *****************************
- *
- * Check for range overflow of pitch.
- */
-
-double octadjust(double thispitch)
-{
-    if(thispitch>MIDITOP)
-        thispitch -= SEMITONES_PER_OCTAVE;
-    if(thispitch<MIDIBOT)
-        thispitch += SEMITONES_PER_OCTAVE;
-    return(thispitch);
-}
-
-/***************************** DO_AMP_INSTR_DUR ************************************/
-
-int do_amp_instr_dur
-(double *thisamp,unsigned char *thisinstr,double *thisdur,noteptr tsetnote,double thistime,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = do_ev_amp(thisamp,thistime,dz))<0)
-        return(exit_status);
-    tsetnote->amp = (float)(*thisamp);
-    if((exit_status = do_ev_ins(thisinstr,thistime,dz))<0)
-        return(exit_status);
-    tsetnote->instr = *thisinstr;
-    if((exit_status = do_ev_dur(thisdur,thistime,dz))<0)
-        return(exit_status);
-    tsetnote->dur = (float)(*thisdur);
-    return(FINISHED);
-}
-
-/********************** DO_EV_INS *******************************
- *
- * Set instrument of event (not group etc.).
- *
- * (0)  If instruments in ornament or decoration are to be relative to
- *      input instr, return this input instrument.
- * (1)  If there is a pre-existing timed set (pretimed = 1).
- * (2)  Negative value causes original value to be replaced
- *      by orig + abs(neg value).
- *      Zero value, by default, causes orig value to be retained.
- */
-
-int do_ev_ins(unsigned char *thisinstr,double thistime,dataptr dz)
-{
-    int exit_status;
-    int instrval;
-    if(dz->process == SIMPLE_TEX && dz->vflag[CYCLIC_TEXFLAG]) {
-        if(dz->itemcnt == dz->infilecnt)
-            dz->itemcnt = 0;
-        if(dz->vflag[PERM_TEXFLAG]) {
-            if(dz->itemcnt == 0)
-                cyclicperm(dz);
-            *thisinstr = (unsigned char)dz->peakno[dz->itemcnt];
-        } else {
-            *thisinstr = (unsigned char)dz->itemcnt;
-        }
-        dz->itemcnt++;
-    } else {
-        if((exit_status = igetvalue(TEXTURE_INSHI,TEXTURE_INSLO,thistime,PM_INSNO,&instrval,dz))<0)
-            return(exit_status);
-        *thisinstr = (unsigned char)instrval;
-    }
-    return(FINISHED);
-}
-
-/********************** DO_EV_AMP ********************************/
-
-int do_ev_amp(double *thisamp,double thistime,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getvalue(TEXTURE_MAXAMP,TEXTURE_MINAMP,thistime,PM_AMP,thisamp,dz))<0)
-        return(exit_status);
-
-    *thisamp *= dz->param[TEXTURE_ATTEN];
-
-    if(*thisamp>MIDITOP + 0.5) {
-        sprintf(errstr,"TEXTURE: amplitude [%.1f] out of midirange at time %.2f\n",*thisamp,thistime);
-        return(DATA_ERROR);
-    }
-    return(FINISHED);
-}
-
-/********************** DO_EV_DUR ********************************/
-
-int do_ev_dur(double *thisdur,double thistime,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getvalue(TEXTURE_MAXDUR,TEXTURE_MINDUR,thistime,PM_DUR,thisdur,dz))<0)
-        return(exit_status);
-    return(FINISHED);                                       /* 4 */
-}
-
-/************************ MAKE_SHADOW ****************************
- *
- * Store addresses of original tset notes.
- */
-
-int make_shadow(motifptr tset,int *shadowsize,noteptr **shadow)
-{
-    noteptr *sh, thisnote = tset->firstnote;
-    int n;
-    *shadowsize     = 0;
-    while(thisnote!=(noteptr)0) {
-        (*shadowsize)++;
-        thisnote = thisnote->next;
-    }
-    if((sh = *shadow = (noteptr *)malloc((*shadowsize) * sizeof(noteptr)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for shadow.\n");
-        return(MEMORY_ERROR);
-    }
-    thisnote = tset->firstnote;
-    n = 0;
-    while(thisnote!=(noteptr)0) {
-        sh[n++]  = thisnote;
-        thisnote = thisnote->next;
-    }
-    return(FINISHED);
-}
-
-/************************ ERASE_SHADOW ****************************
- *
- * Erase original tset from resultant list.
- *
- * (0)  Assuming shadow starts at start of tset, if first note of
- *      shadow is deleted, del_note automatically resets motifptr (tset)
- *      to next note (and so on).
- * (1)  In case shadow started AFTER start of tset (should be impossible!!)
- *      reset pointer to start of remaining motif !
- */
-
-int erase_shadow(int shadowsize,noteptr *shadow,motifptr tset)
-{
-    int n;
-    noteptr thisnote;
-    for(n=0;n<shadowsize;n++)                                       /* 0 */
-        del_note(shadow[n],tset);
-    if((thisnote = tset->firstnote->last)!=(noteptr)0) {    /* 1 */
-        sprintf(errstr,"TEXTURE: erase_shadow(): First note of shadow NOT first note of tset.\n"
-                "This should never happen\n");
-        return(PROGRAM_ERROR);
-        /**** REMOVED FOLLOWING AUTO-CORRECTION CODE : OCT 1997 *****
-              while(thisnote->last!=(noteptr)0)
-              thisnote = thisnote->last;
-              tset->firstnote = thisnote;
-        ****/
-    }
-    return(FINISHED);
-}
-
-/************************ SETUP_DECOR ****************************/
-
-void setup_decor(double *pptop,double *ppbot,int *shadindex,noteptr *tsetnote,dataptr dz)
-{
-    *pptop = MIDITOP;
-    *ppbot = MIDIBOT;
-    if(dz->vflag[WHICH_CHORDNOTE]==DECOR_HIGHEST)
-        *tsetnote = gethipitch(*tsetnote,shadindex);
-}
-
-/**************************** SETUP_ORNAMENT *********************************/
-
-int setup_ornament
-(double *timeadjust,double *thistime,int *gpsize,noteptr *phrlastnote,
- double multiplier,noteptr *phrasenote,int phrno,dataptr dz)
-{
-    int exit_status;
-    double origtime;
-    if((exit_status = get_dec_or_orn_pos(dz))<0)
-        return(exit_status);
-    *timeadjust = 0.0;
-    if(dz->vflag[IS_PRE]) {
-        origtime = *thistime;
-        if((*thistime -= (phrlastnote[phrno])->ntime * multiplier)<0.0) {
-            *thistime = origtime;
-            orn_subzero(thistime,phrlastnote[phrno],phrasenote,timeadjust,multiplier,gpsize);
-        }
-    }
-    return(FINISHED);
-}
-
-/**************************** SET_MOTIF_AMP *********************************/
-
-int set_motif_amp
-(noteptr tsetnote,double *thisamp,int gpsize,double ampstep,noteptr phrasenote,double rangemult,
- double *phraseamp,int phrno,unsigned char amptype)
-{
-    double ampdif;
-    if(amptype==CRESC) {
-        *thisamp -= (double)(gpsize) * ampstep;
-        ampdif    = (phraseamp[phrno] - phrasenote->amp) * rangemult;
-        tsetnote->amp = (float)(*thisamp - ampdif);
-    }
-    return(FINISHED);
-}
-
-/**************************** SET_ORNAMENT_AMP *********************************/
-
-int set_ornament_amp
-(double *phraseamp,noteptr *phrlastnote,double *thisamp,
- noteptr phrasenote,int phrno,noteptr tsetnote,
- double ampstep,double rangemult,int gpsize,dataptr dz)
-{
-    double ampdif;
-    if(dz->vflag[IS_PRE])
-        ampdif=(phraseamp[phrno]-phrlastnote[phrno]->amp) * rangemult;
-    else
-        ampdif=(phraseamp[phrno]-phrasenote->amp) * rangemult;
-    tsetnote->amp -= (float)ampdif;
-    if(ampstep>0.0) /* CRESCENDO */
-        *thisamp -= (double)(gpsize+1) * ampstep;
-    return(FINISHED);
-}
-
-/**************************** CHECK_NEXT_PHRASENOTE_EXISTS *********************************/
-
-int check_next_phrasenote_exists(noteptr *phrasenote,int texflag,dataptr dz)
-{
-    if(texflag & IS_MOTIFS) {
-        if((*phrasenote = (*phrasenote)->next)==(noteptr)0) {
-            sprintf(errstr,"TEXTURE: Accounting Problem in check_next_phrasenote_exists()\n");
-            return(PROGRAM_ERROR);
-        }
-    } else if (texflag & IS_ORNATE){
-        if(*phrasenote==(noteptr)0) {
-            sprintf(errstr,"TEXTURE: 1st Accounting Problem in check_next_phrasenote_exists()\n");
-            return(PROGRAM_ERROR);
-        }
-        if(dz->vflag[IS_PRE] && ((*phrasenote)->next==(noteptr)0)) {
-            sprintf(errstr,"TEXTURE: 2nd Accounting Problem in check_next_phrasenote_exists()\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    return(CONTINUE);
-}
-
-/************************* GETNEXTEVENT_TO_DECORATE ***************************
- *
- * Get the next event in list, i.e. skip over simultaneous events
- * (e.g. chords).
- *
- * (0)  If flagged as 2, ornaments/decorations are attached to EVERY note
- *      so the next event is just the next note in the tset.
- *      OTHERWISE we search for the next event AT A NEW TIME.
- * (1)  If flagged, force a search for the highest note of a simultaneous
- *      group (chord). Hence ornament/dec attaches to highest note.
- *      Otherwise, ornament attached to first listed note of chord in input
- *      data.
- */
-
-noteptr getnextevent_to_decorate(noteptr tsetnote,int *shaddoindex,dataptr dz)
-{
-    if(dz->vflag[WHICH_CHORDNOTE]==DECOR_EVERY)                                             /* 0 */
-        return(tsetnote->next);
-    while(tsetnote->next!=(noteptr)0) {
-        tsetnote = tsetnote->next;
-        (*shaddoindex)++;
-        if(!flteq((double)tsetnote->ntime,(double)tsetnote->last->ntime)) {
-            if(dz->vflag[WHICH_CHORDNOTE]==DECOR_HIGHEST)
-                tsetnote = gethipitch(tsetnote,shaddoindex);    /* 1 */
-            return(tsetnote);
-        }
-    }
-    return((noteptr)0);
-}
-
-/************************** GETNOTETIME ********************************
- *
- * Get actual time of note, from time of tset note, and time of motif
- * or ornament note.
- * (a)  Time is set by an offset from the tset-note, THROUGHOUT each
- *      motif-placement. The offset for each note is its position in the
- *      original note (which have been set relative to zero by set_mtfs())
- *      times the multiplier, with an adjustment if we're actually using
- *      less than the whole motif for some reason.
- * (b)  Time may need to be quantised.
- * (c)  Time of note is this tset-note + offset.
- */
-
-double getnotetime(noteptr phrasenote,double thistime,double multiplier,double timeadjust,dataptr dz)
-{
-    int qunits;
-    double timestep = ((double)phrasenote->ntime - timeadjust) * (double)multiplier; /* a */
-    double thisgrid;
-
-    if(dz->param[TEX_PHGRID]>0.0) {
-        /* NEW  2000 */
-        thisgrid = dz->param[TEX_PHGRID] * MS_TO_SECS;
-
-        qunits    = round(timestep/thisgrid);           /* b */
-        timestep  = (double)(qunits*thisgrid);
-    }
-    return(thistime + timestep);                            /* c */
-}
-
-/************************ GETMTFDUR **********************************/
-
-int getmtfdur(noteptr tsetnote,noteptr phrasenote,double *dur,double multiplier,dataptr dz)
-{
-    if(dz->vflag[DONT_KEEP_MTFDUR])
-        *dur = tsetnote->dur;
-    else
-        *dur = phrasenote->dur * multiplier;
-    if(flteq(*dur,0.0)) {
-        sprintf(errstr,"TEXTURE: Problem 3 in getmtfdur(): Zero duration\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/***************************** ORN_OR_MTF_AMP_SETUP ************************************/
-
-int orn_or_mtf_amp_setup
-(int ampdirected,double *phrange,int phrno,double thisamp,int gpsize,double *rangemult,double *ampstep,
- unsigned char *amptype,unsigned char amptypestor,unsigned char amptypecnt,dataptr dz)
-{
-    int exit_status;
-    double kk;
-    if(phrange[phrno]>=thisamp) {
-        kk = (double)phrange[phrno]*((double)(gpsize+1)/(double)gpsize);
-        *rangemult = (double)thisamp / kk;
-        *ampstep   = 0.0;
-    } else {
-        if(ampdirected) {
-            if((exit_status = getmtfdirampstep(thisamp,phrange[phrno],amptypecnt,ampstep,gpsize,dz))<0)
-                return(exit_status);
-        } else {
-            if((exit_status = getmtfampstep(thisamp,phrange[phrno],ampstep,amptype,amptypestor,amptypecnt,gpsize,dz))<0)
-                return(exit_status);
-        }
-        *rangemult = 1.0;
-    }
-    return(FINISHED);
-}
-
-/**************************** DO_MTF_PARAMS *******************************/
-
-int do_mtf_params
-(noteptr thisnote,double thisamp,noteptr phrasenote,noteptr tsetnote,
- double ampdif,double notetime,double multiplier,dataptr dz)
-{
-    int exit_status;
-    double duration;
-    thisnote->amp   = (float)(thisamp - ampdif);
-    if((exit_status = getmtfdur(tsetnote,phrasenote,&duration,multiplier,dz))<0)
-        return(exit_status);
-    thisnote->dur = (float)duration;
-    if((exit_status = do_grp_ins(tsetnote->instr,&(thisnote->instr),dz))<0)
-        return(exit_status);
-    thisnote->motioncentre = tsetnote->motioncentre;
-    thisnote->ntime  = (float)notetime;
-    return(FINISHED);
-}
-
-/***************************** SETUP_MOTIF_OR_ORNAMENT ************************************/
-
-int setup_motif_or_ornament
-(double thistime,double *multiplier,int *phrno,noteptr *phrasenote,motifptr *phrase,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getvalue(TEX_MULTHI,TEX_MULTLO,thistime,PM_MULT,multiplier,dz))<0)
-        return(exit_status);
-    if((exit_status = doperm((int)dz->tex->phrasecnt,PM_WHICH,phrno,dz))<0)
-        return(exit_status);
-    *phrasenote    = phrase[*phrno]->firstnote;
-    return(FINISHED);
-}
-
-/****************************** POSITION_AND_SIZE_DECORATION **********************************/
-
-int position_and_size_decoration
-(double *thistime,double tsettime,double gpdense,int *gpsize,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = get_dec_or_orn_pos(dz))<0)
-        return(exit_status);
-    if(dz->vflag[IS_PRE]) {
-        if((*thistime -= gpdense * (double)((*gpsize) + 1))< -gpdense) {
-            *thistime = tsettime;
-            if((exit_status = subzero(thistime,gpdense,gpsize))<0)
-                return(exit_status);
-        }
-    }
-    return(FINISHED);
-}
-
-/****************************** SET_DECOR_AMP **********************************/
-
-int set_decor_amp
-(int ampdirected,double *thisamp,double *ampstep,int gpsize,
- unsigned char *amptype,unsigned char amptypecnt,unsigned char amptypestor,dataptr dz)
-{
-    int exit_status;
-    if(ampdirected) {
-        if((exit_status = getdirampstep(*thisamp,amptypecnt,ampstep,gpsize,dz))<0)
-            return(exit_status);
-    } else  {
-        if((exit_status = getampstep(ampstep,*thisamp,amptype,gpsize,amptypecnt,amptypestor,dz))<0)
-            return(exit_status);
-    }
-    if(*ampstep>0.0)
-        *thisamp -= (double)(gpsize+1) * (*ampstep);
-    return(FINISHED);
-}
-
-/****************************** SET_GROUP_AMP **********************************/
-
-int set_group_amp
-(noteptr tsetnote,double *thisamp,unsigned char *amptype, double *ampstep,int gpsize,
- unsigned char amptypecnt,unsigned char amptypestor,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getampstep(ampstep,*thisamp,amptype,gpsize,amptypecnt,amptypestor,dz))<0)
-        return(exit_status);
-    if(*amptype==CRESC) {
-        *thisamp -= (double)(gpsize) * (*ampstep);
-        tsetnote->amp = (float)(*thisamp);
-    }
-    return(FINISHED);
-}
-
-/* LOCAL TO THESE GLOBALS */
-
-/****************************** ORN_SUBZERO *******************************
- *
- * Readjust the groupsize and the pointer to first note of phrase, where
- * otherwise phrase would start before zero.
- *
- * (1)  Note the endtime of the phrase.
- * (2)  For each note in the phrase.
- * (3)  Find the duration of the phrase FROM THIS NOTE, by subtracting time of
- *      current note from end (total) time, and adjusting by multiplier.
- * (4)  If the duration of phrase from here, would put it's start after
- *      zero-time, break from loop.
- * (5)  Count number of notes rejected, and go to next phrase note.
- * (6)  If we're at end of phrase, none of it's notes fall after zero time,
- *      so return a gpsize of 0.
- * (7)  Otherwise reset the event time (mifitime) to start of the group or
- *      part-group which 'thisnote' points to.
- * (8)  Resert the phrase pointer to point at this note of the phrase.
- * (9)  When note times are finally calculated, timeadjust will reset all
- *      the note times WITHIN the ornament to run from the note from
- *      which we're starting, rather than the true start, by subtracting
- *      'timeadjust'.
- * (10) Return a size for the group reduced by the number of rejected notes.
- */
-
-void orn_subzero
-(double *thistime,noteptr phrlastnote,noteptr *phrasenote,double *timeadjust,double multiplier,int *gpsize)
-{
-    double endtime = phrlastnote->ntime;            /* 1 */
-    double phrdur = 0.0;
-    int cnt = 0;
-    noteptr thisnote = *phrasenote;
-    while(thisnote!=(noteptr)0) {                           /* 2 */
-        phrdur = (endtime - thisnote->ntime) * multiplier;      /* 3 */
-        if(*thistime - phrdur >= 0.0)                   /* 4 */
-            break;
-        cnt++;                                                                  /* 5 */
-        thisnote = thisnote->next;
-    }
-    if(thisnote==(noteptr)0) {
-        *gpsize = 0;                                                    /* 6 */
-        return;
-    } else {
-        *thistime -= phrdur;                                    /* 7 */
-        *phrasenote = thisnote;                                 /* 8 */
-        *timeadjust = thisnote->ntime;                  /* 9 */
-    }
-    *gpsize -= cnt;
-    return;                                                                         /* 10 */
-}
-
-/*************************** GETMTFAMPSTEP ******************************
- *
- * Select flat, cresc or decresc, from available types, for motifs.
- *
- * (0)  If the amplitude is bigger than the size of amprise and the
- *      range of the phrase, taken together, amprise is OK as it is.
- * (00) Otherwise, amprise (set as ampstep at this point) is the amount
- *      of the total amplitude left when the amplitude range of the phrase
- *      has been subtracted. This ensures that no note of the phrase
- *      can possibly end up below zero.
- * (1)  IF the cresc will be from zero, clrzamp is 1, and this makes
- *      the amplitude steps a little smaller, so that 1 of the notes
- *      in sequence cannot be at amplitude zero.
- *      OTHERWISE, clrzamp = 0,  and ampstep is as normal.
- */
-
-int getmtfampstep(double amp,double framp,double *ampstep,unsigned char *amptype,
-                  unsigned char amptypestor,unsigned char amptypecnt,int gpsize,dataptr dz)
-{
-    int exit_status;
-    int clrzamp = 0;
-    int k;
-    if((exit_status = doperm((int)amptypecnt,PM_GPCNTR,&k,dz))<0)
-        return(exit_status);
-    if((exit_status=gettritype(k,amptypestor,amptype))<0)
-        return(exit_status);
-    if(*amptype==FLAT) {            /**** FLAT *****/
-        *ampstep =0.0;
-    } else {
-        if(amp>(dz->param[TEX_AMPRISE] + framp)) /* 0 */
-            *ampstep = dz->param[TEX_AMPRISE];
-        else {
-            *ampstep = amp - framp;                 /* 00 */
-            clrzamp = 1;
-        }
-        *ampstep /= (double)(gpsize+clrzamp);           /* 1 */
-        if(*amptype==DECRESC)           /** DECRESCENDO **/
-            *ampstep = -(*ampstep);
-    }
-    return(FINISHED);
-}
-
-/************************************************************************
- *
- * Calculating spatial orientation of motifs,groups,ornaments,decorations.
- */
-
-/**************************** SETSPACE *******************************/
-
-int setspace(noteptr tsetnote,noteptr thisnote,int gpsize,dataptr dz)
-{
-    int exit_status;
-    if(dz->iparam[TEX_GPSPACE]!=IS_STILL) {
-        if((exit_status = space_gpnote(thisnote,gpsize,dz))<0)
-            return(exit_status);
-    } else
-        thisnote->spacepos = tsetnote->spacepos;
-    return(FINISHED);
-}
-
-/***************************** SPACE_GPNOTE *******************************
- *
- * (1)  OUTSIDE THE GROUP- OR PHRASE-MAKING LOOP
- *      (a) Need to know gpsize, dectype(is_post?), gpsprange
- *          (which MUST be +ve!).
- *      (b) Need to run 'init_group_spatialisation()' to establish spinit, & hence
- *          range modifications etc.
- *
- *  Then this will work INSIDE the loop.
- *
- * (1)  NB !!!!! is_pre is defaulted to ZERO. This means that groups
- *      or motifs which CANNOT BE pre- or post- are defaulted to
- *      post (which means the groups start on the tset notes, rather
- *      leading up to them).
- */
-
-int space_gpnote(noteptr thisnote,int gpsize,dataptr dz)
-{
-    int exit_status;
-    if(dz->iparam[TEX_GPSPACE]==IS_SCATTER) {
-        if((exit_status = sp_scatter(thisnote,dz))<0)
-            return(exit_status);
-    } else {
-        if(dz->vflag[IS_PRE]) {                         /* 1 */
-            if((exit_status = pre_place(thisnote,gpsize,dz))<0)
-                return(exit_status);
-        } else {
-            if((exit_status = post_place(thisnote,gpsize,dz))<0)
-                return(exit_status);
-        }
-    }
-    dz->iparam[SPINIT] = 0;         /* disable initialisation after first call to group */
-    return(FINISHED);
-}
-
-/**************************** SP_SCATTER *************************
- *
- * scatter group note around position of main event.
- */
-
-int sp_scatter(noteptr mnote,dataptr dz)
-{
-    int exit_status;
-    double sptop = 1.0, spbot= 0.0, hfthissprange,val;
-    if(dz->param[THISSPRANGE]<=0.0) {
-        mnote->spacepos = (float)dz->param[TPOSITION];
-        return(FINISHED);
-    }
-    if(dz->iparam[SPINIT]) {
-        hfthissprange = dz->param[THISSPRANGE]/(double)2.0;
-        spbot = max((dz->param[TPOSITION] - hfthissprange),0.0);
-        sptop = min((dz->param[TPOSITION] + hfthissprange),1.0);
-        dz->param[THISSPRANGE] = sptop - spbot;
-    }
-    if((exit_status = pscatx(dz->param[THISSPRANGE],spbot,PM_GPSPAC,&val,dz))<0)
-        return(exit_status);
-    mnote->spacepos      = (float)val;
-    return(FINISHED);
-}
-
-/************** MACROS FOR RANGE REORIENTATIONS AND TRUNCATIONS **************
- *
- *      r = group spatial range         p = position of event
- *      c = centre of motion            d = direction of motion
- *
- * (1)  If position to left  of centre, reverse range.
- * (2)  If position to right of centre, reverse range.
- * (3)  If no motion, zero the range.
- * (4)  If motion is right to left reverse range.
- * (5)  If motion is left to right reverse range.
- * (6)  avoid centre crossing
- * (7)  avoid right-edge crossing
- * (8)  avoid left-edge crossing
- * (9)  avoid edge crossing
- */
-
-#define TURNOUTWARD(r,p,c) if((p)-(c)<0.0)  (r) = -(r);                                         /* 1 */
-#define TURNINWARD(r,p,c)  if((p)-(c)>0.0)  (r) = -(r);                                         /* 2 */
-#define CHECKSTIL(r,d)     if((d)==0) (r) = 0.0;                                                        /* 3 */
-#define FOLLOW(r,d)                CHECKSTIL(r,d) else { if((d)<0) (r) = -(r); }        /* 4 */
-#define CONTRARY(r,d)      CHECKSTIL(r,d) else { if((d)>0) (r) = -(r); }        /* 5 */
-#define SET_PRE_INRANGE(r,p,c) if(p<c) r = min(p,r); else r = max(p-1.0,r);
-
-
-#define FREECENTRE(r,p,c)  if((r)>fabs((p)-(c))) (r)=fabs((p)-(c));                     /* 6 */
-#define FREEREDGE(r,p)     if((p)+(r)>1.0) (r) = 1.0 - (p);                                     /* 7 */
-#define FREELEDGE(r,p)     if((p)+(r)<0.0) (r) = -(p);                                          /* 8 */
-#define FREEEDGES(r,p)     if((r)>=0.0) { FREEREDGE((r),(p)) } else { FREELEDGE((r),(p)) }
-/* 9 */
-
-#define FREEREDGE_PRE(r,p) if((p)-(r)>1.0) (r) = (p) - 1.0;                                     /* 7 */
-#define FREELEDGE_PRE(r,p) if((p)-(r)<0.0) (r) = (p);                                           /* 8 */
-#define FREEEDGES_PRE(r,p) if((r)>=0.0) { FREELEDGE_PRE((r),(p)) } else { FREEREDGE_PRE((r),(p)) }
-/* 9 */
-/************************* PRE_PLACE *****************************
- *
- * place-in-space ornaments or decorations BEFORE notes, or motifs or groups
- * at texture points.
- *
- * is_pre = 1.
- */
-
-int pre_place(noteptr thisnote,int gpsize,dataptr dz)
-{
-    if(dz->iparam[SPINIT])
-        dz->iparam[SPCNT] = 0;
-
-    switch(dz->iparam[TEX_GPSPACE]) {
-    case(IS_STILL):
-        dz->param[THISSPRANGE] = 0.0;
-        break;
-    case(IS_INWARD):
-        if(dz->iparam[SPINIT]) {
-            TURNINWARD(dz->param[THISSPRANGE],dz->param[TPOSITION],dz->param[CPOS])
-                SET_PRE_INRANGE(dz->param[THISSPRANGE],dz->param[TPOSITION],dz->param[CPOS])
-
-                }
-        break;
-    case(IS_OUTWARD):
-        if(dz->iparam[SPINIT]) {
-            FREECENTRE(dz->param[THISSPRANGE],dz->param[TPOSITION],dz->param[CPOS])
-                TURNOUTWARD(dz->param[THISSPRANGE],dz->param[TPOSITION],dz->param[CPOS])
-                }
-        break;
-    case(IS_FOLLOWING):
-        if(dz->iparam[SPINIT]) {
-            FOLLOW(dz->param[THISSPRANGE],dz->iparam[DIRECTION])
-                FREEEDGES_PRE(dz->param[THISSPRANGE],dz->param[TPOSITION])
-                }
-        break;
-    case(IS_CONTRARY):
-        if(dz->iparam[SPINIT]) {
-            CONTRARY(dz->param[THISSPRANGE],dz->iparam[DIRECTION])
-                FREEEDGES_PRE(dz->param[THISSPRANGE],dz->param[TPOSITION])
-                }
-        break;
-    default:
-        sprintf(errstr,"TEXTURE: Invalid space-type %d in pre_place()\n",dz->iparam[TEX_GPSPACE]);
-        return(PROGRAM_ERROR);
-    }
-    thisnote->spacepos = (float)(dz->param[TPOSITION] - dz->param[THISSPRANGE]
-                                 + ((dz->param[THISSPRANGE]/(double)gpsize)*(double)(dz->iparam[SPCNT])));
-    dz->iparam[SPCNT]++;
-    return(FINISHED);
-}
-
-/************************* POST_PLACE *****************************
- *
- * place-in-space ornaments or decorations AFTER notes, or motifs or groups
- * at texture points.
- *
- * is_pre = 0, (or no ornament).
- */
-
-int post_place(noteptr thisnote,int gpsize,dataptr dz)
-{
-    if(dz->iparam[SPINIT])
-        dz->iparam[SPCNT] = 1;
-    switch(dz->iparam[TEX_GPSPACE]) {
-    case(IS_STILL):
-        dz->param[THISSPRANGE] = 0.0;
-        break;
-    case(IS_INWARD):
-        if(dz->iparam[SPINIT]) {
-            FREECENTRE(dz->param[THISSPRANGE],dz->param[TPOSITION],dz->param[CPOS])
-                TURNINWARD(dz->param[THISSPRANGE],dz->param[TPOSITION],dz->param[CPOS])
-                }
-        break;
-    case(IS_OUTWARD):
-        if(dz->iparam[SPINIT]) {
-            TURNOUTWARD(dz->param[THISSPRANGE],dz->param[TPOSITION],dz->param[CPOS])
-                FREEEDGES(dz->param[THISSPRANGE],dz->param[TPOSITION])
-                }
-        break;
-    case(IS_FOLLOWING):
-        if(dz->iparam[SPINIT]) {
-            FOLLOW(dz->param[THISSPRANGE],dz->iparam[DIRECTION])
-                FREEEDGES(dz->param[THISSPRANGE],dz->param[TPOSITION])
-                }
-        break;
-    case(IS_CONTRARY):
-        if(dz->iparam[SPINIT]) {
-            CONTRARY(dz->param[THISSPRANGE],dz->iparam[DIRECTION])
-                FREEEDGES(dz->param[THISSPRANGE],dz->param[TPOSITION])
-                }
-        break;
-    default:
-        sprintf(errstr,"TEXTURE: Invalid space-type %d in post_place()\n",dz->iparam[TEX_GPSPACE]);
-        return(PROGRAM_ERROR);
-    }
-    thisnote->spacepos = (float)(dz->param[TPOSITION] +
-                                 ((dz->param[THISSPRANGE]/(double)gpsize)*(double)(dz->iparam[SPCNT])));
-    dz->iparam[SPCNT]++;
-
-    return(FINISHED);
-}
-
-/************************** GPSP_INIT ***********************************
- *
- * Initialise the space-param for each group, before calling the spatialise
- * routines. 'spinit' causes initialisation of range etc elsewhere (in
- * pre_place() or post_place() ).
- */
-
-int init_group_spatialisation(noteptr tsetnote,int shaddoindex,noteptr *shadow,int shadowsize,dataptr dz)
-{
-    int exit_status;
-    dz->iparam[SPINIT] = 1;
-    dz->param[TPOSITION] = tsetnote->spacepos;
-    dz->param[CPOS]      = tsetnote->motioncentre;
-    if(dz->brksize[TEX_GRPSPRANGE]) { /* TABLE VALUES MUST BE 0 - 1 */
-        if((exit_status = read_value_from_brktable((double)tsetnote->ntime,TEX_GRPSPRANGE,dz))<0)
-            return(exit_status);
-    }
-    if(IS_DIRECTED(dz->iparam[TEX_GPSPACE]))
-        dz->iparam[DIRECTION] = read_direction(shaddoindex,shadow,shadowsize);
-    dz->param[THISSPRANGE] = dz->param[TEX_GRPSPRANGE];
-    return(FINISHED);
-}
-
-/**************************** READ_DIRECTION ****************************
- *
- * Read direction of motion from spatial position stored in note.
- *
- * NB: as the tset is in the process of being modified, we cannot
- * refer directly to the tset linked list. We can only access the original
- * tset through it's 'shadow'.
- *
- * (0)  Save the time of the current note as 'now'.
- * (1)  Save position of current note as 'here'.
- * (2)  Whilever we're not at the end of the tset (shadow).
- * (a)  Note time of next note, store as 'then'.
- * (b)  If 'then' is later than 'now'.
- *              Note position of new note as 'there'.
- *              Set as OK and break out of loop.
- * (3)  If it's not OK (i.e. we were at, or came to the end of the tset
- *              (shadow))....
- * (a)  Go back to where we started.
- * (b)  Call this position 'there'.
- * (4)  While ever we're not at beginning of tset...
- * (a)  Note time of previous note, store as 'then'.
- * (b)  If 'then' is 'earlier' than 'now'...
- *              Note position of new note as 'here'.
- *              Set as OK and break out of loop.
- * (5)  If still not OK, then there is no more than 1 (non-simultaneous)
- *              event in the tset, so therefore no motion, so return 0.
- * (6)  If there>here, left-to-right motion, return 1.
- * (7)  If here>there, right-to-left motion, return -1.
- * (8)  Otherwise, no motion, return 0.
- */
-
-int read_direction(int shi,noteptr *shadow,int shadowsize)
-{
-    unsigned char OK;
-    float here, there = 0.0;
-    double now, then;
-    int startshi = shi;
-    now  = (shadow[shi])->ntime;                    /* 0 */
-    here = (shadow[shi])->motioncentre;             /* 1 */
-    OK = 0;
-    while(++shi<shadowsize) {                       /* 2 */
-        then = (shadow[shi])->ntime;            /* a */
-        if(then>(now+FLTERR)) {                 /* b */
-            there = (shadow[shi])->motioncentre;
-            OK = 1;
-            break;
-        }
-    }
-    if(!OK) {                                       /* 3 */
-        shi = startshi;                         /* a */
-        there = here;                           /* b */
-        while(--shi>=0) {                       /* 4 */
-            then = (shadow[shi])->ntime;            /* a */
-            if(then<(now-FLTERR)) {         /* b */
-                here = (shadow[shi])->motioncentre;
-                OK = 1;
-                break;
-            }
-        }
-    }
-    if(!OK)
-        return(0);                              /* 5 */
-    if(there>here)                          /* 6 */
-        return(1);
-    if(there<here)                          /* 7 */
-        return(-1);
-    return(0);                                      /* 8 */
-}
-
-/*************************** GETAMPSTEP ******************************
- *
- * Select flat, cresc or decresc, from available types.
- *
- * (1)  IF the cresc will be from zero, clrzamp is 1, and this makes
- *      the amplitude steps a little smaller, so that 1st note in sequence
- *      will not be at amplitude zero.
- *      OTHERWISE, clrzamp = 0,  and ampstep is as normal.
- */
-
-int getampstep
-(double *ampstep,double amp,unsigned char *amptype,int gpsize,unsigned char amptypecnt,
- unsigned char amptypestor,dataptr dz)
-{
-    int exit_status;
-    int clrzamp = 0, k;
-    /*int texflag = dz->tex->txflag;*/
-    if((exit_status = doperm((int)amptypecnt,PM_GPCNTR,&k,dz))<0)
-        return(exit_status);
-    if((exit_status = gettritype(k,amptypestor,amptype))<0)
-        return(exit_status);
-
-    if(*amptype==FLAT)              /**** FLAT *****/
-        *ampstep =0.0;
-    else {
-        *ampstep = dz->param[TEX_AMPRISE]; /* param with <|> option */
-
-        if(*ampstep>=amp) {
-            clrzamp  = 1;
-            *ampstep = amp;
-        }
-        *ampstep /= (double)(gpsize + clrzamp);         /* 1 */
-        if(*amptype==DECRESC)           /** DECRESCENDO **/
-            *ampstep = -(*ampstep);
-    }
-    return(FINISHED);
-}
-
-/*************************** GETDIRAMPSTEP ******************************
- *
- * (1)  If there are two amplitude types, in THIS CASE, these can only
- *              be DIRECTED or FLAT. So...
- *   (2)  Choose flat or directed via perm.
- *   (3)  and if it's flat, return an ampstep of zero.
- *        Otherwise, we proceed as in the normal case of a directed amp.
- * (4)  Set initial ampstep to amprise.
- * (5)  IF the cresc will be from zero, or decresc to zero,  clrzamp is 1,
- *              and this makes the amplitude steps a little smaller, so that 1st note
- *              of cresc (or last note of decresc) will not be at amplitude zero.
- *              OTHERWISE, clrzamp = 0,  and ampstep is as normal.
- * (6)  Divide ampstep by number of members in group.
- * (7)  If it's a post-ornament, ampstep is negative.
- */
-
-int getdirampstep
-(double amp,unsigned char amptypecnt,double *ampstep,int gpsize,dataptr dz)
-{
-    int exit_status;
-    int k, clrzamp = 0;
-    if(amptypecnt==2) {                                                                     /* 1 */
-        if((exit_status= doperm((int)2,PM_GPCNTR,&k,dz))<0)     /* 2 */
-            return(exit_status);
-        if(k==0) {
-            *ampstep = 0.0;
-            return(FINISHED);                                                       /* 3 */
-        }
-    }
-    *ampstep = dz->param[TEX_AMPRISE];      /* param with <|> option */                             /* 4 */
-    if(*ampstep>=amp) {                                                                     /* 5 */
-        clrzamp = 1;
-        *ampstep = amp;
-    }
-    *ampstep /= (double)(gpsize + clrzamp);                         /* 6 */
-    if(!dz->vflag[IS_PRE])                                                          /* 7 */
-        *ampstep = -(*ampstep);
-
-    return(FINISHED);
-}
-
-/*************************** GETMTFDIRAMPSTEP *******************************
- *
- *      Intelligent guesswork!! Nov 4: 1997
- */
-
-int getmtfdirampstep(double amp,double framp,unsigned char amptypecnt,double *ampstep,int gpsize,dataptr dz)
-{
-    int exit_status;
-    int k, clrzamp = 0;
-    if(amptypecnt==2) {                                                                     /* 1 */
-        if((exit_status= doperm((int)2,PM_GPCNTR,&k,dz))<0)     /* 2 */
-            return(exit_status);
-        if(k==0) {
-            *ampstep = 0.0;
-            return(FINISHED);                                                       /* 3 */
-        }
-    }
-    if(amp>(dz->param[TEX_AMPRISE] + framp))
-        *ampstep = dz->param[TEX_AMPRISE];
-    else {
-        *ampstep = amp - framp;
-        clrzamp = 1;
-    }
-    *ampstep /= (double)(gpsize + clrzamp);                         /* 6 */
-    if(!dz->vflag[IS_PRE])                                                          /* 7 */
-        *ampstep = -(*ampstep);
-
-    return(FINISHED);
-}
-
-/*************************  GET_DEC_OR_ORN_POS ***************************
- *
- * Decuptype flags are selected and shifted down into the range 0-3
- * If its 01 (1), it's a post-ornament, so set 'is_pre' = FALSE.
- * If its 10 (2), it's a pre_ornament,  so set 'is_pre' = TRUE
- * If its 00 (0), it's not set, so we select 'is_pre' at random using doperm on 2 (output 0S or 1).
- *
- * NB: If we are using a group or motif, rather than a decoration
- *      or ornament, is_pre is BY DEFAULT set to 0.
- */
-
-int get_dec_or_orn_pos(dataptr dz)
-{
-    int exit_status;
-    int k;
-    unsigned int dectype = dz->tex->txflag & GET_DECORNPOS;
-    switch(dectype) {
-    case(1): dz->vflag[IS_PRE] = TRUE;      break;
-    case(2): dz->vflag[IS_PRE] = FALSE;     break;
-    default:
-        if((exit_status = doperm((int)2,PM_ORNPOS,&k,dz))<0)
-            return(exit_status);
-        dz->vflag[IS_PRE] = (char)k;
-        break;
-    }
-    if(dz->vflag[IS_PRE] > 1) {
-        sprintf(errstr,"Error from perm in  get_dec_or_orn_pos()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/**************************** SUBZERO ***********************************
- *
- * If start of a decoration falls before time zero, adjust its size
- * and hence starttime(-minus-gpdense) appropriately.
- */
-
-int subzero(double *thistime,double gpdense,int *gpsize)
-{
-    int n = -1;
-    while(*thistime>=0.0) {
-        *thistime -= gpdense;
-        n++;
-    }
-    if(n<0) {
-        sprintf(errstr,"TEXTURE: Problem in subzero()\n");
-        return(PROGRAM_ERROR);
-    }
-    *gpsize = n;
-    return(FINISHED);
-}
-
-/*************************** GETHIPITCH *********************************#
- *
- * Find highest pitch at current time.
- */
-
-noteptr gethipitch(noteptr tsetnote,int *shaddoindex)
-{
-    noteptr hinote, thisnote;
-    double hipitch;
-    int zz = *shaddoindex;
-    hinote = thisnote = tsetnote;
-    hipitch = (double)hinote->pitch;
-    while(thisnote->next!=(noteptr)0) {
-        if(thisnote->next->ntime > thisnote->ntime + FLTERR)
-            return(hinote);
-        thisnote = thisnote->next;
-        zz++;
-        if((double)thisnote->pitch > hipitch) {
-            hipitch = (double)thisnote->pitch;
-            hinote  = thisnote;
-            (*shaddoindex) = zz;
-        }
-    }
-    return(hinote);
-}
-
-/****************************** DO_GRP_INS **********************************
- *
- * Choose instr-no within group/decoration/motif or ornament.
- * Values of instr-no range are preset when instr is chosen for the
- * tset, in do_ev_ins().
- */
-
-int do_grp_ins(unsigned char thisinstr,unsigned char *val,dataptr dz)
-{
-    int exit_status;
-    int irange, ival;
-    if(dz->vflag[INS_TO_SCATTER]) {
-        if((irange = (int)(dz->iparam[TEXTURE_INSHI] - dz->iparam[TEXTURE_INSLO])) < 0) {
-            iswap((int *)&(dz->iparam[TEXTURE_INSHI]),(int *)&(dz->iparam[TEXTURE_INSLO]));
-            irange = -irange;
-        }
-        if(irange==0)
-            *val = (unsigned char)dz->iparam[TEXTURE_INSLO];
-        else {
-            if((exit_status = doperm(irange+1,PM_INSNO,&ival,dz))<0)        /* range INCLUSIVE for ints */
-                return(exit_status);
-            *val = (unsigned char)(ival     + dz->iparam[TEXTURE_INSLO]);
-        }
-    } else
-        *val = thisinstr;
-    return(FINISHED);
-}
-
-/***************************** PSCATX ************************************
- *
- * Select a random value within 'range', by permuting one of BANDCNT equal
- * ranges, and selecting a random value within the chosen range.
- */
-
-int pscatx(double range,double bottom,int pindex,double *val,dataptr dz)
-{
-    int k, exit_status;
-    double bandwidth, bandbottom, x;
-    if((exit_status = doperm((int)BANDCNT,pindex,&k,dz))<0)
-        return(exit_status);
-    bandwidth       = range/(double)BANDCNT;
-    bandbottom      = (double)k * bandwidth;
-    x  = (drand48() * bandwidth);
-    x += bandbottom;
-    *val = x + bottom;
-    return(FINISHED);
-}
-
-/*************************** DEL_NOTE ************************************/
-
-void del_note(noteptr thisnote,motifptr thismotif)
-{
-    if(thisnote->next!=(noteptr)0)
-        thisnote->next->last = thisnote->last;          /* 1 */
-    if(thisnote->last!=(noteptr)0)
-        thisnote->last->next = thisnote->next;          /* 2 */
-    else
-        thismotif->firstnote = thisnote->next;          /* 3 */
-    free(thisnote);                                 /* 4 */
-}
-
-/************************** TIMESORT ****************************
- *
- * Timesorts notes in a list
- *
- * (1)  Move the item with earliest time to start of list, and set this
- *      (minimum) time as maximum time also.
- *      For each item in the list....
- *   (2)   If this item is earlier than current latest item (maxtime)..
- *     (3)    Find where it should be in the list.
- *     (4)    move it to that location.
- *   (5)   Otherwise, set this item's time as latest time(maxtime).
- * (6)  Reset motifhead to start of notelist!!
- */
-
-int arrange_notes_in_timeorder(motifptr mtf)
-{
-    noteptr base, here, there, mark;
-    double thistime, maxtime;
-    if((base = mtf->firstnote)==(noteptr)0)
-        return(FINISHED);
-    maxtime = setup_first_notelist_time(&base);                     /* 1 */
-    here = base;
-    while(here!=(noteptr)0) {
-        if((thistime = here->ntime) < maxtime) {                /* 2 */
-            if((mark = here->last)==(noteptr)0) {
-                sprintf(errstr,"Problem (1) in arrange_notes_in_timeorder()\n");
-                return(PROGRAM_ERROR);
-            }
-            if((there = reverse_search_for_time(here,thistime))==(noteptr)0) {
-                sprintf(errstr,"Timing problem in arrange_notes_in_timeorder()\n");
-                return(PROGRAM_ERROR);
-            }                                               /* 3 */
-            move_notelist_item(here,there);                 /* 4 */
-            here = mark;
-        } else
-            maxtime = here->ntime;                  /* 5 */
-        here = here->next;
-    }
-    return reset_mtfhead(mtf);                                      /* 6 */
-}
-
-/************************* RESET_MTFHEAD ***************************
- *
- * Reset pointer to start of notelist.
- */
-
-int reset_mtfhead(motifptr mtf)
-{
-    noteptr here = mtf->firstnote;
-    if(mtf->firstnote==NULL) {
-        sprintf(errstr,"Problem in reset_mrfhead()\n");
-        return(PROGRAM_ERROR);
-    }
-    while(here->last!=(noteptr)0)
-        here = here->last;
-    mtf->firstnote = here;
-
-    return(FINISHED);
-}
-
-/************************** SETUP_FIRST_NOTELIST_TIME ***************************
- *
- * Put the earliest timed item in a list of notes into start of list.
- */
-
-double setup_first_notelist_time(noteptr *base)
-{
-    noteptr firstnote, here;
-    double  mintime, thistime;
-    firstnote = here = *base;
-    mintime   = (*base)->ntime;
-    while(here!=(noteptr)0) {
-        if((thistime = here->ntime)<mintime) {
-            firstnote = here;
-            mintime = thistime;
-        }
-        here = here->next;
-    }
-    if(firstnote!=(*base)) {
-        move_notelist_item(firstnote,(*base));
-        *base = firstnote;
-    }
-    return(mintime);
-}
-
-/************************* MOVE_NOTELIST_ITEM ***************************
- *
- * Move an item in a notelist from location a to BEFORE location b.
- */
-
-void move_notelist_item(noteptr a,noteptr b)
-{
-    if(a->last!=(noteptr)0)
-        a->last->next = a->next;
-    if(a->next!=(noteptr)0)
-        a->next->last = a->last;
-    a->next = b;
-    a->last = b->last;
-    if(b->last!=(noteptr)0)
-        b->last->next = a;
-    b->last = a;
-}
-
-/************************** REVERSE_SEARCH_FOR_TIME *****************************
- *
- * Reverse search note-list using a time as index, and return address
- * of note whose time is AFTER the input time.
- * WILL RETURN (noteptr)0 IF REFTIME IS OFF END OF LIST.
- */
-
-noteptr reverse_search_for_time(noteptr start,double reftime)
-{
-    noteptr here = start;
-    while(here->ntime >= reftime) {
-        if(here->last == (noteptr)0)
-            return(here);
-        here = here->last;
-    }
-    return(here->next);
-}
-
-/************************** ISWAP *****************************/
-
-void iswap(int *a,int *b)
-{
-    int temp;
-    temp = *a;
-    *a = *b;
-    *b = temp;
-}
-
-/****************************** SET_GROUP_PARAMS **********************************/
-
-int set_group_params
-(noteptr tsetnote,noteptr thisnote,double gpdense,double ampstep,double *thisamp,double *thistime,double thisdur,dataptr dz)
-{
-    int exit_status;
-    double thisgpdense, time_left;
-    *thisamp += ampstep;
-    thisnote->amp   = (float)*thisamp;
-    thisnote->dur   = (float)thisdur;
-    if(dz->vflag[FIXED_STEP])
-        *thistime += gpdense;
-    else {
-        if((exit_status = get_density_val(*thistime,&thisgpdense,dz))<0)
-            return(exit_status);
-        if((dz->tex->txflag & IS_DECOR) && dz->vflag[IS_PRE]) {
-            if((time_left = tsetnote->ntime - *thistime)<0.0) {
-                sprintf(errstr,"Error in assumptions: set_group_params()\n");
-                return(PROGRAM_ERROR);
-            }
-            time_left *= 0.66;
-            thisgpdense = min(time_left,thisgpdense);
-        }
-        *thistime += thisgpdense;
-    }
-    return(FINISHED);
-}
-
-/***************************** GETTRITYPE *****************************
- *
- * Choose a type, from up to three available types in bit-flag.
- * e.g.
- * Choose an amplitude type (flat,cresc,decresc) from 3 available types.
- * Choose a decoration-orientation type (above,below,mid) from 3 types.
- *
- * (1)  For each type in the bitflag.
- * (2)  If this option is flagged, count it.
- * (3)  IF this option is chosen, return its bit-number.
- * (4)  Advance the bitflag mask.
- */
-
-int gettritype(int k,unsigned stor,unsigned char *val)
-{
-    int v = 0, mask = 1, n;
-    k++;
-    for(n=0;n<3;n++) {                              /* 1 */
-        if(mask & stor)                         /* 2 */
-            v++;
-        if(k==v) {                              /* 3 */
-            *val = (unsigned char)n;
-            return(FINISHED);
-        }
-        mask <<= 1;                             /* 4 */
-    }
-    sprintf(errstr,"TEXTURE: Problem in gettritype()\n");
-    return(PROGRAM_ERROR);
-}
-
-/***************************  GET_DENSITY_VAL ******************************/
-
-int get_density_val(double thistime,double *gpdense,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getvalue(TEX_GPPACKHI,TEX_GPPACKLO,thistime,PM_GPDENS,gpdense,dz))<0)
-        return(PROGRAM_ERROR);
-
-    /* NEW MAR 2000 */
-    *gpdense *= MS_TO_SECS;
-
-    if(dz->param[TEX_PHGRID]>0.0)
-        *gpdense = quantise(*gpdense,dz->param[TEX_PHGRID]);
-
-    return FINISHED;
-}
-
-/**************************** SET_MOTIFS *******************************
- *
- * initialise all parameters of input motifs to be used for MOTIFS or
- * ORNAMENTS.
- *
- * (1)For each input motif (called a 'phrase').
- *    phrnotecnt[n] = 0;
- * (2)  Initialise count of number of notes to 0, maximum amplitude
- *      of phrase to 0.0, and lowest pitch to MIDITOP.
- * (3)  Go through each note of the motif.
- * (4)  Add up the number of notes in it.
- * (5)  Find it's lowest pitch.
- * (6)  Find it's loudest note (and set as phraseamp).
- * (7)  Establish dynamic range of phrase.
- * (8)  Transpose the motif into it's lowest possible register.
- * (9)  Ensure motif starts at zero time.
- * (10) Store addresses of last notes in phrases.
- */
-
-int set_motifs
-(int phrcount,motifptr *phrase,int *phrnotecnt,double *phraseamp,double *phrange,noteptr *phrlastnote)
-{
-    int exit_status;
-    int n;
-    double minpitch, mintime, minamp;
-    noteptr thisnote, lastnote = (noteptr)0;
-    for(n=0;n<phrcount;n++) {                                               /* 1 */
-        if((exit_status = arrange_notes_in_timeorder(phrase[n]))<0)
-            return(exit_status);
-        phrnotecnt[n] = 0;
-        phraseamp[n] = 0.0;                                                     /* 2 */
-        minamp   = DBL_MAX;
-        minpitch = MIDITOP;
-        mintime  = DBL_MAX;
-        thisnote = phrase[n]->firstnote;                        /* 3 */
-        while(thisnote!=(noteptr)0) {
-            phrnotecnt[n]++;                                                        /* 4 */
-            if(thisnote->pitch<minpitch)
-                minpitch = thisnote->pitch;                     /* 5 */
-            if(thisnote->ntime<mintime)
-                mintime  = thisnote->ntime;                     /* 5 */
-            if((double)thisnote->amp>phraseamp[n])
-                phraseamp[n] = (double)thisnote->amp;/* 6 */
-            if(thisnote->amp<minamp)
-                minamp = thisnote->amp;                         /* 6 */
-            thisnote = thisnote->next;
-        }
-        if(minamp  == DBL_MAX || mintime == DBL_MAX) {
-            sprintf(errstr,"Error parsing motif: set_motifs()\n");
-            return(PROGRAM_ERROR);
-        }
-        thisnote = phrase[n]->firstnote;
-        phrange[n] = phraseamp[n] - minamp;                     /* 7 */
-        while(thisnote!=(noteptr)0) {
-            thisnote->pitch = (float)(thisnote->pitch - (minpitch + MIDIBOT));      /* 8 */
-            thisnote->ntime = (float)(thisnote->ntime - mintime);                           /* 9 */
-            lastnote = thisnote;                                                                                            /* 10 */
-            thisnote = thisnote->next;
-        }
-        if((phrlastnote[n] = lastnote) == (noteptr)0) {
-            sprintf(errstr,"Zero length phrase encountered: set_motifs()\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    return(FINISHED);
-}
-
-void cyclicperm(dataptr dz)
-{
-    int n, t;
-    do {
-        for(n=0;n<dz->infilecnt;n++) {
-            t = (int)floor(drand48() * (n+1));
-            if(t==n) {
-                hprefix(n,dz->peakno,dz->infilecnt);
-            } else {
-                hinsert(n,t,dz->peakno,dz->infilecnt);
-            }
-        }
-    } while(dz->peakno[0] == dz->lastpeakno[dz->infilecnt - 1]);    // Avoid repetitions at perm boundaries.
-    for(n=0;n<dz->infilecnt;n++)
-        dz->lastpeakno[n] = dz->peakno[n];
-}
-
-void hinsert(int m,int t,int *perm,int permlen)
-{
-    hshuflup(t+1,perm,permlen);
-    perm[t+1] = m;
-}
-
-void hprefix(int m,int *perm,int permlen)
-{
-    hshuflup(0,perm,permlen);
-    perm[0] = m;
-}
-
-void hshuflup(int k,int *perm,int permlen)
-{
-    int n, *i;
-    int z = permlen - 1;
-    i = perm+z;
-    for(n = z;n > k;n--) {
-        *i = *(i-1);
-        i--;
-    }
-}
-
-#ifndef round
-
-int round(double a)
-{
-    return (int)floor(a + 0.5);
-}
-#endif

+ 0 - 623
dev/texture/prevsrc/prev-src/texture5.c

@@ -1,623 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
-
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-
-
-
-/* floatsam version */
-#include <stdio.h>
-#include <stdlib.h>
-#include <memory.h>                     /*RWD*/
-#include <structures.h>
-#include <tkglobals.h>
-#include <globcon.h>
-#include <processno.h>
-#include <modeno.h>
-#include <arrays.h>
-#include <texture.h>
-#include <cdpmain.h>
-
-#include <sfsys.h>
-#ifdef _DEBUG
-#include <assert.h>
-#endif
-
-#if defined unix || defined __GNUC__
-#define round(x) lround((x))
-#endif
-
-static int setup_splice(int st_splicecnt,double **splicebuf);
-static int generate_origdur_and_frq(double **origdur,double **origfrq,dataptr dz);
-static int init_soundout_set(sndoutptr *sndout);
-static int replace_tset_by_soundout_set(noteptr thisnote,sndoutptr *sndout,
-                                        double *origdur,double *origfrq,double  mindur,int st_splicecnt,dataptr dz);
-static int convert_tsetnote_to_sndout_item(noteptr thisnote,sndoutptr sndout,
-                                           double *origdur,double *origfrq,double mindur,int st_splicecnt,int *warning_set,dataptr dz);
-static int generate_previous_sndout(sndoutptr *sndout);
-static int get_thisdur(double *thisdur,noteptr thisnote,int thisins,
-                       double *origdur,double inv_trnsp,double mindur,dataptr dz);
-static int get_stereospace_compensation(double position,double *compensate);
-
-static int do_mix(sndoutptr sndout,double *splicebuf,dataptr dz);
-static int check_sequencing(sndoutptr sndout);
-static int add_samples_to_outbuf_from_inbuf(int *out_of_insamples,int * max_samp_written,
-                                            sndoutptr sndout,double *splicebuf,int splicelen,/*int*/float *lbuf,dataptr dz);
-static void unlink_sndoutptr_at_start_of_list(sndoutptr sndout);
-static void unlink_sndoutptr(sndoutptr sndout);
-static double get_interpd_value(unsigned int here,double ibufpos,sndoutptr sndout);
-static int  free_first_sndout(sndoutptr *sndout);
-
-//TW UPDATE 2002: to make texture from stereo sources (updated to flotsams)
-static int add_stereo_samples_to_outbuf_from_inbuf
-(int *out_of_insamples,int *max_samp_written,sndoutptr sndout,double *splicebuf,int splicelen,float *lbuffer,dataptr dz);
-static double get_interpd_value_stereo(unsigned int here,double ibufpos,double *chanval2,sndoutptr sndout);
-
-/**************************** PRODUCE_TEXTURE_SOUND *****************************/
-
-int produce_texture_sound(dataptr dz)
-{
-    int exit_status;
-    /*insamptr  *insound = dz->tex->insnd;*/
-    motifptr  tset     = dz->tex->timeset;
-    sndoutptr sndout;
-    noteptr   thisnote = tset->firstnote;
-    double *origdur, *origfrq, *splicebuf;
-    double mindur = (dz->frametime + TEXTURE_SAFETY) * MS_TO_SECS;
-    int st_splicecnt = round((dz->frametime * MS_TO_SECS) * dz->infile->srate);
-    if((exit_status = setup_splice(st_splicecnt,&splicebuf))<0)
-        return(exit_status);
-    if((exit_status = generate_origdur_and_frq(&origdur,&origfrq,dz))<0)
-        return(exit_status);
-    if((exit_status = init_soundout_set(&sndout))<0)
-        return(exit_status);
-    if((exit_status = replace_tset_by_soundout_set(thisnote,&sndout,origdur,origfrq,mindur,st_splicecnt,dz))<0)
-        return(exit_status);
-    free(origdur);
-    free(origfrq);
-    return do_mix(sndout,splicebuf,dz);
-}
-
-/************************** SETUP_SPLICE ************************/
-
-int setup_splice(int st_splicecnt,double **splicebuf)
-{
-    int n, m;
-    if((*splicebuf = (double *)malloc(st_splicecnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for splice buffer.\n");
-        return(MEMORY_ERROR);
-    }
-    for(m=0,n=st_splicecnt-1; n>=0; n--,m++)
-        (*splicebuf)[m] = (double)n/(double)st_splicecnt;
-    return(FINISHED);
-}
-
-/************************** GENERATE_ORIGDUR_AND_FRQ ************************/
-
-int generate_origdur_and_frq(double **origdur,double **origfrq,dataptr dz)
-{
-    int n;
-    if((*origdur = (double *)malloc(dz->infilecnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY to store original durations.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*origfrq = (double *)malloc(dz->infilecnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY to store original frqs.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n <dz->infilecnt;n++) {
-        //TW UPDATE: Now allowing stereo sources to be used to make texture
-        (*origdur)[n] = (double)dz->insams[n]/(double)dz->infile->channels/(double)dz->infile->srate;
-        (*origfrq)[n] = miditohz(((dz->tex->insnd)[n])->pitch);
-    }
-    return(FINISHED);
-}
-
-/************************** INIT_SOUNDOUT_SET ************************/
-
-int init_soundout_set(sndoutptr *sndout)
-{
-    if((*sndout = (sndoutptr)malloc(sizeof(struct soundout)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for soundout pointers.\n");
-        return(MEMORY_ERROR);
-    }
-    (*sndout)->last = (sndoutptr)0;
-    (*sndout)->next = (sndoutptr)0;
-    return(FINISHED);
-}
-
-/************************** REPLACE_TSET_BY_SOUNDOUT_SET ************************/
-
-int replace_tset_by_soundout_set
-(noteptr thisnote,sndoutptr *sndout,double *origdur,double *origfrq,double  mindur,int st_splicecnt,dataptr dz)
-{
-    int exit_status;
-    int warning_set = FALSE;
-    while((thisnote->next)!=(noteptr)0)     /* go to end of tset */
-        thisnote = thisnote->next;
-    while(thisnote!=(noteptr)0) {
-        if((exit_status = convert_tsetnote_to_sndout_item
-            (thisnote,*sndout,origdur,origfrq,mindur,st_splicecnt,&warning_set,dz))<0)
-            return(exit_status);
-        if((exit_status = generate_previous_sndout(sndout))<0)
-            return(exit_status);
-        if(thisnote->last!=NULL) {
-            thisnote = thisnote->last;              /* free tset from end backwards */
-            free(thisnote->next);
-        } else {
-            free(thisnote);
-            if((exit_status = free_first_sndout(sndout))<0)
-                return(exit_status);
-            thisnote = NULL;
-        }
-    }
-    return(FINISHED);
-}
-
-/************************** CONVERT_TSETNOTE_TO_SNDOUT_ITEM ************************/
-
-//TW "STEREO" defined in globcon.h
-#define MAXGAIN (1.0)
-
-int convert_tsetnote_to_sndout_item
-(noteptr thisnote,sndoutptr sndout,double *origdur,double *origfrq,double mindur,int st_splicecnt,int *warning_set,dataptr dz)
-{
-    int exit_status;
-    int thisins;
-    unsigned int insampcnt, st_osampcnt;
-    double indur;
-    double thisfrq,thisdur,trnspstep,inv_trnsp,thisamp,thispos,compensate;
-
-    thisins   = thisnote->instr;
-    thisfrq   = miditohz((double)thisnote->pitch);
-    trnspstep = thisfrq/origfrq[thisins];
-    inv_trnsp = 1.0/trnspstep;
-    if((exit_status = get_thisdur(&thisdur,thisnote,thisins,origdur,inv_trnsp,mindur,dz))<0)
-        return(exit_status);
-    indur       = thisdur * trnspstep;
-    //TW UPDATE now counting either mono samples or pairs-of-stereo-sample pairs (as with st_osampcnt) as possibly using stereo input
-    insampcnt   = min(dz->insams[thisins]/dz->infile->channels,round(indur * (double)dz->infile->srate));
-    st_osampcnt = round((double)insampcnt * inv_trnsp);
-    if(st_osampcnt <= (unsigned int)st_splicecnt) {
-        sprintf(errstr,"Error in samplecount calculations: convert_tsetnote_to_sndout_item()\n");
-        return(PROGRAM_ERROR);
-    }
-    thisamp   = thisnote->amp/(double)MIDITOP;
-    thispos   = thisnote->spacepos;
-    if((exit_status = get_stereospace_compensation(thispos,&compensate))<0)
-        return(exit_status);
-    if(thisamp > MAXGAIN) {
-#ifdef _DEBUG
-        assert(thisamp <= MAXGAIN);
-#endif
-        if(!(*warning_set)) {
-            fprintf(stdout,"WARNING: one or more events exceed max level. Adjusted.\n");
-            fflush(stdout);
-            *warning_set = TRUE;
-        }
-        thisamp = MAXGAIN;
-    }
-    sndout->inbuf       = ((dz->tex->insnd)[thisins])->buffer;
-    sndout->ibufcnt     = insampcnt;
-    sndout->st_sstttime = round(thisnote->ntime * dz->infile->srate);
-    sndout->st_sendtime = sndout->st_sstttime + st_osampcnt; /* Redundant variable: might need if func revised */
-    sndout->st_splicpos = sndout->st_sendtime - st_splicecnt;
-    sndout->ibufpos         = 0.0;
-    sndout->step            = trnspstep;
-    //TW UPDATE: in stereo-input case, only 1 gain value used, as no spatialisation takes place
-    if(dz->infile->channels==STEREO) {
-        sndout->lgain           = thisamp;
-    } else {
-        sndout->lgain           = thisamp * (1.0 - thispos) * compensate;
-        sndout->rgain           = thisamp * thispos * compensate;
-    }
-    return(FINISHED);
-}
-
-/************************** GENERATE_PREVIOUS_SNDOUT ************************/
-
-int generate_previous_sndout(sndoutptr *sndout)
-{
-    sndoutptr new;
-    if((new = (sndoutptr)malloc(sizeof(struct soundout)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for new soundout pointers.\n");
-        return(MEMORY_ERROR);
-    }
-    new->last     = (sndoutptr)0;
-    new->next     = *sndout;
-    (*sndout)->last = new;
-    *sndout = new;
-    return(FINISHED);
-}
-
-/************************** FREE_FIRST_SNDOUT ************************/
-
-int free_first_sndout(sndoutptr *sndout)
-{
-    if((*sndout = (*sndout)->next)==NULL) {
-        sprintf(errstr,"Problem in free_first_sndout()\n");
-        return(PROGRAM_ERROR);
-    }
-    free((*sndout)->last);
-    (*sndout)->last = NULL;
-    return(FINISHED);
-}
-
-/************************** GET_THISDUR ************************/
-
-int get_thisdur
-(double *thisdur,noteptr thisnote,int thisins,double *origdur,double inv_trnsp,double mindur,dataptr dz)
-{
-    double transposed_dur = origdur[thisins] * inv_trnsp;
-    *thisdur   = thisnote->dur;
-    if(*thisdur>transposed_dur)
-        *thisdur = transposed_dur;
-    else if(dz->vflag[TEX_IGNORE_DUR])
-        *thisdur = transposed_dur;
-    if(*thisdur<mindur) {
-        sprintf(errstr,
-                "too short dur generated (%lf : mindur = %lf): get_thisdur()\n",*thisdur,mindur);
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/************************** GET_STEREOSPACE_COMPENSATION ************************
- *
- * 1)   comp(ensation) is a factor which compensates for the apparent
- *              loss of perceived amplitude as a sound moves out of the absolute
- *              left or absolute right position (sound from a single loudspeaker)
- *              by simple linear interpolation.
- *              At first we define comp to vary LINERALY from 0.0 at L or R,
- *              to 1.0 in centre.
- * 2)   NONLIN makes this varation nonlinear, but smooth at the centre, and
- *              still between 0.0 and 1.0
- * 3)   As a signal of fixed perceived level moves from left to right (or v.v.)
- *              we wish to boost the amplitude from each loudspeaker somewhat,
- *              using a curve of the shape now defined.
- *              The maximum possible amplitude is 1.0. To define how much we should
- *              boost amplitude at any point on the L-R axis, we need to define
- *              a ratio (MAXBOOST) with which to multiply the signal.
- *              Multiplying comp-curve by this, defines a curve of amplitude-boosting values.
- * 4)   1.0 is now added to this curve, to give a multiplier of amplitude at
- *              each point along the left-right axis.
- *              And MAXBOOST is subtracted, so that the level
- *              from each loudspeaker when at maximum boost cannot exceed
- *              MAXGAIN (1.0).
- */
-
-#define NONLIN   (0.5)
-#define MAXBOOST (0.25)
-
-int get_stereospace_compensation(double position,double *compensate)
-{
-    double comp = 1.0 - (fabs((position * (double)2.0) - (double)1.0));     /* 9a */
-    comp = pow(comp,NONLIN);                    /* 9b */
-    comp *= MAXBOOST;                                   /* 9c */
-    comp += (1.0 - MAXBOOST);                   /* 9d */
-    *compensate = comp;
-    return(FINISHED);
-}
-
-/************************** DO_MIX ************************
- *
- * 1)   Position, in stereo-samples, of start-of-splice in this-sndout-struct =
- *                      sndout->st_splicpos
- *              Position in actual-samples of ditto =
- *                       sndout->st_splicpos * STEREO
- *              Position relative to start of current buffer =
- *                      (sndout->st_splicpos * STEREO) - (obufcnt * dz->buflen);
- *              Same position expressed relative to start-of-splice (so that value 0 = start_of_splice) =
- *                      -((sndout->st_splicpos * STEREO) - (obufcnt * dz->buflen));
- */
-
-int do_mix(sndoutptr sndout,double *splicebuf,dataptr dz)
-{
-    int exit_status;
-    int out_of_insamples;
-    /*unsigned int totaltime = 0;*/
-    int max_samp_written, n;
-    unsigned int this_sampend, obufcnt = 0;
-    int splicelen = round((dz->frametime * MS_TO_SECS) * dz->infile->srate) * STEREO;
-    sndoutptr startsnd = sndout, endsnd = sndout;
-    /*int*/float *lbuf;
-    //TW UPDATE handles stereo input files
-    int is_stereo = 0;
-    if(dz->infile->channels == STEREO)
-        is_stereo = 1;
-    //TW MOVED from texprepro
-    dz->infile->channels = STEREO;  /* for output time calculations */
-    if((exit_status = create_sized_outfile(dz->outfilename,dz))<0)
-        return(exit_status);
-
-    if((lbuf = (float *)malloc(dz->buflen * sizeof(float)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for mixing buffers.\n");
-        return(MEMORY_ERROR);
-    }
-    dz->sbufptr[0] = dz->sampbuf[0];
-    /* <--SAFETY CHECK */
-    if((exit_status = check_sequencing(sndout))<0)
-        return(exit_status);
-    /* SAFETY CHECK--> */
-    while(startsnd != NULL) {                                                                               /* until we reach end of event list */
-        this_sampend = (obufcnt+1) * dz->buflen;                /* get absolute samplecnt of end of current buf */
-        /* look for NEW events starting during this outbuf */
-        if(sndout!=NULL) {
-            while(sndout->st_sstttime * STEREO < this_sampend) {
-                sndout->obufpos  = (sndout->st_sstttime * STEREO) % dz->buflen;/* obufptr for new event */
-                sndout->st_splicpos = (sndout->st_splicpos * STEREO)-(obufcnt * dz->buflen);/* NOTE1 abv*/
-                sndout->st_splicpos = -(sndout->st_splicpos);                                                   /* NOTE 1 above */
-                sndout = sndout->next;
-                endsnd = sndout;                                          /* update the endmarker of the active events list */
-                if(endsnd == NULL)                                                                              /* if all events finished,break */
-                    break;
-            }
-        }
-        sndout = startsnd;                                                                               /* set start to 1st event still active */
-
-        memset((char *)lbuf,0,dz->buflen * sizeof(float));                                           /* empty output buffer */
-        if(sndout == endsnd) {                                      /* If there are NO active events during this buffer */
-            if(endsnd != NULL)                                                                       /* and we are not at end of event list */
-                max_samp_written = dz->buflen;                                            /* setup to write an empty buffer */
-            else {
-                sprintf(errstr,"Error in loop logic: do_mix()\n");
-                return(PROGRAM_ERROR);
-            }
-        } else
-            max_samp_written = 0;
-        while(sndout!= endsnd) {                                                                              /* look in all active buffers */
-            out_of_insamples = FALSE;
-
-            //TW UPDATE: handles stereo input
-            if(is_stereo) {
-                if((exit_status = add_stereo_samples_to_outbuf_from_inbuf
-                    (&out_of_insamples,&max_samp_written,sndout,splicebuf,splicelen,lbuf,dz))<0)
-                    return(exit_status);
-            } else {
-                if((exit_status = add_samples_to_outbuf_from_inbuf
-                    (&out_of_insamples,&max_samp_written,sndout,splicebuf,splicelen,lbuf,dz))<0)
-                    return(exit_status);
-            }
-            if(out_of_insamples) {                                                             /* if inbuf exhausted for THIS event */
-
-                if(sndout->next==NULL) {                                                                                   /* if at end of list */
-                    if(sndout->last==NULL) {                   /* if this is definitively the last active event */
-                        free(sndout);                                                                                                           /* free it */
-                        startsnd = NULL;                        /* and set ptr to NULL, so we dropout of outerloop */
-                        break;
-                    } else {                                                                 /* BUT if some previous event still active */
-                        sndout = sndout->last;                                                  /* unlink final event from list */
-                        free(sndout->next);
-                        sndout->next = NULL;
-                        sndout = sndout->next;                                                    /* move sndout to end of list */
-                    }
-                } else if(sndout==startsnd) {                                    /* if this is 1st active event in list */
-                    sndout   = sndout->next;                                                           /* proceed to next event */
-                    startsnd = sndout;                              /* move start of active list to this next event */
-                    unlink_sndoutptr_at_start_of_list(sndout->last);
-                } else {                                                                /* else if this is NOT 1st active event in list */
-                    sndout   = sndout->next;                                                           /* proceed to next event */
-                    unlink_sndoutptr(sndout->last);/* unlink the exhausted event from (active) list */
-                }
-            } else {                                                        /* else there is data remaining in inbuf for THIS event */
-                sndout->obufpos = 0;                                          /* so reset obufpos to start of next obuf */
-                sndout->st_splicpos += dz->buflen;/* reset relativeposition splice-start & nextbufstart */
-                sndout = sndout->next;                                                                     /* and proceed to next event */
-            }
-        }
-        if(startsnd!=NULL)                                /* If we're not at the end of ALL events, write a full buffer */
-            max_samp_written = dz->buflen;
-
-        for(n=0;n<max_samp_written;n++)
-            dz->sampbuf[0][n] = lbuf[n];
-        if(max_samp_written > 0) {
-            if((exit_status = write_samps(dz->sampbuf[0],max_samp_written,dz))<0)
-                return(exit_status);
-        }
-        obufcnt++;
-    }
-    /*if(dz->iparam[TEX_MAXOUT] > MAXSAMP) {*/
-    if(dz->param[TEX_MAXOUT] > F_MAXSAMP) {
-        fprintf(stdout,"WARNING: OVERLOAD: suggest attenuation by < %lf\n",
-                //TW UPDATE (need to factor in the attenation already being used to give correct new attenuation)
-                (((double)F_MAXSAMP/(double)dz->param[TEX_MAXOUT])) * dz->param[TEXTURE_ATTEN]);
-        fflush(stdout);
-    }
-    return(FINISHED);
-}
-
-/************************** CHECK_SEQUENCING ************************/
-
-int check_sequencing(sndoutptr sndout)
-{
-    unsigned int lasttime = sndout->st_sstttime;
-    unsigned int thistime;
-    while(sndout->next != (sndoutptr)0) {
-        sndout = sndout->next;
-        if((thistime = sndout->st_sstttime) < lasttime) {
-            sprintf(errstr,"Sequencing anomaly in sndout list: check_sequencing()\n");
-            return(PROGRAM_ERROR);
-        }
-        lasttime = thistime;
-    }
-    return(FINISHED);
-}
-
-/************************** ADD_SAMPLES_TO_OUTBUF_FROM_INBUF ************************/
-
-int add_samples_to_outbuf_from_inbuf
-(int *out_of_insamples,int *max_samp_written,sndoutptr sndout,double *splicebuf,int splicelen,float *lbuffer,dataptr dz)
-{
-    unsigned int thisopos = sndout->obufpos;
-    unsigned int here;
-    double hereval = 0.0;
-    float *lbuf    = lbuffer + thisopos;
-    float *lbufend = lbuffer + dz->buflen;
-    int splicpos  = sndout->st_splicpos + thisopos;
-    float outval, thismaxoutval;
-    int max_set = FALSE;
-    while(lbuf < lbufend) {
-        if((here = (unsigned int) sndout->ibufpos) >= sndout->ibufcnt) {        /* TRUNCATE : get current pos in inbuf */
-            *out_of_insamples = TRUE;
-            *max_samp_written = max(*max_samp_written,lbuf - lbuffer);
-            /* SAFETY CHECK--> */
-            if(splicpos < splicelen) {
-                sprintf(errstr,"BUM endsplice: add_samples_to_outbuf_from_inbuf()\n");
-                return(PROGRAM_ERROR);
-            }
-            /* <--SAFETY CHECK */
-
-            max_set = TRUE;
-            break;
-        }
-        hereval = get_interpd_value(here,sndout->ibufpos,sndout);
-        /* SAFETY FOR ARITHMETIC ROUNDING ERROS CALCULATING START OF SPLICE --> */
-        if(splicpos >= splicelen)
-            hereval = 0.0;
-        /* <--SAFETY */
-
-        if(splicpos >= 0)
-            hereval *= splicebuf[splicpos >> 1];
-        splicpos += STEREO;
-        outval =(float)( *lbuf + (hereval * sndout->lgain ));
-        if((thismaxoutval = (float) fabs(outval)) > dz->param[TEX_MAXOUT])
-            dz->param[TEX_MAXOUT] = thismaxoutval;
-        *lbuf  = outval;
-        lbuf++;
-        outval = (float)(*lbuf + (hereval * sndout->rgain));
-        if((thismaxoutval = (float) fabs(outval)) > dz->param[TEX_MAXOUT])
-            dz->param[TEX_MAXOUT] =  thismaxoutval;
-        *lbuf = outval;
-        lbuf++;
-        sndout->ibufpos += sndout->step;
-    }
-    if(!max_set)
-        *max_samp_written = dz->buflen;
-    return(FINISHED);
-}
-
-//TW UPDATE: NEW FUNCTIONfor stereo input (updated for flotsams)
-/************************** ADD_STEREO_SAMPLES_TO_OUTBUF_FROM_INBUF ************************/
-
-int add_stereo_samples_to_outbuf_from_inbuf
-(int *out_of_insamples,int *max_samp_written,sndoutptr sndout,double *splicebuf,int splicelen,float *lbuffer,dataptr dz)
-{
-    unsigned int thisopos = sndout->obufpos;
-    unsigned int here;
-    double chanval1, chanval2;
-    float *lbuf    = lbuffer + thisopos;
-    float *lbufend = lbuffer + dz->buflen;
-    int splicpos  = sndout->st_splicpos + thisopos;
-    float outval, thismaxoutval;
-    int max_set = FALSE;
-    while(lbuf < lbufend) {
-        if((here = (unsigned int)sndout->ibufpos)>=sndout->ibufcnt) {   /* TRUNCATE : get current pos in inbuf */
-            *out_of_insamples = TRUE;
-            *max_samp_written = max(*max_samp_written,lbuf - lbuffer);
-            if(splicpos < splicelen) {
-                sprintf(errstr,"BUM endsplice: add_samples_to_outbuf_from_inbuf()\n");
-                return(PROGRAM_ERROR);
-            }
-            max_set = TRUE;
-            break;
-        }
-        chanval1 = get_interpd_value_stereo(here,sndout->ibufpos,&chanval2,sndout);
-        /* SAFETY FOR ARITHMETIC ROUNDING ERROS CALCULATING START OF SPLICE --> */
-        if(splicpos >= splicelen) {
-            chanval1 = 0.0;
-            chanval2 = 0.0;
-        }
-        /* <--SAFETY */
-        if(splicpos >= 0) {
-            chanval1 *= splicebuf[splicpos >> 1];
-            chanval2 *= splicebuf[splicpos >> 1];
-        }
-        splicpos += STEREO;
-        outval = (float)(*lbuf + (chanval1 * sndout->lgain));
-        if((thismaxoutval = (float)fabs(outval))>dz->param[TEX_MAXOUT])
-            dz->param[TEX_MAXOUT] = thismaxoutval;
-        *lbuf  = outval;
-        lbuf++;
-        outval = (float)(*lbuf + (chanval2 * sndout->lgain));   /* only one gain val for stereo inputs: kept in lgain */
-        if((thismaxoutval = (float)fabs(outval))>dz->param[TEX_MAXOUT])
-            dz->param[TEX_MAXOUT] = thismaxoutval;
-        *lbuf = outval;
-        lbuf++;
-        sndout->ibufpos += sndout->step;
-    }
-    if(!max_set)
-        *max_samp_written = dz->buflen;
-    return(FINISHED);
-}
-
-/************************** GET_INTERPD_VALUE ************************/
-
-double get_interpd_value(unsigned int here,double ibufpos,sndoutptr sndout)
-{
-    unsigned int next = here+1;             /* NB  all inbufs have a wraparound (0val) point at end */
-    double frac     = ibufpos - (double)here;
-    double hereval  = (double)(sndout->inbuf[here]);
-    double nextval  = (double)(sndout->inbuf[next]);
-    double diff     = nextval - hereval;
-    diff    *= frac;
-    return(hereval+diff);
-}
-
-//TW UPDATE NEW FUNCTION for stereo input
-/************************** GET_INTERPD_VALUE_STEREO ************************/
-
-double get_interpd_value_stereo(unsigned int here,double ibufpos,double *chanval2,sndoutptr sndout)
-{
-    unsigned int next = here+1;             /* NB  all inbufs have a wraparound (0val) point at end */
-    double frac     = ibufpos - (double)here;
-    double hereval, nextval, diff;
-    double chanval1;
-    unsigned int sthere = here * 2, stnext = next * 2;
-    hereval  = (double)(sndout->inbuf[sthere]);
-    nextval  = (double)(sndout->inbuf[stnext]);
-    diff     = (nextval - hereval) * frac;
-    chanval1 = hereval+diff;
-    sthere++;
-    stnext++;
-    hereval  = (double)(sndout->inbuf[sthere]);
-    nextval  = (double)(sndout->inbuf[stnext]);
-    diff     = (nextval - hereval) * frac;
-    *chanval2 = hereval+diff;
-    return(chanval1);
-}
-
-/************************** UNLINK_SNDOUTPTR_AT_START_OF_LIST ************************/
-
-void unlink_sndoutptr_at_start_of_list(sndoutptr sndout)
-{
-    sndout->next->last = (sndoutptr)0;
-    free(sndout);
-}
-
-/************************** UNLINK_SNDOUTPTR ************************/
-
-void unlink_sndoutptr(sndoutptr sndout)
-{
-    sndout->next->last = sndout->last;
-    sndout->last->next = sndout->next;
-    free(sndout);
-}

+ 0 - 891
dev/texture/v8/ap_texture.c

@@ -1,891 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
- 
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- 
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
- 
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-/* 03/2020: TW/RWD: corrected usage message argument lists */
-
-/* floatsam version: no changes */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <structures.h>
-#include <cdpmain.h>
-#include <tkglobals.h>
-#include <pnames.h>
-#include <texture.h>
-#include <processno.h>
-#include <modeno.h>
-#include <globcon.h>
-#include <logic.h>
-#include <filetype.h>
-#include <mixxcon.h>
-#include <flags.h>
-#include <speccon.h>
-#include <arrays.h>
-#include <special.h>
-#include <formants.h>
-#include <sfsys.h>
-#include <osbind.h>
-
-#include <srates.h>
-
-/********************************************************************************************/
-/********************************** FORMERLY IN pconsistency.c ******************************/
-/********************************************************************************************/
-
-static int  texture_pconsistency(dataptr dz);
-
-/********************************************************************************************/
-/********************************** FORMERLY IN specialin.c *********************************/
-/********************************************************************************************/
-
-static int  get_the_notedatafile(char *filename,dataptr dz);
-
-/***************************************************************************************/
-/****************************** FORMERLY IN aplinit.c **********************************/
-/***************************************************************************************/
-
-/***************************** ESTABLISH_BUFPTRS_AND_EXTRA_BUFFERS **************************/
-
-int establish_bufptrs_and_extra_buffers(dataptr dz)
-{
-    /*int is_spec = FALSE;*/
-    dz->bptrcnt = 0;
-    dz->bufcnt  = 0;
-    switch(dz->process) {
-    case(SIMPLE_TEX):
-    case(TIMED):
-    case(GROUPS):
-    case(TGROUPS):
-    case(DECORATED):
-    case(PREDECOR): 
-    case(POSTDECOR):
-    case(ORNATE):
-    case(PREORNATE):
-    case(POSTORNATE):
-    case(MOTIFS):
-    case(TMOTIFS):
-    case(MOTIFSIN):
-    case(TMOTIFSIN):
-        dz->extra_bufcnt = 0;   dz->bufcnt = 1;
-        break;
-    default:
-        sprintf(errstr,"Unknown program type [%d] in establish_bufptrs_and_extra_buffers()\n",dz->process);
-        return(PROGRAM_ERROR);
-    }
-    return establish_groucho_bufptrs_and_extra_buffers(dz);
-}
-
-/***************************** SETUP_INTERNAL_ARRAYS_AND_ARRAY_POINTERS **************************/
-
-int setup_internal_arrays_and_array_pointers(dataptr dz)
-{
-    int n;
-    dz->ptr_cnt    = -1;        /* base constructor...process */
-    dz->array_cnt  = -1;
-    dz->iarray_cnt = -1;
-    dz->larray_cnt = -1;
-    switch(dz->process) {
-    case(SIMPLE_TEX):
-    case(TIMED):
-    case(GROUPS):
-    case(TGROUPS):
-    case(DECORATED):
-    case(PREDECOR): 
-    case(POSTDECOR):
-    case(ORNATE):
-    case(PREORNATE):
-    case(POSTORNATE):
-    case(MOTIFS):
-    case(TMOTIFS):
-    case(MOTIFSIN):
-    case(TMOTIFSIN):
-        dz->array_cnt = 1; dz->iarray_cnt = 6; dz->larray_cnt = 0; dz->ptr_cnt = 0; dz->fptr_cnt = 0;
-        break;
-    }
-
-/*** WARNING ***
-ANY APPLICATION DEALING WITH A NUMLIST INPUT: MUST establish AT LEAST 1 double array: i.e. dz->array_cnt = at least 1
-**** WARNING ***/
-
-
-    if(dz->array_cnt < 0 || dz->iarray_cnt < 0 || dz->larray_cnt < 0 || dz->ptr_cnt < 0 || dz->fptr_cnt < 0) {
-        sprintf(errstr,"array_cnt not set in setup_internal_arrays_and_array_pointers()\n");
-        return(PROGRAM_ERROR);
-    }
-
-    if(dz->array_cnt > 0) {
-        if((dz->parray  = (double **)malloc(dz->array_cnt * sizeof(double *)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for internal double arrays.\n");
-            return(MEMORY_ERROR);
-        }
-        for(n=0;n<dz->array_cnt;n++)
-            dz->parray[n] = NULL;
-    }
-    if(dz->iarray_cnt > 0) {
-        if((dz->iparray = (int     **)malloc(dz->iarray_cnt * sizeof(int *)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for internal int arrays.\n");
-            return(MEMORY_ERROR);
-        }
-        for(n=0;n<dz->iarray_cnt;n++)
-            dz->iparray[n] = NULL;
-    }
-    if(dz->larray_cnt > 0) {
-        if((dz->lparray = (int    **)malloc(dz->larray_cnt * sizeof(int *)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for internal long arrays.\n");
-            return(MEMORY_ERROR);
-        }
-        for(n=0;n<dz->larray_cnt;n++)
-            dz->lparray[n] = NULL;
-    }
-    if(dz->ptr_cnt > 0)   {
-        if((dz->ptr     = (double  **)malloc(dz->ptr_cnt  * sizeof(double *)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for internal pointer arrays.\n");
-            return(MEMORY_ERROR);
-        }
-        for(n=0;n<dz->ptr_cnt;n++)
-            dz->ptr[n] = NULL;
-    }
-    if(dz->fptr_cnt > 0)   {
-        if((dz->fptr = (float **)malloc(dz->fptr_cnt * sizeof(float *)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for internal float-pointer arrays.\n");
-            return(MEMORY_ERROR);
-        }
-        for(n=0;n<dz->fptr_cnt;n++)
-            dz->fptr[n] = NULL;
-    }
-    return(FINISHED);
-}
-
-/****************************** ASSIGN_PROCESS_LOGIC *********************************/
-
-int assign_process_logic(dataptr dz)
-{
-    switch(dz->process) {
-    case(SIMPLE_TEX):
-    case(TIMED):
-    case(GROUPS):
-    case(TGROUPS):
-    case(DECORATED):
-    case(PREDECOR):
-    case(POSTDECOR):
-    case(ORNATE):
-    case(PREORNATE):
-    case(POSTORNATE):
-    case(MOTIFS):
-    case(TMOTIFS):
-    case(MOTIFSIN):
-    case(TMOTIFSIN):
-        setup_process_logic(ONE_OR_MANY_SNDFILES,   UNEQUAL_SNDFILE,    SNDFILE_OUT,    dz);
-        break;
-    default:
-        sprintf(errstr,"Unknown process: assign_process_logic()\n");
-        return(PROGRAM_ERROR);
-        break;
-    }
-    if(dz->has_otherfile) {
-        switch(dz->input_data_type) {
-        case(ALL_FILES):
-        case(TWO_SNDFILES):
-        case(SNDFILE_AND_ENVFILE):
-        case(SNDFILE_AND_BRKFILE):
-        case(SNDFILE_AND_UNRANGED_BRKFILE):
-        case(SNDFILE_AND_DB_BRKFILE):
-            break;
-        case(MANY_SNDFILES):
-            if(dz->process==INFO_TIMELIST)
-                break;
-            /* fall thro */
-        default:
-            sprintf(errstr,"Most processes accepting files with different properties\n"
-                           "can only take 2 sound infiles.\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    return(FINISHED);
-}
-
-/***************************** SET_LEGAL_INFILE_STRUCTURE **************************
- *
- * Allows 2nd infile to have different props to first infile.
- */
-
-void set_legal_infile_structure(dataptr dz)
-{
-    switch(dz->process) {
-    default:
-        dz->has_otherfile = FALSE;
-        break;
-    }
-}
-
-/***************************************************************************************/
-/****************************** FORMERLY IN internal.c *********************************/
-/***************************************************************************************/
-
-/****************************** SET_LEGAL_INTERNALPARAM_STRUCTURE *********************************/
-
-int set_legal_internalparam_structure(int process,int mode,aplptr ap)
-{
-    int exit_status = FINISHED;
-    switch(process) {
-    case(SIMPLE_TEX):   case(TIMED):    case(GROUPS):   case(TGROUPS):
-    case(DECORATED):    case(PREDECOR): case(POSTDECOR):
-    case(ORNATE):       case(PREORNATE):case(POSTORNATE):
-    case(MOTIFS):       case(TMOTIFS):  case(MOTIFSIN): case(TMOTIFSIN):
-                        exit_status = set_internalparam_data("iiidddi",ap);         break;
-    default:
-        sprintf(errstr,"Unknown process in set_legal_internalparam_structure()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(exit_status);
-}
-
-/********************************************************************************************/
-/********************************** FORMERLY IN specialin.c *********************************/
-/********************************************************************************************/
-
-/********************** READ_SPECIAL_DATA ************************/
-
-int read_special_data(char *str,dataptr dz)
-{
-/*  int exit_status = FINISHED;*/
-    aplptr ap = dz->application;
-    switch(ap->special_data) {
-    case(TEX_NOTEDATA):         return get_the_notedatafile(str,dz);
-    default:
-        sprintf(errstr,"Unknown special_data type: read_special_data()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);   /* NOTREACHED */
-}
-
-/***************************** GET_THE_NOTEDATAFILE ****************************/
-
-int get_the_notedatafile(char *filename,dataptr dz)
-{
-    if((dz->fp = fopen(filename,"r"))==NULL) {
-        sprintf(errstr,"Failed to open notedata file %s\n",filename);
-        return(DATA_ERROR);
-    }
-    return(FINISHED);
-}
-
-/********************************************************************************************/
-/********************************** FORMERLY IN preprocess.c ********************************/
-/********************************************************************************************/
-
-/****************************** PARAM_PREPROCESS *********************************/
-
-int param_preprocess(dataptr dz)
-{
-/*  int exit_status = FINISHED;*/
-
-    switch(dz->process) {
-    case(SIMPLE_TEX):   case(TIMED):    case(GROUPS):   case(TGROUPS):
-    case(DECORATED):    case(PREDECOR): case(POSTDECOR):
-    case(ORNATE):       case(PREORNATE):case(POSTORNATE):
-    case(MOTIFS):       case(TMOTIFS):  case(MOTIFSIN): case(TMOTIFSIN):
-         return texture_preprocess(dz);
-    default:
-        sprintf(errstr,"PROGRAMMING PROBLEM: Unknown process in param_preprocess()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);   /* NOTREACHED */
-}
-
-/********************************************************************************************/
-/********************************** FORMERLY IN procgrou.c **********************************/
-/********************************************************************************************/
-
-/**************************** GROUCHO_PROCESS_FILE ****************************/
-
-int groucho_process_file(dataptr dz)   /* FUNCTIONS FOUND IN PROCESS.C */
-{   
-    int exit_status = FINISHED;
-
-    switch(dz->process) {
-    case(SIMPLE_TEX):   case(TIMED):    case(GROUPS):   case(TGROUPS):
-    case(DECORATED):    case(PREDECOR): case(POSTDECOR):
-    case(ORNATE):       case(PREORNATE):case(POSTORNATE):
-    case(MOTIFS):       case(MOTIFSIN): case(TMOTIFS):  case(TMOTIFSIN):
-        if((exit_status = make_texture(dz))<0)
-            return(exit_status);
-        if((exit_status = produce_texture_sound(dz))<0)
-            return(exit_status);
-        break;
-    default:
-        sprintf(errstr,"Unknown case in process_file()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/********************************************************************************************/
-/********************************** FORMERLY IN pconsistency.c ******************************/
-/********************************************************************************************/
-
-/****************************** CHECK_PARAM_VALIDITY_AND_CONSISTENCY *********************************/
-
-int check_param_validity_and_consistency(dataptr dz)
-{
-/*  int exit_status = FINISHED;*/
-    handle_pitch_zeros(dz);
-    switch(dz->process) {
-    case(SIMPLE_TEX): case(TIMED):      case(GROUPS):   case(TGROUPS):
-    case(DECORATED):  case(PREDECOR):   case(POSTDECOR):
-    case(ORNATE):     case(PREORNATE):  case(POSTORNATE):
-    case(MOTIFS):     case(TMOTIFS):    case(MOTIFSIN): case(TMOTIFSIN):
-                        return texture_pconsistency(dz);
-    }
-    return(FINISHED);
-}
-
-/***************************** PREPARE_TEXTURE_PARAMETERS ****************************/
-
-int texture_pconsistency(dataptr dz)
-{
-    double *p, *end;
-    int OK = TRUE;
-    if(dz->brksize[TEXTURE_INSLO]) {
-        p = dz->brk[TEXTURE_INSLO] + 1;
-        end = dz->brk[TEXTURE_INSLO] + (dz->brksize[TEXTURE_INSLO] * 2);
-        while(p < end) {
-            if(*p  > (double)dz->infilecnt) {
-                OK = FALSE;
-                break;
-            }
-            p += 2;
-        }
-    } else if(dz->iparam[TEXTURE_INSLO] > dz->infilecnt)
-        OK  = FALSE;
-    if(!OK) {
-        sprintf(errstr,"FIRST SND-IN-LIST TO USE > count of files entered: cannot proceed.\n");
-        return(DATA_ERROR);
-    }
-    OK = TRUE;
-    if(dz->brksize[TEXTURE_INSHI]) {
-        p = dz->brk[TEXTURE_INSHI] + 1;
-        end = dz->brk[TEXTURE_INSHI] + (dz->brksize[TEXTURE_INSHI] * 2);
-        while(p < end) {
-            if(*p  > (double)dz->infilecnt) {
-                OK = FALSE;
-                break;
-            }
-            p += 2;
-        }
-    } else if(dz->iparam[TEXTURE_INSHI] > dz->infilecnt)
-        OK  = FALSE;
-    if(!OK) {
-        sprintf(errstr,"LAST SND-IN-LIST TO USE > count of files entered: cannot proceed.\n");
-        return(DATA_ERROR);
-    }
-    return(FINISHED);
-}
-
-
-
-/********************************************************************************************/
-/********************************** FORMERLY IN buffers.c ***********************************/
-/********************************************************************************************/
-
-/**************************** ALLOCATE_LARGE_BUFFERS ******************************/
-
-int allocate_large_buffers(dataptr dz)
-{
-    switch(dz->process) {
-    case(SIMPLE_TEX):
-    case(TIMED):        case(GROUPS):       case(TGROUPS):
-    case(DECORATED):    case(PREDECOR):     case(POSTDECOR):
-    case(ORNATE):       case(PREORNATE):    case(POSTORNATE):
-    case(MOTIFS):       case(TMOTIFS):      case(MOTIFSIN): 
-    case(TMOTIFSIN):
-        return create_sndbufs(dz);
-    default:
-        sprintf(errstr,"Unknown program no. in allocate_large_buffers()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);   /* NOTREACHED */
-}
-
-/********************************************************************************************/
-/********************************** FORMERLY IN cmdline.c ***********************************/
-/********************************************************************************************/
-
-int get_process_no(char *prog_identifier_from_cmdline,dataptr dz)
-{
-    if     (!strcmp(prog_identifier_from_cmdline,"simple"))         dz->process = SIMPLE_TEX;
-    else if(!strcmp(prog_identifier_from_cmdline,"grouped"))        dz->process = GROUPS;
-    else if(!strcmp(prog_identifier_from_cmdline,"motifs"))         dz->process = MOTIFS;
-    else if(!strcmp(prog_identifier_from_cmdline,"motifsin"))       dz->process = MOTIFSIN;
-    else if(!strcmp(prog_identifier_from_cmdline,"decorated"))      dz->process = DECORATED;
-    else if(!strcmp(prog_identifier_from_cmdline,"predecor"))       dz->process = PREDECOR;
-    else if(!strcmp(prog_identifier_from_cmdline,"postdecor"))      dz->process = POSTDECOR;
-    else if(!strcmp(prog_identifier_from_cmdline,"ornate"))         dz->process = ORNATE;
-    else if(!strcmp(prog_identifier_from_cmdline,"preornate"))      dz->process = PREORNATE;
-    else if(!strcmp(prog_identifier_from_cmdline,"postornate"))     dz->process = POSTORNATE;
-    else if(!strcmp(prog_identifier_from_cmdline,"timed"))          dz->process = TIMED;
-    else if(!strcmp(prog_identifier_from_cmdline,"tgrouped"))       dz->process = TGROUPS;
-    else if(!strcmp(prog_identifier_from_cmdline,"tmotifs"))        dz->process = TMOTIFS;
-    else if(!strcmp(prog_identifier_from_cmdline,"tmotifsin"))      dz->process = TMOTIFSIN;
-    else {
-        sprintf(errstr,"Unknown program identification string '%s'\n",prog_identifier_from_cmdline);
-        return(USAGE_ONLY);
-    }
-
-    return FINISHED;
-}
-
-/********************************************************************************************/
-/********************************** FORMERLY IN usage.c *************************************/
-/********************************************************************************************/
-
-/******************************** USAGE1 ********************************/
-
-int usage1(void)
-{
-    fprintf(stdout, /* HAs to use fprintf because of kbhit */
-    "\n"
-    "USAGE:\ntexture NAME (mode) infile (infile2..etc) outfile notedata params:\n"
-    "\n"
-    "\nwhere NAME can be any one of\n"
-    "\n"
-    "\tTEXTURE MADE FROM ONE OR SEVERAL SOUND FILES\n"
-    "\n"
-    "simple   grouped    decorated    ornate       motifs\n"
-    "                    predecor     preornate    motifsin\n"
-    "                    postdecor    postornate\n"
-    "\n"
-    "\tTIMED TEXTURES MADE FROM ONE OR SEVERAL SOUND FILES\n"
-    "\n"
-    "timed     tmotifs   tmotifsin   tgrouped\n"
-    "\n"
-    "ORNAMENTS & MOTIFS   have user-specified pitch-shapes.\n"
-    "DECORATIONS & GROUPS have random pitch-shapes.\n"
-    "\n"
-    "Type 'texture simple' for more info on simple texture option.... etc.\n"
-    "\n"
-#ifdef IS_PC
-    "MORE??? ----- (hit keyboard)\n"
-    "\n");
-
-    while(!kbhit())
-        ;
-    if(kbhit()) {
-#else
-    "\n");
-#endif
-        fprintf(stdout,
-        "\n"
-        "*********************************************************************\n"
-        "SOME SPECIAL PARAMETER VALUES\n"
-        "*********************************************************************\n"
-        "GPSPACE: spatialisation of event-groups\n"
-        "\n"
-        "     0:still            1:scattered(default) 2:towards-texture-centre\n"
-        "     3:away-from-centre 4:follow-texmotion   5:contrary-to-motion\n"
-        "     4 & 5 only function if spatial position varies in time..\n"
-        "*********************************************************************\n"
-        "CONTOUR: amplitude contour of groups\n"
-        "\n"
-        "     0:mixed(default) 1:cresc     2:flat   3:decresc    4:c_or_fl\n"
-        "     5:c_or_d         6:d_or_fl  [7:directed_to_event   8:dir_or_flat]\n"
-        "*********************************************************************\n"
-        "CENTRING: how decoration pitches centre on decorated line pitches\n"
-        "\n"
-        "     0: centred(default) 1: above       2: below\n"
-        "     3: c_and_a          4: c_and_b     5: a_and_b     6: c_and_a_and_b\n"
-        "     In all cases except 0, pitchrange shifted to tally with line pitch\n\n"
-        "\n"
-        "*********************************************************************\n"
-        "       ALL OTHER PARAMS, except outdur, MAY VARY IN TIME.\n"
-        "*********************************************************************\n"
-        "\n"
-
-#ifdef IS_PC
-        "MORE??? ----- (hit keyboard)\n");
-    }
-    _getch();
-    while(!kbhit())
-        ;
-    if(kbhit()) {
-#else
-        "\n");
-#endif
-
-        fprintf(stdout,
-        "\n"
-        "*********************************************************************\n"
-        "HARMONIC SETS   use only the pitches specified.\n"
-        "\n"
-        "HARMONIC FIELDS duplicate the specified pitches in all 8vas.\n"
-        "*********************************************************************\n"
-        "NOTEDATA is in a textfile containing.....\n"
-        "*********************************************************************\n"
-        "     assumed MIDI 'pitch' of each input snd, specified on 1st line.\n"
-        "\n"
-        "   FOLLOWED BY, where ness,  NOTELIST(S), SPECIFIED THUS:-\n"
-        "\n"
-        "     #N (where N = no. of notes in notelist: follows by N lines of...)\n"
-        "     time(SECS)   infile_no    pitch(MIDI)    amp(MIDI)   dur(SECS)\n"
-        "\n"
-        "where times within motif must increase (or remain same, during chords)\n"
-        "*********************************************************************\n"
-        "NOTELISTS REPRESENT: IN THIS ORDER..\n"
-        "*********************************************************************\n"
-        "Notelist of notes in any timed, ornamented or decorated line in texture.\n"
-        "Notelist of notes in any harmonic field(s) or set(s) specified.\n"
-        "      (For more than one  hfield(hset),\n"
-        "      data should specify chords, placed at appropriae times.)\n"
-        "Notelist(s) of notes in any ornament(s) or motif(s) specified.\n"
-        "*********************************************************************\n");
-
-#ifdef IS_PC
-    }
-#endif
-    return(USAGE_ONLY);
-}
-
-/******************************** USAGE2 ********************************/
-
-int usage2(char *str)
-{
-    if(!strcmp(str,"simple")) {
-        fprintf(stdout,
-        "USAGE:\n"
-        "texture simple mode infile [infile2...] outfile notedata outdur packing scatter\n"
-        "   tgrid sndfirst sndlast  mingain maxgain  mindur maxdur  minpich maxpich omit\n"
-        "             [-aatten] [-pposition] [-sspread] [-rseed] [-w -c -p]\n"
-        "MODES:-\n"
-        "1)  ON A GIVEN HARMONIC-FIELD        3)  ON A GIVEN HARMONIC-SET\n"
-        "2)  ON CHANGING HARMONIC-FIELDS      4)  ON CHANGING HARMONIC-SETS\n"
-        "5)  NONE\n"
-        "notedata: infofile, insnd 'pitches',harmonic fields pitches etc.\n"
-        "outdur:           (min) duration of outfile\n"
-        "packing:          (average) time between event onsets.\n"  
-        "scatter:          randomisation of event-onsets (0 - %.0lf)\n"
-        "tgrid:            minstep(MS) quantised timegrid(for grp starttimes)(default 0)\n"
-        "sndfirst,sndlast: 1st,last snd to use,from list of insnds(range:1 - no.of snds)\n"
-        "mingain,maxgain:  minimum & maximum level of input events (1-127:default 64,64)\n"
-        "mindur,maxdur:    minimum & maximum duration of events in texture\n"
-        "minpich,maxpich:  minimum & maximum pitch (MIDI VALUE):\n"
-        "omit:             1 in \"omit\" events are silent.\n"
-        "                  less and less silent events as param increases.\n"
-        "                  at 64 (as at zero) NO events are silent.\n"
-        "atten:            overall attenuation of the output\n"
-        "position:         centre of output sound-image (0(Left) 1(Right): default 0.5)\n"
-        "spread:           spatial-spread of texture events (0 - 1(full-spread))\n"
-        "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-        "-w:               always play whole input-sound (ignoring duration values).\n"
-        "-c:               Choose files cyclically in listed order (ignore 'sndfirst','last').\n"
-        "-p:               Random permute each cycle (only when -c flag set).\n",MAX_SCAT_TEXTURE);
-    } else if(!strcmp(str,"timed")) {
-        fprintf(stdout,
-        "TIMED TEXTURE:  USAGE:\n"
-        "texture timed mode infile [infile2...]  outfile  notedata     outdur skiptime\n"
-        "             sndfirst sndlast mingain maxgain mindur maxdur minpitch maxpitch\n"
-        "             [-aatten] [-pposition] [-sspread] [-rseed] [-w]\n"
-        "MODES:-\n"
-        "1)  ON A GIVEN HARMONIC-FIELD        3)  ON A GIVEN HARMONIC-SET\n"
-        "2)  ON CHANGING HARMONIC-FIELDS      4)  ON CHANGING HARMONIC-SETS\n"
-        "5)  NONE\n"
-        "notedata: infofile, insnd 'pitches',texture timing,harmonic fields pitches etc.\n"
-        "outdur:            (min) duration of outfile\n"
-        "skiptime:          time between repetitions of timing motif in notedata\n"
-        "sndfirst,sndlast:  1st,last snd to use,from list of insnds(range:1 - all)\n"
-        "mingain,maxgain:   min & max level of input events (1-127:default 64,64)\n"
-        "mindur,maxdur:     min & max duration of events in texture\n"
-        "minpitch,maxpitch: min & max pitch (MIDI VALUE)\n"
-        "atten:             overall attenuation of the output\n"
-        "position:          centre of output sound-image (0(Left) 1(Right):default 0.5)\n"
-        "spread:            spatial-spread of texture events (0 - 1(full-spread))\n"
-        "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-        "-w:                always play whole input-sound (ignoring duration values).\n");
-    } else if(!strcmp(str,"grouped")) {
-        fprintf(stdout,
-        "TEXTURE OF EVENT-GROUPS: USAGE: texture grouped mode infile [infile2..] outfile\n"
-        "notedata outdur packing scatter tgrid\n"
-        "sndfirst sndlast mingain maxgain mindur maxdur minpitch maxpitch phgrid gpspace\n"
-        "gpsprange amprise contour gpsizelo gpsizehi gppaklo gppakhi gpranglo gpranghi\n"
-        "                   [-aatten] [-pposition] [-sspread] [-rseed] [-w] [-d] [-i]\n"
-        "MODES:-\n"
-        "1)ON HARMONIC-FIELD 2)CHANGING HFLDS 3)HARMONIC-SET 4)CHANGING HSETS 5)NONE\n"
-        "notedata:   infofile, 'pitch' of insnds, harmonic fields etc.\n"
-        "outdur:     (min) duration of outfile\n"
-        "packing:    (average) time between group onsets.\n"  
-        "scatter:    randomisation of event-onsets (0 - %.0lf)\n"
-        "tgrid:      minstep(MS) quantised timegrid(for grp starttimes)(default 0)\n"
-        "sndfirst,sndlast: 1st,last snd to use, from list of insnds(range:1 - all)\n"
-        "mingain,maxgain:  min & max level of input events (1-127:default 64,64)\n"
-        "mindur,maxdur:    min & max duration of events in texture\n"
-        "minpitch,maxpitch:min & max pitch (MIDI VALUE)\n"
-        "phgrid:     a timegrid (MS) applying WITHIN the groups\n"
-        "gpspace:    spatialisation of event-groups (Range 0-5: default 1)\n"
-        "gpsprange:  spatial range of event-groups (Range 0-1: default 1)\n"
-        "amprise:    amplitude change within groups: (0-127: default 0)\n"
-        "contour:    amplitude contour of groups (Range 0-6: default 0)\n"
-            /* NOTE : CARE all_types is 7 AND NOT 8 here */
-        "gpsizelo,gpsizehi:smallest,largest no. of events in groups\n"
-        "gppaklo,gppakhi:  shortest,longest time between event-onsets in groups (MS)\n"
-        "gpranglo,gpranghi:min,max pitchrange grps OR (hfields) no.of hf-notes range\n"
-        "atten:      overall attenuation of output\n"
-        "position:   centre of output sound-image (0(Left) 1(Right): default 0.5)\n"
-        "spread:     spatial-spread of texture events (0 - 1(full-spread))\n"
-        "seed:       same seed-no: same output on rerun(dflt 0: differs each time)\n"
-        "-w:         always play whole input-sound (ignore maxdur,mindur vals).\n"
-        "-d:         fixed timestep between groupnotes.\n"
-        "-i:         each group not confined to a fixed instr (default:fixed)\n",MAX_SCAT_TEXTURE);
-    } else if(!strcmp(str,"tgrouped")) {
-        fprintf(stdout,
-        "TIMED TEXTURE OF EVENT-GROUPS: USAGE: texture tgrouped mode infile [infile2..]\n"
-        "outfile notedata outdur skip sndfirst sndlast mingain maxgain mindur maxdur\n"
-        "minpitch maxpitch phgrid gpspace gpsprange amprise contour gpsizelo gpsizehi\n"
-        "gppacklo gppackhi gpranglo gpranghi\n"
-        "                   [-aatten] [-pposition] [-sspread] [-rseed] [-w] [-d] [-i]\n"
-        "MODES:-\n"
-        "1)  ON A GIVEN HARMONIC-FIELD        3)  ON A GIVEN HARMONIC-SET\n"
-        "2)  ON CHANGING HARMONIC-FIELDS      4)  ON CHANGING HARMONIC-SETS\n"
-        "5)  NONE\n"
-        "notedata: infofile, 'pitch' of insnds, timings for timed textures, hfields etc\n"
-        "outdur:           (min) duration of outfile\n"
-        "skip:             time between repetitions of timing motif in notedata\n"
-        "sndfirst,sndlast: 1st,last snd to use from list of insnds(range:1 - all)\n"
-        "mingain,maxgain:  min & max level of input events (1-127:default 64,64)\n"
-        "mindur,maxdur:    min & max duration of events in texture\n"
-        "minpitch,maxpitch:min & max pitch (MIDI VALUE)\n"
-        "phgrid:           timegrid (MS) applying WITHIN the groups\n"
-        "gpspace:          spatialisation of event-groups (Range 0-5: default 1)\n"
-        "gpsprange:        spatial range of event-groups (Range 0-1: default 1)\n"
-        "amprise:          amplitude change within groups: (0-127: default 0)\n"
-        "contour:          amplitude contour of groups (Range 0-6: default 0)\n"
-            /* NOTE : CARE all_types is 7 AND NOT 8 here */
-        "gpsizelo,gpsizehi:smallest & largest numbers of events in groups\n"
-        "gppacklo,gppackhi:shortest & longest time between event-onsets in groups (MS)\n"
-        "gpranglo,gpranghi:min,max pitchrange grps OR (hfields) no.of hf-notes range\n"
-        "atten:            overall attenuation of output\n"
-        "position:         centre of output sound-image (0(Left) 1(Right): default 0.5)\n"
-        "spread:           spatial-spread of texture events (0 - 1(full-spread))\n"
-        "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-        "-w:               always play whole input-sound (ignoring duration values).\n"
-        "-d:                fixed timestep between groupnotes.\n"
-        "-i:               each group not confined to a fixed instr (default:fixed)\n");
-    } else if(!strcmp(str,"decorated") || !strcmp(str,"predecor") || !strcmp(str,"postdecor")) {
-        fprintf(stdout,
-        "TEXTURE WITH DECORATIONS:USAGE:texture decorated|predecor|postdecor mode infile\n"
-        "[infile2..] outfile notedata outdur skiptime sndfirst sndlast mingain maxgain\n"
-        "mindur maxdur phgrid gpspace gpsprange amprise contour gpsizlo gpsizhi\n"
-        "gppaklo gppakhi gpranglo gpranghi centring\n"
-        "              [-aatten] [-ppos] [-ssprd] [-rseed] [-w] [-d] [-i] [-h] [-e] [-k]\n"
-        "MODES:-\n"
-        "1)ON HARMONIC-FIELD 2)CHANGING HFLDS 3)HARMONIC-SET 4)CHANGING HSETS 5)NONE\n"
-        "notedata:         infofile, 'pitch' of insnds, decoration shape etc.\n"
-        "outdur:           (min) duration outfile\n"
-        "skiptime:         time between repets of motif-to-decorate in notedata\n"
-        "sndfirst,sndlast: 1st,last snd to use, from input snds (range 1 - all)\n"
-        "mingain,maxgain:  min & max gain on input events (MIDI)\n"
-        "mindur,maxdur:    min & max duration of events in texture\n"
-        "phgrid:           timegrid (MS) applying WITHIN decors\n"
-        "gpspace:          spatialisation decor-groups (Range 0-5: default 1)\n"
-        "gpsprange:        spatial range decor-groups (Range 0-1: default 1)\n"
-        "amprise:          amplitude change within decors: (0-127: default 0)\n"
-        "contour:          amplitude contour of decors (Range 0-8: default 0)\n"
-        "gpsizlo,gpsizhi:  smallest,largest no. events in decors\n"
-        "gppaklo,gppakhi:  shortest,longest time between event-onsets in decors(MS)\n"
-        "gpranglo,gpranghi:min,max pitchrange decors OR (hfields) no.of hf-notes range\n"
-        "centring:         how decor pitches centre on line pitches(Range 0-7:default 0)\n"
-        "atten:            overall attenuation of output\n"
-        "pos:              centre of output sound-image (-1(Left) 1(Right): default 0)\n"
-        "sprd:             spatial-spread of texture events (0 - 1(full-spread))\n"
-        "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-        "-w: play all insnd(ignore min,maxdur) -h: dec TOPnote chord:(dflt:1st listed)\n"
-        "-d: fixed timestep btwn decornotes    -e: dec all notes of chords\n"
-        "-i: instrs vary in decor(dflt:fixed)  -k: discard orig line, after decor\n");
-    } else if(!strcmp(str,"ornate") || !strcmp(str,"preornate") || !strcmp(str,"postornate")) {
-        fprintf(stdout,
-        "TEXTURE WITH ORNAMENTS: USAGE:\n"
-        "texture ornate|preornate|postornate mode infile [infile2...] outfile notedata\n"
-        "outdur skiptime sndfirst sndlast   mingain maxgain  mindur maxdur\n"
-        "phgrid gpspace gpsprange  amprise  contour   multlo   multhi\n"
-        "          [-aatten] [-pposition] [-sspread] [-rseed] [-w] [-d] [-i] [-h] [-e]\n"
-        "MODES:-\n"
-        "1)ON HARMONIC-FIELD 2)CHANGING HFLDS 3)HARMONIC-SET 4)CHANGING HSETS 5)NONE\n"
-        "notedata:   infofile, 'pitch' of insnds, notes in ornaments, hfields etc.\n"
-        "outdur:           (min) duration of outfile\n"
-        "skiptime:         time between repetitions of motif-to-ornament in notedata\n"
-        "sndfirst,sndlast: 1st,last snd to use, from input snds (range 1 - all)\n"
-        "mingain,maxgain:  min & max level of input events (1-127:default 64,64)\n"
-        "mindur,maxdur:    min & max duration of events in texture\n"
-        "phgrid:           a timegrid (MS) applying WITHIN the ornaments\n"
-        "gpspace:          spatialisation of event-groups (Range 0-5: default 1)\n"
-        "gpsprange:        spatial range of event-groups (Range 0-1: default 1)\n"
-        "amprise:          amplitude change within ornaments: (0-127: default 0)\n"
-        "contour:          amplitude contour of groups (Range 0-8: default 0)\n"
-        "multlo, multhi:   min & max multiplier of total input duration of motif\n"
-        "atten:            overall attenuation of the output\n"
-        "position:         centre of output sound-image (0(Left) 1(Right):default 0.5)\n"
-        "spread:           spatial-spread of texture events (0 - 1(full-spread))\n"
-        "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-        "-w:               always play whole input-sound (ignoring duration values).\n"
-        "-d:               ornament notes all have same duration as ornamented note\n"
-        "-i:               orns not confined to instr of ornd-note (default:same note)\n"
-        "-h:               orns on highest note of any chord:(default:1st note listed)\n"
-        "-e:               ornaments on all notes of any chord.\n");
-    } else if(!strcmp(str,"motifsin")) {        
-        fprintf(stdout,
-        "TEXTURE OF MOTIFS, FORCED ONTO A HARMONIC FIELD: USAGE:\n"
-        "texture motifsin mode infile [infile2..] outfile notedata outdur packing\n"
-        "scatter tgrid sndfirst sndlast mingain maxgain \n"
-        "minpitch maxpitch phgrid gpspace gpsprange amprise  contour multlo multhi\n"
-        "                [-aatten] [-pposition] [-sspread] [-rseed] [-w] [-d] [-i]\n"
-        "MODES:-\n"
-        "1) ON HARMONIC-FIELD 2) CHANGING HFLDS 3) HARMONIC-SET 4) CHANGING HSETS\n"
-        "notedata: infofile,'pitch' of insnds, timings for timed textures, hfields etc\n"
-        "outdur:             (min) duration of outfile\n"
-        "packing:            (average) time between motif onsets.\n"
-        "scatter:            randomisation of event-onsets (0 - %.0lf)\n"
-        "tgrid:              minstep(MS) quantised timegrid (for mtf starttimes)(dflt 0)\n"
-        "sndfirst,sndlast:   1st,last snd to use, from input snds (range 1 - all)\n"
-        "mingain,maxgain:    min & max level of input events (1-127:default 64,64)\n"
-        "minpitch,maxpitch:  min & max pitch (MIDI VALUE)\n"
-        "phgrid:             a timegrid (MS) applying WITHIN the motifs\n"
-        "gpspace:            spatialisation of event-groups (Range 0-5: default 1)\n"
-        "gpsprange:          spatial range of event-groups (Range 0-1: default 1)\n"
-        "amprise:            amplitude change within motifs: (0-127: default 0)\n"
-        "contour:            amplitude contour of groups (Range 0-6: default 0)\n"
-            /* NOTE : CARE all_types is 7 AND NOT 8 here */
-        "multlo, multhi:     min & max multiplier of total input duration of motif\n"
-        "atten:              overall attenuation of the output\n"
-        "position:           centre of output sound-image (0(Left) 1(Right):default 0.5)\n"
-        "spread:             spatial-spread of texture events (0 - 1(full-spread))\n"
-        "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-        "-w:                 always play whole input-sound (ignoring duration values).\n"
-        "-d                  notes within any one motif all have same duration.\n"
-        "-i:                 motif not each confined to fixed instr (default:fixed)\n",MAX_SCAT_TEXTURE);
-    } else if(!strcmp(str,"tmotifsin")) {       
-        fprintf(stdout,
-        "TIMED TEXTURE OF MOTIFS, FORCED ONTO A HARMONIC FIELD: USAGE:\n"
-        "texture tmotifsin mode infile [infile2...] outfile notedata sndfirst sndlast\n"
-        "mingain maxgain minpich maxpich phgrid gpspace gpsprange\n"
-        "amprise contour multlo multhi [-aatten] [-ppos] [-sspread] [-rseed] [-w] [-d]\n"
-        "MODES:-\n"
-        "1) ON HARMONIC-FIELD 2) CHANGING HFLDS 3) HARMONIC-SET 4) CHANGING HSETS\n"
-        "notedata:    infofile, 'pitch' of insnds,motifs,texture timings,hfields etc..\n"
-        "outdur:           (min) duration of outfile\n"
-        "skiptime:         time between repetitions of timing motif in notedata\n"
-        "sndfirst,sndlast: 1st,last snd to use, from input snds (range 1 - all)\n"
-        "mingain,maxgain:  minimum & maximum level of input events (1-127:default 64,64)\n"
-        "minpich,maxpich:  min & max pitch (MIDI VALUE)\n"
-        "phgrid:           a timegrid (MS) applying WITHIN the motifs\n"
-        "gpspace:          spatialisation of event-groups (Range 0-5: default 1)\n"
-        "gpsprange:        spatial range of event-groups (Range 0-1: default 1)\n"
-        "amprise:          amplitude change within motifs: (0-127: default 0)\n"
-        "contour:          amplitude contour of groups (Range 0-6: default 0)\n"
-            /* NOTE : CARE all_types is 7 AND NOT 8 here */
-        "multlo, multhi:   min & max multiplier of total input duration of motif\n"
-        "atten:            overall attenuation of the output\n"
-        "pos:              centre of output sound-image (0(Left) 1(Right):default 0.5)\n"
-        "spread:           spatial-spread of texture events (0 - 1(full-spread))\n"
-        "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-        "-w:               always play whole input-sound (ignoring duration values).\n"
-        "-d:               notes in any one motif all have same duration as timing note.\n"
-        "-i:               motifs not each confined to a fixed instrument (default: fixed)\n");
-    } else if(!strcmp(str,"motifs")) {      
-        fprintf(stdout,
-        "TEXTURE OF MOTIFS, (1ST NOTES ONLY, FORCED ONTO HARMONIC FIELD/SET, IF USED)\n"
-        "USAGE: texture motifs mode infile [infile2...] outfile notedata outdur packing\n"
-        "scatter tgrid sndfirst sndlast mingain maxgain minpich maxpich\n"
-        "phgrid gpspace gpsprange amprise contour multlo multhi\n"
-        "                 [-aatten] [-pposition] [-sspread] [-rseed] [-w] [-d]\n"
-        "MODES:-\n"
-        "1)ON HARMONIC-FIELD 2)CHANGING HFLDS 3)HARMONIC-SET 4)CHANGING HSETS 5)NONE\n"
-        "notedata: infofile, 'pitch' of insnds, timings for timed textures,hfields etc.\n"
-        "outdur:             (min) duration of outfile\n"
-        "packing:            (average) time between motif onsets.\n"
-        "scatter:            randomisation of event-onsets (0 - %.0lf)\n"
-        "tgrid:              minstep(MS) quantised timegrid (for mtf starttimes)(dflt 0)\n"
-        "sndfirst,sndlast:   1st,last snd to use, from input snds (range 1 - all)\n"
-        "mingain,maxgain:    min & max level of input events (1-127:default 64,64)\n"
-        "minpich,maxpich:    min & max pitch (MIDI VALUE)\n"
-        "phgrid:             a timegrid (MS) applying WITHIN the motifs\n"
-        "gpspace:            spatialisation of event-groups (Range 0-5: default 1)\n"
-        "gpsprange:          spatial range of event-groups (Range 0-1: default 1)\n"
-        "amprise:            amplitude change within motifs: (0-127: default 0)\n"
-        "contour:            amplitude contour of groups (Range 0-6: default 0)\n"
-            /* NOTE : CARE all_types is 7 AND NOT 8 here */
-        "multlo, multhi:     min & max multiplier of total input duration of motif\n"
-        "atten:              overall attenuation of the output\n"
-        "position:           centre of output sound-image (0(Left) 1(Right):default 0.5)\n"
-        "spread:             spatial-spread of texture events (0 - 1(full-spread))\n"
-        "seed:               same seed-no: same output on rerun(dflt 0: differs each time)\n"
-        "-w:                 always play whole input-sound (ignoring duration values).\n"
-        "-d                  notes of any one motif all have same duration.\n"
-        "-i:                 motif not each confined to fixed instr (default:fixed)\n",MAX_SCAT_TEXTURE);
-    } else if(!strcmp(str,"tmotifs")) {
-        fprintf(stdout,
-        "TIMED TEXTURE OF MOTIFS, THEMSELVES NOT FORCED ONTO HARMONIC FIELD: USAGE:\n"
-        "texture tmotifs mode infile [infile2...] outfile notedata outdur skip\n"
-        "sndfirst sndlast mingain maxgain minpitch maxpitch phgrid\n"
-        "gpspace gpsprange amprise contour multlo multhi\n"
-        "                    [-aatten] [-pposition] [-sspread] [-rseed] [-w] [-d]\n"
-        "MODES:-\n"
-        "1)ON HARMONIC-FIELD 2)CHANGING HFLDS 3)HARMONIC-SET 4)CHANGING HSETS 5)NONE\n"
-        "notedata:  infofile, 'pitch' of insnds,texture timings,motifs,hfields etc....\n"
-        "outdur:             (min) duration of outfile\n"
-        "skip:               time between repetitions of timing motif in notedata\n"
-        "sndfirst,sndlast:   1st,last snd to use, from input snds (range 1 - all)\n"
-        "mingain,maxgain:    min & max level of input events (1-127:default 64,64)\n"
-        "minpitch,maxpitch:  min & max pitch (MIDI VALUE)\n"
-        "phgrid:             a timegrid (MS) applying WITHIN the motifs\n"
-        "gpspace:            spatialisation of event-groups (Range 0-5: default 1)\n"
-        "gpsprange:          spatial range of event-groups (Range 0-1: default 1)\n"
-        "amprise:            amplitude change within motifs: (0-127: default 0)\n"
-        "contour:            amplitude contour of groups (Range 0-6: default 0)\n"
-            /* NOTE : CARE all_types is 7 AND NOT 8 here */
-        "multlo, multhi:     min & max multiplier of total input duration of motif\n"
-        "atten:              overall attenuation of the output\n"
-        "position:           centre of output sound-image (0(Left) 1(Right):default 0.5)\n"
-        "spread:             spatial-spread of texture events (0 - 1(full-spread))\n"
-        "seed:             same seed-no: same output on rerun(dflt 0: differs each time)\n"
-        "-w:                 always play whole input-sound (ignoring duration values).\n"
-        "-d:                 motif notes all have same duration as ornamented note\n"
-        "-i:                 motif not each confined to fixed instr (default:fixed)\n");
-    } else
-        fprintf(stdout,"Unknown option '%s'\n",str);
-    return(USAGE_ONLY);
-}
-
-/******************************** USAGE3 ********************************/
-
-int usage3(char *str1,char *str2)
-{
-    sprintf(errstr,"Insufficient parameters on command line.\n");
-    return(USAGE_ONLY);
-}
-
-/******************************** INNER_LOOP (redundant)  ********************************/
-
-int inner_loop
-(int *peakscore,int *descnt,int *in_start_portion,int *least,int *pitchcnt,int windows_in_buf,dataptr dz)
-{
-    return(FINISHED);
-}

+ 0 - 234
dev/texture/v8/main.c

@@ -1,234 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
- 
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- 
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
- 
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-/* floatsam version: no changes */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <structures.h>
-#include <tkglobals.h>
-#include <texture.h>
-#include <filetype.h>
-#include <processno.h>
-#include <modeno.h>
-#include <formants.h>
-#include <cdpmain.h>
-#include <special.h>
-#include <logic.h>
-#include <globcon.h>
-#include <cdpmain.h>
-#include <sfsys.h>
-#include <ctype.h>
-
-char errstr[6000];
-
-/*extern*/ int sloom = 0;
-/*extern*/ int sloombatch = 0;
-/*extern*/ int anal_infiles = 0;
-/*extern*/ int is_converted_to_stereo = -1;
-const char* cdp_version = "8.0.1";
-
-/**************************************** MAIN *********************************************/
-
-int main(int argc,char *argv[])
-{
-    int exit_status;
-    dataptr dz = NULL;
-/*  char *special_data_string = NULL;*/
-    char **cmdline;
-    int  cmdlinecnt;
-    aplptr ap;
-    int *valid = NULL;
-    int is_launched = FALSE;
-    int  validcnt;
-
-    if(argc==2 && (strcmp(argv[1],"--version") == 0)) {
-        fprintf(stdout,"%s\n",cdp_version);
-        fflush(stdout);
-        return 0;
-    }
-                        /* CHECK FOR SOUNDLOOM */
-//TW UPDATE
-    if((sloom = sound_loom_in_use(&argc,&argv)) > 1) {
-        sloom = 0;
-        sloombatch = 1;
-    }
-
-    if(!sloom) {
-        if((exit_status = allocate_and_initialise_validity_flags(&valid,&validcnt))<0) {
-            print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-            return(FAILED);
-        }
-    }
-
-    if(sflinit("cdp")){
-        sfperror("cdp: initialisation\n");
-        return(FAILED);
-    }
-
-                          /* SET UP THE PRINCIPLE DATASTRUCTURE */
-    if((exit_status = establish_datastructure(&dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-                      
-    if(!sloom) {
-                              /* INITIAL CHECK OF CMDLINE DATA */
-        if((exit_status = make_initial_cmdline_check(&argc,&argv))<0) {
-            print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-            return(FAILED);
-        }
-        cmdline    = argv;  /* GET PRE_DATA, ALLOCATE THE APPLICATION, CHECK FOR EXTRA INFILES */
-        cmdlinecnt = argc;
-        if((exit_status = get_process_and_mode_from_cmdline(&cmdlinecnt,&cmdline,dz))<0) {
-            print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-            return(FAILED);
-        }       
-        if((exit_status = setup_particular_application(dz))<0) {
-            print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-            return(FAILED);
-        }
-        if((exit_status = count_and_allocate_for_infiles(cmdlinecnt,cmdline,dz))<0) {
-            print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-            return(FAILED);
-        }
-    } else {
-        if((exit_status = parse_tk_data(argc,argv,&cmdline,&cmdlinecnt,dz))<0) {    /* includes setup_particular_application()      */
-            exit_status = print_messages_and_close_sndfiles(exit_status,is_launched,dz);/* and cmdlinelength check = sees extra-infiles */
-            return(exit_status);         
-        }
-    }
-
-    ap = dz->application;
-
-/*********************************************************************************************************************
-       cmdline[0]                         2 vals                              ACTIVE         
-TK      (infile) (more-infiles) (outfile) (flag val) (formantsqksrch) (special) params  options   variant-params  flags
-CMDLINE (infile) (more-infiles) (outfile) (formants) (formantsqksrch) (special) params  POSSIBLY  POSSIBLY      POSSIBLY
-                                          1 val
-*********************************************************************************************************************/
-
-    if((exit_status = parse_infile_and_hone_type(cmdline[0],valid,dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-
-    if((exit_status = setup_param_ranges_and_defaults(dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-
-                    /* OPEN FIRST INFILE AND STORE DATA, AND INFORMATION, APPROPRIATELY */
-
-    if(dz->input_data_type!=NO_FILE_AT_ALL) {
-        if((exit_status = open_first_infile(cmdline[0],dz))<0) {
-            print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-            return(FAILED);
-        }
-//TW UPDATE
-        cmdlinecnt--;
-        cmdline++;
-    }
-    
-/*********************************************************************************************************************
-        cmdline[0]                 2 vals                              ACTIVE
-TK      (more-infiles) (outfile) (flag val) (formantsqksrch) (special) params  options   variant-params  flags
-CMDLINE (more-infiles) (outfile) (formants) (formantsqksrch) (special) params  POSSIBLY  POSSIBLY         POSSIBLY
-                                   1 val
-*********************************************************************************************************************/
-
-    if((exit_status = handle_extra_infiles(&cmdline,&cmdlinecnt,dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-
-/*********************************************************************************************************************
-        cmdline[0]    2                                 ACTIVE
-TK      (outfile) (flag val) (formantsqksrch) (special) params  options   variant-params  flags
-CMDLINE (outfile) (formants) (formantsqksrch) (special) params  POSSIBLY  POSSIBLY         POSSIBLY
-                      1
-*********************************************************************************************************************/
-
-    if((exit_status = handle_outfile(&cmdlinecnt,&cmdline,is_launched,dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-
-/****************************************************************************************
-        cmdline[0]                             ACTIVE
-TK      (flag val) (formantsqksrch) (special) params  options   variant-params  flags
-CMDLINE (formants) (formantsqksrch) (special) params  POSSIBLY  POSSIBLY        POSSIBLY
-*****************************************************************************************/
-
-    if((exit_status = handle_formants(&cmdlinecnt,&cmdline,dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-    if((exit_status = handle_formant_quiksearch(&cmdlinecnt,&cmdline,dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-    if((exit_status = handle_special_data(&cmdlinecnt,&cmdline,dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
- 
-/****************************************************************************************
-        cmdline[0]
-TK      active_params   options         variant-params  flags
-CMDLINE active_params   POSSIBLY        POSSIBLY        POSSIBLY
-*****************************************************************************************/
-
-    if((exit_status = read_parameters_and_flags(&cmdline,&cmdlinecnt,dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-
-    if((exit_status = check_param_validity_and_consistency(dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-
-    is_launched = TRUE;
-
-    if((exit_status = allocate_large_buffers(dz))<0){
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-    if((exit_status = param_preprocess(dz))<0){
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-    if((exit_status = groucho_process_file(dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-    if((exit_status = complete_output(dz))<0) {
-        print_messages_and_close_sndfiles(exit_status,is_launched,dz);
-        return(FAILED);
-    }
-    exit_status = print_messages_and_close_sndfiles(FINISHED,is_launched,dz);
-    free(dz);
-    return(SUCCEEDED);
-}
-

+ 0 - 191
dev/texture/v8/texperm.c

@@ -1,191 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
- 
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- 
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
- 
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-/* floatsam version: no changes */
-#include <stdio.h>
-#include <stdlib.h>
-#include <structures.h>
-#include <tkglobals.h>
-#include <texture.h>
-#include <globcon.h>
-#include <arrays.h>
-
-#include <osbind.h>
-
-static void rndpermm(int k,int pindex,int **permm,dataptr dz);
-static void insert(int m,int t,int pindex,int **permm,dataptr dz);
-static void prefix(int m,int pindex,int **permm,dataptr dz);
-static void shuflup(int k,int pindex, int **permm,dataptr dz);
-
-/******************************** DOPERM *********************************
- *
- * Either deliver next item in a permuted set, or (if set exhausted)
- * generate a randon permutation of the set and deliver its first
- * element.
- *
- * (1)  If this permset does not have the same length as the last...
- * (2)    Set a new permset length.
- * (3)    If a permset already exists (i.e. this is not first)
- *    Free the permset space, and malloc a new space of correct size,
- * (4)    Create a random permutation of elements into the permset.
- * (5)    Set the pointer-to-the-set to 0.
- * (6)    Set the size of the previous perm (which will be this one,
- *    next time!) to this permset size.
- * (6a) Whether or not a new perm set has been set up...
- * (7)    Get the value of the next item in the current permset,
- *    incrementing the set pointer in the process.
- * (8)    If this has the same value as the previous-one-output-from-doperm
- *    increment the repetition counter.
- * (9)    Otherwise set the repetition counter to 1.
- * (10)   If the set pointer has run beyond the permset.
- * (11)     reset the pointer to 0.
- * (12)     generate a new random perm (of same length).
- * (13) Continue this process if the number of permissible repetitions
- *  is exceeded.
- * (14) Set the value for lastpermval, for next call.
- * (15) Return the value.
- */
-
-int doperm(int k,int pindex,int *val,dataptr dz)
-{
-    int i, OK;
-    int **permm = dz->tex->perm;
-    if(pindex >= PERMCNT) {
-        sprintf(errstr,"doperm(): Perm index %d too big (max = %d)\n",pindex,PERMCNT);
-        return(PROGRAM_ERROR);
-    }
-    if(k <= 1) {
-        if(k>=0) {
-            *val = 0;
-            return(FINISHED);
-        } else {
-            sprintf(errstr,"doperm(): Invalid perm count %d\n",k);
-            return(PROGRAM_ERROR);
-        }
-    }
-    if((k*dz->iparray[TXRPT][pindex])!=dz->iparray[TXLASTPERMLEN][pindex]) {    /* 1 */
-        dz->iparray[TXPERMLEN][pindex] = (int)(k * dz->iparray[TXRPT][pindex]); /* 2 */
-        if(permm[pindex]   != (int *)0)                                         /* 3 */
-            free(permm[pindex]);
-        if((permm[pindex] = (int *)malloc(dz->iparray[TXPERMLEN][pindex] * sizeof(int)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for permutation %d\n",pindex+1);
-            return(MEMORY_ERROR);
-        }
-        rndpermm(k,pindex,permm,dz);                                            /* 4 */
-        dz->iparray[TXPERMINDEX][pindex]   = 0;                                 /* 5 */
-        dz->iparray[TXLASTPERMLEN][pindex] = dz->iparray[TXPERMLEN][pindex];    /* 6 */
-    }
-    do {                        /* 6a */
-        OK = 1;
-        i = *(permm[pindex] + (dz->iparray[TXPERMINDEX][pindex]++));            /* 7 */
-        if(i==dz->iparray[TXLASTPERMVAL][pindex]) {                             /* 8 */
-            dz->iparray[TXREPETCNT][pindex]++;
-            if(dz->iparray[TXREPETCNT][pindex]>dz->iparray[TXRPT][pindex]) {
-                dz->iparray[TXREPETCNT][pindex] = dz->iparray[TXRPT][pindex];
-                OK = 0;
-            }
-        } else {
-            dz->iparray[TXREPETCNT][pindex]=1;
-        }
-        if(dz->iparray[TXPERMINDEX][pindex]>=dz->iparray[TXPERMLEN][pindex]) {  /* 10 */
-            dz->iparray[TXPERMINDEX][pindex] = 0;                               /* 11 */
-            rndpermm(k,pindex,permm,dz);                                        /* 12 */
-        }
-    }while(!OK);                                                                /* 13 */
-    dz->iparray[TXLASTPERMVAL][pindex] = i;                                     /* 14 */
-    *val = i;
-    return(FINISHED);                                                           /* 15 */
-}
-
-/*************************** RNDPERMM *******************************
- *
- * Produce a permutation of k objects and store it in permutation-store
- * number 'pindex'.
- *
- * (1)  permlen is the number of objects (k) times the number of repetitions
- *      permitted (rpt[pindex]) = N.
- * (2)  This is the efficient algorithm for distributing N objects into
- *      a random perm.
- * (3)  As we really only have k objects, we take the value%rpt in each
- *      permutation location.
- *      e.g. 3 objects repeated 3 times would give us a random perm of
- *      nine objects such as
- *      5 6 2 8 3 0 1 7 4
- *      applying %3 to this we get
- *      2 0 2 2 0 0 1 1 1
- *      i.e. a perm of 3 objects with no more than 3 consecutive repets
- *      of any one object!!
- */
-
-void rndpermm(int k,int pindex,int **permm,dataptr dz)
-{
-    int n, t;
-    for(n=0;n<dz->iparray[TXPERMLEN][pindex];n++) {     /* 1 */
-        t = (int)(drand48() * (double)(n+1));       /* 2 */
-        if(t==n) {
-            prefix(n,pindex,permm,dz);
-        } else {
-            insert(n,t,pindex,permm,dz);
-        }
-    }
-    for(n=0;n<dz->iparray[TXPERMLEN][pindex];n++)       /* 3 */
-        *(permm[pindex]+n) = (int)(*(permm[pindex]+n) % k);
-}
-
-/***************************** INSERT **********************************
- *
- * Insert the value m AFTER the T-th element in permm[pindex].
- */
-
-void insert(int m,int t,int pindex,int **permm,dataptr dz)
-{   
-    shuflup(t+1,pindex,permm,dz);
-    *(permm[pindex]+t+1) = m;
-}
-
-/***************************** PREFIX ************************************
- *
- * Insert the value m at start of the permutation permm[pindex].
- */
-
-void prefix(int m,int pindex,int **permm,dataptr dz)
-{
-    shuflup(0,pindex,permm,dz);
-    *permm[pindex] = m;
-}
-
-/****************************** SHUFLUP ***********************************
- *
- * move set members in permm[pindex] upwards, starting from element k.
- */
-
-void shuflup(int k,int pindex, int **permm,dataptr dz)
-{
-    int n, *i;
-    int z = dz->iparray[TXPERMLEN][pindex] - 1;
-    i = permm[pindex] + z;
-    for(n = z;n > k;n--) {
-        *i = *(i-1);
-        i--;
-    }
-}

+ 0 - 1661
dev/texture/v8/texprepro.c

@@ -1,1661 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
-
-    The CDP System is free software; you can redistribute it
-    and/or modify it under the terms of the GNU Lesser General Public
-    License as published by the Free Software Foundation; either
-    version 2.1 of the License, or (at your option) any later version.
-
-    The CDP System is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Lesser General Public License for more details.
-
-    You should have received a copy of the GNU Lesser General Public
-    License along with the CDP System; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-    02111-1307 USA
- *
- */
-/* floatsam version */
-#include <stdio.h>
-#include <stdlib.h>
-#include <memory.h>
-#include <structures.h>
-#include <tkglobals.h>
-#include <globcon.h>
-#include <processno.h>
-#include <modeno.h>
-#include <arrays.h>
-#include <texture.h>
-#include <ctype.h>
-#include <sfsys.h>
-#include <osbind.h>
-#include <cdpmain.h>
-
-#if defined unix || defined __GNUC__
-#define round(x) lround((x))
-#endif
-
-#define omit_count  is_rectified
-#define omit_item   is_mapping
-#define one_in      rampbrksize
-#define negscat     fzeroset
-
-#define SQUASH    (2.0) /* non-linearity factor */
-#define MAXPOSCNT (512) /* max no. of spatial positions between lspkrs */
-
-static int  initialise_texture_structure(dataptr dz);
-static int  set_up_and_fill_insample_buffers(insamptr **insound,dataptr dz);
-static int  setup_texflag(texptr tex,dataptr dz);
-static int  adjust_some_input_params(dataptr dz);
-static int  preset_some_internal_texture_params(dataptr dz);
-static int  install_unused_texture_flags(int *total_flags,int unused_flags,dataptr dz);
-static int  install_the_internal_flags(int total_flags,int internal_flags,dataptr dz);
-static int  get_the_notedata(texptr tex,dataptr dz);
-static int  extend_timeset(dataptr dz);
-static int  generate_timeset(dataptr dz);
-static int  do_prespace(motifptr tset,dataptr dz);
-static int  get_sample_pitches(FILE *fp,dataptr dz);
-static int  get_motifs(FILE *fp,int *motifcnt,dataptr dz);
-static int  motifchek(motifptr thismotif);
-static void convert_cmdline_instrnos_to_internal_representation(dataptr dz);
-static int  check_max_transpos_compatible_with_splicelen(dataptr dz);
-static int  set_amptype_params(dataptr dz);
-static int  set_decor_pitchposition_params(dataptr dz);
-static void copy_note(noteptr thisnote,noteptr orignote);
-static int  add_motif_to_end_of_motiflist(motifptr *new,dataptr dz);
-static int  scatter_and_quantise_tset_times(double *lasttime,noteptr *thisnote,dataptr dz);
-static int  pre_space(noteptr thisnote,dataptr dz);
-static int  getpos(double thistime,double *position,dataptr dz);
-static int  spread_and_set_cpos(double *position,double given_position,double spread,dataptr dz);
-static int  chekrang(double *val);
-static int  read_a_note_from_notedata_file
-                (noteptr thisnote,int noteno,int motifno,double *lasttime,dataptr dz);
-static int  generate_tset_times(double *thistime,noteptr *thisnote,dataptr dz);
-static int  un_link_note(noteptr thisnote);
-static int  new_motif(motifptr *thismotif);
-static int  unlink_last_motif(motifptr thismotif);
-static void subtract_one_from_brkvals(int paramno,dataptr dz);
-static int  bigscatter(noteptr *thisnote,double thistime,double timestep,double scatter,double *lasttime,dataptr dz);
-static int  get_data_item(char *q,char **p,double *val);
-static int  init_note(noteptr *thisnote);
-static void put_znote(noteptr thisnote);
-static int  assign_timeset_hfset_motifsets(dataptr dz);
-static int  massage_params(dataptr dz);
-static int  init_motifs(dataptr dz);
-
-/************************* TEXTURE_PREPROCESS ****************************
- *
- * (1)  Establish the bitflag which characterises the texture process.
- * (2)  For consistency across all texture processes, all unused flags are mallocd.
- *      This ensures that the numbering of the INTERNAL flags is consistent across all applics.
- * (3)  Convert some input parameters to form used internally, and check some against insnd lengths.
- */
-
-int texture_preprocess(dataptr dz)
-{
-    int exit_status;
-    int total_flags, unused_flags, n;
-    unsigned int texflag;
-
-    initialise_random_sequence(0,TEXTURE_SEED,dz);
-    if((exit_status = initialise_texture_structure(dz))<0)
-        return(exit_status);
-
-    if((exit_status = set_up_and_fill_insample_buffers(&(dz->tex->insnd),dz))<0)
-        return(exit_status);
-    
-   if((exit_status = initperm(&(dz->tex->perm),dz))<0)
-        return(exit_status);
-
-    if((exit_status = setup_texflag(dz->tex,dz))<0)                     /* 1 */
-        return(exit_status);
-
-    texflag = dz->tex->txflag;
-
-    if((exit_status = adjust_some_input_params(dz))<0)
-        return(exit_status);
-                                                                        
-    if((exit_status = preset_some_internal_texture_params(dz))<0)
-        return(exit_status);
-                                                                        /* 2 */
-    unused_flags = TOTAL_POSSIBLE_USER_FLAGS - dz->application->vflag_cnt;
-
-    if((exit_status = install_unused_texture_flags(&total_flags,unused_flags,dz))<0)
-        return(exit_status);
-
-    if((exit_status = install_the_internal_flags(total_flags,INTERNAL_FLAGS_CNT,dz))<0)
-        return(exit_status);
-
-    if((exit_status = get_the_notedata(dz->tex,dz))<0)
-        return(exit_status);
-
-    if((exit_status = assign_timeset_hfset_motifsets(dz))<0)
-        return(exit_status);
-
-    if((exit_status = massage_params(dz))<0)                            /* 3 */
-        return(exit_status);
-   if(texflag & ORN_DEC_OR_TIMED) {
-        if((exit_status = extend_timeset(dz))<0)                        /* 7 */
-            return(exit_status);
-    } else {
-        if((exit_status = generate_timeset(dz))<0)                      /* 8 */
-            return(exit_status);
-    }
-    if((exit_status = do_prespace(dz->tex->timeset,dz))<0)
-        return(exit_status);
-
-    if(dz->process == SIMPLE_TEX && dz->vflag[CYCLIC_TEXFLAG]) {
-        if(dz->infilecnt < 2)
-            dz->vflag[CYCLIC_TEXFLAG] = 0;
-        else if (dz->vflag[PERM_TEXFLAG]) {
-            if((dz->peakno = (int *)malloc(dz->infilecnt * sizeof(int))) == NULL) {
-                sprintf(errstr,"Insufficient memory for cyclic permutations of input files.\n");
-                return(MEMORY_ERROR);
-            }
-            if((dz->lastpeakno = (int *)malloc(dz->infilecnt * sizeof(int))) == NULL) {
-                sprintf(errstr,"Insufficient memory for cyclic permutations of input files.\n");
-                return(MEMORY_ERROR);
-            }
-            for(n=0;n<dz->infilecnt;n++) {
-                dz->peakno[n] = n;
-                dz->lastpeakno[n] = n;
-            }
-        }
-    }
-    /* create stereo outfile here! */
-    /* RWD 4:2002  now we can open outfile with corect params! */
-//TW UPDATE to use stereo input means that dz->infile->channels must be retained for now
-//TW Open outfile later (texture5.c)
-    return(FINISHED);
-}
-
-/*********************** INITIALISE_TEXTURE_STRUCTURE ******************************/
-
-int initialise_texture_structure(dataptr dz)
-{
-    int n;
-    if((dz->tex = (texptr)malloc(sizeof(struct textural)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for texture structure.\n");
-        return(MEMORY_ERROR);
-    }
-
-    dz->tex->txflag     = 0;
-    dz->tex->motifhead  = (motifptr)0;
-    dz->tex->insnd      = (insamptr *)0;
-    dz->tex->timeset    = (motifptr)0;
-    dz->tex->hfldmotif  = (motifptr)0;
-    dz->tex->phrase     = (motifptr *)0;
-    dz->tex->perm       = (int **)0;
-    dz->tex->dectypstor = 0;
-    dz->tex->dectypcnt  = 0;
-    dz->tex->amptypstor = 0;
-    dz->tex->amptypcnt  = 0;
-    dz->tex->phrasecnt  = 0;
-    dz->tex->ampdirectd = FALSE;
-
-    if((dz->tex->insnd  = (insamptr *)malloc(dz->infilecnt * sizeof(insamptr)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for texture insound structure.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n<dz->infilecnt;n++) {
-        dz->tex->insnd[n] = (insamptr)0;
-        if((dz->tex->insnd[n]= (insamptr)malloc(sizeof(struct insample)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for texture insound[%d] structure.\n",n+1);
-            return(MEMORY_ERROR);
-        }
-    }
-    return(FINISHED);
-}
- 
-/************************** SET_UP_AND_FILL_INSAMPLE_BUFFERS ****************************
- *
- * 1) Set buffer pointer to zero, until it has been malloced.
- *    This make freeing of tex structure possible.
- */
-
-int set_up_and_fill_insample_buffers(insamptr **insound,dataptr dz)
-{
-    int n;
-    int samps_read;
-    int thisbufsize;
-    int wrap_around_samps = 1;
-    for(n=0;n<dz->infilecnt;n++) {
-        ((*insound)[n])->buffer = /*(float *)0*/NULL;                   /* 1 */
-        thisbufsize = dz->insams[n];
-        thisbufsize += wrap_around_samps; 
-        if((((*insound)[n])->buffer  = (float *)malloc(thisbufsize * sizeof(float)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for texture insound buffer pointer %d.\n",n+1);
-            return(MEMORY_ERROR);
-        }
-        memset((char *)((*insound)[n])->buffer,0,thisbufsize * sizeof(float));
-        if((samps_read = fgetfbufEx(((*insound)[n])->buffer,thisbufsize,dz->ifd[n],0)) < 0) {
-            sprintf(errstr,"Can't read sndfile %d to buffer: set_up_and_fill_insample_buffers()\n",n+1);
-            return(SYSTEM_ERROR);
-        }
-        if(samps_read != dz->insams[n]) {
-            sprintf(errstr,"Error reading sndfile %d to buf: set_up_and_fill_insample_buffers()\n",n+1);
-            return(PROGRAM_ERROR);
-        }
-    }
-    return(FINISHED);
-}
-
-/***************************** SETUP_TEXFLAG ****************************/
-
-int setup_texflag(texptr tex,dataptr dz)
-{
-    tex->txflag = 0;
-    switch(dz->process) {
-    case(SIMPLE_TEX): break;
-    case(GROUPS):     tex->txflag |= IS_GROUPS;                                                     break;
-    case(DECORATED):  tex->txflag |= IS_DECOR;                                                      break;
-    case(PREDECOR):   tex->txflag |= IS_DECOR;  tex->txflag |= ISPRE_DECORORN;                      break;
-    case(POSTDECOR):  tex->txflag |= IS_DECOR;  tex->txflag |= ISPOST_DECORORN;                     break;
-    case(ORNATE):     tex->txflag |= IS_ORNATE;                                                     break;
-    case(PREORNATE):  tex->txflag |= IS_ORNATE; tex->txflag |= ISPRE_DECORORN;                      break;
-    case(POSTORNATE): tex->txflag |= IS_ORNATE; tex->txflag |= ISPOST_DECORORN;                     break;
-    case(MOTIFS):     tex->txflag |= IS_MOTIFS;                                                     break;
-    case(MOTIFSIN):   tex->txflag |= IS_MOTIFS; tex->txflag |= MOTIF_IN_HF;                         break;
-    case(TIMED):                                                            tex->txflag |= ISTIMED; break;
-    case(TGROUPS):    tex->txflag |= IS_GROUPS;                             tex->txflag |= ISTIMED; break;
-    case(TMOTIFS):    tex->txflag |= IS_MOTIFS;                             tex->txflag |= ISTIMED; break;
-    case(TMOTIFSIN):  tex->txflag |= IS_MOTIFS; tex->txflag |= MOTIF_IN_HF; tex->txflag |= ISTIMED; break;
-    default:
-        sprintf(errstr,"Unknown process in setup_texflag()\n");
-        return(PROGRAM_ERROR);
-    }
-    switch(dz->mode) {
-    case(TEX_NEUTRAL):  break;
-    case(TEX_HFIELD):   tex->txflag |= ISHARM;                                                          break;
-    case(TEX_HFIELDS):  tex->txflag |= ISHARM;                          tex->txflag |= ISMANY_HFLDS;    break;
-    case(TEX_HSET):     tex->txflag |= ISHARM;  tex->txflag |= IS_HS;                                   break;
-    case(TEX_HSETS):    tex->txflag |= ISHARM;  tex->txflag |= IS_HS;   tex->txflag |= ISMANY_HFLDS;    break;
-    default:
-        sprintf(errstr,"Unknown mode in setup_texflag()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/************************** ADJUST_SOME_INPUT_PARAMS ****************************
- *
- * (1)  dz->vflag[WHICH_CHORDNOTE] internally carries all 3 vals (first,highest,every).
- *
- * (2)  Gprange, in cases with Hfields, is an integer count of HF-field notes to use.
- */
-
-int adjust_some_input_params(dataptr dz)
-{
-    int texflag = dz->tex->txflag;
-    if((texflag & IS_ORN_OR_DEC) && dz->vflag[FORCE_EVERY]==TRUE)
-        dz->vflag[WHICH_CHORDNOTE] = DECOR_EVERY;                       /* 1 */
-
-    if((texflag & IS_DEC_OR_GRP) && (texflag & ISHARM)) {               /* 2 */
-        dz->is_int[TEX_GPRANGLO] = TRUE;
-        dz->is_int[TEX_GPRANGHI] = TRUE;
-        dz->iparam[TEX_GPRANGLO] = round(dz->param[TEX_GPRANGLO]);
-        dz->iparam[TEX_GPRANGHI] = round(dz->param[TEX_GPRANGHI]);
-    }
-    return(FINISHED);
-}
-
-/***************************** PRESET_SOME_INTERNAL_TEXTURE_PARAMS ****************************/
-
-int preset_some_internal_texture_params(dataptr dz)
-{   
-    int cnt = 0;
-    dz->iparam[SPINIT]    = 0;   cnt++; /* ALL CLUMPS */
-    dz->iparam[SPCNT]     = 0;   cnt++; 
-    dz->iparam[DIRECTION] = 0;   cnt++; 
-    dz->param[CPOS]       = 0.5; cnt++; /* for safety only */   /* SPATIALISATION */
-    dz->param[TPOSITION]  = 0.5; cnt++; /* for safety only */
-    dz->param[THISSPRANGE]= 1.0; cnt++; /* full range */
-    /*dz->iparam[TEX_MAXOUT]= 0.0;   cnt++; *//* min value */
-    dz->param[TEX_MAXOUT] = 0.0;   cnt++;         /*RWD*/
-    if(cnt != dz->application->internal_param_cnt) {
-        sprintf(errstr,"preset_some_internal_texture_params() has false count\n");
-        return(PROGRAM_ERROR);
-    }
-    dz->itemcnt = 0;
-    return(FINISHED);
-}
-
-/***************************** INSTALL_UNUSED_TEXTURE_FLAGS ****************************/
-
-int install_unused_texture_flags(int *total_flags,int unused_flags,dataptr dz)
-{
-    int n;
-    *total_flags = dz->application->vflag_cnt + unused_flags;
-    if(unused_flags > 0) {
-        if((dz->vflag  = 
-            (char *)realloc(dz->vflag,(*total_flags) * sizeof(char)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for internal flags.\n");
-            return(MEMORY_ERROR);
-        }
-        for(n=0;n<unused_flags;n++) {
-            switch(n) {
-            case(4):    dz->vflag[2] = FALSE;   break;
-            case(3):    dz->vflag[3] = FALSE;   break;
-            case(2):    dz->vflag[4] = FALSE;   break;
-            case(1):    dz->vflag[5] = FALSE;   break;
-            case(0):    dz->vflag[6] = FALSE;   break;
-            }
-        }
-    }
-    return(FINISHED);
-}
-
-/***************************** INSTALL_THE_INTERNAL_FLAGS ****************************/
-
-int install_the_internal_flags(int total_flags,int internal_flags,dataptr dz)
-{
-        /* THESE FLAGS ARE NOT AVAILABLE TO USER : but they are used in the code */
-    total_flags += internal_flags;
-    if((dz->vflag  = 
-        (char *)realloc(dz->vflag,total_flags * sizeof(char)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate internal flags.\n");
-        return(MEMORY_ERROR);
-    }
-    dz->iparam[DECCENTRE] = FALSE;
-    return(FINISHED);
-}
-
-/***************************** GET_THE_NOTEDATA ****************************/
-
-int get_the_notedata(texptr tex,dataptr dz)
-{
-    int exit_status;
-    unsigned int texflag = tex->txflag;
-    int motifcnt, expected_motifcnt = 0;
-
-    if(dz->fp==NULL) {
-        sprintf(errstr,"notedata fileptr not initialised: get_the_notedata()\n");
-        return(PROGRAM_ERROR);
-    }
-    if((exit_status = get_sample_pitches(dz->fp,dz))<0) {
-        sprintf(errstr,"Insufficient pitch values in notedata file.\n");
-        return(DATA_ERROR);
-    }
-    if((exit_status = get_motifs(dz->fp,&motifcnt,dz))<0)
-        return(exit_status);
-    if(texflag & ORN_DEC_OR_TIMED)  expected_motifcnt++;    /* Line to work on */
-    if(texflag & ISHARM)            expected_motifcnt++;    /* HF data         */
-    if(texflag & IS_ORN_OR_MTF)     expected_motifcnt++;    /* Ornmnts or mtfs */
-
-    if(texflag & IS_ORN_OR_MTF) {
-        if(motifcnt < expected_motifcnt) {
-            sprintf(errstr,"Insufficient motifs in notedata file.\n");
-            return(DATA_ERROR);
-        }
-    } else {
-        if(motifcnt!=expected_motifcnt) {
-            sprintf(errstr,"Incorrect number [%d] of motifs in notedata file (expected %d).\n",
-            motifcnt,expected_motifcnt);
-            return(DATA_ERROR);
-        }
-    }
-    return(FINISHED);
-}
-
-/**************************** EXTEND_TIMESET *******************************/
-
-int extend_timeset(dataptr dz)
-{
-    int exit_status;
-    int origcnt = 0, n;
-    noteptr startnote = dz->tex->motifhead->firstnote;
-    noteptr orignote, thisnote  = startnote;
-    double *timediff;
-    
-    if(startnote==(noteptr)0) {
-        sprintf(errstr,"Problem in note timings: extend_timeset()\n");
-        return(PROGRAM_ERROR);
-    }
-    while(thisnote!=(noteptr)0) {
-        if(thisnote->ntime > dz->param[TEXTURE_DUR]) {
-            delete_notes_here_and_beyond(thisnote);
-            return(FINISHED);
-        }
-        thisnote = thisnote->next;
-        origcnt++;
-    }
-
-    if((timediff = (double *)malloc(origcnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for timegaps array.\n");
-        return(MEMORY_ERROR);
-    }
-    n = 1;
-    thisnote = startnote;
-    while(thisnote->next !=(noteptr)0) {
-        thisnote = thisnote->next;
-        timediff[n++] = thisnote->ntime - thisnote->last->ntime;
-    }
-    if(dz->brksize[TEXTURE_SKIP]) {
-        if((exit_status = read_value_from_brktable(thisnote->ntime,TEXTURE_SKIP,dz))<0) {
-            free(timediff);
-            return(exit_status);
-        }
-    }
-    timediff[0] = dz->param[TEXTURE_SKIP];
-    n = 0;
-    orignote = startnote;
-
-    for(;;) {
-        if(thisnote->ntime > dz->param[TEXTURE_DUR] && timediff[n] > 0.0)
-            break;
-        if((exit_status = make_new_note(&thisnote))<0) {
-            free(timediff);
-            return(exit_status);
-        }
-        copy_note(thisnote,orignote);
-        thisnote->ntime = (float)(thisnote->last->ntime + timediff[n]);
-        if(++n>=origcnt) {
-            if(dz->brksize[TEXTURE_SKIP]) {
-                if((exit_status = read_value_from_brktable(thisnote->ntime,TEXTURE_SKIP,dz))<0) {
-                    free(timediff);
-                    return(exit_status);
-                }
-                timediff[0] = dz->param[TEXTURE_SKIP];
-            }
-            n = 0;
-            orignote = startnote;
-        } else
-            orignote = orignote->next;
-    }
-    dz->brksize[TEXTURE_SKIP] = 0;  /* prevent future reads */
-    free(timediff);
-    return(FINISHED);
-}
-
-
-/*********************************************************************
- *
- * (1)  Generating the tset (set of timed values on or around which the
- *      texture is to be generated).
-*/
-/************************** GENERATE_TIMESET ******************************
- *
- * (A)  Zero all other parameters besides time.
- */     
-
-int generate_timeset(dataptr dz)
-{
-    int exit_status;
-    double lasttime, thistime = 0.0;
-    noteptr thisnote;
-    motifptr tset;
-    if((exit_status = add_motif_to_end_of_motiflist(&(dz->tex->timeset),dz))<0)
-        return(exit_status);
-    tset =  dz->tex->timeset;
-    if((thisnote = tset->firstnote)==(noteptr)0) {
-        sprintf(errstr,"Failure to find 1st note in motif: generate_timeset()\n");
-        return(PROGRAM_ERROR);
-    }
-    put_znote(thisnote);            /* A */
-    thisnote->ntime = (float)thistime;
-    if(dz->brksize[TEXTURE_PACK]) {
-        if((exit_status = read_value_from_brktable(thistime,TEXTURE_PACK,dz))<0)
-            return(exit_status);
-    }       
-    thistime += dz->param[TEXTURE_PACK];
-    while(thistime<dz->param[TEXTURE_DUR]) {
-        if((exit_status = generate_tset_times(&thistime,&thisnote,dz))<0)
-            return(exit_status);
-        put_znote(thisnote);                /* A */
-    }
-    thisnote = tset->firstnote;
-    lasttime = thisnote->ntime;
-    thisnote = thisnote->next;
-    dz->omit_count = 0;
-    dz->omit_item  = 0;
-    dz->negscat    = -1;    // Initialisation
-    while(thisnote!=(noteptr)0) {
-        if((exit_status = scatter_and_quantise_tset_times(&lasttime,&thisnote,dz))<0)
-            return(exit_status);
-    }
-    dz->brksize[TEXTURE_PACK]  = 0; /* set these brktables to appear empty, so no read attempts later */
-    dz->brksize[TEXTURE_SCAT]  = 0;
-    dz->brksize[TEXTURE_TGRID] = 0;
-    if(dz->process == SIMPLE_TEX)
-        dz->brksize[TEX_PHGRID] = 0;
-    return(FINISHED);
-}
-
-/***************************** DO_PRESPACE ******************************
- *
- * Spatialise the time set, prior to output phase&/or ornamentation.
- */
-
-int do_prespace(motifptr tset,dataptr dz)
-{
-    int exit_status;
-    noteptr thisnote = tset->firstnote;
-    while(thisnote!=(noteptr)0) {
-        if((exit_status = pre_space(thisnote,dz))<0)
-            return(exit_status);
-        thisnote = thisnote->next;
-    }
-    return(FINISHED);
-}
-
-/**************************** GET_SAMPLE_PITCHES *****************************/
-
-int get_sample_pitches(FILE *fp,dataptr dz)
-{
-    int exit_status;
-/* TW AUGUST 2006: 200--> 2000 */
-    char temp[200000], *q;
-    int pitchcnt = 0;
-    double *p;
-    int got_all_pitches = FALSE;
-/* TW AUGUST 2006: 200--> 2000 */
-    while(!got_all_pitches && (fgets(temp,200000,fp)!=NULL)) {
-        q = temp;
-        if(*q == ';')   //  Allow comments in file
-            continue;
-        p = &(((dz->tex->insnd)[pitchcnt])->pitch);
-        while((exit_status = get_float_from_within_string(&q,p))==TRUE) {
-            if(++pitchcnt >= dz->infilecnt) {
-                got_all_pitches = TRUE;
-                break;
-            }
-            p = &(((dz->tex->insnd)[pitchcnt])->pitch);
-        }
-        if(exit_status==FALSE)
-            return(DATA_ERROR);
-    }
-    if(!got_all_pitches)
-        return(DATA_ERROR);
-    return(FINISHED);
-}
-
-/**************************** GET_MOTIFS *****************************
- * 
- * Read data from an ascii file to notelist.
- */
-
-int get_motifs(FILE *fp,int *motifcnt,dataptr dz)
-{
-    int exit_status;
-    motifptr thismotif;
-    noteptr thisnote;
-    char *p, temp[200];
-    double lasttime = 0.0;
-    int datalen, noteno, motifno = 0;
-    if((exit_status = init_motifs(dz))<0)       /* 8 */
-        return(exit_status);
-    thismotif = dz->tex->motifhead;
-    while(fgets(temp,200,fp)!=NULL) {
-        p = temp;
-        while(isspace(*p))
-            p++;
-        if(*p==ENDOFSTR)
-            continue;
-        if(*p!=TEXTURE_SEPARATOR) {
-//TW UPDATE
-            sprintf(errstr,"'%c' missing before datacount in notedata file: motif %d (or more notes listed than indicated by %cN)\n"
-            "check datalen is correct\n",TEXTURE_SEPARATOR,motifno+1,TEXTURE_SEPARATOR);
-            return(DATA_ERROR);
-        }
-        p++;
-        if(!isdigit(*p) || sscanf(p,"%d",&datalen)!=1) {
-            sprintf(errstr,"No datalength given: motif %d\n",motifno+1);
-            return(DATA_ERROR);
-        }
-        if(datalen <= 0) {
-            sprintf(errstr,"Invalid data length %d in notedata: motif %d\n",datalen,motifno+1);
-            return(DATA_ERROR);
-        }
-        motifno++;
-        thisnote = thismotif->firstnote;
-        for(noteno=1;noteno<=datalen;noteno++) {
-            if((exit_status = read_a_note_from_notedata_file(thisnote,noteno,motifno,&lasttime,dz))<0)
-                return(exit_status);
-            if(exit_status==CONTINUE) {
-                noteno--;
-                continue;
-            }               
-            if((exit_status = make_new_note(&thisnote))<0)
-                return(exit_status);
-        }
-        if((exit_status = un_link_note(thisnote))<0)
-            return(exit_status);
-        if((exit_status = new_motif(&thismotif))<0)
-            return(exit_status);
-    }
-    *motifcnt = motifno;
-    if(motifno > 0)
-        return unlink_last_motif(thismotif);
-    return(FINISHED);
-}
-
-/************************** MOTIFCHEK ********************************
- *
- * Check we've not run out of motifs.
- */
-
-int motifchek(motifptr thismotif)
-{
-    if(thismotif == (motifptr)0) {
-        sprintf(errstr,"motifchek(): Insufficient motifs: even though correctly counted.\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/***************************** CONVERT_CMDLINE_INSTRNOS_TO_INTERNAL_REPRESENTATION ****************************/
-
-void convert_cmdline_instrnos_to_internal_representation(dataptr dz)
-{
-    if(dz->brksize[TEXTURE_INSLO])
-        subtract_one_from_brkvals(TEXTURE_INSLO,dz);
-    else
-        dz->iparam[TEXTURE_INSLO]--;
-
-    if(dz->brksize[TEXTURE_INSHI])
-        subtract_one_from_brkvals(TEXTURE_INSHI,dz);
-    else
-        dz->iparam[TEXTURE_INSHI]--;
-}
-
-/***************************** CHECK_MAX_TRANSPOS_COMPATIBLE_WITH_SPLICELEN ****************************/
-
-int check_max_transpos_compatible_with_splicelen(dataptr dz)
-{
-    int n, exit_status;
-    double max_maxpitch, max_minpitch, max_transpospitch, maxupshift, upratio, minlen;
-    double min_sndlength = (TEXTURE_SPLICELEN + TEXTURE_SAFETY) * MS_TO_SECS * (double)dz->infile->srate;
-    dz->frametime = TEXTURE_SPLICELEN;
-
-    if(dz->brksize[TEXTURE_MAXPICH]) {
-        if((exit_status = get_maxvalue_in_brktable(&max_maxpitch,TEXTURE_MAXPICH,dz))<0)
-            return(exit_status);
-    } else
-        max_maxpitch = dz->param[TEXTURE_MAXPICH];
-
-    if(dz->brksize[TEXTURE_MINPICH]) {
-        if((exit_status = get_maxvalue_in_brktable(&max_minpitch,TEXTURE_MINPICH,dz))<0)
-            return(exit_status);
-    } else
-        max_minpitch = dz->param[TEXTURE_MINPICH];
-
-    max_transpospitch = max(max_minpitch,max_maxpitch);
-
-    dz->zeroset = 0;    /* use as flag re splicelen change */
-    for(n=0;n<dz->infilecnt;n++) {
-        maxupshift = max_transpospitch - ((dz->tex->insnd)[n])->pitch;
-        upratio    = pow(2.0,(maxupshift/SEMITONES_PER_OCTAVE));
-        minlen     = (double)dz->insams[n]/upratio;
-        if(minlen < min_sndlength) {
-            dz->frametime = 2.0;    
-            min_sndlength = (dz->frametime + TEXTURE_SAFETY) * MS_TO_SECS * (double)dz->infile->srate;
-#ifdef MINDUR_OVERRIDE
-            min_sndlength = 0.0;
-#endif
-            if(minlen < min_sndlength) {
-                dz->frametime = 1.0;    
-                min_sndlength = (dz->frametime + TEXTURE_SAFETY) * MS_TO_SECS * (double)dz->infile->srate;
-                if(minlen < min_sndlength) {
-                    sprintf(errstr,"sndfile %d [%.3lf secs] too short for max upward transposition [ratio %.2lf].\n",
-                    n+1,(double)dz->insams[n]/(double)dz->infile->srate,upratio);
-                    return(DATA_ERROR);
-                }
-            }
-        }
-    }
-    return(FINISHED);
-}
-
-/************************* SET_AMPTYPE_PARAMS *******************************/
-
-int set_amptype_params(dataptr dz)
-{   int mask = 1, n;
-    dz->tex->amptypcnt  = 0;
-    dz->tex->amptypstor = 0;
-    switch(dz->iparam[TEX_AMPCONT]) {
-    case(IS_MIXED):              dz->tex->amptypstor |= 1;  dz->tex->amptypstor |= 2;                           break;
-    case(IS_CRESC):                                         dz->tex->amptypstor |= 2;                           break;
-    case(IS_FLAT):               dz->tex->amptypstor |= 1;                                                      break;
-    case(IS_DECRESC):                                                                 dz->tex->amptypstor |= 4; break;
-    case(IS_FLAT_AND_CRESC):     dz->tex->amptypstor |= 1;  dz->tex->amptypstor |= 2;                           break;
-    case(IS_CRESC_AND_DECRESC):                             dz->tex->amptypstor |= 2; dz->tex->amptypstor |= 4; break;
-    case(IS_FLAT_AND_DECRESC):   dz->tex->amptypstor |= 1;                            dz->tex->amptypstor |= 4; break;
-
-    case(IS_DIRECTIONAL):        dz->tex->ampdirectd = TRUE;    dz->tex->amptypcnt = 1;                         break;
-    case(IS_DIREC_OR_FLAT):      dz->tex->ampdirectd = TRUE;    dz->tex->amptypcnt = 2;                         break;
-    default:
-        sprintf(errstr,"Unknown case in set_amptype_params()\n");
-        return(PROGRAM_ERROR);
-    }
-    if(dz->tex->amptypstor > 0) {
-        for(n=0;n<3;n++) {
-            if(mask & dz->tex->amptypstor)
-                dz->tex->amptypcnt++;
-            mask <<= 1;
-        }
-    }
-    return(FINISHED);
-}
-
-/************************* SET_DECOR_PITCHPOSITION_PARAMS ******************************/
-
-int set_decor_pitchposition_params(dataptr dz)
-{
-    int n, mask = 1;
-    dz->tex->dectypstor = 0;
-    dz->tex->dectypcnt  = 0;
-    switch(dz->iparam[TEX_DECPCENTRE]) {
-    case(DEC_CENTRED): dz->tex->dectypstor |= 1;                                                        break;
-    case(DEC_ABOVE):                             dz->tex->dectypstor |= 2;                              break;
-    case(DEC_BELOW):                                                        dz->tex->dectypstor |= 4;   break;
-    case(DEC_C_A):     dz->tex->dectypstor |= 1; dz->tex->dectypstor |= 2;                              break;
-    case(DEC_C_B):     dz->tex->dectypstor |= 1;                            dz->tex->dectypstor |= 4;   break;
-    case(DEC_A_B):                               dz->tex->dectypstor |= 2;  dz->tex->dectypstor |= 4;   break;
-    case(DEC_C_A_B):   dz->tex->dectypstor |= 1; dz->tex->dectypstor |= 2;  dz->tex->dectypstor |= 4;   break;
-    default:
-        sprintf(errstr,"Unknown case in set_decor_pitchposition_params()\n");
-        return(PROGRAM_ERROR);
-    }
-    if(dz->tex->dectypstor > 0) {
-        for(n=0;n<3;n++) {
-            if(mask & dz->tex->dectypstor)
-                dz->tex->dectypcnt++;
-            mask <<= 1;
-        }
-    }
-    return(FINISHED);
-}
-
-/********************** DELETE_NOTES_HERE_AND_BEYOND *******************************
-
-void delete_notes_here_and_beyond(noteptr startnote)
-{
-    noteptr here = startnote;
-    if(here==(noteptr)0)
-        return;
-    while(here->next!=(noteptr)0)
-        here=here->next;
-    while(here!=startnote) {
-        here=here->last;
-        free(here->next);
-    }
-    if(startnote->last!=(noteptr)0)
-        startnote->last->next = (noteptr)0;
-    free(startnote);
-}
-****/
-
-/********************** MAKE_NEW_NOTE ****************************
- *
- * Create new link in note list.
- */
-
-int make_new_note(noteptr *thisnote)
-{
-    if(((*thisnote)->next = (noteptr)malloc(sizeof(struct nnote)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for a further note store.\n");
-        return(MEMORY_ERROR);
-    }
-    (*thisnote)->next->last = *thisnote;
-    *thisnote = (*thisnote)->next;
-    (*thisnote)->next = (noteptr)0;
-    return(FINISHED);
-}
-
-/**************************** COPY_NOTE *******************************/
-
-void copy_note(noteptr thisnote,noteptr orignote)
-{
-    thisnote->ntime = orignote->ntime;
-    thisnote->amp   = orignote->amp;
-    thisnote->pitch = orignote->pitch;
-    thisnote->dur   = orignote->dur;
-    thisnote->instr = orignote->instr;
-    thisnote->spacepos = orignote->spacepos;
-    thisnote->motioncentre = orignote->motioncentre;
-}
-
-/************************** ADD_MOTIF_TO_END_OF_MOTIFLIST ******************************
- *
- * Create new motif at end of list.
- */
-
-int add_motif_to_end_of_motiflist(motifptr *new,dataptr dz)
-{
-    int exit_status;
-    motifptr here = dz->tex->motifhead;
-    while(here->next!=(motifptr)0)
-        here = here->next;
-    if((exit_status =  new_motif(&here))<0)
-        return(exit_status);
-    *new = here;
-    return(FINISHED);
-}
-    
-/************************* SCATTER_AND_QUANTISE_TSET_TIMES ******************************/
-//
-//int scatter_and_quantise_tset_times(double *lasttime,noteptr *thisnote,dataptr dz)
-//{
-//  int exit_status;
-//  double thistime = (*thisnote)->ntime;           /* 1 */
-//  double timestep = thistime - *lasttime;         /* 2 */
-//  *lasttime = thistime;                           /* 2a */
-//  if(dz->brksize[TEXTURE_SCAT]) {
-//      if((exit_status = read_value_from_brktable(thistime,TEXTURE_SCAT,dz))<0)
-//          return(exit_status);
-//  }       
-//  if(dz->param[TEXTURE_SCAT]>1.0) {               /* 3a */
-//      if((exit_status = bigscatter(thisnote,thistime,timestep,dz->param[TEXTURE_SCAT],lasttime,dz))<0)
-//          return(exit_status);
-//  } else {
-//      if(!flteq(dz->param[TEXTURE_SCAT],0.0))             /* 4 */
-//          thistime -= (float)(drand48() * dz->param[TEXTURE_SCAT] * timestep);
-//  
-//      if(dz->param[TEXTURE_TGRID]>0.0)
-//          thistime  = quantise(thistime,dz->param[TEXTURE_TGRID]);    /* 6 */
-//      (*thisnote)->ntime = (float)thistime;
-//  }
-//  *thisnote = (*thisnote)->next;
-//  return(FINISHED);               /* 8a */
-//}
-//
-/************************* SCATTER_AND_QUANTISE_TSET_TIMES ******************************/
-
-int scatter_and_quantise_tset_times(double *lasttime,noteptr *thisnote,dataptr dz)
-{
-    int exit_status;
-    double thistime = (*thisnote)->ntime;           /* 1 */
-    double timestep = thistime - *lasttime;         /* 2 */
-    noteptr lastnote, priornote;
-    *lasttime = thistime;                           /* 2a */
-    if(dz->brksize[TEXTURE_SCAT]) {
-        if((exit_status = read_value_from_brktable(thistime,TEXTURE_SCAT,dz))<0)
-            return(exit_status);
-    }       
-    if(dz->param[TEXTURE_SCAT]>1.0) {               /* 3a */
-        if((exit_status = bigscatter(thisnote,thistime,timestep,dz->param[TEXTURE_SCAT],lasttime,dz))<0)
-            return(exit_status);
-    } else {
-        if(!flteq(dz->param[TEXTURE_SCAT],0.0))             /* 4 */
-            thistime -= (float)(drand48() * dz->param[TEXTURE_SCAT] * timestep);
-    
-        if(dz->param[TEXTURE_TGRID]>0.0)
-            thistime  = quantise(thistime,dz->param[TEXTURE_TGRID]);    /* 6 */
-        (*thisnote)->ntime = (float)thistime;
-    }
-    if(dz->brksize[TEX_PHGRID]) {
-        if((exit_status = read_value_from_brktable(thistime,TEX_PHGRID,dz))<0)
-            return(exit_status);
-        dz->one_in = (int)ceil(dz->param[TEX_PHGRID]);
-    } else
-        dz->one_in = dz->iparam[TEX_PHGRID];
-    dz->one_in %= 64;                                   //  Omit 1 in 63, goes to omit none (at value 64)
-    if(dz->one_in == 0) {                               //  No omissions: go to next note
-        dz->omit_count = 0;
-        *thisnote = (*thisnote)->next;
-    } else {
-        dz->one_in = max(dz->one_in,2);                 //  dz->one_in cannot be less than 2
-        if(dz->omit_count == dz->omit_item) {           //  If this is item to omit
-            lastnote = *thisnote; 
-            *thisnote = (*thisnote)->next;              //  Go to next note
-            priornote = lastnote->last;                 //  Unlink last note
-            priornote->next = *thisnote;
-            if(*thisnote != NULL)
-                (*thisnote)->last = priornote;
-            free(lastnote);
-        } else                                          //  Else don't omit this note
-            *thisnote = (*thisnote)->next;              //  Just go to next note
-
-        dz->omit_count++;                               //  Advance counter in omit-size group.
-        if(dz->omit_count >= dz->one_in) {              //  Once the group has been used up
-            dz->omit_count = 0;                         //  Reset noteset-group counter, and determine (by random selection)
-            if(dz->param[TEXTURE_SEED] < 32)
-                dz->omit_item = (int)floor(drand48() * dz->one_in); //  event to drop in next dz->one_in events.
-        }
-        return FINISHED;
-    }
-    return(FINISHED);               /* 8a */
-}
-
-/************************* SCATTER_AND_QUANTISE_TSET_TIMES ******************************/
-//
-//int scatter_and_quantise_tset_times(double *lasttime,noteptr *thisnote,dataptr dz)
-//{
-//  int exit_status;
-//  double thistime = (*thisnote)->ntime;           /* 1 */
-//  double timestep = thistime - *lasttime;         /* 2 */
-//  noteptr lastnote, priornote;
-//  double thisscat;
-//  *lasttime = thistime;                           /* 2a */
-//  if(dz->brksize[TEXTURE_SCAT]) {
-//      dz->negscat = 0;
-//      if((exit_status = read_value_from_brktable(thistime,TEXTURE_SCAT,dz))<0)
-//          return(exit_status);
-//      if(dz->param[TEXTURE_SCAT] < 0.0)
-//          dz->negscat = 1;
-//  } else if(dz->negscat < 0) {                            // Initialise negative-scattering, where not a trime-variable pscatter param
-//      dz->negscat = 0;
-//      if(dz->param[TEXTURE_SCAT] < 0.0)
-//          dz->negscat = 1;
-//  }
-//  if (dz->negscat) {                                      //  -3.1 becomes scatter = 0.1 ,events-to-drop = 1-in-3
-//      thisscat   = -dz->param[TEXTURE_SCAT];
-//      dz->one_in = (int)floor(thisscat);                  //  Proportion of events to be dropped = 1 in dz->one_in        
-//      thisscat  -= dz->one_in;                            //  Scatter to be used
-//      dz->one_in = max(dz->one_in,2);                     //  dz->one_in cannot be less than 2
-//
-//      if(dz->omit_count == dz->omit_item) {               //  If this is item to omit
-//          lastnote = *thisnote; 
-//          *thisnote = (*thisnote)->next;                  //  Go to next note
-//          priornote = lastnote->last;                     //  Unlink last note
-//          priornote->next = *thisnote;
-//          (*thisnote)->last = priornote;
-//          free(lastnote);
-//      } else {                                        //  Otherwise, scatter event time       
-//          if(!flteq(thisscat,0.0))
-//              thistime -= (float)(drand48() * thisscat * timestep);
-//          if(dz->param[TEXTURE_TGRID]>0.0)                //  (and quantise if ness)
-//              thistime  = quantise(thistime,dz->param[TEXTURE_TGRID]);
-//          (*thisnote)->ntime = (float)thistime;
-//          *thisnote = (*thisnote)->next;                  //  and go to next note
-//      }
-//      dz->omit_count++;                                   //  Advance counter in omit-size group.
-//      if(dz->omit_count >= dz->one_in) {                  //  Once the group has been used up
-//          dz->omit_count = 0;                             //  Reset noteset-group counter, and determine (by random selection)
-//          if(dz->param[TEXTURE_SEED] < 32)
-//              dz->omit_item = (int)floor(drand48() * dz->one_in); //  event to drop in next dz->one_in events.
-//      }
-//      return FINISHED;
-//  } else if(dz->param[TEXTURE_SCAT]>1.0)  {               /* 3a */
-////TW UPDATE (original code error)
-//      if((exit_status = bigscatter(thisnote,thistime,timestep,dz->param[TEXTURE_SCAT],lasttime,dz))<0)
-//          return(exit_status);
-//  } else {
-//      if(!flteq(dz->param[TEXTURE_SCAT],0.0))             /* 4 */
-//          thistime -= (float)(drand48() * dz->param[TEXTURE_SCAT] * timestep);
-//  
-//      if(dz->param[TEXTURE_TGRID]>0.0)
-//          thistime  = quantise(thistime,dz->param[TEXTURE_TGRID]);    /* 6 */
-//      (*thisnote)->ntime = (float)thistime;
-//  }
-//  *thisnote = (*thisnote)->next;
-//  return(FINISHED);               /* 8a */
-//}
-
-/************************** PRE_SPACE ********************************
- *
- * Store spatial data in the tsetnote spacepos and motioncentre.
- */
-
-int pre_space(noteptr thisnote,dataptr dz)
-{
-    int exit_status;
-    double position;
-    if((exit_status = getpos((double)thisnote->ntime,&position,dz))<0)
-        return(exit_status);
-    thisnote->spacepos     = (float)position;
-    thisnote->motioncentre = (float)dz->param[CPOS];
-    return(FINISHED);
-}
-
-/************************** GETPOS ****************************
- *
- * Calculate spatial position of event from it's time.
- */
-
-int getpos(double thistime,double *position,dataptr dz)
-{
-    int exit_status;
-    if(dz->brksize[TEXTURE_POS] && (exit_status = read_value_from_brktable(thistime,TEXTURE_POS,dz))<0)
-        return(exit_status);
-    if(dz->brksize[TEXTURE_SPRD] && (exit_status = read_value_from_brktable(thistime,TEXTURE_SPRD,dz))<0)
-        return(exit_status);
-    if(dz->param[TEXTURE_SPRD] > 0.0) {
-        if((exit_status = spread_and_set_cpos(position,dz->param[TEXTURE_POS],dz->param[TEXTURE_SPRD],dz))<0)
-            return(exit_status);
-    } else {
-/* NOV 1997--> */
-        dz->param[CPOS] = dz->param[TEXTURE_POS];
-/* <--NOV 1997 */
-        *position       = dz->param[TEXTURE_POS];
-    }
-    return(FINISHED);
-}
-
-/***************************** SPREAD_AND_SET_CPOS *****************************/
-
-int spread_and_set_cpos(double *position,double given_position,double spread,dataptr dz)
-{
-    int exit_status;
-    int    posno, spswitch;
-    int    poscnt,hposcnt;
-    double hspread,spacing, closeness, squash;
-
-    /* total stereospace has MAXPOSCNT positions: calc no. & spacing of positions available at given spread */
-    poscnt  = round(spread * (double)MAXPOSCNT);
-    hposcnt = poscnt/2;
-    hspread = spread/(double)2.0;
-    if(hposcnt != 0)
-        spacing = hspread/(double)hposcnt;
-    else {
-    /* bandwidth effectively zero: return given position */ 
-        dz->param[CPOS] = given_position;
-        *position       = given_position;
-        return(FINISHED);
-    }
-    /* randomly select leftwards/rightwards of the given position */
-    if((exit_status = doperm(2,PM_SPACE,&spswitch,dz))<0)
-        return(exit_status);                    
-    if(!spswitch)
-        spswitch = -1;                              
-
-    /* randomly chose a pos (to left or right) around centre pos */
-    posno  = round(drand48() * hposcnt);                
-    posno *= spswitch;                              
-
-    /* calculate warping coefficient to avoid position-spread leaking over edges of stereo-space */
-    if(spread>(double)1.0/SQUASH)
-        squash = (double)1.0/spread;
-    else
-        squash = SQUASH;
-
-    /* If (position+spread) leaks to right of stereo-space : squeeze position */
-    if(given_position>=0.5 && (given_position + spread) > 1.0) {
-        closeness = (given_position - 0.5)/(double)0.5;
-        dz->param[CPOS] = given_position - (hspread*pow(closeness,squash));
-    /* If (position+spread) leaks to left of stereo-space : squeeze position */
-    } else if(given_position<0.5 && given_position < spread) {  
-        closeness = (0.5 - given_position)/(double)0.5;
-        dz->param[CPOS] = given_position + (hspread*pow(closeness,squash));
-    } else
-        dz->param[CPOS] = given_position;
-
-    /* generate true position, around central position */
-    *position = dz->param[CPOS] + ((double)posno * spacing);
-    return chekrang(position);
-}
-
-/*************************** CHEKRANG **************************
- * 
- * Check variable lies within range 0.0 to 1.0.
- */
-
-int chekrang(double *val)
-{
-    if(flteq(*val,1.0))
-        *val = 1.0;
-    if(flteq(*val,0.0))
-        *val = 0.0;
-    if(*val<0.0 || *val>1.0) {                       
-        sprintf(errstr,"value [%f] outside range 0-1: chekrang()\n",*val);
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/************************** READ_A_NOTE_FROM_NOTEDATA_FILE ********************************/
-
-int read_a_note_from_notedata_file(noteptr thisnote,int noteno,int motifno,double *lasttime,dataptr dz)
-{
-    int exit_status;
-    unsigned int texflag = dz->tex->txflag;
-    char temp[200], *p, *q;
-    double val;
-    int instr_no, start;
-    if(dz->fp==NULL) {
-        sprintf(errstr,"Note datafile descriptor not initialised: read_a_note_from_notedata_file()\n");
-        return(PROGRAM_ERROR);
-    }
-    if(fgets(temp,200,dz->fp)==NULL){
-        sprintf(errstr,"Note data line for note %d, motif %d missing in notedatafile\n",noteno,motifno);
-        return(DATA_ERROR);
-    }
-    p =temp;
-    while(isspace(*p))
-        p++;
-    q = p;
-    if(*q==ENDOFSTR)
-        return(CONTINUE);
-    if((exit_status = get_data_item(q,&p,&val))<0) {
-        sprintf(errstr,"No time data for note %d, motif %d in notedatafile\n",noteno,motifno); 
-        return(DATA_ERROR);
-    }
-    if(exit_status==FINISHED) {
-        sprintf(errstr,"No data after time for note %d, motif %d in notedatafile\n",noteno,motifno); 
-        return(DATA_ERROR);
-    }
-    thisnote->ntime = (float)val;
-    if((noteno > 1) && (*lasttime > thisnote->ntime)) {
-        sprintf(errstr,"Notes in reverse time order: notedata file : motif %d: notes %d & %d\n",
-        motifno,noteno,noteno-1);
-        return(DATA_ERROR);
-    }
-    *lasttime = thisnote->ntime;
-    p++;
-    q = p;
-    if((exit_status = get_data_item(q,&p,&val))<0) {
-        sprintf(errstr,"No instr_no for note %d, motif %d in notedatafile\n",noteno,motifno); 
-        return(DATA_ERROR);
-    }
-    if(exit_status==FINISHED) {
-        sprintf(errstr,"No data after instr_no for note %d, motif %d in notedatafile\n",noteno,motifno); 
-        return(DATA_ERROR);
-    }
-    instr_no = round(val);
-
-    p++;
-    q = p;
-    if((exit_status = get_data_item(q,&p,&val))<0) {
-        sprintf(errstr,"No pitch data for note %d, motif %d in notedatafile\n",noteno,motifno); 
-        return(DATA_ERROR);
-    }
-    if(exit_status==FINISHED) {
-        sprintf(errstr,"No data after pitch for note %d, motif %d in notedatafile\n",noteno,motifno); 
-        return(DATA_ERROR);
-    }
-    thisnote->pitch = (float)val;
-
-/* NEEDS TESTING FOR MIDIRANGE: EXCEPT IN TIMING SET CASE */
-    if(!(texflag & ISTIMED) || motifno!=1) {
-        if(val < MIDIMIN || val > MIDIMAX) {
-            sprintf(errstr,"pitch value [%lf] out of range (%d to %d): motif %d: note %d\n",
-            val,MIDIMIN,MIDIMAX,motifno,noteno);
-            return(DATA_ERROR);
-        }
-    }
-    p++;
-    q = p;
-    if((exit_status = get_data_item(q,&p,&val))<0) {
-        sprintf(errstr,"No amplitude data for note %d, motif %d in notedatafile\n",noteno,motifno); 
-        return(DATA_ERROR);
-    }
-    if(exit_status==FINISHED) {
-        sprintf(errstr,"No data after amp for note %d, motif %d in notedatafile\n",noteno,motifno); 
-        return(DATA_ERROR);
-    }
-    thisnote->amp = (float)val;
-/* 1999 THIS NEEDS TESTING FOR MIDIRANGE EXCEPT IN TIMING SET CASE */
-    if(!(texflag & ISTIMED) || motifno!=1) {
-        if(val < MIDIMIN || val > MIDIMAX) {
-            sprintf(errstr,"amplitude value [%lf] out of range (%d to %d): motif %d: note %d\n",
-            val,MIDIMIN,MIDIMAX,motifno,noteno);
-            return(DATA_ERROR);
-        }
-    }
-    p++;
-    q = p;
-    if((exit_status = get_data_item(q,&p,&val))<0) {
-        sprintf(errstr,"No duration data for note %d, motif %d in notedatafile\n",noteno,motifno); 
-        return(DATA_ERROR);
-    }
-    thisnote->dur = (float)val;
-    if(texflag & IS_ORN_OR_MTF) {
-        if(texflag & IS_ORNATE) {
-            start = 2;
-        } else {
-            start = 1;
-            if(texflag & ISTIMED)
-                start++;
-        }
-        if(texflag & ISHARM)
-            start++;
-        if(motifno >= start) {
-            if(val <= FLTERR) {
-                sprintf(errstr,"Duration value [%lf] is too small: motif %d: note %d\n",val,motifno,noteno);
-                return(DATA_ERROR);
-            }
-        }
-    } else {
-        thisnote->dur = 1.0f;   /* default ; redundant */
-    }
-    return(FINISHED);
-}
-
-/***************************** GENERATE_TSET_TIMES **********************************
- *
- * Store time initially as SECONDS.
- *
- * (1)  Create location for a new note.
- * (2)  Go to that new note.
- * (3)  Store the current time at this note.
- * (4)  Find note-density at this time, and generate time of next event.
- * (5)  Return nextnote.
- */
-
-int generate_tset_times(double *thistime,noteptr *thisnote,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = make_new_note(thisnote))<0)
-        return(exit_status);                        /* 1 */
-    (*thisnote)->ntime = (float)(*thistime);            /* 3 */
-    if(dz->brksize[TEXTURE_PACK]) {
-        if((exit_status = read_value_from_brktable(*thistime,TEXTURE_PACK,dz))<0)
-            return(exit_status);
-    }       
-    *thistime  += dz->param[TEXTURE_PACK];          /* 4 */
-    return(FINISHED);                               /* 5 */
-}
-
-/********************** UN_LINK_NOTE ******************************
- *
- * Deletes empty address space at end of notelist.
- */
-
-int un_link_note(noteptr thisnote)
-{
-    if(thisnote->last==(noteptr)0) {
-        sprintf(errstr,"Problem in un_link_note()\n");
-        return(PROGRAM_ERROR);
-    }
-    thisnote = thisnote->last;
-    free(thisnote->next);
-    thisnote->next = (noteptr)0;
-    return(FINISHED);
-}
-
-/************************ NEW_MOTIF *****************************
- *
- * Set up next motif in a list of musical-motifs.
- * Set up location of first note of this motif.
- */
-
-int new_motif(motifptr *thismotif)
-{
-    int exit_status;
-    motifptr newmotif;
-    noteptr  thisnote;
-    
-    if((newmotif = (motifptr)malloc(sizeof (struct motif)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY to store next motif.\n");
-        return(MEMORY_ERROR);
-    }
-    (*thismotif)->next = newmotif;
-    newmotif->last = *thismotif;
-    newmotif->next = (motifptr)0;
-    if((exit_status = init_note(&thisnote))<0)
-        return(exit_status);
-    thisnote->next = (noteptr)0;   
-    thisnote->last = (noteptr)0;   
-    newmotif->firstnote = thisnote;
-    *thismotif = newmotif;
-    return(FINISHED);
-}
-
-/********************** UNLINK_LAST_MOTIF ******************************
- *
- * Deletes empty address space at end of motiflist.
- */
-
-int unlink_last_motif(motifptr thismotif)
-{
-    if(thismotif->last==(motifptr)0) {
-        sprintf(errstr,"Problem in unlink_last_motif()\n");
-        return(PROGRAM_ERROR);
-    }
-    thismotif = thismotif->last;
-    free(thismotif->next);
-    thismotif->next = (motifptr)0;
-    return(FINISHED);
-}
-
-/**************************** SUBTRACT_ONE_FROM_BRKVALS ****************************/
-
-void subtract_one_from_brkvals(int paramno,dataptr dz)
-{
-    double *p = dz->brk[paramno] + 1;
-    double *pend = dz->brk[paramno] + (dz->brksize[paramno] * 2);
-    while(p < pend) {
-        *p -= 1.0;
-        p += 2;
-    }
-}
-
-/************************ BIGSCATTER *************************************
- *
- * (1)  The number of time-points to be randomly scattered as a group is
- *  scatcnt.
- * (1a) Base time is the time from which these new scattered times are offset.
- * (2)  Save the current position in note list as 'here'.
- * (3)  Go forward in note list until there are scatcnt notes inclusive
- *  between here and there, or until list runs out.
- * (3a) If the list runs out, modify scatcnt accordingly.
- * (4)  Note the (original) time of the last of these events. This will
- *  be returned as the new 'lasttime' for the next cycle of the
- *  program.
- * (5)  Make the time-step include the total duration of all these
- *  events.
- * (5a) Generate a set of times AT RANDOM within this large timestep,
-    sort them and store them.
- * (6)  Replace existing times by scattered times, relative to basetime.
- * (6a) Convert to MIDitime.
- * (6b) Quantise if necessary.
- * (7)  Replace the last time.
- * (9)  Return the last note we worked on.
- */
-
-int bigscatter(noteptr *thisnote,double thistime,double timestep,double scatter,double *lasttime,dataptr dz)
-{
-    int n, scatcnt = round(scatter);        /* 1 */
-    double *sct, *scti;
-    double basetime = thistime - timestep;  /* 1a */
-    noteptr here  = *thisnote;              /* 2 */
-    noteptr there = *thisnote;              /* 2 */
-    if((scti = (double *)malloc(scatcnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for scattering structure.\n");
-        return(MEMORY_ERROR);
-    }
-    sct = scti;
-    for(n=0;n < scatcnt-1; n++) {           /* 3 */
-        if(there->next==(noteptr)0) {
-            scatcnt = n+1;                  /* 3a */
-            break;
-        }
-        there = there->next;
-    }
-    *lasttime = there->ntime;               /* 4 */
-    timestep += *lasttime - thistime;       /* 5 */
-    for(n= 0;n<scatcnt;n++)                 /* 5a */
-        *sct++ = drand48() * timestep;
-    upsort(scti,scatcnt);                   
-    sct = scti;
-    while(here!=there) {                    /* 6 */
-        thistime = basetime + (*sct++);
-        if(dz->param[TEXTURE_TGRID]>0.0)
-            thistime  = quantise(thistime,dz->param[TEXTURE_TGRID]);    /* 6b */
-        here->ntime = (float)thistime;
-        here = here->next;
-    }
-    thistime = basetime + *sct;             /* 7 */
-    if(dz->param[TEXTURE_TGRID]>0.0)
-        thistime  = quantise(thistime,dz->param[TEXTURE_TGRID]);
-    there->ntime = (float)thistime;
-    free(scti);
-    *thisnote = there;
-    return(FINISHED);                   /* 9 */
-}
-
-/************************** QUANTISE *************************************
- *
- * Quantise time point onto a grid.
- */
-
-double quantise(double thistime,double timegrid)
-{
-    int gridpoint;
-    timegrid *= MS_TO_SECS;
-    gridpoint = round(thistime/timegrid);
-    return((double)gridpoint * timegrid);
-}
-
-/************************* GET_DATA_ITEM ****************************/
-
-int get_data_item(char *q,char **p,double *val)
-{
-    int exit_status = CONTINUE;
-    if(*q==ENDOFSTR)
-        return(DATA_ERROR);
-    while(isspace(**p)) {
-        (*p)++;
-        if(**p == ENDOFSTR)
-            return(DATA_ERROR);
-    }
-    if(**p==TEXTURE_SEPARATOR)
-        return(DATA_ERROR);
-    while(!isspace(**p) && **p!=ENDOFSTR) {
-        (*p)++;
-    }
-    if(**p==ENDOFSTR)
-        exit_status = FINISHED;
-    **p = ENDOFSTR;
-    if(sscanf(q,"%lf",val)!=1)
-        return(DATA_ERROR);
-    return(exit_status);
-}
-
-/************************* INIT_NOTE ****************************
- *
- * Initialise notelist.
- */
-
-int init_note(noteptr *thisnote)
-{
-    if((*thisnote = (noteptr)malloc(sizeof(struct nnote)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for another note.\n");
-        return(MEMORY_ERROR);
-    }
-    (*thisnote)->next = (noteptr)0;
-    (*thisnote)->last = (noteptr)0;
-    return(FINISHED);
-}
-
-/********************** UPSORT *******************************
- * 
- * Sort set of doubles into ascending order.
- */
-
-void upsort(double *scti,int scatcnt)
-{
-    double sct;
-    int n, m;
-    for(n=0;n<(scatcnt-1);n++) {
-        for(m=n+1;m<scatcnt;m++) {
-            if(*(scti+m)<*(scti+n)) {
-                sct       = *(scti+m);
-                *(scti+m) = *(scti+n);
-                *(scti+n) = sct;
-            }
-        }
-    }
-}
-
-/*********************** PUT_ZNOTE ********************************
- *
- * Put zero values in all parameters except time.
- */
-
-void put_znote(noteptr thisnote)
-{
-    thisnote->amp   = 0.0f;
-    thisnote->pitch  = 0.0f;
-    thisnote->dur   = 0.0f;
-    thisnote->instr = 0;
-    thisnote->spacepos = 0.0f;
-    thisnote->motioncentre = 0.0f;
-}
-
-/************************* ASSIGN_TIMESET_HFSET_MOTIFSETS ******************************
- *
- * Assign appropriate pointers to input motifs.
- *
- * (1)  If it's a timed texture, indicate first motif in list as that
- *      which defines the set of times (tset).
- *      Similarly, if texture is ornamented or decorated, point to first
- *      motif as that to BE ornamented or decorated (tset).
- * (2)  If the texture restricted to HF(s) or HS(s), indicate next motif
- *      as the HF-set (hfldmotif). It may be read in different ways (as HF, as
- *      HS, or as time-varying of either type) at a later time.
- * (3)  If texture consists of motifs, or is to use specific ornaments...
- * (4)  count the number of motifs remaining.
- * (5)  Set up the array of phrases to point to the appropriate motifs.
- */
-
-int assign_timeset_hfset_motifsets(dataptr dz)
-{
-    int exit_status;
-    unsigned int texflag = dz->tex->txflag;
-    motifptr here, thismotif = dz->tex->motifhead;
-    int n;
-    dz->tex->phrasecnt = 0;    
-    if(texflag & ORN_DEC_OR_TIMED) {
-        if((exit_status = motifchek(thismotif))<0)
-            return(exit_status);
-        dz->tex->timeset = thismotif;                   /* 1 */
-        thismotif = thismotif->next;
-    }
-    if(texflag & ISHARM) {                              /* 2 */
-        if((exit_status = motifchek(thismotif))<0)
-            return(exit_status);
-        dz->tex->hfldmotif = thismotif;
-        thismotif = thismotif->next;
-    }
-    if((texflag & IS_ORNATE) || (texflag & IS_MOTIFS)) {    /* 3 */
-        if((exit_status = motifchek(thismotif))<0)
-            return(exit_status);
-        here = thismotif;
-        while(thismotif!=(motifptr)0) {                 /* 4 */
-            dz->tex->phrasecnt++;
-            thismotif = thismotif->next;
-        }                                               /* 5 */
-        if((dz->tex->phrase = (motifptr *)malloc(dz->tex->phrasecnt * sizeof(motifptr)))==NULL) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for phrase array.\n");
-            return(MEMORY_ERROR);
-        }
-        thismotif = here;
-        n = -1;
-        while(thismotif!=(motifptr)0) {
-            dz->tex->phrase[++n] = thismotif;
-            thismotif = thismotif->next;
-        }
-    }
-    return(FINISHED);
-}
-
-/***************************** MASSAGE_PARAMS ****************************/
-
-int massage_params(dataptr dz)
-{
-    int exit_status;
-    unsigned int texflag = dz->tex->txflag;
-    convert_cmdline_instrnos_to_internal_representation(dz);
-    if((exit_status = check_max_transpos_compatible_with_splicelen(dz))<0)
-        return(exit_status);
-    if(texflag & IS_CLUMPED) {
-        if((exit_status = set_amptype_params(dz))<0)
-            return(exit_status);
-    }
-    if(texflag & IS_DECOR) {
-        if((exit_status = set_decor_pitchposition_params(dz))<0)
-            return(exit_status);
-    }
-    return(FINISHED);
-}
-
-/************************* INIT_MOTIFS *****************************
- *
- * Set up head item of a list of musical-motifs.
- * Set up location of first note of first motif.
- */
-
-int init_motifs(dataptr dz)
-{
-    int exit_status;
-    noteptr thisnote;
-    if((dz->tex->motifhead = (motifptr)malloc(sizeof (struct motif)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY to store any motifs.\n");
-        return(MEMORY_ERROR);
-    }
-    dz->tex->motifhead->next  = (motifptr)0;
-    dz->tex->motifhead->last  = (motifptr)0;
-    if((exit_status = init_note(&thisnote))<0)
-        return(exit_status);
-    dz->tex->motifhead->firstnote = thisnote;
-    thisnote->next = (noteptr)0;   
-    thisnote->last = (noteptr)0;   
-    return(FINISHED);
-}
-
-/******************************** INITPERM *********************************
- *
- * Establish storage space for permutation parameters.
- *
- * (1)  create pointers to the items within the permuted sets.      Initialise to zero.
- * (2)  Create storage for current length of each perm.             Initialise to zero.
- * (3)  Create storage for previous length of each perm.            Initialise to -1 (impossible).
- *      If new perm different length to old, space for permuted elements will need to be re-malloced.
- * (4)  Create pointers to storage areas for each permuted set.     Initialise to point nowhere. 
- *      These will be malloced when the size of each set-to-permute is known.
- * (5)  Create storage for previous outputed val in each perm.      Initialise to -1 (impossible). 
- *      This is useful at permutation boundaries, when a particular element may be repeated more
- *      than permitted no. of times if there's no check. These constants allow no. of repets to be counted.
- * (6)  Create counter of current no. of consecutive repets of an element in each of the (output) perms.
- *      Initialise to 0, though this is arbitrary, as repetcnt should always be set on any call of do_perm.
- * (7)  Create storage for max no. of allowed consecutive repets of an element in each perm-set.
- *      Initialise to 1, which is the default if no info is given to the contrary.
- */
-
-int initperm(int ***permm,dataptr dz)
-{
-    int n;
-    if((dz->iparray[TXPERMINDEX] = (int *)malloc(PERMCNT * sizeof(int)))==NULL) {   /* 1 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for permutation indeces.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n<PERMCNT;n++)
-        dz->iparray[TXPERMINDEX][n] = 0;
-
-    if((dz->iparray[TXPERMLEN] = (int *)malloc(PERMCNT * sizeof(int)))==NULL) {   /* 2 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for permutation lengths.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n<PERMCNT;n++)
-        dz->iparray[TXPERMLEN][n] = 0;
-
-    if((dz->iparray[TXLASTPERMLEN] = (int *)malloc(PERMCNT * sizeof(int)))==NULL) {   /* 3 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for last permutation lengths.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n<PERMCNT;n++)
-        dz->iparray[TXLASTPERMLEN][n] = -1;
-
-    if((*permm = (int **)malloc(PERMCNT * sizeof(int *)))==NULL) {   /* 4 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for permutations.\n");
-        return(MEMORY_ERROR);
-    }
-
-    for(n=0;n<PERMCNT;n++)
-        (*permm)[n] = (int *)0;
-
-    if((dz->iparray[TXLASTPERMVAL] = (int *)malloc(PERMCNT * sizeof(int)))==NULL) {   /* 5 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for last permutation values.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n<PERMCNT;n++)
-        dz->iparray[TXLASTPERMVAL][n] = -1;
-
-    if((dz->iparray[TXREPETCNT] = (int *)malloc(PERMCNT * sizeof(int)))==NULL) {   /* 6 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for permutation repetition counts.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n<PERMCNT;n++)
-        dz->iparray[TXREPETCNT][n] = 1;
-
-    if((dz->iparray[TXRPT] = (int *)malloc(PERMCNT * sizeof(int)))==NULL) {   /* 7 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for permutation repetitions.\n");
-        return(MEMORY_ERROR);
-    }
-    /* THESE ARE THE DEFAULT NUMBER OF REPETITIONS-OF-AN-ENTITY ALLOWED IN A PERM */
-    dz->iparray[TXRPT][PM_SPACE]  = SPACE_REPETS;
-    dz->iparray[TXRPT][PM_PITCH]  = PITCH_REPETS;
-    dz->iparray[TXRPT][PM_AMP]    = AMP_REPETS;
-    dz->iparray[TXRPT][PM_DUR]    = DUR_REPETS;
-    dz->iparray[TXRPT][PM_INSNO]  = INSNO_REPETS;
-    dz->iparray[TXRPT][PM_GPRANG] = GPRANG_REPETS;
-    dz->iparray[TXRPT][PM_GPSIZE] = GPSIZE_REPETS;
-    dz->iparray[TXRPT][PM_GPDENS] = GPDENS_REPETS;
-    dz->iparray[TXRPT][PM_GPCNTR] = GPCNTR_REPETS;
-    dz->iparray[TXRPT][PM_GPPICH] = GPPICH_REPETS;
-    dz->iparray[TXRPT][PM_ORNPOS] = ORNPOS_REPETS;
-    dz->iparray[TXRPT][PM_GPSPAC] = GPSPAC_REPETS;
-    dz->iparray[TXRPT][PM_ORIENT] = ORIENT_REPETS;
-    dz->iparray[TXRPT][PM_DECABV] = DECABV_REPETS;
-    dz->iparray[TXRPT][PM_MULT]   = MULT_REPETS;
-    dz->iparray[TXRPT][PM_WHICH]  = WHICH_REPETS;
-    dz->iparray[TXRPT][PM_GPPICH2]= GPPICH2_REPETS;
-    return(FINISHED);
-}

+ 0 - 33
dev/texture/v8/texture.h

@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
- 
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- 
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
- 
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-#define IS_GROUCHO_COMPILE      (1)
-
-#include    <pnames.h>
-#include    <flags.h>
-#include    <txtucon.h>
-#include    <texture1.h>
-
-/**
-#define MINDUR_OVERRIDE = 1;    // used for "texture_new"
-**/

+ 0 - 220
dev/texture/v8/texture1.c

@@ -1,220 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
- 
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- 
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
- 
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-/* floatsam version: no changes */
-#include <stdio.h>
-#include <stdlib.h>
-#include <structures.h>
-#include <tkglobals.h>
-#include <globcon.h>
-#include <processno.h>
-#include <modeno.h>
-#include <arrays.h>
-#include <texture.h>
-#include <cdpmain.h>
-
-#include <sfsys.h>
-
-/********************* GETTING DATA VALUES VIA RAND PERMUTATIONS *************/
-
-
-
-static int  delete_all_other_motifs(motifptr thismotif,dataptr dz);
-static int  delete_motifs_before(motifptr thismotif,dataptr dz);
-static int  delete_motifs_beyond(motifptr thismotif);
-
-/***************************** TEXTURE 1 ********************************
- * (1)  Generating random permutations of sets of values, and delivering
- *      the next value from one of these.
- * (2)  Scattering values within a range.
- */
-
-/*************************** MAKE_TEXTURE *********************************/
-
-int make_texture(dataptr dz)
-{
-    int exit_status;
-    unsigned int texflag = dz->tex->txflag;
-    display_virtual_time(0,dz);
-    if(texflag & ISHARM) {
-        if(texflag & IS_CLUMPED) {
-            if((exit_status = do_clumped_hftexture(dz))<0)
-                return(exit_status);
-        } else {
-            if((exit_status = do_simple_hftexture(dz))<0)
-                return(exit_status);
-        }
-    } else {
-        if((exit_status = do_texture(dz))<0)
-            return(exit_status);
-    }
-    if((exit_status = delete_all_other_motifs(dz->tex->timeset,dz))<0)
-        return(exit_status);
-    return(FINISHED);
-}
-
-/****************************** GETVALUE **********************************
- *
- * Get value of a parameter, either from table, or fixed value.
- */
-
-int getvalue(int paramhi,int paramlo,double thistime,int z,double *val,dataptr dz)
-{   
-    int exit_status;
-    double range;
-    int is_swap = 0;
-    if(dz->is_int[paramhi] || dz->is_int[paramlo]) {
-        sprintf(errstr,"getvalue() called on integer parameter %d or %d\n",paramhi,paramlo);
-        return(PROGRAM_ERROR);
-    }
-    if(dz->brk[paramhi]) {
-        if((exit_status = read_value_from_brktable(thistime,paramhi,dz))<0)
-            return(exit_status);
-    }
-    if(dz->brk[paramlo]) {
-        if((exit_status = read_value_from_brktable(thistime,paramlo,dz))<0)
-            return(exit_status);
-    }
-    if((range = dz->param[paramhi] - dz->param[paramlo])<0.0) {
-        swap(&dz->param[paramhi],&dz->param[paramlo]);
-        range = -range;
-        is_swap = 1;
-    }
-    if(flteq(range,0.0)) {
-        *val = dz->param[paramhi];
-        if(is_swap)
-            swap(&dz->param[paramhi],&dz->param[paramlo]);
-        return(FINISHED);
-    }
-    if((exit_status = pscatx(range,dz->param[paramlo],z,val,dz))<0)
-        return(exit_status);
-    if(is_swap)
-        swap(&dz->param[paramhi],&dz->param[paramlo]);
-    return(FINISHED);
-}
-
-/****************************** IGETVALUE **********************************
- *
- * Get integer value of a parameter, either from table, or fixed value.
- */
-
-int igetvalue(int paramhi,int paramlo,double thistime,int z,int *ival,dataptr dz)
-{
-    int   exit_status;
-    int  irange;
-    int   a, is_swap = 0;
-
-    if(!dz->is_int[paramhi] || !dz->is_int[paramlo]) {
-        sprintf(errstr,"igetvalue() called on non-integer parameter %d or %d\n",paramhi,paramlo);
-        return(PROGRAM_ERROR);
-    }
-    if(dz->brk[paramhi]) {
-        if((exit_status = read_value_from_brktable(thistime,paramhi,dz))<0)
-            return(exit_status);
-    }
-    if(dz->brk[paramlo]) {
-        if((exit_status = read_value_from_brktable(thistime,paramlo,dz))<0)
-            return(exit_status);
-    }
-
-    if((irange = dz->iparam[paramhi] - dz->iparam[paramlo])<0) {
-        iiswap(&dz->iparam[paramhi],&dz->iparam[paramlo]);
-        irange = -irange;
-        is_swap = 1;
-    }
-    if(irange==0) {
-        *ival = (int)dz->iparam[paramlo]; 
-        if(is_swap)
-            iiswap(&dz->iparam[paramhi],&dz->iparam[paramlo]);
-        return(FINISHED);
-/* OCT 1997 replace ****
-    } else if((exit_status = doperm(irange,z,&a,dz))<0)
-*/
-/* BY */
-    } else if((exit_status = doperm(irange+1,z,&a,dz))<0)
-/* because the range of an integer variable between(say) 3 & 7 is INCLUSIVELY 5, not 7-3) */
-        return(exit_status);
-    a = (int)(a + dz->iparam[paramlo]);
-    *ival = a;
-    if(is_swap)
-        iiswap(&dz->iparam[paramhi],&dz->iparam[paramlo]);
-    return(FINISHED);
-}
-
-/*************************** DELETE_ALL_OTHER_MOTIFS **********************************
- *
- * Deletes all other motifs in motif list.
- */
-
-int delete_all_other_motifs(motifptr thismotif,dataptr dz)
-{
-    int exit_status;
-    motifptr here = thismotif->next;
-    if((exit_status = delete_motifs_before(thismotif,dz))<0)
-        return(exit_status);
-    if(here!=(motifptr)0) {
-        if((exit_status = delete_motifs_beyond(here))<0)
-            return(exit_status);
-    }
-    dz->tex->motifhead = thismotif;
-    return(exit_status);
-}
-
-/********************** DELETE_MOTIFS_BEYOND ******************************
- *
- * Deletes motif-space from this space onwards.
- */
-
-int delete_motifs_beyond(motifptr thismotif)
-{
-    motifptr start = thismotif;
-    while(thismotif->next!=(motifptr)0)
-        thismotif = thismotif->next;
-    while(thismotif!=start) {
-        thismotif = thismotif->last;
-        free(thismotif->next);
-    }
-    thismotif->next = (motifptr)0;
-    return(FINISHED);
-}
-
-/*********************** DELETE_MOTIFS_BEFORE ***************************
- *
- * Kill all motifs BEFORE this one in the motif list.
- */
-
-int delete_motifs_before(motifptr thismotif,dataptr dz)
-{
-    motifptr here = dz->tex->motifhead;
-    while(here!=thismotif) {
-        if((here = here->next)==(motifptr)0) {
-            sprintf(errstr,"Problem in delete_motifs_before()\n");
-            return(PROGRAM_ERROR);
-        }
-        delete_notes_here_and_beyond(here->last->firstnote);
-        free(here->last);
-        here->last = (motifptr)0;
-    }
-    dz->tex->motifhead = thismotif;
-    return(FINISHED);
-}

+ 0 - 517
dev/texture/v8/texture2.c

@@ -1,517 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
- 
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- 
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
- 
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-/* floatsam version: no changes */
-#include <stdio.h>
-#include <stdlib.h>
-#include <structures.h>
-#include <tkglobals.h>
-#include <globcon.h>
-#include <processno.h>
-#include <modeno.h>
-#include <arrays.h>
-#include <texture.h>
-#include <cdpmain.h>
-#include <sfsys.h>
-#include <osbind.h>
-
-/***************************** GENERATING TEXTURES WITH NO HFIELD(S) ******************************/
-
-static int  setup_motif_params
-            (noteptr phrasenote,double tsettime,double *thisamp,double ampstep,double *phraseamp,
-            int phrno,double rangemult,noteptr thisnote,noteptr tsetnote,
-            double multiplier,double timeadjust,dataptr dz);
-static void gen_orn_pitch(noteptr thisnote,noteptr tsetnote,noteptr phrasenote,
-            float phrlpitch,float phrfirstpitch,dataptr dz);
-static void gen_mtf_pitch(noteptr thisnote,noteptr tsetnote,noteptr phrasenote,float phrfirstpitch);
-static int  dec_centre(double tsetpitch,float *val,int gpsize,double gprlow,double gprange,dataptr dz);
-static int  pscat(double range,double bottom,int pindex,double *val,dataptr dz);
-static int  initialise_phrases
-            (int **phrnotecnt,double **phraseamp,double **phrange,noteptr **phrlastnote,dataptr dz);
-static int  do_ev_pch
-            (double *thispitch,double thistime,double *pptop,double *ppbot,dataptr dz);
-static int  get_gpparams
-            (double thistime,double thispitch,unsigned char dectypecnt,double *gprange,double *gprlow,int *gpsize,
-            double *gpdense,double pptop,double ppbot,unsigned char dectypestor,int mingrpsize,dataptr dz);
-static int orientrange
-            (double thispitch,double pptop, double ppbot,double *gprange, double *gprlow,
-            unsigned char dectypestor,unsigned char dectypecnt,dataptr dz);
-static void squeezrange(double thispitch,double *gprange,double *gprlow, double pptop, double ppbot);
-
-/**************************** DO_TEXTURE *****************************/
-
-int do_texture(dataptr dz)
-{
-    int exit_status;
-    noteptr tsetnote = dz->tex->timeset->firstnote;
-    unsigned int texflag     = dz->tex->txflag;
-    unsigned char dectypestor = dz->tex->dectypstor;
-    unsigned char dectypecnt  = dz->tex->dectypcnt;
-    unsigned char amptypestor = dz->tex->amptypstor;
-    unsigned char amptypecnt  = dz->tex->amptypcnt;
-    int ampdirected           = dz->tex->ampdirectd;
-    motifptr tset             = dz->tex->timeset;
-    motifptr *phrase          = dz->tex->phrase;
-    int phrcount              = dz->tex->phrasecnt;
-    int *phrnotecnt=NULL;
-    double *phraseamp=NULL, *phrange=NULL;  
-    noteptr thisnote=NULL, nextnote=NULL, phrasenote=NULL, nextevent=NULL, *phrlastnote=NULL, *shadow=NULL;
-    float phrlpitch=0.0, phrfirstpitch=0.0;
-    unsigned char thisinstr, amptype=0;
-    double  tsettime=0.0, thistime=0.0, thispitch=0.0, ampstep=0.0, thepitch=0.0, thisamp=0.0, thisdur=0.0;
-    double  rangemult=0.0, gpdense=0.0, gprange=0.0, gprlow=0.0, multiplier=0.0;
-    double timeadjust = 0.0; /* default */
-    int phrno=0, n=0, shadowsize=0, gpsize=0, mingrpsize = 0;
-    double pptop=0.0, ppbot=0.0;
-    int shadindex = 0;
-
-    dz->iparam[SPINIT] = 0;
-    if(texflag & IS_CLUMPED) {
-        if((dz->tex->phrasecnt > 0) 
-        && (exit_status = initialise_phrases(&phrnotecnt,&phraseamp,&phrange,&phrlastnote,dz))<0)
-            return(exit_status);
-
-        if(texflag & IS_GROUPS)
-            mingrpsize = 1;         
-
-        if((exit_status= make_shadow(tset,&shadowsize,&shadow))<0)
-            return(exit_status);
-
-        if(texflag & IS_DECOR) {
-            setup_decor(&pptop,&ppbot,&shadindex,&tsetnote,dz);
-        } else if(texflag & IS_MOTIFS)  {
-            if((exit_status = set_motifs(phrcount,phrase,phrnotecnt,phraseamp,phrange,phrlastnote))<0)
-                return(exit_status);
-        } else if(texflag & IS_ORNATE) {
-            if((exit_status = set_motifs(phrcount,phrase,phrnotecnt,phraseamp,phrange,phrlastnote))<0)
-                return(exit_status);
-            if(dz->vflag[WHICH_CHORDNOTE]==DECOR_HIGHEST)
-                tsetnote = gethipitch(tsetnote,&shadindex);
-        }
-    }
-
-    while(tsetnote!=(noteptr)0) {
-        tsettime  = (double)tsetnote->ntime;
-        thistime  = tsettime;
-        if((exit_status = read_values_from_all_existing_brktables(thistime,dz))<0)
-            return(exit_status);
-        if(texflag & IS_DECOR)
-            thispitch = tsetnote->pitch;
-        if(texflag & IS_ORN_OR_MTF) {
-            if((exit_status = 
-            setup_motif_or_ornament(thistime,&multiplier,&phrno,&phrasenote,phrase,dz))<0)
-                return(exit_status);
-        }
-        if(!(texflag & IS_ORN_OR_DEC)) {
-            if((exit_status = do_ev_pch(&thispitch,thistime,&pptop,&ppbot,dz))<0)
-                return(exit_status);
-            tsetnote->pitch = (float)thispitch;
-        }
-        if((exit_status = do_amp_instr_dur(&thisamp,&thisinstr,&thisdur,tsetnote,thistime,dz))<0)
-            return(exit_status);
-        if(texflag & IS_CLUMPED) {
-            if(texflag & IS_MOTIFS) {
-                if((exit_status = getmtfdur(tsetnote,phrasenote,&thisdur,multiplier,dz))<0)
-                    return(exit_status);
-                tsetnote->dur = (float)thisdur;
-            }
-            if(texflag & IS_ORN_OR_MTF) {
-                gpsize = phrnotecnt[phrno];
-                phrfirstpitch = phrasenote->pitch;
-            } else {
-                if((exit_status = get_gpparams(thistime,thispitch,dectypecnt,
-                &gprange,&gprlow,&gpsize,&gpdense,pptop,ppbot,dectypestor,mingrpsize,dz))<0)
-                    return(exit_status);
-            }
-            if(texflag & IS_DECOR) {
-                if((exit_status = position_and_size_decoration(&thistime,tsettime,gpdense,&gpsize,dz))<0)
-                    return(exit_status);
-            } else
-                gpsize--;
-            if(texflag & IS_ORNATE) {
-                phrlpitch = (phrlastnote[phrno])->pitch;
-                if((exit_status = setup_ornament
-                (&timeadjust,&thistime,&gpsize,phrlastnote,multiplier,&phrasenote,phrno,dz))<0)
-                    return(exit_status);
-            }
-            if(!(texflag & IS_DECOR))
-                nextnote = tsetnote->next;
-            if(gpsize>0) {                      /* 3b */
-                if(texflag & IS_ORN_OR_MTF) {
-                    if((exit_status = orn_or_mtf_amp_setup
-                    (ampdirected,phrange,phrno,thisamp,gpsize,&rangemult,&ampstep,&amptype,amptypestor,amptypecnt,dz))<0)
-                        return(exit_status);
-                }
-                if(texflag & IS_MOTIFS) {
-                    if((exit_status = set_motif_amp
-                    (tsetnote,&thisamp,gpsize,ampstep,phrasenote,rangemult,phraseamp,phrno,amptype))<0)
-                        return(exit_status);
-                } else if(texflag & IS_ORNATE) {
-                    if((exit_status = set_ornament_amp
-                    (phraseamp,phrlastnote,&thisamp,phrasenote,phrno,tsetnote,ampstep,rangemult,gpsize,dz))<0)
-                        return(exit_status);
-                } else if(texflag & IS_GROUPS) {
-                    if((exit_status = set_group_amp
-                    (tsetnote,&thisamp,&amptype,&ampstep,gpsize,amptypecnt,amptypestor,dz))<0)
-                        return(exit_status);
-                } else if(texflag & IS_DECOR) {
-                    if((exit_status = set_decor_amp
-                    (ampdirected,&thisamp,&ampstep,gpsize,&amptype,amptypecnt,amptypestor,dz))<0)
-                        return(exit_status);
-                }
-                if(dz->iparam[TEX_GPSPACE]!=IS_STILL) {
-                    if((exit_status = init_group_spatialisation(tsetnote,shadindex,shadow,shadowsize,dz))<0)
-                        return(exit_status);
-                }
-                thisnote  = tsetnote;
-                if(texflag & IS_DECOR)
-                    nextnote = tsetnote->next;
-                else if(texflag & IS_ORNATE) {
-                    if(!dz->vflag[IS_PRE])
-                        phrasenote = phrasenote->next;
-                }
-                if(texflag & IS_ORN_OR_DEC)
-                    nextevent = getnextevent_to_decorate(tsetnote,&shadindex,dz);
-                for(n=0;n<gpsize;n++) {
-                    if((exit_status = make_new_note(&thisnote))<0)
-                        return(exit_status);
-                    if(texflag & IS_DEC_OR_GRP) {
-                        if((exit_status = set_group_params
-                        (tsetnote,thisnote,gpdense,ampstep,&thisamp,&thistime,thisdur,dz))<0)
-                            return(exit_status);
-                        if((exit_status = do_grp_ins(tsetnote->instr,&(thisnote->instr),dz))<0)
-                            return(exit_status);
-                        thisnote->motioncentre = tsetnote->motioncentre;
-                        if(texflag & IS_DECOR) {
-                            if((exit_status = dec_centre
-                            (thispitch,&(thisnote->pitch),gpsize,gprlow,gprange,dz))<0) 
-                                return(exit_status);
-                        } else {
-                            if((exit_status = pscat(gprange,gprlow,PM_GPPICH,&thepitch,dz))<0)
-                                return(exit_status);
-                            thisnote->pitch = (float)thepitch;
-                        }
-                        thisnote->ntime  = (float)thistime; 
-                    } else {
-                        if((exit_status = check_next_phrasenote_exists(&phrasenote,texflag,dz))<0)
-                            return(exit_status);
-                        if((exit_status = setup_motif_params(phrasenote,thistime,&thisamp,ampstep,phraseamp,phrno,
-                        rangemult,thisnote,tsetnote,multiplier,timeadjust,dz))<0)
-                            return(exit_status);
-                        if(texflag & IS_MOTIFS) {
-                            gen_mtf_pitch(thisnote,tsetnote,phrasenote,phrfirstpitch);
-                        } else {
-                            gen_orn_pitch(thisnote,tsetnote,phrasenote,phrlpitch,phrfirstpitch,dz);
-                            phrasenote = phrasenote->next;
-                        }
-                    }
-                    if((exit_status = setspace(tsetnote,thisnote,gpsize,dz))<0)
-                        return(exit_status);
-                }
-                thisnote->next = nextnote;
-                if(nextnote!=(noteptr)0)
-                    nextnote->last = thisnote;
-                if(texflag & IS_ORN_OR_DEC)
-                    tsetnote = nextevent;
-
-            } else if(texflag & IS_ORN_OR_DEC)
-                tsetnote = getnextevent_to_decorate(tsetnote,&shadindex,dz);
-
-        } else 
-            tsetnote = tsetnote->next;
-
-        if(texflag & IS_MTF_OR_GRP) {
-            tsetnote = nextnote;
-            shadindex++;
-        }
-    }
-    if((texflag & IS_DECOR) && dz->vflag[DISCARD_ORIGLINE]) {
-        if((exit_status = erase_shadow(shadowsize,shadow,tset))<0)
-            return(exit_status);
-    }
-    if(texflag & IS_CLUMPED)
-        return arrange_notes_in_timeorder(tset);
-    return(FINISHED);
-}
-
-/**************************** SETUP_MOTIF_PARAMS ****************************/
-
-int setup_motif_params
-(noteptr phrasenote,double tsettime,double *thisamp,double ampstep,double *phraseamp, int phrno,
-double rangemult,noteptr thisnote,noteptr tsetnote,double multiplier,double timeadjust,dataptr dz)
-{
-    double notetime, ampdif;
-    notetime = getnotetime(phrasenote,tsettime,multiplier,timeadjust,dz);
-    *thisamp  += ampstep;
-    ampdif    =(phraseamp[phrno] - phrasenote->amp)*rangemult;/* e */
-    return do_mtf_params(thisnote,*thisamp,phrasenote,tsetnote,ampdif,notetime,multiplier,dz);
-}
-
-/**************************** GEN_ORN_PITCH ****************************/
-
-void gen_orn_pitch
-(noteptr thisnote,noteptr tsetnote,noteptr phrasenote,float phrlpitch,float phrfirstpitch,dataptr dz)
-{
-    if(dz->vflag[IS_PRE])   
-        thisnote->pitch = (float)(tsetnote->pitch + phrasenote->pitch - phrlpitch);
-    else 
-        thisnote->pitch = (float)(tsetnote->pitch + phrasenote->pitch - phrfirstpitch);
-}
-
-/**************************** GEN_MTF_PITCH ****************************/
-
-void gen_mtf_pitch(noteptr thisnote,noteptr tsetnote,noteptr phrasenote,float phrfirstpitch)
-{
-    thisnote->pitch = (float)(tsetnote->pitch + phrasenote->pitch - phrfirstpitch);
-    thisnote->pitch = (float)octadjust((double)thisnote->pitch);
-}
-
-/************************* DEC_CENTRE ******************************
- *
- * Centre a decoration on the decorated pitch.
- *
- * (1)  For groupsize 1 or 2, k=1
- *      For groupsize 3 or 4, k=2
- *      For groupsize 5 or 6, k=3 etc
- * (2)  Scatter pitches as normally.
- * (3)  If range is NOT one-sided, proceed..otherwise return in normal way.
- * (4)  Find ratio of upper half of range to lower. 
- * (5)  Find distance from decorated note.
- * (6)  Save the current value of allowed repetitions.
- *      THese are number of times a note occurs above the decorated pitch,
- *      before it can do so again (same for below).
- * (7)  If the allowed repetitions are bigger than k, replace it by k.
- *      This means that if we allow 3 repetitions but there are only
- *      1,2,3 or 4 notes, we force, 1 repetition for 2 notes, 2 repetitions
- *      for 3 or 4 notes etc. but allow 3 repetitions for 5,6 etc notes.
- * (8)  Select above or below decorated pitch.
- * (9)  If meant to be above note, but is below it, put note in other
- *      half of range, with appropriate adjustment for relative sizes
- *      of half-ranges.
- * (10) If meant to be below note, but is above it, put note in other
- *      half of range, with appropriate adjustment for relative sizes
- *      of half-ranges.
- * (11) Restore the repetcnt value!!
- */
- 
-int dec_centre(double tsetpitch,float *val,int gpsize,double gprlow,double gprange,dataptr dz)
-{
-    int exit_status;
-    double a, q, w, gprhi = gprlow + gprange, ulratio;
-    int s, save, k = (gpsize+1)/2;                              /* 1 */
-    if((exit_status = pscat(gprange,gprlow,PM_GPPICH,&a,dz))<0) /* 2 */
-        return(exit_status);
-    if((w=tsetpitch-gprlow)>FLTERR && !flteq(tsetpitch,gprhi)) {/* 3 */
-        ulratio = (gprhi-tsetpitch)/w;                          /* 4 */
-        q       = a-tsetpitch;                                  /* 5 */
-        save    = dz->iparray[TXREPETCNT][PM_DECABV];           /* 6 */
-        if(dz->iparray[TXREPETCNT][PM_DECABV]>k)                /* 7 */
-            dz->iparray[TXREPETCNT][PM_DECABV] = k;         
-        if((exit_status = doperm((int)2,PM_DECABV,&s,dz))<0)            /* 8 */
-            return(exit_status);
-        if(s && q<0.0)                                          /* 9 */
-            a = tsetpitch - (q*ulratio);
-        if(!s && q>0.0)                                         /* 10 */
-            a = tsetpitch - (q/ulratio);
-        dz->iparray[TXREPETCNT][PM_DECABV] = save;              /* 11 */
-        if(a<MIDIBOT || a>MIDITOP) {
-            sprintf(errstr,"TEXTURE: Problem in dec_centre()\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    *val = (float)a;
-    return(FINISHED);
-}
-
-/***************************** PSCAT ************************************
- *
- * A weighted version of pscatx().
- *
- * Select a random value within 'range', by permuting one of BANDCNT UNequal
- * ranges, and selecting a random value within the chosen range. The upper
- * and lower band are half as wide as the inner 3 bands, ensuring that
- * values within these outer bands are squeezed into a narrow-range-of-values
- * near the boundaries of the total range.
- */
-
-int pscat(double range,double bottom,int pindex,double *val,dataptr dz)
-{
-    int exit_status;
-    double bandbottom, bandwidth, x;
-    int k;
-    if((exit_status = doperm((int)BANDCNT,pindex,&k,dz))<0)
-        return(exit_status);
-    bandwidth = range/(double)LAYERCNT;
-    switch(k) {
-    case(0):
-        bandbottom = 0.0;
-        break;
-    case(BANDCNT-1):
-        bandbottom = (LAYERCNT-1) * bandwidth;
-        break;
-    default:
-        bandbottom = bandwidth + ((double)((k-1) * 2) * bandwidth);
-        bandwidth *= 2.0;
-        break;
-    }
-    x  = (drand48() * bandwidth);
-    x += bandbottom;
-    *val = x + bottom;
-    return(FINISHED);
-}
-
-/**************************** INITIALISE_PHRASES *******************************/
-
-int initialise_phrases(int **phrnotecnt,double **phraseamp,double **phrange,noteptr **phrlastnote,dataptr dz)
-{
-    if((*phrnotecnt = (int *)malloc(dz->tex->phrasecnt * sizeof(int)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for phrase notecnt array.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*phraseamp = (double *)malloc(dz->tex->phrasecnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for phrase amplitude array.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*phrange = (double *)malloc(dz->tex->phrasecnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for phrase range array.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*phrlastnote = (noteptr *)malloc(dz->tex->phrasecnt * sizeof(noteptr)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for phrase lastnote array.\n");
-        return(MEMORY_ERROR);
-    }
-    return(FINISHED);
-}
-
-/********************** DO_EV_PCH *******************************
- *
- * Set pitch of event (not group etc.).
- */
-
-int do_ev_pch
-(double *thispitch,double thistime,double *pptop,double *ppbot,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getvalue(TEXTURE_MAXPICH,TEXTURE_MINPICH,thistime,PM_PITCH,thispitch,dz))<0)
-        return(exit_status);
-    if(*thispitch > MIDITOP || *thispitch < MIDIBOT) {
-        sprintf(errstr,"TEXTURE: pitch [%.1f] out of midirange at time %.2f\n",*thispitch,thistime); 
-        return(DATA_ERROR);
-    }
-    *pptop = dz->param[TEXTURE_MAXPICH];
-    *ppbot = dz->param[TEXTURE_MINPICH];
-    return(FINISHED);
-}
-
-/************************** GET_GPPARMAS **************************
- *
- * Get the parameters for a group of notes.
- *
- * (1)  Get gprange in normal way.
- * (2)  Don't adjust range.
- * (3)  For decorations, the range may be oriented, above, below
- *      or centred on the initial note. So range is adjusted here.
- */
-                                                                                           
-int get_gpparams(double thistime,double thispitch,unsigned char dectypecnt,
-double *gprange,double *gprlow,int *gpsize,double *gpdense,double pptop,double ppbot,
-unsigned char dectypestor,int mingrpsize,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getvalue(TEX_GPRANGHI,TEX_GPRANGLO,thistime,PM_GPRANG,gprange,dz))<0)
-        return(exit_status);                                                /* 1 */
-    if(!dectypecnt)
-        squeezrange(thispitch,gprange,gprlow,pptop,ppbot);
-    else {
-        if((exit_status = orientrange
-        (thispitch,pptop,ppbot,gprange,gprlow,dectypestor,dectypecnt,dz))<0)/* 3 */
-            return(exit_status);
-    }
-    if((exit_status = igetvalue(TEX_GPSIZEHI,TEX_GPSIZELO,thistime,PM_GPSIZE,gpsize,dz))<0)
-        return(PROGRAM_ERROR);
-
-    if(*gpsize < mingrpsize) {
-        sprintf(errstr,"Impossible GROUP SIZE value [%d]\n",*gpsize);
-        return(PROGRAM_ERROR);
-    }
-    return get_density_val(thistime,gpdense,dz);
-}
-
-/***************************  ORIENTRANGE ******************************
- *
- */
-
-int orientrange
-(double thispitch,double pptop, double ppbot,double *gprange, double *gprlow,
-unsigned char dectypestor,unsigned char dectypecnt,dataptr dz)
-{
-    int exit_status;
-    unsigned char dectype;
-    double top;
-    int k;
-    if((exit_status = doperm((int)dectypecnt,PM_ORIENT,&k,dz))<0)
-        return(exit_status);
-    if((exit_status = gettritype(k,dectypestor,&dectype))<0)
-        return(exit_status);
-    switch(dectype) {
-    case(0):            /* centred range */
-        squeezrange(thispitch,gprange,gprlow,pptop,ppbot);
-        dz->vflag[DECCENTRE] = TRUE;
-        break;
-    case(1):            /* range above note */
-        top      = min((thispitch + *gprange),pptop);
-        *gprlow  = max((top - *gprange),ppbot);
-        *gprange = top - *gprlow;
-        dz->vflag[DECCENTRE] = FALSE;
-        break;              
-    case(2):            /* range below note */
-        top      = thispitch;
-        *gprlow  = max((top - *gprange),ppbot);
-        *gprange = top - *gprlow;
-        dz->vflag[DECCENTRE] = FALSE;
-        break;              
-    default:
-        sprintf(errstr,"TEXTURE: Problem in orientrange()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/***************************  SQUEEZRANGE ******************************
- *
- * Adjust range to lie within texture limits.
- *
- * (2)  Top of range is at current pitch plus half range. If this is
- *  above current top-of-texture range (pptop) move top down.
- * (3)  Bottom of range is gprange below top. If this is below
- *  bottom-of-texture range (ppbot), move gprangelo up.
- * (4)  Recalculate the true gprange within true limits.
- */
-
-void squeezrange(double thispitch,double *gprange,double *gprlow, double pptop, double ppbot)
-{
-    double top;
-    top     = min((thispitch + (*gprange/2.0)),pptop);      /* 2 */
-    *gprlow  = max((top-*gprange),ppbot);                   /* 3 */
-    *gprange = top - *gprlow;                               /* 4 */
-}

+ 0 - 2360
dev/texture/v8/texture3.c

@@ -1,2360 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
- 
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- 
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
- 
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-/* floatsam version: no changes */
-#include <stdio.h>
-#include <stdlib.h>
-#include <float.h>
-#include <structures.h>
-#include <tkglobals.h>
-#include <globcon.h>
-#include <processno.h>
-#include <modeno.h>
-#include <arrays.h>
-#include <texture.h>
-#include <cdpmain.h>
-
-#include <sfsys.h>
-#include <osbind.h>
-
-#if defined unix || defined __GNUC__
-#define round(x) lround((x))
-#endif
-
-#define CHARBITSIZE (8)     /* number of bits in a char          */
-
-struct ffit {               /* Structure for FIT of motif to HS  */
-    float transpose;
-    float fit;
-    struct ffit *next;
-    struct ffit *last;
-};
-
-typedef struct ffit *fitptr;
-
-/* RWD Feb 2014: now in sfsys,h, differently! */
-#ifdef MAXINT
-# undef MAXINT
-#endif
-#define MAXINT (2147483647)
-/***************************** GENERATING TEXTURES WITH HFIELD(S) ******************************/
-
-
-static int set_hfmotifs(double *hs,motifptr *phrase,int *phrnotecnt,double *phraseamp,
-            double *phrange, noteptr *phrlastnote,int *endhsindex,int **hfphrase,
-            int hsnotecnt,fitptr fithead,double **notestor,dataptr dz);
-static int gethfphrase
-            (double *hs,double **notestor,int z,double lopitch,double hipitch,int **hfphrase,
-            int hsnotecnt,int *phrnotecnt,motifptr *phrase,fitptr fithead);
-static int shrink_to_hs
-            (int z,int hsnotecnt,double hipitch,double lopitch,double hstop,double hsbot,
-            double *hs, int *hfphrase,motifptr *phrase,int *phrnotecnt);
-static int findhfphrase
-            (int z,double *hs,double hstop,int hsnotecnt,double lopitch,
-            double origlo,motifptr *phrase,int **hfphrase,int *phrnotecnt,fitptr fithead,double **notestor);
-static int getmtfindeces
-            (double transpose,int z,int hsnotecnt,double *hs,motifptr *phrase,int *phrnotecnt,int **hfphrase);
-static int get_fit(double *notestor,fitptr thisfit,double lopitch,double origlo,int z,
-            int hsnotecnt,int *phrnotecnt,double *hs,fitptr *newfit);
-static int put_fit(fitptr thisfit,double transval,double fitval,fitptr *newfit);
-static int best_fit(fitptr fithead,double *transpose);
-static void free_fitlist(fitptr fithead);
-static double hfadjust(double thispitch,double *hs,int x1,int x2,int texflag,int hsnotecnt);
-static int convert_pitch_to_nearest_hset_pitch(double thispitch,double *hs,int hsnotecnt);
-static int hfadj2(int hsi,int hfnotecnt,int hsnotecnt);
-static int setup_hfield(noteptr thisnote,double **hs,int *hsnotecnt,double **hf,int *hfnotecnt,int texflag);
-static int get_next_hfield
-            (double **hf,double **hs,double inputtime,int *hf_cnt,int *hs_cnt,int *hfnotecnt,
-            noteptr *thishfnote,double *thishftime,double *nexthftime,int hfdatacnt,int *hsnotecnt,
-            noteptr *thishsnote,double *thishstime,double *nexthstime,double *hft,int texflag);
-static int setup_motif_note
-            (double thisamp,int thisinstr,double thisdur,noteptr tsetnote,noteptr phrasenote,
-            double *thispitch,double thistime,int *hsindex,int hsnotecnt,double *hs,
-            double *pptop,double *ppbot,int *shadindex,char *shadbits,double multiplier,dataptr dz);
-static int setup_group_note
-            (double thisamp,int thisinstr,double thisdur,noteptr tsetnote,
-            double *thispitch,double thistime,int *hsindex,int hsnotecnt,double *hs,
-            double *pptop,double *ppbot,int *shadindex,char *shadbits,dataptr dz);
-static int setup_ornamentation
-            (int *starthsi,int *endhsi,noteptr *nextevent,noteptr tsetnote,noteptr *phrasenote,
-            int *shadindex, int *endhsindex,int *hfphrase,int phrno,dataptr dz);
-static int generate_motifin_note_pitch
-            (int n,int hsindex,int starthsindex,int hsnotecnt,double thispitch,
-            int *hfphrase,noteptr *thisnote,double *hs,int texflag);
-static int generate_motif_note_pitch
-            (noteptr tsetnote,noteptr phrasenote,double phrfirstnote,noteptr thisnote);
-static int generate_ornament_note_pitch
-            (int n,double *hs, int hsi, int endhsi,int starthsi,noteptr *thisnote,noteptr *phrasenote,
-            int *hfphrase,int hfnotecnt,int hsnotecnt,dataptr dz);
-static int do_ev_hfpch
-            (double thistime,int *hsindex,double *val,
-            int hsnotecnt,double *hs,double *pptop,double *ppbot,dataptr dz);
-static int getp_as_index
-            (double thistime,int *val,int hsnotecnt,double *hs,double *pptop,double *ppbot,dataptr dz);
-static int init_shadbits(int shadowsize,int *shshsize,char **shadbits);
-static int geths(noteptr thisnote,double **hs,int *hsnotecnt);
-static int gethf(noteptr thisnote,double **hf,int *hfnotecnt);
-static int gen_hs(double **hf,double **hs, int *hsnotecnt, int hfnotecnt);
-static int chekrepeat(noteptr thisnote,double lastpitch);
-static void set_shadbit(int k,char *shadbits);
-static int  geths_lobnd(double thispitch,double *hs,int hsnotecnt);
-static int  gethfnote(double thispitch,double *hf,int *hfnotecnt);
-static int  setmtfparams
-            (noteptr thisnote,double thisamp,noteptr phrasenote,noteptr tsetnote,double ampdif,
-            double notetime,int gpsize,double multiplier,dataptr dz);
-static int  initialise_hfphrases
-            (int ***hfphrase,int **endhsindex,int **phrnotecnt,double **phraseamp,double **phrange,
-            noteptr **phrlastnote,dataptr dz);
-static int  readhftimes(noteptr firstnote, int *hfdatacnt,double **hft);
-static int  init_fits(fitptr *thisfit);
-static int  get_hfgpparams(double thistime,double thispitch,double *hs,int hsnotecnt,
-        int *gpsize,int *hfrange,int *hfgpranglo,int *hfgpranghi,
-        double *gprange,double *gpdense,int mingrpsize,
-        double *gprlow, int dectypecnt,unsigned char dectypestor,dataptr dz);
-static int  generate_group_note(noteptr thisnote,noteptr testnote,double thistime,
-        int hfrange,int hfgpranglo,double *hs,int *hsindex,int gpsize,dataptr dz);
-static int  generate_decor_note(noteptr thisnote,noteptr tsetnote,
-        double thispitch,double thistime,int hfrange,int hfgpranghi,int hfgpranglo,
-        double *hs,int *hsindex,int hsnotecnt,double gprlow,double gprange,int gpsize,dataptr dz);
-static void del_ghosts(int shshsize,char *shadbits,noteptr *shadow,int shadowsize,motifptr tset);
-static int  geths_hibnd(double thispitch,int hsnotecnt,double *hs);
-static int  geths_above(double thispitch,double *hs,int hsnotecnt);
-static int  fit_unlink(fitptr thisfit);
-static int  new_fit(fitptr thisfit,fitptr *newfit);
-static int  getnexths(double **hs,double inputtime,int *hs_cnt,int *hsnotecnt,noteptr *thishsnote,
-        double *thishstime,double *nexthstime,int hfdatacnt,double *hft);
-static int  getnexthf(double **hf,double **hs, int *hsnotecnt,double inputtime,int *hf_cnt,
-        int *hfnotecnt,noteptr *thishfnote,double *thishftime,double *nexthftime,int hfdatacnt,double *hft);
-static int  hfscat(int prange,int pbottom,int permindex,int *val,dataptr dz);
-static int  gethsnote(double thispitch,double *thishs,int *hsnotecnt);
-static void hfsqueezrange
-        (double thispitch,int *hfrange,int *hfgpranghi,int *hfgpranglo,int hsnotecnt,double *hs);
-static int  hforientrange(double thispitch,int *hfrange,int *hfgpranghi,int *hfgpranglo,
-        int hsnotecnt,double *hs,int dectypecnt,unsigned char dectypestor,dataptr dz);
-static int  dec_hfcentre(double tsetpitch,double *hs,int hsnotecnt,
-        int hfrange,int hfgpranghi,int hfgpranglo,double gprlow,double gprange,int gpsize,
-        double *val,dataptr dz);
-static int  hfscatx(int prange,int pbottom,int permindex,int *val,dataptr dz);
-static int  get_first_hs(noteptr thisnote,double **hs,int *hsnotecnt);
-static int  get_first_hf(noteptr thisnote,double **hf,int *hfnotecnt);
-static int  setup_first_hfield
-        (noteptr thisnote,double **hs,int *hsnotecnt,double **hf,int *hfnotecnt,int texflag);
-static int octeq(double a,double b);
-
-/**************************** DO_SIMPLE_HFTEXTURE ****************************/
-
-int do_simple_hftexture(dataptr dz)
-{
-    int exit_status;
-    unsigned int texflag     = dz->tex->txflag;
-    motifptr tset             = dz->tex->timeset;
-    motifptr hfmotif          = dz->tex->hfldmotif;
-    int hsindex;
-    noteptr tsetnote = tset->firstnote;
-    noteptr nextnote;
-    double thistime, thispitch, lastpitch = -1.0;
-    noteptr thishfnote = hfmotif->firstnote;
-    noteptr thishsnote = hfmotif->firstnote;
-    double thishftime,nexthftime,thishstime,nexthstime,thisamp,thisdur;
-    unsigned char thisinstr;
-    int hf_cnt = 1, hfnotecnt = 0;
-    int hs_cnt = 1, hsnotecnt = 0, repeated = 0;
-    int hfdatacnt = 0;
-    double *hft, pptop, ppbot;
-    double *hs = (double *)0, *hf = (double *)0;
-    dz->iparam[SPINIT] = 0;
-
-    if((exit_status = readhftimes(hfmotif->firstnote,&hfdatacnt,&hft))<0)
-        return(exit_status);
-    thishftime = nexthftime = thishstime = nexthstime = hft[0];
-
-    if(texflag & ISMANY_HFLDS) {
-        if((exit_status = setup_first_hfield(hfmotif->firstnote,&hs,&hsnotecnt,&hf,&hfnotecnt,texflag))<0)
-            return(exit_status);
-    } else {
-        if((exit_status = setup_hfield(hfmotif->firstnote,&hs,&hsnotecnt,&hf,&hfnotecnt,texflag))<0)
-            return(exit_status);
-    }
-    while(tsetnote!=(noteptr)0) {                   /* 3 */
-        repeated  =  chekrepeat(tsetnote,lastpitch);
-        lastpitch = tsetnote->pitch;                                                    
-        thistime  = (double)tsetnote->ntime;        /* 5 */
-        if((exit_status = read_values_from_all_existing_brktables(thistime,dz))<0)
-            return(exit_status);
-        if(texflag & ISMANY_HFLDS) {
-            if((exit_status = get_next_hfield(&hf,&hs,thistime,&hf_cnt,&hs_cnt,
-            &hfnotecnt,&thishfnote,&thishftime,&nexthftime,hfdatacnt,
-            &hsnotecnt,&thishsnote,&thishstime,&nexthstime,hft,texflag))<0)
-                return(exit_status);
-        }
-        if((exit_status = do_amp_instr_dur(&thisamp,&thisinstr,&thisdur,tsetnote,thistime,dz))<0)
-            return(exit_status);
-        if((exit_status = do_ev_hfpch(thistime,&hsindex,&thispitch,hsnotecnt,hs,&pptop,&ppbot,dz))<0)
-            return(exit_status);
-        tsetnote->pitch = (float)thispitch;
-        if(exit_status == CONTINUE) {
-            nextnote = tsetnote->next;
-            del_note(tsetnote,tset);
-            tsetnote = nextnote;
-        } else
-            tsetnote = tsetnote->next;
-    }
-    if(tset->firstnote==(noteptr)0) {
-        sprintf(errstr,"The harmonic set specified does not tally with the range.\n");
-        return(DATA_ERROR);
-    }
-    return(FINISHED);
-}
-
-/**************************** DO_CLUMPED_HFTEXTURE ****************************/
-
-int do_clumped_hftexture(dataptr dz)
-{
-    int exit_status;
-    unsigned int texflag     = dz->tex->txflag;
-    unsigned char dectypestor = dz->tex->dectypstor;
-    unsigned char dectypecnt  = dz->tex->dectypcnt;
-    unsigned char amptypestor = dz->tex->amptypstor;
-    unsigned char amptypecnt  = dz->tex->amptypcnt;
-    int ampdirected           = dz->tex->ampdirectd;
-    motifptr tset             = dz->tex->timeset;
-    motifptr hfmotif          = dz->tex->hfldmotif;
-    motifptr *phrase          = dz->tex->phrase;
-    int **hfphrase = NULL;
-    int *endhsindex=NULL, *phrnotecnt=NULL;
-    double *phraseamp=NULL, *phrange=NULL;
-    unsigned char amptype = 0;
-    fitptr fithead = NULL;
-    noteptr tsetnote = tset->firstnote;
-    noteptr thisnote=NULL, nextnote=NULL, phrasenote=NULL, nextevent=NULL, *shadow=NULL;
-    double thispitch = 0.0, lastpitch = -1.0, ampstep = 0.0, ampdif = 0.0, notetime = 0.0, thisamp = 0.0, thisdur = 0.0;
-    unsigned char thisinstr;
-    double phrfirstnote = 0.0, thistime = 0.0, rangemult = 0.0, gprlow = 0.0;
-    double timeadjust = 0.0; /* default */
-    noteptr thishfnote = hfmotif->firstnote;
-    noteptr thishsnote = hfmotif->firstnote;
-    noteptr *phrlastnote = NULL;
-    double thishftime = 0.0,nexthftime = 0.0,thishstime = 0.0,nexthstime = 0.0,tsettime = 0.0;
-    int hf_cnt = 1, hfnotecnt = 0, mingrpsize = 0, shadindex = 0, shadowsize=0;
-    double gprange = 0.0,gpdense = 0.0,multiplier = 0.0;
-    double *notestor=NULL;
-    int hfgpranglo=0,hfgpranghi=0;
-    int hs_cnt = 1, hsnotecnt = 0, repeated = 0;
-    int hfdatacnt = 0, hfrange = 0, gpsize,shshsize = 0;
-    int phrno = 0, n=0,  hsindex=0, starthsindex=0, hfchanged=0;
-    int hsi=0, starthsi = 0, endhsi=0;
-    char *shadbits = NULL;
-    double *hft=NULL, pptop=0.0, ppbot=0.0;
-    double *hs = (double *)0, *hf = (double *)0;
-
-    if((dz->tex->phrasecnt > 0) && (exit_status = initialise_hfphrases
-    (&hfphrase,&endhsindex,&phrnotecnt,&phraseamp,&phrange,&phrlastnote,dz))<0)
-        return(exit_status);
-    dz->iparam[SPINIT] = 0;
-    if(texflag & IS_GROUPS)
-        mingrpsize = 1;
-
-    if((exit_status = readhftimes(hfmotif->firstnote,&hfdatacnt,&hft))<0)
-        return(exit_status);
-    thishftime = nexthftime = thishstime = nexthstime = hft[0];
-
-    if((exit_status = make_shadow(tset,&shadowsize,&shadow))<0)
-            return(exit_status);
-
-    if((texflag & MOTIF_IN_HF) || (texflag & IS_ORNATE)) {
-        if((exit_status = init_fits(&fithead))<0)
-            return(exit_status);
-    }
-    if(texflag & IS_DECOR)
-        setup_decor(&pptop,&ppbot,&shadindex,&tsetnote,dz);
-    else {
-        if((exit_status = init_shadbits(shadowsize,&shshsize,&shadbits))<0)
-            return(exit_status);
-    }
-    if(texflag & ISMANY_HFLDS) {
-        if((exit_status = setup_first_hfield(hfmotif->firstnote,&hs,&hsnotecnt,&hf,&hfnotecnt,texflag))<0)
-            return(exit_status);
-    } else {
-        if((exit_status = setup_hfield(hfmotif->firstnote,&hs,&hsnotecnt,&hf,&hfnotecnt,texflag))<0)
-            return(exit_status);
-    }
-    if((texflag & MOTIF_IN_HF) || ((texflag & IS_ORNATE) && !(texflag & ISMANY_HFLDS))) {
-        if((exit_status = set_hfmotifs
-        (hs,phrase,phrnotecnt,phraseamp,phrange,phrlastnote,endhsindex,hfphrase,hsnotecnt,fithead,&notestor,dz))<0)
-            return(exit_status);
-    } else if(texflag & IS_MOTIFS) {
-        if((exit_status = set_motifs
-        (dz->tex->phrasecnt,phrase,phrnotecnt,phraseamp,phrange,phrlastnote))<0)
-            return(exit_status);
-    }
-    while(tsetnote!=(noteptr)0) {
-        if(!(texflag & IS_ORNATE)) {
-            repeated =  chekrepeat(tsetnote,lastpitch);
-            lastpitch = tsetnote->pitch;
-        }
-        tsettime = thistime = (double)tsetnote->ntime;
-        if((exit_status = read_values_from_all_existing_brktables(thistime,dz))<0)
-            return(exit_status);
-        if(texflag & ISMANY_HFLDS) {
-            if((exit_status = get_next_hfield(&hf,&hs,thistime,&hf_cnt,&hs_cnt,
-            &hfnotecnt,&thishfnote,&thishftime,&nexthftime,hfdatacnt,
-            &hsnotecnt,&thishsnote,&thishstime,&nexthstime,hft,texflag))<0)
-                return(exit_status);
-            hfchanged = exit_status;
-            if(((texflag & MOTIF_IN_HF) || (texflag & IS_ORNATE)) && hfchanged) {
-                if((exit_status = set_hfmotifs
-                (hs,phrase,phrnotecnt,phraseamp,phrange,phrlastnote,endhsindex,hfphrase,hsnotecnt,fithead,&notestor,dz))<0)
-                    return(exit_status);
-            }                                                      
-        }
-        if(texflag & IS_ORN_OR_MTF) {
-            if((exit_status = setup_motif_or_ornament(thistime,&multiplier,&phrno,&phrasenote,phrase,dz))<0)
-                return(exit_status);
-        }
-        if((exit_status = do_amp_instr_dur(&thisamp,&thisinstr,&thisdur,tsetnote,thistime,dz))<0)
-            return(exit_status);
-        if(texflag & IS_DECOR)        
-            thispitch = tsetnote->pitch;
-        if(texflag & IS_MTF_OR_GRP) {
-            if(texflag & IS_GROUPS)
-                exit_status = setup_group_note
-                (thisamp,thisinstr,thisdur,tsetnote,&thispitch,
-                thistime,&hsindex,hsnotecnt,hs,&pptop,&ppbot,&shadindex,shadbits,dz);
-            else
-                exit_status = setup_motif_note
-                (thisamp,thisinstr,thisdur,tsetnote,phrasenote,&thispitch,
-                thistime,&hsindex,hsnotecnt,hs,&pptop,&ppbot,&shadindex,shadbits,multiplier,dz);
-            if(exit_status==CONTINUE)
-                continue;
-        }
-        if(texflag & IS_ORN_OR_MTF)
-            gpsize = phrnotecnt[phrno];
-        else {
-            if((exit_status = get_hfgpparams
-            (thistime,thispitch,hs,hsnotecnt,&gpsize,&hfrange,&hfgpranglo,&hfgpranghi,
-            &gprange,&gpdense,mingrpsize,&gprlow,dectypecnt,dectypestor,dz))<0)
-                return(exit_status);
-        }
-        if(texflag & IS_DECOR) {
-            if((exit_status = position_and_size_decoration(&thistime,tsettime,gpdense,&gpsize,dz))<0)
-                return(exit_status);
-        } else
-            gpsize--;
-        if(texflag & IS_MOTIFS)
-            phrfirstnote = phrasenote->pitch;
-        else if(texflag & IS_ORNATE) {
-            if((hsi = convert_pitch_to_nearest_hset_pitch((double)tsetnote->pitch,hs,hsnotecnt))<0)
-                gpsize = 0;         /* note out of bounds, ornament omitted  */
-            if((exit_status = setup_ornament
-            (&timeadjust,&thistime,&gpsize,phrlastnote,multiplier,&phrasenote,phrno,dz))<0)
-                return(exit_status);
-        }
-        if(!(texflag & IS_DECOR))
-            nextnote  = tsetnote->next;
-        if(gpsize>0) {
-            if(texflag & IS_ORN_OR_MTF) {
-                if((exit_status = orn_or_mtf_amp_setup
-                (ampdirected,phrange,phrno,thisamp,gpsize,&rangemult,&ampstep,&amptype,amptypestor,amptypecnt,dz))<0)
-                    return(exit_status);
-            }
-            if(texflag & IS_MOTIFS) {
-                if((exit_status = set_motif_amp
-                (tsetnote,&thisamp,gpsize,ampstep,phrasenote,rangemult,phraseamp,phrno,amptype))<0)
-                    return(exit_status);
-            } else if(texflag & IS_ORNATE) {
-                if((exit_status = set_ornament_amp
-                (phraseamp,phrlastnote,&thisamp,phrasenote,phrno,tsetnote,ampstep,rangemult,gpsize,dz))<0)
-                    return(exit_status);
-            } else if (texflag & IS_GROUPS) {
-                if((exit_status = set_group_amp
-                (tsetnote,&thisamp,&amptype,&ampstep,gpsize,amptypecnt,amptypestor,dz))<0)
-                    return(exit_status);
-            } else if (texflag & IS_DECOR) {
-                if((exit_status = set_decor_amp
-                (ampdirected,&thisamp,&ampstep,gpsize,&amptype,amptypecnt,amptypestor,dz))<0)
-                    return(exit_status);
-            }
-            if(dz->iparam[TEX_GPSPACE]!=IS_STILL) {
-                if((exit_status = init_group_spatialisation(tsetnote,shadindex,shadow,shadowsize,dz))<0)
-                    return(exit_status);
-            }
-            thisnote  = tsetnote;
-            if(texflag & MOTIF_IN_HF)
-                starthsindex =  *(hfphrase[phrno]);
-            else if(texflag & IS_ORNATE) {
-                if((exit_status = setup_ornamentation
-                (&starthsi,&endhsi,&nextevent,tsetnote,&phrasenote,&shadindex,endhsindex,hfphrase[phrno],phrno,dz))<0)
-                    return(exit_status);
-            } else if(texflag & IS_DECOR) {
-                nextnote = tsetnote->next;
-                nextevent = getnextevent_to_decorate(tsetnote,&shadindex,dz);
-            }
-            for(n=0;n<gpsize;n++) {
-                if((exit_status = make_new_note(&thisnote))<0)
-                    return(exit_status);
-                if(texflag & IS_ORN_OR_MTF) {
-                    if((exit_status = check_next_phrasenote_exists(&phrasenote,texflag,dz))<0)
-                        return(exit_status);
-                    notetime = getnotetime(phrasenote,thistime,multiplier,timeadjust,dz);
-                    thisamp += ampstep;
-                    ampdif   = (phraseamp[phrno]-phrasenote->amp)*rangemult;
-                    if((exit_status = setmtfparams
-                    (thisnote,thisamp,phrasenote,tsetnote,ampdif,notetime,gpsize,multiplier,dz))<0)
-                        return(exit_status);
-                } else  {
-                    if((exit_status = set_group_params
-                    (tsetnote,thisnote,gpdense,ampstep,&thisamp,&thistime,thisdur,dz))<0)
-                        return(exit_status);
-                }
-                if(texflag & MOTIF_IN_HF) {
-                    if((exit_status = generate_motifin_note_pitch
-                    (n,hsindex,starthsindex,hsnotecnt,thispitch,hfphrase[phrno],&thisnote,hs,texflag))<0)
-                        return(exit_status);
-                } else if(texflag & IS_MOTIFS) {
-                    if((exit_status = generate_motif_note_pitch(tsetnote,phrasenote,phrfirstnote,thisnote))<0)
-                        return(exit_status);
-                } else if (texflag & IS_ORNATE) {
-                    if((exit_status = generate_ornament_note_pitch
-                    (n,hs,hsi,endhsi,starthsi,&thisnote,&phrasenote,hfphrase[phrno],hfnotecnt,hsnotecnt,dz))<0)
-                        return(exit_status);
-                } else if(texflag & IS_GROUPS) {
-                    if((exit_status = generate_group_note
-                    (thisnote,tsetnote,thistime,hfrange,hfgpranglo,hs,&hsindex,gpsize,dz))<0)
-                        return(exit_status);
-                } else if(texflag & IS_DECOR) {
-                    if((exit_status = generate_decor_note
-                    (thisnote,tsetnote,thispitch,thistime,hfrange,hfgpranghi,hfgpranglo,
-                    hs,&hsindex,hsnotecnt,gprlow,gprange,gpsize,dz))<0)
-                        return(exit_status);
-                }
-                if(exit_status==CONTINUE)
-                    continue;
-            }
-            thisnote->next = nextnote;
-            if(nextnote!=(noteptr)0)
-                nextnote->last = thisnote;
-            if(texflag & IS_ORN_OR_DEC)
-                tsetnote = nextevent;
-        } else if(texflag & IS_ORN_OR_DEC)
-            tsetnote = getnextevent_to_decorate(tsetnote,&shadindex,dz);
-
-        if(texflag & IS_MTF_OR_GRP) {
-            tsetnote = nextnote;
-            shadindex++;
-        }
-    }
-    if(texflag & IS_MTF_OR_GRP) 
-        del_ghosts(shshsize,shadbits,shadow,shadowsize,tset);       /* 5 */
-
-    if(texflag & IS_DECOR) {
-        if(dz->vflag[DISCARD_ORIGLINE] && (exit_status = erase_shadow(shadowsize,shadow,tset))<0)
-            return(exit_status);
-    } else
-        free(shadbits);
-    if((texflag & MOTIF_IN_HF) || (texflag & IS_ORNATE))
-        free(fithead);
-    return arrange_notes_in_timeorder(tset);
-}
-
-/**************************** SET_HFMOTIFS *******************************
- *
- * initialise all parameters of input motifs to be used for MOTIFS or
- * ORNAMENTS, including their HS indexing!!!
- *
- * (1)For each input motif (called a 'phrase').
- *    phrnotecnt[n] = 0;
- * (2)  Initialise count of number of notes to 0, maximum amplitude
- *  of phrase to 0.0, and lowest pitch-index to hsnotecnt.
- * (3)  Go through each note of the motif.
- * (4)  Add up the number of notes in it.
- * (5)  Find it's lowest pitch.
- * (6)  Find it's loudest note (and set as phraseamp).
- * (7)  Establish dynamic range of phrase.
- * (9)  Ensure motif starts at zero time.
- * (10) Generate the corresponding HS indices, in their lowest configuration.
- * (11) Store hfindex of last note of phrase.
- */
-
-int set_hfmotifs
-(double *hs,motifptr *phrase,int *phrnotecnt,double *phraseamp,double *phrange,noteptr *phrlastnote,
-int *endhsindex,int **hfphrase,int hsnotecnt,fitptr fithead,double **notestor,dataptr dz)
-{
-    int exit_status;
-    int n;
-    double mintime, minamp, minpitch, maxpitch;
-    noteptr thisnote, lastnote = (noteptr)0;
-    for(n=0;n<dz->tex->phrasecnt;n++) {                     /* 1 */
-        if((exit_status = arrange_notes_in_timeorder(phrase[n]))<0)
-            return(exit_status);
-        phrnotecnt[n] = 0;
-        phraseamp[n] = 0.0;                         /* 2 */
-        minamp   = DBL_MAX;
-        minpitch = DBL_MAX;
-        maxpitch = -2.0f;
-        mintime  = DBL_MAX;
-        thisnote = phrase[n]->firstnote;            /* 3 */
-        while(thisnote!=(noteptr)0) {
-            phrnotecnt[n]++;                            /* 4 */
-            if((double)thisnote->pitch<minpitch)
-                minpitch = thisnote->pitch;         /* 5 */
-            if((double)thisnote->pitch>maxpitch)
-                maxpitch = thisnote->pitch;         /* 5 */
-            if(thisnote->ntime<mintime)
-                mintime  = thisnote->ntime;         /* 5 */
-            if((double)thisnote->amp>phraseamp[n])
-                phraseamp[n] = (double)thisnote->amp;/* 6 */
-            if(thisnote->amp<minamp)
-                minamp = thisnote->amp;             /* 6 */
-            thisnote = thisnote->next;
-        }
-        if(minamp   == DBL_MAX
-        || minpitch == DBL_MAX
-        || maxpitch == -2.0f
-        || mintime  == DBL_MAX) {
-            sprintf(errstr,"Error parsing notelist: set_hfmotifs()\n");
-            return(PROGRAM_ERROR);
-        }
-        thisnote = phrase[n]->firstnote;
-        phrange[n] = phraseamp[n] - (double)minamp; /* 7 */
-        while(thisnote!=(noteptr)0) {
-            thisnote->ntime = (float)(thisnote->ntime - mintime);               /* 9 */
-            lastnote = thisnote;
-            thisnote = thisnote->next;
-        }   
-        if((phrlastnote[n] = lastnote)==(noteptr)0) {
-            sprintf(errstr,"Encountered an empty motif: set_hfmotifs()\n");
-            return(PROGRAM_ERROR);
-        }
-        if((exit_status = gethfphrase(hs,notestor,n,minpitch,maxpitch,hfphrase,hsnotecnt,phrnotecnt,phrase,fithead))<0) /* 10 */
-            return(exit_status);
-        endhsindex[n]  = *(hfphrase[n]+phrnotecnt[n]-1);            /* 11 */
-    }
-    return(FINISHED);
-}
-
-/*********************** GETHFPHRASE *********************************
- *
- * Get the hfphrase best corresponding to the input motif.
- *
- * (0)  Create storage space to store HS-indices of phrase.
- * (1)  HIpitch of phrase higher than top of HS
- *  AND LOpitch of phrase lower than bottom of HS.
- *  ..Shrink the motif to size of HS, and establish hfphrase.
- * (2)  HIpitch of phrase higher than top of HS
- *  BUT LOpitch within HS range.
- *  .. transpose phraselimits down onto bottom pitch of HS.
- * (a)  If HIpitch of phrase STILL higher than top of HS
- *  ..Shrink the motif to size of HS, and establish hfphrase.
- * (3)  LOpitch of phrase lower than bottom of HS
- *  BUT HIpitch within HS range.
- *  .. transpose phraselimits up onto bottom pitch of HS.
- * (a)  If HIpitch of phrase is NOW higher than top of HS
- *  ..Shrink the motif to size of HS, and establish hfphrase.
- * (4)  Phrase lies with the limits of HS.
- *  .. transpose phraselimits down onto bottom pitch of HS.
- * (5)  Find appropriate hfphrase.
- */
-
-int gethfphrase
-(double *hs,double **notestor,int z,double lopitch,double hipitch,
-int **hfphrase,int hsnotecnt,int *phrnotecnt,motifptr *phrase,fitptr fithead)
-{
-    double origlo = lopitch, hstop = hs[hsnotecnt-1], hsbot = hs[0];
-    double stepdown, stepup;
-    if((hfphrase[z] = (int *)malloc(phrnotecnt[z] * sizeof(int)))==NULL) {  /* 0 */
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic field phrase array.\n");
-        return(MEMORY_ERROR);
-    }
-    if(hipitch>=hstop) {    
-        if(lopitch<=hsbot)              /* 1 */
-            return shrink_to_hs(z,hsnotecnt,hipitch,lopitch,hstop,hsbot,hs,hfphrase[z],phrase,phrnotecnt);
-        else  {
-            stepdown = lopitch - hsbot;         /* 2 */
-            hipitch -= stepdown;
-            lopitch -= stepdown;
-            if(hipitch>hstop)               /* a */
-                return shrink_to_hs(z,hsnotecnt,hipitch,lopitch,hstop,hsbot,hs,hfphrase[z],phrase,phrnotecnt);
-        }
-    } else {
-        if(lopitch<=hsbot) {                /* 3 */
-            stepup  = hsbot - lopitch;
-            hipitch += stepup;
-            lopitch += stepup;
-            if(hipitch>hstop)               /*a */
-                return shrink_to_hs(z,hsnotecnt,hipitch,lopitch,hstop,hsbot,hs,hfphrase[z],phrase,phrnotecnt); 
-        } else {                    /* 4 */
-            stepdown = lopitch - hsbot;
-            hipitch -= stepdown;
-            lopitch -= stepdown;
-        }
-    }
-    return findhfphrase(z,hs,hstop,hsnotecnt,lopitch,origlo,phrase,hfphrase,phrnotecnt,fithead,notestor);   
-}                                           /* 5 */
-
-
-/************************* SHRINK_TO_HS **************************
- *
- * Shrink motif so it fits with HS, then find best HS fit.
- *
- * (1)  Establish pitch-shrinking ratio.
- * (2)  For every note...
- * (3)  Shrink intervals and thus move pitch to appropriate position inside
- *  range of HS.
- * (4)  Find index of the next lowest HS notes.
- * (4a) If note falls outside field, set distance to note to maximum poss.
- * (4b) Else find pitch distances of this note from original pitch.
- * (5)  Find index of the next highest HS notes.
- * (5a) If note falls outside field, set distance to note to maximum poss.
- * (5b) Else find pitch distances of this note from original pitch.
- * (6)  Select HSindex of nearest pitch and store in hfphrase.
- * (7)  Save the lowest such index.
- * (8)  Transpose all indices down to lowest possible values.
- */
-
-int shrink_to_hs(int z,int hsnotecnt,double hipitch,double lopitch,double hstop,
-                double hsbot,double *hs, int *hfphrase, motifptr *phrase,int *phrnotecnt)
-{
-    noteptr thisnote = phrase[z]->firstnote;
-    double shrink ,thispitch, x, y;
-    int minindex = MAXINT, xx, yy, q, n = 0;
-    shrink = (hstop - hsbot)/(hipitch-lopitch);         /* 1 */
-    for(;;) {                           /* 2 */
-        thispitch = thisnote->pitch;    
-        thispitch = ((thispitch - lopitch) * shrink) + hsbot;   /* 3 */
-        if((xx = geths_lobnd(thispitch,hs,hsnotecnt))<0)            /* 4 */
-            x = DBL_MAX;                        /* 4a */
-        else
-            x = fabs(hs[xx] - thispitch);           /* 4b */
-        if((yy = geths_hibnd(thispitch,hsnotecnt,hs))>=hsnotecnt)       /* 5 */
-            y = DBL_MAX;                        /* 5a */
-        else
-            y = fabs(hs[yy] - thispitch);           /* 5b */
-        if(x<y)
-            q = xx;                     /* 6 */
-        else
-            q = yy;
-        *(hfphrase+n) = q;
-        if(q<minindex)
-            minindex = q;                   /* 7 */
-        if((thisnote = thisnote->next)==(noteptr)0)
-            break;
-        if(++n >= phrnotecnt[z]) {
-            sprintf(errstr,"accounting problem in shrink_to_hs()\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    for(n=0;n<phrnotecnt[z];n++)                    /* 8 */
-        *(hfphrase+n) -= minindex;
-    return(FINISHED);
-}
-
-/*********************** FINDHFPHRASE *********************************
- *
- * Extract the best fit onto the HS, and transpose it down to bottom
- * of indices.
- *
- * (1)  Set the FIT-pointer to head of fits-list.
- * (2)  Set up a store for the note values to be tested.
- * (3)  Get interval of transposition to take motif to bottom of HS range.
- * (4)  Store original note values of phrase transposed down to bottom of HS range.
- * (5)  Find the fit-value for motif in its start position.
- * (6)  Outer loop will transpose the phrase through a range...
- *      (7) Set amount to transpose phrase (shift) to max.
-            Then for every note of the phrase.....
- *          (8) Find the HSindex of the nearest note above the current note.
- *              (If there isn't one break out completely).
- *          (9)  If the difference in pitch between this and the current note
- *              is smaller than the minimum shift, reset minimum shift.
- *          (10)Then, for every note of the phrase...
- *          (11)transpose it up by this minimum transposition.
- *              If this takes any note of the phrase outside the range of HS
- *              break out completely.
- *      (12)Back in outer loop, find the fitting-value for this transposition
- *          of the motif, which is a measure of how far its notes are from
- *          the closest HS values.
- * (13) Outside the outer loop, unlink the last unwanted member iof fitlist.
- * (14) Find the best fitvalue, and return the amount by which orig motif
- *      should be transposed to get onto this best fit.
- * (15) Free the fit-list (retains fithead).
- * (16) Get the appropriate HS indices.
- */
-
-int findhfphrase
-(int z,double *hs,double hstop,int hsnotecnt,double lopitch,double origlo,
-motifptr *phrase,int **hfphrase,int *phrnotecnt,fitptr fithead,double **notestor)
-{
-    int exit_status;
-    int hsindex, OK = 1, n, got_transpose = 0;
-    noteptr thisnote = phrase[z]->firstnote;
-    fitptr thisfit = fithead;                                   /* 1 */
-    double shift, thisshift, transpose = 0.0, stepdown, *noteval;
-    if(*notestor!=NULL)
-        free(*notestor);                                        /* 2 */
-    if((noteval = *notestor = (double *)malloc(phrnotecnt[z] * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for note value array.\n");
-        return(MEMORY_ERROR);
-    }
-    stepdown = origlo - lopitch;                                /* 3 */
-    while(thisnote!=(noteptr)0) {                               
-        *noteval = (double)thisnote->pitch - stepdown;          /* 4 */
-        noteval++;
-        thisnote = thisnote->next;
-    }
-    if((exit_status = get_fit(*notestor,thisfit,lopitch,origlo,z,hsnotecnt,phrnotecnt,hs,&thisfit))<0)
-        return(exit_status);                                    /* 5 */
-    if(exit_status == CONTINUE) {
-        transpose = thisfit->last->transpose;
-        got_transpose = 1;
-        OK  = 0;
-    }
-    while(OK) {                                                 /* 6 */
-        shift = DBL_MAX;                                        /* 7 */
-        noteval = *notestor;
-        for(n=0;n<phrnotecnt[z];n++) {
-            if((hsindex = geths_above(*noteval,hs,hsnotecnt))>=hsnotecnt) { /* 8 */
-                OK = 0;
-                break;
-            }
-            if((thisshift  = hs[hsindex] - *noteval)<shift)
-                shift = thisshift;                              /* 9 */
-            noteval++;
-        }
-        if(shift==DBL_MAX) {
-            sprintf(errstr,"Error parsing phrase: findhfphrase()\n");
-            return(PROGRAM_ERROR);
-        }
-        if(!OK)
-            break;
-        noteval = *notestor;
-        for(n=0;n<phrnotecnt[z];n++) {                          /* 10 */
-            if((*noteval++  += (float)shift)>hstop) {
-                OK = 0;                                         /* 11 */
-                break;
-            }
-        }
-        lopitch += shift;
-        if((exit_status = get_fit(*notestor,thisfit,lopitch,origlo,z,hsnotecnt,phrnotecnt,hs,&thisfit))<0)      
-            return(exit_status);                                /* 12 */
-        if(exit_status == CONTINUE) {
-            transpose = thisfit->last->transpose;
-            got_transpose = 1;
-            break;
-        }
-    }
-    if((exit_status = fit_unlink(thisfit))<0)                   /* 13 */
-        return(exit_status);
-    if (!got_transpose) {
-        if((exit_status = best_fit(fithead,&transpose))<0)      /* 14 */
-            return(exit_status);
-    }
-    free_fitlist(fithead);                                      /* 15 */
-    return getmtfindeces(transpose,z,hsnotecnt,hs,phrase,phrnotecnt,hfphrase);  
-}                                                               /* 16 */
-
-/*************************** GETMTFINDECES *****************************
- *
- * Get the HS indices of the phrase, transposed to lowest position in HS.
- *
- * (0)  Point to start of storage space for the HS-indices of the phrase.
- * (1)  Mark end of this storage space (for accounting purposes).
- * (2)  For every note of the phrase...
- *   (3)  Get the pitch..
- *   (4)  Transpose the pitch by the input transposition.
- *   (5)  Find the nearest HS set members above and below the note.
- *   (6)  Decide which is nearest.
- *   (7)  Assign index of nearest value to the HS-index store.
- *   (8)  Keep a note of the smallest index.
- *   (9)  Increment the index-store pointer.
- * (10) Decrement all the indeces to tranpose them all to lowest values
- *  in the hfphrase store.
- */
-
-int getmtfindeces(double transpose,int z,int hsnotecnt,double *hs,motifptr *phrase,int *phrnotecnt,int **hfphrase)
-{
-    noteptr thisnote = phrase[z]->firstnote;
-    int *thisindex, xx, yy, minindex = MAXINT, *indexend;
-    double x, y, thispitch;
-    thisindex = hfphrase[z];                        /* 0 */
-    indexend  = hfphrase[z] + phrnotecnt[z];        /* 1 */
-    for(;;) {                                       /* 2 */
-        thispitch  = thisnote->pitch;               /* 3 */
-        thispitch += transpose;                     /* 4 */
-        xx = geths_lobnd(thispitch,hs,hsnotecnt);   /* 5 */
-        yy = geths_hibnd(thispitch,hsnotecnt,hs);
-        x = fabs(hs[xx] - thispitch);               /* 6 */
-        y = fabs(hs[yy] - thispitch);
-        if(x<y)
-            *thisindex = xx;                        /* 7 */
-        else
-            *thisindex = yy;
-        if(*thisindex<minindex)
-            minindex = *thisindex;                  /* 8 */
-        if((thisnote = thisnote->next)==(noteptr)0)
-            break;
-        if(++thisindex>=indexend) {                 /* 9 */
-            sprintf(errstr,"TEXTURE: Problem in getmtfindices()\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    for(thisindex = hfphrase[z];thisindex<indexend;thisindex++)
-        *thisindex -= minindex;                     /* 10 */
-    return(FINISHED);
-}
-
-/****************************** GET_FIT ************************************
- *
- * Create list of fit_values for motif over HS.
- * 
- * (1)  For every note of the phrase.
- * (3)  Find the index of the next lowest HS note. If there is not one
- *  something is wrong!
- * (4)  Find the index of the next highest HS note. If there is not one
- *  something is wrong!
- * (5)  Find the pitch distance between these notes on the original pitch.
- * (6)  Add the minimum of these two, to a running sum of such differences.
- * (7)  Store the fit-value and the associated ttansposition, creating a
- *  new storage space in the fit list, in the process.
- */
-
-int get_fit(double *notestor,fitptr thisfit,double lopitch,double origlo,int z,
-            int hsnotecnt,int *phrnotecnt,double *hs,fitptr *newfit)
-{
-    int exit_status;
-    double x, y, sum = 0.0, *noteval = notestor;
-    int xx, yy, n;  
-    for(n=0;n<phrnotecnt[z];n++) {                              /* 1 */
-        if((xx = geths_lobnd(*noteval,hs,hsnotecnt))<0) {       /* 3 */
-            sprintf(errstr,"Problem 1 in get_fit()\n");
-            return(PROGRAM_ERROR);
-        }   
-        if((yy=geths_hibnd(*noteval,hsnotecnt,hs))>=hsnotecnt) {/* 4 */
-            sprintf(errstr,"Problem 2 in get_fit()\n");
-            return(PROGRAM_ERROR);
-        }
-        x = fabs(hs[xx] - *noteval);                            /* 5 */
-        y = fabs(hs[yy] - *noteval);
-        sum += min(x,y);                                        /* 6 */
-        noteval++;
-    }
-    if((exit_status = put_fit(thisfit,lopitch - origlo,sum,newfit))<0)
-        return(exit_status);
-    if(flteq(sum,0.0))
-        return(CONTINUE);
-    return(FINISHED);                                           /* 7 */
-}
-
-/************************* PUT_FIT *****************************
- *
- * Put fit value in motif-fits list.
- */
-
-int put_fit(fitptr thisfit,double transval,double fitval,fitptr *newfit)
-{
-    int exit_status;
-    thisfit->transpose = (float)transval;
-    thisfit->fit       = (float)fitval;
-    if((exit_status = new_fit(thisfit,newfit))<0)
-        return(exit_status);
-    return(FINISHED);
-}
-
-/************************* BEST_FIT *****************************
- *
- * Find the appropriate transposition to move the current motif
- * to a pitch where it has the best fit with the HS.
- *
- * (1)  From all available transpositions, find best (lowest) fit value.
- * (2)  From all available transpositions, find all those which have
- *  this bestfit value, and select the one which involves the
- *  least transposition.
- * (3)  Once the transpositions begin to increase, we are moving away from
- *  the smallest transposition, so quit.
- * (4)  Return the best transposition. 
- */
-
-int best_fit(fitptr fithead,double *transpose)
-{
-    fitptr thisfit = fithead;
-    double bestfit = DBL_MAX, besttranspose = DBL_MAX;
-    double abstranspose = DBL_MAX, thistranspose;
-    while(thisfit!=(fitptr)0) {             /* 1 */
-        if(thisfit->fit<(float)bestfit)
-            bestfit = (double)thisfit->fit;
-        thisfit = thisfit->next;
-    }
-    thisfit = fithead;
-    while(thisfit!=(fitptr)0) {             /* 2 */
-        thistranspose = fabs((double)thisfit->transpose);
-        if(flteq((double)thisfit->fit,bestfit)) {
-            if(thistranspose<abstranspose) {
-                besttranspose = (double)thisfit->transpose;
-                abstranspose = fabs(besttranspose);
-            }
-        }
-        if(thistranspose>abstranspose+FLTERR)
-            break;                  /* 3 */
-        thisfit = thisfit->next;
-    }
-    if(besttranspose==DBL_MAX) {
-        sprintf(errstr,"Problem in best_fit()\n");
-        return(PROGRAM_ERROR);
-    }
-    *transpose = besttranspose;
-    return(FINISHED);               /* 4 */
-}
-
-/************************* INIT_FITS() *****************************
- *
- * Set up head item of a list of motif-fits.
- */
-
-int init_fits(fitptr *thisfit)
-{
-    if((*thisfit = (fitptr)malloc(sizeof (struct ffit)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for fitting array.\n");
-        return(MEMORY_ERROR);
-    }
-    (*thisfit)->next  = (fitptr)0;
-    (*thisfit)->last  = (fitptr)0;
-    return(FINISHED);
-}
-
-/************************* NEW_FIT() *****************************
- *
- * Set up next fit in a list of motif-fits.
- */
-
-int new_fit(fitptr thisfit,fitptr *newfit)
-{
-    if((*newfit = (fitptr)malloc(sizeof (struct ffit)))==NULL) {
-        sprintf(errstr,"new_fit()\n");
-        return(PROGRAM_ERROR);
-    }
-    thisfit->next   = *newfit;
-    (*newfit)->last = thisfit;
-    (*newfit)->next = (fitptr)0;
-    return(FINISHED);
-}
-
-/********************** FIT_UNLINK() ******************************
- *
- * Deletes empty address space at end of fitlist.
- */
-
-int fit_unlink(fitptr thisfit)
-{
-    if(thisfit->last==(fitptr)0) {
-        sprintf(errstr,"Problem in fit_unlink()\n");
-        return(PROGRAM_ERROR);
-    }
-    thisfit = thisfit->last;
-    free(thisfit->next);
-    thisfit->next = (fitptr)0;
-    return(FINISHED);
-}
-
-/********************** FREE_FITLIST() ******************************
- *
- * Deletes fitlist, retaining head.
- */
-
-void free_fitlist(fitptr fithead)
-{
-    fitptr thisfit;
-    if((thisfit = fithead->next)==(fitptr)0)
-        return;
-    while(thisfit->next!=(fitptr)0) {
-        thisfit = thisfit->next;
-        free(thisfit->last);
-    }
-    free(thisfit);
-}
-
-/**************************** HFADJUST *********************************
- *
- * Pitch outside HS range. Adjust it.
- *
- * (1)  If this is a HS, there's nothing we can do about it. Return -1.0
- *  which will cause note to be deleted in calling environment.
- * (2)  If it's an HF however....
- *  Set newpitch at appropriate interval from original pitch.
- * (3)  If it's now above the HS
- * (4)  transpose it down by octaves until it is in the HS.
- * (5)  If still not in HS, mark for deletion.
- * (6)  If it's BELOW the HS.
- * (7)  transpose it up by octaves until it is in the HS.
- * (8)  If still not in HS, mark for deletion.
- * (9)  Return new pitch.
- */
-
-double hfadjust(double thispitch,double *hs,int x1,int x2,int texflag,int hsnotecnt)
-{
-    double newpitch;
-    if(texflag & IS_HS)
-        return(-1.0);                               /* 1 */
-    else {                                      
-        newpitch = thispitch+hs[x1]-hs[x2];         /* 2 */
-        if(newpitch > hs[hsnotecnt-1]) {            /* 3 */
-            while(newpitch>hs[hsnotecnt-1])
-                newpitch -= SEMITONES_PER_OCTAVE;   /* 4 */
-            if(newpitch<hs[0])                      /* 5 */
-                return(-1.0);
-        } else {
-            if(newpitch<hs[0]) {                    /* 6 */
-                while(newpitch <hs[0])
-                    newpitch += SEMITONES_PER_OCTAVE;/* 7 */
-                if(newpitch>hs[hsnotecnt-1])
-                    return(-1.0);                   /* 8 */
-            }
-        }
-    }
-    return(newpitch);                               /* 9 */
-}
-
-/**************************** CONVERT_PITCH_TO_NEAREST_HSET_PITCH *********************************
- *
- * Convert pitch value to nearest HS value.
- *
- * ignores the problem of note repetitions in the tset.
- * Note repetitions were only important where the tset notes were being
- * forced onto an HS. Here the HS values are being extracted so the notes
- * can be ornamented. The pitch values of the tset are NOT themselves altered.
- */
-
-int convert_pitch_to_nearest_hset_pitch(double thispitch,double *hs,int hsnotecnt)
-{
-    int n, m;
-    if(thispitch<hs[0]) {
-        if(hs[0] - thispitch > hs[1] - hs[0])
-            return(-1);
-        else
-            return(0);
-    }
-    n = 1;
-    m = n-1;
-    while(n<hsnotecnt) {
-        if(flteq(hs[n],thispitch))
-            return(n);
-        if(hs[n]>thispitch) {
-            if(hs[n] - thispitch > thispitch - hs[m])
-                return(m);
-            else
-                return(n);
-        }
-        n++;
-        m++;
-    }
-    if(hsnotecnt>1 && (thispitch - hs[hsnotecnt-1] > hs[hsnotecnt-1] - hs[hsnotecnt-2]))
-        return(-1);
-    return(hsnotecnt-1);
-}
-
-/**************************** HFADJ2 *********************************
- *
- * HFindex outside HS range. Adjust it.
- * Applies only to HF (i.e. an HS containing octave transpositions)
- * not to HS.
- */
-
-int hfadj2(int hsi,int hfnotecnt,int hsnotecnt)
-{
-    if(hsi<0) {
-        while(hsi<0)
-            hsi += hfnotecnt;
-    } else {
-        while(hsi>=hsnotecnt)
-            hsi -= hfnotecnt;
-    }
-    if(hsi<0 || hsi>=hsnotecnt)
-        return(-1);
-    return(hsi);
-}
-
-/**************************** SETUP_HFIELD *********************************/
-
-int setup_hfield(noteptr thisnote,double **hs,int *hsnotecnt,double **hf,int *hfnotecnt,int texflag)
-{
-    int exit_status;
-    if(texflag & IS_HS) {
-        if((exit_status = geths(thisnote,hs,hsnotecnt))<0)
-            return(exit_status);
-    } else {
-        if((exit_status = gethf(thisnote,hf,hfnotecnt))<0)                  /* 2 */
-            return(exit_status);
-        if((exit_status = gen_hs(hf,hs,hsnotecnt,*hfnotecnt))<0)
-            return(exit_status);
-    }
-    return(FINISHED);
-}
-
-/**************************** SETUP_FIRST_HFIELD *********************************/
-
-int setup_first_hfield(noteptr thisnote,double **hs,int *hsnotecnt,double **hf,int *hfnotecnt,int texflag)
-{
-    int exit_status;
-    if(texflag & IS_HS) {
-        if((exit_status = get_first_hs(thisnote,hs,hsnotecnt))<0)
-            return(exit_status);
-    } else {
-        if((exit_status = get_first_hf(thisnote,hf,hfnotecnt))<0)                   /* 2 */
-            return(exit_status);
-        if((exit_status = gen_hs(hf,hs,hsnotecnt,*hfnotecnt))<0)
-            return(exit_status);
-    }
-    return(FINISHED);
-}
-
-/**************************** GET_NEXT_HFIELD *********************************/
-
-int get_next_hfield(double **hf,double **hs,double inputtime,
-int *hf_cnt,int *hs_cnt,int *hfnotecnt,noteptr *thishfnote,double *thishftime,double *nexthftime,int hfdatacnt,
-int *hsnotecnt,noteptr *thishsnote,double *thishstime,double *nexthstime,double *hft,int texflag)
-{
-    if(texflag & IS_HS)
-        return getnexths(hs,inputtime,hs_cnt,hsnotecnt,thishsnote,thishstime,nexthstime,hfdatacnt,hft);
-    else
-        return getnexthf(hf,hs,hsnotecnt,inputtime,hf_cnt,hfnotecnt,thishfnote,thishftime,nexthftime,hfdatacnt,hft);
-}
-
-/**************************** SETUP_MOTIF_NOTE *********************************
- *
- * (1)  If the program is given a pitchrange OUTSIDE the bounds of the
- *      specified HF or HS, do_ev_hfpch() returns a -ve value. In this
- *      case, the associated tset note is marked for DELETION by setting
- *      the bitflag associated with the shadow (address) of the tset note.
- *      It will be deleted at the very end, by del_ghosts().
- */
-
-int setup_motif_note
-(double thisamp,int thisinstr,double thisdur,noteptr tsetnote,noteptr phrasenote,
-double *thispitch,double thistime,int *hsindex,int hsnotecnt,double *hs,
-double *pptop,double *ppbot,int *shadindex,char *shadbits,double multiplier,dataptr dz)
-{
-    int exit_status;
-    tsetnote->amp = (float)thisamp;
-    tsetnote->instr = (unsigned char)thisinstr;
-    if(dz->vflag[DONT_KEEP_MTFDUR])
-        tsetnote->dur = (float)thisdur;
-    else
-        tsetnote->dur = (float)(phrasenote->dur * multiplier);
-    if(flteq((double)tsetnote->dur,0.0)) {
-        sprintf(errstr,"setup_motif_note(): Zero duration\n");
-        return(PROGRAM_ERROR);
-    }
-    if((exit_status = do_ev_hfpch(thistime,hsindex,thispitch,hsnotecnt,hs,pptop,ppbot,dz))<0) 
-        return(exit_status);
-    if(exit_status==CONTINUE) {
-        set_shadbit(*shadindex,shadbits);    /* 1 */
-        tsetnote = tsetnote->next;              
-        (*shadindex)++;
-        return(CONTINUE);
-    }
-    tsetnote->pitch = (float)(*thispitch);
-    return(FINISHED);
-}
-
-/**************************** SETUP_GROUP_NOTE *********************************/
-
-int setup_group_note
-(double thisamp,int thisinstr,double thisdur,noteptr tsetnote,
-double *thispitch,double thistime,int *hsindex,int hsnotecnt,double *hs,
-double *pptop,double *ppbot,int *shadindex,char *shadbits,dataptr dz)
-{
-    int exit_status;
-    tsetnote->amp = (float)thisamp;
-    tsetnote->instr = (unsigned char)thisinstr;
-    tsetnote->dur = (float)thisdur;
-    if((exit_status = do_ev_hfpch(thistime,hsindex,thispitch,hsnotecnt,hs,pptop,ppbot,dz))<0)   /* 1 */
-        return(exit_status);
-    if(exit_status==CONTINUE) {
-        set_shadbit(*shadindex,shadbits);
-        tsetnote = tsetnote->next;              
-        (*shadindex)++;
-        return(CONTINUE);
-    }
-    tsetnote->pitch = (float)(*thispitch);
-    return(FINISHED);
-}
-
-/**************************** SETUP_ORNAMENTATION *********************************/
-
-int setup_ornamentation
-(int *starthsi,int *endhsi,noteptr *nextevent,noteptr tsetnote,
-noteptr *phrasenote,int *shadindex,int *endhsindex,int *hfphrase,int phrno,dataptr dz)
-{
-    *starthsi  =  *hfphrase;            
-    *endhsi    =  endhsindex[phrno];
-    *nextevent = getnextevent_to_decorate(tsetnote,shadindex,dz);
-    if(!dz->vflag[IS_PRE])
-        *phrasenote = (*phrasenote)->next;
-    return(FINISHED);
-}
-
-/**************************** GENERATE_MOTIF_NOTE_PITCH *********************************/
-
-int generate_motifin_note_pitch(int n,int hsindex,int starthsindex,int hsnotecnt,double thispitch,
-                                int *hfphrase,noteptr *thisnote,double *hs,int texflag)
-{
-    int notehsindex, thishsindex;
-    double newpitch;
-    notehsindex = *(hfphrase+n+1);
-    thishsindex = hsindex + notehsindex - starthsindex;
-    if(thishsindex<0 || thishsindex>=hsnotecnt) {
-        if((newpitch = hfadjust(thispitch,hs,notehsindex,starthsindex,texflag,hsnotecnt))<0.0) {
-            *thisnote = (*thisnote)->last;
-            free((*thisnote)->next);
-            return(CONTINUE);
-        } else
-            (*thisnote)->pitch = (float)newpitch;
-    } else
-        (*thisnote)->pitch=(float)hs[thishsindex];
-    return(FINISHED);
-}
-
-/**************************** GENERATE_MOTIF_NOTE_PITCH *********************************/
-
-int generate_motif_note_pitch(noteptr tsetnote,noteptr phrasenote,double phrfirstnote,noteptr thisnote)
-{
-    thisnote->pitch=(float)(tsetnote->pitch + phrasenote->pitch - phrfirstnote);
-    thisnote->pitch=(float)octadjust((double)thisnote->pitch);
-    return(FINISHED);
-}
-
-/**************************** GENERATE_ORNAMENT_NOTE_PITCH *********************************
- *
- * hsi = harmonic-set index.
- */
- 
-int generate_ornament_note_pitch
-(int n,double *hs,int hsi, int endhsi,int starthsi,noteptr *thisnote,
-noteptr *phrasenote,int *hfphrase,int hfnotecnt,int hsnotecnt,dataptr dz)
-{
-    unsigned int texflag = dz->tex->txflag;
-    int thishsi, refhsi, notehsi;       
-
-    if(dz->vflag[IS_PRE]) {
-        refhsi = endhsi;
-        notehsi = *(hfphrase+n);
-    } else {
-        refhsi = starthsi;
-        notehsi = *(hfphrase+n+1);
-    }
-    thishsi = hsi + notehsi - refhsi;
-    *phrasenote = (*phrasenote)->next;
-    if(thishsi<0 || thishsi>=hsnotecnt) {
-        if((texflag & IS_HS) || (thishsi=hfadj2(thishsi,hfnotecnt,hsnotecnt))<0) {
-            *thisnote = (*thisnote)->last;      
-            free((*thisnote)->next);
-            return(CONTINUE);
-        }
-    }
-    (*thisnote)->pitch=(float)hs[thishsi];  
-    return(FINISHED);
-}
-
-/********************** DO_EV_HFPCH *******************************
- *
- * Generate pitch of event (note group etc.) within HS.
- *
- * (2)  If getp_as_index() returns -1 , this means
- *  that the pitch range specified is outside the HS, so a value of 
- *  -1.0 is returned to calling environment and tset note is DELETED!!
- */
-
-int do_ev_hfpch(double thistime,int *hsindex,double *val,int hsnotecnt,double *hs,double *pptop,double *ppbot,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getp_as_index(thistime,hsindex,hsnotecnt,hs,pptop,ppbot,dz))<0)
-        return(exit_status);
-    if(*hsindex==-1)                /* a */
-        return(CONTINUE);           /* 2 */
-    *val = hs[*hsindex];
-    return(FINISHED);
-}
-
-/****************************** GETP_AS_INDEX *********************************
- *
- * Get integer value of a hf-pitch index, using pitch either from table,
- * or fixed value.
- *
- * (1)  Read values of pitch-range limits from tables (or fixed vals).
- * (2)  If either of pitch values is negative, if it's from a table,
- *  reject it....
- * (3)  But otherwise it can be regarded as a flag. Return -1 causing
- *  the INPUT pitch to be converted to a HS pitch and returned.
- * (4)  Check that range is not inverted.
- * (5)  Get the note in HS which is >  upper pitch boundary. If all HS notes
- *  are above this (function returns 0) return -1.
- *  If all HS notes are BELOW this pitch, function returns hsnotecnt,
- *  wehich forces upper limit of HSindex generated by doperm() to be
- *  hsnotecnt-1, the highest pitch in the HS.
- * (6)  Get the note in HS which is >= lower pitch boundary. If there
- *  is no such note (function returns hsnotecnt) return -1.
- * (7)  Return a weighted scattered value of hf-index, within the
- *  defined range.
- */
-
-int getp_as_index(double thistime,int *val,int hsnotecnt,double *hs,double *pptop,double *ppbot,dataptr dz)
-{
-    int exit_status;
-    int  a, b;
-    double range;
-    if(dz->brk[TEXTURE_MAXPICH]) {                      /* 1 */
-        if((exit_status = read_value_from_brktable(thistime,TEXTURE_MAXPICH,dz))<0)
-            return(exit_status);
-    }
-    if(dz->brk[TEXTURE_MINPICH]) {
-        if((exit_status = read_value_from_brktable(thistime,TEXTURE_MINPICH,dz))<0)
-            return(exit_status);
-    }
-    *pptop = dz->param[TEXTURE_MAXPICH];
-    *ppbot = dz->param[TEXTURE_MINPICH];
-    if((range = dz->param[TEXTURE_MAXPICH] - dz->param[TEXTURE_MINPICH])<0.0)       /* 4 */
-        swap (&dz->param[TEXTURE_MAXPICH],&dz->param[TEXTURE_MINPICH]);
-    if((a = geths_above(dz->param[TEXTURE_MAXPICH],hs,hsnotecnt))==0) {             /* 5 */
-        *val = -1;
-        return(FINISHED);
-    }
-    if((b = geths_hibnd(dz->param[TEXTURE_MINPICH],hsnotecnt,hs))>=hsnotecnt) {     /* 6 */
-        *val = -1;
-        return(FINISHED);
-    }
-    if((exit_status = hfscat(a-b,b,PM_PITCH,&a,dz))<0)  /* 7 */
-        return(exit_status);
-    if( a < 0 || a >= hsnotecnt) {          /* 7 */
-        sprintf(errstr,"TEXTURE: getp_as_index(): TW's logic of index generation wrong\n");
-        return(DATA_ERROR);
-    }
-    *val = a;
-    return(FINISHED);
-}
-
-/**************************** INIT_SHADBITS ****************************
- *
- * Set up, and initialise to zero, a bitflag with one bit for each shadow
- * (tset address).
- */
-
-int init_shadbits(int shadowsize,int *shshsize,char **shadbits)
-{
-    int n = shadowsize;
-    *shshsize = 1;
-    while((n -= CHARBITSIZE)>0)
-        (*shshsize)++;
-    if((*shadbits = (char *)malloc((size_t)(*shshsize)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for shadwoing array.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0; n<(*shshsize); n++)
-        (*shadbits)[n] = 0;
-    return(FINISHED);
-}
-
-/****************************** GETHS ***********************************
- *
- * Extract HS from input data.
- */
-
-int geths(noteptr thisnote,double **hs,int *hsnotecnt)
-{
-    int exit_status;
-    int size = BIGARRAY;
-    if((*hs = (double *)malloc(BIGARRAY * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic set array.\n");
-        return(MEMORY_ERROR);
-    }
-    while(thisnote!=(noteptr)0) {
-        if((exit_status = gethsnote(thisnote->pitch,*hs,hsnotecnt))<0)
-            return(exit_status);
-        if(*hsnotecnt >= BIGARRAY) {
-            size += BIGARRAY;
-            if((*hs=(double *)realloc((char *)(*hs),size * sizeof(double)))==NULL){
-                sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic set array.\n");
-                return(MEMORY_ERROR);
-            }   
-        }
-        thisnote = thisnote->next;
-    }
-    if((*hs=(double *)realloc((char *)(*hs),*hsnotecnt*sizeof(double)))==NULL){
-        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic set array.\n");
-        return(MEMORY_ERROR);
-    }
-    upsort(*hs,*hsnotecnt);
-    return(FINISHED);
-}
-    
-/****************************** GETHF ***********************************
- *
- * Extract HF from input data.
- */
-
-int gethf(noteptr thisnote,double **hf,int *hfnotecnt)
-{
-    int exit_status;
-    int size = BIGARRAY;
-    if((*hf = (double *)malloc(size * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic field array.\n");
-        return(MEMORY_ERROR);
-    }
-    while(thisnote!=(noteptr)0) {
-        if((exit_status = gethfnote(thisnote->pitch,*hf,hfnotecnt))<0)
-            return(exit_status);
-        if(*hfnotecnt >= size) {
-            size += BIGARRAY;
-            if((*hf = (double *)realloc((char *)(*hf),size * sizeof(double)))==NULL){
-                sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic field array.\n");
-                return(MEMORY_ERROR);
-            }   
-        }
-        thisnote = thisnote->next;
-    }
-    if((*hf=(double *)realloc((char *)(*hf),*hfnotecnt * sizeof(double)))==NULL){
-        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic field array.\n");
-        return(MEMORY_ERROR);
-    }
-    upsort(*hf,*hfnotecnt);
-    return(FINISHED);
-}
-    
-/****************************** GEN_HS ***********************************
- *
- * Generate HS from a HF.
- *
- * NB This function assumes thas HF is ordered in ascending pitch order.
- *
- * (1)  Eliminate octave dupliates in hf.
- * (2)  Initialise the HS count to zero.
- * (3)  Start in the lowest octave.
- * (4)  Go round loop generating HS, until we're out of (MIDI) range.
- * (5)  Each time round loop, point to start of HF.
- * (6)  And for all HF members, put them in HS + a (loop) number of 8ves,
- *  counting the HS as we go.
- * (7)  Once the pitch of any note exceeds MIDI upper limit (MIDITOP), break
- *  from inner and (OK=0) outer loops.
- * (8)  Each time round outer loop, increment octave.
- * (9)  Reallocate the HS to the store 'hs'
- */
-
-int gen_hs(double **hf,double **hs, int *hsnotecnt, int hfnotecnt)
-{
-    int n, m, k, thisoct, OK = 1;
-    int size = BIGARRAY;
-    double nextpitch;
-    double *thishf;
-    if((*hs)!=(double *)0)
-        free(*hs);
-    if((*hs = (double *)malloc(size * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic set array.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n<hfnotecnt-1;n++) {        /* 1 */
-        for(m=n+1;m<hfnotecnt;m++) {
-            if(octeq((*hf)[n],(*hf)[m])) {
-                k = m + 1;
-                while(k < hfnotecnt) {
-                    (*hf)[k-1] = (*hf)[k];
-                    k++;
-                }
-                hfnotecnt--;
-                m--;
-            }
-        }
-    }
-    *hsnotecnt = 0;                         /* 2 */
-    thisoct = 0;                        /* 3 */
-    while(OK) {                         /* 4 */
-        thishf = *hf;                       /* 5 */
-        for(n=0;n<hfnotecnt;n++) {                  /* 6 */
-            if((nextpitch = (*thishf++)+((double)thisoct*SEMITONES_PER_OCTAVE))<=MIDITOP) {
-                (*hs)[(*hsnotecnt)++] = nextpitch;
-                if(*hsnotecnt>=size) {
-                    size += BIGARRAY;
-                    if((*hs =(double *)realloc((char *)(*hs),size * sizeof(double)))==NULL) {
-                        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic set array.\n");
-                        return(MEMORY_ERROR);
-                    }   
-                }
-            } else {
-                OK = 0;                     /* 7 */
-                break;
-            }
-        }
-        thisoct++;                      /* 8 */
-    }
-    if((*hs=(double *)realloc((char *)(*hs),*hsnotecnt * sizeof(double)))==NULL){
-        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic set array.\n");
-        return(MEMORY_ERROR);
-    }
-    return(FINISHED);
-}
-    
-/**************************** CHEKREPEAT *********************************
- *
- * Flag if there is a repeated note in the source data.
- */
-
-int chekrepeat(noteptr thisnote,double lastpitch)
-{ 
-    if(flteq((double)thisnote->pitch,lastpitch))
-        return(TRUE);
-    return(FALSE);
-}
-
-/****************************** GETNEXTHF ***********************************
- *
- * Get the harmonic field pertaining to this time, + 'hfnotecnt'.
- *
- * NB 2: THIS FUNCTION ASSUMES IN WILL BE ACCESSED IN TIME-INCREASING ORDER.
- *
- * (1)  Current time preset to zero.
- * (2)  Nexttime to time of next hf in hf_data_motif.
- * (3)  Static pointer points into current place in hf_data_motif.
- * (3a) If noteptr points to zero w'ere
-    EITHER  we're at end of notelist: therefore no more HF data,
-        hence retain existing data.
-    OR  we have not initialised the noteptr, which should happen
-        on first call to this function, BUT in this case the
-        hfnotecnt will be zero as we have not yet created an HF.
-        In this case, error, exit.
- * (4)  If time of function access still less than time of entry of next
- *  harmonic field, do nothing (i.e. stay with current hf returning
- *  current hfnotecnt).
- * (5)  If time of function access is after time of next harmonic field
- *  advance down hfs, until TOFA is before next hf (NB last time in
- *  the hft[] is AFTER end of texture duration).
- * (6)  Establish temporary storage space to read a new hf, and set the
- *  hf pointer 'thishf' to point to it.
- * (7)  Walk through the input notes until we get to notes corresponding
- *  to time of the hf we want.
- * (8)  Store the harmonic field in the temporary array.
- * (9)  Free any existing hf.
- * (10) Reallocate the new hf to the array hf[], and set the hf pointer
- *  'thishf' to point at it.
- * (11) Generate the associated HS !!!
- */
-
-int getnexthf
-(double **hf,double **hs, int *hsnotecnt,double inputtime,int *hf_cnt,int *hfnotecnt,
- noteptr *thishfnote,double *thishftime,double *nexthftime,int hfdatacnt,double *hft)
-{
-    int exit_status;
-    int size = BIGARRAY;
-    if(*thishfnote==(noteptr)0) {                   /* 3a */
-        if(*hfnotecnt==0) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for hfield notecount array.\n");
-            return(PROGRAM_ERROR);
-        }
-        return(TRUE);
-    }
-    if(inputtime<*nexthftime)                   /* 4 */
-        return(FALSE);
-    while(*nexthftime<=inputtime) {             /* 5 */
-        if(*hf_cnt>=hfdatacnt) {
-            sprintf(errstr,"INSUFFICIENT MEMORY for hfield count array.\n");
-            return(PROGRAM_ERROR);
-        }
-        *thishftime = *nexthftime;
-        *nexthftime = hft[*hf_cnt];
-        (*hf_cnt)++;
-    }
-    if(*hf!=(double *)0)                        /* 9 */
-        free(*hf);                      
-    if((*hf = (double *)malloc(size * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for hfield array.\n");
-        return(MEMORY_ERROR);
-    }
-    while(!flteq((double)(*thishfnote)->ntime,*thishftime)) {       /* 7 */
-        if((*thishfnote = (*thishfnote)->next)==(noteptr)0) {
-            sprintf(errstr,"TEXTURE: Search problem in getnexthf()\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    *hfnotecnt = 0;
-    while(flteq((double)(*thishfnote)->ntime,*thishftime)) {        /* 8 */
-        if((exit_status = gethfnote((*thishfnote)->pitch,*hf,hfnotecnt))<0)
-            return(exit_status);
-        if(*hfnotecnt >= size) {
-            size += BIGARRAY;
-            if((*hf = (double *)realloc((char *)(*hf),size * sizeof(double)))==NULL) {
-                sprintf(errstr,"TEXTURE: realloc failed in getnexthf()\n");
-                return(PROGRAM_ERROR);
-            }   
-        }
-        if((*thishfnote = (*thishfnote)->next)==(noteptr)0)
-            break;
-    }
-    if((*hf=(double *)realloc((char *)(*hf),*hfnotecnt * sizeof(double)))==NULL){
-        sprintf(errstr,"TEXTURE: getnexthf(): realloc() failed\n"); /* 10 */
-        return(PROGRAM_ERROR);
-    }
-    upsort(*hf,*hfnotecnt);
-    if((exit_status = gen_hs(hf,hs,hsnotecnt,*hfnotecnt))<0)  /* 11 */
-        return(exit_status);
-    return(TRUE);
-}
-
-/****************************** GETNEXTHS ***********************************
- *
- * Get the harmonic set pertaining to this time.
- *
- * NB 2: THIS FUNCTION ASSUMES IT WILL BE ACCESSED IN TIME-INCREASING ORDER.
- *
- * (3)  Static pointer points into current place in hf_data_motif.
- * (3a) If noteptr points to zero w'ere
-    EITHER  we're at end of notelist: therefore no more HF data,
-        hence retain existing data.
-    OR  we have not initialised the noteptr, which should happen
-        on first call to this function, BUT in this case the
-        hsnotecnt will be zero as we have not yet created an HS.
-        In this case, error, exit.
- * (4)  If time of function access still less than time of entry of next
- *  harmonic set, do nothing (i.e. stay with current hs returning 
- *  current harmonic set cnt hsnotecnt).
- * (5)  If time of function access is after time of next harmonic set
- *  advance down HSs, until TOFA is before next hs (NB last time in
- *  the hft[] is AFTER end of texture duration).
- * (6)  Establish temporary storage space to read a new hs, and set the
- *  hs pointer 'thishs' to point to it.
- * (7)  Walk through the input notes until we get to notes corresponding
- *  to time of the hs we want.
- * (8)  Store the harmonic set in the temporary array.
- * (9)  Free any existing hs.
- * (10) Reallocate the new hs to the array hs[], and set the hs pointer
- *  'thishs' to point at it.
- */
-
-int getnexths
-(double **hs,double inputtime,int *hs_cnt,int *hsnotecnt,noteptr *thishsnote,
-double *thishstime,double *nexthstime,int hfdatacnt,double *hft)
-{
-    int exit_status;
-    int size = BIGARRAY;
-    if(*thishsnote==(noteptr)0) {               /* 3a */
-        if(*hsnotecnt==0) {
-            sprintf(errstr,"getnexths() not initialised\n");
-            return(PROGRAM_ERROR);
-        }
-        return(TRUE);
-    }
-    if(inputtime<*nexthstime)                   /* 4 */
-        return(FALSE);
-    while(*nexthstime<=inputtime) {             /* 5 */
-        if(*hs_cnt>=hfdatacnt) {
-            sprintf(errstr,"Timing problem in getnexths()\n");
-            return(PROGRAM_ERROR);
-        }
-        *thishstime = *nexthstime;
-        *nexthstime = hft[*hs_cnt];
-        (*hs_cnt)++;
-    }
-    if(*hs!=(double *)0)                        /* 9 */
-        free(*hs);                      
-    if((*hs = (double *)malloc(size * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic set array.\n");
-        return(MEMORY_ERROR);
-    }
-
-    while(!flteq((double)(*thishsnote)->ntime,*thishstime)) {           /* 7 */
-        if((*thishsnote = (*thishsnote)->next)==(noteptr)0) {
-            sprintf(errstr,"TEXTURE: Search problem in getnexths()\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    *hsnotecnt = 0;
-    while(flteq((double)(*thishsnote)->ntime,*thishstime)) {            /* 8 */
-        if((exit_status = gethsnote((*thishsnote)->pitch,*hs,hsnotecnt))<0)
-            return(exit_status);
-        if(*hsnotecnt >= size) {
-            size += BIGARRAY;
-            if((*hs =(double *)realloc((char *)(*hs),size * sizeof(double)))==NULL) {
-                sprintf(errstr,"TEXTURE: realloc failed in getnexths()\n");
-                return(PROGRAM_ERROR);
-            }   
-        }
-        if((*thishsnote = (*thishsnote)->next)==(noteptr)0)
-            break;
-    }
-    if((*hs=(double *)realloc((char *)(*hs),*hsnotecnt * sizeof(double)))==NULL){
-        sprintf(errstr,"TEXTURE: getnexths(): realloc() failed\n");/* 10 */
-        return(PROGRAM_ERROR);
-    }
-    upsort(*hs,*hsnotecnt);
-    return(TRUE);
-}
-
-/***************************** GETHSNOTE ************************************
- *
- * Read a note and store in harmonic SET,  IF not already there.
- */
-
-int gethsnote(double thispitch,double *thishs,int *hsnotecnt)
-{
-    int n, OK = 0;
-    for(n=0;n<*hsnotecnt;n++) {
-        if(flteq(thispitch,thishs[n])) {
-            OK = 1;
-            break;
-        }
-    }
-    if(!OK)
-        thishs[*hsnotecnt] = (double)thispitch;
-    (*hsnotecnt)++;
-    return(FINISHED);
-}
-
-/***************************** READHFTIMES ************************************
- *
- * Read times at which successive harmonic fields(sets) enter, and store as list.
- */
-
-int readhftimes(noteptr firstnote, int *hfdatacnt,double **hft)
-{
-    double lasttime, firsttime;
-    int arraysize = BIGARRAY;
-    noteptr thisnote = firstnote;
-    *hfdatacnt = 0;
-    if((*hft = (double *)malloc(arraysize * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic field times array.\n");
-        return(MEMORY_ERROR);
-    }
-    lasttime = thisnote->ntime;
-    (*hft)[0] = lasttime;
-    while(thisnote!=(noteptr)0) {
-        if(!flteq((double)thisnote->ntime,lasttime)) {
-            if(++(*hfdatacnt)>=arraysize-1) {
-                arraysize += BIGARRAY;
-                if((*hft = (double *)realloc((char *)(*hft),arraysize * sizeof(double)))==NULL) {
-                    sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic field times array.\n");
-                    return(PROGRAM_ERROR);
-                }   
-            }
-            (*hft)[*hfdatacnt] = thisnote->ntime;
-            lasttime = thisnote->ntime;
-        }
-        thisnote = thisnote->next;
-    }
-    (*hft)[++(*hfdatacnt)] = DBL_MAX;                   /* 1 */
-    (*hfdatacnt)++;
-    if((*hft = (double *)realloc((char *)(*hft),(*hfdatacnt) * sizeof(double)))==NULL){
-        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic field times array.\n");
-        return(PROGRAM_ERROR);
-    }
-    if(!flteq(**hft,0.0)) {
-        fprintf(stdout,"WARNING: Harmonic Field Data: No field at ZERO time.\n"
-                       "ADJUSTING FIRST FIELD TO ZERO TIME\n");
-        fflush(stdout);
-        thisnote  = firstnote;
-        firsttime = thisnote->ntime;
-        while(flteq(firsttime,**hft)) {
-            thisnote->ntime = 0.0f;
-            if((thisnote = thisnote->next)==(noteptr)0)
-                break;
-        }
-        **hft = 0.0;
-    }
-    return(FINISHED);
-}
-
-/***************************** DEL_GHOSTS ******************************
- *
- * Delete all tset notes MARKED for deletion in shadbits bitflag.
- *
- * (1)  For each byte in the bitflag...
- * (2)  Set the bitmask to the first bit.
- *   (3)  For every bit in this byte....
- *   (4)  If this bit is set, delete the associated shadow (tset) note.
- *   (5)  Advance the bitflag internal to the byte leftwards.
- *   (6)  Advance the count of shadows, and if it reaches the total number
- *    of shadows, exit, because remaining bits in this byte (if any)
- *    have no meaning.
- */
-
-void del_ghosts(int shshsize,char *shadbits,noteptr *shadow,int shadowsize,motifptr tset)
-{
-    int n,m,mask,k = 0;
-    for(n=0;n<shshsize;n++) {               /* 1 */
-        mask = 1;                           /* 2 */
-        for(m=0;m<CHARBITSIZE;m++) {        /* 3 */
-            if(shadbits[n] & mask)          /* 4 */
-                del_note(shadow[k],tset);
-            mask <<= 1;                     /* 5 */
-            if(++k >= shadowsize)           /* 6 */
-                return;
-        }
-    }
-}
-
-/************************** GET_HFGPPARAMS **************************
- *
- * Get the parameters for a group of notes.
- *
- * (0)  If pitch to decorate lies outside the HF range, return with gpsize
- *  set to zero.
- * (1)  If group range is expressed in HS-note units..
- *   (a) Read the gprange as an integer number of (HS) notes.
- *   (b) If HS-range exceeds HS limits, squeeze it.
- *   (c) If HS-range is to be oriented about note, orient it appropriately.
- * (2)  Otherwise...
- *   (a) Read group range in normal way.
- *   (b) If range exceeds HS limits, squeeze it.
- *   (c) If range is to be oriented about note, orient it appropriately.
- *   (d) If the range lies outside range of the HS,
- *   set the groupsize to ZERO and return.
- *   (e) Otherwise set the HS-range.
- * (3)  Read group size.
- * (4)  Read group density.
- * (5)  number of midicliks in a gpdense time-interval.
- * (6)  number of quantisation units, rounded.
- * (7)  readjust gpdense to be number of units * length of units,
- *  and reconvert to seconds.
- */
-                                        
-int get_hfgpparams(double thistime,double thispitch,double *hs,int hsnotecnt,
-int *gpsize,int *hfrange,int *hfgpranglo,int *hfgpranghi,double *gprange,double *gpdense,int mingrpsize,
-double *gprlow, int dectypecnt,unsigned char dectypestor,dataptr dz)
-{
-    int exit_status;
-    if(thispitch<hs[0] || thispitch>hs[hsnotecnt-1]) {
-        *gpsize = 0;                        /* 0 */
-        return(FINISHED);
-    }
-    if((exit_status = igetvalue(TEX_GPRANGHI,TEX_GPRANGLO,thistime,PM_GPRANG,hfrange,dz))<0)
-        return(exit_status);
-
-    if(!dectypecnt) {   
-        hfsqueezrange(thispitch,hfrange,hfgpranghi,hfgpranglo,hsnotecnt,hs);                    /* b */
-        dz->vflag[DECCENTRE] = FALSE;
-    } else {
-        if((exit_status = hforientrange
-        (thispitch,hfrange,hfgpranghi,hfgpranglo,hsnotecnt,hs,dectypecnt,dectypestor,dz))<0) /* c */
-            return(exit_status);
-    }
-/* OCT 17 : hfgpranghi,lo are max & min INDECES within the harmonic field */
-
-    *hfrange = *hfgpranghi - *hfgpranglo;           /* e */
-
-/* OCT 17 : FROM hfgpranghi,lo the actual PITCH values can be deduced */
-    *gprlow  = hs[*hfgpranglo];
-    *gprange = hs[*hfgpranghi] - hs[*hfgpranglo];
-
-    if((exit_status  = igetvalue(TEX_GPSIZEHI,TEX_GPSIZELO,thistime,PM_GPSIZE,gpsize,dz))<0)
-        return(exit_status);
-
-    if(*gpsize  < mingrpsize) {
-        sprintf(errstr,"TEXTURE: Impossible GROUP SIZE value [%d]: get_hfgpparams()\n",*gpsize);
-        return(PROGRAM_ERROR);
-    }
-
-    if((exit_status = getvalue(TEX_GPPACKHI,TEX_GPPACKLO,thistime,PM_GPDENS,gpdense,dz))<0)
-        return(exit_status);
-/* NEW MAR 2000 */
-    *gpdense *= MS_TO_SECS;
-
-    if(dz->param[TEX_PHGRID]>0.0)
-        *gpdense = quantise(*gpdense,dz->param[TEX_PHGRID]);
-    return(FINISHED);
-}
-
-/***************************  HFSQUEEZRANGE ******************************
- *
- * Adjust range to lie within HF limits.
- *
- * (2)  Top of range is at current pitch's HF index (approx). If this is
- *  above current top-of-HF range (hsnotecnt) move top down.
- * (3)  Bottom of range is igprange below top. If this is below
- *  bottom-of-HF (0), move igprlow up.
- * (4)  Recalculate the true igprange within true limits.
- */
-
-void hfsqueezrange(double thispitch,int *hfrange,int *hfgpranghi,int *hfgpranglo,int hsnotecnt,double *hs) 
-{
-    int halfrange = *hfrange/2;
-    if(halfrange * 2 != *hfrange)
-        halfrange++;
-    *hfgpranghi = min((geths_hibnd(thispitch,hsnotecnt,hs)+halfrange),hsnotecnt);   /* 2 */
-    *hfgpranglo = max((*hfgpranghi - *hfrange),0);                          /* 3 */
-    *hfrange = *hfgpranghi - *hfgpranglo;                                   /* 4 */
-}
-
-/****************************** GETHS_HIBND **********************************
- *
- *  hibnd >= pitch
- *
- * Find the index of the harmonic-set note that is immediately above or
- * equal to the input pitch.
- *
- * NB CALL WITH geths_hibnd((double)thisnote->pitch);
- *
- * If the pitch is beyond the HS, n returns the value 'hsnotecnt'.
- */
-
-int geths_hibnd(double thispitch,int hsnotecnt,double *hs)
-{
-    int n;
-    for(n=0;n<hsnotecnt;n++) {
-        if(hs[n]>thispitch || flteq(hs[n],thispitch))
-            break;
-    }
-    return(n);              /* 1 */
-}
-
-/***************************  HFORIENTRANGE ******************************
- *
- * As orientrange() but applied to HF/HS case.
- */
-
-int hforientrange
-(double thispitch,int *hfrange,
-int *hfgpranghi,int *hfgpranglo,int hsnotecnt,double *hs,int dectypecnt,unsigned char dectypestor,dataptr dz)
-{
-    int exit_status;
-    unsigned char dectype;
-    int k;
-    if((exit_status=doperm((int)dectypecnt,PM_ORIENT,&k,dz))<0)
-        return(exit_status);
-    if((exit_status=gettritype(k,dectypestor,&dectype))<0)
-        return(exit_status);
-    switch(dectype) {
-    case(0):            /* centred range */
-        hfsqueezrange(thispitch,hfrange,hfgpranghi,hfgpranglo,hsnotecnt,hs);
-        dz->vflag[DECCENTRE] = TRUE;
-        break;
-    case(1):            /* range above note */
-        *hfgpranghi = min((geths_hibnd(thispitch,hsnotecnt,hs) + *hfrange),hsnotecnt);
-        *hfgpranglo = max((*hfgpranghi - *hfrange),0);
-        *hfrange    = *hfgpranghi - *hfgpranglo;
-        dz->vflag[DECCENTRE] = FALSE;
-        break;              
-    case(2):            /* range below note */
-        *hfgpranghi = geths_hibnd(thispitch,hsnotecnt,hs);
-        *hfgpranglo = max((*hfgpranghi - *hfrange),0);
-        *hfrange    = *hfgpranghi - *hfgpranglo;
-        dz->vflag[DECCENTRE] = FALSE;
-        break;              
-    default:
-        sprintf(errstr,"TEXTURE: Problem in hforientrange()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/****************************** GETHS_ABOVE **********************************
- *
- *  above > pitch
- *
- * Find the index of the harmonic-set note that is immediately above
- * the input pitch.
- *
- * NB CALL WITH geths_above((double)thisnote->pitch);
- *
- * If the pitch is beyond the HS, n gets the value 'hsnotecnt', which becomes
- * the upper limit of the search range for doperm() ensuring that highest
- * possible HSindex val is hsnotecnt-1, the highest pitch in the HS.
- */
-
-int geths_above(double thispitch,double *hs,int hsnotecnt)
-{
-    int n;
-    for(n=0;n<hsnotecnt;n++) {
-        if(hs[n]>thispitch)
-            break;
-    }
-    return(n);                  /* 1 */
-}
-
-/****************************** GENERATE_GROUP_NOTE **********************************/
-
-int generate_group_note
-(noteptr thisnote,noteptr tsetnote,double thistime,int hfrange,int hfgpranglo,
-double *hs,int *hsindex,int gpsize,dataptr dz)
-{
-    int exit_status;
-    unsigned char thisinstr;
-    if((exit_status = do_grp_ins(tsetnote->instr,&thisinstr,dz))<0)
-        return(exit_status);
-    thisnote->instr = thisinstr;
-    thisnote->motioncentre = tsetnote->motioncentre;
-    if((exit_status = hfscat(hfrange,hfgpranglo,PM_GPPICH,hsindex,dz))<0)
-        return(exit_status);
-    thisnote->pitch  = (float)hs[*hsindex];     /* 7 */
-    thisnote->ntime  = (float)thistime; 
-    return setspace(tsetnote,thisnote,gpsize,dz);
-}
-
-/******************************* HFSCAT ***********************************
- *
- * A weighted version of hfscatx().
- */
-
-int hfscat(int prange,int pbottom,int permindex,int *val,dataptr dz)
-{
-    int exit_status;
-    double bandbottom,  bandtop,  bandwidth;
-    int   ibandbottom, ibandtop, ibandwidth, k;
-    if(prange<=LAYERCNT) {
-        if((exit_status = doperm((int)prange,permindex,&k,dz))<0)
-            return(exit_status);
-        *val = k + pbottom;
-        return(FINISHED);
-
-    }
-    if((exit_status = doperm((int)BANDCNT,permindex,&k,dz))<0)
-        return(exit_status);
-    bandwidth = (double)prange/(double)LAYERCNT;
-    switch(k) {
-    case(0):
-        bandbottom = 0;
-        break;
-    case(BANDCNT-1):
-        bandbottom = (double)(LAYERCNT-1) * bandwidth;
-        break;
-    default:
-        bandbottom = bandwidth + ((double)((k-1) * 2) * bandwidth);
-        bandwidth *= 2.0;
-        break;
-    }
-    bandtop     = bandbottom + bandwidth;
-    ibandtop    = round(bandtop);
-    ibandbottom = round(bandbottom);
-    ibandwidth  = ibandtop - ibandbottom;
-    k  = (int)(drand48() * (double)ibandwidth);
-    k += ibandbottom;
-    k += pbottom;
-    *val = k;
-    return(FINISHED);
-}
-
-/****************************** GENERATE_DECOR_NOTE **********************************/
-
-int generate_decor_note(noteptr thisnote,noteptr tsetnote,
-double thispitch,double thistime,int hfrange,int hfgpranghi,int hfgpranglo,double *hs,int *hsindex,
-int hsnotecnt,double gprlow,double gprange,int gpsize,dataptr dz)
-{
-    int exit_status;
-    double val;
-    if((exit_status = do_grp_ins(tsetnote->instr,&thisnote->instr,dz))<0)
-        return(exit_status);
-    thisnote->motioncentre = tsetnote->motioncentre;
-    if(dz->vflag[DECCENTRE]) {
-        if((exit_status = dec_hfcentre
-        (thispitch,hs,hsnotecnt,hfrange,hfgpranghi,hfgpranglo,gprlow,gprange,gpsize,&val,dz))<0)
-            return(exit_status);
-        thisnote->pitch = (float)val;
-    } else {
-        if((exit_status = hfscat(hfrange,hfgpranglo,PM_GPPICH,hsindex,dz))<0)
-            return(exit_status);
-        thisnote->pitch  = (float)hs[*hsindex];
-    }
-    thisnote->ntime  = (float)(thistime); 
-    return setspace(tsetnote,thisnote,gpsize,dz);
-}
-
-/************************* DEC_HFCENTRE *******************************/
- 
-int dec_hfcentre(double tsetpitch,double *hs,int hsnotecnt,int hfrange,int hfgpranghi,int hfgpranglo,
-double gprlow,double gprange,int gpsize,double *val,dataptr dz)
-{
-    int exit_status;
-    double a, gprhi = gprlow + gprange;
-    int s, save, k, hfcentre, n_above, n_below, hsindex;
-    if(tsetpitch-gprlow<=FLTERR || flteq(tsetpitch,gprhi)) {
-        if((exit_status = hfscatx(hfrange,hfgpranglo,PM_GPPICH,&hsindex,dz))<0)
-            return(exit_status);
-        *val = hs[hsindex];
-        return(FINISHED);                   /* 1 */
-    }
-    n_below = hfrange/2;                    /* 2 */
-    if(((n_above=n_below)+n_below)!=hfrange)
-        n_above++;
-    if(((hfcentre =geths_hibnd(tsetpitch,hsnotecnt,hs)) + n_above) > hsnotecnt)
-        n_above = hsnotecnt - hfcentre;             /* 3 */
-    if(hfcentre - n_below < 0)
-        n_below = hfcentre;                 /* 4 */
-    if(n_above<=0 || n_below<=0) { 
-        if((exit_status = hfscatx(hfrange,hfgpranglo,PM_GPPICH,&hsindex,dz))<0)
-            return(exit_status);
-        else {
-            *val = hs[hsindex];
-            return(FINISHED);                   /* 5 */
-        }
-    }
-    save = dz->iparray[TXREPETCNT][PM_DECABV];                      /* 6 */
-    k = (gpsize+1)/2;
-    if(dz->iparray[TXREPETCNT][PM_DECABV]>k)
-        dz->iparray[TXREPETCNT][PM_DECABV] = k;         
-    if((exit_status = doperm((int)2,PM_DECABV,&s,dz))<0)
-        return(exit_status);
-    if(s) {
-        if((exit_status = hfscatx(n_above,hfgpranghi - n_above,PM_GPPICH,&hsindex,dz))<0)
-            return(exit_status);
-    } else {
-        if((exit_status = hfscatx(n_below,hfgpranglo,PM_GPPICH2,&hsindex,dz))<0)
-            return(exit_status);
-    }
-    dz->iparray[TXREPETCNT][PM_DECABV] = save;
-    a = hs[hsindex];
-    if(a<MIDIBOT || a>MIDITOP) {
-        sprintf(errstr,"TEXTURE: Problem in dec_hfcentre()\n");
-        return(PROGRAM_ERROR);
-    }
-    *val = a;
-    return(FINISHED);                           
-}
-
-/******************************* HFSCATX ***********************************
- *
- * As pscat, but working with ranges of integers, especially the indeces
- * of an HS.
- */
-
-int hfscatx(int prange,int pbottom,int permindex,int *val,dataptr dz)
-{
-    int exit_status;
-    double bandbottom,  bandtop,  bandwidth;
-    int   ibandbottom, ibandtop, ibandwidth, k;
-    if(prange<=BANDCNT) {
-        if((exit_status = doperm((int)prange,permindex,val,dz))<0)
-            return(exit_status);
-        *val += pbottom;
-        return(FINISHED);
-    }
-    if((exit_status = doperm((int)BANDCNT,permindex,val,dz))<0)
-        return(exit_status);
-    k = *val;
-    bandwidth   = (double)prange/(double)BANDCNT;
-    bandbottom  = (double)k     * bandwidth;
-    bandtop     = (double)(k+1) * bandwidth;
-    ibandbottom = round(bandbottom);
-    ibandtop    = round(bandtop);
-    ibandwidth  = ibandtop - ibandbottom;
-    k  = (int)(drand48() * (double)ibandwidth);
-    k += ibandbottom;
-    *val = k + pbottom;
-    return(FINISHED);
-}
-
-/******************************** SET_SHADBIT ****************************
- * 
- * Set a bit in the shadow's bitfag.
- */
-
-void set_shadbit(int k,char *shadbits)
-{
-    int bitunit  = k/CHARBITSIZE;
-    int bitshift = k % 8;
-    int mask = 1;
-    mask <<= bitshift;
-    shadbits[bitunit] |= mask;
-}
-
-/****************************** GETHS_LOBND **********************************
- *
- *  lobnd =< pitch
- *
- * Find the index of the harmonic-set note that is immediately below, or
- * equal to the input pitch.
- *
- * NB CALL WITH geths_lobnd((double)thisnote->pitch);
- *
- * NB: If the entered pitch is lower than the entire HS, function returns -1.
- */
-
-int geths_lobnd(double thispitch,double *hs,int hsnotecnt)
-{
-    int n;
-    for(n=0;n<hsnotecnt;n++) {
-        if(hs[n]>thispitch)
-            break;
-    }
-    return(--n);                    /* 1 */
-}
-
-/***************************** GETHFNOTE ************************************
- *
- * Read a note and store in harmonic field IF not already there.
- */
-
-int gethfnote(double thispitch,double *hf,int *hfnotecnt)
-{
-    int n, OK  = 0;
-    float notetransp = (float)fmod(thispitch,SEMITONES_PER_OCTAVE);
-    if(flteq((double)notetransp,0.0))
-        notetransp = (float)(notetransp + SEMITONES_PER_OCTAVE);
-    for(n=0;n<*hfnotecnt;n++) {
-        if(flteq((double)notetransp,hf[n])) {
-            OK = 1;
-            break;
-        }
-    }
-    if(!OK)
-        hf[*hfnotecnt] = (double)notetransp;
-    (*hfnotecnt)++;
-    return(FINISHED);
-}
-
-/**************************** SETMTFPARAMS *******************************
- * 
- * Establish easy parameters of motif or ornament.
- */
-
-int setmtfparams
-(noteptr thisnote,double thisamp,noteptr phrasenote,noteptr tsetnote,double ampdif,double notetime,
-int gpsize,double multiplier,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = do_mtf_params(thisnote,thisamp,phrasenote,tsetnote,ampdif,notetime,multiplier,dz))<0)
-        return(exit_status);
-    return setspace(tsetnote,thisnote,gpsize,dz);
-}
-
-/**************************** INITIALISE_HFPHRASES *******************************/
-
-int initialise_hfphrases
-(int ***hfphrase,int **endhsindex,int **phrnotecnt,double **phraseamp,double **phrange,
-noteptr **phrlastnote,dataptr dz)
-{
-    if((*hfphrase = (int **)malloc(dz->tex->phrasecnt * sizeof(int *)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic field phrases.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*endhsindex = (int *)malloc(dz->tex->phrasecnt * sizeof(int)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic set indices.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*phrnotecnt = (int *)malloc(dz->tex->phrasecnt * sizeof(int)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic field phrase notecnt.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*phraseamp = (double *)malloc(dz->tex->phrasecnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for phrase amplitude array.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*phrange  = (double *)malloc(dz->tex->phrasecnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for phrase range array.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*phrlastnote = (noteptr *)malloc(dz->tex->phrasecnt * sizeof(noteptr)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for phrase lastnote array.\n");
-        return(MEMORY_ERROR);
-    }
-    return(FINISHED);
-}
-
-/****************************** GET_FIRST_HS ***********************************
- *
- * Extract HS from input data.
- */
-
-int get_first_hs(noteptr thisnote,double **hs,int *hsnotecnt)
-{
-    int exit_status;
-    int size = BIGARRAY;
-    noteptr startnote = thisnote;
-    double thistime = 0.0;
-    if((*hs = (double *)malloc(BIGARRAY * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic set array.\n");
-        return(MEMORY_ERROR);
-    }
-    while(thisnote!=(noteptr)0) {
-        if((exit_status = gethsnote(thisnote->pitch,*hs,hsnotecnt))<0)
-            return(exit_status);
-        if(thisnote==startnote)
-            thistime = thisnote->ntime;
-        else {
-            if(!flteq((double)thisnote->ntime,thistime)) {
-                (*hsnotecnt)--;
-                break;
-            }
-        }
-        if(*hsnotecnt >= BIGARRAY) {
-            size += BIGARRAY;
-            if((*hs=(double *)realloc((char *)(*hs),size * sizeof(double)))==NULL){
-                sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic set array.\n");
-                return(MEMORY_ERROR);
-            }   
-        }
-        thisnote = thisnote->next;
-    }
-    if((*hs=(double *)realloc((char *)(*hs),*hsnotecnt*sizeof(double)))==NULL){
-        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic set array.\n");
-        return(MEMORY_ERROR);
-    }
-    upsort(*hs,*hsnotecnt);
-    return(FINISHED);
-}
-    
-/****************************** GET_FIRST_HF ***********************************
- *
- * Extract first HF from input data.
- */
-
-int get_first_hf(noteptr thisnote,double **hf,int *hfnotecnt)
-{
-    int exit_status;
-    int size = BIGARRAY;
-    noteptr startnote = thisnote;
-    double thistime = 0.0;
-
-    if((*hf = (double *)malloc(size * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for harmonic field array.\n");
-        return(MEMORY_ERROR);
-    }
-    while(thisnote!=(noteptr)0) {
-        if((exit_status = gethfnote(thisnote->pitch,*hf,hfnotecnt))<0)
-            return(exit_status);
-        if(thisnote==startnote)
-            thistime = thisnote->ntime;
-        else {
-            if(!flteq((double)thisnote->ntime,thistime)) {
-                (*hfnotecnt)--;
-                break;
-            }
-        }
-        if(*hfnotecnt >= size) {
-            size += BIGARRAY;
-            if((*hf = (double *)realloc((char *)(*hf),size * sizeof(double)))==NULL){
-                sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic field array.\n");
-                return(MEMORY_ERROR);
-            }   
-        }
-        thisnote = thisnote->next;
-    }
-    if((*hf=(double *)realloc((char *)(*hf),*hfnotecnt * sizeof(double)))==NULL){
-        sprintf(errstr,"INSUFFICIENT MEMORY to reallocate harmonic field array.\n");
-        return(MEMORY_ERROR);
-    }
-    upsort(*hf,*hfnotecnt);
-    return(FINISHED);
-}
-
-/******************************** OCTEQ *************************************/
-
-int octeq(double a,double b)
-{
-    a = fmod(a,12.0);
-    b = fmod(b,12.0);
-    if(flteq(a,b)) {
-        return(1);
-    }
-    return(0);
-}

+ 0 - 1474
dev/texture/v8/texture4.c

@@ -1,1474 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
- 
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- 
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
- 
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-/* floatsam version : no changes */
-#include <stdio.h>
-#include <stdlib.h>
-#include <float.h>
-#include <structures.h>
-#include <tkglobals.h>
-#include <globcon.h>
-#include <processno.h>
-#include <modeno.h>
-#include <arrays.h>
-#include <texture.h>
-#include <cdpmain.h>
-
-#include <sfsys.h>
-#include <osbind.h>
-
-#if defined unix || defined __GNUC__
-#define round(x) lround((x))
-#endif
-
-/**** ALL FUNCTIONS WHICH ARE GLOBAL TO ALL PROCESS FUNCTIONS TYPES ***/
-
-/* Functions which are global to all texture applications.
- */
-static void orn_subzero(double *thistime,noteptr phrlastnote,noteptr *phrasenote,
-            double *timeadjust,double multiplier,int *gpsize);
-static int  getmtfampstep
-            (double amp,double framp,double *ampstep,unsigned char *amptype,
-            unsigned char amptypestor,unsigned char amptypecnt,int gpsize,dataptr dz);
-static int  space_gpnote(noteptr thisnote,int gpsize,dataptr dz);
-static int  sp_scatter(noteptr mnote,dataptr dz);
-static int  pre_place(noteptr thisnote,int gpsize,dataptr dz);
-static int  post_place(noteptr thisnote,int gpsize,dataptr dz);
-static int  read_direction(int shi,noteptr *shadow,int shadowsize);
-
-static int  do_ev_ins(unsigned char *thisinstr,double thistime,dataptr dz);
-static int  do_ev_amp(double *thisamp,double thistime,dataptr dz);
-static int  do_ev_dur(double *thisdur,double thistime,dataptr dz);
-static int  getdirampstep
-            (double amp,unsigned char amptypecnt,double *ampstep,int gpsize,dataptr dz);
-static int  getampstep
-            (double *ampstep,double amp,unsigned char *amptype,int gpsize,unsigned char amptypecnt,
-            unsigned char amptypestor,dataptr dz);
-static int  get_dec_or_orn_pos(dataptr dz);
- 
-static int  subzero(double *thistime,double gpdense,int *gpsize);
-
-static noteptr reverse_search_for_time(noteptr start,double reftime);
-static void    move_notelist_item(noteptr a,noteptr b);
-static double  setup_first_notelist_time(noteptr *base);
-static int     reset_mtfhead(motifptr mtf);
-static int     post_place(noteptr thisnote,int gpsize,dataptr dz);
-static int     getmtfdirampstep
-            (double amp,double framp,unsigned char amptypecnt,double *ampstep,int gpsize,dataptr dz);
-static void cyclicperm(dataptr dz);
-static void hinsert(int m,int t,int *perm,int permlen);
-static void hprefix(int m,int *perm,int permlen);
-static void hshuflup(int k,int *perm,int permlen);
-
-/***************************** OCTADJUST *****************************
- *
- * Check for range overflow of pitch.
- */
-
-double octadjust(double thispitch)
-{
-    if(thispitch>MIDITOP)
-        thispitch -= SEMITONES_PER_OCTAVE;
-    if(thispitch<MIDIBOT)
-        thispitch += SEMITONES_PER_OCTAVE;
-    return(thispitch);
-}
-
-/***************************** DO_AMP_INSTR_DUR ************************************/
-
-int do_amp_instr_dur
-(double *thisamp,unsigned char *thisinstr,double *thisdur,noteptr tsetnote,double thistime,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = do_ev_amp(thisamp,thistime,dz))<0)
-        return(exit_status);
-    tsetnote->amp = (float)(*thisamp);
-    if((exit_status = do_ev_ins(thisinstr,thistime,dz))<0)
-        return(exit_status);
-    tsetnote->instr = *thisinstr;
-    if((exit_status = do_ev_dur(thisdur,thistime,dz))<0)
-        return(exit_status);
-    tsetnote->dur = (float)(*thisdur);
-    return(FINISHED);
-}
-
-/********************** DO_EV_INS *******************************
- *
- * Set instrument of event (not group etc.).
- *
- * (0)  If instruments in ornament or decoration are to be relative to
- *  input instr, return this input instrument.
- * (1)  If there is a pre-existing timed set (pretimed = 1).
- * (2)  Negative value causes original value to be replaced
- *  by orig + abs(neg value).
- *  Zero value, by default, causes orig value to be retained.
- */
-
-int do_ev_ins(unsigned char *thisinstr,double thistime,dataptr dz)
-{
-    int exit_status;
-    int instrval;
-    if(dz->process == SIMPLE_TEX && dz->vflag[CYCLIC_TEXFLAG]) {
-        if(dz->itemcnt == dz->infilecnt)
-            dz->itemcnt = 0;
-        if(dz->vflag[PERM_TEXFLAG]) {
-            if(dz->itemcnt == 0)
-                cyclicperm(dz);
-            *thisinstr = (unsigned char)dz->peakno[dz->itemcnt];
-        } else {
-            *thisinstr = (unsigned char)dz->itemcnt;
-        }
-        dz->itemcnt++;
-    } else {
-        if((exit_status = igetvalue(TEXTURE_INSHI,TEXTURE_INSLO,thistime,PM_INSNO,&instrval,dz))<0)
-            return(exit_status);
-        *thisinstr = (unsigned char)instrval;
-    }
-    return(FINISHED);
-}
-
-/********************** DO_EV_AMP ********************************/
-
-int do_ev_amp(double *thisamp,double thistime,dataptr dz)
-{  
-    int exit_status;
-    if((exit_status = getvalue(TEXTURE_MAXAMP,TEXTURE_MINAMP,thistime,PM_AMP,thisamp,dz))<0)
-        return(exit_status);
-
-    *thisamp *= dz->param[TEXTURE_ATTEN];
-
-    if(*thisamp>MIDITOP + 0.5) {
-        sprintf(errstr,"TEXTURE: amplitude [%.1f] out of midirange at time %.2f\n",*thisamp,thistime); 
-        return(DATA_ERROR);
-    }
-    return(FINISHED);
-}
-
-/********************** DO_EV_DUR ********************************/
-
-int do_ev_dur(double *thisdur,double thistime,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getvalue(TEXTURE_MAXDUR,TEXTURE_MINDUR,thistime,PM_DUR,thisdur,dz))<0)
-        return(exit_status);
-    return(FINISHED);                   /* 4 */
-}
-
-/************************ MAKE_SHADOW ****************************
- *
- * Store addresses of original tset notes.
- */
-
-int make_shadow(motifptr tset,int *shadowsize,noteptr **shadow)
-{
-    noteptr *sh, thisnote = tset->firstnote;
-    int n;
-    *shadowsize = 0;
-    while(thisnote!=(noteptr)0) {
-        (*shadowsize)++;
-        thisnote = thisnote->next;
-    }
-    if((sh = *shadow = (noteptr *)malloc((*shadowsize) * sizeof(noteptr)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for shadow.\n");
-        return(MEMORY_ERROR);
-    }
-    thisnote = tset->firstnote;
-    n = 0;
-    while(thisnote!=(noteptr)0) {
-        sh[n++]  = thisnote;
-        thisnote = thisnote->next;
-    }
-    return(FINISHED);
-}
-
-/************************ ERASE_SHADOW ****************************
- *
- * Erase original tset from resultant list.
- *
- * (0)  Assuming shadow starts at start of tset, if first note of
- *  shadow is deleted, del_note automatically resets motifptr (tset)
- *  to next note (and so on).
- * (1)  In case shadow started AFTER start of tset (should be impossible!!)
- *  reset pointer to start of remaining motif !
- */
-
-int erase_shadow(int shadowsize,noteptr *shadow,motifptr tset)
-{
-    int n;
-    noteptr thisnote;
-    for(n=0;n<shadowsize;n++)                   /* 0 */
-        del_note(shadow[n],tset);
-    if((thisnote = tset->firstnote->last)!=(noteptr)0) {    /* 1 */
-        sprintf(errstr,"TEXTURE: erase_shadow(): First note of shadow NOT first note of tset.\n"
-                       "This should never happen\n");
-        return(PROGRAM_ERROR);
-    /**** REMOVED FOLLOWING AUTO-CORRECTION CODE : OCT 1997 *****
-        while(thisnote->last!=(noteptr)0)
-            thisnote = thisnote->last;
-        tset->firstnote = thisnote;
-    ****/
-    }
-    return(FINISHED);
-}
-
-/************************ SETUP_DECOR ****************************/
-
-void setup_decor(double *pptop,double *ppbot,int *shadindex,noteptr *tsetnote,dataptr dz)
-{
-    *pptop = MIDITOP; 
-    *ppbot = MIDIBOT;
-    if(dz->vflag[WHICH_CHORDNOTE]==DECOR_HIGHEST)
-        *tsetnote = gethipitch(*tsetnote,shadindex);
-}
-
-/**************************** SETUP_ORNAMENT *********************************/
-
-int setup_ornament
-(double *timeadjust,double *thistime,int *gpsize,noteptr *phrlastnote,
- double multiplier,noteptr *phrasenote,int phrno,dataptr dz)
-{
-    int exit_status;
-    double origtime;
-    if((exit_status = get_dec_or_orn_pos(dz))<0)
-        return(exit_status);
-    *timeadjust = 0.0;
-    if(dz->vflag[IS_PRE]) {
-        origtime = *thistime;
-        if((*thistime -= (phrlastnote[phrno])->ntime * multiplier)<0.0) {
-            *thistime = origtime;
-            orn_subzero(thistime,phrlastnote[phrno],phrasenote,timeadjust,multiplier,gpsize);
-        }
-    }
-    return(FINISHED);
-}
-
-/**************************** SET_MOTIF_AMP *********************************/
-
-int set_motif_amp
-(noteptr tsetnote,double *thisamp,int gpsize,double ampstep,noteptr phrasenote,double rangemult,
-double *phraseamp,int phrno,unsigned char amptype)
-{
-    double ampdif;
-    if(amptype==CRESC) {
-        *thisamp -= (double)(gpsize) * ampstep;
-        ampdif    = (phraseamp[phrno] - phrasenote->amp) * rangemult;
-        tsetnote->amp = (float)(*thisamp - ampdif);
-    }
-    return(FINISHED);
-}
-
-/**************************** SET_ORNAMENT_AMP *********************************/
-
-int set_ornament_amp
-(double *phraseamp,noteptr *phrlastnote,double *thisamp,
-noteptr phrasenote,int phrno,noteptr tsetnote,
-double ampstep,double rangemult,int gpsize,dataptr dz)
-{
-    double ampdif;
-    if(dz->vflag[IS_PRE])
-        ampdif=(phraseamp[phrno]-phrlastnote[phrno]->amp) * rangemult;
-    else
-        ampdif=(phraseamp[phrno]-phrasenote->amp) * rangemult;
-    tsetnote->amp -= (float)ampdif;
-    if(ampstep>0.0) /* CRESCENDO */
-        *thisamp -= (double)(gpsize+1) * ampstep;
-    return(FINISHED);
-}
-
-/**************************** CHECK_NEXT_PHRASENOTE_EXISTS *********************************/
-
-int check_next_phrasenote_exists(noteptr *phrasenote,int texflag,dataptr dz)
-{
-    if(texflag & IS_MOTIFS) {
-        if((*phrasenote = (*phrasenote)->next)==(noteptr)0) {
-            sprintf(errstr,"TEXTURE: Accounting Problem in check_next_phrasenote_exists()\n");
-            return(PROGRAM_ERROR);
-        }
-    } else if (texflag & IS_ORNATE){
-        if(*phrasenote==(noteptr)0) {
-            sprintf(errstr,"TEXTURE: 1st Accounting Problem in check_next_phrasenote_exists()\n");
-            return(PROGRAM_ERROR);
-        }
-        if(dz->vflag[IS_PRE] && ((*phrasenote)->next==(noteptr)0)) {
-            sprintf(errstr,"TEXTURE: 2nd Accounting Problem in check_next_phrasenote_exists()\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    return(CONTINUE);
-}
-
-/************************* GETNEXTEVENT_TO_DECORATE ***************************
- *
- * Get the next event in list, i.e. skip over simultaneous events
- * (e.g. chords).
- *
- * (0)  If flagged as 2, ornaments/decorations are attached to EVERY note
- *  so the next event is just the next note in the tset.
- *  OTHERWISE we search for the next event AT A NEW TIME.
- * (1)  If flagged, force a search for the highest note of a simultaneous
- *  group (chord). Hence ornament/dec attaches to highest note.
- *  Otherwise, ornament attached to first listed note of chord in input
- *  data.
- */
-
-noteptr getnextevent_to_decorate(noteptr tsetnote,int *shaddoindex,dataptr dz)
-{
-    if(dz->vflag[WHICH_CHORDNOTE]==DECOR_EVERY)                     /* 0 */
-        return(tsetnote->next);
-    while(tsetnote->next!=(noteptr)0) {
-        tsetnote = tsetnote->next;
-        (*shaddoindex)++;
-        if(!flteq((double)tsetnote->ntime,(double)tsetnote->last->ntime)) {
-            if(dz->vflag[WHICH_CHORDNOTE]==DECOR_HIGHEST)
-                tsetnote = gethipitch(tsetnote,shaddoindex);    /* 1 */
-            return(tsetnote);
-        }
-    }
-    return((noteptr)0);
-}
-    
-/************************** GETNOTETIME ********************************
- *
- * Get actual time of note, from time of tset note, and time of motif
- * or ornament note.
- * (a)  Time is set by an offset from the tset-note, THROUGHOUT each
- *  motif-placement. The offset for each note is its position in the
- *  original note (which have been set relative to zero by set_mtfs())
- *  times the multiplier, with an adjustment if we're actually using
- *  less than the whole motif for some reason.
- * (b)  Time may need to be quantised.
- * (c)  Time of note is this tset-note + offset.
- */
-
-double getnotetime(noteptr phrasenote,double thistime,double multiplier,double timeadjust,dataptr dz)
-{   
-    int qunits;
-    double timestep = ((double)phrasenote->ntime - timeadjust) * (double)multiplier; /* a */
-    double thisgrid;
-
-    if(dz->param[TEX_PHGRID]>0.0) {  
-/* NEW  2000 */
-        thisgrid = dz->param[TEX_PHGRID] * MS_TO_SECS;
-
-        qunits    = round(timestep/thisgrid);       /* b */
-        timestep  = (double)(qunits*thisgrid);  
-    }
-    return(thistime + timestep);                /* c */
-}
-
-/************************ GETMTFDUR **********************************/
-
-int getmtfdur(noteptr tsetnote,noteptr phrasenote,double *dur,double multiplier,dataptr dz)
-{
-    if(dz->vflag[DONT_KEEP_MTFDUR])
-        *dur = tsetnote->dur;
-    else
-        *dur = phrasenote->dur * multiplier;
-    if(flteq(*dur,0.0)) {
-        sprintf(errstr,"TEXTURE: Problem 3 in getmtfdur(): Zero duration\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/***************************** ORN_OR_MTF_AMP_SETUP ************************************/
-
-int orn_or_mtf_amp_setup
-(int ampdirected,double *phrange,int phrno,double thisamp,int gpsize,double *rangemult,double *ampstep,
-unsigned char *amptype,unsigned char amptypestor,unsigned char amptypecnt,dataptr dz)
-{
-    int exit_status;
-    double kk;
-    if(phrange[phrno]>=thisamp) {
-        kk = (double)phrange[phrno]*((double)(gpsize+1)/(double)gpsize);
-        *rangemult = (double)thisamp / kk;
-        *ampstep   = 0.0;
-    } else {
-        if(ampdirected) {
-            if((exit_status = getmtfdirampstep(thisamp,phrange[phrno],amptypecnt,ampstep,gpsize,dz))<0)
-                return(exit_status);
-        } else {
-            if((exit_status = getmtfampstep(thisamp,phrange[phrno],ampstep,amptype,amptypestor,amptypecnt,gpsize,dz))<0)
-                return(exit_status);
-        }
-        *rangemult = 1.0;
-    }
-    return(FINISHED);
-}
-
-/**************************** DO_MTF_PARAMS *******************************/
-
-int do_mtf_params
-(noteptr thisnote,double thisamp,noteptr phrasenote,noteptr tsetnote,
-double ampdif,double notetime,double multiplier,dataptr dz)
-{
-    int exit_status;
-    double duration;
-    thisnote->amp   = (float)(thisamp - ampdif);
-    if((exit_status = getmtfdur(tsetnote,phrasenote,&duration,multiplier,dz))<0)
-        return(exit_status);
-    thisnote->dur = (float)duration;
-    if((exit_status = do_grp_ins(tsetnote->instr,&(thisnote->instr),dz))<0)
-        return(exit_status);
-    thisnote->motioncentre = tsetnote->motioncentre;
-    thisnote->ntime  = (float)notetime;
-    return(FINISHED);
-}
-
-/***************************** SETUP_MOTIF_OR_ORNAMENT ************************************/
-
-int setup_motif_or_ornament
-(double thistime,double *multiplier,int *phrno,noteptr *phrasenote,motifptr *phrase,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getvalue(TEX_MULTHI,TEX_MULTLO,thistime,PM_MULT,multiplier,dz))<0)
-        return(exit_status);
-    if((exit_status = doperm((int)dz->tex->phrasecnt,PM_WHICH,phrno,dz))<0)
-        return(exit_status);
-    *phrasenote    = phrase[*phrno]->firstnote;
-    return(FINISHED);
-}
-
-/****************************** POSITION_AND_SIZE_DECORATION **********************************/
-
-int position_and_size_decoration
-(double *thistime,double tsettime,double gpdense,int *gpsize,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = get_dec_or_orn_pos(dz))<0)
-        return(exit_status);
-    if(dz->vflag[IS_PRE]) {
-        if((*thistime -= gpdense * (double)((*gpsize) + 1))< -gpdense) {
-            *thistime = tsettime;
-            if((exit_status = subzero(thistime,gpdense,gpsize))<0)
-                return(exit_status);
-        }
-    }
-    return(FINISHED);
-}
-
-/****************************** SET_DECOR_AMP **********************************/
-
-int set_decor_amp
-(int ampdirected,double *thisamp,double *ampstep,int gpsize,
-unsigned char *amptype,unsigned char amptypecnt,unsigned char amptypestor,dataptr dz)
-{
-    int exit_status;
-    if(ampdirected) {
-        if((exit_status = getdirampstep(*thisamp,amptypecnt,ampstep,gpsize,dz))<0)
-            return(exit_status);
-    } else  {
-        if((exit_status = getampstep(ampstep,*thisamp,amptype,gpsize,amptypecnt,amptypestor,dz))<0)
-            return(exit_status);
-    }
-    if(*ampstep>0.0)
-        *thisamp -= (double)(gpsize+1) * (*ampstep);
-    return(FINISHED);
-}
-
-/****************************** SET_GROUP_AMP **********************************/
-
-int set_group_amp
-(noteptr tsetnote,double *thisamp,unsigned char *amptype, double *ampstep,int gpsize,
-unsigned char amptypecnt,unsigned char amptypestor,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getampstep(ampstep,*thisamp,amptype,gpsize,amptypecnt,amptypestor,dz))<0)
-        return(exit_status);
-    if(*amptype==CRESC) {
-        *thisamp -= (double)(gpsize) * (*ampstep);
-        tsetnote->amp = (float)(*thisamp);
-    }
-    return(FINISHED);
-}
-
-/* LOCAL TO THESE GLOBALS */
-
-/****************************** ORN_SUBZERO *******************************
- *
- * Readjust the groupsize and the pointer to first note of phrase, where
- * otherwise phrase would start before zero.
- *
- * (1)  Note the endtime of the phrase.
- * (2)  For each note in the phrase.
- * (3)  Find the duration of the phrase FROM THIS NOTE, by subtracting time of
- *  current note from end (total) time, and adjusting by multiplier.
- * (4)  If the duration of phrase from here, would put it's start after
- *  zero-time, break from loop.
- * (5)  Count number of notes rejected, and go to next phrase note.
- * (6)  If we're at end of phrase, none of it's notes fall after zero time,
- *  so return a gpsize of 0.
- * (7)  Otherwise reset the event time (mifitime) to start of the group or 
- *  part-group which 'thisnote' points to.
- * (8)  Resert the phrase pointer to point at this note of the phrase.
- * (9)  When note times are finally calculated, timeadjust will reset all
- *  the note times WITHIN the ornament to run from the note from
- *  which we're starting, rather than the true start, by subtracting
- *  'timeadjust'.
- * (10) Return a size for the group reduced by the number of rejected notes.
- */
-
-void orn_subzero
-(double *thistime,noteptr phrlastnote,noteptr *phrasenote,double *timeadjust,double multiplier,int *gpsize)
-{
-    double endtime = phrlastnote->ntime;        /* 1 */
-    double phrdur = 0.0;
-    int cnt = 0;
-    noteptr thisnote = *phrasenote;
-    while(thisnote!=(noteptr)0) {               /* 2 */
-        phrdur = (endtime - thisnote->ntime) * multiplier;  /* 3 */
-        if(*thistime - phrdur >= 0.0)           /* 4 */
-            break;
-        cnt++;                                  /* 5 */
-        thisnote = thisnote->next;
-    }
-    if(thisnote==(noteptr)0) {
-        *gpsize = 0;                            /* 6 */
-        return;
-    } else {
-        *thistime -= phrdur;                    /* 7 */
-        *phrasenote = thisnote;                 /* 8 */
-        *timeadjust = thisnote->ntime;          /* 9 */
-    }
-    *gpsize -= cnt;
-    return;                                     /* 10 */
-}
-
-/*************************** GETMTFAMPSTEP ******************************
- *
- * Select flat, cresc or decresc, from available types, for motifs.
- *
- * (0)  If the amplitude is bigger than the size of amprise and the
- *  range of the phrase, taken together, amprise is OK as it is.
- * (00) Otherwise, amprise (set as ampstep at this point) is the amount
- *  of the total amplitude left when the amplitude range of the phrase
- *  has been subtracted. This ensures that no note of the phrase
- *  can possibly end up below zero.
- * (1)  IF the cresc will be from zero, clrzamp is 1, and this makes
- *  the amplitude steps a little smaller, so that 1 of the notes
- *  in sequence cannot be at amplitude zero.
- *  OTHERWISE, clrzamp = 0,  and ampstep is as normal.
- */
-
-int getmtfampstep(double amp,double framp,double *ampstep,unsigned char *amptype,
-unsigned char amptypestor,unsigned char amptypecnt,int gpsize,dataptr dz)
-{
-    int exit_status;
-    int clrzamp = 0;
-    int k;
-    if((exit_status = doperm((int)amptypecnt,PM_GPCNTR,&k,dz))<0)
-        return(exit_status);
-    if((exit_status=gettritype(k,amptypestor,amptype))<0)
-        return(exit_status);
-    if(*amptype==FLAT) {        /**** FLAT *****/
-        *ampstep =0.0;  
-    } else {
-        if(amp>(dz->param[TEX_AMPRISE] + framp)) /* 0 */
-            *ampstep = dz->param[TEX_AMPRISE];
-        else {
-            *ampstep = amp - framp;         /* 00 */
-            clrzamp = 1;
-        }
-        *ampstep /= (double)(gpsize+clrzamp);       /* 1 */
-        if(*amptype==DECRESC)       /** DECRESCENDO **/
-            *ampstep = -(*ampstep);
-    }
-    return(FINISHED);
-}
-
-/************************************************************************
- *
- * Calculating spatial orientation of motifs,groups,ornaments,decorations.
- */
-
-/**************************** SETSPACE *******************************/
-
-int setspace(noteptr tsetnote,noteptr thisnote,int gpsize,dataptr dz)
-{
-    int exit_status;
-    if(dz->iparam[TEX_GPSPACE]!=IS_STILL) {
-        if((exit_status = space_gpnote(thisnote,gpsize,dz))<0)
-            return(exit_status);
-    } else
-        thisnote->spacepos = tsetnote->spacepos;
-    return(FINISHED);
-}
-
-/***************************** SPACE_GPNOTE *******************************
- *
- * (1)  OUTSIDE THE GROUP- OR PHRASE-MAKING LOOP
- *  (a) Need to know gpsize, dectype(is_post?), gpsprange 
- *      (which MUST be +ve!).
- *  (b) Need to run 'init_group_spatialisation()' to establish spinit, & hence
- *      range modifications etc.
- *
- *  Then this will work INSIDE the loop.
- *
- * (1)  NB !!!!! is_pre is defaulted to ZERO. This means that groups
- *  or motifs which CANNOT BE pre- or post- are defaulted to
- *  post (which means the groups start on the tset notes, rather
- *  leading up to them).
- */
-
-int space_gpnote(noteptr thisnote,int gpsize,dataptr dz)
-{
-    int exit_status;
-    if(dz->iparam[TEX_GPSPACE]==IS_SCATTER) {
-        if((exit_status = sp_scatter(thisnote,dz))<0)
-            return(exit_status);
-    } else {
-        if(dz->vflag[IS_PRE]) {             /* 1 */
-            if((exit_status = pre_place(thisnote,gpsize,dz))<0)
-                return(exit_status);
-        } else {
-            if((exit_status = post_place(thisnote,gpsize,dz))<0)
-                return(exit_status);
-        }
-    }
-    dz->iparam[SPINIT] = 0;     /* disable initialisation after first call to group */
-    return(FINISHED);
-}
-
-/**************************** SP_SCATTER *************************
- *
- * scatter group note around position of main event.
- */
-
-int sp_scatter(noteptr mnote,dataptr dz)
-{
-    int exit_status;
-    double sptop = 1.0, spbot= 0.0, hfthissprange,val;
-    if(dz->param[THISSPRANGE]<=0.0) {     
-        mnote->spacepos = (float)dz->param[TPOSITION];
-        return(FINISHED);
-    }
-    if(dz->iparam[SPINIT]) {
-        hfthissprange = dz->param[THISSPRANGE]/(double)2.0;
-        spbot = max((dz->param[TPOSITION] - hfthissprange),0.0);
-        sptop = min((dz->param[TPOSITION] + hfthissprange),1.0);
-        dz->param[THISSPRANGE] = sptop - spbot;
-    }                                   
-    if((exit_status = pscatx(dz->param[THISSPRANGE],spbot,PM_GPSPAC,&val,dz))<0)
-        return(exit_status);
-    mnote->spacepos      = (float)val;
-    return(FINISHED);
-} 
-
-/************** MACROS FOR RANGE REORIENTATIONS AND TRUNCATIONS **************
- *
- *  r = group spatial range     p = position of event
- *  c = centre of motion        d = direction of motion
- *
- * (1)  If position to left  of centre, reverse range.
- * (2)  If position to right of centre, reverse range.
- * (3)  If no motion, zero the range.
- * (4)  If motion is right to left reverse range.
- * (5)  If motion is left to right reverse range.
- * (6)  avoid centre crossing
- * (7)  avoid right-edge crossing
- * (8)  avoid left-edge crossing
- * (9)  avoid edge crossing
- */
-
-#define TURNOUTWARD(r,p,c) if((p)-(c)<0.0)  (r) = -(r);                     /* 1 */
-#define TURNINWARD(r,p,c)  if((p)-(c)>0.0)  (r) = -(r);                     /* 2 */
-#define CHECKSTIL(r,d)     if((d)==0) (r) = 0.0;                            /* 3 */
-#define FOLLOW(r,d)        CHECKSTIL(r,d) else { if((d)<0) (r) = -(r); }    /* 4 */
-#define CONTRARY(r,d)      CHECKSTIL(r,d) else { if((d)>0) (r) = -(r); }    /* 5 */
-#define SET_PRE_INRANGE(r,p,c) if(p<c) r = min(p,r); else r = max(p-1.0,r);
-
-
-#define FREECENTRE(r,p,c)  if((r)>fabs((p)-(c))) (r)=fabs((p)-(c));         /* 6 */
-#define FREEREDGE(r,p)     if((p)+(r)>1.0) (r) = 1.0 - (p);                 /* 7 */
-#define FREELEDGE(r,p)     if((p)+(r)<0.0) (r) = -(p);                      /* 8 */
-#define FREEEDGES(r,p)     if((r)>=0.0) { FREEREDGE((r),(p)) } else { FREELEDGE((r),(p)) }
-                                                                            /* 9 */
-
-#define FREEREDGE_PRE(r,p) if((p)-(r)>1.0) (r) = (p) - 1.0;                 /* 7 */
-#define FREELEDGE_PRE(r,p) if((p)-(r)<0.0) (r) = (p);                       /* 8 */
-#define FREEEDGES_PRE(r,p) if((r)>=0.0) { FREELEDGE_PRE((r),(p)) } else { FREEREDGE_PRE((r),(p)) }
-                                                                            /* 9 */
-/************************* PRE_PLACE *****************************
- *
- * place-in-space ornaments or decorations BEFORE notes, or motifs or groups
- * at texture points.
- *
- * is_pre = 1.
- */
-
-int pre_place(noteptr thisnote,int gpsize,dataptr dz)
-{
-    if(dz->iparam[SPINIT])
-        dz->iparam[SPCNT] = 0;
-
-    switch(dz->iparam[TEX_GPSPACE]) {
-        case(IS_STILL):
-            dz->param[THISSPRANGE] = 0.0;
-            break;
-        case(IS_INWARD):
-            if(dz->iparam[SPINIT]) {
-                TURNINWARD(dz->param[THISSPRANGE],dz->param[TPOSITION],dz->param[CPOS])
-                SET_PRE_INRANGE(dz->param[THISSPRANGE],dz->param[TPOSITION],dz->param[CPOS])
-
-            }
-            break;
-        case(IS_OUTWARD):
-            if(dz->iparam[SPINIT]) {
-                FREECENTRE(dz->param[THISSPRANGE],dz->param[TPOSITION],dz->param[CPOS])
-                TURNOUTWARD(dz->param[THISSPRANGE],dz->param[TPOSITION],dz->param[CPOS])
-            }
-            break;
-        case(IS_FOLLOWING):
-            if(dz->iparam[SPINIT]) {
-                FOLLOW(dz->param[THISSPRANGE],dz->iparam[DIRECTION])
-                FREEEDGES_PRE(dz->param[THISSPRANGE],dz->param[TPOSITION])
-            }
-            break;
-        case(IS_CONTRARY):
-            if(dz->iparam[SPINIT]) {
-                CONTRARY(dz->param[THISSPRANGE],dz->iparam[DIRECTION])
-                FREEEDGES_PRE(dz->param[THISSPRANGE],dz->param[TPOSITION])
-            }
-            break;
-        default:
-        sprintf(errstr,"TEXTURE: Invalid space-type %d in pre_place()\n",dz->iparam[TEX_GPSPACE]);
-        return(PROGRAM_ERROR);
-    }
-    thisnote->spacepos = (float)(dz->param[TPOSITION] - dz->param[THISSPRANGE]
-                     + ((dz->param[THISSPRANGE]/(double)gpsize)*(double)(dz->iparam[SPCNT])));
-    dz->iparam[SPCNT]++;
-    return(FINISHED);
-}
-           
-/************************* POST_PLACE *****************************
- *
- * place-in-space ornaments or decorations AFTER notes, or motifs or groups
- * at texture points.
- *
- * is_pre = 0, (or no ornament). 
- */
-
-int post_place(noteptr thisnote,int gpsize,dataptr dz)
-{
-    if(dz->iparam[SPINIT])
-        dz->iparam[SPCNT] = 1;
-    switch(dz->iparam[TEX_GPSPACE]) {
-    case(IS_STILL):
-        dz->param[THISSPRANGE] = 0.0;
-        break;
-    case(IS_INWARD):
-        if(dz->iparam[SPINIT]) {
-            FREECENTRE(dz->param[THISSPRANGE],dz->param[TPOSITION],dz->param[CPOS])
-            TURNINWARD(dz->param[THISSPRANGE],dz->param[TPOSITION],dz->param[CPOS])
-        }
-        break;
-    case(IS_OUTWARD):
-        if(dz->iparam[SPINIT]) {
-            TURNOUTWARD(dz->param[THISSPRANGE],dz->param[TPOSITION],dz->param[CPOS])
-            FREEEDGES(dz->param[THISSPRANGE],dz->param[TPOSITION])
-        }
-        break;
-    case(IS_FOLLOWING):
-        if(dz->iparam[SPINIT]) {
-            FOLLOW(dz->param[THISSPRANGE],dz->iparam[DIRECTION])
-            FREEEDGES(dz->param[THISSPRANGE],dz->param[TPOSITION])
-        }
-        break;
-    case(IS_CONTRARY):
-        if(dz->iparam[SPINIT]) {
-            CONTRARY(dz->param[THISSPRANGE],dz->iparam[DIRECTION])
-            FREEEDGES(dz->param[THISSPRANGE],dz->param[TPOSITION])
-        }
-        break;
-    default:
-        sprintf(errstr,"TEXTURE: Invalid space-type %d in post_place()\n",dz->iparam[TEX_GPSPACE]);
-        return(PROGRAM_ERROR);
-    }
-    thisnote->spacepos = (float)(dz->param[TPOSITION] + 
-    ((dz->param[THISSPRANGE]/(double)gpsize)*(double)(dz->iparam[SPCNT])));
-    dz->iparam[SPCNT]++;
-
-    return(FINISHED);
-}
-
-/************************** GPSP_INIT ***********************************
- *
- * Initialise the space-param for each group, before calling the spatialise
- * routines. 'spinit' causes initialisation of range etc elsewhere (in
- * pre_place() or post_place() ).
- */
-
-int init_group_spatialisation(noteptr tsetnote,int shaddoindex,noteptr *shadow,int shadowsize,dataptr dz)
-{
-    int exit_status;
-    dz->iparam[SPINIT] = 1;
-    dz->param[TPOSITION] = tsetnote->spacepos;
-    dz->param[CPOS]      = tsetnote->motioncentre;
-    if(dz->brksize[TEX_GRPSPRANGE]) { /* TABLE VALUES MUST BE 0 - 1 */
-        if((exit_status = read_value_from_brktable((double)tsetnote->ntime,TEX_GRPSPRANGE,dz))<0)
-            return(exit_status);
-    }
-    if(IS_DIRECTED(dz->iparam[TEX_GPSPACE]))
-        dz->iparam[DIRECTION] = read_direction(shaddoindex,shadow,shadowsize);
-    dz->param[THISSPRANGE] = dz->param[TEX_GRPSPRANGE];
-    return(FINISHED);
-}
-
-/**************************** READ_DIRECTION ****************************
- *
- * Read direction of motion from spatial position stored in note.
- *
- * NB: as the tset is in the process of being modified, we cannot
- * refer directly to the tset linked list. We can only access the original
- * tset through it's 'shadow'.
- *
- * (0)  Save the time of the current note as 'now'.
- * (1)  Save position of current note as 'here'.
- * (2)  Whilever we're not at the end of the tset (shadow).
- * (a)  Note time of next note, store as 'then'.
- * (b)  If 'then' is later than 'now'.
- *      Note position of new note as 'there'.
- *      Set as OK and break out of loop.
- * (3)  If it's not OK (i.e. we were at, or came to the end of the tset 
- *      (shadow))....
- * (a)  Go back to where we started.
- * (b)  Call this position 'there'.
- * (4)  While ever we're not at beginning of tset...
- * (a)  Note time of previous note, store as 'then'.
- * (b)  If 'then' is 'earlier' than 'now'...
- *      Note position of new note as 'here'.
- *      Set as OK and break out of loop.
- * (5)  If still not OK, then there is no more than 1 (non-simultaneous)
- *      event in the tset, so therefore no motion, so return 0.
- * (6)  If there>here, left-to-right motion, return 1.
- * (7)  If here>there, right-to-left motion, return -1.
- * (8)  Otherwise, no motion, return 0.
- */
-
-int read_direction(int shi,noteptr *shadow,int shadowsize)
-{
-    unsigned char OK;
-    float here, there = 0.0;
-    double now, then;
-    int startshi = shi;
-    now  = (shadow[shi])->ntime;            /* 0 */
-    here = (shadow[shi])->motioncentre;     /* 1 */
-    OK = 0;
-    while(++shi<shadowsize) {           /* 2 */
-        then = (shadow[shi])->ntime;        /* a */
-        if(then>(now+FLTERR)) {         /* b */
-            there = (shadow[shi])->motioncentre;
-            OK = 1;
-            break;
-        }
-    }
-    if(!OK) {                   /* 3 */
-        shi = startshi;             /* a */
-        there = here;               /* b */
-        while(--shi>=0) {           /* 4 */
-            then = (shadow[shi])->ntime;        /* a */
-            if(then<(now-FLTERR)) {     /* b */
-                here = (shadow[shi])->motioncentre;
-                OK = 1;
-                break;
-            }
-        }
-    }       
-    if(!OK)
-        return(0);              /* 5 */
-    if(there>here)              /* 6 */
-        return(1);
-    if(there<here)              /* 7 */
-        return(-1);
-    return(0);                  /* 8 */
-}
-
-/*************************** GETAMPSTEP ******************************
- *
- * Select flat, cresc or decresc, from available types.
- *
- * (1)  IF the cresc will be from zero, clrzamp is 1, and this makes
- *  the amplitude steps a little smaller, so that 1st note in sequence
- *  will not be at amplitude zero.
- *  OTHERWISE, clrzamp = 0,  and ampstep is as normal.
- */
-
-int getampstep
-(double *ampstep,double amp,unsigned char *amptype,int gpsize,unsigned char amptypecnt,
-unsigned char amptypestor,dataptr dz)
-{
-    int exit_status;
-    int clrzamp = 0, k;
-    /*int texflag = dz->tex->txflag;*/
-    if((exit_status = doperm((int)amptypecnt,PM_GPCNTR,&k,dz))<0)
-        return(exit_status);
-    if((exit_status = gettritype(k,amptypestor,amptype))<0)
-        return(exit_status);
-
-    if(*amptype==FLAT)      /**** FLAT *****/
-        *ampstep =0.0;  
-    else {                                                              
-        *ampstep = dz->param[TEX_AMPRISE]; /* param with <|> option */
-                                                                    
-        if(*ampstep>=amp) {                                         
-            clrzamp  = 1;                                           
-            *ampstep = amp;                                         
-        }
-        *ampstep /= (double)(gpsize + clrzamp);     /* 1 */
-        if(*amptype==DECRESC)       /** DECRESCENDO **/
-            *ampstep = -(*ampstep);
-    }
-    return(FINISHED);
-}
-
-/*************************** GETDIRAMPSTEP ******************************
- *
- * (1)  If there are two amplitude types, in THIS CASE, these can only
- *      be DIRECTED or FLAT. So...
- *   (2)  Choose flat or directed via perm.
- *   (3)  and if it's flat, return an ampstep of zero.
- *    Otherwise, we proceed as in the normal case of a directed amp.
- * (4)  Set initial ampstep to amprise.
- * (5)  IF the cresc will be from zero, or decresc to zero,  clrzamp is 1,
- *      and this makes the amplitude steps a little smaller, so that 1st note
- *      of cresc (or last note of decresc) will not be at amplitude zero.
- *      OTHERWISE, clrzamp = 0,  and ampstep is as normal.
- * (6)  Divide ampstep by number of members in group.
- * (7)  If it's a post-ornament, ampstep is negative.
- */
-
-int getdirampstep
-(double amp,unsigned char amptypecnt,double *ampstep,int gpsize,dataptr dz)
-{
-    int exit_status;
-    int k, clrzamp = 0;
-    if(amptypecnt==2) {                                 /* 1 */
-        if((exit_status= doperm((int)2,PM_GPCNTR,&k,dz))<0) /* 2 */
-            return(exit_status);
-        if(k==0) {
-            *ampstep = 0.0;
-            return(FINISHED);                           /* 3 */
-        }
-    }
-    *ampstep = dz->param[TEX_AMPRISE];  /* param with <|> option */             /* 4 */
-    if(*ampstep>=amp) {                                 /* 5 */
-        clrzamp = 1;
-        *ampstep = amp;
-    }
-    *ampstep /= (double)(gpsize + clrzamp);             /* 6 */
-    if(!dz->vflag[IS_PRE])                              /* 7 */
-        *ampstep = -(*ampstep);
-
-    return(FINISHED);
-}
-
-/*************************** GETMTFDIRAMPSTEP *******************************
- *
- *  Intelligent guesswork!! Nov 4: 1997
- */
-
-int getmtfdirampstep(double amp,double framp,unsigned char amptypecnt,double *ampstep,int gpsize,dataptr dz)
-{
-    int exit_status;
-    int k, clrzamp = 0;
-    if(amptypecnt==2) {                                 /* 1 */
-        if((exit_status= doperm((int)2,PM_GPCNTR,&k,dz))<0) /* 2 */
-            return(exit_status);
-        if(k==0) {
-            *ampstep = 0.0;
-            return(FINISHED);                           /* 3 */
-        }
-    }
-    if(amp>(dz->param[TEX_AMPRISE] + framp))
-         *ampstep = dz->param[TEX_AMPRISE];
-    else {
-        *ampstep = amp - framp; 
-        clrzamp = 1;
-    }
-    *ampstep /= (double)(gpsize + clrzamp);             /* 6 */
-    if(!dz->vflag[IS_PRE])                              /* 7 */
-        *ampstep = -(*ampstep);
-
-    return(FINISHED);
-}
-
-/*************************  GET_DEC_OR_ORN_POS ***************************
- *
- * Decuptype flags are selected and shifted down into the range 0-3
- * If its 01 (1), it's a post-ornament, so set 'is_pre' = FALSE.
- * If its 10 (2), it's a pre_ornament,  so set 'is_pre' = TRUE
- * If its 00 (0), it's not set, so we select 'is_pre' at random using doperm on 2 (output 0S or 1).
- *
- * NB: If we are using a group or motif, rather than a decoration
- *  or ornament, is_pre is BY DEFAULT set to 0.
- */
-
-int get_dec_or_orn_pos(dataptr dz)
-{
-    int exit_status;
-    int k;
-    unsigned int dectype = dz->tex->txflag & GET_DECORNPOS;
-    switch(dectype) {
-    case(1): dz->vflag[IS_PRE] = TRUE;  break;
-    case(2): dz->vflag[IS_PRE] = FALSE; break;
-    default:
-        if((exit_status = doperm((int)2,PM_ORNPOS,&k,dz))<0)
-            return(exit_status);
-        dz->vflag[IS_PRE] = (char)k;        
-        break;
-    }
-    if(dz->vflag[IS_PRE] > 1) {
-        sprintf(errstr,"Error from perm in  get_dec_or_orn_pos()\n");
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/**************************** SUBZERO ***********************************
- *
- * If start of a decoration falls before time zero, adjust its size
- * and hence starttime(-minus-gpdense) appropriately.
- */
-
-int subzero(double *thistime,double gpdense,int *gpsize)
-{
-    int n = -1;
-    while(*thistime>=0.0) {
-        *thistime -= gpdense;
-        n++;
-    }
-    if(n<0) {
-        sprintf(errstr,"TEXTURE: Problem in subzero()\n");
-        return(PROGRAM_ERROR);
-    }
-    *gpsize = n;
-    return(FINISHED);
-}
-
-/*************************** GETHIPITCH *********************************#
- *
- * Find highest pitch at current time.
- */
-
-noteptr gethipitch(noteptr tsetnote,int *shaddoindex)
-{
-    noteptr hinote, thisnote;
-    double hipitch;
-    int zz = *shaddoindex;
-    hinote = thisnote = tsetnote;
-    hipitch = (double)hinote->pitch;
-    while(thisnote->next!=(noteptr)0) {
-        if(thisnote->next->ntime > thisnote->ntime + FLTERR)
-            return(hinote);
-        thisnote = thisnote->next;
-        zz++;
-        if((double)thisnote->pitch > hipitch) {
-            hipitch = (double)thisnote->pitch;
-            hinote  = thisnote;
-            (*shaddoindex) = zz;
-        }
-    }
-    return(hinote);
-}
-
-/****************************** DO_GRP_INS **********************************
- *
- * Choose instr-no within group/decoration/motif or ornament.
- * Values of instr-no range are preset when instr is chosen for the
- * tset, in do_ev_ins().
- */
-
-int do_grp_ins(unsigned char thisinstr,unsigned char *val,dataptr dz)
-{
-    int exit_status;
-    int irange, ival;
-    if(dz->vflag[INS_TO_SCATTER]) {
-        if((irange = (int)(dz->iparam[TEXTURE_INSHI] - dz->iparam[TEXTURE_INSLO])) < 0) {
-            iswap((int *)&(dz->iparam[TEXTURE_INSHI]),(int *)&(dz->iparam[TEXTURE_INSLO]));
-            irange = -irange;
-        }
-        if(irange==0)
-            *val = (unsigned char)dz->iparam[TEXTURE_INSLO];
-        else {
-            if((exit_status = doperm(irange+1,PM_INSNO,&ival,dz))<0)    /* range INCLUSIVE for ints */
-                return(exit_status);
-            *val = (unsigned char)(ival + dz->iparam[TEXTURE_INSLO]);
-        }
-    } else
-        *val = thisinstr;
-    return(FINISHED);
-}
-
-/***************************** PSCATX ************************************
- *
- * Select a random value within 'range', by permuting one of BANDCNT equal
- * ranges, and selecting a random value within the chosen range.
- */
-
-int pscatx(double range,double bottom,int pindex,double *val,dataptr dz)
-{
-    int k, exit_status;
-    double bandwidth, bandbottom, x;
-    if((exit_status = doperm((int)BANDCNT,pindex,&k,dz))<0)
-        return(exit_status);
-    bandwidth   = range/(double)BANDCNT;
-    bandbottom  = (double)k * bandwidth;
-    x  = (drand48() * bandwidth);
-    x += bandbottom;
-    *val = x + bottom;
-    return(FINISHED);
-}
-
-/*************************** DEL_NOTE ************************************/
-
-void del_note(noteptr thisnote,motifptr thismotif)
-{
-    if(thisnote->next!=(noteptr)0)
-        thisnote->next->last = thisnote->last;      /* 1 */
-    if(thisnote->last!=(noteptr)0)
-        thisnote->last->next = thisnote->next;      /* 2 */
-    else
-        thismotif->firstnote = thisnote->next;      /* 3 */
-    free(thisnote);                 /* 4 */
-}
-    
-/************************** TIMESORT ****************************
- *
- * Timesorts notes in a list
- *
- * (1)  Move the item with earliest time to start of list, and set this
- *      (minimum) time as maximum time also.
- *  For each item in the list....
- *   (2)   If this item is earlier than current latest item (maxtime)..
- *     (3)    Find where it should be in the list.
- *     (4)    move it to that location.
- *   (5)   Otherwise, set this item's time as latest time(maxtime).
- * (6)  Reset motifhead to start of notelist!!
- */
-
-int arrange_notes_in_timeorder(motifptr mtf)
-{
-    noteptr base, here, there, mark;
-    double thistime, maxtime;
-    if((base = mtf->firstnote)==(noteptr)0)
-        return(FINISHED);
-    maxtime = setup_first_notelist_time(&base);         /* 1 */
-    here = base;
-    while(here!=(noteptr)0) {
-        if((thistime = here->ntime) < maxtime) {        /* 2 */
-            if((mark = here->last)==(noteptr)0) {
-                sprintf(errstr,"Problem (1) in arrange_notes_in_timeorder()\n");
-                return(PROGRAM_ERROR);
-            }
-            if((there = reverse_search_for_time(here,thistime))==(noteptr)0) {
-                sprintf(errstr,"Timing problem in arrange_notes_in_timeorder()\n");
-                return(PROGRAM_ERROR);
-            }                       /* 3 */
-            move_notelist_item(here,there);         /* 4 */
-            here = mark;
-        } else
-            maxtime = here->ntime;          /* 5 */
-        here = here->next;
-    }
-    return reset_mtfhead(mtf);                  /* 6 */
-}
-
-/************************* RESET_MTFHEAD ***************************
- *
- * Reset pointer to start of notelist.
- */
- 
-int reset_mtfhead(motifptr mtf)
-{
-    noteptr here = mtf->firstnote;
-    if(mtf->firstnote==NULL) {
-        sprintf(errstr,"Problem in reset_mrfhead()\n");
-        return(PROGRAM_ERROR);
-    }
-    while(here->last!=(noteptr)0)
-        here = here->last;
-    mtf->firstnote = here;
-
-    return(FINISHED);
-}
-
-/************************** SETUP_FIRST_NOTELIST_TIME ***************************
- *
- * Put the earliest timed item in a list of notes into start of list.
- */
-
-double setup_first_notelist_time(noteptr *base)
-{
-    noteptr firstnote, here;
-    double  mintime, thistime;
-    firstnote = here = *base;
-    mintime   = (*base)->ntime;
-    while(here!=(noteptr)0) {
-        if((thistime = here->ntime)<mintime) {
-            firstnote = here;
-            mintime = thistime;
-        }
-        here = here->next;
-    }
-    if(firstnote!=(*base)) {
-        move_notelist_item(firstnote,(*base));
-        *base = firstnote;
-    }
-    return(mintime);
-}
-
-/************************* MOVE_NOTELIST_ITEM ***************************
- *
- * Move an item in a notelist from location a to BEFORE location b.
- */
-
-void move_notelist_item(noteptr a,noteptr b)
-{
-    if(a->last!=(noteptr)0)
-        a->last->next = a->next;
-    if(a->next!=(noteptr)0)
-        a->next->last = a->last;
-    a->next = b;
-    a->last = b->last;
-    if(b->last!=(noteptr)0)
-        b->last->next = a;
-    b->last = a;
-}
-
-/************************** REVERSE_SEARCH_FOR_TIME *****************************
- *
- * Reverse search note-list using a time as index, and return address
- * of note whose time is AFTER the input time. 
- * WILL RETURN (noteptr)0 IF REFTIME IS OFF END OF LIST.
- */
-
-noteptr reverse_search_for_time(noteptr start,double reftime)
-{
-    noteptr here = start;
-    while(here->ntime >= reftime) {
-        if(here->last == (noteptr)0)
-            return(here);
-        here = here->last;
-    }
-    return(here->next); 
-}
-
-/************************** ISWAP *****************************/
-
-void iswap(int *a,int *b)
-{
-    int temp;
-    temp = *a;
-    *a = *b;
-    *b = temp;
-}
-
-/****************************** SET_GROUP_PARAMS **********************************/
-
-int set_group_params
-(noteptr tsetnote,noteptr thisnote,double gpdense,double ampstep,double *thisamp,double *thistime,double thisdur,dataptr dz)
-{
-    int exit_status;
-    double thisgpdense, time_left;
-    *thisamp += ampstep;
-    thisnote->amp   = (float)*thisamp;
-    thisnote->dur   = (float)thisdur;
-    if(dz->vflag[FIXED_STEP])
-        *thistime += gpdense;
-    else {
-        if((exit_status = get_density_val(*thistime,&thisgpdense,dz))<0)
-            return(exit_status);
-        if((dz->tex->txflag & IS_DECOR) && dz->vflag[IS_PRE]) {
-            if((time_left = tsetnote->ntime - *thistime)<0.0) {
-                sprintf(errstr,"Error in assumptions: set_group_params()\n");
-                return(PROGRAM_ERROR);
-            }
-            time_left *= 0.66;
-            thisgpdense = min(time_left,thisgpdense);
-        }
-        *thistime += thisgpdense;
-    }
-    return(FINISHED);
-}
-
-/***************************** GETTRITYPE *****************************
- *
- * Choose a type, from up to three available types in bit-flag.
- * e.g.
- * Choose an amplitude type (flat,cresc,decresc) from 3 available types.
- * Choose a decoration-orientation type (above,below,mid) from 3 types.
- *
- * (1)  For each type in the bitflag.
- * (2)  If this option is flagged, count it.
- * (3)  IF this option is chosen, return its bit-number.
- * (4)  Advance the bitflag mask.
- */
-
-int gettritype(int k,unsigned stor,unsigned char *val)
-{
-    int v = 0, mask = 1, n;
-    k++;
-    for(n=0;n<3;n++) {              /* 1 */
-        if(mask & stor)             /* 2 */
-            v++;
-        if(k==v) {              /* 3 */
-            *val = (unsigned char)n;
-            return(FINISHED);
-        }
-        mask <<= 1;             /* 4 */
-    }
-    sprintf(errstr,"TEXTURE: Problem in gettritype()\n");
-    return(PROGRAM_ERROR);
-}
-
-/***************************  GET_DENSITY_VAL ******************************/
-
-int get_density_val(double thistime,double *gpdense,dataptr dz)
-{
-    int exit_status;
-    if((exit_status = getvalue(TEX_GPPACKHI,TEX_GPPACKLO,thistime,PM_GPDENS,gpdense,dz))<0)
-        return(PROGRAM_ERROR);
-
-/* NEW MAR 2000 */
-    *gpdense *= MS_TO_SECS;
-
-    if(dz->param[TEX_PHGRID]>0.0)
-        *gpdense = quantise(*gpdense,dz->param[TEX_PHGRID]);
-
-    return FINISHED;
-}
-
-/**************************** SET_MOTIFS *******************************
- *
- * initialise all parameters of input motifs to be used for MOTIFS or
- * ORNAMENTS.
- *
- * (1)For each input motif (called a 'phrase').
- *    phrnotecnt[n] = 0;
- * (2)  Initialise count of number of notes to 0, maximum amplitude
- *  of phrase to 0.0, and lowest pitch to MIDITOP.
- * (3)  Go through each note of the motif.
- * (4)  Add up the number of notes in it.
- * (5)  Find it's lowest pitch.
- * (6)  Find it's loudest note (and set as phraseamp).
- * (7)  Establish dynamic range of phrase.
- * (8)  Transpose the motif into it's lowest possible register.
- * (9)  Ensure motif starts at zero time.
- * (10) Store addresses of last notes in phrases.
- */
-
-int set_motifs
-(int phrcount,motifptr *phrase,int *phrnotecnt,double *phraseamp,double *phrange,noteptr *phrlastnote)
-{
-    int exit_status;
-    int n;
-    double minpitch, mintime, minamp;
-    noteptr thisnote, lastnote = (noteptr)0;
-    for(n=0;n<phrcount;n++) {                       /* 1 */
-        if((exit_status = arrange_notes_in_timeorder(phrase[n]))<0)
-            return(exit_status);
-        phrnotecnt[n] = 0;
-        phraseamp[n] = 0.0;                         /* 2 */
-        minamp   = DBL_MAX;
-        minpitch = MIDITOP;
-        mintime  = DBL_MAX;
-        thisnote = phrase[n]->firstnote;            /* 3 */
-        while(thisnote!=(noteptr)0) {
-            phrnotecnt[n]++;                            /* 4 */
-            if(thisnote->pitch<minpitch)
-                minpitch = thisnote->pitch;         /* 5 */
-            if(thisnote->ntime<mintime)
-                mintime  = thisnote->ntime;         /* 5 */
-            if((double)thisnote->amp>phraseamp[n])
-                phraseamp[n] = (double)thisnote->amp;/* 6 */
-            if(thisnote->amp<minamp)
-                minamp = thisnote->amp;             /* 6 */
-            thisnote = thisnote->next;
-        }
-        if(minamp  == DBL_MAX || mintime == DBL_MAX) {
-            sprintf(errstr,"Error parsing motif: set_motifs()\n");
-            return(PROGRAM_ERROR);
-        }
-        thisnote = phrase[n]->firstnote;
-        phrange[n] = phraseamp[n] - minamp;         /* 7 */
-        while(thisnote!=(noteptr)0) {
-            thisnote->pitch = (float)(thisnote->pitch - (minpitch + MIDIBOT));  /* 8 */
-            thisnote->ntime = (float)(thisnote->ntime - mintime);               /* 9 */
-            lastnote = thisnote;                                                /* 10 */
-            thisnote = thisnote->next;
-        }
-        if((phrlastnote[n] = lastnote) == (noteptr)0) {
-            sprintf(errstr,"Zero length phrase encountered: set_motifs()\n");
-            return(PROGRAM_ERROR);
-        }
-    }
-    return(FINISHED);
-}
-
-void cyclicperm(dataptr dz) 
-{
-    int n, t;
-    do {
-        for(n=0;n<dz->infilecnt;n++) {
-            t = (int)floor(drand48() * (n+1));
-            if(t==n) {
-                hprefix(n,dz->peakno,dz->infilecnt);
-            } else {
-                hinsert(n,t,dz->peakno,dz->infilecnt);
-            }
-        }
-    } while(dz->peakno[0] == dz->lastpeakno[dz->infilecnt - 1]);    // Avoid repetitions at perm boundaries.
-    for(n=0;n<dz->infilecnt;n++)
-        dz->lastpeakno[n] = dz->peakno[n];
-}
-
-void hinsert(int m,int t,int *perm,int permlen)
-{
-    hshuflup(t+1,perm,permlen);
-    perm[t+1] = m;
-}
-
-void hprefix(int m,int *perm,int permlen)
-{
-    hshuflup(0,perm,permlen);
-    perm[0] = m;
-}
-
-void hshuflup(int k,int *perm,int permlen)
-{
-    int n, *i;
-    int z = permlen - 1;
-    i = perm+z;
-    for(n = z;n > k;n--) {
-        *i = *(i-1);
-        i--;
-    }
-}
-
-#ifndef round
-
-int round(double a)
-{
-    return (int)floor(a + 0.5);
-}
-#endif

+ 0 - 627
dev/texture/v8/texture5.c

@@ -1,627 +0,0 @@
-/*
- * Copyright (c) 1983-2013 Trevor Wishart and Composers Desktop Project Ltd
- * http://www.trevorwishart.co.uk
- * http://www.composersdesktop.com
- *
- This file is part of the CDP System.
- 
- The CDP System is free software; you can redistribute it
- and/or modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- 
- The CDP System is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Lesser General Public License for more details.
- 
- You should have received a copy of the GNU Lesser General Public
- License along with the CDP System; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA
- *
- */
-/* floatsam version */
-#include <stdio.h>
-#include <stdlib.h>
-#include <memory.h>         /*RWD*/
-#include <structures.h>
-#include <tkglobals.h>
-#include <globcon.h>
-#include <processno.h>
-#include <modeno.h>
-#include <arrays.h>
-#include <texture.h>
-#include <cdpmain.h>
-
-#include <sfsys.h>
-#ifdef _DEBUG
-#include <assert.h>
-#endif
-
-#if defined unix || defined __GNUC__
-#define round(x) lround((x))
-#endif
-
-static int setup_splice(int st_splicecnt,double **splicebuf);
-static int generate_origdur_and_frq(double **origdur,double **origfrq,dataptr dz);
-static int init_soundout_set(sndoutptr *sndout);
-static int replace_tset_by_soundout_set(noteptr thisnote,sndoutptr *sndout,
-            double *origdur,double *origfrq,double  mindur,int st_splicecnt,dataptr dz);
-static int convert_tsetnote_to_sndout_item(noteptr thisnote,sndoutptr sndout,
-            double *origdur,double *origfrq,double mindur,int st_splicecnt,int *warning_set,dataptr dz);
-static int generate_previous_sndout(sndoutptr *sndout);
-static int get_thisdur(double *thisdur,noteptr thisnote,int thisins,
-            double *origdur,double inv_trnsp,double mindur,dataptr dz);
-static int get_stereospace_compensation(double position,double *compensate);
-
-static int do_mix(sndoutptr sndout,double *splicebuf,dataptr dz);
-static int check_sequencing(sndoutptr sndout);
-static int add_samples_to_outbuf_from_inbuf(int *out_of_insamples,int * max_samp_written,
-            sndoutptr sndout,double *splicebuf,int splicelen,/*int*/float *lbuf,dataptr dz);
-static void unlink_sndoutptr_at_start_of_list(sndoutptr sndout);
-static void unlink_sndoutptr(sndoutptr sndout);
-static double get_interpd_value(unsigned int here,double ibufpos,sndoutptr sndout);
-static int  free_first_sndout(sndoutptr *sndout);
-
-//TW UPDATE 2002: to make texture from stereo sources (updated to flotsams)
-static int add_stereo_samples_to_outbuf_from_inbuf
-(int *out_of_insamples,int *max_samp_written,sndoutptr sndout,double *splicebuf,int splicelen,float *lbuffer,dataptr dz);
-static double get_interpd_value_stereo(unsigned int here,double ibufpos,double *chanval2,sndoutptr sndout);
-
-/**************************** PRODUCE_TEXTURE_SOUND *****************************/
-
-int produce_texture_sound(dataptr dz)
-{
-    int exit_status;
-    /*insamptr  *insound = dz->tex->insnd;*/
-    motifptr  tset     = dz->tex->timeset;
-    sndoutptr sndout;
-    noteptr   thisnote = tset->firstnote;
-    double *origdur, *origfrq, *splicebuf;
-    double mindur = (dz->frametime + TEXTURE_SAFETY) * MS_TO_SECS;
-    int st_splicecnt = round((dz->frametime * MS_TO_SECS) * dz->infile->srate);
-#ifdef MINDUR_OVERRIDE
-    mindur = 0.0;
-    st_splicecnt = 0;
-#endif
-    if((exit_status = setup_splice(st_splicecnt,&splicebuf))<0)
-        return(exit_status);
-    if((exit_status = generate_origdur_and_frq(&origdur,&origfrq,dz))<0)
-        return(exit_status);
-    if((exit_status = init_soundout_set(&sndout))<0)
-        return(exit_status);
-    if((exit_status = replace_tset_by_soundout_set(thisnote,&sndout,origdur,origfrq,mindur,st_splicecnt,dz))<0)
-        return(exit_status);
-    free(origdur);
-    free(origfrq);
-    return do_mix(sndout,splicebuf,dz);
-} 
-
-/************************** SETUP_SPLICE ************************/
-
-int setup_splice(int st_splicecnt,double **splicebuf)
-{
-    int n, m;
-    if((*splicebuf = (double *)malloc(st_splicecnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for splice buffer.\n");
-        return(MEMORY_ERROR);
-    }
-    for(m=0,n=st_splicecnt-1; n>=0; n--,m++)
-        (*splicebuf)[m] = (double)n/(double)st_splicecnt;
-    return(FINISHED);
-}
-
-/************************** GENERATE_ORIGDUR_AND_FRQ ************************/
-
-int generate_origdur_and_frq(double **origdur,double **origfrq,dataptr dz)
-{
-    int n;
-    if((*origdur = (double *)malloc(dz->infilecnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY to store original durations.\n");
-        return(MEMORY_ERROR);
-    }
-    if((*origfrq = (double *)malloc(dz->infilecnt * sizeof(double)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY to store original frqs.\n");
-        return(MEMORY_ERROR);
-    }
-    for(n=0;n <dz->infilecnt;n++) {
-//TW UPDATE: Now allowing stereo sources to be used to make texture
-        (*origdur)[n] = (double)dz->insams[n]/(double)dz->infile->channels/(double)dz->infile->srate;
-        (*origfrq)[n] = miditohz(((dz->tex->insnd)[n])->pitch);
-    }
-    return(FINISHED);
-}
-
-/************************** INIT_SOUNDOUT_SET ************************/
-
-int init_soundout_set(sndoutptr *sndout)
-{
-    if((*sndout = (sndoutptr)malloc(sizeof(struct soundout)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for soundout pointers.\n");
-        return(MEMORY_ERROR);
-    }
-    (*sndout)->last = (sndoutptr)0;
-    (*sndout)->next = (sndoutptr)0;
-    return(FINISHED);
-}
-
-/************************** REPLACE_TSET_BY_SOUNDOUT_SET ************************/
-
-int replace_tset_by_soundout_set
-(noteptr thisnote,sndoutptr *sndout,double *origdur,double *origfrq,double  mindur,int st_splicecnt,dataptr dz)
-{
-    int exit_status;
-    int warning_set = FALSE;
-    while((thisnote->next)!=(noteptr)0) /* go to end of tset */
-        thisnote = thisnote->next;
-    while(thisnote!=(noteptr)0) {
-        if((exit_status = convert_tsetnote_to_sndout_item
-        (thisnote,*sndout,origdur,origfrq,mindur,st_splicecnt,&warning_set,dz))<0)
-            return(exit_status);
-        if((exit_status = generate_previous_sndout(sndout))<0)
-            return(exit_status);
-        if(thisnote->last!=NULL) {
-            thisnote = thisnote->last;      /* free tset from end backwards */
-            free(thisnote->next);   
-        } else {
-            free(thisnote);
-            if((exit_status = free_first_sndout(sndout))<0) 
-                return(exit_status);
-            thisnote = NULL;
-        }
-    }
-    return(FINISHED);
-}
-
-/************************** CONVERT_TSETNOTE_TO_SNDOUT_ITEM ************************/
-
-//TW "STEREO" defined in globcon.h
-#define MAXGAIN (1.0)
-
-int convert_tsetnote_to_sndout_item
-(noteptr thisnote,sndoutptr sndout,double *origdur,double *origfrq,double mindur,int st_splicecnt,int *warning_set,dataptr dz)
-{
-    int exit_status;
-    int thisins;
-    unsigned int insampcnt, st_osampcnt;
-    double indur;
-    double thisfrq,thisdur,trnspstep,inv_trnsp,thisamp,thispos,compensate;
-
-    thisins   = thisnote->instr;
-    thisfrq   = miditohz((double)thisnote->pitch);
-    trnspstep = thisfrq/origfrq[thisins];
-    inv_trnsp = 1.0/trnspstep;
-    if((exit_status = get_thisdur(&thisdur,thisnote,thisins,origdur,inv_trnsp,mindur,dz))<0)
-        return(exit_status);
-    indur       = thisdur * trnspstep;
-//TW UPDATE now counting either mono samples or pairs-of-stereo-sample pairs (as with st_osampcnt) as possibly using stereo input
-    insampcnt   = min(dz->insams[thisins]/dz->infile->channels,round(indur * (double)dz->infile->srate));       
-    st_osampcnt = round((double)insampcnt * inv_trnsp);     
-    if(st_osampcnt <= (unsigned int)st_splicecnt) {
-        sprintf(errstr,"Error in samplecount calculations: convert_tsetnote_to_sndout_item()\n");
-        return(PROGRAM_ERROR);
-    }
-    thisamp   = thisnote->amp/(double)MIDITOP;
-    thispos   = thisnote->spacepos;
-    if((exit_status = get_stereospace_compensation(thispos,&compensate))<0)
-        return(exit_status);
-    if(thisamp > MAXGAIN) {
-#ifdef _DEBUG
-        assert(thisamp <= MAXGAIN);
-#endif
-        if(!(*warning_set)) {
-            fprintf(stdout,"WARNING: one or more events exceed max level. Adjusted.\n");
-            fflush(stdout);
-            *warning_set = TRUE;
-        }
-        thisamp = MAXGAIN;
-    }
-    sndout->inbuf       = ((dz->tex->insnd)[thisins])->buffer;
-    sndout->ibufcnt     = insampcnt;
-    sndout->st_sstttime = round(thisnote->ntime * dz->infile->srate);
-    sndout->st_sendtime = sndout->st_sstttime + st_osampcnt; /* Redundant variable: might need if func revised */
-    sndout->st_splicpos = sndout->st_sendtime - st_splicecnt;
-    sndout->ibufpos     = 0.0;
-    sndout->step        = trnspstep;
-//TW UPDATE: in stereo-input case, only 1 gain value used, as no spatialisation takes place
-    if(dz->infile->channels==STEREO) {
-        sndout->lgain       = thisamp;
-    } else {
-        sndout->lgain       = thisamp * (1.0 - thispos) * compensate;
-        sndout->rgain       = thisamp * thispos * compensate;
-    }
-    return(FINISHED);
-}
-
-/************************** GENERATE_PREVIOUS_SNDOUT ************************/
-
-int generate_previous_sndout(sndoutptr *sndout)
-{
-    sndoutptr new;
-    if((new = (sndoutptr)malloc(sizeof(struct soundout)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for new soundout pointers.\n");
-        return(MEMORY_ERROR);
-    }
-    new->last     = (sndoutptr)0;
-    new->next     = *sndout;
-    (*sndout)->last = new;
-    *sndout = new;
-    return(FINISHED);
-}
-
-/************************** FREE_FIRST_SNDOUT ************************/
-
-int free_first_sndout(sndoutptr *sndout)
-{
-    if((*sndout = (*sndout)->next)==NULL) {
-        sprintf(errstr,"Problem in free_first_sndout()\n");
-        return(PROGRAM_ERROR);
-    }
-    free((*sndout)->last);
-    (*sndout)->last = NULL;
-    return(FINISHED);
-}
-
-/************************** GET_THISDUR ************************/
-
-int get_thisdur
-(double *thisdur,noteptr thisnote,int thisins,double *origdur,double inv_trnsp,double mindur,dataptr dz)
-{
-    double transposed_dur = origdur[thisins] * inv_trnsp;
-    *thisdur   = thisnote->dur;
-    if(*thisdur>transposed_dur)         
-        *thisdur = transposed_dur;
-    else if(dz->vflag[TEX_IGNORE_DUR])
-        *thisdur = transposed_dur;
-    if(*thisdur<mindur) {
-        sprintf(errstr,
-        "too short dur generated (%lf : mindur = %lf): get_thisdur()\n",*thisdur,mindur);
-        return(PROGRAM_ERROR);
-    }
-    return(FINISHED);
-}
-
-/************************** GET_STEREOSPACE_COMPENSATION ************************
- *
- * 1)   comp(ensation) is a factor which compensates for the apparent
- *      loss of perceived amplitude as a sound moves out of the absolute
- *      left or absolute right position (sound from a single loudspeaker)
- *      by simple linear interpolation. 
- *      At first we define comp to vary LINERALY from 0.0 at L or R,
- *      to 1.0 in centre.
- * 2)   NONLIN makes this varation nonlinear, but smooth at the centre, and
- *      still between 0.0 and 1.0
- * 3)   As a signal of fixed perceived level moves from left to right (or v.v.)
- *      we wish to boost the amplitude from each loudspeaker somewhat,
- *      using a curve of the shape now defined.
- *      The maximum possible amplitude is 1.0. To define how much we should
- *      boost amplitude at any point on the L-R axis, we need to define
- *      a ratio (MAXBOOST) with which to multiply the signal.
- *      Multiplying comp-curve by this, defines a curve of amplitude-boosting values.
- * 4)   1.0 is now added to this curve, to give a multiplier of amplitude at
- *      each point along the left-right axis.
- *      And MAXBOOST is subtracted, so that the level 
- *      from each loudspeaker when at maximum boost cannot exceed
- *      MAXGAIN (1.0).
- */
-
-#define NONLIN   (0.5)
-#define MAXBOOST (0.25)
-
-int get_stereospace_compensation(double position,double *compensate)
-{
-    double comp = 1.0 - (fabs((position * (double)2.0) - (double)1.0));     /* 9a */
-    comp = pow(comp,NONLIN);            /* 9b */
-    comp *= MAXBOOST;                   /* 9c */
-    comp += (1.0 - MAXBOOST);           /* 9d */
-    *compensate = comp;
-    return(FINISHED);
-}
-
-/************************** DO_MIX ************************
- *
- * 1)   Position, in stereo-samples, of start-of-splice in this-sndout-struct =  
- *          sndout->st_splicpos
- *      Position in actual-samples of ditto = 
- *           sndout->st_splicpos * STEREO
- *      Position relative to start of current buffer = 
- *          (sndout->st_splicpos * STEREO) - (obufcnt * dz->buflen);
- *      Same position expressed relative to start-of-splice (so that value 0 = start_of_splice) = 
- *          -((sndout->st_splicpos * STEREO) - (obufcnt * dz->buflen));
- */
-
-int do_mix(sndoutptr sndout,double *splicebuf,dataptr dz)
-{
-    int exit_status;
-    int out_of_insamples;
-    /*unsigned int totaltime = 0;*/
-    int max_samp_written, n;
-    unsigned long this_sampend, obufcnt = 0;
-    long splicelen = round((dz->frametime * MS_TO_SECS) * dz->infile->srate) * STEREO;
-    sndoutptr startsnd = sndout, endsnd = sndout;
-    /*int*/float *lbuf;
-//TW UPDATE handles stereo input files
-    int is_stereo = 0;
-#ifdef MINDUR_OVERRIDE
-    splicelen = 0;
-#endif
-    if(dz->infile->channels == STEREO)
-        is_stereo = 1;
-//TW MOVED from texprepro
-    dz->infile->channels = STEREO;  /* for output time calculations */
-    if((exit_status = create_sized_outfile(dz->outfilename,dz))<0)
-        return(exit_status);
-
-    if((lbuf = (float *)malloc(dz->buflen * sizeof(float)))==NULL) {
-        sprintf(errstr,"INSUFFICIENT MEMORY for mixing buffers.\n");
-        return(MEMORY_ERROR);
-    }
-    dz->sbufptr[0] = dz->sampbuf[0];
-/* <--SAFETY CHECK */
-    if((exit_status = check_sequencing(sndout))<0)
-        return(exit_status);
-/* SAFETY CHECK--> */
-    while(startsnd != NULL) {                                       /* until we reach end of event list */
-        this_sampend = (obufcnt+1) * dz->buflen;        /* get absolute samplecnt of end of current buf */
-                                                     /* look for NEW events starting during this outbuf */
-        if(sndout!=NULL) {
-            while(sndout->st_sstttime * STEREO < this_sampend) {     
-                sndout->obufpos  = (sndout->st_sstttime * STEREO) % dz->buflen;/* obufptr for new event */
-                sndout->st_splicpos = (sndout->st_splicpos * STEREO)-(obufcnt * dz->buflen);/* NOTE1 abv*/
-                sndout->st_splicpos = -(sndout->st_splicpos);                           /* NOTE 1 above */
-                sndout = sndout->next;
-                endsnd = sndout;                      /* update the endmarker of the active events list */
-                if(endsnd == NULL)                                      /* if all events finished,break */
-                    break;
-            }
-        }
-        sndout = startsnd;                                       /* set start to 1st event still active */
-
-        memset((char *)lbuf,0,dz->buflen * sizeof(float));                       /* empty output buffer */
-        if(sndout == endsnd) {                      /* If there are NO active events during this buffer */
-            if(endsnd != NULL)                                   /* and we are not at end of event list */
-                max_samp_written = dz->buflen;                        /* setup to write an empty buffer */
-            else {
-                sprintf(errstr,"Error in loop logic: do_mix()\n");
-                return(PROGRAM_ERROR);
-            }
-        } else
-            max_samp_written = 0;
-        while(sndout!= endsnd) {                                          /* look in all active buffers */
-            out_of_insamples = FALSE;
-
-//TW UPDATE: handles stereo input
-            if(is_stereo) {
-                if((exit_status = add_stereo_samples_to_outbuf_from_inbuf
-                (&out_of_insamples,&max_samp_written,sndout,splicebuf,splicelen,lbuf,dz))<0)
-                    return(exit_status);
-            } else {
-                if((exit_status = add_samples_to_outbuf_from_inbuf
-                (&out_of_insamples,&max_samp_written,sndout,splicebuf,splicelen,lbuf,dz))<0)
-                    return(exit_status);
-            }
-            if(out_of_insamples) {                                 /* if inbuf exhausted for THIS event */
-
-                if(sndout->next==NULL) {                                           /* if at end of list */
-                    if(sndout->last==NULL) {           /* if this is definitively the last active event */
-                         free(sndout);                                                       /* free it */     
-                         startsnd = NULL;            /* and set ptr to NULL, so we dropout of outerloop */
-                         break;
-                    } else {                                 /* BUT if some previous event still active */
-                        sndout = sndout->last;                          /* unlink final event from list */
-                        free(sndout->next);
-                        sndout->next = NULL;
-                        sndout = sndout->next;                            /* move sndout to end of list */
-                    }
-                } else if(sndout==startsnd) {                    /* if this is 1st active event in list */
-                        sndout   = sndout->next;                               /* proceed to next event */
-                        startsnd = sndout;              /* move start of active list to this next event */
-                        unlink_sndoutptr_at_start_of_list(sndout->last);
-                } else {                                /* else if this is NOT 1st active event in list */
-                        sndout   = sndout->next;                               /* proceed to next event */
-                        unlink_sndoutptr(sndout->last);/* unlink the exhausted event from (active) list */
-                }
-            } else {                            /* else there is data remaining in inbuf for THIS event */
-                sndout->obufpos = 0;                          /* so reset obufpos to start of next obuf */
-                sndout->st_splicpos += dz->buflen;/* reset relativeposition splice-start & nextbufstart */
-                sndout = sndout->next;                                     /* and proceed to next event */
-            }
-        }
-        if(startsnd!=NULL)                /* If we're not at the end of ALL events, write a full buffer */
-            max_samp_written = dz->buflen;
-
-        for(n=0;n<max_samp_written;n++)
-            dz->sampbuf[0][n] = lbuf[n];
-        if(max_samp_written > 0) {
-            if((exit_status = write_samps(dz->sampbuf[0],max_samp_written,dz))<0)
-                return(exit_status);
-        }
-        obufcnt++;
-    }
-    /*if(dz->iparam[TEX_MAXOUT] > MAXSAMP) {*/
-    if(dz->param[TEX_MAXOUT] > F_MAXSAMP) {
-        fprintf(stdout,"WARNING: OVERLOAD: suggest attenuation by < %lf\n",
-//TW UPDATE (need to factor in the attenation already being used to give correct new attenuation)
-            (((double)F_MAXSAMP/(double)dz->param[TEX_MAXOUT])) * dz->param[TEXTURE_ATTEN]);
-        fflush(stdout);
-    }
-    return(FINISHED);
-}
-
-/************************** CHECK_SEQUENCING ************************/
-
-int check_sequencing(sndoutptr sndout)
-{
-    unsigned int lasttime = sndout->st_sstttime;
-    unsigned int thistime;
-    while(sndout->next != (sndoutptr)0) {
-        sndout = sndout->next;
-        if((thistime = sndout->st_sstttime) < lasttime) {
-            sprintf(errstr,"Sequencing anomaly in sndout list: check_sequencing()\n");
-            return(PROGRAM_ERROR);
-        }
-        lasttime = thistime;
-    } 
-    return(FINISHED);
-}
-
-/************************** ADD_SAMPLES_TO_OUTBUF_FROM_INBUF ************************/
-
-int add_samples_to_outbuf_from_inbuf
-(int *out_of_insamples,int *max_samp_written,sndoutptr sndout,double *splicebuf,int splicelen,float *lbuffer,dataptr dz)
-{
-    unsigned int thisopos = sndout->obufpos;
-    unsigned int here;
-    double hereval = 0.0;
-    float *lbuf    = lbuffer + thisopos;
-    float *lbufend = lbuffer + dz->buflen;
-    int splicpos  = sndout->st_splicpos + thisopos;
-    float outval, thismaxoutval;
-    int max_set = FALSE;
-    while(lbuf < lbufend) {
-        if((here = (unsigned int) sndout->ibufpos) >= sndout->ibufcnt) {    /* TRUNCATE : get current pos in inbuf */
-            *out_of_insamples = TRUE;
-            *max_samp_written = max(*max_samp_written,lbuf - lbuffer);
-/* SAFETY CHECK--> */
-            if(splicpos < splicelen) {
-                sprintf(errstr,"BUM endsplice: add_samples_to_outbuf_from_inbuf()\n"); 
-                return(PROGRAM_ERROR);
-            }
-/* <--SAFETY CHECK */
-
-            max_set = TRUE;
-            break;
-        }
-        hereval = get_interpd_value(here,sndout->ibufpos,sndout);
-/* SAFETY FOR ARITHMETIC ROUNDING ERROS CALCULATING START OF SPLICE --> */
-        if(splicpos >= splicelen)
-            hereval = 0.0;
-/* <--SAFETY */
-
-        if(splicpos >= 0)
-            hereval *= splicebuf[splicpos >> 1];
-        splicpos += STEREO;
-        outval =(float)( *lbuf + (hereval * sndout->lgain ));
-        if((thismaxoutval = (float) fabs(outval)) > dz->param[TEX_MAXOUT])
-            dz->param[TEX_MAXOUT] = thismaxoutval;
-        *lbuf  = outval;
-        lbuf++;
-        outval = (float)(*lbuf + (hereval * sndout->rgain));
-        if((thismaxoutval = (float) fabs(outval)) > dz->param[TEX_MAXOUT])
-            dz->param[TEX_MAXOUT] =  thismaxoutval;
-        *lbuf = outval;
-        lbuf++;
-        sndout->ibufpos += sndout->step;
-    }
-    if(!max_set)
-        *max_samp_written = dz->buflen;
-    return(FINISHED);
-}
-
-//TW UPDATE: NEW FUNCTIONfor stereo input (updated for flotsams)
-/************************** ADD_STEREO_SAMPLES_TO_OUTBUF_FROM_INBUF ************************/
-
-int add_stereo_samples_to_outbuf_from_inbuf
-(int *out_of_insamples,int *max_samp_written,sndoutptr sndout,double *splicebuf,int splicelen,float *lbuffer,dataptr dz)
-{
-    unsigned int thisopos = sndout->obufpos;
-    unsigned int here;
-    double chanval1, chanval2;
-    float *lbuf    = lbuffer + thisopos;
-    float *lbufend = lbuffer + dz->buflen;
-    int splicpos  = sndout->st_splicpos + thisopos;
-    float outval, thismaxoutval;
-    int max_set = FALSE;
-    while(lbuf < lbufend) {
-        if((here = (unsigned int)sndout->ibufpos)>=sndout->ibufcnt) {   /* TRUNCATE : get current pos in inbuf */
-            *out_of_insamples = TRUE;
-            *max_samp_written = max(*max_samp_written,lbuf - lbuffer);
-            if(splicpos < splicelen) {
-                sprintf(errstr,"BUM endsplice: add_samples_to_outbuf_from_inbuf()\n"); 
-                return(PROGRAM_ERROR);
-            }
-            max_set = TRUE;
-            break;
-        }
-        chanval1 = get_interpd_value_stereo(here,sndout->ibufpos,&chanval2,sndout);
-    /* SAFETY FOR ARITHMETIC ROUNDING ERROS CALCULATING START OF SPLICE --> */
-        if(splicpos >= splicelen) {
-            chanval1 = 0.0;
-            chanval2 = 0.0;
-        }
-    /* <--SAFETY */
-        if(splicpos >= 0) {
-            chanval1 *= splicebuf[splicpos >> 1];
-            chanval2 *= splicebuf[splicpos >> 1];
-        }
-        splicpos += STEREO;
-        outval = (float)(*lbuf + (chanval1 * sndout->lgain));
-        if((thismaxoutval = (float)fabs(outval))>dz->param[TEX_MAXOUT])
-            dz->param[TEX_MAXOUT] = thismaxoutval;
-        *lbuf  = outval;
-        lbuf++;
-        outval = (float)(*lbuf + (chanval2 * sndout->lgain));   /* only one gain val for stereo inputs: kept in lgain */
-        if((thismaxoutval = (float)fabs(outval))>dz->param[TEX_MAXOUT])
-            dz->param[TEX_MAXOUT] = thismaxoutval;
-        *lbuf = outval;
-        lbuf++;
-        sndout->ibufpos += sndout->step;
-    }
-    if(!max_set)
-        *max_samp_written = dz->buflen;
-    return(FINISHED);
-}
-
-/************************** GET_INTERPD_VALUE ************************/
-
-double get_interpd_value(unsigned int here,double ibufpos,sndoutptr sndout)
-{
-    unsigned int next = here+1;         /* NB  all inbufs have a wraparound (0val) point at end */
-    double frac     = ibufpos - (double)here;
-    double hereval  = (double)(sndout->inbuf[here]);
-    double nextval  = (double)(sndout->inbuf[next]);
-    double diff     = nextval - hereval;
-    diff    *= frac;
-    return(hereval+diff);
-}
-
-//TW UPDATE NEW FUNCTION for stereo input
-/************************** GET_INTERPD_VALUE_STEREO ************************/
-
-double get_interpd_value_stereo(unsigned int here,double ibufpos,double *chanval2,sndoutptr sndout)
-{
-    unsigned int next = here+1;         /* NB  all inbufs have a wraparound (0val) point at end */
-    double frac     = ibufpos - (double)here;
-    double hereval, nextval, diff;
-    double chanval1;
-    unsigned int sthere = here * 2, stnext = next * 2;
-    hereval  = (double)(sndout->inbuf[sthere]);
-    nextval  = (double)(sndout->inbuf[stnext]);
-    diff     = (nextval - hereval) * frac;
-    chanval1 = hereval+diff;
-    sthere++;
-    stnext++;
-    hereval  = (double)(sndout->inbuf[sthere]);
-    nextval  = (double)(sndout->inbuf[stnext]);
-    diff     = (nextval - hereval) * frac;
-    *chanval2 = hereval+diff;
-    return(chanval1);
-}
-
-/************************** UNLINK_SNDOUTPTR_AT_START_OF_LIST ************************/
-
-void unlink_sndoutptr_at_start_of_list(sndoutptr sndout)
-{
-    sndout->next->last = (sndoutptr)0;
-    free(sndout);
-}
-
-/************************** UNLINK_SNDOUTPTR ************************/
-
-void unlink_sndoutptr(sndoutptr sndout)
-{
-    sndout->next->last = sndout->last;
-    sndout->last->next = sndout->next;
-    free(sndout);
-}