[PD-cvs] externals/frankenstein common.c, 1.16, 1.17 common.h, 1.13, 1.14 rhythms_memory.c, 1.7, 1.8 test-rhythms_memory.pd, 1.2, 1.3

dmorelli morellid at users.sourceforge.net
Tue Dec 27 02:28:53 CET 2005


Update of /cvsroot/pure-data/externals/frankenstein
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18887

Modified Files:
	common.c common.h rhythms_memory.c test-rhythms_memory.pd 
Log Message:
added rhythms playing. still need debugging

Index: test-rhythms_memory.pd
===================================================================
RCS file: /cvsroot/pure-data/externals/frankenstein/test-rhythms_memory.pd,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** test-rhythms_memory.pd	22 Dec 2005 23:21:04 -0000	1.2
--- test-rhythms_memory.pd	27 Dec 2005 01:28:51 -0000	1.3
***************
*** 1,27 ****
! #N canvas 224 39 661 478 12;
! #X obj 134 262 rhythms_memory;
  #X msg 126 212 measure;
! #X msg 317 224 0;
! #X obj 168 46 metro 500;
! #X obj 130 84 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
  -1;
! #X obj 168 23 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1
  ;
! #X obj 169 69 int 0;
! #X obj 220 70 + 1;
! #X obj 169 92 % 4;
  #X obj 127 155 sel 0;
  #X obj 125 185 bang;
! #X obj 317 189 bng 30 250 50 0 empty empty empty 0 -6 0 8 -258699 -1
  -1;
! #X obj 133 285 unpack f f f f f;
! #X floatatom 131 312 5 0 0 1 is_this_a_new_rhythm - -;
! #X floatatom 160 330 5 0 0 1 id - -;
! #X floatatom 193 348 5 0 0 1 subid - -;
! #X floatatom 225 368 5 0 0 1 root_closeness - -;
! #X floatatom 257 391 5 0 0 1 sub_closeness - -;
! #X text 344 314 (0=known \, 1=new root \, 2=new sub);
! #X obj 169 115 t f f;
! #X msg 444 194 crash;
  #N canvas 0 0 454 304 drum 0;
  #X obj 108 27 inlet;
--- 1,27 ----
! #N canvas 91 38 909 527 12;
! #X obj 126 256 rhythms_memory;
  #X msg 126 212 measure;
! #X msg 232 220 0;
! #X obj 123 48 metro 500;
! #X obj 85 86 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
  -1;
! #X obj 123 25 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1
  ;
! #X obj 124 71 int 0;
! #X obj 175 72 + 1;
! #X obj 124 94 % 4;
  #X obj 127 155 sel 0;
  #X obj 125 185 bang;
! #X obj 232 185 bng 30 250 50 0 empty empty empty 0 -6 0 8 -258699 -1
  -1;
! #X obj 231 363 unpack f f f f f;
! #X floatatom 229 390 5 0 0 1 is_this_a_new_rhythm - -;
! #X floatatom 258 408 5 0 0 1 id - -;
! #X floatatom 291 426 5 0 0 1 subid - -;
! #X floatatom 323 446 5 0 0 1 root_closeness - -;
! #X floatatom 355 469 5 0 0 1 sub_closeness - -;
! #X text 442 392 (0=known \, 1=new root \, 2=new sub);
! #X obj 124 117 t f f;
! #X msg 568 247 crash;
  #N canvas 0 0 454 304 drum 0;
  #X obj 108 27 inlet;
***************
*** 43,52 ****
  #X connect 8 0 6 0;
  #X connect 8 1 5 0;
! #X restore 429 115 pd drum;
! #X obj 429 82 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
  -1;
! #X obj 423 147 dac~;
! #X floatatom 192 152 5 0 0 0 - - -;
! #X connect 0 0 12 0;
  #X connect 1 0 0 0;
  #X connect 2 0 0 0;
--- 43,68 ----
  #X connect 8 0 6 0;
  #X connect 8 1 5 0;
! #X restore 276 155 pd drum;
! #X obj 274 124 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
  -1;
! #X obj 270 187 dac~;
! #X floatatom 180 155 5 0 0 0 - - -;
! #X msg 384 39 rhythm 1 1;
! #X obj 126 294 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
! -1;
! #X msg 489 133 1 0 0.5;
! #X text 381 17 you can ask it to play a stored rhythm;
! #X text 559 227 (crash me! for debugging);
! #X text 405 98 you will be able to send rhythms in the form of list
! of floats (TODO);
! #X obj 180 319 print;
! #X text 152 294 here you get the wanted rhythms played in realtime
! ;
! #X text 235 315 here you'll get the wanted rhythms in the form of lists
! of floats (TODO);
! #X text 373 361 here you get info on the last detected rhythm;
! #X connect 0 0 26 0;
! #X connect 0 1 31 0;
! #X connect 0 2 12 0;
  #X connect 1 0 0 0;
  #X connect 2 0 0 0;
***************
*** 74,75 ****
--- 90,93 ----
  #X connect 22 0 21 0;
  #X connect 22 0 11 0;
+ #X connect 25 0 0 0;
+ #X connect 27 0 0 1;

Index: rhythms_memory.c
===================================================================
RCS file: /cvsroot/pure-data/externals/frankenstein/rhythms_memory.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** rhythms_memory.c	26 Dec 2005 11:55:23 -0000	1.7
--- rhythms_memory.c	27 Dec 2005 01:28:51 -0000	1.8
***************
*** 10,16 ****
    * test and debug core functionalities
    * memory save/load to file
-   * output rhythms in realtime (BANGs)
    * output rhythms in the form of list of floats
    * add velo
  
  */
--- 10,16 ----
    * test and debug core functionalities
    * memory save/load to file
    * output rhythms in the form of list of floats
    * add velo
+   * input rhythms from a list (second inlet)
  
  */
***************
*** 36,40 ****
  {
      t_object x_obj; // myself
! 	t_outlet *l_out;
  	t_rhythm_event *curr_seq;
  	int seq_initialized;
--- 36,44 ----
  {
      t_object x_obj; // myself
! 	// 3 outlets:
! 	// bangs_out plays the wanted rhythmsin realtime
! 	// list_out outputs the wanted rhythm as a list of floats
! 	// info_out outputs info on the last recognized rhythm
! 	t_outlet *bangs_out, *list_out, *info_out;
  	t_rhythm_event *curr_seq;
  	int seq_initialized;
***************
*** 52,55 ****
--- 56,60 ----
  	t_clock *x_clock;
      double x_deltime;
+ 	double last_event_out_time;
  	
  } t_rhythms_memory;
***************
*** 65,68 ****
--- 70,74 ----
  }
  
+ // called when a new measure starts
  void start_measure(t_rhythms_memory *x)
  {
***************
*** 70,75 ****
--- 76,83 ----
  	// of this very moment
  	x->measure_start_time = clock_getlogicaltime();
+ 	x->last_event_out_time = 0;
  }
  
+ // called when a new event occours
  void add_event(t_rhythms_memory *x, unsigned short int voice)
  {
***************
*** 99,102 ****
--- 107,111 ----
  }
  
+ // called when a measure ends
  void end_measure(t_rhythms_memory *x)
  {
***************
*** 111,114 ****
--- 120,125 ----
  	int rhythm_found;
  	t_rhythm_event *wanted_rhythm;
+ 	t_rhythm_event *curr_rhythm;
+ 	event *lastOutEvent;
  
  	// I call the pd functions to get a representation
***************
*** 161,165 ****
  		SETFLOAT(lista+3, (float) root_closeness);
  		SETFLOAT(lista+4, (float) sub_closeness);
! 		outlet_anything(x->l_out,
  						gensym("list") ,
  						5, 
--- 172,176 ----
  		SETFLOAT(lista+3, (float) root_closeness);
  		SETFLOAT(lista+4, (float) sub_closeness);
! 		outlet_anything(x->info_out,
  						gensym("list") ,
  						5, 
***************
*** 185,191 ****
  	if (x->next_main_rhythm_out)
  	{
  		// ask the memory for the wanted rhythm
  		rhythm_found = rhythm_memory_get_rhythm(x->rhythms_memory, // the memory
! 								wanted_rhythm, // a pointer to the returned rhythm
  								// the id of the main rhythm wanted
  								x->next_main_rhythm_out, 
--- 196,203 ----
  	if (x->next_main_rhythm_out)
  	{
+ 		wanted_rhythm = 0;
  		// ask the memory for the wanted rhythm
  		rhythm_found = rhythm_memory_get_rhythm(x->rhythms_memory, // the memory
! 								&wanted_rhythm, // a pointer to the returned rhythm
  								// the id of the main rhythm wanted
  								x->next_main_rhythm_out, 
***************
*** 198,210 ****
  		}
  
  		// now I setup the events_out list
  		// for each event in wanted_rhythm
  		// allocate and link an element of elements_out
  
- 		//--> TODO <--
- 		
  		// also setup the timer for the first event
! 
! 		//--> TODO <--
  
  	}
--- 210,262 ----
  		}
  
+ 		if (wanted_rhythm==0)
+ 		{
+ 			error("rhythms_memory: wanted_rhythm should not be null! ");
+ 			return 0;
+ 		}
+ 
  		// now I setup the events_out list
  		// for each event in wanted_rhythm
  		// allocate and link an element of elements_out
+ 		curr_rhythm = wanted_rhythm;
+ 		lastOutEvent = 0;
+ 		while (curr_rhythm)
+ 		{
+ 			event *newEvent;
+ 			newEvent = malloc(sizeof(event));
+ 			newEvent->next = 0;
+ 			newEvent->voice = curr_rhythm->voice;
+ 			newEvent->when = (double) (duration2float(curr_rhythm->start) * x->measure_length);
+ 			post("DEBUG: add event in moment: %f", newEvent->when);
+ 			if (x->events_out)
+ 			{
+ 				// this is not the first event
+ 				// assign the next
+ 				lastOutEvent->next = newEvent;
+ 			} else
+ 			{
+ 				// this is the first event
+ 				x->events_out = newEvent;
+ 			}
+ 			// change the last pointer
+ 			lastOutEvent = newEvent;
+ 			curr_rhythm = curr_rhythm->next;
+ 		}
  
  		// also setup the timer for the first event
! 		if (x->events_out)
! 		{
! 			// setup the clock
! 			clock_delay(x->x_clock, x->events_out->when);
! 			// remember when next event will occour
! 			x->last_event_out_time = x->events_out->when;
! 			// remember the curr event
! 			lastOutEvent = x->events_out;
! 			//reassign next event
! 			x->events_out = x->events_out->next;
! 			// free old event
! 			free(lastOutEvent);
! 		}
! 		x->next_main_rhythm_out = 0;
  
  	}
***************
*** 218,238 ****
  // this function is called  by pd
  // when the timer bangs
! static void delay_tick(t_rhythms_memory *x)
  {
      // here i must:
  	// take the next element in x->events_out
  	// and compute when I'll need to schedule next event
  	// (next_event - curr_event)
- 	
- 	// TODO
- 
  	// set the next element as the current one
  	// and free the memory allocated for the old curr event
! 	
! 	// TODO
! 
! 	// set up the timer
! 
! 	// TODO
  }
  
--- 270,300 ----
  // this function is called  by pd
  // when the timer bangs
! static void rhythms_tick(t_rhythms_memory *x)
  {
+ 	event *lastOutEvent;
      // here i must:
  	// take the next element in x->events_out
  	// and compute when I'll need to schedule next event
  	// (next_event - curr_event)
  	// set the next element as the current one
  	// and free the memory allocated for the old curr event
! 	// set up the timer	
! 	post("DEBUG: eveng bang");
! 	// first of all trigger the bang!
! 	outlet_bang(x->bangs_out);
! 	//then do the stuff
! 	if (x->events_out)
! 	{
! 		// setup the clock
! 		clock_delay(x->x_clock, x->events_out->when - x->last_event_out_time);
! 		// remember when next event will occour
! 		x->last_event_out_time = x->events_out->when ;
! 		// remember the curr event
! 		lastOutEvent = x->events_out;
! 		//reassign next event
! 		x->events_out = x->events_out->next;
! 		// free old event
! 		free(lastOutEvent);
! 	}
  }
  
***************
*** 241,252 ****
  static void ask_rhythm(t_rhythms_memory *x, t_symbol *s, int argc, t_atom *argv)
  {
! 	if (argc<3)
  	{
  		error("this method needs at least 2 floats: main_rhythm and sub_rhythm wanted");
  		return;
  	}
! 	argv++;
  	x->next_main_rhythm_out = atom_getfloat(argv++);
  	x->next_sub_rhythm_out = atom_getfloat(argv);
  	// i have nothing left to do:
  	// when this measure will end a list of events_out will be set
--- 303,315 ----
  static void ask_rhythm(t_rhythms_memory *x, t_symbol *s, int argc, t_atom *argv)
  {
! 	if (argc<2)
  	{
  		error("this method needs at least 2 floats: main_rhythm and sub_rhythm wanted");
  		return;
  	}
! 	//argv++;
  	x->next_main_rhythm_out = atom_getfloat(argv++);
  	x->next_sub_rhythm_out = atom_getfloat(argv);
+ 	post("DEBUG: asked rhythm %i %i", x->next_main_rhythm_out, x->next_sub_rhythm_out); 
  	// i have nothing left to do:
  	// when this measure will end a list of events_out will be set
***************
*** 254,257 ****
--- 317,327 ----
  }
  
+ // add this rhythm to the memory
+ static void add_rhythm(t_rhythms_memory *x, t_symbol *s, int argc, t_atom *argv)
+ {
+  // TODO
+ 	post("TODO");
+ }
+ 
  static void rhythms_memory_bang(t_rhythms_memory *x) {
  
***************
*** 290,296 ****
  	time_t a;
      t_rhythms_memory *x = (t_rhythms_memory *)pd_new(rhythms_memory_class);
  	//x->l_out = outlet_new(&x->x_obj, &s_list);
! 	x->l_out = outlet_new(&x->x_obj, "symbol");
! 	
  	x->seq_initialized = 0;
  
--- 360,375 ----
  	time_t a;
      t_rhythms_memory *x = (t_rhythms_memory *)pd_new(rhythms_memory_class);
+ 	// first is for bangs (to let this external play in realtime
  	//x->l_out = outlet_new(&x->x_obj, &s_list);
! 	x->bangs_out = outlet_new(&x->x_obj, gensym("bang"));
! 	// this outputs lists of events
! 	x->list_out = outlet_new(&x->x_obj, "symbol");
! 	// this outputs info on the last detected rhythm
! 	x->info_out = outlet_new(&x->x_obj, "symbol");
! 
! 	// inlet for rhythms in the form of lists
! 	inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("list"), gensym("rhythm_in"));
! 
! 	x->x_clock = clock_new(x, (t_method)rhythms_tick);
  	x->seq_initialized = 0;
  
***************
*** 318,322 ****
  	class_addmethod(rhythms_memory_class, (t_method)crash, gensym("crash"), 0);
  	// the user asks for a rhythm
! 	class_addmethod(rhythms_memory_class, (t_method)ask_rhythm, gensym("rhythm"),
          A_GIMME, 0);
  }
--- 397,404 ----
  	class_addmethod(rhythms_memory_class, (t_method)crash, gensym("crash"), 0);
  	// the user asks for a rhythm
! 	class_addmethod(rhythms_memory_class, (t_method)ask_rhythm, gensym("rhythm_out"),
!         A_GIMME, 0);
! 	// adds a rhythm passing it as a list of floats
! 	class_addmethod(rhythms_memory_class, (t_method)add_rhythm, gensym("rhythm_in"),
          A_GIMME, 0);
  }

Index: common.c
===================================================================
RCS file: /cvsroot/pure-data/externals/frankenstein/common.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** common.c	22 Dec 2005 23:21:04 -0000	1.16
--- common.c	27 Dec 2005 01:28:51 -0000	1.17
***************
*** 684,688 ****
  // return 0 if failed finding the rhythm, 1 if the rhythm was found
  int rhythm_memory_get_rhythm(t_rhythm_memory_representation *rep_list, // the memory
! 							  t_rhythm_event *out_rhythm, // a pointer to the returned rhythm
  							  // the id of the main rhythm wanted
  							  unsigned short int id, 
--- 684,688 ----
  // return 0 if failed finding the rhythm, 1 if the rhythm was found
  int rhythm_memory_get_rhythm(t_rhythm_memory_representation *rep_list, // the memory
! 							  t_rhythm_event **out_rhythm, // a pointer to the returned rhythm
  							  // the id of the main rhythm wanted
  							  unsigned short int id, 
***************
*** 706,710 ****
  				{
  					// i've found the rhythm!
! 					out_rhythm=curr2->rhythm;
  					return 1;
  				}
--- 706,710 ----
  				{
  					// i've found the rhythm!
! 					*out_rhythm=curr2->rhythm;
  					return 1;
  				}

Index: common.h
===================================================================
RCS file: /cvsroot/pure-data/externals/frankenstein/common.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** common.h	22 Dec 2005 00:58:39 -0000	1.13
--- common.h	27 Dec 2005 01:28:51 -0000	1.14
***************
*** 258,262 ****
  // return 0 if failed finding the rhythm, 1 if the rhythm was found
  int rhythm_memory_get_rhythm(t_rhythm_memory_representation *rep_list, // the memory
! 							  t_rhythm_event *out_rhythm, // a pointer to the returned rhythm
  							  // the id of the main rhythm wanted
  							  unsigned short int id, 
--- 258,262 ----
  // return 0 if failed finding the rhythm, 1 if the rhythm was found
  int rhythm_memory_get_rhythm(t_rhythm_memory_representation *rep_list, // the memory
! 							  t_rhythm_event **out_rhythm, // a pointer to the returned rhythm
  							  // the id of the main rhythm wanted
  							  unsigned short int id, 





More information about the Pd-cvs mailing list