A curious beginner's questions about codeboxes

Eren Utku's icon

Hello everyone,

I make music using SuperCollider and code mostly in Python, with a basic knowledge of C++ syntax, so the two of the several things that always pushed me back from Max was having to do simple operations through connecting cables and not being able to define a function. I think cables get out of control pretty quickly and I don't want to spend time moving things around too much. With the new Max 9 update, I saw that the usage of codebox has been extended, so I thought I would give it a try. My aim is to use either gen or javascript codeboxes as much as I can, to reduce the amount of cables and objects and also because I feel more comfortable with that kind of syntax.

Regarding these thoughts, I had a few questions:

  • Does this kind of approach make sense in Max, or using codebox objects this way make simple stuff more complicated than they are?

  • If I want to do simple addition at a control rate, for v8.codebox, I saw that I have to define msg_float function. But for gen.codebox, I just have to say out1 = in1 + in2 , which is easier to type out. However, I am not sure if gen has to work at audio rate and whether doing simple operations for simple control in gen~ would clutter the CPU?

  • I realized I cannot input a signal generator like cycle~ to a gen.codebox, but I can process it by inputting to v8.codebox and defining a signal function. Afaik, JS is a high level language and I am not sure if it is an ideal choice for real-time audio processing. If anybody could clarify this I would be glad because it would be good to efficiently manipulate the signal objects within a codebox. (in SC, it would be like using the UGens)

Thank you all in advance!

Roman Thilenius's icon

i believe it mostly depends on your preferences and experience. nobody forces you to use either this or that. in gen or javascript you can do a forloop and 3 expressions in one turn. in max you need 12 objects for the same process but therefore you get it dependency-free and within the max paradigm.

while max is more effective than js, gen~ is more effective than MSP.

choose one or use both...

Eren Utku's icon

Additionally, I just discovered there is not only gen.codebox and v8.codebox but also codebox and codebox~ that runs rnboscript, which had no helpfile and did not appear as suggestion in the object. I should check that too

Edit: I see it now that codebox and codebox~ helpfile are in rnbo

testcase's icon

there is also gen.codebox~

Eren Utku's icon

@TESTCASE i think what I was looking for was the gen and gen~ objects, which I can use the signal generators or other objects as input.

There are so many stuff in Max but the information is just all over the place if you are not used to the documentation and not familiar with the environment.

For example I can't understand from the documentation why the gen~ object can receive cycle~ as input and then lets you create a codebox inside it which can receive the signal as input, but it doesn't let cycle~ as input when I make a gen.codebox~ in a Max patcher window. I think gen~ environment somehow lets the code to be executed in some way but then what is the need for gen.codebox~ outside gen~ if you can't use it the same way you use it inside gen~ object?

Joshua Kit Clayton's icon

It sounds like you're just missing the tilde (~).

gen.codebox is for events. gen.codebox~ is for audio signals

Eren Utku's icon

@Joshua Kit Clayton aha... thanks a lot, that solves all my problems :)