MusicTools is a small application for generating music, consisting of currently two tools: Scale Explorer and Melody Creator.
Scale Explorer uses a binary system for defining scales, inspired by A study of musical scales by Ian Ring.
Here are the features:
- Pick a scale by turning on and off bits and selecting a root note.
- Easily find chords within the scale.
- Listen to playback of both chord and scale.
- Copy the chord or scale into Melody Creator.
- Rotate to find scales within the same family or to invert chords.
- View chord name and scale name in the sidebar.
Melody Creator uses mathematical expressions to generate melodies.
Here are the features:
- Select time signature, tempo, length, and scale.
- Create reusable expressions, each assigned a letter from A-Z.
- View the reusable expressions as graphs.
- Define note pitch, duration, velocity, and type by expressions.
- Listen to playback of the generated melody.
- Save and load melodies to/from MIDI.
This is for people who want to make alterations to the code of the program.
- Pull the repository unto your computer with Git or download it from GitHub.
- Setup a virtual environment in the root directory of the project.
- Enter the virtual environment in your IDE and the terminal.
- Use a package manager like pip to install the packages in the
requirements.txt
file. - Make the wanted changes to the code.
- Run
streamlit run main.py
in the terminal to test the changes.
These instructions assume that you've done the steps under Making Changes.
-
If your changes uses any new packages not from the standard library, these must be added to the
requirements.txt
file. If you've added a lot of imports, you can use the pipreqs package to collect the requirements.-
Install pipreqs in the virtual environment with your package manager.
-
Run
pipreqs
in the terminal. Therequirement.txt
file will now contain all imported packages.
-
-
Install the pyinstaller package in the virtual environment with your package manager.
-
Run
pyinstaller --onefile run.py --clean
in the terminal. This will generate arun.spec
file in the directory. -
Add the following code in the beginning of the
run.spec
file:
from PyInstaller.utils.hooks import collect_data_files, copy_metadata
datas = [("project_env/Lib/site-packages/streamlit/runtime", "./streamlit/runtime")]
datas += collect_data_files("streamlit")
datas += copy_metadata("streamlit")
-
Replace
project_env/Lib
with the path to thesite_packages
directory in your virtual environment directory. -
In
run.spec
, set pathex to this:
a = Analysis(
...
pathex=["."],
...
)
- In
run.spec
, write all imports underhiddenimports
. For example:
a = Analysis(
...
hiddenimports=["midiutil", "mido", "numpy", "plotly", "pygame", "pyperclip", "st_pages", "streamlit", "streamlit_extras.switch_page_button", "filedialogs"],
...
)
-
Run
pyinstaller run.spec --clean
in the terminal. In thedist
directory, you will findrun.exe
. -
To test the build, you need to copy any files used by the application into the
dist
directory (while maintaining their original directory structure). By default it should look like this:
dist/
├─ lib/
├─ pages/
├─ res/
├─ main.py
├─ license.txt
├─ run.exe
-
Now go ahead and run
run.exe
. The application should start now. -
If you get an error that an import is missing, add it to the
hiddenimports
variable and runpyinstaller run.spec --clean
again.
If something still isn't working, feel free to let me know. I will gladly try to help you out.
If you want to more easily distribute your version, you can use something like Inno Setup to create an installer.
Just make sure the structure of the dist
directory is maintained when installing.