Qirky / Troop

Real-time Live Coding collaboration app
306 stars 37 forks source link

Tidal music doesn't change #4

Closed Chovin closed 5 years ago

Chovin commented 6 years ago

Trying to execute Tidal code with syntax errors and the like seems to stop Troop from sending any new input to SuperCollider.

There is no output to any console that'd make this obvious. A restart of the Troop client is required to send code to SC again

Qirky commented 6 years ago

Hi Chovin, can you take me through the steps that lead to this - from how you start off and an example of code with errors and causes the dropped connection? Thanks

Chovin commented 6 years ago

Sure thing,

  1. start up SuperCollider and SuperDirt.start
  2. cd to Troop and start the server python3 run-server.py
  3. run client python3 run-client.py --mode TidalCyclesStack (stack for me)
  4. d1 $ s "bd"
  5. d1 s "bd"

That should do it. A restart of the client (and sometimes SC) seems to be needed. Although I can't reproduce it again since whenever I try to do d1 $ s "bd" now, I get [Errno 32] Broken pipe d1 $ s "bd" Will come back with more info later

Qirky commented 6 years ago

I haven't used the TidalCyclesStack mode so I wonder if it's because of that? I can't seem to replicate the issue. Do you manage to get any sound if you start with correct syntax?

Chovin commented 6 years ago

Yes, I get sound if I start with correct syntax. It's not like the sound stops, I just can't interact with it anymore. So quite the opposite, I can't hush.

It shouldn't be a slack problem. the guy I was connected to was using cabal --mode TidalCycles and his stopped working after either of us executed bad code as well

Qirky commented 6 years ago

When you can't interact with it - is it freezing or are you able to "evaluate" code but nothing changes in the audio? In interpreter.py I changed the stderror to PIPE instead of STDOUT and seemed to replicate the issue somewhat. What operating system are you using? If you don't mind going into the code could you change stderr=STDOUT to stdout=PIPE on line 73 of interpreter.py and see if you still get the issue

Chovin commented 6 years ago
[Errno 32] Broken pipe
d1 $ sound "bd" # n "3"

just got back to it. updated my Troop, but now I can't execute anything with stderr=STDOUT or PIPE

Qirky commented 6 years ago

Can you copy exactly what's in the console or send a screenshot? What version of Python are you using? I was having trouble with Python 3 recently but seem to have got it working but not sure that's the issue here. I made a few small changes to Interpreter.py so if you could update Troop and try again that'd be great

Chovin commented 6 years ago

image That's the full console contents. I'm using Python 3.6.2

I am using the Stack tidal option.

running it through the terminal works fine. I get sound from that.

$ stack ghci
Configuring GHCi with the following packages:
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /private/var/folders/db/gnl24pna0s9n23jknjdi/T/ghci5150/ghci-script
Prelude> import Sound.Tidal.Context
Prelude Sound.Tidal.Context> :set -XOverloadedStrings
Prelude Sound.Tidal.Context> (cps, getNow) <- bpsUtils
Prelude Sound.Tidal.Context> (d1,t1) <- superDirtSetters getNow
Prelude Sound.Tidal.Context> d1 $ s "bd*3" # n "5"
Qirky commented 6 years ago

Could you try saving and running the following code? This should open an interactive ghci terminal with Tidal running. I think it was because I wasn't using the "flush" method where I should so if this works then I think I have the solution. If not, then it's back to the drawing board!

from subprocess import Popen, PIPE

path = ["stack", "ghci"]

lang = Popen(path, shell=True, universal_newlines=True, stdin=PIPE)

lang.stdin.write("import Sound.Tidal.Context\n")
lang.stdin.flush()
lang.stdin.write(":set -XOverloadedStrings\n")
lang.stdin.flush()
lang.stdin.write("(cps, getNow) <- bpsUtils\n")
lang.stdin.flush()
lang.stdin.write("(d1, t1) <- superDirtSetters getNow\n")
lang.stdin.flush()

while True:
    text = input()
    if len(text) > 0:
        lang.stdin.write(text + "\n")
        lang.stdin.flush()
    else:
        break

lang.kill()
Chovin commented 6 years ago

hmmm saving and running it gives me the man page like the command was structured incorrectly

$ python3 test.py
stack - The Haskell Tool Stack

Usage: stack [--help] [--version] [--numeric-version] [--hpack-numeric-version]
             [--docker*] [--nix*] ([--verbosity VERBOSITY] | [-v|--verbose] |
...
$

if I run it as lang = Popen(' '.join(path), shell=True, universal_newlines=True, stdin=PIPE) it works fine though.

if I leave out shell=True, I don't have to join the path. I think it might be a Mac thing

Chovin commented 6 years ago

I'm also getting this as of the most recent commit

Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 1699, in __call__
    return self.func(*args)
  File "/Users/Chovin/Projects/LiveCoding/Troop/src/interface/interface.py", line 1204, in set_interpreter
    self.lang=langtypes[name]()
  File "/Users/Chovin/Projects/LiveCoding/Troop/src/interpreter.py", line 368, in __init__
    while self.stdout() > 0:
  File "/Users/Chovin/Projects/LiveCoding/Troop/src/interpreter.py", line 134, in stdout
    self.lang.stdout.seek(0,2)
io.UnsupportedOperation: underlying stream is not seekable
Qirky commented 6 years ago

Ah yes, that was an error on my part in that test file - shell is set to False in Troop. So I've added a catch for that last error and changed the command from ["stack", "ghci"] to just "stack ghci" to see if it improves things on Mac. Let me know how it goes :)

Chovin commented 6 years ago

looks as though it gives me this now:

Traceback (most recent call last):
  File "run-client.py", line 73, in <module>
    myClient = Client(host, port, name, lang, logging)
  File "/Users/Chovin/Projects/LiveCoding/Troop/src/client.py", line 70, in __init__
    self.ui = Interface("Troop - {}@{}:{}".format(self.name, self.send.hostname, self.send.port), self.lang, logging)
  File "/Users/Chovin/Projects/LiveCoding/Troop/src/interface/interface.py", line 112, in __init__
    self.lang = language()
  File "/Users/Chovin/Projects/LiveCoding/Troop/src/interpreter.py", line 338, in __init__
    Interpreter.__init__(self, self.path)
  File "/Users/Chovin/Projects/LiveCoding/Troop/src/interpreter.py", line 80, in __init__
    stderr=STDOUT)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1333, in _execute_child
    raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'stack ghci'

Changing src/interpreter.py#L77 to shell=True seems to get it working fine though

weird ¯\_(ツ)_/¯

Qirky commented 6 years ago

I tested both FoxDot and TidalCycles (non-stack) with both Python 2 and 3 and setting Shell to True is fine there. I think it's because of the way Unix based systems, like Mac, deal with subprocesses with multiple arguments (e.g. stack ghci) but I've changed the shell argument to True now. Let me know how you get on

Chovin commented 6 years ago

seems to work now! \o/ Thank you!

Qirky commented 6 years ago

Yaaaaay!

Chovin commented 6 years ago

nuuuuu

now that all the other stuff is out of the way, we're back to the original problem 😬

I accidentally threw a s "crow*#" in there and now nothing changes image * sorry, it wouldn't let me copy from the console

hush doesn't stop the sounds, but closing Troop does.

Qirky commented 6 years ago

And no error message in the terminal?

Chovin commented 6 years ago

no error message in terminal. I can't get it to break consistently either. I don't know if there are other factors in play but it usually takes me a few errors before it stops responding.

Qirky commented 6 years ago

Ok so I think I have it! Been starting to move the pipe communication over to FoxDot as well so that it'll be easier to release Troop as a standalone app and ran into the same issues. I think I've sorted them (well at least on Windows) could you see if this improves things?

Qirky commented 6 years ago

So I've stopped trying to read from the GHCI stdout as there isn't a delimiter so currently Tidal will print to your actual console for the time being. Let me know if you get any more crashes as this, hypothetically, shouldn't cause any issues.

Qirky commented 6 years ago

Hey Chovin, I'm trying a new method to get the tidal console text into Troop and works ok on Windows. Could you try updating Troop and see how you get on?

Chovin commented 6 years ago

Sorry for the lack of activity. I'll see if I can give it a try this weekend

Qirky commented 5 years ago

Can I go ahead and close this issue?