Cabbage Logo
Back to Cabbage Site

If then else and prints

Hi Guys,

Super noob question : why does the following instrument enters every single condition for printing whenever the condition is not met ?

<Cabbage>
form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginID("def1")
keyboard bounds(8, 158, 381, 95)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1
gkTest1 init 0
gkTest2 init 1

;instrument will be triggered by keyboard widget
instr 1

if gkTest1>0 then 
    prints " Test1 >0   "
    if gkTest2==0 then 
        prints "             Test2 = 0   "
    else
        prints "             Test2 <> 0   "
    endif
else
    prints " Test1 <=0   "
    if gkTest2!=0 then 
        prints "             Test2 = 0   "
    else
        prints "             Test2 <> 0   "
    endif
endif

kEnv madsr .1, .2, .6, .4
aOut vco2 p5, p4
outs aOut*kEnv, aOut*kEnv
prints "\n\n"

endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
</CsScore>
</CsoundSynthesizer>

When the instrument is launched it first runs what’s known as an init pass. Only i-rate tests will work in this initialisation pass. Once the init pass is complete k-rate checks will work. If you want to check the initial value of k-rate, use a k-rate version of prints, i.e, printks.

Getting your head around Csound’s init and k-perf passes can be a little tricky at first. But after a while it becomes second nature. Further information can be found in the Csound floss manual.

These print family opcode are totally *****!~?* ! [A lot of French words totally censored :grin:]
I do not find the solution.

Which of these cryptic print family opcodes should I use to only to get an output like something I would get in C++ or C or python or Pascal (just print when the condition is entered and not every line)?

I’m not quite sure what you want. The print family of opcodes can print something just like C/Python, pascal or whatever, you just have to be careful of init and perf passes. If you swap out the prints(which is i-rate) for printks (which is k-rate) your instrument will work as one might expect. Or? Perhaps I’m not following what you are trying to do?

I discovered a huge memory leak in my synth under windows and I was trying to find where it comes from.
Funny enough it does not behave the same way under linux : No memory leak.
All in all, this memory leak happens when the instrument is the sum of 2 poscil … what could be more stupid ?
I also discover that under linux, event "i","Some_instrument",0,-1 does not play that instrument for more than one sec… ( the negative number is ignored…) I spent 3 hours on that Csound bug, at least on my linux build. This must be a Csound bug because I was testing some of @iainmccurdy midi routines (http://iainmccurdy.org/CsoundRealtimeExamples/MIDI/midiin_trigger_notes.csd) … so not my code !!

I believe the poscil issue is a bug and it has been reported on the Csound list. It might be good to join that list, it might have saved you some time? I’m not sure if the negative duration issue has been raised. It should work. If not it’s also a bug.

Can you try this version for windows
https://ci.appveyor.com/api/buildjobs/kptdhpcnq040eng0/artifacts/msvc%2FSetup_Csound_x64_6.10.0rc-vst.exe
The poscil bug should be fixed at least…

Btw, were you able to reproduce the negative duration problem with command line Csound? If so you might file an issue on the Csound github page.

Yes, @iainmccurdy 's example is a command csd. Notes sound stops after 1 sec. The minus is not taken into.

I am not on the list.

I did … Same. Yesterday I tried every single oscillator ( poscil, oscil,oscilkt…) of Csound. Memory leaks everywhere ! And it is not Cabbage which is responsible as I made a CSD with no Cabbage at all.

There is something very wrong with Csound windows builds. I don’t want to incriminate my code anymore because it is based on if /then/else/elseif. If there would be something wrong with that ,then at compile time, I should get error message.

This is really frustrating :confounded:

Note that the version of Csound we are testing on Windows is not for public consumption. We’re moving from using mingw to Visual Studio for building Csound and there are likely going to be some issues that need resolving before the first public release.

I think the poscil issue that reported to the Csound list was actually something else. I’m going to see now if I can recreate the memory leaks. If I can I will report it tout suite.

I know it’s frustrating. Right now you’re not just beta testing Cabbage, you’ve also accidently become a beta tester for the latest build of Csound!

I just tried the latest version of Csound there and I can’t see any memory problems? Can you send me the test csd that you used?

Do you have the possibility to use reaper files ?
If yes, i can send you all my stuff . As it works bith under linux and windows.
It is made of a simple bass line. The audio engine is the very last version of the morpheur synth.
There are 2 possibilities:
Use the Morpheur synth as a VST included in REAPER as a FX and play it
Use REAPER to send Midi Message to Cabbage playing the Morpheur Synth.
And then check under windows and Linux :
Linux every thing works great. No memory leak, a little bit CPU usage
Windows : Memory gets filled up.

You said you recreated the issues outside of Cabbage, in plain old Csound? Can you send me that file so I can test here because I’m seeing no problems with Csound.

This is Iain example. Under linux.

http://www.iainmccurdy.org/CsoundRealtimeExamples/MIDI/MIDIReadPitchAndVelocity.csd

No problems here with this file. It works perfectly. I don’t see any increased memory usage from playing it. I don’t know what’s happening on your system, but like I say, it works fine here.

Here are the files
Please use preset Morpheur 43
Test_morpheur.tar.gz (26.9 KB)

I’ll try now, Btw, a negative duration is also working perfectly fine for me.

Your latest version just crashes Cabbage for me, but I need to rebuild the latest version as I’m still using the last one. I will rebuild later and try it again. I think it’s crashing because the old path issue is still in my old build. I have to leave this for now, but I’ll let you know how it works out.

Ohhh you need to have 3 files in the same directory. Here is an updated archive.Test_morpheur.tar.gz (373.3 KB)

I had those files already. I’ll need to rebuild. But what about the negative duration issue? I couldn’t recreate that?