sebpiq / WebPd

Run your Pure Data patches on the web.
GNU Lesser General Public License v3.0
935 stars 88 forks source link

webpd could provide a dictionary from label to nodeId #137

Closed qlambert-pro closed 11 months ago

qlambert-pro commented 1 year ago

It would make it possible to have a stable interface between the puredata patch and the code where it is used.

It could be a compilation option, or a structure embedded in the compiled code.

sebpiq commented 1 year ago

Hi @qlambert-pro !

Yes indeed ... I was thinking about this as well : maybe embedding the metadata into the compiled code. It already has metadata, so it would just be a matter of adding it there.

What I am not sure about yet is what data exactly needs to be there. For example some might need also the info for all UI elements (elem type, position, label). Also I'm considering adding automatically a port for [send] boxes, so the metadata would be different there too.

So in the end something probably like this :

{
    "node_id_1": {
        "portletIds": ["0", "1"],
        "type": "vslider",
        "group": "gui",
        "label": "Some volume control",
        "position": [123, 89],
    },
    "node_id_2": {
        "portletIds": ["0"],
        "type": "send",
        "group": "send",
        "busName": "some_name",
    },
}
qlambert-pro commented 1 year ago

That sounds great.

sebpiq commented 1 year ago

Cool! I'll tackle this as soon as I'm done with current tasks

sebpiq commented 11 months ago

@qlambert-pro this is done ! Will be shipped with the next release (coming today or tomorrow!).

Here's an example of how to read the info (see run-example.html) : https://github.com/sebpiq/WebPd_example-compiler-browser/

const metadata = await WebPd.Browser.readMetadata(compiledPatch)
console.log(metadata.compilation.io.messageReceivers)

FYI here are the types for the messageReceivers :

type IoMessageSpecs = {
    [nodeId: DspGraph.NodeId]: {
        portletIds: Array<DspGraph.PortletId>
        metadata?: {
            [key: string]:
                | PortletsSpecMetadataBasicValue
                | Array<PortletsSpecMetadataBasicValue>
                | {[key: string]: PortletsSpecMetadataBasicValue}
        }
    }
}

and for the messageReceivers' metadata :

type IoMessageSpecs = {
    [nodeId: DspGraph.NodeId]: {
        portletIds: Array<DspGraph.PortletId>
        metadata?: {
            [key: string]:
                | PortletsSpecMetadataBasicValue
                | Array<PortletsSpecMetadataBasicValue>
                | {[key: string]: PortletsSpecMetadataBasicValue}
        }
    }
}

interface IoMessageSpecMetadataControlBase {
    group: string
    type: PdJson.NodeType
    position: [number, number]
    label?: string
}

interface IoMessageSpecMetadataControlFloat
    extends IoMessageSpecMetadataControlBase {
    group: 'control:float'
    initValue: number
    minValue: number
    maxValue: number
}

interface IoMessageSpecMetadataControl
    extends IoMessageSpecMetadataControlBase {
    group: 'control'
}

interface IoMessageSpecMetadataSend {
    group: 'send'
    name: string
    position: [number, number]
}

export type IoMessageSpecMetadata =
    | IoMessageSpecMetadataControl
    | IoMessageSpecMetadataControlFloat
    | IoMessageSpecMetadataSend
qlambert-pro commented 11 months ago

Thank you very much! I will be looking into that soon.

qlambert-pro commented 4 months ago

Am I correct that I should include the webpd-bundle.js file available here to my project? I am trying to get my hand on what used to be called webpd-runtime.js.

sebpiq commented 4 months ago

@qlambert-pro if you use the compiler (CLI or online) you should get a webpd-runtime.js file ! Forget about that bundle it is something else

qlambert-pro commented 4 months ago

got it thanks