Skip to content

Silly Sequencer assigns a random sample to each note of each channel of a MIDI file and outputs the resulting audio file.

Notifications You must be signed in to change notification settings

rklogan/Silly-Sequencer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Silly-Sequencer

Silly Sequencer assigns a random sample to each note of each channel of a MIDI file and outputs the resulting audio file. The samples are pitch shifted to the note specified in the MIDI file. Silly Sequencer is written in Python3.

Why do this?

Because we can. (And it's amusing.)

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

Python 3.x

Installation instructions can be found here

pip

While pip is not strictly required to run this project, the installation instructions contained here will use it. References to the dependencies' developer's instructions will be included if you do not wish to install pip. Installation instructions can be found here. Commands in this document use the default alias in BASH; substitute 'pip3' for 'pip' to use the default on Windows shells.

NumPy

NumPy can be installed using pip as follows:

pip3 install numpy

Otherwise, consult this link for further instructions.

Mido

Mido is a library for working with MIDI messages and ports. It can be installed with pip as follows:

pip3 install Mido

Otherwise, you can consult the Mido documentation

LibROSA

LibROSA is a python package for music and audio analysis. It can be installed with pip as follows:

pip3 install librosa

Alternative installation instructions can be found here

SoundFile

SoundFile is used to read and write sound files. It can be installed with pip as follows:

pip3 install PySoundFile

On Linux, you will additionally need to install libsndfile. Depending on your package manager this can be done with:

sudo apt-get install libsndfile1

You can consult the SoundFile documentation for further information.

Installing

Once the prerequisites are intalled, no further installation is required.

Usage

Provided Example

To run the provided example simply run the following in the top level directory of the repository:

python Silly_Sequencer.py

or

python3 Silly_Sequencer.py

depending on your alias configuration.

This will run Silly Sequencer with it's default parameters. It may take a minute for Silly Sequencer to complete it's execution, but will provide updates on the terminal as it progresses. Upon completion an audio file will be created for each track that was used in the MIDI example. In this case, it will generate three audio files that, when played together, will play the first 45 seconds of Queen's Bohemian Rhapsody.

General Usage

python Silly_Sequencer.py [sample_directory] [score] [output_directory] [gain] [verbose] [ignore_channel_ten]
  • sample_directory: The relative path to the directory containing the samples. To recreate the example, a value of 'Samples' (without quotation marks) could be used.
  • score: The relative path to the MIDI file that is to be processed. To recreate the example, a value of 'score.mid' (without quotation marks) could be used.
  • output_directory: The relative path to the directory to which the output audio should be written. Should the directory not exist, it will be created. Should it already contain audio files that match the track names of the MIDI file being process they will be OVERWRITTEN. To recreate the example, a value of 'Output' (without quotation marks) could be provided.
  • gain: This is the gain factor applied to all the samples. By default it is 0.2. Depending on the MIDI file being processed, and the number of samples that are playing simultaneously this may need to be adjusted to avoid clipping.
  • verbose: If a value of 'f', 'F', or 'False' is provided in this position, Silly Sequencer will only update the console if an error has occured. That is to say, it will not report it's progress on the terminal.
  • ignore_channel_ten: If a value of 't', 'T', or 'True' is provided in this position, Silly Sequencer will ignore all instructions on MIDI channel ten. This is useful when the convention of exclusively using channel ten for percussion has been followed. If any other parameter or no parameter is provided Silly Sequencer will process MIDI channel ten normally.

Thus, the example provided can be recreated with the command:

python3 Silly_Sequencer.py Samples score.mid Output 0.2 True False

All parameters listed above are positional and must be provided in the order presented above. Should the user wish to use later parameters without using earlier ones a value of 'None' can be passed to indicate to Silly Sequencer that the parameter should be ignored. For example:

python3 Silly_Sequencer.py None None new_output_directory

would use the default parameters for sample_directory, score, gain and verbose, but would instead write the output values to new_output_directory.

General Notes

  • Silly Sequencer produces rather chaotic music. Sample choice greatly effects the musicality of the output. For instance, in the provided example the gunshot sound effects are not noticeably effected by the pitch shifting and result, for the most part, in destroying the melodic structure (however amusing it might be).

  • Silly Sequencer will automatically select the sample rate for the audio files to be the same as the sample rate of the sample whose file name is first lexicographically. As such, all samples should have the same sample rate to avoid erroneous behaviour.

  • Silly Sequencer will work with mono and stereo samples. It has not been tested with samples that contain more than two audio channels.

  • If the Samples directory provided does not exist, the program will fail. Furthermore if the Samples directory is empty the program will also fail. Finally, the samples directory must contain EXCLUSIVELY audio files. The presence of any other type of file will cause failure. As per the limitations of the dependency SoundFile, Silly Sequencer fully supports WAV, FLAC and MAT files and has limited support for OGG files. See the SoundFile documentation for more details.

  • This version of Silly Sequencer does not acknowledge Note Off events, nor does it respond to Note On events with a velocity of 0 (which both usually indicate that the note should stop playing). When Silly Sequencer recieves a Note On event with non-zero velocity, it will play the entire sample, stopping only if the end point of the song has been reached.

  • There are a few scenarios where writing the audio files can fail:

    1. Silly Sequencer does not have permission to write to the output destination.
    2. Silly Sequencer is trying to write to files that are in use by another program.
    3. The track names in the MIDI file are not valid filenames for the OS.

    In the first two cases the user will be prompted to rectify the problem and then press enter to resume execution. In the third case the user will be prompted to enter a new filename for the track.

Built With

  • LibROSA - Used for audio analysis
  • Mido - Used to parse MIDI
  • NumPy - Required for other dependencies
  • SoundFile - Used for writing audio files

Example Samples Source

The provided test tones were generated using audiocheck's 'Sine Tone Generator'.
The MIDI file used in the example is a cropped version of the file found here.

Listed below is the source for the samples used in the example:

Authors

MIT License

Copyright <2019>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Silly Sequencer assigns a random sample to each note of each channel of a MIDI file and outputs the resulting audio file.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages