Guitar Tablature
Gen can output guitar tablature (TAB) in two formats: MusicXML for notation software, and ASCII for terminal display.
MusicXML TAB
Use compile_to_tab() for MusicXML with TAB clef:
use gen::compile_to_tab;
let source = r#"---title: Guitar Rifftime-signature: 4/4---_E _G A B^C ^D ^E ^G"#;
let musicxml = compile_to_tab(source)?;The output includes:
- TAB clef (6-line staff)
- String numbers (1-6)
- Fret positions
- Rhythm notation
ASCII TAB
For terminal display, use compile_to_ascii_tab():
use gen::compile_to_ascii_tab;
let source = "C D E F G A B ^C";let tab = compile_to_ascii_tab(source)?;println!("{}", tab);Output:
e|------------------------0-|B|------------------0-1-----|G|------------0-2-----------|D|------0-2-----------------|A|--3-----------------------|E|--------------------------|Structured TAB Data
For programmatic access, use compile_to_tab_data():
use gen::compile_to_tab_data;
let source = "C D E F";let tab = compile_to_tab_data(source)?;
for measure in &tab.measures { for note in &measure.notes { if let Some(pos) = note.position { println!("String {}, Fret {}", pos.string, pos.fret); } }}Fingering Algorithm
The TAB generator uses an intelligent fingering algorithm:
Priority Order
- Open strings: Prefers notes that can be played open (fret 0)
- Same string continuation: Keeps consecutive notes on the same string when possible
- Look-ahead: Considers the next note to optimize hand position
- Fret proximity: Minimizes hand movement between notes
Example
For the C major scale C D E F G A B ^C:
| Note | String | Fret | Reasoning |
|---|---|---|---|
| C | 5 (A) | 3 | 3rd fret A string |
| D | 4 (D) | 0 | Open D string (preferred) |
| E | 4 (D) | 2 | Same string as previous |
| F | 4 (D) | 3 | Same string continuation |
| G | 3 (G) | 0 | Open G string |
| A | 3 (G) | 2 | Same string |
| B | 2 (B) | 0 | Open B string |
| ^C | 1 (e) | 0 | Open high E |
Standard Tuning
The TAB generator assumes standard 6-string guitar tuning:
| String | Note | MIDI |
|---|---|---|
| 1 (e) | E4 | 64 |
| 2 (B) | B3 | 59 |
| 3 (G) | G3 | 55 |
| 4 (D) | D3 | 50 |
| 5 (A) | A2 | 45 |
| 6 (E) | E2 | 40 |
Playable Range
Notes are mapped to positions within a reasonable fret range:
| Range | Fret Range |
|---|---|
| Low E (E2) to high E (E6) | Frets 0-24 |
Notes outside the guitar’s range will have no TAB position.
Example: Blues Riff
---title: Blues Rifftime-signature: 4/4key-signature: A---
_A _A ^C/ _A/ _A/ ^C _A_E _E _G/ _E/ _E/ _G _EASCII TAB output:
e|------------------------|------------------------|B|------------------------|------------------------|G|--2----2----2-2---------|------------------------|D|------------------2-----|--2----2----2-2---------|A|--0----0--------0-------|------------------2-----|E|------------------------|--0----0--------0-------|Limitations
- Standard tuning only: No alternate tunings currently supported
- Single notes: Chords are rendered as arpeggios (one note per position)
- No techniques: Bends, slides, hammer-ons, and pull-offs are not notated
- Range: Notes outside E2-E6 cannot be positioned
Tips
- Write in guitar-friendly ranges: Use
_and^to keep notes in the guitar’s range - Consider open strings: Melodies using open string notes (E, A, D, G, B) are easier to play
- Check the output: Review ASCII TAB to ensure playability before sharing
CLI Usage
From the command line:
# MusicXML TABcargo run -- --tab score.gen > score_tab.musicxml
# ASCII TABcargo run -- --ascii-tab score.gen