Convert musical events to playable guitar tablature via DP optimization
Project description
tabsynth
Convert pre-detected musical events (notes and chords) into playable guitar tablature via candidate generation and dynamic programming optimization.
Overview
tabsynth is a production-ready Python package that transforms musical event data into optimized guitar tablature. It focuses on the synthesis and optimization of tablature from already-detected musical events—audio detection is out of scope.
Key Features
- Event-Based Input: Accepts
NoteEvent(single pitch) andChordEvent(multiple pitches) objects - Candidate Generation: Creates multiple playable fingering options for each event
- DP Optimization: Uses Viterbi-style dynamic programming to find the optimal sequence minimizing hand movement and difficulty
- Chord Template Matching: Built-in library of common chord shapes (open chords, barre chords)
- Multiple Output Formats: ASCII tablature, JSON, and compact text representations
- Extensible: Easy to add custom chord templates
Installation
pip install tabsynth
Or install from source:
cd tabsynth
pip install -e .
For development with tests:
pip install -e ".[dev]"
Quick Start
Basic Usage
from tabsynth import NoteEvent, ChordEvent, events_to_tablature
# Define some musical events
events = [
NoteEvent(pitch_hz=329.63, start=0.0, duration=0.5), # E4
NoteEvent(pitch_hz=369.99, start=0.5, duration=0.5), # F#4
NoteEvent(pitch_hz=392.00, start=1.0, duration=0.5), # G4
NoteEvent(pitch_hz=440.00, start=1.5, duration=0.5), # A4
]
# Convert to tablature
tablature = events_to_tablature(events, output_format="ascii")
print(tablature)
Working with Chords
from tabsynth import ChordEvent, events_to_tablature
# E major chord
chord = ChordEvent(
pitches_hz=[329.63, 415.30, 493.88], # E, G#, B
start=0.0,
duration=1.0
)
tablature = events_to_tablature([chord], output_format="ascii")
print(tablature)
Using the Pipeline API
from tabsynth import TabSynthPipeline, NoteEvent
# Create a pipeline with custom settings
pipeline = TabSynthPipeline(
max_fret=12,
tolerance_cents=50.0
)
# Process events
events = [NoteEvent(pitch_hz=440.0, start=0.0, duration=0.5)]
result = pipeline.process(events, output_format="json")
Command-Line Interface
The package includes a demo CLI:
# Show help
tabsynth help
# Run demos
tabsynth demo-notes
tabsynth demo-chords
tabsynth demo-mixed
Architecture
Data Flow
Events (Notes/Chords)
↓
Candidate Generation (multiple fingerings per event)
↓
Cost Calculation (hand position, stretch, barre difficulty)
↓
DP Optimization (Viterbi algorithm)
↓
Rendering (ASCII/JSON/Compact)
Core Components
- model.py: Data structures for events and playable states
- fretboard.py: Pitch helpers and fretboard modeling
- templates.py: Chord shape library
- candidates.py: Generate playable fingering candidates
- cost.py: Cost functions for transitions and states
- optimize.py: Dynamic programming optimizer
- render.py: Output formatting
- pipeline.py: End-to-end integration
Extending with Custom Chord Templates
You can add your own chord shapes:
from tabsynth import ChordTemplate, TabSynthPipeline
# Define a custom chord
my_chord = ChordTemplate(
id="D_major_open",
frets=[None, None, 0, 2, 3, 2], # Strings 6,5,4,3,2,1
barre=False,
pitch_classes={"D", "F#", "A"},
span=3,
tags={"open", "basic"}
)
# Use it in a pipeline
pipeline = TabSynthPipeline(templates=[my_chord])
Template Fields
- id: Unique identifier
- frets: List of 6 fret numbers or None (for strings 6→1)
- barre: Whether the chord requires barre technique
- pitch_classes: Set of note names in the chord
- span: Fret span (max - min among fretted notes)
- tags: Descriptive tags (e.g., "open", "barre", "E-shape")
Output Formats
ASCII Tablature
Guitar Tablature
========================================
e|0-5-7-5|
B|0-7-8-7|
G|1-6-7-6|
D|2-7-9-7|
A|2-7-9-7|
E|0-5-7-5|
Chords:
E_major_open
JSON
[
{
"index": 0,
"start": 0.0,
"duration": 0.5,
"kind": "note",
"strings": [1],
"frets": {"1": 5},
"mean_fret": 5.0,
"min_fret": 5,
"max_fret": 5,
"requires_barre": false,
"chord_id": null
}
]
Compact
0: t=0.00 note [1:5]
1: t=0.50 note [1:7]
2: t=1.00 E_major_open [6:0,5:2,4:2,3:1,2:0,1:0]
API Reference
Events
NoteEvent(pitch_hz: float, start: float, duration: float, confidence: float = 1.0)
ChordEvent(pitches_hz: list[float], start: float, duration: float, confidence: float = 1.0)
Pipeline
events_to_tablature(
events: list[Event],
output_format: "ascii" | "json" | "compact" = "ascii",
templates: list[ChordTemplate] = None,
max_fret: int = 15,
tolerance_cents: float = 50.0
) -> str
Optimization
optimize_sequence(
events: list[Event],
templates: list[ChordTemplate] = None,
max_fret: int = 15,
tolerance_cents: float = 50.0
) -> list[PlayableState]
Testing
Run tests with pytest:
pytest tabsynth/tests/
Tests cover:
- Fretboard and pitch calculations
- Candidate generation
- Optimization correctness
- End-to-end pipeline
Design Principles
- Minimal Dependencies: Core functionality requires only Python 3.10+
- Typed: Full type hints for better IDE support
- Extensible: Easy to add new chord templates and cost functions
- Focused: Audio detection is out of scope; assumes pre-detected events
- Optimized: DP algorithm ensures efficient fingering sequences
Limitations
- Audio detection not included: Requires pre-detected pitch events
- Standard tuning focus: Primary support for EADGBE tuning
- Template-based chords: Chord recognition relies on predefined templates
- No timing quantization: Preserves input event timing as-is
Contributing
To add new chord templates to the library:
- Define a
ChordTemplatewith accurate fret positions - Specify pitch classes and tags
- Add to
V1_TEMPLATESintemplates.py - Write tests to verify matching
License
MIT License - see LICENSE file for details.
Version
Current version: 0.1.0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tabsynth-1.0.4.tar.gz.
File metadata
- Download URL: tabsynth-1.0.4.tar.gz
- Upload date:
- Size: 19.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22855329051adecaef05423bd553a238a6329e95fe596298bfa6e99d3b1d8398
|
|
| MD5 |
14e2f1f6124360eb945c2dabbe9561b8
|
|
| BLAKE2b-256 |
65284b0657e55284b7ffb0d9e0bbbc74a8add879e4b3bd05474b56610184a199
|
Provenance
The following attestation bundles were made for tabsynth-1.0.4.tar.gz:
Publisher:
release.yml on AreteDriver/AI_GuitarTabs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tabsynth-1.0.4.tar.gz -
Subject digest:
22855329051adecaef05423bd553a238a6329e95fe596298bfa6e99d3b1d8398 - Sigstore transparency entry: 798187018
- Sigstore integration time:
-
Permalink:
AreteDriver/AI_GuitarTabs@f429b23f42627530990583c06d944782abf87ad0 -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/AreteDriver
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f429b23f42627530990583c06d944782abf87ad0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tabsynth-1.0.4-py3-none-any.whl.
File metadata
- Download URL: tabsynth-1.0.4-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
685656caedaa1b93f6d6135e1f6bbb6bfc6a753553b2cae36cce9ab2532519a4
|
|
| MD5 |
788c927ae99aa8f5f4c98d2063f994f5
|
|
| BLAKE2b-256 |
2a862ee679b96531613b5f41b735f66e339b7a4a447422fbe2802e118dc89fba
|
Provenance
The following attestation bundles were made for tabsynth-1.0.4-py3-none-any.whl:
Publisher:
release.yml on AreteDriver/AI_GuitarTabs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tabsynth-1.0.4-py3-none-any.whl -
Subject digest:
685656caedaa1b93f6d6135e1f6bbb6bfc6a753553b2cae36cce9ab2532519a4 - Sigstore transparency entry: 798187027
- Sigstore integration time:
-
Permalink:
AreteDriver/AI_GuitarTabs@f429b23f42627530990583c06d944782abf87ad0 -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/AreteDriver
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@f429b23f42627530990583c06d944782abf87ad0 -
Trigger Event:
push
-
Statement type: