Cabbage Logo
Back to Cabbage Site

Troubleshooting suggestions

I’m working on a program that is a “proof” of concept, not so much a useful finished product. But, this program uses a lot of k-rate loops, and when I try to insert print statements into these loops, it prints things that are not at all what I am expecting. All this despite the program doing things very unexpectedly. Structurally, it appears my program is working, but I can’t quite figure out why it doesn’t produce the results I am expecting.

Any suggestions would be appreciated!

What do you mean by k-rate loops? While-loops? If-statements?

I remember I had a issue with if-statements and k-rate variables at initialization. The if-statement would run even if the condition was not true, thus setting the identifier to a value it was not supposed to be when starting to run the code. The way I fixed this was by using inline if-statements (like this post is showing: LFO on GUI Parameters).

Could it be related to this? Maybe you can prepare a simple .csd where you experience the issue? Atleast record a .gif and post here (using something like ScreenToGif)?

Essentially, I am trying to do a “Game of Life” simulation. In the main loop, it has two while loops, iterating over a two dimensional array. Then from within that loop, it calls other opcodes that execute loops themselves. The problem doesn’t appear to be the loops themselves, I just can’t seem to get any kind of meaningful information about the state of the program as it is running.

There really is nothing out of the ordinary here, but it appears that whenever I put any print statements within those loops, it only prints the first call of that print statement. All other iterations of those loops do nothing for printing, but everything else seems to be executing. I just can’t seem to figure out how to troubleshoot because those print statements are not doing what I am expecting.

Can you post a very boiled down version of the necessary code for this to happen? Even just a simple screenshot of the code with the print statements would be very helpful…

So, this is the score with the main instr. You’ll notice the score calls instr 1, which builds the widgets, that part of the program works fine. And then “GoL” is run.

The highlighted code is one of the loops that doesn’t seem to print what I am expecting. The output should be a pair of numbers for each cell in the first row of the widget matrix.

Also, if you notice the last part of the GoL code prints out a generation number, which effectively is once every k-cycle, a new generation is produced. When I run it, it will print out the number of generations iterated, so it appears that it is still counting…

Thanks for your help.

The while-loop keeps crashing on me when I comment out stuff :rage:

Is this correct?

<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue") pluginId("def1")

</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1


instr 1
iXMax = 42
iYMax = 42
kNextGen[][] init iXMax, iYMax

kY init 0

if metro(.5) == 1 then    
    if kY < iYMax then
        printks "%d", 0, kNextGen[0][kY]
        printks "%d", 0, kY
        kY = kY + 1
    endif
endif

endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

Minus the fact that there is no loop there, that is effectively how it seems to be executing…

In your code with the while-loop, the variable kY instantly jumped to 42 for some reason, which I couldn’t understand why…

Anyway, going to bed now.

I noticed that as well. Thanks again. Sleep well.

So the program works but you’re finding it hard to print info from Csound? I’ve seen this issue before when running k-rate loops. Can you try using printf instead? If that doesn’t work, try calling an instrument that will print info for you using an event or schedule opcode. I think that should do trick.

Thanks! Usually when I get to a point like this, I will find some other way to do things. But here I just can’t make heads nor tails of anything.