Further Adventures with Twitter, node-red and Sonic Pi

Building upon the methods explored here, I’ve been experimenting with using node-red’s Twitter node to interface directly with ruby files in Sonic Pi by means of shell scripting. By creating multiple instances of the Twitter nodes in a single flow, I can set unique search terms, strings, hash tags, etc per node, which correspond to individual ruby files. These files are then called up in Sonic Pi, via the command line interface sonic-pi-cli. Using AppleScript syntax within a .sh file, we have the following:

#!/usr/bin/env osascript

tell application "System Events" 
if "Terminal" is not in name of processes then launch application "Terminal" 
tell process "Terminal" 
set frontmost to true 
if (count windows) is 1 then keystroke "n" using command down 
if (count windows) is 2 then 
end if 
end tell 
end tell

tell application "Terminal" 
do script "`sonic_pi \"run_file '~/Dropbox/Code/Ruby/SonicPi/multiRandom.rb'\"`" in window 1
end tell

Instead of connecting Twitter nodes to OSC nodes (to communicate with QLab), I am using exec nodes to run the shell scripts. When configuring the exec nodes, the Command is ‘exec’, uncheck the option to ‘append msg.payload’, and in the ‘extra input parameters’ enter the file pathway to your .sh file, including the extension. Make sure your .sh files are executable once you create them. And, obviously, you will need to set the file pathway to a location pertinent to your machine.

This method uses only freely available tools, rather than paid commercial software – which is not to say you shouldn’t use QLab if you want, but Script cues are a paid feature.

Next, I will update the shell files to run Python commands, making this method cross-platform.