Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
avsys final source code
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);
# )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.