DEV Community

Cover image for How does your code sound?
Edvinas Pranka
Edvinas Pranka

Posted on

How does your code sound?

As a developer, I love listening to music while coding. The orchestral music allows me to focus more on what I do. And one day I noticed my fingers dance on the keyboard by the music rhythm. Like playing the piano. Every word or symbol in the code was written with harmony. And then I thought... how it could sound... The code I write every day?

And the idea was born. ⭐

Go to live on soundcode.now.sh, put your code and enjoy how it sounds! 🎢

soundcode

How it works

Firstly, we load the sound fonts of the instruments which are used in this little orchestra. When you paste or write your code (or using our example), we parse it using the TypeScript AST parser to individual nodes. Then the composition begins.

The mood of the code

By code source, we determine the mood of the code. The more cheerful words in the code, the happier the mood and vice versa. The mood of the code is used to set the musical scale. If happy, a Major will be likely selected, if sad - Minor.

Chords

By the code source and with some easy math we choose which chords progression play from the determined musical scale.

The Melody of the piano

Each piano note is the TypeScript Token. With some math, we set the note, pitch, duration and time when to play. The special symbols like ,.+-/*, etc are excluded and used in the other instrument

Other instruments

Each instrument has its notes. Some just looping the notes of the chord, while others play specific notes by the source code. For example, the Cello always plays the active chord root note, when Harp only plays at the special characters or Chorus at the strings.

You can check the full source code in my GitHub repository epranka/soundcode

If you have ideas on how to improve it (new features, bugs and etc...) feel free to share it on the GitHub Issues.

Follow on Twitter, GitHub, and let’s connect on LinkedIn

Feedback and questions are appreciated.

Top comments (17)

Collapse
 
adrianbdesigns profile image
Adrian Bece

This is really cool. I really like how you determine how chords and instruments are played. Every code snippet I've tried sounded good. Great work!

Collapse
 
epranka profile image
Edvinas Pranka

Thanks :) Sometimes I play the piano, but I found that I play better with code :D

Collapse
 
vagoel profile image
Varun

What an idea !! Super cool.
Loved it ...

Collapse
 
epranka profile image
Edvinas Pranka

Thanks :)

Collapse
 
kimsean profile image
thedevkim

great! it looks like a motivational music.

Collapse
 
epranka profile image
Edvinas Pranka

Thanks!

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

This is phenomenal! I love it!

I'd just love to see some variation in the rhythm section and tempo between code snippets, perhaps based on frequency of whitespace or some such?

Collapse
 
epranka profile image
Edvinas Pranka

Thanks :) I'll think about it!

Collapse
 
miteshkamat27 profile image
Mitesh Kamat

That's awesome!!! Thanks for bringing in music

Collapse
 
epranka profile image
Edvinas Pranka

Thanks for feedback :) I always feel the passion to the music :)

Collapse
 
monfernape profile image
Usman Khalil

It's such a crazy idea. Loved it

Collapse
 
epranka profile image
Edvinas Pranka

Thanks :)

Collapse
 
supunkavinda profile image
Supun Kavinda

INNOVATIVE

Collapse
 
nombrekeff profile image
Keff

Cool stuff, I thought about doing something similar, but with the indentation of each line, every time i look at code it feels like a wave :)

Collapse
 
diek profile image
diek

Wow man, this is an awesome project. Really awesome!

Collapse
 
epranka profile image
Edvinas Pranka

Thanks! The feedback is very important to me :))

Collapse
 
epranka profile image
Edvinas Pranka

Thanks! What is Unzalgo? :D