Use this file to discover all available pages before exploring further.
Plugdata includes pd-lua, allowing you to create custom objects using Lua scripting. This provides a flexible way to extend plugdata without compiling C code.
function MyObject:initialize(sel, atoms) -- Set inlet/outlet counts self.inlets = 2 -- Number of inlets self.outlets = 3 -- Number of outlets -- Or use tables for specific types self.inlets = {DATA, DATA} -- 2 message inlets self.outlets = {DATA, SIGNAL, DATA} -- message, signal, message return trueend
local Gain = pd.Class:new():register("gain~")function Gain:initialize(sel, atoms) self.inlets = {SIGNAL, DATA} -- Signal in, control in self.outlets = {SIGNAL} -- Signal out self.gain = atoms[1] or 1 -- Initial gain return trueendfunction Gain:in_2_float(f) self.gain = f -- Update gain from control inletendfunction Gain:dsp(samplerate, blocksize) -- Called when DSP is turned on -- Return true to enable perform function return trueendfunction Gain:perform(in1, out1) -- in1: input signal buffer (table) -- out1: output signal buffer (table) local gain = self.gain for i = 1, #in1 do out1[i] = in1[i] * gain endend
function MyObject:perform(in1, in2, out1, out2) local blocksize = #in1 -- Number of samples for i = 1, blocksize do -- Read from inputs local sample1 = in1[i] local sample2 = in2[i] -- Process local result = sample1 + sample2 -- Write to outputs out1[i] = result out2[i] = result * 0.5 endend
function MyObject:in_1_bang() -- Read from Pd table local t = pd.Table:new():sync("mytable") if t then local size = t:length() local value = t:get(0) -- Get first element self:outlet(1, "float", {value}) endendfunction MyObject:in_1_float(f) -- Write to Pd table local t = pd.Table:new():sync("mytable") if t then t:set(0, f) -- Set first element t:redraw() -- Update visual endend
local RandomSeq = pd.Class:new():register("randomseq")function RandomSeq:initialize(sel, atoms) self.inlets = 3 self.outlets = 1 -- Parameters self.min = atoms[1] or 0 self.max = atoms[2] or 127 self.steps = atoms[3] or 8 -- Internal state self.sequence = {} self.position = 1 -- Generate random sequence self:generate() return trueendfunction RandomSeq:generate() self.sequence = {} for i = 1, self.steps do local value = math.random(self.min, self.max) table.insert(self.sequence, value) endendfunction RandomSeq:in_1_bang() -- Output current step local value = self.sequence[self.position] self:outlet(1, "float", {value}) -- Advance position self.position = self.position + 1 if self.position > self.steps then self.position = 1 endendfunction RandomSeq:in_1_float(f) -- Set position self.position = math.max(1, math.min(self.steps, math.floor(f)))endfunction RandomSeq:in_2_float(f) -- Regenerate sequence if f ~= 0 then self:generate() endendfunction RandomSeq:in_3_float(f) -- Set number of steps self.steps = math.max(1, math.floor(f)) self:generate()end