Save to text while running

Is there a way to save to a (text) file while running?

For example, if I’m running code controlled by midi.
sample :bd_boom, amp: var-gets-it-from-midi-1, rate, var-gets-it-from-midi-2
etc.

And after trying different midi-input for a while, I might find that amp: 2, rate: 0.7 is exactly the sound i was looking for.

Is there a way to say “save content of variable X to file” or make a string and “save string to file”, while running. For future reference of 'sounds i liked", easy usage in other code, …?

puts, but to a file in stead of to the log window.

You could pick a gesture on your controller and on its cue event which you trigger as you have those magical “hey, that’s cool – time to save” scenarios use Ruby’s file I/O to save your interesting bits in an appropriate place:

x = File.open("/tmp/fx.rb", "w")
x.puts "my favorite settings"
x.close

Alternatively, there’s another interesting thing going on automatically behind the scenes that might work for you. Sonic-pi is storing its IDE buffer tab code in a behind-the-scenes git repository as you live-code. The location varies depending on what type of computer/OS you’re using. On my MacOS laptop, I can find this git project in ~/.sonic-pi/store/default – I can do something “ls -laR ~/.sonic-pi/store/default” and see all the underlying git gravy. As an example, your first tab is stored in a file named “workspace_one.spi”, and so on.

HTH,
d00d