Commit 0eeeb22e authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

This adds the following:

* b_sym field to t_textbuf
* 2nd inlet and "send" method for text define
* text insert class
* improve a stray evalfile error
* show the [text] name (if it exists) in the title for the window
* updates help doc accordingly
parent dd632b2d
Pipeline #2201 passed with stage
in 241 minutes and 49 seconds
#N struct text-help-struct float x float y text z;
#N canvas 781 162 622 555 12;
#X obj 131 499 list;
#N canvas 976 92 622 580 12;
#X obj 131 529 list;
#X obj 18 6 text;
#X text 25 498 see also:;
#X text 25 528 see also:;
#N canvas 0 50 600 400 (subpatch) 0;
#N canvas 0 50 450 250 (subpatch) 0;
#X array table4 100 float 0;
#X array table4 100 float 0 black black;
#X coords 0 1 99 -1 500 300 1;
#X restore 50 50 graph;
#X restore 171 499 array;
#X restore 171 529 array;
#X obj 280 217 text define;
#X text 81 173 The text object's first argument sets its function:
, f 30;
#N canvas 636 69 631 661 define 0;
#N canvas 1163 93 631 733 define 0;
#X msg 39 141 clear;
#X msg 37 167 read text-object-help.txt;
#X msg 40 196 write text-object-help.txt;
#X msg 46 167 read text-object-help.txt;
#X msg 51 196 write text-object-help.txt;
#X text 32 20 "text define" maintains a text object and can name it
so that other objects can find it (and later should have some alternative
\, anonymous way to be found).;
#X text 61 376 click to open and edit text:;
#X text 296 364 creation arguments:;
#X text 324 382 optional -k flag to keep contents;
#X text 326 399 optional name;
#X text 91 416 click to open and edit text:;
#X text 296 404 creation arguments:;
#X text 306 439 optional name;
#X text 77 263 (optionally you can read or write to/from a file interpreting
carriage returns as separators \; this should allow reading some text
file formats - like this:);
#X text 274 165 read from a file;
#X text 276 196 write to a file;
#X text 277 139 clear;
#X obj 48 228 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
#X text 253 165 read from a file;
#X text 257 196 write to a file;
#X obj 58 228 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X obj 38 491 t b p;
#X obj 38 540 text get -s text t;
#X msg 39 515 0;
#X obj 38 590 print;
#X obj 38 565 list trim;
#X text 204 499 machinery for printing out first line of text when
output as a pointer (by "bang" method above)., f 30;
#X text 69 222 bang to output a pointer to a scalar (struct) containing
#X obj 38 531 t b p;
#X obj 38 580 text get -s text t;
#X msg 39 555 0;
#X obj 38 630 print;
#X obj 38 605 list trim;
#X text 79 222 bang to output a pointer to a scalar (struct) containing
the text, f 35;
#X obj 38 400 text define -k text-help-1;
#X obj 38 440 text define -k text-help-1;
#A set this is a message \; this is another 1 ... \;;
#X msg 149 326 write -c /tmp/test-cr.txt;
#X connect 0 0 20 0;
#X connect 1 0 20 0;
#X connect 2 0 20 0;
#X connect 12 0 20 0;
#X connect 13 0 15 0;
#X connect 13 1 14 3;
#X connect 14 0 17 0;
#X msg 68 354 send text-help-send;
#X text 213 354 send pointer to a named receive object;
#X obj 438 110 r text-help-send;
#X obj 438 139 print;
#X obj 217 470 print notify-outlet;
#X text 215 498 Second outlet notifies you when text changes. As of
Pd 0.48 this only outputs the message "updated" when text changes \,
but this might be extended to offer more information in the future.
, f 42;
#X text 119 616 First outlet is pointer to a "text" scalar containing
the text \, which is output when the object is sent a "bang". For example
\, here's machinery for printing out first line of text., f 46;
#X text 107 139 clear the object's state;
#X msg 105 384 click;
#X msg 153 384 close;
#X text 201 384 open and close text window;
#X text 304 422 optional -k flag to save contents with patch;
#X connect 0 0 17 0;
#X connect 1 0 17 0;
#X connect 2 0 17 0;
#X connect 10 0 17 0;
#X connect 11 0 13 0;
#X connect 11 1 12 3;
#X connect 12 0 15 0;
#X connect 13 0 12 0;
#X connect 15 0 14 0;
#X connect 17 0 16 0;
#X connect 20 0 13 0;
#X connect 21 0 20 0;
#X connect 17 0 11 0;
#X connect 17 1 23 0;
#X connect 18 0 17 0;
#X connect 19 0 17 0;
#X connect 21 0 22 0;
#X connect 27 0 17 0;
#X connect 28 0 17 0;
#X restore 392 217 pd define;
#X obj 280 240 text get;
#N canvas 885 156 859 566 get 0;
......@@ -159,7 +177,7 @@ inlet -- none to specify whole line), f 63;
#X text 58 35 a simple example showing how to access text in data structures
via pointers.;
#N canvas 851 144 450 300 text-help-data 0;
#X scalar text-help-struct 20 20 \; 1 2 3 \\\; a b c d \\\; \;;
#X scalar text-help-struct 20 20 \; 1 2 3 \;;
#X text 13 86 We have one datum (above) whose "z" field is text.;
#X restore 209 108 pd text-help-data;
#X msg 205 258 traverse pd-text-help-data \, next, f 18;
......@@ -194,11 +212,11 @@ via pointers.;
#X connect 21 0 18 0;
#X connect 22 0 17 0;
#X connect 23 0 17 0;
#X restore 83 459 pd text-and-data-structures;
#X text 73 435 here's how to access texts inside data structures:;
#X restore 83 489 pd text-and-data-structures;
#X text 73 465 here's how to access texts inside data structures:;
#X text 63 6 - manage a list of messages;
#X obj 219 499 scalar;
#X obj 280 312 text size;
#X obj 219 529 scalar;
#X obj 280 342 text size;
#N canvas 847 155 741 313 size 0;
#X obj 71 55 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
......@@ -220,7 +238,7 @@ of range);
#X connect 2 0 3 0;
#X connect 4 0 2 0;
#X connect 9 0 2 1;
#X restore 392 311 pd size;
#X restore 392 341 pd size;
#X obj 280 264 text set;
#N canvas 483 595 834 537 set 0;
#X floatatom 107 197 5 0 0 0 - - -, f 5;
......@@ -270,14 +288,14 @@ to whole line), f 47;
#X text 60 216 create \, store \, and/or edit;
#X text 91 239 read and output a line;
#X text 100 263 replace or add a line;
#X text 115 313 get number of lines;
#X text 115 343 get number of lines;
#X text 62 50 In Pd a "text" refers to a list of atoms that can include
commas \, semicolons \, and dollar-sign constructs - anything that
can go in a message box or a patch (as a saved file). You can use them
to store a semicolon-separated list of lists \, or as messages to "execute"
as in a sequencer or message box.;
#X text 145 337 convert to list;
#X obj 280 335 text tolist;
#X text 145 367 convert to list;
#X obj 280 365 text tolist;
#N canvas 842 231 590 379 tolist 0;
#X obj 86 99 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
......@@ -289,7 +307,7 @@ backslashes).;
#X obj 86 180 text tolist text-help-1;
#X obj 173 218 list prepend set;
#X obj 173 241 list trim;
#X msg 173 291 this is a message \\\; this is another 1 ... \\\;;
#X msg 173 291 this is a message \; this is another 1 ... \;;
#X msg 187 265 set;
#X obj 87 218 print;
#X text 72 326 N.B.: text-help-1 is defined in 'pd define' subwindow.
......@@ -305,16 +323,15 @@ backslashes).;
#X connect 5 0 6 0;
#X connect 7 0 6 0;
#X connect 11 0 3 1;
#X restore 392 335 pd tolist;
#X obj 280 359 text fromlist;
#X restore 392 365 pd tolist;
#X obj 280 389 text fromlist;
#N canvas 842 231 604 318 fromlist 0;
#X obj 81 202 text fromlist text-help-fromlist;
#X obj 114 263 text define text-help-fromlist;
#X text 46 21 "text fromlist" converts a list such as "text tolist"
would output and fills the text with it. Whatever the text had previously
contained is discarded.;
#X msg 81 115 list this is a message \\\; this is another 1 ... \\\;
;
#X msg 81 115 list this is a message \; this is another 1 ... \;;
#X text 135 241 click here to see contents;
#X msg 92 145 list 1 2 3;
#X text 437 157 find another text by name or pointer, f 18;
......@@ -323,10 +340,10 @@ contained is discarded.;
#X connect 3 0 0 0;
#X connect 5 0 0 0;
#X connect 7 0 0 1;
#X restore 392 359 pd fromlist;
#X text 131 361 convert from list;
#X text 218 384 search;
#X obj 280 383 text search;
#X restore 392 389 pd fromlist;
#X text 131 391 convert from list;
#X text 218 414 search;
#X obj 280 413 text search;
#N canvas 626 77 1011 913 search 0;
#X floatatom 60 313 5 0 0 0 - - -, f 5;
#X text 385 232 find another text by name or pointer, f 18;
......@@ -426,9 +443,9 @@ far from it) so line 0 whose second field is closer to 1 wins., f
#X connect 42 0 40 0;
#X connect 43 0 40 0;
#X connect 44 0 40 0;
#X restore 393 383 pd search;
#X text 76 408 sequencer/message-sender;
#X obj 280 406 text sequence;
#X restore 393 413 pd search;
#X text 76 438 sequencer/message-sender;
#X obj 280 436 text sequence;
#N canvas 199 57 1155 839 sequence 0;
#X msg 138 468 symbol text-help-search;
#X text 101 443 specify another text by name or pointer;
......@@ -578,10 +595,10 @@ simply sequence a list of numbers:;
#X connect 61 2 62 0;
#X connect 65 0 30 0;
#X connect 69 0 7 0;
#X restore 393 406 pd sequence;
#X text 365 497 updated for Pd version 0.47;
#X text 100 287 delete a line or clear;
#X obj 280 288 text delete;
#X restore 393 436 pd sequence;
#X text 365 527 updated for Pd version 0.47;
#X text 100 317 delete a line or clear;
#X obj 280 318 text delete;
#N canvas 1058 154 749 465 delete 0;
#X text 409 144 find another text by name or pointer;
#X text 319 257 <-- click here to see text;
......@@ -595,8 +612,8 @@ simply sequence a list of numbers:;
#X msg 58 89 -1;
#X text 98 92 clear whole text;
#X obj 57 401 text fromlist text-help-delete;
#X msg 57 376 list line 0 \\\; line 1 \\\; line 2 \\\; line 3 \\\;
line 4 \\\;;
#X msg 57 376 list line 0 \; line 1 \; line 2 \; line 3 \; line 4 \;
;
#X text 78 353 click below to get original text back:;
#X text 46 9 "text delete" deletes the nth line.;
#X text 88 62 delete line nyumber 2 (counting from 0);
......@@ -604,4 +621,38 @@ line 4 \\\;;
#X connect 6 0 2 0;
#X connect 7 0 2 0;
#X connect 10 0 9 0;
#X restore 392 287 pd delete;
#X restore 392 317 pd delete;
#X text 166 290 insert a line;
#X obj 280 291 text insert;
#N canvas 1076 169 744 566 insert 0;
#X text 448 177 find another text by name or pointer;
#X msg 275 177 symbol text-help-delete;
#X msg 171 109 2;
#X msg 163 353 list line 0 \; line 1 \; line 2 \; line 3 \; line 4
\;;
#X text 184 330 click below to get original text back:;
#X obj 163 464 text fromlist text-help-insert;
#X obj 98 283 text define -k text-help-insert;
#A set line 0 \; line 1 \; line 2 \; 12 23 34 45 56 56 \; line 3 \;
line 4 \;;
#X msg 183 137 1e+09;
#X text 232 139 insert after end;
#X msg 69 84 list x y z w;
#X msg 85 111 1 2 3;
#X msg 50 57 12 23 34 45 56 56;
#X text 183 57 list to insert into the text;
#X text 292 210 arguments: name of the text object or "-s struct-name"
;
#X text 293 231 one optional arg to set inlet 1 (line number);
#X obj 68 210 text insert text-help-insert 3;
#X text 71 14 "text insert" inserts a line.;
#X text 210 109 insert before line number 2 (counting from 0);
#X text 333 285 <= click here to see text;
#X connect 1 0 15 2;
#X connect 2 0 15 1;
#X connect 3 0 5 0;
#X connect 7 0 15 1;
#X connect 9 0 15 0;
#X connect 10 0 15 0;
#X connect 11 0 15 0;
#X restore 392 291 pd insert;
......@@ -64,6 +64,7 @@ function apply() {
line = line.replace("$", " \\$ ");
pdgui.pdsend(pd_object_callback, "addline", line);
});
pdgui.pdsend(pd_object_callback, "notify");
dirty = 0;
}
......@@ -100,11 +101,13 @@ function set_dirty(state) {
// This gets called from the nw_create_window function in index.html
// It provides us with our window id from the C side. Once we have it
// we can create the menu and register event callbacks
function register_window_id(gfxstub, text_string) {
function register_window_id(gfxstub, attr) {
var head, tail, templates, data, data_separator;
pd_object_callback = gfxstub;
add_events(gfxstub);
pdgui.post("title is " + attr.title);
translate_form();
// We request the text data only after we're certain our window
// has loaded. Otherwise the node.js context might try to populate
......@@ -114,12 +117,24 @@ function register_window_id(gfxstub, text_string) {
// creates the window.
pdgui.pdsend(gfxstub, "map");
// Quick and dirty-- just set the host fontsize in "pt" here. We probably
// do all kinds of kludges to get fonts sized correctly to fit into boxes
// on the canvas. I don't think it matters whether it's exactly the same
// here, so let's just use point sizes.
document.getElementsByClassName("container")[0]
.style.setProperty("font-size", attr.fontsize + "pt");
// We don't turn on rendering of the "container" div until
// We've finished displaying all the spans and populating the
// labels and form elements. That makes it more efficient and
// snappier, at least on older machines.
document.getElementsByClassName("container")[0]
.style.setProperty("display", "inline");
// Hack-- add the title. Currently this is set first by nw.js when the
// nwjs window, so you'll see a flicker to the title set here if it's
// not "text". We need to change this so that the title can be different
// from the dialog type in nw_create_window.
document.title = attr.title;
}
// Stop-gap translator
......
......@@ -5452,10 +5452,14 @@ function gui_text_dialog_set_dirty(did, state) {
}
}
function gui_text_dialog(did, width, height, font_size) {
function gui_text_dialog(did, name, width, height, font_size) {
dialogwin[did] = create_window(did, "text", width, height,
popup_coords[2], popup_coords[3],
font_size);
{
fontsize: font_size,
title: name
}
);
}
function dialog_raise(did) {
......
......@@ -9,6 +9,7 @@
#include "s_stuff.h"
#include "g_canvas.h"
#include <stdio.h>
#include <errno.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
......@@ -1673,12 +1674,12 @@ void binbuf_evalfile(t_symbol *name, t_symbol *dir)
t_binbuf *b = binbuf_new();
int import = !strcmp(name->s_name + strlen(name->s_name) - 4, ".pat") ||
!strcmp(name->s_name + strlen(name->s_name) - 4, ".mxt");
/* set filename so that new canvases can pick them up */
int dspstate = canvas_suspend_dsp();
/* set filename so that new canvases can pick them up */
glob_setfilename(0, name, dir);
if (binbuf_read(b, name->s_name, dir->s_name, 0))
{
error("%s: read failed", name->s_name);
error("%s: read failed: %s", name->s_name, strerror(errno));
}
else
{
......
......@@ -49,12 +49,14 @@ typedef struct _textbuf
t_binbuf *b_binbuf;
t_canvas *b_canvas;
t_guiconnect *b_guiconnect;
t_symbol *b_sym;
} t_textbuf;
static void textbuf_init(t_textbuf *x)
static void textbuf_init(t_textbuf *x, t_symbol *sym)
{
x->b_binbuf = binbuf_new();
x->b_canvas = canvas_getcurrent();
x->b_sym = sym;
}
static void textbuf_senditup(t_textbuf *x)
......@@ -120,11 +122,12 @@ static void textbuf_open(t_textbuf *x)
//glist_getzoom(x->b_canvas)));
sprintf(buf, "x%lx", (unsigned long)x);
x->b_guiconnect = guiconnect_new(&x->b_ob.ob_pd, gensym(buf));
gui_vmess("gui_text_dialog", "xiii",
gui_vmess("gui_text_dialog", "xsiii",
x,
x->b_sym->s_name,
600,
340,
sys_hostfontsize(glist_getfont(x->b_canvas)));
sys_hostfontsize(glist_getfont(x->b_canvas)));
//textbuf_senditup(x);
}
}
......@@ -266,6 +269,7 @@ typedef struct _text_define
{
t_textbuf x_textbuf;
t_outlet *x_out;
t_outlet *x_notifyout;
t_symbol *x_bindsym;
t_scalar *x_scalar; /* faux scalar (struct text-scalar) to point to */
t_gpointer x_gp; /* pointer to it */
......@@ -306,12 +310,14 @@ static void *text_define_new(t_symbol *s, int argc, t_atom *argv)
post("warning: text define ignoring extra argument: ");
postatom(argc, argv); endpost();
}
textbuf_init(&x->x_textbuf);
textbuf_init(&x->x_textbuf, *x->x_bindsym->s_name ? x->x_bindsym :
gensym("text"));
/* set up a scalar and a pointer to it that we can output */
x->x_scalar = scalar_new(canvas_getcurrent(), gensym("pd-text"));
binbuf_free(x->x_scalar->sc_vec[2].w_binbuf);
x->x_scalar->sc_vec[2].w_binbuf = x->x_binbuf;
x->x_out = outlet_new(&x->x_ob, &s_pointer);
x->x_notifyout = outlet_new(&x->x_ob, 0);
gpointer_init(&x->x_gp);
x->x_canvas = canvas_getcurrent();
/* bashily unbind #A -- this would create garbage if #A were
......@@ -402,6 +408,27 @@ static void text_define_save(t_gobj *z, t_binbuf *bb)
obj_saveformat(&x->x_ob, bb);
}
/* send a pointer to the scalar that owns this text to
whomever is bound to the given symbol */
static void text_define_send(t_text_define *x, t_symbol *s)
{
if (!s->s_thing)
pd_error(x, "text_define_send: %s: no such object", s->s_name);
else
{
gpointer_setglist(&x->x_gp, x->x_canvas, (t_gobj *)x->x_scalar);
pd_pointer(s->s_thing, &x->x_gp);
}
}
/* notification from GUI that we've been updated */
static void text_define_notify(t_text_define *x)
{
outlet_anything(x->x_notifyout, gensym("updated"), 0, 0);
textbuf_senditup(&x->x_textbuf);
}
static void text_define_free(t_text_define *x)
{
textbuf_free(&x->x_textbuf);
......@@ -782,6 +809,75 @@ static void text_set_list(t_text_set *x,
text_client_senditup(&x->x_tc);
}
/* --------- text_insert object - insert a line ----------- */
typedef struct _text_insert
{
t_text_client x_tc;
t_float x_f1; /* line number */
} t_text_insert;
t_class *text_insert_class;
static void *text_insert_new(t_symbol *s, int argc, t_atom *argv)
{
t_text_insert *x = (t_text_insert *)pd_new(text_insert_class);
floatinlet_new(&x->x_obj, &x->x_f1);
x->x_f1 = 0;
text_client_argparse(&x->x_tc, &argc, &argv, "text insert");
if (argc)
{
if (argv->a_type == A_FLOAT)
x->x_f1 = argv->a_w.w_float;
else
{
post("text insert: can't understand line number");
postatom(argc, argv); endpost();
}
argc--; argv++;
}
if (argc)
{
post("warning: text insert ignoring extra argument: ");
postatom(argc, argv); endpost();
}
if (x->x_struct)
pointerinlet_new(&x->x_obj, &x->x_gp);
else symbolinlet_new(&x->x_obj, &x->x_tc.tc_sym);
return (x);
}
static void text_insert_list(t_text_insert *x,
t_symbol *s, int argc, t_atom *argv)
{
t_binbuf *b = text_client_getbuf(&x->x_tc);
int start, end, n, nwas, i,
lineno = (x->x_f1 > (double)0x7fffffff ? 0x7fffffff : x->x_f1);
t_atom *vec;
if (!b)
return;
if (lineno < 0)
{
pd_error(x, "text insert: line number (%d) < 0", lineno);
return;
}
nwas = binbuf_getnatom(b);
if (!text_nthline(nwas, binbuf_getvec(b), lineno, &start, &end))
start = nwas;
(void)binbuf_resize(b, (n = nwas + argc + 1));
vec = binbuf_getvec(b);
if (start < n)
memmove(&vec[start+(argc+1)], &vec[start], sizeof(*vec) * (nwas-start));
for (i = 0; i < argc; i++)
{
if (argv[i].a_type == A_POINTER)
SETSYMBOL(&vec[start+i], gensym("(pointer)"));
else vec[start+i] = argv[i];
}
SETSEMI(&vec[start+argc]);
text_client_senditup(&x->x_tc);
}
/* --------- text_delete object - delete nth line ----------- */
typedef struct _text_delete
{
......@@ -1559,6 +1655,8 @@ static void *text_new(t_symbol *s, int argc, t_atom *argv)
newest = text_get_new(s, argc-1, argv+1);
else if (!strcmp(str, "set"))
newest = text_set_new(s, argc-1, argv+1);
else if (!strcmp(str, "insert"))
newest = text_insert_new(s, argc-1, argv+1);
else if (!strcmp(str, "delete"))
newest = text_delete_new(s, argc-1, argv+1);
else if (!strcmp(str, "size"))
......@@ -1609,7 +1707,7 @@ static t_class *qlist_class;
static void *qlist_new( void)
{
t_qlist *x = (t_qlist *)pd_new(qlist_class);
textbuf_init(&x->x_textbuf);
textbuf_init(&x->x_textbuf, gensym("qlist"));
x->x_clock = clock_new(x, (t_method)qlist_tick);
outlet_new(&x->x_ob, &s_list);
x->x_bangout = outlet_new(&x->x_ob, &s_bang);
......@@ -1837,7 +1935,7 @@ static t_class *textfile_class;
static void *textfile_new( void)
{
t_qlist *x = (t_qlist *)pd_new(textfile_class);
textbuf_init(&x->x_textbuf);
textbuf_init(&x->x_textbuf, gensym("textfile"));
outlet_new(&x->x_ob, &s_list);
x->x_bangout = outlet_new(&x->x_ob, &s_bang);
x->x_onset = 0x7fffffff;
......@@ -1926,6 +2024,8 @@ void x_qlist_setup(void )
gensym("close"), 0);
class_addmethod(text_define_class, (t_method)textbuf_addline,
gensym("addline"), A_GIMME, 0);
class_addmethod(text_define_class, (t_method)text_define_notify,
gensym("notify"), 0, 0);
class_addmethod(text_define_class, (t_method)text_define_set,
gensym("set"), A_GIMME, 0);
class_addmethod(text_define_class, (t_method)text_define_clear,
......@@ -1934,6 +2034,8 @@ void x_qlist_setup(void )
gensym("write"), A_GIMME, 0);
class_addmethod(text_define_class, (t_method)textbuf_read,
gensym("read"), A_GIMME, 0);
class_addmethod(text_define_class, (t_method)text_define_send,
gensym("send"), A_SYMBOL, 0);
class_setsavefn(text_define_class, text_define_save);
class_addbang(text_define_class, text_define_bang);
class_sethelpsymbol(text_define_class, gensym("text-object"));
......@@ -1952,6 +2054,12 @@ void x_qlist_setup(void )
class_addlist(text_set_class, text_set_list);
class_sethelpsymbol(text_set_class, gensym("text-object"));
text_insert_class = class_new(gensym("text insert"),
(t_newmethod)text_insert_new, (t_method)text_client_free,
sizeof(t_text_insert), 0, A_GIMME, 0);
class_addlist(text_insert_class, text_insert_list);
class_sethelpsymbol(text_insert_class, gensym("text-object"));
text_delete_class = class_new(gensym("text delete"),
(t_newmethod)text_delete_new, (t_method)text_client_free,
sizeof(t_text_delete), 0, A_GIMME, 0);
......
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