Last active
December 14, 2015 11:19
-
-
Save ohAitch/5078344 to your computer and use it in GitHub Desktop.
Backend for the iOS app "Musix"
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
//Copyright 2013 ohAitch | |
//Released under GPL 3+, see http://www.gnu.org/licenses/gpl.html | |
n = NetAddr("127.0.0.1", 57120); // 57120 is sclang default port | |
~amp.free; | |
SynthDef(\looperAmpControl, | |
{ arg volumeAmp = 1, volumeLag = 0.1, volumeGate=1; | |
XOut.ar(0, | |
Linen.kr(volumeGate, releaseTime: 0.05, doneAction:2), | |
In.ar(0, Server.default.options.numOutputBusChannels) * Lag.kr(volumeAmp, volumeLag) ); | |
}).send; | |
~amp = Synth.new(\looperAmpControl, [\volumeAmp, 10], addAction: \addAfter); | |
SynthDef(\jangles, | |
{|freq=440, trig=1, gate = 1| | |
Out.ar(0, Pluck.ar(BPF.ar(WhiteNoise.ar(0.2), freq*2, 0.1), trig, 10.reciprocal, freq.reciprocal, 20, coef:0.1) * Linen.kr(gate, 0.01, 0.7, 0.3, 2)) | |
}).send; | |
SynthDef( "metro", {|freq=1| Out.ar([0,1], Ringz.ar(Impulse.ar(freq*2) + Impulse.ar(freq/2), 4*44.midicps, 0.2, mul:0.03))}).send; | |
//t = TempoClock(queueSize: 2048); | |
~delays=Pseq([16], inf); | |
~sdict = Dictionary.new; | |
~mdict = Dictionary.new; | |
~response ={|type| {|msg, time, addr, port| | |
var normal = { | |
var spawn = { | |
var key = [msg[1], msg[5]];//Note and column //(2 * msg[5]) + (msg[4] % 2); | |
var synth = ~sdict[key]; //msg.postln; key.postln; ~sdict.post; ~mdict.postln; | |
type.switch( | |
\on, {~mdict[key] = msg; | |
if(synth.isPlaying) {synth.release(0.2)}; | |
~sdict[key] = Synth("jangles", [\freq, msg[1].midicps]).register}, | |
\moved,{}, // {synth.set(\freq, msg[1].midicps * (1 + ((msg[3] - ~mdict[key][3]) / 20)))}, | |
\off, {synth.release(0.4)}).value}; | |
m.isPlaying.if({ | |
var rot = ~delays.asStream; | |
t.sched(0, {spawn.(); rot.next})}, | |
spawn)}; | |
msg[1].switch( | |
44, {(type == \on).if {m.isPlaying.if({m.free}, | |
{m = Synth("metro", [\freq, t.tempo]).register})}}, | |
32, {t.clear}, | |
normal)}}; | |
OSCdef('NoteOn', ~response.(\on), "/Musix/note/on"); | |
//OSCdef('NoteMoved', ~response.(\moved), "/Musix/note/Moved"); | |
OSCdef('NoteOff', ~response.(\off), "/Musix/note/Off"); | |
t.sched(0, {n.sendMsg("/Musix/note/on", 80, 0, 0.3, 0, 0)}); | |
t.sched(0.5, {n.sendMsg("/Musix/note/Off", 80, 0, 0, 0, 0)}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment