Commit aa403dad authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

Merge branch 'aggraef/purr-data-dollar-substitutions'

parents 58a885c9 ddc199e5
...@@ -567,9 +567,14 @@ function apply() { ...@@ -567,9 +567,14 @@ function apply() {
for (i = 0; i < pd_garray_attrs.length; i++) { for (i = 0; i < pd_garray_attrs.length; i++) {
attrs = pd_garray_attrs[i]; attrs = pd_garray_attrs[i];
name = get_array_value("array_name", attrs); name = get_array_value("array_name", attrs);
if (name.slice(0, 1) === "$") { var arr = name.split("");
name = "#" + name.slice(1); for (var i = 0; i < arr.length; i++) {
if (arr[i] === "$" && i+1 < arr.length &&
arr[i+1] >= "0" && arr[i+1] <= "9") {
arr[i] = "#";
}
} }
name = arr.join("");
pdgui.pdsend( pdgui.pdsend(
get_array_value("array_gfxstub", attrs), get_array_value("array_gfxstub", attrs),
"arraydialog", "arraydialog",
......
...@@ -177,15 +177,16 @@ function strip_problem_chars(arg) { ...@@ -177,15 +177,16 @@ function strip_problem_chars(arg) {
} }
function gatom_escape(str) { function gatom_escape(str) {
var arr, i, ret; var ret;
if (str.length === 0) { if (str.length === 0) {
ret = "-"; ret = "-";
} else if (str.slice(0,1) === "-") { } else if (str.slice(0,1) === "-") {
ret = "-" + str; ret = "-" + str;
} else { } else {
arr = str.split(""); var arr = str.split("");
for (i = 0; i < arr.length; i++) { for (var i = 0; i < arr.length; i++) {
if (arr[i] === "$") { if (arr[i] === "$" && i+1 < arr.length &&
arr[i+1] >= "0" && arr[i+1] <= "9") {
arr[i] = "#"; arr[i] = "#";
} }
} }
...@@ -194,6 +195,22 @@ function gatom_escape(str) { ...@@ -194,6 +195,22 @@ function gatom_escape(str) {
return strip_problem_chars(ret); return strip_problem_chars(ret);
} }
function gatom_unescape(str) {
if (str.slice(0,1) === "-") {
str = str.slice(1);
} else {
var arr = str.split("");
for (var i = 0; i < arr.length; i++) {
if (arr[i] === "#" && i+1 < arr.length &&
arr[i+1] >= "0" && arr[i+1] <= "9") {
arr[i] = "$";
}
}
str = arr.join("");
}
return str;
}
function update_attr(elem) { function update_attr(elem) {
new_attrs[elem.name] = elem.value; new_attrs[elem.name] = elem.value;
} }
...@@ -306,11 +323,11 @@ function populate_form(attributes) { ...@@ -306,11 +323,11 @@ function populate_form(attributes) {
get_elem("draglo").value = attributes.draglo; get_elem("draglo").value = attributes.draglo;
get_elem("draghi").value = attributes.draghi; get_elem("draghi").value = attributes.draghi;
label = attributes.label; label = attributes.label;
get_elem("label").value = label === "-" ? "" : label; get_elem("label").value = gatom_unescape(label);
snd = attributes.send_symbol; snd = attributes.send_symbol;
get_elem("send_symbol").value = snd === "-" ? "" : snd; get_elem("send_symbol").value = gatom_unescape(snd);
rcv = attributes.receive_symbol; rcv = attributes.receive_symbol;
get_elem("receive_symbol").value = rcv === "-" ? "" : rcv; get_elem("receive_symbol").value = gatom_unescape(rcv);
labelpos = attributes.labelpos; labelpos = attributes.labelpos;
radios = document.getElementsByName("labelpos"); radios = document.getElementsByName("labelpos");
......
...@@ -371,16 +371,33 @@ function update_attr(elem) { ...@@ -371,16 +371,33 @@ function update_attr(elem) {
} }
//Clean up strings to send as symbol arguments to Pd //Clean up strings to send as symbol arguments to Pd
function pd_symbol_carwash(s) { function iemgui_escape(s) {
s = !s ? "empty" : s; s = !s ? "empty" : s;
if (s.charAt(0) === "$") { var arr = s.split("");
s = "#" + s.slice(1); for (var i = 0; i < arr.length; i++) {
if (arr[i] === "$" && i+1 < arr.length &&
arr[i+1] >= "0" && arr[i+1] <= "9") {
arr[i] = "#";
}
} }
s = arr.join("");
s = substitute_space(s); s = substitute_space(s);
s = strip_problem_chars(s); s = strip_problem_chars(s);
return s; return s;
} }
function iemgui_unescape(s) {
var arr = s.split("");
for (var i = 0; i < arr.length; i++) {
if (arr[i] === "#" && i+1 < arr.length &&
arr[i+1] >= "0" && arr[i+1] <= "9") {
arr[i] = "$";
}
}
s = arr.join("");
return s;
}
function send_params(attrs, create_undo_point) { function send_params(attrs, create_undo_point) {
/* Not sure what these are... /* Not sure what these are...
iemgui_clip_dim $id iemgui_clip_dim $id
...@@ -394,9 +411,9 @@ function send_params(attrs, create_undo_point) { ...@@ -394,9 +411,9 @@ function send_params(attrs, create_undo_point) {
var send_symbol = attrs.send_symbol, var send_symbol = attrs.send_symbol,
receive_symbol = attrs.receive_symbol, receive_symbol = attrs.receive_symbol,
label = attrs["label"]; label = attrs["label"];
send_symbol = pd_symbol_carwash(send_symbol); send_symbol = iemgui_escape(send_symbol);
receive_symbol = pd_symbol_carwash(receive_symbol); receive_symbol = iemgui_escape(receive_symbol);
label = pd_symbol_carwash(label); label = iemgui_escape(label);
var label_x_offset = attrs.x_offset; var label_x_offset = attrs.x_offset;
var label_y_offset = attrs.y_offset; var label_y_offset = attrs.y_offset;
...@@ -605,6 +622,10 @@ function populate_form(attr_object) { ...@@ -605,6 +622,10 @@ function populate_form(attr_object) {
elem[0].checked = +attr_object[attr]; elem[0].checked = +attr_object[attr];
} else if (elem[0].type === "select-one") { } else if (elem[0].type === "select-one") {
elem[0].selectedIndex = +attr_object[attr]; elem[0].selectedIndex = +attr_object[attr];
} else if (attr === "send_symbol" ||
attr === "receive_symbol" ||
attr === "label") {
elem[0].value = iemgui_unescape(attr_object[attr]);
} else { } else {
elem[0].value = attr_object[attr]; elem[0].value = attr_object[attr];
} }
......
...@@ -53,7 +53,7 @@ t_symbol *iemgui_dollar2raute(t_symbol *s) ...@@ -53,7 +53,7 @@ t_symbol *iemgui_dollar2raute(t_symbol *s)
return (s); return (s);
for (s1 = s->s_name, s2 = buf; ; s1++, s2++) for (s1 = s->s_name, s2 = buf; ; s1++, s2++)
{ {
if (*s1 == '$') if (*s1 == '$' && *s1 && isdigit(s1[1]))
*s2 = '#'; *s2 = '#';
else if (!(*s2 = *s1)) else if (!(*s2 = *s1))
break; break;
...@@ -68,7 +68,7 @@ t_symbol *iemgui_raute2dollar(t_symbol *s) ...@@ -68,7 +68,7 @@ t_symbol *iemgui_raute2dollar(t_symbol *s)
return (s); return (s);
for (s1 = s->s_name, s2 = buf; ; s1++, s2++) for (s1 = s->s_name, s2 = buf; ; s1++, s2++)
{ {
if (*s1 == '#') if (*s1 == '#' && *s1 && isdigit(s1[1]))
*s2 = '$'; *s2 = '$';
else if (!(*s2 = *s1)) else if (!(*s2 = *s1))
break; break;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "m_pd.h" #include "m_pd.h"
#include "g_canvas.h" #include "g_canvas.h"
#include <math.h> #include <math.h>
#include <ctype.h>
extern int glob_lmclick; extern int glob_lmclick;
...@@ -24,15 +25,17 @@ two, but how? */ ...@@ -24,15 +25,17 @@ two, but how? */
t_symbol *sharptodollar(t_symbol *s) t_symbol *sharptodollar(t_symbol *s)
{ {
if (*s->s_name == '#') char buf[MAXPDSTRING], *s1, *s2;
if (strlen(s->s_name) >= MAXPDSTRING)
return (s);
for (s1 = s->s_name, s2 = buf; ; s1++, s2++)
{ {
char buf[MAXPDSTRING]; if (*s1 == '#' && *s1 && isdigit(s1[1]))
strncpy(buf, s->s_name, MAXPDSTRING); *s2 = '$';
buf[MAXPDSTRING-1] = 0; else if (!(*s2 = *s1))
buf[0] = '$'; break;
return (gensym(buf));
} }
else return (s); return (gensym(buf));
} }
/* --------- "pure" arrays with scalars for elements. --------------- */ /* --------- "pure" arrays with scalars for elements. --------------- */
......
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