[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-users] Announcement: ddwPrototype quark deprecates Function:e
And, a quick announcement: I just pushed an update to several of my
quarks, removing any uses of Function:e and deprecating that method.
Probably doesn't affect many users, but if you were using ddwPrototype
('Proto' class), it might.
Reason: I got in the habit of using 'e' for any kind of GUI or OSC
action functions whenever environments were involved. But, it was too
easy to forget about this when putting code in students' hands... and,
without my extension, then... "Message 'e' not understood." After
getting burned by this for the 15th time, I decided to remove it in
favor of the equivalent 'inEnvir' (which exists in the main class
library).
(Why was this necessary anyway? Because a Proto object is an
Environment, and the environment should be "current" whenever you're
doing anything inside it. That includes GUI, OSC, MIDI, HID response
functions, SimpleController or NotificationCenter functions etc. --
anything that can be called from outside the Proto, but which
logically is local to the Proto object. 'inEnvir' wraps a function in
`theEnvir.use`. See below. Once upon a time, I felt it was too
inconvenient to type inEnvir, so I added a shortcut `e` in my quark...
but then found that caused problems with distributing code.)
If you're using this, and you update my quarks, your code should still
work but will get deprecation warnings in places. Just replace 'e'
with 'inEnvir' and they will go away.
If you're using a unixy system, the attached script will run through
an entire directory structure and fix every occurrence of `e {` for
you in .sc and .scd files. (The regexp is really "[non-alphanum]e {"
so it shouldn't break things like "PR(\a).clone {...}".) I don't know
the Windows equivalent of sed, so I didn't make a Windows version.
hjh
Demo:
(
p = Proto {
~value = 1;
~prep = {
~button = Button(nil, Rect(800, 200, 100, 50))
.states_([["click me"]])
.action_({ "~value is %\n".postf(~value) }) // posts nil
.front;
currentEnvironment
};
~free = { ~button.close };
}.prep;
)
p.free;
(
p = Proto {
~value = 1;
~prep = {
~button = Button(nil, Rect(800, 200, 100, 50))
.states_([["click me"]])
.action_(inEnvir { "~value is %\n".postf(~value) }) // posts 1
.front;
currentEnvironment
};
~free = { ~button.close };
}.prep;
)
p.free;
(
f = { |dir|
forkIfNeeded {
var cond = Condition.new;
["*.sc", "*.scd"].do { |ext|
(dir +/+ ext).pathMatch.do { |path|
"sed -i'.bak' --follow-symlinks 's/\\([^a-zA-Z0-9_]\\)e {/\\1inEnvir {/' '%'"
.format(path)
.postln
.unixCmd({ |exit|
if(exit != 0) { "failed .%".format(path.drop(dir.size)).warn };
cond.unhang;
});
cond.hang;
};
};
(dir +/+ "*/").pathMatch.do { |path| // directories
f.(path);
};
};
};
)
FileDialog({ |path| p = path.postcs; f.(path[0]) }, fileMode: 2);