Supercollider tips, Q/A


#264

this is spot on

use Mix to bring them together into a mono signal

{ Mix.new( [SinOsc.ar(440, 0, 0.2), SinOsc.ar(442, 0, 0.2), SinOsc.ar(542, 0, 0.2)] ) .play;

lots more information here

http://doc.sccode.org/Guides/Multichannel-Expansion.html


#265

@edbkt & @junklight: Thank you very much – I was utterly bamboozled by this, especially since stereo/multichannel explanations are first mentioned as late as in the sixth part of the SC tutorial. I guess I would have given up before without your help!


#266

hi,
Im getting back into supercollider after a bit of time off, and I think im missing something pretty simple,
perhaps someone can point me back on track :slight_smile:

DigitalIO is a custom ugen, which sends out digital signals for bela, (but its not really the issue), and i want it to change it value when a midi note is received so something like:

       ~gate = 0;
        DigitalIO.kr(~led1,0,~gate);

        MIDIdef.noteOn(\noteon, { 
	    arg vel, note;
             ~gate = 1;
        });
	
       MIDIdef.noteOff(\noteoff, { 
           arg vel, note;
            ~gate = 0;
        });

this fails :slight_smile:

ok, I remember this is because ~gate will be a client side var, but Im struggling to remember how id get something similar to this on the server side,

the only things i can think of is using something like Ndef to replace the ugen, but that seems overly complex - no?

e.g.

	MIDIdef.noteOn(\noteon, { 
		arg vel, note;
		Ndef(\t1led, { DigitalIO.kr(~led1,0,1) });
	});
	
	MIDIdef.noteOff(\noteoff, { 
		arg vel, note;
   		Ndef(\t1led, { DigitalIO.kr(~led1,0,0) });
	});

EDIT:

ok, memories are coming back so i think i should be able to do something like

(but still not working :wink: )

	Ndef(\t1led, { 
		arg g;
		DigitalIO.kr(~led1,0,DC.kr(g));
	});

	MIDIdef.noteOn(\noteon, { 
		arg vel, note;
		Ndef(\t1led).set(\g,1);
	});
	
	MIDIdef.noteOff(\noteoff, { 
		arg vel, note;
		Ndef(\t1led).set(\g,0);
	});

EDIT 2:

ok fixed , without the DC.kr works :slight_smile:

	Ndef(\t1led, { 
		arg g;
		DigitalIO.kr(~led1,0,g);
	});
	MIDIdef.noteOn(\noteon, { 
		arg vel, note;
		Ndef(\t1led).set(\g,1);
	});
	
	MIDIdef.noteOff(\noteoff, { 
		arg vel, note;
		Ndef(\t1led).set(\g,0);
	});

not sure its the best way, but I think is workable for my needs…


#267

Could do it with a SynthDef:

SynthDef(\tiled, {
    arg g;
    DigitalIO.kr(~led1,0,g);
}).add;

x = Synth(\tiled);

x.set(\g, 0); // put this in your MIDIDef
x.set(\g, 1);

#268

Cool, I’m guessing that’s pretty much equivalent to NDef - no? Just a different way to declare the synth node?


#269

It’s a little different, though maybe not in your usecase. Ndef’s are “node proxies”, which handle the creation and management of nodes on the server. For example, you can change the Ndef while the node is playing, and behind the scenes the Ndef will create a new node, fade it in, and then fade out the old node and release it. As such Ndef’s are good for live coding. The synth command just makes a node on the server. So either will work, but Ndef’s are more complicated…


#270

thank you…

yeah, last time I was doing more Live coding so ‘fell in love’ with Ndef :slight_smile:
so picked up those examples, but of course had forgotten the background.

so when playing this morning, indeed I found issues using Ndef due to the functionality you described, which was quickly fixed by using a simple synthdef - which was cool - thank you.
also means Im go go dig back into the jitproxy stuff again, to refamiarise myself - make sure im using the right tool for the job :wink:

having fun though , its nice to be jumping back into the SC…


#271

Hello!
Been quite a while since I posted on the forum, I recently moved to Chicago for school and have been very busy with classes. Anyways, I hope everyone is well!

So this semester I’m taking an audio programming course taught in SuperCollider, and while working on my final project, SuperCollider stopped receiving audio input.

I am working on macOS Mojave 10.14, and SuperCollider 3.9.3.
Here are my audio settings when booting the server:

Number of Devices: 6
0 : “Built-in Microph”
1 : “Built-in Output”
2 : “Soundflower (2ch)”
3 : “Soundflower (64ch)”
4 : “Pro Tools Aggregate I/O”
5 : “Aggregate Device”

“Built-in Microph” Input Device
Streams: 1
0 channels 2

“Built-in Output” Output Device
Streams: 1
0 channels 2

SC_AudioDriver: sample rate = 44100.000000, driver’s block size = 512
SuperCollider 3 server ready.

Here is an example of code I am trying to run:

x = {SoundIn.ar(0) }.play;

The Server Meter doesn’t show any input response.
Using other applications such as Ableton or Max I am able to get audio input normally.
I have tried killing all servers, closing the application, changing my input device (between my computer’s built in, and my external audio interface) and even uninstalling SuperCollider.
I spoke with my professor as well and she couldn’t figure it out either.

Any insight on what might be going on and possible fixes would be greatly appreciated!


#272

just a thought, mojave now requires an app permission to access audio input. this has to be requested in the app’s Info.plist.

maybe your SC biuld is not doing this; 3.9.3 was released back in april when only preview mojave builds were available, so i think this seems likely.

maybe worth trying a newer build


#273

Nailed it, thank you so much!


#274

And… since you wrote that, 3.10 is out…


#275

Hello again!

So I am working on an audio input recorder and looper but am struggling to get it to work the way I would like.

I am trying to:

1)Record into a buffer
2)Use a function to copy the buffer to a second buffer
3)Loop the second second buffer and play it

I think the problem is somewhere in my copyBuf function.
Perhaps I can’t just pass buffers as arguments?

Here is my code:

~recBuf_1 = Buffer.alloc(s, 44100 * 12.0, 1); // Recording buffer 1
~loopBuf_1 = Buffer.alloc(s, 44100 * 12.0, 1); // Looping Buffer 1

// Recorder SynthDef
(
SynthDef(\simpleRecorder, {
	arg bufNum, run = 1, ;
    var sig;
	sig = SoundIn.ar(0!1);
    RecordBuf.ar(sig, bufNum, loop: 0);
}).add;
)

// Looper SynthDef
(
SynthDef(\simpleLooper, {
	arg  amp = 1.0, out = 0, bufNum, rate = 1.0, startPos = 0.0, loop = 1;
    var playBuf;
    playBuf = PlayBuf.ar(1, bufnum: bufNum, rate: rate, startPos: startPos, loop: loop)*amp;
    Out.ar(out, playBuf);
}).add;
)


//copyBuf function
(
FunctionDef( \copyBuf, {
	arg inBuf, outBuf;
	var tempArray;
	tempArray = \inBuf.loadToFloatArray(); //copy recBuf to tempArray
	\outBuf.loadCollection(tempArray); //copy tempArray to loopBuf
});
)



x = Synth(\simpleRecorder);
Function.value(\copyBuf, [~recBuf_1, ~loopBuf_1]);
y = Synth(\simpleLooper, [\bufNum: ~loopBuf_1.bufnum]);

I’m still very much a novice working with supercollider so any help would be greatly appreciated!
cheers!


#276

Try this:

Buffer.freeAll;
~recBuf_1 = Buffer.alloc(s, 44100 * 2, 1); // Recording buffer 1
~loopBuf_1 = Buffer.alloc(s, 44100 * 2, 1); // Looping Buffer 1

(
// Recorder SynthDef
SynthDef(\simpleRecorder, {
	arg bufNum, run = 1;
	var sig, doneTrig;
	sig = SoundIn.ar(0);
	RecordBuf.ar(sig, bufNum, loop: 0);

	// a little clean-up
	doneTrig = TDelay.kr(Impulse.kr(0), BufDur.ir(bufNum));
	SendReply.kr(doneTrig, '/rec/done');
	FreeSelf.kr(doneTrig);
}).add;

// Looper SynthDef
SynthDef(\simpleLooper, {
	arg amp = 1.0, out = 0, bufNum, rate = 1.0, startPos = 0.0, loop = 1;
	var playBuf;
	playBuf = PlayBuf.ar(1, bufnum: bufNum, rate: rate, startPos: startPos, loop: loop)*amp;
	Out.ar(out, playBuf);
}).add;
)

(
//copyBuf function
~copyBuf = {
	arg inBuf, outBuf;
	inBuf.loadToFloatArray(action: {
		arg x;
		outBuf.sendCollection(x);
	});
};

// catch notification that recording has finished
OSCdef.newMatching(\startLooper, {
	~copyBuf.value(~recBuf_1, ~loopBuf_1);
	y = Synth(\simpleLooper, [\bufNum: ~loopBuf_1]);
},"/rec/done").permanent_(true);
)


x = Synth(\simpleRecorder, [\bufNum, ~recBuf_1]);

#277

Hey! Wow this is great, thanks so much for helping out!
Would you be able to explain a little what is going on with the OSCdef?
It like listens for the /rec/done message from the simpleRecorder, then runs the copyBuf function and creates the simpleLooper synth?


#278

Yes that’s all it does. You can of course call copyBuf and instantiate the simpleLooper manually if you want as well.


#280

Hello!
Is there a way to check if a specific node exists in a group?
I am trying to create an if statement that does the following:
if the node doesn’t exist -> create a synth node
if the node already exists -> replace with a new synth node

I’m sure this is relatively simple but I can’t figure it out!


#281

I don’t have my computer with me rn but I know there’s a method to print the node tree to the console…I usually have to swim on the doc system to remember it. Perhaps start with Server?


#282

Hey! Yeah there definitely is, s.queryAllNodes I think. I was just running into issues implementing that info into a conditional statement.
But I kinda figured out a work around by registering the nodes with NodeWatcher and then the isRunning method. A little sloppy for how my code is structured because I need to create the Synths before I’m actually using them but it works so I’ll take it!


#283

Look here: http://doc.sccode.org/Guides/NodeMessaging.html


#284

I’d like to use my new Korg nanoKONTROL 2 for a SuperCollider project, but couldn’t figure out how to change only one key of my Pdef without setting up a new instance. Do you have any advice?

You can find my code on GitHub: https://github.com/kenokenobingo/studies.