Csound Csound-dev Csound-tekno Search About

[Csnd] combining variable names

Date2008-12-20 23:32
Fromjoachim
Subject[Csnd] combining variable names
I'd like to combine a name and a (changing) number in a variable name.  
I thought I could do this with a macro. This is okay:

instr 1
iwasdenn1	=	100
iwasdenn2	=	200
#define HU(a) #iwasdenn$a.#
print	$HU(1)
endin

(It prints:
instr 1: iwasdenn1 = 100.000)

But what I actually want to do is, to calculate the number and then,  
after the calculation, getting the variable name. But when I write:

instr 1
iwasdenn1	=	100
iwasdenn2	=	200
#define HU(a) #iwasdenn$a.#
ival	 =	1
print	$HU(ival)
endin

I get the error message that "input arg 'iwasdennival' used before  
defined".
So instead of regarding ival as a variable, and evaluating it, the  
macro just takes it as a name.
Is there any way to get the value of ival (not the name) in the macro?
Or is there any other way to do want I wish?

Thanks -

	joachim

Date2008-12-21 03:56
FromDarren Nelsen
Subject[Csnd] Re: combining variable names
Couldn't you define ival as a macro?, ie.

> instr 1
> iwasdenn1	=	100
> iwasdenn2	=	200
> #define HU(a) #iwasdenn$a.#
> #define IVAL #1#
> print	$HU($IVAL)
> endin


--
Darren Nelsen
http://www.curiomusic.com

On Dec 20, 2008, at 6:32 PM, joachim wrote:

> I'd like to combine a name and a (changing) number in a variable  
> name. I thought I could do this with a macro. This is okay:
>
> instr 1
> iwasdenn1	=	100
> iwasdenn2	=	200
> #define HU(a) #iwasdenn$a.#
> print	$HU(1)
> endin
>
> (It prints:
> instr 1: iwasdenn1 = 100.000)
>
> But what I actually want to do is, to calculate the number and then,  
> after the calculation, getting the variable name. But when I write:
>
> instr 1
> iwasdenn1	=	100
> iwasdenn2	=	200
> #define HU(a) #iwasdenn$a.#
> ival	 =	1
> print	$HU(ival)
> endin
>
> I get the error message that "input arg 'iwasdennival' used before  
> defined".
> So instead of regarding ival as a variable, and evaluating it, the  
> macro just takes it as a name.
> Is there any way to get the value of ival (not the name) in the macro?
> Or is there any other way to do want I wish?
>
> Thanks -
>
> 	joachim
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
> "unsubscribe csound"
>


Date2008-12-21 10:41
Fromjoachim
Subject[Csnd] Re: Re: combining variable names
I think the problem remains, because I don't know the value of ival,  
but want to calculate it (e.g. in a reinit loop).
So I am looking for a way to get the value of ival (which is different  
in several cases) in a macro.
But this seems to be impossible.
Thinking in an other direction, this can be done with a string:
ival			random	1, 10
Symbol		sprintf	"iwasdenn%d", int(ival)
gives something like "iwasdenn8".
But I can't see a way to transform a string in a variable name.
Perhaps with a python opcode?


Am 21.12.2008 um 04:56 schrieb Darren Nelsen:

> Couldn't you define ival as a macro?, ie.
>
>> instr 1
>> iwasdenn1	=	100
>> iwasdenn2	=	200
>> #define HU(a) #iwasdenn$a.#
>> #define IVAL #1#
>> print	$HU($IVAL)
>> endin
>
>
> --
> Darren Nelsen
> http://www.curiomusic.com
>
> On Dec 20, 2008, at 6:32 PM, joachim wrote:
>
>> I'd like to combine a name and a (changing) number in a variable  
>> name. I thought I could do this with a macro. This is okay:
>>
>> instr 1
>> iwasdenn1	=	100
>> iwasdenn2	=	200
>> #define HU(a) #iwasdenn$a.#
>> print	$HU(1)
>> endin
>>
>> (It prints:
>> instr 1: iwasdenn1 = 100.000)
>>
>> But what I actually want to do is, to calculate the number and  
>> then, after the calculation, getting the variable name. But when I  
>> write:
>>
>> instr 1
>> iwasdenn1	=	100
>> iwasdenn2	=	200
>> #define HU(a) #iwasdenn$a.#
>> ival	 =	1
>> print	$HU(ival)
>> endin
>>
>> I get the error message that "input arg 'iwasdennival' used before  
>> defined".
>> So instead of regarding ival as a variable, and evaluating it, the  
>> macro just takes it as a name.
>> Is there any way to get the value of ival (not the name) in the  
>> macro?
>> Or is there any other way to do want I wish?
>>
>> Thanks -
>>
>> 	joachim
>>
>>
>> Send bugs reports to this list.
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
>> "unsubscribe csound"
>>
>
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
> "unsubscribe csound"


Date2008-12-21 15:22
From"Andres Cabrera"
Subject[Csnd] Re: Re: Re: combining variable names
AttachmentsNone  

Date2008-12-21 19:25
FromMark Van Peteghem
Subject[Csnd] Re: Re: Re: combining variable names
A simpler alternative would be to create a table of sufficient size, and 
read and write it with the opcodes table and tablew.

joachim wrote:
> Perhaps with a python opcode?
>
>
> Am 21.12.2008 um 04:56 schrieb Darren Nelsen:
>
>> Couldn't you define ival as a macro?, ie.
>>
>>> instr 1
>>> iwasdenn1    =    100
>>> iwasdenn2    =    200
>>> #define HU(a) #iwasdenn$a.#
>>> #define IVAL #1#
>>> print    $HU($IVAL)
>>> endin
>>
>>
>> -- 
>> Darren Nelsen
>> http://www.curiomusic.com
>>
>> On Dec 20, 2008, at 6:32 PM, joachim wrote:
>>
>>> I'd like to combine a name and a (changing) number in a variable 
>>> name. I thought I could do this with a macro. This is okay:
>>>
>>> instr 1
>>> iwasdenn1    =    100
>>> iwasdenn2    =    200
>>> #define HU(a) #iwasdenn$a.#
>>> print    $HU(1)
>>> endin
>>>
>>> (It prints:
>>> instr 1: iwasdenn1 = 100.000)
>>>
>>> But what I actually want to do is, to calculate the number and then, 
>>> after the calculation, getting the variable name. But when I write:
>>>
>>> instr 1
>>> iwasdenn1    =    100
>>> iwasdenn2    =    200
>>> #define HU(a) #iwasdenn$a.#
>>> ival     =    1
>>> print    $HU(ival)
>>> endin
>>>
>>> I get the error message that "input arg 'iwasdennival' used before 
>>> defined".
>>> So instead of regarding ival as a variable, and evaluating it, the 
>>> macro just takes it as a name.
>>> Is there any way to get the value of ival (not the name) in the macro?
>>> Or is there any other way to do want I wish?
>>>
>>> Thanks -
>>>
>>>     joachim
>>>
>>>
>>> Send bugs reports to this list.
>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body 
>>> "unsubscribe csound"
>>>
>>
>>
>>
>> Send bugs reports to this list.
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body 
>> "unsubscribe csound"
>
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body 
> "unsubscribe csound"
>
>

-- 
  Mark
  _________________________________________
  When you get lemons, you make lemonade.
  When you get hardware, you make software.


Date2008-12-21 21:45
From"Oeyvind Brandtsegg"
Subject[Csnd] Re: Re: Re: Re: combining variable names
AttachmentsNone  

Date2008-12-21 22:49
FromDavidW
Subject[Csnd] Re: Re: Re: Re: combining variable names
% import python

 >>> stringy='x=2'
 >>> exec(stringy)
 >>> print x
2


On 22/12/2008, at 2:22 AM, Andres Cabrera wrote:

> Hi,
>
> Macros are used by the preprocessor, so they are fixed when csound is
> running. You could do this with a python array. I don't think you can
> convert a string into a variable name to use in expressions in csound
> or in python, or can you?
>
> Cheers,
> Andrés
>
> On Sun, Dec 21, 2008 at 5:41 AM, joachim  wrote:
>> I think the problem remains, because I don't know the value of  
>> ival, but
>> want to calculate it (e.g. in a reinit loop).
>> So I am looking for a way to get the value of ival (which is  
>> different in
>> several cases) in a macro.
>> But this seems to be impossible.
>> Thinking in an other direction, this can be done with a string:
>> ival                    random  1, 10
>> Symbol          sprintf "iwasdenn%d", int(ival)
>> gives something like "iwasdenn8".
>> But I can't see a way to transform a string in a variable name.
>> Perhaps with a python opcode?
>>
>>
>> Am 21.12.2008 um 04:56 schrieb Darren Nelsen:
>>
>>> Couldn't you define ival as a macro?, ie.
>>>
>>>> instr 1
>>>> iwasdenn1       =       100
>>>> iwasdenn2       =       200
>>>> #define HU(a) #iwasdenn$a.#
>>>> #define IVAL #1#
>>>> print   $HU($IVAL)
>>>> endin
>>>
>>>
>>> --
>>> Darren Nelsen
>>> http://www.curiomusic.com
>>>
>>> On Dec 20, 2008, at 6:32 PM, joachim wrote:
>>>
>>>> I'd like to combine a name and a (changing) number in a variable  
>>>> name. I
>>>> thought I could do this with a macro. This is okay:
>>>>
>>>> instr 1
>>>> iwasdenn1       =       100
>>>> iwasdenn2       =       200
>>>> #define HU(a) #iwasdenn$a.#
>>>> print   $HU(1)
>>>> endin
>>>>
>>>> (It prints:
>>>> instr 1: iwasdenn1 = 100.000)
>>>>
>>>> But what I actually want to do is, to calculate the number and  
>>>> then,
>>>> after the calculation, getting the variable name. But when I write:
>>>>
>>>> instr 1
>>>> iwasdenn1       =       100
>>>> iwasdenn2       =       200
>>>> #define HU(a) #iwasdenn$a.#
>>>> ival     =      1
>>>> print   $HU(ival)
>>>> endin
>>>>
>>>> I get the error message that "input arg 'iwasdennival' used before
>>>> defined".
>>>> So instead of regarding ival as a variable, and evaluating it,  
>>>> the macro
>>>> just takes it as a name.
>>>> Is there any way to get the value of ival (not the name) in the  
>>>> macro?
>>>> Or is there any other way to do want I wish?
>>>>
>>>> Thanks -
>>>>
>>>>       joachim
>>>>
>>>>
>>>> Send bugs reports to this list.
>>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
>>>> "unsubscribe
>>>> csound"
>>>>
>>>
>>>
>>>
>>> Send bugs reports to this list.
>>> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
>>> "unsubscribe
>>> csound"
>>
>>
>>
>> Send bugs reports to this list.
>> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
>> "unsubscribe
>> csound"
>>
>
>
>
> -- 
>
>
> Andrés
>
>
> Send bugs reports to this list.
> To unsubscribe, send email sympa@lists.bath.ac.uk with body  
> "unsubscribe csound"
>

________________________________________________
David Worrall.
- Experimental Polymedia:	www.avatar.com.au
- Education for Financial Independence: www.mindthemarkets.com.au
Australian research affiliations:
- Capital Markets Cooperative Research Centre: www.cmcrc.com
- Sonic Communications Research Group:	creative.canberra.edu.au/scrg
- MARCS Auditory Laboratories: marcs.uws.edu.au





Date2008-12-22 15:11
From"Andres Cabrera"
Subject[Csnd] Re: Re: Re: Re: Re: combining variable names
AttachmentsNone