# Arpeggios on a tb303 bass

**URL:** <https://in-thread.sonic-pi.net/t/arpeggios-on-a-tb303-bass/1019>\
**Category:** Performances, Streams & Live Coding\
**Created:** [April 24, 2018, 5:27pm UTC](https://in-thread.sonic-pi.net/t/arpeggios-on-a-tb303-bass/1019 "2018-04-24T17:27:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [April 24, 2018, 5:27pm UTC](https://in-thread.sonic-pi.net/t/arpeggios-on-a-tb303-bass/1019/1 "2018-04-24T17:27:05Z")

</div>

https://w.soundcloud.com/player/?visual=false&url=https%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F434528394&show_artwork=true&maxheight=166

code link

> <https://gist.github.com/rbnpi/414eda26c112b0c7cdc922f1c7194e92>

For another interesting variation change line 83 as below

```ruby
ch.each do |n| #play each chord as an arpeggio #interesting variation is to change to ch.shuffle.each do |n|

```

---

<div class="post-metadata">

**Author:** ![Mike](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/mike/32/556_2.png) [@Mike](https://in-thread.sonic-pi.net/u/Mike)\
**Post date:** [April 24, 2018, 11:05pm UTC](https://in-thread.sonic-pi.net/t/arpeggios-on-a-tb303-bass/1019/2 "2018-04-24T23:05:20Z")

</div>

That sounds very nice! It’s great to have an example with harmonic, dynamic, and temporal structure.

I suspect I’m going to learn a lot by studying your code. Thanks!

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [April 25, 2018, 7:10am UTC](https://in-thread.sonic-pi.net/t/arpeggios-on-a-tb303-bass/1019/3 "2018-04-25T07:10:47Z")

</div>

Thanks Mike  
I enjoyed working on the piece, which just seemed to “click” as I added more features and let it grow from very humble beginnings, starting with just triad apreggios, then adding a fourth bass note to each triad, then transposing using 0,5,7,-5 (C,F,G,G-Lower octave) and adding a pedal note for each progression. I always like to add dynamic structure as well and the use of teh at command with timed amp\_slides gives a nice way to achieve crescendos and diminuendos.

BTW I enjoyed reading your article on Tbon on github. I have worked in the past on manujally converting a lilypond script to Sinic Pi, and also on converting midi to Sonic Pi format using MuseScore to convert the midi to monophonic parts and then to MusicXML and then a [processing script](https://rbnrpi.wordpress.com/2016/08/19/converting-musicxml-or-midi-files-to-work-with-sonic-pi/) modified from one by Tachibani to convert that to Sonic Pi forma. It has fairly stringent constraints, but I have used it successfully for many conversions. I also did some work with [JoeMac’s script](http://in-thread.sonic-pi.net/t/playing-midi-files-on-sonic-pi/358?u=robin.newman) which achieves a similar result. I look foward to having a more detailed look at Tonb.

Probably the most ambitious work I converted from midi to Sonic Pi was the whole of Mozart’s Requiem, which I voiced with samples. see

[https://youtu.be/6Q0vgcNcsdg](https://youtu.be/6Q0vgcNcsdg)

---

<div class="post-metadata">

**Author:** ![Mike](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/mike/32/556_2.png) [@Mike](https://in-thread.sonic-pi.net/u/Mike)\
**Post date:** [April 25, 2018, 8:41pm UTC](https://in-thread.sonic-pi.net/t/arpeggios-on-a-tb303-bass/1019/4 "2018-04-25T20:41:55Z")

</div>

**Learning**  
@robin.newman Looking through your code, I think I get the gist, but there some Sonic Pi / Ruby -isms I’m unclear about. For example in line 19 I see

```
with_fx :level, amp: 0 do |v|

```

- Is `with_fx` similar to a Python context manager `with` statement?
- What type of variable is `|v|`? It doesn’t seem quite like a function argument. Is it a local reference to a the `:level` effect?

A couple of lines down I see

```
at [51.2,102.4,153.2,204.8],[0.5,1,0.4,1] do |t|

```

I get that this is specifying a time (in beats?) at which to begin sliding the volume to a target value but where is `at` documented? I searched in the tutorial and with google but didn’t find anything.

**Tbon**  
I’m approaching bringing Tbon into SP with a sense of humility. I don’t want to reinvent the wheel and I don’t want to do something that’s a kluge just for the sake of doing it. That being said, it looks like a quick and dirty test might be to call a modified version of Tbon with Ruby’s system call notation and eval a returned string to get a pair of lists with times and durations suitable for use with `play_pattern_timed`, e.g.

```
# Greensleeves. First 4 bars, no pickup.

melody = [
    [:c4,1], [:d4,0.5], [:e4,0.75], [:f4,0.25], [:e4,0.5],
    [:d4,1], [:b3,0.5], [:g3,0.75], [:a3,0.25], [:b3,0.5],
    [:c4,1], [:a3,0.5], [:a3,0.75], [:gs3,0.25], [:a3,0.5],
    [:b3,1], [:gs3,0.5], [:e3,1.5],
].transpose

# Tbon notation for same four bar fragment is:
# K=a T=90 B=4.
# c-d e--fe- | d-b g--ab- | c-a a--#ga- | b-#g e |
#
# So a system call and ruby eval of the result could
# look something like:
# melody = (eval `tbon "c-d e--fe- | d-b g--ab- | ..."`)

use_bpm 90
use_synth :piano
play_pattern_timed melody[0], melody[1]

```

To make that work, I’d need to put different backend onto Tbon to emit a string representing a list of lists with the appropriate note names and beat durations.

If you’d like to play with Tbon outside of SP, there’s a [live online demo](http://ellisgrant.pythonanywhere.com/) where you can enter Tbon notation and play it through a JS synth in your browser. Have fun!

**Requiem**  
I found your Mozart Requiem a couple of days ago. Wow, that’s a monumental effort. The Requiem is one of the great choral works. There’s something new to appreciate every time I’ve sung it.

---

<div class="post-metadata">

**Author:** ![robin.newman](https://avatars.discourse-cdn.com/v4/letter/r/76d3ee/32.png) [@robin.newman](https://in-thread.sonic-pi.net/u/robin.newman)\
**Post date:** [April 26, 2018, 6:31am UTC](https://in-thread.sonic-pi.net/t/arpeggios-on-a-tb303-bass/1019/5 "2018-04-26T06:31:16Z")

</div>

In asnwer to your questions, with\_fx do…end is the construct used for wrapping some code with a named effect. It is documented in several places in the help system.  
First in the Lang tab look up with\_fx (Note the built in help system contains other sections than the tutorial which is the section available on line).  
Second there is a separate Fx tab which gives details of all the individual Fx available, together with details of their options.  
In my example v is indeed a reference to the running effect which can be used to control various opts in the effect. In this case I control tha :amp setting of the :leve effect, and also use the amp\_slide: paraneter to control the time over which changes take place. There is an example of using such a variable in the with\_fx docucumentation in the Lang section of the help file. (note you can use a `puts v` command inside the do…end loop to see the information it holds.)

Similarly the at command is detailed in the Lang section of the help file, with some examples there. eg

```ruby
at [1, 2, 3], [75, 76, 77] do |n| 
    play n #plays three different notes (at beats 1,2 and 3
  end

```

---

<div class="post-metadata">

**Author:** ![Mike](https://dub1.discourse-cdn.com/flex017/user_avatar/in-thread.sonic-pi.net/mike/32/556_2.png) [@Mike](https://in-thread.sonic-pi.net/u/Mike)\
**Post date:** [April 26, 2018, 3:15pm UTC](https://in-thread.sonic-pi.net/t/arpeggios-on-a-tb303-bass/1019/6 "2018-04-26T15:15:43Z")

</div>

Thanks! I totally missed the Lang tab. 😮
