# Print Samplepath

**URL:** <https://in-thread.sonic-pi.net/t/print-samplepath/518>\
**Category:** \[P\] Patreon Support\
**Created:** [December 12, 2017, 4:55pm UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518 "2017-12-12T16:55:27Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![synchron](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@synchron](https://in-thread.sonic-pi.net/u/synchron)\
**Post date:** [December 12, 2017, 4:55pm UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/1 "2017-12-12T16:55:27Z")

</div>

Hi,  
while i play a sample with  
sample [“path”,“partOfFile”,“OtherPart”]  
the terminal show things like:

sample “/path/”,  
“file.wav”, {pan: 1, lpf: 100, hpf: 70, start: 0.2, amp: 0, pamp: 0.2, pamp\_slide: 3}

Is it possible to get the filename and path, to write it to a file?  
something like

log = "/path/logfile.log"  
log.puts samplepath [“path”,“partOfFile”,“OtherPart”]  
log.puts samplename [“path”,“partOfFile”,“OtherPart”]

Thank you

---

<div class="post-metadata">

**Author:** ![d00d](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/d00d/32/35_2.png) [@d00d](https://in-thread.sonic-pi.net/u/d00d)\
**Post date:** [December 13, 2017, 4:39am UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/2 "2017-12-13T04:39:46Z")

</div>

sample\_paths might provide the path details you’re looking for, and you can use Ruby’s file I/O to write the file – parse the parts you’re interested in from sample\_paths YOUR\_SAMPLE into path\_stuff in the sample code below…

```
path_stuff = (sample_paths YOUR_SAMPLE)[0]
log = "/path/logfile.log"
x = File.open(log, "w")
x.puts path_stuff
x.close

```

hth,  
d00d

---

<div class="post-metadata">

**Author:** ![synchron](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@synchron](https://in-thread.sonic-pi.net/u/synchron)\
**Post date:** [December 13, 2017, 5:43pm UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/3 "2017-12-13T17:43:11Z")

</div>

Thank you!  
With this, it is possible to print out the complete filepath.  
Is it even possible to only print the filename? like “sound.wav”?

And a second question. (Sorry, but i am not so firm with Ruby and the Stringmanipulationthings…)  
Is it possible to sorround the filepath with other text? like “The file sound.wav was played at time: 2:32, with amp 2 and a panning of -0.3”

Thanks!

---

<div class="post-metadata">

**Author:** ![d00d](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/d00d/32/35_2.png) [@d00d](https://in-thread.sonic-pi.net/u/d00d)\
**Post date:** [December 13, 2017, 8:56pm UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/4 "2017-12-13T20:56:41Z")

</div>

sure, parsing strings works like this:

```
puts (sample_paths :ambi_choir)[0].split("/")[-1] # unqualified filename

```

you can generate sentence-like text strings by concatenating the bits together:

```
o = " orange"
puts "apple " + 36.to_s + o

```

perhaps sample\_info provides some interesting sample details as well

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [December 14, 2017, 3:06pm UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/5 "2017-12-14T15:06:19Z")

</div>

Hi there,

simply use `sample_info` to get access to information about your sample 🙂

```ruby
s = sample_info :ambi_choir

puts s.path 

```

---

<div class="post-metadata">

**Author:** ![synchron](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@synchron](https://in-thread.sonic-pi.net/u/synchron)\
**Post date:** [December 20, 2017, 5:52pm UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/6 "2017-12-20T17:52:07Z")

</div>

Thank you very much!  
Works great

---

<div class="post-metadata">

**Author:** ![synchron](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@synchron](https://in-thread.sonic-pi.net/u/synchron)\
**Post date:** [December 22, 2017, 2:47pm UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/7 "2017-12-22T14:47:39Z")

</div>

Sorry for my questions. But …  
is there a way to print out the time?  
When i play a sample the console puts out a  
{run: 1, time:1.234}  
Can i access this time value?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Martin](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/martin/32/157_2.png) [@Martin](https://in-thread.sonic-pi.net/u/Martin)\
**Post date:** [December 22, 2017, 3:03pm UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/8 "2017-12-22T15:03:34Z")

</div>

Yes, have a look at the lang documentation and the function: `sample_duration`.

---

<div class="post-metadata">

**Author:** ![synchron](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@synchron](https://in-thread.sonic-pi.net/u/synchron)\
**Post date:** [December 22, 2017, 3:05pm UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/9 "2017-12-22T15:05:59Z")

</div>

sample\_duration only gives me the duration of the current sample.  
I want the complete past time… or i had to make an addition of all sleeps before the point i want to know the time…

---

<div class="post-metadata">

**Author:** ![synchron](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@synchron](https://in-thread.sonic-pi.net/u/synchron)\
**Post date:** [December 22, 2017, 3:10pm UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/10 "2017-12-22T15:10:14Z")

</div>

Ah, i found:  
puts rt(beat)  
Seams to work.  
Thanks!

---

<div class="post-metadata">

**Author:** ![synchron](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@synchron](https://in-thread.sonic-pi.net/u/synchron)\
**Post date:** [December 22, 2017, 3:11pm UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/11 "2017-12-22T15:11:13Z")

</div>

sorry…no…does not do it right…

---

<div class="post-metadata">

**Author:** ![Martin](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/martin/32/157_2.png) [@Martin](https://in-thread.sonic-pi.net/u/Martin)\
**Post date:** [December 22, 2017, 3:13pm UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/12 "2017-12-22T15:13:16Z")

</div>

Oh, sorry. Well, yes, you probably will have to add up all your `sleep`s. At least I don’t know of any function in the core.

---

<div class="post-metadata">

**Author:** ![synchron](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@synchron](https://in-thread.sonic-pi.net/u/synchron)\
**Post date:** [December 22, 2017, 3:13pm UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/13 "2017-12-22T15:13:53Z")

</div>

ok. thank you very much!

---

<div class="post-metadata">

**Author:** ![synchron](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@synchron](https://in-thread.sonic-pi.net/u/synchron)\
**Post date:** [December 22, 2017, 3:23pm UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/14 "2017-12-22T15:23:39Z")

</div>

Found a way, even if its not very stable.  
At the beginning i set  
t = Time.now  
and in the moment is use it i do  
puts (Time.now - t)  
But this gives slightly different values each time. But i can live with it 🙂

---

<div class="post-metadata">

**Author:** ![samaaron](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/samaaron/32/7_2.png) [@samaaron](https://in-thread.sonic-pi.net/u/samaaron)\
**Post date:** [December 24, 2017, 8:57am UTC](https://in-thread.sonic-pi.net/t/print-samplepath/518/15 "2017-12-24T08:57:26Z")

</div>

See the fn `vt` - perhaps that’s what you’re looking for?
