gregchapman-dev / converter21

A music21-based music notation file format converter CLI app, and some new sub converter plug-ins
Other
15 stars 1 forks source link

Demonstration materials? #12

Open alexandermorgan opened 1 month ago

alexandermorgan commented 1 month ago

This repo looks really interesting. Are there any demonstration materials available beyond the printout of the --help menu? A notebook, video, blog post, or anything else?

gregchapman-dev commented 1 month ago

Thank you! I have no videos/blog posts/notebooks specifically about converter21, sorry!

A good example client is musicdiff, where you can see in musicdiff/__init__.py how converter21 is registered with music21 so musicdiff can read Humdrum and MEI files more accurately (for better comparisons with things like MusicXML, which music21 reads very accurately).

I do have a blog post about musicdiff, which talks a little bit about converter21, if you're interested: musicdiff: a general purpose music notation diff tool

I saw from your comments in your music21 PR #1684 that you are particularly interested in Humdrum import. FWIW, I patterned my Humdrum reader after Verovio (and humlib, which Verovio uses). The Verovio/humlib code is as close to documentation of "Humdrum in 2024" as you can get. My Humdrum writer is patterned after the writing code in humlib, as well.

I would also say that emailing any questions to me (gregc@mac.com) is always welcome.

gregchapman-dev commented 1 month ago

Oh, another client is VerovioHumdrumViewer which, while it uses Verovio to read and display Humdrum files (and convert them to MEI), it uses converter21+music21 to convert from Humdrum to MusicXML (File/Save As MusicXML).

craigsapp commented 1 month ago

For Humdrum to MusicXML, I use a web service which is how the conversion on VHV is done with converter21 being run on the server. On the command line, the same interface is used in this script:

#!/usr/bin/env perl
# Programmer:     Craig Stuart Sapp <craig@ccrma.stanford.edu>
# Creation Date:  Mon 13 Sep 2021 11:06:35 AM PDT
# Last Modified:  Mon 13 Sep 2021 11:06:38 AM PDT
# Program Name:   humdrum2musicxml
# Syntax:         PERL 5
# Usage:          humdrum2musicxml file.krn > file.musicxml
# Usage:          cat file.krn | humdrum2musicxml > file.musicxml
#
# Description:    Converts Humdrum data into MusicXML data, using
#                 conversion interface at http://data.musicxml.humdrum.org
#
# To use LWP, you may need to run this command or related:
#       perl -MCPAN -e "install Bundle::LWP;"
#       dnf install 'perl(LWP::ConsoleLogger)'
#      

use strict;
use HTTP::Request::Common;
use LWP::UserAgent;
#use LWP::ConsoleLogger::Easy qw( debug_ua );

my $data;
my $line;
while ($line = <>) {
   $data .= "$line";
}

my $url = "https://data.musicxml.humdrum.org";
my $ua = LWP::UserAgent->new();
#debug_ua( $ua );
my $request = POST($url, ['inputdata', [$data]]);
my $content = $ua->request($request)->as_string();
#print STDERR $content;
my @lines = split(/\n/, $content);
my $emptyline = 0;
for (my $i=0; $i<@lines; $i++) {
        $line = $lines[$i];
        if (($line eq "") && !$emptyline ) {
                $emptyline = 1;
                next;
        }
        next if !$emptyline;
        print "$line\n";
}
alexandermorgan commented 1 month ago

Thanks for the info. I was able to get the tool working from the terminal to read and write kern. I was impressed to see that all three issues in reading kern my open pr to music21 fixes already appear to be handled well in converter21. But I was a little surprised that I wasn't able to produce mei output. I came across this comment in the code referring to mei: # NOTE: we're only working on import for now So I guess mei output is not supported yet despite the README saying there is an mei parser/writer.

I also pip installed converter21, and then in a script where I use music21 I imported both like this:

import music21
import converter21
converter21.register()

That executed without issue, but didn't seem to do anything since it doesn't bring the same improvements in reading kern files to the music21 representations of imported scores. It seems that I'm missing something but I think this shows that even an example as simple as the three lines above followed by the import of a piece would be very helpful.

craigsapp commented 1 month ago

Humdrum to MEI conversion will be more advanced via verovio:

git clone https://github.com/rism-digital/verovio
cd verovio/tools
git branch develop-humdrum
./.configure
make
sudo make install

The command to convert from Humdrum to MEI:

verovio file.krn -t mei

-t means --to. This will create file.mei. To use another name use the -o option:

verovio file.krn -t mei -o another_file.mei

If running from python, then capturing standard output might be useful:

verovio file.krn -t mei -o -

Converting multiple files in a bash shell (and probably zsh):

for file in *.krn
do
    echo Processing $file
    verovio $file -t mei
done

(There is also a python binding for verovio).

gregchapman-dev commented 1 month ago

I agree that Humdrum to MEI conversion is much better in verovio than in converter21. It makes sense that Craig's server code uses converter21 only for Humdrum to MusicXML conversion.

However, your "register converter21 and then read with music21" code should definitely get you all of converter21's benefits (read/write of Humdrum files and read/write of MEI files). It sounds like it got you none of converter21. @alexandermorgan, can you show more of your code, so I can figure out what's happening? (And yes, I need to write up some example code.)

gregchapman-dev commented 1 month ago

OUCH. I searched for that comment in converter21, and found it. And yes, I had the one line commented out that registers the MEI writer so music21 can use it. Let's hear it for lack of integration testing (all my MEI writing tests talk directly to the MEIWriter interface inside my converter).

The develop branch of converter21 has a fix; I will publish a release on pypi.com soon.

craigsapp commented 1 month ago

Also both of you (and others) may be interested in the update I made recently to https://github.com/humdrum-tools/humdrum-data, which now manages download of almost all of the Humdrum data that I know of on GitHub. Smaller datasets on kernScores are not on GitHub yet, though.

gregchapman-dev commented 1 month ago

@craigsapp That looks fantastic, thanks!

@alexandermorgan I have now released v3.1.1 on pypi.org, with the MEI writer enabled. But please do show me your code so I can figure out why you weren't getting the Humdrum import improvements.

alexandermorgan commented 1 month ago

@craigsapp, thanks for the build instructions and the heads-up about the humdrum data collection. I may have another dataset for that soon.

@gregchapman-dev, that was very fast. As for how I was trying to integrate this, I've worked on a few projects that use music21 for importing, and the CRIM Intervals repo is a good example. Here's where that project imports music21 (more precisely, they do from music21 import *).

How can this be adapted to use converter21? Once converter21 is registered, is there some variable we could inspect to confirm this, or any other indication that the registration worked?

gregchapman-dev commented 1 month ago

All that is required is a call to converter21.register() before you do any music21 conversions.

The only theory I have is that somehow the call to converter21.register() didn't actually happen, or that it happened after the conversion.