Making music with Code πŸ‘¨β€πŸ’»+🎸+πŸ₯=🎢 (Alan walker – Fade, song cover)

Back in high school, I was very much interested in music. I took music lessons for different instruments and played in the morning assembly daily. We had a variety of instruments and I was really into music more than anything else. Then we moved to a different city and although I took my instruments with me I couldn’t continue with my music lessons, and it stalled to a complete stop. We sold off the instruments and I just kept a keyboard 🎹 and would occasionally play it, which stopped working right NOW, during the COVID quarantine! Although nothing beats playing music on an instrument, I still tried playing some on my PC & using some software.

hardcore nerd πŸ€“ in the making 🀣

last music class 😒

I just found out about SuperCollider, it creates a server for audio synthesis. There’s another amazing tool, FoxDot which lets us write code for SuperCollider as we play it! It has a bunch of prepackaged instruments and a big collection to extend it. I’m having fun with this, and I think it’s worth checking even if you don’t like coding. It uses basic programming concepts like functions, loops, conditionals, etc, and lets you make some decent music. I tried to recreate one of Alan Walker’s tracks – Fade (just a random song).  

Disclaimer ⚠️ I’m just having fun with the code so it’s nowhere nearly as good as his song. Just added some guitar and drums, added a simple drop and it’s all just a few lines of Python Code 🐍.

πŸš§πŸš§πŸ›‘πŸ›‘πŸ›‘πŸ›‘βš οΈβš οΈβš οΈβš οΈπŸ›‘πŸ›‘πŸ›‘πŸ›‘πŸš§πŸš§

The code is not very clean πŸ˜› proceed with caution, it’s work in progress, I’ll be working on it later

import time as t # for sleep / delay between sounds

#speed of track
def setTempo(time):
    Clock.bpm=time #set tempo(its like speed of beats but not exactly speed)
    Clock.mod(16)

# guitar sounds and tracks
def guitar(fill1,fill2):
    if(fill1):
        #for slow guitar play in the music, with some echo
        #these nos are for keys, next number for next key viz. added on new lines for better understanding of keys
        p1>>pluck([0,0,0,2,5,5,5,4,2,2,2,2,0,-1,-1,-1,0],dur=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1/2,1/2],sus=1) 
    if(fill2): 
        #for the second overlapping guitar with double notes
        p2>>pluck([0,0,0,0,0,0,2,2,2,2,5,5,5,5,5,5,4,4,2,2,2,2,2,2,2,2,2,2,0,-1,-1,-1,-1,-1,-1,-1,0],dur=[1/2,1/2,1/2,1/2,1/2,1/2, 1/4,1/4,1/4,1/4, 1/2,1/2,1/2,1/2,1/2,1/2, 1/2,1/2, 1/2,1/2,1/2,1/2,1/2,1/2, 1/4,1/4,1/4,1/4, 1/2, 1/2,1/2,1/2,1/2,1/2,1/2, 1/4,1/4 ],amp=0.5,sus=3)

#beats for track
def regularBeat(preBeatDrop=2,trigger=True,ampp=4):
    if(trigger):
        p3>>play("x",dur=[preBeatDrop],amp=ampp)
    else:
        p3.stop()
    
#beats change before DROP    
def beforeDropBeat():
    regularBeat(1)
    t.sleep(16)
    regularBeat(1/2)
    t.sleep(8)
    regularBeat(1/4)
    t.sleep(6)
    regularBeat(1/8,True,4.5)
    t.sleep(4)
    regularBeat(0,True)

#track after the drop
def drop():
    guitar(1,0)
    p4>>play("x-",dur=[1/2,1/2],sample=[17,17],sus=5,amp=[4,1])

#stop music
def stop():
    Clock.clear()
    
#all components of song
def alanWalkerFaded():
    setTempo(80)
    guitar(1,0)
    t.sleep(16)
    guitar(1,1)
    t.sleep(8)
    regularBeat()
    t.sleep(2)
    beforeDropBeat()
    drop()
    t.sleep(40)
    stop()

#play the song !
alanWalkerFaded()

This code just plays the song, you can record it with any software. I usedΒ AudacityΒ to record and export it as an MP3 file. You canΒ downloadΒ it or listen to it here, in the player below.Β Link to complete file.

Will add more… thanks for checking out !

2 thoughts on “Making music with Code πŸ‘¨β€πŸ’»+🎸+πŸ₯=🎢 (Alan walker – Fade, song cover)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s