Coder Social home page Coder Social logo

tr808-pi's Introduction

tr808-pi

A DALL-E picture from a prompt: A drum machine next to a piece of pie

Art made by Craiyon, formerly DALL·E mini. The prompt: A drum machine next to a piece of pie.

This project is a demonstration of emulating the Roland TR-808 drum machine in Sonic Pi. I was inspired by GUI-based versions such as tr808r and Roland's online version of TR-808 and decided to make a lightweight text-based version. The samples were taken from this free resource by Michael Fischer.

Warning

This is still a work in progress and will likely evolve rapidly, but most of it is already functional and will likely remain the same with possible enhancements and tweaks.

How do I get it?

All you need to do is download this git repo as a zip, unarchive it somewhere on your computer.

In Sonic Pi, you then require the filepath for the main file tr808-pi.rb at the top of your file:

require "~/Documents/projects/tr808-pi/tr808-pi.rb"

How do I use it?

To play the TR-808, you pass a string format to tr808() that represents the beat pattern, where:

  • the left-hand side is the specific instrument (e.g. BD for bass drum)
  • followed by a space
  • and 16 x (play the note) or - (do not play the note) with | for visual separation of notes

Here's an example of the beat for "1000 Knives" by Yellow Magic Orchestra:

BD xx--|----|xx--|----
SD ----|----|----|----
LT ----|----|----|----
MT ----|----|----|----
HT ----|----|----|----
LC ----|----|----|----
MC ----|----|----|----
HC ----|----|----|----
RS ----|x---|----|x---
CL ----|----|----|----
CP ----|----|----|--x-
MA ----|----|----|----
CB ----|----|----|----
CY ----|----|----|----
OH ----|x---|----|x---
CH --xx|---x|--xx|---x

Note Refer to the TR808.TXT file of the sample pack on what sounds the abbreviations map to.

Here's an example of playing the beat above by passing it to tr808() with some of the instruments removed since they're not used.

tr808("
BD xx--|----|xx--|----
RS ----|x---|----|x---
CP ----|----|----|--x-
OH ----|x---|----|x---
CH --xx|---x|--xx|---x
", bpm: 104)
1000knivesdemo1.mp4

Note When you copy-paste these code snippets, if you turn off auto indentation you can copy this code style. Otherwise, the editor in Sonic Pi will indent the code after copy-paste or running it and it may not look as neat.

In the above example, we have a live beat pattern with various instruments playing in a measure which is 16 notes in total. This will keep playing indefinitely because it is a live_loop under the hood. You do not have to worry about new lines before or after the ".

There is no error handling but since this is going to be played in a live loop context it won't matter if you mess up the number of notes or |: it will just affect when the notes are played.

Tweak the x's and -'s to explore all the fun possibilities!

Multiple patterns

It wouldn't be fun if you could only create one set of beat patterns, so you can also specify multiple patterns.

To add another pattern you simply need to pass in a list of strings and optionally specify the order to play each pattern with a pattern: parameter that accepts an array of integers corresponding to an item.

Let's modify the above example to add a different pattern:

tr808([
"
BD xx--|----|xx--|----
RS ----|x---|----|x---
CB ----|----|----|----
CP ----|----|----|--x-
OH ----|x---|----|x---
CH --xx|---x|--xx|---x
",
"
BD xx--|----|xx--|---x
RS ---x|----|---x|----
CB --xx|-x--|x--x|-xxx
CP ----|---x|----|-x-x
OH ----|x---|----|x---
CH --xx|---x|--xx|---x
"
], 
bpm: 104)

Without the pattern: argument being set, the tr808() will only play the first pattern. So, let's say we want to play each pattern in succession:

tr808([
"
BD xx--|----|xx--|----
RS ----|x---|----|x---
CB ----|----|----|----
CP ----|----|----|--x-
OH ----|x---|----|x---
CH --xx|---x|--xx|---x
",
"
BD xx--|----|xx--|---x
RS ---x|----|---x|----
CB --xx|-x--|x--x|-xxx
CP ----|---x|----|-x-x
OH ----|x---|----|x---
CH --xx|---x|--xx|---x
"
], 
bpm: 104, pattern: [0, 1])
1000knivesdemo2.mp4

By specifying pattern: [0, 1], this plays the first pattern for the first measure, then the second and then cycle back to the first. You can still keep modifying the beat in either pattern and Sonic Pi will pick up the change in the next 16 notes!

Using knit for pattern sequencing

Let's look at a more complex example. This is a drum and bass beat where we have 3 patterns, and we play each one twice:

tr808([
"
OH ----|----|----|----
CH x-x-|x-x-|x-x-|x-x-
SD ----|x---|----|x---
BD x---|----|--x-|----
",
"
OH ----|--x-|----|----
CH x-x-|x-x-|x-x-|x-x-
SD ----|x--x|-x--|x---
BD x---|----|--x-|----
",
"
OH ----|--x-|--x-|----
CH xxxx|xxxx|xxxx|xxxx
SD ----|x--x|-x--|x---
BD x---|----|--x-|----
"
], bpm: 160, pattern: [0, 0, 1, 1, 2, 2])
drumandbassdemo1.mp4

We can re-write this particular pattern: using the knit() function in Sonic Pi. Instead of:

[0, 0, 1, 1, 2, 2]

we can write:

knit(0, 2, 1, 2, 2, 2)

This allows us to be more succinct if we wanted more repeats of some patterns. For example, maybe we'd like to play each pattern 4 times. It would be tedious to write:

[0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2]

when we can write it more succinctly with:

knit(0, 4, 1, 4, 2, 4)

Here's the full example:

tr808([
"
OH ----|----|----|----
CH x-x-|x-x-|x-x-|x-x-
SD ----|x---|----|x---
BD x---|----|--x-|----
",
"
OH ----|--x-|----|----
CH x-x-|x-x-|x-x-|x-x-
SD ----|x--x|-x--|x---
BD x---|----|--x-|----
",
"
OH ----|--x-|--x-|----
CH xxxx|xxxx|xxxx|xxxx
SD ----|x--x|-x--|x---
BD x---|----|--x-|----
"
], bpm: 160, pattern: knit(0, 4, 1, 4, 2, 4))
drumandbassdemo2.mp4

Examples

You can check out examples you can directly copy-paste into Sonic Pi.

Share your beats!

This string is also copy-paste-able text so that you can easily share it with others! The character length is a bit too long for tweets if you choose to use all the instruments. However, you can choose to use only a subset of the instruments, and can remove some. For example, transforming the long example above fits in a tweet:

BD xx--|----|xx--|----
RS ----|x---|----|x---
CP ----|----|----|--x-
OH ----|x---|----|x---
CH --xx|---x|--xx|---x

If it's too long, you can create a gist and share the link.

Happy beat making y'all!

You can refer to some popular TR-808 beats here.

Warning

There is no error handling at all so the string format is strict for now. If time permits, I will add enhancements to protect the user, and allow further tweaks to the way the notes are played.

tr808-pi's People

Contributors

nischalshrestha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

tr808-pi's Issues

Enable a custom samples map

While the TR-808 samples are awesome, and you can re-create TONS of beats with it, we might want to allow a custom samples pack and instruments. For e.g. even being able to use Sonic Pi's drum samples would be a great. I would also want to use external samples for even more fun!

For existing Sonic Pi drum samples, we might consider a slightly different implementation via sonic_beats() where you could create your own abbreviations to the existing samples.

For external packs, we could share some logic that currently maps TR-808 instruments to particular sample files, but we would need to generalize this to accept any custom mapping and sample directory/files.

Named patterns for easier beat composition

While it is great we can specify the sequence of patterns to play with indices, it would be nice if we can name them so it's easier to recall. For e.g. instead of 0, we could name the first pattern "A" or "Verse 1".

Allow duplicating instruments for interesting patterns

You might sometimes want to have multiple versions of the same instrument to either play different patterns, timing, or amplitude. For e.g. I would love to be able to play a drum n bass sound that has 2 snares:

CH x-x-|x-x-|x-x-|x-x-
SD ----|---x|-x--|----
SD ----|x---|----|x---
BD x---|----|--x-|----

Perhaps we can have multiple entries of the same instrument with different parameters.

Tweak parameters of each sample

It would be great if we can tweak certain parameters of the samples, for e.g. amplitude (level) or other sample related parameters. The TR-808 sample pack also has various versions of the instrument which we should also be able to pick.

Handle multiple measures

While it's nice to work with just the 16note single measure, we might also want to handle multiple measures especially if you want to compose a longer sequence of beat grids.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.