[Csnd] how to do this best?
| Date | 2025-08-10 09:01 |
| From | joachim heintz |
| Subject | [Csnd] how to do this best? |
i have seven simple rhythms, like this:
rtm_1:i[] = [1/4,1]
rtm_2:i[] = [1/4,1/4,1]
rtm_3:i[] = [1/2,1,1/4,1]
rtm_4:i[] = [2/3,1/4,1]
rtm_5:i[] = [1/4,1,1]
rtm_6:i[] = [1,1/4,1]
rtm_7:i[] = [1,1]
i want to get one of the elements randomly (again and again for an
instrument call).
if we had lists in csound 7, i could put these arrays in a list and then
take a random element:
all_rtms:i[] = [rtm_1,rtm_2,rtm_3,rtm_4,rtm_5,rtm_6,rtm_7]
as we don't have lists yet, what would be the best approach?
cheers -
joachim
Csound mailing list
Csound@listserv.heanet.ie
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 |
| Date | 2025-08-10 10:34 |
| From | Tarmo Johannes |
| Subject | Re: [Csnd] how to do this best? |
Hi! Tables and array of table numbers? Or twodimenrional array and getrow? Tarmo P, 10. august 2025 11:01 joachim heintz <jh@joachimheintz.de> kirjutas: i have seven simple rhythms, like this: |
| Date | 2025-08-10 10:54 |
| From | Eduardo Moguillansky |
| Subject | Re: [Csnd] how to do this best? |
I think I understand what you want to do, but I don't think that csound has a way to do exactly that with the given opcodes. I have an opcode pair "ref" and "deref" which can take a reference to an array and place that in another array, which would make your code work. What I would do if limited to vanilla csound is to make a 2D array with rhythms, each row being one of the rhythms. The row size of the 2D array would be the longest of the rhythms + 1, appending a sentinel value (maybe 0 in your case) to mark the end. Then you can get a row of that 2D array and iterate until the sentinel is reached. Another approach is to prepend the length of the subarray as the item 0, so once you get a row of the array, the effective length of the subarray is in the first value. On Sun, Aug 10, 2025 at 10:01 AM joachim heintz <jh@joachimheintz.de> wrote: i have seven simple rhythms, like this: |
| Date | 2025-08-10 11:58 |
| From | thorin kerr |
| Subject | Re: [Csnd] how to do this best? |
In the olde tongue: opcode concatarray, i[],i[]i[]i[]i[]i[]i[]i[]j iarr1[],iarr2[],iarr3[],iarr4[],iarr5[],iarr6[],iarr7[],iarrcnt xin iresult[] init lenarray(iarr1) + lenarray(iarr2) iarrcnt = (iarrcnt == -1 ? 6 : iarrcnt) indx = 0 until indx = lenarray(iresult) do if indx < lenarray(iarr1) then iresult[indx] = iarr1[indx] else iresult[indx] = iarr2[indx - lenarray(iarr1)] endif indx += 1 od iarrcnt -= 1 if iarrcnt > 0 then iresult[] concatarray iresult,iarr3,iarr4,iarr5,iarr6,iarr7,iarr7,iarrcnt endif xout iresult endop instr rhpicker irtm_1[] fillarray 1/4,1 irtm_2[] fillarray 1/4,1/4,1 irtm_3[] fillarray 1/2,1,1/4,1 irtm_4[] fillarray 2/3,1/4,1 irtm_5[] fillarray 1/4,1,1 irtm_6[] fillarray 1,1/4,1 irtm_7[] fillarray 1,1 iall_rtms[] concatarray irtm_1,irtm_2,irtm_3,irtm_4,irtm_5,irtm_6,irtm_7 indx = floor(unirand:i(lenarray:i(iall_rtms)-0.0000001)) irandpick = iall_rtms[indx] printf_i "indx = %f, irndpick = %f\n",1,indx,irandpick endin schedule "rhpicker", 0, 1 On Sun, Aug 10, 2025 at 6:01 PM joachim heintz <jh@joachimheintz.de> wrote: i have seven simple rhythms, like this: |
| Date | 2025-08-10 12:00 |
| From | "Jeanette C." |
| Subject | Re: [Csnd] how to do this best? |
Hi Joachim,
tables of rhythms and an array with table numbers is a good one or, if you
have one trigger instrument, send table numbers through specific channels. Or
you could create a longer table or array with a good internal structure, so
you could pass along starting indices. Perhaps indicate how many elements your
rhythm has or determine a maximum length and fill empty spots with symbolic
values like 0 or -1. Perhaps you could use a UDO to convert this more complex
structure to a simple array inside your playing instruments, so you can go
through the more awkward logic only once in i-time per instrument event.
Personally, I would not use 2D arrays, since I seem to recall some issues with
certain situations.
As a last thought: I remember some Csound genius using a kind of dynamic code
generation. I think it was cslc, a library supporting all kinds of
live-coding:
https://github.com/ErrorThink/cslc-csd
HTH.
Best wishes,
Jeanette
Aug 10 2025, joachim heintz has written:
> i have seven simple rhythms, like this:
> rtm_1:i[] = [1/4,1]
> rtm_2:i[] = [1/4,1/4,1]
> rtm_3:i[] = [1/2,1,1/4,1]
> rtm_4:i[] = [2/3,1/4,1]
> rtm_5:i[] = [1/4,1,1]
> rtm_6:i[] = [1,1/4,1]
> rtm_7:i[] = [1,1]
>
> i want to get one of the elements randomly (again and again for an instrument
> call).
>
> if we had lists in csound 7, i could put these arrays in a list and then take
> a random element:
> all_rtms:i[] = [rtm_1,rtm_2,rtm_3,rtm_4,rtm_5,rtm_6,rtm_7]
>
> as we don't have lists yet, what would be the best approach?
>
> cheers -
> joachim
>
> Csound mailing list
> Csound@listserv.heanet.ie
> 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
>
--
* Website: http://juliencoder.de - for summer is a state of sound
* Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
* Audiobombs: https://www.audiobombs.com/users/jeanette_c
* GitHub: https://github.com/jeanette-c
It's not complicated
We just syncopated
We can read each others' minds <3
(Britney Spears)
Csound mailing list
Csound@listserv.heanet.ie
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 |
| Date | 2025-08-10 19:31 |
| From | joachim heintz |
| Subject | Re: [Csnd] how to do this best? |
thanks to all for the suggestions!
i learned some new possibilities, and the cslc-csd library is very
impressive --- didn't know it at all!
joachim
On 10/08/2025 13:00, Jeanette C. wrote:
> Hi Joachim,
> tables of rhythms and an array with table numbers is a good one or, if
> you have one trigger instrument, send table numbers through specific
> channels. Or you could create a longer table or array with a good
> internal structure, so you could pass along starting indices. Perhaps
> indicate how many elements your rhythm has or determine a maximum length
> and fill empty spots with symbolic values like 0 or -1. Perhaps you
> could use a UDO to convert this more complex structure to a simple array
> inside your playing instruments, so you can go through the more awkward
> logic only once in i-time per instrument event.
>
> Personally, I would not use 2D arrays, since I seem to recall some
> issues with certain situations.
>
> As a last thought: I remember some Csound genius using a kind of dynamic
> code generation. I think it was cslc, a library supporting all kinds of
> live-coding:
> https://github.com/ErrorThink/cslc-csd
>
> HTH.
>
> Best wishes,
>
> Jeanette
>
> Aug 10 2025, joachim heintz has written:
>
>> i have seven simple rhythms, like this:
>> rtm_1:i[] = [1/4,1]
>> rtm_2:i[] = [1/4,1/4,1]
>> rtm_3:i[] = [1/2,1,1/4,1]
>> rtm_4:i[] = [2/3,1/4,1]
>> rtm_5:i[] = [1/4,1,1]
>> rtm_6:i[] = [1,1/4,1]
>> rtm_7:i[] = [1,1]
>>
>> i want to get one of the elements randomly (again and again for an
>> instrument call).
>>
>> if we had lists in csound 7, i could put these arrays in a list and
>> then take a random element:
>> all_rtms:i[] = [rtm_1,rtm_2,rtm_3,rtm_4,rtm_5,rtm_6,rtm_7]
>>
>> as we don't have lists yet, what would be the best approach?
>>
>> cheers -
>> joachim
>>
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> 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
Csound@listserv.heanet.ie
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 |