Music-Abc-DT

 view release on metacpan or  search on metacpan

lib/Music/Abc/DT.pm  view on Meta::CPAN

    ABC_T_MREST  => 8,   #  multi-measure rest
    ABC_T_MREP   => 9,   #  measure repeat
    ABC_T_V_OVER => 10,  #  voice overlay
    ABC_T_TUPLET => 11,
  };

  use constant { # symbol state in file/tune
    ABC_S_GLOBAL  => 0,      # global
    ABC_S_HEAD    => 1,      # in header (after X:)
    ABC_S_TUNE    => 2,       # in tune (after K:)
    ABC_S_EMBED   => 3     # embedded header (between [..])
  };


  use constant { # info flags
    ABC_F_ERROR       => 0x0001,  #  error around this symbol
    ABC_F_INVIS       => 0x0002,  #  invisible symbol
    ABC_F_SPACE       => 0x0004,  #  space before a note
    ABC_F_STEMLESS    => 0x0008,  #  note with no stem
    ABC_F_LYRIC_START => 0x0010,  #  may start a lyric here
    ABC_F_GRACE       => 0x0020,  #  grace note

lib/Music/Abc/DT.pm  view on Meta::CPAN

    'M'             => 'meter',
    'Q'             => 'tempo',
    'V'             => 'voice',
    'w'             => 'lyrics',
    'W'             => 'lyrics',
  );
  our %state_name = (
    (ABC_S_GLOBAL)  => 'in_global',
    (ABC_S_HEAD)    => 'in_header',
    (ABC_S_TUNE)    => 'in_tune',
    (ABC_S_EMBED)   => 'in_line',
  );

  our @key_tonic = qw(F C G D A E B);
  our @key_shift = (1, 3, 5, 0, 2, 4, 6, 1, 4); # [7 + 2]
  our @clef_type = qw(treble alto bass perc);

}


# Processes abc tunes;

lib/Music/Abc/DT.pm  view on Meta::CPAN

  # and if it doesn't exist either, it applies the identity function - toabc()
  $proc ||= $abch{'-default'} || \&toabc;

  return $proc;
}

#  -- Updates the current voice and some info related to it --
sub _get_voice {
  my $sym = shift;

  if ( $sym->{state} == ABC_S_TUNE || $sym->{state} == ABC_S_EMBED ) {
    $c_voice = $sym->{info}->{voice};

    #set voice stuff if not already set
    #TODO check abcm2ps-7.3.4/parse.c:2817 (do_tune)
    $voice_struct{$c_voice}{id}              ||= $sym->{info}->{id};
    $voice_struct{$c_voice}{name}            ||= $sym->{info}->{fname} || q{};
    $voice_struct{$c_voice}{time}            ||= 0;
    $voice_struct{$c_voice}{meter}{text}     ||= $voice_struct{$GLOBAL}{meter}{text}     || 'M:' . DEFAULT_METER;
    $voice_struct{$c_voice}{meter}{wmeasure} ||= $voice_struct{$GLOBAL}{meter}{wmeasure} || BASE_LEN;
    $voice_struct{$c_voice}{length}          ||= $voice_struct{$GLOBAL}{length}          || 'L:' . DEFAULT_LENGTH;

lib/Music/Abc/DT.pm  view on Meta::CPAN

  my $v = shift;
  return 'down' if ($v < 0);
  return 'auto' if ($v == 2);
  return 'up';
}

# -- returns the abc for the info field and the new line flag
sub _info_to_abc {
  my ($new_abc, $sym, $c, $nl_new) = @_;

  if ($sym->{state} == ABC_S_EMBED) { $new_abc .= '[' }
  elsif ($c ne "\n")                { $new_abc .= "\\\n";
    # _lyrics_dump($new_abc, $sym);
  }
  $new_abc = _header_dump($new_abc, $sym);
  if ($sym->{state} == ABC_S_EMBED) { $new_abc .= ']' }
  else                              { $nl_new = 1; }

  return ($new_abc, $nl_new);
}

# Initializes voice variables
sub _initialize {

  $voice_struct{$c_voice}{id}              = q{};
  $voice_struct{$c_voice}{name}            = q{};

lib/Music/Abc/DT.pm  view on Meta::CPAN

  my $c   = $IMPLICIT_VOICE;    # current voice

#FIXME ver se consigo deixar de usar o ${$s} e passar a usar so $s
  # sets the duration of all notes/rests without regard for tuplets - this is needed for tuplets
  for my $ix ( 0 .. $n_symbols ) {
    my $s = \${$tunes_ref}->{$tune}->{symbols}->[$ix];
    given ( ${$s}->{type} ) {
      when (ABC_T_INFO) {
        given ( substr ${$s}->{text}, 0, 1 ) {
          when ('V') {    # Voice
            if ( ${$s}->{state} ~~ [ABC_S_TUNE, ABC_S_EMBED] ) {
              $c = ${$s}->{info}->{voice};
              $v_i{$c}{meter}{wmeasure} ||= BASE_LEN;
            }
          }
          when ('M') {    # Meter
            if ( ${$s}->{state} ~~ [ ABC_S_HEAD, ABC_S_TUNE ] ) {
              $v_i{$c}{meter}{wmeasure} = ${$s}->{info}->{wmeasure};
            }
          }
        }

lib/Music/Abc/DT.pm  view on Meta::CPAN

  $v_i{$c}{bar}{time}       ||= 0;
  $v_i{$c}{time}            ||= 0;

  for my $ix ( 0 .. $n_symbols ) {
    my $s = ${$tunes_ref}->{$tune}->{symbols}->[$ix];

    given ( $s->{type} ) {
      when (ABC_T_INFO) {
        given ( substr $s->{text}, 0, 1 ) {
          when ('V') {    # Voice
            if ( $s->{state} ~~ [ABC_S_TUNE, ABC_S_EMBED] ) {
              $c = $s->{info}->{voice};
              $v_i{$c}{meter}{wmeasure} ||= BASE_LEN;
              $v_i{$c}{bar}{num}        ||= int $FIRST_MEASURE;
              $v_i{$c}{bar}{time}       ||= 0;
              $v_i{$c}{time}            ||= 0;
            }
          }
          when ('M') {    # Meter
            if ( $s->{state} ~~ [ ABC_S_HEAD, ABC_S_TUNE ] ) {
              $v_i{$c}{meter}{wmeasure} = $s->{info}->{wmeasure};



( run in 1.436 second using v1.01-cache-2.11-cpan-71847e10f99 )