# Get current buffer as a string

**URL:** <https://in-thread.sonic-pi.net/t/get-current-buffer-as-a-string/5709>\
**Category:** Creations & Ideas\
**Created:** [June 17, 2021, 2:29pm UTC](https://in-thread.sonic-pi.net/t/get-current-buffer-as-a-string/5709 "2021-06-17T14:29:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amiika](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/amiika/32/2401_2.png) [@amiika](https://in-thread.sonic-pi.net/u/amiika)\
**Post date:** [June 17, 2021, 2:29pm UTC](https://in-thread.sonic-pi.net/t/get-current-buffer-as-a-string/5709/1 "2021-06-17T14:29:47Z")

</div>

I was thinking about creating something really meta, such as sonifying the current buffer by running it. Is it possible to get the content of the buffer as a string?

---

<div class="post-metadata">

**Author:** ![amiika](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/amiika/32/2401_2.png) [@amiika](https://in-thread.sonic-pi.net/u/amiika)\
**Post date:** [June 17, 2021, 7:54pm UTC](https://in-thread.sonic-pi.net/t/get-current-buffer-as-a-string/5709/2 "2021-06-17T19:54:56Z")

</div>

Did not find any method from the Sonic Pi language but after few beers found a way:

```ruby
buffer = project_path+"workspace_one.spi"
text = File.read(buffer)
notes = {}
text.chars.each do |char|
  if !notes[char]
    notes[char] = {note: rrand_i(60,120), sleep: [0.25,0.5].choose }
  end
  with_fx :ping_pong, feedback: 0.5, phase: 0.25 do
    synth :mod_beep, note: notes[char][:note]
  end
  sleep notes[char][:sleep]
end

```

Run this in buffer one … such meta 🙃🍻 👾

---

<div class="post-metadata">

**Author:** ![ethancrawford](https://avatars.discourse-cdn.com/v4/letter/e/a88e4f/32.png) [@ethancrawford](https://in-thread.sonic-pi.net/u/ethancrawford)\
**Post date:** [February 12, 2022, 2:31pm UTC](https://in-thread.sonic-pi.net/t/get-current-buffer-as-a-string/5709/3 "2022-02-12T14:31:07Z")

</div>

Hey @amiika,

Was looking over some old code I have lying around and stumbled across a line which might have helped you slightly with this…  
If it’s still useful - and for anyone else that ends up reading: as mentioned above, there is no built-in way in the Sonic Pi language to get the path or contents of the current buffer, though by doing essentially what amiika shows above, you can read the file contents.  
_However_ - you _can_ (currently) use a function deep in the Sonic Pi source code to get the name of the current buffer:

```ruby
puts Thread.current.__system_thread_locals.get(:sonic_pi_spider_job_info)[:workspace]

```

…produces, for example:

```ruby
"workspace_one"

```

(Of course, the success of using this internal function may or may not change in the future as Sonic Pi evolves).
