Commit 977e997f authored by Miller Puckette's avatar Miller Puckette
Browse files

search allows partial word matches

bug fixes
parent 070e61a4
#N canvas 281 13 533 567 12;
#N canvas -10 52 610 611 12;
#X obj 54 90 osc~ 100;
#X msg 62 117 clear;
#X obj 79 547 lop~;
#X text 10 550 see also:;
#X text 333 549 updated for Pd version-0.38;
#X obj 86 497 rzero~;
#X obj 37 517 cpole~;
#X obj 37 497 rpole~;
#X obj 135 497 rzero_rev~;
#X obj 86 517 czero~;
#X obj 135 517 czero_rev~;
#X text 213 497 real;
#X text 212 518 complex;
#X text 34 481 1-pole;
#X text 83 481 1-zero;
#X text 133 481 1-zero \, reversed;
#X text 59 466 summary of raw filters:;
#X text 73 300 y[n] = y[n-1] + a[n] * x[n];
#X text 12 369 The transfer function is H(Z) = 1/(1 - aZ^-1).;
#X text 106 116 <-- clear internal state to zero;
#X text 115 116 <-- clear internal state to zero;
#N canvas 168 90 498 357 test 0;
#X obj 76 78 osc~;
#X floatatom 76 55 5 0 0 0 - - -;
......@@ -84,18 +68,17 @@
#X connect 28 0 9 1;
#X connect 29 0 28 0;
#X restore 459 483 pd test;
#X text 113 550 etc.: user-friendly filters;
#X text 10 387 (Pd also provides a suite of user-friendly filters.
This and other raw filters are provided for situations which the user-friendly
ones can't handle. See Chapter 8 of http://crca.ucsd.edu/~msp/techniques
for an introduction to the necessary theory.);
#X obj 52 7 cpole~;
#X text 114 7 complex one-pole (recursive) filter \, raw;
#X text 118 91 <-- signal to filter (real part);
#X text 117 173 <-- signal to filter (imaginary part);
#X text 132 93 <-- signal to filter (real part);
#X text 130 173 <-- signal to filter (imaginary part);
#X obj 84 172 sig~;
#X obj 115 197 sig~;
#X text 149 199 <-- filter coefficient (real part);
#X text 162 199 <-- filter coefficient (real part);
#X obj 145 219 sig~;
#X obj 53 244 cpole~ 0.9 0.4;
#X text 159 246 <-- creation arguments initialize filter;
......@@ -104,16 +87,33 @@ for an introduction to the necessary theory.);
#X text 11 320 where y[n] is the output \, x[n] the input \, and a[n]
the filter coefficient (all complex numbers). The filter is unstable
if/when |a[n]|>1.;
#X text 8 31 Cpole~ filters a complex audio signal (first two inlets)
#X text 12 27 Cpole~ filters a complex audio signal (first two inlets)
via a one-pole filter \, whose coefficients are controlled by creation
arguments or by another complex audio signal (remaining two inlets).
;
#X text 150 144 <-- set internal state (real&imaginary parts);
#X text 171 143 <-- set internal state (real&imaginary parts);
#X msg 64 143 set 0.6 0.8;
#X text 179 221 <-- filter coefficient (imaginary part);
#X connect 0 0 31 0;
#X connect 1 0 31 0;
#X connect 27 0 31 1;
#X connect 28 0 31 2;
#X connect 30 0 31 3;
#X connect 38 0 31 0;
#X text 190 221 <-- filter coefficient (imaginary part);
#X text 73 300 y[n] = x[n] + a[n] * y[n-1];
#X obj 97 566 lop~;
#X text 11 566 see also:;
#X obj 96 497 rzero~;
#X obj 36 519 cpole~;
#X obj 36 497 rpole~;
#X obj 156 497 rzero_rev~;
#X obj 96 519 czero~;
#X obj 156 519 czero_rev~;
#X text 255 497 real;
#X text 254 520 complex;
#X text 33 481 1-pole;
#X text 93 481 1-zero;
#X text 143 481 1-zero \, reversed;
#X text 58 466 summary of raw filters:;
#X text 137 566 etc.: user-friendly filters;
#X text 343 583 updated for Pd version 0.42;
#X connect 0 0 14 0;
#X connect 1 0 14 0;
#X connect 10 0 14 1;
#X connect 11 0 14 2;
#X connect 13 0 14 3;
#X connect 21 0 14 0;
......@@ -9,7 +9,6 @@
#X text 8 35 Rpole~ filters an audio signal (left inlet) via a one-pole
real filter \, whose coefficient is controlled by a creation argument
or by an audio signal (right inlet).;
#X text 413 511 updated for Pd version-0.38;
#X obj 95 441 rzero~;
#X obj 35 463 cpole~;
#X obj 35 441 rpole~;
......@@ -28,7 +27,6 @@ or by an audio signal (right inlet).;
#X text 150 173 <-- filter coefficient (may be a signal);
#X text 150 195 <-- creation argument initializes filter coefficient
;
#X text 73 252 y[n] = y[n-1] + a[n] * x[n];
#X text 10 310 The transfer function is H(Z) = 1/(1 - aZ^-1).;
#X text 121 117 <-- clear internal state to zero;
#X text 11 272 where y[n] is the output \, x[n] the input \, and a[n]
......@@ -73,7 +71,9 @@ the filter coefficient. The filter is unstable if/when |a[n]|>1.;
and other raw filters are provided for situations which the user-friendly
ones can't handle. See Chapter 8 of http://crca.ucsd.edu/~msp/techniques
for an introduction to the necessary theory.);
#X connect 0 0 30 1;
#X connect 1 0 30 0;
#X connect 2 0 30 0;
#X connect 21 0 30 0;
#X text 73 252 y[n] = x[n] + a[n] * y[n-1];
#X text 413 511 updated for Pd version 0.42;
#X connect 0 0 28 1;
#X connect 1 0 28 0;
#X connect 2 0 28 0;
#X connect 20 0 28 0;
......@@ -1896,9 +1896,9 @@ static void canvas_menufont(t_canvas *x)
gfxstub_new(&x2->gl_pd, &x2->gl_pd, buf);
}
static int canvas_find_index1, canvas_find_index2;
static int canvas_find_index1, canvas_find_index2, canvas_find_wholeword;
static t_binbuf *canvas_findbuf;
int binbuf_match(t_binbuf *inbuf, t_binbuf *searchbuf);
int binbuf_match(t_binbuf *inbuf, t_binbuf *searchbuf, int wholeword);
/* find an atom or string of atoms */
static int canvas_dofind(t_canvas *x, int *myindex1p)
......@@ -1913,7 +1913,8 @@ static int canvas_dofind(t_canvas *x, int *myindex1p)
t_object *ob = 0;
if (ob = pd_checkobject(&y->g_pd))
{
if (binbuf_match(ob->ob_binbuf, canvas_findbuf))
if (binbuf_match(ob->ob_binbuf, canvas_findbuf,
canvas_find_wholeword))
{
if (myindex1 > canvas_find_index1 ||
myindex1 == canvas_find_index1 &&
......@@ -1943,25 +1944,16 @@ static int canvas_dofind(t_canvas *x, int *myindex1p)
return (0);
}
static void canvas_find(t_canvas *x, t_symbol *s, int ac, t_atom *av)
static void canvas_find(t_canvas *x, t_symbol *s, t_floatarg wholeword)
{
int myindex1 = 0, i;
for (i = 0; i < ac; i++)
{
if (av[i].a_type == A_SYMBOL)
{
if (!strcmp(av[i].a_w.w_symbol->s_name, "_semi_"))
SETSEMI(&av[i]);
else if (!strcmp(av[i].a_w.w_symbol->s_name, "_comma_"))
SETCOMMA(&av[i]);
}
}
int myindex1 = 0;
t_symbol *decodedsym = sys_decodedialog(s);
if (!canvas_findbuf)
canvas_findbuf = binbuf_new();
binbuf_clear(canvas_findbuf);
binbuf_add(canvas_findbuf, ac, av);
binbuf_text(canvas_findbuf, decodedsym->s_name, strlen(decodedsym->s_name));
canvas_find_index1 = 0;
canvas_find_index2 = -1;
canvas_find_wholeword = wholeword;
canvas_whichfind = x;
if (!canvas_dofind(x, &myindex1))
{
......@@ -2635,7 +2627,7 @@ void g_editor_setup(void)
class_addmethod(canvas_class, (t_method)canvas_font,
gensym("font"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_find,
gensym("find"), A_GIMME, A_NULL);
gensym("find"), A_SYMBOL, A_FLOAT, A_NULL);
class_addmethod(canvas_class, (t_method)canvas_find_again,
gensym("findagain"), A_NULL);
class_addmethod(canvas_class, (t_method)canvas_find_parent,
......
......@@ -1308,7 +1308,7 @@ static t_binbuf *binbuf_convert(t_binbuf *oldb, int maxtopd)
}
/* function to support searching */
int binbuf_match(t_binbuf *inbuf, t_binbuf *searchbuf)
int binbuf_match(t_binbuf *inbuf, t_binbuf *searchbuf, int wholeword)
{
int indexin, nmatched;
for (indexin = 0; indexin <= inbuf->b_n - searchbuf->b_n; indexin++)
......@@ -1317,15 +1317,25 @@ int binbuf_match(t_binbuf *inbuf, t_binbuf *searchbuf)
{
t_atom *a1 = &inbuf->b_vec[indexin + nmatched],
*a2 = &searchbuf->b_vec[nmatched];
if (a1->a_type != a2->a_type ||
a1->a_type == A_SYMBOL && a1->a_w.w_symbol != a2->a_w.w_symbol
||
a1->a_type == A_FLOAT && a1->a_w.w_float != a2->a_w.w_float
||
a1->a_type == A_DOLLAR && a1->a_w.w_index != a2->a_w.w_index
||
a1->a_type == A_DOLLSYM && a1->a_w.w_symbol != a2->a_w.w_symbol)
if (a1->a_type == A_SEMI || a1->a_type == A_COMMA)
{
if (a2->a_type != a1->a_type)
goto nomatch;
}
else if (a1->a_type == A_FLOAT || a1->a_type == A_DOLLAR)
{
if (a2->a_type != a1->a_type ||
a1->a_w.w_float != a2->a_w.w_float)
goto nomatch;
}
else if (a1->a_type == A_SYMBOL || a1->a_type == A_DOLLSYM)
{
if ((a2->a_type != A_SYMBOL && a2->a_type == A_DOLLSYM)
|| (wholeword && a1->a_w.w_symbol != a2->a_w.w_symbol)
|| (!wholeword && !strstr(a1->a_w.w_symbol->s_name,
a2->a_w.w_symbol->s_name)))
goto nomatch;
}
}
return (1);
nomatch: ;
......
......@@ -25,9 +25,6 @@ static int pa_inchans, pa_outchans;
static float *pa_soundin, *pa_soundout;
static t_audiocallback pa_callback;
#define MAX_PA_CHANS 32
#define MAX_SAMPLES_PER_FRAME MAX_PA_CHANS * DEFDACBLKSIZE
int pa_foo;
static int pa_lowlevel_callback(const void *inputBuffer,
......
......@@ -419,9 +419,9 @@ int sys_rcfile(void)
for (i = 1; i < NUMARGS-1; i++)
{
if (fscanf(file, "%999s", buf) < 0)
if (fscanf(file, "%998s", buf) < 0)
break;
buf[1000] = 0;
buf[999] = 0;
if (!(rcargv[i] = malloc(strlen(buf) + 1)))
goto cleanup;
strcpy(rcargv[i], buf);
......@@ -437,7 +437,7 @@ int sys_rcfile(void)
fclose(file);
if (sys_verbose)
{
if (rcargv)
if (rcargc)
{
post("startup args from RC file:");
for (i = 1; i < rcargc; i++)
......
......@@ -28,7 +28,7 @@ int sys_open_absolute(const char *name, const char* ext,
char *dirresult, char **nameresult, unsigned int size, int bin, int *fdp);
int sys_trytoopenone(const char *dir, const char *name, const char* ext,
char *dirresult, char **nameresult, unsigned int size, int bin);
t_symbol *sys_decodedialog(t_symbol *s);
/* s_file.c */
......
......@@ -835,16 +835,12 @@ proc menu_fixwindowmenu {name} {
set find_canvas nobody
set find_string ""
set find_count 1
set find_wholeword 1
proc find_apply {name} {
global find_string
global find_canvas
regsub -all \; $find_string " _semi_ " find_string2
regsub -all \, $find_string2 " _comma_ " find_string3
# puts stderr [concat $find_canvas find $find_string3 \
# \;]
pd [concat $find_canvas find $find_string3 \
\;]
global find_string find_canvas find_wholeword
pd [concat $find_canvas find [pdtk_encodedialog $find_string] \
$find_wholeword \;]
after 50 destroy $name
}
......@@ -853,9 +849,7 @@ proc find_cancel {name} {
}
proc menu_findobject {canvas} {
global find_string
global find_canvas
global find_count
global find_string find_canvas find_count find_wholeword
set name [format ".find%d" $find_count]
set find_count [expr $find_count + 1]
......@@ -869,6 +863,9 @@ proc menu_findobject {canvas} {
entry $name.entry -textvariable find_string
pack $name.entry -side top
checkbutton $name.wholeword -variable find_wholeword \
-text {whole word} -anchor e
pack $name.wholeword -side bottom
frame $name.buttonframe
pack $name.buttonframe -side bottom -fill x -pady 2m
......@@ -4233,7 +4230,9 @@ proc path_apply {id} {
for {set x 0} {$x < $pd_path_count} {incr x} {
global pd_path$x
set this_path [set pd_path$x]
if {0==[string match "" $this_path]} {lappend pd_path [pdtk_encodedialog $this_path]}
if {0==[string match "" $this_path]} {
lappend pd_path [pdtk_encodedialog $this_path]
}
}
pd [concat pd path-dialog $pd_extrapath $pd_verbose $pd_path \;]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment