Metadata-Version: 2.4
Name: ungrave
Version: 0.1.0
Summary: Convert vector PDF scores to MusicXML by reading glyphs and paths (no OCR); Encore, MuseScore, Finale, Sibelius and Capella backends
Author: Jérôme Hénin
License-Expression: GPL-3.0-or-later
Project-URL: Homepage, https://github.com/jhenin/ungrave
Project-URL: Source, https://github.com/jhenin/ungrave
Project-URL: Issues, https://github.com/jhenin/ungrave/issues
Keywords: musicxml,pdf,sheet music,score,music21,notation,converter
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Multimedia :: Sound/Audio :: Conversion
Classifier: Topic :: Artistic Software
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pymupdf>=1.24
Requires-Dist: music21>=9.1
Requires-Dist: verovio>=4.0
Dynamic: license-file

# ungrave: bringing engraved music back to life

Convert vector PDF scores to **MusicXML** without optical recognition, by reversing the engraving process.

PDFs exported from notation programs are vector files. Notes, clefs and accidentals are
characters of an embedded music font placed at exact coordinates, and staff lines, stems, beams,
ties and hairpins are vector paths.
Music OCR tools (OMR) rasterize the vector file and then decode it using image recognition technology.
ungrave reads those glyphs and paths directly from the PDF and rebuilds the notation from them.
This is a much simpler task that runs quickly on any computer.

Supported source programs: Capella, Encore, Finale, MuseScore, and Sibelius.
The PDF must come straight from the notation program (exported, or printed to a PDF printer):
a scanned score has no glyphs to read.

## Install

ungrave needs Python 3.10 or later. Install it as a command-line tool with
[pipx](https://pipx.pypa.io) or [uv](https://docs.astral.sh/uv/):

```sh
pipx install ungrave
# or
uv tool install ungrave
```

Or, into the current Python environment, `pip install ungrave`.

To try it without installing anything, open the
[Colab notebook](https://colab.research.google.com/github/jhenin/ungrave/blob/master/examples/ungrave_colab.ipynb)
(needs a Google account; your PDF is uploaded to a temporary Google machine).

## Use

```sh
ungrave score.pdf                    # writes score.mxl
ungrave score.pdf -o out.musicxml    # plain (uncompressed) MusicXML, or another name
ungrave score.pdf -p 1-2             # only pages 1 to 2
ungrave score.pdf --source finale    # don't guess the source program
ungrave score.pdf --proof            # also writes score.proof.pdf, to check the result
ungrave score.pdf --no-breaks        # let the notation program lay the score out anew
```

Open the resulting `.mxl` file (compressed MusicXML) in MuseScore, Sibelius, Finale, Dorico or any
program that reads MusicXML.

The program that made the PDF is detected automatically; `--source` (`-s`) overrides it. With
`-p`, the whole PDF is still read (for time signatures, part names and ties across pages), but
only the requested pages are written.

ungrave never replaces a file it didn't write: if `score.mxl` already exists (for example the
MusicXML exported with the PDF), it stops and asks for another name (`-o`), or `--force`.

The result keeps the PDF's line and page breaks, so that it opens looking like the original.
`--no-breaks` leaves them out, for a new layout (other page size, larger staves, parts). Use it too
when the result lays out badly: a notation program may need more room than the original's program
for the same measures, and then splits systems and pushes pages.

`--proof` writes a PDF to check the result with: each page of the original, with the places
that raised a warning marked in red, next to the same page rendered from the result, and the
page's warnings listed below.

### Warnings

Warnings are printed while converting. Read them: they are the converter's self-checks, and point
to the places worth checking in the result.

- `mN: duration X != Y`: the notes in measure N don't add up to the time signature. This usually
  means a misread rhythm or an unknown symbol. It can also be in the source itself: Encore allows
  overfull measures, and some scores end with a shortened last measure.
- `A/B mN: notes at xX start at T1 and T2`: notes printed one above the other in two staves don't start
  at the same time in the result. A rhythm was misread in one of them, even though both measures add up.
- `unmatched arc`: a curve that could not be matched to notes as a tie or slur.
- `unknown glyph U+XXXX`: a music symbol the converter does not know, which is ignored.
- `lyric 'x' placed Npt from its note`: a syllable printed far from any note; check its placement.
- `N staves instead of M ...`: a system with hidden staves whose parts could not be identified.

## What is converted

- Staves, systems and barlines (single, double, final); any number of staves per system
- Part names and abbreviations from the staff labels. Systems that hide empty staves are matched to
  the parts by their labels, or else by clef and pitch range
- Staff groups: brackets and square brackets become part groups; braced staves (piano) become one
  part with several staves
- Clefs (treble, treble-8, bass, bass-8, C clefs), key signatures (including changes after a
  barline), time signatures (numbers, common and cut time, additive numerators such as 2+3+2/8)
- Notes and chords, accidentals (double ones too), dots, rests (whole-measure rests too); rhythm
  from beams, flags and tuplet numbers; beaming is written as printed
- Several voices on a staff (Finale layers, Sibelius and Capella voices), including voices that
  enter or leave mid-measure
- Ties (per note within chords, across system breaks, between voices) and slurs
- Lyrics with hyphenation and several verses
- Dynamics, hairpins, articulations (accent, staccato, staccatissimo, tenuto, marcato), fermatas,
  breath marks, with their placement above or below the staff
- Text expressions, dashed text lines ("rit. - - -"), rehearsal marks, metronome marks
- Title, subtitle, composer, lyricist and arranger from the page-1 header
- Repeat barlines and first/second endings (voltas)
- Early-music editions: unmetered measures (senza misura), breves, incipits (left out)
- Page size, margins, staff size, line and page breaks, and staves hidden in some systems, so that
  the result opens with a layout close to the PDF

## Current limits

- Not handled: segno and coda, D.C./D.S., clef changes inside a staff, grace and cue
  notes, ottava lines, chord symbols, multi-measure rests, lyric extender lines.
- Slurs from one staff to another are dropped (with a warning). A dashed text line continued across
  a system break becomes two lines.
- Tempo values that aren't printed (playback tempo) can't be recovered.
- Each source program has been tested on one or two scores. Symbols and layouts those scores don't
  use may be misread: watch the warnings.
- Encore: one voice per staff; slurs are not written. Its tolerances scale with the staff size but
  were fitted to one score.
- MuseScore: one voice per staff, and braces don't make braced (piano) parts yet.
  MuseScore 3 PDFs are untested.
- Finale: two stemless notes in two voices at one place come out as a chord; a third layer becomes
  voice 1 or 2.

## Contributing

Bug reports with a sample PDF help most. To work on the code, run the tests or add support for
another notation program, see
[CONTRIBUTING.md](https://github.com/jhenin/ungrave/blob/master/CONTRIBUTING.md).

## License

ungrave is free software, released under the GNU General Public License, version 3 or
(at your option) any later version. See [LICENSE](https://github.com/jhenin/ungrave/blob/master/LICENSE).
