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.txtfile. - Make the wanted changes to the code.
- Run
streamlit run main.pyin 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.txtfile. 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
pipreqsin the terminal. Therequirement.txtfile will now contain all imported packages.
-
-
Install the pyinstaller package in the virtual environment with your package manager.
-
Run
pyinstaller --onefile run.py --cleanin the terminal. This will generate arun.specfile in the directory. -
Add the following code in the beginning of the
run.specfile:
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/Libwith the path to thesite_packagesdirectory 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 --cleanin the terminal. In thedistdirectory, you will findrun.exe. -
To test the build, you need to copy any files used by the application into the
distdirectory (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
hiddenimportsvariable and runpyinstaller run.spec --cleanagain.
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.