[Csnd] #include with macros or strings

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

[Csnd] #include with macros or strings

00000008a49663bc-dmarc-request

Dear List,

Is there a way to use a macro or a string variable as part on an address of an #include statement?

I have several files to include in an orchestra (all in the same directory) so I'd like to write the path of the directory only once.

Something similar to this (does not work for me, at least on android):

#define PATHH #/path/to/somewere#

#include "$PATHH/file1.txt"

#include "$PATHH/file2.txt"

#include "$PATHH/file3.txt"

Instead of (that works but require to change every single statement):

#include "/path/to/somewere/file1.txt"

#include "/path/to/somewere/file2.txt"

#include "/path/to/somewere/file3.txt"


Stefano

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] #include with macros or strings

Dave Seidel
I would like this capability as well, In my case, I'd like to be able to define a macro on the command line (using --omacro) and then use the macro in an #include statement, so that I can have different runs use different include files based on the command line.

On Wed, Jun 6, 2018 at 3:32 AM <[hidden email]> wrote:

Dear List,

Is there a way to use a macro or a string variable as part on an address of an #include statement?

I have several files to include in an orchestra (all in the same directory) so I'd like to write the path of the directory only once.

Something similar to this (does not work for me, at least on android):

#define PATHH #/path/to/somewere#

#include "$PATHH/file1.txt"

#include "$PATHH/file2.txt"

#include "$PATHH/file3.txt"

Instead of (that works but require to change every single statement):

#include "/path/to/somewere/file1.txt"

#include "/path/to/somewere/file2.txt"

#include "/path/to/somewere/file3.txt"


Stefano

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here


--
Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] #include with macros or strings

jpff
In reply to this post by 00000008a49663bc-dmarc-request
I will have to look closely at the code as macro expansion is delicate.  Will look today....

⁣Sent from TypeApp ​

On Jun 6, 2018, 08:33, at 08:33, [hidden email] wrote:

>Dear List,
>
>Is there a way to use a macro or a string variable as part on an
>address of an #include statement?
>
>I have several files to include in an orchestra (all in the same
>directory) so I'd like to write the path of the directory only once.
>
>Something similar to this (does not work for me, at least on android):
>
>#define PATHH #/path/to/somewere#
>
>#include "$PATHH/file1.txt"
>
>#include "$PATHH/file2.txt"
>
>#include "$PATHH/file3.txt"
>
>Instead of (that works but require to change every single statement):
>
>#include "/path/to/somewere/file1.txt"
>
>#include "/path/to/somewere/file2.txt"
>
>#include "/path/to/somewere/file3.txt"
>
>
>Stefano
>
>Csound mailing list
>[hidden email]
>https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>Send bugs reports to
>        https://github.com/csound/csound/issues
>Discussions of bugs and features can be posted here

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] #include with macros or strings

jpff
In reply to this post by Dave Seidel
Frst look says it ispossible but with a load a duplicated code.  I will
try to see if it can be mitigated.  At present as the character
surrounding the file name can be anything reading the string is not
simple.  I hope/expect there is a way to refactor but t will take a while.
==John ff

On Wed, 6 Jun 2018, Dave Seidel wrote:

> I would like this capability as well, In my case, I'd like to be able to
> define a macro on the command line (using --omacro) and then use the macro in
> an #include statement, so that I can have different runs use different include
> files based on the command line.
>
> On Wed, Jun 6, 2018 at 3:32 AM
> <[hidden email]> wrote:
>
>       Dear List,
>
>       Is there a way to use a macro or a string variable as part on an
>       address of an #include statement?
>
>       I have several files to include in an orchestra (all in the same
>       directory) so I'd like to write the path of the directory only
>       once.
>
>       Something similar to this (does not work for me, at least on
>       android):
>
>       #define PATHH #/path/to/somewere#
>
>       #include "$PATHH/file1.txt"
>
>       #include "$PATHH/file2.txt"
>
>       #include "$PATHH/file3.txt"
>
>       Instead of (that works but require to change every single
>       statement):
>
>       #include "/path/to/somewere/file1.txt"
>
>       #include "/path/to/somewere/file2.txt"
>
>       #include "/path/to/somewere/file3.txt"
>
>
>       Stefano
>
> Csound mailing list [hidden email]
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
> https://github.com/csound/csound/issues Discussions of bugs and features
> can be posted here
>
>
>
> --
> http://mysterybear.nethttps://soundcloud.com/mysterybear
> https://mysterybear.bandcamp.com
>
> http://recordings.irritablehedgehog.com/album/dave-seidel-60-hz
> Csound mailing list [hidden email]
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
> https://github.com/csound/csound/issues Discussions of bugs and features can
> be posted here
>

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] #include with macros or strings

luis antunes pena-4
In reply to this post by 00000008a49663bc-dmarc-request

Would something like this be usefull for you using strings instead of macros?

Sdir = "/path/to/something"
Sfile1 = "file1"
Sfile sprintf "%s/%s.txt", Sdir, Sfile1

Best,
Luis

Am 06.06.18 um 09:32 schrieb [hidden email]:

Dear List,

Is there a way to use a macro or a string variable as part on an address of an #include statement?

I have several files to include in an orchestra (all in the same directory) so I'd like to write the path of the directory only once.

Something similar to this (does not work for me, at least on android):

#define PATHH #/path/to/somewere#

#include "$PATHH/file1.txt"

#include "$PATHH/file2.txt"

#include "$PATHH/file3.txt"

Instead of (that works but require to change every single statement):

#include "/path/to/somewere/file1.txt"

#include "/path/to/somewere/file2.txt"

#include "/path/to/somewere/file3.txt"


Stefano

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] #include with macros or strings

thorin kerr
You could mimic #include with a UDO, which would let you use sprintf like Luis suggests to format the input argument.
This seems to work.... although, you mentioned Android, and I don't think it will work in the Csound for Android app if that's what you're using.

opcode includer, 0, S
Sfile xin
cigoto (filevalid(Sfile) == 0), NOTFOUND
iline init 0
Sresult = ""
while iline != -1 do
   Sline, iline readfi Sfile
   Sresult strcat Sresult, Sline
od
igoto EXITOPCODE
NOTFOUND:
prints "Could not read file\n"
EXITOPCODE:
ival evalstr Sresult
endop

 - Thorin




On Wed, Jun 6, 2018 at 10:43 AM, luis antunes pena <[hidden email]> wrote:

Would something like this be usefull for you using strings instead of macros?

Sdir = "/path/to/something"
Sfile1 = "file1"
Sfile sprintf "%s/%s.txt", Sdir, Sfile1

Best,
Luis

Am 06.06.18 um 09:32 schrieb [hidden email]:

Dear List,

Is there a way to use a macro or a string variable as part on an address of an #include statement?

I have several files to include in an orchestra (all in the same directory) so I'd like to write the path of the directory only once.

Something similar to this (does not work for me, at least on android):

#define PATHH #/path/to/somewere#

#include "$PATHH/file1.txt"

#include "$PATHH/file2.txt"

#include "$PATHH/file3.txt"

Instead of (that works but require to change every single statement):

#include "/path/to/somewere/file1.txt"

#include "/path/to/somewere/file2.txt"

#include "/path/to/somewere/file3.txt"


Stefano

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] #include with macros or strings

jpff
In reply to this post by luis antunes pena-4
No that would not work.  Includinf of files is done lexically before and
parsing of orc code and way before execution.


On Wed, 6 Jun 2018, luis antunes pena wrote:

>
> Would something like this be usefull for you using strings instead of macros?
>
> Sdir = "/path/to/something"
> Sfile1 = "file1"
> Sfile sprintf "%s/%s.txt", Sdir, Sfile1
>
> Best,
> Luis
>
> Am 06.06.18 um 09:32 schrieb
> [hidden email]:
>
>       Dear List,
>
>       Is there a way to use a macro or a string variable as part on an
>       address of an #include statement?
>
>       I have several files to include in an orchestra (all in the same
>       directory) so I'd like to write the path of the directory only
>       once.
>
>       Something similar to this (does not work for me, at least on
>       android):
>
>       #define PATHH #/path/to/somewere#
>
>       #include "$PATHH/file1.txt"
>
>       #include "$PATHH/file2.txt"
>
>       #include "$PATHH/file3.txt"
>
>       Instead of (that works but require to change every single
>       statement):
>
>       #include "/path/to/somewere/file1.txt"
>
>       #include "/path/to/somewere/file2.txt"
>
>       #include "/path/to/somewere/file3.txt"
>
>
>       Stefano
>
>       Csound mailing list [hidden email]
>       https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports
>       to https://github.com/csound/csound/issues Discussions of bugs and
>       features can be posted here
>
>
> --
> http://luisantunespena.eu
> http://sumtone.com
> Csound mailing list [hidden email]
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
> https://github.com/csound/csound/issues Discussions of bugs and features can
> be posted here
>

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] #include with macros or strings

jpff
In reply to this post by 00000008a49663bc-dmarc-request
I have a simplified macro in include working, good enough for the example
given.  It only accepts macros without arguments and without trailing .
(but I can easiy remove the latter restriction).  Also only written for
orc at present but easy to migrate to scores.

The question is thus is this sufficient?  Adding arguments would be a a
lot of code and I am not realy confident about how it would work.  Any
thoughts welcome

It would perhaps be easier if the syntax of iclude was changed so the file
name must be in double quotes instead of the current any character.  Does
anyone use that facility?

==John ff
On Wed, 6 Jun 2018, [hidden email] wrote:

>
> Dear List,
>
> Is there a way to use a macro or a string variable as part on an address of an
> #include statement?
>
> I have several files to include in an orchestra (all in the same directory) so
> I'd like to write the path of the directory only once.
>
> Something similar to this (does not work for me, at least on android):
>
> #define PATHH #/path/to/somewere#
>
> #include "$PATHH/file1.txt"
>
> #include "$PATHH/file2.txt"
>
> #include "$PATHH/file3.txt"
>
> Instead of (that works but require to change every single statement):
>
> #include "/path/to/somewere/file1.txt"
>
> #include "/path/to/somewere/file2.txt"
>
> #include "/path/to/somewere/file3.txt"
>
>
> Stefano
>
> Csound mailing list [hidden email]
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
> https://github.com/csound/csound/issues Discussions of bugs and features can
> be posted here
>

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] #include with macros or strings

Steven Yi
Rather than complicate things here, why not just set different INCDIR values?  This seems equivalent to using different -I paths with gcc or other compilers.  It already works and is rooted in a common practice and wouldn't require more code to maintain. 

On Thu, Jun 7, 2018 at 6:37 AM jpff <[hidden email]> wrote:
I have a simplified macro in include working, good enough for the example
given.  It only accepts macros without arguments and without trailing .
(but I can easiy remove the latter restriction).  Also only written for
orc at present but easy to migrate to scores.

The question is thus is this sufficient?  Adding arguments would be a a
lot of code and I am not realy confident about how it would work.  Any
thoughts welcome

It would perhaps be easier if the syntax of iclude was changed so the file
name must be in double quotes instead of the current any character.  Does
anyone use that facility?

==John ff
On Wed, 6 Jun 2018, [hidden email] wrote:

>
> Dear List,
>
> Is there a way to use a macro or a string variable as part on an address of an
> #include statement?
>
> I have several files to include in an orchestra (all in the same directory) so
> I'd like to write the path of the directory only once.
>
> Something similar to this (does not work for me, at least on android):
>
> #define PATHH #/path/to/somewere#
>
> #include "$PATHH/file1.txt"
>
> #include "$PATHH/file2.txt"
>
> #include "$PATHH/file3.txt"
>
> Instead of (that works but require to change every single statement):
>
> #include "/path/to/somewere/file1.txt"
>
> #include "/path/to/somewere/file2.txt"
>
> #include "/path/to/somewere/file3.txt"
>
>
> Stefano
>
> Csound mailing list [hidden email]
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to
> https://github.com/csound/csound/issues Discussions of bugs and features can
> be posted here
>

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] #include with macros or strings

00000008a49663bc-dmarc-request
In reply to this post by jpff

I only use double quotes, for me not having arguments is not a problem at the moment, don't know for others.

Does this work also with -omacro flag?

Anyway, thank you  


> Il 7 giugno 2018 alle 15.37 jpff <[hidden email]> ha scritto:
>
>
> I have a simplified macro in include working, good enough for the example
> given. It only accepts macros without arguments and without trailing .
> (but I can easiy remove the latter restriction). Also only written for
> orc at present but easy to migrate to scores.
>
> The question is thus is this sufficient? Adding arguments would be a a
> lot of code and I am not realy confident about how it would work. Any
> thoughts welcome
>
> It would perhaps be easier if the syntax of iclude was changed so the file
> name must be in double quotes instead of the current any character. Does
> anyone use that facility?
>
> ==John ff

Csound mailing list [hidden email] https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here
Reply | Threaded
Open this post in threaded view
|

Re: [Csnd] #include with macros or strings

jpff
I should have added that it only works if the body of the macro is text, not macro calls.

I have some other ideas to try to generalise....

⁣Sent from TypeApp ​

On Jun 8, 2018, 08:19, at 08:19, [hidden email] wrote:

>I only use double quotes, for me not having arguments is not a problem
>at the moment, don't know for others.
>
>Does this work also with -omacro flag?
>
>Anyway, thank you
>
>
>> Il 7 giugno 2018 alle 15.37 jpff <[hidden email]> ha scritto:
>>
>>
>> I have a simplified macro in include working, good enough for the
>example
>> given. It only accepts macros without arguments and without trailing
>.
>> (but I can easiy remove the latter restriction). Also only written
>for
>> orc at present but easy to migrate to scores.
>>
>> The question is thus is this sufficient? Adding arguments would be a
>a
>> lot of code and I am not realy confident about how it would work. Any
>> thoughts welcome
>>
>> It would perhaps be easier if the syntax of iclude was changed so the
>file
>> name must be in double quotes instead of the current any character.
>Does
>> anyone use that facility?
>>
>> ==John ff
>
>
>Csound mailing list
>[hidden email]
>https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
>Send bugs reports to
>        https://github.com/csound/csound/issues
>Discussions of bugs and features can be posted here

Csound mailing list
[hidden email]
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here