Open zeffii opened 8 years ago
eventually there's going to be an elegant way to add paths and define functions to be called when the paths pass new values.. but for now a reference to a bpy.data.text['OSC_COMMANDS'] file would be OK to get us started.
Imagine one might write a class to accept individual messages
some scraps (Send)
+class FileOverOsc(sublime_plugin.TextCommand):
+ def run(self, edit):
+ view = self.view
+ file_name = view.file_name()
+ print(file_name)
+
+ client = udp_client.UDPClient("127.0.0.1", 6449)
+
+ msg = osc_message_builder.OscMessageBuilder(address="/filepath")
+ msg.add_arg(file_name)
+ msg = msg.build()
+ client.send(msg)
receive:
# routine to execute when `/filepath` is received, fp in this case is the string being sent
# as filepath.
def filepath_handler(uh, fp):
temp_path = osc_statemachine['tempfile']
with open('/home/zeffii/Desktop/OSC/fp.io', 'w') as f:
print('received: ', fp)
f.write(fp)
# commence OSC receiver
def start_server_comms():
ip = "127.0.0.1"
port = 6449
parser = argparse.ArgumentParser()
parser.add_argument("--ip", default=ip, help="The ip to listen on")
parser.add_argument("--port", type=int, default=port, help="The port to listen on")
args = parser.parse_args()
disp = dispatcher.Dispatcher()
disp.map("/filepath", filepath_handler)
osc_statemachine['dispatcher'] = disp
osc_statemachine['args'] = args
try:
server = osc_server.ForkingOSCUDPServer((args.ip, args.port), disp)
osc_statemachine['server'] = server
except:
print('already active')
server = osc_statemachine['server']
server_thread = threading.Thread(target=server.serve_forever)
server_thread.start()
print("Serving on {}".format(server.server_address))
https://github.com/zeffii/bpy_externall/blob/e8aecfb5fc655d0d2e68441978180ba70b8fcecd/__init__.py
test values sending from Supercollider
(
b = NetAddr.new("127.0.0.1", 7771);
t = Task({
loop {
var a, c;
a = Pcauchy(0.0, 1.0, inf);
c = a.asStream.nextN(1);
b.sendMsg("/hello", c[0]);
0.2.wait;
c[0].postln;
}
}).play;
)
t.stop;
seems like I might have to take a different approach, because i'm using this on windows... and..
File "C:\blender-2.7\2.77\python\lib\socketserver.py", line 591, in process_request
pid = os.fork()
AttributeError: module 'os' has no attribute 'fork'
or.. use something other than server = osc_server.ForkingOSCUDPServer
:)
spitting increments the stupid way?
(
b = NetAddr.new("127.0.0.1", 7771);
t = Task({
var total_points = 40;
var theta = 2pi / total_points;
var points = Array.fill(total_points, { arg i; (i * theta)});
var pindex = 0;
loop {
var a, c;
a = Pcauchy(0.0, 1.0, inf);
c = a.asStream.nextN(1);
b.sendMsg("/random_integer", c[0]);
b.sendMsg("/circle", points[pindex].cos);
points[pindex].postln;
pindex = pindex + 1;
if (pindex == total_points) { pindex = 0; };
0.2.wait;
}
}).play;
)
t.stop;
then in bpy.data.texts have a block called 'do_circle' with the following content
bpy.data.objects['Cube'].location.x = value
Is "Tahiti" the latest good good for now?
yes (i think so), i could push Tahiti to master if it's working as expected.
@zeffii Hi Zeffii, is it possible to have this OSC thing to work with Blender 2.80 or via SV as nodes?
sure. read up about the changes needed for 2.80, try it yourself.
First some thoughts about what is needed from such a panel and how to implement it conveniently for generic use. Best define this before writing any code ( all existing code in this repo was written prior to starting the repo)
First the UI needs properties
Essentially the panel will be a UI for a modal operator which will repeatedly checks the OSC message queue every
<interval>
seconds.