Compare commits
3 Commits
b79b8f9dad
...
163ca09a8a
Author | SHA1 | Date |
---|---|---|
Jurij Podgoršek | 163ca09a8a | |
Jurij Podgoršek | b4645bf161 | |
Jurij Podgoršek | 6c4f3fb032 |
|
@ -0,0 +1,5 @@
|
|||
.~*~
|
||||
.*~undo-tree~
|
||||
.~lock*#
|
||||
.*.swp
|
||||
node_modules
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,106 @@
|
|||
const WebSocket = require('ws')
|
||||
const osc = require('osc')
|
||||
|
||||
const ip = process.argv[2]
|
||||
|
||||
const DEBUG = {
|
||||
midi: true,
|
||||
osc: false
|
||||
}
|
||||
|
||||
//const ws = new WebSocket(`ws://${ip}:6676`)
|
||||
|
||||
/*
|
||||
const wsp = new osc.WebsocketClientPlugin({
|
||||
host: ip,
|
||||
port: 6676
|
||||
})
|
||||
*/
|
||||
const oscWS = new osc.WebSocketPort({
|
||||
url: `ws://${ip}:6676`,
|
||||
metadata: false
|
||||
})
|
||||
|
||||
oscWS.on('ready', () => {
|
||||
console.log(`Povezan sem na ${ip}`)
|
||||
|
||||
/*
|
||||
setInterval(() => {
|
||||
console.log('ping')
|
||||
oscWS.send({ address: '/ping', args: [true]})
|
||||
}, 500)
|
||||
*/
|
||||
})
|
||||
|
||||
let midiOn = false
|
||||
|
||||
const zaznava = 0.5
|
||||
|
||||
let cakaj = false
|
||||
const cakajInterval = 1 / 5
|
||||
const razponTona = [0.1, 0.5]
|
||||
//const razponTona = [0.001, 0.002]
|
||||
|
||||
let rotVisina = 0
|
||||
|
||||
oscWS.on('message', ({ address, args }) => {
|
||||
DEBUG.osc && console.log('MSG OSC', address, args.map(x => x.toFixed(4)))
|
||||
if (address == '/euler') {
|
||||
//const eVisina = Math.sin(args[0] + args[1])
|
||||
const eVisina = Math.sin(args[2])
|
||||
rotVisina = 24 + Math.round(((eVisina / 2) + 0.5) * 24)
|
||||
//console.log("rotVisina", rotVisina)
|
||||
}
|
||||
|
||||
if (address == '/accel') {
|
||||
const acX = args[0]
|
||||
const acY = args[1]
|
||||
const acZ = args[2]
|
||||
const vsota = acX + acY + acZ
|
||||
|
||||
if (cakaj) {
|
||||
//console.log("CAKAM!")
|
||||
return
|
||||
}
|
||||
|
||||
if (acX > zaznava && !cakaj) {
|
||||
|
||||
cakaj = true
|
||||
|
||||
// Pavza
|
||||
setTimeout(() => {
|
||||
//console.log("nehaj cakat")
|
||||
cakaj = false
|
||||
}, cakajInterval * 1000)
|
||||
|
||||
|
||||
// Od 24 do 48
|
||||
const accval = Math.sin((acX - zaznava) / 3)
|
||||
// Acc visina
|
||||
const visina = 24 + Math.round(((accval / 2.5) + 0.5) * 48)
|
||||
//const visina = rotVisina
|
||||
|
||||
//console.log('posiljam midi', [144, visina, 127])
|
||||
oscWS.send({
|
||||
address: '/midi',
|
||||
args: [144, visina, 127]
|
||||
})
|
||||
console.log('vklopi', visina)
|
||||
|
||||
midiOn = true
|
||||
|
||||
// Ugasni cez en cas
|
||||
let izklop = razponTona[0] + Math.random() * (razponTona[1] - razponTona[0])
|
||||
setTimeout(() => {
|
||||
oscWS.send({
|
||||
address: '/midi',
|
||||
args: [128, visina, 127]
|
||||
})
|
||||
console.log('izklopi', visina)
|
||||
}, izklop * 1000)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
oscWS.open()
|
|
@ -0,0 +1,82 @@
|
|||
// Zacetek / konec
|
||||
|
||||
s.boot;
|
||||
s.stop;
|
||||
|
||||
// Server -> Boot /// Ctrl+B
|
||||
|
||||
// HELP: shift+ctrl+D
|
||||
// recimo ugen
|
||||
|
||||
NetAddr.langPort;
|
||||
|
||||
|
||||
(
|
||||
|
||||
SynthDef.new(\slOSC, {
|
||||
// Najprej argumenti, potem variable
|
||||
arg f=220, ampOsc=200, ch=0, off=0;
|
||||
var so;
|
||||
so = SinOsc.ar(f, off, SinOsc.kr(ampOsc));
|
||||
Out.ar(ch, so);
|
||||
}).add;
|
||||
|
||||
//s = Synth.new(\slOSC);
|
||||
z = Synth.new(\slOSC);
|
||||
//v = Synth.new(\slOSC);
|
||||
u = Synth.new(\slOSC);
|
||||
|
||||
OSCFunc({
|
||||
arg msg, time, addr, recvPort;
|
||||
[msg, time, addr, recvPort].postln;
|
||||
~gdX = msg[1];
|
||||
~gdY = msg[2];
|
||||
~gdZ = msg[3];
|
||||
}, '/eulerDiff', n);
|
||||
|
||||
OSCFunc({
|
||||
arg msg, time, addr, recvPort;
|
||||
[msg, time, addr, recvPort].postln;
|
||||
~gX = msg[1];
|
||||
~gY = msg[2];
|
||||
~gZ = msg[3];
|
||||
}, '/euler', n);
|
||||
|
||||
OSCFunc({
|
||||
arg msg, time, addr, recvPort;
|
||||
[msg, time, addr, recvPort].postln;
|
||||
~aX = msg[1];
|
||||
~aY = msg[2];
|
||||
~aZ = msg[3];
|
||||
}, '/accel', n);
|
||||
|
||||
OSCFunc({
|
||||
arg msg, time, addr, recvPort;
|
||||
//msg.postln;
|
||||
}, '/euler', n);
|
||||
|
||||
~polje = [];
|
||||
|
||||
OSCFunc({
|
||||
arg msg, time, addr, recvPort;
|
||||
//[msg, time, addr, recvPort].postln;
|
||||
|
||||
//s.get(\f, {arg f; s.set(\f, f + ~gX)});
|
||||
//s.get(\f, {arg f; s.set(\f, f - (~aX / 100))});
|
||||
z.get(\f, {arg f; s.set(\f, f + (~aY * 100))});
|
||||
u.get(\f, {arg f; s.set(\f, f + (~aX / 10))});
|
||||
|
||||
//s.get(\f, {arg f; ~polje.add(f); s.set(\f, f + (~gdX * 100))});
|
||||
//v.get(\f, {arg f; ~polje.add(f); s.set(\f, f + (~gdZ * 100))});
|
||||
|
||||
//z.get(\f, {arg f; s.set(\f, ~aY/ 10)});
|
||||
|
||||
//s.get(\ampOsc, {arg f; s.set(\ampOsc, f + (~gX))});
|
||||
}, '/keys', n);
|
||||
)
|
||||
|
||||
~polje;
|
||||
|
||||
[1, 5, 8, 7, 2, 19].plot;
|
||||
|
||||
[].add(123);
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
# Risanje grafa
|
||||
import matplotlib
|
||||
matplotlib.use('GTK4Agg')
|
||||
import matplotlib.pyplot as plt
|
||||
import pandas as pd
|
||||
import plotly_express as px
|
||||
|
||||
plt.style.use('ggplot')
|
||||
#x, ax, ay, az = []
|
||||
x = []
|
||||
ax = []
|
||||
ay = []
|
||||
az = []
|
||||
|
||||
ga = pd.read_csv('graf_a.csv')
|
||||
|
||||
fig = px.line(ga, x="t", y=ga.columns[1:2])
|
||||
fig.show()
|
||||
|
||||
gg = pd.read_csv('graf_g.csv')
|
||||
|
||||
fig = px.line(gg, x="t", y=gg.columns[1:4])
|
||||
fig.show()
|
||||
fig = px.line(gg, x="t", y=gg.columns[4:5])
|
||||
fig.show()
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
# OSC komunikacija
|
||||
from pythonosc.osc_server import BlockingOSCUDPServer
|
||||
from pythonosc.dispatcher import Dispatcher
|
||||
from time import time
|
||||
from threading import Thread
|
||||
|
||||
# Risanje grafa
|
||||
import matplotlib
|
||||
matplotlib.use('GTK4Agg')
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.animation import FuncAnimation
|
||||
|
||||
dispecer = Dispatcher()
|
||||
|
||||
srv = BlockingOSCUDPServer(("127.0.0.1", 57120), dispecer)
|
||||
|
||||
# Zacetna (casovna) tocka
|
||||
zacetek = time()
|
||||
|
||||
# use ggplot style for more sophisticated visuals
|
||||
plt.style.use('ggplot')
|
||||
|
||||
|
||||
size = 1000
|
||||
x_vec = []
|
||||
gx_vec = []
|
||||
gy_vec = []
|
||||
gz_vec = []
|
||||
ax_vec = []
|
||||
ay_vec = []
|
||||
az_vec = []
|
||||
|
||||
x = 0
|
||||
gx = 0
|
||||
gy = 0
|
||||
gz = 0
|
||||
ax = 0
|
||||
ay = 0
|
||||
az = 0
|
||||
|
||||
interval = 60 / 1000
|
||||
razlika = 0
|
||||
|
||||
# Shranim "trenutne" vrednosti
|
||||
def beriSenzor(address, *args):
|
||||
global x, gx, gy, gz, ax, ay, az, razlika
|
||||
|
||||
if (address == '/accel'):
|
||||
ax, ay, az = args
|
||||
|
||||
if (address == '/euler'):
|
||||
gx, gy, gz = args
|
||||
print("euler", args)
|
||||
|
||||
razlika = time() - zacetek
|
||||
if (razlika > interval):
|
||||
izrisi()
|
||||
razlika = razlika % interval
|
||||
|
||||
fig = plt.gcf()
|
||||
#gxs = fig.add_subplot()
|
||||
#gys = fig.add_subplot()
|
||||
|
||||
#gxp, = gxs.plot([])
|
||||
#gyp, = gys.plot([])
|
||||
|
||||
fajl_g = open("graf_g.csv", "w")
|
||||
fajl_g.write("t,gx,gy,gz,rgx,rgy,rgz\n")
|
||||
fajl_a = open("graf_a.csv", "w")
|
||||
fajl_a.write("t,ax,ay,az\n")
|
||||
def izrisi():
|
||||
global x, gx, gy, gz, ax, ay, az, fig, plt, gxp, gyp, zacetek
|
||||
|
||||
# Dodamo casovno tocko
|
||||
x = time() - zacetek
|
||||
#x_vec.append(x)
|
||||
|
||||
fajl_g.write(str(x) + "," + str(gx) + "," + str(gy) + "," + str(gz) + "," + str(gx % 3.14) + "," + str(gy % 3.14) + "," + str(gz % 3.14) + "\n")
|
||||
|
||||
fajl_a.write(str(x) + "," + str(ax) + "," + str(ay) + "," + str(az) + "\n")
|
||||
|
||||
|
||||
|
||||
# Dodamo gyro in accel vrednosti v polja
|
||||
#gx_vec.append(gx)
|
||||
#gy_vec.append(gy)
|
||||
#gz_vec.append(gz)
|
||||
#ax_vec.append(ax)
|
||||
#ay_vec.append(ay)
|
||||
#az_vec.append(az)
|
||||
|
||||
#plt.cla()
|
||||
#yplot.plot(x_vec, gx_vec)
|
||||
#yplot.plot(x_vec, gy_vec)
|
||||
#fig.set_xdata(x_vec)
|
||||
|
||||
#gxp.set_data(x_vec, gx_vec)
|
||||
#gyp.set_data(x_vec, gy_vec)
|
||||
#print("RISEMO", x, gx)
|
||||
#plt.plot(x_vec, gx_vec, label="gyro x")
|
||||
#plt.plot(x_vec, gy_vec)
|
||||
#plt.plot(x_vec, gz_vec)
|
||||
#plt.plot(x_vec, ax_vec)
|
||||
#plt.plot(x_vec, ay_vec)
|
||||
#plt.plot(x_vec, az_vec)
|
||||
|
||||
#plt.pause(0.0001)
|
||||
#fig.canvas.draw()
|
||||
#plt.show()
|
||||
#plt.pause(0.0001)
|
||||
#return gxp,
|
||||
|
||||
#plt.gcf().autofmt_xdate()
|
||||
#plt.tight_layout()
|
||||
#plt.pause(0.001)
|
||||
|
||||
#plt.gcf()
|
||||
#plt.pause(1)
|
||||
#return plt
|
||||
#plt.show()
|
||||
#return plt
|
||||
|
||||
# Animiraj na cca 60hz
|
||||
#animacija = FuncAnimation(fig, izrisi, 500)
|
||||
#animacija = FuncAnimation(plt.gcf(), izrisi, interval=0.05, repeat=True)
|
||||
#print(animacija)
|
||||
#animacija = FuncAnimation(fig, izrisi)
|
||||
|
||||
#plt.show()
|
||||
|
||||
dispecer.map("/*", beriSenzor)
|
||||
# Zacni poslusat senzor
|
||||
print("serving...")
|
||||
srv.serve_forever()
|
||||
#trd = Thread(target=srv.serve_forever).start()
|
||||
|
||||
# Kazi graf
|
||||
#print("Kazi graf!")
|
||||
#plt.tight_layout()
|
||||
#plt.show()
|
||||
#plt.plot([0, 0], [1, 5], [3, 7])
|
||||
#print('kazem', plt)
|
||||
|
||||
# AJD!
|
||||
file.close()
|
||||
print("bye")
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "kegel",
|
||||
"version": "0.1.0",
|
||||
"description": "kiberkegel",
|
||||
"dependencies": {
|
||||
"nodemon": "^2.0.16",
|
||||
"osc": "^2.4.2",
|
||||
"ws": "^7.3.1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "npx nodemon kegel.js"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
python-osc ~= 1.8.0
|
||||
plotly-express ~= 0.4.1
|
|
@ -0,0 +1,8 @@
|
|||
{SinOsc.ar(1)}.plot(1);
|
||||
|
||||
{VarSaw.ar(20)}.plot(1);
|
||||
{VarSaw.ar(1, 0.25)}.plot(1);
|
||||
|
||||
{VarSaw.ar(1, 0.25, 1)}.plot(1);
|
||||
|
||||
{VarSaw.ar(50!2, 0.9, 1) * 0.1}.play;
|
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib import patheffects
|
||||
|
||||
# Plot a straight diagonal line with ticked style path
|
||||
fig, ax = plt.subplots(figsize=(6, 6))
|
||||
ax.plot([0, 1], [0, 1], label="Line",
|
||||
path_effects=[patheffects.withTickedStroke(spacing=7, angle=135)])
|
||||
|
||||
# Plot a curved line with ticked style path
|
||||
nx = 101
|
||||
x = np.linspace(0.0, 1.0, nx)
|
||||
y = 0.3*np.sin(x*8) + 0.4
|
||||
ax.plot(x, y, label="Curve", path_effects=[patheffects.withTickedStroke()])
|
||||
|
||||
ax.legend()
|
||||
|
||||
plt.show()
|
||||
|
||||
print("PLOT!")
|
||||
print(plt)
|
Loading…
Reference in New Issue