Cabbage Logo
Back to Cabbage Site

List of numeric values - Read a rhythm

Hi all,

I’m trying to write a list of numeric values with an instrument in a table (maybe using tableiw?) but the important thing is that I’d like to change the list to create different rhythms, so I need to write it all the time that I change the parameters.

for example:

iBeats = 7
iAccents = 3
iPauses = iBeats - iAccents

1 0 0 1 0 1 0

or

iBeats = 6
iAccents = 3
iPauses = iBeats - iAccents

1 0 1 0 1 0

and after that read it with another instrument: if 1 then play a note, if 0 then turnoff the instrument
I do not know if I was clear, but I’m a little bit confused…:sweat_smile:
Someone have some suggestions?

Thanks for your help

How about something like this? I didn’t add many comments. Let me know if you have any questions. test.csd (1.1 KB)

1 Like

That’s exactly what I was looking for!
It’s all clear, but I cant’t understand this two lines because in the Csound Manual I can’t find these two symbols “?” and “:”…

kIndex = kIndex==7 ? 0 : kIndex+1

tabw kVal>0 ? 1 : 0, kCnt, giRtm

I’m using Cabbage for an exam at Conservatory and It’s really helpful for live electronics!
Thanks for your time

That expression is known as a ternary operator. It basically states that if kIndex is currently 7, it should be set to 0, otherwise add 1 to it. The same idea could be expressed using a few more lines of code:

if kIndex==7 then 
 kIndex = 0 
else 
 kIndex = kIndex+1
endif

Ternary operators usually use this type of structure:

<condition> ? <true-case-code> : <false-case-code>;

If you search for ternary operators online you’ll find lots of examples. Most languages follow the same structure. What university are you studying in?

Now I get it!
I’m an electronic composition student at Conservatorio N. Paganini in Genova, but the next semester I’ll be in Bilgi University in Istanbul to do a project based on “usuls”, rhythmic patterns in Ottoman music. That’s why I’m starting to practice with rhythms sequences on Cabbage.

Sound cool. I’ve used Cabbage for a lot of Rhythm generation in the past. You’d be surprised how much you can modify adapt and hack that example I sent you. Note that you should also consider using arrays instead of tables. It might make things a little easier to follow. I currently use the two approaches, but find myself slipping into using arrays by default.

Many thanks for your tips, I’ll take a look also at the arrays. :grinning: