Getting Started - gammaspire/midichlorians GitHub Wiki
Editor's Note
This page is a comprehensive overview of how to pull this repository and install the necessary packages. Ideally, by the conclusion of my ramblings the reader will have properly initialized the system environment and set up their parameters file.
0. Install Anaconda
1. Cloning the repository
Yes, you must indeed have the code saved locally in order to run the GUI locally. After navigating to your preferred (local) directory, type the following in a terminal window to pull all files from my repository:
git clone https://github.com/gammaspire/midichlorians.git
2. Set up virtual environment
Among the ostensible clutter will be a textfile named "requirements_soni.txt", which contains every package+version that that the GUI requires in order to run successfully. I would argue that one of the least involved approaches to ensuring you have the correct versions while simultaneously not affecting the versions you use for other projects is to create a conda virtual environment. In a conda terminal,
conda create -n name_of_env python=3.8.0
conda activate name_of_env
Now that you are in your new virtual environment, which you have hopefully named to be different than "name_of_env", you should go to the location of the MIDIchlorians files (in particular where the requirements_soni.txt file lies) and type the following to install all packages:
conda install pip
pip install -r requirements.txt
In the event that a package does not successfully install or a package cannot be found/imported when trying to save a .wav file, such as with fluidsynth (I do type from experience...), you can try to install it manually using conda-forge:
conda install -c conda-forge fluidsynth
3. (OPTIONAL) Install ffmpeg
One feature of the GUI interface is the ability to overlay a .mp4 with the .wav file (see saved_mp4files/example.mp4). Generating this matplotlib animation requires the installation of the ffmpeg executable, which the python wrapper calls on in the script. You can download ffmpeg from here. Then, unzip and move the executable (its icon should resemble a terminal window) to a desired location, such as your Downloads or Applications directory. Be sure you remember where you place it, because you will need the path for your params.txt file.
4. Configuring the params.txt file
Nice segue, huh? Also in the github repository is a params.txt file, which helps keep the GUI code generalized. You can specify the paths to ffmpeg, a default directory where your FITS images are, the path to where you are keeping the github repository locally, the path to the soundfont, and the desired window geometry for the GUI interface. Be sure to edit this file before running the code!
Brief note on soundfonts: there are innumerable soundfonts available online, which are effectively the conversion maps between a MIDI number and the instrumental sound when downloading your results as a WAV file. I quite enjoy using some of the vintage GBA game soundfonts, but you are welcome to try any option you find suitable.
And a final note: if you are not sure what the full path is to a certain directory that you are located in, go to your terminal window and type pwd. This will print the exact path that you should paste into your params.txt.
5. (OPTIONAL) Editing the midi2audio source code
When playing the MIDI audio in the GUI, I noticed that the volume was quite low. FluidSynth (the executable for which the midi2audio package is a wrapper) does have an optional argument, "gain," which can dictate the master volume of the WAV output; however, I noticed that the source code's class doesn't properly incorporate the gain argument. If you find that you are experiencing similar complications, I include here an optional fix:
- find midi2audio.py in /Users/[your_username]/anaconda3/envs/[your_env_name]/lib/python3.8/site-packages
- then edit init with the following:
def __init__(self, sound_font=DEFAULT_SOUND_FONT, gain=gain, sample_rate=DEFAULT_SAMPLE_RATE):self.sample_rate = sample_rateself.sound_font = os.path.expanduser(sound_font)def midi_to_audio(self, midi_file, audio_file):subprocess.call(['fluidsynth', '-ni', self.sound_font, midi_file, '-F', audio_file, '-r',str(self.sample_rate), '-g', str(gain)])def play_midi(self, midi_file):subprocess.call(['fluidsynth', '-i', self.sound_font, midi_file, '-r', str(self.sample_rate), '-g', str(gain)])
Not all of these lines are edited; I simply included them for context.
6. Is it done?
And now, testing time. Navigate to your MIDIchlorians directory, activate your sparkly new conda environment, and type
python midigui.py -params params.txt
If all goes well, the GUI window should appear after the 5-10 seconds that pygame needs to load (silly pygame).