Skip to content

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 Riff
time-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

  1. Open strings: Prefers notes that can be played open (fret 0)
  2. Same string continuation: Keeps consecutive notes on the same string when possible
  3. Look-ahead: Considers the next note to optimize hand position
  4. Fret proximity: Minimizes hand movement between notes

Example

For the C major scale C D E F G A B ^C:

NoteStringFretReasoning
C5 (A)33rd fret A string
D4 (D)0Open D string (preferred)
E4 (D)2Same string as previous
F4 (D)3Same string continuation
G3 (G)0Open G string
A3 (G)2Same string
B2 (B)0Open B string
^C1 (e)0Open high E

Standard Tuning

The TAB generator assumes standard 6-string guitar tuning:

StringNoteMIDI
1 (e)E464
2 (B)B359
3 (G)G355
4 (D)D350
5 (A)A245
6 (E)E240

Playable Range

Notes are mapped to positions within a reasonable fret range:

RangeFret 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 Riff
time-signature: 4/4
key-signature: A
---
_A _A ^C/ _A/ _A/ ^C _A
_E _E _G/ _E/ _E/ _G _E

ASCII 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

  1. Write in guitar-friendly ranges: Use _ and ^ to keep notes in the guitar’s range
  2. Consider open strings: Melodies using open string notes (E, A, D, G, B) are easier to play
  3. Check the output: Review ASCII TAB to ensure playability before sharing

CLI Usage

From the command line:

Terminal window
# MusicXML TAB
cargo run -- --tab score.gen > score_tab.musicxml
# ASCII TAB
cargo run -- --ascii-tab score.gen