Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • Konsumer/pd-lua
1 result
Show changes
Showing
with 1357 additions and 0 deletions
#N canvas 632 280 461 305 10;
#X obj 88 73 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X floatatom 88 176 5 0 0 0 - - -, f 5;
#X obj 88 94 fibs;
#X msg 120 73 10;
#X msg 151 73 23;
#X msg 182 73 4;
#X floatatom 88 219 5 0 0 0 - - -, f 5;
#X obj 17 43 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1 1
;
#X msg 213 73 3;
#X floatatom 244 73 5 0 0 0 - - -, f 5;
#X obj 88 154 spigot;
#X obj 121 132 tgl 15 1 empty empty empty 17 7 0 10 -262144 -1 -1 1
1;
#X floatatom 208 176 5 0 0 0 - - -, f 5;
#X floatatom 208 219 5 0 0 0 - - -, f 5;
#X obj 208 154 spigot;
#X obj 241 132 tgl 15 1 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 88 262 noteout 1;
#X obj 208 262 noteout 2;
#X text 40 43 <-- click me to play the sequence!;
#X text 285 73 <-- change the modulus;
#X obj 88 197 + 48;
#X obj 208 197 + 55;
#X obj 17 73 metro 200;
#X text 265 131 <-- activate the 2nd voice;
#X obj 88 240 makenote 64 200;
#X obj 208 240 makenote 64 200;
#X connect 0 0 2 0;
#X connect 1 0 20 0;
#X connect 2 0 10 0;
#X connect 2 1 14 0;
#X connect 3 0 2 0;
#X connect 4 0 2 0;
#X connect 5 0 2 0;
#X connect 6 0 24 0;
#X connect 7 0 22 0;
#X connect 8 0 2 0;
#X connect 9 0 2 0;
#X connect 10 0 1 0;
#X connect 11 0 10 1;
#X connect 12 0 21 0;
#X connect 13 0 25 0;
#X connect 14 0 12 0;
#X connect 15 0 14 1;
#X connect 20 0 6 0;
#X connect 21 0 13 0;
#X connect 22 0 2 0;
#X connect 24 0 16 0;
#X connect 24 1 16 1;
#X connect 25 0 17 0;
#X connect 25 1 17 1;
local fibs = pd.Class:new():register("fibs")
function fibs:initialize(sel, atoms)
-- one inlet for bangs and other messages
self.inlets = 1
-- two outlets for the numbers in pairs
self.outlets = 2
-- intial pair
self.a, self.b = 0, 1
-- the modulus can also be set as creation argument
self.m = type(atoms[1]) == "number" and atoms[1] or 10
-- make sure that it's an integer > 0
self.m = math.max(1, math.floor(self.m))
-- print the modulus in the console, so that the user knows what it is
pd.post(string.format("fibs: modulus %d", self.m))
return true
end
function fibs:in_1_bang()
-- output the current pair in the conventional right-to-left order
self:outlet(2, "float", {self.b})
self:outlet(1, "float", {self.a})
-- calculate the next pair; note that it's sufficient to calculate the
-- remainder for the new number
self.a, self.b = self.b, (self.a+self.b) % self.m
end
function fibs:in_1_float(m)
-- a float input changes the modulus and resets the sequence
self.m = math.max(1, math.floor(m))
self.a, self.b = 0, 1
pd.post(string.format("fibs: modulus %d", self.m))
end
function fibs:in_1_reset()
-- a reset message just resets the sequence
self.a, self.b = 0, 1
end
#N canvas 768 366 451 155 12;
#X obj 87 38 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X floatatom 87 91 5 0 0 0 - - -, f 5;
#X obj 252 38 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X floatatom 252 91 5 0 0 0 - - -, f 5;
#X text 115 36 <-- click me! -->;
#X obj 87 62 pdluax foo;
#X obj 252 62 pdluax foo 0 5;
#X connect 0 0 5 0;
#X connect 2 0 6 0;
#X connect 5 0 1 0;
#X connect 6 0 3 0;
#N canvas 863 346 453 305 12;
#X obj 92 82 foo;
#X obj 92 58 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X floatatom 92 111 5 0 0 0 - - -, f 5;
#X obj 257 58 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X floatatom 257 111 5 0 0 0 - - -, f 5;
#X text 120 56 <-- click me! -->;
#X obj 327 58 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X floatatom 327 111 5 0 0 0 - - -, f 5;
#X obj 257 82 foo 5;
#X obj 327 82 foo 0 5;
#X connect 0 0 2 0;
#X connect 1 0 0 0;
#X connect 3 0 8 0;
#X connect 6 0 9 0;
#X connect 8 0 4 0;
#X connect 9 0 7 0;
local foo = pd.Class:new():register("foo")
function foo:initialize(sel, atoms)
self.inlets = 1
self.outlets = 1
self.counter = 0
self.step = 1
if type(atoms[1]) == "number" then
self.counter = atoms[1]
elseif type(atoms[1]) ~= "nil" then
self:error(string.format("foo: #1: %s is of the wrong type %s",
tostring(atoms[1]), type(atoms[1])))
end
if type(atoms[2]) == "number" then
self.step = atoms[2]
elseif type(atoms[2]) ~= "nil" then
self:error(string.format("foo: #2: %s is of the wrong type %s",
tostring(atoms[2]), type(atoms[2])))
end
pd.post(string.format("foo: initialized counter: %g, step size: %s",
self.counter, self.step))
return true
end
foo.init = 0
function foo:postinitialize()
if foo.init == 0 then
pd.post("Welcome to foo! Copyright (c) by Foo software.")
end
foo.init = foo.init + 1
end
function foo:finalize()
foo.init = foo.init - 1
if foo.init == 0 then
pd.post("Thanks for using foo!")
end
end
function foo:in_1_bang()
self:outlet(1, "float", {self.counter})
self.counter = self.counter + self.step
end
return function (self, sel, atoms)
self.inlets = 1
self.outlets = 1
self.counter = type(atoms[1]) == "number" and atoms[1] or 0
self.step = type(atoms[2]) == "number" and atoms[2] or 1
function self:in_1_bang()
self:outlet(1, "float", {self.counter})
self.counter = self.counter + self.step
end
return true
end
counter = counter and counter + 1 or 0
pd.post(string.format("loadtest: counter = %d", counter))
#N canvas 822 320 453 116 12;
#X obj 32 58 pdlua;
#X msg 32 29 load loadtest.lua;
#X connect 1 0 0 0;
#N canvas 808 331 451 193 12;
#X obj 307 25 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X obj 307 58 luarecv \$0-stuff;
#X msg 132 24 99;
#X msg 132 58 1 2 3;
#X msg 132 92 foo 1 bar 99;
#X obj 132 126 s \$0-stuff;
#X floatatom 184 24 5 0 0 0 - - #0-stuff, f 5;
#X obj 307 92 list prepend set;
#X obj 307 126 list trim;
#X text 333 23 <-- then here;
#X msg 307 160;
#X text 17 59 click here -->;
#X connect 0 0 1 0;
#X connect 1 0 7 0;
#X connect 2 0 5 0;
#X connect 3 0 5 0;
#X connect 4 0 5 0;
#X connect 7 0 8 0;
#X connect 8 0 10 0;
local luarecv = pd.Class:new():register("luarecv")
function luarecv:initialize(sel, atoms)
self.inlets = 1
self.outlets = 1
-- pass the receiver symbol as creation argument
local sym = tostring(atoms[1])
pd.post(string.format("luarecv: receiver '%s'", sym))
-- create the receiver
self.recv = pd.Receive:new():register(self, sym, "receive")
return true
end
function luarecv:finalize()
self.recv:destruct()
end
function luarecv:receive(sel, atoms)
-- simply store the message, so that we can output it later
self.sel, self.atoms = sel, atoms
pd.post(string.format("luarecv: got '%s %s'", sel,
table.concat(atoms, " ")))
end
function luarecv:in_1_bang()
-- output the last message we received (if any)
if self.sel then
self:outlet(1, self.sel, self.atoms)
end
end
#N canvas 833 416 453 105 12;
#X obj 44 23 tgl 15 0 empty \$0-onoff empty 17 7 0 10 -262144 -1 -1
0 1;
#X floatatom 44 47 5 0 0 0 - - -, f 5;
#X obj 154 23 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X obj 154 47 luasend \$0-onoff;
#X text 194 23 <-- click me;
#X connect 0 0 1 0;
#X connect 2 0 3 0;
local luasend = pd.Class:new():register("luasend")
function luasend:initialize(sel, atoms)
self.inlets = 1
-- pass the receiver symbol as creation argument
self.receiver = tostring(atoms[1])
pd.post(string.format("luasend: receiver '%s'", self.receiver))
return true
end
function luasend:in_1_bang()
pd.send(self.receiver, "float", {1})
end
#N canvas 842 313 460 310 12;
#N canvas 0 0 450 300 (subpatch) 0;
#X array wave 1024 float 1 black black;
#A 0 -1.22465e-15 0.0306449 0.0612012 0.0916405 0.121934 0.152055 0.181974
0.211663 0.241097 0.270246 0.299085 0.327587 0.355726 0.383477 0.410813
0.43771 0.464144 0.490091 0.515528 0.54043 0.564777 0.588547 0.611717
0.634268 0.65618 0.677433 0.698008 0.717888 0.737055 0.755493 0.773185
0.790117 0.806274 0.821642 0.836208 0.849961 0.862888 0.87498 0.886227
0.896618 0.906148 0.914807 0.92259 0.929491 0.935505 0.940628 0.944857
0.948189 0.950624 0.952161 0.952799 0.95254 0.951386 0.94934 0.946405
0.942585 0.937886 0.932314 0.925875 0.918578 0.910431 0.901442 0.891622
0.880982 0.869534 0.857288 0.844259 0.83046 0.815906 0.800611 0.784591
0.767862 0.750442 0.732348 0.713599 0.694212 0.674208 0.653607 0.632428
0.610693 0.588423 0.56564 0.542366 0.518625 0.494438 0.469831 0.444825
0.419447 0.39372 0.367669 0.341318 0.314695 0.287823 0.260728 0.233437
0.205975 0.178368 0.150643 0.122826 0.0949426 0.0670197 0.0390834 0.0111599
-0.0167245 -0.0445437 -0.0722718 -0.0998828 -0.127351 -0.154651 -0.181757
-0.208645 -0.235289 -0.261665 -0.287749 -0.313516 -0.338943 -0.364006
-0.388684 -0.412952 -0.43679 -0.460176 -0.483088 -0.505506 -0.527409
-0.548778 -0.569594 -0.589838 -0.609492 -0.628539 -0.646962 -0.664745
-0.681872 -0.698328 -0.714098 -0.729171 -0.743531 -0.757167 -0.770068
-0.782223 -0.793621 -0.804253 -0.814111 -0.823186 -0.831472 -0.838961
-0.845649 -0.85153 -0.856601 -0.860857 -0.864296 -0.866917 -0.868718
-0.869699 -0.869861 -0.869205 -0.867732 -0.865445 -0.862349 -0.858447
-0.853744 -0.848247 -0.841961 -0.834894 -0.827053 -0.818449 -0.809089
-0.798983 -0.788144 -0.776581 -0.764308 -0.751337 -0.73768 -0.723353
-0.708369 -0.692745 -0.676495 -0.659636 -0.642184 -0.624158 -0.605575
-0.586453 -0.566812 -0.54667 -0.526047 -0.504964 -0.48344 -0.461498
-0.439158 -0.416442 -0.393372 -0.36997 -0.346258 -0.32226 -0.297998
-0.273496 -0.248776 -0.223864 -0.198781 -0.173553 -0.148203 -0.122755
-0.0972329 -0.071661 -0.0460635 -0.0204643 0.0051124 0.0306428 0.0561028
0.0814688 0.106717 0.131824 0.156766 0.181521 0.206065 0.230375 0.254429
0.278206 0.301682 0.324837 0.347649 0.370098 0.392163 0.413823 0.435059
0.455853 0.476184 0.496035 0.515387 0.534224 0.552529 0.570285 0.587476
0.604088 0.620104 0.635513 0.650299 0.66445 0.677954 0.690799 0.702973
0.714468 0.725272 0.735378 0.744775 0.753458 0.761418 0.76865 0.775147
0.780906 0.785921 0.790188 0.793706 0.796473 0.798485 0.799744 0.800249
0.8 0.798999 0.797249 0.794751 0.79151 0.78753 0.782815 0.777371 0.771205
0.764323 0.756733 0.748443 0.739462 0.729799 0.719465 0.708471 0.696827
0.684545 0.671639 0.658121 0.644005 0.629305 0.614036 0.598213 0.581851
0.564968 0.547578 0.529701 0.511352 0.492551 0.473316 0.453664 0.433616
0.41319 0.392407 0.371287 0.34985 0.328116 0.306106 0.283842 0.261345
0.238636 0.215737 0.19267 0.169456 0.146118 0.122678 0.0991575 0.0755795
0.0519658 0.0283388 0.00472062 -0.0188665 -0.0424005 -0.0658594 -0.0892212
-0.112464 -0.135566 -0.158507 -0.181264 -0.203816 -0.226144 -0.248225
-0.27004 -0.291568 -0.312791 -0.333687 -0.354239 -0.374427 -0.394233
-0.413639 -0.432627 -0.451181 -0.469282 -0.486915 -0.504065 -0.520715
-0.536851 -0.552458 -0.567523 -0.582031 -0.595971 -0.609331 -0.622097
-0.63426 -0.645808 -0.656732 -0.667022 -0.67667 -0.685668 -0.694007
-0.701682 -0.708686 -0.715013 -0.720658 -0.725617 -0.729887 -0.733464
-0.736346 -0.738531 -0.740018 -0.740808 -0.740899 -0.740294 -0.738993
-0.736999 -0.734315 -0.730944 -0.726891 -0.722159 -0.716756 -0.710686
-0.703956 -0.696574 -0.688547 -0.679885 -0.670595 -0.660688 -0.650174
-0.639063 -0.627367 -0.615098 -0.602268 -0.588889 -0.574976 -0.560542
-0.545601 -0.530169 -0.514259 -0.497889 -0.481074 -0.46383 -0.446174
-0.428123 -0.409695 -0.390909 -0.371781 -0.35233 -0.332575 -0.312536
-0.29223 -0.271679 -0.250901 -0.229916 -0.208744 -0.187406 -0.165921
-0.144311 -0.122595 -0.100794 -0.0789284 -0.0570194 -0.0350875 -0.0131532
0.00876294 0.0306403 0.0524583 0.0741966 0.0958349 0.117353 0.138731
0.159949 0.180986 0.201825 0.222445 0.242827 0.262952 0.282802 0.302359
0.321605 0.340522 0.359092 0.377299 0.395126 0.412556 0.429575 0.446167
0.462316 0.478008 0.493229 0.507965 0.522203 0.535931 0.549136 0.561806
0.573931 0.585499 0.596501 0.606927 0.616768 0.626015 0.634661 0.642699
0.650121 0.656921 0.663095 0.668636 0.673541 0.677806 0.681427 0.684403
0.686731 0.68841 0.68944 0.689819 0.689549 0.688631 0.687067 0.684858
0.682009 0.678521 0.6744 0.669651 0.664278 0.658287 0.651685 0.644479
0.636677 0.628286 0.619316 0.609774 0.599673 0.58902 0.577828 0.566107
0.553869 0.541127 0.527892 0.514179 0.5 0.48537 0.470302 0.454812 0.438915
0.422626 0.405961 0.388936 0.371568 0.353873 0.335869 0.317573 0.299001
0.280173 0.261107 0.241819 0.22233 0.202657 0.182819 0.162835 0.142724
0.122505 0.102197 0.0818202 0.0613925 0.0409338 0.0204632 3.59312e-15
-0.0204366 -0.0408273 -0.0611532 -0.0813951 -0.101534 -0.121552 -0.141429
-0.161147 -0.180689 -0.200035 -0.219168 -0.23807 -0.256724 -0.275112
-0.293218 -0.311025 -0.328516 -0.345676 -0.362488 -0.378938 -0.39501
-0.410691 -0.425965 -0.440818 -0.455238 -0.469211 -0.482726 -0.495768
-0.508328 -0.520394 -0.531955 -0.543001 -0.553522 -0.563508 -0.572953
-0.581846 -0.590181 -0.59795 -0.605146 -0.611765 -0.617799 -0.623245
-0.628098 -0.632354 -0.63601 -0.639062 -0.64151 -0.643352 -0.644586
-0.645212 -0.64523 -0.644642 -0.643448 -0.64165 -0.639251 -0.636254
-0.632662 -0.62848 -0.623712 -0.618363 -0.612439 -0.605946 -0.598892
-0.591283 -0.583127 -0.574434 -0.56521 -0.555467 -0.545213 -0.53446
-0.523217 -0.511495 -0.499308 -0.486665 -0.473581 -0.460068 -0.446138
-0.431806 -0.417086 -0.401992 -0.386538 -0.37074 -0.354612 -0.338171
-0.321433 -0.304412 -0.287126 -0.269591 -0.251825 -0.233843 -0.215664
-0.197304 -0.17878 -0.160112 -0.141316 -0.12241 -0.103412 -0.0843394
-0.0652113 -0.0460453 -0.0268594 -0.00767158 0.0115 0.0306374 0.0497226
0.0687378 0.0876653 0.106487 0.125186 0.143745 0.162145 0.180371 0.198405
0.216231 0.233831 0.251191 0.268293 0.285122 0.301662 0.317899 0.333817
0.349403 0.36464 0.379516 0.394018 0.408131 0.421843 0.435143 0.448017
0.460454 0.472443 0.483973 0.495034 0.505616 0.515711 0.525307 0.534399
0.542977 0.551034 0.558563 0.565557 0.572011 0.57792 0.583278 0.588081
0.592325 0.596007 0.599124 0.601673 0.603654 0.605065 0.605904 0.606173
0.605872 0.605 0.603561 0.601556 0.598987 0.595858 0.592172 0.587934
0.583147 0.577818 0.571951 0.565553 0.558631 0.551192 0.543242 0.534791
0.525847 0.516419 0.506516 0.496149 0.485326 0.47406 0.462361 0.450241
0.437712 0.424785 0.411474 0.397791 0.383751 0.369365 0.354649 0.339616
0.324282 0.30866 0.292766 0.276614 0.260222 0.243604 0.226775 0.209753
0.192554 0.175193 0.157687 0.140053 0.122308 0.104468 0.0865507 0.0685724
0.0505503 0.0325014 0.0144427 -0.00360893 -0.0216364 -0.0396228 -0.0575513
-0.0754052 -0.0931677 -0.110822 -0.128352 -0.145741 -0.162974 -0.180033
-0.196904 -0.21357 -0.230016 -0.246227 -0.262188 -0.277884 -0.293301
-0.308425 -0.323241 -0.337736 -0.351897 -0.365712 -0.379166 -0.392249
-0.404947 -0.417251 -0.429148 -0.440628 -0.451681 -0.462296 -0.472464
-0.482177 -0.491425 -0.5002 -0.508495 -0.516302 -0.523615 -0.530427
-0.536733 -0.542526 -0.547803 -0.552559 -0.556789 -0.560491 -0.563662
-0.566299 -0.5684 -0.569964 -0.570991 -0.571479 -0.571429 -0.570841
-0.569717 -0.568059 -0.565868 -0.563147 -0.5599 -0.556129 -0.55184
-0.547036 -0.541723 -0.535907 -0.529592 -0.522787 -0.515497 -0.507731
-0.499495 -0.490799 -0.481651 -0.472059 -0.462035 -0.451586 -0.440725
-0.429461 -0.417805 -0.405769 -0.393365 -0.380604 -0.367499 -0.354063
-0.340309 -0.32625 -0.311899 -0.297271 -0.282379 -0.267237 -0.251861
-0.236265 -0.220463 -0.204472 -0.188305 -0.171979 -0.155509 -0.138911
-0.1222 -0.105393 -0.0885042 -0.0715509 -0.0545487 -0.0375136 -0.0204618
-0.00340919 0.0136281 0.0306341 0.0475929 0.0644885 0.0813052 0.0980272
0.114639 0.131125 0.14747 0.163658 0.179675 0.195506 0.211136 0.22655
0.241735 0.256676 0.271359 0.285771 0.299899 0.31373 0.327251 0.34045
0.353314 0.365832 0.377992 0.389784 0.401197 0.41222 0.422843 0.433058
0.442854 0.452223 0.461157 0.469647 0.477687 0.485269 0.492386 0.499032
0.505202 0.51089 0.516092 0.520802 0.525018 0.528735 0.531951 0.534664
0.53687 0.538569 0.53976 0.540441 0.540614 0.540278 0.539434 0.538083
0.536228 0.53387 0.531013 0.527659 0.523812 0.519477 0.514657 0.509358
0.503586 0.497346 0.490645 0.483489 0.475886 0.467844 0.459369 0.450472
0.44116 0.431442 0.421329 0.41083 0.399956 0.388717 0.377124 0.365188
0.352921 0.340335 0.327441 0.314253 0.300784 0.287045 0.27305 0.258814
0.244348 0.229668 0.214786 0.199718 0.184478 0.16908 0.153539 0.137869
0.122086 0.106205 0.0902397 0.0742061 0.0581192 0.0419942 0.0258463
0.00969074 -0.00645738 -0.0225828 -0.0386705 -0.0547053 -0.0706721
-0.0865561 -0.102342 -0.118016 -0.133563 -0.148968 -0.164218 -0.179297
-0.194192 -0.20889 -0.223376 -0.237637 -0.25166 -0.265432 -0.27894
-0.292172 -0.305115 -0.317759 -0.330091 -0.3421 -0.353774 -0.365104
-0.37608 -0.38669 -0.396926 -0.406778 -0.416237 -0.425295 -0.433944
-0.442177 -0.449984 -0.457361 -0.4643 -0.470795 -0.476841 -0.482432
-0.487564 -0.492232 -0.496432 -0.500161 -0.503416 -0.506193 -0.508492
-0.510311 -0.511647 -0.512501 -0.512872 -0.51276 -0.512165 -0.51109
-0.509535 -0.507502 -0.504993 -0.502012 -0.498562 -0.494647 -0.49027
-0.485436 -0.48015 -0.474418 -0.468245 -0.461638 -0.454603 -0.447148
-0.439279 -0.431005 -0.422334 -0.413274 -0.403834 -0.394024 -0.383852
-0.37333 -0.362467 -0.351274;
#A 1000 -0.339761 -0.32794 -0.315822 -0.303419 -0.290743 -0.277806
-0.264621 -0.251199 -0.237554 -0.223699 -0.209648 -0.195413 -0.181008
-0.166447 -0.151744 -0.136912 -0.121967 -0.106921 -0.0917889 -0.0765856
-0.0613251 -0.0460219 -0.0306903 -0.0153449;
#X coords 0 1 1023 -1 200 140 1;
#X restore 30 30 graph;
#X floatatom 30 192 5 0 0 0 - - -, f 5;
#X obj 30 220 luatab wave;
#X obj 30 249 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X obj 302 32 pdlua-remote;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
local luatab = pd.Class:new():register("luatab")
-- our own pdlua extension, needed for the reload functionality
local pdx = require 'pdx'
function luatab:initialize(sel, atoms)
-- single inlet for the frequency, bang goes to the single outlet when we
-- finished generating a new waveform
self.inlets = 1
self.outlets = 1
-- enable the reload callback
pdx.reload(self)
-- the name of the array/table should be in the 1st creation argument
if type(atoms[1]) == "string" then
self.tabname = atoms[1]
return true
else
self:error(string.format("luatab: expected array name, got %s",
tostring(atoms[1])))
return false
end
end
function luatab:in_1_float(freq)
if type(freq) == "number" then
-- the waveform we want to compute, adjust this as needed
local function f(x)
return math.sin(2*math.pi*freq*(x+1))/(x+1)
end
-- get the Pd array and its length
local t = pd.Table:new():sync(self.tabname)
if t == nil then
self:error(string.format("luatab: array or table %s not found",
self.tabname))
return
end
local l = t:length()
-- Pd array indices are zero-based
for i = 0, l-1 do
-- normalize arguments to the 0-1 range
t:set(i, f(i/l))
end
-- this is needed to update the graph display
t:redraw()
-- output a bang to indicate that we've generated a new waveform
self:outlet(1, "bang", {})
else
self:error(string.format("luatab: expected frequency, got %s",
tostring(freq)))
end
end
;;; pdlua-remote.el --- Pd remote control stuff for pd-lua.
;;; Commentary:
;;; Install this anywhere where Emacs finds it (e.g., in the Emacs site-lisp
;;; directory -- usually under /usr/share/emacs/site-lisp on Un*x systems, or
;;; in any directory on the Emacs load-path) and load it in your .emacs as
;;; follows:
;;; (require 'pdlua-remote)
;;; Or just add the following lines directly to your .emacs.
;;; Code:
(defun pd-send-start-process ()
"Start a pdsend process to communicate with Pd via UDP port 4711."
(interactive)
(start-process "pdsend" nil "pdsend" "4711" "localhost" "udp")
(process-kill-without-query (get-process "pdsend")))
(defun pd-send-stop-process ()
"Stops a previously started pdsend process."
(interactive)
(delete-process "pdsend"))
(defun pd-send-message (message)
"Send the given MESSAGE to Pd. Start the pdsend process if needed."
(interactive "sMessage: ")
(unless (get-process "pdsend") (pd-send-start-process))
(process-send-string "pdsend" (concat message "\n")))
; Pd Lua uses this as the extension for Lua scripts
(require 'lua-mode)
(setq auto-mode-alist (cons '("\\.pd_luax?$" . lua-mode) auto-mode-alist))
; Pd tie-in for lua-mode (see pd-lua tutorial)
(define-key lua-mode-map "\C-c\C-k" '(lambda () "Reload" (interactive)
(pd-send-message "reload")))
(provide 'pdlua-remote)
;;; pdlua-remote.el ends here
#N canvas 1691 337 450 301 12;
#X obj 78 25 netreceive 4711 1;
#X obj 322 26 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X msg 322 50 reload;
#X obj 27 25 inlet;
#X obj 27 102 t a a;
#X obj 27 131 outlet;
#X obj 89 131 s pdluax;
#X connect 0 0 4 0;
#X connect 1 0 2 0;
#X connect 2 0 4 0;
#X connect 3 0 4 0;
#X connect 4 0 5 0;
#X connect 4 1 6 0;
#X coords 0 -1 1 1 124 24 1 218 21;
--[[
pdx.lua: useful extensions to pd.lua
Copyright (C) 2020 Albert Gräf <aggraef@gmail.com>
To use this in your pd-lua scripts: local pdx = require 'pdx'
Currently there's only the pdx.reload() function, which implements a kind of
remote reload functionality based on dofile and receivers, as explained in the
pd-lua tutorial. More may be added in the future.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
--]]
local pdx = {}
--[[
Reload functionality. Call pdx.reload() on your object to enable, and
pdx.unreload() to disable this functionality again.
pdx.reload installs a "pdluax" receiver which reloads the object's script file
when it receives the "reload" message without any arguments, or a "reload
class" message with a matching class name.
We have to go to some lengths here since we only want the script to be
reloaded *once* for each class, not for every object in the class. This
complicates things quite a bit. In particular, we need to keep track of object
deletions to perform the necessary bookkeeping, in order to ensure that at any
time there's exactly one participating object in the class which receives the
message. Which means that we also need to keep track of the object's finalize
method, so that we can chain to it in our own finalizer.
--]]
local reloadables = {}
-- finalize method, here we perform the necessary bookkeeping when an object
-- in the reloadables table gets deleted
local function finalize(self)
if reloadables[self._name] then
-- remove the object from the reloadables table, and restore its
-- original finalizer
pdx.unreload(self)
-- call the object's own finalizer, if any
if self.finalize then
self.finalize(self)
end
end
end
-- Our receiver. In the future, more functionality may be added here, but at
-- present this only recognizes the "reload" message and checks the class
-- name, if given.
local function pdluax(self, sel, atoms)
if sel == "reload" then
-- reload message, check that any extra argument matches the class name
if atoms[1] == nil or atoms[1] == self._name then
pd.post(string.format("pdx: reloading %s", self._name))
self:dofile(self._scriptname)
-- update the object's finalizer and restore our own, in case
-- anything has changed there
if self.finalize ~= finalize then
reloadables[self._name][self].finalize = self.finalize
self.finalize = finalize
end
end
end
end
-- purge an object from the reloadables table
function pdx.unreload(self)
if reloadables[self._name] then
if reloadables[self._name].current == self then
-- self is the current receiver, find another one
local current = nil
for obj, data in pairs(reloadables[self._name]) do
if type(obj) == "table" and obj ~= self then
-- install the receiver
data.recv = pd.Receive:new():register(obj, "pdluax", "_pdluax")
obj._pdluax = pdluax
-- record that we have a new receiver and bail out
current = obj
break
end
end
reloadables[self._name].current = current
-- get rid of the old receiver
reloadables[self._name][self].recv:destruct()
self._pdluax = nil
end
-- restore the object's finalize method
self.finalize = reloadables[self._name][self].finalize
-- purge the object from the reloadables table
reloadables[self._name][self] = nil
-- if the list of reloadables in this class is now empty, purge the
-- entire class from the reloadables table
if reloadables[self._name].current == nil then
reloadables[self._name] = nil
end
end
end
-- register a new object in the reloadables table
function pdx.reload(self)
if reloadables[self._name] then
-- We already have an object for this class, simply record the new one
-- and install our finalizer so that we can perform the necessary
-- cleanup when the object gets deleted. Also check that we don't
-- register the same object twice (this won't really do any harm, but
-- would be a waste of time).
if reloadables[self._name][self] == nil then
reloadables[self._name][self] = { finalize = self.finalize }
self.finalize = finalize
end
else
-- New class, make this the default receiver.
reloadables[self._name] = { current = self }
reloadables[self._name][self] = { finalize = self.finalize }
-- install our finalizer
self.finalize = finalize
-- add the receiver
reloadables[self._name][self].recv =
pd.Receive:new():register(self, "pdluax", "_pdluax")
self._pdluax = pdluax
end
end
return pdx
#N canvas 922 336 452 303 12;
#X obj 129 33 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1
1;
#X obj 129 57 tictoc 1000;
#X obj 89 106 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1
-1;
#X obj 243 106 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#X obj 170 214 noteout 10;
#X msg 244 22 500;
#X msg 278 22 250;
#X msg 312 22 100;
#X msg 346 22 50;
#X msg 203 22 1000;
#X msg 89 130 32;
#X msg 243 130 33;
#X obj 170 182 makenote 64 50;
#X connect 0 0 1 0;
#X connect 1 0 2 0;
#X connect 1 1 3 0;
#X connect 2 0 10 0;
#X connect 3 0 11 0;
#X connect 5 0 1 1;
#X connect 6 0 1 1;
#X connect 7 0 1 1;
#X connect 8 0 1 1;
#X connect 9 0 1 1;
#X connect 10 0 12 0;
#X connect 11 0 12 0;
#X connect 12 0 4 0;
#X connect 12 1 4 1;
local tictoc = pd.Class:new():register("tictoc")
function tictoc:initialize(sel, atoms)
-- inlet 1 takes an on/off flag, inlet 2 the delay time
self.inlets = 2
-- bangs are output alternating between the two outlets
self.outlets = 2
-- the delay time (optional creation argument, 1000 msec by default)
self.delay = type(atoms[1]) == "number" and atoms[1] or 1000
-- we start out on the left outlet
self.left = true
-- initialize the clock
self.clock = pd.Clock:new():register(self, "tictoc")
return true
end
-- don't forget this, or else...
function tictoc:finalize()
self.clock:destruct()
end
-- As with the metro object, nonzero, "bang" and "start" start the clock,
-- zero and "stop" stop it.
function tictoc:in_1_float(state)
if state ~= 0 then
-- output the first tick immediately
self:tictoc()
else
-- stop the clock
self.clock:unset()
end
end
function tictoc:in_1_bang()
self:in_1_float(1)
end
function tictoc:in_1_start()
self:in_1_float(1)
end
function tictoc:in_1_stop()
self:in_1_float(0)
end
-- set the delay (always in msec, we don't convert units)
function tictoc:in_2_float(delay)
-- this will be picked up the next time the clock reschedules itself
self.delay = delay >= 1 and delay or 1
end
-- the clock method: tic, toc, tic, toc ...
function tictoc:tictoc()
-- output a bang, alternate between left and right
self:outlet(self.left and 1 or 2, "bang", {})
self.left = not self.left
-- reschedule
self.clock:delay(self.delay)
end
source diff could not be displayed: it is too large. Options to address this: view the blob.