head	1.6;
access;
symbols
	rel-0-2-1:1.4
	before_adj_struct:1.3.2.5
	jack:1.3.0.2
	rel-0-1-0:1.2
	rel-0-0-0:1.1;
locks; strict;
comment	@ * @;


1.6
date	2007.03.22.20.55.43;	author robertatwood;	state Exp;
branches;
next	1.5;

1.5
date	2006.04.23.22.03.14;	author robertatwood;	state Exp;
branches;
next	1.4;

1.4
date	2006.04.05.21.53.36;	author robertatwood;	state Exp;
branches;
next	1.3;

1.3
date	2005.08.20.18.26.42;	author robertatwood;	state Exp;
branches
	1.3.2.1;
next	1.2;

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

1.1
date	2004.04.16.11.36.56;	author robertatwood;	state Exp;
branches;
next	;

1.3.2.1
date	2005.11.24.00.45.04;	author robertatwood;	state Exp;
branches;
next	1.3.2.2;

1.3.2.2
date	2005.11.24.01.23.44;	author robertatwood;	state Exp;
branches;
next	1.3.2.3;

1.3.2.3
date	2005.12.28.01.34.16;	author robertatwood;	state Exp;
branches;
next	1.3.2.4;

1.3.2.4
date	2005.12.28.18.16.59;	author robertatwood;	state Exp;
branches;
next	1.3.2.5;

1.3.2.5
date	2006.01.04.00.06.03;	author robertatwood;	state Exp;
branches;
next	1.3.2.6;

1.3.2.6
date	2006.01.04.00.41.58;	author robertatwood;	state Exp;
branches;
next	1.3.2.7;

1.3.2.7
date	2006.01.04.02.31.33;	author robertatwood;	state Exp;
branches;
next	1.3.2.8;

1.3.2.8
date	2006.01.10.23.43.46;	author robertatwood;	state Exp;
branches;
next	;


desc
@@


1.6
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 <math.h>
#include <stdio.h>
#include <pthread.h>

#if ( defined JACK && defined PORTAUDIO )
#error Cannot define both
#endif
#ifdef JACK
#elif defined PORTAUDIO 
#include <portaudio.h>
#else
/* no output defined */
#error NO OUTPUT DEFINED
#endif

#include "constants.h"
#include "myFl.h"
#include "notes.h"
#include "mysound.h"
#include "pattern.h"
#include "replace.h"
extern samples * sampletable;
extern ctrl ** sliders;
extern pattern * thepattern;

extern Fl_Round_Button * rewrite_button;

extern pthread_mutex_t rewrite_lock;

#ifdef PORTAUDIO
   extern PortAudioStream * mystream;
#endif
extern int going;
extern sbuf mysound;
extern int * whichone;
extern int * whichbutton;
extern Fl_Window *pwin;
extern Fl_Window *fwin;

void onesecond(Fl_Widget *w, void *v){
    printf("%s\n",__func__);
    return;
}

/* middle click to reset the note length to default */
/* only update the length when releasing the button */
int slenval::handle(int event){
       ctrl * c = (ctrl *) (parent());
       int cflag = 0;
       int nn,nl;
       if (event == FL_RELEASE){
          cflag = 1;
          if (Fl::event_button() == 2){
          /* middle click to reset the note length to default */
				 value(8);
				 #ifndef NOPRINT
				 printf("%i release, %f,%i\n",c->my_num,value(),Fl::event_button());
				 #endif
				 do_callback();
				 redraw();
          }
       }
       if (event == FL_KEYUP){
				 if (this == Fl::focus()){
				 cflag = 1;
				 #ifndef NOPRINT
				 printf("%i key, %f\n",c->my_num,value());
				 #endif
				 }
	    }
  		 /* only update the length upon releasing the button */
  		 /* or due to keyboard adjustment of the widget */
  		 if (cflag == 1){
			 nn = c->my_num;
			 nl = (int)(value());
			 thepattern->change_note_length(nn,nl);

			 #ifndef NOPRINT
			 printf("Responding to event nn=%i nl=%i\n",nn,nl);
			 #endif
       }
       return(Fl_Slider::handle(event));
}

int soct::handle(int event){
       ctrl * c = (ctrl *) (parent());
       int cflag = 0;
       int nn,no;
       if (event == FL_RELEASE){
          cflag = 1;
          if (Fl::event_button() == 2){
          /* middle click to reset the note length to default */
				 value(8);
				 #ifndef NOPRINT
				 printf("octave: %i release, %f,%i\n",c->my_num,value(),Fl::event_button());
				 #endif
				 do_callback();
				 redraw();
          }
       }
       if (event == FL_KEYUP){
				 if (this == Fl::focus()){
				 cflag = 1;
				 #ifndef NOPRINT
				 printf("octave: %i key, %f\n",c->my_num,value());
				 #endif
				 }
	    }
  		 /* only update the length upon releasing the button */
  		 /* or due to keyboard adjustment of the widget */
  		 if (cflag == 1){
			 nn = c->my_num;
			 no = (int)(value());

			 #ifndef NOPRINT
			 printf("octave: Responding to event nn=%i no=%i\n",nn,no);
			 #endif
			 thepattern->setnoteoctave(nn,no);
          thepattern->writenote(&mysound,nn);
       }
       return(Fl_Slider::handle(event));
}
int stype::handle(int event){
       sampctrl * c = (sampctrl *) (parent());
       int cflag = 0;
       int nn,no;
       if (event == FL_RELEASE){
          cflag = 1;
          if (Fl::event_button() == 2){
          /* middle click to reset the note length to default */
				 value(0);
				 #ifndef NOPRINT
				 printf("sampctrl: %i release, %f,%i\n",c->my_num,value(),Fl::event_button());
				 #endif
				 do_callback();
				 redraw();
          }
       }
       if (event == FL_KEYUP){
				 if (this == Fl::focus()){
				 cflag = 1;
				 #ifndef NOPRINT
				 printf("sampctrl: %i key, %f\n",c->my_num,value());
				 #endif
				 }
	    }
  		 /* only update the length upon releasing the button */
  		 /* or due to keyboard adjustment of the widget */
  		 if (cflag == 1){
			 nn = c->my_num;
			 no = (int)(value());

			 #ifndef NOPRINT
			 printf("sampctrl: Responding to event nn=%i no=%i\n",nn,no);
			 #endif
       }
       return(Fl_Slider::handle(event));
}


/*                            */
/* master value callbacks     */
/*                            */
/* master volume              */

void mvol_cb(Fl_Widget*w, void*d) {
   Fl_Slider * mvol = (Fl_Slider *)w;
   double volval = (double)mvol->value();
   volval = exp(volval);

   /* change the color to indicate overload volume */
   if (volval >= 1.0) mvol->selection_color(FL_RED);
   else mvol->selection_color(FL_GREEN);

   thepattern->setvol(volval);
   thepattern->write(&mysound,0);
}

/* rewrite the pattern */
void rewrite_cb(Fl_Widget *w, void *d){
   Fl_Round_Button * r = (Fl_Round_Button *)(w);
   pthread_mutex_lock(&rewrite_lock);
   #ifndef NOPRINT
   printf("%s locked rewrite\n",__func__);
        #endif
     thepattern->write(&mysound,0);
   #ifndef NOPRINT
   printf("%s unlocking rewrite\n",__func__);
        #endif
   pthread_mutex_unlock(&rewrite_lock);
   r->clear();
}

/* master speed              */
void sp_cb(Fl_Widget *o, void *v) {
  Fl_Value_Input *a = (Fl_Value_Input *)o;
  pattern * p = (pattern *)(v);

  /* can allow typed input greater than max, but */
  /* a value less than the min may crash it */
  if (a->value() < SP_MIN){
     p->setspeed(SP_MIN);
     a->value(SP_MIN);
     a->redraw();
  } else p->setspeed((float)(a->value()));
}
/* master smooth              */
void msmooth_cb(Fl_Widget *o, void *v) {
  Fl_Value_Input *a = (Fl_Value_Input *)o;
  pattern * p = (pattern *)(v);
  p->setsmooth((float)(a->value()));
}

/*                            */
/* individual value callbacks */
/*                            */
/* note octave */
void noct_cb(Fl_Widget*w, void*v) {
   int nval; 
   Fl_Slider * no = (Fl_Slider *)w;

   nval = (int) no->value();
   #ifndef NOPRINT
   printf("noct_cb: %i\n",nval);
   #endif
   no->color2(nval);
   no->redraw();
}
void stype_cb(Fl_Widget*w, void*v) {
   int nval; 
   stype * nl = (stype *)w;
   nval = (int) nl->value();
   #ifndef NOPRINT
   printf("stype_cb: %i \n",nval);
   #endif
   nl->color(nval);
   nl->redraw();
}
/*  apply the sampel scramblizer     */
void ap_cb(Fl_Widget*w, void*d) {
   mybt * r = (mybt *)w;
   sampctrl * c= (sampctrl *) (r->parent());
   int n = c->mynum();
   if (r->value() != 0 ){
   #ifndef NOPRINT
   printf("%s applying scramblizer for %i \n",__func__,n);
   #endif
      sampletable->setadj(n,(int)(c->bars.value()),(int)(c->type.value()));
   }else{
   #ifndef NOPRINT
   printf("%s removing scramblizer for %i \n",__func__,n);
   #endif
      sampletable->setadj(n,1,0);
   }
}
/* note length */
void nlen_cb(Fl_Widget*w, void*v) {
   int nval; 
   slenval * nl = (slenval *)w;
   nval = (int) nl->value();
   #ifndef NOPRINT
   printf("nlen_cb: %i \n",nval);
   #endif
   nl->color(nval);
   nl->redraw();
}

/*  panning                   */
void rpan_cb(Fl_Widget*w, void*d) {
   Fl_Dial * rpan = (Fl_Dial *)w;
   ctrl * c= (ctrl *) (rpan->parent());
   int n = c->mynum();
   thepattern->setpan(n,rpan->value());
   thepattern->writenote(&mysound,n);
}


/*  clipping                    */
void rclip_cb(Fl_Widget*w, void*d) {
   Fl_Slider * rclip = (Fl_Slider *)w;
   ctrl * c= (ctrl *) (rclip->parent());
   double clipval = (double)rclip->value();
   int n = c->mynum();
   thepattern->setclip(n,clipval);
   thepattern->writenote(&mysound,n);
}
/*  volume                    */
void rvol_cb(Fl_Widget*w, void*d) {
   Fl_Slider * rvol = (Fl_Slider *)w;
   ctrl * c= (ctrl *) (rvol->parent());
   double volval = (double)rvol->value();
   int n = c->mynum();
   volval = exp(volval);

   /* change the color to indicate overload volume */
   if (volval >= 1.0) rvol->selection_color(FL_RED);
   else rvol->selection_color(FL_GREEN);

   thepattern->setvol(n,volval);
   thepattern->writenote(&mysound,n);
}

/*  pitch value              */
void note_slider_cb(Fl_Widget * w, void* thedata) {
   int notelevel;
   Fl_Value_Slider * theslider = (Fl_Value_Slider *)(w);
   ctrl * c= (ctrl *) (theslider->parent());
   int n = c->mynum();

   notelevel = (int)theslider->value() - 1;
   theslider->redraw();
   thepattern->setnote(n,notelevel);

   if(going ==1) {
      #ifdef PORTAUDIO
      Pa_StopStream(mystream);
      #endif
   }
   thepattern->writenote(&mysound,n);
   if (going == 1) {
      #ifdef PORTAUDIO
      Pa_StartStream(mystream);
      #endif
   }
   
}


/*  sample selection button  */
/*  invoked within the popup window  */
void select_cb(Fl_Widget  *w, void *data){
   mybt * bt = (mybt *) (w) ;
   int * whichbt = (int *)(data);
   /* whichone is the number of the control seleted */
   /* to invoke the popup window */
   /* mynum is the number of the sample to be */
   /* associated wiht that control */

   #ifdef JUNK
   pthread_mutex_lock(&rewrite_lock);
   #ifndef NOPRINT
   printf("%s locked rewrite\n",__func__);
   #endif /*NOPRINT*/
   #endif

   sliders[*whichone]->button_color(bt->mynum());
   sliders[*whichone]->redraw();
   thepattern->setnotesample(*whichone,bt->mynum());
   thepattern->writenote(&mysound,*whichone);
   #ifndef NOPRINT
       printf("placing sample %i in slider %i\n",bt->mynum(),*whichone);
   #endif /*NOPRINT*/
   /* data returns into whichbutton to tell what button was pushed */
   *whichbt = bt->mynum();
   bt->window()->hide();

   #ifdef JUNK
   #ifndef NOPRINT
   printf("%s unlocking rewrite\n",__func__);
   #endif /*NOPRINT*/
   pthread_mutex_unlock(&rewrite_lock);
   #endif
}


/*  sample alter button  */
/*  invoked within the sample window  */
/* to replace or otherwise alter the base sampel*/
/* for this colour button */
void adjust_cb(Fl_Widget  *w, void *data){
   mybt * bt = (mybt *) (w) ;
   int * whichbt = (int *)(data);
   Fl_Output * whichop = (Fl_Output *)(bt->o_handle); 

   /* whichone is the number of the control seleted */
   /* to invoke the popup window */
   /* mynum is the number of the sample to be */
   /* associated wiht that control */
   /* data passed via whichbt to tell what button was pushed */
   *whichbt = bt->mynum();
   #ifndef NOPRINT
       printf("adjusting sample %i\n",*whichbt);
   #endif /*NOPRINT*/

   switch (bt->my_func){
		case 1:
			replace(sampletable,*whichbt);
		break;
		case 2:
			replace_inp(sampletable,*whichbt);
		break;
		case 3:
			replace_buf_rnd(sampletable,*whichbt);
	   break;
		default:
			fprintf(stderr,"Oops %s No default function\n",__func__);
		break;
   }

   whichop->value(sampletable->samplenames[*whichbt]);
   /* keep the centre color displayed */
   rewrite_button->value(1);
   bt->value(1);
}

/*  sample selection button  */
/*  open up the popup to choose which sample  */
/*  goes with this note                       */
void press(Fl_Widget  *w, void *data){
	/* note button was pressed, pop up a list of options for that button */
	int x,y;
	mybt * bt = (mybt *) (w) ;
	ctrl * which = (ctrl *) (bt->parent());
	int num = which->mynum();
   #ifndef NOPRINT
		printf("bt num %i value %i\n",num,bt->value());
		printf("noteval %f\n",sliders[num]->note.value());
   #endif /* NOPRINT */

	  /* find the correct location to pop up the window */
	  x=bt->x();
	  y=bt->y();
	  x += bt->parent()->parent()->parent()->x();
	  y += bt->parent()->parent()->parent()->y();

	  /* whichone is the number of this slider */
	  *whichone = which->mynum();

     #ifdef JUNK
     pthread_mutex_lock(&rewrite_lock);
   #ifndef NOPRINT
   printf("%s locked rewrite\n",__func__);
   #endif
   #endif
     thepattern->setnotestate(*whichone,bt->value());

     /* select which sample if turning on the note */
     if(bt->value() ==1 ){
        /* sample was not on before, so select the sample */
		  /* the popup takes care of writing the note */
		  /* once the sample is selected              */
		  pwin->position(x,y);
		  pwin->show();
	  }else{
	     /* sample is changed so write the note.   */
	     /* This takes care of silencing the note  */
	     /* when it is turned off, since writenote */
	     /* uses the note-state information        */
	     thepattern->writenote(&mysound,*whichone);
		#ifdef JUNK
		#ifndef NOPRINT
		printf("%s unlocking rewrite\n",__func__);
		#endif
		  pthread_mutex_unlock(&rewrite_lock);
		#endif
	  }
   #ifdef JUNK
   #ifndef NOPRINT
   printf("%s unlocking rewrite\n",__func__);
   #endif
	  pthread_mutex_unlock(&rewrite_lock);
   #endif
}

/* add a button to the popup window */
/* for each sample added to the table */
/* also add a button and name box to the */
/* sample name window */
void addbutton(const char * samplename){
	static int n=0;
	#ifndef NOPRINT
	static int pctr=0;
	#endif 
	int oldx,oldy;
	/* sample select in slider button */
	mybt * newbt = new mybt(0,0,SWIDTH,SWIDTH,"");


   /* sample replace from file */
   oldx=fwin->x();
   oldy=fwin->y();
   fwin->hide();

   sampctrl * sctrl = new sampctrl(MARGIN,MARGIN+SWIDTH,200,SWIDTH,samplename);
	pwin->size(pwin->w(),pwin->h()+SWIDTH);
	#ifndef NOPRINT
	printf("%s fwin size %i pctr %i\n",__func__,fwin->h(),pctr++);
	printf("%s oldx %i oldy %i\n",__func__,oldx,oldy);
	printf("%s pwin size %i pctr %i\n",__func__,pwin->h(),pctr++);
	#endif /*NOPRINT*/
	fwin->resize(oldx,oldy-SWIDTH,fwin->w(),fwin->h()+SWIDTH);
	#ifndef NOPRINT
	printf("%s fwin size %i pctr %i\n",__func__,fwin->h(),pctr++);
	printf("%s oldx %i oldy %i\n",__func__,oldx,oldy);
	printf("%s pwin size %i pctr %i\n",__func__,pwin->h(),pctr++);
	#endif /*NOPRINT*/

	/* sample chooser button */
	/* add to the popup window */
	pwin->add(newbt);
	newbt->position(MARGIN,pwin->h()-SWIDTH-MARGIN);

	/* sample replacement buttons*/
	/* added to the f window     */
	fwin->add(sctrl);
	sctrl->mynum(n);
	newbt->mynum(n);
	n++;


   /* assign the callback function tothe button */
   /* replace from file/inpu/buffer uses the same callback */
   /* and tests myfunc */
   newbt->callback(select_cb,whichbutton);
   sctrl->position(MARGIN,fwin->h()-SWIDTH-MARGIN);
	sctrl->scallback(adjust_cb,whichbutton);
   newbt->color(newbt->mynum());
   newbt->selection_color(newbt->mynum());
   
   pwin->redraw();
   fwin->redraw();
	#ifndef NOPRINT
	printf("%s fwin size %i pctr %i\n",__func__,fwin->h(),pctr++);
	printf("%s x %i y %i\n",__func__,fwin->x(),fwin->y());
	printf("%s pwin size %i pctr %i\n",__func__,pwin->h(),pctr++);
	#endif /*NOPRINT*/
	fwin->show();
}

/* save the note to a file as part of a pattern */
/* critical values for the note must be kept in */
/* the notepub structure                        */
void note::savenote(FILE * fp){
    fwrite(this,sizeof(notepub),1,fp);
}

/* load the note from a file as part of a pattern*/
/* then reset the sound data buffer*/
void note::loadnote(FILE * fp){
   ctrl * sl;
   fread (this, sizeof(notepub),1,fp);
   sl = sliders[my_num];
   setsample(samplenum,notelevel);

   /* readjust the control panel */
   sl->sampbut.value(state);

   if(samplenum != N_NONE)
		sl->sampbut.selection_color(samplenum);

   sl->pan.value(pan);
   sl->vol.value(log(vol));
   sl->clip.value(clip);
   sl->nlen.value(ticks);
   sl->nlen.do_callback();/* update the colour also*/
   sl->oct.value(noteoctave);
   sl->oct.do_callback();


   if (notelevel != N_NONE)
		sl->note.value(notelevel);
   else sl->note.value(0);
   
}
   
   
/* $Id: callbacks.C,v 1.5 2006/04/23 22:03:14 robertatwood Exp $ */
@


1.5
log
@Fixed popup window location and sample name label
@
text
@d18 1
a18 1
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
d22 1
d589 1
a589 1
/* $Id: callbacks.C,v 1.4 2006/04/05 21:53:36 robertatwood Exp $ */
@


1.4
log
@Jack version is the main branch now
@
text
@d444 2
a445 2
	  x += bt->parent()->parent()->x();
	  y += bt->parent()->parent()->y();
d505 1
a505 1
   sampctrl * sctrl = new sampctrl(MARGIN,MARGIN+SWIDTH,200,SWIDTH,"");
d588 1
a588 1
/* $Id: callbacks.C,v 1.3.2.8 2006/01/10 23:43:46 robertatwood Exp $ */
@


1.3
log
@Added a save/restore workspace function
Added window to display names of samples
@
text
@d24 7
d32 5
d42 2
a43 1
extern samples sampletable;
d46 8
a53 1
extern PortAudioStream * mystream;
d57 1
d61 5
d144 36
d203 9
a211 1
   thepattern->write(&mysound,0);
d250 27
d335 5
a339 1
   if(going ==1) Pa_StopStream(mystream);
d341 5
a345 1
   if (going == 1) Pa_StartStream(mystream);
d354 1
d360 7
d374 2
d377 48
d447 1
d449 7
d471 6
d478 6
d485 1
d488 2
d492 5
d498 8
a505 2
   Fl_Light_Button * nlbt = new Fl_Light_Button(0,0,SWIDTH,SWIDTH,"");
   Fl_Output * noutp = new Fl_Output(0,0,200,SWIDTH,"");
d507 11
a517 1
	fwin->size(fwin->w(),fwin->h()+SWIDTH);
d519 2
a521 1
	fwin->add(nlbt);
a522 1
	nlbt->position(MARGIN,fwin->h()-SWIDTH-MARGIN);
d524 14
a537 2
	newbt->mynum(n++);
   newbt->callback(select_cb,NULL);
a538 2
   nlbt->color(newbt->mynum());

a539 4
   nlbt->selection_color(newbt->mynum());
   fwin->add(noutp);
   noutp->resize(SWIDTH+MARGIN,fwin->h()-SWIDTH-MARGIN,200,SWIDTH);
   noutp->value(samplename);
d543 6
d551 3
a553 1
/* save the note to a file as part of a pattern*/
d557 1
d588 1
a588 1
/* $Id: callbacks.C,v 1.5 2005/08/20 18:23:08 robert Exp $ */
@


1.3.2.1
log
@Main jack callback compiles ...  so far so good
@
text
@a23 6

#if ( defined JACK && defined PORTAUDIO )
#error Cannot define both
#endif
#ifdef JACK
#elif defined PORTAUDIO 
a24 5
#else
/* no output defined */
#error NO OUTPUT DEFINED
#endif

d366 1
a366 1
/* $Id: callbacks.C,v 1.3 2005/08/20 18:26:42 robertatwood Exp $ */
@


1.3.2.2
log
@Works at least, sound comes out with JACK running!
@
text
@d44 1
a44 4

#ifdef PORTAUDIO
   extern PortAudioStream * mystream;
#endif
d249 1
a249 5
   if(going ==1) {
      #ifdef PORTAUDIO
      Pa_StopStream(mystream);
      #endif
   }
d251 1
a251 5
   if (going == 1) {
      #ifdef PORTAUDIO
      Pa_StartStream(mystream);
      #endif
   }
d377 1
a377 1
/* $Id: callbacks.C,v 1.3.2.1 2005/11/24 00:45:04 robertatwood Exp $ */
@


1.3.2.3
log
@Began sample-replace segment
@
text
@a43 1
extern void replace(samples * sampletable,int whichrepl) ;
a50 1
extern int * whichbutton;
a270 1
   int * whichbt = (int *)(data);
a282 2
   /* data returns into whichbutton to tell what button was pushed */
   *whichbt = bt->mynum();
a284 18
/*  sample alter button  */
/*  invoked within the sample window  */
/* to replace or otherwise alter the base sampel*/
/* for this colour button */
void adjust_cb(Fl_Widget  *w, void *data){
   mybt * bt = (mybt *) (w) ;
   int * whichbt = (int *)(data);
   /* whichone is the number of the control seleted */
   /* to invoke the popup window */
   /* mynum is the number of the sample to be */
   /* associated wiht that control */
   /* data returns into whichbutton to tell what button was pushed */
   *whichbt = bt->mynum();
   #ifndef NOPRINT
       printf("adjusting sample %i\n",*whichbt);
       replace(&sampletable,*whichbt);
   #endif /*NOPRINT*/
}
a305 1
	  /* whichone is the number of this slider */
a315 7
   #ifdef JUNK
   /* now the sampel gets written into the audio */
        sliders[*whichone]->button_color(*whichbutton);
        sliders[*whichone]->redraw();
        thepattern->setnotesample(*whichone,*whichbutton);
        thepattern->writenote(&mysound,*whichone);
   #endif
a325 2
/* also add a button and name box to the */
/* sample name window */
d329 1
a329 1
   mybt * nlbt = new mybt(0,0,SWIDTH,SWIDTH,"");
d339 2
a340 6
	/* assign the number to the button */
	newbt->mynum(n);
	nlbt->mynum(n);
	n++;
   newbt->callback(select_cb,whichbutton);
   nlbt->callback(adjust_cb,whichbutton);
d388 1
a388 1
/* $Id: callbacks.C,v 1.3.2.2 2005/11/24 01:23:44 robertatwood Exp $ */
@


1.3.2.4
log
@Appears to work but needs file name placed in the textbox after replacement
@
text
@d41 1
a41 1
extern samples * sampletable;
d301 1
a301 1
   /* data passed via whichbt to tell what button was pushed */
d305 1
a305 1
       replace(sampletable,*whichbt);
a371 2
	nlbt->sethandle(noutp);

d425 1
a425 1
/* $Id: callbacks.C,v 1.3.2.3 2005/12/28 01:34:16 robertatwood Exp $ */
@


1.3.2.5
log
@Jack input as well, and scrambling in compile-time option
@
text
@a23 1
#include <pthread.h>
a40 1
#include "replace.h"
d44 1
a44 4

extern Fl_Round_Button * rewrite_button;

extern pthread_mutex_t rewrite_lock;
a55 5
void onesecond(Fl_Widget *w, void *v){
    printf("%s\n",__func__);
    return;
}

d157 1
a157 9
   pthread_mutex_lock(&rewrite_lock);
   #ifndef NOPRINT
   printf("%s locked rewrite\n",__func__);
        #endif
     thepattern->write(&mysound,0);
   #ifndef NOPRINT
   printf("%s unlocking rewrite\n",__func__);
        #endif
   pthread_mutex_unlock(&rewrite_lock);
a195 13
#ifdef NOTYET
/*  length */
void sctype_cb(Fl_Widget*w, void*v) {
   int nval; 
   slenval * nl = (slenval *)w;
   nval = (int) nl->value();
   #ifndef NOPRINT
   printf("nlen_cb: %i \n",nval);
   #endif
   nl->color(nval);
   nl->redraw();
}
#endif
a278 7
   #ifdef JUNK
   pthread_mutex_lock(&rewrite_lock);
   #ifndef NOPRINT
   printf("%s locked rewrite\n",__func__);
   #endif /*NOPRINT*/
   #endif

a288 7

   #ifdef JUNK
   #ifndef NOPRINT
   printf("%s unlocking rewrite\n",__func__);
   #endif /*NOPRINT*/
   pthread_mutex_unlock(&rewrite_lock);
   #endif
a289 2


a296 2
   Fl_Output * whichop = (Fl_Output *)(bt->o_handle); 

d305 1
a306 20

   switch (bt->my_func){
		case 1:
			replace(sampletable,*whichbt);
		break;
		case 2:
			replace_inp(sampletable,*whichbt);
		break;
		case 3:
			replace_buf_rnd(sampletable,*whichbt);
	   break;
		default:
			fprintf(stderr,"Oops %s No default function\n",__func__);
		break;
   }

   whichop->value(sampletable->samplenames[*whichbt]);
   /* keep the centre color displayed */
   rewrite_button->value(1);
   bt->value(1);
a330 7

     #ifdef JUNK
     pthread_mutex_lock(&rewrite_lock);
   #ifndef NOPRINT
   printf("%s locked rewrite\n",__func__);
   #endif
   #endif
d340 7
a352 6
		#ifdef JUNK
		#ifndef NOPRINT
		printf("%s unlocking rewrite\n",__func__);
		#endif
		  pthread_mutex_unlock(&rewrite_lock);
		#endif
a353 6
   #ifdef JUNK
   #ifndef NOPRINT
   printf("%s unlocking rewrite\n",__func__);
   #endif
	  pthread_mutex_unlock(&rewrite_lock);
   #endif
a360 1
	/* sample select in slider button */
d362 2
a363 5


   /* sample replace from file */

   sampctrl * sctrl = new sampctrl(MARGIN,MARGIN+SWIDTH,200,SWIDTH,"");
a366 2
	/* sample chooser button */
	/* add to the popup window */
d368 1
d370 3
d374 1
a374 4
	/* sample replacement buttons*/
	/* added to the f window     */
	fwin->add(sctrl);
	sctrl->mynum(n);
d376 1
a377 5


   /* assign the callback function tothe button */
   /* replace from file/inpu/buffer uses the same callback */
   /* and tests myfunc */
d379 1
a379 2
   sctrl->position(MARGIN,fwin->h()-SWIDTH-MARGIN);
	sctrl->scallback(adjust_cb,whichbutton);
d381 2
d384 4
d393 1
a393 3
/* save the note to a file as part of a pattern */
/* critical values for the note must be kept in */
/* the notepub structure                        */
a396 1

d427 1
a427 1
/* $Id: callbacks.C,v 1.3.2.4 2005/12/28 18:16:59 robertatwood Exp $ */
@


1.3.2.6
log
@Before adding the adjustment structure into the sampel table
@
text
@a143 36
int stype::handle(int event){
       sampctrl * c = (sampctrl *) (parent());
       int cflag = 0;
       int nn,no;
       if (event == FL_RELEASE){
          cflag = 1;
          if (Fl::event_button() == 2){
          /* middle click to reset the note length to default */
				 value(0);
				 #ifndef NOPRINT
				 printf("sampctrl: %i release, %f,%i\n",c->my_num,value(),Fl::event_button());
				 #endif
				 do_callback();
				 redraw();
          }
       }
       if (event == FL_KEYUP){
				 if (this == Fl::focus()){
				 cflag = 1;
				 #ifndef NOPRINT
				 printf("sampctrl: %i key, %f\n",c->my_num,value());
				 #endif
				 }
	    }
  		 /* only update the length upon releasing the button */
  		 /* or due to keyboard adjustment of the widget */
  		 if (cflag == 1){
			 nn = c->my_num;
			 no = (int)(value());

			 #ifndef NOPRINT
			 printf("sampctrl: Responding to event nn=%i no=%i\n",nn,no);
			 #endif
       }
       return(Fl_Slider::handle(event));
}
d214 3
a216 1
void stype_cb(Fl_Widget*w, void*v) {
d218 1
a218 1
   stype * nl = (stype *)w;
d221 1
a221 1
   printf("stype_cb: %i \n",nval);
d226 1
d514 1
a514 1
/* $Id: callbacks.C,v 1.3.2.5 2006/01/04 00:06:03 robertatwood Exp $ */
@


1.3.2.7
log
@Sample scramblizer adjusters added
@
text
@a259 17
/*  apply the sampel scramblizer     */
void ap_cb(Fl_Widget*w, void*d) {
   mybt * r = (mybt *)w;
   sampctrl * c= (sampctrl *) (r->parent());
   int n = c->mynum();
   if (r->value() != 0 ){
   #ifndef NOPRINT
   printf("%s applying scramblizer for %i \n",__func__,n);
   #endif
      sampletable->setadj(n,c->bars.value(),c->type.value());
   }else{
   #ifndef NOPRINT
   printf("%s removing scramblizer for %i \n",__func__,n);
   #endif
      sampletable->setadj(n,1,0);
   }
}
d547 1
a547 1
/* $Id: callbacks.C,v 1.3.2.6 2006/01/04 00:41:58 robertatwood Exp $ */
@


1.3.2.8
log
@Jack and input autosampler
Need to use -DJACK -DINPUT -DSCRAMBLE
Sometimes seg faults due to unknown jack related problem
@
text
@d269 1
a269 1
      sampletable->setadj(n,(int)(c->bars.value()),(int)(c->type.value()));
a484 1

a490 4
	#ifndef NOPRINT
	static int pctr=0;
	#endif 
	int oldx,oldy;
a495 3
   oldx=fwin->x();
   oldy=fwin->y();
   fwin->hide();
d499 1
a499 11
	#ifndef NOPRINT
	printf("%s fwin size %i pctr %i\n",__func__,fwin->h(),pctr++);
	printf("%s oldx %i oldy %i\n",__func__,oldx,oldy);
	printf("%s pwin size %i pctr %i\n",__func__,pwin->h(),pctr++);
	#endif /*NOPRINT*/
	fwin->resize(oldx,oldy-SWIDTH,fwin->w(),fwin->h()+SWIDTH);
	#ifndef NOPRINT
	printf("%s fwin size %i pctr %i\n",__func__,fwin->h(),pctr++);
	printf("%s oldx %i oldy %i\n",__func__,oldx,oldy);
	printf("%s pwin size %i pctr %i\n",__func__,pwin->h(),pctr++);
	#endif /*NOPRINT*/
a524 6
	#ifndef NOPRINT
	printf("%s fwin size %i pctr %i\n",__func__,fwin->h(),pctr++);
	printf("%s x %i y %i\n",__func__,fwin->x(),fwin->y());
	printf("%s pwin size %i pctr %i\n",__func__,pwin->h(),pctr++);
	#endif /*NOPRINT*/
	fwin->show();
d564 1
a564 1
/* $Id: callbacks.C,v 1.3.2.7 2006/01/04 02:31:33 robertatwood Exp $ */
@


1.2
log
@Changed the buffer writing so that samples extend into unused notes.
Altered file choose usage to correctly use the FLTK chooser
@
text
@d38 1
d251 2
d258 3
d304 1
a304 1
void addbutton(){
d307 2
d310 2
d313 1
d315 2
d320 2
d323 5
d329 1
d355 3
d366 1
a366 1
/* $Id: callbacks.C,v 1.2 2005/04/03 19:05:10 robert Exp $ */
@


1.1
log
@Initial version uploaded to Sourceforge
@
text
@d137 7
d342 1
a342 1
/* $Id: callbacks.C,v 1.12 2004/04/12 13:22:33 robert Exp $ */
@

