Why isn't q making a sound ,despite the console launching synths?

Why isn’t q making a sound ,despite the console launching synths when executing q ?
I learned so much stuf the past few weeks , but when I look back at some verry simple stuff , I either totally forgot or must be doing something terribly wrong
The method call play is stored within the variable q , then it should wok no ?


(
q=
(
{
	SinOsc.ar(110,mul:0.2)!2
}.play
)
)
///
q.free;
q;////////executing launches synths but no sound 
q.class

execute q.isRunning

when you interpret ‘q’ you are not launching a synth, you are just finding out what is stored in interpreter variable q.

Its a Synth object. but when you sent that object the .free method, the node it used to reference on the server was stopped and removed.

maybe you are wanting to make a function that plays a synth, something like

q = {
  { SinOsc.ar(300,0,0.1)}.play
}

then you can write q.() and you will get a synth
if you want to access the synth in that setup you need to assign it to something

r = q.()
r.free

but in your example you wrapped the inner function in parens which wasn’t necessary.

Thanks ,
I have seen empty parenthesis before , what’s their use ?
Why do you reassign a new variable to q , that’s what I don’t get , q is assigned a function ,so executing q is enough too play , but freeing q does not


q = {
  { SinOsc.ar(300,0,0.1)}.play
}


q.play;
q.free;


parenthesis define an expression - the contents are evaluated first. No need to evaluate the contents first in your example.

If we assign q to a Function, q.value or q.() will evaluate the function stored in q. The contents of q are not changed. running a function returns the last value computed in the function. In this case that return value is a Synth

so when you assign q, q is a Function.
so when you run u = q.(), q is still a Function. u is set to the return value of q. so u is the Synth.

If you want to access the result of a function you need to store that function’s return value somewhere.

But ,() is from class event ? ,
I just can’t wrap my head around the langauge
The dsp stuff is awesome and easy to achieve but the language is just killing me :frowning:

You are just complicating stuff that does not need to.
Why parenthesis.
What is your purpose?
What do you try to achieve?

I didn’t want to achieve anything , I got strayed away because I wanted to trigger a piece of code hence the assignment of the variable , which took me back to the beginning og laerning supercollide and I oviously forgot a lot of stuff
Why the parenthesis , to include everything in one block

One potential simpler answer: If you are using built-in laptop speakers, they can’t produce frequencies below about 200 Hz. So 110 Hz is dead in the water.

Try a higher pitch?

(I made literally this exact same mistake once, was in a huge panic “omg SC is broken what am I gonna do” and then someone pointed out the laptop speaker limitation :man_facepalming: I felt like an idiot.)

hjh

One thing that is working against you here is that SC culture prefers to give a lot of alternatives, even when it may not be appropriate.

“How do I…?”

  • You could do this, or this.
  • Or this! Don’t forget about this!
  • IMO this is the best way.
  • But you could also do that…

And now you’re in the position of evaluating which of these is ideal. This requires background knowledge and context, which you’re still in the middle of learning.

So this type of discussion is sometimes not actually helpful, especially for beginners.

Starting over, then:

“Why isn’t q making a sound ,despite the console launching synths when executing q ?”

Was it, though? Did you see the “s” number going up?

“The method call play is stored within the variable q”

No, it isn’t. This is definitely never how variables work. Best to delete this idea from your brain.

A variable is a pointer to an object that exists somewhere in memory.

Objects are the results of expressions.

q = ... something... means: Step 1. Evaluate “something” – this will produce an object as the result. Step 2. Change q to point to this result.

The result of { }.play is a Synth. q then refers to this Synth object.

q.free then deletes that Synth object from the server (but this does nothing to change q in the language).

q is still the synth object, but it’s defunct. So accessing q simply calls up the old synth object, which isn’t doing anything.

Remember also that the only way SC does anything is with a method call.

In q, where is the method call? Where’s the receiver and method selector? There’s not one. So this doesn’t take any action. It only gives you back a prior result.

At this point, semiquaver wanted to give you a q that could make new synths. That’s valid but perhaps premature. In any case, writing an action into a function, and saving that function into a variable for reuse, is an important way to write clearer programs.

Then it really went off the rails with q.(). This is a shortcut syntax. IMO it’s better to avoid shortcut syntax with new users because it’s confusing!

So to explain the hidden bits:

Let’s say that you have assigned into q a synth-making function: q = { { SinOsc.ar(110, 0, 0.1).dup }.play };.

If you want it to do its thing – again, nothing happens in SC without a method call. So you need to call a method on the object stored in q.

This method is value. When you send the message value to a function object, it evaluates its stored instructions (which, here, are to play a function).

q.value;

In this case, q declares no arguments, so there’s no argument list given to the value message. But in other contexts, it could be myFunction.value(... args...).

Now the fun bit: SC allows the keyword value to be omitted if it’s being applied as a method selector to an object. That would leave q. – but this is ambiguous syntax – if it were allowed, then there could be some obscure uses of dots where the compiler couldn’t reduce it to one and only one meaning. So there needs to be something to disambiguate. And this is – when you’re leaving out value, you must write an argument list in parentheses – always q.( ... something ...), never just q.

But then the argument list may be empty – so q.() is a valid shortcut for q.value without arguments. (It has nothing to do with events.)

Do you need to know all that right now? Probably not. If I were teaching you privately, I would not have gone into this at this moment. There are too many other concepts that are more important.

Do keep the thing about method calls in mind. It’s the top #1 rule in SC.

hjh

3 Likes