Skip to content

Commit

Permalink
Remove freesound support for v2.1
Browse files Browse the repository at this point in the history
- needs a little more thought
  • Loading branch information
samaaron committed Nov 21, 2014
1 parent f8ba436 commit 208a0e0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 51 deletions.
64 changes: 31 additions & 33 deletions app/server/sonicpi/lib/sonicpi/mods/sound.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1535,8 +1535,6 @@ def load_sample(path)
else
raise "No sample exists with path #{path}"
end
when Numeric
freesound(path)
else
raise "Unknown sample description: #{path}"
end
Expand Down Expand Up @@ -2682,11 +2680,11 @@ def set_current_synth(name)
Thread.current.thread_variable_set(:sonic_pi_mod_sound_current_synth_name, name)
end

def freesound_path(id)
def __freesound_path(id)
cache_dir = home_dir + '/freesound/'
ensure_dir(cache_dir)

cache_file = cache_dir + id.to_s + ".wav"
cache_file = cache_dir + "freesound-" + id.to_s + ".wav"

return cache_file if File.exists?(cache_file)

Expand All @@ -2713,18 +2711,18 @@ def freesound_path(id)
end
return nil
end
doc name: :freesound_path,
introduced: Version.new(2,1,0),
summary: "Return local path for sound from freesound.org",
doc: "Download and cache a sample by ID from freesound.org. Returns path as string if cached. If not cached, returns nil and starts a background thread to download the sample.",
args: [[:id, :number]],
opts: nil,
accepts_block: false,
examples: ["
puts freesound(250129) # preloads a freesound and prints its local path, such as '/home/user/.sonic_pi/freesound/250129.wav'"]

def freesound(id, *opts)
path = freesound_path(id)
# doc name: :freesound_path,
# introduced: Version.new(2,1,0),
# summary: "Return local path for sound from freesound.org",
# doc: "Download and cache a sample by ID from freesound.org. Returns path as string if cached. If not cached, returns nil and starts a background thread to download the sample.",
# args: [[:id, :number]],
# opts: nil,
# accepts_block: false,
# examples: ["
# puts freesound(250129) # preloads a freesound and prints its local path, such as '/home/user/.sonic_pi/freesound/250129.wav'"]

def __freesound(id, *opts)
path = __freesound_path(id)
arg_h = resolve_synth_opts_hash_or_array(opts)
fallback = arg_h[:fallback]

Expand All @@ -2739,23 +2737,23 @@ def freesound(id, *opts)
end

end
doc name: :freesound,
introduced: Version.new(2,1,0),
summary: "Play sample from freesound.org",
doc: "Fetch from cache (or download then cache) a sample by ID from freesound.org, and then play it.",
args: [[:id, :number]],
opts: {:fallback => "Symbol representing built-in sample to play if the freesound id isn't yet downloaded"},
accepts_block: false,
examples: ["
freesound(250129) # takes time to download the first time, but then the sample is cached locally
",
"
loop do
sample freesound(27130)
sleep sample_duration(27130)
end
"
]
# doc name: :freesound,
# introduced: Version.new(2,1,0),
# summary: "Play sample from freesound.org",
# doc: "Fetch from cache (or download then cache) a sample by ID from freesound.org, and then play it.",
# args: [[:id, :number]],
# opts: {:fallback => "Symbol representing built-in sample to play if the freesound id isn't yet downloaded"},
# accepts_block: false,
# examples: ["
# freesound(250129) # takes time to download the first time, but then the sample is cached locally
# ",
# "
# loop do
# sample freesound(27130)
# sleep sample_duration(27130)
# end
# "
# ]
end
end
end
38 changes: 20 additions & 18 deletions etc/doc/tutorial/03.6-External-Samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

Whilst the built-in samples can get you up and started quickly, you
might wish to experiment with other recorded sounds in your music. Sonic
Pi totally supports this with two approaches. First though, let's have a
quick discussion on the portability of your piece.
Pi totally supports this. First though, let's have a quick discussion on
the portability of your piece.

## Portablility

Expand All @@ -21,35 +21,37 @@ for others to manipulate, mash-up and experiment with your work. Of
course this shouldn't stop you from using your own samples, it's just
something to consider.

<!-- ## Freesound Support -->

## Freesound Support
<!-- One way to get the ability to experiment with new sounds whilst keeping -->
<!-- code portability is to use the [Freesound](http:freesound.org) -->
<!-- support. http://freesound.org is a website which allows people to upload -->
<!-- and share their samples. Each sample uploaded gets a special number -->
<!-- (kind of like a phone number) which you can use to dial up that sample -->
<!-- from Sonic Pi. The only drawback is that you need to have internet -->
<!-- access for it to work. -->

One way to get the ability to experiment with new sounds whilst keeping
code portability is to use the [Freesound](http:freesound.org)
support. http://freesound.org is a website which allows people to upload
and share their samples. Each sample uploaded gets a special number
(kind of like a phone number) which you can use to dial up that sample
from Sonic Pi. The only drawback is that you need to have internet
access for it to work.
<!-- If you currently have internet access, try it for yourself: -->

If you currently have internet access, try it for yourself:
<!-- ``` -->
<!-- freesound 24787 -->
<!-- ``` -->

```
freesound 27130
```

You might have to wait a moment.
<!-- The first time you do this you'll hear a standard `:elec_beep` as a -->
<!-- placeholder for the sound. Y -->


## Local Samples

Sonic Pi also supports the ability to play any arbitrary wav or aif file on your computer. All you need to do is pass the path to that file to `sample`:
So how do you play any arbitrary wav or aif file on your computer? All
you need to do is pass the path to that file to `sample`:

```
sample "/Users/sam/Desktop/my-sound.wav"
```

Sonic Pi will automatically load and play the sample. You can also pass all the standard params you're used to passing `sample`:
Sonic Pi will automatically load and play the sample. You can also pass
all the standard params you're used to passing `sample`:

```
sample "/Users/sam/Desktop/my-sound.wav", rate: 0.5, amp: 0.3
Expand Down

0 comments on commit 208a0e0

Please sign in to comment.