abc2svg-1.js 303 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719
  1. // abc2svg - ABC to SVG translator
  2. // @source: https://chiselapp.com/user/moinejf/repository/abc2svg
  3. // Copyright (C) 2014-2023 Jean-Francois Moine - LGPL3+
  4. //abc2svg-abc2svg.js
  5. if(typeof abc2svg=="undefined")
  6. var abc2svg={};abc2svg.C={BLEN:1536,BAR:0,CLEF:1,CUSTOS:2,SM:3,GRACE:4,KEY:5,METER:6,MREST:7,NOTE:8,PART:9,REST:10,SPACE:11,STAVES:12,STBRK:13,TEMPO:14,BLOCK:16,REMARK:17,FULL:0,EMPTY:1,OVAL:2,OVALBARS:3,SQUARE:4,SL_ABOVE:0x01,SL_BELOW:0x02,SL_AUTO:0x03,SL_HIDDEN:0x04,SL_DOTTED:0x08,SL_ALI_MSK:0x70,SL_ALIGN:0x10,SL_CENTER:0x20,SL_CLOSE:0x40};abc2svg.sym_name=['bar','clef','custos','smark','grace','key','meter','Zrest','note','part','rest','yspace','staves','Break','tempo','','block','remark']
  7. abc2svg.keys=[new Int8Array([-1,-1,-1,-1,-1,-1,-1]),new Int8Array([-1,-1,-1,0,-1,-1,-1]),new Int8Array([0,-1,-1,0,-1,-1,-1]),new Int8Array([0,-1,-1,0,0,-1,-1]),new Int8Array([0,0,-1,0,0,-1,-1]),new Int8Array([0,0,-1,0,0,0,-1]),new Int8Array([0,0,0,0,0,0,-1]),new Int8Array([0,0,0,0,0,0,0]),new Int8Array([0,0,0,1,0,0,0]),new Int8Array([1,0,0,1,0,0,0]),new Int8Array([1,0,0,1,1,0,0]),new Int8Array([1,1,0,1,1,0,0]),new Int8Array([1,1,0,1,1,1,0]),new Int8Array([1,1,1,1,1,1,0]),new Int8Array([1,1,1,1,1,1,1])]
  8. abc2svg.p_b40=new Int8Array([2,8,14,19,25,31,37])
  9. abc2svg.b40_p=new Int8Array([0,0,0,0,0,0,1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6])
  10. abc2svg.b40_a=new Int8Array([-2,-1,0,1,2,-3,-2,-1,0,1,2,-3,-2,-1,0,1,2,-2,-1,0,1,2,-3,-2,-1,0,1,2,-3,-2,-1,0,1,2,-3,-2,-1,0,1,2])
  11. abc2svg.b40_m=new Int8Array([-2,-1,0,1,2,0,0,1,2,3,4,0,2,3,4,5,6,3,4,5,6,7,0,5,6,7,8,9,0,7,8,9,10,11,0,9,10,11,12,13])
  12. abc2svg.b40k=new Int8Array([36,1,2,3,8,2,2,7,8,13,14,2,8,13,14,19,20,13,14,19,20,25,2,19,24,25,30,31,2,25,30,31,36,37,2,31,36,37,42,43])
  13. abc2svg.b40sf=new Int8Array([-2,-7,0,7,2,88,0,-5,2,-3,4,88,2,-3,4,-1,6,-3,4,-1,6,1,88,-1,-6,1,-4,3,88,1,-4,3,-2,5,88,3,-2,5,0,7])
  14. abc2svg.isb40=new Int8Array([0,1,6,11,12,17,18,23,28,29,34,35])
  15. abc2svg.pab40=function(p,a){p+=19
  16. var b40=((p/7)|0)*40+abc2svg.p_b40[p%7]
  17. if(a&&a!=3)
  18. b40+=a
  19. return b40}
  20. abc2svg.b40p=function(b){return((b/40)|0)*7+abc2svg.b40_p[b%40]-19}
  21. abc2svg.b40a=function(b){return abc2svg.b40_a[b%40]}
  22. abc2svg.b40m=function(b){return((b/40)|0)*12+abc2svg.b40_m[b%40]}
  23. abc2svg.ch_alias={"maj":"","min":"m","-":"m","°":"dim","+":"aug","+5":"aug","maj7":"M7","Δ7":"M7","Δ":"M7","min7":"m7","-7":"m7","ø7":"m7b5","°7":"dim7","min+7":"m+7","aug7":"+7","7+5":"+7","7#5":"+7","sus":"sus4","7sus":"7sus4"}
  24. abc2svg.font_tb=[]
  25. abc2svg.font_st={}
  26. abc2svg.ft_w={thin:100,extralight:200,light:300,regular:400,medium:500,semi:600,demi:600,semibold:600,demibold:600,bold:700,extrabold:800,ultrabold:800,black:900,heavy:900}
  27. abc2svg.ft_re=new RegExp('\
  28. -?Thin|-?Extra Light|-?Light|-?Regular|-?Medium|\
  29. -?[DS]emi|-?[DS]emi[ -]?Bold|\
  30. -?Bold|-?Extra[ -]?Bold|-?Ultra[ -]?Bold|-?Black|-?Heavy/',"i")
  31. abc2svg.rat=function(n,d){var a,t,n0=0,d1=0,n1=1,d0=1
  32. while(1){if(d==0)
  33. break
  34. t=d
  35. a=(n/d)|0
  36. d=n%d
  37. n=t
  38. t=n0+a*n1
  39. n0=n1
  40. n1=t
  41. t=d0+a*d1
  42. d0=d1
  43. d1=t}
  44. return[n1,d1]}
  45. abc2svg.pitcmp=function(n1,n2){return n1.pit-n2.pit}
  46. abc2svg.Abc=function(user){"use strict";var C=abc2svg.C;var require=empty_function,system=empty_function,write=empty_function,XMLHttpRequest=empty_function;var OPEN_BRACE=0x01,CLOSE_BRACE=0x02,OPEN_BRACKET=0x04,CLOSE_BRACKET=0x08,OPEN_PARENTH=0x10,CLOSE_PARENTH=0x20,STOP_BAR=0x40,FL_VOICE=0x80,OPEN_BRACE2=0x0100,CLOSE_BRACE2=0x0200,OPEN_BRACKET2=0x0400,CLOSE_BRACKET2=0x0800,MASTER_VOICE=0x1000,IN=96,CM=37.8,YSTEP
  47. var errs={bad_char:"Bad character '$1'",bad_grace:"Bad character in grace note sequence",bad_transp:"Bad transpose value",bad_val:"Bad value in $1",bar_grace:"Cannot have a bar in grace notes",ignored:"$1: inside tune - ignored",misplaced:"Misplaced '$1' in %%score",must_note:"!$1! must be on a note",must_note_rest:"!$1! must be on a note or a rest",nonote_vo:"No note in voice overlay",not_ascii:"Not an ASCII character",not_enough_n:'Not enough notes/rests for %%repeat',not_enough_m:'Not enough measures for %%repeat',not_enough_p:"Not enough parameters in %%map",not_in_tune:"Cannot have '$1' inside a tune",notransp:"Cannot transpose with a temperament"}
  48. var self=this,glovar={meter:{type:C.METER,wmeasure:1,a_meter:[]},},info={},parse={ctx:{},prefix:'%',state:0,ottava:[],line:new scanBuf},tunes=[],psvg
  49. function clone(obj,lvl){if(!obj)
  50. return obj
  51. var tmp=new obj.constructor
  52. for(var k in obj)
  53. if(obj.hasOwnProperty(k)){if(lvl&&typeof obj[k]=="object")
  54. tmp[k]=clone(obj[k],lvl-1)
  55. else
  56. tmp[k]=obj[k]}
  57. return tmp}
  58. function errbld(sev,txt,fn,idx){var i,j,l,c,h
  59. if(user.errbld){switch(sev){case 0:sev="warn";break
  60. case 1:sev="error";break
  61. default:sev="fatal";break}
  62. user.errbld(sev,txt,fn,idx)
  63. return}
  64. if(idx!=undefined&&idx>=0){i=l=0
  65. while(1){j=parse.file.indexOf('\n',i)
  66. if(j<0||j>idx)
  67. break
  68. l++;i=j+1}
  69. c=idx-i}
  70. h=""
  71. if(fn){h=fn
  72. if(l)
  73. h+=":"+(l+1)+":"+(c+1);h+=" "}
  74. switch(sev){case 0:h+="Warning: ";break
  75. case 1:h+="Error: ";break
  76. default:h+="Internal bug: ";break}
  77. user.errmsg(h+txt,l,c)}
  78. function error(sev,s,msg,a1,a2,a3,a4){var i,j,regex,tmp
  79. if(!sev&&cfmt.quiet)
  80. return
  81. if(s){if(s.err)
  82. return
  83. s.err=true}
  84. if(user.textrans){tmp=user.textrans[msg]
  85. if(tmp)
  86. msg=tmp}
  87. if(arguments.length>3)
  88. msg=msg.replace(/\$./g,function(a){switch(a){case'$1':return a1
  89. case'$2':return a2
  90. case'$3':return a3
  91. default:return a4}})
  92. if(s&&s.fname)
  93. errbld(sev,msg,s.fname,s.istart)
  94. else
  95. errbld(sev,msg)}
  96. function scanBuf(){this.index=0;scanBuf.prototype.char=function(){return this.buffer[this.index]}
  97. scanBuf.prototype.next_char=function(){return this.buffer[++this.index]}
  98. scanBuf.prototype.get_int=function(){var val=0,c=this.buffer[this.index]
  99. while(c>='0'&&c<='9'){val=val*10+Number(c);c=this.next_char()}
  100. return val}}
  101. function syntax(sev,msg,a1,a2,a3,a4){var s={fname:parse.fname,istart:parse.istart+parse.line.index}
  102. error(sev,s,msg,a1,a2,a3,a4)}
  103. function js_inject(js){if(!/eval *\(|Function|setTimeout|setInterval/.test(js))
  104. eval('"use strict";\n'+js)
  105. else
  106. syntax(1,"Unsecure code")}
  107. var dd_tb={},a_de,cross
  108. var decos={dot:"0 stc 6 1.5 1",tenuto:"0 emb 6 4 3",slide:"1 sld 3 7 1",arpeggio:"2 arp 12 10 3",roll:"3 roll 5,4 5 6",lowermordent:"3 lmrd 6,5 4 6",uppermordent:"3 umrd 6,5 4 6",trill:"3 trl 14 5 8",upbow:"3 upb 10,2 3 7",downbow:"3 dnb 9 4 6",gmark:"3 grm 7 4 6",wedge:"0 wedge 8 1.5 1",longphrase:"5 lphr 0 1 16",mediumphrase:"5 mphr 0 1 16",shortphrase:"5 sphr 0 1 16",turnx:"3 turnx 7,2.5 5 6",invertedturn:"3 turn 7,2 5 6","0":"3 fng 5,5 3 3 0","1":"3 fng 5,5 3 3 1","2":"3 fng 5,5 3 3 2","3":"3 fng 5,5 3 3 3","4":"3 fng 5,5 3 3 4","5":"3 fng 5,5 3 3 5",plus:"3 dplus 8,2 2 4","+":"3 dplus 8,2 2 4",">":"5 accent 3.5,3.5 4 4",accent:"5 accent 3.5,3.5 4 4",emphasis:"5 accent 3.5,3.5 4 4",marcato:"3 marcato 9 5 5","^":"3 marcato 9 5 5",mordent:"3 lmrd 6,5 4 6",open:"3 opend 8 3 3",snap:"3 snap 10 3 3",thumb:"3 thumb 10 3 3",turn:"3 turn 7,2.5 5 6","trill(":"5 ltr 8 0 0","trill)":"5 ltr 8 0 0","8va(":"5 8va 12 6 6","8va)":"5 8va 12 6 6","8vb(":"4 8vb 10,5 6 6","8vb)":"4 8vb 10,5 6 6","15ma(":"5 15ma 12 9 9","15ma)":"5 15ma 12 9 9","15mb(":"4 15mb 12 9 9","15mb)":"4 15mb 12 9 9",breath:"5 brth 0 1 16",caesura:"5 caes 0 1 20",short:"5 short 0 1 16",tick:"5 tick 0 1 16",coda:"5 coda 22,5 10 10",dacapo:"5 dacs 16 20 20 Da Capo",dacoda:"5 dacs 16 20 20 Da Coda","D.C.":"5 dcap 16,3 12 12","D.S.":"5 dsgn 16,3 12 12","D.C.alcoda":"5 dacs 16 38 38 D.C. al Coda","D.S.alcoda":"5 dacs 16 38 38 D.S. al Coda","D.C.alfine":"5 dacs 16 38 38 D.C. al Fine","D.S.alfine":"5 dacs 16 38 38 D.S. al Fine",fermata:"5 hld 12 7.5 7.5",fine:"5 dacs 16 14 14 Fine",invertedfermata:"7 hld 12 8 8",segno:"5 sgno 22,2 5 5",f:"6 f 12,5 3 4",ff:"6 ff 12,5 8 5",fff:"6 fff 12,5 11 9",ffff:"6 ffff 12,5 15 12",mf:"6 mf 12,5 8 10",mp:"6 mp 12,5 9 10",p:"6 p 12,5 3 6",pp:"6 pp 12,5 8 9",ppp:"6 ppp 12,5 14 11",pppp:"6 pppp 12,5 14 17",pralltriller:"3 umrd 6,5 4 6",sfz:"6 sfz 12,5 9 9",ped:"7 ped 14 6 10","ped-up":"7 pedoff 12 4 4","ped(":"7 lped 14 1 1","ped)":"7 lped 14 1 1","crescendo(":"6 cresc 15,2 0 0","crescendo)":"6 cresc 15,2 0 0","<(":"6 cresc 15,2 0 0","<)":"6 cresc 15,2 0 0","diminuendo(":"6 dim 15,2 0 0","diminuendo)":"6 dim 15,2 0 0",">(":"6 dim 15,2 0 0",">)":"6 dim 15,2 0 0","-(":"8 gliss 0 0 0","-)":"8 gliss 0 0 0","~(":"8 glisq 0 0 0","~)":"8 glisq 0 0 0",invisible:"32 0 0 0 0",beamon:"33 0 0 0 0",trem1:"34 0 0 0 0",trem2:"34 0 0 0 0",trem3:"34 0 0 0 0",trem4:"34 0 0 0 0",xstem:"35 0 0 0 0",beambr1:"36 0 0 0 0",beambr2:"36 0 0 0 0",rbstop:"37 0 0 0 0","/":"38 0 0 6 6","//":"38 0 0 6 6","///":"38 0 0 6 6","beam-accel":"39 0 0 0 0","beam-rall":"39 0 0 0 0",stemless:"40 0 0 0 0",rbend:"41 0 0 0 0",editorial:"42 0 0 0 0","sacc-1":"3 sacc-1 6,4 4 4",sacc3:"3 sacc3 6,5 4 4",sacc1:"3 sacc1 6,4 4 4",courtesy:"43 0 0 0 0","cacc-1":"3 cacc-1 0 0 0",cacc3:"3 cacc3 0 0 0",cacc1:"3 cacc1 0 0 0","tie(":"44 0 0 0 0","tie)":"44 0 0 0 0"},f_near=[d_near,d_slide,d_arp],f_note=[null,null,null,d_upstaff,d_upstaff],f_staff=[null,null,null,null,null,d_upstaff,d_upstaff,d_upstaff]
  109. function y_get(st,up,x,w){var y,p_staff=staff_tb[st],i=(x/2)|0,j=((x+w)/2)|0
  110. if(i<0)
  111. i=0
  112. if(j>=YSTEP){j=YSTEP-1
  113. if(i>j)
  114. i=j}
  115. if(up){y=p_staff.top[i++]
  116. while(i<=j){if(y<p_staff.top[i])
  117. y=p_staff.top[i];i++}}else{y=p_staff.bot[i++]
  118. while(i<=j){if(y>p_staff.bot[i])
  119. y=p_staff.bot[i];i++}}
  120. return y}
  121. function y_set(st,up,x,w,y){var p_staff=staff_tb[st],i=(x/2)|0,j=((x+w)/2)|0
  122. if(i<0)
  123. i=0
  124. if(j>=YSTEP){j=YSTEP-1
  125. if(i>j)
  126. i=j}
  127. if(up){while(i<=j){if(p_staff.top[i]<y)
  128. p_staff.top[i]=y;i++}}else{while(i<=j){if(p_staff.bot[i]>y)
  129. p_staff.bot[i]=y;i++}}}
  130. function up3(s,pos){switch(pos&0x07){case C.SL_ABOVE:return 1
  131. case C.SL_BELOW:return 0}
  132. return!s.second}
  133. function up6(s,pos){switch(pos&0x07){case C.SL_ABOVE:return true
  134. case C.SL_BELOW:return false}
  135. if(s.multi)
  136. return s.multi>0
  137. if(!s.p_v.have_ly)
  138. return false
  139. return(s.pos.voc&0x07)!=C.SL_ABOVE}
  140. function d_arp(de){var m,h,dx,s=de.s,dd=de.dd,xc=dd.wr
  141. if(s.type==C.NOTE){for(m=0;m<=s.nhd;m++){if(s.notes[m].acc){dx=s.notes[m].shac}else{dx=1-s.notes[m].shhd
  142. switch(s.head){case C.SQUARE:dx+=3.5
  143. break
  144. case C.OVALBARS:case C.OVAL:dx+=2
  145. break}}
  146. if(dx>xc)
  147. xc=dx}}
  148. h=3*(s.notes[s.nhd].pit-s.notes[0].pit)+4;m=dd.h
  149. if(h<m)
  150. h=m;de.has_val=true;de.val=h;de.x-=xc;de.y=3*((s.notes[0].pit+s.notes[s.nhd].pit)/2-18)-h/2-3}
  151. function d_near(de){var y,up=de.up,s=de.s,dd=de.dd
  152. if(dd.str){return}
  153. y=up?s.ymx:s.ymn
  154. if(y>0&&y<24){y=(((y+9)/6)|0)*6-6}
  155. if(up){y+=dd.hd
  156. s.ymx=y+dd.h}else if(dd.name[0]=='w'){de.inv=true
  157. y-=dd.h
  158. s.ymn=y}else{y-=dd.h
  159. s.ymn=y-dd.hd}
  160. de.x-=dd.wl
  161. de.y=y
  162. if(s.type==C.NOTE)
  163. de.x+=s.notes[s.stem>=0?0:s.nhd].shhd
  164. if(dd.name[0]=='d'){if(!(s.beam_st&&s.beam_end)){if(up){if(s.stem>0)
  165. de.x+=3.5}else{if(s.stem<0)
  166. de.x-=3.5}}else{if(up&&s.stem>0){y=s.y+(y-s.y)*.6
  167. if(y>=27){de.y=y
  168. s.ymx=de.y+dd.h}}}}}
  169. function d_slide(de){var m,dx,s=de.s,yc=s.notes[0].pit,xc=5
  170. for(m=0;m<=s.nhd;m++){if(s.notes[m].acc){dx=4+s.notes[m].shac}else{dx=5-s.notes[m].shhd
  171. switch(s.head){case C.SQUARE:dx+=3.5
  172. break
  173. case C.OVALBARS:case C.OVAL:dx+=2
  174. break}}
  175. if(s.notes[m].pit<=yc+3&&dx>xc)
  176. xc=dx}
  177. de.x-=xc;de.y=3*(yc-18)}
  178. function d_trill(de){if(de.ldst)
  179. return
  180. var y,w,tmp,dd=de.dd,de2=de.prev,up=de.up,s2=de.s,st=s2.st,s=de.start.s,x=s.x
  181. function sh_st(){var de3,de2=de.start,s=de2.s,i=de2.ix
  182. while(--i>=0){de3=a_de[i]
  183. if(!de3||de3.s!=s)
  184. break}
  185. while(1){i++
  186. de3=a_de[i]
  187. if(!de3||de3.s!=s)
  188. break
  189. if(de3==de2)
  190. continue
  191. if(!(up^de3.up)&&(de3.dd.name=="trill"||de3.dd.func==6)){x+=de3.dd.wr+2
  192. break}}}
  193. function sh_en(){var de3,i=de.ix
  194. while(--i>0){de3=a_de[i]
  195. if(!de3||de3.s!=s2)
  196. break}
  197. while(1){i++
  198. de3=a_de[i]
  199. if(!de3||de3.s!=s2)
  200. break
  201. if(de3==de)
  202. continue
  203. if(!(up^de3.up)&&de3.dd.func==6){w-=de3.dd.wl
  204. break}}}
  205. if(de2){x=de2.s.x+de.dd.wl+2
  206. de2.val-=de2.dd.wr
  207. if(de2.val<8)
  208. de2.val=8}
  209. de.st=st
  210. sh_st()
  211. if(de.defl.noen){w=de.x-x
  212. if(w<20){x=de.x-20-3;w=20}}else{w=s2.x-x-4
  213. sh_en(de)
  214. if(w<20)
  215. w=20}
  216. y=y_get(st,up,x-dd.wl,w)
  217. if(up){tmp=staff_tb[s.st].topbar+2
  218. if(y<tmp)
  219. y=tmp}else{tmp=staff_tb[s.st].botbar-2
  220. if(y>tmp)
  221. y=tmp
  222. y-=dd.h}
  223. if(de2){if(up){if(y<de2.y)
  224. y=de2.y}else{if(y>=de2.y){y=de2.y}else{do{de2.y=y
  225. de2=de2.prev}while(de2)}}}
  226. de.lden=false;de.has_val=true;de.val=w;de.x=x;de.y=y
  227. if(up)
  228. y+=dd.h;else
  229. y-=dd.hd
  230. y_set(st,up,x,w,y)
  231. if(up)
  232. s.ymx=s2.ymx=y
  233. else
  234. s.ymn=s2.ymn=y}
  235. function d_upstaff(de){if(de.ldst)
  236. return
  237. if(de.start){d_trill(de)
  238. return}
  239. var y,inv,up=de.up,s=de.s,dd=de.dd,x=de.x,w=dd.wl+dd.wr
  240. switch(dd.glyph){case"brth":case"caes":case"lphr":case"mphr":case"sphr":case"short":case"tick":y=staff_tb[s.st].topbar+2+dd.hd
  241. if(s.type==C.BAR){s.invis=1}else{if(dd.glyph=="brth"&&y<s.ymx)
  242. y=s.ymx
  243. for(s=s.ts_next;s;s=s.ts_next)
  244. if(s.seqst)
  245. break
  246. x+=((s?s.x:realwidth)-x)*.45}
  247. de.x=x
  248. de.y=y
  249. return}
  250. if(s.nhd)
  251. x+=s.notes[s.stem>=0?0:s.nhd].shhd;switch(dd.ty){case'@':case'<':case'>':y=de.y
  252. break}
  253. if(y==undefined){if(up){y=y_get(s.st,true,x-dd.wl,w)
  254. +dd.hd
  255. if(de.y>y)
  256. y=de.y
  257. s.ymx=y+dd.h}else{y=y_get(s.st,false,x-dd.wl,w)
  258. -dd.h
  259. if(de.y<y)
  260. y=de.y
  261. if(dd.name=="fermata"||dd.glyph=="accent"||dd.glyph=="roll")
  262. de.inv=1
  263. s.ymn=y-dd.hd}}
  264. if(dd.wr>10&&x>realwidth-dd.wr)
  265. de.x=x=realwidth-dd.wr-dd.wl
  266. if(up)
  267. y_set(s.st,1,x-dd.wl,w,y+dd.h)
  268. else
  269. y_set(s.st,0,x-dd.wl,w,y-dd.hd)
  270. de.y=y}
  271. function deco_add(param){var dv=param.match(/(\S*)\s+(.*)/);decos[dv[1]]=dv[2]}
  272. function deco_def(nm,nmd){if(!nmd)
  273. nmd=nm
  274. var a,dd,dd2,nm2,c,i,elts,str,hd,text=decos[nmd]
  275. if(!text&&/\d[()]$/.test(nmd))
  276. text=decos[nmd.replace(/\d/,'')]
  277. if(!text){if(cfmt.decoerr)
  278. error(1,null,"Unknown decoration '$1'",nm)
  279. return}
  280. a=text.match(/(\d+)\s+(.+?)\s+([0-9.,]+)\s+([0-9.]+)\s+([0-9.]+)/)
  281. if(!a){error(1,null,"Invalid decoration '$1'",nm)
  282. return}
  283. var c_func=Number(a[1]),h=a[3],wl=parseFloat(a[4]),wr=parseFloat(a[5])
  284. if(isNaN(c_func)){error(1,null,"%%deco: bad C function value '$1'",a[1])
  285. return}
  286. if(c_func>10&&(c_func<32||c_func>44)){error(1,null,"%%deco: bad C function index '$1'",c_func)
  287. return}
  288. if(h.indexOf(',')>0){h=h.split(',')
  289. hd=h[1]
  290. h=h[0]}else{hd=0}
  291. if(h>50||wl>80||wr>80){error(1,null,"%%deco: abnormal h/wl/wr value '$1'",text)
  292. return}
  293. dd=dd_tb[nm]
  294. if(!dd){dd={name:nm}
  295. dd_tb[nm]=dd}
  296. dd.func=nm.indexOf("head-")==0?9:c_func;dd.glyph=a[2];dd.h=Number(h)
  297. dd.hd=Number(hd)
  298. dd.wl=wl;dd.wr=wr;str=text.replace(a[0],'').trim()
  299. if(str){if(str[0]=='"')
  300. str=str.slice(1,-1);if(str[0]=='@'&&!str.match(/^@([0-9.-]+),([0-9.-]+);?/)){error(1,null,"%%deco: bad position '$1'",str)
  301. return}
  302. dd.str=str}
  303. if(dd.func==6&&dd.str==undefined)
  304. dd.str=nm
  305. c=nm.slice(-1)
  306. if(c=='('||(c==')'&&nm.indexOf('(')<0)){dd.str=null;nm2=nm.slice(0,-1)+(c=='('?')':'(');dd2=dd_tb[nm2]
  307. if(dd2){if(c=='('){dd.dd_en=dd2;dd2.dd_st=dd}else{dd.dd_st=dd2;dd2.dd_en=dd}}}
  308. return dd}
  309. function do_ctie(nm,s,nt1){var nt2=cross[nm],nm2=nm.slice(0,-1)+(nm.slice(-1)=='('?')':'(')
  310. if(nt2){error(1,s,"Conflict on !$1!",nm)
  311. return}
  312. nt1.s=s
  313. nt2=cross[nm2]
  314. if(!nt2){cross[nm]=nt1
  315. return}
  316. if(nm.slice(-1)==')'){nt2=nt1
  317. nt1=cross[nm2]}
  318. cross[nm2]=null
  319. if(nt1.midi!=nt2.midi||nt1.s.time+nt1.s.dur!=nt2.s.time){error(1,s,"Bad tie")}else{nt1.tie_ty=C.SL_AUTO
  320. nt1.tie_e=nt2
  321. nt2.tie_s=nt1
  322. nt1.s.ti1=nt2.s.ti2=true}}
  323. function get_dd(nm){var ty,p,dd=dd_tb[nm]
  324. if(dd)
  325. return dd
  326. if("<>^_@".indexOf(nm[0])>=0&&!/^([>^]|[<>]\d?[()])$/.test(nm)){ty=nm[0]
  327. if(ty=='@'){p=nm.match(/@([-\d]+),([-\d]+)/)
  328. if(p)
  329. ty=p[0]
  330. else
  331. ty=''}
  332. dd=deco_def(nm,nm.replace(ty,''))}else{dd=deco_def(nm)}
  333. if(!dd)
  334. return
  335. if(ty){if(ty[0]=='@'){dd.x=Number(p[1])
  336. dd.y=Number(p[2])
  337. ty='@'}
  338. dd.ty=ty}
  339. return dd}
  340. function deco_cnv(s,prev){var i,j,dd,nm,note,s1,court
  341. while(1){nm=a_dcn.shift()
  342. if(!nm)
  343. break
  344. dd=get_dd(nm)
  345. if(!dd)
  346. continue
  347. switch(dd.func){case 0:if(s.type==C.BAR&&nm=="dot"){s.bar_dotted=true
  348. continue}
  349. case 1:case 2:if(!s.notes){error(1,s,errs.must_note_rest,nm)
  350. continue}
  351. break
  352. case 4:case 5:i=nm.match(/1?[85]([vm])([ab])([()])/)
  353. if(i){j=i[1]=='v'?1:2
  354. if(i[2]=='b')
  355. j=-j
  356. if(!s.ottava)
  357. s.ottava=[]
  358. s.ottava[i[3]=='('?0:1]=j
  359. glovar.ottava=1}
  360. break
  361. case 8:if(s.type!=C.NOTE){error(1,s,errs.must_note,nm)
  362. continue}
  363. note=s.notes[s.nhd]
  364. if(!note.a_dd)
  365. note.a_dd=[]
  366. note.a_dd.push(dd)
  367. continue
  368. case 9:if(!s.notes){error(1,s,errs.must_note_rest,nm)
  369. continue}
  370. for(j=0;j<=s.nhd;j++){note=s.notes[j]
  371. note.invis=true
  372. if(!note.a_dd)
  373. note.a_dd=[]
  374. note.a_dd.push(dd)}
  375. continue
  376. case 10:if(s.notes){for(j=0;j<=s.nhd;j++)
  377. s.notes[j].color=nm}else{s.color=nm}
  378. break
  379. case 32:s.invis=true
  380. break
  381. case 33:if(s.type!=C.BAR){error(1,s,"!beamon! must be on a bar")
  382. continue}
  383. s.beam_on=true
  384. break
  385. case 34:if(s.type!=C.NOTE||!prev||prev.type!=C.NOTE||s.dur!=prev.dur){error(1,s,"!$1! must be on the last of a couple of notes",nm)
  386. continue}
  387. s.trem2=true;s.beam_end=true;s.beam_st=false;prev.beam_st=true;prev.beam_end=false;s.ntrem=prev.ntrem=Number(nm[4]);for(j=0;j<=s.nhd;j++)
  388. s.notes[j].dur*=2;for(j=0;j<=prev.nhd;j++)
  389. prev.notes[j].dur*=2
  390. break
  391. case 35:if(s.type!=C.NOTE){error(1,s,errs.must_note,nm)
  392. continue}
  393. s.xstem=true;break
  394. case 36:if(s.type!=C.NOTE){error(1,s,errs.must_note,nm)
  395. continue}
  396. if(nm[6]=='1')
  397. s.beam_br1=true
  398. else
  399. s.beam_br2=true
  400. break
  401. case 37:s.rbstop=1
  402. break
  403. case 38:if(s.type!=C.NOTE){error(1,s,errs.must_note,nm)
  404. continue}
  405. s.trem1=true;s.ntrem=nm.length
  406. break
  407. case 39:if(s.type!=C.NOTE){error(1,s,errs.must_note,nm)
  408. continue}
  409. s.feathered_beam=nm[5]=='a'?1:-1;break
  410. case 40:s.stemless=true
  411. break
  412. case 41:s.rbstop=2
  413. break
  414. case 42:if(!s.notes[0].acc)
  415. continue
  416. nm="sacc"+s.notes[0].acc.toString()
  417. dd=dd_tb[nm]
  418. if(!dd){dd=deco_def(nm)
  419. if(!dd){error(1,s,errs.bad_val,"!editorial!")
  420. continue}}
  421. delete s.notes[0].acc
  422. curvoice.acc[s.notes[0].pit+19]=0
  423. break
  424. case 43:j=curvoice.acc[s.notes[0].pit+19]
  425. if(s.notes[0].acc||!j)
  426. continue
  427. court=1
  428. break
  429. case 44:do_ctie(nm,s,s.notes[0])
  430. continue}
  431. if(!s.a_dd)
  432. s.a_dd=[]
  433. s.a_dd.push(dd)}
  434. if(court){a_dcn.push("cacc"+j)
  435. dh_cnv(s,s.notes[0])}}
  436. function dh_cnv(s,nt){var k,nm,dd
  437. while(1){nm=a_dcn.shift()
  438. if(!nm)
  439. break
  440. dd=get_dd(nm)
  441. if(!dd)
  442. continue
  443. switch(dd.func){case 0:case 1:case 3:case 4:case 8:break
  444. default:error(1,s,"Cannot have !$1! on a head",nm)
  445. continue
  446. case 9:nt.invis=true
  447. break
  448. case 32:nt.invis=true
  449. continue
  450. case 10:nt.color=nm
  451. continue
  452. case 40:s.stemless=true
  453. continue
  454. case 44:do_ctie(nm,s,nt)
  455. continue}
  456. if(!nt.a_dd)
  457. nt.a_dd=[]
  458. nt.a_dd.push(dd)}}
  459. function deco_update(s,dx){var i,de,nd=a_de.length
  460. for(i=0;i<nd;i++){de=a_de[i]
  461. if(de.s==s)
  462. de.x+=dx}}
  463. function deco_width(s,wlnt){var dd,i,w,wl=wlnt,wr=s.wr,a_dd=s.a_dd,nd=a_dd.length
  464. for(i=0;i<nd;i++){dd=a_dd[i]
  465. switch(dd.func){case 1:case 2:if(wl<12)
  466. wl=12
  467. break
  468. case 3:switch(dd.glyph){case"brth":case"lphr":case"mphr":case"sphr":if(s.wr<20)
  469. s.wr=20
  470. break
  471. default:w=dd.wl+2
  472. if(wl<w)
  473. wl=w
  474. break}
  475. default:switch(dd.ty){case'<':w=wlnt+dd.wl+dd.wr+6
  476. if(wl<w)
  477. wl=w
  478. break
  479. case'>':w=wr+dd.wl+dd.wr+6
  480. if(s.wr<w)
  481. s.wr=w
  482. break}
  483. break}}
  484. return wl}
  485. function deco_wch(nt){var i,w,dd,wl=0,n=nt.a_dd.length
  486. for(i=0;i<n;i++){dd=nt.a_dd[i]
  487. if(dd.ty=='<'){w=dd.wl+dd.wr+4
  488. if(w>wl)
  489. wl=w}}
  490. return wl}
  491. Abc.prototype.draw_all_deco=function(){if(!a_de.length)
  492. return
  493. var de,dd,s,note,f,st,x,y,y2,ym,uf,i,str,a,new_de=[],ymid=[]
  494. st=nstaff;y=staff_tb[st].y
  495. while(--st>=0){y2=staff_tb[st].y;ymid[st]=(y+24+y2)*.5;y=y2}
  496. while(1){de=a_de.shift()
  497. if(!de)
  498. break
  499. dd=de.dd
  500. if(!dd)
  501. continue
  502. if(dd.dd_en)
  503. continue
  504. s=de.s
  505. f=dd.glyph;i=f.indexOf('/')
  506. if(i>0){if(s.stem>=0)
  507. f=f.slice(0,i)
  508. else
  509. f=f.slice(i+1)}
  510. if(f_staff[dd.func])
  511. set_sscale(s.st)
  512. else
  513. set_scale(s);st=de.st;if(!staff_tb[st].topbar)
  514. continue
  515. x=de.x;y=de.y+staff_tb[st].y
  516. if(de.m!=undefined){note=s.notes[de.m];if(note.shhd)
  517. x+=note.shhd*stv_g.scale}else if(dd.func==6&&((de.pos&C.SL_ALI_MSK)==C.SL_CENTER||((de.pos&C.SL_ALI_MSK)==0&&!s.fmt.dynalign))&&((de.up&&st>0)||(!de.up&&st<nstaff))){if(de.up)
  518. ym=ymid[--st]
  519. else
  520. ym=ymid[st++];ym-=dd.h*.5
  521. if((de.up&&y<ym)||(!de.up&&y>ym)){y2=y_get(st,!de.up,de.x,de.val)
  522. +staff_tb[st].y
  523. if(de.up)
  524. y2-=dd.h
  525. if((de.up&&y2>ym)||(!de.up&&y2<ym)){y=ym;if(stv_g.scale!=1)
  526. y+=stv_g.dy/2}}}
  527. uf=user[f]
  528. if(uf&&typeof(uf)=="function"){uf(x,y,de)
  529. continue}
  530. if(self.psdeco(f,x,y,de))
  531. continue
  532. anno_start(s,'deco')
  533. if(de.inv){y=y+dd.h-dd.hd
  534. g_open(x,y,0,1,-1);x=y=0}
  535. if(de.has_val){if(dd.func!=2||stv_g.st<0)
  536. out_deco_val(x,y,f,de.val/stv_g.scale,de.defl)
  537. else
  538. out_deco_val(x,y,f,de.val,de.defl)
  539. if(de.cont)
  540. new_de.push(de.start)}else if(dd.str!=undefined){str=dd.str
  541. if(str[0]=='@'){a=str.match(/^@([0-9.-]+),([0-9.-]+);?/);x+=Number(a[1]);y+=Number(a[2]);str=str.replace(a[0],"")}
  542. out_deco_str(x,y,f,str)}else if(de.lden){out_deco_long(x,y,de)}else{xygl(x,y,f)}
  543. if(stv_g.g)
  544. g_close();anno_stop(s,'deco')}
  545. a_de=new_de}
  546. function draw_deco_near(){var s,g
  547. function ldeco_update(s){var i,de,x=s.x-s.wl,nd=a_de.length
  548. for(i=0;i<nd;i++){de=a_de[i];de.ix=i;de.s.x=de.x=x;de.defl.nost=true}}
  549. function create_deco(s){var dd,k,pos,de,x,y,up,nd=s.a_dd.length
  550. if(s.y==undefined)
  551. s.y=0
  552. for(k=0;k<nd;k++){dd=s.a_dd[k]
  553. x=s.x
  554. y=s.y
  555. switch(dd.func){default:if(dd.func>=10)
  556. continue
  557. pos=0
  558. break
  559. case 3:case 4:case 5:pos=s.pos.orn
  560. break
  561. case 6:pos=s.pos.dyn
  562. break}
  563. switch(dd.ty){case'^':pos=(pos&~0x07)|C.SL_ABOVE
  564. break
  565. case'_':pos=(pos&~0x07)|C.SL_BELOW
  566. break
  567. case'<':case'>':pos=(pos&0x07)|C.SL_CLOSE
  568. if(dd.ty=='<'){x-=dd.wr+8
  569. if(s.notes[0].acc)
  570. x-=8}else{x+=dd.wl+8}
  571. y=3*(s.notes[0].pit-18)
  572. -(dd.h-dd.hd)/2
  573. break
  574. case'@':x+=dd.x
  575. y+=dd.y
  576. break}
  577. if((pos&0x07)==C.SL_HIDDEN)
  578. continue
  579. de={s:s,dd:dd,st:s.st,ix:a_de.length,defl:{},x:x,y:y}
  580. if(pos)
  581. de.pos=pos
  582. up=0
  583. if(dd.ty=='^'){up=1}else if(dd.ty=='_'){}else{switch(dd.func){case 0:if(s.multi)
  584. up=s.multi>0
  585. else
  586. up=s.stem<0
  587. break
  588. case 3:case 5:up=up3(s,pos)
  589. break
  590. case 6:case 7:up=up6(s,pos)
  591. break}}
  592. de.up=up
  593. if(dd.name.indexOf("inverted")>=0)
  594. de.inv=1
  595. if(s.type==C.BAR&&!dd.ty)
  596. de.x-=s.wl/2-2
  597. a_de.push(de)
  598. if(dd.dd_en){de.ldst=true}else if(dd.dd_st){de.lden=true;de.defl.nost=true}
  599. if(f_near[dd.func])
  600. f_near[dd.func](de)}}
  601. function create_dh(s,m){var de,k,dd,note=s.notes[m],nd=note.a_dd.length,x=s.x
  602. for(k=0;k<nd;k++){dd=note.a_dd[k]
  603. de={s:s,dd:dd,st:s.st,m:m,ix:0,defl:{},x:x,y:3*(note.pit-18)-(dd.h-dd.hd)/2}
  604. if(dd.ty){if(dd.ty=='@'){de.x+=dd.x
  605. de.y+=dd.y}else{de.y-=(dd.h-dd.hd)/2
  606. if(dd.ty=='<'){de.x-=dd.wr+8
  607. if(s.notes[m].acc)
  608. x-=8}else if(dd.ty=='>'){de.x+=dd.wl+8}}}
  609. a_de.push(de)
  610. if(dd.dd_en){de.ldst=true}else if(dd.dd_st){de.lden=true;de.defl.nost=true}}}
  611. function create_all(s){if(s.invis&&s.play)
  612. return
  613. if(s.a_dd)
  614. create_deco(s)
  615. if(s.notes){for(var m=0;m<s.notes.length;m++){if(s.notes[m].a_dd)
  616. create_dh(s,m)}}}
  617. function ll_deco(){var i,j,de,de2,de3,dd,dd2,v,s,st,n_de=a_de.length
  618. for(i=0;i<n_de;i++){de=a_de[i]
  619. if(!de.ldst)
  620. continue
  621. dd=de.dd;dd2=dd.dd_en;s=de.s;v=s.v
  622. for(j=i+1;j<n_de;j++){de2=a_de[j]
  623. if(!de2.start&&de2.dd==dd2&&de2.s.v==v)
  624. break}
  625. if(j==n_de){st=s.st;for(j=i+1;j<n_de;j++){de2=a_de[j]
  626. if(!de2.start&&de2.dd==dd2&&de2.s.st==st)
  627. break}}
  628. if(j==n_de){de2={s:s,st:de.st,dd:dd2,ix:a_de.length-1,x:realwidth-6,y:s.y,cont:true,lden:true,defl:{noen:true}}
  629. if(de2.x<s.x+10)
  630. de2.x=s.x+10
  631. if(de.m!=undefined)
  632. de2.m=de.m;a_de.push(de2)}
  633. de2.start=de;de2.defl.nost=de.defl.nost
  634. j=i
  635. while(--j>=0){de3=a_de[j]
  636. if(!de3.start)
  637. continue
  638. if(de3.s.time<s.time)
  639. break
  640. if(de3.dd.name==de2.dd.name){de2.prev=de3
  641. break}}}
  642. for(i=0;i<n_de;i++){de2=a_de[i]
  643. if(!de2.lden||de2.start)
  644. continue
  645. s=de2.s;de={s:prev_scut(s),st:de2.st,dd:de2.dd.dd_st,ix:a_de.length-1,y:s.y,ldst:true}
  646. de.x=de.s.x+de.s.wr
  647. if(de2.m!=undefined)
  648. de.m=de2.m;a_de.push(de);de2.start=de}}
  649. for(s=tsfirst;s;s=s.ts_next){switch(s.type){case C.CLEF:case C.KEY:case C.METER:continue}
  650. break}
  651. if(a_de.length)
  652. ldeco_update(s)
  653. for(;s;s=s.ts_next){switch(s.type){case C.BAR:case C.MREST:case C.NOTE:case C.REST:case C.SPACE:break
  654. case C.GRACE:for(g=s.extra;g;g=g.next)
  655. create_all(g)
  656. break
  657. default:continue}
  658. create_all(s)}
  659. ll_deco()}
  660. function draw_deco_note(){var i,de,dd,f,nd=a_de.length
  661. for(i=0;i<nd;i++){de=a_de[i];dd=de.dd;f=dd.func
  662. if(f_note[f]&&de.m==undefined)
  663. f_note[f](de)}}
  664. function draw_deco_staff(){var s,p_voice,y,i,v,de,dd,w,minmax=new Array(nstaff+1),nd=a_de.length
  665. function draw_repbra(p_voice){var s,s1,x,y,y2,i,p,w,wh,first_repeat;y=staff_tb[p_voice.st].topbar+15
  666. for(s=p_voice.sym;s;s=s.next){if(s.type!=C.BAR)
  667. continue
  668. if(!s.rbstart||s.norepbra)
  669. continue
  670. if(!s.next)
  671. break
  672. if(!first_repeat){first_repeat=s;set_font("repeat")}
  673. s1=s
  674. for(;;){if(!s.next)
  675. break
  676. s=s.next
  677. if(s.rbstop)
  678. break}
  679. x=s1.x
  680. if(s1.xsh)
  681. x+=s1.xsh
  682. y2=y_get(p_voice.st,true,x,s.x-x)+2
  683. if(y<y2)
  684. y=y2
  685. if(s1.rbstart==2){y2=y_get(p_voice.st,true,x,3)+10
  686. if(y<y2)
  687. y=y2}
  688. if(s.rbstop==2){y2=y_get(p_voice.st,true,s.x-3,3)+10
  689. if(y<y2)
  690. y=y2}
  691. if(s1.text){wh=strwh(s1.text);y2=y_get(p_voice.st,true,x+4,wh[0])+
  692. wh[1]
  693. if(y<y2)
  694. y=y2}
  695. if(s.rbstart)
  696. s=s.prev}
  697. s=first_repeat
  698. if(!s)
  699. return
  700. set_dscale(p_voice.st,true);y2=y*staff_tb[p_voice.st].staffscale
  701. for(;s;s=s.next){if(!s.rbstart||s.norepbra)
  702. continue
  703. s1=s
  704. while(1){if(!s.next)
  705. break
  706. s=s.next
  707. if(s.rbstop)
  708. break}
  709. if(s1==s)
  710. break
  711. x=s1.x
  712. if(s1.xsh)
  713. x+=s1.xsh
  714. if(cfmt.measurenb>0&s.bar_num&&s.bar_num%cfmt.measurenb)
  715. x+=6
  716. if(s.type!=C.BAR){w=s.rbstop?0:s.x-realwidth+4}else if((s.bar_type.length>1&&s.bar_type!="[]")||s.bar_type=="]"){if(s1.st>0&&!(cur_sy.staves[s1.st-1].flags&STOP_BAR))
  717. w=s.wl
  718. else if(s.bar_type.slice(-1)==':')
  719. w=12
  720. else if(s.bar_type[0]!=':')
  721. w=0
  722. else
  723. w=8}else{w=(s.rbstop&&!s.rbstart)?0:8}
  724. w=(s.x-x-w)
  725. if(!s.next&&!s.rbstop&&!p_voice.bar_start){p_voice.bar_start=_bar(s)
  726. p_voice.bar_start.bar_type=""
  727. p_voice.bar_start.rbstart=1}
  728. if(s1.text)
  729. xy_str(x+4,y2-gene.curfont.size,s1.text);xypath(x,y2);if(s1.rbstart==2)
  730. output+='m0 10v-10';output+='h'+w.toFixed(1)
  731. if(s.rbstop==2)
  732. output+='v10';output+='"/>\n';y_set(s1.st,true,x,w,y+2)
  733. if(s.rbstart)
  734. s=s.prev}}
  735. for(i=0;i<=nstaff;i++)
  736. minmax[i]={ymin:0,ymax:0}
  737. for(i=0;i<nd;i++){de=a_de[i];dd=de.dd
  738. if(!dd)
  739. continue
  740. if(!f_staff[dd.func]||de.m!=undefined||dd.ty=='<'||dd.ty=='>'||dd.ty=='@')
  741. continue
  742. f_staff[dd.func](de)
  743. if(dd.func!=6||dd.dd_en)
  744. continue
  745. if((de.pos&C.SL_ALI_MSK)==C.SL_ALIGN||((de.pos&C.SL_ALI_MSK)==0&&de.s.fmt.dynalign>0)){if(de.up){if(de.y>minmax[de.st].ymax)
  746. minmax[de.st].ymax=de.y}else{if(de.y<minmax[de.st].ymin)
  747. minmax[de.st].ymin=de.y}}}
  748. for(i=0;i<nd;i++){de=a_de[i];dd=de.dd
  749. if(!dd)
  750. continue
  751. if(dd.ty=='@'){var y2
  752. y=de.y
  753. if(y>0){y2=y+dd.h+2
  754. if(y2>staff_tb[de.st].ann_top)
  755. staff_tb[de.st].ann_top=y2}else{y2=y-dd.hd-2
  756. if(y2<staff_tb[de.st].ann_bot)
  757. staff_tb[de.st].ann_bot=y2}
  758. continue}
  759. if(dd.func!=6||dd.ty=='<'||dd.ty=='>'||dd.dd_en)
  760. continue
  761. w=de.val||(dd.wl+dd.wr)
  762. if((de.pos&C.SL_ALI_MSK)==C.SL_ALIGN||((de.pos&C.SL_ALI_MSK)==0&&de.s.fmt.dynalign>0)){if(de.up)
  763. y=minmax[de.st].ymax
  764. else
  765. y=minmax[de.st].ymin;de.y=y}else{y=de.y}
  766. if(de.up)
  767. y+=dd.h;else
  768. y-=dd.hd
  769. y_set(de.st,de.up,de.x,w,y)}
  770. for(i=0;i<nd;i++){de=a_de[i]
  771. dd=de.dd
  772. if(!dd)
  773. continue
  774. if(dd.dd_en||dd.name.slice(0,3)!="ped")
  775. continue
  776. w=de.val||10
  777. de.y=y_get(de.st,0,de.x,w)
  778. -(dd.dd_st&&cfmt.pedline?10:dd.h)
  779. y_set(de.st,0,de.x,w,de.y)}
  780. draw_all_chsy()
  781. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v]
  782. if(p_voice.second||!p_voice.sym||p_voice.ignore)
  783. continue
  784. draw_repbra(p_voice)}}
  785. function draw_measnb(){var s,st,bar_num,x,y,w,any_nb,font_size,w0,sy=cur_sy
  786. for(st=0;st<=nstaff;st++){if(sy.st_print[st])
  787. break}
  788. if(st>nstaff)
  789. return
  790. set_dscale(st)
  791. if(staff_tb[st].staffscale!=1){font_size=get_font("measure").size;param_set_font("measurefont","* "+
  792. (font_size/staff_tb[st].staffscale).toString())}
  793. set_font("measure");w0=cwidf('0');s=tsfirst;bar_num=gene.nbar
  794. if(bar_num>1){if(cfmt.measurenb==0){any_nb=true;y=y_get(st,true,0,20)
  795. if(y<staff_tb[st].topbar+14)
  796. y=staff_tb[st].topbar+14;xy_str(0,y-gene.curfont.size*.2,bar_num.toString())
  797. y_set(st,true,0,20,y+gene.curfont.size+2)}else if(bar_num%cfmt.measurenb==0){for(;;s=s.ts_next){switch(s.type){case C.CLEF:case C.KEY:case C.METER:case C.STBRK:continue}
  798. break}
  799. if(s.type!=C.BAR||!s.bar_num){any_nb=true;w=w0
  800. if(bar_num>=10)
  801. w*=bar_num>=100?3:2
  802. if(gene.curfont.pad)
  803. w+=gene.curfont.pad*2
  804. x=(s.prev?s.prev.x+s.prev.wr/2:s.x-s.wl)-w
  805. y=y_get(st,true,x,w)+5
  806. if(y<staff_tb[st].topbar+6)
  807. y=staff_tb[st].topbar+6;y+=gene.curfont.pad
  808. xy_str(x,y-gene.curfont.size*.2,bar_num.toString())
  809. y+=gene.curfont.size+gene.curfont.pad
  810. y_set(st,true,x,w,y)}}}
  811. for(;s;s=s.ts_next){switch(s.type){case C.STAVES:sy=s.sy
  812. for(st=0;st<nstaff;st++){if(sy.st_print[st])
  813. break}
  814. set_dscale(st)
  815. continue
  816. default:continue
  817. case C.BAR:if(!s.bar_num||s.bar_num<=1)
  818. continue
  819. break}
  820. bar_num=s.bar_num
  821. if(cfmt.measurenb==0||(bar_num%cfmt.measurenb)!=0||!s.next||s.bar_mrep)
  822. continue
  823. if(!any_nb)
  824. any_nb=true;w=w0
  825. if(bar_num>=10)
  826. w*=bar_num>=100?3:2
  827. if(gene.curfont.pad)
  828. w+=gene.curfont.pad*2
  829. x=s.x
  830. y=y_get(st,true,x,w)
  831. if(y<staff_tb[st].topbar+6)
  832. y=staff_tb[st].topbar+6
  833. if(s.next.type==C.NOTE){if(s.next.stem>0){if(y<s.next.ys-gene.curfont.size)
  834. y=s.next.ys-gene.curfont.size}else{if(y<s.next.y)
  835. y=s.next.y}}
  836. y+=2+gene.curfont.pad
  837. xy_str(x,y-gene.curfont.size*.2,bar_num.toString())
  838. y+=gene.curfont.size+gene.curfont.pad
  839. y_set(st,true,x,w,y)}
  840. gene.nbar=bar_num
  841. if(font_size)
  842. param_set_font("measurefont","* "+font_size.toString())}
  843. function draw_partempo(){var s,s2,some_part,some_tempo,h,w,y,st,sy=cur_sy
  844. for(st=0;st<=nstaff;st++){if(sy.st_print[st])
  845. break}
  846. if(st>nstaff)
  847. return
  848. set_dscale(st,1)
  849. var ymin=staff_tb[st].topbar+2,dosh=0,shift=1,x=-100,yn=0
  850. for(s=tsfirst;s;s=s.ts_next){s2=s.part
  851. if(!s2||s2.invis)
  852. continue
  853. if(!some_part){some_part=s;set_font("parts");h=gene.curfont.size+2+
  854. gene.curfont.pad*2}
  855. if(s2.x==undefined)
  856. s2.x=s.x-10
  857. w=strwh(s2.text)[0]
  858. y=y_get(st,true,s2.x,w+3)
  859. if(ymin<y)
  860. ymin=y}
  861. if(some_part){set_sscale(-1)
  862. ymin*=staff_tb[st].staffscale
  863. for(s=some_part;s;s=s.ts_next){s2=s.part
  864. if(!s2||s2.invis)
  865. continue
  866. w=strwh(s2.text)[0]
  867. if(user.anno_start||user.anno_stop){s2.wl=0
  868. s2.wr=w
  869. s2.ymn=ymin
  870. s2.ymx=s2.ymn+h
  871. anno_start(s2)}
  872. xy_str(s2.x,ymin+2+gene.curfont.pad+gene.curfont.size*.22,s2.text)
  873. y_set(st,1,s2.x,w+3,ymin+2+h)
  874. if(s2.x<0)
  875. yn=ymin+2+h
  876. anno_stop(s2)}}
  877. ymin=staff_tb[st].topbar+6
  878. for(s=tsfirst;s;s=s.ts_next){if(s.type!=C.TEMPO||s.invis)
  879. continue
  880. if(!some_tempo)
  881. some_tempo=s
  882. w=s.tempo_wh[0]
  883. y=y_get(st,true,s.x-16,w)
  884. if(s.x-16<0)
  885. y=yn
  886. if(y>ymin)
  887. ymin=y
  888. if(x>=s.x-16&&!(dosh&(shift>>1)))
  889. dosh|=shift
  890. shift<<=1
  891. x=s.x-16+w}
  892. if(some_tempo){set_sscale(-1)
  893. set_font("tempo")
  894. h=gene.curfont.size
  895. ymin+=2
  896. ymin*=staff_tb[st].staffscale
  897. for(s=some_tempo;s;s=s.ts_next){if(s.type!=C.TEMPO||s.invis)
  898. continue
  899. w=s.tempo_wh[0]
  900. y=ymin
  901. if(dosh&1)
  902. y+=h
  903. if(user.anno_start||user.anno_stop){s.wl=16
  904. s.wr=w-16
  905. s.ymn=y
  906. s.ymx=s.ymn+14
  907. anno_start(s)}
  908. writempo(s,s.x-16,y)
  909. anno_stop(s)
  910. y_set(st,1,s.x-16,w,y+h+2)
  911. dosh>>=1}}}
  912. var STEM_MIN=16,STEM_MIN2=14,STEM_MIN3=12,STEM_MIN4=10,STEM_CH_MIN=14,STEM_CH_MIN2=10,STEM_CH_MIN3=9,STEM_CH_MIN4=9,BEAM_DEPTH=3.2,BEAM_OFFSET=.25,BEAM_SHIFT=5,BEAM_STUB=7,SLUR_SLOPE=.5,GSTEM=15,GSTEM_XOFF=2.3
  913. var cache,anno_a=[]
  914. function b_pos(grace,stem,nflags,b){var top,bot,d1,d2,shift=!grace?BEAM_SHIFT:3.5,depth=!grace?BEAM_DEPTH:1.8
  915. function rnd6(y){var iy=Math.round((y+12)/6)*6-12
  916. return iy-y}
  917. if(stem>0){bot=b-(nflags-1)*shift-depth
  918. if(bot>26)
  919. return 0
  920. top=b}else{top=b+(nflags-1)*shift+depth
  921. if(top<-2)
  922. return 0
  923. bot=b}
  924. d1=rnd6(top-BEAM_OFFSET);d2=rnd6(bot+BEAM_OFFSET)
  925. return d1*d1>d2*d2?d2:d1}
  926. function sym_dup(s){var m,note
  927. s=clone(s)
  928. s.invis=true
  929. delete s.extra;delete s.text
  930. delete s.a_gch
  931. delete s.a_ly
  932. delete s.a_dd;delete s.tp
  933. s.notes=clone(s.notes)
  934. for(m=0;m<=s.nhd;m++){note=s.notes[m]=clone(s.notes[m])
  935. delete note.a_dd}
  936. return s}
  937. var min_tb=[[STEM_MIN,STEM_MIN,STEM_MIN2,STEM_MIN3,STEM_MIN4,STEM_MIN4],[STEM_CH_MIN,STEM_CH_MIN,STEM_CH_MIN2,STEM_CH_MIN3,STEM_CH_MIN4,STEM_CH_MIN4]]
  938. Abc.prototype.calculate_beam=function(bm,s1){var s,s2,g,notes,nflags,st,v,two_staves,two_dir,x,y,ys,a,b,stem_err,max_stem_err,p_min,p_max,s_closest,stem_xoff,scale,visible,dy
  939. if(!s1.beam_st){s=sym_dup(s1);lkvsym(s,s1);lktsym(s,s1);s.x-=12
  940. if(s.x>s1.prev.x+12)
  941. s.x=s1.prev.x+12;s.beam_st=true
  942. delete s.beam_end;s.tmp=true
  943. delete s.sls;s1=s}
  944. notes=nflags=0;two_staves=two_dir=false;st=s1.st;v=s1.v;stem_xoff=s1.grace?GSTEM_XOFF:3.5
  945. for(s2=s1;;s2=s2.next){if(s2.type==C.NOTE){if(s2.nflags>nflags)
  946. nflags=s2.nflags;notes++
  947. if(s2.st!=st)
  948. two_staves=true
  949. if(s2.stem!=s1.stem)
  950. two_dir=true
  951. if(!visible&&!s2.invis&&(!s2.stemless||s2.trem2))
  952. visible=true
  953. if(s2.beam_end)
  954. break}
  955. if(!s2.next){for(;;s2=s2.prev){if(s2.type==C.NOTE)
  956. break}
  957. s=sym_dup(s2);s.next=s2.next
  958. if(s.next)
  959. s.next.prev=s;s2.next=s;s.prev=s2;s.ts_next=s2.ts_next
  960. if(s.ts_next)
  961. s.ts_next.ts_prev=s;s2.ts_next=s;s.ts_prev=s2
  962. delete s.beam_st;s.beam_end=true;s.tmp=true
  963. delete s.sls;s.x+=12
  964. if(s.x<realwidth-12)
  965. s.x=realwidth-12;s2=s;notes++
  966. break}}
  967. if(!visible)
  968. return false;bm.s2=s2
  969. if(staff_tb[st].y==0){if(two_staves)
  970. return false}else{if(!two_staves){bm.s1=s1;bm.a=(s1.ys-s2.ys)/(s1.xs-s2.xs);bm.b=s1.ys-s1.xs*bm.a+staff_tb[st].y;bm.nflags=nflags
  971. return true}}
  972. s_closest=s1;p_min=100;p_max=0
  973. for(s=s1;;s=s.next){if(s.type!=C.NOTE)
  974. continue
  975. if((scale=s.p_v.scale)==1)
  976. scale=staff_tb[s.st].staffscale
  977. if(s.stem>=0){x=stem_xoff+s.notes[0].shhd
  978. if(s.notes[s.nhd].pit>p_max){p_max=s.notes[s.nhd].pit;s_closest=s}}else{x=-stem_xoff+s.notes[s.nhd].shhd
  979. if(s.notes[0].pit<p_min){p_min=s.notes[0].pit;s_closest=s}}
  980. s.xs=s.x+x*scale;if(s==s2)
  981. break}
  982. if(s.grace&&s1.fmt.flatbeams)
  983. a=0
  984. else if(!two_dir&&notes>=3&&s_closest!=s1&&s_closest!=s2)
  985. a=0
  986. y=s1.ys+staff_tb[st].y
  987. if(a==undefined)
  988. a=(s2.ys+staff_tb[s2.st].y-y)/(s2.xs-s1.xs)
  989. if(a!=0){a=s1.fmt.beamslope*a/(s1.fmt.beamslope+Math.abs(a))
  990. if(a>-.04&&a<.04)
  991. a=0}
  992. b=(y+s2.ys+staff_tb[s2.st].y)/2-a*(s2.xs+s1.xs)/2
  993. max_stem_err=0;s=s1
  994. if(two_dir){ys=((s1.grace?3.5:BEAM_SHIFT)*(nflags-1)+
  995. BEAM_DEPTH)*.5
  996. if(s1.nflags==s2.nflags);else if(s1.stem!=s2.stem&&s1.nflags<s2.nflags)
  997. b+=ys*s2.stem
  998. else
  999. b+=ys*s1.stem}else if(!s1.grace){var beam_h=BEAM_DEPTH+BEAM_SHIFT*(nflags-1)
  1000. while(s.ts_prev&&s.ts_prev.type==C.NOTE&&s.ts_prev.time==s.time&&s.ts_prev.x>s1.xs)
  1001. s=s.ts_prev
  1002. for(;s&&s.time<=s2.time;s=s.ts_next){if(s.type!=C.NOTE||s.invis||(s.st!=st&&s.v!=v)){continue}
  1003. x=s.v==v?s.xs:s.x;ys=a*x+b-staff_tb[s.st].y
  1004. if(s.v==v){stem_err=min_tb[s.nhd==0?0:1][s.nflags]
  1005. if(s.stem>0){if(s.notes[s.nhd].pit>26){stem_err-=2
  1006. if(s.notes[s.nhd].pit>28)
  1007. stem_err-=2}
  1008. stem_err-=ys-3*(s.notes[s.nhd].pit-18)}else{if(s.notes[0].pit<18){stem_err-=2
  1009. if(s.notes[0].pit<16)
  1010. stem_err-=2}
  1011. stem_err-=3*(s.notes[0].pit-18)-ys}
  1012. stem_err+=BEAM_DEPTH+BEAM_SHIFT*(s.nflags-1)}else{if(s1.stem>0){if(s.stem>0){if(s.ymn>ys+4||s.ymx<ys-beam_h-2)
  1013. continue
  1014. if(s.v>v)
  1015. stem_err=s.ymx-ys
  1016. else
  1017. stem_err=s.ymn+8-ys}else{stem_err=s.ymx-ys}}else{if(s.stem<0){if(s.ymx<ys-4||s.ymn>ys-beam_h-2)
  1018. continue
  1019. if(s.v<v)
  1020. stem_err=ys-s.ymn
  1021. else
  1022. stem_err=ys-s.ymx+8}else{stem_err=ys-s.ymn}}
  1023. stem_err+=2+beam_h}
  1024. if(stem_err>max_stem_err)
  1025. max_stem_err=stem_err}}else{for(;;s=s.next){ys=a*s.xs+b-staff_tb[s.st].y;stem_err=GSTEM-2
  1026. if(s.stem>0)
  1027. stem_err-=ys-(3*(s.notes[s.nhd].pit-18))
  1028. else
  1029. stem_err+=ys-(3*(s.notes[0].pit-18));stem_err+=3*(s.nflags-1)
  1030. if(stem_err>max_stem_err)
  1031. max_stem_err=stem_err
  1032. if(s==s2)
  1033. break}}
  1034. if(max_stem_err>0)
  1035. b+=s1.stem*max_stem_err
  1036. if(!two_staves&&!two_dir)
  1037. for(s=s1.next;;s=s.next){switch(s.type){case C.REST:if(!s.multi)
  1038. break
  1039. g=s.ts_next
  1040. if(!g||g.st!=st||(g.type!=C.NOTE&&g.type!=C.REST))
  1041. break
  1042. case C.BAR:if(s.invis)
  1043. break
  1044. case C.CLEF:y=a*s.x+b
  1045. if(s1.stem>0){y=s.ymx-y
  1046. +BEAM_DEPTH+BEAM_SHIFT*(nflags-1)
  1047. +2
  1048. if(y>0)
  1049. b+=y}else{y=s.ymn-y
  1050. -BEAM_DEPTH-BEAM_SHIFT*(nflags-1)
  1051. -2
  1052. if(y<0)
  1053. b+=y}
  1054. break
  1055. case C.GRACE:for(g=s.extra;g;g=g.next){y=a*g.x+b
  1056. if(s1.stem>0){y=g.ymx-y
  1057. +BEAM_DEPTH+BEAM_SHIFT*(nflags-1)
  1058. +2
  1059. if(y>0)
  1060. b+=y}else{y=g.ymn-y
  1061. -BEAM_DEPTH-BEAM_SHIFT*(nflags-1)
  1062. -2
  1063. if(y<0)
  1064. b+=y}}
  1065. break}
  1066. if(s==s2)
  1067. break}
  1068. if(a==0)
  1069. b+=b_pos(s1.grace,s1.stem,nflags,b-staff_tb[st].y)
  1070. for(s=s1;;s=s.next){switch(s.type){case C.NOTE:s.ys=a*s.xs+b-staff_tb[s.st].y
  1071. if(s.stem>0){s.ymx=s.ys+2.5
  1072. if(s.ts_prev&&s.ts_prev.stem>0&&s.ts_prev.st==s.st&&s.ts_prev.ymn<s.ymx&&s.ts_prev.x==s.x&&s.notes[0].shhd==0){s.ts_prev.x-=3;s.ts_prev.xs-=3}}else{s.ymn=s.ys-2.5}
  1073. break
  1074. case C.REST:y=a*s.x+b-staff_tb[s.st].y
  1075. dy=BEAM_DEPTH+BEAM_SHIFT*(nflags-1)
  1076. +(s.head!=C.FULL?4:9)
  1077. if(s1.stem>0){y-=dy
  1078. if(s1.multi==0&&y>12)
  1079. y=12
  1080. if(s.y<=y)
  1081. break}else{y+=dy
  1082. if(s1.multi==0&&y<12)
  1083. y=12
  1084. if(s.y>=y)
  1085. break}
  1086. if(s.head!=C.FULL)
  1087. y=(((y+3+12)/6)|0)*6-12;s.y=y
  1088. break}
  1089. if(s==s2)
  1090. break}
  1091. if(staff_tb[st].y==0)
  1092. return false
  1093. bm.s1=s1;bm.a=a;bm.b=b;bm.nflags=nflags
  1094. return true}
  1095. function draw_beams(bm){var s,i,beam_dir,shift,bshift,bstub,bh,da,bd,k,k1,k2,x1,s1=bm.s1,s2=bm.s2
  1096. function draw_beam(x1,x2,dy,h,bm,n){var y1,dy2,s=bm.s1,nflags=s.nflags
  1097. if(s.ntrem)
  1098. nflags-=s.ntrem
  1099. if(s.trem2&&n>nflags){if(s.dur>=C.BLEN/2){x1=s.x+6;x2=bm.s2.x-6}else if(s.dur<C.BLEN/4){var dx=x2-x1
  1100. if(dx<16){x1+=dx/4
  1101. x2-=dx/4}else{x1+=5
  1102. x2-=6}}}
  1103. y1=bm.a*x1+bm.b-dy;x2-=x1;x2/=stv_g.scale;dy2=bm.a*x2*stv_g.scale
  1104. xypath(x1,y1,true);output+='l'+x2.toFixed(1)+' '+(-dy2).toFixed(1)+'v'+h.toFixed(1)+'l'+(-x2).toFixed(1)+' '+dy2.toFixed(1)+'z"/>\n'}
  1105. anno_start(s1,'beam')
  1106. if(!s1.grace){bshift=BEAM_SHIFT;bstub=BEAM_STUB;shift=.34;bh=BEAM_DEPTH}else{bshift=3.5;bstub=3.2;shift=.29;bh=1.8}
  1107. bh/=stv_g.scale
  1108. beam_dir=s1.stem
  1109. if(s1.stem!=s2.stem&&s1.nflags<s2.nflags)
  1110. beam_dir=s2.stem
  1111. if(beam_dir<0)
  1112. bh=-bh;draw_beam(s1.xs-shift,s2.xs+shift,0,bh,bm,1);da=0
  1113. for(s=s1;;s=s.next){if(s.type==C.NOTE&&s.stem!=beam_dir)
  1114. s.ys=bm.a*s.xs+bm.b
  1115. -staff_tb[s.st].y
  1116. +bshift*(s.nflags-1)*s.stem
  1117. -bh
  1118. if(s==s2)
  1119. break}
  1120. if(s1.feathered_beam){da=bshift/(s2.xs-s1.xs)
  1121. if(s1.feathered_beam>0){da=-da;bshift=da*s1.xs}else{bshift=da*s2.xs}
  1122. da=da*beam_dir}
  1123. shift=0
  1124. for(i=2;i<=bm.nflags;i++){shift+=bshift
  1125. if(da!=0)
  1126. bm.a+=da
  1127. for(s=s1;;s=s.next){if(s.type!=C.NOTE||s.nflags<i){if(s==s2)
  1128. break
  1129. continue}
  1130. if(s.trem1&&i>s.nflags-s.ntrem){x1=(s.dur>=C.BLEN/2)?s.x:s.xs;draw_beam(x1-5,x1+5,(shift+2.5)*beam_dir,bh,bm,i)
  1131. if(s==s2)
  1132. break
  1133. continue}
  1134. k1=s
  1135. while(1){if(s==s2)
  1136. break
  1137. k=s.next
  1138. if(k.type==C.NOTE||k.type==C.REST){if(k.trem1){if(k.nflags-k.ntrem<i)
  1139. break}else if(k.nflags<i){break}}
  1140. if(k.beam_br1||(k.beam_br2&&i>2))
  1141. break
  1142. s=k}
  1143. k2=s
  1144. while(k2.type!=C.NOTE)
  1145. k2=k2.prev;x1=k1.xs
  1146. bd=beam_dir
  1147. if(k1==k2){if(k1==s1){x1+=bstub}else if(k1==s2){x1-=bstub}else if(k1.beam_br1||(k1.beam_br2&&i>2)){x1+=bstub}else{k=k1.next
  1148. while(k.type!=C.NOTE)
  1149. k=k.next
  1150. if(k.beam_br1||(k.beam_br2&&i>2)){x1-=bstub}else{k1=k1.prev
  1151. while(k1.type!=C.NOTE)
  1152. k1=k1.prev
  1153. if(k1.nflags<k.nflags||(k1.nflags==k.nflags&&k1.dots<k.dots))
  1154. x1+=bstub
  1155. else
  1156. x1-=bstub}}
  1157. if(k1.stem!=beam_dir){bd=k1.stem
  1158. k1.ys=bm.a*k1.xs+bm.b
  1159. -staff_tb[k1.st].y-bh}}
  1160. draw_beam(x1,k2.xs,shift*bd,bh,bm,i)
  1161. if(s==s2)
  1162. break}}
  1163. if(s1.tmp)
  1164. unlksym(s1)
  1165. else if(s2.tmp)
  1166. unlksym(s2)
  1167. anno_stop(s1,'beam')}
  1168. function draw_lstaff(x){var i,j,yb,h,fl,nst=cur_sy.nstaff,l=0
  1169. function draw_sysbra(x,st,flag){var i,st_end,yt,yb
  1170. while(!cur_sy.st_print[st]){if(cur_sy.staves[st].flags&flag)
  1171. return
  1172. st++}
  1173. i=st_end=st
  1174. while(1){if(cur_sy.st_print[i])
  1175. st_end=i
  1176. if(cur_sy.staves[i].flags&flag)
  1177. break
  1178. i++}
  1179. yt=staff_tb[st].y+staff_tb[st].topbar*staff_tb[st].staffscale;yb=staff_tb[st_end].y+staff_tb[st_end].botbar*staff_tb[st_end].staffscale
  1180. if(flag&(CLOSE_BRACE|CLOSE_BRACE2))
  1181. out_brace(x,yb,yt-yb)
  1182. else
  1183. out_bracket(x,yt,yt-yb)}
  1184. for(i=0;;i++){fl=cur_sy.staves[i].flags
  1185. if(fl&(OPEN_BRACE|OPEN_BRACKET))
  1186. l++
  1187. if(cur_sy.st_print[i])
  1188. break
  1189. if(fl&(CLOSE_BRACE|CLOSE_BRACKET))
  1190. l--
  1191. if(i==nst)
  1192. break}
  1193. for(j=nst;j>i;j--){if(cur_sy.st_print[j])
  1194. break}
  1195. if(i==j&&l==0)
  1196. return
  1197. yb=staff_tb[j].y+staff_tb[j].botbar*staff_tb[j].staffscale;h=staff_tb[i].y+staff_tb[i].topbar*staff_tb[i].staffscale-yb;xypath(x,yb);output+="v"+(-h).toFixed(1)+'"/>\n'
  1198. for(i=0;i<=nst;i++){fl=cur_sy.staves[i].flags
  1199. if(fl&OPEN_BRACE)
  1200. draw_sysbra(x,i,CLOSE_BRACE)
  1201. if(fl&OPEN_BRACKET)
  1202. draw_sysbra(x,i,CLOSE_BRACKET)
  1203. if(fl&OPEN_BRACE2)
  1204. draw_sysbra(x-6,i,CLOSE_BRACE2)
  1205. if(fl&OPEN_BRACKET2)
  1206. draw_sysbra(x-6,i,CLOSE_BRACKET2)}}
  1207. function draw_meter(s){if(!s.a_meter)
  1208. return
  1209. var dx,i,j,meter,x,st=s.st,p_staff=staff_tb[st],y=p_staff.y;if(p_staff.stafflines!='|||||')
  1210. y+=(p_staff.topbar+p_staff.botbar)/2-12
  1211. for(i=0;i<s.a_meter.length;i++){meter=s.a_meter[i];x=s.x+s.x_meter[i]
  1212. if(meter.bot){out_XYAB('\
  1213. <g transform="translate(X,Y)" text-anchor="middle">\n\
  1214. <text y="-12">A</text>\n\
  1215. <text>B</text>\n\
  1216. </g>\n',x,y+6,m_gl(meter.top),m_gl(meter.bot))}else{out_XYAB('\
  1217. <text x="X" y="Y" text-anchor="middle">A</text>\n',x,y+12,m_gl(meter.top))}}}
  1218. var acc_nd={}
  1219. function draw_acc(x,y,a){if(typeof a=="object"){var c,n=a[0],d=a[1]
  1220. c=n+'_'+d
  1221. a=acc_nd[c]
  1222. if(!a){a=abc2svg.rat(Math.abs(n),d)
  1223. d=a[1]
  1224. a=(n<0?-a[0]:a[0]).toString()
  1225. if(d!=1)
  1226. a+='_'+d
  1227. acc_nd[c]=a}}
  1228. xygl(x,y,"acc"+a)}
  1229. function set_hl(p_st,n,x,dx1,dx2){var i,hl
  1230. if(n>=0){hl=p_st.hlu[n]
  1231. if(!hl)
  1232. hl=p_st.hlu[n]=[]}else{hl=p_st.hld[-n]
  1233. if(!hl)
  1234. hl=p_st.hld[-n]=[]}
  1235. for(i=0;i<hl.length;i++){if(x>=hl[i][0])
  1236. break}
  1237. if(i==hl.length){hl.push([x,dx1,dx2])}else if(x>hl[i][0]){hl.splice(++i,0,[x,dx1,dx2])}else{if(dx1<hl[i][1])
  1238. hl[i][1]=dx1
  1239. if(dx2>hl[i][2])
  1240. hl[i][2]=dx2}}
  1241. Abc.prototype.draw_hl=function(s){var i,j,n,note,hla=[],st=s.st,p_staff=staff_tb[st]
  1242. if(!p_staff.hll||s.invis)
  1243. return
  1244. for(i=0;i<=s.nhd;i++){note=s.notes[i]
  1245. if(!p_staff.hlmap[note.pit-p_staff.hll])
  1246. hla.push([note.pit-18,note.shhd*stv_g.scale])}
  1247. n=hla.length
  1248. if(!n)
  1249. return
  1250. var dx1,dx2,hl,shhd,hlp,stafflines=p_staff.stafflines,top=stafflines.length-1,yu=top,bot=p_staff.botline/6,yl=bot,dx=s.grace?4:hw_tb[s.head]*1.3
  1251. note=s.notes[s.stem<0?s.nhd:0]
  1252. shhd=note.shhd
  1253. for(i=0;i<hla.length;i++){hlp=hla[i][0]
  1254. dx1=(hla[i][1]<shhd?hla[i][1]:shhd)-dx
  1255. dx2=(hla[i][1]>shhd?hla[i][1]:shhd)+dx
  1256. if(hlp<bot*2){if(hlp<yl*2)
  1257. yl=++hlp>>1
  1258. n--}else if(hlp>top*2){yu=hlp>>1
  1259. n--}
  1260. set_hl(p_staff,hlp>>1,s.x,dx1,dx2)}
  1261. dx1=shhd-dx
  1262. dx2=shhd+dx
  1263. while(++yl<bot)
  1264. set_hl(p_staff,yl,s.x,dx1,dx2)
  1265. while(--yu>top)
  1266. set_hl(p_staff,yu,s.x,dx1,dx2)
  1267. if(!n)
  1268. return
  1269. i=yl;j=yu
  1270. while(i>bot&&stafflines[i]=='-')
  1271. i--
  1272. while(j<top&&stafflines[j]=='-')
  1273. j++
  1274. for(;i<j;i++){if(stafflines[i]=='-')
  1275. set_hl(p_staff,i,s.x,dx1,dx2)}}
  1276. var sharp_cl=new Int8Array([24,9,15,21,6,12,18]),flat_cl=new Int8Array([12,18,24,9,15,21,6]),sharp1=new Int8Array([-9,12,-9,-9,12,-9]),sharp2=new Int8Array([12,-9,12,-9,12,-9]),flat1=new Int8Array([9,-12,9,-12,9,-12]),flat2=new Int8Array([-12,9,-12,9,-12,9])
  1277. Abc.prototype.draw_keysig=function(x,s){var old_sf=s.k_old_sf,st=s.st,staffb=staff_tb[st].y,i,shift,p_seq,clef_ix=s.k_y_clef,a_acc=s.k_a_acc
  1278. function set_k_acc(a_acc,sf){var i,j,n,nacc,p_acc,accs=[],pits=[]
  1279. if(sf>0){for(nacc=0;nacc<sf;nacc++){accs[nacc]=1
  1280. pits[nacc]=[26,23,27,24,21,25,22][nacc]}}else{for(nacc=0;nacc<-sf;nacc++){accs[nacc]=-1
  1281. pits[nacc]=[22,25,21,24,20,23,26][nacc]}}
  1282. n=a_acc.length
  1283. for(i=0;i<n;i++){p_acc=a_acc[i]
  1284. for(j=0;j<nacc;j++){if(pits[j]==p_acc.pit){accs[j]=p_acc.acc
  1285. break}}
  1286. if(j==nacc){accs[j]=p_acc.acc
  1287. pits[j]=p_acc.pit
  1288. nacc++}}
  1289. for(i=0;i<nacc;i++){p_acc=a_acc[i]
  1290. if(!p_acc)
  1291. p_acc=a_acc[i]={}
  1292. p_acc.acc=accs[i]
  1293. p_acc.pit=pits[i]}}
  1294. if(clef_ix&1)
  1295. clef_ix+=7;clef_ix/=2
  1296. while(clef_ix<0)
  1297. clef_ix+=7;clef_ix%=7
  1298. if(a_acc&&!s.exp)
  1299. set_k_acc(a_acc,s.k_sf)
  1300. if(!a_acc){if(s.fmt.cancelkey||s.k_sf==0){if(s.k_sf==0||old_sf*s.k_sf<0){shift=sharp_cl[clef_ix];p_seq=shift>9?sharp1:sharp2
  1301. for(i=0;i<old_sf;i++){xygl(x,staffb+shift,"acc3");shift+=p_seq[i];x+=5.5}
  1302. shift=flat_cl[clef_ix];p_seq=shift<18?flat1:flat2
  1303. for(i=0;i>old_sf;i--){xygl(x,staffb+shift,"acc3");shift+=p_seq[-i];x+=5.5}
  1304. if(s.k_sf!=0)
  1305. x+=3}}
  1306. if(s.k_sf>0){shift=sharp_cl[clef_ix];p_seq=shift>9?sharp1:sharp2
  1307. for(i=0;i<s.k_sf;i++){xygl(x,staffb+shift,"acc1");shift+=p_seq[i];x+=5.5}
  1308. if(s.fmt.cancelkey&&i<old_sf){x+=2
  1309. for(;i<old_sf;i++){xygl(x,staffb+shift,"acc3");shift+=p_seq[i];x+=5.5}}
  1310. if(s.k_bagpipe=='p'){xygl(x,staffb+27,"acc3")
  1311. x+=5.5}}
  1312. if(s.k_sf<0){shift=flat_cl[clef_ix];p_seq=shift<18?flat1:flat2
  1313. for(i=0;i>s.k_sf;i--){xygl(x,staffb+shift,"acc-1");shift+=p_seq[-i];x+=5.5}
  1314. if(s.fmt.cancelkey&&i>old_sf){x+=2
  1315. for(;i>old_sf;i--){xygl(x,staffb+shift,"acc3");shift+=p_seq[-i];x+=5.5}}}}else if(a_acc.length){var acc,last_acc=a_acc[0].acc,last_shift=100,s2={st:st,nhd:0,notes:[{}]}
  1316. for(i=0;i<a_acc.length;i++){acc=a_acc[i];shift=(s.k_y_clef
  1317. +acc.pit-18)*3
  1318. while(shift<-3)
  1319. shift+=21
  1320. while(shift>27)
  1321. shift-=21
  1322. if(i!=0&&(shift>last_shift+18||shift<last_shift-18))
  1323. x-=5.5
  1324. else if(acc.acc!=last_acc)
  1325. x+=3;last_acc=acc.acc;s2.x=x
  1326. s2.notes[0].pit=shift/3+18;last_shift=shift;draw_acc(x,staffb+shift,acc.acc)
  1327. x+=5.5}}}
  1328. function nrep_out(x,y,n){y-=3
  1329. if(n<10){xygl(x-4,y,"mtr"+n)}else{xygl(x-10,y,"mtr"+((n/10)|0))
  1330. xygl(x-2,y,"mtr"+(n%10))}}
  1331. function center_rest(s){var s2,x
  1332. if(s.dur<C.BLEN*2)
  1333. s.nflags=-2
  1334. else if(s.dur<C.BLEN*4)
  1335. s.nflags=-3
  1336. else
  1337. s.nflags=-4
  1338. s.dots=0
  1339. s2=s.ts_next
  1340. while(s2.time!=s.time+s.dur&&s2.ts_next)
  1341. s2=s2.ts_next
  1342. x=s2.x-s2.wl
  1343. s2=s
  1344. while(!s2.seqst)
  1345. s2=s2.ts_prev
  1346. s2=s2.ts_prev
  1347. x=(x+s2.x+s2.wr)/2
  1348. if(s.a_dd)
  1349. deco_update(s,x-s.x)
  1350. s.x=x}
  1351. var rest_tb=["r128","r64","r32","r16","r8","r4","r2","r1","r0","r00"]
  1352. function draw_rest(s){var s2,i,j,y,bx,p_staff=staff_tb[s.st],yb=p_staff.y,x=s.x
  1353. if(s.notes[0].shhd)
  1354. x+=s.notes[0].shhd*stv_g.scale
  1355. if(s.rep_nb){set_sscale(s.st);anno_start(s);if(p_staff.stafflines=='|||||')
  1356. yb+=12
  1357. else
  1358. yb+=(p_staff.topbar+p_staff.botbar)/2
  1359. if(s.rep_nb<0){xygl(x,yb,"srep")}else{xygl(x,yb,"mrep")
  1360. if(s.rep_nb>2&&s.v==cur_sy.top_voice&&s.fmt.measrepnb>0&&!(s.rep_nb%s.fmt.measrepnb))
  1361. nrep_out(x,yb+p_staff.topbar,s.rep_nb)}
  1362. anno_a.push(s)
  1363. return}
  1364. set_scale(s);anno_start(s);if(s.notes[0].color)
  1365. set_color(s.notes[0].color);y=s.y;i=5-s.nflags
  1366. if(i==7&&y==12&&p_staff.stafflines.length<=2)
  1367. y-=6
  1368. if(!s.notes[0].invis)
  1369. xygl(x,y+yb,rest_tb[i])
  1370. if(s.dots){x+=8;y+=yb+3
  1371. j=s.dots
  1372. i=(s.dur_orig/12)>>((5-s.nflags)-j)
  1373. while(j-->0){xygl(x,y,(i&(1<<j))?"dot":"dot+")
  1374. x+=3.5}}
  1375. set_color();anno_a.push(s)}
  1376. function draw_mrest(s){var x1,x2,prev,p_st=staff_tb[s.st],y=p_st.y+(p_st.topbar+p_st.botbar)/2,p=s.nmes.toString()
  1377. if(!s.next){error(1,s,"Lack of bar after multi-measure rest")
  1378. return}
  1379. set_scale(s)
  1380. prev=s
  1381. while(!prev.seqst)
  1382. prev=prev.ts_prev
  1383. prev=prev.ts_prev
  1384. while(!prev.seqst)
  1385. prev=prev.ts_prev
  1386. x1=prev.x+20
  1387. x2=s.next.x-20
  1388. s.x=(x1+x2)/2
  1389. anno_start(s)
  1390. out_XYAB('<path d="mX Y',x1+.6,y-2.7)
  1391. output+='v2.7h-1.4v-10.8h1.4v2.7h'
  1392. +((x2-x1-2.8)/stv_g.scale).toFixed(1)
  1393. +'v-2.7h1.4v10.8h-1.4v-2.7z"/>\n'
  1394. if(s.tacet)
  1395. out_XYAB('<text x ="X" y="Y" style="font-size:12px;font-weight:700"\
  1396. text-anchor="middle">A</text>\n',s.x,y+18,s.tacet)
  1397. else
  1398. out_XYAB('<text x ="X" y="Y" text-anchor="middle">A</text>\n',s.x,y+22,m_gl(p))
  1399. anno_a.push(s)}
  1400. function grace_slur(s){var yy,x0,y0,x3,y3,bet1,bet2,dy1,dy2,last,below,so=s,g=s.extra
  1401. while(1){if(!g.next)
  1402. break
  1403. g=g.next}
  1404. last=g
  1405. below=((g.stem>=0||s.multi<0)&&g.notes[0].pit<=28)||g.notes[0].pit<16
  1406. if(below){yy=127
  1407. for(g=s.extra;g;g=g.next){if(g.y<yy){yy=g.y;last=g}}
  1408. x0=last.x;y0=last.y-5
  1409. if(s.extra!=last){x0-=4;y0+=1}
  1410. s=s.next;x3=s.x-1
  1411. if(s.stem<0&&s.nflags>-2)
  1412. x3-=4;y3=3*(s.notes[0].pit-18)-5;dy1=(x3-x0)*.4
  1413. if(dy1>3)
  1414. dy1=3;dy2=dy1;bet1=.2;bet2=.8
  1415. if(y0>y3+7){x0=last.x-1;y0+=.5;y3+=6.5;x3=s.x-5.5;dy1=(y0-y3)*.8;dy2=(y0-y3)*.2;bet1=0}else if(y3>y0+4){y3=y0+4;x0=last.x+2;y0=last.y-4}}else{yy=-127
  1416. for(g=s.extra;g;g=g.next){if(g.y>yy){yy=g.y;last=g}}
  1417. x0=last.x;y0=last.y+5
  1418. if(s.extra!=last){x0-=4;y0-=1}
  1419. s=s.next;x3=s.x-1
  1420. if(s.stem>=0&&s.nflags>-2)
  1421. x3-=2;y3=3*(s.notes[s.nhd].pit-18)+5;dy1=(x0-x3)*.4
  1422. if(dy1<-3)
  1423. dy1=-3;dy2=dy1;bet1=.2;bet2=.8
  1424. if(y0<y3-7){x0=last.x-1;y0-=.5;y3-=6.5;x3=s.x-5.5;dy1=(y0-y3)*.8;dy2=(y0-y3)*.2;bet1=0}else if(y3<y0-4){y3=y0-4;x0=last.x+2;y0=last.y+4}}
  1425. so.slur={x0:x0,y0:y0,x1:bet1*x3+(1-bet1)*x0-x0,y1:y0-bet1*y3-(1-bet1)*y0+dy1,x2:bet2*x3+(1-bet2)*x0-x0,y2:y0-bet2*y3-(1-bet2)*y0+dy2,x3:x3-x0,y3:y0-y3}
  1426. y0-=so.slur.y1
  1427. g=so.extra
  1428. if(below){if(y0<g.ymn)
  1429. g.ymn=y0}else{if(y0>g.ymx)
  1430. g.ymx=y0}}
  1431. function draw_gracenotes(s){var x1,y1,last,note,bm={},g=s.extra
  1432. while(1){if(g.beam_st&&!g.beam_end){if(self.calculate_beam(bm,g))
  1433. draw_beams(bm)}
  1434. anno_start(g)
  1435. draw_note(g,!bm.s2)
  1436. if(g==bm.s2)
  1437. bm.s2=null
  1438. anno_a.push(s)
  1439. if(!g.next)
  1440. break
  1441. g=g.next}
  1442. last=g
  1443. if(s.sappo){g=s.extra
  1444. if(!g.next){x1=9
  1445. y1=g.stem>0?5:-5}else{x1=(g.next.x-g.x)*.5+4
  1446. y1=(g.ys+g.next.ys)*.5-g.y
  1447. if(g.stem>0)
  1448. y1-=1
  1449. else
  1450. y1+=1}
  1451. note=g.notes[g.stem<0?0:g.nhd]
  1452. out_acciac(x_head(g,note),y_head(g,note),x1,y1,g.stem>0)}
  1453. g=s.slur
  1454. if(g){anno_start(s,'slur')
  1455. xypath(g.x0,g.y0+staff_tb[s.st].y)
  1456. output+='c'+g.x1.toFixed(1)+' '+g.y1.toFixed(1)+' '+g.x2.toFixed(1)+' '+g.y2.toFixed(1)+' '+g.x3.toFixed(1)+' '+g.y3.toFixed(1)+'"/>\n'
  1457. anno_stop(s,'slur')}}
  1458. function setdoty(s,y_tb){var m,m1,y
  1459. for(m=0;m<=s.nhd;m++){y=3*(s.notes[m].pit-18)
  1460. if((y%6)==0){if(s.dot_low)
  1461. y-=3
  1462. else
  1463. y+=3}
  1464. y_tb[m]=y}
  1465. for(m=0;m<s.nhd;m++){if(y_tb[m+1]>y_tb[m])
  1466. continue
  1467. m1=m
  1468. while(m1>0){if(y_tb[m1]>y_tb[m1-1]+6)
  1469. break
  1470. m1--}
  1471. if(3*(s.notes[m1].pit-18)-y_tb[m1]<y_tb[m+1]-3*(s.notes[m+1].pit-18)){while(m1<=m)
  1472. y_tb[m1++]-=6}else{y_tb[m+1]=y_tb[m]+6}}}
  1473. function x_head(s,note){return s.x+note.shhd*stv_g.scale}
  1474. function y_head(s,note){return staff_tb[s.st].y+3*(note.pit-18)}
  1475. function draw_basic_note(s,m,y_tb){var i,p,yy,dotx,doty,inv,old_color=false,note=s.notes[m],staffb=staff_tb[s.st].y,x=s.x,y=3*(note.pit-18),shhd=note.shhd*stv_g.scale,x_note=x+shhd,y_note=y+staffb
  1476. var elts=identify_note(s,note.dur),head=elts[0],dots=elts[1],nflags=elts[2]
  1477. if(note.invis){}else if(s.grace){p="ghd";x_note-=4.5*stv_g.scale}else if(note.map&&note.map[0]){i=s.head;p=note.map[0][i]
  1478. if(!p)
  1479. p=note.map[0][note.map[0].length-1]
  1480. i=p.indexOf('/')
  1481. if(i>=0){if(s.stem>=0)
  1482. p=p.slice(0,i)
  1483. else
  1484. p=p.slice(i+1)}}else if(s.type==C.CUSTOS){p="custos"}else{switch(head){case C.OVAL:p="HD"
  1485. break
  1486. case C.OVALBARS:if(s.head!=C.SQUARE){p="HDD"
  1487. break}
  1488. case C.SQUARE:if(nflags>-4){p="breve"}else{p="longa"
  1489. inv=s.stem>0}
  1490. if(!tsnext&&s.next&&s.next.type==C.BAR&&!s.next.next)
  1491. dots=0
  1492. x_note+=1
  1493. break
  1494. case C.EMPTY:p="Hd"
  1495. break
  1496. default:p="hd"
  1497. break}}
  1498. if(note.color!=undefined)
  1499. old_color=set_color(note.color)
  1500. if(p){if(inv){g_open(x_note,y_note,0,1,-1);x_note=y_note=0}
  1501. if(!self.psxygl(x_note,y_note,p))
  1502. xygl(x_note,y_note,p)
  1503. if(inv)
  1504. g_close()}
  1505. if(dots){dotx=x+(7.7+s.xmx)*stv_g.scale
  1506. if(y_tb[m]==undefined){y_tb[m]=3*(s.notes[m].pit-18)
  1507. if((s.notes[m].pit&1)==0)
  1508. y_tb[m]+=3}
  1509. doty=y_tb[m]+staffb
  1510. i=(note.dur/12)>>((5-nflags)-dots)
  1511. while(dots-->0){xygl(dotx,doty,(i&(1<<dots))?"dot":"dot+")
  1512. dotx+=3.5}}
  1513. if(note.acc){x-=note.shac*stv_g.scale
  1514. if(!s.grace){draw_acc(x,y+staffb,note.acc)}else{g_open(x,y+staffb,0,.75);draw_acc(0,0,note.acc)
  1515. g_close()}}
  1516. if(old_color!=false)
  1517. set_color(old_color)}
  1518. function draw_note(s,fl){var s2,i,m,y,slen,c,nflags,y_tb=new Array(s.nhd+1),note=s.notes[s.stem<0?s.nhd:0],x=x_head(s,note),y=y_head(s,note),staffb=staff_tb[s.st].y
  1519. if(s.dots)
  1520. setdoty(s,y_tb)
  1521. if(!s.stemless){slen=s.ys-s.y;nflags=s.nflags
  1522. if(s.ntrem)
  1523. nflags-=s.ntrem
  1524. if(!fl||nflags<=0){if(s.nflags>0){if(s.stem>=0)
  1525. slen-=1
  1526. else
  1527. slen+=1}
  1528. out_stem(x,y,slen,s.grace)}else{out_stem(x,y,slen,s.grace,nflags,s.fmt.straightflags)}}else if(s.xstem){s2=s.ts_prev;slen=(s2.stem>0?s2.y:s2.ys)-s.y;slen+=staff_tb[s2.st].y-staffb;out_stem(x,y,slen)}
  1529. if(fl&&s.trem1){var ntrem=s.ntrem||0,x1=x;slen=3*(s.notes[s.stem>0?s.nhd:0].pit-18)
  1530. if(s.head==C.FULL||s.head==C.EMPTY){x1+=(s.grace?GSTEM_XOFF:3.5)*s.stem
  1531. if(s.stem>0)
  1532. slen+=6+5.4*ntrem
  1533. else
  1534. slen-=6+5.4}else{if(s.stem>0)
  1535. slen+=5+5.4*ntrem
  1536. else
  1537. slen-=5+5.4}
  1538. slen/=s.p_v.scale;out_trem(x1,staffb+slen,ntrem)}
  1539. for(m=0;m<=s.nhd;m++)
  1540. draw_basic_note(s,m,y_tb)}
  1541. function prev_scut(s){while(s.prev){s=s.prev
  1542. if(s.rbstart)
  1543. return s}
  1544. s=s.p_v.sym
  1545. while(s.type!=C.CLEF)
  1546. s=s.ts_prev
  1547. if(s.next&&s.next.type==C.KEY)
  1548. s=s.next
  1549. if(s.next&&s.next.type==C.METER)
  1550. return s.next
  1551. return s}
  1552. function slur_direction(k1,k2){var s,some_upstem,low,dir
  1553. function slur_multi(s1,s2){if(s1.multi)
  1554. return s1.multi
  1555. if(s2.multi)
  1556. return s2.multi
  1557. return 0}
  1558. if(k1.grace&&k1.stem>0)
  1559. return-1
  1560. dir=slur_multi(k1,k2)
  1561. if(dir)
  1562. return dir
  1563. for(s=k1;;s=s.next){if(s.type==C.NOTE){if(!s.stemless){if(s.stem<0)
  1564. return 1
  1565. some_upstem=true}
  1566. if(s.notes[0].pit<22)
  1567. low=true}
  1568. if(s.time==k2.time)
  1569. break}
  1570. if(!some_upstem&&!low)
  1571. return 1
  1572. return-1}
  1573. function slur_out(x1,y1,x2,y2,dir,height,dotted){var dx,dy,dz,alfa=.3,beta=.45;dy=y2-y1
  1574. if(dy<0)
  1575. dy=-dy;dx=x2-x1
  1576. if(dx>40.&&dy/dx<.7){alfa=.3+.002*(dx-40.)
  1577. if(alfa>.7)
  1578. alfa=.7}
  1579. var mx=.5*(x1+x2),my=.5*(y1+y2),xx1=mx+alfa*(x1-mx),yy1=my+alfa*(y1-my)+height;xx1=x1+beta*(xx1-x1);yy1=y1+beta*(yy1-y1)
  1580. var xx2=mx+alfa*(x2-mx),yy2=my+alfa*(y2-my)+height;xx2=x2+beta*(xx2-x2);yy2=y2+beta*(yy2-y2);dy=2*dir;dz=.2+.001*dx
  1581. if(dz>.6)
  1582. dz=.6;dz*=dir
  1583. dx*=.03
  1584. var scale_y=1
  1585. if(!dotted)
  1586. output+='<path d="M'
  1587. else
  1588. output+='<path class="stroke" stroke-dasharray="5,5" d="M';out_sxsy(x1,' ',y1);output+='c'+
  1589. ((xx1-x1)/stv_g.scale).toFixed(1)+' '+
  1590. ((y1-yy1)/scale_y).toFixed(1)+' '+
  1591. ((xx2-x1)/stv_g.scale).toFixed(1)+' '+
  1592. ((y1-yy2)/scale_y).toFixed(1)+' '+
  1593. ((x2-x1)/stv_g.scale).toFixed(1)+' '+
  1594. ((y1-y2)/scale_y).toFixed(1)
  1595. if(!dotted)
  1596. output+='\n\tv'+
  1597. (-dz).toFixed(1)+'c'+
  1598. ((xx2-dx-x2)/stv_g.scale).toFixed(1)+' '+
  1599. ((y2+dz-yy2-dy)/scale_y).toFixed(1)+' '+
  1600. ((xx1+dx-x2)/stv_g.scale).toFixed(1)+' '+
  1601. ((y2+dz-yy1-dy)/scale_y).toFixed(1)+' '+
  1602. ((x1-x2)/stv_g.scale).toFixed(1)+' '+
  1603. ((y2-y1)/scale_y).toFixed(1)
  1604. output+='"/>\n'}
  1605. function draw_slur(path,sl){var i,k,g,x1,y1,x2,y2,height,addy,a,y,z,h,dx,dy,ty=sl.ty,dir=(ty&0x07)==C.SL_ABOVE?1:-1,n=path.length,i1=0,i2=n-1,not1=sl.nts,k1=path[0],k2=path[i2]
  1606. var nn=1,upstaff=k1.st,two_staves=false
  1607. set_dscale(k1.st)
  1608. for(i=1;i<n;i++){k=path[i]
  1609. if(k.type==C.NOTE||k.type==C.REST){nn++
  1610. if(k.st!=upstaff){two_staves=true
  1611. if(k.st<upstaff)
  1612. upstaff=k.st}}}
  1613. if(two_staves)error(2,k1,"*** multi-staves slurs not treated yet");x1=k1.x
  1614. if(k1.notes&&k1.notes[0].shhd)
  1615. x1+=k1.notes[0].shhd;x2=k2.x
  1616. if(k2.notes)
  1617. x2+=k2.notes[0].shhd
  1618. if(not1){y1=3*(not1.pit-18)+2*dir
  1619. x1+=3}else{y1=dir>0?k1.ymx+2:k1.ymn-2
  1620. if(k1.type==C.NOTE){if(dir>0){if(k1.stem>0){x1+=5
  1621. if(k1.beam_end&&k1.nflags>=-1&&!k1.in_tuplet){if(k1.nflags>0){x1+=2;y1=k1.ys-3}else{y1=k1.ys-6}}else{y1=k1.ys+3}}else{y1=k1.y+8}}else{if(k1.stem<0){x1-=1
  1622. if(k2.grace){y1=k1.y-8}else if(k1.beam_end&&k1.nflags>=-1&&(!k1.in_tuplet||k1.ys<y1+3)){if(k1.nflags>0){x1+=2;y1=k1.ys+3}else{y1=k1.ys+6}}else{y1=k1.ys-3}}else{y1=k1.y-8}}}}
  1623. if(sl.nte){y2=3*(sl.nte.pit-18)+2*dir
  1624. x2-=3}else{y2=dir>0?k2.ymx+2:k2.ymn-2
  1625. if(k2.type==C.NOTE){if(dir>0){if(k2.stem>0){x2+=1
  1626. if(k2.beam_st&&k2.nflags>=-1&&!k2.in_tuplet)
  1627. y2=k2.ys-6
  1628. else
  1629. y2=k2.ys+3}else{y2=k2.y+8}}else{if(k2.stem<0){x2-=5
  1630. if(k2.beam_st&&k2.nflags>=-1&&!k2.in_tuplet)
  1631. y2=k2.ys+6
  1632. else
  1633. y2=k2.ys-3}else{y2=k2.y-8}}}}
  1634. if(k1.type!=C.NOTE){y1=y2+1.2*dir;x1=k1.x+k1.wr*.5
  1635. if(x1>x2-12)
  1636. x1=x2-12}
  1637. if(k2.type!=C.NOTE){if(k1.type==C.NOTE)
  1638. y2=y1+1.2*dir
  1639. else
  1640. y2=y1
  1641. if(k1!=k2)
  1642. x2=k2.x-k2.wl*.3}
  1643. if(nn>=3){k=path[1]
  1644. if(k.type!=C.BAR&&k.x<x1+48){if(dir>0){y=k.ymx-2
  1645. if(y1<y)
  1646. y1=y}else{y=k.ymn+2
  1647. if(y1>y)
  1648. y1=y}}
  1649. k=path[i2-1]
  1650. if(k.type!=C.BAR&&k.x>x2-48){if(dir>0){y=k.ymx-2
  1651. if(y2<y)
  1652. y2=y}else{y=k.ymn+2
  1653. if(y2>y)
  1654. y2=y}}}
  1655. a=(y2-y1)/(x2-x1)
  1656. if(a>SLUR_SLOPE||a<-SLUR_SLOPE){a=a>SLUR_SLOPE?SLUR_SLOPE:-SLUR_SLOPE
  1657. if(a*dir>0)
  1658. y1=y2-a*(x2-x1)
  1659. else
  1660. y2=y1+a*(x2-x1)}
  1661. y=y2-y1
  1662. if(y>8)
  1663. y=8
  1664. else if(y<-8)
  1665. y=-8
  1666. z=y
  1667. if(z<0)
  1668. z=-z;dx=.5*z;dy=.3*y
  1669. if(y*dir>0){x2-=dx;y2-=dy}else{x1+=dx;y1+=dy}
  1670. if(k1.grace)
  1671. x1=k1.x-GSTEM_XOFF*.5
  1672. if(k2.grace)
  1673. x2=k2.x+GSTEM_XOFF*1.5;h=0;a=(y2-y1)/(x2-x1)
  1674. if(k1!=k2&&k1.v==k2.v){addy=y1-a*x1
  1675. for(i=1;i<i2;i++){k=path[i]
  1676. if(k.st!=upstaff)
  1677. continue
  1678. switch(k.type){case C.NOTE:case C.REST:if(dir>0){y=3*(k.notes[k.nhd].pit-18)+6
  1679. if(y<k.ymx)
  1680. y=k.ymx;y-=a*k.x+addy
  1681. if(y>h)
  1682. h=y}else{y=3*(k.notes[0].pit-18)-6
  1683. if(y>k.ymn)
  1684. y=k.ymn;y-=a*k.x+addy
  1685. if(y<h)
  1686. h=y}
  1687. break
  1688. case C.GRACE:for(g=k.extra;g;g=g.next){if(dir>0){y=3*(g.notes[g.nhd].pit-18)+6
  1689. if(y<g.ymx)
  1690. y=g.ymx;y-=a*g.x+addy
  1691. if(y>h)
  1692. h=y}else{y=3*(g.notes[0].pit-18)-6
  1693. if(y>g.ymn)
  1694. y=g.ymn;y-=a*g.x+addy
  1695. if(y<h)
  1696. h=y}}
  1697. break}}
  1698. y1+=.45*h;y2+=.45*h;h*=.65}
  1699. if(nn>3)
  1700. height=(.08*(x2-x1)+12)*dir
  1701. else
  1702. height=(.03*(x2-x1)+8)*dir
  1703. if(dir>0){if(height<3*h)
  1704. height=3*h
  1705. if(height>40)
  1706. height=40}else{if(height>3*h)
  1707. height=3*h
  1708. if(height<-40)
  1709. height=-40}
  1710. y=y2-y1
  1711. if(y<0)
  1712. y=-y
  1713. if(dir>0){if(height<.8*y)
  1714. height=.8*y}else{if(height>-.8*y)
  1715. height=-.8*y}
  1716. height*=k1.fmt.slurheight;slur_out(x1,y1,x2,y2,dir,height,ty&C.SL_DOTTED);dx=x2-x1;a=(y2-y1)/dx;addy=y1-a*x1
  1717. if(height>0)
  1718. addy+=4*Math.sqrt(height)-2
  1719. else
  1720. addy-=4*Math.sqrt(-height)-2
  1721. for(i=0;i<i2;i++){k=path[i]
  1722. if(k.st!=upstaff||k.type==C.BAR)
  1723. continue
  1724. y=a*k.x+addy
  1725. if(k.ymx<y)
  1726. k.ymx=y
  1727. else if(k.ymn>y)
  1728. k.ymn=y
  1729. if(i==i2-1){dx=x2
  1730. if(sl.nte)
  1731. dx-=5;if(i)
  1732. y-=height/3}else{dx=path[i+1].x}
  1733. if(i!=0)
  1734. x1=k.x
  1735. else
  1736. y-=height/3
  1737. dx-=x1;y_set(upstaff,dir>0,x1,dx,y)}}
  1738. function draw_slurs(s,last){var gr1,i,m,note,sls,nsls
  1739. function draw_sls(s,sl){var k,v,i,dir,s3,path=[],s2=sl.se
  1740. if(last&&s2.time>last.time)
  1741. return
  1742. switch(sl.loc){case'i':s=prev_scut(s)
  1743. break
  1744. case'o':for(s3=s;s3.ts_next;s3=s3.ts_next);s2=s3
  1745. for(;s3;s3=s3.ts_prev){if(s3.v==s.v){s2=s3
  1746. break}
  1747. if(s3.st==s.st)
  1748. s2=s3
  1749. if(s3.ts_prev.time!=s2.time)
  1750. break}
  1751. break}
  1752. if(s.p_v.s_next&&s2.time>=tsnext.time){if(s2.time==tsnext.time){if(s2.grace){for(s3=tsnext;s3&&s3.time==s2.time;s3=s3.ts_next){if(s3.type==C.GRACE){s3=null
  1753. break}}}else{for(s3=tsnext;s3.time==s2.time;s3=s3.ts_next){if(s3==s2){s3=null
  1754. break}}}}else{s3=null}
  1755. if(!s3){s.p_v.sls.push(sl);s2=s.p_v.s_next.prev
  1756. while(s2.next)
  1757. s2=s2.next;sl=Object.create(sl)}}
  1758. switch(sl.ty&0x07){case C.SL_ABOVE:dir=1;break
  1759. case C.SL_BELOW:dir=-1;break
  1760. default:dir=s.v!=s2.v?1:slur_direction(s,s2)
  1761. sl.ty&=~0x07
  1762. sl.ty|=dir>0?C.SL_ABOVE:C.SL_BELOW
  1763. break}
  1764. if(s.v==s2.v){v=s.v}if(!cur_sy.voices[s.v]||!cur_sy.voices[s2.v]){v=s.v>s2.v?s.v:s2.v}else if(dir*(cur_sy.voices[s.v].range<=cur_sy.voices[s2.v].range?1:-1)>0)
  1765. v=s.v
  1766. else
  1767. v=s2.v
  1768. if(gr1&&!(s2.grace&&s.v==s2.v&&s.time==s2.time)){do{path.push(s);s=s.next}while(s);s=gr1.next}else{path.push(s);if(s.grace)
  1769. s=s.next
  1770. else
  1771. s=s.ts_next}
  1772. if(!s2.grace){while(s){if(s.v==v)
  1773. path.push(s)
  1774. if(s==s2)
  1775. break
  1776. s=s.ts_next}}else if(s.grace){while(1){path.push(s)
  1777. if(s==s2)
  1778. break
  1779. s=s.next}}else{k=s2
  1780. while(k.prev)
  1781. k=k.prev
  1782. while(1){if(s.v==v)
  1783. path.push(s)
  1784. if(s.extra==k)
  1785. break
  1786. s=s.ts_next}
  1787. s=k
  1788. while(1){path.push(s)
  1789. if(s==s2)
  1790. break
  1791. s=s.next}}
  1792. for(i=1;i<path.length-1;i++){s=path[i]
  1793. if(s.sls)
  1794. draw_slurs(s,last)
  1795. if(s.tp)
  1796. draw_tuplet(s)}
  1797. draw_slur(path,sl)
  1798. return 1}
  1799. while(1){if(!s||s==last){if(!gr1||!(s=gr1.next)||s==last)
  1800. break
  1801. gr1=null}
  1802. if(s.type==C.GRACE){gr1=s;s=s.extra
  1803. continue}
  1804. if(s.sls){sls=s.sls
  1805. s.sls=null
  1806. nsls=[]
  1807. for(i=0;i<sls.length;i++){if(!draw_sls(s,sls[i]))
  1808. nsls.push(sls[i])}
  1809. if(nsls.length)
  1810. s.sls=nsls}
  1811. s=s.next}}
  1812. function draw_tuplet(s1){var s2,s3,g,upstaff,nb_only,x1,x2,y1,y2,xm,ym,a,s0,yy,yx,dy,a,dir,r,tp=s1.tp.shift()
  1813. if(!s1.tp.length)
  1814. delete s1.tp
  1815. upstaff=s1.st
  1816. set_dscale(s1.st)
  1817. for(s2=s1;s2;s2=s2.next){switch(s2.type){case C.GRACE:if(!s2.sl1)
  1818. continue
  1819. for(g=s2.extra;g;g=g.next){if(g.sls)
  1820. draw_slurs(g)}
  1821. default:continue
  1822. case C.NOTE:case C.REST:break}
  1823. if(s2.sls)
  1824. draw_slurs(s2)
  1825. if(s2.st<upstaff)
  1826. upstaff=s2.st
  1827. if(s2.tp)
  1828. draw_tuplet(s2)
  1829. if(s2.tpe)
  1830. break}
  1831. if(s2)
  1832. s2.tpe--
  1833. if(tp.f[0]==1)
  1834. return
  1835. if(!s2){error(1,s1,"No end of tuplet in this music line")
  1836. return}
  1837. dir=tp.f[3]
  1838. if(!dir){s3=s1
  1839. while(s3&&!s3.stem)
  1840. s3=s3.next
  1841. dir=(s3&&s3.stem<0)?C.SL_BELOW:C.SL_ABOVE}
  1842. if(s1==s2||tp.f[1]==2){nb_only=true}else if(tp.f[1]==1){nb_only=true;draw_slur([s1,s2],{ty:dir})}else{if(tp.f[0]!=2&&s1.type==C.NOTE&&s2.type==C.NOTE){nb_only=true
  1843. for(s3=s1;;s3=s3.next){if(s3.type!=C.NOTE&&s3.type!=C.REST){if(s3.type==C.GRACE||s3.type==C.SPACE)
  1844. continue
  1845. nb_only=false
  1846. break}
  1847. if(s3==s2)
  1848. break
  1849. if(s3.beam_end){nb_only=false
  1850. break}}
  1851. if(nb_only&&!s1.beam_st&&!s1.beam_br1&&!s1.beam_br2){for(s3=s1.prev;s3;s3=s3.prev){if(s3.type==C.NOTE||s3.type==C.REST){if(s3.nflags>=s1.nflags)
  1852. nb_only=false
  1853. break}}}
  1854. if(nb_only&&!s2.beam_end){for(s3=s2.next;s3;s3=s3.next){if(s3.type==C.NOTE||s3.type==C.REST){if(!s3.beam_br1&&!s3.beam_br2&&s3.nflags>=s2.nflags)
  1855. nb_only=false
  1856. break}}}}}
  1857. if(nb_only){if(tp.f[2]==1)
  1858. return
  1859. set_font("tuplet")
  1860. xm=(s2.x+s1.x)/2
  1861. if(dir==C.SL_ABOVE)
  1862. ym=y_get(upstaff,1,xm-4,8)
  1863. else
  1864. ym=y_get(upstaff,0,xm-4,8)-
  1865. gene.curfont.size
  1866. if(s1.stem*s2.stem>0){if(s1.stem>0)
  1867. xm+=1.5
  1868. else
  1869. xm-=1.5}
  1870. if(tp.f[2]==0)
  1871. xy_str(xm,ym,tp.p.toString(),'c')
  1872. else
  1873. xy_str(xm,ym,tp.p+':'+tp.q,'c')
  1874. for(s3=s1;;s3=s3.next){if(s3.x>=xm)
  1875. break}
  1876. if(dir==C.SL_ABOVE){ym+=gene.curfont.size
  1877. if(s3.ymx<ym)
  1878. s3.ymx=ym;y_set(upstaff,true,xm-3,6,ym)}else{if(s3.ymn>ym)
  1879. s3.ymn=ym;y_set(upstaff,false,xm-3,6,ym)}
  1880. return}
  1881. x1=s1.x-4
  1882. if(s2.dur>s2.prev.dur){s3=s2.next
  1883. if(!s3||s3.time!=s2.time+s2.dur){for(s3=s2.ts_next;s3;s3=s3.ts_next){if(s3.seqst&&s3.time>=s2.time+s2.dur)
  1884. break}}
  1885. x2=s3?s3.x-s3.wl-5:realwidth-6}else{x2=s2.x+4
  1886. r=s2.stem>=0?0:s2.nhd
  1887. if(s2.notes[r].shhd>0)
  1888. x2+=s2.notes[r].shhd
  1889. if(s2.st==upstaff&&s2.stem>0)
  1890. x2+=3.5}
  1891. if(dir==C.SL_ABOVE){if(s1.st==s2.st){y1=y2=staff_tb[upstaff].topbar+2}else{y1=s1.ymx;y2=s2.ymx}
  1892. if(s1.st==upstaff){for(s3=s1;!s3.dur;s3=s3.next);ym=y_get(upstaff,1,s3.x-4,8)
  1893. if(ym>y1)
  1894. y1=ym
  1895. if(s1.stem>0)
  1896. x1+=3}
  1897. if(s2.st==upstaff){for(s3=s2;!s3.dur;s3=s3.prev);ym=y_get(upstaff,1,s3.x-4,8)
  1898. if(ym>y2)
  1899. y2=ym}
  1900. xm=.5*(x1+x2);ym=.5*(y1+y2);a=(y2-y1)/(x2-x1);s0=3*(s2.notes[s2.nhd].pit-s1.notes[s1.nhd].pit)/(x2-x1)
  1901. if(s0>0){if(a<0)
  1902. a=0
  1903. else if(a>s0)
  1904. a=s0}else{if(a>0)
  1905. a=0
  1906. else if(a<s0)
  1907. a=s0}
  1908. a=s1.fmt.beamslope*a/(s1.fmt.beamslope+Math.abs(a))
  1909. if(a*a<.1*.1)
  1910. a=0
  1911. dy=0
  1912. for(s3=s1;;s3=s3.next){if(!s3.dur||s3.st!=upstaff){if(s3==s2)
  1913. break
  1914. continue}
  1915. yy=ym+(s3.x-xm)*a;yx=y_get(upstaff,1,s3.x-4,8)+2
  1916. if(yx-yy>dy)
  1917. dy=yx-yy
  1918. if(s3==s2)
  1919. break}
  1920. ym+=dy;y1=ym+a*(x1-xm);y2=ym+a*(x2-xm);ym+=6
  1921. for(s3=s1;;s3=s3.next){if(s3.st==upstaff){yy=ym+(s3.x-xm)*a
  1922. if(s3.ymx<yy)
  1923. s3.ymx=yy
  1924. y_set(upstaff,true,s3.x-3,6,yy)}
  1925. if(s3==s2)
  1926. break}}else{if(s1.stem<0)
  1927. x1-=2
  1928. if(s1.st==upstaff){for(s3=s1;!s3.dur;s3=s3.next);y1=y_get(upstaff,0,s3.x-4,8)}else{y1=0}
  1929. if(s2.st==upstaff){for(s3=s2;!s3.dur;s3=s3.prev);y2=y_get(upstaff,0,s3.x-4,8)}else{y2=0}
  1930. xm=.5*(x1+x2);ym=.5*(y1+y2);a=(y2-y1)/(x2-x1);s0=3*(s2.notes[0].pit-s1.notes[0].pit)/(x2-x1)
  1931. if(s0>0){if(a<0)
  1932. a=0
  1933. else if(a>s0)
  1934. a=s0
  1935. if(a>.35)
  1936. a=.35}else{if(a>0)
  1937. a=0
  1938. else if(a<s0)
  1939. a=s0
  1940. if(a<-.35)
  1941. a=-.35}
  1942. if(a*a<.1*.1)
  1943. a=0
  1944. dy=0
  1945. for(s3=s1;;s3=s3.next){if(!s3.dur||s3.st!=upstaff){if(s3==s2)
  1946. break
  1947. continue}
  1948. yy=ym+(s3.x-xm)*a;yx=y_get(upstaff,0,s3.x-4,8)
  1949. if(yx-yy<dy)
  1950. dy=yx-yy
  1951. if(s3==s2)
  1952. break}
  1953. ym+=dy-8
  1954. y1=ym+a*(x1-xm);y2=ym+a*(x2-xm);ym-=2
  1955. for(s3=s1;;s3=s3.next){if(s3.st==upstaff){yy=ym+(s3.x-xm)*a
  1956. if(s3.ymn>yy)
  1957. s3.ymn=yy;y_set(upstaff,false,s3.x-3,6,yy)}
  1958. if(s3==s2)
  1959. break}}
  1960. if(tp.f[2]==1){out_tubr(x1,y1+4,x2-x1,y2-y1,dir==C.SL_ABOVE);return}
  1961. out_tubrn(x1,y1,x2-x1,y2-y1,dir==C.SL_ABOVE,tp.f[2]==0?tp.p.toString():tp.p+':'+tp.q);if(dir==C.SL_ABOVE)
  1962. y_set(upstaff,true,xm-3,6,yy+2)
  1963. else
  1964. y_set(upstaff,false,xm-3,6,yy)}
  1965. function draw_tie(not1,not2,job){var m,x1,s,y,h,time,p=job==2?not1.pit:not2.pit,dir=(not1.tie_ty&0x07)==C.SL_ABOVE?1:-1,s1=not1.s,st=s1.st,s2=not2.s,x2=s2.x,sh=not1.shhd
  1966. for(m=0;m<s1.nhd;m++)
  1967. if(s1.notes[m]==not1)
  1968. break
  1969. if(dir>0){if(m<s1.nhd&&p+1==s1.notes[m+1].pit)
  1970. if(s1.notes[m+1].shhd>sh)
  1971. sh=s1.notes[m+1].shhd}else{if(m>0&&p==s1.notes[m-1].pit+1)
  1972. if(s1.notes[m-1].shhd>sh)
  1973. sh=s1.notes[m-1].shhd}
  1974. x1=s1.x+sh
  1975. if(job!=2){for(m=0;m<s2.nhd;m++)
  1976. if(s2.notes[m]==not2)
  1977. break
  1978. sh=s2.notes[m].shhd
  1979. if(dir>0){if(m<s2.nhd&&p+1==s2.notes[m+1].pit)
  1980. if(s2.notes[m+1].shhd<sh)
  1981. sh=s2.notes[m+1].shhd}else{if(m>0&&p==s2.notes[m-1].pit+1)
  1982. if(s2.notes[m-1].shhd<sh)
  1983. sh=s2.notes[m-1].shhd}
  1984. x2+=sh}
  1985. switch(job){default:if(p<not2.pit||dir<0)
  1986. p=not1.pit
  1987. break
  1988. case 3:dir=-dir
  1989. case 1:x1=s2.prev?(s2.prev.x+s2.wr):s1.x
  1990. if(s1.st!=s2.st)
  1991. st=s2.st
  1992. x1+=(x2-x1)*.4
  1993. if(x1>x2-20)
  1994. x1=x2-20
  1995. break
  1996. case 2:x2=s1.next?s1.next.x:realwidth
  1997. if(x2!=realwidth)
  1998. x2-=(x2-x1)*.4
  1999. if(x2<x1+16)
  2000. x2=x1+16
  2001. break}
  2002. if(x2-x1>20){x1+=3.5
  2003. x2-=3.5}else{x1+=1.5
  2004. x2-=1.5}
  2005. if(s1.dots&&!(not1.pit&1)&&((dir>0&&!s1.dot_low)||(dir<0&&s1.dot_low)))
  2006. x1+=5
  2007. y=staff_tb[st].y+3*(p-18)+dir
  2008. h=(.03*(x2-x1)+16)*dir*s1.fmt.tieheight
  2009. slur_out(x1,y,x2,y,dir,h,not1.tie_ty&C.SL_DOTTED)}
  2010. function draw_all_ties(p_voice){var s,s1,s2,clef_chg,x,dx,m,not1,not2,tim2=0
  2011. s1=p_voice.sym
  2012. set_color(s1.color)
  2013. for(;s1;s1=s1.next){if(s1.ti2&&s1.time!=tim2){for(m=0;m<=s1.nhd;m++){not2=s1.notes[m]
  2014. not1=not2.tie_s
  2015. if(!not1||not1.s.v!=s1.v)
  2016. continue
  2017. draw_tie(not1,not2,1)}}
  2018. if(!s1.ti1)
  2019. continue
  2020. if(s1.type==C.GRACE){for(s=s1.extra;s;s=s.next){for(m=0;m<=s1.nhd;m++){not1=s.notes[m]
  2021. not2=not1.tie_e
  2022. if(!not2)
  2023. continue
  2024. draw_tie(not1,not2)
  2025. tim2=not2.s.time}}
  2026. continue}
  2027. for(m=0;m<=s1.nhd;m++){not1=s1.notes[m]
  2028. not2=not1.tie_e
  2029. if(!not2){if(not1.tie_ty)
  2030. draw_tie(not1,not1,2)
  2031. continue}
  2032. s2=not2.s
  2033. if(tsnext&&s2.time>=tsnext.time){draw_tie(not1,not2,2)
  2034. continue}
  2035. tim2=s2.time
  2036. for(s=s1.ts_next;s!=s2;s=s.ts_next){if(s.st!=s1.st)
  2037. continue
  2038. if(s.type==C.CLEF){clef_chg=true
  2039. break}}
  2040. if(clef_chg||s1.st!=s2.st){draw_tie(not1,not2,2)
  2041. draw_tie(not1,not2,3)
  2042. clef_chg=false}else{draw_tie(not1,not2)}}}}
  2043. function draw_sym_near(){var p_voice,p_st,s,v,st,y,g,w,i,st,dx,top,bot,ymn,output_sav=output;function set_yab(s1,s2){var y,k=realwidth/YSTEP,i=(s1.x/k)|0,j=(s2.x/k)|0,a=(s1.ys-s2.ys)/(s1.xs-s2.xs),b=s1.ys-s1.xs*a,p_st=staff_tb[s1.st]
  2044. k*=a
  2045. if(s1.stem>0){while(i<=j){y=k*i+b
  2046. if(p_st.top[i]<y)
  2047. p_st.top[i]=y
  2048. i++}}else{while(i<=j){y=k*i+b
  2049. if(p_st.bot[i]>y)
  2050. p_st.bot[i]=y
  2051. i++}}}
  2052. output=""
  2053. YSTEP=Math.ceil(realwidth/2)
  2054. for(st=0;st<=nstaff;st++){p_st=staff_tb[st]
  2055. p_st.top=new Float32Array(YSTEP)
  2056. p_st.bot=new Float32Array(YSTEP)
  2057. for(i=0;i<YSTEP;i++){p_st.top[i]=0
  2058. p_st.bot[i]=24}}
  2059. for(v=0;v<voice_tb.length;v++){var bm={},first_note=true;p_voice=voice_tb[v]
  2060. for(s=p_voice.sym;s;s=s.next){switch(s.type){case C.GRACE:for(g=s.extra;g;g=g.next){if(g.beam_st&&!g.beam_end){self.calculate_beam(bm,g)
  2061. if(bm.s2)
  2062. set_yab(g,bm.s2)}}
  2063. if(!s.p_v.ckey.k_bagpipe&&s.fmt.graceslurs&&!s.gr_shift&&!s.sl1&&!s.ti1&&s.next&&s.next.type==C.NOTE)
  2064. grace_slur(s)
  2065. break}}
  2066. for(s=p_voice.sym;s;s=s.next){switch(s.type){case C.NOTE:if((s.beam_st&&!s.beam_end)||(first_note&&!s.beam_st)){first_note=false;self.calculate_beam(bm,s)
  2067. if(bm.s2)
  2068. set_yab(s,bm.s2)}
  2069. break}}}
  2070. set_tie_room();draw_deco_near()
  2071. for(s=tsfirst;s;s=s.ts_next){if(s.invis)
  2072. continue
  2073. switch(s.type){case C.GRACE:for(g=s.extra;g;g=g.next){y_set(s.st,true,g.x-2,4,g.ymx+1);y_set(s.st,false,g.x-2,4,g.ymn-5)}
  2074. continue
  2075. case C.MREST:y_set(s.st,true,s.x+16,32,s.ymx+2)
  2076. continue
  2077. default:y_set(s.st,true,s.x-s.wl,s.wl+s.wr,s.ymx+2);y_set(s.st,false,s.x-s.wl,s.wl+s.wr,s.ymn-2)
  2078. continue
  2079. case C.NOTE:break}
  2080. if(s.stem>0){if(s.stemless){dx=-5;w=10}else if(s.beam_st){dx=3;w=s.beam_end?4:10}else{dx=-8;w=s.beam_end?11:16}
  2081. y_set(s.st,true,s.x+dx,w,s.ymx);ymn=s.ymn
  2082. if(s.notes[0].acc&&ymn>3*(s.notes[0].pit-18)-9)
  2083. ymn=3*(s.notes[0].pit-18)-9
  2084. y_set(s.st,false,s.x-s.wl,s.wl+s.wr,ymn)}else{y_set(s.st,true,s.x-s.wl,s.wl+s.wr,s.ymx);if(s.stemless){dx=-5;w=10}else if(s.beam_st){dx=-6;w=s.beam_end?4:10}else{dx=-8;w=s.beam_end?5:16}
  2085. dx+=s.notes[0].shhd;y_set(s.st,false,s.x+dx,w,s.ymn)}
  2086. if(s.notes[s.nhd].acc){y=3*(s.notes[s.nhd].pit-18)
  2087. +(s.notes[s.nhd].acc==-1?11:10)
  2088. y_set(s.st,true,s.x-10,10,y)}
  2089. if(s.notes[0].acc){y=3*(s.notes[0].pit-18)
  2090. -(s.notes[0].acc==-1?5:10)
  2091. y_set(s.st,false,s.x-10,10,y)}}
  2092. draw_deco_note()
  2093. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v];s=p_voice.sym
  2094. if(!s)
  2095. continue
  2096. set_color(s.color);st=p_voice.st;for(;s;s=s.next){if(s.play)
  2097. continue
  2098. if(s.tp)
  2099. draw_tuplet(s)
  2100. if(s.sls||s.sl1)
  2101. draw_slurs(s)}}
  2102. set_color()
  2103. for(st=0;st<=nstaff;st++){p_st=staff_tb[st];top=p_st.topbar+2;bot=p_st.botbar-2
  2104. for(i=0;i<YSTEP;i++){if(top>p_st.top[i])
  2105. p_st.top[i]=top
  2106. if(bot<p_st.bot[i])
  2107. p_st.bot[i]=bot}}
  2108. if(cfmt.measurenb>=0)
  2109. draw_measnb();set_dscale(-1)
  2110. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v]
  2111. if(p_voice.have_ly){draw_all_lyrics()
  2112. break}}
  2113. draw_deco_staff()
  2114. draw_partempo()
  2115. set_dscale(-1);output=output_sav}
  2116. function draw_vname(indent,stl){var p_voice,n,st,v,a_p,p,y,h,h2,staff_d=[]
  2117. for(st=stl.length;st>=0;st--){if(stl[st])
  2118. break}
  2119. if(st<0)
  2120. return
  2121. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v]
  2122. if(!cur_sy.voices[v])
  2123. continue
  2124. st=cur_sy.voices[v].st
  2125. if(!stl[st])
  2126. continue
  2127. if(!gene.vnt)
  2128. continue
  2129. p=gene.vnt==2?p_voice.nm:p_voice.snm
  2130. if(!p)
  2131. continue
  2132. delete p_voice.new_name
  2133. if(!staff_d[st])
  2134. staff_d[st]=p
  2135. else
  2136. staff_d[st]+="\n"+p}
  2137. if(!staff_d.length)
  2138. return
  2139. set_font("voice");h=gene.curfont.size
  2140. h2=h/2
  2141. indent=-indent*.5
  2142. for(st=0;st<staff_d.length;st++){if(!staff_d[st])
  2143. continue
  2144. a_p=staff_d[st].split("\n");y=staff_tb[st].y
  2145. +staff_tb[st].topbar*.5*staff_tb[st].staffscale
  2146. +h2*(a_p.length-2)
  2147. if((cur_sy.staves[st].flags&OPEN_BRACE)&&st+1<staff_tb.length&&(cur_sy.staves[st+1].flags&CLOSE_BRACE)&&!staff_d[st+1])
  2148. y-=(staff_tb[st].y-staff_tb[st+1].y)*.5
  2149. for(n=0;n<a_p.length;n++){p=a_p[n];xy_str(indent,y,p,"c");y-=h}}}
  2150. function set_staff(){var i,st,prev_staff,v,y,staffsep,dy,maxsep,mbot,val,p_voice,p_staff,fmt=tsfirst.fmt,sy=cur_sy
  2151. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v]
  2152. if(p_voice.scale!=1)
  2153. p_voice.scale_str='transform="scale('+p_voice.scale.toFixed(2)+')"'}
  2154. for(st=0;st<=nstaff;st++){if(gene.st_print[st])
  2155. break}
  2156. y=0
  2157. if(st>nstaff){st--;p_staff=staff_tb[st]}
  2158. p_staff=staff_tb[st]
  2159. for(i=0;i<YSTEP;i++){val=p_staff.top[i]
  2160. if(y<val)
  2161. y=val}
  2162. y*=p_staff.staffscale;staffsep=fmt.staffsep*.5+
  2163. p_staff.topbar*p_staff.staffscale
  2164. if(y<staffsep)
  2165. y=staffsep
  2166. if(y<p_staff.ann_top)
  2167. y=p_staff.ann_top;p_staff.y=-y;for(prev_staff=0;prev_staff<st;prev_staff++)
  2168. staff_tb[prev_staff].y=-y
  2169. if(!gene.st_print[st])
  2170. return y
  2171. var sy_staff_prev=sy.staves[prev_staff]
  2172. for(st++;st<=nstaff;st++){if(!gene.st_print[st])
  2173. continue
  2174. p_staff=staff_tb[st]
  2175. staffsep=sy_staff_prev.sep||cfmt.sysstaffsep;maxsep=sy_staff_prev.maxsep||cfmt.maxsysstaffsep;dy=0
  2176. if(p_staff.staffscale==staff_tb[prev_staff].staffscale){for(i=0;i<YSTEP;i++){val=p_staff.top[i]-
  2177. staff_tb[prev_staff].bot[i]
  2178. if(dy<val)
  2179. dy=val}
  2180. dy*=p_staff.staffscale}else{for(i=0;i<YSTEP;i++){val=p_staff.top[i]*p_staff.staffscale
  2181. -staff_tb[prev_staff].bot[i]*staff_tb[prev_staff].staffscale
  2182. if(dy<val)
  2183. dy=val}}
  2184. staffsep+=p_staff.topbar*p_staff.staffscale
  2185. if(dy<staffsep)
  2186. dy=staffsep;maxsep+=p_staff.topbar*p_staff.staffscale
  2187. if(dy>maxsep)
  2188. dy=maxsep;y+=dy;p_staff.y=-y;while(!gene.st_print[++prev_staff])
  2189. staff_tb[prev_staff].y=-y
  2190. while(1){sy_staff_prev=sy.staves[prev_staff]
  2191. if(sy_staff_prev)
  2192. break
  2193. sy=sy.next}}
  2194. mbot=0
  2195. for(i=0;i<YSTEP;i++){val=staff_tb[prev_staff].bot[i]
  2196. if(mbot>val)
  2197. mbot=val}
  2198. if(mbot>p_staff.ann_bot)
  2199. mbot=p_staff.ann_bot;mbot*=staff_tb[prev_staff].staffscale
  2200. for(st=0;st<=nstaff;st++){p_staff=staff_tb[st];dy=p_staff.y
  2201. if(p_staff.staffscale!=1){p_staff.scale_str='transform="translate(0,'+
  2202. (posy-dy).toFixed(1)+') '+'scale('+p_staff.staffscale.toFixed(2)+')"'}}
  2203. if(mbot==0){for(st=nstaff;st>=0;st--){if(gene.st_print[st])
  2204. break}
  2205. if(st<0)
  2206. return y}
  2207. dy=-mbot;staffsep=fmt.staffsep*.5
  2208. if(dy<staffsep)
  2209. dy=staffsep;maxsep=fmt.maxstaffsep*.5
  2210. if(dy>maxsep)
  2211. dy=maxsep;return y+dy}
  2212. function draw_systems(indent){var s,s2,st,x,x2,res,sy,xstaff=[],stl=[],bar_bot=[],bar_height=[],ba=[],sb="",thb=""
  2213. function bar_set(){var st,staffscale,top,bot,dy=0
  2214. for(st=0;st<=cur_sy.nstaff;st++){if(xstaff[st]<0){bar_bot[st]=bar_height[st]=0
  2215. continue}
  2216. staffscale=staff_tb[st].staffscale;top=staff_tb[st].topbar*staffscale;bot=staff_tb[st].botbar*staffscale
  2217. if(dy==0)
  2218. dy=staff_tb[st].y+top;bar_bot[st]=staff_tb[st].y+bot;bar_height[st]=dy-bar_bot[st];dy=(cur_sy.staves[st].flags&STOP_BAR)?0:bar_bot[st]}}
  2219. function draw_staff(st,x1,x2){var w,i,dy,ty,y=0,ln="",stafflines=staff_tb[st].stafflines,l=stafflines.length,il=6*staff_tb[st].staffscale
  2220. if(!/[\[|]/.test(stafflines))
  2221. return
  2222. w=x2-x1;set_sscale(-1)
  2223. if(cache&&cache.st_l==stafflines&&staff_tb[st].staffscale==1&&cache.st_w==(w|0)){xygl(x1,staff_tb[st].y,'stdef'+cfmt.fullsvg)
  2224. return}
  2225. for(i=0;i<l;i++,y-=il){if(stafflines[i]=='.')
  2226. continue
  2227. dy=0
  2228. for(;i<l;i++,y-=il,dy-=il){switch(stafflines[i]){case'.':case'-':continue
  2229. case ty:ln+='m-'+w.toFixed(1)+' '+dy+'h'+w.toFixed(1);dy=0
  2230. continue}
  2231. if(ty!=undefined)
  2232. ln+='"/>\n';ty=stafflines[i]
  2233. ln+='<path class="'+
  2234. (ty=='['?'slthW':'slW')+'" d="m0 '+y+'h'+w.toFixed(1);dy=0}
  2235. ln+='"/>'}
  2236. y=staff_tb[st].y
  2237. if(!cache&&w>get_lwidth()-10&&staff_tb[st].staffscale==1){cache={st_l:stafflines,st_w:w|0}
  2238. i='stdef'+cfmt.fullsvg;if(ln.indexOf('<path',1)<0)
  2239. glyphs[i]=ln.replace('path','path id="'+i+'"')
  2240. else
  2241. glyphs[i]='<g id="'+i+'">\n'+ln+'\n</g>';xygl(x1,y,i)
  2242. return}
  2243. out_XYAB('<g transform="translate(X, Y)">\n'+ln+'\n</g>\n',x1,y)}
  2244. function draw_bar(s,bot,h){var i,s2,yb,w,bar_type=s.bar_type,st=s.st,p_staff=staff_tb[st],x=s.x
  2245. if(st!=0&&s.ts_prev&&s.ts_prev.type!=C.BAR)
  2246. h=p_staff.topbar*p_staff.staffscale;s.ymx=s.ymn+h;set_sscale(-1)
  2247. anno_start(s)
  2248. if(s.color)
  2249. set_color(s.color);yb=p_staff.y+12;if(p_staff.stafflines!='|||||')
  2250. yb+=(p_staff.topbar+p_staff.botbar)/2-12
  2251. if(s.bar_mrep){set_sscale(st)
  2252. if(s.bar_mrep==1){for(s2=s.prev;s2.type!=C.REST;s2=s2.prev);xygl(s2.x,yb,"mrep")}else{xygl(x,yb,"mrep2")
  2253. if(s.v==cur_sy.top_voice)
  2254. nrep_out(x,yb+p_staff.topbar,s.bar_mrep)}
  2255. set_sscale(-1)}
  2256. if(bar_type=='||:')
  2257. bar_type='[|:'
  2258. for(i=bar_type.length;--i>=0;){switch(bar_type[i]){case"|":if(s.bar_dotted){w=(5*p_staff.staffscale).toFixed(1);out_XYAB('<path class="bW" stroke-dasharray="A,A" d="MX Yv-G"/>\n',x,bot,w,h)}else if(s.color){out_XYAB('<path class="bW" d="MX Yv-F"/>\n',x,bot,h)}else{sb+='M'+sx(x).toFixed(1)
  2259. +' '+self.sy(bot).toFixed(1)
  2260. +'v-'+h.toFixed(1)}
  2261. break
  2262. default:x-=3;if(s.color)
  2263. out_XYAB('<path class="bthW" d="MX Yv-F"/>\n',x+1.5,bot,h)
  2264. else
  2265. thb+='M'+sx(x+1.5).toFixed(1)
  2266. +' '+self.sy(bot).toFixed(1)
  2267. +'v-'+h.toFixed(1)
  2268. break
  2269. case":":x-=2;set_sscale(st);xygl(x+1,yb-12,"rdots")
  2270. set_sscale(-1)
  2271. break}
  2272. x-=3}
  2273. set_color();anno_stop(s)}
  2274. function out_bars(){var i,b,bx,l=ba.length
  2275. set_font("annotation");bx=gene.curfont.box
  2276. if(bx)
  2277. gene.curfont.box=0
  2278. for(i=0;i<l;i++){b=ba[i];draw_bar(b[0],b[1],b[2])}
  2279. if(bx)
  2280. gene.curfont.box=bx
  2281. set_sscale(-1)
  2282. if(sb)
  2283. output+='<path class="bW" d="'
  2284. +sb
  2285. +'"/>\n'
  2286. if(thb)
  2287. output+='<path class="bthW" d="'
  2288. +thb
  2289. +'"/>\n'}
  2290. function hl_rest(s){var j,p_st=staff_tb[s.st],i=5-s.nflags,x=s.x,y=s.y
  2291. if(i<6)
  2292. return
  2293. if(i==7&&y==12&&p_st.stafflines.length<=2)
  2294. y-=6
  2295. j=y/6
  2296. switch(i){default:switch(p_st.stafflines[j+1]){case'|':case'[':break
  2297. default:set_hl(p_st,j+1,x,-7,7)
  2298. break}
  2299. if(i==9){y-=6
  2300. j--}
  2301. break
  2302. case 7:y+=6
  2303. j++
  2304. case 6:break}
  2305. switch(p_st.stafflines[j]){case'|':case'[':break
  2306. default:set_hl(p_st,j,x,-7,7)
  2307. break}}
  2308. for(st=0;st<=nstaff;st++){stl[st]=cur_sy.st_print[st]
  2309. xstaff[st]=!stl[st]?-1:0}
  2310. bar_set();draw_lstaff(0)
  2311. for(s=tsfirst;s;s=s.ts_next){switch(s.type){case C.STAVES:sy=s.sy
  2312. for(st=0;st<=nstaff;st++){x=xstaff[st]
  2313. if(x<0){if(sy.st_print[st]){if(s.ts_prev.bar_type)
  2314. xstaff[st]=s.ts_prev.x
  2315. else if(s.ts_next.bar_type)
  2316. xstaff[st]=s.x
  2317. else
  2318. xstaff[st]=s.ts_prev.x
  2319. +s.ts_prev.wr
  2320. stl[st]=true}
  2321. continue}
  2322. if(sy.st_print[st]&&cur_sy.staves[st]&&sy.staves[st].stafflines==cur_sy.staves[st].stafflines)
  2323. continue
  2324. if(s.ts_prev.bar_type){x2=s.ts_prev.x}else{x2=(s.ts_prev.x+s.x)/2
  2325. xstaff[st]=-1}
  2326. draw_staff(st,x,x2)
  2327. xstaff[st]=sy.st_print[st]?x2:-1}
  2328. cur_sy=sy;bar_set()
  2329. continue
  2330. case C.BAR:if(s.invis||!s.bar_type||!cur_sy.st_print[s.st])
  2331. break
  2332. if(s.second&&(!s.ts_prev||(s.ts_prev.type==C.BAR&&s.ts_prev.st==s.st)))
  2333. break
  2334. ba.push([s,bar_bot[s.st],bar_height[s.st]])
  2335. break
  2336. case C.STBRK:if(cur_sy.voices[s.v]&&cur_sy.voices[s.v].range==0){if(s.xmx>14){var nv=0
  2337. for(var i=0;i<voice_tb.length;i++){if(cur_sy.voices[i]&&cur_sy.voices[i].range>0)
  2338. nv++}
  2339. for(s2=s.ts_next;s2;s2=s2.ts_next){if(s2.type!=C.STBRK)
  2340. break
  2341. nv--}
  2342. if(nv==0)
  2343. draw_lstaff(s.x)}}
  2344. st=s.st;x=xstaff[st]
  2345. if(x>=0){s2=s.prev
  2346. if(!s2)
  2347. break
  2348. x2=s2.type==C.BAR?s2.x:s.x-s.xmx
  2349. if(x>=x2)
  2350. break
  2351. draw_staff(st,x,x2)
  2352. xstaff[st]=s.x}
  2353. break
  2354. case C.GRACE:for(s2=s.extra;s2;s2=s2.next)
  2355. self.draw_hl(s2)
  2356. break
  2357. case C.NOTE:if(!s.invis)
  2358. self.draw_hl(s)
  2359. break
  2360. case C.REST:if(s.fmr||(s.rep_nb&&s.rep_nb>=0))
  2361. center_rest(s)
  2362. if(!s.invis)
  2363. hl_rest(s)
  2364. break}}
  2365. for(st=0;st<=nstaff;st++){x=xstaff[st]
  2366. if(x<0||x>=realwidth)
  2367. continue
  2368. draw_staff(st,x,realwidth)}
  2369. draw_all_hl()
  2370. out_bars()
  2371. draw_vname(indent,stl)}
  2372. Abc.prototype.draw_symbols=function(p_voice){var bm={},s,x,y,st;for(s=p_voice.sym;s;s=s.next){if(s.invis){switch(s.type){case C.CLEF:if(s.time>=staff_tb[s.st].clef.time)
  2373. staff_tb[s.st].clef=s
  2374. continue
  2375. case C.KEY:p_voice.ckey=s
  2376. default:continue
  2377. case C.NOTE:break}}
  2378. st=s.st
  2379. x=s.x;set_color(s.color)
  2380. switch(s.type){case C.NOTE:set_scale(s)
  2381. if(s.beam_st&&!s.beam_end){if(self.calculate_beam(bm,s))
  2382. draw_beams(bm)}
  2383. if(!s.invis){anno_start(s);draw_note(s,!bm.s2);anno_a.push(s)}
  2384. if(s==bm.s2)
  2385. bm.s2=null
  2386. break
  2387. case C.REST:if(!gene.st_print[st])
  2388. break
  2389. draw_rest(s);break
  2390. case C.BAR:break
  2391. case C.CLEF:if(s.time>=staff_tb[st].clef.time)
  2392. staff_tb[st].clef=s
  2393. if(s.second||!staff_tb[st].topbar||!gene.st_print[st])
  2394. break
  2395. set_color();set_sscale(st);anno_start(s);y=staff_tb[st].y
  2396. if(s.clef_name)
  2397. xygl(x,y+s.y,s.clef_name)
  2398. else if(!s.clef_small)
  2399. xygl(x,y+s.y,s.clef_type+"clef")
  2400. else
  2401. xygl(x,y+s.y,"s"+s.clef_type+"clef")
  2402. if(s.clef_octave){if(s.clef_octave>0){y+=s.ymx-10
  2403. if(s.clef_small)
  2404. y-=1}else{y+=s.ymn+6
  2405. if(s.clef_small)
  2406. y+=1}
  2407. xygl(x-2,y,(s.clef_octave==7||s.clef_octave==-7)?"oct":"oct2")}
  2408. anno_a.push(s)
  2409. break
  2410. case C.METER:p_voice.meter=s
  2411. if(s.second||!staff_tb[s.st].topbar)
  2412. break
  2413. set_color();set_sscale(s.st);anno_start(s);draw_meter(s);anno_a.push(s)
  2414. break
  2415. case C.KEY:p_voice.ckey=s
  2416. if(s.second||!staff_tb[s.st].topbar)
  2417. break
  2418. set_color();set_sscale(s.st);anno_start(s);self.draw_keysig(x,s);anno_a.push(s)
  2419. break
  2420. case C.MREST:draw_mrest(s)
  2421. break
  2422. case C.GRACE:set_scale(s);draw_gracenotes(s)
  2423. break
  2424. case C.SPACE:case C.STBRK:break
  2425. case C.CUSTOS:set_scale(s);draw_note(s,0)
  2426. break
  2427. case C.BLOCK:case C.REMARK:case C.STAVES:case C.TEMPO:break
  2428. default:error(2,s,"draw_symbols - Cannot draw symbol "+s.type)
  2429. break}}
  2430. set_scale(p_voice.sym)}
  2431. function draw_all_sym(){var p_voice,v,n=voice_tb.length
  2432. for(v=0;v<n;v++){p_voice=voice_tb[v]
  2433. if(p_voice.sym&&p_voice.sym.x!=undefined){self.draw_symbols(p_voice)
  2434. draw_all_ties(p_voice);set_color()}}
  2435. self.draw_all_deco()
  2436. glout()
  2437. anno_put()
  2438. set_sscale(-1)}
  2439. function set_tie_dir(s){var i,ntie,dir,sec,pit,ty,s2
  2440. for(;s;s=s.next){if(!s.ti1)
  2441. continue
  2442. sec=ntie=0;pit=128
  2443. for(i=0;i<=s.nhd;i++){if(s.notes[i].tie_ty){ntie++
  2444. if(pit<128&&s.notes[i].pit<=pit+1)
  2445. sec++;pit=s.notes[i].pit
  2446. s2=s.notes[i].tie_e}}
  2447. if(s2&&s.stem*s2.stem<0)
  2448. dir=pit>=22?C.SL_ABOVE:C.SL_BELOW
  2449. else if(s.multi)
  2450. dir=s.multi>0?C.SL_ABOVE:C.SL_BELOW
  2451. else
  2452. dir=s.stem<0?C.SL_ABOVE:C.SL_BELOW
  2453. if(s.multi){for(i=0;i<=s.nhd;i++){ty=s.notes[i].tie_ty
  2454. if(!((ty&0x07)==C.SL_AUTO))
  2455. continue
  2456. s.notes[i].tie_ty=(ty&C.SL_DOTTED)|dir}
  2457. continue}
  2458. if(ntie<=1){for(i=0;i<=s.nhd;i++){ty=s.notes[i].tie_ty
  2459. if(ty){if((ty&0x07)==C.SL_AUTO)
  2460. s.notes[i].tie_ty=(ty&C.SL_DOTTED)|dir
  2461. break}}
  2462. continue}
  2463. if(!sec){if(ntie&1){ntie=(ntie-1)/2;dir=C.SL_BELOW
  2464. for(i=0;i<=s.nhd;i++){ty=s.notes[i].tie_ty
  2465. if(!ty)
  2466. continue
  2467. if(ntie==0){if(s.notes[i].pit>=22)
  2468. dir=C.SL_ABOVE}
  2469. if((ty&0x07)==C.SL_AUTO)
  2470. s.notes[i].tie_ty=(ty&C.SL_DOTTED)|dir
  2471. if(ntie--==0)
  2472. dir=C.SL_ABOVE}
  2473. continue}
  2474. ntie/=2;dir=C.SL_BELOW
  2475. for(i=0;i<=s.nhd;i++){ty=s.notes[i].tie_ty
  2476. if(!ty)
  2477. continue
  2478. if((ty&0x07)==C.SL_AUTO)
  2479. s.notes[i].tie_ty=(ty&C.SL_DOTTED)|dir
  2480. if(--ntie==0)
  2481. dir=C.SL_ABOVE}
  2482. continue}
  2483. pit=128
  2484. for(i=0;i<=s.nhd;i++){if(s.notes[i].tie_ty){if(pit<128&&s.notes[i].pit<=pit+1){ntie=i
  2485. break}
  2486. pit=s.notes[i].pit}}
  2487. dir=C.SL_BELOW
  2488. for(i=0;i<=s.nhd;i++){ty=s.notes[i].tie_ty
  2489. if(!ty)
  2490. continue
  2491. if(ntie==i)
  2492. dir=C.SL_ABOVE
  2493. if((ty&0x07)==C.SL_AUTO)
  2494. s.notes[i].tie_ty=(ty&C.SL_DOTTED)|dir}}}
  2495. function set_tie_room(){var p_voice,s,s2,v,dx,y,dy
  2496. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v];s=p_voice.sym
  2497. if(!s)
  2498. continue
  2499. s=s.next
  2500. if(!s)
  2501. continue
  2502. set_tie_dir(s)
  2503. for(;s;s=s.next){if(!s.ti1)
  2504. continue
  2505. if(s.notes[0].pit<20&&s.notes[0].tie_ty&&(s.notes[0].tie_ty&0x07)==C.SL_BELOW);else if(s.notes[s.nhd].pit>24&&s.notes[s.nhd].tie_ty&&(s.notes[s.nhd].tie_ty&0x07)==C.SL_ABOVE);else
  2506. continue
  2507. s2=s.next
  2508. while(s2&&s2.type!=C.NOTE)
  2509. s2=s2.next
  2510. if(s2){if(s2.st!=s.st)
  2511. continue
  2512. dx=s2.x-s.x-10}else{dx=realwidth-s.x-10}
  2513. if(dx<100)
  2514. dy=9
  2515. else if(dx<300)
  2516. dy=12
  2517. else
  2518. dy=16
  2519. if(s.notes[s.nhd].pit>24){y=3*(s.notes[s.nhd].pit-18)+dy
  2520. if(s.ymx<y)
  2521. s.ymx=y
  2522. if(s2&&s2.ymx<y)
  2523. s2.ymx=y;y_set(s.st,true,s.x+5,dx,y)}
  2524. if(s.notes[0].pit<20){y=3*(s.notes[0].pit-18)-dy
  2525. if(s.ymn>y)
  2526. s.ymn=y
  2527. if(s2&&s2.ymn>y)
  2528. s2.ymn=y;y_set(s.st,false,s.x+5,dx,y)}}}}
  2529. var musicfont='url("data:application/octet-stream;base64,\
  2530. AAEAAAAOAIAAAwBgRkZUTZHVOuoAAFgMAAAAHEdERUYAFQAUAABX8AAAABxPUy8yWMFdCgAAAWgA\
  2531. AABWY21hcHlUuFMAAAQIAAAD5mN2dCAAIgKIAAAH8AAAAARnYXNw//8AAwAAV+gAAAAIZ2x5ZqUq\
  2532. QgUAAAkcAABF/GhlYWQVmDJzAAAA7AAAADZoaGVhCWn/GwAAASQAAAAkaG10eNm9+0EAAAHAAAAC\
  2533. SGxvY2HHqraAAAAH9AAAASZtYXhwANkBEgAAAUgAAAAgbmFtZeq7sB0AAE8YAAADFXBvc3SIfxKM\
  2534. AABSMAAABbUAAQAAAAEAANGbj/xfDzz1AAsEAAAAAADRlyIXAAAAAOBezej/OPzvBUsEiAAAAAgA\
  2535. AgAAAAAAAAABAAAEiPzvAFwEJf84/XQFSwABAAAAAAAAAAAAAAAAAAAAkgABAAAAkgDhAAUAAAAA\
  2536. AAIAAAABAAEAAABAAC4AAAAAAAEBgAGQAAUACAKZAswAAACPApkCzAAAAesAMwEJAAACAAUDAAAA\
  2537. AAAAAAAAARAAAAAAAAAAAAAAAFBmRWQAQAAA7LcDOP84AFwEiAMRAAAAAQAAAAAAAAF2ACIAAAAA\
  2538. AVUAAAGQAAACWAAAAFcAAAAjAAAAJQAAACT//wBkAAAEIwAABCUAAAHg/9wDugAAAwsAAALSAAAC\
  2539. v/+6AdYAAAMLAAADDgAAAyf/yADIAAABaAAAAa4AAAEiAAABkAAAAXwAAAGQAAABkAAAAYEAAAGQ\
  2540. AAABkAAAAYEAAAGZAAkBmAAJAfQAAAEEABQBBAAKAmsAJAISAAABwgAAAUIAAAFAAAABSv/+ASwA\
  2541. AAIwAAABSgAAAUoAAABkAAABQAAAAUAAAAFAAAABQAAAAGQAAAE2AAAA5gAAATYAAAE7AAABOwAA\
  2542. ATsAAAE7AAABOwAAATsAAAE7AAABOwAAATsAAAE7AAABDQAAAMgAAAD/AAABCwAUAW4AAACMAAAA\
  2543. jAAAAQ0AMgFu//UAqQAAAToAAAFA//0AUAAAAVQAAABkAAABGAAAAlgAAAC2AAABkAAFAIIAAACC\
  2544. AAABLAAAASwAAADuAAAA/wAAAUkAAAGPAAAB2AAAAdgAAAIz//ADIP/hAXv/tAG4/9sBFv9+ARP/\
  2545. 2wDcAAAA6P/kAr//tAIz/7QCv/+0Ayv/2wFf/9sCaf9+AV//fgJp/34BXwAAAf0ABQG1AAABtQAA\
  2546. AkQADQJEAA0BGAAAATYAAAEs//8BLAAAAPoAAADIAAABGP84APoAAADIAAAEDQAAAhwADAH0AAAB\
  2547. 9AAAAfQAAAH0AAAB9AAAAfQAAAB4AAAALQAAAhwAAAD6AAAA+v/oAcIAAAFIAAABQAAAAgoAAAIK\
  2548. AAAAZAAAAAAAAwAAAAMAAAAcAAEAAAAAAuAAAwABAAAAHAAEAsQAAABgAEAABQAgAAAAIOAA4DDg\
  2549. OeBI4FDgXOBi4GngjOCV4KTgqeCz4QHhu+Hn4gDiSeJk4mvig+Ss5MDk0eTq5QHlMeU55W3lguXQ\
  2550. 5eLmGOYk5jDmUOZV6RjpIOkl6V3qAuqk7Knst///AAAAAAAg4ADgMOA44EPgUOBc4GLgaeB64JTg\
  2551. oOCp4LPhAeG54efh8uJA4mDiauKA5KDkwOTO5OHlAOUg5TnlZuWC5dDl4uYQ5iT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ARGR0rCRgrNS8fGdERHRAeHQsGCxAPFh8qCxkoFjcWHht9AR4QxikrNA0ZHhQVJjkh\
  2708. EiA5NEACRv7BMiYBHRHGKS8wExMcFhUmNiQWHD4vGyUCRv7BMgAAAQAA/wYAjAD6AA4AADcVBhUU\
  2709. FxUuAzQ+AoxQUBolMhsbMiX6FEOjpkAUDx86WnBaOh8AAAEAAP8GAIwA+gAOAAA1HgMUDgIHNTY1\
  2710. NCcaJTIbGzIlGlBQ+g8fOlpwWjofDxRApqNDAAACADL/ZAENAbAACgAWAAA3IgYVFBcWFzU0Jicy\
  2711. FxEzESInJjU0NqsXIC4uGiozOiMjOlJPOXomGzBFQgPLEh4mNAFE/bRSUEUjMgAABP/1/2oBbAGw\
  2712. AA4AHQAsADsAADcjIgcGFRQXFhcWMzU0JicyFxEzESImJyYnJjU0NhcOAR0BMjc2NzY1NCcmIzcy\
  2713. FhUUBwYHDgEjETMRNlcBERAKBAwfHg4eKzAZHxY3FysYCSvpER0QHh0LBgsQDxYfKgsZKBY3Fh4b\
  2714. fRUUHhkNNCspxhAeJzIBP/26JRs0OSASITkmAR0RxikvMBMTHBYVJjYkFhw+LxslAkb+wTIAAAAA\
  2715. AQAA/sAAqQFAABMAABMzFTcVBxU3FQcVIzUHNTc1BzU3RB5HR0dHHkREREQBQKIOXA5/DloPqKIO\
  2716. XA5/DloPAAMAAP6YAToBaAAjACcAKwAANzUzFTcVBxU3FQcVIzUHFSM1DwEjNQc1NzUHNTc1MxU3\
  2717. NTMVAzUHFTcVNzXpHjMzMzMePR48AR4zMzMzHj0eHj1bPcCong9cD58PWg+1qhKspBCong9cD58P\
  2718. Wg+1qhKspP79nhGfuJ4RnwAB//0AAAE/APQAGAAANwYjIiY1ND8BNi8BJjU0NjMyMRcFFhUUBxIC\
  2719. AwcJBs8ODs0ICwcBAgEfDg4BARAICgNJBwZPAwsKEgFrBg4NBQAAAAEAAAAAAFAAUAAJAAA1NDYy\
  2720. FhQGIyImFyIXFxEQGCgRFx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AQ4eHv7yHkaMjHgyMvxU\
  2875. AmIyAAEAAAAAAlYBcgALAAA1Nxc3FzcXAScHJweJVFZSryL+/FRWUzVBuXNzcekW/qR0dHBHAAAB\
  2876. /+gAvQESATcAFwAAJj4BMzIWMjc2MzIVFA4BIyImIgcGIyI1GDAhHBRVKBQDBw4wIRwUVSgUBAcN\
  2877. 9jARPRQDBwwwET0UBAgAAAAAAgAA/4kBwgCLAAsAEwAABTQmIyIGFRQWMzI+ARQGIiY0NjIBUVo2\
  2878. IDRdNyEvcX3IfX3IFDRPJx80TCN0bEtLbEsAAAACAAD/bAFIAqgADQAcAAAlJiMiBhUUFxYzMjY1\
  2879. NBMzERQGIyInJjU0NjMyFwEkDSU8lwYLJjyXAh1+SE8kD35IQCREF2ErCgkXYSsJAm79bkNnQx4d\
  2880. Q2ctAAAAAAEAAP95AUACqAANAAABMxEUBiMiJjU0NjMyFwEiHnlZMjx6WDEfAqj9gEZpOCdFahwA\
  2881. AAABAAD/eQIKAqgAGgAAAREUBiMiJjU0NjMyFxE1Mx4EFRQHNjU0AUB5WTI8elgxHx4GLjk4JTIS\
  2882. Abn+b0ZpOCdFahwBTu81XEdOdUlIckFJ7wAAAAACAAD/eQILAqgAHwAoAAAlNREzHgQVFAcWFRQH\
  2883. NjU0JiMRFAYjIiY1NDYzMhMeARc0NjU0JgEiHgkwODYjFRYiBXY4eVkyPHpYMT0OhRsBdmvmAVck\
  2884. RztCWDMlMjAkLkEZIV+e/tZGaTgnRWoBdjuiNQMOA1+fAAABAAD/zgBkADIABwAAFiImNDYyFhRH\
  2885. Kh0dKh0yHSodHSoAAAAAAA4ArgABAAAAAAAAAIMBCAABAAAAAAABAAcBnAABAAAAAAACAAcBtAAB\
  2886. AAAAAAADAB8B/AABAAAAAAAEAAcCLAABAAAAAAAFAAgCRgABAAAAAAAGAAcCXwADAAEECQAAAQYA\
  2887. AAADAAEECQABAA4BjAADAAEECQACAA4BpAADAAEECQADAD4BvAADAAEECQAEAA4CHAADAAEECQAF\
  2888. ABACNAADAAEECQAGAA4CTwBDAG8AcAB5AHIAaQBnAGgAdAAgAFwAMgA1ADEAIAAyADAAMQA4AC0A\
  2889. MgAwADEAOQAgAEoAZQBhAG4ALQBGAHIAYQBuAGMAbwBpAHMAIABNAG8AaQBuAGUALgAgAFQAaABp\
  2890. AHMAIABmAG8AbgB0ACAAaQBzACAAbABpAGMAZQBuAHMAZQBkACAAdQBuAGQAZQByACAAdABoAGUA\
  2891. IABTAEkATAAgAE8AcABlAG4AIABGAG8AbgB0ACAATABpAGMAZQBuAHMAZQAgAFwAKABoAHQAdABw\
  2892. ADoALwAvAHMAYwByAGkAcAB0AHMALgBzAGkAbAAuAG8AcgBnAC8ATwBGAEwAXAApAC4AAENvcHly\
  2893. aWdodCBcMjUxIDIwMTgtMjAxOSBKZWFuLUZyYW5jb2lzIE1vaW5lLiBUaGlzIGZvbnQgaXMgbGlj\
  2894. ZW5zZWQgdW5kZXIgdGhlIFNJTCBPcGVuIEZvbnQgTGljZW5zZSBcKGh0dHA6Ly9zY3JpcHRzLnNp\
  2895. bC5vcmcvT0ZMXCkuAABhAGIAYwAyAHMAdgBnAABhYmMyc3ZnAABSAGUAZwB1AGwAYQByAABSZWd1\
  2896. bGFyAABGAG8AbgB0AEYAbwByAGcAZQAgADoAIABhAGIAYwAyAHMAdgBnACAAOgAgADEANAAtADQA\
  2897. LQAyADAAMgAzAABGb250Rm9yZ2UgOiBhYmMyc3ZnIDogMTQtNC0yMDIzAABhAGIAYwAyAHMAdgBn\
  2898. AABhYmMyc3ZnAABWAGUAcgBzAGkAbwBuACAAAFZlcnNpb24gAABhAGIAYwAyAHMAdgBnAABhYmMy\
  2899. c3ZnAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJIAAAABAAIBAgADAQMBBAEF\
  2900. AQYBBwEIAQkBCgELAQwBDQEOAQ8BEAERARIBEwEUARUBFgEXARgBGQEaARsBHAEdAR4BHwEgASEB\
  2901. IgEj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
  2927. var font_scale_tb={serif:1,serifBold:1,'sans-serif':1,'sans-serifBold':1,Palatino:1.1,monospace:1.35},txt_ff="text,serif",fmt_lock={}
  2928. var cfmt={"abc-version":"1",annotationfont:{name:"text,sans-serif",size:12},aligncomposer:1,beamslope:.4,bardef:{"[":"","[]":"","|:":"[|:","|::":"[|::","|:::":"[|:::",":|":":|]","::|":"::|]",":::|":":::|]","::":":][:"},breaklimit:.7,breakoneoln:true,cancelkey:true,composerfont:{name:txt_ff,style:"italic",size:14},composerspace:6,decoerr:true,dynalign:true,footerfont:{name:txt_ff,size:16},fullsvg:'',gchordfont:{name:"text,sans-serif",size:12},gracespace:new Float32Array([6,8,11]),graceslurs:true,headerfont:{name:txt_ff,size:16},historyfont:{name:txt_ff,size:16},hyphencont:true,indent:0,infofont:{name:txt_ff,style:"italic",size:14},infoname:'R "Rhythm: "\n\
  2929. B "Book: "\n\
  2930. S "Source: "\n\
  2931. D "Discography: "\n\
  2932. N "Notes: "\n\
  2933. Z "Transcription: "\n\
  2934. H "History: "',infospace:0,keywarn:true,leftmargin:1.4*CM,lineskipfac:1.1,linewarn:true,maxshrink:.65,maxstaffsep:2000,maxsysstaffsep:2000,measrepnb:1,measurefont:{name:txt_ff,style:"italic",size:10},measurenb:-1,musicfont:{name:"music",src:musicfont,size:24},musicspace:6,partsfont:{name:txt_ff,size:15},parskipfac:.4,partsspace:8,pagewidth:21*CM,"propagate-accidentals":"o",printmargin:0,rightmargin:1.4*CM,rbmax:4,rbmin:2,repeatfont:{name:txt_ff,size:9},scale:1,slurheight:1.0,spatab:new Float32Array([10.2,13.3,17.3,22.48,29.2,38,49.4,64.2,83.5,108.5]),staffsep:46,stemheight:21,stretchlast:.25,stretchstaff:true,subtitlefont:{name:txt_ff,size:16},subtitlespace:3,sysstaffsep:34,tempofont:{name:txt_ff,weight:"bold",size:12},textfont:{name:txt_ff,size:16},textspace:14,tieheight:1.0,titlefont:{name:txt_ff,size:20},titlespace:6,titletrim:true,topspace:22,tuplets:[0,0,0,0],tupletfont:{name:txt_ff,style:"italic",size:12},vocalfont:{name:txt_ff,weight:"bold",size:13},vocalspace:10,voicefont:{name:txt_ff,weight:"bold",size:13},writefields:"CMOPQsTWw",wordsfont:{name:txt_ff,size:16},wordsspace:5,"writeout-accidentals":"n"}
  2935. var sfmt={bardef:true,barsperstaff:true,beamslope:true,breaklimit:true,bstemdown:true,cancelkey:true,dynalign:true,flatbeams:true,gracespace:true,hyphencont:true,keywarn:true,maxshrink:true,maxstaffsep:true,measrepnb:true,rbmax:true,rbmin:true,shiftunison:true,slurheight:true,squarebreve:true,staffsep:true,stemheight:true,stretchlast:true,stretchstaff:true,tieheight:true,timewarn:true,vocalspace:true}
  2936. function get_bool(param){return!param||!/^(0|n|f)/i.test(param)}
  2937. function get_font_scale(param){var i,font,a=info_split(param)
  2938. if(a.length<=1)
  2939. return
  2940. var scale=+a[a.length-1]
  2941. if(isNaN(scale)||scale<=0.5){syntax(1,"Bad scale value in %%font")
  2942. return}
  2943. font_scale_tb[a[0]]=scale}
  2944. function set_font_fac(font){var scale=font_scale_tb[font.fname||font.name]
  2945. if(!scale)
  2946. scale=1.1;font.swfac=font.size*scale}
  2947. function param_set_font(xxxfont,p){var font,n,a,ft2,k
  2948. if(xxxfont[xxxfont.length-2]=='-'){n=xxxfont[xxxfont.length-1]
  2949. if(n<'1'||n>'9')
  2950. return
  2951. xxxfont="u"+n+"font"}
  2952. font={}
  2953. a=p.match(/\s+(no)?box(\s|$)/)
  2954. if(a){if(a[1]){font.box=false
  2955. font.pad=0}else{font.box=true
  2956. font.pad=2.5}
  2957. p=p.replace(a[0],a[2])}
  2958. a=p.match(/\s+padding=([\d.]+)(\s|$)/)
  2959. if(a){font.pad=a[1]?+a[1]:0
  2960. p=p.replace(a[0],a[2])}
  2961. a=p.match(/\s+class=(.*?)(\s|$)/)
  2962. if(a){font.class=a[1];p=p.replace(a[0],a[2])}
  2963. a=p.match(/\s+wadj=(.*?)(\s|$)/)
  2964. if(a){if(typeof document=="undefined")
  2965. switch(a[1]){case'none':font.wadj=''
  2966. break
  2967. case'space':font.wadj='spacing'
  2968. break
  2969. case'glyph':font.wadj='spacingAndGlyphs'
  2970. break
  2971. default:syntax(1,errs.bad_val,"%%"+xxxfont)
  2972. break}
  2973. p=p.replace(a[0],a[2])}
  2974. a=p.match(/\s+([0-9.]+|\*)$/)
  2975. if(a){if(a[1]!="*")
  2976. font.size=+a[1]
  2977. p=p.replace(a[0],"")}
  2978. if(p[0]=='u'&&p.slice(0,4)=="url("){n=p.indexOf(')',1)
  2979. if(n<0){syntax(1,"No end of url in font family")
  2980. return}
  2981. font.src=p.slice(0,n+1)
  2982. font.fid=abc2svg.font_tb.length
  2983. abc2svg.font_tb.push(font)
  2984. font.name='ft'+font.fid
  2985. p=p.replace(font.src,'')}
  2986. a=p.match(/[- ]?[nN]ormal/)
  2987. if(a){font.normal=true
  2988. p=p.replace(a[0],'')}
  2989. a=p.match(abc2svg.ft_re)
  2990. if(a){font.weight=abc2svg.ft_w[a[0].replace(/[ -]/,'').toLowerCase()]
  2991. p=p.replace(a[0],'')}
  2992. a=p.match(/[- ]?[iI]talic/)
  2993. if(a){font.style="italic"
  2994. p=p.replace(a[0],'')}
  2995. a=p.match(/[- ]?[oO]blique/)
  2996. if(a){font.style="oblique"
  2997. p=p.replace(a[0],'')}
  2998. if(!font.src){if(p[0]=='"'){n=p.indexOf('"',1)
  2999. if(n<0){syntax(1,"No end of string in font family")
  3000. return}
  3001. p=p.slice(1,n)}
  3002. p=p.trim()
  3003. switch(p){case"":case"*":p="";break
  3004. case"Times-Roman":case"Times":p="serif";break
  3005. case"Helvetica":p="sans-serif";break
  3006. case"Courier":p="monospace";break
  3007. case"music":p=cfmt.musicfont.name;break
  3008. default:if(p.indexOf("Fig")>0)
  3009. font.figb=true
  3010. break}}
  3011. if(p&&!font.name)
  3012. font.name=p
  3013. if(font.size)
  3014. set_font_fac(font)
  3015. if(!font.name||!font.size){ft2=cfmt[xxxfont]
  3016. for(k in ft2){if(!ft2.hasOwnProperty(k)||font[k]!=undefined)
  3017. continue
  3018. switch(k){case"fid":case"used":break
  3019. case"style":case"weight":if(font.normal)
  3020. break
  3021. default:font[k]=ft2[k]
  3022. break}}
  3023. if(!font.swfac)
  3024. set_font_fac(font)}
  3025. if(font.pad==undefined)
  3026. font.pad=0
  3027. font.fname=font.name
  3028. if(font.weight>=700)
  3029. font.fname+='Bold'
  3030. cfmt[xxxfont]=font}
  3031. function get_unit(param){var v=param.toLowerCase().match(/(-?[\d.]+)(.*)/)
  3032. if(!v)
  3033. return NaN
  3034. v[1]=+v[1]
  3035. switch(v[2]){case"cm":return v[1]*CM
  3036. case"in":return v[1]*IN
  3037. case"pt":return v[1]*.75
  3038. case"px":case"":return v[1]}
  3039. return NaN}
  3040. function set_infoname(param){var tmp=cfmt.infoname.split("\n"),letter=param[0]
  3041. for(var i=0;i<tmp.length;i++){var infoname=tmp[i]
  3042. if(infoname[0]!=letter)
  3043. continue
  3044. if(param.length==1)
  3045. tmp.splice(i,1)
  3046. else
  3047. tmp[i]=param
  3048. cfmt.infoname=tmp.join('\n')
  3049. return}
  3050. cfmt.infoname+="\n"+param}
  3051. var textopt={align:'j',center:'c',fill:'f',justify:'j',obeylines:'l',ragged:'f',right:'r',skip:'s',"0":'l',"1":'j',"2":'f',"3":'c',"4":'s',"5":'r'}
  3052. function get_textopt(v){var i=v.indexOf(' ')
  3053. if(i>0)
  3054. v=v.slice(0,i)
  3055. return textopt[v]}
  3056. var posval={above:C.SL_ABOVE,auto:0,below:C.SL_BELOW,down:C.SL_BELOW,hidden:C.SL_HIDDEN,opposite:C.SL_HIDDEN,under:C.SL_BELOW,up:C.SL_ABOVE}
  3057. function set_pos(k,v){k=k.slice(0,3)
  3058. if(k=="ste")
  3059. k="stm"
  3060. set_v_param("pos",'"'+k+' '+v+'"')}
  3061. function set_writefields(parm){var c,i,a=parm.split(/\s+/)
  3062. if(get_bool(a[1])){for(i=0;i<a[0].length;i++){c=a[0][i]
  3063. if(cfmt.writefields.indexOf(c)<0)
  3064. cfmt.writefields+=c}}else{for(i=0;i<a[0].length;i++){c=a[0][i]
  3065. if(cfmt.writefields.indexOf(c)>=0)
  3066. cfmt.writefields=cfmt.writefields.replace(c,'')}}}
  3067. function set_v_param(k,v){k=[k+'=',v]
  3068. if(parse.state<3)
  3069. memo_kv_parm(curvoice?curvoice.id:'*',k)
  3070. else if(curvoice)
  3071. set_kv_parm(k)
  3072. else
  3073. memo_kv_parm('*',k)}
  3074. function set_page(){if(!img.chg)
  3075. return
  3076. img.chg=false;img.lm=cfmt.leftmargin-cfmt.printmargin
  3077. if(img.lm<0)
  3078. img.lm=0;img.rm=cfmt.rightmargin-cfmt.printmargin
  3079. if(img.rm<0)
  3080. img.rm=0;img.width=cfmt.pagewidth-2*cfmt.printmargin
  3081. if(img.width-img.lm-img.rm<100){error(0,undefined,"Bad staff width");img.width=img.lm+img.rm+150}
  3082. img.lw=(img.width-img.lm-img.rm
  3083. -2)
  3084. / cfmt.scale
  3085. set_posx()}
  3086. Abc.prototype.set_format=function(cmd,param){var f,f2,v,i
  3087. if(/.+font(-[\d])?$/.test(cmd)){if(cmd=="soundfont")
  3088. cfmt.soundfont=param
  3089. else
  3090. param_set_font(cmd,param)
  3091. return}
  3092. if(sfmt[cmd]&&parse.ufmt)
  3093. cfmt=Object.create(cfmt)
  3094. switch(cmd){case"aligncomposer":case"barsperstaff":case"infoline":case"measurenb":case"rbmax":case"rbmin":case"measrepnb":case"shiftunison":v=parseInt(param)
  3095. if(isNaN(v)){syntax(1,"Bad integer value");break}
  3096. cfmt[cmd]=v
  3097. break
  3098. case"abc-version":case"bgcolor":case"fgcolor":case"propagate-accidentals":case"titleformat":case"writeout-accidentals":cfmt[cmd]=param
  3099. break
  3100. case"beamslope":case"breaklimit":case"lineskipfac":case"maxshrink":case"pagescale":case"parskipfac":case"scale":case"slurheight":case"stemheight":case"tieheight":f=+param
  3101. if(isNaN(f)||!param||f<0){syntax(1,errs.bad_val,'%%'+cmd)
  3102. break}
  3103. switch(cmd){case"scale":f/=.75
  3104. case"pagescale":if(f<.1)
  3105. f=.1
  3106. cmd="scale";img.chg=true
  3107. break}
  3108. cfmt[cmd]=f
  3109. break
  3110. case"annotationbox":case"gchordbox":case"measurebox":case"partsbox":param_set_font(cmd.replace("box","font"),"* * "+(get_bool(param)?"box":"nobox"))
  3111. break
  3112. case"altchord":case"bstemdown":case"breakoneoln":case"cancelkey":case"checkbars":case"contbarnb":case"custos":case"decoerr":case"flatbeams":case"graceslurs":case"graceword":case"hyphencont":case"keywarn":case"linewarn":case"quiet":case"squarebreve":case"splittune":case"straightflags":case"stretchstaff":case"timewarn":case"titlecaps":case"titleleft":cfmt[cmd]=get_bool(param)
  3113. break
  3114. case"dblrepbar":param=":: "+param
  3115. case"bardef":v=param.split(/\s+/)
  3116. if(v.length!=2){syntax(1,errs.bad_val,"%%bardef")}else{if(parse.ufmt)
  3117. cfmt.bardef=Object.create(cfmt.bardef)
  3118. cfmt.bardef[v[0]]=v[1]}
  3119. break
  3120. case"chordalias":v=param.split(/\s+/)
  3121. if(!v.length)
  3122. syntax(1,errs.bad_val,"%%chordalias")
  3123. else
  3124. abc2svg.ch_alias[v[0]]=v[1]||""
  3125. break
  3126. case"composerspace":case"indent":case"infospace":case"maxstaffsep":case"maxsysstaffsep":case"musicspace":case"partsspace":case"staffsep":case"subtitlespace":case"sysstaffsep":case"textspace":case"titlespace":case"topspace":case"vocalspace":case"wordsspace":f=get_unit(param)
  3127. if(isNaN(f))
  3128. syntax(1,errs.bad_val,'%%'+cmd)
  3129. else
  3130. cfmt[cmd]=f
  3131. break
  3132. case"page-format":user.page_format=get_bool(param)
  3133. break
  3134. case"print-leftmargin":syntax(0,"$1 is deprecated - use %%printmargin instead",'%%'+cmd)
  3135. cmd="printmargin"
  3136. case"printmargin":case"leftmargin":case"pagewidth":case"rightmargin":f=get_unit(param)
  3137. if(isNaN(f)){syntax(1,errs.bad_val,'%%'+cmd)
  3138. break}
  3139. cfmt[cmd]=f;img.chg=true
  3140. break
  3141. case"concert-score":if(cfmt.sound!="play")
  3142. cfmt.sound="concert"
  3143. break
  3144. case"writefields":set_writefields(param)
  3145. break
  3146. case"volume":cmd="dynamic"
  3147. case"dynamic":case"gchord":case"gstemdir":case"ornament":case"stemdir":case"vocal":set_pos(cmd,param)
  3148. break
  3149. case"font":get_font_scale(param)
  3150. break
  3151. case"fullsvg":if(parse.state!=0){syntax(1,errs.not_in_tune,"%%fullsvg")
  3152. break}
  3153. cfmt[cmd]=param
  3154. break
  3155. case"gracespace":v=param.split(/\s+/)
  3156. for(i=0;i<3;i++)
  3157. if(isNaN(+v[i])){syntax(1,errs.bad_val,"%%gracespace")
  3158. break}
  3159. if(parse.ufmt)
  3160. cfmt[cmd]=new Float32Array(3)
  3161. for(i=0;i<3;i++)
  3162. cfmt[cmd][i]=+v[i]
  3163. break
  3164. case"tuplets":v=param.split(/\s+/)
  3165. f=v[3]
  3166. if(f)
  3167. f=posval[f]
  3168. if(f)
  3169. v[3]=f
  3170. if(curvoice)
  3171. curvoice.tup=v
  3172. else
  3173. cfmt[cmd]=v
  3174. break
  3175. case"infoname":set_infoname(param)
  3176. break
  3177. case"notespacingfactor":v=param.match(/([.\d]+)[,\s]*(\d+)?/)
  3178. if(v){f=+v[1]
  3179. if(isNaN(f)||f<1||f>2){f=0}else if(v[2]){f2=+v[2]
  3180. if(isNaN(f))
  3181. f=0}else{f2=cfmt.spatab[5]}}
  3182. if(!f){syntax(1,errs.bad_val,"%%"+cmd)
  3183. break}
  3184. cfmt[cmd]=param
  3185. cfmt.spatab=new Float32Array(10)
  3186. i=5;do{cfmt.spatab[i]=f2
  3187. f2/=f}while(--i>=0)
  3188. i=5;f2=cfmt.spatab[i]
  3189. for(;++i<cfmt.spatab.length;){f2*=f;cfmt.spatab[i]=f2}
  3190. break
  3191. case"play":cfmt.sound="play"
  3192. break
  3193. case"pos":cmd=param.match(/(\w*)\s+(.*)/)
  3194. if(!cmd||!cmd[2]){syntax(1,"Error in %%pos")
  3195. break}
  3196. if(cmd[1].slice(0,3)=='tup'&&curvoice){if(!curvoice.tup)
  3197. curvoice.tup=cfmt.tuplets
  3198. else
  3199. curvoice.tup=Object.create(curvoice.tup)
  3200. v=posval[cmd[2]]
  3201. switch(v){case C.SL_ABOVE:curvoice.tup[3]=1
  3202. break
  3203. case C.SL_BELOW:curvoice.tup[3]=2
  3204. break
  3205. case C.SL_HIDDEN:curvoice.tup[2]=1
  3206. break}
  3207. break}
  3208. if(cmd[1].slice(0,3)=="vol")
  3209. cmd[1]="dyn"
  3210. set_pos(cmd[1],cmd[2])
  3211. break
  3212. case"sounding-score":if(cfmt.sound!="play")
  3213. cfmt.sound="sounding"
  3214. break
  3215. case"staffwidth":v=get_unit(param)
  3216. if(isNaN(v)){syntax(1,errs.bad_val,'%%'+cmd)
  3217. break}
  3218. if(v<100){syntax(1,"%%staffwidth too small")
  3219. break}
  3220. v=cfmt.pagewidth-v-cfmt.leftmargin
  3221. if(v<2){syntax(1,"%%staffwidth too big")
  3222. break}
  3223. cfmt.rightmargin=v;img.chg=true
  3224. break
  3225. case"textoption":cfmt[cmd]=get_textopt(param)
  3226. break
  3227. case"dynalign":case"singleline":case"stretchlast":case"titletrim":v=+param
  3228. if(isNaN(v))
  3229. v=get_bool(param)?0:1
  3230. if(cmd[1]=='t'){if(v<0||v>1){syntax(1,errs.bad_val,'%%'+cmd)
  3231. break}}
  3232. cfmt[cmd]=v
  3233. break
  3234. case"combinevoices":syntax(1,"%%combinevoices is deprecated - use %%voicecombine instead")
  3235. break
  3236. case"voicemap":set_v_param("map",param)
  3237. break
  3238. case"voicescale":set_v_param("scale",param)
  3239. break
  3240. case"rbdbstop":v=get_bool(param)
  3241. if(v&&cfmt["abc-version"]>="2.2")
  3242. cfmt["abc-version"]="1"
  3243. else if(!v&&cfmt["abc-version"]<"2.2")
  3244. cfmt["abc-version"]="2.2"
  3245. break
  3246. default:if(!parse.state)
  3247. cfmt[cmd]=param
  3248. break}
  3249. if(sfmt[cmd]&&parse.ufmt){parse.ufmt=false}}
  3250. function st_font(font){var n=font.name,r=""
  3251. if(font.weight)
  3252. r+=font.weight+" "
  3253. if(font.style)
  3254. r+=font.style+" "
  3255. if(n.indexOf('"')<0&&n.indexOf(' ')>0)
  3256. n='"'+n+'"'
  3257. return r+font.size.toFixed(1)+'px '+n}
  3258. function style_font(font){return'font:'+st_font(font)}
  3259. Abc.prototype.style_font=style_font
  3260. function font_class(font){var f='f'+font.fid+cfmt.fullsvg
  3261. if(font.class)
  3262. f+=' '+font.class
  3263. if(font.box)
  3264. f+=' '+'box'
  3265. return f}
  3266. function use_font(font){if(!font.used){font.used=true;if(font.fid==undefined){font.fid=abc2svg.font_tb.length
  3267. abc2svg.font_tb.push(font)
  3268. if(!font.swfac)
  3269. set_font_fac(font)
  3270. if(!font.pad)
  3271. font.pad=0}
  3272. add_fstyle(".f"+font.fid+
  3273. (cfmt.fullsvg||"")+"{"+style_font(font)+"}")
  3274. if(font.src)
  3275. add_fstyle("@font-face{\n\
  3276. font-family:"+font.name+";\n\
  3277. src:"+font.src+"}")
  3278. if(font==cfmt.musicfont)
  3279. add_fstyle(".f"+font.fid
  3280. +(cfmt.fullsvg||"")
  3281. +' text,tspan{white-space:pre}')}}
  3282. function get_font(fn){var font,font2,fid,st
  3283. fn+="font"
  3284. font=cfmt[fn]
  3285. if(!font){syntax(1,"Unknown font $1",fn)
  3286. return gene.curfont}
  3287. if(!font.name||!font.size){font2=Object.create(gene.deffont)
  3288. if(font.name)
  3289. font2.name=font.name
  3290. if(font.normal){if(font2.weight)
  3291. font2.weight=null
  3292. if(font2.style)
  3293. font2.style=null}else{if(font.weight)
  3294. font2.weight=font.weight
  3295. if(font.style)
  3296. font2.style=font.style}
  3297. if(font.src)
  3298. font2.src=font.src
  3299. if(font.size)
  3300. font2.size=font.size
  3301. st=st_font(font2)
  3302. if(font.class){font2.class=font.class
  3303. st+=' '+font.class}
  3304. fid=abc2svg.font_st[st]
  3305. if(fid!=undefined)
  3306. return abc2svg.font_tb[fid]
  3307. abc2svg.font_st[st]=abc2svg.font_tb.length
  3308. font2.fid=font2.used=undefined
  3309. font=font2}
  3310. use_font(font)
  3311. return font}
  3312. var sav={},mac={},maci={},modone={}
  3313. var abc_utf={"=D":"Đ","=H":"Ħ","=T":"Ŧ","=d":"đ","=h":"ħ","=t":"ŧ","/O":"Ø","/o":"ø","/L":"Ł","/l":"ł","vL":"Ľ","vl":"ľ","vd":"ď",".i":"ı","AA":"Å","aa":"å","AE":"Æ","ae":"æ","DH":"Ð","dh":"ð","OE":"Œ","oe":"œ","ss":"ß","TH":"Þ","th":"þ"}
  3314. var oct_acc={"1":"\u266f","2":"\u266d","3":"\u266e","4":"&#x1d12a;","5":"&#x1d12b;"}
  3315. function cnv_escape(src,flag){var c,c2,dst="",i,j=0
  3316. while(1){i=src.indexOf('\\',j)
  3317. if(i<0)
  3318. break
  3319. dst+=src.slice(j,i);c=src[++i]
  3320. if(!c)
  3321. return dst+'\\'
  3322. switch(c){case'0':case'2':if(src[i+1]!='0')
  3323. break
  3324. c2=oct_acc[src[i+2]]
  3325. if(c2){dst+=c2;j=i+3
  3326. continue}
  3327. break
  3328. case'u':j=Number("0x"+src.slice(i+1,i+5));if(isNaN(j)||j<0x20){dst+=src[++i]+"\u0306"
  3329. j=i+1
  3330. continue}
  3331. c=String.fromCharCode(j)
  3332. if(c=='\\'){i+=4
  3333. break}
  3334. dst+=c
  3335. j=i+5
  3336. continue
  3337. case't':dst+='\t';j=i+1
  3338. continue
  3339. case'n':dst+='\n';j=i+1
  3340. continue
  3341. default:c2=abc_utf[src.slice(i,i+2)]
  3342. if(c2){dst+=c2;j=i+2
  3343. continue}
  3344. c2=src[i+1]
  3345. if(!c2)
  3346. break
  3347. if(!/[A-Za-z]/.test(c2))
  3348. break
  3349. switch(c){case'`':dst+=c2+"\u0300"
  3350. j=i+2
  3351. continue
  3352. case"'":dst+=c2+"\u0301"
  3353. j=i+2
  3354. continue
  3355. case'^':dst+=c2+"\u0302"
  3356. j=i+2
  3357. continue
  3358. case'~':dst+=c2+"\u0303"
  3359. j=i+2
  3360. continue
  3361. case'=':dst+=c2+"\u0304"
  3362. j=i+2
  3363. continue
  3364. case'_':dst+=c2+"\u0305"
  3365. j=i+2
  3366. continue
  3367. case'.':dst+=c2+"\u0307"
  3368. j=i+2
  3369. continue
  3370. case'"':dst+=c2+"\u0308"
  3371. j=i+2
  3372. continue
  3373. case'o':dst+=c2+"\u030a"
  3374. j=i+2
  3375. continue
  3376. case'H':dst+=c2+"\u030b"
  3377. j=i+2
  3378. continue
  3379. case'v':dst+=c2+"\u030c"
  3380. j=i+2
  3381. continue
  3382. case'c':dst+=c2+"\u0327"
  3383. j=i+2
  3384. continue
  3385. case';':dst+=c2+"\u0328"
  3386. j=i+2
  3387. continue}
  3388. break}
  3389. if(flag=='w')
  3390. dst+='\\'
  3391. dst+=c
  3392. j=i+1}
  3393. return dst+src.slice(j)}
  3394. var include=0
  3395. function do_include(fn){var file,parse_sav
  3396. if(!user.read_file){syntax(1,"No read_file support")
  3397. return}
  3398. if(include>2){syntax(1,"Too many include levels")
  3399. return}
  3400. file=user.read_file(fn)
  3401. if(!file){syntax(1,"Cannot read file '$1'",fn)
  3402. return}
  3403. include++;parse_sav=clone(parse);tosvg(fn,file);parse_sav.state=parse.state;parse=parse_sav;include--}
  3404. function tosvg(in_fname,file,bol,eof){var i,c,eol,end,select,line0,line1,last_info,opt,text,a,b,s,pscom,txt_add='\n'
  3405. function tune_selected(){var re,res,i=file.indexOf('K:',bol)
  3406. if(i<0){return false}
  3407. i=file.indexOf('\n',i)
  3408. if(parse.select.test(file.slice(parse.bol,i)))
  3409. return true
  3410. re=/\n\w*\n/;re.lastIndex=i;res=re.exec(file)
  3411. if(res)
  3412. eol=re.lastIndex
  3413. else
  3414. eol=eof
  3415. return false}
  3416. function uncomment(src,flag){if(!src)
  3417. return src
  3418. var i=src.indexOf('%')
  3419. if(i==0)
  3420. return''
  3421. if(i>0)
  3422. src=src.replace(/([^\\])%.*/,'$1').replace(/\\%/g,'%');src=src.replace(/\s+$/,'')
  3423. if(flag&&src.indexOf('\\')>=0)
  3424. return cnv_escape(src,flag)
  3425. return src}
  3426. function end_tune(){generate()
  3427. cfmt=sav.cfmt;info=sav.info;char_tb=sav.char_tb;glovar=sav.glovar;maps=sav.maps;mac=sav.mac;maci=sav.maci;parse.tune_v_opts=null;parse.scores=null;parse.ufmt=false
  3428. delete parse.ctrl
  3429. init_tune()
  3430. img.chg=true;set_page()}
  3431. function do_voice(select,in_tune){var opt,bol
  3432. if(select=="end")
  3433. return
  3434. if(in_tune){if(!parse.tune_v_opts)
  3435. parse.tune_v_opts={};opt=parse.tune_v_opts}else{if(!parse.voice_opts)
  3436. parse.voice_opts={};opt=parse.voice_opts}
  3437. opt[select]=[]
  3438. while(1){bol=++eol
  3439. if(file[bol]!='%')
  3440. break
  3441. eol=file.indexOf('\n',eol);if(file[bol+1]!=line1)
  3442. continue
  3443. bol+=2
  3444. if(eol<0)
  3445. text=file.slice(bol)
  3446. else
  3447. text=file.slice(bol,eol);a=text.match(/\S+/)
  3448. switch(a[0]){default:opt[select].push(uncomment(text,true))
  3449. continue
  3450. case"score":case"staves":case"tune":case"voice":bol-=2
  3451. break}
  3452. break}
  3453. eol=parse.eol=bol-1}
  3454. function tune_filter(){var o,opts,j,pc,h,i=file.indexOf('K:',bol)
  3455. i=file.indexOf('\n',i);h=file.slice(parse.bol,i)
  3456. for(i in parse.tune_opts){if(!parse.tune_opts.hasOwnProperty(i))
  3457. continue
  3458. if(!(new RegExp(i)).test(h))
  3459. continue
  3460. opts=parse.tune_opts[i]
  3461. for(j=0;j<opts.t_opts.length;j++){pc=opts.t_opts[j]
  3462. switch(pc.match(/\S+/)[0]){case"score":case"staves":if(!parse.scores)
  3463. parse.scores=[];parse.scores.push(pc)
  3464. break
  3465. default:self.do_pscom(pc)
  3466. break}}
  3467. opts=opts.v_opts
  3468. if(!opts)
  3469. continue
  3470. for(j in opts){if(!opts.hasOwnProperty(j))
  3471. continue
  3472. if(!parse.tune_v_opts)
  3473. parse.tune_v_opts={};if(!parse.tune_v_opts[j])
  3474. parse.tune_v_opts[j]=opts[j]
  3475. else
  3476. parse.tune_v_opts[j]=parse.tune_v_opts[j].concat(opts[j])}}}
  3477. if(abc2svg.mhooks){for(i in abc2svg.mhooks){if(!modone[i]){modone[i]=1
  3478. abc2svg.mhooks[i](self)}}}
  3479. parse.file=file;parse.fname=in_fname
  3480. if(bol==undefined)
  3481. bol=0
  3482. if(!eof)
  3483. eof=file.length
  3484. if(file.slice(bol,bol+5)=="%abc-")
  3485. cfmt["abc-version"]=/[1-9.]+/.exec(file.slice(bol+5,bol+10))
  3486. for(;bol<eof;bol=parse.eol+1){eol=file.indexOf('\n',bol)
  3487. if(eol<0||eol>eof)
  3488. eol=eof;parse.eol=eol
  3489. while(1){eol--
  3490. switch(file[eol]){case' ':case'\t':continue}
  3491. break}
  3492. eol++
  3493. if(eol==bol){if(parse.state==1){parse.istart=bol;syntax(1,"Empty line in tune header - ignored")}else if(parse.state>=2){end_tune()
  3494. parse.state=0
  3495. if(parse.select){eol=file.indexOf('\nX:',parse.eol)
  3496. if(eol<0)
  3497. eol=eof
  3498. parse.eol=eol}}
  3499. continue}
  3500. parse.istart=parse.bol=bol;parse.iend=eol;parse.line.index=0;line0=file[bol];line1=file[bol+1]
  3501. if((line0=='I'&&line1==':')||line0=='%'){if(line0=='%'&&parse.prefix.indexOf(line1)<0)
  3502. continue
  3503. if(file[bol+2]=='a'&&file[bol+3]=='b'&&file[bol+4]=='c'&&file[bol+5]==' '){bol+=6;line0=file[bol];line1=file[bol+1]}else{pscom=true}}
  3504. if(pscom){pscom=false;bol+=2
  3505. text=file.slice(bol,eol)
  3506. a=text.match(/([^\s]+)\s*(.*)/)
  3507. if(!a||a[1][0]=='%')
  3508. continue
  3509. switch(a[1]){case"abcm2ps":case"ss-pref":parse.prefix=a[2]
  3510. continue
  3511. case"abc-include":do_include(uncomment(a[2]))
  3512. continue}
  3513. if(a[1].slice(0,5)=='begin'){b=a[1].substr(5);end='\n'+line0+line1+"end"+b;i=file.indexOf(end,eol)
  3514. if(i<0){syntax(1,"No $1 after %%$2",end.slice(1),a[1]);parse.eol=eof
  3515. continue}
  3516. self.do_begin_end(b,uncomment(a[2]),file.slice(eol+1,i).replace(/\n%[^%].*$/gm,'').replace(/^%%/gm,''))
  3517. parse.eol=file.indexOf('\n',i+6)
  3518. if(parse.eol<0)
  3519. parse.eol=eof
  3520. continue}
  3521. switch(a[1]){case"select":if(parse.state!=0){syntax(1,errs.not_in_tune,"%%select")
  3522. continue}
  3523. select=uncomment(text.slice(7))
  3524. if(select[0]=='"')
  3525. select=select.slice(1,-1);if(!select){delete parse.select
  3526. continue}
  3527. select=select.replace(/\(/g,'\\(');select=select.replace(/\)/g,'\\)');parse.select=new RegExp(select,'m')
  3528. continue
  3529. case"tune":if(parse.state!=0){syntax(1,errs.not_in_tune,"%%tune")
  3530. continue}
  3531. select=uncomment(a[2])
  3532. if(!select){parse.tune_opts={}
  3533. continue}
  3534. if(select=="end")
  3535. continue
  3536. if(!parse.tune_opts)
  3537. parse.tune_opts={};parse.tune_opts[select]=opt={t_opts:[]};while(1){bol=++eol
  3538. if(file[bol]!='%')
  3539. break
  3540. eol=file.indexOf('\n',eol);if(file[bol+1]!=line1)
  3541. continue
  3542. bol+=2
  3543. if(eol<0)
  3544. text=file.slice(bol)
  3545. else
  3546. text=file.slice(bol,eol);a=text.match(/([^\s]+)\s*(.*)/)
  3547. switch(a[1]){case"tune":break
  3548. case"voice":do_voice(uncomment(a[2],true),true)
  3549. continue
  3550. default:opt.t_opts.push(uncomment(text,true))
  3551. continue}
  3552. break}
  3553. if(parse.tune_v_opts){opt.v_opts=parse.tune_v_opts;parse.tune_v_opts=null}
  3554. parse.eol=bol-1
  3555. continue
  3556. case"voice":if(parse.state!=0){syntax(1,errs.not_in_tune,"%%voice")
  3557. continue}
  3558. select=uncomment(a[2])
  3559. if(!select){parse.voice_opts=null
  3560. continue}
  3561. do_voice(select)
  3562. continue}
  3563. self.do_pscom(uncomment(text,true))
  3564. continue}
  3565. if(line1!=':'||!/[A-Za-z+]/.test(line0)){last_info=undefined;if(parse.state<2)
  3566. continue
  3567. parse.line.buffer=uncomment(file.slice(bol,eol))
  3568. if(parse.line.buffer)
  3569. parse_music_line()
  3570. continue}
  3571. bol+=2
  3572. while(1){switch(file[bol]){case' ':case'\t':bol++
  3573. continue}
  3574. break}
  3575. if(line0=='+'){if(!last_info){syntax(1,"+: without previous info field")
  3576. continue}
  3577. txt_add=' ';line0=last_info}
  3578. text=uncomment(file.slice(bol,eol),line0)
  3579. switch(line0){case'X':if(parse.state!=0){syntax(1,errs.ignored,line0)
  3580. continue}
  3581. if(parse.select&&!tune_selected()){eol=file.indexOf('\nX:',parse.eol)
  3582. if(eol<0)
  3583. eol=eof;parse.eol=eol
  3584. continue}
  3585. sav.cfmt=clone(cfmt);sav.info=clone(info,2)
  3586. sav.char_tb=clone(char_tb);sav.glovar=clone(glovar);sav.maps=clone(maps,1);sav.mac=clone(mac);sav.maci=clone(maci);info.X=text;parse.state=1
  3587. if(user.page_format&&blkdiv<1)
  3588. blkdiv=1
  3589. if(parse.tune_opts)
  3590. tune_filter()
  3591. continue
  3592. case'T':switch(parse.state){case 0:continue
  3593. case 1:case 2:if(info.T==undefined)
  3594. info.T=text
  3595. else
  3596. info.T+="\n"+text
  3597. continue}
  3598. s=new_block("title");s.text=text
  3599. continue
  3600. case'K':switch(parse.state){case 0:continue
  3601. case 1:info.K=text
  3602. break}
  3603. do_info(line0,text)
  3604. continue
  3605. case'W':if(parse.state==0||cfmt.writefields.indexOf(line0)<0)
  3606. break
  3607. if(info.W==undefined)
  3608. info.W=text
  3609. else
  3610. info.W+=txt_add+text
  3611. break
  3612. case'm':if(parse.state>=2){syntax(1,errs.ignored,line0)
  3613. continue}
  3614. a=text.match(/(.*?)[= ]+(.*)/)
  3615. if(!a||!a[2]){syntax(1,errs.bad_val,"m:")
  3616. continue}
  3617. mac[a[1]]=a[2];maci[a[1][0]]=true
  3618. break
  3619. case's':if(parse.state!=3||cfmt.writefields.indexOf(line0)<0)
  3620. break
  3621. get_sym(text,txt_add==' ')
  3622. break
  3623. case'w':if(parse.state!=3||cfmt.writefields.indexOf(line0)<0)
  3624. break
  3625. get_lyrics(text,txt_add==' ')
  3626. break
  3627. case'|':if(parse.state<2)
  3628. continue
  3629. parse.line.buffer=text
  3630. parse_music_line()
  3631. continue
  3632. default:if("ABCDFGHNOSZ".indexOf(line0)>=0){if(parse.state>=2){syntax(1,errs.ignored,line0)
  3633. continue}
  3634. if(!info[line0])
  3635. info[line0]=text
  3636. else
  3637. info[line0]+=txt_add+text
  3638. break}
  3639. do_info(line0,text)
  3640. continue}
  3641. txt_add='\n';last_info=line0}
  3642. if(include)
  3643. return
  3644. if(parse.state>=2)
  3645. end_tune();parse.state=0}
  3646. Abc.prototype.tosvg=tosvg
  3647. var gene,staff_tb,nstaff,tsnext,realwidth,insert_meter,spf_last,smallest_duration
  3648. var dx_tb=new Float32Array([10,10,11,13,15])
  3649. var hw_tb=new Float32Array([4.7,5,6,7.2,7.5])
  3650. var w_note=new Float32Array([3.5,3.7,5,6,7])
  3651. function identify_note(s,dur_o){var head,flags,dots=0,dur=dur_o
  3652. if(dur%12!=0)
  3653. error(1,s,"Invalid note duration $1",dur);dur/=12
  3654. if(!dur)
  3655. error(1,s,"Note too short")
  3656. for(flags=5;dur;dur>>=1,flags--){if(dur&1)
  3657. break}
  3658. dur>>=1
  3659. if((dur+1)&dur){if(s.type!=C.REST||dur_o!=s.p_v.wmeasure)
  3660. error(0,s,"Non standard note duration $1",dur_o)}
  3661. while(dur>>dots>0)
  3662. dots++
  3663. flags-=dots
  3664. if(flags>=0){head=C.FULL}else switch(flags){default:error(1,s,"Note too long")
  3665. flags=-4
  3666. case-4:head=C.SQUARE
  3667. break
  3668. case-3:head=s.fmt.squarebreve?C.SQUARE:C.OVALBARS
  3669. break
  3670. case-2:head=C.OVAL
  3671. break
  3672. case-1:head=C.EMPTY
  3673. break}
  3674. return[head,dots,flags]}
  3675. function set_head_shift(s){var i,i1,i2,d,ps,dx,dx_head=dx_tb[s.head],dir=s.stem,n=s.nhd
  3676. if(!n)
  3677. return
  3678. dx=dx_head*.74
  3679. if(s.grace)
  3680. dx*=.6
  3681. if(dir>=0){i1=1;i2=n+1;ps=s.notes[0].pit}else{dx=-dx;i1=n-1;i2=-1;ps=s.notes[n].pit}
  3682. var shift=false,dx_max=0
  3683. for(i=i1;i!=i2;i+=dir){d=s.notes[i].pit-ps;ps=s.notes[i].pit
  3684. if(!d){if(shift){var new_dx=s.notes[i].shhd=s.notes[i-dir].shhd+dx
  3685. if(dx_max<new_dx)
  3686. dx_max=new_dx
  3687. continue}
  3688. if(i+dir!=i2&&ps+dir==s.notes[i+dir].pit){s.notes[i].shhd=-dx
  3689. if(dx_max<-dx)
  3690. dx_max=-dx
  3691. continue}}
  3692. if(d<0)
  3693. d=-d
  3694. if(d>3||(d>=2&&s.head!=C.SQUARE)){shift=false}else{shift=!shift
  3695. if(shift){s.notes[i].shhd=dx
  3696. if(dx_max<dx)
  3697. dx_max=dx}}}
  3698. s.xmx=dx_max}
  3699. function acc_shift(notes,dx_head){var i,i1,i2,dx,dx1,dx2,ps,p1,acc,n=notes.length
  3700. for(i=n-1;--i>=0;){dx=notes[i].shhd
  3701. if(!dx||dx>0)
  3702. continue
  3703. dx=dx_head-dx;ps=notes[i].pit
  3704. for(i1=n;--i1>=0;){if(!notes[i1].acc)
  3705. continue
  3706. p1=notes[i1].pit
  3707. if(p1<ps-3)
  3708. break
  3709. if(p1>ps+3)
  3710. continue
  3711. if(notes[i1].shac<dx)
  3712. notes[i1].shac=dx}}
  3713. for(i1=n;--i1>=0;){if(notes[i1].acc){p1=notes[i1].pit
  3714. dx1=notes[i1].shac
  3715. if(!dx1){dx1=notes[i1].shhd
  3716. if(dx1<0)
  3717. dx1=dx_head-dx1
  3718. else
  3719. dx1=dx_head}
  3720. break}}
  3721. if(i1<0)
  3722. return
  3723. for(i2=0;i2<i1;i2++){if(notes[i2].acc){ps=notes[i2].pit
  3724. dx2=notes[i2].shac
  3725. if(!dx2){dx2=notes[i2].shhd
  3726. if(dx2<0)
  3727. dx2=dx_head-dx2
  3728. else
  3729. dx2=dx_head}
  3730. break}}
  3731. if(i1==i2){notes[i1].shac=dx1
  3732. return}
  3733. if(p1>ps+4){if(dx1>dx2)
  3734. dx2=dx1
  3735. notes[i1].shac=notes[i2].shac=dx2}else{notes[i1].shac=dx1
  3736. if(notes[i1].pit!=notes[i2].pit)
  3737. dx1+=7
  3738. notes[i2].shac=dx2=dx1}
  3739. dx2+=7
  3740. for(i=i1;--i>i2;){acc=notes[i].acc
  3741. if(!acc)
  3742. continue
  3743. dx=notes[i].shac
  3744. if(dx<dx2)
  3745. dx=dx2
  3746. ps=notes[i].pit
  3747. for(i1=n;--i1>i;){if(!notes[i1].acc)
  3748. continue
  3749. p1=notes[i1].pit
  3750. if(p1>=ps+4){if(p1>ps+4||acc<0||notes[i1].acc<0)
  3751. continue}
  3752. if(dx>notes[i1].shac-6){dx1=notes[i1].shac+7
  3753. if(dx1>dx)
  3754. dx=dx1}}
  3755. notes[i].shac=dx}}
  3756. function set_acc_shft(){var s,s2,st,i,acc,st,t,dx_head,notes
  3757. s=tsfirst
  3758. while(s){if(s.type!=C.NOTE||s.invis){s=s.ts_next
  3759. continue}
  3760. st=s.st;t=s.time;acc=false
  3761. for(s2=s;s2;s2=s2.ts_next){if(s2.time!=t||s2.type!=C.NOTE||s2.st!=st)
  3762. break
  3763. if(acc)
  3764. continue
  3765. for(i=0;i<=s2.nhd;i++){if(s2.notes[i].acc){acc=true
  3766. break}}}
  3767. if(!acc){s=s2
  3768. continue}
  3769. dx_head=dx_tb[s.head]
  3770. notes=[]
  3771. for(;s!=s2;s=s.ts_next){if(!s.invis)
  3772. Array.prototype.push.apply(notes,s.notes)}
  3773. notes.sort(abc2svg.pitcmp)
  3774. acc_shift(notes,dx_head)}}
  3775. function lkvsym(s,next){s.next=next;s.prev=next.prev
  3776. if(s.prev)
  3777. s.prev.next=s
  3778. else
  3779. s.p_v.sym=s;next.prev=s}
  3780. function lktsym(s,next){var old_wl
  3781. s.ts_next=next
  3782. if(next){s.ts_prev=next.ts_prev
  3783. if(s.ts_prev)
  3784. s.ts_prev.ts_next=s;next.ts_prev=s}else{error(2,s,"Bad linkage")
  3785. s.ts_prev=null}
  3786. s.seqst=!s.ts_prev||s.time!=s.ts_prev.time||(w_tb[s.ts_prev.type]!=w_tb[s.type]&&!!w_tb[s.ts_prev.type])
  3787. if(!next||next.seqst)
  3788. return
  3789. next.seqst=next.time!=s.time||(w_tb[s.type]!=w_tb[next.type]&&!!w_tb[s.type])
  3790. if(next.seqst){old_wl=next.wl
  3791. self.set_width(next)
  3792. if(next.a_ly)
  3793. ly_set(next)
  3794. if(!next.shrink){next.shrink=next.wl
  3795. if(next.prev)
  3796. next.shrink+=next.prev.wr}else{next.shrink+=next.wl-old_wl}
  3797. next.space=0}}
  3798. function unlksym(s){if(s.next)
  3799. s.next.prev=s.prev
  3800. if(s.prev)
  3801. s.prev.next=s.next
  3802. else
  3803. s.p_v.sym=s.next
  3804. if(s.ts_next){if(s.seqst){if(s.ts_next.seqst){s.ts_next.shrink+=s.shrink;s.ts_next.space+=s.space}else{s.ts_next.seqst=true;s.ts_next.shrink=s.shrink;s.ts_next.space=s.space}}else{if(s.ts_next.seqst&&s.ts_prev&&s.ts_prev.seqst&&!w_tb[s.ts_prev.type]){s.ts_next.seqst=false
  3805. s.shrink=s.ts_next.shrink
  3806. s.space=s.ts_next.space}}
  3807. s.ts_next.ts_prev=s.ts_prev}
  3808. if(s.ts_prev)
  3809. s.ts_prev.ts_next=s.ts_next
  3810. if(tsfirst==s)
  3811. tsfirst=s.ts_next
  3812. if(tsnext==s)
  3813. tsnext=s.ts_next}
  3814. function insert_clef(s,clef_type,clef_line){var p_voice=s.p_v,new_s,st=s.st
  3815. if(s.type==C.BAR&&s.prev&&s.prev.type==C.BAR&&s.prev.bar_type[0]!=':')
  3816. s=s.prev;p_voice.last_sym=s.prev
  3817. if(!p_voice.last_sym)
  3818. p_voice.sym=null;p_voice.time=s.time;new_s=sym_add(p_voice,C.CLEF);new_s.next=s;s.prev=new_s;new_s.clef_type=clef_type;new_s.clef_line=clef_line;new_s.st=st;new_s.clef_small=true
  3819. delete new_s.second;new_s.notes=[]
  3820. new_s.notes[0]={pit:s.notes[0].pit}
  3821. new_s.nhd=0;while(!s.seqst)
  3822. s=s.ts_prev;lktsym(new_s,s)
  3823. if(s.soln){new_s.soln=true
  3824. delete s.soln}
  3825. return new_s}
  3826. function set_float(){var p_voice,st,staff_chg,v,s,s1,up,down
  3827. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v]
  3828. staff_chg=false;st=p_voice.st
  3829. for(s=p_voice.sym;s;s=s.next){if(!s.floating){while(s&&!s.floating)
  3830. s=s.next
  3831. if(!s)
  3832. break
  3833. staff_chg=false}
  3834. if(!s.dur){if(staff_chg)
  3835. s.st++
  3836. continue}
  3837. if(s.notes[0].pit>=19){staff_chg=false
  3838. continue}
  3839. if(s.notes[s.nhd].pit<=12){staff_chg=true
  3840. s.st++
  3841. continue}
  3842. up=127
  3843. for(s1=s.ts_prev;s1;s1=s1.ts_prev){if(s1.st!=st||s1.v==s.v)
  3844. break
  3845. if(s1.type==C.NOTE)
  3846. if(s1.notes[0].pit<up)
  3847. up=s1.notes[0].pit}
  3848. if(up==127){if(staff_chg)
  3849. s.st++
  3850. continue}
  3851. if(s.notes[s.nhd].pit>up-3){staff_chg=false
  3852. continue}
  3853. down=-127
  3854. for(s1=s.ts_next;s1;s1=s1.ts_next){if(s1.st!=st+1||s1.v==s.v)
  3855. break
  3856. if(s1.type==C.NOTE)
  3857. if(s1.notes[s1.nhd].pit>down)
  3858. down=s1.notes[s1.nhd].pit}
  3859. if(down==-127){if(staff_chg)
  3860. s.st++
  3861. continue}
  3862. if(s.notes[0].pit<down+3){staff_chg=true
  3863. s.st++
  3864. continue}
  3865. up-=s.notes[s.nhd].pit
  3866. down=s.notes[0].pit-down
  3867. if(!staff_chg){if(up<down+3)
  3868. continue
  3869. staff_chg=true}else{if(up<down-3){staff_chg=false
  3870. continue}}
  3871. s.st++}}}
  3872. function set_graceoffs(s){var next,m,dx,x,gspleft=s.fmt.gracespace[0],gspinside=s.fmt.gracespace[1],gspright=s.fmt.gracespace[2],g=s.extra;if(s.prev&&s.prev.type==C.BAR)
  3873. gspleft-=3;x=gspleft;g.beam_st=true
  3874. for(;;g=g.next){set_head_shift(g)
  3875. acc_shift(g.notes,6.5)
  3876. dx=0
  3877. for(m=g.nhd;m>=0;m--){if(g.notes[m].shac-2>dx)
  3878. dx=g.notes[m].shac-2}
  3879. x+=dx;g.x=x
  3880. if(g.nflags<=0)
  3881. g.beam_st=g.beam_end=true
  3882. next=g.next
  3883. if(!next){g.beam_end=true
  3884. break}
  3885. if(next.nflags<=0)
  3886. g.beam_end=true
  3887. if(g.beam_end){next.beam_st=true;x+=gspinside/4}
  3888. if(g.nflags<=0)
  3889. x+=gspinside/4
  3890. if(g.y>next.y+8)
  3891. x-=1.5
  3892. x+=gspinside}
  3893. next=s.next
  3894. if(next&&next.type==C.NOTE){if(g.y>=3*(next.notes[next.nhd].pit-18))
  3895. gspright-=1
  3896. else if(g.beam_st&&g.y<3*(next.notes[next.nhd].pit-18)-4)
  3897. gspright+=2}
  3898. x+=gspright;return x}
  3899. function set_w_chs(s){var i,ch,w0,s0,dw,x=0,n=0
  3900. set_font("vocal")
  3901. for(;s;s=s.ts_next){if(s.shrink){x+=s.shrink;n++}
  3902. if(s.a_ly)
  3903. ly_set(s)
  3904. if(!s.a_gch)
  3905. continue
  3906. for(i=0;i<s.a_gch.length;i++){ch=s.a_gch[i]
  3907. if(ch.type!='g'||ch.y<0)
  3908. continue
  3909. if(w0){if(w0>x+ch.x){if(s.prev&&s.prev.seqst&&s.prev.type==C.BAR)
  3910. n--
  3911. dw=(w0-x-ch.x)/n
  3912. while(1){s0=s0.ts_next
  3913. if(s0.shrink)
  3914. s0.shrink+=dw
  3915. if(s0==s||s0.type==C.BAR)
  3916. break}}}
  3917. s0=s;w0=ch.text.wh[0];n=0;x=0
  3918. break}}}
  3919. function gchord_width(s,wlnote,wlw){var gch,w,ix,arspc=0
  3920. for(ix=0;ix<s.a_gch.length;ix++){gch=s.a_gch[ix]
  3921. switch(gch.type){case'<':w=gch.text.wh[0]+wlnote
  3922. if(w>wlw)
  3923. wlw=w
  3924. break
  3925. case'>':w=gch.text.wh[0]+s.wr
  3926. if(w>arspc)
  3927. arspc=w
  3928. break}}
  3929. if(s.wr<arspc)
  3930. s.wr=arspc
  3931. return wlw}
  3932. Abc.prototype.set_width=function(s){var s2,i,m,xx,w,wlnote,wlw,acc,nt,bar_type,meter,last_acc,n1,n2,esp,tmp
  3933. if(s.play){s.wl=s.wr=0
  3934. return}
  3935. switch(s.type){case C.NOTE:case C.REST:s.wr=wlnote=s.invis?0:hw_tb[s.head]
  3936. if(s.xmx>0)
  3937. s.wr+=s.xmx+4;for(s2=s.prev;s2;s2=s2.prev){if(w_tb[s2.type])
  3938. break}
  3939. if(s2){switch(s2.type){case C.BAR:case C.CLEF:case C.KEY:case C.METER:wlnote+=3
  3940. break
  3941. case C.STBRK:wlnote+=8
  3942. break}}
  3943. for(m=0;m<=s.nhd;m++){nt=s.notes[m]
  3944. xx=nt.shhd
  3945. if(xx<0){if(wlnote<-xx+5)
  3946. wlnote=-xx+5}
  3947. acc=nt.acc
  3948. if(acc){tmp=nt.shac+
  3949. (typeof acc=="object"?5.5:3.5)
  3950. if(wlnote<tmp)
  3951. wlnote=tmp}
  3952. if(nt.a_dd)
  3953. wlnote+=deco_wch(nt)}
  3954. if(s2){switch(s2.type){case C.BAR:case C.CLEF:case C.KEY:case C.METER:wlnote-=3
  3955. break}}
  3956. if(s.a_dd)
  3957. wlnote=deco_width(s,wlnote)
  3958. if(s.beam_st&&s.beam_end&&s.stem>0&&s.nflags>0){if(s.wr<s.xmx+9)
  3959. s.wr=s.xmx+9}
  3960. if(s.dots){if(s.wl==undefined)
  3961. switch(s.head){case C.SQUARE:case C.OVALBARS:s.xmx+=3
  3962. break
  3963. case C.OVAL:s.xmx+=1
  3964. break}
  3965. if(s.wr<s.xmx+8)
  3966. s.wr=s.xmx+8
  3967. if(s.dots>=2)
  3968. s.wr+=3.5*(s.dots-1)}
  3969. if(s.trem2&&s.beam_end&&wlnote<20)
  3970. wlnote=20
  3971. wlw=wlnote
  3972. if(s2){switch(s2.type){case C.NOTE:if(s2.stem>0&&s.stem<0){if(wlw<7)
  3973. wlw=7}
  3974. if((s.y>27&&s2.y>27)||(s.y<-3&&s2.y<-3)){if(wlw<6)
  3975. wlw=6}
  3976. if(s2.tie){if(wlw<14)
  3977. wlw=14}
  3978. break
  3979. case C.CLEF:if(s2.second||s2.clef_small)
  3980. break
  3981. case C.KEY:if(s.a_gch)
  3982. wlw+=4
  3983. case C.METER:wlw+=3
  3984. break}}
  3985. if(s.a_gch)
  3986. wlw=gchord_width(s,wlnote,wlw)
  3987. if(s.prev&&s.prev.type==C.GRACE){s.prev.wl+=wlnote-4.5
  3988. s.wl=s.prev.wl}else{s.wl=wlw}
  3989. return
  3990. case C.SPACE:xx=s.width/2;s.wr=xx
  3991. if(s.a_gch)
  3992. xx=gchord_width(s,xx,xx)
  3993. if(s.a_dd)
  3994. xx=deco_width(s,xx)
  3995. s.wl=xx
  3996. return
  3997. case C.BAR:bar_type=s.bar_type
  3998. switch(bar_type){case"|":w=5
  3999. break
  4000. case"[":w=0
  4001. break
  4002. default:w=2+2.8*bar_type.length
  4003. for(i=0;i<bar_type.length;i++){switch(bar_type[i]){case"[":case"]":w+=1
  4004. case":":w+=2
  4005. break}}
  4006. break}
  4007. s.wl=w
  4008. if(s.next&&s.next.type!=C.METER)
  4009. s.wr=7
  4010. else
  4011. s.wr=5
  4012. if(s.invis)
  4013. s.wl=s.wr=2
  4014. s2=s.prev
  4015. if(s2&&s2.type==C.GRACE)
  4016. s.wl-=6
  4017. for(;s2;s2=s2.prev){if(w_tb[s2.type]){if(s2.type==C.STBRK)
  4018. s.wl-=12
  4019. break}}
  4020. if(s.a_dd)
  4021. s.wl=deco_width(s,s.wl)
  4022. if(s.text&&s.text.length<4&&s.next&&s.next.a_gch){set_font("repeat");s.wr+=strwh(s.text)[0]+2
  4023. if(cfmt.measurenb>0&s.bar_num&&s.bar_num%cfmt.measurenb)
  4024. s.wr+=4}
  4025. return
  4026. case C.CLEF:if(s.invis){s.wl=s.wr=1
  4027. return}
  4028. if(s.prev&&s.prev.type==C.STBRK){s.wl=6
  4029. s.wr=13
  4030. delete s.clef_small
  4031. return}
  4032. s.wl=s.clef_small?11:12
  4033. s.wr=s.clef_small?8:13
  4034. return
  4035. case C.KEY:if(s.invis){s.wl=s.wr=0
  4036. return}
  4037. s.wl=0
  4038. esp=3
  4039. n1=s.k_sf
  4040. if(s.k_old_sf&&(s.fmt.cancelkey||n1==0))
  4041. n2=s.k_old_sf
  4042. else
  4043. n2=0
  4044. if(n1*n2>=0){if(n1<0)
  4045. n1=-n1
  4046. if(n2<0)
  4047. n2=-n2
  4048. if(n2>n1)
  4049. n1=n2}else{n1-=n2
  4050. if(n1<0)
  4051. n1=-n1;esp+=3}
  4052. if(s.k_bagpipe=='p')
  4053. n1++
  4054. if(s.k_a_acc){n2=s.k_a_acc.length
  4055. if(s.exp)
  4056. n1=n2
  4057. else
  4058. n1+=n2
  4059. if(n2)
  4060. last_acc=s.k_a_acc[0].acc
  4061. for(i=1;i<n2;i++){acc=s.k_a_acc[i]
  4062. if(acc.pit>s.k_a_acc[i-1].pit+6||acc.pit<s.k_a_acc[i-1].pit-6)
  4063. n1--
  4064. else if(acc.acc!=last_acc)
  4065. esp+=3;last_acc=acc.acc}}
  4066. if(!n1)
  4067. break
  4068. s.wr=5.5*n1+esp
  4069. if(s.prev&&!s.prev.bar_type)
  4070. s.wl+=2
  4071. return
  4072. case C.METER:s.x_meter=[]
  4073. if(!s.a_meter.length)
  4074. break
  4075. wlw=0
  4076. for(i=0;i<s.a_meter.length;i++){meter=s.a_meter[i]
  4077. switch(meter.top[0]){case'C':case'c':case'o':s.x_meter[i]=wlw+6;wlw+=12
  4078. break
  4079. case'.':case'|':s.x_meter[i]=s.x_meter[i-1]
  4080. break
  4081. default:w=0
  4082. if(!meter.bot||meter.top.length>meter.bot.length)
  4083. meter=meter.top
  4084. else
  4085. meter=meter.bot;for(m=0;m<meter.length;m++){switch(meter[m]){case'(':wlw+=4
  4086. case')':case'1':w+=4
  4087. break
  4088. default:w+=12
  4089. break}}
  4090. s.x_meter[i]=wlw+w/2
  4091. wlw+=w}}
  4092. s.wl=1
  4093. s.wr=wlw+7
  4094. return
  4095. case C.MREST:s.wl=6;s.wr=66
  4096. return
  4097. case C.GRACE:if(s.invis)
  4098. break
  4099. s.wl=set_graceoffs(s);s.wr=0
  4100. if(s.a_ly)
  4101. ly_set(s)
  4102. return
  4103. case C.STBRK:s.wl=s.xmx
  4104. s.wr=8
  4105. return
  4106. case C.CUSTOS:s.wl=s.wr=4
  4107. return
  4108. case C.TEMPO:tempo_build(s)
  4109. break
  4110. case C.BLOCK:case C.REMARK:case C.STAVES:break
  4111. default:error(2,s,"set_width - Cannot set width for symbol $1",s.type)
  4112. break}
  4113. s.wl=s.wr=0}
  4114. function time2space(s,len){var i,l,space
  4115. if(smallest_duration>=C.BLEN/2){if(smallest_duration>=C.BLEN)
  4116. len/=4
  4117. else
  4118. len/=2}else if(!s.next&&len>=C.BLEN){len/=2}
  4119. if(len>=C.BLEN/4){if(len<C.BLEN/2)
  4120. i=5
  4121. else if(len<C.BLEN)
  4122. i=6
  4123. else if(len<C.BLEN*2)
  4124. i=7
  4125. else if(len<C.BLEN*4)
  4126. i=8
  4127. else
  4128. i=9}else{if(len>=C.BLEN/8)
  4129. i=4
  4130. else if(len>=C.BLEN/16)
  4131. i=3
  4132. else if(len>=C.BLEN/32)
  4133. i=2
  4134. else if(len>=C.BLEN/64)
  4135. i=1
  4136. else
  4137. i=0}
  4138. l=len-((C.BLEN/16/8)<<i)
  4139. space=cfmt.spatab[i]
  4140. if(l){if(l<0){space=cfmt.spatab[0]*len/(C.BLEN/16/8)}else{if(i>=9)
  4141. i=8
  4142. space+=(cfmt.spatab[i+1]-cfmt.spatab[i])*l/((C.BLEN/16/8)<<i)}}
  4143. return space}
  4144. function set_space(s,ptime){var space,len,s2,stemdir
  4145. len=s.time-ptime
  4146. if(!len){switch(s.type){case C.MREST:return s.wl}
  4147. return 0}
  4148. if(s.ts_prev.type==C.MREST)
  4149. return 71
  4150. space=time2space(s,len)
  4151. while(!s.dur){switch(s.type){case C.BAR:if(!s.next)
  4152. space*=.9
  4153. return space*.9-3
  4154. case C.CLEF:return space-s.wl-s.wr
  4155. case C.BLOCK:case C.REMARK:case C.STAVES:case C.TEMPO:s=s.ts_next
  4156. if(!s)
  4157. return space
  4158. continue}
  4159. break}
  4160. if(s.dur&&len<=C.BLEN/4){s2=s
  4161. while(s2){if(!s2.beam_st){space*=.9
  4162. break}
  4163. s2=s2.ts_next
  4164. if(!s2||s2.seqst)
  4165. break}}
  4166. if(s.type==C.NOTE&&s.nflags>=-1&&s.stem>0){stemdir=true
  4167. for(s2=s.ts_prev;s2&&s2.time==ptime;s2=s2.ts_prev){if(s2.type==C.NOTE&&(s2.nflags<-1||s2.stem>0)){stemdir=false
  4168. break}}
  4169. if(stemdir){for(s2=s.ts_next;s2&&s2.time==s.time;s2=s2.ts_next){if(s2.type==C.NOTE&&(s2.nflags<-1||s2.stem<0)){stemdir=false
  4170. break}}
  4171. if(stemdir)
  4172. space*=.9}}
  4173. return space}
  4174. function set_sp_tup(s,s_et){var tim=s.time,ttim=s_et.time-tim,sp=time2space(s,ttim),s2=s,wsp=0
  4175. while(1){s2=s2.ts_next
  4176. if(s2.seqst){wsp+=s2.space
  4177. if(s2.bar_type)
  4178. wsp+=10}
  4179. if(s2==s_et)
  4180. break}
  4181. sp=(sp+wsp)/2/ttim
  4182. while(1){s=s.ts_next
  4183. if(s.seqst){s.space=sp*(s.time-tim)
  4184. tim=s.time}
  4185. if(s==s_et)
  4186. break}}
  4187. function _bar(s){return{type:C.BAR,bar_type:"|",fname:s.fname,istart:s.istart,iend:s.iend,v:s.v,p_v:s.p_v,st:s.st,dur:0,time:s.time+(s.dur||0),nhd:0,notes:[{pit:s.notes?s.notes[0].pit:22}],seqst:true,invis:true,prev:s,fmt:s.fmt}}
  4188. function add_end_bar(s){var b=_bar(s),sn=s.ts_next
  4189. b.wl=0
  4190. b.wr=0
  4191. b.ts_prev=s
  4192. b.next=s.next
  4193. b.ts_next=s.ts_next
  4194. b.shrink=s.type==C.STBRK?0:(s.wr+3)
  4195. if(s.next)
  4196. s.next.prev=b
  4197. s.ts_next.ts_prev=b
  4198. s.next=s.ts_next=b
  4199. b.space=sn.space*.9-3
  4200. return b}
  4201. function set_allsymwidth(first){var val,st,s_chs,stup,itup,s=tsfirst,s2=s,xa=0,xl=[],wr=[],maxx=xa,tim=s.time
  4202. while(1){itup=0
  4203. do{if((s.a_gch||s.a_ly)&&!s_chs)
  4204. s_chs=s;self.set_width(s);st=s.st
  4205. if(xl[st]==undefined)
  4206. xl[st]=0
  4207. if(wr[st]==undefined)
  4208. wr[st]=0;val=xl[st]+wr[st]+s.wl
  4209. if(val>maxx)
  4210. maxx=val
  4211. if(s.dur&&s.dur!=s.notes[0].dur&&first)
  4212. itup=1
  4213. s=s.ts_next}while(s&&!s.seqst);s2.shrink=maxx-xa
  4214. s2.space=s2.ts_prev?set_space(s2,tim):0
  4215. if(s2.space==0&&s2.ts_prev&&s2.ts_prev.type==C.SPACE&&s2.ts_prev.seqst)
  4216. s2.space=s2.ts_prev.space/=2
  4217. if(itup){if(!stup)
  4218. stup=s2}else if(stup&&stup.v==s2.v){set_sp_tup(stup,s2)
  4219. stup=null}
  4220. if(!s2.shrink){if(s2.type==C.CLEF&&!s2.ts_prev.bar_type){delete s2.seqst;s2.time=tim}else{s2.shrink=10}}
  4221. tim=s2.time
  4222. if(!s)
  4223. break
  4224. s=s2
  4225. do{wr[s.st]=0
  4226. s=s.ts_next}while(!s.seqst)
  4227. xa=maxx
  4228. do{st=s2.st;xl[st]=xa
  4229. if(s2.wr>wr[st])
  4230. wr[st]=s2.wr
  4231. s2=s2.ts_next}while(!s2.seqst)}
  4232. if(stup)
  4233. set_sp_tup(stup,s2)
  4234. if(first&&s_chs)
  4235. set_w_chs(s_chs)}
  4236. function to_rest(so){var s=clone(so)
  4237. s.prev.next=so.ts_prev=so.prev=s.ts_prev.ts_next=s
  4238. s.next=s.ts_next=so
  4239. so.seqst=false
  4240. so.invis=so.play=true
  4241. s.type=C.REST
  4242. delete s.in_tuplet
  4243. delete s.tp
  4244. delete s.a_dd
  4245. delete s.a_gch
  4246. delete s.sls
  4247. return s}
  4248. function set_repeat(s){var s2,s3,i,j,dur,n=s.repeat_n,k=s.repeat_k,st=s.st,v=s.v
  4249. s.repeat_n=0
  4250. if(n<0){n=-n;i=n
  4251. for(s3=s.prev;s3;s3=s3.prev){if(!s3.dur){if(s3.type==C.BAR){error(1,s3,"Bar in repeat sequence")
  4252. return}
  4253. continue}
  4254. if(--i<=0)
  4255. break}
  4256. if(!s3){error(1,s,errs.not_enough_n)
  4257. return}
  4258. dur=s.time-s3.time;i=k*n
  4259. for(s2=s;s2;s2=s2.next){if(!s2.dur){if(s2.type==C.BAR){error(1,s2,"Bar in repeat sequence")
  4260. return}
  4261. continue}
  4262. if(--i<=0)
  4263. break}
  4264. if(!s2||!s2.next){error(1,s,errs.not_enough_n)
  4265. return}
  4266. for(s2=s.prev;s2!=s3;s2=s2.prev){if(s2.type==C.NOTE){s2.beam_end=true
  4267. break}}
  4268. for(j=k;--j>=0;){i=n
  4269. if(s.dur)
  4270. i--;s2=s.ts_next
  4271. while(i>0){if(s2.st==st){s2.invis=s2.play=true
  4272. if(s2.seqst&&s2.ts_next.seqst)
  4273. s2.seqst=false
  4274. if(s2.v==v&&s2.dur)
  4275. i--}
  4276. s2=s2.ts_next}
  4277. s=to_rest(s)
  4278. s.dur=s.notes[0].dur=dur;s.rep_nb=-1;s.beam_st=true;self.set_width(s)
  4279. s.head=C.SQUARE;for(s=s2;s;s=s.ts_next){if(s.st==st&&s.v==v&&s.dur)
  4280. break}}
  4281. return}
  4282. i=n
  4283. for(s2=s.prev.prev;s2;s2=s2.prev){if(s2.type==C.BAR||s2.time==tsfirst.time){if(--i<=0)
  4284. break}}
  4285. if(!s2){error(1,s,errs.not_enough_m)
  4286. return}
  4287. dur=s.time-s2.time
  4288. if(n==1)
  4289. i=k
  4290. else
  4291. i=n
  4292. for(s2=s;s2;s2=s2.next){if(s2.type==C.BAR){if(--i<=0)
  4293. break}}
  4294. if(!s2){error(1,s,errs.not_enough_m)
  4295. return}
  4296. i=k
  4297. if(n==2&&i>1){s2=s2.next
  4298. if(!s2){error(1,s,errs.not_enough_m)
  4299. return}
  4300. s2.repeat_n=n;s2.repeat_k=--i}
  4301. dur/=n
  4302. if(n==2){s3=s
  4303. for(s2=s.ts_next;;s2=s2.ts_next){if(s2.st!=st)
  4304. continue
  4305. if(s2.type==C.BAR){if(s2.v==v)
  4306. break
  4307. continue}
  4308. s2.invis=s2.play=true
  4309. if(s2.seqst&&s2.ts_next.seqst)
  4310. s2.seqst=false}
  4311. s3=to_rest(s3)
  4312. s3.dur=s3.notes[0].dur=dur;s3.invis=true
  4313. s2.bar_mrep=2
  4314. s3=s2.next;for(s2=s3.ts_next;;s2=s2.ts_next){if(s2.st!=st)
  4315. continue
  4316. if(s2.type==C.BAR){if(s2.v==v)
  4317. break
  4318. continue}
  4319. if(!s2.dur)
  4320. continue
  4321. s2.invis=s2.play=true
  4322. if(s2.seqst&&s2.ts_next.seqst)
  4323. s2.seqst=false}
  4324. s3=to_rest(s3)
  4325. s3.dur=s3.notes[0].dur=dur;s3.invis=true;self.set_width(s3)
  4326. return}
  4327. s3=s
  4328. for(j=k;--j>=0;){for(s2=s3.ts_next;;s2=s2.ts_next){if(s2.st!=st)
  4329. continue
  4330. if(s2.type==C.BAR){if(s2.v==v)
  4331. break
  4332. continue}
  4333. if(!s2.dur)
  4334. continue
  4335. s2.invis=s2.play=true
  4336. if(s2.seqst&&s2.ts_next.seqst)
  4337. s2.seqst=false}
  4338. s3=to_rest(s3)
  4339. s3.dur=s3.notes[0].dur=dur;s3.beam_st=true
  4340. if(k==1){s3.rep_nb=1
  4341. break}
  4342. s3.rep_nb=k-j+1;s3=s2.next}}
  4343. function custos_add(s){var p_voice,new_s,i,s2=s
  4344. while(1){if(s2.type==C.NOTE)
  4345. break
  4346. s2=s2.next
  4347. if(!s2)
  4348. return}
  4349. p_voice=s.p_v;p_voice.last_sym=s.prev;p_voice.time=s.time;new_s=sym_add(p_voice,C.CUSTOS);new_s.next=s;s.prev=new_s;new_s.wl=0
  4350. new_s.wr=4
  4351. lktsym(new_s,s);new_s.shrink=s.shrink
  4352. if(new_s.shrink<8+4)
  4353. new_s.shrink=8+4;new_s.space=s2.space;new_s.head=C.FULL
  4354. new_s.stem=s2.stem
  4355. new_s.nhd=s2.nhd;new_s.notes=[]
  4356. for(i=0;i<s2.notes.length;i++){new_s.notes[i]={pit:s2.notes[i].pit,shhd:0,dur:C.BLEN/4}}
  4357. new_s.stemless=true}
  4358. function set_nl(s){var p_voice,done,tim,ptyp
  4359. function bardiv(so){var s,s1,s2,t1,t2,i
  4360. function new_type(s){var t=s.bar_type.match(/(:*)([^:]*)(:*)/)
  4361. if(!t[3]){t1=t[1]+t[2]
  4362. t2='['}else if(!t[1]){t1='||'
  4363. t2='[|'+t[3]}else{i=(t[2].length/2)|0
  4364. t1=t[1]+'|'+t[2].slice(0,i)
  4365. t2=t[2].slice(i)+'|'+t[3]}}
  4366. function eol_bar(s,so,sst){var s1,s2,s3
  4367. for(s1=so.ts_prev;s1.time==s.time;s1=s1.ts_prev){if(s1.v!=s.v)
  4368. continue
  4369. if(s1.bar_type){if(s1.bar_type!='|')
  4370. return
  4371. s2=s1
  4372. break}
  4373. if(!s3)
  4374. s3=s1.next}
  4375. if(!s2){s2=clone(s)
  4376. if(!s3)
  4377. s3=s
  4378. s2.next=s3
  4379. s2.prev=s3.prev
  4380. if(s2.prev)
  4381. s2.prev.next=s2
  4382. s3.prev=s2
  4383. s2.ts_prev=so.ts_prev
  4384. s2.ts_prev.ts_next=s2
  4385. s2.ts_next=so
  4386. so.ts_prev=s2
  4387. if(s==sst)
  4388. s2.seqst=1
  4389. if(s2.seqst){for(s=s2.ts_next;!s.seqst;s=s.ts_next);s2.shrink=s.shrink
  4390. s.shrink=s2.wr+s.wl
  4391. s2.space=s.space
  4392. s.space=0}
  4393. delete s2.part}
  4394. s2.bar_type="||"}
  4395. s=so
  4396. while(s&&s.time==so.time){if(s.bar_type&&s.bar_type.slice(-1)==':'){s2=s
  4397. break}
  4398. s=s.ts_next}
  4399. if(s2){s=s2
  4400. while(1){eol_bar(s2,so,s)
  4401. s2=s2.ts_next
  4402. if(!s2||s2.seqst)
  4403. break}
  4404. return so}
  4405. s=so
  4406. while(s.ts_prev&&s.ts_prev.time==so.time){s=s.ts_prev
  4407. if(s.bar_type)
  4408. s1=s
  4409. else if(!s1&&s.type==C.GRACE&&s.seqst)
  4410. so=s}
  4411. if(!s1||!s1.bar_type||(s1.bar_type.slice(-1)!=':'&&!s1.text))
  4412. return so
  4413. for(so=s1;so.time==s1.time;so=so.ts_prev){switch(so.ts_prev.type){case C.KEY:case C.METER:case C.TEMPO:case C.STAVES:case C.STBRK:continue}
  4414. break}
  4415. s=s1
  4416. while(1){new_type(s1)
  4417. s2=clone(s1)
  4418. s2.bar_type=t1
  4419. s1.bar_type=t2
  4420. s2.ts_prev=so.ts_prev
  4421. s2.ts_prev.ts_next=s2
  4422. s2.ts_next=so
  4423. so.ts_prev=s2
  4424. if(s1==s)
  4425. s2.seqst=1
  4426. s2.next=s1
  4427. if(s2.prev)
  4428. s2.prev.next=s2
  4429. s1.prev=s2
  4430. if(s1.rbstop)
  4431. s2.rbstop=s1.rbstop
  4432. if(s1.text){s1.invis=1
  4433. delete s1.xsh
  4434. delete s2.text
  4435. delete s2.rbstart}
  4436. delete s2.part
  4437. delete s1.a_dd
  4438. do{s1=s1.ts_next}while(!s1.seqst&&!s1.bar_type)
  4439. if(s1.seqst)
  4440. break}
  4441. return so}
  4442. function set_eol(s){if(cfmt.custos&&voice_tb.length==1)
  4443. custos_add(s)
  4444. s.nl=true
  4445. s=s.ts_prev
  4446. if(s.type!=C.BAR)
  4447. add_end_bar(s)}
  4448. function do_warn(s){var s1,s2,s3,s4,w
  4449. for(s2=s;s2&&s2.time==s.time;s2=s2.ts_next){switch(s2.type){case C.KEY:if(!s.fmt.keywarn||s2.invis)
  4450. continue
  4451. for(s1=s.ts_prev;s1;s1=s1.ts_prev){if(s1.type!=C.METER)
  4452. break}
  4453. case C.METER:if(s2.type==C.METER){if(!s.fmt.timewarn)
  4454. continue
  4455. s1=s.ts_prev}
  4456. case C.CLEF:if(!s2.prev)
  4457. continue
  4458. if(s2.type==C.CLEF){if(s2.invis)
  4459. break
  4460. for(s1=s.ts_prev;s1;s1=s1.ts_prev){switch(s1.type){case C.BAR:if(s1.bar_type[0]==':')
  4461. break
  4462. case C.KEY:case C.METER:continue}
  4463. break}}
  4464. s3=clone(s2)
  4465. lktsym(s3,s1.ts_next)
  4466. s1=s3
  4467. while(1){s1=s1.ts_next
  4468. if(s1.v==s2.v)
  4469. break}
  4470. lkvsym(s3,s1)
  4471. if(s3.seqst){self.set_width(s3)
  4472. s3.shrink=s3.wl
  4473. s4=s3.ts_prev
  4474. w=0
  4475. while(1){if(s4.wr>w)
  4476. w=s4.wr
  4477. if(s4.seqst)
  4478. break
  4479. s4=s4.ts_prev}
  4480. s3.shrink+=w
  4481. s3.space=0
  4482. s4=s3
  4483. while(1){if(s4.ts_next.seqst)
  4484. break
  4485. s4=s4.ts_next}
  4486. w=0
  4487. while(1){if(s4.wl>w)
  4488. w=s4.wl
  4489. s4=s4.ts_next
  4490. if(s4.seqst)
  4491. break}
  4492. s4.shrink=s3.wr+w}
  4493. delete s3.part
  4494. continue}
  4495. if(w_tb[s2.type])
  4496. break}}
  4497. s=bardiv(s)
  4498. do_warn(s)
  4499. if(s.ts_prev.type!=C.STAVES){set_eol(s)
  4500. return s}
  4501. for(s=s.ts_prev;s;s=s.ts_prev){if(s.seqst&&s.type!=C.CLEF)
  4502. break}
  4503. done=0
  4504. ptyp=s.type
  4505. for(;;s=s.ts_next){if(!s)
  4506. return s
  4507. if(s.type==ptyp)
  4508. continue
  4509. ptyp=s.type
  4510. if(done<0)
  4511. break
  4512. switch(s.type){case C.STAVES:if(!s.ts_prev)
  4513. return
  4514. if(s.ts_prev.type==C.BAR)
  4515. break
  4516. while(s.ts_next){if(w_tb[s.ts_next.type]&&s.ts_next.type!=C.CLEF)
  4517. break
  4518. s=s.ts_next}
  4519. if(!s.ts_next||s.ts_next.type!=C.BAR)
  4520. continue
  4521. s=s.ts_next
  4522. case C.BAR:if(done)
  4523. break
  4524. done=1;continue
  4525. case C.STBRK:if(!s.stbrk_forced)
  4526. unlksym(s)
  4527. else
  4528. done=-1
  4529. continue
  4530. case C.CLEF:if(done)
  4531. break
  4532. continue
  4533. default:if(!done||(s.prev&&s.prev.type==C.GRACE))
  4534. continue
  4535. break}
  4536. break}
  4537. set_eol(s)
  4538. return s}
  4539. function get_ck_width(){var r0,r1,p_voice=voice_tb[0]
  4540. self.set_width(p_voice.clef);self.set_width(p_voice.ckey);self.set_width(p_voice.meter)
  4541. return[p_voice.clef.wl+p_voice.clef.wr+
  4542. p_voice.ckey.wl+p_voice.ckey.wr,p_voice.meter.wl+p_voice.meter.wr]}
  4543. function get_width(s,next){var shrink,space,w=0,wmx=0,sp_fac=(1-s.fmt.maxshrink)
  4544. while(s!=next){if(s.seqst){shrink=s.shrink
  4545. wmx+=shrink
  4546. if((space=s.space)<shrink)
  4547. w+=shrink
  4548. else
  4549. w+=shrink*s.fmt.maxshrink
  4550. +space*sp_fac
  4551. s.x=w}
  4552. s=s.ts_next}
  4553. if(next)
  4554. wmx+=next.wr
  4555. return[w,wmx]}
  4556. function set_lines(s,next,lwidth,indent){var first,s2,s3,s4,s5,x,xmin,xmid,xmax,wwidth,shrink,space,nlines,last=next?next.ts_prev:null,ws=get_width(s,next)
  4557. if(s.fmt.keywarn&&next&&next.type==C.KEY&&!last.dur){ws[0]+=next.wr
  4558. ws[1]+=next.wr}
  4559. if(ws[0]+indent<lwidth){if(next)
  4560. next=set_nl(next)
  4561. return next||last}
  4562. wwidth=ws[0]+indent
  4563. while(1){nlines=Math.ceil(wwidth/lwidth)
  4564. if(nlines<=1){if(next)
  4565. next=set_nl(next)
  4566. return next||last}
  4567. s2=first=s;xmin=s.x-s.shrink-indent;xmax=xmin+lwidth;xmid=xmin+wwidth/nlines;xmin+=wwidth/nlines*s.fmt.breaklimit;for(s=s.ts_next;s!=next;s=s.ts_next){if(!s.x)
  4568. continue
  4569. if(s.type==C.BAR)
  4570. s2=s
  4571. if(s.x>=xmin)
  4572. break}
  4573. s4=s
  4574. if(s==next){if(s)
  4575. s=set_nl(s)
  4576. return s}
  4577. s3=null
  4578. for(;s!=next;s=s.ts_next){x=s.x
  4579. if(!x)
  4580. continue
  4581. if(x>xmax)
  4582. break
  4583. if(s.type!=C.BAR)
  4584. continue
  4585. if(x<xmid){s3=s
  4586. continue}
  4587. if(!s3||x-xmid<xmid-s3.x)
  4588. s3=s
  4589. break}
  4590. if(!s3){s=s4
  4591. var beam=0,bar_time=s2.time
  4592. xmax-=8;s5=s
  4593. for(;s!=next;s=s.ts_next){if(s.seqst){x=s.x
  4594. if(x+s.wr>=xmax)
  4595. break
  4596. if(!beam&&!s.in_tuplet&&(xmid-s5.x>x-xmid||(s.time-bar_time)%(C.BLEN/4)==0))
  4597. s3=s}
  4598. if(s.beam_st)
  4599. beam|=1<<s.v
  4600. if(s.beam_end)
  4601. beam&=~(1<<s.v)
  4602. s5=s}
  4603. if(s3){do{s3=s3.ts_prev}while(!s3.seqst)}}
  4604. if(!s3){s3=s=s4
  4605. for(;s!=next;s=s.ts_next){x=s.x
  4606. if(!x)
  4607. continue
  4608. if(x+s.wr>=xmax)
  4609. break
  4610. if(s3&&x>=xmid){if(xmid-s3.x>x-xmid)
  4611. s3=s
  4612. break}
  4613. s3=s}}
  4614. s=s3
  4615. while(s.ts_next){s=s.ts_next
  4616. if(s.seqst)
  4617. break}
  4618. if(s.nl){error(0,s,"Line split problem - adjust maxshrink and/or breaklimit");nlines=2
  4619. for(s=s.ts_next;s!=next;s=s.ts_next){if(!s.x)
  4620. continue
  4621. if(--nlines<=0)
  4622. break}}
  4623. s=set_nl(s)
  4624. if(!s||(next&&s.time>=next.time))
  4625. break
  4626. wwidth-=s.x-first.x;indent=0}
  4627. return s}
  4628. function cut_tune(lwidth,lsh){var s2,i,mc,pg_sav={leftmargin:cfmt.leftmargin,rightmargin:cfmt.rightmargin,pagewidth:cfmt.pagewidth,scale:cfmt.scale},indent=lsh[0]-lsh[1],ckw=get_ck_width(),s=tsfirst
  4629. lwidth-=lsh[1]
  4630. if(cfmt.indent&&cfmt.indent>lsh[0])
  4631. indent+=cfmt.indent
  4632. lwidth-=ckw[0]
  4633. indent+=ckw[1]
  4634. if(cfmt.custos&&voice_tb.length==1)
  4635. lwidth-=12
  4636. i=s.fmt.barsperstaff
  4637. if(i){for(s2=s;s2;s2=s2.ts_next){if(s2.type!=C.BAR||!s2.bar_num||--i>0)
  4638. continue
  4639. while(s2.ts_next&&s2.ts_next.type==C.BAR)
  4640. s2=s2.ts_next
  4641. if(s2.ts_next)
  4642. s2.ts_next.soln=true
  4643. i=s.fmt.barsperstaff}}
  4644. s2=s
  4645. for(;s;s=s.ts_next){if(s.type==C.BLOCK){switch(s.subtype){case"leftmargin":case"rightmargin":case"pagescale":case"pagewidth":case"scale":case"staffwidth":if(!s.soln)
  4646. self.set_format(s.subtype,s.param)
  4647. break
  4648. case"mc_start":mc={lm:cfmt.leftmargin,rm:cfmt.rightmargin}
  4649. break
  4650. case"mc_new":case"mc_end":if(!mc)
  4651. break
  4652. cfmt.leftmargin=mc.lm
  4653. cfmt.rightmargin=mc.rm
  4654. img.chg=1
  4655. break}}
  4656. if(!s.ts_next){s=null}else if(!s.soln){continue}else{s.soln=false
  4657. if(s.time==s2.time)
  4658. continue
  4659. while(!s.seqst)
  4660. s=s.ts_prev}
  4661. set_page()
  4662. lwidth=get_lwidth()-lsh[1]-ckw[0]
  4663. s2=set_lines(s2,s,lwidth,indent)
  4664. if(!s2)
  4665. break
  4666. s=s2.type==C.BLOCK?s2.ts_prev:s
  4667. indent=0}
  4668. cfmt.leftmargin=pg_sav.leftmargin
  4669. cfmt.rightmargin=pg_sav.rightmargin
  4670. cfmt.pagewidth=pg_sav.pagewidth
  4671. cfmt.scale=pg_sav.scale
  4672. img.chg=1
  4673. set_page()}
  4674. function set_yval(s){switch(s.type){case C.CLEF:if(s.second||s.invis){s.ymx=s.ymn=12
  4675. break}
  4676. s.y=(s.clef_line-1)*6
  4677. switch(s.clef_type){default:s.ymx=s.y+28
  4678. s.ymn=s.y-14
  4679. break
  4680. case"c":s.ymx=s.y+13
  4681. s.ymn=s.y-11
  4682. break
  4683. case"b":s.ymx=s.y+7
  4684. s.ymn=s.y-12
  4685. break}
  4686. if(s.clef_small){s.ymx-=2;s.ymn+=2}
  4687. if(s.ymx<26)
  4688. s.ymx=26
  4689. if(s.ymn>-1)
  4690. s.ymn=-1
  4691. if(s.clef_octave){if(s.clef_octave>0)
  4692. s.ymx+=12
  4693. else
  4694. s.ymn-=12}
  4695. break
  4696. case C.KEY:if(s.k_sf>2)
  4697. s.ymx=24+10
  4698. else if(s.k_sf>0)
  4699. s.ymx=24+6
  4700. else
  4701. s.ymx=24+2;s.ymn=-2
  4702. break
  4703. default:s.ymx=24;s.ymn=0
  4704. break}}
  4705. function set_ottava(){var s,s1,st,o,d,m=nstaff+1,staff_d=new Int8Array(m)
  4706. function sym_ott(s,d){var g,m,note
  4707. switch(s.type){case C.REST:if(voice_tb.length==1)
  4708. break
  4709. case C.NOTE:if(!s.p_v.ckey.k_drum){for(m=s.nhd;m>=0;m--){note=s.notes[m];if(!note.opit)
  4710. note.opit=note.pit;note.pit+=d}}
  4711. break
  4712. case C.GRACE:for(g=s.extra;g;g=g.next){if(!s.p_v.ckey.k_drum){for(m=0;m<=g.nhd;m++){note=g.notes[m]
  4713. if(!note.opit)
  4714. note.opit=note.pit
  4715. note.pit+=d}}}
  4716. break}}
  4717. function deco_rm(s){for(var i=s.a_dd.length;--i>=0;){if(s.a_dd[i].name.match(/1?[85][vm][ab]/))
  4718. s.a_dd.splice(i,1)}}
  4719. for(s=tsfirst;s;s=s.ts_next){st=s.st
  4720. o=s.ottava
  4721. if(o){if(o[0]){if(staff_d[st]&&!o[1]){sym_ott(s,staff_d[st])
  4722. deco_rm(s)
  4723. continue}}else if(!staff_d[st]){deco_rm(s)
  4724. continue}
  4725. s1=s
  4726. while(s1&&!s1.seqst)
  4727. s1=s1.ts_prev
  4728. if(s1){while(s1!=s){if(s1.st==st){if(o[1])
  4729. sym_ott(s1,-staff_d[st])
  4730. if(o[0])
  4731. sym_ott(s1,-o[0]*7)}
  4732. s1=s1.ts_next}}
  4733. if(o[0]){staff_d[st]=-o[0]*7}else{staff_d[st]=0}}
  4734. if(staff_d[st])
  4735. sym_ott(s,staff_d[st])}}
  4736. function mrest_expand(){var s,s2
  4737. function mexp(s){var bar,s3,s4,tim,nbar,nb=s.nmes,dur=s.dur/nb,s2=s.next
  4738. while(!s2.bar_type)
  4739. s2=s2.next
  4740. bar=s2
  4741. while(!s2.bar_num)
  4742. s2=s2.ts_prev
  4743. nbar=s2.bar_num-s.nmes
  4744. s.type=C.REST
  4745. s.notes[0].dur=s.dur=s.dur_orig=dur
  4746. s.nflags=-2
  4747. s.head=C.FULL
  4748. s.fmr=1
  4749. tim=s.time+dur
  4750. s3=s
  4751. while(--nb>0){s2=clone(bar)
  4752. delete s2.soln
  4753. delete s2.a_gch
  4754. delete s2.a_dd
  4755. delete s2.text
  4756. delete s2.rbstart
  4757. delete s2.rbstop
  4758. lkvsym(s2,s.next)
  4759. s2.time=tim
  4760. while(s3.time<tim)
  4761. s3=s3.ts_next
  4762. while(s3&&s3.v<s.v&&s3.type==C.BAR)
  4763. s3=s3.ts_next
  4764. if(s3){if(s3.bar_type)
  4765. s3.seqst=0
  4766. lktsym(s2,s3)
  4767. if(s3.type==C.BAR)
  4768. delete s3.bar_num}else{s3=s
  4769. while(s3.ts_next)
  4770. s3=s3.ts_next
  4771. s3.ts_next=s2
  4772. s2.ts_prev=s3
  4773. s2.ts_next=null}
  4774. nbar++
  4775. if(s2.seqst){s2.bar_num=nbar
  4776. s4=s2.ts_next}else{delete s2.bar_num
  4777. s4=s2.ts_prev}
  4778. s2.bar_type=s4.bar_type||"|"
  4779. if(s4.bar_num&&!s4.seqst)
  4780. delete s4.bar_num
  4781. s4=clone(s)
  4782. delete s4.a_dd
  4783. delete s4.soln
  4784. delete s4.a_gch
  4785. delete s4.part
  4786. if(s2.next){s4.next=s2.next
  4787. s4.next.prev=s4}else{s4.next=null}
  4788. s2.next=s4
  4789. s4.prev=s2
  4790. s4.time=tim
  4791. while(s3&&!s3.dur&&s3.time==tim)
  4792. s3=s3.ts_next
  4793. while(s3&&s3.v<s.v){s3=s3.ts_next
  4794. if(s3&&s3.seqst)
  4795. break}
  4796. if(s3){if(s3.dur)
  4797. s3.seqst=0
  4798. lktsym(s4,s3)}else{s3=s
  4799. while(s3.ts_next)
  4800. s3=s3.ts_next
  4801. s3.ts_next=s4
  4802. s4.ts_prev=s3
  4803. s4.ts_next=null}
  4804. tim+=dur
  4805. s=s3=s4}}
  4806. for(s=tsfirst;s;s=s.ts_next){if(s.type!=C.MREST)
  4807. continue
  4808. if(!s.seqst&&w_tb[s.ts_prev.type]){s2=s}else{s2=s.ts_next
  4809. while(!s2.seqst){if(s2.type!=C.MREST||s2.nmes!=s.nmes)
  4810. break
  4811. s2=s2.ts_next}}
  4812. if(!s2.seqst){while(s.type==C.MREST){mexp(s)
  4813. s=s.ts_next}}else{s=s2.ts_prev}}}
  4814. function set_auto_clef(st,s_start,clef_type_start){var s,time,s2,s3,max=12,min=20
  4815. for(s=s_start;s;s=s.ts_next){if(s.type==C.STAVES&&s!=s_start)
  4816. break
  4817. if(s.st!=st)
  4818. continue
  4819. if(s.type!=C.NOTE){if(s.type==C.CLEF){if(s.clef_type!='a')
  4820. break
  4821. unlksym(s)}
  4822. continue}
  4823. if(s.notes[0].pit<min)
  4824. min=s.notes[0].pit
  4825. if(s.notes[s.nhd].pit>max)
  4826. max=s.notes[s.nhd].pit}
  4827. if(min>=19||(min>=13&&clef_type_start!='b'))
  4828. return't'
  4829. if(max<=13||(max<=19&&clef_type_start!='t'))
  4830. return'b'
  4831. if(clef_type_start=='a'){if((max+min)/2>=16)
  4832. clef_type_start='t'
  4833. else
  4834. clef_type_start='b'}
  4835. var clef_type=clef_type_start,s_last=s,s_last_chg=null
  4836. for(s=s_start;s!=s_last;s=s.ts_next){if(s.type==C.STAVES&&s!=s_start)
  4837. break
  4838. if(s.st!=st||s.type!=C.NOTE)
  4839. continue
  4840. time=s.time
  4841. if(clef_type=='t'){if(s.notes[0].pit>12||s.notes[s.nhd].pit>20){if(s.notes[0].pit>20)
  4842. s_last_chg=s
  4843. continue}
  4844. s2=s.ts_prev
  4845. if(s2&&s2.time==time&&s2.st==st&&s2.type==C.NOTE&&s2.notes[0].pit>=19)
  4846. continue
  4847. s2=s.ts_next
  4848. if(s2&&s2.st==st&&s2.time==time&&s2.type==C.NOTE&&s2.notes[0].pit>=19)
  4849. continue}else{if(s.notes[0].pit<=12||s.notes[s.nhd].pit<20){if(s.notes[s.nhd].pit<=12)
  4850. s_last_chg=s
  4851. continue}
  4852. s2=s.ts_prev
  4853. if(s2&&s2.time==time&&s2.st==st&&s2.type==C.NOTE&&s2.notes[0].pit<=13)
  4854. continue
  4855. s2=s.ts_next
  4856. if(s2&&s2.st==st&&s2.time==time&&s2.type==C.NOTE&&s2.notes[0].pit<=13)
  4857. continue}
  4858. if(!s_last_chg){clef_type=clef_type_start=clef_type=='t'?'b':'t';s_last_chg=s
  4859. continue}
  4860. s3=s
  4861. for(s2=s.ts_prev;s2!=s_last_chg;s2=s2.ts_prev){if(s2.st!=st)
  4862. continue
  4863. if(s2.type==C.BAR){s3=s2.bar_type[0]!=':'?s2:s2.next
  4864. break}
  4865. if(s2.type!=C.NOTE)
  4866. continue
  4867. if(s2.beam_st&&!s2.p_v.second)
  4868. s3=s2}
  4869. if(s3.time==s_last_chg.time){s_last_chg=s
  4870. continue}
  4871. s_last_chg=s;clef_type=clef_type=='t'?'b':'t';s2=insert_clef(s3,clef_type,clef_type=="t"?2:4);s2.clef_auto=true}
  4872. return clef_type_start}
  4873. function set_clefs(){var s,s2,st,v,p_voice,g,new_type,new_line,p_staff,pit,staff_clef=new Array(nstaff+1),sy=cur_sy,mid=[]
  4874. staff_tb=new Array(nstaff+1)
  4875. for(st=0;st<=nstaff;st++){staff_clef[st]={autoclef:true}
  4876. staff_tb[st]={output:"",sc_out:""}}
  4877. for(st=0;st<=sy.nstaff;st++)
  4878. mid[st]=(sy.staves[st].stafflines.length-1)*3
  4879. for(s=tsfirst;s;s=s.ts_next){if(s.repeat_n)
  4880. set_repeat(s)
  4881. switch(s.type){case C.STAVES:sy=s.sy
  4882. for(st=0;st<=nstaff;st++)
  4883. staff_clef[st].autoclef=true
  4884. for(v=0;v<voice_tb.length;v++){if(!sy.voices[v])
  4885. continue
  4886. p_voice=voice_tb[v];st=sy.voices[v].st
  4887. if(!sy.voices[v].second){sy.staves[st].staffnonote=p_voice.staffnonote
  4888. if(p_voice.staffscale)
  4889. sy.staves[st].staffscale=p_voice.staffscale
  4890. if(sy.voices[v].sep)
  4891. sy.staves[st].sep=sy.voices[v].sep
  4892. if(sy.voices[v].maxsep)
  4893. sy.staves[st].maxsep=sy.voices[v].maxsep}
  4894. s2=p_voice.clef
  4895. if(!s2.clef_auto)
  4896. staff_clef[st].autoclef=false}
  4897. for(st=0;st<=sy.nstaff;st++)
  4898. mid[st]=(sy.staves[st].stafflines.length-1)*3
  4899. for(v=0;v<voice_tb.length;v++){if(!sy.voices[v]||sy.voices[v].second)
  4900. continue
  4901. p_voice=voice_tb[v];st=sy.voices[v].st;s2=p_voice.clef
  4902. if(s2.clef_auto){new_type=set_auto_clef(st,s,staff_clef[st].clef?staff_clef[st].clef.clef_type:'a');new_line=new_type=='t'?2:4}else{new_type=s2.clef_type;new_line=s2.clef_line}
  4903. if(!staff_clef[st].clef){if(s2.clef_auto){if(s2.clef_type!='a')
  4904. p_voice.clef=clone(p_voice.clef);p_voice.clef.clef_type=new_type;p_voice.clef.clef_line=new_line}
  4905. staff_tb[st].clef=staff_clef[st].clef=p_voice.clef
  4906. continue}
  4907. if(new_type==staff_clef[st].clef.clef_type&&new_line==staff_clef[st].clef.clef_line)
  4908. continue
  4909. g=s.ts_prev
  4910. while(g&&g.time==s.time&&(g.v!=v||g.st!=st))
  4911. g=g.ts_prev
  4912. if(!g||g.time!=s.time){g=s.ts_next
  4913. while(g&&(g.v!=v||g.st!=st))
  4914. g=g.ts_next
  4915. if(!g||g.time!=s.time)
  4916. g=s}
  4917. if(g.type!=C.CLEF){g=insert_clef(g,new_type,new_line)
  4918. if(s2.clef_auto)
  4919. g.clef_auto=true}
  4920. staff_clef[st].clef=p_voice.clef=g}
  4921. continue
  4922. default:s.mid=mid[s.st]
  4923. continue
  4924. case C.CLEF:break}
  4925. if(s.clef_type=='a'){s.clef_type=set_auto_clef(s.st,s.ts_next,staff_clef[s.st].clef.clef_type);s.clef_line=s.clef_type=='t'?2:4}
  4926. p_voice=s.p_v;p_voice.clef=s
  4927. if(s.second){unlksym(s)
  4928. continue}
  4929. st=s.st
  4930. if(staff_clef[st].clef){if(s.clef_type==staff_clef[st].clef.clef_type&&s.clef_line==staff_clef[st].clef.clef_line){continue}}else{staff_tb[st].clef=s}
  4931. staff_clef[st].clef=s}
  4932. sy=cur_sy
  4933. for(v=0;v<voice_tb.length;v++){if(!sy.voices[v])
  4934. continue
  4935. s2=voice_tb[v].sym
  4936. if(!s2||s2.notes[0].pit!=127)
  4937. continue
  4938. st=sy.voices[v].st
  4939. switch(staff_tb[st].clef.clef_type){default:pit=22
  4940. break
  4941. case"c":pit=16
  4942. break
  4943. case"b":pit=10
  4944. break}
  4945. for(s=s2;s;s=s.next)
  4946. s.notes[0].pit=pit}}
  4947. var delta_tb={t:0-2*2,c:6-3*2,b:12-4*2,p:0-3*2}
  4948. var rest_sp=[[18,18],[12,18],[12,12],[6,12],[6,8],[10,10],[6,4],[10,0],[10,4],[10,10]]
  4949. Abc.prototype.set_pitch=function(last_s){var s,s2,g,st,delta,pitch,note,dur=C.BLEN,m=nstaff+1,staff_delta=new Int16Array(new Array(m*2)),sy=cur_sy
  4950. for(st=0;st<=nstaff;st++){s=staff_tb[st].clef;staff_delta[st]=delta_tb[s.clef_type]+s.clef_line*2
  4951. if(s.clefpit)
  4952. staff_delta[st]+=s.clefpit
  4953. if(cfmt.sound){if(s.clef_octave&&!s.clef_oct_transp)
  4954. staff_delta[st]+=s.clef_octave}else{if(s.clef_oct_transp)
  4955. staff_delta[st]-=s.clef_octave}}
  4956. for(s=tsfirst;s!=last_s;s=s.ts_next){st=s.st
  4957. switch(s.type){case C.CLEF:staff_delta[st]=delta_tb[s.clef_type]+
  4958. s.clef_line*2
  4959. if(s.clefpit)
  4960. staff_delta[st]+=s.clefpit
  4961. if(cfmt.sound){if(s.clef_octave&&!s.clef_oct_transp)
  4962. staff_delta[st]+=s.clef_octave}else{if(s.clef_oct_transp)
  4963. staff_delta[st]-=s.clef_octave}
  4964. set_yval(s)
  4965. break
  4966. case C.GRACE:for(g=s.extra;g;g=g.next){delta=staff_delta[g.st]
  4967. if(delta&&!s.p_v.ckey.k_drum){for(m=0;m<=g.nhd;m++){note=g.notes[m];note.opit=note.pit
  4968. note.pit+=delta}}
  4969. g.ymn=3*(g.notes[0].pit-18)-2;g.ymx=3*(g.notes[g.nhd].pit-18)+2}
  4970. set_yval(s)
  4971. break
  4972. case C.KEY:s.k_y_clef=staff_delta[st]
  4973. default:set_yval(s)
  4974. break
  4975. case C.MREST:if(s.invis)
  4976. break
  4977. s.y=12;s.ymx=24+15;s.ymn=-2
  4978. break
  4979. case C.REST:if(s.rep_nb>1||s.bar_mrep){s.y=12
  4980. s.ymx=38
  4981. s.ymn=0
  4982. break}
  4983. if(voice_tb.length==1){s.y=12;s.ymx=24;s.ymn=0
  4984. break}
  4985. case C.NOTE:delta=staff_delta[st]
  4986. if(delta&&!s.p_v.ckey.k_drum){for(m=s.nhd;m>=0;m--){note=s.notes[m]
  4987. note.opit=note.pit
  4988. note.pit+=delta}}
  4989. if(s.type==C.REST){s.y=(((s.notes[0].pit-18)/2)|0)*6;s.ymx=s.y+rest_sp[5-s.nflags][0];s.ymn=s.y-rest_sp[5-s.nflags][1]}
  4990. if(s.dur<dur)
  4991. dur=s.dur
  4992. break}}
  4993. if(!last_s)
  4994. smallest_duration=dur}
  4995. Abc.prototype.set_stem_dir=function(){var t,u,i,st,rvoice,v,v_st,st_v,vobj,v_st_tb,st_v_tb=[],s=tsfirst,sy=cur_sy,nst=sy.nstaff
  4996. while(s){for(st=0;st<=nst;st++)
  4997. st_v_tb[st]=[]
  4998. v_st_tb=[]
  4999. for(u=s;u;u=u.ts_next){if(u.type==C.BAR)
  5000. break;if(u.type==C.STAVES){if(u!=s)
  5001. break
  5002. sy=s.sy
  5003. for(st=nst;st<=sy.nstaff;st++)
  5004. st_v_tb[st]=[]
  5005. nst=sy.nstaff
  5006. continue}
  5007. if((u.type!=C.NOTE&&u.type!=C.REST)||u.invis)
  5008. continue
  5009. st=u.st;if(st>nst){var msg="*** fatal set_stem_dir(): bad staff number "+st+" max "+nst;error(2,null,msg);throw new Error(msg)}
  5010. v=u.v;v_st=v_st_tb[v]
  5011. if(!v_st){v_st={st1:-1,st2:-1}
  5012. v_st_tb[v]=v_st}
  5013. if(v_st.st1<0){v_st.st1=st}else if(v_st.st1!=st){if(st>v_st.st1){if(st>v_st.st2)
  5014. v_st.st2=st}else{if(v_st.st1>v_st.st2)
  5015. v_st.st2=v_st.st1;v_st.st1=st}}
  5016. st_v=st_v_tb[st];rvoice=sy.voices[v].range;for(i=st_v.length;--i>=0;){vobj=st_v[i]
  5017. if(vobj.v==rvoice)
  5018. break}
  5019. if(i<0){vobj={v:rvoice,ymx:0,ymn:24}
  5020. for(i=0;i<st_v.length;i++){if(rvoice<st_v[i].v){st_v.splice(i,0,vobj)
  5021. break}}
  5022. if(i==st_v.length)
  5023. st_v.push(vobj)}
  5024. if(u.type!=C.NOTE)
  5025. continue
  5026. if(u.ymx>vobj.ymx)
  5027. vobj.ymx=u.ymx
  5028. if(u.ymn<vobj.ymn)
  5029. vobj.ymn=u.ymn
  5030. if(u.xstem){if(u.ts_prev.st!=st-1||u.ts_prev.type!=C.NOTE){error(1,s,"Bad !xstem!");u.xstem=false}else{u.ts_prev.multi=1;u.multi=1;u.stemless=true}}}
  5031. for(;s!=u;s=s.ts_next){if(s.multi)
  5032. continue
  5033. switch(s.type){default:continue
  5034. case C.REST:if((s.combine!=undefined&&s.combine<0)||!s.ts_next||s.ts_next.type!=C.REST||s.ts_next.st!=s.st||s.time!=s.ts_next.time||s.dur!=s.ts_next.dur||(s.a_dd&&s.ts_next.a_dd)||(s.a_gch&&s.ts_next.a_gch)||s.invis)
  5035. break
  5036. if(s.ts_next.a_dd)
  5037. s.a_dd=s.ts_next.a_dd
  5038. if(s.ts_next.a_gch)
  5039. s.a_gch=s.ts_next.a_gch
  5040. unlksym(s.ts_next)
  5041. break
  5042. case C.NOTE:case C.GRACE:break}
  5043. st=s.st;v=s.v;v_st=v_st_tb[v];st_v=st_v_tb[st]
  5044. if(v_st&&v_st.st2>=0){if(st==v_st.st1)
  5045. s.multi=-1
  5046. else if(st==v_st.st2)
  5047. s.multi=1
  5048. continue}
  5049. if(st_v.length<=1){if(s.floating)
  5050. s.multi=st==voice_tb[v].st?-1:1
  5051. continue}
  5052. rvoice=sy.voices[v].range
  5053. for(i=st_v.length;--i>=0;){if(st_v[i].v==rvoice)
  5054. break}
  5055. if(i<0)
  5056. continue
  5057. if(i==st_v.length-1){s.multi=-1}else{s.multi=1
  5058. if(i&&i+2==st_v.length){if(st_v[i].ymn-s.fmt.stemheight>=st_v[i+1].ymx)
  5059. s.multi=-1;t=s.ts_next
  5060. if(s.ts_prev&&s.ts_prev.time==s.time&&s.ts_prev.st==s.st&&s.notes[s.nhd].pit==s.ts_prev.notes[0].pit&&s.beam_st&&s.beam_end&&(!t||t.st!=s.st||t.time!=s.time))
  5061. s.multi=-1}}}
  5062. while(s&&s.type==C.BAR)
  5063. s=s.ts_next}}
  5064. function set_rest_offset(){var s,s2,v,end_time,not_alone,v_s,y,ymax,ymin,shift,dots,dx,v_s_tb=[],sy=cur_sy
  5065. for(s=tsfirst;s;s=s.ts_next){if(s.invis)
  5066. continue
  5067. if(s.type==C.STAVES)
  5068. sy=s.sy
  5069. if(!s.dur)
  5070. continue
  5071. v_s=v_s_tb[s.v]
  5072. if(!v_s){v_s={}
  5073. v_s_tb[s.v]=v_s}
  5074. v_s.s=s;v_s.st=s.st;v_s.end_time=s.time+s.dur
  5075. if(s.type!=C.REST)
  5076. continue
  5077. ymin=-127;ymax=127;not_alone=dots=false
  5078. for(v=0;v<=v_s_tb.length;v++){v_s=v_s_tb[v]
  5079. if(!v_s||!v_s.s||v_s.st!=s.st||v==s.v)
  5080. continue
  5081. if(v_s.end_time<=s.time)
  5082. continue
  5083. not_alone=true;s2=v_s.s
  5084. if(sy.voices[v].range<sy.voices[s.v].range){if(s2.time==s.time){if(s2.ymn<ymax){ymax=s2.ymn
  5085. if(s2.dots)
  5086. dots=true}}else{if(s2.y<ymax)
  5087. ymax=s2.y}}else{if(s2.time==s.time){if(s2.ymx>ymin){ymin=s2.ymx
  5088. if(s2.dots)
  5089. dots=true}}else{if(s2.y>ymin)
  5090. ymin=s2.y}}}
  5091. end_time=s.time+s.dur
  5092. for(s2=s.ts_next;s2;s2=s2.ts_next){if(s2.time>=end_time)
  5093. break
  5094. if(s2.st!=s.st||!s2.dur||s2.invis)
  5095. continue
  5096. not_alone=true
  5097. if(sy.voices[s2.v].range<sy.voices[s.v].range){if(s2.time==s.time){if(s2.ymn<ymax){ymax=s2.ymn
  5098. if(s2.dots)
  5099. dots=true}}else{if(s2.y<ymax)
  5100. ymax=s2.y}}else{if(s2.time==s.time){if(s2.ymx>ymin){ymin=s2.ymx
  5101. if(s2.dots)
  5102. dots=true}}else{if(s2.y>ymin)
  5103. ymin=s2.y}}}
  5104. if(!not_alone){s.y=12;s.ymx=24;s.ymn=0
  5105. continue}
  5106. if(ymax==127&&s.y<12){shift=12-s.y
  5107. s.y+=shift;s.ymx+=shift;s.ymn+=shift}
  5108. if(ymin==-127&&s.y>12){shift=s.y-12
  5109. s.y-=shift;s.ymx-=shift;s.ymn-=shift}
  5110. shift=ymax-s.ymx
  5111. if(shift<0){shift=Math.ceil(-shift/6)*6
  5112. if(s.ymn-shift>=ymin){s.y-=shift;s.ymx-=shift;s.ymn-=shift
  5113. continue}
  5114. dx=dots?15:10;s.notes[0].shhd=dx;s.xmx=dx
  5115. continue}
  5116. shift=ymin-s.ymn
  5117. if(shift>0){shift=Math.ceil(shift/6)*6
  5118. if(s.ymx+shift<=ymax){s.y+=shift;s.ymx+=shift;s.ymn+=shift
  5119. continue}
  5120. dx=dots?15:10;s.notes[0].shhd=dx;s.xmx=dx
  5121. continue}}}
  5122. function new_sym(s,p_v,last_s){s.p_v=p_v
  5123. s.v=p_v.v
  5124. s.st=p_v.st
  5125. s.time=last_s.time
  5126. if(p_v.last_sym){s.next=p_v.last_sym.next
  5127. if(s.next)
  5128. s.next.prev=s;p_v.last_sym.next=s;s.prev=p_v.last_sym}
  5129. p_v.last_sym=s;lktsym(s,last_s)}
  5130. function init_music_line(){var p_voice,s,s1,s2,s3,last_s,v,st,shr,shrmx,shl,shlp,p_st,top,nv=voice_tb.length,fmt=tsfirst.fmt
  5131. for(v=0;v<nv;v++){if(!cur_sy.voices[v])
  5132. continue
  5133. p_voice=voice_tb[v];p_voice.st=cur_sy.voices[v].st
  5134. p_voice.second=cur_sy.voices[v].second;p_voice.last_sym=p_voice.sym;for(s=p_voice.sym;s&&s.time==tsfirst.time;s=s.next){switch(s.type){case C.CLEF:case C.KEY:case C.METER:switch(s.type){case C.CLEF:staff_tb[s.st].clef=s
  5135. break
  5136. case C.KEY:s.p_v.ckey=s
  5137. break
  5138. case C.METER:s.p_v.meter=s
  5139. insert_meter=cfmt.writefields.indexOf('M')>=0&&s.a_meter.length
  5140. break}
  5141. if(s.part)
  5142. s.next.part=s.part
  5143. unlksym(s)
  5144. case C.TEMPO:case C.BLOCK:case C.REMARK:continue}
  5145. break}}
  5146. last_s=tsfirst
  5147. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  5148. if(!cur_sy.voices[v]||(cur_sy.voices[v].second&&!p_voice.bar_start))
  5149. continue
  5150. st=cur_sy.voices[v].st
  5151. if(!staff_tb[st]||!staff_tb[st].clef)
  5152. continue
  5153. s=clone(staff_tb[st].clef);s.v=v;s.p_v=p_voice;s.st=st;s.time=tsfirst.time;s.prev=null;s.next=p_voice.sym
  5154. if(s.next)
  5155. s.next.prev=s;p_voice.sym=p_voice.last_sym=s
  5156. s.ts_next=last_s;if(last_s)
  5157. s.ts_prev=last_s.ts_prev
  5158. else
  5159. s.ts_prev=null
  5160. if(!s.ts_prev){tsfirst=s}else{s.ts_prev.ts_next=s
  5161. delete s.seqst}
  5162. if(last_s)
  5163. last_s.ts_prev=s
  5164. delete s.clef_small;delete s.part
  5165. s.second=cur_sy.voices[v].second
  5166. if(!cur_sy.st_print[st])
  5167. s.invis=true
  5168. s.fmt=fmt}
  5169. for(v=0;v<nv;v++){if(!cur_sy.voices[v]||cur_sy.voices[v].second||!cur_sy.st_print[cur_sy.voices[v].st])
  5170. continue
  5171. p_voice=voice_tb[v]
  5172. s2=p_voice.ckey
  5173. if(s2.k_sf||s2.k_a_acc){s=clone(s2)
  5174. new_sym(s,p_voice,last_s)
  5175. delete s.invis
  5176. delete s.part
  5177. s.k_old_sf=s2.k_sf
  5178. s.fmt=fmt}}
  5179. if(insert_meter){for(v=0;v<nv;v++){p_voice=voice_tb[v];s2=p_voice.meter
  5180. if(!cur_sy.voices[v]||cur_sy.voices[v].second||!cur_sy.st_print[cur_sy.voices[v].st])
  5181. continue
  5182. s=clone(s2)
  5183. new_sym(s,p_voice,last_s)
  5184. delete s.part
  5185. s.fmt=fmt}
  5186. insert_meter=false}
  5187. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  5188. if(p_voice.sls.length){s={type:C.BAR,fname:last_s.fname,bar_type:"|",dur:0,multi:0,invis:true,sls:p_voice.sls,fmt:fmt}
  5189. new_sym(s,p_voice,last_s)
  5190. p_voice.sls=[]}}
  5191. for(v=0;v<nv;v++){p_voice=voice_tb[v];s2=p_voice.bar_start;p_voice.bar_start=null
  5192. for(s=last_s;s&&s.time==last_s.time;s=s.ts_next){if(s.rbstop){s2=null
  5193. break}}
  5194. if(!s2)
  5195. continue
  5196. if(!cur_sy.voices[v]||!cur_sy.st_print[cur_sy.voices[v].st])
  5197. continue
  5198. if(p_voice.last_sym.type==C.BAR){if(!p_voice.last_sym.rbstop)
  5199. p_voice.last_sym.rbstart=1}else{new_sym(s2,p_voice,last_s)
  5200. s2.fmt=fmt}}
  5201. self.set_pitch(last_s);s=tsfirst
  5202. s.seqst=true
  5203. for(s=last_s;s.ts_next&&!s.ts_next.seqst;s=s.ts_next);if(s.ts_next&&s.ts_next.type!=C.CLEF&&!s.ts_next.a_ly)
  5204. for(s=s.ts_next;s.ts_next&&!s.ts_next.seqst;s=s.ts_next);s2=s.ts_next
  5205. s.ts_next=null
  5206. set_allsymwidth()
  5207. s.ts_next=s2}
  5208. function check_end_bar(){var s2,s=tsfirst
  5209. while(s.ts_next)
  5210. s=s.ts_next
  5211. if(s.type!=C.BAR){s2=_bar(s)
  5212. s2.ts_prev=s
  5213. s.next=s.ts_next=s2}}
  5214. function set_words(p_voice){var s,s2,nflags,lastnote,res,start_flag=true,pitch=127
  5215. function trem_adj(s){s.prev.trem2=true
  5216. s.prev.head=++s.head
  5217. if(--s.nflags>0){s.nflags+=s.ntrem}else{if(s.nflags<=-2){s.stemless=true
  5218. s.prev.stemless=true}
  5219. s.nflags=s.ntrem}
  5220. s.prev.nflags=s.nflags}
  5221. for(s=p_voice.sym;s;s=s.next){if(s.type==C.NOTE){pitch=s.notes[0].pit
  5222. break}}
  5223. for(s=p_voice.sym;s;s=s.next){if(s.a_gch)
  5224. self.gch_build(s)
  5225. switch(s.type){case C.MREST:start_flag=true
  5226. break
  5227. case C.BAR:res=s.fmt.bardef[s.bar_type]
  5228. if(res)
  5229. s.bar_type=res
  5230. if(!s.beam_on)
  5231. start_flag=true
  5232. if(!s.next&&s.prev&&!s.invis&&s.prev.head==C.OVALBARS)
  5233. s.prev.head=C.SQUARE
  5234. break
  5235. case C.GRACE:for(s2=s.extra;s2;s2=s2.next){s2.notes.sort(abc2svg.pitcmp)
  5236. res=identify_note(s2,s2.dur_orig)
  5237. s2.head=res[0]
  5238. s2.dots=res[1]
  5239. s2.nflags=res[2]
  5240. if(s2.trem2&&(!s2.next||s2.next.trem2))
  5241. trem_adj(s2)}
  5242. break
  5243. case C.NOTE:case C.REST:res=identify_note(s,s.dur_orig);s.head=res[0];s.dots=res[1];s.nflags=res[2]
  5244. if(s.nflags<=-2)
  5245. s.stemless=true
  5246. if(s.xstem)
  5247. s.nflags=0
  5248. if(s.trem1){if(s.nflags>0)
  5249. s.nflags+=s.ntrem
  5250. else
  5251. s.nflags=s.ntrem}
  5252. if(s.next&&s.next.trem2)
  5253. break
  5254. if(s.trem2){trem_adj(s)
  5255. break}
  5256. nflags=s.nflags
  5257. if(s.ntrem)
  5258. nflags+=s.ntrem
  5259. if(s.type==C.REST&&s.beam_end&&!s.beam_on){start_flag=true}
  5260. if(start_flag||nflags<=0){if(lastnote){lastnote.beam_end=true;lastnote=null}
  5261. if(nflags<=0){s.beam_st=s.beam_end=true}else if(s.type==C.NOTE||s.beam_on){s.beam_st=true;start_flag=false}}
  5262. if(s.beam_end)
  5263. start_flag=true
  5264. if(s.type==C.NOTE||s.beam_on)
  5265. lastnote=s
  5266. break}
  5267. if(s.type==C.NOTE){if(s.nhd)
  5268. s.notes.sort(abc2svg.pitcmp)
  5269. pitch=s.notes[0].pit
  5270. for(s2=s.prev;s2;s2=s2.prev){if(s2.type!=C.REST)
  5271. break
  5272. s2.notes[0].pit=pitch}}else{if(!s.notes){s.notes=[]
  5273. s.notes[0]={}
  5274. s.nhd=0}
  5275. s.notes[0].pit=pitch}}
  5276. if(lastnote)
  5277. lastnote.beam_end=true}
  5278. function set_rb(p_voice){var s2,n,s=p_voice.sym
  5279. while(s){if(s.type!=C.BAR||!s.rbstart||s.norepbra){s=s.next
  5280. continue}
  5281. n=0;s2=null
  5282. for(s=s.next;s;s=s.next){if(s.type!=C.BAR)
  5283. continue
  5284. if(s.rbstop)
  5285. break
  5286. if(!s.next){s.rbstop=2
  5287. break}
  5288. n++
  5289. if(n==s.fmt.rbmin)
  5290. s2=s
  5291. if(n==s.fmt.rbmax){if(s2)
  5292. s=s2;s.rbstop=1
  5293. break}}}}
  5294. var delpit=[0,-7,-14,0]
  5295. function set_global(){var p_voice,v,nv=voice_tb.length,sy=cur_sy,st=sy.nstaff
  5296. insert_meter=cfmt.writefields.indexOf('M')>=0
  5297. while(1){sy=sy.next
  5298. if(!sy)
  5299. break
  5300. if(sy.nstaff>st)
  5301. st=sy.nstaff}
  5302. nstaff=st;check_end_bar()
  5303. for(v=0;v<nv;v++){p_voice=voice_tb[v];set_words(p_voice)
  5304. p_voice.ckey=p_voice.key
  5305. set_rb(p_voice)}
  5306. if(nv>1){set_float()
  5307. if(glovar.mrest_p)
  5308. mrest_expand()}
  5309. if(glovar.ottava&&cfmt.sound!="play")
  5310. set_ottava();set_clefs();self.set_pitch(null)}
  5311. function get_lshift(){var st,v,p_v,p1,po,fnt,w,sy=cur_sy,lsh1=0,lsho=0,nv=voice_tb.length
  5312. function get_wx(p,wx){var w,j,i=0
  5313. p+='\n'
  5314. while(1){j=p.indexOf("\n",i)
  5315. if(j<0)
  5316. break
  5317. w=strwh(p.slice(i,j))[0]+12
  5318. if(w>wx)
  5319. wx=w
  5320. if(j<0)
  5321. break
  5322. i=j+1}
  5323. return wx}
  5324. for(v=0;v<nv;v++){p_v=voice_tb[v]
  5325. p1=p_v.nm
  5326. po=p_v.snm
  5327. if((p1||po)&&!fnt){set_font("voice")
  5328. fnt=gene.deffont}
  5329. if(p1){w=get_wx(p1,lsh1)
  5330. if(w>lsh1)
  5331. lsh1=w}
  5332. if(po){w=get_wx(po,lsho)
  5333. if(w>lsho)
  5334. lsho=w}}
  5335. w=0
  5336. while(sy){for(st=0;st<=sy.nstaff;st++){if(sy.staves[st].flags&(OPEN_BRACE2|OPEN_BRACKET2)){w=12
  5337. break}
  5338. if(sy.staves[st].flags&(OPEN_BRACE|OPEN_BRACKET))
  5339. w=6}
  5340. if(w==12)
  5341. break
  5342. sy=sy.next}
  5343. lsh1+=w
  5344. lsho+=w
  5345. return[lsh1,lsho]}
  5346. function set_indent(lsh){var st,v,w,p_voice,p,i,j,font,vnt=0,nv=voice_tb.length
  5347. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  5348. if(!cur_sy.voices[v]||!gene.st_print[p_voice.st])
  5349. continue
  5350. if(p_voice.new_name){vnt=2
  5351. break}
  5352. if(p_voice.snm)
  5353. vnt=1}
  5354. gene.vnt=vnt
  5355. return vnt==2?lsh[0]:lsh[1]}
  5356. function set_beams(sym){var s,t,g,beam,s_opp,n,m,mid_p,pu,pd,laststem=-1
  5357. for(s=sym;s;s=s.next){if(s.type!=C.NOTE){if(s.type!=C.GRACE)
  5358. continue
  5359. g=s.extra
  5360. if(g.stem==2){s_opp=s
  5361. continue}
  5362. if(!s.stem)
  5363. s.stem=s.multi||1
  5364. for(;g;g=g.next){g.stem=s.stem;g.multi=s.multi}
  5365. continue}
  5366. if(!s.stem&&s.multi)
  5367. s.stem=s.multi
  5368. if(!s.stem){mid_p=s.mid/3+18
  5369. if(beam){s.stem=laststem}else if(s.beam_st&&!s.beam_end){beam=true;pu=s.notes[s.nhd].pit;pd=s.notes[0].pit
  5370. for(g=s.next;g;g=g.next){if(g.type!=C.NOTE)
  5371. continue
  5372. if(g.stem||g.multi)
  5373. s.stem=g.stem||g.multi
  5374. if(g.notes[g.nhd].pit>pu)
  5375. pu=g.notes[g.nhd].pit
  5376. if(g.notes[0].pit<pd)
  5377. pd=g.notes[0].pit
  5378. if(g.beam_end)
  5379. break}
  5380. if(!s.stem&&g.beam_end){if(pu+pd<mid_p*2){s.stem=1}else if(pu+pd>mid_p*2){s.stem=-1}else{if(s.fmt.bstemdown)
  5381. s.stem=-1}}
  5382. if(!s.stem)
  5383. s.stem=laststem}else{n=(s.notes[s.nhd].pit+s.notes[0].pit)/2
  5384. if(n==mid_p&&s.nhd>1){for(m=0;m<s.nhd;m++){if(s.notes[m].pit>=mid_p)
  5385. break}
  5386. n=m*2<s.nhd?mid_p-1:mid_p+1}
  5387. if(n<mid_p)
  5388. s.stem=1
  5389. else if(n>mid_p||s.fmt.bstemdown)
  5390. s.stem=-1
  5391. else
  5392. s.stem=laststem}}else{if(s.beam_st&&!s.beam_end)
  5393. beam=true}
  5394. if(s.beam_end)
  5395. beam=false;laststem=s.stem;if(s_opp){for(g=s_opp.extra;g;g=g.next)
  5396. g.stem=-laststem;s_opp.stem=-laststem;s_opp=null}}}
  5397. function same_head(s1,s2){var i1,i2,l1,l2,head,i11,i12,i21,i22,sh1,sh2,shu=s1.fmt.shiftunison||0
  5398. if(shu>=3)
  5399. return false
  5400. if((l1=s1.dur)>=C.BLEN)
  5401. return false
  5402. if((l2=s2.dur)>=C.BLEN)
  5403. return false
  5404. if(s1.stemless&&s2.stemless)
  5405. return false
  5406. if(s1.dots!=s2.dots){if(shu&1||s1.dots*s2.dots!=0)
  5407. return false}
  5408. if(s1.stem*s2.stem>0)
  5409. return false
  5410. i1=i2=0
  5411. if(s1.notes[0].pit>s2.notes[0].pit){if(s1.stem<0)
  5412. return false
  5413. while(s2.notes[i2].pit!=s1.notes[0].pit){if(++i2>s2.nhd)
  5414. return false}}else if(s1.notes[0].pit<s2.notes[0].pit){if(s2.stem<0)
  5415. return false
  5416. while(s2.notes[0].pit!=s1.notes[i1].pit){if(++i1>s1.nhd)
  5417. return false}}
  5418. if(s2.notes[i2].acc!=s1.notes[i1].acc)
  5419. return false;i11=i1;i21=i2;sh1=s1.notes[i1].shhd;sh2=s2.notes[i2].shhd
  5420. do{i1++;i2++
  5421. if(i1>s1.nhd){break}
  5422. if(i2>s2.nhd){break}
  5423. if(s2.notes[i2].acc!=s1.notes[i1].acc)
  5424. return false
  5425. if(sh1<s1.notes[i1].shhd)
  5426. sh1=s1.notes[i1].shhd
  5427. if(sh2<s2.notes[i2].shhd)
  5428. sh2=s2.notes[i2].shhd}while(s2.notes[i2].pit==s1.notes[i1].pit)
  5429. if(i1<=s1.nhd){if(i2<=s2.nhd)
  5430. return false
  5431. if(s2.stem>0)
  5432. return false}else if(i2<=s2.nhd){if(s1.stem>0)
  5433. return false}
  5434. i12=i1;i22=i2;head=0
  5435. if(l1!=l2){if(l1<l2){l1=l2;l2=s1.dur}
  5436. if(l1<C.BLEN/2){if(s2.dots)
  5437. head=2
  5438. else if(s1.dots)
  5439. head=1}else if(l2<C.BLEN/4){if(shu&2)
  5440. return false
  5441. head=s2.dur>=C.BLEN/2?2:1}else{return false}}
  5442. if(!head)
  5443. head=s1.p_v.scale<s2.p_v.scale?2:1
  5444. if(head==1){for(i2=i21;i2<i22;i2++){s2.notes[i2].invis=true
  5445. delete s2.notes[i2].acc}
  5446. for(i2=0;i2<=s2.nhd;i2++)
  5447. s2.notes[i2].shhd+=sh1}else{for(i1=i11;i1<i12;i1++){s1.notes[i1].invis=true
  5448. delete s1.notes[i1].acc}
  5449. for(i1=0;i1<=s1.nhd;i1++)
  5450. s1.notes[i1].shhd+=sh2}
  5451. return true}
  5452. function unison_acc(s1,s2,i1,i2){var m,d,acc
  5453. acc=s2.notes[i2].acc
  5454. if(!acc){d=w_note[s2.head]*2+s2.xmx+s1.notes[i1].shac+2
  5455. acc=s1.notes[i1].acc
  5456. if(typeof acc=="object")
  5457. d+=2
  5458. if(s2.dots)
  5459. d+=6
  5460. for(m=0;m<=s1.nhd;m++){s1.notes[m].shhd+=d;s1.notes[m].shac-=d}
  5461. s1.xmx+=d}else{d=w_note[s1.head]*2+s1.xmx+s2.notes[i2].shac+2
  5462. if(typeof acc=="object")
  5463. d+=2
  5464. if(s1.dots)
  5465. d+=6
  5466. for(m=0;m<=s2.nhd;m++){s2.notes[m].shhd+=d;s2.notes[m].shac-=d}
  5467. s2.xmx+=d}}
  5468. var MAXPIT=48*2
  5469. function set_left(s){var m,i,j,shift,w_base=w_note[s.head],w=w_base,left=[]
  5470. for(i=0;i<MAXPIT;i++)
  5471. left.push(-100)
  5472. if(s.nflags>-2){if(s.stem>0){w=-w;i=s.notes[0].pit*2;j=(Math.ceil((s.ymx-2)/3)+18)*2}else{i=(Math.ceil((s.ymn+2)/3)+18)*2;j=s.notes[s.nhd].pit*2}
  5473. if(i<0)
  5474. i=0
  5475. if(j>=MAXPIT)
  5476. j=MAXPIT-1
  5477. while(i<=j)
  5478. left[i++]=w}
  5479. shift=s.notes[s.stem>0?0:s.nhd].shhd;for(m=0;m<=s.nhd;m++){w=-s.notes[m].shhd+w_base+shift;i=s.notes[m].pit*2
  5480. if(i<0)
  5481. i=0
  5482. else if(i>=MAXPIT-1)
  5483. i=MAXPIT-2
  5484. if(w>left[i])
  5485. left[i]=w
  5486. if(s.head!=C.SQUARE)
  5487. w-=1
  5488. if(w>left[i-1])
  5489. left[i-1]=w
  5490. if(w>left[i+1])
  5491. left[i+1]=w}
  5492. return left}
  5493. function set_right(s){var m,i,j,k,shift,w_base=w_note[s.head],w=w_base,flags=s.nflags>0&&s.beam_st&&s.beam_end,right=[]
  5494. for(i=0;i<MAXPIT;i++)
  5495. right.push(-100)
  5496. if(s.nflags>-2){if(s.stem<0){w=-w;i=(Math.ceil((s.ymn+2)/3)+18)*2;j=s.notes[s.nhd].pit*2;k=i+4}else{i=s.notes[0].pit*2;j=(Math.ceil((s.ymx-2)/3)+18)*2}
  5497. if(i<0)
  5498. i=0
  5499. if(j>MAXPIT)
  5500. j=MAXPIT
  5501. while(i<j)
  5502. right[i++]=w}
  5503. if(flags){if(s.stem>0){if(s.xmx==0)
  5504. i=s.notes[s.nhd].pit*2
  5505. else
  5506. i=s.notes[0].pit*2;i+=4
  5507. if(i<0)
  5508. i=0
  5509. for(;i<MAXPIT&&i<=j-4;i++)
  5510. right[i]=11}else{i=k
  5511. if(i<0)
  5512. i=0
  5513. for(;i<MAXPIT&&i<=s.notes[0].pit*2-4;i++)
  5514. right[i]=3.5}}
  5515. shift=s.notes[s.stem>0?0:s.nhd].shhd
  5516. for(m=0;m<=s.nhd;m++){w=s.notes[m].shhd+w_base-shift;i=s.notes[m].pit*2
  5517. if(i<0)
  5518. i=0
  5519. else if(i>=MAXPIT-1)
  5520. i=MAXPIT-2
  5521. if(w>right[i])
  5522. right[i]=w
  5523. if(s.head!=C.SQUARE)
  5524. w-=1
  5525. if(w>right[i-1])
  5526. right[i-1]=w
  5527. if(w>right[i+1])
  5528. right[i+1]=w}
  5529. return right}
  5530. function set_overlap(){var s,s1,s2,s3,i,i1,i2,m,sd,t,dp,d,d2,dr,dr2,dx,left1,right1,left2,right2,right3,pl,pr,sy=cur_sy
  5531. function v_invert(){s1=s2;s2=s;d=d2;pl=left1;pr=right1;dr2=dr}
  5532. for(s=tsfirst;s;s=s.ts_next){if(s.type!=C.NOTE||s.invis){if(s.type==C.STAVES)
  5533. sy=s.sy
  5534. continue}
  5535. if(s.xstem&&s.ts_prev.stem<0){for(m=0;m<=s.nhd;m++){s.notes[m].shhd-=7;s.notes[m].shac+=16}}
  5536. s2=s
  5537. while(1){s2=s2.ts_next
  5538. if(!s2)
  5539. break
  5540. if(s2.time!=s.time){s2=null
  5541. break}
  5542. if(s2.type==C.NOTE&&!s2.invis&&s2.st==s.st)
  5543. break}
  5544. if(!s2)
  5545. continue
  5546. s1=s
  5547. if(sy.voices[s1.v].range<sy.voices[s2.v].range)
  5548. s2.dot_low=true
  5549. else
  5550. s1.dot_low=true
  5551. if(s1.ymn>s2.ymx||s1.ymx<s2.ymn)
  5552. continue
  5553. if(same_head(s1,s2))
  5554. continue
  5555. if(!s1.dots&&!s2.dots)
  5556. if((s1.stem>0&&s2.stem<0&&s1.notes[0].pit==s2.notes[s2.nhd].pit+1)||(s1.stem<0&&s2.stem>0&&s1.notes[s1.nhd].pit+1==s2.notes[0].pit)){if(s1.stem<0){s1=s2;s2=s}
  5557. d=s1.notes[0].shhd+7
  5558. for(m=0;m<=s2.nhd;m++)
  5559. s2.notes[m].shhd+=d
  5560. s2.xmx+=d
  5561. s1.xmx=s2.xmx
  5562. continue}
  5563. right1=set_right(s1);left2=set_left(s2);s3=s1.ts_prev
  5564. if(s3&&s3.time==s1.time&&s3.st==s1.st&&s3.type==C.NOTE&&!s3.invis){right3=set_right(s3)
  5565. for(i=0;i<MAXPIT;i++){if(right3[i]>right1[i])
  5566. right1[i]=right3[i]}}else{s3=null}
  5567. d=-10
  5568. for(i=0;i<MAXPIT;i++){if(left2[i]+right1[i]>d)
  5569. d=left2[i]+right1[i]}
  5570. if(d<-3&&((s2.notes[0].pit&1)||!(s1.dots||s2.dots)||(!(s1.notes[s1.nhd].pit==s2.notes[0].pit+2&&s1.dot_low)&&!(s1.notes[s1.nhd].pit+2==s2.notes[0].pit&&s2.dot_low))))
  5571. continue
  5572. right2=set_right(s2);left1=set_left(s1)
  5573. if(s3){right3=set_left(s3)
  5574. for(i=0;i<MAXPIT;i++){if(right3[i]>left1[i])
  5575. left1[i]=right3[i]}}
  5576. d2=dr=dr2=-100
  5577. for(i=0;i<MAXPIT;i++){if(left1[i]+right2[i]>d2)
  5578. d2=left1[i]+right2[i]
  5579. if(right2[i]>dr2)
  5580. dr2=right2[i]
  5581. if(right1[i]>dr)
  5582. dr=right1[i]}
  5583. t=0;i1=s1.nhd;i2=s2.nhd
  5584. while(1){dp=s1.notes[i1].pit-s2.notes[i2].pit
  5585. switch(dp){case 2:if(!(s1.notes[i1].pit&1))
  5586. s1.dot_low=false
  5587. break
  5588. case 1:if(s1.notes[i1].pit&1)
  5589. s2.dot_low=true
  5590. else
  5591. s1.dot_low=false
  5592. break
  5593. case 0:if(s1.notes[i1].acc!=s2.notes[i2].acc){t=-1
  5594. break}
  5595. if(s2.notes[i2].acc){if(!s1.notes[i1].acc)
  5596. s1.notes[i1].acc=s2.notes[i2].acc
  5597. s2.notes[i2].acc=0}
  5598. if(s1.dots&&s2.dots&&(s1.notes[i1].pit&1))
  5599. t=1
  5600. break
  5601. case-1:if(s1.notes[i1].pit&1)
  5602. s2.dot_low=false
  5603. else
  5604. s1.dot_low=true
  5605. break
  5606. case-2:if(!(s1.notes[i1].pit&1))
  5607. s2.dot_low=false
  5608. break}
  5609. if(t<0)
  5610. break
  5611. if(dp>=0){if(--i1<0)
  5612. break}
  5613. if(dp<=0){if(--i2<0)
  5614. break}}
  5615. if(t<0){unison_acc(s1,s2,i1,i2)
  5616. continue}
  5617. sd=0;if(s1.dots){if(s2.dots){if(!t)
  5618. sd=1}else{v_invert()}}else if(s2.dots){if(d2+dr<d+dr2)
  5619. sd=1}
  5620. pl=left2;pr=right2
  5621. if(!s3&&d2+dr<d+dr2)
  5622. v_invert()
  5623. d+=3
  5624. if(d<0)
  5625. d=0;m=s1.stem>=0?0:s1.nhd;d+=s1.notes[m].shhd;m=s2.stem>=0?0:s2.nhd;d-=s2.notes[m].shhd
  5626. if(s1.dots){dx=7.7+s1.xmx+
  5627. 3.5*s1.dots-3.5+
  5628. 3;if(!sd){d2=-100;for(i1=0;i1<=s1.nhd;i1++){i=s1.notes[i1].pit
  5629. if(!(i&1)){if(!s1.dot_low)
  5630. i++
  5631. else
  5632. i--}
  5633. i*=2
  5634. if(i<1)
  5635. i=1
  5636. else if(i>=MAXPIT-1)
  5637. i=MAXPIT-2
  5638. if(pl[i]>d2)
  5639. d2=pl[i]
  5640. if(pl[i-1]+1>d2)
  5641. d2=pl[i-1]+1
  5642. if(pl[i+1]+1>d2)
  5643. d2=pl[i+1]+1}
  5644. if(dx+d2+2>d)
  5645. d=dx+d2+2}else{if(dx<d+dr2+s2.xmx){d2=0
  5646. for(i1=0;i1<=s1.nhd;i1++){i=s1.notes[i1].pit
  5647. if(!(i&1)){if(!s1.dot_low)
  5648. i++
  5649. else
  5650. i--}
  5651. i*=2
  5652. if(i<1)
  5653. i=1
  5654. else if(i>=MAXPIT-1)
  5655. i=MAXPIT-2
  5656. if(pr[i]>d2)
  5657. d2=pr[i]
  5658. if(pr[i-1]+1>d2)
  5659. d2=pr[i-1]=1
  5660. if(pr[i+1]+1>d2)
  5661. d2=pr[i+1]+1}
  5662. if(d2>4.5&&7.7+s1.xmx+2<d+d2+s2.xmx)
  5663. s2.xmx=d2+3-7.7}}}
  5664. for(m=s2.nhd;m>=0;m--){s2.notes[m].shhd+=d}
  5665. s2.xmx+=d
  5666. if(sd)
  5667. s1.xmx=s2.xmx}}
  5668. Abc.prototype.set_stems=function(){var s,s2,g,slen,scale,ymn,ymx,nflags,ymin,ymax
  5669. for(s=tsfirst;s;s=s.ts_next){if(s.type!=C.NOTE){if(s.type!=C.GRACE)
  5670. continue
  5671. ymin=ymax=s.mid
  5672. for(g=s.extra;g;g=g.next){slen=GSTEM
  5673. if(g.nflags>1)
  5674. slen+=1.2*(g.nflags-1);ymn=3*(g.notes[0].pit-18);ymx=3*(g.notes[g.nhd].pit-18)
  5675. if(s.stem>=0){g.y=ymn;g.ys=ymx+slen;ymx=Math.round(g.ys)}else{g.y=ymx;g.ys=ymn-slen;ymn=Math.round(g.ys)}
  5676. ymx+=4
  5677. ymn-=4
  5678. if(ymn<ymin)
  5679. ymin=ymn
  5680. else if(ymx>ymax)
  5681. ymax=ymx;g.ymx=ymx;g.ymn=ymn}
  5682. s.ymx=ymax;s.ymn=ymin
  5683. continue}
  5684. set_head_shift(s);nflags=s.nflags
  5685. if(s.beam_st&&!s.beam_end){if(s.feathered_beam)
  5686. nflags=++s.nflags
  5687. for(s2=s.next;;s2=s2.next){if(s2.type==C.NOTE){if(s.feathered_beam)
  5688. s2.nflags++
  5689. if(s2.beam_end)
  5690. break}}
  5691. if(s2.nflags>nflags)
  5692. nflags=s2.nflags}else if(!s.beam_st&&s.beam_end){for(s2=s.prev;;s2=s2.prev){if(s2.beam_st)
  5693. break}
  5694. if(s2.nflags>nflags)
  5695. nflags=s2.nflags}
  5696. slen=s.fmt.stemheight
  5697. switch(nflags){case 2:slen+=0;break
  5698. case 3:slen+=4;break
  5699. case 4:slen+=8;break
  5700. case 5:slen+=12;break}
  5701. if((scale=s.p_v.scale)!=1)
  5702. slen*=(scale+1)*.5;ymn=3*(s.notes[0].pit-18)
  5703. if(s.nhd>0){slen-=2;ymx=3*(s.notes[s.nhd].pit-18)}else{ymx=ymn}
  5704. if(s.ntrem)
  5705. slen+=2*s.ntrem
  5706. if(s.stemless){if(s.stem>=0){s.y=ymn;s.ys=ymx}else{s.ys=ymn;s.y=ymx}
  5707. s.ymx=ymx+4;s.ymn=ymn-4}else if(s.stem>=0){if(s.notes[s.nhd].pit>26&&(nflags<=0||!s.beam_st||!s.beam_end)){slen-=2
  5708. if(s.notes[s.nhd].pit>28)
  5709. slen-=2}
  5710. s.y=ymn
  5711. if(s.notes[0].tie)
  5712. ymn-=3;s.ymn=ymn-4;s.ys=ymx+slen
  5713. if(s.ys<s.mid)
  5714. s.ys=s.mid;s.ymx=(s.ys+2.5)|0}else{if(s.notes[0].pit<18&&(nflags<=0||!s.beam_st||!s.beam_end)){slen-=2
  5715. if(s.notes[0].pit<16)
  5716. slen-=2}
  5717. s.ys=ymn-slen
  5718. if(s.ys>s.mid)
  5719. s.ys=s.mid;s.ymn=(s.ys-2.5)|0;s.y=ymx
  5720. if(s.notes[s.nhd].tie)
  5721. ymx+=3;s.ymx=ymx+4}}}
  5722. var blocks=[]
  5723. Abc.prototype.block_gen=function(s){switch(s.subtype){case"leftmargin":case"rightmargin":case"pagescale":case"pagewidth":case"scale":case"staffwidth":self.set_format(s.subtype,s.param)
  5724. break
  5725. case"mc_start":if(multicol){error(1,s,"No end of the previous %%multicol")
  5726. break}
  5727. multicol={posy:posy,maxy:posy,lm:cfmt.leftmargin,rm:cfmt.rightmargin,w:cfmt.pagewidth,sc:cfmt.scale}
  5728. break
  5729. case"mc_new":if(!multicol){error(1,s,"%%multicol new without start")
  5730. break}
  5731. if(posy>multicol.maxy)
  5732. multicol.maxy=posy
  5733. cfmt.leftmargin=multicol.lm
  5734. cfmt.rightmargin=multicol.rm
  5735. cfmt.pagewidth=multicol.w
  5736. cfmt.scale=multicol.sc
  5737. posy=multicol.posy
  5738. img.chg=1
  5739. break
  5740. case"mc_end":if(!multicol){error(1,s,"%%multicol end without start")
  5741. break}
  5742. if(posy<multicol.maxy)
  5743. posy=multicol.maxy
  5744. cfmt.leftmargin=multicol.lm
  5745. cfmt.rightmargin=multicol.rm
  5746. cfmt.pagewidth=multicol.w
  5747. cfmt.scale=multicol.sc
  5748. multicol=undefined
  5749. blk_flush()
  5750. img.chg=1
  5751. break
  5752. case"ml":blk_flush()
  5753. user.img_out(s.text)
  5754. break
  5755. case"newpage":if(!user.page_format)
  5756. break
  5757. blk_flush()
  5758. if(blkdiv<0)
  5759. user.img_out('</div>')
  5760. blkdiv=2
  5761. break
  5762. case"sep":set_page();vskip(s.sk1);output+='<path class="stroke"\n\td="M';out_sxsy((img.width-s.l)/2-img.lm,' ',0)
  5763. output+='h'+s.l.toFixed(1)+'"/>\n';vskip(s.sk2);break
  5764. case"text":set_font(s.font)
  5765. use_font(s.font)
  5766. write_text(s.text,s.opt)
  5767. break
  5768. case"title":write_title(s.text,true)
  5769. break
  5770. case"vskip":vskip(s.sk);break}}
  5771. function sym_staff_move(st){for(var s=tsfirst;s;s=s.ts_next){if(s.nl)
  5772. break
  5773. if(s.st==st&&s.type!=C.CLEF){s.st++
  5774. if(s.type!=C.TEMPO)
  5775. s.invis=true}}}
  5776. function set_piece(){var s,last,p_voice,st,v,nv,tmp,non_empty=[],non_empty_gl=[],sy=cur_sy
  5777. function reset_staff(st){var p_staff=staff_tb[st],sy_staff=sy.staves[st]
  5778. if(!p_staff)
  5779. p_staff=staff_tb[st]={}
  5780. p_staff.y=0;p_staff.stafflines=sy_staff.stafflines;p_staff.staffscale=sy_staff.staffscale;p_staff.ann_top=p_staff.ann_bot=0}
  5781. function set_brace(){var st,i,empty_fl,n=sy.staves.length
  5782. for(st=0;st<n;st++){if(!(sy.staves[st].flags&(OPEN_BRACE|OPEN_BRACE2)))
  5783. continue
  5784. empty_fl=0;i=st
  5785. while(st<n){empty_fl|=non_empty[st]?1:2
  5786. if(sy.staves[st].flags&(CLOSE_BRACE|CLOSE_BRACE2))
  5787. break
  5788. st++}
  5789. if(empty_fl==3){while(i<=st){non_empty[i]=true;non_empty_gl[i++]=true}}}}
  5790. function set_top_bot(){var st,p_staff,i,j,l
  5791. for(st=0;st<=nstaff;st++){p_staff=staff_tb[st]
  5792. p_staff.hlu=[]
  5793. p_staff.hld=[]
  5794. l=p_staff.stafflines.length;p_staff.topbar=6*(l-1)
  5795. for(i=0;i<l-1;i++){switch(p_staff.stafflines[i]){case'.':case'-':continue}
  5796. break}
  5797. p_staff.botline=p_staff.botbar=i*6
  5798. if(i>=l-2){if(p_staff.stafflines[i]!='.'){p_staff.botbar-=6;p_staff.topbar+=6}else{p_staff.botbar-=12;p_staff.topbar+=12
  5799. continue}}
  5800. if(!non_empty_gl[st])
  5801. continue
  5802. p_staff.hll=17+i*2
  5803. p_staff.hlmap=new Int8Array(new Array((l-i+1)*2))
  5804. for(j=1;i<l;i++,j+=2){switch(p_staff.stafflines[i]){case'|':case'[':p_staff.hlmap[j-1]=1;p_staff.hlmap[j]=1;p_staff.hlmap[j+1]=1
  5805. break}}}}
  5806. if(tsfirst.type==C.STAVES){s=tsfirst
  5807. tsfirst=tsfirst.ts_next
  5808. tsfirst.ts_prev=null
  5809. if(s.seqst)
  5810. tsfirst.seqst=true
  5811. s.p_v.sym=s.next
  5812. if(s.next)
  5813. s.next.prev=null}
  5814. nstaff=sy.nstaff
  5815. for(st=0;st<=nstaff;st++)
  5816. reset_staff(st);for(s=tsfirst;s;s=s.ts_next){if(s.nl)
  5817. break
  5818. switch(s.type){case C.STAVES:set_brace();sy.st_print=new Uint8Array(non_empty);sy=s.sy;while(nstaff<sy.nstaff)
  5819. reset_staff(++nstaff)
  5820. non_empty=[]
  5821. continue
  5822. case C.BLOCK:if(!s.play){blocks.push(s)
  5823. unlksym(s)}else if(s.ts_next&&s.ts_next.shrink)
  5824. s.ts_next.shrink=0
  5825. continue}
  5826. st=s.st
  5827. if(st>nstaff){switch(s.type){case C.CLEF:staff_tb[st].clef=s
  5828. break
  5829. case C.KEY:s.p_v.ckey=s
  5830. break
  5831. case C.METER:s.p_v.meter=s
  5832. break}
  5833. unlksym(s)
  5834. continue}
  5835. if(non_empty[st])
  5836. continue
  5837. switch(s.type){default:continue
  5838. case C.BAR:if(s.bar_mrep||sy.staves[st].staffnonote>1)
  5839. break
  5840. continue
  5841. case C.GRACE:break
  5842. case C.NOTE:case C.REST:case C.SPACE:case C.MREST:if(sy.staves[st].staffnonote>1)
  5843. break
  5844. if(s.invis)
  5845. continue
  5846. if(sy.staves[st].staffnonote||s.type==C.NOTE)
  5847. break
  5848. continue}
  5849. non_empty_gl[st]=non_empty[st]=true}
  5850. tsnext=s;set_brace()
  5851. sy.st_print=new Uint8Array(non_empty);set_top_bot()
  5852. for(st=0;st<nstaff;st++){if(!non_empty_gl[st])
  5853. sym_staff_move(st)}
  5854. if(!non_empty_gl[nstaff])
  5855. staff_tb[nstaff].topbar=0
  5856. if(tsnext){s=tsnext;delete s.nl;last=s.ts_prev;last.ts_next=null;nv=voice_tb.length
  5857. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  5858. if(p_voice.sym&&p_voice.sym.time<=tsnext.time){for(s=tsnext.ts_prev;s;s=s.ts_prev){if(s.v==v){p_voice.s_next=s.next;s.next=null;break}}
  5859. if(s)
  5860. continue}
  5861. p_voice.s_next=p_voice.sym;p_voice.sym=null}}
  5862. init_music_line()
  5863. gene.st_print=new Uint8Array(non_empty_gl)}
  5864. Abc.prototype.set_sym_glue=function(width){var s,g,ll,x,some_grace,spf,xmin=0,xx=0,xs=0,xse=0
  5865. for(s=tsfirst;s;s=s.ts_next){if(s.type==C.GRACE&&!some_grace)
  5866. some_grace=s
  5867. if(s.seqst){xmin+=s.shrink
  5868. if(xmin>width){error(1,s,"Line too much shrunk $1 $2 $3",xmin.toFixed(1),xx.toFixed(1),width.toFixed(1))
  5869. break}
  5870. if(s.space){if(s.space<s.shrink){xse+=s.shrink;xx+=s.shrink}else{xx+=s.space}}else{xs+=s.shrink}}}
  5871. if(!xx){realwidth=0
  5872. return}
  5873. ll=!tsnext||(tsnext.type==C.BLOCK&&!tsnext.play)||blocks.length
  5874. s=tsfirst
  5875. if(xmin>=width){x=0
  5876. for(;s;s=s.ts_next){if(s.seqst)
  5877. x+=s.shrink;s.x=x}
  5878. spf_last=0}else if((ll&&xx+xs>width*(1-s.fmt.stretchlast))||(!ll&&(xx+xs>width||s.fmt.stretchstaff))){if(xx==xse)
  5879. xx+=5
  5880. for(var cnt=4;--cnt>=0;){spf=(width-xs-xse)/(xx-xse);xx=0;xse=0;x=0
  5881. for(s=tsfirst;s;s=s.ts_next){if(s.seqst){if(s.space){if(s.space*spf<=s.shrink){xse+=s.shrink;xx+=s.shrink;x+=s.shrink}else{xx+=s.space;x+=s.space*spf}}else{x+=s.shrink}}
  5882. s.x=x}
  5883. if(Math.abs(x-width)<0.1)
  5884. break}
  5885. spf_last=spf}else{spf=1-s.fmt.maxshrink
  5886. if(spf_last&&xx*spf_last+xs<width)
  5887. spf=spf_last
  5888. x=0
  5889. for(;s;s=s.ts_next){if(s.seqst)
  5890. x+=s.space<=s.shrink?s.shrink:s.shrink*(1-spf)+s.space*spf
  5891. s.x=x}}
  5892. realwidth=x
  5893. for(s=some_grace;s;s=s.ts_next){if(s.type!=C.GRACE)
  5894. continue
  5895. if(s.gr_shift)
  5896. x=s.prev.x+s.prev.wr
  5897. else
  5898. x=s.x-s.wl
  5899. for(g=s.extra;g;g=g.next)
  5900. g.x+=x}}
  5901. function set_sym_line(){var p_v,s,v=voice_tb.length
  5902. while(--v>=0){p_v=voice_tb[v]
  5903. if(p_v.sym&&p_v.s_prev)
  5904. p_v.sym.prev=p_v.s_prev
  5905. s=p_v.s_next
  5906. p_v.s_next=null
  5907. p_v.sym=s
  5908. if(s){if(s.prev)
  5909. s.prev.next=s
  5910. p_v.s_prev=s.prev
  5911. s.prev=null}else{p_v.s_prev=null}}}
  5912. function set_posx(){posx=img.lm/cfmt.scale}
  5913. function gen_init(){var s=tsfirst,tim=s.time
  5914. for(;s;s=s.ts_next){if(s.time!=tim){set_page()
  5915. return}
  5916. switch(s.type){case C.NOTE:case C.REST:case C.MREST:case C.SPACE:set_page()
  5917. return
  5918. default:continue
  5919. case C.STAVES:cur_sy=s.sy
  5920. continue
  5921. case C.BLOCK:if(s.play)
  5922. continue
  5923. self.block_gen(s)
  5924. break}
  5925. unlksym(s)
  5926. if(s.p_v.s_next==s)
  5927. s.p_v.s_next=s.next}
  5928. tsfirst=null}
  5929. Abc.prototype.output_music=function(){var v,lwidth,indent,lsh,line_height,ts1st,tslast,p_v,nv=voice_tb.length
  5930. set_global()
  5931. if(nv>1)
  5932. self.set_stem_dir()
  5933. for(v=0;v<nv;v++)
  5934. set_beams(voice_tb[v].sym);self.set_stems()
  5935. set_acc_shft()
  5936. if(nv>1){set_rest_offset();set_overlap()}
  5937. set_allsymwidth(1)
  5938. lsh=get_lshift()
  5939. if(cfmt.singleline){v=get_ck_width();lwidth=lsh[0]+v[0]+v[1]+get_width(tsfirst,null)[0]
  5940. v=cfmt.singleline==2?get_lwidth():lwidth
  5941. if(v>lwidth)
  5942. lwidth=v
  5943. else
  5944. img.width=lwidth*cfmt.scale+img.lm+img.rm+2}else{lwidth=get_lwidth();cut_tune(lwidth,lsh)}
  5945. gen_init()
  5946. if(!tsfirst)
  5947. return
  5948. ts1st=tsfirst
  5949. v=nv
  5950. while(--v>=0)
  5951. voice_tb[v].osym=voice_tb[v].sym
  5952. spf_last=0
  5953. while(1){set_piece();indent=set_indent(lsh)
  5954. if(!line_height&&cfmt.indent&&indent<cfmt.indent)
  5955. indent=cfmt.indent
  5956. self.set_sym_glue(lwidth-indent)
  5957. if(realwidth){if(indent)
  5958. posx+=indent;draw_sym_near();line_height=set_staff();draw_systems(indent);draw_all_sym();delayed_update();if(output)
  5959. vskip(line_height)
  5960. if(indent)
  5961. posx-=indent}
  5962. blk_flush()
  5963. while(blocks.length)
  5964. self.block_gen(blocks.shift())
  5965. if(tslast)
  5966. tslast.ts_next.ts_prev=tslast
  5967. if(!tsnext)
  5968. break
  5969. tsnext.ts_prev.ts_next=tsfirst=tsnext
  5970. gen_init()
  5971. if(!tsfirst)
  5972. break
  5973. tslast=tsfirst.ts_prev
  5974. tsfirst.ts_prev=null;set_sym_line();lwidth=get_lwidth()}
  5975. tsfirst=ts1st
  5976. v=nv
  5977. while(--v>=0){p_v=voice_tb[v]
  5978. if(p_v.sym&&p_v.s_prev)
  5979. p_v.sym.prev=p_v.s_prev
  5980. p_v.sym=p_v.osym}}
  5981. var a_gch,a_dcn=[],multicol,maps={}
  5982. var qplet_tb=new Int8Array([0,1,3,2,3,0,2,0,3,0]),ntb="CDEFGABcdefgab"
  5983. function set_ref(s){s.fname=parse.fname;s.istart=parse.istart;s.iend=parse.iend}
  5984. function new_clef(clef_def){var s={type:C.CLEF,clef_line:2,clef_type:"t",v:curvoice.v,p_v:curvoice,time:curvoice.time,dur:0},i=1
  5985. set_ref(s)
  5986. switch(clef_def[0]){case'"':i=clef_def.indexOf('"',1);s.clef_name=clef_def.slice(1,i);i++
  5987. break
  5988. case'a':if(clef_def[1]=='u'){s.clef_type="a";s.clef_auto=true;i=4
  5989. break}
  5990. i=4
  5991. case'C':s.clef_type="c";s.clef_line=3
  5992. break
  5993. case'b':i=4
  5994. case'F':s.clef_type="b";s.clef_line=4
  5995. break
  5996. case'n':i=4
  5997. s.invis=true
  5998. break
  5999. case't':if(clef_def[1]=='e'){s.clef_type="c";s.clef_line=4
  6000. break}
  6001. i=6
  6002. case'G':break
  6003. case'p':i=4
  6004. case'P':s.clef_type="p";s.clef_line=3;break
  6005. default:syntax(1,"Unknown clef '$1'",clef_def)
  6006. return}
  6007. if(clef_def[i]>='1'&&clef_def[i]<='9'){s.clef_line=+clef_def[i]
  6008. i++}
  6009. delete curvoice.snd_oct
  6010. if(clef_def[i+1]!='8'&&clef_def[i+1]!='1')
  6011. return s
  6012. switch(clef_def[i]){case'^':s.clef_oct_transp=true
  6013. case'+':s.clef_octave=clef_def[i+1]=='8'?7:14
  6014. if(!s.clef_oct_transp)
  6015. curvoice.snd_oct=clef_def[i+1]==8?12:24
  6016. break
  6017. case'_':s.clef_oct_transp=true
  6018. case'-':s.clef_octave=clef_def[i+1]=='8'?-7:-14
  6019. if(!s.clef_oct_transp)
  6020. curvoice.snd_oct=clef_def[i+1]==8?-12:-24
  6021. break}
  6022. return s}
  6023. function get_interval(param,score){var i,val,tmp,note,pit
  6024. tmp=new scanBuf;tmp.buffer=param
  6025. pit=[]
  6026. for(i=0;i<2;i++){note=tmp.buffer[tmp.index]?parse_acc_pit(tmp):null
  6027. if(!note){if(i!=1||!score){syntax(1,errs.bad_transp)
  6028. return}
  6029. pit[i]=242}else{if(typeof note.acc=="object"){syntax(1,errs.bad_transp)
  6030. return}
  6031. pit[i]=abc2svg.pab40(note.pit,note.acc)}}
  6032. return pit[1]-pit[0]}
  6033. function nt_trans(nt,a){var ak,an,d,b40,n
  6034. if(typeof a=="object"){n=a[0]
  6035. d=a[1]
  6036. a=n>0?1:-1}
  6037. b40=abc2svg.pab40(nt.pit,a)
  6038. +curvoice.tr_sco
  6039. nt.pit=abc2svg.b40p(b40)
  6040. an=abc2svg.b40a(b40)
  6041. if(!d){if(an==-3)
  6042. return an
  6043. a=an
  6044. if(nt.acc){if(!a)
  6045. a=3}else{if(!curvoice.ckey.k_none)
  6046. a=0}
  6047. nt.acc=a
  6048. return an}
  6049. switch(an){case-2:if(n>0)
  6050. n-=d*2
  6051. else
  6052. n-=d
  6053. break
  6054. case-1:if(n>0)
  6055. n-=d
  6056. break
  6057. case 0:case 3:if(n>0)
  6058. n-=d
  6059. else
  6060. n+=d
  6061. break
  6062. case 1:if(n<0)
  6063. n+=d
  6064. break
  6065. case 2:if(n<0)
  6066. n+=d*2
  6067. else
  6068. n+=d
  6069. break}
  6070. nt.acc=[n,d]
  6071. return an}
  6072. function set_linebreak(param){var i,item
  6073. for(i=0;i<128;i++){if(char_tb[i]=="\n")
  6074. char_tb[i]=nil}
  6075. param=param.split(/\s+/)
  6076. for(i=0;i<param.length;i++){item=param[i]
  6077. switch(item){case'!':case'$':case'*':case';':case'?':case'@':break
  6078. case"<none>":continue
  6079. case"<EOL>":item='\n'
  6080. break
  6081. default:syntax(1,"Bad value '$1' in %%linebreak - ignored",item)
  6082. continue}
  6083. char_tb[item.charCodeAt(0)]='\n'}}
  6084. function set_user(parm){var k,c,v,a=parm.match(/(.)[=\s]*(\[I:.+\]|".+"|!.+!)$/)
  6085. if(!a){syntax(1,'Lack of starting [, ! or " in U: / %%user')
  6086. return}
  6087. c=a[1];v=a[2]
  6088. if(c[0]=='\\'){if(c[1]=='t')
  6089. c='\t'
  6090. else if(!c[1])
  6091. c=' '}
  6092. k=c.charCodeAt(0)
  6093. if(k>=128){syntax(1,errs.not_ascii)
  6094. return}
  6095. switch(char_tb[k][0]){case'0':case'd':case'i':case' ':break
  6096. case'"':case'!':case'[':if(char_tb[k].length>1)
  6097. break
  6098. default:syntax(1,"Bad user character '$1'",c)
  6099. return}
  6100. switch(v){case"!beambreak!":v=" "
  6101. break
  6102. case"!ignore!":v="i"
  6103. break
  6104. case"!nil!":case"!none!":v="d"
  6105. break}
  6106. char_tb[k]=v}
  6107. function get_st_lines(param){if(!param)
  6108. return
  6109. if(/^[\]\[|.-]+$/.test(param))
  6110. return param.replace(/\]/g,'[')
  6111. var n=+param
  6112. switch(n){case 0:return"..."
  6113. case 1:return"..|"
  6114. case 2:return".||"
  6115. case 3:return".|||"}
  6116. if(isNaN(n)||n<0||n>16)
  6117. return
  6118. return"||||||||||||||||".slice(0,n)}
  6119. function new_block(subtype){var c_v,s={type:C.BLOCK,subtype:subtype,dur:0}
  6120. c_v=curvoice
  6121. if(subtype.slice(0,4)!="midi")
  6122. curvoice=voice_tb[0]
  6123. sym_link(s)
  6124. if(c_v)
  6125. curvoice=c_v
  6126. return s}
  6127. Abc.prototype.set_vp=function(a){var s,item,pos,val,clefpit,tr_p=0
  6128. while(1){item=a.shift()
  6129. if(!item)
  6130. break
  6131. if(item.slice(-1)=='='&&!a.length){syntax(1,errs.bad_val,item)
  6132. break}
  6133. switch(item){case"clef=":s=a.shift()
  6134. break
  6135. case"clefpitch=":item=a.shift()
  6136. if(item){val=ntb.indexOf(item[0])
  6137. if(val>=0){switch(item[1]){case"'":val+=7
  6138. break
  6139. case',':val-=7
  6140. if(item[2]==',')
  6141. val-=7
  6142. break}
  6143. clefpit=4-val
  6144. break}}
  6145. syntax(1,errs.bad_val,item)
  6146. break
  6147. case"octave=":val=+a.shift()
  6148. if(isNaN(val))
  6149. syntax(1,errs.bad_val,item)
  6150. else
  6151. curvoice.octave=val
  6152. break
  6153. case"cue=":curvoice.scale=a.shift()=='on'?.7:1
  6154. break
  6155. case"instrument=":item=a.shift()
  6156. val=item.indexOf('/')
  6157. if(val<0){val=get_interval('c'+item)
  6158. if(val==undefined)
  6159. break
  6160. curvoice.sound=val
  6161. tr_p|=2
  6162. val=0}else{val=get_interval('c'+item.slice(val+1))
  6163. if(val==undefined)
  6164. break
  6165. curvoice.sound=val
  6166. tr_p|=2
  6167. val=get_interval(item.replace('/',''))
  6168. if(val==undefined)
  6169. break}
  6170. curvoice.score=cfmt.sound?curvoice.sound:val
  6171. tr_p|=1
  6172. break
  6173. case"map=":curvoice.map=a.shift()
  6174. break
  6175. case"name=":case"nm=":curvoice.nm=a.shift()
  6176. if(curvoice.nm[0]=='"')
  6177. curvoice.nm=cnv_escape(curvoice.nm.slice(1,-1))
  6178. curvoice.new_name=true
  6179. break
  6180. case"stem=":case"pos=":if(item=="pos=")
  6181. item=a.shift().slice(1,-1).split(' ')
  6182. else
  6183. item=["stm",a.shift()];val=posval[item[1]]
  6184. if(val==undefined){syntax(1,errs.bad_val,"%%pos")
  6185. break}
  6186. switch(item[2]){case"align":val|=C.SL_ALIGN;break
  6187. case"center":val|=C.SL_CENTER;break
  6188. case"close":val|=C.SL_CLOSE;break}
  6189. if(!pos)
  6190. pos={}
  6191. pos[item[0]]=val
  6192. break
  6193. case"scale=":val=+a.shift()
  6194. if(isNaN(val)||val<.5||val>2)
  6195. syntax(1,errs.bad_val,"%%voicescale")
  6196. else
  6197. curvoice.scale=val
  6198. break
  6199. case"score=":if(cfmt.nedo){syntax(1,errs.notransp)
  6200. break}
  6201. item=a.shift()
  6202. if(cfmt.sound)
  6203. break
  6204. val=get_interval(item,true)
  6205. if(val!=undefined){curvoice.score=val
  6206. tr_p|=1}
  6207. break
  6208. case"shift=":if(cfmt.nedo){syntax(1,errs.notransp)
  6209. break}
  6210. val=get_interval(a.shift())
  6211. if(val!=undefined){curvoice.shift=val
  6212. tr_p=3}
  6213. break
  6214. case"sound=":if(cfmt.nedo){syntax(1,errs.notransp)
  6215. break}
  6216. val=get_interval(a.shift())
  6217. if(val==undefined)
  6218. break
  6219. curvoice.sound=val
  6220. if(cfmt.sound)
  6221. curvoice.score=val
  6222. tr_p|=2
  6223. break
  6224. case"subname=":case"sname=":case"snm=":curvoice.snm=a.shift()
  6225. if(curvoice.snm[0]=='"')
  6226. curvoice.snm=curvoice.snm.slice(1,-1);break
  6227. case"stafflines=":val=get_st_lines(a.shift())
  6228. if(val==undefined)
  6229. syntax(1,"Bad %%stafflines value")
  6230. else if(curvoice.st!=undefined)
  6231. par_sy.staves[curvoice.st].stafflines=val
  6232. else
  6233. curvoice.stafflines=val
  6234. break
  6235. case"staffnonote=":val=+a.shift()
  6236. if(isNaN(val))
  6237. syntax(1,"Bad %%staffnonote value")
  6238. else
  6239. curvoice.staffnonote=val
  6240. break
  6241. case"staffscale=":val=+a.shift()
  6242. if(isNaN(val)||val<.3||val>2)
  6243. syntax(1,"Bad %%staffscale value")
  6244. else
  6245. curvoice.staffscale=val
  6246. break
  6247. case"tacet=":val=a.shift()
  6248. curvoice.tacet=val||undefined
  6249. break
  6250. case"transpose=":if(cfmt.nedo){syntax(1,errs.notransp)
  6251. break}
  6252. val=get_transp(a.shift())
  6253. if(val==undefined){syntax(1,errs.bad_transp)}else{curvoice.sound=val
  6254. if(cfmt.sound)
  6255. curvoice.score=val
  6256. tr_p=2}
  6257. break
  6258. default:switch(item.slice(0,4)){case"treb":case"bass":case"alto":case"teno":case"perc":s=item
  6259. break
  6260. default:if("GFC".indexOf(item[0])>=0)
  6261. s=item
  6262. else if(item.slice(-1)=='=')
  6263. a.shift()
  6264. break}
  6265. break}}
  6266. if(pos){curvoice.pos=clone(curvoice.pos)
  6267. for(item in pos)
  6268. if(pos.hasOwnProperty(item))
  6269. curvoice.pos[item]=pos[item]}
  6270. if(s){s=new_clef(s)
  6271. if(s){if(clefpit)
  6272. s.clefpit=clefpit
  6273. get_clef(s)}}
  6274. if(tr_p&2){tr_p=(curvoice.sound|0)+(curvoice.shift|0)
  6275. if(tr_p)
  6276. curvoice.tr_snd=abc2svg.b40m(tr_p+122)-36
  6277. else if(curvoice.tr_snd)
  6278. curvoice.tr_snd=0}}
  6279. function set_kv_parm(a){if(!curvoice.init){curvoice.init=true
  6280. if(info.V){if(info.V[curvoice.id])
  6281. a=info.V[curvoice.id].concat(a)
  6282. if(info.V['*'])
  6283. a=info.V['*'].concat(a)}}
  6284. if(a.length)
  6285. self.set_vp(a)}
  6286. function memo_kv_parm(vid,a){if(!a.length)
  6287. return
  6288. if(!info.V)
  6289. info.V={}
  6290. if(info.V[vid])
  6291. Array.prototype.push.apply(info.V[vid],a)
  6292. else
  6293. info.V[vid]=a}
  6294. function new_key(param){var i,key_end,c,tmp,note,sf="FCGDAEB".indexOf(param[0])-1,mode=0,s={type:C.KEY,dur:0}
  6295. set_ref(s);i=1
  6296. if(sf<-1){switch(param[0]){case'H':key_end=true
  6297. if(param[1].toLowerCase()!='p'){syntax(1,"Unknown bagpipe-like key")
  6298. break}
  6299. s.k_bagpipe=param[1];sf=param[1]=='P'?0:2;i++
  6300. if(!cfmt.temper)
  6301. cfmt.temper=new Float32Array([11.62,12.55,1.66,2.37,3.49,0,1.66,2.37,3.49,4.41,5.53,0,3.49,4.41,5.53,6.63,7.35,4.41,5.53,6.63,7.35,8.19,0,6.63,7.35,8.19,9.39,10.51,0,8.19,9.39,10.51,11.62,12.55,0,10.51,11.62,12.55,1.66,1.66])
  6302. break
  6303. case'P':syntax(1,"K:P is deprecated");sf=0;s.k_drum=true;key_end=true
  6304. break
  6305. case'n':if(param.indexOf("none")==0){sf=0;s.k_none=true;i=4
  6306. break}
  6307. default:s.k_map=[]
  6308. s.k_mode=0
  6309. return[s,info_split(param)]}}
  6310. if(!key_end){switch(param[i]){case'#':sf+=7;i++;break
  6311. case'b':sf-=7;i++;break}
  6312. param=param.slice(i).trim()
  6313. switch(param.slice(0,3).toLowerCase()){default:if(param[0]!='m'||(param[1]!=' '&&param[1]!='\t'&&param[1]!='\n')){key_end=true
  6314. break}
  6315. case"aeo":case"m":case"min":sf-=3;mode=5
  6316. break
  6317. case"dor":sf-=2;mode=1
  6318. break
  6319. case"ion":case"maj":break
  6320. case"loc":sf-=5;mode=6
  6321. break
  6322. case"lyd":sf+=1;mode=3
  6323. break
  6324. case"mix":sf-=1;mode=4
  6325. break
  6326. case"phr":sf-=4;mode=2
  6327. break}
  6328. if(!key_end)
  6329. param=param.replace(/\w+\s*/,'')
  6330. if(param.indexOf("exp ")==0){param=param.replace(/\w+\s*/,'')
  6331. if(!param)
  6332. syntax(1,"No accidental after 'exp'");s.exp=1}
  6333. c=param[0]
  6334. if(c=='^'||c=='_'||c=='='){s.k_a_acc=[];tmp=new scanBuf;tmp.buffer=param
  6335. do{note=parse_acc_pit(tmp)
  6336. if(!note)
  6337. break
  6338. s.k_a_acc.push(note);c=param[tmp.index]
  6339. while(c==' ')
  6340. c=param[++tmp.index]}while(c=='^'||c=='_'||c=='=');param=param.slice(tmp.index)}else if(s.exp&&param.indexOf("none")==0){sf=0
  6341. param=param.replace(/\w+\s*/,'')}}
  6342. if(sf<-7||sf>7){syntax(1,"Key with double sharps/flats")
  6343. if(sf>7)
  6344. sf-=12
  6345. else
  6346. sf+=12}
  6347. s.k_sf=sf;s.k_map=s.k_bagpipe&&!sf?abc2svg.keys[9]:abc2svg.keys[sf+7]
  6348. if(s.k_a_acc){s.k_map=new Int8Array(s.k_map)
  6349. i=s.k_a_acc.length
  6350. while(--i>=0){note=s.k_a_acc[i]
  6351. s.k_map[(note.pit+19)%7]=note.acc}}
  6352. s.k_mode=mode
  6353. s.k_b40=[1,24,7,30,13,36,19,2,25,8,31,14,37,20,3][sf+7]
  6354. return[s,info_split(param)]}
  6355. function new_meter(p){var p_v,s={type:C.METER,dur:0,a_meter:[]},meter={},val,v,m1=0,m2,i=0,j,wmeasure,in_parenth;set_ref(s)
  6356. if(p.indexOf("none")==0){i=4;wmeasure=1}else{wmeasure=0
  6357. while(i<p.length){if(p[i]=='=')
  6358. break
  6359. switch(p[i]){case'C':meter.top=p[i++]
  6360. if(!m1){m1=4;m2=4}
  6361. break
  6362. case'c':case'o':meter.top=p[i++]
  6363. if(!m1){if(p[i-1]=='c'){m1=2;m2=4}else{m1=3;m2=4}
  6364. switch(p[i]){case'|':m2/=2
  6365. break
  6366. case'.':m1*=3;m2*=2
  6367. break}}
  6368. break
  6369. case'.':case'|':m1=0;meter.top=p[i++]
  6370. break
  6371. case'(':if(p[i+1]=='('){in_parenth=true;meter.top=p[i++];s.a_meter.push(meter);meter={}}
  6372. j=i+1
  6373. while(j<p.length){if(p[j]==')'||p[j]=='/')
  6374. break
  6375. j++}
  6376. if(p[j]==')'&&p[j+1]=='/'){i++
  6377. continue}
  6378. case')':in_parenth=p[i]=='(';meter.top=p[i++];s.a_meter.push(meter);meter={}
  6379. continue
  6380. default:if(p[i]<='0'||p[i]>'9'){syntax(1,"Bad char '$1' in M:",p[i])
  6381. return}
  6382. m2=2;meter.top=p[i++]
  6383. for(;;){while(p[i]>='0'&&p[i]<='9')
  6384. meter.top+=p[i++]
  6385. if(p[i]==')'){if(p[i+1]!='/')
  6386. break
  6387. i++}
  6388. if(p[i]=='/'){i++;if(p[i]<='0'||p[i]>'9'){syntax(1,"Bad char '$1' in M:",p[i])
  6389. return}
  6390. meter.bot=p[i++]
  6391. while(p[i]>='0'&&p[i]<='9')
  6392. meter.bot+=p[i++]
  6393. break}
  6394. if(p[i]!=' '&&p[i]!='+')
  6395. break
  6396. if(i>=p.length||p[i+1]=='(')
  6397. break
  6398. meter.top+=p[i++]}
  6399. m1=+meter.top
  6400. break}
  6401. if(!in_parenth){if(meter.bot)
  6402. m2=+meter.bot
  6403. wmeasure+=m1*C.BLEN/m2}
  6404. s.a_meter.push(meter);meter={}
  6405. while(p[i]==' ')
  6406. i++
  6407. if(p[i]=='+'){meter.top=p[i++];s.a_meter.push(meter);meter={}}}}
  6408. if(p[i]=='='){val=p.substring(++i).match(/^(\d+)\/(\d+)$/)
  6409. if(!val){syntax(1,"Bad duration '$1' in M:",p.substring(i))
  6410. return}
  6411. wmeasure=C.BLEN*val[1]/val[2]}
  6412. if(!wmeasure){syntax(1,errs.bad_val,'M:')
  6413. return}
  6414. s.wmeasure=wmeasure
  6415. if(cfmt.writefields.indexOf('M')<0)
  6416. s.a_meter=[]
  6417. if(parse.state!=3){info.M=p;glovar.meter=s
  6418. if(parse.state){if(!glovar.ulen){if(wmeasure<=1||wmeasure>=C.BLEN*3/4)
  6419. glovar.ulen=C.BLEN/8
  6420. else
  6421. glovar.ulen=C.BLEN/16}
  6422. for(v=0;v<voice_tb.length;v++){voice_tb[v].meter=s;voice_tb[v].wmeasure=wmeasure}}}else{curvoice.wmeasure=wmeasure
  6423. if(is_voice_sig())
  6424. curvoice.meter=s
  6425. else
  6426. sym_link(s)
  6427. for(p_v=curvoice.voice_down;p_v;p_v=p_v.voice_down)
  6428. p_v.wmeasure=wmeasure}}
  6429. function new_tempo(text){var i,c,d,nd,txt=text,s={type:C.TEMPO,dur:0}
  6430. function get_nd(p){var n,d,nd=p.match(/(\d+)\/(\d+)/)
  6431. if(nd){d=+nd[2]
  6432. if(d&&!isNaN(d)&&!(d&(d-1))){n=+nd[1]
  6433. if(!isNaN(n))
  6434. return C.BLEN*n/d}}
  6435. syntax(1,"Invalid note duration $1",c)}
  6436. set_ref(s)
  6437. if(cfmt.writefields.indexOf('Q')<0)
  6438. s.invis=true
  6439. if(text[0]=='"'){c=text.match(/"([^"]*)"/)
  6440. if(!c){syntax(1,"Unterminated string in Q:")
  6441. return}
  6442. s.tempo_str1=c[1]
  6443. text=text.slice(c[0].length).replace(/^\s+/,'')}
  6444. if(text.slice(-1)=='"'){i=text.indexOf('"')
  6445. s.tempo_str2=text.slice(i+1,-1)
  6446. text=text.slice(0,i).replace(/\s+$/,'')}
  6447. i=text.indexOf('=')
  6448. if(i>0){d=text.slice(0,i).split(/\s+/)
  6449. text=text.slice(i+1).replace(/^\s+/,'')
  6450. while(1){c=d.shift()
  6451. if(!c)
  6452. break
  6453. nd=get_nd(c)
  6454. if(!nd)
  6455. return
  6456. if(!s.tempo_notes)
  6457. s.tempo_notes=[]
  6458. s.tempo_notes.push(nd)}
  6459. if(text.slice(0,4)=="ca. "){s.tempo_ca='ca. '
  6460. text=text.slice(4)}
  6461. i=text.indexOf('/')
  6462. if(i>0){nd=get_nd(text)
  6463. if(!nd)
  6464. return
  6465. s.new_beat=nd}else{s.tempo=+text
  6466. if(!s.tempo||isNaN(s.tempo)){syntax(1,"Bad tempo value")
  6467. return}}}
  6468. if(parse.state<2||(!curvoice.time&&!glovar.tempo)){info.Q=txt
  6469. glovar.tempo=s
  6470. return}
  6471. if(!glovar.tempo)
  6472. syntax(0,"No previous tempo")
  6473. if(new_ctrl(s))
  6474. sym_link(s)}
  6475. function do_info(info_type,text){var s,d1,d2,a,vid,tim,v,p_v
  6476. if(curvoice&&curvoice.ignore){switch(info_type){default:return
  6477. case'P':case'Q':case'V':break}}
  6478. switch(info_type){case'I':self.do_pscom(text)
  6479. break
  6480. case'L':a=text.match(/^1\/(\d+)(=(\d+)\/(\d+))?$/)
  6481. if(a){d1=+a[1]
  6482. if(!d1||(d1&(d1-1))!=0)
  6483. break
  6484. d1=C.BLEN/d1
  6485. if(a[2]){d2=+a[4]
  6486. d2=d2?+a[3]/d2*C.BLEN:0}else{d2=d1}}else if(text=="auto"){d1=d2=-1}
  6487. if(!d2){syntax(1,"Bad L: value")
  6488. break}
  6489. if(parse.state<=1){glovar.ulen=d1}else{curvoice.ulen=d1;curvoice.dur_fact=d2/d1}
  6490. break
  6491. case'M':new_meter(text)
  6492. break
  6493. case'U':set_user(text)
  6494. break
  6495. case'P':if(!parse.state)
  6496. break
  6497. if(parse.state==1){info.P=text
  6498. break}
  6499. s={type:C.PART,text:text,time:tim}
  6500. if(!new_ctrl(s))
  6501. break
  6502. sym_link(s)
  6503. if(cfmt.writefields.indexOf(info_type)<0)
  6504. s.invis=true
  6505. break
  6506. case'Q':if(!parse.state)
  6507. break
  6508. new_tempo(text)
  6509. break
  6510. case'V':get_voice(text)
  6511. if(parse.state==3)
  6512. curvoice.ignore=!par_sy.voices[curvoice.v]
  6513. break
  6514. case'K':if(!parse.state)
  6515. break
  6516. get_key(text)
  6517. break
  6518. case'N':case'R':if(!info[info_type])
  6519. info[info_type]=text
  6520. else
  6521. info[info_type]+='\n'+text
  6522. break
  6523. case'r':if(!user.keep_remark||parse.state!=3)
  6524. break
  6525. s={type:C.REMARK,text:text,dur:0}
  6526. sym_link(s)
  6527. break
  6528. default:syntax(0,"'$1:' line ignored",info_type)
  6529. break}}
  6530. function adjust_dur(s){var s2,time,auto_time,i,fac;s2=curvoice.last_sym
  6531. if(!s2)
  6532. return;if(s2.type==C.MREST||s2.type==C.BAR)
  6533. return
  6534. while(s2.type!=C.BAR&&s2.prev)
  6535. s2=s2.prev;time=s2.time;auto_time=curvoice.time-time
  6536. fac=curvoice.wmeasure/auto_time
  6537. if(fac==1)
  6538. return
  6539. for(;s2;s2=s2.next){s2.time=time
  6540. if(!s2.dur||s2.grace)
  6541. continue
  6542. s2.dur*=fac;s2.dur_orig*=fac;time+=s2.dur
  6543. if(s2.type!=C.NOTE&&s2.type!=C.REST)
  6544. continue
  6545. for(i=0;i<=s2.nhd;i++)
  6546. s2.notes[i].dur*=fac}
  6547. curvoice.time=s.time=time}
  6548. function new_bar(){var s2,c,bar_type,line=parse.line,s={type:C.BAR,fname:parse.fname,istart:parse.bol+line.index,dur:0,multi:0}
  6549. if(vover&&vover.bar)
  6550. get_vover('|')
  6551. if(glovar.new_nbar){s.bar_num=glovar.new_nbar;glovar.new_nbar=0}
  6552. bar_type=line.char()
  6553. while(1){c=line.next_char()
  6554. switch(c){case'|':case'[':case']':case':':bar_type+=c
  6555. continue}
  6556. break}
  6557. if(bar_type[0]==':'){if(bar_type==':'){bar_type='|';s.bar_dotted=true}else{s.rbstop=2}}
  6558. if(a_gch)
  6559. csan_add(s)
  6560. if(a_dcn.length)
  6561. deco_cnv(s)
  6562. if(bar_type.slice(-1)=='['&&!(/[0-9" ]/.test(c))){bar_type=bar_type.slice(0,-1);line.index--;c='['}
  6563. if(c>'0'&&c<='9'){s.text=c
  6564. while(1){c=line.next_char()
  6565. if("0123456789,.-".indexOf(c)<0)
  6566. break
  6567. s.text+=c}}else if(c=='"'&&bar_type.slice(-1)=='['){s.text=""
  6568. while(1){c=line.next_char()
  6569. if(!c){syntax(1,"No end of repeat string")
  6570. return}
  6571. if(c=='"'){line.index++
  6572. break}
  6573. s.text+=c}}
  6574. if(bar_type[0]==']'){s.rbstop=2
  6575. if(bar_type.length!=1)
  6576. bar_type=bar_type.slice(1)
  6577. else
  6578. s.invis=true}
  6579. s.iend=parse.bol+line.index
  6580. if(s.text&&bar_type.slice(-1)=='['&&bar_type!='[')
  6581. bar_type=bar_type.slice(0,-1)
  6582. if(bar_type.slice(-1)==':'){s.rbstop=1
  6583. if(s.text){syntax(1,"Variant ending on a left repeat bar")
  6584. delete s.text}
  6585. curvoice.tie_s_rep=null}
  6586. if(s.text){s.rbstart=s.rbstop=2
  6587. if(s.text[0]=='1'){curvoice.tie_s_rep=curvoice.tie_s
  6588. if(curvoice.acc_tie)
  6589. curvoice.acc_tie_rep=curvoice.acc_tie.slice()
  6590. else if(curvoice.acc_tie_rep)
  6591. curvoice.acc_tie_rep=null}else{curvoice.tie_s=curvoice.tie_s_rep
  6592. if(curvoice.acc_tie_rep)
  6593. curvoice.acc_tie=curvoice.acc_tie_rep.slice()}
  6594. if(curvoice.norepbra&&!curvoice.second)
  6595. s.norepbra=1}
  6596. if(curvoice.ulen<0)
  6597. adjust_dur(s);if((bar_type=="["||bar_type=="|:")&&!curvoice.eoln&&!s.a_gch&&!s.invis){s2=curvoice.last_sym
  6598. if(s2&&s2.type==C.BAR){if((bar_type=="["&&!s2.text)||s.norepbra){if(s.text){s2.text=s.text
  6599. if(curvoice.st&&!s.norepbra&&!(par_sy.staves[curvoice.st-1].flags&STOP_BAR))
  6600. s2.xsh=4}
  6601. if(s.norepbra)
  6602. s2.norepbra=1
  6603. if(s.rbstart)
  6604. s2.rbstart=s.rbstart
  6605. if(s.rbstop)
  6606. s2.rbstop=s.rbstop
  6607. return}
  6608. if(bar_type=="|:"){switch(s2.bar_type){case":|":s2.bar_type="::";s2.rbstop=2
  6609. return}}}}
  6610. switch(bar_type){case"[":case"[]":case"[|]":s.invis=true;bar_type=s.rbstart?"[":"[]"
  6611. break
  6612. case":|:":case":||:":bar_type="::"
  6613. break
  6614. case"||":if(cfmt["abc-version"]>="2.2")
  6615. break
  6616. case"[|":case"|]":s.rbstop=2
  6617. break}
  6618. s.bar_type=bar_type
  6619. if(!curvoice.lyric_restart)
  6620. curvoice.lyric_restart=s
  6621. if(!curvoice.sym_restart)
  6622. curvoice.sym_restart=s
  6623. sym_link(s);s.st=curvoice.st
  6624. if(s.text&&s.st>0&&!s.norepbra&&!(par_sy.staves[s.st-1].flags&STOP_BAR)&&bar_type!='[')
  6625. s.xsh=4
  6626. if(!s.bar_dotted&&!s.invis)
  6627. curvoice.acc=[]}
  6628. function parse_staves(p){var v,vid,vids={},a_vf=[],err=false,flags=0,brace=0,bracket=0,parenth=0,flags_st=0,e,a=p.match(/[^[\]|{}()*+\s]+|[^\s]/g)
  6629. if(!a){syntax(1,errs.bad_val,"%%score")
  6630. return}
  6631. while(1){e=a.shift()
  6632. if(!e)
  6633. break
  6634. switch(e){case'[':if(parenth||brace+bracket>=2){syntax(1,errs.misplaced,'[');err=true
  6635. break}
  6636. flags|=brace+bracket==0?OPEN_BRACKET:OPEN_BRACKET2;bracket++;flags_st<<=8;flags_st|=OPEN_BRACKET
  6637. break
  6638. case'{':if(parenth||brace||bracket>=2){syntax(1,errs.misplaced,'{');err=true
  6639. break}
  6640. flags|=!bracket?OPEN_BRACE:OPEN_BRACE2;brace++;flags_st<<=8;flags_st|=OPEN_BRACE
  6641. break
  6642. case'(':if(parenth){syntax(1,errs.misplaced,'(');err=true
  6643. break}
  6644. flags|=OPEN_PARENTH;parenth++;flags_st<<=8;flags_st|=OPEN_PARENTH
  6645. break
  6646. case'*':if(brace&&!parenth&&!(flags&(OPEN_BRACE|OPEN_BRACE2)))
  6647. flags|=FL_VOICE
  6648. break
  6649. case'+':flags|=MASTER_VOICE
  6650. break
  6651. case']':case'}':case')':syntax(1,"Bad voice ID in %%score");err=true
  6652. break
  6653. default:vid=e
  6654. while(1){e=a.shift()
  6655. if(!e)
  6656. break
  6657. switch(e){case']':if(!(flags_st&OPEN_BRACKET)){syntax(1,errs.misplaced,']');err=true
  6658. break}
  6659. bracket--;flags|=brace+bracket==0?CLOSE_BRACKET:CLOSE_BRACKET2;flags_st>>=8
  6660. continue
  6661. case'}':if(!(flags_st&OPEN_BRACE)){syntax(1,errs.misplaced,'}');err=true
  6662. break}
  6663. brace--;flags|=!bracket?CLOSE_BRACE:CLOSE_BRACE2;flags&=~FL_VOICE;flags_st>>=8
  6664. continue
  6665. case')':if(!(flags_st&OPEN_PARENTH)){syntax(1,errs.misplaced,')');err=true
  6666. break}
  6667. parenth--;flags|=CLOSE_PARENTH;flags_st>>=8
  6668. continue
  6669. case'|':flags|=STOP_BAR
  6670. continue}
  6671. break}
  6672. if(vids[vid]){syntax(1,"Double voice in %%score")
  6673. err=true}else{vids[vid]=true
  6674. a_vf.push([vid,flags])}
  6675. flags=0
  6676. if(!e)
  6677. break
  6678. a.unshift(e)
  6679. break}}
  6680. if(flags_st!=0){syntax(1,"'}', ')' or ']' missing in %%score");err=true}
  6681. if(err||!a_vf.length)
  6682. return
  6683. return a_vf}
  6684. function info_split(text){if(!text)
  6685. return[]
  6686. var a=text.match(/[^\s"=]+=?|"[^"]*"/g)
  6687. if(!a){syntax(1,"Unterminated string")
  6688. return[]}
  6689. return a}
  6690. var reg_dur=/(\d*)(\/*)(\d*)/g
  6691. function parse_dur(line){var res,num,den;reg_dur.lastIndex=line.index;res=reg_dur.exec(line.buffer)
  6692. if(!res[0])
  6693. return[1,1];num=res[1]||1;den=res[3]||1
  6694. if(!res[3])
  6695. den*=1<<res[2].length;line.index=reg_dur.lastIndex
  6696. return[+num,+den]}
  6697. function parse_acc_pit(line){var note,acc,pit,d,nd,c=line.char()
  6698. switch(c){case'^':c=line.next_char()
  6699. if(c=='^'){acc=2;c=line.next_char()}else{acc=1}
  6700. break
  6701. case'=':acc=3;c=line.next_char()
  6702. break
  6703. case'_':c=line.next_char()
  6704. if(c=='_'){acc=-2;c=line.next_char()}else{acc=-1}
  6705. break}
  6706. if(acc==1||acc==-1){if((c>='1'&&c<='9')||c=='/'){nd=parse_dur(line);if(acc<0)
  6707. nd[0]=-nd[0]
  6708. if(cfmt.nedo&&nd[1]==1){nd[0]*=12
  6709. nd[1]*=cfmt.nedo}
  6710. acc=nd
  6711. c=line.char()}}
  6712. pit=ntb.indexOf(c)+16;c=line.next_char()
  6713. if(pit<16){syntax(1,"'$1' is not a note",line.buffer[line.index-1])
  6714. return}
  6715. while(c=="'"){pit+=7;c=line.next_char()}
  6716. while(c==','){pit-=7;c=line.next_char()}
  6717. note={pit:pit,shhd:0,shac:0}
  6718. if(acc)
  6719. note.acc=acc
  6720. return note}
  6721. function set_map(note,acc){var pit=note.pit,nn=not2abc(pit,acc),map=maps[curvoice.map]
  6722. if(!map[nn]){nn='o'+nn.replace(/[',]+/,'')
  6723. if(!map[nn]){nn='k'+ntb[(pit+75-
  6724. curvoice.ckey.k_sf*11)%7]
  6725. if(!map[nn]){nn='all'
  6726. if(!map[nn])
  6727. return}}}
  6728. note.map=map=map[nn]
  6729. if(map[1]){note.pit=pit=map[1].pit
  6730. note.acc=map[1].acc
  6731. if(map[1].notrp){note.notrp=1
  6732. note.noplay=1}}
  6733. if(map[2])
  6734. note.color=map[2]
  6735. nn=map[3]
  6736. if(nn)
  6737. note.midi=pit2mid(nn.pit+19,nn.acc)}
  6738. function parse_basic_note(line,ulen){var nd,note=parse_acc_pit(line)
  6739. if(!note)
  6740. return
  6741. if(line.char()=='0'){parse.stemless=true;line.index++}
  6742. nd=parse_dur(line);note.dur=ulen*nd[0]/nd[1]
  6743. return note}
  6744. function parse_vpos(){var line=parse.line,ty=0
  6745. if(a_dcn.length&&a_dcn[a_dcn.length-1]=="dot"){ty=C.SL_DOTTED
  6746. a_dcn.pop()}
  6747. switch(line.next_char()){case"'":line.index++
  6748. return ty+C.SL_ABOVE
  6749. case",":line.index++
  6750. return ty+C.SL_BELOW}
  6751. return ty+C.SL_AUTO}
  6752. function slur_add(s,nt){var i,s2,sl
  6753. for(i=curvoice.sls.length;--i>=0;){sl=curvoice.sls[i]
  6754. if(sl.ss==s)
  6755. continue
  6756. curvoice.sls.splice(i,1)
  6757. sl.se=s
  6758. if(nt)
  6759. sl.nte=nt
  6760. s2=sl.ss
  6761. if(!s2.sls)
  6762. s2.sls=[]
  6763. s2.sls.push(sl)
  6764. if(sl.grace)
  6765. sl.grace.sl1=true
  6766. return}
  6767. for(s2=s.prev;s2;s2=s2.prev){if(s2.type==C.BAR&&s2.bar_type[0]==':'&&s2.text){if(!s2.sls)
  6768. s2.sls=[];s2.sls.push({ty:C.SL_AUTO,ss:s2,se:s})
  6769. if(nt)
  6770. s2.sls[s2.sls.length-1].nte=nt
  6771. return}}
  6772. if(!s.sls)
  6773. s.sls=[];s.sls.push({ty:C.SL_AUTO,se:s,loc:'i'})
  6774. if(nt)
  6775. s.sls[s.sls.length-1].nte=nt}
  6776. function pit2mid(pit,acc){var p=[0,2,4,5,7,9,11][pit%7],o=((pit/7)|0)*12,p0,p1,s,b40
  6777. if(curvoice.snd_oct)
  6778. o+=curvoice.snd_oct
  6779. if(acc==3)
  6780. acc=0
  6781. if(acc){if(typeof acc=="object"){s=acc[0]/acc[1]
  6782. if(acc[1]==100)
  6783. return p+o+s}else{s=acc}}else{if(cfmt.temper)
  6784. return cfmt.temper[abc2svg.p_b40[pit%7]]+o
  6785. return p+o}
  6786. if(!cfmt.nedo){if(!cfmt.temper){p+=o+s
  6787. return p}}else{if(typeof acc!="object"){b40=abc2svg.p_b40[pit%7]+acc
  6788. return cfmt.temper[b40]+o}
  6789. if(acc[1]==cfmt.nedo){b40=abc2svg.p_b40[pit%7]
  6790. return cfmt.temper[b40]+o+s}}
  6791. p0=cfmt.temper[abc2svg.p_b40[pit%7]]
  6792. if(s>0){p1=cfmt.temper[(abc2svg.p_b40[pit%7]+1)%40]
  6793. if(p1<p0)
  6794. p1+=12}else{p1=cfmt.temper[(abc2svg.p_b40[pit%7]+39)%40]
  6795. if(p1>p0)
  6796. p1-=12
  6797. s=-s}
  6798. return p0+o+(p1-p0)*s}
  6799. function do_ties(s,tie_s){var i,m,not1,not2,mid,g,nt=0,se=(tie_s.time+tie_s.dur)==curvoice.time
  6800. for(m=0;m<=s.nhd;m++){not2=s.notes[m]
  6801. mid=not2.midi
  6802. if(tie_s.type!=C.GRACE){for(i=0;i<=tie_s.nhd;i++){not1=tie_s.notes[i]
  6803. if(!not1.tie_ty)
  6804. continue
  6805. if(not1.midi==mid&&(!se||!not1.tie_e)){not2.tie_s=not1
  6806. not2.s=s
  6807. delete not2.acc
  6808. if(se){not1.tie_e=not2
  6809. not1.s=tie_s}
  6810. nt++
  6811. break}}}else{for(g=tie_s.extra;g;g=g.next){not1=g.notes[0]
  6812. if(!not1.tie_ty)
  6813. continue
  6814. if(not1.midi==mid){g.ti1=true
  6815. not2.tie_s=not1
  6816. not2.s=s
  6817. not1.tie_e=not2
  6818. not1.s=g
  6819. nt++
  6820. break}}}}
  6821. if(!nt)
  6822. error(1,tie_s,"Bad tie")
  6823. else
  6824. s.ti2=true}
  6825. Abc.prototype.new_note=function(grace,sls){var note,s,in_chord,c,dcn,type,tie_s,acc_tie,i,n,s2,nd,res,num,dur,apit,div,ty,dpit=0,sl1=[],line=parse.line,a_dcn_sav=a_dcn
  6826. a_dcn=[]
  6827. parse.stemless=false;s={type:C.NOTE,fname:parse.fname,stem:0,multi:0,nhd:0,xmx:0}
  6828. s.istart=parse.bol+line.index
  6829. if(curvoice.color)
  6830. s.color=curvoice.color
  6831. if(grace){s.grace=true}else{if(curvoice.tie_s){tie_s=curvoice.tie_s
  6832. curvoice.tie_s=null}
  6833. if(a_gch)
  6834. csan_add(s)
  6835. if(parse.repeat_n){s.repeat_n=parse.repeat_n;s.repeat_k=parse.repeat_k;parse.repeat_n=0}}
  6836. c=line.char()
  6837. switch(c){case'X':s.invis=true
  6838. case'Z':s.type=C.MREST;c=line.next_char()
  6839. s.nmes=(c>'0'&&c<='9')?line.get_int():1;if(curvoice.wmeasure==1){error(1,s,"multi-measure rest, but no measure!")
  6840. return}
  6841. s.dur=curvoice.wmeasure*s.nmes
  6842. if(curvoice.second){delete curvoice.eoln
  6843. curvoice.time+=s.dur
  6844. return}
  6845. if(s.nmes==1){s.type=C.REST;s.dur_orig=s.dur;s.fmr=1
  6846. s.notes=[{pit:18,dur:s.dur}]}else{glovar.mrest_p=true
  6847. if(par_sy.voices.length==1){s.tacet=curvoice.tacet
  6848. delete s.invis}}
  6849. break
  6850. case'y':s.type=C.SPACE;s.invis=true;s.dur=0;c=line.next_char()
  6851. if(c>='0'&&c<='9')
  6852. s.width=line.get_int()
  6853. else
  6854. s.width=10
  6855. if(tie_s){curvoice.tie_s=tie_s
  6856. tie_s=null}
  6857. break
  6858. case'x':s.invis=true
  6859. case'z':s.type=C.REST;line.index++;nd=parse_dur(line);s.dur_orig=((curvoice.ulen<0)?C.BLEN:curvoice.ulen)*nd[0]/nd[1];s.dur=s.dur_orig*curvoice.dur_fact;if(s.dur==curvoice.wmeasure)
  6860. s.fmr=1
  6861. s.notes=[{pit:18,dur:s.dur_orig}]
  6862. break
  6863. case'[':in_chord=true;c=line.next_char()
  6864. default:if(curvoice.acc_tie){acc_tie=curvoice.acc_tie
  6865. curvoice.acc_tie=null}
  6866. s.notes=[]
  6867. while(1){if(in_chord){while(1){if(!c)
  6868. break
  6869. i=c.charCodeAt(0);if(i>=128){syntax(1,errs.not_ascii)
  6870. return}
  6871. type=char_tb[i]
  6872. switch(type[0]){case'(':sl1.push(parse_vpos());c=line.char()
  6873. continue
  6874. case'!':if(type.length>1)
  6875. a_dcn.push(type.slice(1,-1))
  6876. else
  6877. get_deco()
  6878. c=line.next_char()
  6879. continue}
  6880. break}}
  6881. note=parse_basic_note(line,s.grace?C.BLEN/4:curvoice.ulen<0?C.BLEN:curvoice.ulen)
  6882. if(!note)
  6883. return
  6884. if(curvoice.octave)
  6885. note.pit+=curvoice.octave*7
  6886. apit=note.pit+19
  6887. i=note.acc
  6888. if(!i){if(cfmt["propagate-accidentals"][0]=='p')
  6889. i=curvoice.acc[apit%7]
  6890. else
  6891. i=curvoice.acc[apit]
  6892. if(!i)
  6893. i=curvoice.ckey.k_map[apit%7]||0}
  6894. if(i){if(cfmt["propagate-accidentals"][0]=='p')
  6895. curvoice.acc[apit%7]=i
  6896. else if(cfmt["propagate-accidentals"][0]!='n')
  6897. curvoice.acc[apit]=i}
  6898. if(acc_tie&&acc_tie[apit])
  6899. i=acc_tie[apit]
  6900. if(curvoice.map&&maps[curvoice.map])
  6901. set_map(note,i)
  6902. if(!note.midi)
  6903. note.midi=pit2mid(apit,i)
  6904. if(curvoice.tr_sco&&!note.notrp){i=nt_trans(note,i)
  6905. if(i==-3){error(1,s,"triple sharp/flat")
  6906. i=note.acc>0?1:-1
  6907. note.pit+=i
  6908. note.acc=i}
  6909. dpit=note.pit+19-apit}
  6910. if(curvoice.tr_snd)
  6911. note.midi+=curvoice.tr_snd
  6912. if(i){switch(cfmt["writeout-accidentals"][1]){case'd':s2=curvoice.ckey
  6913. if(!s2.k_a_acc)
  6914. break
  6915. for(n=0;n<s2.k_a_acc.length;n++){if((s2.k_a_acc[n].pit-note.pit)%7==0){note.acc=i
  6916. break}}
  6917. break
  6918. case'l':note.acc=i
  6919. break}}
  6920. if(sl1.length){while(1){i=sl1.shift()
  6921. if(!i)
  6922. break
  6923. curvoice.sls.push({ty:i,ss:s,nts:note})}}
  6924. if(a_dcn.length){s.time=curvoice.time
  6925. dh_cnv(s,note)}
  6926. s.notes.push(note)
  6927. if(!in_chord)
  6928. break
  6929. c=line.char()
  6930. while(1){switch(c){case')':slur_add(s,note)
  6931. c=line.next_char()
  6932. continue
  6933. case'-':note.tie_ty=parse_vpos()
  6934. note.s=s
  6935. curvoice.tie_s=s
  6936. s.ti1=true
  6937. if(curvoice.acc[apit]||(acc_tie&&acc_tie[apit])){if(!curvoice.acc_tie)
  6938. curvoice.acc_tie=[]
  6939. i=curvoice.acc[apit]
  6940. if(acc_tie&&acc_tie[apit])
  6941. i=acc_tie[apit]
  6942. curvoice.acc_tie[apit]=i}
  6943. c=line.char()
  6944. continue
  6945. case'.':c=line.next_char()
  6946. switch(c){case'-':case'(':a_dcn.push("dot")
  6947. continue}
  6948. syntax(1,"Misplaced dot")
  6949. break}
  6950. break}
  6951. if(c==']'){line.index++;nd=parse_dur(line);s.nhd=s.notes.length-1
  6952. for(i=0;i<=s.nhd;i++){note=s.notes[i];note.dur=note.dur*nd[0]/nd[1]}
  6953. break}}
  6954. if(sls.length){while(1){i=sls.shift()
  6955. if(!i)
  6956. break
  6957. curvoice.sls.push({ty:i,ss:s})
  6958. if(grace)
  6959. curvoice.sls[curvoice.sls.length-1].grace=grace}}
  6960. s.dur_orig=s.notes[0].dur;s.dur=s.notes[0].dur*curvoice.dur_fact
  6961. break}
  6962. if(s.grace&&s.type!=C.NOTE){syntax(1,errs.bad_grace)
  6963. return}
  6964. if(s.notes){if(!grace){switch(curvoice.pos.stm&0x07){case C.SL_ABOVE:s.stem=1;break
  6965. case C.SL_BELOW:s.stem=-1;break
  6966. case C.SL_HIDDEN:s.stemless=true;break}
  6967. num=curvoice.brk_rhythm
  6968. if(num){curvoice.brk_rhythm=0;s2=curvoice.last_note
  6969. if(num>0){n=num*2-1;s.dur=s.dur*n/num;s.dur_orig=s.dur_orig*n/num
  6970. for(i=0;i<=s.nhd;i++)
  6971. s.notes[i].dur=s.notes[i].dur*n/num;s2.dur/=num;s2.dur_orig/=num
  6972. for(i=0;i<=s2.nhd;i++)
  6973. s2.notes[i].dur/=num}else{num=-num;n=num*2-1;s.dur/=num;s.dur_orig/=num
  6974. for(i=0;i<=s.nhd;i++)
  6975. s.notes[i].dur/=num;s2.dur=s2.dur*n/num;s2.dur_orig=s2.dur_orig*n/num
  6976. for(i=0;i<=s2.nhd;i++)
  6977. s2.notes[i].dur=s2.notes[i].dur*n/num}
  6978. curvoice.time=s2.time+s2.dur;for(s2=s2.next;s2;s2=s2.next)
  6979. s2.time=curvoice.time}}else{div=curvoice.ckey.k_bagpipe?8:4
  6980. for(i=0;i<=s.nhd;i++)
  6981. s.notes[i].dur/=div;s.dur/=div;s.dur_orig/=div
  6982. if(grace.stem)
  6983. s.stem=grace.stem}
  6984. curvoice.last_note=s
  6985. c=line.char()
  6986. while(1){switch(c){case'.':if(line.buffer[line.index+1]!='-')
  6987. break
  6988. a_dcn.push("dot")
  6989. line.index++
  6990. case'-':ty=parse_vpos()
  6991. for(i=0;i<=s.nhd;i++){s.notes[i].tie_ty=ty
  6992. s.notes[i].s=s}
  6993. curvoice.tie_s=grace||s
  6994. curvoice.tie_s.ti1=true
  6995. for(i=0;i<=s.nhd;i++){note=s.notes[i]
  6996. apit=note.pit+19
  6997. -dpit
  6998. if(curvoice.acc[apit]||(acc_tie&&acc_tie[apit])){if(!curvoice.acc_tie)
  6999. curvoice.acc_tie=[]
  7000. n=curvoice.acc[apit]
  7001. if(acc_tie&&acc_tie[apit])
  7002. n=acc_tie[apit]
  7003. curvoice.acc_tie[apit]=n}}
  7004. c=line.char()
  7005. continue}
  7006. break}
  7007. if(tie_s)
  7008. do_ties(s,tie_s)}
  7009. sym_link(s)
  7010. if(!grace){if(!curvoice.lyric_restart)
  7011. curvoice.lyric_restart=s
  7012. if(!curvoice.sym_restart)
  7013. curvoice.sym_restart=s}
  7014. if(a_dcn_sav.length){a_dcn=a_dcn_sav
  7015. deco_cnv(s,s.prev)}
  7016. if(grace&&s.ottava)
  7017. grace.ottava=s.ottava
  7018. if(parse.stemless)
  7019. s.stemless=true
  7020. s.iend=parse.bol+line.index
  7021. return s}
  7022. function tp_adj(s,fact){var d,tim=s.time,to=curvoice.time-tim,tt=to*fact
  7023. curvoice.time=tim+tt
  7024. while(1){s.in_tuplet=true
  7025. if(!s.grace){s.time=tim
  7026. if(s.dur){d=Math.round(s.dur*tt/to)
  7027. to-=s.dur
  7028. s.dur=d
  7029. tt-=s.dur
  7030. tim+=s.dur}}
  7031. if(!s.next){if(s.tpe)
  7032. s.tpe++
  7033. else
  7034. s.tpe=1
  7035. break}
  7036. s=s.next}}
  7037. function get_deco(){var c,line=parse.line,i=line.index,dcn=""
  7038. while(1){c=line.next_char()
  7039. if(!c){line.index=i
  7040. syntax(1,"No end of decoration")
  7041. return}
  7042. if(c=='!')
  7043. break
  7044. dcn+=c}
  7045. a_dcn.push(dcn)}
  7046. var nil="0",char_tb=[nil,nil,nil,nil,nil,nil,nil,nil,nil," ","\n",nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil," ","!",'"',"i","\n",nil,"&",nil,"(",")","i",nil,nil,"-","!dot!",nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,nil,"|","i","<","n","<","i","i","n","n","n","n","n","n","n","!fermata!","d","d","d","!emphasis!","!lowermordent!","d","!coda!","!uppermordent!","d","d","!segno!","!trill!","d","d","d","n","d","n","[","\\","|","n","n","i","n","n","n","n","n","n","n","d","d","d","d","d","d","d","d","d","d","d","d","d","!upbow!","!downbow!","d","n","n","n","{","|","}","!gmark!",nil,]
  7047. function parse_music_line(){var grace,last_note_sav,a_dcn_sav,no_eol,s,tps,tp=[],tpn=-1,sls=[],line=parse.line
  7048. function check_mac(m){var i,j,b
  7049. for(i=1,j=line.index+1;i<m.length;i++,j++){if(m[i]==line.buffer[j])
  7050. continue
  7051. if(m[i]!='n')
  7052. return
  7053. b=ntb.indexOf(line.buffer[j])
  7054. if(b<0)
  7055. return
  7056. while(line.buffer[j+1]=="'"){b+=7;j++}
  7057. while(line.buffer[j+1]==','){b-=7;j++}}
  7058. line.index=j
  7059. return b}
  7060. function n2n(n){var c=''
  7061. while(n<0){n+=7;c+=','}
  7062. while(n>=14){n-=7;c+="'"}
  7063. return ntb[n]+c}
  7064. function expand(m,b){if(b==undefined)
  7065. return m
  7066. var c,i,r="",n=m.length
  7067. for(i=0;i<n;i++){c=m[i]
  7068. if(c>='h'&&c<='z'){r+=n2n(b+c.charCodeAt(0)-'n'.charCodeAt(0))}else{r+=c}}
  7069. return r}
  7070. function parse_mac(k,m,b){var te,ti,curv,s,line_sav=line,istart_sav=parse.istart;parse.line=line=new scanBuf;parse.istart+=line_sav.index;if(cfmt.writefields.indexOf('m')<0){line.buffer=k.replace('n',n2n(b))
  7071. s=curvoice.last_sym
  7072. ti=curvoice.time
  7073. parse_seq(true)
  7074. if(!s)
  7075. s=curvoice.sym
  7076. for(s=s.next;s;s=s.next)
  7077. s.noplay=true
  7078. te=curvoice.time
  7079. curv=curvoice
  7080. curvoice=clone_voice(curv.id+'-p')
  7081. if(!par_sy.voices[curvoice.v]){curvoice.second=true
  7082. par_sy.voices[curvoice.v]={st:curv.st,second:true,range:curvoice.v}}
  7083. curvoice.time=ti
  7084. s=curvoice.last_sym
  7085. parse.line=line=new scanBuf
  7086. parse.istart+=line_sav.index
  7087. line.buffer=expand(m,b)
  7088. parse_seq(true)
  7089. if(curvoice.time!=te)
  7090. syntax(1,"Bad length of the macro sequence")
  7091. if(!s)
  7092. s=curvoice.sym
  7093. for(;s;s=s.next)
  7094. s.invis=s.play=true
  7095. curvoice=curv}else{line.buffer=expand(m,b)
  7096. parse_seq(true)}
  7097. parse.line=line=line_sav
  7098. parse.istart=istart_sav}
  7099. function parse_seq(in_mac){var c,idx,type,k,s,dcn,i,n,text,note
  7100. while(1){c=line.char()
  7101. if(!c)
  7102. break
  7103. if(!in_mac&&maci[c]){n=undefined
  7104. for(k in mac){if(!mac.hasOwnProperty(k)||k[0]!=c)
  7105. continue
  7106. if(k.indexOf('n')<0){if(line.buffer.indexOf(k,line.index)
  7107. !=line.index)
  7108. continue
  7109. line.index+=k.length}else{n=check_mac(k)
  7110. if(n==undefined)
  7111. continue}
  7112. parse_mac(k,mac[k],n)
  7113. n=1
  7114. break}
  7115. if(n)
  7116. continue}
  7117. idx=c.charCodeAt(0)
  7118. if(idx>=128){syntax(1,errs.not_ascii)
  7119. line.index++
  7120. break}
  7121. type=char_tb[idx]
  7122. switch(type[0]){case' ':s=curvoice.last_note
  7123. if(s){s.beam_end=true
  7124. if(grace)
  7125. grace.gr_shift=true}
  7126. break
  7127. case'\n':if(cfmt.barsperstaff)
  7128. break
  7129. curvoice.eoln=true
  7130. break
  7131. case'&':if(grace){syntax(1,errs.bad_grace)
  7132. break}
  7133. c=line.next_char()
  7134. if(c==')'){get_vover(c)
  7135. break}
  7136. get_vover('&')
  7137. continue
  7138. case'(':c=line.next_char()
  7139. if(c>'0'&&c<='9'){if(grace){syntax(1,errs.bad_grace)
  7140. break}
  7141. var pplet=line.get_int(),qplet=qplet_tb[pplet],rplet=pplet
  7142. c=line.char()
  7143. if(c==':'){c=line.next_char()
  7144. if(c>'0'&&c<='9'){qplet=line.get_int();c=line.char()}
  7145. if(c==':'){c=line.next_char()
  7146. if(c>'0'&&c<='9'){rplet=line.get_int();c=line.char()}else{syntax(1,"Invalid 'r' in tuplet")
  7147. continue}}}
  7148. if(qplet==0||qplet==undefined)
  7149. qplet=(curvoice.wmeasure%9)==0?3:2;if(tpn<0)
  7150. tpn=tp.length
  7151. tp.push({p:pplet,q:qplet,r:rplet,ro:rplet,f:curvoice.tup||cfmt.tuplets})
  7152. continue}
  7153. if(c=='&'){if(grace){syntax(1,errs.bad_grace)
  7154. break}
  7155. get_vover('(')
  7156. break}
  7157. line.index--;sls.push(parse_vpos())
  7158. continue
  7159. case')':s=curvoice.last_sym
  7160. if(s){switch(s.type){case C.SPACE:if(!s.notes){s.notes=[]
  7161. s.notes[0]={}}
  7162. case C.NOTE:case C.REST:break
  7163. case C.GRACE:for(s=s.extra;s.next;s=s.next);break
  7164. default:s=null
  7165. break}}
  7166. if(!s){syntax(1,errs.bad_char,c)
  7167. break}
  7168. slur_add(s)
  7169. break
  7170. case'!':if(type.length>1)
  7171. a_dcn.push(type.slice(1,-1))
  7172. else
  7173. get_deco()
  7174. break
  7175. case'"':if(grace){syntax(1,errs.bad_grace)
  7176. break}
  7177. parse_gchord(type)
  7178. break
  7179. case'[':if(type.length>1){self.do_pscom(type.slice(3,-1))
  7180. break}
  7181. var c_next=line.buffer[line.index+1]
  7182. if('|[]: "'.indexOf(c_next)>=0||(c_next>='1'&&c_next<='9')){if(grace){syntax(1,errs.bar_grace)
  7183. break}
  7184. new_bar()
  7185. continue}
  7186. if(line.buffer[line.index+2]==':'){if(grace){syntax(1,errs.bad_grace)
  7187. break}
  7188. i=line.buffer.indexOf(']',line.index+1)
  7189. if(i<0){syntax(1,"Lack of ']'")
  7190. break}
  7191. text=line.buffer.slice(line.index+3,i).trim()
  7192. parse.istart=parse.bol+line.index;parse.iend=parse.bol+ ++i;line.index=0;do_info(c_next,text);line.index=i
  7193. continue}
  7194. case'n':s=self.new_note(grace,sls)
  7195. if(!s)
  7196. continue
  7197. if(grace||!s.notes)
  7198. continue
  7199. if(tpn>=0){s.tp=tp.slice(tpn)
  7200. tpn=-1
  7201. if(tps)
  7202. s.tp[0].s=tps
  7203. tps=s}else if(!tps){continue}
  7204. k=tp[tp.length-1]
  7205. if(--k.r>0)
  7206. continue
  7207. while(1){tp_adj(tps,k.q/k.p)
  7208. i=k.ro
  7209. if(k.s)
  7210. tps=k.s
  7211. tp.pop()
  7212. if(!tp.length){tps=null
  7213. break}
  7214. k=tp[tp.length-1]
  7215. k.r-=i
  7216. if(k.r>0)
  7217. break}
  7218. continue
  7219. case'<':if(!curvoice.last_note){syntax(1,"No note before '<'")
  7220. break}
  7221. if(grace){syntax(1,"Cannot have a broken rhythm in grace notes")
  7222. break}
  7223. n=c=='<'?1:-1
  7224. while(c=='<'||c=='>'){n*=2;c=line.next_char()}
  7225. curvoice.brk_rhythm=n
  7226. continue
  7227. case'i':break
  7228. case'{':if(grace){syntax(1,"'{' in grace note")
  7229. break}
  7230. last_note_sav=curvoice.last_note;curvoice.last_note=null;a_dcn_sav=a_dcn;a_dcn=[]
  7231. grace={type:C.GRACE,fname:parse.fname,istart:parse.bol+line.index,dur:0,multi:0}
  7232. if(curvoice.color)
  7233. grace.color=curvoice.color
  7234. switch(curvoice.pos.gst&0x07){case C.SL_ABOVE:grace.stem=1;break
  7235. case C.SL_BELOW:grace.stem=-1;break
  7236. case C.SL_HIDDEN:grace.stem=2;break}
  7237. sym_link(grace);c=line.next_char()
  7238. if(c=='/'){grace.sappo=true
  7239. break}
  7240. continue
  7241. case'|':if(grace){syntax(1,errs.bar_grace)
  7242. break}
  7243. new_bar()
  7244. continue
  7245. case'}':if(curvoice.ignore){grace=null
  7246. break}
  7247. s=curvoice.last_note
  7248. if(!grace||!s){syntax(1,errs.bad_char,c)
  7249. break}
  7250. if(a_dcn.length)
  7251. syntax(1,"Decoration ignored");grace.extra=grace.next;grace.extra.prev=null;grace.next=null;curvoice.last_sym=grace;grace=null
  7252. if(!s.prev&&!curvoice.ckey.k_bagpipe){for(i=0;i<=s.nhd;i++)
  7253. s.notes[i].dur*=2;s.dur*=2;s.dur_orig*=2}
  7254. curvoice.last_note=last_note_sav;a_dcn=a_dcn_sav
  7255. break
  7256. case"\\":if(!line.buffer[line.index+1]){no_eol=true
  7257. break}
  7258. default:syntax(1,errs.bad_char,c)
  7259. break}
  7260. line.index++}}
  7261. if(parse.state!=3)
  7262. return
  7263. if(parse.tp){tp=parse.tp
  7264. tpn=parse.tpn
  7265. tps=parse.tps
  7266. parse.tp=null}
  7267. parse_seq()
  7268. if(tp.length){parse.tp=tp
  7269. parse.tps=tps
  7270. parse.tpn=tpn}
  7271. if(sls.length)
  7272. syntax(1,"Start of slur without note")
  7273. if(grace){syntax(1,"No end of grace note sequence");curvoice.last_sym=grace.prev;curvoice.last_note=last_note_sav
  7274. if(grace.prev)
  7275. grace.prev.next=null}
  7276. if(!no_eol&&!cfmt.barsperstaff&&!vover&&char_tb['\n'.charCodeAt(0)]=='\n')
  7277. curvoice.eoln=true
  7278. if(curvoice.eoln&&cfmt.breakoneoln&&curvoice.last_note)
  7279. curvoice.last_note.beam_end=true}
  7280. var sheet
  7281. var add_fstyle=typeof document!="undefined"?function(s){var e
  7282. if(cfmt.fullsvg)
  7283. font_style+="\n"+s
  7284. if(!sheet){if(abc2svg.sheet){sheet=abc2svg.sheet
  7285. e=sheet.cssRules.length
  7286. while(--e>=0)
  7287. sheet.deleteRule(e)}else{e=document.createElement('style')
  7288. document.head.appendChild(e)
  7289. abc2svg.sheet=sheet=e.sheet}}
  7290. s=s.match(/[^{]+{[^}]+}/g)
  7291. while(1){e=s.shift()
  7292. if(!e)
  7293. break
  7294. sheet.insertRule(e,sheet.cssRules.length)}}:function(s){font_style+="\n"+s}
  7295. var
  7296. sw_tb=new Float32Array([.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.250,.333,.408,.500,.500,.833,.778,.333,.333,.333,.500,.564,.250,.564,.250,.278,.500,.500,.500,.500,.500,.500,.500,.500,.500,.500,.278,.278,.564,.564,.564,.444,.921,.722,.667,.667,.722,.611,.556,.722,.722,.333,.389,.722,.611,.889,.722,.722,.556,.722,.667,.556,.611,.722,.722,.944,.722,.722,.611,.333,.278,.333,.469,.500,.333,.444,.500,.444,.500,.444,.333,.500,.500,.278,.278,.500,.278,.778,.500,.500,.500,.500,.333,.389,.278,.500,.500,.722,.500,.500,.444,.480,.200,.480,.541,.500]),ssw_tb=new Float32Array([.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.000,.278,.278,.355,.556,.556,.889,.667,.191,.333,.333,.389,.584,.278,.333,.278,.278,.556,.556,.556,.556,.556,.556,.556,.556,.556,.556,.278,.278,.584,.584,.584,.556,1.015,.667,.667,.722,.722,.667,.611,.778,.722,.278,.500,.667,.556,.833,.722,.778,.667,.778,.722,.667,.611,.722,.667,.944,.667,.667,.611,.278,.278,.278,.469,.556,.333,.556,.556,.500,.556,.556,.278,.556,.556,.222,.222,.500,.222,.833,.556,.556,.556,.556,.333,.500,.278,.556,.500,.722,.500,.500,.500,.334,.260,.334,.584,.512]),cw_tb=sw_tb
  7297. function cwid(c){var i=c.charCodeAt(0)
  7298. if(i>=0x80){if(i>=0x300&&i<0x370)
  7299. return 0;i=0x61}
  7300. return cw_tb[i]}
  7301. function cwidf(c){return cwid(c)*gene.curfont.swfac}
  7302. var strwh
  7303. (function(){if(typeof document!="undefined"){var el
  7304. strwh=function(str){if(str.wh)
  7305. return str.wh
  7306. if(!el){el=document.createElement('text')
  7307. el.style.position='absolute'
  7308. el.style.top='-1000px'
  7309. el.style.padding='0'
  7310. document.body.appendChild(el)}
  7311. var c,font=gene.curfont,h=font.size,w=0,n=str.length,i0=0,i=0
  7312. el.className=font_class(font)
  7313. el.style.lineHeight=1
  7314. if(typeof str=="object"){el.innerHTML=str
  7315. str.wh=[el.clientWidth,el.clientHeight]
  7316. return str.wh}
  7317. str=str.replace(/<|>|&[^&\s]*?;|&/g,function(c){switch(c){case'<':return"&lt;"
  7318. case'>':return"&gt;"
  7319. case'&':return"&amp;"}
  7320. return c})
  7321. while(1){i=str.indexOf('$',i)
  7322. if(i>=0){c=str[i+1]
  7323. if(c=='0'){font=gene.deffont}else if(c>='1'&&c<='9'){font=get_font("u"+c)}else{i++
  7324. continue}}
  7325. el.innerHTML=str.slice(i0,i>=0?i:undefined)
  7326. w+=el.clientWidth
  7327. if(el.clientHeight>h)
  7328. h=el.clientHeight
  7329. if(i<0)
  7330. break
  7331. el.style.font=style_font(font).slice(5);i+=2;i0=i}
  7332. return[w,h]}}else{strwh=function(str){var font=gene.curfont,swfac=font.swfac,h=font.size,w=0,i,j,c,n=str.length
  7333. for(i=0;i<n;i++){c=str[i]
  7334. switch(c){case'$':c=str[i+1]
  7335. if(c=='0'){font=gene.deffont}else if(c>='1'&&c<='9'){font=get_font("u"+c)}else{c='$'
  7336. break}
  7337. i++;swfac=font.swfac
  7338. if(font.size>h)
  7339. h=font.size
  7340. continue
  7341. case'&':if(str[i+1]==' ')
  7342. break
  7343. j=str.indexOf(';',i)
  7344. if(j>0&&j-i<10){i=j;c='a'}
  7345. break}
  7346. w+=cwid(c)*swfac}
  7347. return[w,h]}}})()
  7348. function str2svg(str){if(typeof str=="object")
  7349. return str
  7350. var n_font,wh,o_font=gene.deffont,c_font=gene.curfont,o=""
  7351. function tspan(nf,of){var cl
  7352. if(nf.class&&nf.name==of.name&&nf.size==of.size&&nf.weight==of.weight&&nf.style==of.style)
  7353. cl=nf.class
  7354. else
  7355. cl=font_class(nf)
  7356. return'<tspan\n\tclass="'+cl+'">'}
  7357. if(c_font!=o_font)
  7358. o=tspan(c_font,o_font)
  7359. o+=str.replace(/<|>|&[^&\s]*?;|&|\$./g,function(c){switch(c){case'<':return"&lt;"
  7360. case'>':return"&gt;"
  7361. case'&':return"&amp;"
  7362. default:if(c[0]!='$')
  7363. break
  7364. if(c[1]=='0')
  7365. n_font=gene.deffont
  7366. else if(c[1]>='1'&&c[1]<='9')
  7367. n_font=get_font("u"+c[1])
  7368. else
  7369. break
  7370. c=''
  7371. if(n_font==c_font)
  7372. return c
  7373. if(c_font!=o_font)
  7374. c="</tspan>"
  7375. c_font=n_font
  7376. if(c_font==o_font)
  7377. return c
  7378. return c+tspan(c_font,o_font)}
  7379. return c})
  7380. if(c_font!=o_font)
  7381. o+="</tspan>"
  7382. o=new String(o)
  7383. if(typeof document!="undefined")
  7384. strwh(o)
  7385. else
  7386. o.wh=strwh(str)
  7387. gene.curfont=c_font
  7388. return o}
  7389. function set_font(xxx){if(typeof xxx=="string")
  7390. xxx=get_font(xxx)
  7391. cw_tb=xxx.name.slice(0,4)=='sans'?ssw_tb:sw_tb
  7392. gene.curfont=gene.deffont=xxx}
  7393. function out_str(str){output+=str2svg(str)}
  7394. function xy_str(x,y,str,action,w,wh){if(!wh)
  7395. wh=str.wh||strwh(str)
  7396. output+='<text class="'+font_class(gene.deffont)
  7397. if(action!='j'&&str.length>5&&gene.deffont.wadj)
  7398. output+='" lengthAdjust="'+gene.deffont.wadj+'" textLength="'+wh[0].toFixed(1);output+='" x="';out_sxsy(x,'" y="',y)
  7399. switch(action){case'c':output+='" text-anchor="middle">'
  7400. break
  7401. case'j':output+='" textLength="'+w.toFixed(1)+'">'
  7402. break
  7403. case'r':output+='" text-anchor="end">'
  7404. break
  7405. default:output+='">'
  7406. break}
  7407. out_str(str);output+="</text>\n"}
  7408. function trim_title(title,is_subtitle){var i
  7409. if(cfmt.titletrim){i=title.lastIndexOf(", ")
  7410. if(i<0||title[i+2]<'A'||title[i+2]>'Z'){i=0}else if(cfmt.titletrim==1){if(i<title.length-7||title.indexOf(' ',i+3)>=0)
  7411. i=0}else{if(i<title.length-cfmt.titletrim-2)
  7412. i=0}
  7413. if(i)
  7414. title=title.slice(i+2).trim()+' '+title.slice(0,i)}
  7415. if(!is_subtitle&&cfmt.writefields.indexOf('X')>=0)
  7416. title=info.X+'. '+title
  7417. if(cfmt.titlecaps)
  7418. return title.toUpperCase()
  7419. return title}
  7420. function get_lwidth(){if(img.chg)
  7421. set_page()
  7422. return img.lw}
  7423. function write_title(title,is_subtitle){var h,wh
  7424. if(!title)
  7425. return
  7426. set_page();title=trim_title(title,is_subtitle)
  7427. if(is_subtitle){set_font("subtitle");h=cfmt.subtitlespace}else{set_font("title");h=cfmt.titlespace}
  7428. wh=strwh(title)
  7429. wh[1]+=gene.curfont.pad*2
  7430. vskip(wh[1]+h+gene.curfont.pad)
  7431. h=gene.curfont.pad+wh[1]*.22
  7432. if(cfmt.titleleft)
  7433. xy_str(0,h,title,null,null,wh)
  7434. else
  7435. xy_str(get_lwidth()/2,h,title,"c",null,wh)}
  7436. function put_inf2r(x,y,str1,str2,action){if(!str1){if(!str2)
  7437. return
  7438. str1=str2;str2=null}
  7439. if(!str2)
  7440. xy_str(x,y,str1,action)
  7441. else
  7442. xy_str(x,y,str1+' ('+str2+')',action)}
  7443. function write_text(text,action){if(action=='s')
  7444. return
  7445. set_page();var wh,font,o,strlw=get_lwidth(),sz=gene.curfont.size,lineskip=sz*cfmt.lineskipfac,parskip=sz*cfmt.parskipfac,i,j,x,words,w,k,ww,str;switch(action){default:font=gene.curfont
  7446. switch(action){case'c':x=strlw/2;break
  7447. case'r':x=strlw-font.pad;break
  7448. default:x=font.pad;break}
  7449. j=0
  7450. while(1){i=text.indexOf('\n',j)
  7451. if(i==j){vskip(parskip);blk_flush()
  7452. use_font(gene.curfont)
  7453. while(text[i+1]=='\n'){vskip(lineskip);i++}
  7454. if(i==text.length)
  7455. break}else{if(i<0)
  7456. str=text.slice(j)
  7457. else
  7458. str=text.slice(j,i)
  7459. ww=strwh(str)
  7460. vskip(ww[1]*cfmt.lineskipfac
  7461. +font.pad*2)
  7462. xy_str(x,font.pad+ww[1]*.2,str,action)
  7463. if(i<0)
  7464. break}
  7465. j=i+1}
  7466. vskip(parskip);blk_flush()
  7467. break
  7468. case'f':case'j':j=0
  7469. while(1){i=text.indexOf('\n\n',j)
  7470. if(i<0)
  7471. words=text.slice(j)
  7472. else
  7473. words=text.slice(j,i);words=words.split(/\s+/);w=k=wh=0
  7474. for(j=0;j<words.length;j++){ww=strwh(words[j]+' ')
  7475. w+=ww[0]
  7476. if(w>=strlw){vskip(wh*cfmt.lineskipfac)
  7477. xy_str(0,ww[1]*.2,words.slice(k,j).join(' '),action,strlw)
  7478. k=j;w=ww[0]
  7479. wh=0}
  7480. if(ww[1]>wh)
  7481. wh=ww[1]}
  7482. if(w!=0){vskip(wh*cfmt.lineskipfac)
  7483. xy_str(0,ww[1]*.2,words.slice(k).join(' '))}
  7484. vskip(parskip);blk_flush()
  7485. if(i<0)
  7486. break
  7487. while(text[i+2]=='\n'){vskip(lineskip);i++}
  7488. if(i==text.length)
  7489. break
  7490. use_font(gene.curfont);j=i+2}
  7491. break}}
  7492. function put_words(words){var p,i,j,nw,w,lw,x1,x2,i1,i2,do_flush,maxn=0,n=1
  7493. function put_wline(p,x){var i=0,k=0
  7494. if(p[0]=='$'&&p[1]>='0'&&p[1]<='9'){gene.curfont=p[1]=='0'?gene.deffont:get_font("u"+p[1])
  7495. p=p.slice(2)}
  7496. if((p[i]>='0'&&p[i]<='9')||p[i+1]=='.'){while(i<p.length){i++
  7497. if(p[i]==' '||p[i-1]==':'||p[i-1]=='.')
  7498. break}
  7499. k=i
  7500. while(p[i]==' ')
  7501. i++}
  7502. var y=gene.curfont.size*.22
  7503. if(k!=0)
  7504. xy_str(x,y,p.slice(0,k),'r')
  7505. if(i<p.length)
  7506. xy_str(x+5,y,p.slice(i),'l')}
  7507. set_font("words")
  7508. vskip(cfmt.wordsspace)
  7509. svg_flush()
  7510. words=words.split('\n')
  7511. nw=words.length
  7512. for(i=0;i<nw;i++){p=words[i]
  7513. if(!p){while(i+1<nw&&!words[i+1])
  7514. i++
  7515. n++}else if(p.length>maxn){maxn=p.length
  7516. i1=i}}
  7517. w=get_lwidth()/2
  7518. lw=strwh(words[i1])[0]
  7519. i1=i2=0
  7520. if(lw<w){j=n>>1
  7521. for(i=0;i<nw;i++){p=words[i]
  7522. if(!p){if(--j<=0)
  7523. i1=i
  7524. while(i+1<nw&&!words[i+1])
  7525. i++
  7526. if(j<=0){i2=i+1
  7527. break}}}
  7528. n>>=1}
  7529. if(i2){x1=(w-lw)/2+10
  7530. x2=x1+w}else{x2=w-lw/2+10}
  7531. do_flush=true
  7532. for(i=0;i<i1||i2<nw;i++,i2++){vskip(cfmt.lineskipfac*gene.curfont.size)
  7533. if(i<i1){p=words[i]
  7534. if(p)
  7535. put_wline(p,x1)
  7536. else
  7537. use_font(gene.curfont)}
  7538. if(i2<nw){p=words[i2]
  7539. if(p){put_wline(p,x2)}else{if(--n==0){if(i<i1){n++}else if(i2<nw-1){x2=w-lw/2+10
  7540. svg_flush()}}}}
  7541. if(!words[i+1]&&!words[i2+1]){if(do_flush){svg_flush()
  7542. do_flush=false}}else{do_flush=true}}}
  7543. function put_history(){var i,j,c,str,font,h,w,wh,head,names=cfmt.infoname.split("\n"),n=names.length
  7544. for(i=0;i<n;i++){c=names[i][0]
  7545. if(cfmt.writefields.indexOf(c)<0)
  7546. continue
  7547. str=info[c]
  7548. if(!str)
  7549. continue
  7550. if(!font){font=true;set_font("history");vskip(cfmt.textspace);h=gene.curfont.size*cfmt.lineskipfac}
  7551. head=names[i].slice(2)
  7552. if(head[0]=='"')
  7553. head=head.slice(1,-1);vskip(h);wh=strwh(head);xy_str(0,wh[1]*.22,head,null,null,wh);w=wh[0];str=str.split('\n');xy_str(w,wh[1]*.22,str[0])
  7554. for(j=1;j<str.length;j++){if(!str[j]){vskip(gene.curfont.size*cfmt.parskipfac)
  7555. continue}
  7556. vskip(h);xy_str(w,wh[1]*.22,str[j])}
  7557. vskip(h*cfmt.parskipfac)
  7558. use_font(gene.curfont)}}
  7559. var info_font_init={A:"info",C:"composer",O:"composer",P:"parts",Q:"tempo",R:"info",T:"title",X:"title"}
  7560. function write_headform(lwidth){var c,font,font_name,align,x,y,sz,w,info_val={},info_font=Object.create(info_font_init),info_sz={A:cfmt.infospace,C:cfmt.composerspace,O:cfmt.composerspace,R:cfmt.infospace},info_nb={}
  7561. var fmt="",p=cfmt.titleformat,j=0,i=0
  7562. while(1){while(p[i]==' ')
  7563. i++
  7564. c=p[i++]
  7565. if(!c)
  7566. break
  7567. if(c<'A'||c>'Z'){switch(c){case'+':align='+'
  7568. c=p[i++]
  7569. break
  7570. case',':fmt+='\n'
  7571. default:continue
  7572. case'<':align='l'
  7573. c=p[i++]
  7574. break
  7575. case'>':align='r'
  7576. c=p[i++]
  7577. break}}else{switch(p[i]){case'-':align='l'
  7578. i++
  7579. break
  7580. case'1':align='r'
  7581. i++
  7582. break
  7583. case'0':i++
  7584. default:align='c'
  7585. break}}
  7586. if(!info_val[c]){if(!info[c])
  7587. continue
  7588. info_val[c]=info[c].split('\n');info_nb[c]=1}else{info_nb[c]++}
  7589. fmt+=align+c}
  7590. fmt+='\n'
  7591. var ya={l:cfmt.titlespace,c:cfmt.titlespace,r:cfmt.titlespace},xa={l:0,c:lwidth*.5,r:lwidth},yb={},str;p=fmt;i=0
  7592. while(1){yb.l=yb.c=yb.r=y=0;j=i
  7593. while(1){align=p[j++]
  7594. if(align=='\n')
  7595. break
  7596. c=p[j++]
  7597. if(align=='+'||yb[align])
  7598. continue
  7599. str=info_val[c]
  7600. if(!str)
  7601. continue
  7602. font_name=info_font[c]
  7603. if(!font_name)
  7604. font_name="history";font=get_font(font_name);sz=font.size*1.1
  7605. if(info_sz[c])
  7606. sz+=info_sz[c]
  7607. if(y<sz)
  7608. y=sz;yb[align]=sz}
  7609. ya.l+=y-yb.l;ya.c+=y-yb.c;ya.r+=y-yb.r
  7610. while(1){align=p[i++]
  7611. if(align=='\n')
  7612. break
  7613. c=p[i++]
  7614. if(!info_val[c].length)
  7615. continue
  7616. str=info_val[c].shift()
  7617. if(p[i]=='+'){info_nb[c]--;i++
  7618. c=p[i++];if(info_val[c].length){if(str)
  7619. str+=' '+info_val[c].shift()
  7620. else
  7621. str=' '+info_val[c].shift()}}
  7622. font_name=info_font[c]
  7623. if(!font_name)
  7624. font_name="history";font=get_font(font_name);sz=font.size*1.1
  7625. if(info_sz[c])
  7626. sz+=info_sz[c];set_font(font);x=xa[align];y=ya[align]+sz
  7627. if(c=='Q'){self.set_width(glovar.tempo)
  7628. if(!glovar.tempo.invis){if(align!='l'){tempo_build(glovar.tempo)
  7629. w=glovar.tempo.tempo_wh[0]
  7630. if(align=='c')
  7631. w*=.5;x-=w}
  7632. writempo(glovar.tempo,x,-y)}}else if(str){if(c=='T')
  7633. str=trim_title(str,info_font.T[0]=='s')
  7634. xy_str(x,-y,str,align)}
  7635. if(c=='T'){font_name=info_font.T="subtitle";info_sz.T=cfmt.subtitlespace}
  7636. if(info_nb[c]<=1){if(c=='T'){font=get_font(font_name);sz=font.size*1.1
  7637. if(info_sz[c])
  7638. sz+=info_sz[c];set_font(font)}
  7639. while(info_val[c].length>0){y+=sz;str=info_val[c].shift();xy_str(x,-y,str,align)}}
  7640. info_nb[c]--;ya[align]=y}
  7641. if(ya.c>ya.l)
  7642. ya.l=ya.c
  7643. if(ya.r>ya.l)
  7644. ya.l=ya.r
  7645. if(i>=p.length)
  7646. break
  7647. ya.c=ya.r=ya.l}
  7648. vskip(ya.l)}
  7649. function write_heading(){var i,j,area,composer,origin,rhythm,down1,down2,lwidth=get_lwidth()
  7650. vskip(cfmt.topspace)
  7651. if(cfmt.titleformat){write_headform(lwidth);vskip(cfmt.musicspace)
  7652. return}
  7653. if(info.T&&cfmt.writefields.indexOf('T')>=0){i=0
  7654. while(1){j=info.T.indexOf("\n",i)
  7655. if(j<0){write_title(info.T.substring(i),i!=0)
  7656. break}
  7657. write_title(info.T.slice(i,j),i!=0);i=j+1}}
  7658. down1=down2=0
  7659. if(parse.ckey.k_bagpipe&&!cfmt.infoline&&cfmt.writefields.indexOf('R')>=0)
  7660. rhythm=info.R
  7661. if(rhythm){set_font("composer");down1=cfmt.composerspace+gene.curfont.size+2
  7662. xy_str(0,-down1+gene.curfont.size*.22,rhythm)}
  7663. area=info.A
  7664. if(cfmt.writefields.indexOf('C')>=0)
  7665. composer=info.C
  7666. if(cfmt.writefields.indexOf('O')>=0)
  7667. origin=info.O
  7668. if(composer||origin||cfmt.infoline){var xcomp,align;set_font("composer");if(cfmt.aligncomposer<0){xcomp=0;align=' '}else if(cfmt.aligncomposer==0){xcomp=lwidth*.5;align='c'}else{xcomp=lwidth;align='r'}
  7669. if(composer||origin){down2=cfmt.composerspace+2
  7670. i=0
  7671. while(1){down2+=gene.curfont.size
  7672. if(composer)
  7673. j=composer.indexOf("\n",i)
  7674. else
  7675. j=-1
  7676. if(j<0){put_inf2r(xcomp,-down2+gene.curfont.size*.22,composer?composer.substring(i):null,origin,align)
  7677. break}
  7678. xy_str(xcomp,-down2+gene.curfont.size*.22,composer.slice(i,j),align);i=j+1}}
  7679. rhythm=rhythm?null:info.R
  7680. if((rhythm||area)&&cfmt.infoline){set_font("info");down2+=cfmt.infospace+gene.curfont.size
  7681. put_inf2r(lwidth,-down2+gene.curfont.size*.22,rhythm,area,'r')}}
  7682. if(info.P&&cfmt.writefields.indexOf('P')>=0){set_font("parts");i=cfmt.partsspace+gene.curfont.size+gene.curfont.pad
  7683. if(down1+i>down2)
  7684. down2=down1+i
  7685. else
  7686. down2+=i
  7687. xy_str(0,-down2+gene.curfont.size*.22,info.P)
  7688. down2+=gene.curfont.pad}else if(down1>down2){down2=down1}
  7689. vskip(down2+cfmt.musicspace)}
  7690. var output="",style='\
  7691. \n.stroke{stroke:currentColor;fill:none}\
  7692. \n.bW{stroke:currentColor;fill:none;stroke-width:1}\
  7693. \n.bthW{stroke:currentColor;fill:none;stroke-width:3}\
  7694. \n.slW{stroke:currentColor;fill:none;stroke-width:.7}\
  7695. \n.slthW{stroke:currentColor;fill:none;stroke-width:1.5}\
  7696. \n.sW{stroke:currentColor;fill:none;stroke-width:.7}\
  7697. \n.box{outline:1px solid black;outline-offset:1px}',font_style='',posx=cfmt.leftmargin/cfmt.scale,posy=0,img={width:cfmt.pagewidth,lm:cfmt.leftmargin,rm:cfmt.rightmargin,chg:1},defined_glyph={},defs='',fulldefs='',stv_g={scale:1,dy:0,st:-1,v:-1,g:0},blkdiv=0
  7698. var tgls={"mtr ":{x:0,y:0,c:"\u0020"},brace:{x:0,y:0,c:"\ue000"},lphr:{x:0,y:23,c:"\ue030"},mphr:{x:0,y:23,c:"\ue038"},sphr:{x:0,y:26,c:"\ue039"},short:{x:0,y:32,c:"\ue038"},tick:{x:0,y:29,c:"\ue039"},rdots:{x:-1,y:0,c:"\ue043"},dsgn:{x:-12,y:0,c:"\ue045"},dcap:{x:-12,y:0,c:"\ue046"},sgno:{x:-5,y:0,c:"\ue047"},coda:{x:-10,y:0,c:"\ue048"},tclef:{x:-8,y:0,c:"\ue050"},cclef:{x:-8,y:0,c:"\ue05c"},bclef:{x:-8,y:0,c:"\ue062"},pclef:{x:-6,y:0,c:"\ue069"},spclef:{x:-6,y:0,c:"\ue069"},stclef:{x:-8,y:0,c:"\ue07a"},scclef:{x:-8,y:0,c:"\ue07b"},sbclef:{x:-7,y:0,c:"\ue07c"},oct:{x:0,y:2,c:"\ue07d"},oct2:{x:0,y:2,c:"\ue07e"},mtr0:{x:0,y:0,c:"\ue080"},mtr1:{x:0,y:0,c:"\ue081"},mtr2:{x:0,y:0,c:"\ue082"},mtr3:{x:0,y:0,c:"\ue083"},mtr4:{x:0,y:0,c:"\ue084"},mtr5:{x:0,y:0,c:"\ue085"},mtr6:{x:0,y:0,c:"\ue086"},mtr7:{x:0,y:0,c:"\ue087"},mtr8:{x:0,y:0,c:"\ue088"},mtr9:{x:0,y:0,c:"\ue089"},mtrC:{x:0,y:0,c:"\ue08a"},"mtr+":{x:0,y:0,c:"\ue08c"},"mtr(":{x:0,y:0,c:"\ue094"},"mtr)":{x:0,y:0,c:"\ue095"},HDD:{x:-7,y:0,c:"\ue0a0"},breve:{x:-7,y:0,c:"\ue0a1"},HD:{x:-5.2,y:0,c:"\ue0a2"},Hd:{x:-3.8,y:0,c:"\ue0a3"},hd:{x:-3.7,y:0,c:"\ue0a4"},ghd:{x:2,y:0,c:"\ue0a4",sc:.66},pshhd:{x:-3.7,y:0,c:"\ue0a9"},pfthd:{x:-3.7,y:0,c:"\ue0b3"},x:{x:-3.7,y:0,c:"\ue0a9"},"circle-x":{x:-3.7,y:0,c:"\ue0b3"},srep:{x:-5,y:0,c:"\ue101"},"dot+":{x:-5,y:0,sc:.7,c:"\ue101"},diamond:{x:-4,y:0,c:"\ue1b9"},triangle:{x:-4,y:0,c:"\ue1bb"},dot:{x:-1,y:0,c:"\ue1e7"},flu1:{x:-.3,y:0,c:"\ue240"},fld1:{x:-.3,y:0,c:"\ue241"},flu2:{x:-.3,y:0,c:"\ue242"},fld2:{x:-.3,y:0,c:"\ue243"},flu3:{x:-.3,y:3.5,c:"\ue244"},fld3:{x:-.3,y:-4,c:"\ue245"},flu4:{x:-.3,y:8,c:"\ue246"},fld4:{x:-.3,y:-9,c:"\ue247"},flu5:{x:-.3,y:12.5,c:"\ue248"},fld5:{x:-.3,y:-14,c:"\ue249"},"acc-1":{x:-1,y:0,c:"\ue260"},"cacc-1":{x:-18,y:0,c:"\ue26a\ue260\ue26b"},"sacc-1":{x:-1,y:0,sc:.7,c:"\ue260"},acc3:{x:-1,y:0,c:"\ue261"},"cacc3":{x:-18,y:0,c:"\ue26a\ue261\ue26b"},sacc3:{x:-1,y:0,sc:.7,c:"\ue261"},acc1:{x:-2,y:0,c:"\ue262"},"cacc1":{x:-18,y:0,c:"\ue26a\ue262\ue26b"},sacc1:{x:-2,y:0,sc:.7,c:"\ue262"},acc2:{x:-3,y:0,c:"\ue263"},"acc-2":{x:-3,y:0,c:"\ue264"},"acc-1_2":{x:-2,y:0,c:"\ue280"},"acc-3_2":{x:-3,y:0,c:"\ue281"},acc1_2:{x:-1,y:0,c:"\ue282"},acc3_2:{x:-3,y:0,c:"\ue283"},accent:{x:-3,y:2,c:"\ue4a0"},stc:{x:0,y:-2,c:"\ue4a2"},emb:{x:0,y:-2,c:"\ue4a4"},wedge:{x:0,y:0,c:"\ue4a8"},marcato:{x:-3,y:-2,c:"\ue4ac"},hld:{x:-7,y:-2,c:"\ue4c0"},brth:{x:0,y:0,c:"\ue4ce"},caes:{x:0,y:8,c:"\ue4d1"},r00:{x:-1.5,y:0,c:"\ue4e1"},r0:{x:-1.5,y:0,c:"\ue4e2"},r1:{x:-3.5,y:-6,c:"\ue4e3"},r2:{x:-3.2,y:0,c:"\ue4e4"},r4:{x:-3,y:0,c:"\ue4e5"},r8:{x:-3,y:0,c:"\ue4e6"},r16:{x:-4,y:0,c:"\ue4e7"},r32:{x:-4,y:0,c:"\ue4e8"},r64:{x:-4,y:0,c:"\ue4e9"},r128:{x:-4,y:0,c:"\ue4ea"},mrep:{x:-6,y:0,c:"\ue500"},mrep2:{x:-9,y:0,c:"\ue501"},p:{x:-3,y:0,c:"\ue520"},f:{x:-3,y:0,c:"\ue522"},pppp:{x:-15,y:0,c:"\ue529"},ppp:{x:-14,y:0,c:"\ue52a"},pp:{x:-8,y:0,c:"\ue52b"},mp:{x:-8,y:0,c:"\ue52c"},mf:{x:-8,y:0,c:"\ue52d"},ff:{x:-7,y:0,c:"\ue52f"},fff:{x:-10,y:0,c:"\ue530"},ffff:{x:-14,y:0,c:"\ue531"},sfz:{x:-10,y:0,c:"\ue539"},trl:{x:-5,y:-2,c:"\ue566"},turn:{x:-5,y:0,c:"\ue567"},turnx:{x:-5,y:0,c:"\ue569"},umrd:{x:-6,y:2,c:"\ue56c"},lmrd:{x:-6,y:2,c:"\ue56d"},dplus:{x:-3,y:0,c:"\ue582"},sld:{x:-8,y:12,c:"\ue5d0"},grm:{x:-3,y:-2,c:"\ue5e2"},dnb:{x:-3,y:0,c:"\ue610"},upb:{x:-2,y:0,c:"\ue612"},opend:{x:-2,y:-2,c:"\ue614"},roll:{x:0,y:0,c:"\ue618"},thumb:{x:-2,y:-2,c:"\ue624"},snap:{x:-2,y:-2,c:"\ue630"},ped:{x:-10,y:0,c:"\ue650"},pedoff:{x:-5,y:0,c:"\ue655"},mtro:{x:0,y:0,c:"\ue911"},mtrc:{x:0,y:0,c:"\ue915"},"mtr.":{x:0,y:0,c:"\ue920"},"mtr|":{x:0,y:0,c:"\ue925"},longa:{x:-4.7,y:0,c:"\ue95d"},custos:{x:-4,y:3,c:"\uea02"},ltr:{x:2,y:6,c:"\ueaa4"}}
  7699. var glyphs={}
  7700. function m_gl(s){return s.replace(/[Cco]\||[co]\.|./g,function(e){var m=tgls["mtr"+e]
  7701. return m?m.c:0})}
  7702. function def_use(gl){var i,j,g
  7703. if(defined_glyph[gl])
  7704. return
  7705. defined_glyph[gl]=true;g=glyphs[gl]
  7706. if(!g){error(1,null,"Unknown glyph: '$1'",gl)
  7707. return}
  7708. j=0
  7709. while(1){i=g.indexOf('xlink:href="#',j)
  7710. if(i<0)
  7711. break
  7712. i+=13;j=g.indexOf('"',i);def_use(g.slice(i,j))}
  7713. defs+='\n'+g}
  7714. function defs_add(text){var i,j,gl,tag,is,ie=0
  7715. text=text.replace(/<!--.*?-->/g,'')
  7716. while(1){is=text.indexOf('<',ie);if(is<0)
  7717. break
  7718. i=text.indexOf('id="',is)
  7719. if(i<0)
  7720. break
  7721. i+=4;j=text.indexOf('"',i);if(j<0)
  7722. break
  7723. gl=text.slice(i,j);ie=text.indexOf('>',j);if(ie<0)
  7724. break
  7725. if(text[ie-1]=='/'){ie++}else{i=text.indexOf(' ',is);if(i<0)
  7726. break
  7727. tag=text.slice(is+1,i);ie=text.indexOf('</'+tag+'>',ie)
  7728. if(ie<0)
  7729. break
  7730. ie+=3+tag.length}
  7731. if(text.substr(is,7)=='<filter')
  7732. fulldefs+=text.slice(is,ie)+'\n'
  7733. else
  7734. glyphs[gl]=text.slice(is,ie)}}
  7735. function set_g(){if(stv_g.started){stv_g.started=false;glout()
  7736. output+="</g>\n"}
  7737. if(stv_g.scale==1&&!stv_g.color)
  7738. return
  7739. glout()
  7740. output+='<g '
  7741. if(stv_g.scale!=1){if(stv_g.st<0)
  7742. output+=voice_tb[stv_g.v].scale_str
  7743. else if(stv_g.v<0)
  7744. output+=staff_tb[stv_g.st].scale_str
  7745. else
  7746. output+='transform="translate(0,'+
  7747. (posy-stv_g.dy).toFixed(1)+') scale('+stv_g.scale.toFixed(2)+')"'}
  7748. if(stv_g.color){if(stv_g.scale!=1)
  7749. output+=' ';output+='color="'+stv_g.color+'"'}
  7750. output+=">\n";stv_g.started=true}
  7751. function set_color(color){if(color==stv_g.color)
  7752. return undefined
  7753. var old_color=stv_g.color;stv_g.color=color;set_g()
  7754. return old_color}
  7755. function set_sscale(st){var new_scale,dy
  7756. if(st!=stv_g.st&&stv_g.scale!=1)
  7757. stv_g.scale=0;new_scale=st>=0?staff_tb[st].staffscale:1
  7758. if(st>=0&&new_scale!=1)
  7759. dy=staff_tb[st].y
  7760. else
  7761. dy=posy
  7762. if(new_scale==stv_g.scale&&dy==stv_g.dy)
  7763. return
  7764. stv_g.scale=new_scale;stv_g.dy=dy;stv_g.st=st;stv_g.v=-1;set_g()}
  7765. function set_scale(s){var new_dy,new_scale=s.p_v.scale
  7766. if(new_scale==1){set_sscale(s.st)
  7767. return}
  7768. new_dy=posy
  7769. if(staff_tb[s.st].staffscale!=1){new_scale*=staff_tb[s.st].staffscale;new_dy=staff_tb[s.st].y}
  7770. if(new_scale==stv_g.scale&&stv_g.dy==posy)
  7771. return
  7772. stv_g.scale=new_scale;stv_g.dy=new_dy;stv_g.st=staff_tb[s.st].staffscale==1?-1:s.st;stv_g.v=s.v;set_g()}
  7773. function set_dscale(st,no_scale){if(output){if(stv_g.started){stv_g.started=false
  7774. glout()
  7775. output+="</g>\n"}
  7776. if(stv_g.st<0){staff_tb[0].output+=output}else if(stv_g.scale==1){staff_tb[stv_g.st].output+=output}else{staff_tb[stv_g.st].sc_out+=output}
  7777. output=""}
  7778. if(st<0)
  7779. stv_g.scale=1
  7780. else
  7781. stv_g.scale=no_scale?1:staff_tb[st].staffscale;stv_g.st=st;stv_g.dy=0}
  7782. function delayed_update(){var st,new_out,text
  7783. for(st=0;st<=nstaff;st++){if(staff_tb[st].sc_out){output+='<g '+staff_tb[st].scale_str+'>\n'+
  7784. staff_tb[st].sc_out+'</g>\n';staff_tb[st].sc_out=""}
  7785. if(!staff_tb[st].output)
  7786. continue
  7787. output+='<g transform="translate(0,'+
  7788. (-staff_tb[st].y).toFixed(1)+')">\n'+
  7789. staff_tb[st].output+'</g>\n';staff_tb[st].output=""}}
  7790. function anno_out(s,t,f){if(s.istart==undefined)
  7791. return
  7792. var type=s.type,h=s.ymx-s.ymn+4,wl=s.wl||2,wr=s.wr||2
  7793. if(s.grace)
  7794. type=C.GRACE
  7795. f(t||abc2svg.sym_name[type],s.istart,s.iend,s.x-wl-2,staff_tb[s.st].y+s.ymn+h-2,wl+wr+4,h,s)}
  7796. function a_start(s,t){anno_out(s,t,user.anno_start)}
  7797. function a_stop(s,t){anno_out(s,t,user.anno_stop)}
  7798. function empty_function(){}
  7799. var anno_start=empty_function,anno_stop=empty_function
  7800. function anno_put(){var s
  7801. while(1){s=anno_a.shift()
  7802. if(!s)
  7803. break
  7804. switch(s.type){case C.CLEF:case C.METER:case C.KEY:case C.REST:if(s.type!=C.REST||s.rep_nb){set_sscale(s.st)
  7805. break}
  7806. case C.GRACE:case C.NOTE:case C.MREST:set_scale(s)
  7807. break}
  7808. anno_stop(s)}}
  7809. function out_XYAB(str,x,y,a,b){x=sx(x);y=sy(y);output+=str.replace(/X|Y|A|B|F|G/g,function(c){switch(c){case'X':return x.toFixed(1)
  7810. case'Y':return y.toFixed(1)
  7811. case'A':return a
  7812. case'B':return b
  7813. case'F':return a.toFixed(1)
  7814. default:return b.toFixed(1)}})}
  7815. function g_open(x,y,rot,sx,sy){glout()
  7816. out_XYAB('<g transform="translate(X,Y',x,y);if(rot)
  7817. output+=') rotate('+rot.toFixed(2)
  7818. if(sx){if(sy)
  7819. output+=') scale('+sx.toFixed(2)+', '+sy.toFixed(2)
  7820. else
  7821. output+=') scale('+sx.toFixed(2)}
  7822. output+=')">\n';stv_g.g++}
  7823. function g_close(){glout()
  7824. stv_g.g--;output+='</g>\n'}
  7825. Abc.prototype.out_svg=function(str){output+=str}
  7826. function sx(x){if(stv_g.g)
  7827. return x
  7828. return(x+posx)/stv_g.scale}
  7829. Abc.prototype.sx=sx
  7830. function sy(y){if(stv_g.g)
  7831. return-y
  7832. if(stv_g.scale==1)
  7833. return posy-y
  7834. if(stv_g.v>=0)
  7835. return(stv_g.dy-y)/voice_tb[stv_g.v].scale
  7836. return stv_g.dy-y}
  7837. Abc.prototype.sy=sy;Abc.prototype.sh=function(h){if(stv_g.st<0)
  7838. return h/stv_g.scale
  7839. return h}
  7840. Abc.prototype.ax=function(x){return x+posx}
  7841. Abc.prototype.ay=function(y){if(stv_g.st<0)
  7842. return posy-y
  7843. return posy+(stv_g.dy-y)*stv_g.scale-stv_g.dy}
  7844. Abc.prototype.ah=function(h){if(stv_g.st<0)
  7845. return h
  7846. return h*stv_g.scale}
  7847. function out_sxsy(x,sep,y){x=sx(x);y=sy(y);output+=x.toFixed(1)+sep+y.toFixed(1)}
  7848. Abc.prototype.out_sxsy=out_sxsy
  7849. function xypath(x,y,fill){if(fill)
  7850. out_XYAB('<path d="mX Y',x,y)
  7851. else
  7852. out_XYAB('<path class="stroke" d="mX Y',x,y)}
  7853. Abc.prototype.xypath=xypath
  7854. function draw_all_hl(){var st,p_st
  7855. function hlud(hla,d){var hl,hll,i,xp,dx2,x2,n=hla.length
  7856. if(!n)
  7857. return
  7858. for(i=0;i<n;i++){hll=hla[i]
  7859. if(!hll||!hll.length)
  7860. continue
  7861. xp=sx(hll[0][0])
  7862. output+='<path class="stroke" stroke-width="1" d="M'+
  7863. xp.toFixed(1)+' '+
  7864. sy(p_st.y+d*i).toFixed(1)
  7865. dx2=0
  7866. while(1){hl=hll.shift()
  7867. if(!hl)
  7868. break
  7869. x2=sx(hl[0])
  7870. output+='m'+
  7871. (x2-xp+hl[1]-dx2).toFixed(2)+' 0h'+(-hl[1]+hl[2]).toFixed(2)
  7872. xp=x2
  7873. dx2=hl[2]}
  7874. output+='"/>\n'}}
  7875. for(st=0;st<=nstaff;st++){p_st=staff_tb[st]
  7876. if(!p_st.hlu)
  7877. continue
  7878. set_sscale(st)
  7879. hlud(p_st.hlu,6)
  7880. hlud(p_st.hld,-6)}}
  7881. var gla=[[],[],"",[],[],[]]
  7882. function glout(){var e,v=[]
  7883. if(gla[0].length){while(1){e=gla[0].shift()
  7884. if(e==undefined)
  7885. break
  7886. v.push(e.toFixed(1))}
  7887. output+='<text x="'+v.join(',')
  7888. v=[]
  7889. while(1){e=gla[1].shift()
  7890. if(e==undefined)
  7891. break
  7892. v.push(e.toFixed(1))}
  7893. output+='"\ny="'+v.join(',')
  7894. output+='"\n>'+gla[2]+'</text>\n'
  7895. gla[2]=""}
  7896. if(!gla[3].length)
  7897. return
  7898. output+='<path class="sW" d="'
  7899. while(1){e=gla[3].shift()
  7900. if(e==undefined)
  7901. break
  7902. output+='M'+e.toFixed(1)+' '+gla[3].shift().toFixed(1)+'v'+gla[3].shift().toFixed(1)}
  7903. output+='"/>\n'}
  7904. function xygl(x,y,gl){if(glyphs[gl]){def_use(gl)
  7905. out_XYAB('<use x="X" y="Y" xlink:href="#A"/>\n',x,y,gl)}else{var tgl=tgls[gl]
  7906. if(tgl){x+=tgl.x*stv_g.scale;y-=tgl.y
  7907. if(tgl.sc){out_XYAB('<text transform="translate(X,Y) scale(A)">B</text>\n',x,y,tgl.sc,tgl.c)}else{gla[0].push(sx(x))
  7908. gla[1].push(sy(y))
  7909. gla[2]+=tgl.c}}else{error(1,null,'no definition of $1',gl)}}}
  7910. function out_acciac(x,y,dx,dy,up){if(up){x-=1;y+=4}else{x-=5;y-=4}
  7911. out_XYAB('<path class="stroke" d="mX YlF G"/>\n',x,y,dx,-dy)}
  7912. function out_brace(x,y,h){x+=posx-6;y=posy-y;h/=24;output+='<text transform="translate('+
  7913. x.toFixed(1)+','+y.toFixed(1)+') scale(2.5,'+h.toFixed(2)+')">'+tgls.brace.c+'</text>\n'}
  7914. function out_bracket(x,y,h){x+=posx-5;y=posy-y-3;h+=2;output+='<path d="m'+x.toFixed(1)+' '+y.toFixed(1)+'\n\
  7915. c10.5 1 12 -4.5 12 -3.5c0 1 -3.5 5.5 -8.5 5.5\n\
  7916. v'+h.toFixed(1)+'\n\
  7917. c5 0 8.5 4.5 8.5 5.5c0 1 -1.5 -4.5 -12 -3.5"/>\n'}
  7918. function out_hyph(x,y,w){var n,a_y,d=25+((w/20)|0)*3
  7919. if(w>15.)
  7920. n=((w-15)/d)|0
  7921. else
  7922. n=0;x+=(w-d*n-5)/2;out_XYAB('<path class="stroke" stroke-width="1.2"\n\
  7923. stroke-dasharray="5,A"\n\
  7924. d="mX YhB"/>\n',x,y+4,Math.round((d-5)/stv_g.scale),d*n+5)}
  7925. function out_stem(x,y,h,grace,nflags,straight){var dx=grace?GSTEM_XOFF:3.5,slen=-h
  7926. if(h<0)
  7927. dx=-dx;x+=dx*stv_g.scale
  7928. if(stv_g.v>=0)
  7929. slen/=voice_tb[stv_g.v].scale;gla[3].push(sx(x))
  7930. gla[3].push(sy(y))
  7931. gla[3].push(slen)
  7932. if(!nflags)
  7933. return
  7934. y+=h
  7935. if(h>0){if(!straight){if(!grace){xygl(x,y,"flu"+nflags)
  7936. return}else{output+='<path d="'
  7937. if(nflags==1){out_XYAB('MX Yc0.6 3.4 5.6 3.8 3 10\n\
  7938. 1.2 -4.4 -1.4 -7 -3 -7\n',x,y)}else{while(--nflags>=0){out_XYAB('MX Yc1 3.2 5.6 2.8 3.2 8\n\
  7939. 1.4 -4.8 -2.4 -5.4 -3.2 -5.2\n',x,y);y-=3.5}}}}else{output+='<path d="'
  7940. if(!grace){while(--nflags>=0){out_XYAB('MX Yl7 3.2 0 3.2 -7 -3.2z\n',x,y);y-=5.4}}else{while(--nflags>=0){out_XYAB('MX Yl3 1.5 0 2 -3 -1.5z\n',x,y);y-=3}}}}else{if(!straight){if(!grace){xygl(x,y,"fld"+nflags)
  7941. return}else{output+='<path d="'
  7942. if(nflags==1){out_XYAB('MX Yc0.6 -3.4 5.6 -3.8 3 -10\n\
  7943. 1.2 4.4 -1.4 7 -3 7\n',x,y)}else{while(--nflags>=0){out_XYAB('MX Yc1 -3.2 5.6 -2.8 3.2 -8\n\
  7944. 1.4 4.8 -2.4 5.4 -3.2 5.2\n',x,y);y+=3.5}}}}else{output+='<path d="'
  7945. if(!grace){while(--nflags>=0){out_XYAB('MX Yl7 -3.2 0 -3.2 -7 3.2z\n',x,y);y+=5.4}}}}
  7946. output+='"/>\n'}
  7947. function out_trem(x,y,ntrem){out_XYAB('<path d="mX Y\n\t',x-4.5,y)
  7948. while(1){output+='l9 -3v3l-9 3z'
  7949. if(--ntrem<=0)
  7950. break
  7951. output+='m0 5.4'}
  7952. output+='"/>\n'}
  7953. function out_tubr(x,y,dx,dy,up){var h=up?-3:3;y+=h;dx/=stv_g.scale;output+='<path class="stroke" d="m';out_sxsy(x,' ',y);output+='v'+h.toFixed(1)+'l'+dx.toFixed(1)+' '+(-dy).toFixed(1)+'v'+(-h).toFixed(1)+'"/>\n'}
  7954. function out_tubrn(x,y,dx,dy,up,str){var dxx,sw=str.length*10,h=up?-3:3;set_font("tuplet")
  7955. xy_str(x+dx/2,y+dy/2-gene.curfont.size*.1,str,'c')
  7956. dx/=stv_g.scale
  7957. if(!up)
  7958. y+=6;output+='<path class="stroke" d="m';out_sxsy(x,' ',y);dxx=dx-sw+1
  7959. if(dy>0)
  7960. sw+=dy/8
  7961. else
  7962. sw-=dy/8
  7963. output+='v'+h.toFixed(1)+'m'+dx.toFixed(1)+' '+(-dy).toFixed(1)+'v'+(-h).toFixed(1)+'"/>\n'+'<path class="stroke" stroke-dasharray="'+
  7964. (dxx/2).toFixed(1)+' '+sw.toFixed(1)+'" d="m';out_sxsy(x,' ',y-h);output+='l'+dx.toFixed(1)+' '+(-dy).toFixed(1)+'"/>\n'}
  7965. function out_wln(x,y,w){out_XYAB('<path class="stroke" stroke-width="0.8" d="mX YhF"/>\n',x,y+1,w)}
  7966. var deco_str_style={crdc:{dx:0,dy:5,style:'font:italic 14px text,serif',anchor:' text-anchor="middle"'},dacs:{dx:0,dy:3,style:'font:16px text,serif',anchor:' text-anchor="middle"'},pf:{dx:0,dy:5,style:'font:italic bold 16px text,serif'},'@':{dx:0,dy:5,style:'font:12px text,sans-serif'}}
  7967. function out_deco_str(x,y,name,str){if(name=='fng'){out_XYAB('\
  7968. <text x="X" y="Y" style="font-size:14px">A</text>\n',x-2,y,m_gl(str))
  7969. return}
  7970. var f,a_deco=deco_str_style[name]
  7971. if(!a_deco){xygl(x,y,name)
  7972. return}
  7973. x+=a_deco.dx;y+=a_deco.dy;if(!a_deco.def){style+="\n."+name+" {"+a_deco.style+"}";a_deco.def=true}
  7974. out_XYAB('<text x="X" y="Y" class="A"B>',x,y,name,a_deco.anchor||"");set_font("annotation");out_str(str);output+='</text>\n'}
  7975. function out_arp(x,y,val){g_open(x,y,270);x=0;val=Math.ceil(val/6)
  7976. while(--val>=0){xygl(x,6,"ltr");x+=6}
  7977. g_close()}
  7978. function out_cresc(x,y,val,defl){x+=val*stv_g.scale
  7979. val=-val;out_XYAB('<path class="stroke"\n\
  7980. d="mX YlF ',x,y,val)
  7981. if(defl.nost)
  7982. output+='-2.2m0 -3.6l'+(-val).toFixed(1)+' -2.2"/>\n'
  7983. else
  7984. output+='-4l'+(-val).toFixed(1)+' -4"/>\n'}
  7985. function out_dim(x,y,val,defl){out_XYAB('<path class="stroke"\n\
  7986. d="mX YlF ',x,y,val)
  7987. if(defl.noen)
  7988. output+='-2.2m0 -3.6l'+(-val).toFixed(1)+' -2.2"/>\n'
  7989. else
  7990. output+='-4l'+(-val).toFixed(1)+' -4"/>\n'}
  7991. function out_ltr(x,y,val){y+=4;val=Math.ceil(val/6)
  7992. while(--val>=0){xygl(x,y,"ltr");x+=6}}
  7993. Abc.prototype.out_lped=function(x,y,val,defl){if(!defl.nost)
  7994. xygl(x,y,"ped");if(!defl.noen)
  7995. xygl(x+val+6,y,"pedoff")}
  7996. function out_8va(x,y,val,defl){if(val<18){val=18
  7997. x-=4}
  7998. if(!defl.nost){out_XYAB('<text x="X" y="Y" \
  7999. style="font:italic bold 12px text,serif">8\
  8000. <tspan dy="-4" style="font-size:10px">va</tspan></text>\n',x-8,y);x+=12;val-=12}
  8001. y+=6;out_XYAB('<path class="stroke" stroke-dasharray="6,6" d="mX YhF"/>\n',x,y,val)
  8002. if(!defl.noen)
  8003. out_XYAB('<path class="stroke" d="mX Yv6"/>\n',x+val,y)}
  8004. function out_8vb(x,y,val,defl){if(val<18){val=18
  8005. x-=4}
  8006. if(!defl.nost){out_XYAB('<text x="X" y="Y" \
  8007. style="font:italic bold 12px text,serif">8\
  8008. <tspan dy=".5" style="font-size:10px">vb</tspan></text>\n',x-8,y);x+=10
  8009. val-=10}
  8010. out_XYAB('<path class="stroke" stroke-dasharray="6,6" d="mX YhF"/>\n',x,y,val)
  8011. if(!defl.noen)
  8012. out_XYAB('<path class="stroke" d="mX Yv-6"/>\n',x+val,y)}
  8013. function out_15ma(x,y,val,defl){if(val<25){val=25
  8014. x-=6}
  8015. if(!defl.nost){out_XYAB('<text x="X" y="Y" \
  8016. style="font:italic bold 12px text,serif">15\
  8017. <tspan dy="-4" style="font-size:10px">ma</tspan></text>\n',x-10,y);x+=20;val-=20}
  8018. y+=6;out_XYAB('<path class="stroke" stroke-dasharray="6,6" d="mX YhF"/>\n',x,y,val)
  8019. if(!defl.noen)
  8020. out_XYAB('<path class="stroke" d="mX Yv6"/>\n',x+val,y)}
  8021. function out_15mb(x,y,val,defl){if(val<24){val=24
  8022. x-=5}
  8023. if(!defl.nost){out_XYAB('<text x="X" y="Y" \
  8024. style="font:italic bold 12px text,serif">15\
  8025. <tspan dy=".5" style="font-size:10px">mb</tspan></text>\n',x-10,y);x+=18
  8026. val-=18}
  8027. out_XYAB('<path class="stroke" stroke-dasharray="6,6" d="mX YhF"/>\n',x,y,val)
  8028. if(!defl.noen)
  8029. out_XYAB('<path class="stroke" d="mX Yv-6"/>\n',x+val,y)}
  8030. var deco_val_tb={arp:out_arp,cresc:out_cresc,dim:out_dim,ltr:out_ltr,lped:function(x,y,val,defl){self.out_lped(x,y,val,defl)},"8va":out_8va,"8vb":out_8vb,"15ma":out_15ma,"15mb":out_15mb}
  8031. function out_deco_val(x,y,name,val,defl){if(deco_val_tb[name])
  8032. deco_val_tb[name](x,y,val,defl)
  8033. else
  8034. error(1,null,"No function for decoration '$1'",name)}
  8035. function out_glisq(x2,y2,de){var ar,a,len,de1=de.start,x1=de1.x,y1=de1.y+staff_tb[de1.st].y,dx=x2-x1,dy=self.sh(y1-y2)
  8036. if(!stv_g.g)
  8037. dx/=stv_g.scale
  8038. ar=Math.atan2(dy,dx)
  8039. a=ar/Math.PI*180
  8040. len=(dx-(de1.s.dots?13+de1.s.xmx:8)
  8041. -8-(de.s.notes[0].shac||0))
  8042. / Math.cos(ar)
  8043. g_open(x1,y1,a);x1=de1.s.dots?13+de1.s.xmx:8;len=len/6|0
  8044. if(len<1)
  8045. len=1
  8046. while(--len>=0){xygl(x1,0,"ltr");x1+=6}
  8047. g_close()}
  8048. function out_gliss(x2,y2,de){var ar,a,len,de1=de.start,x1=de1.x,y1=de1.y+staff_tb[de1.st].y,dx=x2-x1,dy=self.sh(y1-y2)
  8049. if(!stv_g.g)
  8050. dx/=stv_g.scale
  8051. ar=Math.atan2(dy,dx)
  8052. a=ar/Math.PI*180
  8053. len=(dx-(de1.s.dots?13+de1.s.xmx:8)
  8054. -8-(de.s.notes[0].shac||0))
  8055. / Math.cos(ar)
  8056. g_open(x1,y1,a);xypath(de1.s.dots?13+de1.s.xmx:8,0)
  8057. output+='h'+len.toFixed(1)+'" stroke-width="1"/>\n';g_close()}
  8058. var deco_l_tb={glisq:out_glisq,gliss:out_gliss}
  8059. function out_deco_long(x,y,de){var s,p_v,m,nt,i,name=de.dd.glyph,de1=de.start
  8060. if(!deco_l_tb[name]){error(1,null,"No function for decoration '$1'",name)
  8061. return}
  8062. p_v=de.s.p_v
  8063. if(de.defl.noen){s=p_v.s_next
  8064. while(s&&!s.dur)
  8065. s=s.next
  8066. if(s){for(m=0;m<=s.nhd;m++){nt=s.notes[m]
  8067. if(!nt.a_dd)
  8068. continue
  8069. for(i=0;i<nt.a_dd.length;i++){if(nt.a_dd[i].name==de.dd.name){y=3*(nt.pit-18)
  8070. +staff_tb[de.s.st].y
  8071. break}}}}
  8072. x+=8}else if(de.defl.nost){s=p_v.s_prev
  8073. while(s&&!s.dur)
  8074. s=s.prev
  8075. if(s){for(m=0;m<=s.nhd;m++){nt=s.notes[m]
  8076. if(!nt.a_dd)
  8077. continue
  8078. for(i=0;i<nt.a_dd.length;i++){if(nt.a_dd[i].name==de1.dd.name){de1.y=3*(nt.pit-18)
  8079. break}}}}
  8080. de1.x-=8}
  8081. deco_l_tb[name](x,y,de)}
  8082. function tempo_note(s,dur){var p,elts=identify_note(s,dur)
  8083. switch(elts[0]){case C.OVAL:p="\ueca2"
  8084. break
  8085. case C.EMPTY:p="\ueca3"
  8086. break
  8087. default:switch(elts[2]){case 2:p="\ueca9"
  8088. break
  8089. case 1:p="\ueca7"
  8090. break
  8091. default:p="\ueca5"
  8092. break}
  8093. break}
  8094. if(elts[1])
  8095. p+='<tspan dx=".1em">\uecb7</tspan>'
  8096. return p}
  8097. function tempo_build(s){var i,j,bx,p,wh,dy,w=0,str=[]
  8098. if(s.tempo_str)
  8099. return
  8100. if(!cfmt.musicfont.used)
  8101. get_font("music")
  8102. set_font("tempo")
  8103. if(s.tempo_str1){str.push(s.tempo_str1)
  8104. w+=strwh(s.tempo_str1)[0]}
  8105. if(s.tempo_notes){dy=' dy="-1"'
  8106. for(i=0;i<s.tempo_notes.length;i++){p=tempo_note(s,s.tempo_notes[i])
  8107. str.push('<tspan\nclass="'+
  8108. font_class(cfmt.musicfont)+'" style="font-size:'+
  8109. (gene.curfont.size*1.3).toFixed(1)+'px"'+
  8110. dy+'>'+
  8111. p+'</tspan>')
  8112. j=p.length>1?2:1
  8113. w+=j*gene.curfont.swfac
  8114. dy=''}
  8115. str.push('<tspan dy="1">=</tspan>')
  8116. w+=cwidf('=')
  8117. if(s.tempo_ca){str.push(s.tempo_ca)
  8118. w+=strwh(s.tempo_ca)[0]
  8119. j=s.tempo_ca.length+1}
  8120. if(s.tempo){str.push(s.tempo)
  8121. w+=strwh(s.tempo.toString())[0]}else{p=tempo_note(s,s.new_beat)
  8122. str.push('<tspan\nclass="'+
  8123. font_class(cfmt.musicfont)+'" style="font-size:'+
  8124. (gene.curfont.size*1.3).toFixed(1)+'px" dy="-1">'+
  8125. p+'</tspan>')
  8126. j=p.length>1?2:1
  8127. w+=j*gene.curfont.swfac
  8128. dy='y'}}
  8129. if(s.tempo_str2){if(dy)
  8130. str.push('<tspan\n\tdy="1">'+
  8131. s.tempo_str2+'</tspan>')
  8132. else
  8133. str.push(s.tempo_str2)
  8134. w+=strwh(s.tempo_str2)[0]}
  8135. s.tempo_str=str.join(' ')
  8136. w+=cwidf(' ')*(str.length-1)
  8137. s.tempo_wh=[w,13.0]}
  8138. function writempo(s,x,y){var bh
  8139. set_font("tempo")
  8140. if(gene.curfont.box){gene.curfont.box=false
  8141. bh=gene.curfont.size+4}
  8142. output+='<text class="'+font_class(gene.curfont)+'" x="'
  8143. out_sxsy(x,'" y="',y+gene.curfont.size*.22)
  8144. output+='">'+s.tempo_str+'</text>\n'
  8145. if(bh){gene.curfont.box=true
  8146. output+='<rect class="stroke" x="'
  8147. out_sxsy(x-2,'" y="',y+bh-1)
  8148. output+='" width="'+(s.tempo_wh[0]+4).toFixed(1)+'" height="'+bh.toFixed(1)+'"/>\n'}
  8149. s.invis=true}
  8150. function vskip(h){posy+=h}
  8151. function svg_flush(){if(multicol||!output||!user.img_out||posy==0)
  8152. return
  8153. var i,font,head='<svg xmlns="http://www.w3.org/2000/svg" version="1.1"\n\
  8154. xmlns:xlink="http://www.w3.org/1999/xlink"\n\
  8155. fill="currentColor" stroke-width=".7"',g=''
  8156. glout()
  8157. font=get_font("music")
  8158. head+=' class="'+font_class(font)+' tune'+tunes.length+'"\n'
  8159. posy*=cfmt.scale
  8160. if(user.imagesize!=undefined)
  8161. head+=user.imagesize
  8162. else
  8163. head+=' width="'+img.width.toFixed(0)
  8164. +'px" height="'+posy.toFixed(0)+'px"'
  8165. head+=' viewBox="0 0 '+img.width.toFixed(0)+' '
  8166. +posy.toFixed(0)+'">\n'
  8167. +fulldefs
  8168. if(style||font_style){head+='<style>'+font_style
  8169. if(cfmt.fgcolor||cfmt.bgcolor){head+='\n.f'+font.fid+(cfmt.fullsvg||'')
  8170. +'{'
  8171. +(cfmt.fgcolor?('color:'+cfmt.fgcolor+';'):'')
  8172. +(cfmt.bgcolor?('background-color:'+cfmt.bgcolor):'')
  8173. +'}'}
  8174. head+=style+'\n</style>\n'}
  8175. if(defs)
  8176. head+='<defs>'+defs+'\n</defs>\n'
  8177. if(cfmt.scale!=1){head+='<g class="g" transform="scale('+
  8178. cfmt.scale.toFixed(2)+')">\n';g='</g>\n'}
  8179. if(psvg)
  8180. psvg.ps_flush(true);if(blkdiv>0){user.img_out(blkdiv==1?'<div class="nobrk">':'<div class="nobrk newpage">')
  8181. blkdiv=-1}
  8182. user.img_out(head+output+g+"</svg>");output=""
  8183. font_style=''
  8184. if(cfmt.fullsvg){defined_glyph={}
  8185. for(i=0;i<abc2svg.font_tb.length;i++)
  8186. abc2svg.font_tb[i].used=false}else{style='';fulldefs=''}
  8187. defs='';posy=0}
  8188. function blk_flush(){svg_flush()
  8189. if(blkdiv<0&&(!parse.state||cfmt.splittune)){user.img_out('</div>')
  8190. blkdiv=0}}
  8191. Abc.prototype.blk_flush=blk_flush
  8192. var par_sy,cur_sy,voice_tb,curvoice,staves_found,vover,tsfirst
  8193. function voice_filter(){var opt
  8194. function vfilt(opts,opt){var i,sel=new RegExp(opt)
  8195. if(sel.test(curvoice.id)||sel.test(curvoice.nm)){for(i=0;i<opts.length;i++)
  8196. self.do_pscom(opts[i])}}
  8197. if(parse.voice_opts)
  8198. for(opt in parse.voice_opts){if(parse.voice_opts.hasOwnProperty(opt))
  8199. vfilt(parse.voice_opts[opt],opt)}
  8200. if(parse.tune_v_opts)
  8201. for(opt in parse.tune_v_opts){if(parse.tune_v_opts.hasOwnProperty(opt))
  8202. vfilt(parse.tune_v_opts[opt],opt)}}
  8203. function sym_link(s){var tim=curvoice.time
  8204. if(!s.fname)
  8205. set_ref(s)
  8206. if(!curvoice.ignore){s.prev=curvoice.last_sym
  8207. if(curvoice.last_sym)
  8208. curvoice.last_sym.next=s
  8209. else
  8210. curvoice.sym=s}
  8211. curvoice.last_sym=s
  8212. s.v=curvoice.v;s.p_v=curvoice;s.st=curvoice.cst;s.time=tim
  8213. if(s.dur&&!s.grace)
  8214. curvoice.time+=s.dur;parse.ufmt=true
  8215. s.fmt=cfmt
  8216. s.pos=curvoice.pos
  8217. if(curvoice.second)
  8218. s.second=true
  8219. if(curvoice.floating)
  8220. s.floating=true
  8221. if(curvoice.eoln){s.soln=true
  8222. curvoice.eoln=false}}
  8223. function sym_add(p_voice,type){var s={type:type,dur:0},s2,p_voice2=curvoice;curvoice=p_voice;sym_link(s);curvoice=p_voice2;s2=s.prev
  8224. if(!s2)
  8225. s2=s.next
  8226. if(s2){s.fname=s2.fname;s.istart=s2.istart;s.iend=s2.iend}
  8227. return s}
  8228. var w_tb=new Uint8Array([6,2,8,6,0,3,4,9,9,0,9,5,0,1,0,0,0,0])
  8229. function sort_all(){var s,s2,time,w,wmin,ir,fmt,v,p_voice,prev,fl,new_sy,nv=voice_tb.length,vtb=[],vn=[],sy=cur_sy
  8230. function b_chk(){var bt,s,s2,v,t,ir=0
  8231. while(1){v=vn[ir++]
  8232. if(v==undefined)
  8233. break
  8234. s=vtb[v]
  8235. if(!s||!s.bar_type||s.invis||s.time!=time)
  8236. continue
  8237. if(!bt){bt=s.bar_type
  8238. if(s.text&&bt=='|')
  8239. t=s.text
  8240. continue}
  8241. if(s.bar_type!=bt)
  8242. break
  8243. if(s.text&&!t&&bt=='|'){t=s.text
  8244. break}}
  8245. if(!fl){while(prev.type==C.GRACE&&vtb[prev.v]&&!vtb[prev.v].bar_type){vtb[prev.v]=prev
  8246. prev=prev.ts_prev
  8247. fl=1}}
  8248. if(v==undefined)
  8249. return
  8250. if(bt=="::"||bt==":|"||t){ir=0
  8251. bt=t?'|':"::"
  8252. while(1){v=vn[ir++]
  8253. if(v==undefined)
  8254. break
  8255. s=vtb[v]
  8256. if(!s||s.invis||s.bar_type!=bt||(bt=='|'&&!s.text))
  8257. continue
  8258. s2=clone(s)
  8259. if(bt=="::"){s.bar_type=":|"
  8260. s2.bar_type="|:"}else{delete s.text
  8261. delete s.rbstart
  8262. s2.bar_type='['
  8263. s2.invis=1
  8264. s2.xsh=0}
  8265. s2.next=s.next
  8266. if(s2.next)
  8267. s2.next.prev=s2
  8268. s2.prev=s
  8269. s.next=s2}}else{error(1,s,"Different bars $1 and $2",(bt+(t||'')),(s.bar_type+(s.text||'')))}}
  8270. for(v=0;v<nv;v++){s=voice_tb[v].sym
  8271. vtb[v]=s
  8272. if(sy.voices[v]){vn[sy.voices[v].range]=v
  8273. if(!prev&&s){fmt=s.fmt
  8274. p_voice=voice_tb[v]
  8275. prev={type:C.STAVES,fname:parse.fname,dur:0,v:v,p_v:p_voice,time:0,st:0,sy:sy,next:s,fmt:fmt,seqst:true}}}}
  8276. if(!prev)
  8277. return
  8278. p_voice.sym=tsfirst=s=prev
  8279. if(s.next)
  8280. s.next.prev=s
  8281. else
  8282. p_voice.last_sym=s
  8283. s=glovar.tempo
  8284. if(s){s.v=v=p_voice.v
  8285. s.p_v=p_voice
  8286. s.st=0
  8287. s.time=0
  8288. s.prev=prev
  8289. s.next=prev.next
  8290. if(s.next)
  8291. s.next.prev=s
  8292. else
  8293. p_voice.last_sym=s
  8294. s.prev.next=s
  8295. s.fmt=fmt
  8296. glovar.tempo=null
  8297. vtb[v]=s}
  8298. if(nv==1){s=tsfirst
  8299. s.ts_next=s.next
  8300. while(1){s=s.next
  8301. if(!s)
  8302. return
  8303. if(s.time!=s.prev.time||w_tb[s.prev.type]||s.type==C.GRACE&&s.prev.type==C.GRACE)
  8304. s.seqst=1
  8305. if(s.type==C.PART){s.prev.next=s.prev.ts_next=s.next
  8306. if(s.next){s.next.part=s
  8307. s.next.prev=s.prev
  8308. if(s.soln)
  8309. s.next.soln=1
  8310. if(s.seqst)
  8311. s.next.seqst=1}
  8312. continue}
  8313. s.ts_prev=s.prev
  8314. s.ts_next=s.next}}
  8315. while(1){if(new_sy){sy=new_sy;new_sy=null;vn.length=0
  8316. for(v=0;v<nv;v++){if(!sy.voices[v])
  8317. continue
  8318. vn[sy.voices[v].range]=v}}
  8319. wmin=time=10000000
  8320. ir=0
  8321. while(1){v=vn[ir++]
  8322. if(v==undefined)
  8323. break
  8324. s=vtb[v]
  8325. if(!s||s.time>time)
  8326. continue
  8327. w=w_tb[s.type]
  8328. if(s.type==C.GRACE&&s.next&&s.next.type==C.GRACE)
  8329. w--
  8330. if(s.time<time){time=s.time;wmin=w}else if(w<wmin){wmin=w}}
  8331. if(wmin>127)
  8332. break
  8333. if(wmin==6)
  8334. b_chk()
  8335. ir=0
  8336. while(1){v=vn[ir++]
  8337. if(v==undefined)
  8338. break
  8339. s=vtb[v]
  8340. if(!s||s.time!=time)
  8341. continue
  8342. w=w_tb[s.type]
  8343. if(!w&&s.type==C.GRACE&&s.next&&s.next.type==C.GRACE)
  8344. w--
  8345. if(w!=wmin)
  8346. continue
  8347. if(!w&&s.type==C.PART){if(s.prev)
  8348. s.prev.next=s.next
  8349. vtb[v]=s.next
  8350. if(s.next){s.next.part=s
  8351. s.next.prev=s.prev
  8352. if(s.soln)
  8353. s.next.soln=1}
  8354. continue}
  8355. if(s.type==C.STAVES)
  8356. new_sy=s.sy
  8357. if(fl){fl=0;s.seqst=true}
  8358. s.ts_prev=prev
  8359. prev.ts_next=s
  8360. prev=s
  8361. vtb[v]=s.next}
  8362. if(wmin)
  8363. fl=1}}
  8364. function voice_adj(sys_chg){var p_voice,s,s2,v,sl
  8365. function set_feathered_beam(s1){var s,s2,t,d,b,i,a,d=s1.dur,n=1
  8366. for(s=s1;s;s=s.next){if(s.beam_end||!s.next)
  8367. break
  8368. n++}
  8369. if(n<=1){delete s1.feathered_beam
  8370. return}
  8371. s2=s;b=d/2;a=d/(n-1);t=s1.time
  8372. if(s1.feathered_beam>0){for(s=s1,i=n-1;s!=s2;s=s.next,i--){d=((a*i)|0)+b;s.dur=d;s.time=t;t+=d}}else{for(s=s1,i=0;s!=s2;s=s.next,i++){d=((a*i)|0)+b;s.dur=d;s.time=t;t+=d}}
  8373. s.dur=s.time+s.dur-t;s.time=t}
  8374. if(curvoice&&curvoice.clone){parse.istart=parse.eol
  8375. do_cloning()}
  8376. if(par_sy.one_v)
  8377. fill_mr_ba(voice_tb[par_sy.top_voice])
  8378. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v]
  8379. if(!sys_chg){delete p_voice.eoln
  8380. while(1){sl=p_voice.sls.shift()
  8381. if(!sl)
  8382. break
  8383. s=sl.ss
  8384. if(!s.sls)
  8385. s.sls=[]
  8386. sl.loc='o'
  8387. s.sls.push(sl)}}
  8388. for(s=p_voice.sym;s;s=s.next){if(s.time>=staves_found)
  8389. break}
  8390. for(;s;s=s.next){if(w_tb[s.type]<5&&s.type!=C.STAVES&&s.type!=C.CLEF&&s.time&&(!s.prev||s.time>s.prev.time+s.prev.dur)){s2={type:C.BAR,bar_type:"[]",v:s.v,p_v:s.p_v,st:s.st,time:s.time,dur:0,next:s,prev:s.prev,fmt:s.fmt,invis:1}
  8391. if(s.prev)
  8392. s.prev.next=s2
  8393. else
  8394. voice_tb[s.v].sym=s2
  8395. s.prev=s2}
  8396. switch(s.type){case C.GRACE:if(!cfmt.graceword)
  8397. continue
  8398. for(s2=s.next;s2;s2=s2.next){switch(s2.type){case C.SPACE:continue
  8399. case C.NOTE:if(!s2.a_ly)
  8400. break
  8401. s.a_ly=s2.a_ly;s2.a_ly=null
  8402. break}
  8403. break}
  8404. continue}
  8405. if(s.feathered_beam)
  8406. set_feathered_beam(s)}}}
  8407. function new_syst(init){var st,v,sy_staff,p_voice,sy_new={voices:[],staves:[],top_voice:0}
  8408. if(init){cur_sy=par_sy=sy_new
  8409. return}
  8410. for(v=0;v<voice_tb.length;v++){if(par_sy.voices[v]){st=par_sy.voices[v].st
  8411. sy_staff=par_sy.staves[st]
  8412. p_voice=voice_tb[v]
  8413. sy_staff.staffnonote=p_voice.staffnonote
  8414. if(p_voice.staffscale)
  8415. sy_staff.staffscale=p_voice.staffscale}}
  8416. for(st=0;st<par_sy.staves.length;st++){sy_new.staves[st]=clone(par_sy.staves[st]);sy_new.staves[st].flags=0}
  8417. par_sy.next=sy_new;par_sy=sy_new}
  8418. Abc.prototype.set_bar_num=function(){var s,s2,rep_tim,k,n,nu,txt,tim=0,bar_num=gene.nbar,bar_tim=0,ptim=0,wmeasure=voice_tb[cur_sy.top_voice].meter.wmeasure
  8419. function check_meas(){var s3
  8420. if(tim>ptim+wmeasure&&s.prev.type!=C.MREST)
  8421. return 1
  8422. for(s3=s.next;s3&&s3.time==s.time;s3=s3.next);for(;s3&&!s3.bar_type;s3=s3.next);return s3&&(s3.time-bar_tim)%wmeasure}
  8423. for(s=tsfirst;;s=s.ts_next){if(!s)
  8424. return
  8425. switch(s.type){case C.METER:wmeasure=s.wmeasure
  8426. case C.CLEF:case C.KEY:case C.STBRK:continue
  8427. case C.BAR:if(s.bar_num)
  8428. bar_num=s.bar_num
  8429. break}
  8430. break}
  8431. for(s2=s.ts_next;s2;s2=s2.ts_next){if(s2.type==C.BAR&&s2.time){if(s2.time<wmeasure){s=s2
  8432. bar_tim=s.time}
  8433. break}}
  8434. for(;s;s=s.ts_next){switch(s.type){case C.METER:if(s.time==bar_tim)
  8435. break
  8436. if(wmeasure!=1)
  8437. bar_num+=(s.time-bar_tim)/wmeasure
  8438. bar_tim=s.time
  8439. wmeasure=s.wmeasure
  8440. break
  8441. case C.BAR:if(s.time<=tim)
  8442. break
  8443. tim=s.time
  8444. nu=1
  8445. txt=""
  8446. for(s2=s;s2;s2=s2.next){if(s2.time>tim||s2.dur)
  8447. break
  8448. if(!s2.bar_type)
  8449. continue
  8450. if(s2.bar_type!='[')
  8451. nu=0
  8452. if(s2.text)
  8453. txt=s2.text}
  8454. if(s.bar_num){bar_num=s.bar_num
  8455. ptim=bar_tim=tim
  8456. continue}
  8457. if(wmeasure==1){if(s.bar_dotted)
  8458. continue
  8459. if(txt){if(!cfmt.contbarnb){if(txt[0]=='1')
  8460. rep_tim=bar_num
  8461. else
  8462. bar_num=rep_tim}}
  8463. if(!nu)
  8464. s.bar_num=++bar_num
  8465. continue}
  8466. n=bar_num+(tim-bar_tim)/wmeasure
  8467. k=n-(n|0)
  8468. if(cfmt.checkbars&&k&&check_meas())
  8469. error(0,s,"Bad measure duration")
  8470. if(tim>ptim+wmeasure){n|=0
  8471. k=0
  8472. bar_tim=tim
  8473. bar_num=n}
  8474. if(txt){if(txt[0]=='1'){if(cfmt.contbarnb)
  8475. rep_tim=bar_tim+k*wmeasure
  8476. else
  8477. rep_tim=tim
  8478. if(!nu)
  8479. s.bar_num=n}else{if(cfmt.contbarnb)
  8480. bar_tim=rep_tim
  8481. else
  8482. bar_tim+=tim-rep_tim
  8483. n=bar_num+(tim-bar_tim)/wmeasure
  8484. if(n==(n|0))
  8485. s.bar_num=n}}else{n|=0
  8486. s.bar_num=n}
  8487. if(!k)
  8488. ptim=tim
  8489. break}}}
  8490. function not2abc(pit,acc){var i,nn=''
  8491. if(acc&&acc!=3){if(typeof acc!="object"){nn=['__','_','','^','^^'][acc+2]}else{i=acc[0]
  8492. if(i>0){nn+='^'}else{nn+='_'
  8493. i=-i}
  8494. nn+=i+'/'+acc[1]}}
  8495. nn+=ntb[(pit+75)%7]
  8496. for(i=pit;i>=23;i-=7)
  8497. nn+="'"
  8498. for(i=pit;i<16;i+=7)
  8499. nn+=","
  8500. return nn}
  8501. function get_map(text){if(!text)
  8502. return
  8503. var i,note,notes,map,tmp,ns,ty='',a=text.split(/\s+/)
  8504. if(a.length<3){syntax(1,not_enough_p)
  8505. return}
  8506. ns=a[1]
  8507. if(ns[0]=='*'||ns.indexOf("all")==0){ns='all'}else{if(ns.indexOf("octave,")==0||ns.indexOf("key,")==0){ty=ns[0]
  8508. ns=ns.split(',')[1]
  8509. ns=ns.replace(/[,']+/,'').toUpperCase()
  8510. if(ns.indexOf("key,")==0)
  8511. ns=ns.replace(/[=^_]+/,'')}
  8512. tmp=new scanBuf
  8513. tmp.buffer=ns
  8514. note=parse_acc_pit(tmp)
  8515. if(!note){syntax(1,"Bad note in %%map")
  8516. return}
  8517. ns=ty+not2abc(note.pit,note.acc)}
  8518. notes=maps[a[0]]
  8519. if(!notes)
  8520. maps[a[0]]=notes={}
  8521. map=notes[ns]
  8522. if(!map)
  8523. notes[ns]=map=[]
  8524. a.shift()
  8525. a.shift()
  8526. if(!a.length)
  8527. return
  8528. a=info_split(a.join(' '))
  8529. i=0
  8530. if(a[0].indexOf('=')<0){if(a[0][0]!='*'){tmp=new scanBuf;tmp.buffer=a[0];map[1]=parse_acc_pit(tmp)}
  8531. if(!a[1])
  8532. return
  8533. i++
  8534. if(a[1].indexOf('=')<0){map[0]=a[1].split(',')
  8535. i++}}
  8536. for(;i<a.length;i++){switch(a[i]){case"heads=":if(!a[++i]){syntax(1,not_enough_p)
  8537. break}
  8538. map[0]=a[i].split(',')
  8539. break
  8540. case"print=":case"play=":case"print_notrp=":if(!a[++i]){syntax(1,not_enough_p)
  8541. break}
  8542. tmp=new scanBuf;tmp.buffer=a[i];note=parse_acc_pit(tmp)
  8543. if(a[i-1][5]=='_')
  8544. note.notrp=1
  8545. if(a[i-1][1]=='r')
  8546. map[1]=note
  8547. else
  8548. map[3]=note
  8549. break
  8550. case"color=":if(!a[++i]){syntax(1,not_enough_p)
  8551. break}
  8552. map[2]=a[i]
  8553. break}}}
  8554. function new_ctrl(s){var ty=abc2svg.sym_name[s.type],tim=curvoice.time
  8555. if(!parse.ctrl)
  8556. parse.ctrl={}
  8557. if(!parse.ctrl[tim])
  8558. parse.ctrl[tim]={}
  8559. if(parse.ctrl[tim][ty])
  8560. return
  8561. parse.ctrl[tim][ty]=1
  8562. return 1}
  8563. function get_transp(param){if(param[0]=='0')
  8564. return 0
  8565. if("123456789-+".indexOf(param[0])>=0){var val=parseInt(param)
  8566. if(isNaN(val)||val<-36||val>36){syntax(1,errs.bad_transp)
  8567. return}
  8568. val+=36
  8569. val=((val/12|0)-3)*40+abc2svg.isb40[val%12]
  8570. if(param.slice(-1)=='b')
  8571. val+=4
  8572. return val}}
  8573. Abc.prototype.do_pscom=function(text){var h1,val,s,cmd,param,n,k,b
  8574. cmd=text.match(/[^\s]+/)
  8575. if(!cmd)
  8576. return
  8577. cmd=cmd[0];if(curvoice&&curvoice.ignore){switch(cmd){case"staves":case"score":break
  8578. default:return}}
  8579. param=text.replace(cmd,'').trim()
  8580. if(param.slice(-5)==' lock'){fmt_lock[cmd]=true;param=param.slice(0,-5).trim()}else if(fmt_lock[cmd]){return}
  8581. switch(cmd){case"clef":if(parse.state>=2){s=new_clef(param)
  8582. if(s)
  8583. get_clef(s)}
  8584. return
  8585. case"deco":deco_add(param)
  8586. return
  8587. case"linebreak":set_linebreak(param)
  8588. return
  8589. case"map":get_map(param)
  8590. return
  8591. case"maxsysstaffsep":case"sysstaffsep":if(parse.state==3){val=get_unit(param)
  8592. if(isNaN(val)){syntax(1,errs.bad_val,"%%"+cmd)
  8593. return}
  8594. par_sy.voices[curvoice.v][cmd[0]=='m'?"maxsep":"sep"]=val
  8595. return}
  8596. break
  8597. case"multicol":switch(param){case"start":case"new":case"end":break
  8598. default:syntax(1,"Unknown keyword '$1' in %%multicol",param)
  8599. return}
  8600. s={type:C.BLOCK,subtype:"mc_"+param,dur:0}
  8601. if(parse.state>=2){curvoice=voice_tb[0]
  8602. curvoice.eoln=1
  8603. sym_link(s)
  8604. return}
  8605. set_ref(s)
  8606. self.block_gen(s)
  8607. return
  8608. case"ottava":if(parse.state!=3)
  8609. return
  8610. n=parseInt(param)
  8611. if(isNaN(n)||n<-2||n>2||(!n&&!curvoice.ottava)){syntax(1,errs.bad_val,"%%ottava")
  8612. return}
  8613. k=n
  8614. if(n){curvoice.ottava=n}else{n=curvoice.ottava
  8615. curvoice.ottava=0}
  8616. a_dcn.push(["15mb","8vb","","8va","15ma"][n+2]
  8617. +(k?'(':')'))
  8618. return
  8619. case"repbra":if(curvoice)
  8620. curvoice.norepbra=!get_bool(param)
  8621. return
  8622. case"repeat":if(parse.state!=3)
  8623. return
  8624. if(!curvoice.last_sym){syntax(1,"%%repeat cannot start a tune")
  8625. return}
  8626. if(!param.length){n=1;k=1}else{b=param.split(/\s+/);n=parseInt(b[0]);k=parseInt(b[1])
  8627. if(isNaN(n)||n<1||(curvoice.last_sym.type==C.BAR&&n>2)){syntax(1,"Incorrect 1st value in %%repeat")
  8628. return}
  8629. if(isNaN(k)){k=1}else{if(k<1){syntax(1,"Incorrect 2nd value in %%repeat")
  8630. return}}}
  8631. parse.repeat_n=curvoice.last_sym.type==C.BAR?n:-n;parse.repeat_k=k
  8632. return
  8633. case"sep":var h2,len,values,lwidth;set_page();lwidth=img.width-img.lm-img.rm;h1=h2=len=0
  8634. if(param){values=param.split(/\s+/);h1=get_unit(values[0])
  8635. if(values[1]){h2=get_unit(values[1])
  8636. if(values[2])
  8637. len=get_unit(values[2])}
  8638. if(isNaN(h1)||isNaN(h2)||isNaN(len)){syntax(1,errs.bad_val,"%%sep")
  8639. return}}
  8640. if(h1<1)
  8641. h1=14
  8642. if(h2<1)
  8643. h2=h1
  8644. if(len<1)
  8645. len=90
  8646. if(parse.state>=2){s=new_block(cmd);s.x=(lwidth-len)/2/cfmt.scale;s.l=len/cfmt.scale;s.sk1=h1;s.sk2=h2
  8647. return}
  8648. vskip(h1);output+='<path class="stroke"\n\td="M';out_sxsy((lwidth-len)/2/cfmt.scale,' ',0);output+='h'+(len/cfmt.scale).toFixed(1)+'"/>\n';vskip(h2);blk_flush()
  8649. return
  8650. case"setbarnb":val=parseInt(param)
  8651. if(isNaN(val)||val<1){syntax(1,"Bad %%setbarnb value")
  8652. break}
  8653. glovar.new_nbar=val
  8654. return
  8655. case"staff":if(parse.state!=3)
  8656. return
  8657. val=parseInt(param)
  8658. if(isNaN(val)){syntax(1,"Bad %%staff value '$1'",param)
  8659. return}
  8660. var st
  8661. if(param[0]=='+'||param[0]=='-')
  8662. st=curvoice.cst+val
  8663. else
  8664. st=val-1
  8665. if(st<0||st>nstaff){syntax(1,"Bad %%staff number $1 (cur $2, max $3)",st,curvoice.cst,nstaff)
  8666. return}
  8667. delete curvoice.floating;curvoice.cst=st
  8668. return
  8669. case"staffbreak":if(parse.state!=3)
  8670. return
  8671. s={type:C.STBRK,dur:0}
  8672. if(param.slice(-1)=='f'){s.stbrk_forced=true
  8673. param=param.replace(/\sf$/,'')}
  8674. if(param){val=get_unit(param)
  8675. if(isNaN(val)){syntax(1,errs.bad_val,"%%staffbreak")
  8676. return}
  8677. s.xmx=val}else{s.xmx=14}
  8678. sym_link(s)
  8679. return
  8680. case"tacet":if(param[0]=='"')
  8681. param=param.slice(1,-1)
  8682. case"stafflines":case"staffscale":case"staffnonote":set_v_param(cmd,param)
  8683. return
  8684. case"staves":case"score":if(!parse.state)
  8685. return
  8686. if(parse.scores&&parse.scores.length>0){text=parse.scores.shift();cmd=text.match(/([^\s]+)\s*(.*)/);param=cmd[2]
  8687. cmd=cmd[1]}
  8688. get_staves(cmd,param)
  8689. return
  8690. case"center":case"text":k=cmd[0]=='c'?'c':cfmt.textoption
  8691. set_font("text")
  8692. if(parse.state>=2){s=new_block("text")
  8693. s.text=param
  8694. s.opt=k
  8695. s.font=cfmt.textfont
  8696. return}
  8697. write_text(param,k)
  8698. return
  8699. case"transpose":if(cfmt.sound)
  8700. return
  8701. val=get_transp(param)
  8702. if(val==undefined){val=get_interval(param)
  8703. if(val==undefined)
  8704. return}
  8705. switch(parse.state){case 0:cfmt.transp=0
  8706. case 1:cfmt.transp=(cfmt.transp||0)+val
  8707. return}
  8708. cfmt.transp=(cfmt.transp||0)+val
  8709. key_trans()
  8710. return
  8711. case"tune":return
  8712. case"user":set_user(param)
  8713. return
  8714. case"voicecolor":if(curvoice)
  8715. curvoice.color=param
  8716. return
  8717. case"vskip":val=get_unit(param)
  8718. if(isNaN(val)){syntax(1,errs.bad_val,"%%vskip")
  8719. return}
  8720. if(val<0){syntax(1,"%%vskip cannot be negative")
  8721. return}
  8722. if(parse.state>=2){s=new_block(cmd);s.sk=val
  8723. return}
  8724. vskip(val);return
  8725. case"newpage":case"leftmargin":case"rightmargin":case"pagescale":case"pagewidth":case"printmargin":case"scale":case"staffwidth":if(parse.state>=2){s=new_block(cmd);s.param=param
  8726. return}
  8727. if(cmd=="newpage"){blk_flush()
  8728. if(user.page_format)
  8729. blkdiv=2
  8730. return}
  8731. break}
  8732. self.set_format(cmd,param)}
  8733. Abc.prototype.do_begin_end=function(type,opt,text){var i,j,action,s
  8734. switch(type){case"js":js_inject(text)
  8735. break
  8736. case"ml":if(cfmt.pageheight){syntax(1,"Cannot have %%beginml with %%pageheight")
  8737. break}
  8738. if(parse.state>=2){s=new_block(type);s.text=text}else{blk_flush()
  8739. if(user.img_out)
  8740. user.img_out(text)}
  8741. break
  8742. case"svg":j=0
  8743. while(1){i=text.indexOf('<style',j)
  8744. if(i<0)
  8745. break
  8746. i=text.indexOf('>',i)
  8747. j=text.indexOf('</style>',i)
  8748. if(j<0){syntax(1,"No </style> in %%beginsvg sequence")
  8749. break}
  8750. style+=text.slice(i+1,j).replace(/\s+$/,'')}
  8751. j=0
  8752. while(1){i=text.indexOf('<defs>\n',j)
  8753. if(i<0)
  8754. break
  8755. j=text.indexOf('</defs>',i)
  8756. if(j<0){syntax(1,"No </defs> in %%beginsvg sequence")
  8757. break}
  8758. defs_add(text.slice(i+6,j))}
  8759. break
  8760. case"text":action=get_textopt(opt);if(!action)
  8761. action=cfmt.textoption
  8762. set_font("text")
  8763. if(text.indexOf('\\')>=0)
  8764. text=cnv_escape(text)
  8765. if(parse.state>1){s=new_block(type);s.text=text
  8766. s.opt=action
  8767. s.font=cfmt.textfont
  8768. break}
  8769. write_text(text,action)
  8770. break}}
  8771. function generate(){var s,v,p_voice;if(a_dcn.length){syntax(1,"Decoration without symbol")
  8772. a_dcn=[]}
  8773. if(parse.tp){syntax(1,"No end of tuplet")
  8774. s=parse.tps
  8775. if(s)
  8776. delete s.tp
  8777. delete parse.tp}
  8778. if(vover){syntax(1,"No end of voice overlay");get_vover(vover.bar?'|':')')}
  8779. voice_adj();sort_all()
  8780. if(tsfirst){for(v=0;v<voice_tb.length;v++){if(!voice_tb[v].key)
  8781. voice_tb[v].key=parse.ckey}
  8782. if(user.anno_start)
  8783. anno_start=a_start
  8784. if(user.anno_stop)
  8785. anno_stop=a_stop
  8786. self.set_bar_num()
  8787. if(info.P)
  8788. tsfirst.parts=info.P
  8789. if(user.get_abcmodel)
  8790. user.get_abcmodel(tsfirst,voice_tb,abc2svg.sym_name,info)
  8791. if(user.img_out)
  8792. self.output_music()}
  8793. set_page()
  8794. if(info.W)
  8795. put_words(info.W)
  8796. put_history()
  8797. parse.state=0
  8798. blk_flush()
  8799. if(tsfirst){tunes.push([tsfirst,voice_tb,info,cfmt])
  8800. tsfirst=null}}
  8801. function key_trans(){var i,n,a_acc,b40,s=curvoice.ckey,ti=s.time||0
  8802. if(s.k_bagpipe||s.k_drum)
  8803. return
  8804. n=(curvoice.score|0)
  8805. +(curvoice.shift|0)
  8806. +(cfmt.transp|0)
  8807. if((curvoice.tr_sco|0)==n)
  8808. return
  8809. if(is_voice_sig()){curvoice.key=s}else if(curvoice.time!=ti){s=clone(s.orig||s)
  8810. if(!curvoice.new)
  8811. s.k_old_sf=curvoice.ckey.k_sf
  8812. sym_link(s)}
  8813. curvoice.ckey=s
  8814. if(cfmt.transp&&curvoice.shift)
  8815. syntax(0,"Mix of old and new transposition syntaxes");curvoice.tr_sco=n
  8816. b40=(s.k_b40+200+n)%40
  8817. i=abc2svg.b40k[b40]-b40
  8818. if(i){curvoice.tr_sco+=i
  8819. b40+=i}
  8820. s.orig=clone(s)
  8821. s.k_b40=b40
  8822. if(!s.k_none)
  8823. s.k_sf=abc2svg.b40sf[b40]
  8824. if(!s.k_a_acc)
  8825. return
  8826. a_acc=[]
  8827. for(i=0;i<s.k_a_acc.length;i++){b40=abc2svg.pab40(s.k_a_acc[i].pit,s.k_a_acc[i].acc)+d
  8828. a_acc[i]={pit:abc2svg.b40p(b40),acc:abc2svg.b40a(b40)||3}}
  8829. s.k_a_acc=a_acc}
  8830. function fill_mr_ba(p_v){var v,p_v2,mxt=0
  8831. for(v=0;v<voice_tb.length;v++){if(voice_tb[v].time>mxt){p_v2=voice_tb[v]
  8832. mxt=p_v2.time}}
  8833. if(p_v.time>=mxt)
  8834. return
  8835. var p_v_sav=curvoice,dur=mxt-p_v.time,s={type:C.MREST,stem:0,multi:0,nhd:0,xmx:0,frm:1,dur:dur,dur_orig:dur,nmes:dur/p_v.wmeasure,notes:[{pit:18,dur:dur}],tacet:p_v.tacet},s2={type:C.BAR,bar_type:'|',dur:0,multi:0}
  8836. if(p_v2.last_sym.bar_type)
  8837. s2.bar_type=p_v2.last_sym.bar_type
  8838. glovar.mrest_p=1
  8839. curvoice=p_v
  8840. sym_link(s)
  8841. sym_link(s2)
  8842. curvoice=p_v_sav}
  8843. function get_staves(cmd,parm){var s,p_voice,p_voice2,i,flags,v,vid,a_vf,st,range,nv=voice_tb.length,maxtime=0
  8844. if(parm){a_vf=parse_staves(parm)
  8845. if(!a_vf)
  8846. return}else if(staves_found<0){syntax(1,errs.bad_val,'%%'+cmd)
  8847. return}
  8848. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  8849. if(p_voice.time>maxtime)
  8850. maxtime=p_voice.time}
  8851. if(!maxtime){par_sy.staves=[]
  8852. par_sy.voices=[]}else{voice_adj(true)
  8853. for(v=0;v<par_sy.voices.length;v++){if(par_sy.voices[v]){curvoice=voice_tb[v]
  8854. break}}
  8855. curvoice.time=maxtime;s={type:C.STAVES,dur:0}
  8856. sym_link(s);par_sy.nstaff=nstaff;if(!parm){s.sy=clone(par_sy,1)
  8857. par_sy.next=s.sy
  8858. par_sy=s.sy
  8859. staves_found=maxtime
  8860. for(v=0;v<nv;v++)
  8861. voice_tb[v].time=maxtime
  8862. curvoice=voice_tb[par_sy.top_voice]
  8863. return}
  8864. new_syst();s.sy=par_sy}
  8865. staves_found=maxtime
  8866. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  8867. delete p_voice.second
  8868. delete p_voice.floating
  8869. if(p_voice.ignore){p_voice.ignore=0
  8870. s=p_voice.sym
  8871. if(s){while(s.next)
  8872. s=s.next}
  8873. p_voice.last_sym=s}}
  8874. range=0
  8875. for(i=0;i<a_vf.length;i++){vid=a_vf[i][0];p_voice=new_voice(vid);p_voice.time=maxtime;v=p_voice.v
  8876. a_vf[i][0]=p_voice;while(1){par_sy.voices[v]={range:range++}
  8877. p_voice=p_voice.voice_down
  8878. if(!p_voice)
  8879. break
  8880. v=p_voice.v}}
  8881. par_sy.top_voice=a_vf[0][0].v
  8882. if(a_vf.length==1)
  8883. par_sy.one_v=1
  8884. if(cmd[1]=='t'){for(i=0;i<a_vf.length;i++){flags=a_vf[i][1]
  8885. if(!(flags&(OPEN_BRACE|OPEN_BRACE2)))
  8886. continue
  8887. if((flags&(OPEN_BRACE|CLOSE_BRACE))==(OPEN_BRACE|CLOSE_BRACE)||(flags&(OPEN_BRACE2|CLOSE_BRACE2))==(OPEN_BRACE2|CLOSE_BRACE2))
  8888. continue
  8889. if(a_vf[i+1][1]!=0)
  8890. continue
  8891. if((flags&OPEN_PARENTH)||(a_vf[i+2][1]&OPEN_PARENTH))
  8892. continue
  8893. if(a_vf[i+2][1]&(CLOSE_BRACE|CLOSE_BRACE2)){a_vf[i+1][1]|=FL_VOICE}else if(a_vf[i+2][1]==0&&(a_vf[i+3][1]&(CLOSE_BRACE|CLOSE_BRACE2))){a_vf[i][1]|=OPEN_PARENTH;a_vf[i+1][1]|=CLOSE_PARENTH;a_vf[i+2][1]|=OPEN_PARENTH;a_vf[i+3][1]|=CLOSE_PARENTH}}}
  8894. st=-1
  8895. for(i=0;i<a_vf.length;i++){flags=a_vf[i][1]
  8896. if((flags&(OPEN_PARENTH|CLOSE_PARENTH))==(OPEN_PARENTH|CLOSE_PARENTH)){flags&=~(OPEN_PARENTH|CLOSE_PARENTH);a_vf[i][1]=flags}
  8897. p_voice=a_vf[i][0]
  8898. if(flags&FL_VOICE){p_voice.floating=true;p_voice.second=true}else{st++;if(!par_sy.staves[st]){par_sy.staves[st]={stafflines:p_voice.stafflines||"|||||",staffscale:1}}
  8899. par_sy.staves[st].flags=0}
  8900. v=p_voice.v;p_voice.st=p_voice.cst=par_sy.voices[v].st=st;par_sy.staves[st].flags|=flags
  8901. if(flags&OPEN_PARENTH){p_voice2=p_voice
  8902. while(i<a_vf.length-1){p_voice=a_vf[++i][0];v=p_voice.v
  8903. if(a_vf[i][1]&MASTER_VOICE){p_voice2.second=true
  8904. p_voice2=p_voice}else{p_voice.second=true}
  8905. p_voice.st=p_voice.cst=par_sy.voices[v].st=st
  8906. if(a_vf[i][1]&CLOSE_PARENTH)
  8907. break}
  8908. par_sy.staves[st].flags|=a_vf[i][1]}}
  8909. if(st<0)
  8910. st=0
  8911. par_sy.nstaff=nstaff=st
  8912. if(cmd[1]=='c'){for(st=0;st<nstaff;st++)
  8913. par_sy.staves[st].flags^=STOP_BAR}
  8914. nv=voice_tb.length
  8915. st=0
  8916. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  8917. if(par_sy.voices[v])
  8918. st=p_voice.st
  8919. else
  8920. p_voice.st=st
  8921. if(!maxtime){for(s=p_voice.sym;s;s=s.next)
  8922. s.st=st}
  8923. if(!par_sy.voices[v])
  8924. continue
  8925. p_voice2=p_voice.voice_down
  8926. while(p_voice2){i=p_voice2.v
  8927. p_voice2.st=p_voice2.cst=par_sy.voices[i].st=st
  8928. p_voice2=p_voice2.voice_down}
  8929. par_sy.voices[v].second=p_voice.second;st=p_voice.st
  8930. if(st>0&&p_voice.norepbra==undefined&&!(par_sy.staves[st-1].flags&STOP_BAR))
  8931. p_voice.norepbra=true}
  8932. curvoice=parse.state>=2?voice_tb[par_sy.top_voice]:null}
  8933. function clone_voice(id){var v,p_voice
  8934. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v]
  8935. if(p_voice.id==id)
  8936. return p_voice}
  8937. p_voice=clone(curvoice);p_voice.v=voice_tb.length;p_voice.id=id;p_voice.sym=p_voice.last_sym=null;p_voice.key=clone(curvoice.key)
  8938. p_voice.sls=[]
  8939. delete p_voice.nm
  8940. delete p_voice.snm
  8941. delete p_voice.new_name
  8942. delete p_voice.lyric_restart
  8943. delete p_voice.lyric_cont
  8944. delete p_voice.sym_restart
  8945. delete p_voice.sym_cont
  8946. delete p_voice.have_ly
  8947. delete p_voice.tie_s
  8948. voice_tb.push(p_voice)
  8949. return p_voice}
  8950. function get_vover(type){var p_voice2,p_voice3,range,s,time,v,v2,v3,s2
  8951. if(type=='|'||type==')'){if(!curvoice.last_note){syntax(1,errs.nonote_vo)
  8952. if(vover){curvoice=vover.p_voice
  8953. vover=null}
  8954. return}
  8955. curvoice.last_note.beam_end=true
  8956. if(!vover){syntax(1,"Erroneous end of voice overlay")
  8957. return}
  8958. if(curvoice.time!=vover.p_voice.time){if(!curvoice.ignore)
  8959. syntax(1,"Wrong duration in voice overlay");if(curvoice.time>vover.p_voice.time)
  8960. vover.p_voice.time=curvoice.time}
  8961. curvoice.acc=[]
  8962. p_voice2=vover.p_voice
  8963. s=curvoice.last_sym
  8964. if(s.type==C.SPACE&&p_voice2.last_sym.type!=C.SPACE){s.p_v=p_voice2
  8965. s.v=s.p_v.v
  8966. while(s.prev.type==C.SPACE){s=s.prev
  8967. s.p_v=p_voice2
  8968. s.v=s.p_v.v}
  8969. s2=s.prev
  8970. s2.next=null
  8971. s.prev=p_voice2.last_sym
  8972. s.prev.next=s
  8973. p_voice2.last_sym=curvoice.last_sym
  8974. curvoice.last_sym=s2}
  8975. curvoice=p_voice2
  8976. vover=null
  8977. return}
  8978. if(type=='('){if(vover){syntax(1,"Voice overlay already started")
  8979. return}
  8980. vover={p_voice:curvoice,time:curvoice.time}
  8981. return}
  8982. if(!curvoice.last_note){syntax(1,errs.nonote_vo)
  8983. return}
  8984. curvoice.last_note.beam_end=true;p_voice2=curvoice.voice_down
  8985. if(!p_voice2){p_voice2=clone_voice(curvoice.id+'o');curvoice.voice_down=p_voice2;p_voice2.time=0;p_voice2.second=true;p_voice2.last_note=null
  8986. v2=p_voice2.v;if(par_sy.voices[curvoice.v]){par_sy.voices[v2]={st:curvoice.st,second:true}
  8987. range=par_sy.voices[curvoice.v].range
  8988. for(v=0;v<par_sy.voices.length;v++){if(par_sy.voices[v]&&par_sy.voices[v].range>range)
  8989. par_sy.voices[v].range++}
  8990. par_sy.voices[v2].range=range+1}}
  8991. p_voice2.ulen=curvoice.ulen
  8992. p_voice2.dur_fact=curvoice.dur_fact
  8993. p_voice2.acc=[]
  8994. if(!vover){time=p_voice2.time
  8995. if(curvoice.ignore)
  8996. s=null
  8997. else
  8998. for(s=curvoice.last_sym;;s=s.prev){if(s.type==C.BAR||s.time<=time)
  8999. break}
  9000. vover={bar:(s&&s.bar_type)?s.bar_type:'|',p_voice:curvoice,time:s?s.time:curvoice.time}}else{if(curvoice!=vover.p_voice&&curvoice.time!=vover.p_voice.time){syntax(1,"Wrong duration in voice overlay")
  9001. if(curvoice.time>vover.p_voice.time)
  9002. vover.p_voice.time=curvoice.time}}
  9003. p_voice2.time=vover.time;curvoice=p_voice2}
  9004. function is_voice_sig(){var s
  9005. if(curvoice.time)
  9006. return false
  9007. if(!curvoice.last_sym)
  9008. return true
  9009. for(s=curvoice.last_sym;s;s=s.prev)
  9010. if(w_tb[s.type])
  9011. return false
  9012. return true}
  9013. function get_clef(s){var s2,s3
  9014. if(s.clef_type=='p'){s2=curvoice.ckey
  9015. s2.k_drum=1
  9016. s2.k_sf=0
  9017. s2.k_b40=2
  9018. s2.k_map=abc2svg.keys[7]
  9019. if(!curvoice.key)
  9020. curvoice.key=s2}
  9021. if(!curvoice.time&&is_voice_sig()){curvoice.clef=s
  9022. s.fmt=cfmt
  9023. return}
  9024. for(s2=curvoice.last_sym;s2&&s2.time==curvoice.time;s2=s2.prev){if(w_tb[s2.type])
  9025. break}
  9026. if(s2&&s2.time==curvoice.time&&s2.k_sf!=undefined){s3=s2
  9027. s2=s2.prev}
  9028. if(s2&&s2.time==curvoice.time&&s2.bar_type&&s2.bar_type[0]!=':')
  9029. s3=s2
  9030. if(s3){s2=curvoice.last_sym
  9031. curvoice.last_sym=s3.prev
  9032. sym_link(s)
  9033. s.next=s3
  9034. s3.prev=s
  9035. curvoice.last_sym=s2
  9036. if(s.soln){delete s.soln
  9037. curvoice.eoln=true}}else{sym_link(s)}
  9038. if(s.prev)
  9039. s.clef_small=1}
  9040. function get_key(parm){var v,p_voice,transp,sndtran,nt,a=new_key(parm),s_key=a[0],s=s_key,empty=s.k_sf==undefined&&!s.k_a_acc
  9041. a=a[1]
  9042. if(empty)
  9043. s.invis=1
  9044. if(parse.state==1){parse.ckey=s
  9045. if(empty){s_key.k_sf=0;s_key.k_none=true
  9046. s_key.k_map=abc2svg.keys[7]}
  9047. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v];p_voice.ckey=clone(s_key)}
  9048. if(a.length){memo_kv_parm('*',a)
  9049. a=[]}
  9050. if(!glovar.ulen)
  9051. glovar.ulen=C.BLEN/8;goto_tune()}else if(!empty){s.k_old_sf=curvoice.ckey.k_sf
  9052. curvoice.ckey=s
  9053. sym_link(s)
  9054. if(curvoice.tr_sco)
  9055. curvoice.tr_sco=0}
  9056. if(!curvoice){if(!voice_tb.length){curvoice=new_voice("1")
  9057. var def=1}else{curvoice=voice_tb[staves_found<0?0:par_sy.top_voice]}}
  9058. p_voice=curvoice.clone
  9059. if(p_voice)
  9060. curvoice.clone=null
  9061. get_voice(curvoice.id+' '+a.join(' '))
  9062. if(p_voice)
  9063. curvoice.clone=p_voice
  9064. if(def)
  9065. curvoice.default=1}
  9066. function new_voice(id){var v,p_v_sav,p_voice=voice_tb[0],n=voice_tb.length
  9067. if(n==1&&p_voice.default){delete p_voice.default
  9068. if(!p_voice.time){p_voice.id=id
  9069. return p_voice}}
  9070. for(v=0;v<n;v++){p_voice=voice_tb[v]
  9071. if(p_voice.id==id)
  9072. return p_voice}
  9073. p_voice={v:v,id:id,time:0,new:true,pos:{},scale:1,ulen:glovar.ulen,dur_fact:1,meter:clone(glovar.meter),wmeasure:glovar.meter.wmeasure,staffnonote:1,clef:{type:C.CLEF,clef_auto:true,clef_type:"a",time:0},acc:[],sls:[],hy_st:0}
  9074. voice_tb.push(p_voice);if(parse.state==3){p_voice.ckey=clone(parse.ckey)
  9075. if(p_voice.ckey.k_bagpipe&&!p_voice.pos.stm){p_voice.pos=clone(p_voice.pos)
  9076. p_voice.pos.stm&=~0x07
  9077. p_voice.pos.stm|=C.SL_BELOW}}
  9078. return p_voice}
  9079. function init_tune(){nstaff=-1;voice_tb=[];curvoice=null;new_syst(true);staves_found=-1;gene={}
  9080. a_de=[]
  9081. cross={}}
  9082. function do_cloning(){var i,clone=curvoice.clone,vs=clone.vs,a=clone.a,bol=clone.bol,eol=parse.eol,parse_sav=parse,file=parse.file
  9083. delete curvoice.clone
  9084. if(file[eol-1]=='[')
  9085. eol--
  9086. include++;for(i=0;i<vs.length;i++){parse=Object.create(parse_sav)
  9087. parse.line=Object.create(parse_sav.line)
  9088. get_voice(vs[i]+' '+a.join(' '))
  9089. tosvg(parse.fname,file,bol,eol)}
  9090. include--
  9091. parse=parse_sav}
  9092. function get_voice(parm){var v,vs,a=info_split(parm),vid=a.shift()
  9093. if(!vid)
  9094. return
  9095. if(curvoice&&curvoice.clone)
  9096. do_cloning()
  9097. if(vid.indexOf(',')>0)
  9098. vs=vid.split(',')
  9099. else
  9100. vs=[vid]
  9101. if(parse.state<2){while(1){vid=vs.shift()
  9102. if(!vid)
  9103. break
  9104. if(a.length)
  9105. memo_kv_parm(vid,a)
  9106. if(vid!='*'&&parse.state==1)
  9107. curvoice=new_voice(vid)}
  9108. return}
  9109. if(vid=='*'){syntax(1,"Cannot have V:* in tune body")
  9110. return}
  9111. curvoice=new_voice(vs[0])
  9112. if(vs.length>1){vs.shift()
  9113. curvoice.clone={vs:vs,a:a,bol:parse.iend}
  9114. if(parse.file[curvoice.clone.bol-1]!=']')
  9115. curvoice.clone.bol++}
  9116. set_kv_parm(a)
  9117. key_trans()
  9118. v=curvoice.v
  9119. if(curvoice.new){delete curvoice.new
  9120. if(staves_found<0){curvoice.st=curvoice.cst=++nstaff;par_sy.nstaff=nstaff;par_sy.voices[v]={st:nstaff,range:v}
  9121. par_sy.staves[nstaff]={stafflines:curvoice.stafflines||"|||||",staffscale:1}}else if(!par_sy.voices[v]){curvoice.ignore=1
  9122. return}}
  9123. if(!curvoice.filtered&&par_sy.voices[v]&&(parse.voice_opts||parse.tune_v_opts)){curvoice.filtered=true;voice_filter()}}
  9124. function goto_tune(){var v,p_voice
  9125. set_page();write_heading();if(glovar.new_nbar){gene.nbar=glovar.new_nbar
  9126. glovar.new_nbar=0}else{gene.nbar=1}
  9127. parse.state=3
  9128. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v];p_voice.ulen=glovar.ulen
  9129. if(parse.ckey.k_bagpipe&&!p_voice.pos.stm){p_voice.pos=clone(p_voice.pos)
  9130. p_voice.pos.stm&=~0x07
  9131. p_voice.pos.stm|=C.SL_BELOW}}
  9132. if(staves_found<0){v=voice_tb.length
  9133. par_sy.nstaff=nstaff=v-1
  9134. while(--v>=0){p_voice=voice_tb[v];delete p_voice.new;p_voice.st=p_voice.cst=v;par_sy.voices[v]={st:v,range:v}
  9135. par_sy.staves[v]={stafflines:p_voice.stafflines||"|||||",staffscale:1}}}}
  9136. function get_sym(p,cont){var s,c,i,j,d
  9137. if(curvoice.ignore)
  9138. return
  9139. if(cont){s=curvoice.sym_cont
  9140. if(!s){syntax(1,"+: symbol line without music")
  9141. return}}else{if(curvoice.sym_restart){curvoice.sym_start=curvoice.sym_restart;curvoice.sym_restart=null}
  9142. s=curvoice.sym_start
  9143. if(!s)
  9144. s=curvoice.sym
  9145. if(!s){syntax(1,"s: without music")
  9146. return}}
  9147. i=0
  9148. while(1){while(p[i]==' '||p[i]=='\t')
  9149. i++;c=p[i]
  9150. if(!c)
  9151. break
  9152. switch(c){case'|':while(s&&s.type!=C.BAR)
  9153. s=s.next
  9154. if(!s){syntax(1,"Not enough measure bars for symbol line")
  9155. return}
  9156. s=s.next;i++
  9157. continue
  9158. case'!':case'"':j=++i
  9159. i=p.indexOf(c,j)
  9160. if(i<0){syntax(1,c=='!'?"No end of decoration":"No end of chord symbol/annotation");i=p.length
  9161. continue}
  9162. d=p.slice(j-1,i+1)
  9163. break
  9164. case'*':break
  9165. default:d=c.charCodeAt(0)
  9166. if(d<128){d=char_tb[d]
  9167. if(d.length>1&&(d[0]=='!'||d[0]=='"')){c=d[0]
  9168. break}}
  9169. syntax(1,errs.bad_char,c)
  9170. break}
  9171. while(s&&s.type!=C.NOTE)
  9172. s=s.next
  9173. if(!s){syntax(1,"Too many elements in symbol line")
  9174. return}
  9175. switch(c){default:break
  9176. case'!':a_dcn.push(d.slice(1,-1))
  9177. deco_cnv(s,s.prev)
  9178. break
  9179. case'"':parse_gchord(d)
  9180. if(a_gch)
  9181. csan_add(s)
  9182. break}
  9183. s=s.next;i++}
  9184. curvoice.sym_cont=s}
  9185. function get_lyrics(text,cont){var s,word,p,i,j,ly,dfnt,ln,c,cf
  9186. if(curvoice.ignore)
  9187. return
  9188. if((curvoice.pos.voc&0x07)!=C.SL_HIDDEN)
  9189. curvoice.have_ly=true
  9190. if(cont){s=curvoice.lyric_cont
  9191. if(!s){syntax(1,"+: lyric without music")
  9192. return}
  9193. dfnt=get_font("vocal")
  9194. if(gene.deffont!=dfnt){if(gene.curfont==gene.deffont)
  9195. gene.curfont=dfnt
  9196. gene.deffont=dfnt}}else{set_font("vocal")
  9197. if(curvoice.lyric_restart){curvoice.lyric_start=s=curvoice.lyric_restart;curvoice.lyric_restart=null;curvoice.lyric_line=0}else{curvoice.lyric_line++;s=curvoice.lyric_start}
  9198. if(!s)
  9199. s=curvoice.sym
  9200. if(!s){syntax(1,"w: without music")
  9201. return}}
  9202. p=text;i=0
  9203. cf=gene.curfont
  9204. while(1){while(p[i]==' '||p[i]=='\t')
  9205. i++
  9206. if(!p[i])
  9207. break
  9208. ln=0
  9209. j=parse.istart+i+2
  9210. switch(p[i]){case'|':while(s&&s.type!=C.BAR)
  9211. s=s.next
  9212. if(!s){syntax(1,"Not enough measure bars for lyric line")
  9213. return}
  9214. s=s.next;i++
  9215. continue
  9216. case'-':case'_':word=p[i]
  9217. ln=p[i]=='-'?2:3
  9218. break
  9219. case'*':word=""
  9220. break
  9221. default:word="";while(1){if(!p[i])
  9222. break
  9223. switch(p[i]){case'_':case'*':case'|':i--
  9224. case' ':case'\t':break
  9225. case'~':word+=' '
  9226. i++
  9227. continue
  9228. case'-':ln=1
  9229. break
  9230. case'\\':if(!p[++i])
  9231. continue
  9232. word+=p[i++]
  9233. continue
  9234. case'$':word+=p[i++]
  9235. c=p[i]
  9236. if(c=='0')
  9237. gene.curfont=gene.deffont
  9238. else if(c>='1'&&c<='9')
  9239. gene.curfont=get_font("u"+c)
  9240. default:word+=p[i++]
  9241. continue}
  9242. break}
  9243. break}
  9244. while(s&&s.type!=C.NOTE)
  9245. s=s.next
  9246. if(!s){syntax(1,"Too many words in lyric line")
  9247. return}
  9248. if(word&&(s.pos.voc&0x07)!=C.SL_HIDDEN){ly={t:word,font:cf,istart:j,iend:j+word.length}
  9249. if(ln)
  9250. ly.ln=ln
  9251. if(!s.a_ly)
  9252. s.a_ly=[]
  9253. s.a_ly[curvoice.lyric_line]=ly
  9254. cf=gene.curfont}
  9255. s=s.next;i++}
  9256. curvoice.lyric_cont=s}
  9257. function ly_set(s){var i,j,ly,d,s1,s2,p,w,spw,xx,sz,shift,dw,s3=s,wx=0,wl=0,n=0,dx=0,a_ly=s.a_ly,align=0
  9258. for(s2=s.ts_next;s2;s2=s2.ts_next){if(s2.shrink){dx+=s2.shrink
  9259. n++}
  9260. if(s2.bar_type){dx+=3
  9261. break}
  9262. if(!s2.a_ly)
  9263. continue
  9264. i=s2.a_ly.length
  9265. while(--i>=0){ly=s2.a_ly[i]
  9266. if(!ly)
  9267. continue
  9268. if(!ly.ln||ly.ln<2)
  9269. break}
  9270. if(i>=0)
  9271. break}
  9272. for(i=0;i<a_ly.length;i++){ly=a_ly[i]
  9273. if(!ly)
  9274. continue
  9275. gene.curfont=ly.font
  9276. ly.t=p=str2svg(ly.t)
  9277. if(ly.ln>=2){ly.shift=0
  9278. continue}
  9279. spw=cwid(' ')*ly.font.swfac
  9280. w=p.wh[0]+spw*1.5
  9281. if(s.type==C.GRACE){shift=s.wl}else if((p[0]>='0'&&p[0]<='9'&&p.length>2)||p[1]==':'||p[0]=='('||p[0]==')'){if(p[0]=='('){sz=spw}else{j=p.indexOf(' ')
  9282. set_font(ly.font)
  9283. if(j>0)
  9284. sz=strwh(p.slice(0,j))[0]
  9285. else
  9286. sz=w*.2}
  9287. shift=(w-sz)*.4
  9288. if(shift>14)
  9289. shift=14
  9290. shift+=sz
  9291. if(p[0]>='0'&&p[0]<='9'){if(shift>align)
  9292. align=shift}}else{shift=w*.4
  9293. if(shift>14)
  9294. shift=14}
  9295. ly.shift=shift
  9296. if(shift>wl)
  9297. wl=shift
  9298. w-=shift
  9299. if(w>wx)
  9300. wx=w}
  9301. while(!s3.seqst)
  9302. s3=s3.ts_prev
  9303. if(s3.ts_prev&&s3.ts_prev.bar_type)
  9304. wl-=4
  9305. if(s3.wl<wl){s3.shrink+=wl-s3.wl
  9306. s3.wl=wl}
  9307. dx-=6
  9308. if(dx<wx){dx=(wx-dx)/n
  9309. s1=s.ts_next
  9310. while(1){if(s1.shrink){s1.shrink+=dx
  9311. s3.wr+=dx
  9312. s3=s1}
  9313. if(s1==s2)
  9314. break
  9315. s1=s1.ts_next}}
  9316. if(align>0){for(i=0;i<a_ly.length;i++){ly=a_ly[i]
  9317. if(ly&&ly.t[0]>='0'&&ly.t[0]<='9')
  9318. ly.shift=align}}}
  9319. function draw_lyric_line(p_voice,j,y){var p,lastx,w,s,s2,ly,lyl,ln,hyflag,lflag,x0,shift
  9320. if(p_voice.hy_st&(1<<j)){hyflag=true;p_voice.hy_st&=~(1<<j)}
  9321. for(s=p_voice.sym;;s=s.next)
  9322. if(s.type!=C.CLEF&&s.type!=C.KEY&&s.type!=C.METER)
  9323. break
  9324. lastx=s.prev?s.prev.x:tsfirst.x;x0=0
  9325. for(;s;s=s.next){if(s.a_ly)
  9326. ly=s.a_ly[j]
  9327. else
  9328. ly=null
  9329. if(!ly){switch(s.type){case C.REST:case C.MREST:if(lflag){out_wln(lastx+3,y,x0-lastx);lflag=false;lastx=s.x+s.wr}}
  9330. continue}
  9331. if(ly.font!=gene.curfont)
  9332. gene.curfont=ly.font
  9333. p=ly.t;ln=ly.ln||0
  9334. w=p.wh[0]
  9335. shift=ly.shift
  9336. if(hyflag){if(ln==3){ln=2}else if(ln<2){out_hyph(lastx,y,s.x-shift-lastx);hyflag=false;lastx=s.x+s.wr}}
  9337. if(lflag&&ln!=3){out_wln(lastx+3,y,x0-lastx+3);lflag=false;lastx=s.x+s.wr}
  9338. if(ln>=2){if(x0==0&&lastx>s.x-18)
  9339. lastx=s.x-18
  9340. if(ln==2)
  9341. hyflag=true
  9342. else
  9343. lflag=true;x0=s.x-shift
  9344. continue}
  9345. x0=s.x-shift;if(ln)
  9346. hyflag=true
  9347. if(user.anno_start||user.anno_stop){s2={p_v:s.p_v,st:s.st,istart:ly.istart,iend:ly.iend,ts_prev:s,ts_next:s.ts_next,x:x0,y:y,ymn:y,ymx:y+gene.curfont.size,wl:0,wr:w}
  9348. anno_start(s2,'lyrics')}
  9349. xy_str(x0,y,p)
  9350. anno_stop(s2,'lyrics')
  9351. lastx=x0+w}
  9352. if(hyflag){hyflag=false;x0=realwidth-10
  9353. if(x0<lastx+10)
  9354. x0=lastx+10;out_hyph(lastx,y,x0-lastx)
  9355. if(p_voice.s_next&&p_voice.s_next.fmt.hyphencont)
  9356. p_voice.hy_st|=(1<<j)}
  9357. for(p_voice.s_next;s;s=s.next){if(s.type==C.NOTE){if(!s.a_ly)
  9358. break
  9359. ly=s.a_ly[j]
  9360. if(ly&&ly.ln==3){lflag=true;x0=realwidth-15
  9361. if(x0<lastx+12)
  9362. x0=lastx+12}
  9363. break}}
  9364. if(lflag){out_wln(lastx+3,y,x0-lastx+3);lflag=false}}
  9365. function draw_lyrics(p_voice,nly,a_h,y,incr){var j,top,sc=staff_tb[p_voice.st].staffscale;set_font("vocal")
  9366. if(incr>0){if(y>-tsfirst.fmt.vocalspace)
  9367. y=-tsfirst.fmt.vocalspace;y*=sc
  9368. for(j=0;j<nly;j++){y-=a_h[j]*1.1;draw_lyric_line(p_voice,j,y+a_h[j]*.22)}
  9369. return y/sc}
  9370. top=staff_tb[p_voice.st].topbar+tsfirst.fmt.vocalspace
  9371. if(y<top)
  9372. y=top;y*=sc
  9373. for(j=nly;--j>=0;){draw_lyric_line(p_voice,j,y+a_h[j]*.22)
  9374. y+=a_h[j]*1.1}
  9375. return y/sc}
  9376. function draw_all_lyrics(){var p_voice,s,v,nly,i,x,y,w,a_ly,ly,lyst_tb=new Array(nstaff+1),nv=voice_tb.length,h_tb=new Array(nv),nly_tb=new Array(nv),above_tb=new Array(nv),rv_tb=new Array(nv),top=0,bot=0,st=-1
  9377. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  9378. if(!p_voice.sym)
  9379. continue
  9380. if(p_voice.st!=st){top=0;bot=0;st=p_voice.st}
  9381. nly=0
  9382. if(p_voice.have_ly){if(!h_tb[v])
  9383. h_tb[v]=[]
  9384. for(s=p_voice.sym;s;s=s.next){a_ly=s.a_ly
  9385. if(!a_ly)
  9386. continue
  9387. x=s.x;w=10
  9388. for(i=0;i<a_ly.length;i++){ly=a_ly[i]
  9389. if(ly){x-=ly.shift;w=ly.t.wh[0]
  9390. break}}
  9391. y=y_get(p_voice.st,1,x,w)
  9392. if(top<y)
  9393. top=y;y=y_get(p_voice.st,0,x,w)
  9394. if(bot>y)
  9395. bot=y
  9396. while(nly<a_ly.length)
  9397. h_tb[v][nly++]=0
  9398. for(i=0;i<a_ly.length;i++){ly=a_ly[i]
  9399. if(!ly)
  9400. continue
  9401. if(!h_tb[v][i]||ly.t.wh[1]>h_tb[v][i])
  9402. h_tb[v][i]=ly.t.wh[1]}}}else{y=y_get(p_voice.st,1,0,realwidth)
  9403. if(top<y)
  9404. top=y;y=y_get(p_voice.st,0,0,realwidth)
  9405. if(bot>y)
  9406. bot=y}
  9407. if(!lyst_tb[st])
  9408. lyst_tb[st]={}
  9409. lyst_tb[st].top=top;lyst_tb[st].bot=bot;nly_tb[v]=nly
  9410. if(nly==0)
  9411. continue
  9412. if(p_voice.pos.voc)
  9413. above_tb[v]=(p_voice.pos.voc&0x07)==C.SL_ABOVE
  9414. else if(voice_tb[v+1]&&voice_tb[v+1].st==st&&voice_tb[v+1].have_ly)
  9415. above_tb[v]=true
  9416. else
  9417. above_tb[v]=false
  9418. if(above_tb[v])
  9419. lyst_tb[st].a=true
  9420. else
  9421. lyst_tb[st].b=true}
  9422. i=0
  9423. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  9424. if(!p_voice.sym)
  9425. continue
  9426. if(!p_voice.have_ly)
  9427. continue
  9428. if(above_tb[v]){rv_tb[i++]=v
  9429. continue}
  9430. st=p_voice.st;set_dscale(st,true)
  9431. if(nly_tb[v]>0)
  9432. lyst_tb[st].bot=draw_lyrics(p_voice,nly_tb[v],h_tb[v],lyst_tb[st].bot,1)}
  9433. while(--i>=0){v=rv_tb[i];p_voice=voice_tb[v];st=p_voice.st;set_dscale(st,true);lyst_tb[st].top=draw_lyrics(p_voice,nly_tb[v],h_tb[v],lyst_tb[st].top,-1)}
  9434. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  9435. if(!p_voice.sym)
  9436. continue
  9437. st=p_voice.st;if(lyst_tb[st].a){top=lyst_tb[st].top+2
  9438. for(s=p_voice.sym;s;s=s.next){if(s.a_ly){y_set(st,1,s.x-2,10,top)}}}
  9439. if(lyst_tb[st].b){bot=lyst_tb[st].bot-2
  9440. if(nly_tb[p_voice.v]>0){for(s=p_voice.sym;s;s=s.next){if(s.a_ly){y_set(st,0,s.x-2,10,bot)}}}else{y_set(st,0,0,realwidth,bot)}}}}
  9441. function parse_gchord(type){var c,text,gch,x_abs,y_abs,i,j,istart,iend,ann_font=get_font("annotation"),h_ann=ann_font.size,line=parse.line
  9442. function get_float(){var txt=''
  9443. while(1){c=text[i++]
  9444. if("1234567890.-".indexOf(c)<0)
  9445. return parseFloat(txt)
  9446. txt+=c}}
  9447. istart=parse.bol+line.index
  9448. if(type.length>1){text=type.slice(1,-1);iend=istart+1}else{i=++line.index
  9449. while(1){j=line.buffer.indexOf('"',i)
  9450. if(j<0){syntax(1,"No end of chord symbol/annotation")
  9451. return}
  9452. if(line.buffer[j-1]!='\\'||line.buffer[j-2]=='\\')
  9453. break
  9454. i=j+1}
  9455. text=cnv_escape(line.buffer.slice(line.index,j))
  9456. line.index=j
  9457. iend=parse.bol+line.index+1}
  9458. if(ann_font.pad)
  9459. h_ann+=ann_font.pad
  9460. i=0;type='g'
  9461. while(1){c=text[i]
  9462. if(!c)
  9463. break
  9464. gch={text:"",istart:istart,iend:iend,font:ann_font}
  9465. switch(c){case'@':type=c;i++;x_abs=get_float()
  9466. if(c!=','){syntax(1,"',' lacking in annotation '@x,y'");y_abs=0}else{y_abs=get_float()
  9467. if(c!=' ')
  9468. i--}
  9469. gch.x=x_abs;gch.y=y_abs
  9470. break
  9471. case'^':gch.pos=C.SL_ABOVE
  9472. case'_':if(c=='_')
  9473. gch.pos=C.SL_BELOW
  9474. case'<':case'>':i++;type=c
  9475. break
  9476. default:switch(type){case'g':gch.font=get_font("gchord")
  9477. gch.pos=curvoice.pos.gch||C.SL_ABOVE
  9478. break
  9479. case'^':gch.pos=C.SL_ABOVE
  9480. break
  9481. case'_':gch.pos=C.SL_BELOW
  9482. break
  9483. case'@':gch.x=x_abs;y_abs-=h_ann;gch.y=y_abs
  9484. break}
  9485. break}
  9486. gch.type=type
  9487. while(1){c=text[i]
  9488. if(!c)
  9489. break
  9490. switch(c){case'\\':c=text[++i]
  9491. if(c=='n')
  9492. break
  9493. gch.text+='\\'
  9494. if(!c)
  9495. break
  9496. default:gch.text+=c;i++
  9497. continue
  9498. case'&':while(1){gch.text+=c;c=text[++i]
  9499. switch(c){default:continue
  9500. case';':case undefined:case'\\':break}
  9501. break}
  9502. if(c==';'){i++;gch.text+=c
  9503. continue}
  9504. break
  9505. case';':break}
  9506. i++
  9507. break}
  9508. gch.otext=gch.text
  9509. if(!a_gch)
  9510. a_gch=[]
  9511. a_gch.push(gch)}}
  9512. var note_names="CDEFGAB",acc_name=["bb","b","","#","##"]
  9513. function gch_tr1(p,tr){var i,o,n,a,ip,b40,csa=p.split('/')
  9514. for(i=0;i<csa.length;i++){p=csa[i];o=p.search(/[A-G]/)
  9515. if(o<0)
  9516. continue
  9517. ip=o+1
  9518. a=0
  9519. while(p[ip]=='#'||p[ip]=='\u266f'){a++;ip++}
  9520. while(p[ip]=='b'||p[ip]=='\u266d'){a--;ip++}
  9521. n=note_names.indexOf(p[o])+16
  9522. b40=(abc2svg.pab40(n,a)+tr+200)%40
  9523. b40=abc2svg.b40k[b40]
  9524. csa[i]=p.slice(0,o)+
  9525. note_names[abc2svg.b40_p[b40]]+
  9526. acc_name[abc2svg.b40_a[b40]+2]+
  9527. p.slice(ip)}
  9528. return csa.join('/')}
  9529. function csan_add(s){var i,gch
  9530. if(s.type==C.BAR){for(i=0;i<a_gch.length;i++){if(a_gch[i].type=='g'){error(1,s,"There cannot be chord symbols on measure bars")
  9531. a_gch.splice(i)}}}
  9532. if(curvoice.tr_sco){for(i=0;i<a_gch.length;i++){gch=a_gch[i]
  9533. if(gch.type=='g')
  9534. gch.text=gch_tr1(gch.text,curvoice.tr_sco)}}
  9535. if(s.a_gch)
  9536. s.a_gch=s.a_gch.concat(a_gch)
  9537. else
  9538. s.a_gch=a_gch
  9539. a_gch=null}
  9540. Abc.prototype.gch_build=function(s){var gch,wh,xspc,ix,y_left=0,y_right=0,GCHPRE=.4;for(ix=0;ix<s.a_gch.length;ix++){gch=s.a_gch[ix]
  9541. if(gch.type=='g'){gch.text=gch.text.replace(/##|#|=|bb|b/g,function(x){switch(x){case'##':return"&#x1d12a;"
  9542. case'#':return"\u266f"
  9543. case'=':return"\u266e"
  9544. case'b':return"\u266d"}
  9545. return"&#x1d12b;"})}else{if(gch.type=='@'&&!user.anno_start&&!user.anno_stop){set_font(gch.font)
  9546. gch.text=str2svg(gch.text)
  9547. continue}}
  9548. set_font(gch.font);gch.text=str2svg(gch.text)
  9549. wh=gch.text.wh
  9550. switch(gch.type){case'@':break
  9551. default:xspc=wh[0]*GCHPRE
  9552. if(xspc>8)
  9553. xspc=8;gch.x=-xspc;break
  9554. case'<':gch.x=-(wh[0]+6);y_left-=wh[1];gch.y=y_left+wh[1]/2
  9555. break
  9556. case'>':gch.x=6;y_right-=wh[1];gch.y=y_right+wh[1]/2
  9557. break}}
  9558. y_left/=2;y_right/=2
  9559. for(ix=0;ix<s.a_gch.length;ix++){gch=s.a_gch[ix]
  9560. switch(gch.type){case'<':gch.y-=y_left
  9561. break
  9562. case'>':gch.y-=y_right
  9563. break}}}
  9564. Abc.prototype.draw_gchord=function(i,s,x,y){if(s.invis&&s.play)
  9565. return
  9566. var y2,an=s.a_gch[i],h=an.text.wh[1],pad=an.font.pad,w=an.text.wh[0]+pad*2,dy=h*.22
  9567. if(an.font.figb){h*=2.4
  9568. dy+=an.font.size*1.3}
  9569. switch(an.type){case'_':y-=h+pad
  9570. break
  9571. case'^':y+=pad
  9572. break
  9573. case'<':case'>':if(an.type=='<'){if(s.notes[0].acc)
  9574. x-=s.notes[0].shac
  9575. x-=pad}else{if(s.xmx)
  9576. x+=s.xmx
  9577. if(s.dots)
  9578. x+=1.5+3.5*s.dots
  9579. x+=pad}
  9580. y+=(s.type==C.NOTE?(((s.notes[s.nhd].pit+s.notes[0].pit)>>1)-
  9581. 18)*3:12)
  9582. -h/2
  9583. break
  9584. default:if(y>=0)
  9585. y+=pad
  9586. else
  9587. y-=h+pad
  9588. break
  9589. case'@':y+=(s.type==C.NOTE?(((s.notes[s.nhd].pit+s.notes[0].pit)>>1)-
  9590. 18)*3:12)
  9591. -h/2
  9592. if(y>0){y2=y+h+pad+2
  9593. if(y2>staff_tb[s.st].ann_top)
  9594. staff_tb[s.st].ann_top=y2}else{y2=y-2
  9595. if(y2<staff_tb[s.st].ann_bot)
  9596. staff_tb[s.st].ann_bot=y2}
  9597. break}
  9598. if(an.type!='@'){if(y>=0)
  9599. y_set(s.st,1,x,w,y+h+pad+2)
  9600. else
  9601. y_set(s.st,0,x,w,y-pad)}
  9602. use_font(an.font)
  9603. set_font(an.font)
  9604. set_dscale(s.st)
  9605. if(user.anno_start)
  9606. user.anno_start("annot",an.istart,an.iend,x-2,y+h+2,w+4,h+4,s)
  9607. xy_str(x,y+dy,an.text)
  9608. if(user.anno_stop)
  9609. user.anno_stop("annot",an.istart,an.iend,x-2,y+h+2,w+4,h+4,s)}
  9610. function draw_all_chsy(){var s,san1,an,i,x,y,w,n_an=0,minmax=new Array(nstaff+1)
  9611. function set_an_yu(j){var an,i,s,x,y,w
  9612. for(s=san1;s;s=s.ts_next){an=s.a_gch
  9613. if(!an)
  9614. continue
  9615. i=an.length-j-1
  9616. an=an[i]
  9617. if(!an)
  9618. continue
  9619. if(an.pos==C.SL_ABOVE){x=s.x+an.x
  9620. w=an.text.wh[0]
  9621. if(w&&x+w>realwidth)
  9622. x=realwidth-w
  9623. y=y_get(s.st,1,x,w)+2
  9624. if(an.type=='g'&&y<minmax[s.st].yup)
  9625. y=minmax[s.st].yup}else if(an.pos==C.SL_BELOW||an.pos==C.SL_HIDDEN){continue}else{x=s.x+an.x
  9626. y=an.y}
  9627. self.draw_gchord(i,s,x,y)}}
  9628. function set_an_yl(i){var an,x,y,w
  9629. for(var s=san1;s;s=s.ts_next){an=s.a_gch
  9630. if(!an)
  9631. continue
  9632. an=an[i]
  9633. if(!an||an.pos!=C.SL_BELOW)
  9634. continue
  9635. x=s.x+an.x
  9636. w=an.text.wh[0]
  9637. if(w&&x+w>realwidth)
  9638. x=realwidth-w
  9639. y=y_get(s.st,0,x,w)-2
  9640. if(an.type=='g'&&y>minmax[s.st].ydn)
  9641. y=minmax[s.st].ydn
  9642. self.draw_gchord(i,s,x,y)}}
  9643. for(i=0;i<=nstaff;i++)
  9644. minmax[i]={ydn:staff_tb[i].botbar-3,yup:staff_tb[i].topbar+4}
  9645. for(s=tsfirst;s;s=s.ts_next){an=s.a_gch
  9646. if(!an)
  9647. continue
  9648. if(!san1)
  9649. san1=s
  9650. i=an.length
  9651. if(i>n_an)
  9652. n_an=i
  9653. while(--i>=0){if(an[i].type=='g'){an=an[i]
  9654. x=s.x+an.x
  9655. w=an.text.wh[0]
  9656. if(w&&x+w>realwidth)
  9657. x=realwidth-w
  9658. if(an.pos==C.SL_ABOVE){y=y_get(s.st,true,x,w)+2
  9659. if(y>minmax[s.st].yup)
  9660. minmax[s.st].yup=y}else if(an.pos==C.SL_BELOW){y=y_get(s.st,false,x,w)-2
  9661. if(y<minmax[s.st].ydn)
  9662. minmax[s.st].ydn=y}
  9663. break}}}
  9664. if(!san1)
  9665. return
  9666. set_dscale(-1)
  9667. for(i=0;i<n_an;i++){set_an_yu(i)
  9668. set_an_yl(i)}}
  9669. init_tune()
  9670. Abc.prototype.a_de=function(){return a_de}
  9671. Abc.prototype.add_style=function(s){style+=s};Abc.prototype.cfmt=function(){return cfmt};Abc.prototype.clone=clone;Abc.prototype.deco_put=function(nm,s){a_dcn.push(nm)
  9672. deco_cnv(s)}
  9673. Abc.prototype.defs_add=defs_add
  9674. Abc.prototype.dh_put=function(nm,s,nt){a_dcn.push(nm)
  9675. dh_cnv(s,nt)}
  9676. Abc.prototype.draw_meter=draw_meter
  9677. Abc.prototype.draw_note=draw_note;Abc.prototype.errs=errs;Abc.prototype.font_class=font_class;Abc.prototype.gch_tr1=gch_tr1;Abc.prototype.get_bool=get_bool;Abc.prototype.get_cur_sy=function(){return cur_sy};Abc.prototype.get_curvoice=function(){return curvoice};Abc.prototype.get_delta_tb=function(){return delta_tb};Abc.prototype.get_decos=function(){return decos};Abc.prototype.get_font=get_font;Abc.prototype.get_font_style=function(){return font_style};Abc.prototype.get_glyphs=function(){return glyphs};Abc.prototype.get_img=function(){return img};Abc.prototype.get_maps=function(){return maps};Abc.prototype.get_multi=function(){return multicol};Abc.prototype.get_newpage=function(){if(block.newpage){block.newpage=false;return true}};Abc.prototype.get_posy=function(){return posy}
  9678. Abc.prototype.get_staff_tb=function(){return staff_tb};Abc.prototype.get_top_v=function(){return par_sy.top_voice};Abc.prototype.get_tsfirst=function(){return tsfirst};Abc.prototype.get_unit=get_unit;Abc.prototype.get_voice_tb=function(){return voice_tb};Abc.prototype.glout=glout
  9679. Abc.prototype.info=function(){return info};Abc.prototype.new_block=new_block;Abc.prototype.out_arp=out_arp;Abc.prototype.out_deco_str=out_deco_str;Abc.prototype.out_deco_val=out_deco_val;Abc.prototype.out_ltr=out_ltr;Abc.prototype.param_set_font=param_set_font;Abc.prototype.parse=parse;Abc.prototype.psdeco=empty_function;Abc.prototype.psxygl=empty_function;Abc.prototype.set_cur_sy=function(sy){cur_sy=sy};Abc.prototype.set_dscale=set_dscale;Abc.prototype.set_font=set_font;Abc.prototype.set_a_gch=function(s,a){a_gch=a;csan_add(s)}
  9680. Abc.prototype.set_hl=set_hl
  9681. Abc.prototype.set_page=set_page
  9682. Abc.prototype.set_pagef=function(){blkdiv=1}
  9683. Abc.prototype.set_realwidth=function(v){realwidth=v}
  9684. Abc.prototype.set_scale=set_scale;Abc.prototype.set_sscale=set_sscale
  9685. Abc.prototype.set_tsfirst=function(s){tsfirst=s};Abc.prototype.set_v_param=set_v_param;Abc.prototype.strwh=strwh;Abc.prototype.stv_g=function(){return stv_g};Abc.prototype.svg_flush=svg_flush;Abc.prototype.syntax=syntax;Abc.prototype.tunes=tunes
  9686. Abc.prototype.unlksym=unlksym;Abc.prototype.use_font=use_font;Abc.prototype.vskip=vskip
  9687. Abc.prototype.xy_str=xy_str;Abc.prototype.xygl=xygl}
  9688. var Abc=abc2svg.Abc
  9689. if(typeof module=='object'&&typeof exports=='object'){exports.abc2svg=abc2svg;exports.Abc=Abc}
  9690. if(!abc2svg.loadjs){abc2svg.loadjs=function(fn,onsuccess,onerror){if(onerror)
  9691. onerror(fn)}}
  9692. abc2svg.modules={ambitus:{},begingrid:{fn:'grid3'},beginps:{fn:'psvg'},break:{},capo:{},chordnames:{},clip:{},clairnote:{fn:'clair'},voicecombine:{fn:'combine'},diagram:{fn:'diag'},equalbars:{},gamelan:{},grid:{},grid2:{},jazzchord:{},jianpu:{},mdnn:{},MIDI:{},nns:{},pageheight:{fn:'page'},pedline:{},percmap:{fn:'perc'},roman:{},soloffs:{},sth:{},strtab:{},temperament:{fn:'temper'},tropt:{},nreq:0,load:function(file,relay,errmsg){function get_errmsg(){if(typeof user=='object'&&user.errmsg)
  9693. return user.errmsg
  9694. if(typeof abc2svg.printErr=='function')
  9695. return abc2svg.printErr
  9696. if(typeof alert=='function')
  9697. return function(m){alert(m)}
  9698. if(typeof console=='object')
  9699. return console.log
  9700. return function(){}}
  9701. function load_end(){if(--abc2svg.modules.nreq==0)
  9702. abc2svg.modules.cbf()}
  9703. var m,i,fn,nreq_i=this.nreq,ls=file.match(/(^|\n)(%%|I:).+?\b/g)
  9704. if(!ls)
  9705. return true
  9706. this.cbf=relay||function(){}
  9707. this.errmsg=errmsg||get_errmsg()
  9708. for(i=0;i<ls.length;i++){fn=ls[i].replace(/\n?(%%|I:)/,'')
  9709. m=abc2svg.modules[fn]
  9710. if(!m||m.loaded)
  9711. continue
  9712. m.loaded=true
  9713. if(m.fn)
  9714. fn=m.fn
  9715. this.nreq++
  9716. abc2svg.loadjs(fn+"-1.js",load_end,function(){abc2svg.modules.errmsg('Error loading the module '+fn)
  9717. load_end()})}
  9718. return this.nreq==nreq_i}}
  9719. abc2svg.version="v1.22.9";abc2svg.vdate="2023-07-22"