head	1.3;
access;
symbols
	rel-0-2-1:1.2
	before_adj_struct:1.1.2.4
	jack:1.1.0.2;
locks; strict;
comment	@ * @;


1.3
date	2007.03.22.20.55.43;	author robertatwood;	state Exp;
branches;
next	1.2;

1.2
date	2006.04.05.21.53.36;	author robertatwood;	state Exp;
branches;
next	1.1;

1.1
date	2005.08.20.18.26.42;	author robertatwood;	state Exp;
branches
	1.1.2.1;
next	;

1.1.2.1
date	2005.12.28.01.34.16;	author robertatwood;	state Exp;
branches;
next	1.1.2.2;

1.1.2.2
date	2005.12.28.16.13.35;	author robertatwood;	state Exp;
branches;
next	1.1.2.3;

1.1.2.3
date	2005.12.28.18.17.00;	author robertatwood;	state Exp;
branches;
next	1.1.2.4;

1.1.2.4
date	2006.01.04.00.06.03;	author robertatwood;	state Exp;
branches;
next	1.1.2.5;

1.1.2.5
date	2006.01.04.02.31.33;	author robertatwood;	state Exp;
branches;
next	;


desc
@@


1.3
log
@Updated GPL text to reflect new address of Free Software foundation
Prepare to move repository to savannah.nongnu.org
@
text
@/**************************************************************
This file is part of the Variseq program.
Variseq -- a variable pitch and step sample sequencer
Copyright (C) 2004  Robert Atwood r.atwood (at) imperial (dot) ac (dot) uk

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 
See the file COPYING for more information
**************************************************************/

#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include "constants.h"
#include "mysound.h"
#include "samples.h"
extern sbuf origsound;
extern void addbutton(const char *s);

   void init_adj(Adj * ap){
      ap->type=0;
      ap->bars=1;
   }
   void save_adj(Adj * ap,FILE * fp){
      fwrite(ap,sizeof(Adj),1,fp);
   }
   void read_adj(Adj * ap,FILE * fp){
      fread(ap,sizeof(Adj),1,fp);
   }

   void samples::save_samples(FILE * fp){
      int i;
      char hdr[32];
      char tlr[32];
      memset(hdr,0,32);
      memset(tlr,0,32);
      snprintf(hdr,32,"table of %i samples\n",nsamples);
      snprintf(tlr,32,"this space for rent\n");
      fwrite(hdr,sizeof(char),32,fp);
      fwrite (&nsamples,sizeof(int),1,fp);
      for ( i=0;i<nsamples;i++){
         fwrite(samplenames[i],sizeof(char),NAMELENGTH,fp);
         save_sbuf((orig_samples+i),fp);
         save_adj((adj+i),fp);
      }
      fwrite(tlr,sizeof(char),32,fp);
   }
   void samples::read_samples(FILE*fp){
      int i ;
      int ninp;
      char hdr[32];
      char tlr[32];
      char name[NAMELENGTH];
      fread(hdr,sizeof(char),32,fp);
      printf("%s",hdr);
      fread(&ninp,sizeof(int),1,fp);
      for(i=0;i<ninp;i++){
         fread(name,sizeof(char),NAMELENGTH,fp);
         read_sbuf(&origsound,fp);
         add_sample(&origsound,name);
         read_adj((adj+i),fp);
         addbutton(name);
      }
      fread(tlr,sizeof(char),32,fp);
      printf("%s",tlr);

    }
   /* Replace the sample and all its derived stretched */
   /* samples with either input or a new clip from a file */
   /* passed in the sbuf newsample arguement */
   void samples::replace_sample(sbuf * newsample,const char * name,int whichrepl){
      int this_sample = whichrepl;
      int * this_used;
      int this_oct;
      int this_tone;

      if (this_sample >= nsamples){
         fprintf(stderr,"ERROR %s   Illegal sample number %i\n",__func__, this_sample);
         return;
      }
      /* store the original in the table of original samples */
      copy_sbuf((orig_samples + this_sample) , newsample);
      snprintf(samplenames[this_sample],NAMELENGTH,"%s",name);

      /* create the table for the stretched samples */
      /* generated from the new sample*/

      // *(used + this_sample) = (int **) calloc(N_OCT, sizeof (int *));
      // *(str_samples + this_sample) = (sbuf **) calloc(N_OCT, sizeof (sbuf *));
      for (this_oct =0; this_oct < N_OCT;this_oct++){
         this_used = *( *(used + this_sample) + this_oct);
         if (this_used != NULL){
				for(this_tone=0;this_tone<ntones;this_tone++){
					if (this_used[this_tone] == 1 ){
					  this_used[this_tone] =2; /* flag the next routine to replace this */
					  if ( get_note(this_sample,this_oct,this_tone) == NULL){
						  fprintf(stderr,"ERROR: %s\n",__func__);
					  }else{
					  #ifndef NOPRINT
					  printf("Replaced sample %i octave %i tone %i\n",this_sample,this_oct,this_tone);
					  #endif
					  }

					}
				}
			}
      }


      #ifdef JUNK
      /* for the default octave */
      add_octave(D_OCT,this_sample);
      /* add the unstretched sample */
      stretch(this_sample,D_OCT,0);
      #endif
   }
   void samples::add_sample(sbuf * newsample,const char * name){
      int this_sample = nsamples;
      int i;
      nsamples ++;
      orig_samples = (sbuf *)realloc(orig_samples,nsamples * sizeof(sbuf));
      samplenames = (char **) realloc(samplenames,nsamples * sizeof(char *));
      adj = (Adj *) realloc(adj,nsamples * sizeof(Adj));
      for (i=this_sample;i<nsamples;i++){
         init_adj(adj+i);
      }

      samplenames[this_sample]=(char *) calloc(NAMELENGTH,sizeof(char));
      /* store the original in the table of original samples */
      init_sbuf(orig_samples + this_sample,44100);
      copy_sbuf((orig_samples + this_sample) , newsample);
      snprintf(samplenames[this_sample],NAMELENGTH,"%s",name);

      /* create the table for the stretched samples */
      /* generated from the new sample*/
      used = (int ***) realloc(used,nsamples * sizeof(int **));
      str_samples = (sbuf ***) realloc(str_samples,nsamples * sizeof(sbuf **));

      *(used + this_sample) = (int **) calloc(N_OCT, sizeof (int *));
      *(str_samples + this_sample) = (sbuf **) calloc(N_OCT, sizeof (sbuf *));


      /* for the default octave */
      add_octave(D_OCT,this_sample);
      /* add the unstretched sample */
      stretch(this_sample,D_OCT,0);
   }

   sbuf * samples::get_note(int samplenum,int oct, int notenum){
      if (used == NULL) return(NULL);
      if (samplenum >= nsamples) return(NULL);


      if ( (* ( *(used+samplenum) +oct)) == NULL ) add_octave(oct,samplenum);

      int * thisused = (* ( *(used+samplenum) +oct));
      sbuf * thisbuf = *(*(str_samples+samplenum)+oct);

      if (orig_samples + samplenum == NULL) return (NULL);

      if (thisused[notenum] != 1){ /* 0= unused; 2= needs replacing */
         stretch(samplenum,oct,notenum);
      }
      return(thisbuf + notenum);
   }
/* $Id: samples.C,v 1.2 2006/04/05 21:53:36 robertatwood Exp $ */

@


1.2
log
@Jack version is the main branch now
@
text
@d18 1
a18 1
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
d21 1
d177 1
a177 1
/* $Id: samples.C,v 1.1.2.5 2006/01/04 02:31:33 robertatwood Exp $ */
@


1.1
log
@Added a save/restore workspace function
Added window to display names of samples
@
text
@d30 11
d54 1
d71 1
d78 49
d129 1
d133 5
d171 1
a171 1
      if (!thisused[notenum]){
d176 1
a176 1
/* $Id: samples.C,v 1.2 2005/08/20 18:23:08 robert Exp $ */
@


1.1.2.1
log
@Began sample-replace segment
@
text
@a64 27
   void samples::replace_sample(sbuf * newsample,const char * name){
      #ifdef NOTYET
      int this_sample = nsamples;
      nsamples ++;
      orig_samples = (sbuf *)realloc(orig_samples,nsamples * sizeof(sbuf));
      samplenames = (char **) realloc(samplenames,nsamples * sizeof(char *));
      samplenames[this_sample]=(char *) calloc(NAMELENGTH,sizeof(char));
      /* store the original in the table of original samples */
      init_sbuf(orig_samples + this_sample,44100);
      copy_sbuf((orig_samples + this_sample) , newsample);
      snprintf(samplenames[this_sample],NAMELENGTH,"%s",name);

      /* create the table for the stretched samples */
      /* generated from the new sample*/
      used = (int ***) realloc(used,nsamples * sizeof(int **));
      str_samples = (sbuf ***) realloc(str_samples,nsamples * sizeof(sbuf **));

      *(used + this_sample) = (int **) calloc(N_OCT, sizeof (int *));
      *(str_samples + this_sample) = (sbuf **) calloc(N_OCT, sizeof (sbuf *));


      /* for the default octave */
      add_octave(D_OCT,this_sample);
      /* add the unstretched sample */
      stretch(this_sample,D_OCT,0);
      #endif
   }
d108 1
a108 1
/* $Id: samples.C,v 1.1 2005/08/20 18:26:42 robertatwood Exp $ */
@


1.1.2.2
log
@Checkpoint-problem with sample table address
@
text
@d65 7
a71 10
   void samples::replace_sample(sbuf * newsample,const char * name,int whichrepl){
      int this_sample = whichrepl;
      int * this_used;
      int this_oct;
      int this_tone;

      if (this_sample >= nsamples){
         fprintf(stderr,"ERROR %s   Illegal sample number %i\n",__func__, this_sample);
         return;
      }
d73 1
d79 2
d82 2
a83 17
      // *(used + this_sample) = (int **) calloc(N_OCT, sizeof (int *));
      // *(str_samples + this_sample) = (sbuf **) calloc(N_OCT, sizeof (sbuf *));
      for (this_oct =0; this_oct < N_OCT;this_oct++){
         this_used = *( *(used + this_sample) + this_oct);
         for(this_tone=0;this_tone<ntones;this_tone++){
            if (this_used[this_tone] == 1 ){
              if ( get_note(this_sample,this_oct,this_tone) == NULL){
                 fprintf(stderr,"ERROR: %s\n",__func__);
              }else{
              #ifndef NO_PRINT
              printf("Replaced sample %i octave %i tone %i\n",this_sample,this_oct,this_tone);
              #endif
              }

            }
         }
      }
d90 1
d135 1
a135 1
/* $Id: samples.C,v 1.1.2.1 2005/12/28 01:34:16 robertatwood Exp $ */
@


1.1.2.3
log
@Appears to work but needs file name placed in the textbox after replacement
@
text
@d86 12
a97 15
         if (this_used != NULL){
				for(this_tone=0;this_tone<ntones;this_tone++){
					if (this_used[this_tone] == 1 ){
					  this_used[this_tone] =2; /* flag the next routine to replace this */
					  if ( get_note(this_sample,this_oct,this_tone) == NULL){
						  fprintf(stderr,"ERROR: %s\n",__func__);
					  }else{
					  #ifndef NO_PRINT
					  printf("Replaced sample %i octave %i tone %i\n",this_sample,this_oct,this_tone);
					  #endif
					  }

					}
				}
			}
a100 1
      #ifdef JUNK
a104 1
      #endif
d144 1
a144 1
      if (thisused[notenum] != 1){ /* 0= unused; 2= needs replacing */
d149 1
a149 1
/* $Id: samples.C,v 1.1.2.2 2005/12/28 16:13:35 robertatwood Exp $ */
@


1.1.2.4
log
@Jack input as well, and scrambling in compile-time option
@
text
@a64 3
   /* Replace the sample and all its derived stretched */
   /* samples with either input or a new clip from a file */
   /* passed in the sbuf newsample arguement */
d93 1
a93 1
					  #ifndef NOPRINT
d154 1
a154 1
/* $Id: samples.C,v 1.1.2.3 2005/12/28 18:17:00 robertatwood Exp $ */
@


1.1.2.5
log
@Sample scramblizer adjusters added
@
text
@a29 11
   void init_adj(Adj * ap){
      ap->type=0;
      ap->bars=1;
   }
   void save_adj(Adj * ap,FILE * fp){
      fwrite(ap,sizeof(Adj),1,fp);
   }
   void read_adj(Adj * ap,FILE * fp){
      fread(ap,sizeof(Adj),1,fp);
   }

a42 1
         save_adj((adj+i),fp);
a58 1
         read_adj((adj+i),fp);
a115 1
      int i;
a118 5
      adj = (Adj *) realloc(adj,nsamples * sizeof(Adj));
      for (i=this_sample;i<nsamples;i++){
         init_adj(adj+i);
      }

d157 1
a157 1
/* $Id: samples.C,v 1.1.2.4 2006/01/04 00:06:03 robertatwood Exp $ */
@


