A programming language where code is composed like music.
BitSonata is an almost Turing-complete programming language based entirely on musical structure. In BitSonata, writing a program means composing a song. Variables, expressions, control flow, and logic are expressed through melody, rhythm, harmony, and musical motifs.
Inspired by music theory and powered by abstract syntax trees, BitSonata is designed to be interpreted, expressive, and musical — your code doesn't just run… it plays.
To mix 2 of my passions, coding and music. Trying to turn computer science into art, and being able to enjoy CS
- 🗝️ Key-based scope: The code is key based, so it can be played in every possible instrument. It is possible to write the same code in 2 completly different keys
- 🎶 Variable declarations via rhythmic motifs.
- 🔁 Loops, conditions, and logic built from cadences, intervals, and phrasing.
- 🧠 Melodic arithmetic: Ascending = addition, descending = subtraction, and more.
- 🎼 Readable and musical output — you can literally listen to your code. (MuseScore website)
Follow these steps to get started with BitSonata:
-
Clone the repository
git clone https://github.com/yourusername/bitsonata.git cd bitsonata -
Install dependencies
pip install -r requirements.txt
-
Compose your code
- Use MuseScore or your preferred music notation software to compose your program as a music sheet or MIDI file.
- Save your composition in one of the supported formats (
.mxl,.musicxml,.xml,.mid,.midi).
-
Run the interpreter
python interpreter.py "path/to/your/music_sheet_or_midi"Replace
"path/to/your/music_sheet_or_midi"with the actual path to your file. -
Listen and enjoy
- The interpreter will process your musical code and execute it.
- You can listen to your code and see the output in your terminal.
Example:
python interpreter.py "examples/hello_world.mxl"💡 Tip: Try composing simple melodies to get started, then experiment with more complex musical structures to explore the full power of BitSonata!
Use for your BitSonata files:
.mxl.musicxml.xml.mid.midi
my_composition.mxl
It's been mainly tested with .mxl
- More freesom when composing
- for loops
- ELSE conditionals
- break statement
- array support
- Live interpreter with MIDI output
- Audio input for live performances (vibe coding at its mamximum exponent)
- Visual editor for composing, turns the music into pseudocode so it is easier to code
- Improve lexer so it allows more modes than major and minor
- More examples
- Web interpreter so everybody can use it online
- Company website
This project is licensed under the MIT License.
MIT License
Copyright (c) 2024 [Your Name]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
