Py Looper

by MattJ134 in Circuits > Linux

1698 Views, 8 Favorites, 0 Comments

Py Looper

Screenshot from 2023-08-17 20-59-39.png

Hi everyone! If you haven't seen my instructable on how to build your own Loop Station just like what Ed Sheeran uses then please go check it out (https://www.instructables.com/DIY-Chewie-Monsta-Looper-Based-on-Ed-Sheerans). I built my loop station about 5 years ago and it has worked great since. So what am I doing making new instructable about loop pedals? After thinking about it and despite how much I love what I've already built, I realized I didn't actually achieve my initial goal which was to create a "low cost" solution.

As you know, the "brain" of the loop station is the Mobius software from Circular Labs which is 100% free. It's a fantastic piece of software and I can't say enough good things about it. However, it is no longer supported and hasn't been updated since 2012. Also (and this is my main issue) it only runs on Windows which is hard for me because I'm a Linux guy. This means that you either need to have a laptop that you can "Frankenstein" and donate into the pedal or (in my case) you have to use your "everyday" laptop to run it. To me, this really negates the "low cost" of the solution. So to solve this problem I'd have to replace Mobius with something that can run on Linux.

So this instructable is going to cover "Part 1" which is getting some form of looping software running on Linux. My ultimate solution is going to run the looper software on a Raspberry Pi with a 10in screen built into the loop station but more to come on that. So if this sounds like something you might be interested in trying for yourself then read on.

Linux

Lets start with Linux. I'm going to assume that you already have some base knowledge on how to install and use Linux. There are lots of different Linux distribution that you can use and all should work with what I've built however I run Ubuntu 20.04 so that is what I'd recommend using if possible since I've tested it and know that it works. I tried to set it up on Ubuntu 22.04 and ran into issues with some of the newer python libraries. Also remember If you are running Fedora or an Arch linux distro then the package manager commands will be different to install the required apps/libraries.

Check out this link if you need help installing Ubuntu (https://ubuntu.com/tutorials/install-ubuntu-desktop#1-overview). I'm not going to go over it step by step but make sure you set it up with a user account that has "sudo" access.

Python

Screenshot from 2023-08-17 21-39-03.png
Screenshot from 2023-08-17 21-41-53.png

I chose Python as the text stack to write my looping software. Python is a very easily language to learn and has many powerful libraries. In this case, I used a library called PyAudio as the heart of the looping software. PyAudio is a cross-platform library that make it seamless to interface with audio devices connected to you computer. Python 3.8.10 is the version that runs on Ubuntu 20.04 and is that version that I have developed and tested Py Looper on so I recommend using it if possible.

While researching how to do this I did a lot of internet searches and ran across a You Tube video from "ThePsychotenuse" where he built something very close to what I was looking for except there was no screen for user feedback. However, I was able to take the base elements of how he recorded, overdubbed, and played back audio and built my solution around this. So I want to make sure I give credit where credit is due. Please check out his video (https://www.youtube.com/watch?v=S_rkdmCzIO0) and give him some awesome feedback.

So lets start with installing Python on your computer. Most Linux distros will probably have it installed by default but lets be sure. Also make sure you are running Python3 and not an older version.

open a "terminal" and run the following commands:

  • "sudo apt update" - This will update the package lists for your package manager to make sure you are using the latest.
  • "sudo apt upgrade" - This will install all package updates. Note: this may take several minutes.
  • "sudo apt install python3 -y" - This will download and install python. You will probably get a message saying the latest is already installed.
  • "sudo apt install python3-pip -y" - This will download and install the PIP manager which downloads and installs python libraries that we will need.


Now we can start loading the libraries that our software will need.

  • "sudo apt install python3-pyaudio -y" - This will install the core pyaudio libraries and dependencies.
  • "sudo apt install python3-tk -y" - This will install the Tkinter python library which is used to create all the GUI objects.
  • "sudo pip3 install numpy" - This will install the numpy python library. Numpy is used for tons of complex math and memory functions.
  • "sudo pip3 install py-midi" - This will install the py-midi python library used for the MIDI interface from the pedals.

Once all these are successfully installed you are ready to load and configure Py Looper!

Github Repo

Screenshot from 2023-08-17 22-21-25.png
Screenshot from 2023-08-17 22-26-07.png

Now that you are ready to install Py Looper, go to the Github repository (https://github.com/mjoseph81/py-looper) and download the project to your computer. Click the green "Code<>" button, select "HTTP", then click "Download ZIP"

Optional: If you want to use the command line git tools then run "gh repo clone mjoseph81/py-looper" to download the project.

Once downloaded and unzipped, you should have a folder called py-looper with two directories and 10 files in it.

Files:

  1. audio_plot.py - This isn't actually part of the project but it will record a 5 sec audio clip and then plot the waveform which is just cool. (Note: additional python libraries are required to run this script)
  2. audioloop_channels.py - Python script that contains the main class that handles the audio loop, recording, overdubbing, muting, and playback.
  3. configure_audio_settings.py - Python script that allows you to input the configuration settings for the audio setup.
  4. configure_channels_to_tracks.py - Python script that allows you to map specific input channels to specific tracks.
  5. configure_gui.py - Python script that allows you to set certain configuration options for the GUI.
  6. configure_midi_commands.py - Python script that allows you to set the MIDI control command bindings.
  7. get_latency.py - Python script that measures the latency through your audio device.
  8. get_my_devices.py - Python script that lists the audio interfaces connected to your computer.
  9. get_serial_ports.py - Python script that lists the serial devices connected to your computer.
  10. py-looper.py - Main Python script. This will be the file you run to start Py Looper.

Directory:

  1. Config - this directory contains the configuration files that are created from the "configure" scripts above. These files are loaded at startup by the py-looper.py script.
  2. audio_settings.conf - Output file that stores the input provided by configure_audio_settings.py.
  3. channels_to_tracks.conf - Output file that stores the input provided by configure_channels_to_tracks.py.
  4. gui.conf - Output file that stores the input provided by configure_gui.py.
  5. midi_commands.conf - Output file that stores the input provided by configure_midi_commands.py. If you want to run Py Looper without the MIDI interface then rename/remove this file.
  6. Arduino - This directory contains the Arduino sketch required to be loaded on the pedal HW. See Step 6

Collect Setup Info for Py Looper

Screenshot from 2023-08-19 09-18-20.png
Screenshot from 2023-08-19 09-17-53.png
Screenshot from 2023-08-19 20-12-43.png
Screenshot from 2023-08-19 20-23-29.png

Once the project is downloaded from github and unzipped, you need to run three python scripts in order to collect some configuration information that is required for the setup. Open a "terminal" window then "cd" into the directory where the files are located (ex. cd py-looper).

  1. Connect the audio interface to your computer via USB. Then in the terminal window type "sudo python3 get_my_devices.py" and note the output. At the bottom of the output it will list all the audio devices connected to your computer. Look for the one that describes your audio interface. In my case mine says "USB Audio Codec". If you are unsure which is yours then disconnect the audio interface and rerun the script and see which device disappears from the list. Once you indentify which device is the correct one take note of the "Input device ID" and the "Channels", you will need these later during the setup.
  2. Next, connect your MIDI device which in this case should be the Arduino controlling the pedals. Then in the terminal window type "sudo python3 get_serial_ports.py". Take note of the serial port listed which should be something like "/dev/ttyUSB0" or "/dev/ttyACM0". You will need this later during the setup.
  3. Finally, we need to measure the latency through the audio interface. Before you can do this step you need to configure the audio interface as described in the first bullet for Step 5. So do that step then come back and complete this step.
  4. connect one of the "output" channels of your audio device to one of the "input" channels. Then in the terminal window type "sudo python3 get_latency.py". This script will send some tones out your audio interface and record them as they loop back through. This will allow the script to measure the latency through your audio device. Press 'enter' at the prompt to begin the test. Once complete the script will ask if you want to update the audio_settings.conf file with the measured latency. Press 'y' to update the file.

Configure Py Looper

Screenshot from 2023-08-19 10-17-50.png
Screenshot from 2023-08-19 10-18-11.png
Screenshot from 2023-08-19 12-41-21.png
Screenshot from 2023-08-19 10-32-08.png

After collecting the required input data we can now run the configuration scripts for Py Looper. Again, open a "terminal" window then "cd" into the directory where the files are located (ex. cd py-looper).

  • In the terminal window type "sudo python3 configure_audio_settings.py". Several prompts will be displayed asking for input.
  • Sample Rate - The two most common options are 44100 or 48000. So far I have only used 48000 and have not had any issues. Type either "44100" or "48000" and press enter.
  • Buffer size - Enter one of the options. So far I have only use 1024 and have not had any issues. Type your option and press enter.
  • Latency correction - Enter any value initially. Once you complete inputting all the required info for this script, go back and complete Step 4 bullet 3. If you have issues running that script then any value around 50 should be good.
  • Input device index - Enter the "input device ID" value you received from the get_my_devices.py script and press enter. In my case mine was 6.
  • Output device index - This should be the same as your input device index.
  • Late button press - This is actually left over for the original source project I used. Just enter "500" and press enter.
  • Number of channels - Here you have the option to enter any number of channels you want between 1 and the number of channels you got from the get_my_devices.py script. Ideally you want to enter the value from the script as this will be the max number of audio input channels you can use in your looper.
  • Next, in the terminal window type "sudo python3 configure_channels_to_tracks.py". Several prompts will be displayed asking for input.
  • You will be prompted to enter the input channels that you want to map to each looper track. You can enter any combination of available input channels. If entering multiple channels then seperate them with a comma. In my case, I have 2 input channels (1 = mic, 2 = guitar). I only want the guitar to record on tracks 1 and 2 so I enter "2" and press enter. I want both channels to record on track 3 so I enter "1,2" and press enter. Then on track 4 I only want the mic so I enter "1" and press enter. You can configure your tracks with whatever works for you.
  • FULL DISCLOSURE: I only have a 2 channel audio interface so that is all I could test but Py Looper should work with as many channels as your device supports.
  • Next, in the terminal window type "sudo python3 configure_gui.py". Several prompts will be displayed asking for input.
  • You will be prompted to enter a "Name" for each track that will be displayed in the GUI. Enter any text you want and press enter.
  • Number of tracks to display - The GUI supports displaying between 2 and 4 tracks. I did this after I got so much feedback on the first loop pedal instructable to support 4 tracks so you're welcome.
  • Display GUI buttons - All of the pedal controls are represented as buttons on the GUI. This was mainly for testing purposed but if you have a use for them then enter "YES" to make the visibile. I don't use them during normal operation so I have mine set to "NO".
  • Finally, in the terminal window type "sudo python3 configure_midi_commands.py". Several prompts will be displayed asking for input.
  • You will be prompted to enter the MIDI command control number for each pedal. I'm assuming you will be using the Arduino code that I wrote for this project so I will list those values. If you are using a different midi device or writing your own them be sure the values are correct.
  • MODE = 90
  • RESET = 91
  • UNDO = 92
  • CLEAR = 82
  • REC/PLAY = 93
  • STOP = 94
  • TRACK 1 = 95
  • TRACK 2 = 96
  • TRACK 3 = 97
  • TRACK 4 = 98
  • Then you will be prompted to enter the "serial port" that your MIDI device is connected to. This will be the value you got from the get_serial_ports.py script (probably "/dev/ttyUSB0" or "/dev/ttyACM0". Type in the value and press enter.
  • Finally you will be prompted to specify if you want to enable support for the pedal LEDs (YES or NO). The code will support tricolor (Red/Green/Amber) LEDs for "MODE" and all four tracks. Arduino code v1.2.0 is required for this function to work.

Py Looper is now all setup and configured!

Arduino

For this project I reused the same loop pedal hardware that I built in the first instructable so check that one out if you want more details on it. However, to make the pedals work with Py Looper the arduino code was drastically simplified. In this version all the arduino does is monitor for button presses and send a single MIDI command for each button. There is no mode state or track state being tracked this time. It really as simple as it can possibly be.

I released version 1.2.1 which adds support for the LEDs on the pedal board so you can enable those if you want. Its not necessary since all the Mode and Track information is visualized in the GUI.

The Arduino code is also in the github repository that you already downloaded the python scripts from but here is the link again anyway.

If you aren't familiar with Arduino then I suggest you check out the link below to learn the basics.

Run Py Looper

Screenshot from 2023-08-20 19-05-22.png
Screenshot from 2023-08-17 20-56-15.png
Screenshot from 2023-08-17 20-56-43.png
Screenshot from 2023-08-17 20-56-55.png
Screenshot from 2023-08-17 20-57-15.png
Screenshot from 2023-08-17 20-57-24.png
Screenshot from 2023-08-17 20-57-30.png
Screenshot from 2023-08-17 20-57-37.png

Congratulations! Py Looper is now all setup and ready to use. You can now run the for Py Looper.

Again, open a "terminal" window then "cd" into the directory where the files are located (ex. cd py-looper) and run "sudo python3 py-looper.py".

The operation of Py Looper is the same as the v1.5 version of the Mobius based pedal in my first instructable. Here are the basics.

  • GUI
  • Control Frame - The frame on the left of Py Looper contains the controls and status information.
  • The first label tells you what MODE the loop station is currently in.
  • PLAY (Green) - indicates Playback mode
  • RECORD (Red) - indicates Record mode
  • The second label tells you which track is the "active track". The REC/PLAY button and X/STOP button only affect the "active track".
  • The remaining buttons are software versions of the physical pedals on the loop station and will take the same actions. These buttons will not be visible if you disabled the buttons in the configuration file.
  • Track Frames - Each track that is configured based on the input configuration will have its own track frame.
  • Loop Bar - This horizontal bar indicates the position of the track in the loop. It also changes color based on the state of the track.
  • RED - Record/Overdub
  • BLUE - Playback
  • GRAY - Muted
  • YELLOW - Armed (will be unmuted the next time the PLAY button is pressed)
  • Volume Bar - This vertical bar indicates the volume of the track during playback. It also changes color based on the state of the track.
  • RED - Record/Overdub
  • GREEN - Playback
  • GRAY - Muted
  • YELLOW - Armed (will be unmuted the next time the PLAY button is pressed)
  • Track Name - This is the name you gave to the track based on the configuration file
  • Track Button - This is a software version of the physical track pedal and will take the same action. This button will not be visible if you disabled the buttons in the configuration file.
  • Operation
  • Reset
  • After start up, Py Looper will be in the "RESET" state meaning no loops have been defined yet. Py Looper will return to this state when the "RESET" button is pressed which clears out all previously recorded loops.
  • Initial Loop
  • When in "RESET" mode, press the "MODE" button to put the software into "RECORD" mode.
  • You can record the initial loop be either pressing the "REC/PLAY" to record on the active track which in this state will always be TRACK 1 or you can press any of the TRACK buttons to record the initial loop on that track.
  • The initial loop is indicated by the Loop Bars for all tracks being Full and RED
  • The initial loop is closed by either pressing the "REC/PLAY" which will put all tracks into "PLAY" state except the active track which will be put into "OVERDUB". All Loop Bars will begin moving in sync and the Volume Bar on the recorded track will begin moving.
  • The only difference with closing the loop with a TRACK button is that the active track will also go to "PLAY".
  • Note: The initial loop is recorded to all tracks (indicated by the RED loop bars). This is done to guarantee that all tracks have exactly equal length. The non-active tracks record silence for this layer and won't show any volume after closing the initial loop.
  • Additional Loops
  • Now that the initial loop is created you can toggle between "OVERDUB" and "PLAY" on any of the tracks by pressing the TRACK button for that track.
  • Clear
  • Pressing the CLEAR button will delete all layers on the active track but will maintain the loop length.
  • Instant Multiply
  • Pressing the X/STOP button (in RECORD mode) will double the length of the active track and duplicate all layers that have already been recorded.
  • Playback/MUTE/ARM
  • Press the MODE button again to switch to "PLAY" mode.
  • Press any TRACK button to "MUTE" that track (indicated by gray loop and volume bars).
  • Press any TRACK button again to "ARM" the track (indicated by yellow loop and volume bars).. Tracks will only toggle between "ARM" and "MUTE". In order to unmute a track you must "ARM" the track then press REC/PLAY (in PLAY mode).
  • STOP
  • Press the STOP button to stop all tracks from playback (indicated by no volume or loop bars).
  • All tracks that were previously in "PLAY" mode (not muted) will be put into "ARM" mode so that only they will be restarted.
  • RESTART
  • When in "STOP" mode, press the REC/PLAY button to restart all tracks in "ARM" state. Tracks will play from the beginning of the loop regardless of where they were stopped.

That's about it. I hope you you enjoyed this instructable. Leave me a comment to let me know how your build is going. Happy looping!