Skip to main content

punchline

CLI tool to generate SVG punch cards (stripes with melodies) for a DIY music box from MIDI melodies.

Some basics:

  • SVG is a vector format of images, meaning that you can scale the image as much as you want and print it on any printer, pen plotter, or laser cutter.
  • MIDI is a sound format that instead of exact sounds describes which musical instruments should play which note at which moment. You can find a free MIDI file for any popular melody online.
  • DIY music box is a type of music box which instead of playing a predefined melody can play any melody from a paper stripe with holes in it. You can buy one online for a pretty low price.

Features:

  • Written on modern Python.
  • Has friendly CLI.
  • Well documented source code (if you really want to tweak something).
  • Highly configurable.
  • Has only necessary dependencies.
  • Automatically finds the best transposition.
  • Finds the best fit for notes that aren't present on the music box.
  • Supports all kinds of music boxes.
  • Works offline.
  • Detects notes that might be silent.
  • Laser cutter friendly output.

Installation

You'll need:

  1. Python version 3.9 or later
  2. pip
  3. Knowledge of how to use terminal.
python3.9 -m pip install punchline

Usage

Get help:

python3.9 -m punchline --help

Generate punch cards from 3rd track in SevenNationArmy.mid for 20-notes music box that supports sharp notes and save the result into "7nation" directory:

python3.9 -m punchline --input SevenNationArmy.mid --tracks 3 --sharps --notes-count 20 --output 7nation

The only required argument is --input. By default, it will generate stripes from all tracks for 15-notes non-sharp music box and store the result in the "output" directory.

You can find a few more examples in presets.md.

Editing tips

  1. You can use Inkscape to edit generated SVG images. It's free and powerful.
  2. To mass-edit a specific type of element:
    1. Select an element of this type
    2. Right-click on it.
    3. Open "Select same" menu.
    4. Select "Fill and stroke"
  3. Red circles indicate sounds that aren't perfectly fit on the music box. They are either in a different octave comparing to most of the other sounds or they are semitones (sharp notes) when your music box doesn't support semitones. Punchline tries its best to place them where it will sound OK but you may want to edit them or remove altogether.
  4. Pay attention to the outlined circles (filled with white instead of a color). They indicate sounds that are too close to the previous one on the same line. They might be silent because of limitations of the music box. You may want to decrease the --speed for the whole melody or manually move (or remove) colliding sounds. The minimal distance between circles (their centers) is configured by --min-distance.

Acknowledgments

  1. The initial implementation is based on punchbox.
  2. mido is used to read MIDI files.
  3. svg.py is used to generate SVG files.

Release files for punchline 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for punchline 1.4.0
File Size Uploaded
punchline-1.4.0.tar.gz 13.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for punchline 1.4.0
File Interpreter ABI Platform
punchline-1.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.0 kB

Release files / punchline-1.4.0.tar.gz

Download URL punchline-1.4.0.tar.gz
Size 13.9 kB
Tags Source
SHA-256 checksum
How to use checksums
017dd699a1a78920c1989c9e6d6b8fc6a58c3d563834d7ed29f3bd3a8087b4a9
BLAKE2b-256 checksum
How to use checksums
91459028d43e71e2c7ecc2bfaca6993176f16d8c3476b66f7cd3624a1d3c6a3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release files / punchline-1.4.0-py3-none-any.whl

Download URL punchline-1.4.0-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29936a1cf337e42c9c9d595497426a08b0b60ed3a15dce6c756686c8d1dedea0
BLAKE2b-256 checksum
How to use checksums
648e269ed9452839c99c5e2b8c314167cdfabf2cb136948baddd0ce333a47355
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.25.1

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page