diff --git a/FoxDot/lib/ServerManager.py b/FoxDot/lib/ServerManager.py index eca0411f..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')) + 'max_nodes', 'max_synth_defs', 'foxdot_root', 'foxdot_snd')) class OSCClientWrapper(OSCClient): @@ -178,11 +178,15 @@ class SCLangServerManager(ServerManager): fxlist = None synthdefs = None - def __init__(self, addr, osc_port, sclang_port): + 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 @@ -213,7 +217,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: @@ -227,6 +236,8 @@ 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() self.sclang.connect( (self.addr, self.SCLang_port)) @@ -608,6 +619,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 ) @@ -627,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) @@ -1097,10 +1118,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_ROOT, FOXDOT_SND # DefaultServer = SCLangServerManager(ADDRESS, PORT, PORT2) - Server = SCLangServerManager(ADDRESS, PORT, PORT2) + 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 19ceff96..c4541933 100644 --- a/FoxDot/lib/Settings/__init__.py +++ b/FoxDot/lib/Settings/__init__.py @@ -122,6 +122,21 @@ def GET_TUTORIAL_FILES(): FOXDOT_SND = os.path.realpath(conf.SAMPLES_DIR) +# Recreate info file from template +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}'") + 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 92% rename from FoxDot/osc/Info.scd rename to FoxDot/osc/Info.scd.template index 6d2abbaa..faa214ba 100644 --- a/FoxDot/osc/Info.scd +++ b/FoxDot/osc/Info.scd.template @@ -13,6 +13,8 @@ OSCFunc( Server.default.options.numBuffers, Server.default.options.maxNodes, Server.default.options.maxSynthDefs, + , + , ); }, '/foxdot/info' );