App-Music-ChordPro

 view release on metacpan or  search on metacpan

lib/ChordPro.pm  view on Meta::CPAN

	require ChordPro::Chords;
	ChordPro::Chords::dump_chords($dump_chords);
	exit 0;
    }

    if ( $clo->{filelist} ) {
	my @files;
	foreach ( @{ $clo->{filelist} } ) {
	    push( @files, "--filelist=" . qquote($_) );
	    my $dir = fn_dirname($_);
	    my $list = fs_load( $_, $clo );
	    push( @files, "--dir=" . qquote($dir) );
	    foreach ( @$list ) {
		next unless /\S/;
		next if /^#/;
		s/[\r\n]+$//;
		push( @files, $_ );
	    }
	    push( @files, "--filelist", "--dir" );
	}
	if ( @files ) {
	    if ( $files[0] =~ /\.pdf$/i ) {
		$options->{'front-matter'} //= $files[0];
		shift(@files);
	    }
	    if ( $files[-1] =~ /\.pdf$/i ) {
		$options->{'back-matter'} //= $files[-1];
		pop(@files);
	    }
	}
	unshift( @ARGV, @files ) if @files;
    }

    # At this point, there should be filename argument(s)
    # unless we're embedded or just dumping chords.
    app_usage(\*STDERR, 1)
      unless $::__EMBEDDED__
      || $clo->{'dump-chords'}
      || $clo->{'convert-config'}
      || @ARGV;

    # Return result.
    $options;
}

sub app_ident {
    my ($fh, $exit) = @_;
    print {$fh} ("This is ChordPro ",
		 $::options->{reference} ? "reference " : "core ",
		 $VERSION,
		 $VERSION =~ /_/ ? " (Unsupported development snapshot)" : "",
		 "\n"
		);
    exit $exit if defined $exit;
}

sub app_about {
    my ($fh, $level, $exit) = @_;

    if ( $level > 2 ) {
	require JSON::XS;
	select $fh; $| = 1;	# otherwise no output on MacOS
	print ${fh} ( JSON::XS->new->canonical->
		      # pretty->
		      utf8->convert_blessed->encode(runtime_info()) );
    }
    else {
	print ${fh} <<EndOfAbout,

ChordPro: A lyrics and chords formatting program.

ChordPro will read a text file containing the lyrics of one or many
songs plus chord information. ChordPro will then generate a
photo-ready, professional looking, impress-your-friends sheet-music
suitable for printing on your nearest printer.

To learn more about ChordPro, look for the man page or do
"chordpro --help" for the list of options.

For more information, see https://www.chordpro.org .

Run-time information:
EndOfAbout
      ::runtimeinfo( $level > 1 ? "extensive" : "normal" );
    }
    exit $exit if defined $exit;
}

use List::Util qw(uniq);

sub ::runtimeinfo {
    my $level = shift // "normal";
    my %i = %{runtime_info($level)};
    my $fmt0   = "  %-26.26s %-10s";
    my $fmt2   = $fmt0 . "\n";
    my $fmt3   = $fmt0 . " (%s)\n";

    my $msg;
    for ( $i{general}->{chordpro} ) {
	if ( $_->{aux} ) {
	    $msg = sprintf( $fmt3,
			    "ChordPro " . ($_->{type}//"core"), $_->{version},
			    $_->{aux} );
	}
	else {
	    $msg = sprintf( $fmt2,
			    "ChordPro " . ($_->{type}//"core"), $_->{version} );
	}
    }
    if ( $level eq "short" ) {	# used for PDF Creator info
	$msg =~ s/^\s+//;
	$msg =~ s/\s+/ /g;
	$msg =~ s/\n+$//;
	return $msg;
    }

    for ( $i{general}{perl} ) {
	$msg .= sprintf( $fmt3, "Perl", $_->{version}, $_->{dppath} );
    }

    for ( $i{general}{packager} ) {
	next unless defined;
	$msg .= sprintf( $fmt2, $_->{packager}." Packager", $_->{version} );

lib/ChordPro.pm  view on Meta::CPAN

    local $SIG{__WARN__} = sub {};
    local $SIG{__DIE__} = sub {};
    eval {
	require Wx;
	no strict 'subs';
	push( @p,
	      { name => "wxPerl",    version => $dd->($Wx::VERSION)  },
	      { name => "wxWidgets", version => $dd->($Wx::wxVERSION) } );
    } if $ENV{DISPLAY};

    $vv->("Storable");
    $vv->("Object::Pad");
    eval {
	require Text::Layout;
	$vv->("Text::Layout");
    };
    eval {
	require HarfBuzz::Shaper;
	$vv->("HarfBuzz::Shaper");
	$p[-1]->{library} = $dd->(HarfBuzz::Shaper::hb_version_string());
    };
    eval {
	require String::Interpolate::Named;
	$vv->("String::Interpolate::Named");
    };
    eval {
	require File::LoadLines;
	$vv->("File::LoadLines");
    };
    eval {
	require PDF::Builder;
	$vv->("PDF::Builder");
    };
    eval {
	require PDF::API2;
	$vv->("PDF::API2");
	eval {
	    require PDF::API2::XS;
	    $vv->("PDF::API2::XS");
	};
    };
    eval {
	require SVGPDF;
	$vv->("SVGPDF");
    };
    eval {
	require Font::TTF;
	$vv->("Font::TTF");
    };
    eval {
	require JavaScript::QuickJS;
	$vv->("JavaScript::QuickJS");
    };

    eval {
	require JSON::Relaxed;
	$vv->( "JSON::Relaxed" );
    };

    eval {
	require JSON::XS;
	$vv->("JSON::XS");
    };

    $res->{modules} = [ @p ];

    $res->{metadata} = $::config->{metadata}{keys};

    @p = ( qw(title subtitle),
	   ( grep { !/^(sub)?title$/ } sort(@{$::config->{metadata}{keys}//[]}) ),
	   grep { !/^(sub)?title$/ } (keys(%{ChordPro::Song::_directives()})) );
    $res->{directives} = [ @p ];

    $res->{directive_abbrevs} = ChordPro::Song::_directive_abbrevs();

    return $res;
}

sub splitpath {
    my ( $path ) = @_;
    return () unless $path;
    if ( $^O =~ /Win/ ) {
	return split( /;/, $path );
    }
    return split( /;/, $path );
}

sub app_usage {
    my ($fh, $exit) = @_;
    my %cfg;
    for ( qw( config userconfig sysconfig) ) {
	$cfg{$_} = $configs{$_} || "no default";
    }

    if ( $::options->{reference} ) {
	print ${fh} <<EndOfUsage;
Usage: $0 [ options ] [ file ... ]

Options:
    --[no]strict        Strict conformance
    --output=FILE  -o   Saves the output to FILE
    --about  -A         About ChordPro...
    --version  -V       Prints version and exits
    --help  -h          This message
    --ident             Show identification
    --verbose           Verbose information. Repeat for more.
EndOfUsage
	exit $exit if defined $exit;
	return;
    }

    ####TODO: weed out for --reference.
    print ${fh} <<EndOfUsage;
Usage: $0 [ options ] [ file ... ]

Options:
    --a2crd                       Perform text to ChordPro conversion only
    --noa2crd                     Do not auto-sense text to ChordPro conversion
    --about  -A                   About ChordPro...
    --back-matter=FILE            Add back matter pages from PDF document
    --config=JSON  --cfg          Config definitions (multiple)
    --cover=FILE                  Add cover pages from PDF document



( run in 0.538 second using v1.01-cache-2.11-cpan-437f7b0c052 )