Path to project folder?

17 views
Skip to first unread message

Davide D'Angelo

unread,
Apr 5, 2019, 9:55:52 AM4/5/19
to PraxisLIVE software discussion group
Hi, as in the object, I would like to know what is the way to point to the project folder or to ./resources ?
I see i.e. that in the text with font example you sent me it looks directly into ./resources and if I copy the project with a different name, the path is automatically updated.
But I have to read a file.csv and I would like the same behaviour.
Is it possible?

I wish it's clear what I mean..

Davide. 

Neil C Smith

unread,
Apr 5, 2019, 10:26:16 AM4/5/19
to Praxis LIVE software discussion group
Yes, you need a PResource property of some sort.

While the simplest thing is just @P(1) PResource file; it's better to
use Property for this and handle the fact it might not be set. eg. in
a core:custom in a data patch -

```
@P(1) @Type(PResource.class)
Property res;
@P(2) @ReadOnly
String loc;

@Override
public void init() {
res.valuesAs(PResource::from).link(r -> {
loc = r.map(PResource::toString).orElse("");
// loc = r.map(rr ->
rr.resolve(getLookup()).get(0).toString()).orElse("");
}
);
}

```

The commented out line is necessary if your project might run across
multiple computers - resolve gives you a list of possible URIs to try
loading from - if it's always a local file it isn't necessary.

You can also look at the attached custom component, to be added to a
generic data patch, which will listen on a file for changes and
automatically load the text and send from the output.

Hope that helps.

Best wishes,

Neil


--
Neil C Smith
Artist & Technologist
www.neilcsmith.net

PraxisLIVE - hybrid visual live programming
for creatives, for programmers, for students, for tinkerers
www.praxislive.org
file-listener.pxg

Davide D'Angelo

unread,
Apr 9, 2019, 8:59:24 AM4/9/19
to PraxisLIVE software discussion group


Il giorno venerdì 5 aprile 2019 16:26:16 UTC+2, Neil C Smith ha scritto:
On Fri, 5 Apr 2019 at 14:55, Davide D'Angelo <77d...@gmail.com> wrote:
> Hi, as in the object, I would like to know what is the way to point to the project folder or to ./resources ?
> I see i.e. that in the text with font example you sent me it looks directly into ./resources and if I copy the project with a different name, the path is automatically updated.
> But I have to read a file.csv and I would like the same behaviour.
> Is it possible?

Yes, you need a PResource property of some sort.

While the simplest thing is just @P(1) PResource file; it's better to
use Property for this and handle the fact it might not be set. eg. in
a core:custom in a data patch -

```
    @P(1) @Type(PResource.class)
    Property res;
    @P(2) @ReadOnly
    String loc;

    @Override
    public void init() {
        res.valuesAs(PResource::from).link(r -> {
            loc = r.map(PResource::toString).orElse("");
            // loc = r.map(rr ->
rr.resolve(getLookup()).get(0).toString()).orElse("");
        }
        );
    }

```

I have two problems here, one is the leading "file:", while the other is with the SPACE char inside the praxis automatic project folder name.
i.e. to solve I've done this:
// Old working address:
//String fileName = "/home/dab/PraxisLIVE Projects/CueCall_v0_91/resources/Show.csv";
// Way to make PResource work:
String[] output = loc.substring(5).split("%20"); // this cut the leading "file:" and change "%20" with " ".
File file = new File(output[0]+" "+output[1]);


Davide D'Angelo

unread,
Apr 9, 2019, 9:05:08 AM4/9/19
to PraxisLIVE software discussion group
Apart from that, I can confirm that if I copy the project folder with another name, that address changes on the new folder as I needed.
Thank you Neil.

Regards, Davide.

Neil C Smith

unread,
Apr 9, 2019, 9:08:42 AM4/9/19
to Praxis LIVE software discussion group


On Tue, 9 Apr 2019, 13:59 Davide D'Angelo, <77d...@gmail.com> wrote:
I have two problems here, one is the leading "file:", while the other is with the SPACE char inside the praxis automatic project folder name.

Yes, it's a URI wrapper. Rather than toString() you can use value(), or the URI list returned from resolving, and pass that into File constructor (or newer Path class) 

Best wishes, 

Neil
Reply all
Reply to author
Forward
0 new messages