Steven Engel: Engineering Portfolio
Music Score Writer (Python) Table of Contents
The Code: Summary
User Input Window
Sample Output
Areas For Future Improvement
​
Interests Table of Contents
Main Table of Contents

Music Score Writer (Python)
Summer 2021
I am interested in both playing music and writing code, so I decided to combine these interests into a fun project that I could teach myself the python programming language with. I developed a program that (based on user input) procedurally generates a solo piece for viola as a .mscx file and opens it in MuseScore, a popular music composition program.
​

The Code: Summary
The code for this project was written in Python 3 and the program itself is approximately 700 lines long. The first few lines of it are shown above. The following is a summary of the steps that occur in the program:
​
1. Creates and displays window with GUI for user input options.
2. When user clicks "Write Score", the information is saved in necessary program variables and modified from the raw user input where necessary.
3. Formatting information is written to the .mscx file of the name given by the user in the previous step. The .mcsx file has a structure similar to that of an xml file and is used to store score information such as the title, composer, copyright, instruments involved, and more. This varies based on the user's input.
4. After the preliminary information is written, the time signature, tempo, key signature, and notes themselves are written. The algorithm for writing the notes is a complicated system of weighted randoms for certain intervals and rhythms with other musical considerations involved. These considerations include but are not limited to instrument pitch range, key conformity, rhythmic repetition, a recurring theme of certain intervals, rhythms not exceeding measure length, and sprinkling in rests and accidentals.
5. Some final formatting information is added to the end of the file, the file is closed and saved, and the file is opened in MuseScore if MuseScore is open. The user may modify, print, or share their score from there.

User Input Window
This is the window where users can enter information to influence the creation of the score. When the window pops up, these default ("recommended") settings are displayed.
The Version, Program Version, and Program Revision refer to Musescore program data. The Composer Name and Work Title are self-explanatory and the user input here is printed at the top of the score. The filename is the name of the score file without the .mscx extension. The user can choose various other musical attributes, such as what instrument to write the solo for, the random range of how many measures the piece should have, the time and key signature (defined by number of sharps/flats), chance for any note to become a rest, chance for notes to conform to the key signature, the random range for the piece's tempo, and the chance for any given note to follow the piece's recurring theme.

Sample Output
A sample score using the default settings is shown to the left. This is a solo piece in G major with a time signature of 4/4 and a tempo of 96 beats per minute.
Areas For Future Improvement
In its current state, the program is useful for writing viola solos that could serve as good practice exercises. However, as with any engineering project, there are several areas where the program could be improved:
More Instruments
Not everybody plays viola and reads alto clef (in fact, few musicians do). Additionally, music "scores" rarely feature only one instrument; the program could be improved by adding support for more instruments and the ability to write a score featuring multiple instruments based on principals of harmony and chords. This would also be useful for instruments which read multiple clefs at once (like the piano, accordion).
More User-Friendly
If the program were intended for distribution to other users, it would be helpful to add features such as a detailed description of the effects of some of the user input options, error-checking for these inputs, the ability to change the directory where the file is saved, and the ability to directly import the necessary MuseScore program data.
Smarter Algorithm
While the current note-writing algorithm is well-suited for writing melodies and utilizing common interval-based themes throughout the piece, it has no big-picture understanding of the piece as a whole- instead, it literally writes note-by-note and "learns" from notes it has already written. This can lead to notes and rhythms occasionally feeling out of place in the "flow" of the piece to human ears. An addition to the algorithm which reviews what has already been written and applies various musical "corrections" would be helpful in this regard (and would make multi-part scores easier to implement).