79
78
die "missing output file after $arg\n" unless defined $mg_file;
80
79
$outfile_specified = 1;
82
elsif ($arg =~ /^(-t|--tuplet-factor)$/) {
83
$tuplet_factor = shift;
84
die "bad or missing tuplet factor `$tuplet_factor'\n"
85
unless $tuplet_factor > 0;
87
81
elsif ($arg =~ /^(-w|--ignore-wrong-track)$/) {
88
82
$ignore_wrong_track = 1;
142
136
track numbers starting from 1.
143
137
-N or --exclude-tracks i[,j...]
144
138
As `-n' but excludes the listed tracks
145
-t n or --tuplet-factor n
146
An additional factor for files with odd note lengths,
147
to prevent them being translated as decimals (n should
148
be a prime number >3).
149
139
-F or --no-factorise
150
140
Do not factorise time values.
245
235
$track_name = $event->[2];
249
my @event_tokens = split ' ', &get_event_string($event);
239
my $tokens = &get_event_string($event);
240
next unless defined $tokens;
241
my @event_tokens = split ' ', $tokens;
250
242
@track_tokens = (@track_tokens, @event_tokens)
251
243
unless $event_tokens[0] eq '$ctrl' and
252
244
$event_tokens[1] eq '121,0' and
480
471
$value++ if $value == 8191;
481
472
$value = int((8192.5 + $value) / 128);
482
473
if ($dtime > 0) {
483
return sprintf "/l%s/r \$pitch $value",
484
&clicks_to_time($dtime);
474
return sprintf "/l%s/r \$pitch $value", &clicks_to_time($dtime);
487
477
return "\$pitch $value";
491
481
my (undef, $dtime, $tempo) = @$event;
492
482
if ($dtime > 0) {
493
483
return sprintf "/l%s/r \$tempo %s",
494
&clicks_to_time($dtime), int(60000000 / $tempo);
484
&clicks_to_time($dtime), int(60000000 / $tempo);
497
487
return sprintf "\$tempo %s", int(60000000 / $tempo);
501
491
my (undef, $dtime, $num, $den) = @$event;
502
492
if ($dtime > 0) {
503
493
return sprintf "/l%s/r \$time_sig $num/%s",
504
&clicks_to_time($dtime), $den * $den;
494
&clicks_to_time($dtime), $den * $den;
507
497
return sprintf "\$time_sig $num/%s", $den * $den;
521
511
elsif ($event->[0] eq 'text_event') {
522
512
my (undef, $dtime, $text) = @$event;
513
return undef if length $text == 0;
524
515
if ($dtime > 0) {
525
516
return sprintf "/l%s/r \$text $text", &clicks_to_time($dtime);
581
572
elsif ($event->[0] eq 'marker') {
582
573
my (undef, $dtime, $text) = @$event;
574
return undef if length $text == 0;
584
576
if ($dtime > 0) {
585
577
return sprintf "/l%s/r \$marker \"$text\"",
586
&clicks_to_time($dtime);
578
&clicks_to_time($dtime);
589
581
return "\$marker \"$text\"";
1173
1165
sub clicks_to_time {
1174
my $clicks = shift; # time in clicks
1175
my $time; # n:d value to return
1176
my $res = 960; # resolution to work to (n => (1/n)th note)
1178
$res *= $tuplet_factor;
1179
$time = ($clicks * $res) / (4 * $resolution);
1181
if ($res / $time == int($res / $time)) {
1182
$time = $res / $time;
1185
if ($ctt_do_factorise) {
1186
foreach my $i (2, 3, 5, 7, 11, 13, 17, 19) {
1187
while (($time / $i == int($time / $i))
1188
and ($res / $i == int($res / $i))) {
1196
# try to deal with fractions
1197
unless ($time == int $time) {
1198
my $factor = 1 / ($time - int $time);
1200
if ($factor > 1 and $factor == int $factor) {
1205
if ($factor - 3 < .0000001 and
1206
3 - $factor < .0000001) {
1208
$time = int(3 * time);
1211
elsif (($factor * 2) - 3 < .0000001 and
1212
3 - ($factor * 2) < .0000001) {
1214
$time = int(3 * $time);
1215
$res = int(3 * $res);
1220
$time = "$time:$res";
1166
my $clicks = $_[0]; # time in clicks
1168
my $whole = 4 * $resolution;
1169
my $hcf = &get_hcf($clicks, $whole);
1174
return ($clicks == 1)? $whole : "$clicks:$whole";
1178
## Return the highest common factor of the two integer arguments.
1184
die "Error: get_hcf(): both arguments must be integers"
1185
unless $v1 == int $v1 and $v2 == int $v2;
1187
my $f1 = &get_factors($v1);
1188
my $f2 = &get_factors($v2);
1193
foreach my $f (@$f1) {
1194
shift @$f2 while @$f2 > 0 and $f2->[0] < $f;
1196
if (@$f2 > 0 and $f2->[0] == $f) {
1206
## Return the prime factors of the integer argument.
1211
die "Error: get_factors(): argument must be an integer\n"
1212
unless $v == int $v;
1216
for my $prime (qw(2 3 5 7 11 13 17 19 23 29 31)) {
1219
while ($v / $prime == int($v / $prime)) {
1222
push @factors, $prime;
1226
push @factors, $v unless $v == 1;