Skip to content

Commit

Permalink
closes #581
Browse files Browse the repository at this point in the history
  • Loading branch information
porres committed Mar 13, 2024
1 parent f27574d commit dc25f6b
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 120 deletions.
115 changes: 39 additions & 76 deletions cyclone_objects/binaries/control/offer.c 100644 → 100755
Expand Up @@ -6,112 +6,75 @@
#include <common/api.h>
#include "control/tree.h"

//adding offer_bang, typecasting arg in offer_ft1 to and from int to get rid of mantissa - Derek Kwan 2016

/* As a class `derived' from the common hammertree code (also in funbuff),
offer maintains the auxiliary list, the main purpose of which is faster
traversal (not needed here). As a side-effect, there is a bonus of a small
speedup of deletion, and a penalty of a small slowdown of insertion. */

typedef struct _offer
{
t_object x_ob;
t_float x_value; //value received in inlet 1
int x_valueset; //if a value has been received in inlet 1
t_hammertree x_tree; // a red-black tree!
} t_offer;
// Derek and Porres, added offer_bang and cleanup

typedef struct _offer{
t_object x_obj;
t_float x_value;
int x_valueset;
t_hammertree x_tree;
}t_offer;

static t_class *offer_class;

static void offer_float(t_offer *x, t_float f)
{
int ndx;
if((int)f == f) /* CHECKED */
{
t_hammernode *np;
if (x->x_valueset)
{
hammertree_insertfloat(&x->x_tree, ndx, x->x_value, 1);
static void offer_float(t_offer *x, t_float f){
int ndx = (int)f;
if((t_float)ndx == f){
t_hammernode *np;
if(x->x_valueset){
hammertree_insertfloat(&x->x_tree, ndx, x->x_value, 1);
x->x_valueset = 0;
}
else if (np = hammertree_search(&x->x_tree, ndx))
{
outlet_float(((t_object *)x)->ob_outlet, HAMMERNODE_GETFLOAT(np));
hammertree_delete(&x->x_tree, np);
}
}
else if(np = hammertree_search(&x->x_tree, ndx)){
outlet_float(((t_object *)x)->ob_outlet, HAMMERNODE_GETFLOAT(np));
hammertree_delete(&x->x_tree, np);
}
}
else{
else
pd_error(x, "[offer]: doesn't understand \"noninteger float\"");
}
}

static void offer_ft1(t_offer *x, t_floatarg f)
{
/* this is incompatible -- CHECKED float is silently truncated */

//getting rid of the mantissa a cheap way - DK
int val = (int)f;
x->x_value = (t_float)val;
static void offer_ft1(t_offer *x, t_floatarg f){
x->x_value = (int)f;
x->x_valueset = 1;
}

static void offer_clear(t_offer *x)
{
hammertree_clear(&x->x_tree, 0);
/* CHECKED valueset is not cleared */
static void offer_bang(t_offer * x){
t_hammernode * node = x->x_tree.t_last;
while(node){
t_float curf = HAMMERNODE_GETFLOAT(node);
outlet_float(((t_object *)x)->ob_outlet, curf);
node = node->n_prev;
};
}

#ifdef HAMMERTREE_DEBUG
static void offer_debug(t_offer *x, t_floatarg f)
{
hammertree_debug(&x->x_tree, (int)f, 0);
static void offer_clear(t_offer *x){
hammertree_clear(&x->x_tree, 0);
}
#endif

static void offer_free(t_offer *x)
{
static void offer_free(t_offer *x){
hammertree_clear(&x->x_tree, 0);
}

static void *offer_new(void)
{
static void *offer_new(void){
t_offer *x = (t_offer *)pd_new(offer_class);
x->x_valueset = 0;
hammertree_inittyped(&x->x_tree, HAMMERTYPE_FLOAT, 0);
inlet_new((t_object *)x, (t_pd *)x, &s_float, gensym("ft1"));
outlet_new((t_object *)x, &s_float);
return (x);
}

static void offer_bang(t_offer * x){

t_hammernode * node = x->x_tree.t_last;

//traverse doubly-linked list, grab float value from each node and set in flist
while(node){
t_float curf = HAMMERNODE_GETFLOAT(node);
outlet_float(((t_object *)x)->ob_outlet, curf);
node = node->n_prev;

};


return(x);
}

CYCLONE_OBJ_API void offer_setup(void)
{
offer_class = class_new(gensym("offer"),
(t_newmethod)offer_new,
(t_method)offer_free,
sizeof(t_offer), 0, 0);
CYCLONE_OBJ_API void offer_setup(void){
offer_class = class_new(gensym("offer"), (t_newmethod)offer_new,
(t_method)offer_free, sizeof(t_offer), 0, 0);
class_addfloat(offer_class, offer_float);
class_addmethod(offer_class, (t_method)offer_ft1,
gensym("ft1"), A_FLOAT, 0);
class_addmethod(offer_class, (t_method)offer_clear,
gensym("clear"), 0);
class_addmethod(offer_class, (t_method)offer_ft1, gensym("ft1"), A_FLOAT, 0);
class_addmethod(offer_class, (t_method)offer_clear, gensym("clear"), 0);
class_addbang(offer_class, offer_bang);
#ifdef HAMMERTREE_DEBUG
class_addmethod(offer_class, (t_method)offer_debug,
gensym("debug"), A_DEFFLOAT, 0);
#endif
}
92 changes: 48 additions & 44 deletions documentation/help_files/offer-help.pd
@@ -1,55 +1,59 @@
#N canvas 520 70 560 535 10;
#X obj 2 308 cnv 3 550 3 empty empty inlets 8 12 0 13 #dcdcdc #000000 0;
#X obj 3 439 cnv 3 550 3 empty empty outlets 8 12 0 13 #dcdcdc #000000 0;
#X obj 3 473 cnv 3 550 3 empty empty arguments 8 12 0 13 #dcdcdc #000000 0;
#X obj 88 316 cnv 17 3 94 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
#X obj 87 448 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
#X text 278 482 (none);
#X obj 86 414 cnv 17 3 17 empty empty 1 5 9 0 16 #dcdcdc #9c9c9c 0;
#N canvas 487 52 572 545 10;
#X obj 2 328 cnv 3 550 3 empty empty inlets 8 12 0 13 #dcdcdc #000000 0;
#X obj 3 440 cnv 3 550 3 empty empty outlets 8 12 0 13 #dcdcdc #000000 0;
#X obj 3 474 cnv 3 550 3 empty empty arguments 8 12 0 13 #dcdcdc #000000 0;
#X obj 88 336 cnv 17 3 74 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
#X obj 87 449 cnv 17 3 17 empty empty 0 5 9 0 16 #dcdcdc #9c9c9c 0;
#X text 278 483 (none);
#X obj 86 415 cnv 17 3 17 empty empty 1 5 9 0 16 #dcdcdc #9c9c9c 0;
#X obj 150 242 cyclone/offer;
#X obj 3 528 cnv 1 550 1 empty empty empty 0 0 0 4 #fcfcfc #fcfcfc 0;
#X obj 3 507 cnv 15 552 21 empty empty empty 20 12 0 14 #e0e0e0 #202020 0;
#X msg 346 210 clear;
#X obj 286 247 cyclone/offer;
#X text 124 317 float;
#X text 130 360 list;
#X text 124 414 float;
#X text 124 449 float;
#X text 124 394 clear;
#X text 174 414 - 'y' value \, before setting 'x' in the left inlet, f 60;
#X text 174 449 - 'y' value corresponding to a given 'x', f 60;
#X obj 150 277 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
#X obj 150 165 trigger b b;
#X obj 3 548 cnv 1 550 1 empty empty empty 0 0 0 4 #fcfcfc #fcfcfc 0;
#X obj 3 508 cnv 15 552 21 empty empty empty 20 12 0 14 #e0e0e0 #202020 0;
#X msg 377 210 clear;
#X obj 317 247 cyclone/offer;
#X text 124 337 float;
#X text 124 415 float;
#X text 124 450 float;
#X text 124 392 clear;
#X text 174 415 - 'y' value \, before setting 'x' in the left inlet, f 60;
#X text 174 450 - 'y' value corresponding to a given 'x', f 60;
#X obj 150 273 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
#X obj 150 170 trigger b b;
#X text 247 198 y;
#X text 175 199 x;
#X text 52 194 retrieve;
#X text 52 208 & delete;
#X msg 112 199 8;
#X obj 150 141 bng 15 250 50 0 empty empty empty 17 7 0 10 #dcdcdc #000000 #000000;
#X obj 286 277 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
#X text 174 394 - clears the stored pairs, f 60;
#X text 130 377 bang;
#X obj 301 182 hradio 15 1 0 4 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0;
#X floatatom 301 207 5 0 0 0 - - - 0;
#X obj 150 141 bng 18 250 50 0 empty empty empty 17 7 0 10 #dcdcdc #000000 #000000;
#X obj 317 273 nbx 5 14 -1e+37 1e+37 0 0 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0 256;
#X text 174 392 - clears the stored pairs, f 60;
#X text 130 375 bang;
#X obj 332 182 hradio 15 1 0 4 empty empty empty 0 -8 0 10 #dcdcdc #000000 #000000 0;
#X floatatom 332 207 5 0 0 0 - - - 0;
#X msg 150 199 8;
#X msg 213 199 23;
#X msg 286 153 0 10 \, 1 11 \, 2 12 \, 3 13;
#X text 58 86 [offer] stores a x/y integer number pair and accesses the 'y' value from the corresponding 'x' (after retrieving \, the pair is deleted).;
#X text 370 181 <= retrieve & delete;
#X text 174 317 - 'x' value: outputs the corresponding 'y' value and deletes the x/y pair. Sets the 'x' value of a x/y pair if the 'y' value was previously set in the right inlet.;
#X text 174 360 - two integers: the x/y pair of values to store, f 60;
#X text 174 377 - outputs every stored 'y' values (without deleting);
#X text 58 86 [offer] stores a x/y integer number pair and accesses the 'y' value from the corresponding 'x' (after retrieving \, the pair is deleted)., f 69;
#X text 401 181 <= retrieve & delete;
#X text 174 337 - 'x' value: outputs the corresponding 'y' value and deletes the x/y pair. Sets the 'x' value of a x/y pair if the 'y' value was previously set in the right inlet.;
#X text 174 375 - outputs every stored 'y' values (without deleting), f 60;
#X obj 2 2 ./header offer;
#X text 22 61 Store one-time number pairs;
#X connect 7 0 19 0;
#X obj 317 300 print offer;
#X obj 150 300 print offer;
#X obj 293 203 bng 18 250 50 0 empty empty empty 0 -8 0 10 #dfdfdf #000000 #000000;
#X msg 317 153 0 10 \, 1 11 \, 2 12 \, 3 13;
#X connect 7 0 18 0;
#X connect 10 0 11 0;
#X connect 11 0 27 0;
#X connect 20 0 32 0;
#X connect 20 1 33 0;
#X connect 25 0 7 0;
#X connect 26 0 20 0;
#X connect 30 0 31 0;
#X connect 31 0 11 0;
#X connect 32 0 7 0;
#X connect 33 0 7 1;
#X connect 34 0 11 0;
#X connect 11 0 26 0;
#X connect 18 0 40 0;
#X connect 19 0 31 0;
#X connect 19 1 32 0;
#X connect 24 0 7 0;
#X connect 25 0 19 0;
#X connect 26 0 39 0;
#X connect 29 0 30 0;
#X connect 30 0 11 0;
#X connect 31 0 7 0;
#X connect 32 0 7 1;
#X connect 41 0 11 0;
#X connect 42 0 11 0;

0 comments on commit dc25f6b

Please sign in to comment.