App-Music-ChordPro

 view release on metacpan or  search on metacpan

lib/ChordPro.pm  view on Meta::CPAN

sub xximport {
    # Add private library.
    my $lib = CP->privlib;
    for ( @INC ) {
	return if $_ eq $lib;
    }
    unshift( @INC, $lib );
}

sub ::run {
    binmode(STDERR, ':utf8');
    binmode(STDOUT, ':utf8');
    for ( @ARGV ) {
	next if ref ne "";
	$_ = decode_utf8($_);
    }

    $options = app_setup( "ChordPro", $VERSION );
    $options->{trace}   = 1 if $options->{debug};
    $options->{verbose} = 1 if $options->{trace};
    $options->{verbose} = 9 if $options->{debug};
    main();

lib/ChordPro.pm  view on Meta::CPAN

    # Some backends write output themselves, others return an
    # array of lines to be written.
    if ( $res && @$res > 0 ) {
        if ( $of && $of ne "-" ) {
            my $fd = fs_open( $of, '>:utf8' );
	    push( @$res, '' ) unless $res->[-1] eq '';
	    print { $fd } ( join( "\n", @$res ) );
	    close($fd);
        }
	else {
	    binmode( STDOUT, ":utf8" );
	    push( @$res, '' ) unless $res->[-1] eq '';
	    print( join( "\n", @$res ) );
	}
	# Don't close STDOUT!
    }

    if ( $options->{verbose} ) {
	my $st = json_stats;
	warn("JSON: xs = ", $st->{xs}, ", rr = ", $st->{rr}, "\n");
    }

lib/ChordPro.pm  view on Meta::CPAN

    $::options = $options;
    # warn(::dump($options), "\n") if $options->{debug};

    # To avoid confusion, produce a template if the user asks for a
    # default config.
    # Unless she insists...
    if ( $defcfg >= 2 ) {
	use File::Copy;
	my $cfg = fn_catfile( CP->findresdirs("config")->[-1],
			      "chordpro.json" );
	binmode STDOUT => ':raw';
	copy( $cfg, \*STDOUT );
	exit 0;
    }
    if ( $tmplcfg || $defcfg ) {
	use File::Copy;
	my $cfg = fn_catfile( CP->findresdirs("config")->[-1],
			      "config.tmpl" );
	binmode STDOUT => ':raw';
	copy( $cfg, \*STDOUT );
	exit 0;
    }
    if ( $fincfg || $deltacfg ) {
	print ChordPro::Config::config_final( delta   => $deltacfg );
	exit 0;
    }

    if ( $about ) {
	$::config = ChordPro::Config::configurator({});

lib/ChordPro/Chords/Parser.pm  view on Meta::CPAN

sub is_chord      ( $self ) { 0 };
sub is_annotation ( $self ) { 0 };
sub has_diagram   ( $self ) { 0 };

################ Testing ################

package main;

unless ( caller ) {
    select(STDERR);
    binmode(STDERR, ':utf8');
    $::config = { settings => { chordnames => "strict" } };
    $::options = { verbose => 2 };
    foreach ( @ARGV ) {
	if ( $_ eq '-' ) {
	    $::config = { settings => { chordnames => "relaxed" } };
	    ChordPro::Chords::Parser->reset_parsers("common");
	    next;
	}
	my $p0 = ChordPro::Chords::Parser->default;
	my $p1 = ChordPro::Chords::Parser->get_parser("common", 1);

lib/ChordPro/Delegate/Program.pm  view on Meta::CPAN

	DEBUG && warn("Using Wx::ExecuteStdoutStderr\n");
	( $status, $stdout_buf, $stderr_buf ) =
	  Wx::ExecuteStdoutStderr( "@cmd" );
	# $stdout_buf and $stderr_buf will be strings.
    }
    else {
	DEBUG && warn("Using IPC::Run3::run3\n");
	$stdout_buf = '';
	$stderr_buf = '';
	run3( \@cmd, \$input_data, \$stdout_buf, \$stderr_buf,
	      { binmode_stdout => ':raw',
		return_if_system_error => 1 } );
	# $stdout_buf and $stderr_buf will be strings.
	$status = $? >> 8;
    }

    if ( DEBUG ) {
	::dump( $stdout_buf, as => "Raw result (status: $status)" );
	::dump( $stderr_buf, as => "Raw diagnostics" );
	my $files = fs_find( $td, { filter => qr/^[^.]/ } );
	warn("Temp files:\n") if @$files;

lib/ChordPro/Output/PDF/Writer.pm  view on Meta::CPAN


    ::dump($self->{pdf}->{pagestack})
      if $::config->{debug}->{pages} & 0x04;

    if ( $file && $file ne "-" ) {
	my $fd = fs_open( $file, '>:raw' );
	print $fd $self->{pdf}->stringify;
	close($fd);
    }
    else {
	binmode(STDOUT);
	print STDOUT ( $self->{pdf}->stringify );
	close(STDOUT);
    }
}

sub init_fonts {
    my ( $self ) = @_;
    my $ps = $self->{ps};
    my $fail;

lib/ChordPro/Testing.pm  view on Meta::CPAN


use strict;
use warnings;
use utf8;
use Carp;

use FindBin;
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::Bin/../lib/ChordPro/lib";

binmode STDOUT => ':utf8';
binmode STDERR => ':utf8';

package ChordPro::Testing;

use parent 'Exporter';
our @EXPORT = qw( $config );

use Test::More ();
use Test::More::UTF8;

use ChordPro::Files;

lib/ChordPro/lib/SVGPDF/FontManager.pm  view on Meta::CPAN

		      lc($2) eq "opentype" ? ".otf" :
		      '';
		}
		elsif ( $opts->{_filesource} =~ /\.(\w+)$/ ) {
		    $sfx = $2;
		}
		# No (or unknown) format, skip.
		next unless $sfx;

		my ($fh,$fn) = tempfile( "${td}SVGXXXX", SUFFIX => $sfx );
		binmode( $fh => ':raw' );
		print $fh $data;
		close($fh);
		my $font = eval { $svg->pdf->font($fn) };
		croak($@) if $@;
		my $f = $fc->{$key} =
		  { font => $font,
		    src => $opts->{_filesource} };
		#warn("SRC: ", $opts->{_filesource}, "\n");
		return ( $f->{font},
			 $style->{'font-size'} || 12,

lib/ChordPro/lib/SVGPDF/FontManager.pm  view on Meta::CPAN

		if ( $src =~ /\bformat\((["'])(.*?)\1\)/ ) {
		    $sfx =
		      lc($2) eq "truetype" ? ".ttf" :
		      lc($2) eq "opentype" ? ".otf" :
		      '';
		}
		# No (or unknown) format, skip.
		next unless $sfx;

		my ($fh,$fn) = tempfile( "${td}SVGXXXX", SUFFIX => $sfx );
		binmode( $fh => ':raw' );
		print $fh decode_base64($data);
		close($fh);
		my $font = eval { $svg->pdf->font($fn) };
		croak($@) if $@;
		my $f = $fc->{$key} =
		  { font => $font,
		    src => 'data' };
		return ( $f->{font},
			 $style->{'font-size'} || 12,
			 $f->{src} );

lib/ChordPro/lib/SVGPDF/Image.pm  view on Meta::CPAN

	$format = "pnm"  if $format =~ /^x[bp]m$/; # bonus
	$format = "tiff" if $format eq "tif";

	# Make the image. Silence missing library warnings.
	my $fh;
	# Also, do not use the fast IPL module, it cannot read from scalar.
	if ( $format eq "tiff" ) {
	    # TIFF can't read from scalar file handle.
	    use File::Temp;
	    ( my $fd, $fh ) = File::Temp::tempfile( UNLINK => 1 );
	    binmode $fd => ':raw';
	    print $fd $data;
	    close($fd);
	    # Yes, trickery... $fh is now a file name, not a handle.
	}
	else {
	    open( $fh, '<:raw', \$data );
	}
	$img = $self->root->pdf->image( $fh, format => $format,
					silent => 1, nouseIPL => 1 );
    }

script/cfgboot.pl  view on Meta::CPAN

app_options();

$trace |= ($debug || $test);

################ The Process ################

use JSON::Relaxed qw();
use JSON::XS qw();
use File::LoadLines;
use Encode qw(decode_utf8);
binmode STDOUT => ':utf8';
binmode STDERR => ':utf8';

my $parser = JSON::Relaxed::Parser->new
  ( booleans => [ $Types::Serialiser::false, $Types::Serialiser::true ] );

my $json = "";
# RJSON files can be concatenated.
for my $file ( @ARGV ) {
    my $opts = { split => 0, fail => "soft" };
    $json .= loadlines( $file, $opts );
    die( "$file: $opts->{error}\n") if $opts->{error};

script/rrjson.pl  view on Meta::CPAN

}

################ The Process ################

use FindBin;
use lib "$FindBin::Bin/../lib";
use JSON::Relaxed;
use JSON::PP;
use File::LoadLines;
use Encode qw(decode_utf8);
binmode STDOUT => ':utf8';
binmode STDERR => ':utf8';

if ( $schema ) {
    my $parser = JSON::Relaxed::Parser->new( strict => 0 );
    my $data = loadlines( $schema, { split => 0 } );
    $data = $parser->decode($data);
    warn("Schema $schema loaded\n") if $verbose;
    $schema = $data;
}

my $parser = JSON::Relaxed::Parser->new

script/wxchordpro.pl  view on Meta::CPAN

# Last Modified On: Wed Sep 17 12:15:41 2025
# Update Count    : 339
# Status          : Unknown, Use with caution!

################ Common stuff ################

use strict;
use warnings;

use utf8;
binmode(STDERR, ':utf8');
binmode(STDOUT, ':utf8');

use FindBin;

# @INC construction...
# Standard paths are lib and lib/ChordPro/lib relative to the parent
# of the script directory. This may fail if the ChordPro files are installed
# in another directory than next to the script.
# Directories in CHORDPRO_XLIBS follow, to augment the path.
# For example, to add custom delegates.
# Directories in CHORDPRO_XXLIBS are put in front, these can be used

t/010_files.t  view on Meta::CPAN

use strict;
use warnings;
use utf8;

use Test::More;
use ChordPro::Files;
use Encode qw( encode_utf8 decode_utf8 );

# Stolen from Test::More::UTF8.
my @h = qw(failure_output todo_output output);
binmode Test::More->builder->$_, ':utf8' for @h;

if ( -d "t" ) {
    chdir "t";
    $0 =~ s;(^|/)t/;$1;;
}

use lib "../script";

my %files = ( "Test.fstst"    => 1,
	      "Café.fstst"    => 1,



( run in 1.017 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )