aboutsummaryrefslogtreecommitdiff
path: root/posts
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2022-07-05 07:48:18 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2022-07-05 07:48:18 +0200
commitc05714786bf5d28c3313b8090b6e3a83775c4a76 (patch)
tree4e0618588d5725071af4d2acefbccbed7eb1de52 /posts
parentf39f15f2a9ea9a8a08996c3b70f75f7f178a56df (diff)
downloadmitjafelicijan.com-c05714786bf5d28c3313b8090b6e3a83775c4a76.tar.gz
Added MIDI to DNA
Diffstat (limited to 'posts')
-rw-r--r--posts/2022-07-05-what-would-dna-sound-if-synthesized.md65
1 files changed, 64 insertions, 1 deletions
diff --git a/posts/2022-07-05-what-would-dna-sound-if-synthesized.md b/posts/2022-07-05-what-would-dna-sound-if-synthesized.md
index a44b516..2d3afd9 100644
--- a/posts/2022-07-05-what-would-dna-sound-if-synthesized.md
+++ b/posts/2022-07-05-what-would-dna-sound-if-synthesized.md
@@ -18,7 +18,8 @@ Tags: []
18 2. [Mouse](#mouse) 18 2. [Mouse](#mouse)
19 3. [Bison](#bison) 19 3. [Bison](#bison)
20 4. [Taurus](#taurus) 20 4. [Taurus](#taurus)
218. [Going even further](#going-even-further) 218. [Making a drummer out of a DNA sequence](#making-a-drummer-out-of-a-dna-sequence)
229. [Going even further](#going-even-further)
22 23
23## Introduction 24## Introduction
24 25
@@ -228,6 +229,68 @@ This is part of a taurus genome `Bos_taurus.ARS-UCD1.2.cdna`. You can get [genom
228 229
229![Spectogram](/assets/dna-synthesized/taurus/spectogram.png) 230![Spectogram](/assets/dna-synthesized/taurus/spectogram.png)
230 231
232## Making a drummer out of a DNA sequence
233
234To make things even more interesting, I decided to send this data via MIDI to my [Elektron Model:Samples](https://www.elektron.se/en/model-samples). This is a really cool piece of equipment that supports MIDI in via USB and 3.5 mm audio jack.
235
236Elektron is connected to my MacBook via USB cable and audio out is patched to a Sony Bluetooth speaker I have that supports 3.5 mm audio in. Elektron doesn't have internal speakers.
237
238![](/assets/dna-synthesized/elektron/IMG_0619.jpg)
239
240![](/assets/dna-synthesized/elektron/IMG_0620.jpg)
241
242![](/assets/dna-synthesized/elektron/IMG_0622.jpg)
243
244For communicating with Elektron, I choose `pygame` Python module that has MIDI built in. With this, it was rather simple to send notes to the device. All I did was map MIDI notes to the actual Nucleotides.
245
246Before all of this I also checked Audio MIDI Setup app under MacOS and checked MIDI Studio by pressing ⌘-2.
247
248![](/assets/dna-synthesized/elektron/midi-studio.jpg)
249
250The whole script that parses and send notes to the Elektron looks like this.
251
252```python
253import pygame.midi
254import time
255
256pygame.midi.init()
257
258print(pygame.midi.get_default_output_id())
259print(pygame.midi.get_device_info(0))
260
261player = pygame.midi.Output(1)
262player.set_instrument(2)
263
264def send_note(note, velocity):
265 global player
266 player.note_on(note, velocity)
267 time.sleep(0.3)
268 player.note_off(note, velocity)
269
270
271nucleotide_midi_map = {
272 'A': 60,
273 'C': 90,
274 'G': 160,
275 'T': 180, # is D
276}
277
278with open("quote.fa") as f:
279 sequence = f.read().replace('\n', '')
280
281for nucleotide in [char for char in sequence]:
282 print("Playing nucleotide {} with MIDI note {}".format(
283 nucleotide, nucleotide_midi_map[nucleotide]))
284 send_note(nucleotide_midi_map[nucleotide], 127)
285
286del player
287pygame.midi.quit()
288```
289
290<video src="/assets/dna-synthesized/elektron/elektron.mp4" controls></video>
291
292All of this could be made much more interesting if I choose different instruments for different Nucleotides, or doing more funky stuff with Elektron. But for now, this should be enough. It is just a proof of concept. Something to play around with.
293
231## Going even further 294## Going even further
232 295
233As you probably notice, the end results are quite similar to each other. This is to be expected because we are operating only with 4 notes essentially. What could make this more interesting is using something like [Supercollider](https://supercollider.github.io/) to create more interesting sounds. By transposing notes or using effects based on repeated data in a sequence. Possibilities are endless. 296As you probably notice, the end results are quite similar to each other. This is to be expected because we are operating only with 4 notes essentially. What could make this more interesting is using something like [Supercollider](https://supercollider.github.io/) to create more interesting sounds. By transposing notes or using effects based on repeated data in a sequence. Possibilities are endless.