Skip to content

Instantly share code, notes, and snippets.

@pmzeitler
Created May 26, 2018 15:44
Show Gist options
  • Save pmzeitler/e53f46224eb78f59814429f9f6dda286 to your computer and use it in GitHub Desktop.
Save pmzeitler/e53f46224eb78f59814429f9f6dda286 to your computer and use it in GitHub Desktop.
Sonic Pi - The two notes play simultaneously instead of in sequence. Additionally functions defined in the external file are not usable in the calling file.
#This is the file that will be run manually in the Sonic Pi editor window.
run_file "~/something/RunThis.rb"
#Expected behavior: the code in RunThis.rb should be treated as if it is in the same file/buffer as this
#Observed behavior: the code is loaded into a virtual buffer, and thus a different execution context and begins execution simultaneously
play 50
sleep 1
#Expected behavior: the play 60 and sleep 1 in RunThis.rb should be played and completed before reaching this play/sleep call
#Observed behavior: the play 50/sleep 1 and this play 60/sleep 1 are played simultaneously
bell_line
#Expected behavior: The function "bell_line" from RunThis.rb should be executed
#Observed behavior: A runtime error occurs because the function "bell_line" does not exist in this execution context
#This is the file called by the run_file request in Main.rb.
play 60
sleep 1
#Expected behavior: when execution reaches this point after having been called by Main.rb the sleep 1 request should be honored, preventing further execution until the sleep expires
#Observed behavior: Main.rb executes this in another thread/buffer context completely divorced from Main.rb's execution context
define :bell_line do
use_synth :tri
play chord(:D, "m7-5"), release: 2.5
sleep 2
play chord(:G, "minor7"), release: 2
sleep 1
play chord(:C, "minor7"), release: 2
sleep 1
end
#Expected behavior: This function should be available to both this execution context and the execution context of any context which calls it via run_file
#Observed behavior: This function is only available in the walled-off execution context of RunThis.rb and not in the execution context of the context that called it via run_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment