Skip to content

Instantly share code, notes, and snippets.

@pLabarta
Created January 26, 2020 14:55
Show Gist options
  • Select an option

  • Save pLabarta/27c6aeedba4cbc14f7332b06db88d4d6 to your computer and use it in GitHub Desktop.

Select an option

Save pLabarta/27c6aeedba4cbc14f7332b06db88d4d6 to your computer and use it in GitHub Desktop.
Decred Sounds (dcrdata + FoxDot experiment)
# The DCR blockchain music project is back!
# Powered by dcrdata.org API, FoxDot and Supercollider
Scale.default='minorPentatonic'; Root.default=0
#Drums
d4.stop()
d1 >> play('X ', dur=var([1/2, 1/8],[6,2]))
d2 >> play(' * ')
d4 >> play('X ', dur=1/2)
#bass
b1.reset() >> bass(var([0,1,-1,[-2,-3]],4), dur=PDur([8],16), drive=0.1,shape=0, oct=[5,6])
z1 >> saw(b1.pitch, dur=PDur([7,13],16), drive=0.1, shape=0.1, oct=P[5,[4,5],6,[5,7]]).every(4, 'stutter',4, dur=2, pan=[-1,1],oct=6)
z1.stop()
z2 >> dirt(b1.pitch, dur=PDur([10],16), oct=[5,6,7,5,5], shape=linvar([0.1,0.3],8), room=0.5).spread()
z3 >> jbass(b1.pitch, dur=PDur([8,13],16),shape=0.1, drive=0.1)
Group(p5).solo()
#DCR BlockchainPiano powered by dcrdata.org
def load_blockchain_piano():
last_hash = get_last_hash()
last_hash_decimal = Pattern([int(n,16) for n in last_hash.replace('0','')])
p5.reset() >> bass(var(last_hash_decimal[0:4].every(2,'mirror'),16), dur=PDur([8],16), sus=p5.dur, oct=[5,6,5,[5,7]], drive=0.1) + var([0,1,-1,-2],4)
Clock.future(64, λ: load_blockchain_piano())
load_blockchain_piano()
### Code & custom functions
import json
import requests
# Get last block from DCR Data
def get_last_block():
get_response = requests.get('https://dcrdata.decred.org/api/block/best/')
response_content = get_response.content
json_content = json.loads(response_content)
return(json_content)
#Get hash from that last block
def get_last_hash():
last_block = get_last_block()
last_block_hash = last_block['hash']
return last_block_hash
#Remove 0s from the hash and replace some sounds to trigger samples
def load_blockchain_drums():
p1 >> play(get_last_hash().replace('0','').replace('1','X').replace('3','-').replace('2','o').replace('4','r'), dur=1/4, room=0.4, mix=0.4).often(1, 'stutter',4, dur=1)
#p2 >> play('X ').offbeat()
#p3 >> saw(var([0,1,-2],[8,2,2]), cut=0.5, dur=[1/4], oct=(4,5))
#p4 >> saw(var([-1,2,-3],[8,2,2]), cut=0.5, dur=[1,1/2], delay=0.5)
Clock.future(72, lambda: load_blockchain_drums())
#Convert hash to decimal and use as notes on a scale to play a piano.
def load_blockchain_piano():
last_hash = get_last_hash()
last_hash_decimal = [int(n,16) for n in last_hash.replace('0','')]
p5 >> piano(last_hash_decimal, dur=[1/2,1/2, rest(1/2)], sus=1, oct=[4,5], formant=2).every(2, 'stutter',2, dur=3/2)
Clock.future(64, λ: load_blockchain_piano())
load_blockchain_piano()
Scale.default='major'
def load_blockchain_chords():
last_hash = get_last_hash()
last_hash_decimal = [int(n,16) for n in last_hash.replace('0','')]
chords = []
for each in last_hash_decimal:
chords.append((each, each+2, each+4))
p6 >> piano(chords, dur=4, sus=6, lpf=777)
Clock.future(64, λ: load_blockchain_chords())
load_blockchain_chords(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment