| 1 |
#!/usr/bin/env texlua |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
MUSIXFLXVERSION = "0.83" |
| 6 |
VERSION = "0.83.3.lua7" |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
MAX_SIGNS = 128; MAX_SECTIONS = 128; MAX_BARS = 2048 |
| 86 |
|
| 87 |
function GETLINE() |
| 88 |
linebuf = infile:read() |
| 89 |
return linebuf |
| 90 |
end |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
zbar = {}; lr_repeat = {}; raggedline = {} |
| 97 |
l_repeat = {}; barno = {} |
| 98 |
|
| 99 |
|
| 100 |
autolines = {}; bars = {}; mulooseness = {} |
| 101 |
|
| 102 |
|
| 103 |
signchange = {} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
xbar = {}; linegoal = {} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
hardbarlength = {}; softbarlength = {} |
| 114 |
width_leftrightrepeat = {}; width_leftrepeat = {} |
| 115 |
|
| 116 |
|
| 117 |
eff_hardlength = {}; eff_softlength = {} |
| 118 |
|
| 119 |
|
| 120 |
oldsignskip = {}; signskip = {}; futuresignskip = {} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
function error_exit (error_number) |
| 125 |
|
| 126 |
|
| 127 |
if error_number == 0 then |
| 128 |
print("\nFile error.") |
| 129 |
elseif error_number == 1 then |
| 130 |
print("\nUsage: [texlua] musixflx.lua basename[.tex | .mx1] [ d | m | f | s ]") |
| 131 |
elseif error_number == 2 then |
| 132 |
print("\nThis shouldn't happen ! Too few bars or \\mulooseness too large ?") |
| 133 |
elseif error_number == 3 then |
| 134 |
print("\nThis shouldn't happen ! Too few bars in section !") |
| 135 |
elseif error_number == 4 then |
| 136 |
print("\nMissing endmark ! Forgotten \\stop[end]piece ?") |
| 137 |
elseif error_number == 5 then |
| 138 |
print("\nDivision by zero ! Ask a wizard !") |
| 139 |
elseif error_number == 6 then |
| 140 |
print("\nVersion mis-match:") |
| 141 |
print("MusiXTeX version " .. linebuf) |
| 142 |
print("musixflx expected version " .. MUSIXFLXVERSION) |
| 143 |
elseif error_number == 7 then |
| 144 |
print("\nFile not found: " .. infilename) |
| 145 |
elseif error_number == 8 then |
| 146 |
print("\nCorrupted " .. infilename) |
| 147 |
elseif error_number == 9 then |
| 148 |
print("\nToo many sections, maximum number of sections: " .. MAX_SECTIONS) |
| 149 |
elseif error_number == 10 then |
| 150 |
print("\nError in " .. infilename .. " at line " .. currentline) |
| 151 |
elseif error_number == 11 then |
| 152 |
print("\nToo many bars, maximum number of bars: " .. MAX_BARS) |
| 153 |
else |
| 154 |
print("!!! Can't go on !!!") |
| 155 |
end |
| 156 |
os.exit(3) |
| 157 |
|
| 158 |
end |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
function strrchr(str, pat) |
| 167 |
notfound = true |
| 168 |
currentIndex = 0 |
| 169 |
lastIndex = 0 |
| 170 |
while notfound do |
| 171 |
currentIndex = string.find(str, pat, lastIndex+1, true) |
| 172 |
if (not currentIndex) then |
| 173 |
notfound = false |
| 174 |
else |
| 175 |
lastIndex = currentIndex |
| 176 |
end |
| 177 |
end |
| 178 |
if lastIndex == 0 then return nil end |
| 179 |
return string.sub(str, lastIndex+1) |
| 180 |
end |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
io.write(string.format("Musixflx-%s", VERSION)) |
| 186 |
|
| 187 |
|
| 188 |
junk = -9999 |
| 189 |
dbug = false |
| 190 |
dbug_lines = false |
| 191 |
dbug_logfile = false |
| 192 |
showresult = false |
| 193 |
detectraggedline = false |
| 194 |
currentline = 1 |
| 195 |
samechapter = true |
| 196 |
line_number = 0 |
| 197 |
chapterno = 1 |
| 198 |
|
| 199 |
lthick = .4 |
| 200 |
|
| 201 |
if dbug then |
| 202 |
print("\n ... decoding command line") |
| 203 |
end |
| 204 |
|
| 205 |
filename = arg[1] |
| 206 |
if not filename then |
| 207 |
error_exit(1) |
| 208 |
end |
| 209 |
|
| 210 |
extension = string.sub(filename, -4, -1) |
| 211 |
if extension == ".tex" or extension == ".mx1" then |
| 212 |
basename = string.sub(filename, 1, -5) |
| 213 |
else |
| 214 |
basename = filename |
| 215 |
end |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
if (#arg == 2) then |
| 228 |
if (arg[2] == "d") then |
| 229 |
dbug = true |
| 230 |
elseif (arg[2] == "m") then |
| 231 |
dbug_lines = true |
| 232 |
elseif (arg[2] == "f") then |
| 233 |
dbug = true |
| 234 |
dbug_logfile = true |
| 235 |
dbug_lines = true |
| 236 |
elseif (arg[2] == "s") then |
| 237 |
showresult = true |
| 238 |
else |
| 239 |
error_exit(1) |
| 240 |
end |
| 241 |
end |
| 242 |
|
| 243 |
infilename = basename .. ".mx1" |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
if dbug then |
| 248 |
print(" ... opening " .. infilename .. " for input") |
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
end |
| 253 |
infile = io.open(infilename, "r") |
| 254 |
if (not infile) then |
| 255 |
error_exit(7) |
| 256 |
end |
| 257 |
io.write(string.format(" (%s", infilename)) |
| 258 |
if showresult then |
| 259 |
print("") |
| 260 |
end |
| 261 |
|
| 262 |
currentline = currentline + 1 |
| 263 |
if GETLINE() and (linebuf ~= MUSIXFLXVERSION) then |
| 264 |
error_exit(6) |
| 265 |
end |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
outfilename = basename .. ".mx2" |
| 270 |
if dbug then |
| 271 |
print(" ... opening " .. outfilename .. " for output") |
| 272 |
end |
| 273 |
outfile = io.open(outfilename, "w") |
| 274 |
if (not outfile) then |
| 275 |
print("\nCan't create: " .. outfilename) |
| 276 |
os.exit(3) |
| 277 |
end |
| 278 |
|
| 279 |
|
| 280 |
if dbug_logfile then |
| 281 |
logfilename = basename .. ".mxl" |
| 282 |
print(" ... open " .. logfilename .. " for debugging") |
| 283 |
logfile = io.open(logfilename, "w") |
| 284 |
if (not logfile) then |
| 285 |
print("\nCan't create: " .. logfilename) |
| 286 |
os.exit(3) |
| 287 |
end |
| 288 |
logfile:write("Version ", VERSION, "\n") |
| 289 |
end |
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
if GETLINE() and (linebuf ~= "S") then |
| 294 |
error_exit(8) |
| 295 |
end |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
GETLINE() |
| 306 |
|
| 307 |
repeat |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
if dbug then print("\n------- Chapter " .. chapterno .. " -------\n"); end |
| 312 |
if dbug_logfile then logfile:write("\n------- Chapter ", chapterno, " -------\n\n"); end |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
for i = 0, MAX_SIGNS-1 do |
| 319 |
signchange[i] = junk |
| 320 |
oldsignskip[i] = 0 |
| 321 |
futuresignskip[i] = 0 |
| 322 |
signskip[i] = 0 |
| 323 |
end |
| 324 |
|
| 325 |
for i = 0, MAX_BARS-1 do |
| 326 |
hardbarlength[i] = 0 |
| 327 |
softbarlength[i] = 0 |
| 328 |
width_leftrightrepeat[i] = 0 |
| 329 |
lr_repeat[i] = false |
| 330 |
width_leftrepeat[i] = 0 |
| 331 |
xbar[i] = 0 |
| 332 |
l_repeat[i] = false |
| 333 |
zbar[i] = false |
| 334 |
raggedline[i] = false |
| 335 |
barno[i] = 0 |
| 336 |
end |
| 337 |
|
| 338 |
for i = 0, MAX_SECTIONS-1 do |
| 339 |
eff_hardlength[i] = 0 |
| 340 |
eff_softlength[i] = 0 |
| 341 |
bars[i] = 0 |
| 342 |
autolines[i] = false |
| 343 |
linegoal[i] = 0 |
| 344 |
mulooseness[i] = 0 |
| 345 |
end |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
if linebuf then linewidth = string.sub(linebuf, 1, -3); currentline=currentline+1 end |
| 364 |
GETLINE(); if linebuf then parindent = string.sub(linebuf, 1, -3); currentline=currentline+1 end |
| 365 |
GETLINE(); if linebuf then beforerule = string.sub(linebuf, 1, -3); currentline=currentline+1 end |
| 366 |
GETLINE(); if linebuf then afterrule = string.sub(linebuf, 1, -3); currentline=currentline+1 end |
| 367 |
GETLINE(); if linebuf then elemskip = string.sub(linebuf, 1, -3); currentline=currentline+1 end |
| 368 |
GETLINE(); if linebuf then clefskip = string.sub(linebuf, 1, -3); currentline=currentline+1 end |
| 369 |
GETLINE(); if linebuf then signskip[0] = string.sub(linebuf, 1, -3); currentline=currentline+1 end |
| 370 |
|
| 371 |
futuresignskip[0] = signskip[0] |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
jbar = junk |
| 382 |
i = 0 |
| 383 |
sign = 0 |
| 384 |
xbar_count = 0 |
| 385 |
xbar_flag = false |
| 386 |
hardsign = 0 |
| 387 |
softspace_count = 0 |
| 388 |
|
| 389 |
all_section = 0 |
| 390 |
|
| 391 |
if dbug then |
| 392 |
print(" ... reading") |
| 393 |
end |
| 394 |
|
| 395 |
while (samechapter and GETLINE()) do |
| 396 |
|
| 397 |
currentline = currentline + 1 |
| 398 |
local firstChar = string.sub(linebuf, 1, 1) |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
if (firstChar == "S") then |
| 411 |
samechapter = false |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
elseif (firstChar == "*") then |
| 423 |
local firstSpace = string.find(linebuf, " ") |
| 424 |
local secondSpace = string.find(linebuf, " ", firstSpace+1) |
| 425 |
if not secondSpace then |
| 426 |
mulooseness[all_section] = string.sub(linebuf, firstSpace+1) |
| 427 |
else |
| 428 |
mulooseness[all_section] = string.sub(linebuf, firstSpace+1, secondSpace-1) |
| 429 |
end |
| 430 |
|
| 431 |
linegoal[all_section] = 0 |
| 432 |
if secondSpace then |
| 433 |
linegoal[all_section] = string.sub(linebuf, secondSpace+1) |
| 434 |
end |
| 435 |
linegoal[all_section] = linegoal[all_section] + 0 |
| 436 |
mulooseness[all_section] = mulooseness[all_section] + 0 |
| 437 |
if ((mulooseness[all_section] ~= 0) and (linegoal[all_section] > 0)) then |
| 438 |
print("\\linegoal{" .. linegoal[all_section] .. "} ignored because \\mulooseness not equal to zero") |
| 439 |
print(" for section " .. all_section+1 .. " in chapter " .. chapterno) |
| 440 |
linegoal[all_section] = 0 |
| 441 |
end |
| 442 |
all_section = all_section + 1 |
| 443 |
if all_section > (MAX_SECTIONS - 1) then |
| 444 |
error_exit(9) |
| 445 |
end |
| 446 |
jbar=junk |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
elseif (firstChar == "a") then |
| 457 |
autolines[all_section] = true |
| 458 |
all_section = all_section + 1 |
| 459 |
if (all_section > (MAX_SECTIONS - 1)) then |
| 460 |
error_exit(9) |
| 461 |
end |
| 462 |
jbar=junk |
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
elseif (firstChar == "r") then |
| 472 |
raggedline[i+1] = true |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
elseif (firstChar == "z") then |
| 477 |
zbar[i] = true |
| 478 |
barno[i] = strrchr(linebuf, " ") |
| 479 |
xbar_count = xbar_count + 1 |
| 480 |
hardsign = 0 |
| 481 |
softspace_count = 0 |
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
elseif (firstChar == "l") then |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
lr_repeat[i] = true |
| 495 |
local firstSpace = string.find(linebuf, " ") |
| 496 |
local secondSpace = string.find(linebuf, " ", firstSpace + 1) |
| 497 |
width_leftrightrepeat[i] = string.sub(linebuf, firstSpace+1, secondSpace-3) |
| 498 |
width_leftrepeat[i] = string.sub(linebuf, secondSpace+1, -3) |
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
elseif (firstChar == "L") then |
| 507 |
l_repeat[i] = true |
| 508 |
local firstSpace = string.find(linebuf, " ") |
| 509 |
width_leftrepeat[i] = string.sub(linebuf, firstSpace+1, -3) |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
elseif (firstChar == "b") then |
| 514 |
barno[i] = strrchr(linebuf, " ") |
| 515 |
xbar_count = xbar_count+1 |
| 516 |
xbar_flag = true |
| 517 |
hardsign = 0 |
| 518 |
softspace_count = 0 |
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
elseif (firstChar == "h") then |
| 527 |
x = string.sub(strrchr(linebuf, " "), 1, -3) |
| 528 |
softbarlength[i] = softbarlength[i] - x |
| 529 |
hardbarlength[i] = hardbarlength[i] + x |
| 530 |
eff_softlength[all_section] = eff_softlength[all_section] - x |
| 531 |
eff_hardlength[all_section] = eff_hardlength[all_section] + x |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
elseif (firstChar == "s") then |
| 540 |
|
| 541 |
local firstSpace = string.find(linebuf, " ") |
| 542 |
local secondSpace = string.find(linebuf, " ", firstSpace+1) |
| 543 |
if not secondSpace then |
| 544 |
tempholdskip = string.sub(linebuf, firstSpace+1, -3) |
| 545 |
else |
| 546 |
tempholdskip = string.sub(linebuf, firstSpace+1, secondSpace-3) |
| 547 |
end |
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
if (not (signchange[sign] == i)) then |
| 555 |
sign = sign + 1 |
| 556 |
signchange[sign] = i |
| 557 |
signskip[sign] = tempholdskip |
| 558 |
oldsignskip[sign] = hardsign |
| 559 |
xbar[i] = xbar[i] + 1 |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
if softspace_count > 0 then xbar[i] = 2 end |
| 570 |
end |
| 571 |
|
| 572 |
futuresignskip[sign] = tempholdskip |
| 573 |
|
| 574 |
|
| 575 |
elseif (firstChar == "%") then |
| 576 |
|
| 577 |
|
| 578 |
else |
| 579 |
if (not (tonumber(firstChar))) then |
| 580 |
error_exit(10) |
| 581 |
end |
| 582 |
local firstSpace = string.find(linebuf, " ") |
| 583 |
local secondSpace = string.find(linebuf, " ", firstSpace + 1) |
| 584 |
bar = string.sub(linebuf, 1, firstSpace-1) |
| 585 |
typ = string.sub(linebuf, firstSpace+1, secondSpace-1) |
| 586 |
x = string.sub(linebuf, secondSpace+1, -3) |
| 587 |
if (typ ~= "0") then eff_softlength[all_section] = eff_softlength[all_section] + x |
| 588 |
else eff_hardlength[all_section] = eff_hardlength[all_section] + x |
| 589 |
end |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
bar = bar + 0 |
| 597 |
if tonumber(bar) > jbar then |
| 598 |
i = i + 1 |
| 599 |
bars[all_section] = bars[all_section] + 1 |
| 600 |
if i > MAX_BARS then |
| 601 |
error_exit(11) |
| 602 |
end |
| 603 |
end |
| 604 |
|
| 605 |
|
| 606 |
if xbar_flag then |
| 607 |
if ((xbar_count - bar - 1) == 0) then |
| 608 |
xbar_count = xbar_count-1 |
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
if (xbar[i] == 0) then |
| 616 |
|
| 617 |
xbar[i] = 1 |
| 618 |
end |
| 619 |
end |
| 620 |
end |
| 621 |
|
| 622 |
xbar_flag = false |
| 623 |
|
| 624 |
if (typ ~= "0") then |
| 625 |
softbarlength[i] = softbarlength[i] + x |
| 626 |
|
| 627 |
softspace_count = softspace_count+1 |
| 628 |
hardsign = 0 |
| 629 |
else |
| 630 |
hardbarlength[i] = hardbarlength[i] + x |
| 631 |
hardsign = hardsign + x |
| 632 |
end |
| 633 |
|
| 634 |
jbar = bar |
| 635 |
|
| 636 |
end |
| 637 |
|
| 638 |
end |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
if dbug then |
| 649 |
print(" ... compute") |
| 650 |
end |
| 651 |
|
| 652 |
if (bars[all_section] == 0) then |
| 653 |
all_section = all_section - 1 |
| 654 |
else |
| 655 |
error_exit(4) |
| 656 |
end |
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
if dbug then |
| 661 |
print("\nNumber of sections : " .. (all_section+1) .."\n") |
| 662 |
|
| 663 |
for section = 0, all_section do |
| 664 |
if (autolines[section]) then |
| 665 |
print("---- autoline section ----") |
| 666 |
end |
| 667 |
print("Section : " .. (section+1)) |
| 668 |
print("Number of bars in section : " .. bars[section]) |
| 669 |
print("Length(hard) of section " .. (section+1) .. " : " .. eff_hardlength[section]) |
| 670 |
print("Length(soft) of section " .. (section+1) .. " : " .. eff_softlength[section]) |
| 671 |
if (linegoal[section] ~= 0) then |
| 672 |
print("Section line goal was determined by \\linegoal value...") |
| 673 |
print("Line Goal for section : " .. linegoal[section]) |
| 674 |
else |
| 675 |
print("Looseness of section : " .. mulooseness[section]) |
| 676 |
end |
| 677 |
|
| 678 |
io.read() |
| 679 |
end |
| 680 |
|
| 681 |
end |
| 682 |
|
| 683 |
if dbug_logfile then |
| 684 |
logfile:write("\nNumber of sections : ", all_section+1, "\n\n") |
| 685 |
|
| 686 |
for section = 0, all_section do |
| 687 |
if (autolines[section]) then |
| 688 |
logfile:write("---- autoline section ----\n") |
| 689 |
end |
| 690 |
logfile:write("Section : ", section+1, "\n") |
| 691 |
logfile:write("Number of bars in section : ", bars[section], "\n") |
| 692 |
logfile:write("Length(hard) of section ", section+1, " : ", eff_hardlength[section], "\n") |
| 693 |
logfile:write("Length(soft) of section ", section+1, " : ", eff_softlength[section], "\n") |
| 694 |
if (linegoal[section] ~= 0) then |
| 695 |
logfile:write("Section line goal was determined by \\linegoal value...\n") |
| 696 |
logfile:write("Line goal for section : ", linegoal[section], "\n") |
| 697 |
else |
| 698 |
logfile:write("Looseness of section : ", mulooseness[section], "\n") |
| 699 |
end |
| 700 |
end |
| 701 |
end |
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
sign = 0 |
| 712 |
mark = 0 |
| 713 |
lastbarnumber = 0 |
| 714 |
|
| 715 |
|
| 716 |
for section = 0, all_section do |
| 717 |
line_in_section = 1 |
| 718 |
lastbarnumber = lastbarnumber + bars[section] |
| 719 |
|
| 720 |
|
| 721 |
lines = math.floor(((eff_hardlength[section] + eff_softlength[section] + parindent)/ |
| 722 |
(linewidth-(clefskip+signskip[sign]))) + .5) |
| 723 |
if (lines == 0) then lines = 1 end |
| 724 |
|
| 725 |
natural_lines = lines |
| 726 |
lines = lines + mulooseness[section] |
| 727 |
if ((mulooseness[section] ~= 0) and (linegoal[section] > 0)) then |
| 728 |
print("Unexpected line goal reset occured for section " .. section+1) |
| 729 |
linegoal[section] = 0 |
| 730 |
end |
| 731 |
if (linegoal[section] > 0) then lines = linegoal[section] end |
| 732 |
if lines < 1 then |
| 733 |
lines = 1 |
| 734 |
print("Don't stress \\mulooseness too much !!!") |
| 735 |
end |
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
if (autolines[section]) then lines = 1 end |
| 744 |
|
| 745 |
if dbug then |
| 746 |
print("Section number : " .. section+1) |
| 747 |
print("Last bar in this section : " .. lastbarnumber) |
| 748 |
print("Number of bars : " .. bars[section]) |
| 749 |
print("Natural number of lines : " .. natural_lines) |
| 750 |
print("Chosen number of lines : " .. lines .. "\n") |
| 751 |
end |
| 752 |
|
| 753 |
if dbug_logfile then |
| 754 |
logfile:write("Section number : ", section+1, "\n") |
| 755 |
logfile:write("Last bar in this section : ", lastbarnumber, "\n") |
| 756 |
logfile:write("Number of bars : ", bars[section], "\n") |
| 757 |
logfile:write("Natural number of lines : ", natural_lines, "\n") |
| 758 |
logfile:write("Chosen number of lines : ", lines, "\n\n") |
| 759 |
end |
| 760 |
|
| 761 |
if (bars[section]<1) then error_exit(3) end |
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
for j = 1, lines do |
| 779 |
line_number = line_number + 1 |
| 780 |
fill_length = (lines-j+1) * (linewidth - (clefskip + signskip[sign])) |
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
if (eff_softlength[section] == 0) then error_exit(5) end |
| 794 |
spc_factor = (fill_length - eff_hardlength[section])/eff_softlength[section] |
| 795 |
if ((xbar[mark+1] > 1) and (mark>0)) then |
| 796 |
|
| 797 |
eff_linewidth = linewidth - (clefskip+signskip[sign-1]) - parindent |
| 798 |
else |
| 799 |
eff_linewidth = linewidth - (clefskip+signskip[sign]) - parindent |
| 800 |
end |
| 801 |
|
| 802 |
signskip[sign] = futuresignskip[sign] |
| 803 |
|
| 804 |
parindent = 0 |
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
i = mark |
| 809 |
firstbarno = barno[mark+1] |
| 810 |
hardlength = 0 |
| 811 |
softlength = 0 |
| 812 |
x = 0 |
| 813 |
lastbar = 0 |
| 814 |
detect_end = false |
| 815 |
|
| 816 |
while (x < eff_linewidth) do |
| 817 |
if detect_end then break end |
| 818 |
i = i + 1 |
| 819 |
|
| 820 |
|
| 821 |
if raggedline[i] then detectraggedline = true end |
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
if (i == signchange[sign+1]) then sign = sign + 1 end |
| 826 |
|
| 827 |
lastbar = hardbarlength[i] + spc_factor*softbarlength[i] |
| 828 |
x = x + lastbar |
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
if (i==lastbarnumber) then detect_end = true |
| 833 |
elseif (line_in_section == lines) then |
| 834 |
detect_end = false |
| 835 |
x = 0 |
| 836 |
end |
| 837 |
|
| 838 |
hardlength = hardlength + hardbarlength[i] |
| 839 |
softlength = softlength + softbarlength[i] |
| 840 |
|
| 841 |
end |
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
if ((x-eff_linewidth) < (lastbar/2)) then |
| 851 |
barsinline = i - mark |
| 852 |
mark = i |
| 853 |
lastbarno = barno[mark] |
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
if zbar[mark] then |
| 863 |
softbarlength[i+1] = softbarlength[i+1] + afterrule |
| 864 |
eff_softlength[section] = eff_softlength[section] + afterrule |
| 865 |
end |
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
if lr_repeat[mark] then |
| 876 |
|
| 877 |
|
| 878 |
hardlength = hardlength - (width_leftrightrepeat[i] - width_leftrepeat[i]) |
| 879 |
eff_hardlength[section] = eff_hardlength[section] + (width_leftrightrepeat[i] - width_leftrepeat[i]) |
| 880 |
hardbarlength[i+1] = hardbarlength[i+1] + width_leftrepeat[i] |
| 881 |
softbarlength[i+1] = softbarlength[i+1] + (afterrule/2) |
| 882 |
eff_softlength[section] = eff_softlength[section] + (afterrule/2) |
| 883 |
end |
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
if l_repeat[mark] then |
| 894 |
hardlength = hardlength - (width_leftrepeat[i] - lthick) |
| 895 |
hardbarlength[i+1] = hardbarlength[i+1] + width_leftrepeat[i] |
| 896 |
softbarlength[i+1] = softbarlength[i+1] + (afterrule/2) |
| 897 |
eff_softlength[section] = eff_softlength[section] + (afterrule/2) |
| 898 |
end |
| 899 |
|
| 900 |
if (signchange[sign+1] == mark+1) then |
| 901 |
sign = sign + 1 |
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
if (xbar[mark+1] < 2) then |
| 916 |
hardlength = hardlength + oldsignskip[sign] |
| 917 |
hardbarlength[mark+1] = hardbarlength[mark+1] - oldsignskip[sign] |
| 918 |
end |
| 919 |
end |
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
else |
| 924 |
barsinline=i-1-mark |
| 925 |
if (barsinline < 1) then error_exit(2) end |
| 926 |
mark = i - 1 |
| 927 |
lastbarno = barno[mark] |
| 928 |
hardlength = hardlength - hardbarlength[i] |
| 929 |
softlength = softlength - softbarlength[i] |
| 930 |
|
| 931 |
if zbar[mark] then softbarlength[i] = softbarlength[i] + afterrule end |
| 932 |
|
| 933 |
if lr_repeat[mark] then |
| 934 |
hardlength = hardlength - (width_leftrightrepeat[i-1]-width_leftrepeat[i-1]) |
| 935 |
eff_hardlength[section] = eff_hardlength[section] + (width_leftrightrepeat[i-1] - width_leftrepeat[i-1]) |
| 936 |
hardbarlength[i] = hardbarlength[i] + width_leftrepeat[i-1] |
| 937 |
softbarlength[i] = softbarlength[i] + (afterrule/2) |
| 938 |
eff_softlength[section] = eff_softlength[section] + (afterrule/2) |
| 939 |
end |
| 940 |
|
| 941 |
if l_repeat[mark] then |
| 942 |
hardlength = hardlength - (width_leftrepeat[i-1] - lthick) |
| 943 |
hardbarlength[i] = hardbarlength[i] + width_leftrepeat[i-1] |
| 944 |
softbarlength[i] = softbarlength[i] + (afterrule/2) |
| 945 |
eff_softlength[section] = eff_softlength[section] + (afterrule/2) |
| 946 |
end |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
if (signchange[sign] == (mark+1)) then |
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
if(xbar[mark+1] < 2) then |
| 966 |
hardlength = hardlength + oldsignskip[sign] |
| 967 |
hardbarlength[mark+1] = hardbarlength[mark+1] - oldsignskip[sign] |
| 968 |
end |
| 969 |
|
| 970 |
end |
| 971 |
|
| 972 |
end |
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
if (softlength == 0) then error_exit(5) end |
| 982 |
flexit = (eff_linewidth - hardlength) / softlength |
| 983 |
if detectraggedline then |
| 984 |
flexit = 1 |
| 985 |
detectraggedline = false |
| 986 |
end |
| 987 |
cor_elemskip = elemskip * flexit |
| 988 |
cor_afterrule = afterrule * flexit |
| 989 |
cor_beforerule = beforerule * flexit |
| 990 |
|
| 991 |
if dbug then |
| 992 |
print("Line number : " .. line_number) |
| 993 |
print("Fill length : " .. fill_length) |
| 994 |
print("Effective length : " .. eff_softlength[section] + eff_hardlength[section]) |
| 995 |
print("Mean space factor : " .. spc_factor) |
| 996 |
print("Bars in line : " .. barsinline) |
| 997 |
print("Effective linewidth : " .. eff_linewidth) |
| 998 |
print("Uncorrected hard length : " .. hardlength) |
| 999 |
print("Uncorrected soft length : " .. softlength) |
| 1000 |
print("fLex factor (soft) : " .. flexit) |
| 1001 |
print("Corrected elemskip : " .. cor_elemskip) |
| 1002 |
print("Corrected afterrule : " .. cor_afterrule) |
| 1003 |
print("Corrected beforerule : " .. cor_beforerule) |
| 1004 |
|
| 1005 |
io.read() |
| 1006 |
end |
| 1007 |
|
| 1008 |
if dbug_logfile then |
| 1009 |
logfile:write("Line number : ", line_number, "\n") |
| 1010 |
logfile:write("Fill length : ", fill_length, "\n") |
| 1011 |
logfile:write("Effective length : ", eff_softlength[section] + eff_hardlength[section], "\n") |
| 1012 |
logfile:write("Mean space factor : ", spc_factor, "\n") |
| 1013 |
logfile:write("Bars in line : ", barsinline, "\n") |
| 1014 |
logfile:write("Effective linewidth : ", eff_linewidth, "\n") |
| 1015 |
logfile:write("Uncorrected hard length : ", hardlength, "\n") |
| 1016 |
logfile:write("Uncorrected soft length : ", softlength, "\n") |
| 1017 |
logfile:write("Flex factor (soft) : ", flexit, "\n") |
| 1018 |
logfile:write("Corrected elemskip : ", cor_elemskip, "\n") |
| 1019 |
logfile:write("Corrected afterrule : ", cor_afterrule, "\n") |
| 1020 |
logfile:write("Corrected beforerule : ", cor_beforerule, "\n\n") |
| 1021 |
end |
| 1022 |
|
| 1023 |
eff_hardlength[section] = eff_hardlength[section] - hardlength |
| 1024 |
eff_softlength[section] = eff_softlength[section] - softlength |
| 1025 |
fill_length = fill_length - eff_linewidth |
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
outfile:write( |
| 1030 |
string.format("\\lineset{%3d}{%2d}{%8.5fpt}{%8.5fpt}{%8.5fpt}%% %d - %d\n", |
| 1031 |
line_number, barsinline, cor_elemskip, cor_afterrule, |
| 1032 |
cor_beforerule, |
| 1033 |
firstbarno, lastbarno)) |
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
if showresult then |
| 1038 |
print( |
| 1039 |
string.format("\\lineset{%3d}{%2d}{%8.5fpt}{%8.5fpt}{%8.5fpt}%% %d - %d", |
| 1040 |
line_number, barsinline, cor_elemskip, cor_afterrule, |
| 1041 |
cor_beforerule, |
| 1042 |
firstbarno, lastbarno)) |
| 1043 |
end |
| 1044 |
|
| 1045 |
if dbug_lines then print(" ... writing line : " .. line_number) end |
| 1046 |
line_in_section = line_in_section + 1 |
| 1047 |
end |
| 1048 |
end |
| 1049 |
|
| 1050 |
if dbug_lines then print("") end |
| 1051 |
|
| 1052 |
|
| 1053 |
samechapter = true |
| 1054 |
chapterno = chapterno + 1 |
| 1055 |
until (not GETLINE()) |
| 1056 |
|
| 1057 |
|
| 1058 |
infile:close() |
| 1059 |
io.write(")") |
| 1060 |
if dbug_logfile then |
| 1061 |
logfile:close() |
| 1062 |
if (not logfile) then error_exit(0) end |
| 1063 |
end |
| 1064 |
outfile:close() |
| 1065 |
if (not outfile) then error_exit(0) end |
| 1066 |
|
| 1067 |
if dbug then |
| 1068 |
print(" ... that's all, bye") |
| 1069 |
end |
| 1070 |
print("") |
| 1071 |
|