Skip to content

Create real-time audio and midi visualizations on led strips using Arduino and Python.

License

Notifications You must be signed in to change notification settings

tfrere/music-to-led-server

Repository files navigation

Licence Platform support Last update Current version

This repository is a part from the music to led project.

Table of contents

Installation

Binary

First, download binary file that can be downloaded here

./musicToLedServer --help

-h, --help            show this help message and exit
-l, --list-devices    list available devices
--test-audio-device TEST_AUDIO_DEVICE
                      Test a given audio port.
--test-midi-device TEST_MIDI_DEVICE
                      Test a given midi port.
--test-serial-device TEST_SERIAL_DEVICE
                      Test a given serial port. This will test your arduino / led installation by
                      displaying three ( red green bue ) pixels and make them roll on the strip.
--test-config-file TEST_CONFIG_FILE
                      Test a given config file.
--single-strip SINGLE_STRIP
                      Launch the first strip without gui and multiprocessing.
                      It's for testing purpose.
--with-config-file WITH_CONFIG_FILE
                      Launch with spectific config file. Default one is
                      CONFIG.yml just near the executable.

Shell interface

launch

Arduino part

Build an arduino case

Once the wiring is finished and your code uploaded, you can test it following these simple steps :

    1. Connect the arduino to your computer through usb cable
    1. run ./musicToLedServer --list-devices and find the corresponding usb name
    1. run ./musicToLedServer --test-serial-device "YOUR CORRESPONDING USB NAME"

Configuration

This program will use Audio ports, Midi ports and Serial ports.

To help you to configure your CONFIG.yml correctly, there is a little helper that will list all available ports for each of them.

./musicToLedServer --list-devices

Audio channels

This program is streaming audio from the default audio input device (set by the operating system).

Examples of typical audio sources:

  • Audio cable connected to the audio input jack (requires USB sound card on Raspberry Pi)
  • Webcam microphone, headset, studio recording microphone, etc

On OSX you have the "Built-In Microphone" as a default choice.

Virtual audio sources

You can use a "virtual audio device" to transfer audio playback from one application to another. This means that you can play music on your computer and connect the playback directly into the program.

Linux

Linux users can use Jack Audio to create a virtual audio device.

OSX

On OSX, Loopback can be use to create a virtual audio device. For open source alternatives, you can use Soundflower and Jack Audio

Midi channels

This program is streaming midi from the default midi input device (set by the operating system).

Virtual MIDI Sources

On OSX, it's pretty easy to make some virtual MIDI channels.

Example for using them with ableton live :

osx-midi-settings

To virtually test MIDI, you can use VMPK. It's a virtual midi keyboard right in your operating system.

CONFIG.yml

You can validate the config file with

./musicToLedServer --test-config-file "./CONFIG.yml"

Sample config file

--- # document start

# Desired framerate for all the strips

desirated_framerate: 60

# Display the GUI
# For performance reasons, please consider using GUI only for debug or work purpose

display_interface: true

# Audio ports
# List of used audio ports
# Available ports can be listed with --list-devices
# Can be changed with the option "Change audio channel"

audio_ports:
  - name: Built-in Microphone
    min_frequency: 200
    max_frequency: 12000

# Strips
# They represents independant Arduino cases

strips:
  - # Name of the strip
    # Only used in the GUI

    name: Led strip name

    # Name of the associated serial port
    # Available ports can be found with --list-devices

    serial_port_name: /dev/tty.usbserial-14210

    # Midi channels
    # Can be listed with --list-devices
    # midi_ports_for_visualization : used for midi based visualizers
    # midi_ports_for_changing_mode : used for live changing modes

    midi_ports_for_visualization:
      - USB MIDI Interface
    midi_ports_for_changing_mode:
      - LPK25

    # Default state that have to be used on start up

    active_state_index: 0

    # Physical shape
    # Represents the physical shape of the strip
    # Only used in the GUI

    physical_shape:
      - 254

# States
# These are default states for strips
# They contains all the variables that the visualizer need to run properly

states:
  - # Name of the strip
    # Only used in the GUI

    name: 'Mirrored Energy light blue'

    # Visualizer function
    # These functions can be found in the documentation below

    active_visualizer_effect: energy

    # The propagation curve is used to determine how scroll propagation will
    # work

    active_propagation_curve: ease_in

    # Default audio channel

    active_audio_channel_index: 0

    # Filters

    audio_channel_min_frequency: 200
    audio_channel_max_frequency: 12000

    # Shapes
    # Represents virtual shape that are used by the visualizer
    # Be sure they not contains odd numbers

    shapes:
      - - 50
        - 50

    # Active shape index
    # Determine what shape have to be used

    active_shape_index: 0

    # Available color schemes
    # Can be changed via "Change color scheme" function
    #
    # You can call them using hexadecimal notation or using a real name according
    # to the color list that can be found below ->
    # python-app/helpers/color/colorSchemeFormatter.py

    color_schemes:
      - - '#FF0000'
        - '#00FF00'
        - '#0000FF'
      - - red
        - green
        - blue

    # Active color scheme index
    # Determine what color scheme have to be used

    active_color_scheme_index: 0

    # Maximum allowed brightness
    # Can be used to limit the power consumption
    # Check the Arduino part readme for more informations about it

    max_brightness: 255

    # Reverse and mirror mods

    is_reverse: false
    is_mirror: false

    # Time interval value that is used in time based visualizers

    time_interval: 120

    # Chunk size used in alternate colors

    chunk_size: 5
... # document end

Effects & Modes

Music To Led has 16 visualization effects and 8 mods.

They can be live changed via dedicated Midi channels. You can choose to use programs like Ableton Live to automate these changes or use a dedicated synthetiser / pad to change them manually during the show.

Big principle You have to send a midi note signal for activating / modifying effects. See the doc below.

Effects

All the examples are based on a ["red", "green", "blue"] color scheme.

Sound based

Example Midi Note Effect name Explanation
C-2 scroll Split the sound samples into N parts according to the color number in the color scheme. Then mix theses colors according to the sound samples intensity. Then scroll the strip to the right.

  • Speed time_interval
C#-2 energy Split the sound samples into N parts according to the color number of color scheme. Then make them appear all along the strip with a length based on sample intensity and mixed with others.
D-2 channel_intensity Split the sound samples into N parts according to the shape parts length. Then draw a line with a length based on sample intensity with the first color of the color scheme. Then add a pixel on top on max intensity with the second color of the color scheme if available.

  • color first and second color of the scheme
D#-2 channel_flash Split the sound samples into N parts according to the shape parts length. Then illuminate the shape part with an brightness based on sample intensity.

  • color Repeating the color scheme
F-2 spectrum Represents audio spectrum

Midi based

Example Midi Note Effect name Params
F#-2 piano_scroll Make a smooth scrolled light based on the note you play.

  • color Index in color scheme according to the number of notes you are playing at the same time.
TO ADD G-2 piano_note Make a light appear based on the position where you typed on the keyboard.

  • color Index in color scheme according to the number of notes you are playing at the same time.
G#-2 pitchwheel_flash Make the whole strip illuminates according to the pitch bend intensity of your keyboard. Begin on a black strip.

  • brightness Based on pitchbend.
  • color First color of the scheme.

Time based

Example Midi Note Effect name Params
A#-2 alternate_color_chunks Make a pattern with chunks of colors scrolling to the right.

  • chunk_size Size of a chunk
  • color Repeated color scheme
  • time_interval Relative speed of the scroll
B-2 alternate_color_shapes Make chunks of colors with size based on shapes.

  • chunk_size Based on shape
  • color Repeated color scheme
  • time_interval Relative speed of the scroll
TO DO C-1 transition_color_shapes Make the whole strip illuminates with a smooth color transition.

  • color First color of the scheme
TO DO C#-1 draw_line Draw a line.

  • chunk_size Based on shape
  • color First color in the scheme
  • time_interval Relative speed of the scroll

Generic

Example Midi Note Effect name Params
D#-1 full Illuminates the whole strip with the first color in your active color scheme.

  • color First color in the scheme
E-1 fade_to_nothing Stop current visualization. Then slowly fade to black the whole strip.
F-1 clear Stop current visualization. Instant clear of the frame.
F#-1 fire A beautiful fire. Based on nothing for the moment.

Modes

Example Midi Note Mode name Params
G#-1 toggle_reverse_mode Toggle reverse effect on the strip.
A-1 toggle_mirror_mode Toggle mirror effect on the strip.
A#-1 change_shape Change active shape.

  • The chosen shape is based on the note's velocity. If the note's velocity is higher than the shapes parameter length, take the next shape.
B-1 change_color_scheme Change active color scheme.

  • The chosen color scheme is based on the note's velocity. If the note's velocity is higher than the color schemes parameter length, take the next color scheme.
C-0 change audio_channel Change active audio_channel.

  • The chosen audio_channel is based on the note's velocity. If the note's velocity is higher than the audio_channels parameter length, take the next audio_channel.
C#-0 change_time_interval in ms Change active time_interval.

  • The chosen time_interval is based on the note's velocity.
D-0 change_max_Brightness Change active max_brightness.

  • The chosen max_brightness is based on the note's velocity. If the note's velocity is higher than 255, take 255.
D#-0 change_chunk_size Change active max_brightness.

  • The chosen chunk_size is based on the note's velocity.
D#-0 change_state Change active state.

  • The chosen state is based on the note's velocity. If the note's velocity is higher than the states parameter length, take the next state.

Contribute

If you have any idea to improve this project or any problem using this, please feel free to upload an issue.

Future Roadmap

  • Plug and play feature on all ports
  • Effect blender
  • Handling more than the WS2812B led strip
  • DMX handling ?

Python installlation for developement purpose

Code is compatible with Python 3.7.

# on mint and for linux more generally you may have to install jack before
# apt-get install libjack-dev libasound2-dev
conda env create --name music-to-led-server --file environment.yml

conda activate music-to-led-server

Deploy on raspberrypi

For Raspberry Pi it has been tested on Raspberry 4, the 4go ram version. On Debian Buster.

Here are some conf file you can add to your debian mounted sd card to automate wifi and ssh stuff.

Wifi automation

wpa_supplicant.conf

country=US # Your 2-digit country code
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
network={
ssid="YOUR_NETWORK_NAME"
psk="YOUR_PASSWORD"
key_mgmt=WPA-PSK
}

SSH auto enabling

touch ssh

Installation

git clone http://github.com/tfrere/music-to-led-server
pip3 install -r requirements.txt
pip3 install mido
sudo apt-get install python3-pyaudio
sudo apt-get install python3-rtmidi
sudo apt-get install libatlas-base-dev
sudo apt-get install python3-numpy

Licence

This project was developed by Thibaud FRERE on MIT Licence.

Contribute

If you encounter any problems running program, please open a new issue. Also, please consider opening an issue if you have any questions or suggestions for improving the installation process.

About

Create real-time audio and midi visualizations on led strips using Arduino and Python.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published