Csound Csound-dev Csound-tekno Search About

[Csnd] printf in while loops

Date2020-03-07 16:29
Fromkelly hirai
Subject[Csnd] printf in while loops
hey csound community,

i'm trying to get an array of strings to print on the signal ktrig using 
printf in a while loop. in this construction, it seems only the first 
iteration gets printed. is there a better way to do this?

kelly

output:

new alloc for instr 1:
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
B  0.000 .. 10.000 T 10.000 TT 10.000 M:      0.0      0.0

csd:



sr =44100
kr =4410
ksmps =10
nchnls =2

instr 1
  ktrig metro 1

  kitr = 0
  Sout =":"
  while kitr < 2 do
   printf "%s%d,%d\n", ktrig,Sout,ktrig,kitr
   kitr +=1
  od
endin



i1 0 10



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

Date2020-03-07 17:08
Fromjoachim heintz
SubjectRe: [Csnd] printf in while loops
not sure what you exactly want to do (print only when metro is 1?) but i 
think the second argument of your printf should be kitr+1, not ktrig.
best -
	joachim



On 07/03/2020 17:29, kelly hirai wrote:
> hey csound community,
> 
> i'm trying to get an array of strings to print on the signal ktrig using 
> printf in a while loop. in this construction, it seems only the first 
> iteration gets printed. is there a better way to do this?
> 
> kelly
> 
> output:
> 
> new alloc for instr 1:
> :1,0
> :1,0
> :1,0
> :1,0
> :1,0
> :1,0
> :1,0
> :1,0
> :1,0
> :1,0
> B  0.000 .. 10.000 T 10.000 TT 10.000 M:      0.0      0.0
> 
> csd:
> 
> 
> 
> sr =44100
> kr =4410
> ksmps =10
> nchnls =2
> 
> instr 1
>   ktrig metro 1
> 
>   kitr = 0
>   Sout =":"
>   while kitr < 2 do
>    printf "%s%d,%d\n", ktrig,Sout,ktrig,kitr
>    kitr +=1
>   od
> endin
> 
> 
> 
> i1 0 10
> 
> 
> 
> 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

Date2020-03-07 20:06
FromJohn ff
SubjectRe: [Csnd] printf in while loops
Setting kitr to zero every perf cycle is a little odd too
Maybe....
⁣Sent from TypeApp ​

On Mar 7, 2020, 16:30, at 16:30, kelly hirai  wrote:
>hey csound community,
>
>i'm trying to get an array of strings to print on the signal ktrig
>using 
>printf in a while loop. in this construction, it seems only the first 
>iteration gets printed. is there a better way to do this?
>
>kelly
>
>output:
>
>new alloc for instr 1:
>:1,0
>:1,0
>:1,0
>:1,0
>:1,0
>:1,0
>:1,0
>:1,0
>:1,0
>:1,0
>B  0.000 .. 10.000 T 10.000 TT 10.000 M:      0.0      0.0
>
>csd:
>
>
>
>sr =44100
>kr =4410
>ksmps =10
>nchnls =2
>
>instr 1
>  ktrig metro 1
>
>  kitr = 0
>  Sout =":"
>  while kitr < 2 do
>   printf "%s%d,%d\n", ktrig,Sout,ktrig,kitr
>   kitr +=1
>  od
>endin
>
>
>
>i1 0 10
>
>
>
>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

Date2020-03-08 19:36
Fromkelly hirai
SubjectRe: [Csnd] printf in while loops
shouldn't the output be

:1,0
:1,1

repeated 10 times? ultimately i'm trying to get an array of strings dynamically printed to the console on the signal from ktrig. the fillarray manual entry uses unrolled printks:

instr 1

  kS[] fillarray 1,7,5
       printk 0, kS[0]
       printk 0, kS[1]
       printk 0, kS[2]
  turnoff
endin

how would you do this with iteration?

k.


On 3/7/20 3:06 PM, John ff wrote:
Setting kitr to zero every perf cycle is a little odd too
Maybe....
⁣Sent from TypeApp ​

On Mar 7, 2020, 16:30, at 16:30, kelly hirai <khirai@hiraimusic.net> wrote:
hey csound community,

i'm trying to get an array of strings to print on the signal ktrig
using 
printf in a while loop. in this construction, it seems only the first 
iteration gets printed. is there a better way to do this?

kelly

output:

new alloc for instr 1:
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
B  0.000 .. 10.000 T 10.000 TT 10.000 M:      0.0      0.0

csd:

<CsoundSynthesizer>
<CsInstruments>
sr =44100
kr =4410
ksmps =10
nchnls =2

instr 1
 ktrig metro 1

 kitr = 0
 Sout =":"
 while kitr < 2 do
  printf "%s%d,%d\n", ktrig,Sout,ktrig,kitr
  kitr +=1
 od
endin
</CsInstruments>

<CsScore>
i1 0 10
</CsScore>
</CsoundSynthesizer>

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

Date2020-03-08 20:16
FromRory Walsh
SubjectRe: [Csnd] printf in while loops
There is a printarray opcode, but it doesn't seem to work for strings. Maybe you can file a ticket for that in the github issue tracker ;)

Opcodes with an internal state can't be run in a loop like this but I've no idea if that's the case with printf. Either way, when I hit these issues I always reach for the old recursive UDO to resolve them. And it works here too... 

opcode printMyArray, 0k[]o
    kArray[], iCnt xin
    kTrig metro 1
    iArrayLen = lenarray:i(kArray)
    printf "%d:%d\n"kTrig,iCnt,kArray[iCnt]
    if iCnt < iArrayLen-1 then
            printMyArray kArray, iCnt+1
    endif
endop

instr 1
    kArray[] fillarray 1,7,5
    printMyArray kArray
endin



On Sun, 8 Mar 2020 at 19:36, kelly hirai <khirai@hiraimusic.net> wrote:
shouldn't the output be

:1,0
:1,1

repeated 10 times? ultimately i'm trying to get an array of strings dynamically printed to the console on the signal from ktrig. the fillarray manual entry uses unrolled printks:

instr 1

  kS[] fillarray 1,7,5
       printk 0, kS[0]
       printk 0, kS[1]
       printk 0, kS[2]
  turnoff
endin

how would you do this with iteration?

k.


On 3/7/20 3:06 PM, John ff wrote:
Setting kitr to zero every perf cycle is a little odd too
Maybe....
⁣Sent from TypeApp ​

On Mar 7, 2020, 16:30, at 16:30, kelly hirai <khirai@hiraimusic.net> wrote:
hey csound community,

i'm trying to get an array of strings to print on the signal ktrig
using 
printf in a while loop. in this construction, it seems only the first 
iteration gets printed. is there a better way to do this?

kelly

output:

new alloc for instr 1:
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
:1,0
B  0.000 .. 10.000 T 10.000 TT 10.000 M:      0.0      0.0

csd:

<CsoundSynthesizer>
<CsInstruments>
sr =44100
kr =4410
ksmps =10
nchnls =2

instr 1
 ktrig metro 1

 kitr = 0
 Sout =":"
 while kitr < 2 do
  printf "%s%d,%d\n", ktrig,Sout,ktrig,kitr
  kitr +=1
 od
endin
</CsInstruments>

<CsScore>
i1 0 10
</CsScore>
</CsoundSynthesizer>

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
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