Skip to content

Add support for property menus in Pd #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

charlesneimog
Copy link

This PR adds the functions _properties_add, _properties_newframe, _properties_addcheckbox, _properties_addtextinput, and _properties_addcolorpicker to pd.

It also reserves the properties method to be executed when the user clicks on "Properties" in Pd. Property menus can be defined as shown in the example below:

function properties:properties()
    self:newframe("First CheckBox", 2)
    self:addcheckbox("Check Box 1", "updatecheckbox1", self.checkbox1)
    self:addcheckbox("Check Box 2", "updatecheckbox2", self.checkbox2)

    self:newframe("First textinput", 2)
    self:addtextinput("Check textinput 1", "updatetext1", self.textinput1, 5)
    self:addtextinput("Check textinput 2", "updatetext2", self.textinput2, 5)

    self:newframe("My Color Picker", 1)
    self:addcolorpicker("Background", "updatecolorbg");
end

New self functions

self:newframe

Creates a new container.

  • arg1: Title of the container.
  • arg2: Number of columns in the container.

The self:add... methods add GUI elements to the last created container.

self:addcheckbox

Adds a checkbox.

  • arg1: Title of the checkbox.
  • arg2: Method to be executed when the checkbox state changes. This method receives a table as an argument, containing the value 1 when checked and 0 when unchecked.
  • arg3: Initial value (1 for checked, 0 for unchecked).

Example of a method triggered on state change:

function properties:updatetext1(args)
    self.textinput1 = args[1]
    pd.post("textinput1 is now " .. self.textinput1);
end

self:addtextinput

Adds a text input field.

  • arg1: Title of the text input.
  • arg2: Method to be executed when the value changes. This method receives a table containing a list of arguments following the Pd convention. For example, the input hello world 1 2 3 will be split into five items, one for each atom.
  • arg3: Initial value, which can be a string or a number.
function properties:updatetext1(args)
    self.textinput1 = args[1]
    pd.post("textinput1 is now " .. self.textinput1);
end

self:addcolorpicker

Adds a color picker.

  • arg1: Title of the color picker.
  • arg2: Method to be executed when the color changes. This method receives a table containing another table with the rgb values.

Example of a method triggered on color change:

function properties:updatecolorbg(args)
    self.color[1] = args[1][1]
    self.color[2] = args[1][2]
    self.color[3] = args[1][3]
    self:repaint(1)
end

Examples

This example is inside pdlua/tutorial/examples/properties-help.pd

output.mp4

@charlesneimog charlesneimog changed the title Properties via lua Add support for property menus in Pd Apr 2, 2025
@charlesneimog charlesneimog marked this pull request as draft April 3, 2025 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant