AJ | Pact | logo
Prism Fission

Prism Fission

9 September 2017

CreativePact (13 posts)

In this CreativePact, following a couple of months in the creative doldrums, I will be working to complete Prism Exhilarated, a unique media music release by ‑otron.

Prism in Python - venv and arguments

AJ Pact | Prism Fission | Prism in Python - venv and arguments

And the Pact begins! Thinking that the Python Audio Engine for Prism Exhilarated is clearly the biggest item on the list I got going setting up the Python project.

This process begun by creating a Python virtual environment (using these instructions), which effectively encapsulates a project, along with its dependencies and specific version of Python (3.6.2, in my case), into its own environment. That way, multiple Python projects can exist alongside but not interfere with one another.

Next came installing dependencies, and the most important by far (and the reason I chose Python for this project in the first place) is the audio library this playback engine will run on: pydub. Installing dependencies in Python is easy, using the pip package manager.

Then down to business: starting on the code. I set up a file called prism.py (nice and short as Python makes heavy use of the command line) and decided to focus on script calling and command line options. Python's handy argparse module was useful here, allowing me to set up logic routes for the following commands:

  • -i / --info: Print album info to the screen
  • -c / --check: Check the structure of a single track or the whole album
  • -a / --album: Play the whole album, specifying either a particular rendition or letting the script choose at random
  • -t / --track: Play a chosen track, specifying either a particular rendition or letting the script choose at random

I managed to get that coded up today, with just enough time to set up my Git repository.