Created
May 10, 2024 23:05
-
-
Save pwqw/655713b5242c7c2f973efe9a73edfc9e to your computer and use it in GitHub Desktop.
Simple Piano 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A simple example of MIDI Keyboard for SuperCollider 3.6.x | |
*/ | |
MIDIIn.connectAll; | |
s.boot; | |
( | |
SynthDef("umbSinewave",{ | |
arg freq=440, gate=1, amp=1, pan=0; | |
var x; | |
x = SinOsc.ar(freq, 0, amp); | |
x = EnvGen.kr(Env.adsr(0.01,0.3,0.5,1,0.6,-4),gate,doneAction: 2) * x; | |
Out.ar(0, Pan2.ar(x,pan)); | |
}).add; | |
SynthDef("umbSinewaveEnvCareeta", { | |
arg freq=440, gate=1, amp=1, pan=0; | |
var x; | |
x = SinOsc.ar(freq, 0, amp); | |
x = EnvGen.kr( | |
Env.linen(1, 0.5, 0.5, 0.6), | |
doneAction: 2, | |
) * x; | |
/*x = BLowPass.ar(x, freq: 1000.0);*/ | |
Out.ar(0, Pan2.ar(x,pan)); | |
}).add; | |
SynthDef("otro",{ | |
arg freq=440, gate=1, amp=1, pan=0; | |
var x; | |
x = SinOscFB.ar(freq, 0, amp); | |
x = EnvGen.kr(Env.adsr(0.001,0.3, 0.5,0.1 ,0.6,-3,0),gate,doneAction: 2) * x; | |
Out.ar(0, Pan2.ar(x,pan)); | |
}).add; | |
SynthDef("blip",{ | |
arg freq=440, gate=1, amp=1, pan=0; | |
var x; | |
x = Blip.ar(freq, 100); | |
x = EnvGen.kr(Env.adsr(0.001,0.3, 0.5,0.1 ,0.6,-3,0),gate,doneAction: 2) * x; | |
x = x * amp; | |
Out.ar(0, Pan2.ar(x,pan)); | |
}).add; | |
SynthDef("blipRedondo",{ | |
arg freq=440, gate=1, amp=1, pan=0; | |
var x; | |
x = Blip.ar(freq, 100) + SinOsc.ar(freq, 8pi); | |
x = EnvGen.kr(Env.adsr(0.001,0.3, 0.5,0.1 ,0.6,-3,0),gate,doneAction: 2) * x; | |
x = x * amp; | |
Out.ar(0, Pan2.ar(x,pan)); | |
}).add; | |
SynthDef("blipRedondo2",{ | |
arg freq=440, gate=2, amp=1, pan=0; | |
var x; | |
x = Blip.ar(freq, 10) + SinOsc.ar(freq, 1pi); //+ Saw.ar(freq); | |
x = EnvGen.kr(Env.adsr(0.001,0.3, 0.5,0.1 ,0.6,-3,0),gate,doneAction: 2) * x; | |
x = x * amp; | |
Out.ar(0, Pan2.ar(x,pan)); | |
}).add; | |
//run this first | |
SynthDef("PMCrotale", { | freq=440, tone=3, art=1, amp=0.8, pan=0 | | |
var env, out, mod; | |
env = Env.perc(0, art); | |
mod = 5 + (1/IRand(2, 6)); | |
out = PMOsc.ar(freq, mod*freq, | |
pmindex: EnvGen.kr(env, timeScale: art, levelScale: tone), | |
mul: EnvGen.kr(env, timeScale: art, levelScale: 0.3)); | |
out = Pan2.ar(out, pan); | |
out = out * EnvGen.kr(env, timeScale: 1.3*art, | |
levelScale: Rand(0.1, 0.5), doneAction:2); | |
out = out * amp; | |
Out.ar(0, out); //Out.ar(bus, out);0 | |
}).add; | |
/* >> | |
SynthDef("PMCrotaleLargas", { | freq=440, tone=3, art=2, amp=0.8, pan=0 | | |
var out; | |
out = Synth("PMCrotale", [\freq, freq, \tone, tone, \art, art, \pan, pan]); | |
Out.ar(0, out * amp); | |
}).add; | |
*/ | |
~keys = Array.newClear(128); | |
if(z != nil, { | |
z.synthdef = "PMCrotale"; | |
// z.synthdef = "PMCrotaleLargas"; | |
z.synthdef = "umbSinewave"; | |
z.synthdef = "umbSinewaveEnvCareeta"; | |
z.synthdef = "blipRedondo"; | |
z.synthdef = "blipRedondo2"; | |
z.synthdef = "blip"; | |
z.synthdef = "otro"; | |
},{ | |
z = (); | |
z.synthdef = "otro"; | |
}); | |
~volume = 1; | |
~pitch = 0; | |
~noteOn.free; | |
~noteOff.free; | |
~srcId = MIDIClient.sources.detect({ |e| e.device.containsi("microKEY2-25") }).uid; | |
~noteOnFunc = {|vel, num, chan, src| | |
var node; | |
node = ~keys.at(num); | |
if (node.notNil, { | |
node.release; | |
~keys.put(num, nil); | |
}); | |
node = Synth(z.synthdef, [ | |
\freq, num.midicps + ~pitch, | |
\amp, vel/127*2 * ~volume, | |
]); | |
~keys.put(num, node); | |
[chan,num,vel/127].postln; | |
}; | |
~noteOn = MIDIFunc.noteOn(~noteOnFunc, srcID: ~srcId); | |
~noteOffFunc = {|vel, num, chan, src| | |
var node; | |
node = ~keys.at(num); | |
if (node.notNil, { | |
node.release; | |
~keys.put(num, nil); | |
}); | |
}; | |
~noteOff = MIDIFunc.noteOff(~noteOffFunc, srcID: ~srcId); | |
// paz en luyaba es real | |
~controlOn.free; | |
~controlOn = MIDIFunc.cc({|val, num| | |
// num 1 arriba, num 2 abajo | |
if(num==2,{ | |
// para aabajo | |
~volume = 1 - (val / 127); | |
~keys.do({|node| | |
if(node != nil, { | |
node.set(\amp, ~volume); | |
}); | |
}); | |
}, { | |
// para arriba | |
~keys.do({|node, i| | |
if(node != nil, { | |
var freq = i.midicps; | |
}); | |
}); | |
}) | |
}, srcID: ~srcId); | |
~bendOn.free; | |
~bendOn = MIDIFunc.bend({|val, num| | |
var midivalxD = (val - 8192) / 64; | |
if(midivalxD.isNegative, { | |
~pitch = midivalxD.abs.midicps * -1; | |
}, { | |
~pitch = midivalxD.midicps; | |
}); | |
~pitch = ~pitch / 400; | |
~keys.do({|node, i| | |
if(node != nil, { | |
var freq = i.midicps; | |
[midivalxD, ~pitch].postln; | |
node.set(\freq, freq + ~pitch); | |
}); | |
}); | |
}, srcID: ~srcId); | |
~clitorisSynths = ["otro", "umbSinewave", "blipRedondo"]; | |
~clitorisSelected = 0; | |
// el boton del clitoris | |
MIDIFunc.cc({|val, num| | |
if(val == 127, { | |
~clitorisSelected = ~clitorisSelected + 1; | |
z.synthdef = ~clitorisSynths.wrapAt(~clitorisSelected); | |
}); | |
}, 67, 0); | |
//FIN | |
) | |
// cleanup | |
( | |
~noteOn.free; | |
~noteOff.free; | |
~controlOn.free; | |
) | |
MIDIFunc.trace(false); | |
MIDIClient.sources.detect({ |e| e.device.containsi("microKEY2-25") }).uid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding the PPA
The PPA contains a working version of SuperCollider, unlike the default package source. Add the PPA by entering these lines into a terminal:
Further information about the PPA can be found here.
Installing SuperCollider
Enter these lines into a terminal:
When you are presented with a screen asking you if you would like to enable realtime access priority, choose 'Yes'.
Checking the installation worked
First, open the SuperCollider IDE by searching for and running 'SuperCollider IDE'. The IDE should open and give you three main panes:
Secondly, boot the server using the command in the Language menu, or Ctrl+B.
Thirdly, enter the following into the blank text window:
Ensure the cursor is on this line and hit Ctrl+Enter. You should now hear a sine tone. Kill the sine tone by hitting Ctrl+..
If you don't hear the tone, remember to check your speakers, volume control – all the regular suspects!
Source Installing SuperCollider on Ubuntu systems.