public
Last active

avsys final source code

  • Download Gist
avsys.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
require 'osc-ruby'
include OSC
 
client = OSC::Client.new( 'localhost', 12000 )
synthid = 2
 
graphs = []
colors = [:red, :blue, :green, :white, :red]
ard = Arduino.new
 
setup do
until ard.initialized?
ard.update
end
 
ard.setup_analog :all_analog
3.times { graphs << [] }
alpha_blending true
framerate 60
smoothing true
background :white
circle_resolution 64
size 1280, 720
end
 
update do
ard.update
end
 
offset = [2.25, 2.2, 1.5]
notes = [523.25, 622.25 , 783.99]
pos = [[200, 200], [980, 100], [640, 400]]
tim = 0
step = 0.005
 
draw do
tim += step
for i in 0..2
graph = graphs[i]
if graph.empty?
graph << 0
else
graph << ((graph.last..ard.analog(i)*3) * 0.05 - offset[i])
end
color :black
# text graph.last
if graph.last > 10 and graph.size > 3 and graph[-1] < graph[-2] and graph[-2] >= graph[-3]
tone notes[i], 0.5, graph[-2] * 10
step += 0.005
end
# tone graph.last * 5, 0.5, noise(i, graph[-2]) * 100
if step > 0.005
step *= 0.99
end
while graph.size > width
graph.shift
end
# color colors[i]
# text "#{i} : #{graphs[i].last.to_i}"
# graph.every 2 do |a, b, x|
# line x, height - a, x+1, height - b
# end
end
for i in 0..2
unless graphs[i].size < 50
graphs[i][-50..-1].every do |r, j|
t = 1-j/50.0
# fill false
c = j.even? ? :black : :white
color c, 255# * (1-t)
x0, y0 = pos[i]
x, y = x0 + signed_noise(tim, j * 0.05,i) * 25, y0 + signed_noise(tim, j*0.05+1,i) * 25
circle x, y, (0.5) * (width/2 - r) * t**2
end
end
end
# text graph.max, 1, height - graph.max - 10
# text ard.sensor, width - 30, 10
# horizontal height - graph.max
# horizontal height - graph.max/2
#
# color :green
# text last_peak, 100, height - last_peak - 10
# horizontal height - last_peak
# if not played_note and graph.size > 3 and graph[-1] < graph[-2] and graph[-2] <= graph[-3]
# # peak detected
# if graph[-2] > 50
# last_peak = graph[-2]
# played_note = true
# synthid += 1
# client.send( Message.new( "/s_new", "env-sine", synthid, 1, 0,
# "freq", graph[-2] < 250 ? 800 : 4000 ))
# end
#
# end
#
# if ard.sensor < 50
# played_note = false
# end
color :black
# text step
end
 
exit do
ard.disconnect
end
 
def tone freq=880, amp=0.125, detune=0
synthid += 1
# client.send( Message.new( "/n_set", 2,
# "freq", freq,
# "amp", amp,
# "detune", detune ))
client.send( Message.new( "/s_new", "env-sine", synthid, 1, 0,
"freq", freq,
"amp", amp,
"detune", detune ))
end
 
# s = Server("myServer", NetAddr("127.0.0.1", 12000));
# s.boot;
# s.dumpOSC(1);
#
# (
# SynthDef("env-sine", { arg freq = 880, amp=0.125, detune=0;
# var env, x;
# env = EnvGen.kr(Env.perc(0.005,3,1,-4), doneAction: 2);
# x = env * SinOsc.ar([freq, freq+detune],0, amp);
# Out.ar(0, x)
# }).send(s)
# );
#
# (
# SynthDef("sinewave", {
# arg freq = 880, amp=0.125, detune=0;
# x = SinOsc.ar([freq,freq+detune],0, amp);
# Out.ar(0, x)
# }).send(s));
#
# (
# s.sendMsg("/s_new", "sinewave", x = 2, 1, 1, "freq", 800);
# )
#
# (
# s.sendMsg("/n_set", x, "freq", 700);
# )

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.