From edd67ebb9c90484b8451b2dbe3e28a633e571b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20S=C3=A1nchez=20Medina?= Date: Fri, 11 Jun 2021 16:47:43 -0500 Subject: [PATCH 1/4] Prevent SocketError if address is remote --- FoxDot/lib/ServerManager.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/FoxDot/lib/ServerManager.py b/FoxDot/lib/ServerManager.py index eca0411f..f2171567 100644 --- a/FoxDot/lib/ServerManager.py +++ b/FoxDot/lib/ServerManager.py @@ -213,7 +213,12 @@ def reset(self): # OSC Connection for custom OSCFunc in SuperCollider if GET_SC_INFO: - self.sclang = BidirectionalOSCServer() + # Prevent SocketError when connecting to a remote FoxDot instance + server_address=('0.0.0.0', 0) + if (self.addr == 'localhost' or self.addr == '127.0.0.1'): + server_address=('localhost', 0) + + self.sclang = BidirectionalOSCServer(server_address=server_address) self.sclang.connect( (self.addr, self.SCLang_port) ) self.loadSynthDef(FOXDOT_INFO_FILE) try: From 55601ff10fe1a6ce65c3d083d055e71cd98789a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20S=C3=A1nchez=20Medina?= Date: Sat, 12 Jun 2021 09:49:23 -0500 Subject: [PATCH 2/4] Fix sample path for remote Supercollider --- FoxDot/lib/ServerManager.py | 16 ++++++++++++---- FoxDot/lib/Settings/__init__.py | 13 +++++++++++++ FoxDot/osc/{Info.scd => Info.scd.template} | 1 + 3 files changed, 26 insertions(+), 4 deletions(-) rename FoxDot/osc/{Info.scd => Info.scd.template} (96%) diff --git a/FoxDot/lib/ServerManager.py b/FoxDot/lib/ServerManager.py index f2171567..606ae5de 100644 --- a/FoxDot/lib/ServerManager.py +++ b/FoxDot/lib/ServerManager.py @@ -33,7 +33,7 @@ ('sample_rate', 'actual_sample_rate', 'num_synths', 'num_groups', 'num_audio_bus_channels', 'num_control_bus_channels', 'num_input_bus_channels', 'num_output_bus_channels', 'num_buffers', - 'max_nodes', 'max_synth_defs')) + 'max_nodes', 'max_synth_defs', 'foxdot_snd')) class OSCClientWrapper(OSCClient): @@ -178,11 +178,13 @@ class SCLangServerManager(ServerManager): fxlist = None synthdefs = None - def __init__(self, addr, osc_port, sclang_port): + def __init__(self, addr, osc_port, sclang_port, foxdot_snd): self.addr = addr self.port = osc_port self.SCLang_port = sclang_port + self.foxdot_snd = foxdot_snd + self.foxdot_snd_remote = "" self.midi_nudge = 0 @@ -232,6 +234,7 @@ def reset(self): self.num_output_busses = info.num_output_bus_channels self.max_busses = info.num_audio_bus_channels self.bus = self.num_input_busses + self.num_output_busses + self.foxdot_snd_remote = info.foxdot_snd else: self.sclang = OSCClientWrapper() self.sclang.connect( (self.addr, self.SCLang_port)) @@ -613,6 +616,11 @@ def free_node(self, node): def bufferRead(self, path, bufnum): """ Sends a message to SuperCollider to read an audio file into a buffer """ + + # Update path for proper file load in the remote Supercollider + if (not(self.addr == 'localhost' or self.addr == '127.0.0.1')): + path = path.replace(self.foxdot_snd, self.foxdot_snd_remote) + message = OSCMessage("/b_allocRead") message.append([bufnum, path]) self.client.send( message ) @@ -1102,10 +1110,10 @@ def kill(self): if __name__ != "__main__": - from .Settings import ADDRESS, PORT, PORT2, FORWARD_PORT, FORWARD_ADDRESS + from .Settings import ADDRESS, PORT, PORT2, FORWARD_PORT, FORWARD_ADDRESS, FOXDOT_SND # DefaultServer = SCLangServerManager(ADDRESS, PORT, PORT2) - Server = SCLangServerManager(ADDRESS, PORT, PORT2) + Server = SCLangServerManager(ADDRESS, PORT, PORT2, FOXDOT_SND) if FORWARD_PORT and FORWARD_ADDRESS: Server.add_forward(FORWARD_ADDRESS, FORWARD_PORT) diff --git a/FoxDot/lib/Settings/__init__.py b/FoxDot/lib/Settings/__init__.py index 19ceff96..c1b6516c 100644 --- a/FoxDot/lib/Settings/__init__.py +++ b/FoxDot/lib/Settings/__init__.py @@ -122,6 +122,19 @@ def GET_TUTORIAL_FILES(): FOXDOT_SND = os.path.realpath(conf.SAMPLES_DIR) +# Recreate info file from template +if os.path.isfile(FOXDOT_INFO_FILE): + os.remove(FOXDOT_INFO_FILE) + +try: + with open(FOXDOT_INFO_FILE+".template", "r") as fread: + content = fread.read() + content = content.replace("", f"'{FOXDOT_SND}'") + with open(FOXDOT_INFO_FILE, "w") as f: + f.write(content) +except FileNotFoundError: + pass + def get_timestamp(): import time return time.strftime("%Y%m%d-%H%M%S") diff --git a/FoxDot/osc/Info.scd b/FoxDot/osc/Info.scd.template similarity index 96% rename from FoxDot/osc/Info.scd rename to FoxDot/osc/Info.scd.template index 6d2abbaa..11878b0d 100644 --- a/FoxDot/osc/Info.scd +++ b/FoxDot/osc/Info.scd.template @@ -13,6 +13,7 @@ OSCFunc( Server.default.options.numBuffers, Server.default.options.maxNodes, Server.default.options.maxSynthDefs, + , ); }, '/foxdot/info' ); From b5258bb4ace19e59eda4172a12d8f7e4363de4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20S=C3=A1nchez=20Medina?= Date: Sat, 12 Jun 2021 11:31:09 -0500 Subject: [PATCH 3/4] Fix synthdef path for remote Supercollider --- FoxDot/lib/ServerManager.py | 16 ++++++++++++---- FoxDot/lib/Settings/__init__.py | 1 + FoxDot/osc/Info.scd.template | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/FoxDot/lib/ServerManager.py b/FoxDot/lib/ServerManager.py index 606ae5de..a2955830 100644 --- a/FoxDot/lib/ServerManager.py +++ b/FoxDot/lib/ServerManager.py @@ -33,7 +33,7 @@ ('sample_rate', 'actual_sample_rate', 'num_synths', 'num_groups', 'num_audio_bus_channels', 'num_control_bus_channels', 'num_input_bus_channels', 'num_output_bus_channels', 'num_buffers', - 'max_nodes', 'max_synth_defs', 'foxdot_snd')) + 'max_nodes', 'max_synth_defs', 'foxdot_root', 'foxdot_snd')) class OSCClientWrapper(OSCClient): @@ -178,12 +178,14 @@ class SCLangServerManager(ServerManager): fxlist = None synthdefs = None - def __init__(self, addr, osc_port, sclang_port, foxdot_snd): + def __init__(self, addr, osc_port, sclang_port, foxdot_root, foxdot_snd): self.addr = addr self.port = osc_port self.SCLang_port = sclang_port + self.foxdot_root = foxdot_root self.foxdot_snd = foxdot_snd + self.foxdot_root_remote = "" self.foxdot_snd_remote = "" self.midi_nudge = 0 @@ -234,6 +236,7 @@ def reset(self): self.num_output_busses = info.num_output_bus_channels self.max_busses = info.num_audio_bus_channels self.bus = self.num_input_busses + self.num_output_busses + self.foxdot_root_remote = info.foxdot_root self.foxdot_snd_remote = info.foxdot_snd else: self.sclang = OSCClientWrapper() @@ -640,6 +643,11 @@ def sendMidi(self, msg, cmd=OSC_MIDI_ADDRESS): def loadSynthDef(self, fn, cmd='/foxdot'): """ Sends a message to the FoxDot class in SuperCollider to load a SynthDef from file """ + + # Update path for proper file load in the remote Supercollider + if (not(self.addr == 'localhost' or self.addr == '127.0.0.1')): + fn = fn.replace(self.foxdot_root, self.foxdot_root_remote) + msg = OSCMessage() msg.setAddress(cmd) msg.append(fn) @@ -1110,10 +1118,10 @@ def kill(self): if __name__ != "__main__": - from .Settings import ADDRESS, PORT, PORT2, FORWARD_PORT, FORWARD_ADDRESS, FOXDOT_SND + from .Settings import ADDRESS, PORT, PORT2, FORWARD_PORT, FORWARD_ADDRESS, FOXDOT_ROOT, FOXDOT_SND # DefaultServer = SCLangServerManager(ADDRESS, PORT, PORT2) - Server = SCLangServerManager(ADDRESS, PORT, PORT2, FOXDOT_SND) + Server = SCLangServerManager(ADDRESS, PORT, PORT2, FOXDOT_ROOT, FOXDOT_SND) if FORWARD_PORT and FORWARD_ADDRESS: Server.add_forward(FORWARD_ADDRESS, FORWARD_PORT) diff --git a/FoxDot/lib/Settings/__init__.py b/FoxDot/lib/Settings/__init__.py index c1b6516c..2c2ce0df 100644 --- a/FoxDot/lib/Settings/__init__.py +++ b/FoxDot/lib/Settings/__init__.py @@ -129,6 +129,7 @@ def GET_TUTORIAL_FILES(): try: with open(FOXDOT_INFO_FILE+".template", "r") as fread: content = fread.read() + content = content.replace("", f"'{FOXDOT_ROOT}'") content = content.replace("", f"'{FOXDOT_SND}'") with open(FOXDOT_INFO_FILE, "w") as f: f.write(content) diff --git a/FoxDot/osc/Info.scd.template b/FoxDot/osc/Info.scd.template index 11878b0d..faa214ba 100644 --- a/FoxDot/osc/Info.scd.template +++ b/FoxDot/osc/Info.scd.template @@ -13,6 +13,7 @@ OSCFunc( Server.default.options.numBuffers, Server.default.options.maxNodes, Server.default.options.maxSynthDefs, + , , ); }, '/foxdot/info' From ee48471578e2d02d40ae46752107825494da6865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20S=C3=A1nchez=20Medina?= Date: Thu, 24 Jun 2021 10:21:00 -0500 Subject: [PATCH 4/4] Delete info file only when template file exists --- FoxDot/lib/Settings/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/FoxDot/lib/Settings/__init__.py b/FoxDot/lib/Settings/__init__.py index 2c2ce0df..c4541933 100644 --- a/FoxDot/lib/Settings/__init__.py +++ b/FoxDot/lib/Settings/__init__.py @@ -123,11 +123,12 @@ def GET_TUTORIAL_FILES(): FOXDOT_SND = os.path.realpath(conf.SAMPLES_DIR) # Recreate info file from template -if os.path.isfile(FOXDOT_INFO_FILE): - os.remove(FOXDOT_INFO_FILE) - try: with open(FOXDOT_INFO_FILE+".template", "r") as fread: + # Delete info file only if template file exists + if os.path.isfile(FOXDOT_INFO_FILE): + os.remove(FOXDOT_INFO_FILE) + content = fread.read() content = content.replace("", f"'{FOXDOT_ROOT}'") content = content.replace("", f"'{FOXDOT_SND}'")