Skip to content

Instantly share code, notes, and snippets.

@nvitucci
Last active September 17, 2022 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nvitucci/957c9bbbc880694a2120a30865326068 to your computer and use it in GitHub Desktop.
Save nvitucci/957c9bbbc880694a2120a30865326068 to your computer and use it in GitHub Desktop.
Using Alda with Python
  1. Download and install Alda per the Install instructions
  2. Run the Alda REPL as a server:
    $ alda repl --server --port 12345
    
  3. In a different terminal, run an interactive Python session (e.g. IPython)
  4. Install an nREPL client such as nrepl-python-client (a bit dated but does the job)
    !pip install --user nrepl-python-client
    
  5. Create some Alda code, for example:
    code = """ 
        (tempo! 90) 
        piano:  
            o3 c1/e/g/b | f2/a/>c/e ~ <e2/g/b/>d 
        violin: 
            o2 c1 ~ | f2 ~ g2 
        percussion: 
            o2 [c8 r8 c8 r8 e8 c8 r8 c8] * 2 
    """
    
  6. Send it as a message to the Alda server nREPL:
    c.write({"op": "eval-and-play", "code": code})
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment