abc2svg-1.js 305 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823
  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.start.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. de.up=up
  211. sh_st()
  212. if(de.defl.noen){w=de.x-x
  213. if(w<20){x=de.x-20-3;w=20}}else{w=s2.x-x-4
  214. sh_en(de)
  215. if(w<20)
  216. w=20}
  217. y=y_get(st,up,x-dd.wl,w)
  218. if(up){tmp=staff_tb[s.st].topbar+2
  219. if(y<tmp)
  220. y=tmp}else{tmp=staff_tb[s.st].botbar-2
  221. if(y>tmp)
  222. y=tmp
  223. y-=dd.h}
  224. if(de2){if(up){if(y<de2.y)
  225. y=de2.y}else{if(y>=de2.y){y=de2.y}else{do{de2.y=y
  226. de2=de2.prev}while(de2)}}}
  227. de.lden=false;de.has_val=true;de.val=w;de.x=x;de.y=y
  228. if(up)
  229. y+=dd.h;else
  230. y-=dd.hd
  231. y_set(st,up,x,w,y)
  232. if(up)
  233. s.ymx=s2.ymx=y
  234. else
  235. s.ymn=s2.ymn=y}
  236. function d_upstaff(de){if(de.ldst)
  237. return
  238. if(de.start){d_trill(de)
  239. return}
  240. var y,inv,up=de.up,s=de.s,dd=de.dd,x=de.x,w=dd.wl+dd.wr
  241. 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
  242. if(s.type==C.BAR){s.invis=1}else{if(dd.glyph=="brth"&&y<s.ymx)
  243. y=s.ymx
  244. for(s=s.ts_next;s;s=s.ts_next)
  245. if(s.seqst)
  246. break
  247. x+=((s?s.x:realwidth)-x)*.45}
  248. de.x=x
  249. de.y=y
  250. return}
  251. if(s.nhd)
  252. x+=s.notes[s.stem>=0?0:s.nhd].shhd;switch(dd.ty){case'@':case'<':case'>':y=de.y
  253. break}
  254. if(y==undefined){if(up){y=y_get(s.st,true,x-dd.wl,w)
  255. +dd.hd
  256. if(de.y>y)
  257. y=de.y
  258. s.ymx=y+dd.h}else{y=y_get(s.st,false,x-dd.wl,w)
  259. -dd.h
  260. if(de.y<y)
  261. y=de.y
  262. if(dd.name=="fermata"||dd.glyph=="accent"||dd.glyph=="roll")
  263. de.inv=1
  264. s.ymn=y-dd.hd}}
  265. if(dd.wr>10&&x>realwidth-dd.wr)
  266. de.x=x=realwidth-dd.wr-dd.wl
  267. if(up)
  268. y_set(s.st,1,x-dd.wl,w,y+dd.h)
  269. else
  270. y_set(s.st,0,x-dd.wl,w,y-dd.hd)
  271. de.y=y}
  272. function deco_add(param){var dv=param.match(/(\S*)\s+(.*)/);decos[dv[1]]=dv[2]}
  273. function deco_def(nm,nmd){if(!nmd)
  274. nmd=nm
  275. var a,dd,dd2,nm2,c,i,elts,str,hd,text=decos[nmd]
  276. if(!text&&/\d[()]$/.test(nmd))
  277. text=decos[nmd.replace(/\d/,'')]
  278. if(!text){if(cfmt.decoerr)
  279. error(1,null,"Unknown decoration '$1'",nm)
  280. return}
  281. a=text.match(/(\d+)\s+(.+?)\s+([0-9.,]+)\s+([0-9.]+)\s+([0-9.]+)/)
  282. if(!a){error(1,null,"Invalid decoration '$1'",nm)
  283. return}
  284. var c_func=Number(a[1]),h=a[3],wl=parseFloat(a[4]),wr=parseFloat(a[5])
  285. if(isNaN(c_func)){error(1,null,"%%deco: bad C function value '$1'",a[1])
  286. return}
  287. if(c_func>10&&(c_func<32||c_func>44)){error(1,null,"%%deco: bad C function index '$1'",c_func)
  288. return}
  289. if(h.indexOf(',')>0){h=h.split(',')
  290. hd=h[1]
  291. h=h[0]}else{hd=0}
  292. if(h>50||wl>80||wr>80){error(1,null,"%%deco: abnormal h/wl/wr value '$1'",text)
  293. return}
  294. dd=dd_tb[nm]
  295. if(!dd){dd={name:nm}
  296. dd_tb[nm]=dd}
  297. dd.func=nm.indexOf("head-")==0?9:c_func;dd.glyph=a[2];dd.h=Number(h)
  298. dd.hd=Number(hd)
  299. dd.wl=wl;dd.wr=wr;str=text.replace(a[0],'').trim()
  300. if(str){if(str[0]=='"')
  301. str=str.slice(1,-1);if(str[0]=='@'&&!str.match(/^@([0-9.-]+),([0-9.-]+);?/)){error(1,null,"%%deco: bad position '$1'",str)
  302. return}
  303. dd.str=str}
  304. if(dd.func==6&&dd.str==undefined)
  305. dd.str=nm
  306. c=nm.slice(-1)
  307. if(c=='('||(c==')'&&nm.indexOf('(')<0)){dd.str=null;nm2=nm.slice(0,-1)+(c=='('?')':'(');dd2=dd_tb[nm2]
  308. if(dd2){if(c=='('){dd.dd_en=dd2;dd2.dd_st=dd}else{dd.dd_st=dd2;dd2.dd_en=dd}}}
  309. return dd}
  310. function do_ctie(nm,s,nt1){var nt2=cross[nm],nm2=nm.slice(0,-1)+(nm.slice(-1)=='('?')':'(')
  311. if(nt2){error(1,s,"Conflict on !$1!",nm)
  312. return}
  313. nt1.s=s
  314. nt2=cross[nm2]
  315. if(!nt2){cross[nm]=nt1
  316. return}
  317. if(nm.slice(-1)==')'){nt2=nt1
  318. nt1=cross[nm2]}
  319. cross[nm2]=null
  320. 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
  321. nt1.tie_e=nt2
  322. nt2.tie_s=nt1
  323. nt1.s.ti1=nt2.s.ti2=true}}
  324. function get_dd(nm){var ty,p,dd=dd_tb[nm]
  325. if(dd)
  326. return dd
  327. if("<>^_@".indexOf(nm[0])>=0&&!/^([>^]|[<>]\d?[()])$/.test(nm)){ty=nm[0]
  328. if(ty=='@'){p=nm.match(/@([-\d]+),([-\d]+)/)
  329. if(p)
  330. ty=p[0]
  331. else
  332. ty=''}
  333. dd=deco_def(nm,nm.replace(ty,''))}else{dd=deco_def(nm)}
  334. if(!dd)
  335. return
  336. if(ty){if(ty[0]=='@'){dd.x=Number(p[1])
  337. dd.y=Number(p[2])
  338. ty='@'}
  339. dd.ty=ty}
  340. return dd}
  341. function deco_cnv(s,prev){var i,j,dd,nm,note,s1,court
  342. while(1){nm=a_dcn.shift()
  343. if(!nm)
  344. break
  345. dd=get_dd(nm)
  346. if(!dd)
  347. continue
  348. switch(dd.func){case 0:if(s.type==C.BAR&&nm=="dot"){s.bar_dotted=true
  349. continue}
  350. case 1:case 2:if(!s.notes){error(1,s,errs.must_note_rest,nm)
  351. continue}
  352. break
  353. case 4:case 5:i=nm.match(/1?[85]([vm])([ab])([()])/)
  354. if(i){j=i[1]=='v'?1:2
  355. if(i[2]=='b')
  356. j=-j
  357. if(!s.ottava)
  358. s.ottava=[]
  359. s.ottava[i[3]=='('?0:1]=j
  360. glovar.ottava=1}
  361. break
  362. case 8:if(s.type!=C.NOTE){error(1,s,errs.must_note,nm)
  363. continue}
  364. note=s.notes[s.nhd]
  365. if(!note.a_dd)
  366. note.a_dd=[]
  367. note.a_dd.push(dd)
  368. continue
  369. case 9:if(!s.notes){error(1,s,errs.must_note_rest,nm)
  370. continue}
  371. for(j=0;j<=s.nhd;j++){note=s.notes[j]
  372. note.invis=true
  373. if(!note.a_dd)
  374. note.a_dd=[]
  375. note.a_dd.push(dd)}
  376. continue
  377. case 10:if(s.notes){for(j=0;j<=s.nhd;j++)
  378. s.notes[j].color=nm}else{s.color=nm}
  379. break
  380. case 32:s.invis=true
  381. break
  382. case 33:if(s.type!=C.BAR){error(1,s,"!beamon! must be on a bar")
  383. continue}
  384. s.beam_on=true
  385. break
  386. 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)
  387. continue}
  388. 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++)
  389. s.notes[j].dur*=2;for(j=0;j<=prev.nhd;j++)
  390. prev.notes[j].dur*=2
  391. break
  392. case 35:if(s.type!=C.NOTE){error(1,s,errs.must_note,nm)
  393. continue}
  394. s.xstem=true;break
  395. case 36:if(s.type!=C.NOTE){error(1,s,errs.must_note,nm)
  396. continue}
  397. if(nm[6]=='1')
  398. s.beam_br1=true
  399. else
  400. s.beam_br2=true
  401. break
  402. case 37:s.rbstop=1
  403. break
  404. case 38:if(s.type!=C.NOTE){error(1,s,errs.must_note,nm)
  405. continue}
  406. s.trem1=true;s.ntrem=nm.length
  407. break
  408. case 39:if(s.type!=C.NOTE){error(1,s,errs.must_note,nm)
  409. continue}
  410. s.feathered_beam=nm[5]=='a'?1:-1;break
  411. case 40:s.stemless=true
  412. break
  413. case 41:s.rbstop=2
  414. break
  415. case 42:if(!s.notes[0].acc)
  416. continue
  417. nm="sacc"+s.notes[0].acc.toString()
  418. dd=dd_tb[nm]
  419. if(!dd){dd=deco_def(nm)
  420. if(!dd){error(1,s,errs.bad_val,"!editorial!")
  421. continue}}
  422. delete s.notes[0].acc
  423. curvoice.acc[s.notes[0].pit+19]=0
  424. break
  425. case 43:j=curvoice.acc[s.notes[0].pit+19]
  426. if(s.notes[0].acc||!j)
  427. continue
  428. court=1
  429. break
  430. case 44:do_ctie(nm,s,s.notes[0])
  431. continue}
  432. if(!s.a_dd)
  433. s.a_dd=[]
  434. s.a_dd.push(dd)}
  435. if(court){a_dcn.push("cacc"+j)
  436. dh_cnv(s,s.notes[0])}}
  437. function dh_cnv(s,nt){var k,nm,dd
  438. while(1){nm=a_dcn.shift()
  439. if(!nm)
  440. break
  441. dd=get_dd(nm)
  442. if(!dd)
  443. continue
  444. switch(dd.func){case 0:case 1:case 3:case 4:case 8:break
  445. default:error(1,s,"Cannot have !$1! on a head",nm)
  446. continue
  447. case 9:nt.invis=true
  448. break
  449. case 32:nt.invis=true
  450. continue
  451. case 10:nt.color=nm
  452. continue
  453. case 40:s.stemless=true
  454. continue
  455. case 44:do_ctie(nm,s,nt)
  456. continue}
  457. if(!nt.a_dd)
  458. nt.a_dd=[]
  459. nt.a_dd.push(dd)}}
  460. function deco_update(s,dx){var i,de,nd=a_de.length
  461. for(i=0;i<nd;i++){de=a_de[i]
  462. if(de.s==s)
  463. de.x+=dx}}
  464. function deco_width(s,wlnt){var dd,i,w,wl=wlnt,wr=s.wr,a_dd=s.a_dd,nd=a_dd.length
  465. for(i=0;i<nd;i++){dd=a_dd[i]
  466. switch(dd.func){case 1:case 2:if(wl<12)
  467. wl=12
  468. break
  469. case 3:switch(dd.glyph){case"brth":case"lphr":case"mphr":case"sphr":if(s.wr<20)
  470. s.wr=20
  471. break
  472. default:w=dd.wl+2
  473. if(wl<w)
  474. wl=w
  475. break}
  476. default:switch(dd.ty){case'<':w=wlnt+dd.wl+dd.wr+6
  477. if(wl<w)
  478. wl=w
  479. break
  480. case'>':w=wr+dd.wl+dd.wr+6
  481. if(s.wr<w)
  482. s.wr=w
  483. break}
  484. break}}
  485. return wl}
  486. function deco_wch(nt){var i,w,dd,wl=0,n=nt.a_dd.length
  487. for(i=0;i<n;i++){dd=nt.a_dd[i]
  488. if(dd.ty=='<'){w=dd.wl+dd.wr+4
  489. if(w>wl)
  490. wl=w}}
  491. return wl}
  492. Abc.prototype.draw_all_deco=function(){if(!a_de.length)
  493. return
  494. var de,dd,s,note,f,st,x,y,y2,ym,uf,i,str,a,new_de=[],ymid=[]
  495. st=nstaff;y=staff_tb[st].y
  496. while(--st>=0){y2=staff_tb[st].y;ymid[st]=(y+24+y2)*.5;y=y2}
  497. while(1){de=a_de.shift()
  498. if(!de)
  499. break
  500. dd=de.dd
  501. if(!dd)
  502. continue
  503. if(dd.dd_en)
  504. continue
  505. s=de.s
  506. f=dd.glyph;i=f.indexOf('/')
  507. if(i>0){if(s.stem>=0)
  508. f=f.slice(0,i)
  509. else
  510. f=f.slice(i+1)}
  511. if(f_staff[dd.func])
  512. set_sscale(s.st)
  513. else
  514. set_scale(s);st=de.st;if(!staff_tb[st].topbar)
  515. continue
  516. x=de.x;y=de.y+staff_tb[st].y
  517. if(de.m!=undefined){note=s.notes[de.m];if(note.shhd)
  518. 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)
  519. ym=ymid[--st]
  520. else
  521. ym=ymid[st++];ym-=dd.h*.5
  522. if((de.up&&y<ym)||(!de.up&&y>ym)){y2=y_get(st,!de.up,de.x,de.val)
  523. +staff_tb[st].y
  524. if(de.up)
  525. y2-=dd.h
  526. if((de.up&&y2>ym)||(!de.up&&y2<ym)){y=ym;if(stv_g.scale!=1)
  527. y+=stv_g.dy/2}}}
  528. uf=user[f]
  529. if(uf&&typeof(uf)=="function"){uf(x,y,de)
  530. continue}
  531. if(self.psdeco(f,x,y,de))
  532. continue
  533. anno_start(s,'deco')
  534. if(de.inv){y=y+dd.h-dd.hd
  535. g_open(x,y,0,1,-1);x=y=0}
  536. if(de.has_val){if(dd.func!=2||stv_g.st<0)
  537. out_deco_val(x,y,f,de.val/stv_g.scale,de.defl)
  538. else
  539. out_deco_val(x,y,f,de.val,de.defl)
  540. if(de.cont)
  541. new_de.push(de.start)}else if(dd.str!=undefined){str=dd.str
  542. if(str[0]=='@'){a=str.match(/^@([0-9.-]+),([0-9.-]+);?/);x+=Number(a[1]);y+=Number(a[2]);str=str.replace(a[0],"")}
  543. out_deco_str(x,y,f,str)}else if(de.lden){out_deco_long(x,y,de)}else{xygl(x,y,f)}
  544. if(stv_g.g)
  545. g_close();anno_stop(s,'deco')}
  546. a_de=new_de}
  547. function draw_deco_near(){var s,g
  548. function ldeco_update(s){var i,de,x=s.x-s.wl,nd=a_de.length
  549. for(i=0;i<nd;i++){de=a_de[i];de.ix=i;de.s.x=de.x=x;de.defl.nost=true}}
  550. function create_deco(s){var dd,k,pos,de,x,y,up,nd=s.a_dd.length
  551. if(s.y==undefined)
  552. s.y=0
  553. for(k=0;k<nd;k++){dd=s.a_dd[k]
  554. x=s.x
  555. y=s.y
  556. switch(dd.func){default:if(dd.func>=10)
  557. continue
  558. pos=0
  559. break
  560. case 3:case 4:case 5:pos=s.pos.orn
  561. break
  562. case 6:pos=s.pos.dyn
  563. break}
  564. switch(dd.ty){case'^':pos=(pos&~0x07)|C.SL_ABOVE
  565. break
  566. case'_':pos=(pos&~0x07)|C.SL_BELOW
  567. break
  568. case'<':case'>':pos=(pos&0x07)|C.SL_CLOSE
  569. if(dd.ty=='<'){x-=dd.wr+8
  570. if(s.notes[0].acc)
  571. x-=8}else{x+=dd.wl+8}
  572. y=3*(s.notes[0].pit-18)
  573. -(dd.h-dd.hd)/2
  574. break
  575. case'@':x+=dd.x
  576. y+=dd.y
  577. break}
  578. if((pos&0x07)==C.SL_HIDDEN)
  579. continue
  580. de={s:s,dd:dd,st:s.st,ix:a_de.length,defl:{},x:x,y:y}
  581. if(pos)
  582. de.pos=pos
  583. up=0
  584. if(dd.ty=='^'){up=1}else if(dd.ty=='_'){}else{switch(dd.func){case 0:if(s.multi)
  585. up=s.multi>0
  586. else
  587. up=s.stem<0
  588. break
  589. case 3:case 5:up=up3(s,pos)
  590. break
  591. case 6:case 7:up=up6(s,pos)
  592. break}}
  593. de.up=up
  594. if(dd.name.indexOf("inverted")>=0)
  595. de.inv=1
  596. if(s.type==C.BAR&&!dd.ty)
  597. de.x-=s.wl/2-2
  598. a_de.push(de)
  599. if(dd.dd_en){de.ldst=true}else if(dd.dd_st){de.lden=true;de.defl.nost=true}
  600. if(f_near[dd.func])
  601. f_near[dd.func](de)}}
  602. function create_dh(s,m){var de,k,dd,note=s.notes[m],nd=note.a_dd.length,x=s.x
  603. for(k=0;k<nd;k++){dd=note.a_dd[k]
  604. 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}
  605. if(dd.ty){if(dd.ty=='@'){de.x+=dd.x
  606. de.y+=dd.y}else{de.y-=(dd.h-dd.hd)/2
  607. if(dd.ty=='<'){de.x-=dd.wr+8
  608. if(s.notes[m].acc)
  609. x-=8}else if(dd.ty=='>'){de.x+=dd.wl+8}}}
  610. a_de.push(de)
  611. if(dd.dd_en){de.ldst=true}else if(dd.dd_st){de.lden=true;de.defl.nost=true}}}
  612. function create_all(s){if(s.invis&&s.play)
  613. return
  614. if(s.a_dd)
  615. create_deco(s)
  616. if(s.notes){for(var m=0;m<s.notes.length;m++){if(s.notes[m].a_dd)
  617. create_dh(s,m)}}}
  618. function ll_deco(){var i,j,de,de2,de3,dd,dd2,v,s,st,n_de=a_de.length
  619. for(i=0;i<n_de;i++){de=a_de[i]
  620. if(!de.ldst)
  621. continue
  622. dd=de.dd;dd2=dd.dd_en;s=de.s;v=s.v
  623. for(j=i+1;j<n_de;j++){de2=a_de[j]
  624. if(!de2.start&&de2.dd==dd2&&de2.s.v==v)
  625. break}
  626. if(j==n_de){st=s.st;for(j=i+1;j<n_de;j++){de2=a_de[j]
  627. if(!de2.start&&de2.dd==dd2&&de2.s.st==st)
  628. break}}
  629. 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}}
  630. if(de2.x<s.x+10)
  631. de2.x=s.x+10
  632. if(de.m!=undefined)
  633. de2.m=de.m;a_de.push(de2)}
  634. de2.start=de;de2.defl.nost=de.defl.nost
  635. j=i
  636. while(--j>=0){de3=a_de[j]
  637. if(!de3.start)
  638. continue
  639. if(de3.s.time<s.time)
  640. break
  641. if(de3.dd.name==de2.dd.name){de2.prev=de3
  642. break}}}
  643. for(i=0;i<n_de;i++){de2=a_de[i]
  644. if(!de2.lden||de2.start)
  645. continue
  646. 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}
  647. de.x=de.s.x+de.s.wr
  648. if(de2.m!=undefined)
  649. de.m=de2.m;a_de.push(de);de2.start=de}}
  650. for(s=tsfirst;s;s=s.ts_next){switch(s.type){case C.CLEF:case C.KEY:case C.METER:continue}
  651. break}
  652. if(a_de.length)
  653. ldeco_update(s)
  654. 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
  655. case C.GRACE:for(g=s.extra;g;g=g.next)
  656. create_all(g)
  657. break
  658. default:continue}
  659. create_all(s)}
  660. ll_deco()}
  661. function draw_deco_note(){var i,de,dd,f,nd=a_de.length
  662. for(i=0;i<nd;i++){de=a_de[i];dd=de.dd;f=dd.func
  663. if(f_note[f]&&de.m==undefined)
  664. f_note[f](de)}}
  665. function draw_deco_staff(){var s,p_voice,y,i,v,de,dd,w,minmax=new Array(nstaff+1),nd=a_de.length
  666. 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
  667. for(s=p_voice.sym;s;s=s.next){if(s.type!=C.BAR)
  668. continue
  669. if(!s.rbstart||s.norepbra)
  670. continue
  671. if(!s.next)
  672. break
  673. if(!first_repeat){first_repeat=s;set_font("repeat")}
  674. s1=s
  675. for(;;){if(!s.next)
  676. break
  677. s=s.next
  678. if(s.rbstop)
  679. break}
  680. x=s1.x
  681. if(s1.xsh)
  682. x+=s1.xsh
  683. y2=y_get(p_voice.st,true,x,s.x-x)+2
  684. if(y<y2)
  685. y=y2
  686. if(s1.rbstart==2){y2=y_get(p_voice.st,true,x,3)+10
  687. if(y<y2)
  688. y=y2}
  689. if(s.rbstop==2){y2=y_get(p_voice.st,true,s.x-3,3)+10
  690. if(y<y2)
  691. y=y2}
  692. if(s1.text){wh=strwh(s1.text);y2=y_get(p_voice.st,true,x+4,wh[0])+
  693. wh[1]
  694. if(y<y2)
  695. y=y2}
  696. if(s.rbstart)
  697. s=s.prev}
  698. s=first_repeat
  699. if(!s)
  700. return
  701. set_dscale(p_voice.st,true);y2=y*staff_tb[p_voice.st].staffscale
  702. for(;s;s=s.next){if(!s.rbstart||s.norepbra)
  703. continue
  704. s1=s
  705. while(1){if(!s.next)
  706. break
  707. s=s.next
  708. if(s.rbstop)
  709. break}
  710. if(s1==s)
  711. break
  712. x=s1.x
  713. if(s1.xsh)
  714. x+=s1.xsh
  715. if(cfmt.measurenb>0&s.bar_num&&s.bar_num%cfmt.measurenb)
  716. x+=6
  717. 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))
  718. w=s.wl
  719. else if(s.bar_type.slice(-1)==':')
  720. w=12
  721. else if(s.bar_type[0]!=':')
  722. w=0
  723. else
  724. w=8}else{w=(s.rbstop&&!s.rbstart)?0:8}
  725. w=(s.x-x-w)
  726. if(!s.next&&!s.rbstop&&!p_voice.bar_start){p_voice.bar_start=_bar(s)
  727. p_voice.bar_start.bar_type=""
  728. p_voice.bar_start.rbstart=1}
  729. if(s1.text)
  730. xy_str(x+4,y2-gene.curfont.size,s1.text);xypath(x,y2);if(s1.rbstart==2)
  731. output+='m0 10v-10';output+='h'+w.toFixed(1)
  732. if(s.rbstop==2)
  733. output+='v10';output+='"/>\n';y_set(s1.st,true,x,w,y+2)
  734. if(s.rbstart)
  735. s=s.prev}}
  736. for(i=0;i<=nstaff;i++)
  737. minmax[i]={ymin:0,ymax:0}
  738. for(i=0;i<nd;i++){de=a_de[i];dd=de.dd
  739. if(!dd)
  740. continue
  741. if(!f_staff[dd.func]||de.m!=undefined||dd.ty=='<'||dd.ty=='>'||dd.ty=='@')
  742. continue
  743. f_staff[dd.func](de)
  744. if(dd.func!=6||dd.dd_en)
  745. continue
  746. 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)
  747. minmax[de.st].ymax=de.y}else{if(de.y<minmax[de.st].ymin)
  748. minmax[de.st].ymin=de.y}}}
  749. for(i=0;i<nd;i++){de=a_de[i];dd=de.dd
  750. if(!dd)
  751. continue
  752. if(dd.ty=='@'){var y2
  753. y=de.y
  754. if(y>0){y2=y+dd.h+2
  755. if(y2>staff_tb[de.st].ann_top)
  756. staff_tb[de.st].ann_top=y2}else{y2=y-dd.hd-2
  757. if(y2<staff_tb[de.st].ann_bot)
  758. staff_tb[de.st].ann_bot=y2}
  759. continue}
  760. if(dd.func!=6||dd.ty=='<'||dd.ty=='>'||dd.dd_en)
  761. continue
  762. w=de.val||(dd.wl+dd.wr)
  763. 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)
  764. y=minmax[de.st].ymax
  765. else
  766. y=minmax[de.st].ymin;de.y=y}else{y=de.y}
  767. if(de.up)
  768. y+=dd.h;else
  769. y-=dd.hd
  770. y_set(de.st,de.up,de.x,w,y)}
  771. for(i=0;i<nd;i++){de=a_de[i]
  772. dd=de.dd
  773. if(!dd)
  774. continue
  775. if(dd.dd_en||dd.name.slice(0,3)!="ped")
  776. continue
  777. w=de.val||10
  778. de.y=y_get(de.st,0,de.x,w)
  779. -(dd.dd_st&&cfmt.pedline?10:dd.h)
  780. y_set(de.st,0,de.x,w,de.y)}
  781. draw_all_chsy()
  782. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v]
  783. if(p_voice.second||!p_voice.sym||p_voice.ignore)
  784. continue
  785. draw_repbra(p_voice)}}
  786. function draw_measnb(){var s,st,bar_num,x,y,w,any_nb,font_size,w0,sy=cur_sy
  787. for(st=0;st<=nstaff;st++){if(sy.st_print[st])
  788. break}
  789. if(st>nstaff)
  790. return
  791. set_dscale(st)
  792. if(staff_tb[st].staffscale!=1){font_size=get_font("measure").size;param_set_font("measurefont","* "+
  793. (font_size/staff_tb[st].staffscale).toString())}
  794. set_font("measure");w0=cwidf('0');s=tsfirst;bar_num=gene.nbar
  795. if(bar_num>1){if(cfmt.measurenb==0){any_nb=true;y=y_get(st,true,0,20)
  796. if(y<staff_tb[st].topbar+14)
  797. y=staff_tb[st].topbar+14;xy_str(0,y-gene.curfont.size*.2,bar_num.toString())
  798. 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}
  799. break}
  800. if(s.type!=C.BAR||!s.bar_num){any_nb=true;w=w0
  801. if(bar_num>=10)
  802. w*=bar_num>=100?3:2
  803. if(gene.curfont.pad)
  804. w+=gene.curfont.pad*2
  805. x=(s.prev?s.prev.x+s.prev.wr/2:s.x-s.wl)-w
  806. y=y_get(st,true,x,w)+5
  807. if(y<staff_tb[st].topbar+6)
  808. y=staff_tb[st].topbar+6;y+=gene.curfont.pad
  809. xy_str(x,y-gene.curfont.size*.2,bar_num.toString())
  810. y+=gene.curfont.size+gene.curfont.pad
  811. y_set(st,true,x,w,y)}}}
  812. for(;s;s=s.ts_next){switch(s.type){case C.STAVES:sy=s.sy
  813. for(st=0;st<nstaff;st++){if(sy.st_print[st])
  814. break}
  815. set_dscale(st)
  816. continue
  817. default:continue
  818. case C.BAR:if(!s.bar_num||s.bar_num<=1)
  819. continue
  820. break}
  821. bar_num=s.bar_num
  822. if(cfmt.measurenb==0||(bar_num%cfmt.measurenb)!=0||!s.next||s.bar_mrep)
  823. continue
  824. if(!any_nb)
  825. any_nb=true;w=w0
  826. if(bar_num>=10)
  827. w*=bar_num>=100?3:2
  828. if(gene.curfont.pad)
  829. w+=gene.curfont.pad*2
  830. x=s.x
  831. y=y_get(st,true,x,w)
  832. if(y<staff_tb[st].topbar+6)
  833. y=staff_tb[st].topbar+6
  834. if(s.next.type==C.NOTE){if(s.next.stem>0){if(y<s.next.ys-gene.curfont.size)
  835. y=s.next.ys-gene.curfont.size}else{if(y<s.next.y)
  836. y=s.next.y}}
  837. y+=2+gene.curfont.pad
  838. xy_str(x,y-gene.curfont.size*.2,bar_num.toString())
  839. y+=gene.curfont.size+gene.curfont.pad
  840. y_set(st,true,x,w,y)}
  841. gene.nbar=bar_num
  842. if(font_size)
  843. param_set_font("measurefont","* "+font_size.toString())}
  844. function draw_partempo(){var s,s2,some_part,some_tempo,h,w,y,st,sy=cur_sy
  845. for(st=0;st<=nstaff;st++){if(sy.st_print[st])
  846. break}
  847. if(st>nstaff)
  848. return
  849. set_dscale(st,1)
  850. var ymin=staff_tb[st].topbar+2,dosh=0,shift=1,x=-100,yn=0
  851. for(s=tsfirst;s;s=s.ts_next){s2=s.part
  852. if(!s2||s2.invis)
  853. continue
  854. if(!some_part){some_part=s;set_font("parts");h=gene.curfont.size+2+
  855. gene.curfont.pad*2}
  856. if(s2.x==undefined)
  857. s2.x=s.x-10
  858. w=strwh(s2.text)[0]
  859. y=y_get(st,true,s2.x,w+3)
  860. if(ymin<y)
  861. ymin=y}
  862. if(some_part){set_sscale(-1)
  863. ymin*=staff_tb[st].staffscale
  864. for(s=some_part;s;s=s.ts_next){s2=s.part
  865. if(!s2||s2.invis)
  866. continue
  867. w=strwh(s2.text)[0]
  868. if(user.anno_start||user.anno_stop){s2.wl=0
  869. s2.wr=w
  870. s2.ymn=ymin
  871. s2.ymx=s2.ymn+h
  872. anno_start(s2)}
  873. xy_str(s2.x,ymin+2+gene.curfont.pad+gene.curfont.size*.22,s2.text)
  874. y_set(st,1,s2.x,w+3,ymin+2+h)
  875. if(s2.x<0)
  876. yn=ymin+2+h
  877. anno_stop(s2)}}
  878. ymin=staff_tb[st].topbar+6
  879. for(s=tsfirst;s;s=s.ts_next){if(s.type!=C.TEMPO||s.invis)
  880. continue
  881. if(!some_tempo)
  882. some_tempo=s
  883. w=s.tempo_wh[0]
  884. y=y_get(st,true,s.x-16,w)
  885. if(s.x-16<0)
  886. y=yn
  887. if(y>ymin)
  888. ymin=y
  889. if(x>=s.x-16&&!(dosh&(shift>>1)))
  890. dosh|=shift
  891. shift<<=1
  892. x=s.x-16+w}
  893. if(some_tempo){set_sscale(-1)
  894. set_font("tempo")
  895. h=gene.curfont.size
  896. ymin+=2
  897. ymin*=staff_tb[st].staffscale
  898. for(s=some_tempo;s;s=s.ts_next){if(s.type!=C.TEMPO||s.invis)
  899. continue
  900. w=s.tempo_wh[0]
  901. y=ymin
  902. if(dosh&1)
  903. y+=h
  904. if(user.anno_start||user.anno_stop){s.wl=16
  905. s.wr=w-16
  906. s.ymn=y
  907. s.ymx=s.ymn+14
  908. anno_start(s)}
  909. writempo(s,s.x-16,y)
  910. anno_stop(s)
  911. y_set(st,1,s.x-16,w,y+h+2)
  912. dosh>>=1}}}
  913. 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
  914. var cache,anno_a=[]
  915. function b_pos(grace,stem,nflags,b){var top,bot,d1,d2,shift=!grace?BEAM_SHIFT:3.5,depth=!grace?BEAM_DEPTH:1.8
  916. function rnd6(y){var iy=Math.round((y+12)/6)*6-12
  917. return iy-y}
  918. if(stem>0){bot=b-(nflags-1)*shift-depth
  919. if(bot>26)
  920. return 0
  921. top=b}else{top=b+(nflags-1)*shift+depth
  922. if(top<-2)
  923. return 0
  924. bot=b}
  925. d1=rnd6(top-BEAM_OFFSET);d2=rnd6(bot+BEAM_OFFSET)
  926. return d1*d1>d2*d2?d2:d1}
  927. function sym_dup(s){var m,note
  928. s=clone(s)
  929. s.invis=true
  930. delete s.extra;delete s.text
  931. delete s.a_gch
  932. delete s.a_ly
  933. delete s.a_dd;delete s.tp
  934. s.notes=clone(s.notes)
  935. for(m=0;m<=s.nhd;m++){note=s.notes[m]=clone(s.notes[m])
  936. delete note.a_dd}
  937. return s}
  938. 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]]
  939. 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
  940. if(!s1.beam_st){s=sym_dup(s1);lkvsym(s,s1);lktsym(s,s1);s.x-=12
  941. if(s.x>s1.prev.x+12)
  942. s.x=s1.prev.x+12;s.beam_st=true
  943. delete s.beam_end;s.tmp=true
  944. delete s.sls;s1=s}
  945. notes=nflags=0;two_staves=two_dir=false;st=s1.st;v=s1.v;stem_xoff=s1.grace?GSTEM_XOFF:3.5
  946. for(s2=s1;;s2=s2.next){if(s2.type==C.NOTE){if(s2.nflags>nflags)
  947. nflags=s2.nflags;notes++
  948. if(s2.st!=st)
  949. two_staves=true
  950. if(s2.stem!=s1.stem)
  951. two_dir=true
  952. if(!visible&&!s2.invis&&(!s2.stemless||s2.trem2))
  953. visible=true
  954. if(s2.beam_end)
  955. break}
  956. if(!s2.next){for(;;s2=s2.prev){if(s2.type==C.NOTE)
  957. break}
  958. s=sym_dup(s2);s.next=s2.next
  959. if(s.next)
  960. s.next.prev=s;s2.next=s;s.prev=s2;s.ts_next=s2.ts_next
  961. if(s.ts_next)
  962. s.ts_next.ts_prev=s;s2.ts_next=s;s.ts_prev=s2
  963. delete s.beam_st;s.beam_end=true;s.tmp=true
  964. delete s.sls;s.x+=12
  965. if(s.x<realwidth-12)
  966. s.x=realwidth-12;s2=s;notes++
  967. break}}
  968. if(!visible)
  969. return false;bm.s2=s2
  970. if(staff_tb[st].y==0){if(two_staves)
  971. 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
  972. return true}}
  973. s_closest=s1;p_min=100;p_max=0
  974. for(s=s1;;s=s.next){if(s.type!=C.NOTE)
  975. continue
  976. if((scale=s.p_v.scale)==1)
  977. scale=staff_tb[s.st].staffscale
  978. if(s.stem>=0){x=stem_xoff+s.notes[0].shhd
  979. 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
  980. if(s.notes[0].pit<p_min){p_min=s.notes[0].pit;s_closest=s}}
  981. s.xs=s.x+x*scale;if(s==s2)
  982. break}
  983. if(s.grace&&s1.fmt.flatbeams)
  984. a=0
  985. else if(!two_dir&&notes>=3&&s_closest!=s1&&s_closest!=s2)
  986. a=0
  987. y=s1.ys+staff_tb[st].y
  988. if(a==undefined)
  989. a=(s2.ys+staff_tb[s2.st].y-y)/(s2.xs-s1.xs)
  990. if(a!=0){a=s1.fmt.beamslope*a/(s1.fmt.beamslope+Math.abs(a))
  991. if(a>-.04&&a<.04)
  992. a=0}
  993. b=(y+s2.ys+staff_tb[s2.st].y)/2-a*(s2.xs+s1.xs)/2
  994. max_stem_err=0;s=s1
  995. if(two_dir){ys=((s1.grace?3.5:BEAM_SHIFT)*(nflags-1)+
  996. BEAM_DEPTH)*.5
  997. if(s1.nflags==s2.nflags);else if(s1.stem!=s2.stem&&s1.nflags<s2.nflags)
  998. b+=ys*s2.stem
  999. else
  1000. b+=ys*s1.stem}else if(!s1.grace){var beam_h=BEAM_DEPTH+BEAM_SHIFT*(nflags-1)
  1001. while(s.ts_prev&&s.ts_prev.type==C.NOTE&&s.ts_prev.time==s.time&&s.ts_prev.x>s1.xs)
  1002. s=s.ts_prev
  1003. for(;s&&s.time<=s2.time;s=s.ts_next){if(s.type!=C.NOTE||s.invis||(s.st!=st&&s.v!=v)){continue}
  1004. x=s.v==v?s.xs:s.x;ys=a*x+b-staff_tb[s.st].y
  1005. if(s.v==v){stem_err=min_tb[s.nhd==0?0:1][s.nflags]
  1006. if(s.stem>0){if(s.notes[s.nhd].pit>26){stem_err-=2
  1007. if(s.notes[s.nhd].pit>28)
  1008. stem_err-=2}
  1009. stem_err-=ys-3*(s.notes[s.nhd].pit-18)}else{if(s.notes[0].pit<18){stem_err-=2
  1010. if(s.notes[0].pit<16)
  1011. stem_err-=2}
  1012. stem_err-=3*(s.notes[0].pit-18)-ys}
  1013. 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)
  1014. continue
  1015. if(s.v>v)
  1016. stem_err=s.ymx-ys
  1017. else
  1018. 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)
  1019. continue
  1020. if(s.v<v)
  1021. stem_err=ys-s.ymn
  1022. else
  1023. stem_err=ys-s.ymx+8}else{stem_err=ys-s.ymn}}
  1024. stem_err+=2+beam_h}
  1025. if(stem_err>max_stem_err)
  1026. max_stem_err=stem_err}}else{for(;;s=s.next){ys=a*s.xs+b-staff_tb[s.st].y;stem_err=GSTEM-2
  1027. if(s.stem>0)
  1028. stem_err-=ys-(3*(s.notes[s.nhd].pit-18))
  1029. else
  1030. stem_err+=ys-(3*(s.notes[0].pit-18));stem_err+=3*(s.nflags-1)
  1031. if(stem_err>max_stem_err)
  1032. max_stem_err=stem_err
  1033. if(s==s2)
  1034. break}}
  1035. if(max_stem_err>0)
  1036. b+=s1.stem*max_stem_err
  1037. if(!two_staves&&!two_dir)
  1038. for(s=s1.next;;s=s.next){switch(s.type){case C.REST:if(!s.multi)
  1039. break
  1040. g=s.ts_next
  1041. if(!g||g.st!=st||(g.type!=C.NOTE&&g.type!=C.REST))
  1042. break
  1043. case C.BAR:if(s.invis)
  1044. break
  1045. case C.CLEF:y=a*s.x+b
  1046. if(s1.stem>0){y=s.ymx-y
  1047. +BEAM_DEPTH+BEAM_SHIFT*(nflags-1)
  1048. +2
  1049. if(y>0)
  1050. b+=y}else{y=s.ymn-y
  1051. -BEAM_DEPTH-BEAM_SHIFT*(nflags-1)
  1052. -2
  1053. if(y<0)
  1054. b+=y}
  1055. break
  1056. case C.GRACE:for(g=s.extra;g;g=g.next){y=a*g.x+b
  1057. if(s1.stem>0){y=g.ymx-y
  1058. +BEAM_DEPTH+BEAM_SHIFT*(nflags-1)
  1059. +2
  1060. if(y>0)
  1061. b+=y}else{y=g.ymn-y
  1062. -BEAM_DEPTH-BEAM_SHIFT*(nflags-1)
  1063. -2
  1064. if(y<0)
  1065. b+=y}}
  1066. break}
  1067. if(s==s2)
  1068. break}
  1069. if(a==0)
  1070. b+=b_pos(s1.grace,s1.stem,nflags,b-staff_tb[st].y)
  1071. for(s=s1;;s=s.next){switch(s.type){case C.NOTE:s.ys=a*s.xs+b-staff_tb[s.st].y
  1072. if(s.stem>0){s.ymx=s.ys+2.5
  1073. 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}
  1074. break
  1075. case C.REST:y=a*s.x+b-staff_tb[s.st].y
  1076. dy=BEAM_DEPTH+BEAM_SHIFT*(nflags-1)
  1077. +(s.head!=C.FULL?4:9)
  1078. if(s1.stem>0){y-=dy
  1079. if(s1.multi==0&&y>12)
  1080. y=12
  1081. if(s.y<=y)
  1082. break}else{y+=dy
  1083. if(s1.multi==0&&y<12)
  1084. y=12
  1085. if(s.y>=y)
  1086. break}
  1087. if(s.head!=C.FULL)
  1088. y=(((y+3+12)/6)|0)*6-12;s.y=y
  1089. break}
  1090. if(s==s2)
  1091. break}
  1092. if(staff_tb[st].y==0)
  1093. return false
  1094. bm.s1=s1;bm.a=a;bm.b=b;bm.nflags=nflags
  1095. return true}
  1096. 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
  1097. function draw_beam(x1,x2,dy,h,bm,n){var y1,dy2,s=bm.s1,nflags=s.nflags
  1098. if(s.ntrem)
  1099. nflags-=s.ntrem
  1100. 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
  1101. if(dx<16){x1+=dx/4
  1102. x2-=dx/4}else{x1+=5
  1103. x2-=6}}}
  1104. y1=bm.a*x1+bm.b-dy;x2-=x1;x2/=stv_g.scale;dy2=bm.a*x2*stv_g.scale
  1105. 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'}
  1106. anno_start(s1,'beam')
  1107. 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}
  1108. bh/=stv_g.scale
  1109. beam_dir=s1.stem
  1110. if(s1.stem!=s2.stem&&s1.nflags<s2.nflags)
  1111. beam_dir=s2.stem
  1112. if(beam_dir<0)
  1113. bh=-bh;draw_beam(s1.xs-shift,s2.xs+shift,0,bh,bm,1);da=0
  1114. for(s=s1;;s=s.next){if(s.type==C.NOTE&&s.stem!=beam_dir)
  1115. s.ys=bm.a*s.xs+bm.b
  1116. -staff_tb[s.st].y
  1117. +bshift*(s.nflags-1)*s.stem
  1118. -bh
  1119. if(s==s2)
  1120. break}
  1121. if(s1.feathered_beam){da=bshift/(s2.xs-s1.xs)
  1122. if(s1.feathered_beam>0){da=-da;bshift=da*s1.xs}else{bshift=da*s2.xs}
  1123. da=da*beam_dir}
  1124. shift=0
  1125. for(i=2;i<=bm.nflags;i++){shift+=bshift
  1126. if(da!=0)
  1127. bm.a+=da
  1128. for(s=s1;;s=s.next){if(s.type!=C.NOTE||s.nflags<i){if(s==s2)
  1129. break
  1130. continue}
  1131. 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)
  1132. if(s==s2)
  1133. break
  1134. continue}
  1135. k1=s
  1136. while(1){if(s==s2)
  1137. break
  1138. k=s.next
  1139. if(k.type==C.NOTE||k.type==C.REST){if(k.trem1){if(k.nflags-k.ntrem<i)
  1140. break}else if(k.nflags<i){break}}
  1141. if(k.beam_br1||(k.beam_br2&&i>2))
  1142. break
  1143. s=k}
  1144. k2=s
  1145. while(k2.type!=C.NOTE)
  1146. k2=k2.prev;x1=k1.xs
  1147. bd=beam_dir
  1148. 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
  1149. while(k.type!=C.NOTE)
  1150. k=k.next
  1151. if(k.beam_br1||(k.beam_br2&&i>2)){x1-=bstub}else{k1=k1.prev
  1152. while(k1.type!=C.NOTE)
  1153. k1=k1.prev
  1154. if(k1.nflags<k.nflags||(k1.nflags==k.nflags&&k1.dots<k.dots))
  1155. x1+=bstub
  1156. else
  1157. x1-=bstub}}
  1158. if(k1.stem!=beam_dir){bd=k1.stem
  1159. k1.ys=bm.a*k1.xs+bm.b
  1160. -staff_tb[k1.st].y-bh}}
  1161. draw_beam(x1,k2.xs,shift*bd,bh,bm,i)
  1162. if(s==s2)
  1163. break}}
  1164. if(s1.tmp)
  1165. unlksym(s1)
  1166. else if(s2.tmp)
  1167. unlksym(s2)
  1168. anno_stop(s1,'beam')}
  1169. function draw_lstaff(x){var i,j,yb,h,fl,nst=cur_sy.nstaff,l=0
  1170. function draw_sysbra(x,st,flag){var i,st_end,yt,yb
  1171. while(!cur_sy.st_print[st]){if(cur_sy.staves[st].flags&flag)
  1172. return
  1173. st++}
  1174. i=st_end=st
  1175. while(1){if(cur_sy.st_print[i])
  1176. st_end=i
  1177. if(cur_sy.staves[i].flags&flag)
  1178. break
  1179. i++}
  1180. 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
  1181. if(flag&(CLOSE_BRACE|CLOSE_BRACE2))
  1182. out_brace(x,yb,yt-yb)
  1183. else
  1184. out_bracket(x,yt,yt-yb)}
  1185. for(i=0;;i++){fl=cur_sy.staves[i].flags
  1186. if(fl&(OPEN_BRACE|OPEN_BRACKET))
  1187. l++
  1188. if(cur_sy.st_print[i])
  1189. break
  1190. if(fl&(CLOSE_BRACE|CLOSE_BRACKET))
  1191. l--
  1192. if(i==nst)
  1193. break}
  1194. for(j=nst;j>i;j--){if(cur_sy.st_print[j])
  1195. break}
  1196. if(i==j&&l==0)
  1197. return
  1198. 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'
  1199. for(i=0;i<=nst;i++){fl=cur_sy.staves[i].flags
  1200. if(fl&OPEN_BRACE)
  1201. draw_sysbra(x,i,CLOSE_BRACE)
  1202. if(fl&OPEN_BRACKET)
  1203. draw_sysbra(x,i,CLOSE_BRACKET)
  1204. if(fl&OPEN_BRACE2)
  1205. draw_sysbra(x-6,i,CLOSE_BRACE2)
  1206. if(fl&OPEN_BRACKET2)
  1207. draw_sysbra(x-6,i,CLOSE_BRACKET2)}}
  1208. function draw_meter(s){if(!s.a_meter)
  1209. return
  1210. var dx,i,j,meter,x,st=s.st,p_staff=staff_tb[st],y=p_staff.y;if(p_staff.stafflines!='|||||')
  1211. y+=(p_staff.topbar+p_staff.botbar)/2-12
  1212. for(i=0;i<s.a_meter.length;i++){meter=s.a_meter[i];x=s.x+s.x_meter[i]
  1213. if(meter.bot){out_XYAB('\
  1214. <g transform="translate(X,Y)" text-anchor="middle">\n\
  1215. <text y="-12">A</text>\n\
  1216. <text>B</text>\n\
  1217. </g>\n',x,y+6,m_gl(meter.top),m_gl(meter.bot))}else{out_XYAB('\
  1218. <text x="X" y="Y" text-anchor="middle">A</text>\n',x,y+12,m_gl(meter.top))}}}
  1219. var acc_nd={}
  1220. function draw_acc(x,y,a){if(typeof a=="object"){var c,n=a[0],d=a[1]
  1221. c=n+'_'+d
  1222. a=acc_nd[c]
  1223. if(!a){a=abc2svg.rat(Math.abs(n),d)
  1224. d=a[1]
  1225. a=(n<0?-a[0]:a[0]).toString()
  1226. if(d!=1)
  1227. a+='_'+d
  1228. acc_nd[c]=a}}
  1229. xygl(x,y,"acc"+a)}
  1230. function set_hl(p_st,n,x,dx1,dx2){var i,hl
  1231. if(n>=0){hl=p_st.hlu[n]
  1232. if(!hl)
  1233. hl=p_st.hlu[n]=[]}else{hl=p_st.hld[-n]
  1234. if(!hl)
  1235. hl=p_st.hld[-n]=[]}
  1236. for(i=0;i<hl.length;i++){if(x>=hl[i][0])
  1237. break}
  1238. 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])
  1239. hl[i][1]=dx1
  1240. if(dx2>hl[i][2])
  1241. hl[i][2]=dx2}}
  1242. Abc.prototype.draw_hl=function(s){var i,j,n,note,hla=[],st=s.st,p_staff=staff_tb[st]
  1243. if(!p_staff.hll||s.invis)
  1244. return
  1245. for(i=0;i<=s.nhd;i++){note=s.notes[i]
  1246. if(!p_staff.hlmap[note.pit-p_staff.hll])
  1247. hla.push([note.pit-18,note.shhd*stv_g.scale])}
  1248. n=hla.length
  1249. if(!n)
  1250. return
  1251. 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
  1252. note=s.notes[s.stem<0?s.nhd:0]
  1253. shhd=note.shhd
  1254. for(i=0;i<hla.length;i++){hlp=hla[i][0]
  1255. dx1=(hla[i][1]<shhd?hla[i][1]:shhd)-dx
  1256. dx2=(hla[i][1]>shhd?hla[i][1]:shhd)+dx
  1257. if(hlp<bot*2){if(hlp<yl*2)
  1258. yl=++hlp>>1
  1259. n--}else if(hlp>top*2){yu=hlp>>1
  1260. n--}
  1261. set_hl(p_staff,hlp>>1,s.x,dx1,dx2)}
  1262. dx1=shhd-dx
  1263. dx2=shhd+dx
  1264. while(++yl<bot)
  1265. set_hl(p_staff,yl,s.x,dx1,dx2)
  1266. while(--yu>top)
  1267. set_hl(p_staff,yu,s.x,dx1,dx2)
  1268. if(!n)
  1269. return
  1270. i=yl;j=yu
  1271. while(i>bot&&stafflines[i]=='-')
  1272. i--
  1273. while(j<top&&stafflines[j]=='-')
  1274. j++
  1275. for(;i<j;i++){if(stafflines[i]=='-')
  1276. set_hl(p_staff,i,s.x,dx1,dx2)}}
  1277. 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])
  1278. 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
  1279. function set_k_acc(a_acc,sf){var i,j,n,nacc,p_acc,accs=[],pits=[]
  1280. if(sf>0){for(nacc=0;nacc<sf;nacc++){accs[nacc]=1
  1281. pits[nacc]=[26,23,27,24,21,25,22][nacc]}}else{for(nacc=0;nacc<-sf;nacc++){accs[nacc]=-1
  1282. pits[nacc]=[22,25,21,24,20,23,26][nacc]}}
  1283. n=a_acc.length
  1284. for(i=0;i<n;i++){p_acc=a_acc[i]
  1285. for(j=0;j<nacc;j++){if(pits[j]==p_acc.pit){accs[j]=p_acc.acc
  1286. break}}
  1287. if(j==nacc){accs[j]=p_acc.acc
  1288. pits[j]=p_acc.pit
  1289. nacc++}}
  1290. for(i=0;i<nacc;i++){p_acc=a_acc[i]
  1291. if(!p_acc)
  1292. p_acc=a_acc[i]={}
  1293. p_acc.acc=accs[i]
  1294. p_acc.pit=pits[i]}}
  1295. if(clef_ix&1)
  1296. clef_ix+=7;clef_ix/=2
  1297. while(clef_ix<0)
  1298. clef_ix+=7;clef_ix%=7
  1299. if(a_acc&&!s.exp)
  1300. set_k_acc(a_acc,s.k_sf)
  1301. 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
  1302. for(i=0;i<old_sf;i++){xygl(x,staffb+shift,"acc3");shift+=p_seq[i];x+=5.5}
  1303. shift=flat_cl[clef_ix];p_seq=shift<18?flat1:flat2
  1304. for(i=0;i>old_sf;i--){xygl(x,staffb+shift,"acc3");shift+=p_seq[-i];x+=5.5}
  1305. if(s.k_sf!=0)
  1306. x+=3}}
  1307. if(s.k_sf>0){shift=sharp_cl[clef_ix];p_seq=shift>9?sharp1:sharp2
  1308. for(i=0;i<s.k_sf;i++){xygl(x,staffb+shift,"acc1");shift+=p_seq[i];x+=5.5}
  1309. if(s.fmt.cancelkey&&i<old_sf){x+=2
  1310. for(;i<old_sf;i++){xygl(x,staffb+shift,"acc3");shift+=p_seq[i];x+=5.5}}
  1311. if(s.k_bagpipe=='p'){xygl(x,staffb+27,"acc3")
  1312. x+=5.5}}
  1313. if(s.k_sf<0){shift=flat_cl[clef_ix];p_seq=shift<18?flat1:flat2
  1314. for(i=0;i>s.k_sf;i--){xygl(x,staffb+shift,"acc-1");shift+=p_seq[-i];x+=5.5}
  1315. if(s.fmt.cancelkey&&i>old_sf){x+=2
  1316. 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:[{}]}
  1317. for(i=0;i<a_acc.length;i++){acc=a_acc[i];shift=(s.k_y_clef
  1318. +acc.pit-18)*3
  1319. while(shift<-3)
  1320. shift+=21
  1321. while(shift>27)
  1322. shift-=21
  1323. if(i!=0&&(shift>last_shift+18||shift<last_shift-18))
  1324. x-=5.5
  1325. else if(acc.acc!=last_acc)
  1326. x+=3;last_acc=acc.acc;s2.x=x
  1327. s2.notes[0].pit=shift/3+18;last_shift=shift;draw_acc(x,staffb+shift,acc.acc)
  1328. x+=5.5}}}
  1329. function nrep_out(x,y,n){y-=3
  1330. if(n<10){xygl(x-4,y,"mtr"+n)}else{xygl(x-10,y,"mtr"+((n/10)|0))
  1331. xygl(x-2,y,"mtr"+(n%10))}}
  1332. function center_rest(s){var s2,x
  1333. if(s.dur<C.BLEN*2)
  1334. s.nflags=-2
  1335. else if(s.dur<C.BLEN*4)
  1336. s.nflags=-3
  1337. else
  1338. s.nflags=-4
  1339. s.dots=0
  1340. s2=s.ts_next
  1341. while(s2.time!=s.time+s.dur&&s2.ts_next)
  1342. s2=s2.ts_next
  1343. x=s2.x-s2.wl
  1344. s2=s
  1345. while(!s2.seqst)
  1346. s2=s2.ts_prev
  1347. s2=s2.ts_prev
  1348. x=(x+s2.x+s2.wr)/2
  1349. if(s.a_dd)
  1350. deco_update(s,x-s.x)
  1351. s.x=x}
  1352. var rest_tb=["r128","r64","r32","r16","r8","r4","r2","r1","r0","r00"]
  1353. function draw_rest(s){var s2,i,j,y,bx,p_staff=staff_tb[s.st],yb=p_staff.y,x=s.x
  1354. if(s.notes[0].shhd)
  1355. x+=s.notes[0].shhd*stv_g.scale
  1356. if(s.rep_nb){set_sscale(s.st);anno_start(s);if(p_staff.stafflines=='|||||')
  1357. yb+=12
  1358. else
  1359. yb+=(p_staff.topbar+p_staff.botbar)/2
  1360. if(s.rep_nb<0){xygl(x,yb,"srep")}else{xygl(x,yb,"mrep")
  1361. if(s.rep_nb>2&&s.v==cur_sy.top_voice&&s.fmt.measrepnb>0&&!(s.rep_nb%s.fmt.measrepnb))
  1362. nrep_out(x,yb+p_staff.topbar,s.rep_nb)}
  1363. anno_a.push(s)
  1364. return}
  1365. set_scale(s);anno_start(s);if(s.notes[0].color)
  1366. set_color(s.notes[0].color);y=s.y;i=5-s.nflags
  1367. if(i==7&&y==12&&p_staff.stafflines.length<=2)
  1368. y-=6
  1369. if(!s.notes[0].invis)
  1370. xygl(x,y+yb,rest_tb[i])
  1371. if(s.dots){x+=8;y+=yb+3
  1372. j=s.dots
  1373. i=(s.dur_orig/12)>>((5-s.nflags)-j)
  1374. while(j-->0){xygl(x,y,(i&(1<<j))?"dot":"dot+")
  1375. x+=3.5}}
  1376. set_color();anno_a.push(s)}
  1377. 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()
  1378. if(!s.next){error(1,s,"Lack of bar after multi-measure rest")
  1379. return}
  1380. set_scale(s)
  1381. prev=s
  1382. while(!prev.seqst)
  1383. prev=prev.ts_prev
  1384. prev=prev.ts_prev
  1385. while(!prev.seqst)
  1386. prev=prev.ts_prev
  1387. x1=prev.x+20
  1388. x2=s.next.x-20
  1389. s.x=(x1+x2)/2
  1390. anno_start(s)
  1391. out_XYAB('<path d="mX Y',x1+.6,y-2.7)
  1392. output+='v2.7h-1.4v-10.8h1.4v2.7h'
  1393. +((x2-x1-2.8)/stv_g.scale).toFixed(1)
  1394. +'v-2.7h1.4v10.8h-1.4v-2.7z"/>\n'
  1395. if(s.tacet)
  1396. out_XYAB('<text x ="X" y="Y" style="font-size:12px;font-weight:700"\
  1397. text-anchor="middle">A</text>\n',s.x,y+18,s.tacet)
  1398. else
  1399. out_XYAB('<text x ="X" y="Y" text-anchor="middle">A</text>\n',s.x,y+22,m_gl(p))
  1400. anno_a.push(s)}
  1401. function grace_slur(s){var yy,x0,y0,x3,y3,bet1,bet2,dy1,dy2,last,below,so=s,g=s.extra
  1402. while(1){if(!g.next)
  1403. break
  1404. g=g.next}
  1405. last=g
  1406. below=((g.stem>=0||s.multi<0)&&g.notes[0].pit<=28)||g.notes[0].pit<16
  1407. if(below){yy=127
  1408. for(g=s.extra;g;g=g.next){if(g.y<yy){yy=g.y;last=g}}
  1409. x0=last.x;y0=last.y-5
  1410. if(s.extra!=last){x0-=4;y0+=1}
  1411. s=s.next;x3=s.x-1
  1412. if(s.stem<0&&s.nflags>-2)
  1413. x3-=4;y3=3*(s.notes[0].pit-18)-5;dy1=(x3-x0)*.4
  1414. if(dy1>3)
  1415. dy1=3;dy2=dy1;bet1=.2;bet2=.8
  1416. 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
  1417. for(g=s.extra;g;g=g.next){if(g.y>yy){yy=g.y;last=g}}
  1418. x0=last.x;y0=last.y+5
  1419. if(s.extra!=last){x0-=4;y0-=1}
  1420. s=s.next;x3=s.x-1
  1421. if(s.stem>=0&&s.nflags>-2)
  1422. x3-=2;y3=3*(s.notes[s.nhd].pit-18)+5;dy1=(x0-x3)*.4
  1423. if(dy1<-3)
  1424. dy1=-3;dy2=dy1;bet1=.2;bet2=.8
  1425. 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}}
  1426. 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}
  1427. y0-=so.slur.y1
  1428. g=so.extra
  1429. if(below){if(y0<g.ymn)
  1430. g.ymn=y0}else{if(y0>g.ymx)
  1431. g.ymx=y0}}
  1432. function draw_gracenotes(s){var x1,y1,last,note,bm={},g=s.extra
  1433. while(1){if(g.beam_st&&!g.beam_end){if(self.calculate_beam(bm,g))
  1434. draw_beams(bm)}
  1435. anno_start(g)
  1436. draw_note(g,!bm.s2)
  1437. if(g==bm.s2)
  1438. bm.s2=null
  1439. anno_a.push(s)
  1440. if(!g.next)
  1441. break
  1442. g=g.next}
  1443. last=g
  1444. if(s.sappo){g=s.extra
  1445. if(!g.next){x1=9
  1446. y1=g.stem>0?5:-5}else{x1=(g.next.x-g.x)*.5+4
  1447. y1=(g.ys+g.next.ys)*.5-g.y
  1448. if(g.stem>0)
  1449. y1-=1
  1450. else
  1451. y1+=1}
  1452. note=g.notes[g.stem<0?0:g.nhd]
  1453. out_acciac(x_head(g,note),y_head(g,note),x1,y1,g.stem>0)}
  1454. g=s.slur
  1455. if(g){anno_start(s,'slur')
  1456. xypath(g.x0,g.y0+staff_tb[s.st].y)
  1457. 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'
  1458. anno_stop(s,'slur')}}
  1459. function setdoty(s,y_tb){var m,m1,y
  1460. for(m=0;m<=s.nhd;m++){y=3*(s.notes[m].pit-18)
  1461. if((y%6)==0){if(s.dot_low)
  1462. y-=3
  1463. else
  1464. y+=3}
  1465. y_tb[m]=y}
  1466. for(m=0;m<s.nhd;m++){if(y_tb[m+1]>y_tb[m])
  1467. continue
  1468. m1=m
  1469. while(m1>0){if(y_tb[m1]>y_tb[m1-1]+6)
  1470. break
  1471. m1--}
  1472. if(3*(s.notes[m1].pit-18)-y_tb[m1]<y_tb[m+1]-3*(s.notes[m+1].pit-18)){while(m1<=m)
  1473. y_tb[m1++]-=6}else{y_tb[m+1]=y_tb[m]+6}}}
  1474. function x_head(s,note){return s.x+note.shhd*stv_g.scale}
  1475. function y_head(s,note){return staff_tb[s.st].y+3*(note.pit-18)}
  1476. 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
  1477. var elts=identify_note(s,note.dur),head=elts[0],dots=elts[1],nflags=elts[2]
  1478. 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]
  1479. if(!p)
  1480. p=note.map[0][note.map[0].length-1]
  1481. i=p.indexOf('/')
  1482. if(i>=0){if(s.stem>=0)
  1483. p=p.slice(0,i)
  1484. else
  1485. p=p.slice(i+1)}}else if(s.type==C.CUSTOS){p="custos"}else{switch(head){case C.OVAL:p="HD"
  1486. break
  1487. case C.OVALBARS:if(s.head!=C.SQUARE){p="HDD"
  1488. break}
  1489. case C.SQUARE:if(nflags>-4){p="breve"}else{p="longa"
  1490. inv=s.stem>0}
  1491. if(!tsnext&&s.next&&s.next.type==C.BAR&&!s.next.next)
  1492. dots=0
  1493. x_note+=1
  1494. break
  1495. case C.EMPTY:p="Hd"
  1496. break
  1497. default:p="hd"
  1498. break}}
  1499. if(note.color!=undefined)
  1500. old_color=set_color(note.color)
  1501. if(p){if(inv){g_open(x_note,y_note,0,1,-1);x_note=y_note=0}
  1502. if(!self.psxygl(x_note,y_note,p))
  1503. xygl(x_note,y_note,p)
  1504. if(inv)
  1505. g_close()}
  1506. if(dots){dotx=x+(7.7+s.xmx)*stv_g.scale
  1507. if(y_tb[m]==undefined){y_tb[m]=3*(s.notes[m].pit-18)
  1508. if((s.notes[m].pit&1)==0)
  1509. y_tb[m]+=3}
  1510. doty=y_tb[m]+staffb
  1511. i=(note.dur/12)>>((5-nflags)-dots)
  1512. while(dots-->0){xygl(dotx,doty,(i&(1<<dots))?"dot":"dot+")
  1513. dotx+=3.5}}
  1514. if(note.acc){x-=note.shac*stv_g.scale
  1515. if(!s.grace){draw_acc(x,y+staffb,note.acc)}else{g_open(x,y+staffb,0,.75);draw_acc(0,0,note.acc)
  1516. g_close()}}
  1517. if(old_color!=false)
  1518. set_color(old_color)}
  1519. 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
  1520. if(s.dots)
  1521. setdoty(s,y_tb)
  1522. if(!s.stemless){slen=s.ys-s.y;nflags=s.nflags
  1523. if(s.ntrem)
  1524. nflags-=s.ntrem
  1525. if(!fl||nflags<=0){if(s.nflags>0){if(s.stem>=0)
  1526. slen-=1
  1527. else
  1528. slen+=1}
  1529. 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)}
  1530. if(fl&&s.trem1){var ntrem=s.ntrem||0,x1=x;slen=3*(s.notes[s.stem>0?s.nhd:0].pit-18)
  1531. if(s.head==C.FULL||s.head==C.EMPTY){x1+=(s.grace?GSTEM_XOFF:3.5)*s.stem
  1532. if(s.stem>0)
  1533. slen+=6+5.4*ntrem
  1534. else
  1535. slen-=6+5.4}else{if(s.stem>0)
  1536. slen+=5+5.4*ntrem
  1537. else
  1538. slen-=5+5.4}
  1539. slen/=s.p_v.scale;out_trem(x1,staffb+slen,ntrem)}
  1540. for(m=0;m<=s.nhd;m++)
  1541. draw_basic_note(s,m,y_tb)}
  1542. function prev_scut(s){while(s.prev){s=s.prev
  1543. if(s.rbstart)
  1544. return s}
  1545. s=s.p_v.sym
  1546. while(s.type!=C.CLEF)
  1547. s=s.ts_prev
  1548. if(s.next&&s.next.type==C.KEY)
  1549. s=s.next
  1550. if(s.next&&s.next.type==C.METER)
  1551. return s.next
  1552. return s}
  1553. function slur_direction(k1,k2){var s,some_upstem,low,dir
  1554. function slur_multi(s1,s2){if(s1.multi)
  1555. return s1.multi
  1556. if(s2.multi)
  1557. return s2.multi
  1558. return 0}
  1559. if(k1.grace&&k1.stem>0)
  1560. return-1
  1561. dir=slur_multi(k1,k2)
  1562. if(dir)
  1563. return dir
  1564. for(s=k1;;s=s.next){if(s.type==C.NOTE){if(!s.stemless){if(s.stem<0)
  1565. return 1
  1566. some_upstem=true}
  1567. if(s.notes[0].pit<22)
  1568. low=true}
  1569. if(s.time==k2.time)
  1570. break}
  1571. if(!some_upstem&&!low)
  1572. return 1
  1573. return-1}
  1574. function slur_out(x1,y1,x2,y2,dir,height,dotted){var dx,dy,dz,alfa=.3,beta=.45;dy=y2-y1
  1575. if(dy<0)
  1576. dy=-dy;dx=x2-x1
  1577. if(dx>40.&&dy/dx<.7){alfa=.3+.002*(dx-40.)
  1578. if(alfa>.7)
  1579. alfa=.7}
  1580. 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)
  1581. 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
  1582. if(dz>.6)
  1583. dz=.6;dz*=dir
  1584. dx*=.03
  1585. var scale_y=1
  1586. if(!dotted)
  1587. output+='<path d="M'
  1588. else
  1589. output+='<path class="stroke" stroke-dasharray="5,5" d="M';out_sxsy(x1,' ',y1);output+='c'+
  1590. ((xx1-x1)/stv_g.scale).toFixed(1)+' '+
  1591. ((y1-yy1)/scale_y).toFixed(1)+' '+
  1592. ((xx2-x1)/stv_g.scale).toFixed(1)+' '+
  1593. ((y1-yy2)/scale_y).toFixed(1)+' '+
  1594. ((x2-x1)/stv_g.scale).toFixed(1)+' '+
  1595. ((y1-y2)/scale_y).toFixed(1)
  1596. if(!dotted)
  1597. output+='\n\tv'+
  1598. (-dz).toFixed(1)+'c'+
  1599. ((xx2-dx-x2)/stv_g.scale).toFixed(1)+' '+
  1600. ((y2+dz-yy2-dy)/scale_y).toFixed(1)+' '+
  1601. ((xx1+dx-x2)/stv_g.scale).toFixed(1)+' '+
  1602. ((y2+dz-yy1-dy)/scale_y).toFixed(1)+' '+
  1603. ((x1-x2)/stv_g.scale).toFixed(1)+' '+
  1604. ((y2-y1)/scale_y).toFixed(1)
  1605. output+='"/>\n'}
  1606. function draw_slur(path,sl,recurr){var i,k,g,x1,y1,x2,y2,height,addy,s_st2,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],nn=1
  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!=k1.st&&!s_st2)
  1611. s_st2=k}}
  1612. if(s_st2&&!recurr){if(!gene.a_sl)
  1613. gene.a_sl=[]
  1614. h=24+k1.fmt.sysstaffsep
  1615. if(s_st2.st>k1.st)
  1616. h=-h
  1617. for(i=0;i<n;i++){k=path[i]
  1618. if(k.st==k1.st){if(k.dur)
  1619. a=k
  1620. continue}
  1621. k=clone(k)
  1622. if(path[i]==s_st2)
  1623. s_st2=k
  1624. path[i]=k
  1625. if(k.dur){k.notes=clone(k.notes)
  1626. k.notes[0]=clone(k.notes[0])
  1627. if(sl.ty&C.SL_CENTER){if(k.st!=a.st){sl.ty=(sl.ty&~0x07)|(a.st<k.st?C.SL_BELOW:C.SL_ABOVE)
  1628. z=k1.ymn
  1629. h=k2.ymx
  1630. if(k.st<a.st){for(i1=1;i1<i;i1++){a=path[i1]
  1631. if(a.ymn<z)
  1632. z=a.ymn}
  1633. for(i1=i;i1<i2;i1++){a=path[i1]
  1634. if(a.ymx>h)
  1635. h=a.ymx}}else{for(i1=1;i1<i;i1++){a=path[i1]
  1636. if(a.ymx>h)
  1637. h=a.ymx}
  1638. for(i1=i;i1<i2;i1++){a=path[i1]
  1639. if(a.ymn<z)
  1640. z=a.ymn}}
  1641. h+=z
  1642. a=k}
  1643. k.y=h-k.y
  1644. k.notes[0].pit=(k.y/3|0)+18
  1645. k.ys=h-k.ys
  1646. y=k.ymx
  1647. k.ymx=h-k.ymn
  1648. k.ymn=h-y
  1649. k.stem=-k.stem}else{k.notes[0].pit+=h/3|0
  1650. k.ys+=h
  1651. k.y+=h
  1652. k.ymx+=h
  1653. k.ymn+=h}}}
  1654. ty=k1.st>s_st2.st?'/':'\\'
  1655. if(sl.ty&C.SL_CENTER)
  1656. ty=ty+ty
  1657. else if(k1.st==k2.st)
  1658. ty=ty=='/'?'/\\':'\\/'
  1659. else
  1660. ty+=dir>0?'+':'-'
  1661. var savout=output
  1662. output=""
  1663. draw_slur(path,sl,1)
  1664. gene.a_sl.push([k1,s_st2,ty,output])
  1665. output=savout
  1666. return}
  1667. x1=k1.x
  1668. if(k1.notes&&k1.notes[0].shhd)
  1669. x1+=k1.notes[0].shhd;x2=k2.x
  1670. if(k2.notes)
  1671. x2+=k2.notes[0].shhd
  1672. if(not1){y1=3*(not1.pit-18)+2*dir
  1673. x1+=3}else{y1=dir>0?k1.ymx+2:k1.ymn-2
  1674. if(k1.type==C.NOTE){if(dir>0){if(k1.stem>0){x1+=5
  1675. 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
  1676. 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}}}}
  1677. if(sl.nte){y2=3*(sl.nte.pit-18)+2*dir
  1678. x2-=3}else{y2=dir>0?k2.ymx+2:k2.ymn-2
  1679. if(k2.type==C.NOTE){if(dir>0){if(k2.stem>0){x2+=1
  1680. if(k2.beam_st&&k2.nflags>=-1&&!k2.in_tuplet)
  1681. y2=k2.ys-6
  1682. else
  1683. y2=k2.ys+3}else{y2=k2.y+8}}else{if(k2.stem<0){x2-=5
  1684. if(k2.beam_st&&k2.nflags>=-1&&!k2.in_tuplet)
  1685. y2=k2.ys+6
  1686. else
  1687. y2=k2.ys-3}else{y2=k2.y-8}}}}
  1688. if(k1.type!=C.NOTE){y1=y2+1.2*dir;x1=k1.x+k1.wr*.5
  1689. if(x1>x2-12)
  1690. x1=x2-12}
  1691. if(k2.type!=C.NOTE){if(k1.type==C.NOTE)
  1692. y2=y1+1.2*dir
  1693. else
  1694. y2=y1
  1695. if(k1!=k2)
  1696. x2=k2.x-k2.wl*.3}
  1697. if(nn>=3){k=path[1]
  1698. if(k.type!=C.BAR&&k.x<x1+48){if(dir>0){y=k.ymx-2
  1699. if(y1<y)
  1700. y1=y}else{y=k.ymn+2
  1701. if(y1>y)
  1702. y1=y}}
  1703. k=path[i2-1]
  1704. if(k.type!=C.BAR&&k.x>x2-48){if(dir>0){y=k.ymx-2
  1705. if(y2<y)
  1706. y2=y}else{y=k.ymn+2
  1707. if(y2>y)
  1708. y2=y}}}
  1709. a=(y2-y1)/(x2-x1)
  1710. if(a>SLUR_SLOPE||a<-SLUR_SLOPE){a=a>SLUR_SLOPE?SLUR_SLOPE:-SLUR_SLOPE
  1711. if(a*dir>0)
  1712. y1=y2-a*(x2-x1)
  1713. else
  1714. y2=y1+a*(x2-x1)}
  1715. y=y2-y1
  1716. if(y>8)
  1717. y=8
  1718. else if(y<-8)
  1719. y=-8
  1720. z=y
  1721. if(z<0)
  1722. z=-z;dx=.5*z;dy=.3*y
  1723. if(y*dir>0){x2-=dx;y2-=dy}else{x1+=dx;y1+=dy}
  1724. if(k1.grace)
  1725. x1=k1.x-GSTEM_XOFF*.5
  1726. if(k2.grace)
  1727. x2=k2.x+GSTEM_XOFF*1.5;h=0;a=(y2-y1)/(x2-x1)
  1728. if(k1!=k2&&k1.v==k2.v){addy=y1-a*x1
  1729. for(i=1;i<i2;i++){k=path[i]
  1730. switch(k.type){case C.NOTE:case C.REST:if(dir>0){y=3*(k.notes[k.nhd].pit-18)+6
  1731. if(y<k.ymx)
  1732. y=k.ymx;y-=a*k.x+addy
  1733. if(y>h)
  1734. h=y}else{y=3*(k.notes[0].pit-18)-6
  1735. if(y>k.ymn)
  1736. y=k.ymn;y-=a*k.x+addy
  1737. if(y<h)
  1738. h=y}
  1739. break
  1740. case C.GRACE:for(g=k.extra;g;g=g.next){if(dir>0){y=3*(g.notes[g.nhd].pit-18)+6
  1741. if(y<g.ymx)
  1742. y=g.ymx;y-=a*g.x+addy
  1743. if(y>h)
  1744. h=y}else{y=3*(g.notes[0].pit-18)-6
  1745. if(y>g.ymn)
  1746. y=g.ymn;y-=a*g.x+addy
  1747. if(y<h)
  1748. h=y}}
  1749. break}}
  1750. y1+=.45*h;y2+=.45*h;h*=.65}
  1751. if(nn>3)
  1752. height=(.08*(x2-x1)+12)*dir
  1753. else
  1754. height=(.03*(x2-x1)+8)*dir
  1755. if(dir>0){if(height<3*h)
  1756. height=3*h
  1757. if(height>40)
  1758. height=40}else{if(height>3*h)
  1759. height=3*h
  1760. if(height<-40)
  1761. height=-40}
  1762. y=y2-y1
  1763. if(y<0)
  1764. y=-y
  1765. if(dir>0){if(height<.8*y)
  1766. height=.8*y}else{if(height>-.8*y)
  1767. height=-.8*y}
  1768. 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
  1769. if(height>0)
  1770. addy+=4*Math.sqrt(height)-2
  1771. else
  1772. addy-=4*Math.sqrt(-height)-2
  1773. for(i=0;i<i2;i++){k=path[i]
  1774. if(k.st!=k1.st||k.type==C.BAR)
  1775. continue
  1776. y=a*k.x+addy
  1777. if(k.ymx<y)
  1778. k.ymx=y
  1779. else if(k.ymn>y)
  1780. k.ymn=y
  1781. if(recurr)
  1782. continue
  1783. if(i==i2-1){dx=x2
  1784. if(sl.nte)
  1785. dx-=5}else{dx=k.x+k.wr}
  1786. if(i!=0)
  1787. x1=k.x
  1788. if(!i||i==i2)
  1789. y-=height/3
  1790. dx-=x1-k.wl
  1791. y_set(k1.st,dir>0,x1-k.wl,dx,y)}}
  1792. function draw_slurs(s,last){var gr1,i,m,note,sls,nsls
  1793. function draw_sls(s,sl){var k,v,i,dir,s3,path=[],s2=sl.se
  1794. if(last&&s2.time>last.time)
  1795. return
  1796. switch(sl.loc){case'i':s=prev_scut(s)
  1797. break
  1798. case'o':for(s3=s;s3.ts_next;s3=s3.ts_next);s2=s3
  1799. for(;s3;s3=s3.ts_prev){if(s3.v==s.v){s2=s3
  1800. break}
  1801. if(s3.st==s.st)
  1802. s2=s3
  1803. if(s3.ts_prev.time!=s2.time)
  1804. break}
  1805. break}
  1806. 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
  1807. break}}}else{for(s3=tsnext;s3.time==s2.time;s3=s3.ts_next){if(s3==s2){s3=null
  1808. break}}}}else{s3=null}
  1809. if(!s3){s.p_v.sls.push(sl);s2=s.p_v.s_next.prev
  1810. while(s2.next)
  1811. s2=s2.next;sl=Object.create(sl)}}
  1812. switch(sl.ty&0x07){case C.SL_ABOVE:dir=1;break
  1813. case C.SL_BELOW:dir=-1;break
  1814. default:dir=s.v!=s2.v?1:slur_direction(s,s2)
  1815. sl.ty&=~0x07
  1816. sl.ty|=dir>0?C.SL_ABOVE:C.SL_BELOW
  1817. break}
  1818. 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)
  1819. v=s.v
  1820. else
  1821. v=s2.v
  1822. 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)
  1823. s=s.next
  1824. else
  1825. s=s.ts_next}
  1826. if(!s2.grace){while(s){if(s.v==v)
  1827. path.push(s)
  1828. if(s==s2)
  1829. break
  1830. s=s.ts_next}}else if(s.grace){while(1){path.push(s)
  1831. if(s==s2)
  1832. break
  1833. s=s.next}}else{k=s2
  1834. while(k.prev)
  1835. k=k.prev
  1836. while(1){if(s.v==v)
  1837. path.push(s)
  1838. if(s.extra==k)
  1839. break
  1840. s=s.ts_next}
  1841. s=k
  1842. while(1){path.push(s)
  1843. if(s==s2)
  1844. break
  1845. s=s.next}}
  1846. for(i=1;i<path.length-1;i++){s=path[i]
  1847. if(s.sls)
  1848. draw_slurs(s,last)
  1849. if(s.tp)
  1850. draw_tuplet(s)}
  1851. draw_slur(path,sl)
  1852. return 1}
  1853. while(1){if(!s||s==last){if(!gr1||!(s=gr1.next)||s==last)
  1854. break
  1855. gr1=null}
  1856. if(s.type==C.GRACE){gr1=s;s=s.extra
  1857. continue}
  1858. if(s.sls){sls=s.sls
  1859. s.sls=null
  1860. nsls=[]
  1861. for(i=0;i<sls.length;i++){if(!draw_sls(s,sls[i]))
  1862. nsls.push(sls[i])}
  1863. if(nsls.length)
  1864. s.sls=nsls}
  1865. s=s.next}}
  1866. 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()
  1867. if(!s1.tp.length)
  1868. delete s1.tp
  1869. upstaff=s1.st
  1870. set_dscale(s1.st)
  1871. for(s2=s1;s2;s2=s2.next){switch(s2.type){case C.GRACE:if(!s2.sl1)
  1872. continue
  1873. for(g=s2.extra;g;g=g.next){if(g.sls)
  1874. draw_slurs(g)}
  1875. default:continue
  1876. case C.NOTE:case C.REST:break}
  1877. if(s2.sls)
  1878. draw_slurs(s2)
  1879. if(s2.st<upstaff)
  1880. upstaff=s2.st
  1881. if(s2.tp)
  1882. draw_tuplet(s2)
  1883. if(s2.tpe)
  1884. break}
  1885. if(s2)
  1886. s2.tpe--
  1887. if(tp.f[0]==1)
  1888. return
  1889. if(!s2){error(1,s1,"No end of tuplet in this music line")
  1890. return}
  1891. dir=tp.f[3]
  1892. if(!dir){s3=s1
  1893. while(s3&&!s3.stem)
  1894. s3=s3.next
  1895. dir=(s3&&s3.stem<0)?C.SL_BELOW:C.SL_ABOVE}
  1896. 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
  1897. for(s3=s1;;s3=s3.next){if(s3.type!=C.NOTE&&s3.type!=C.REST){if(s3.type==C.GRACE||s3.type==C.SPACE)
  1898. continue
  1899. nb_only=false
  1900. break}
  1901. if(s3==s2)
  1902. break
  1903. if(s3.beam_end){nb_only=false
  1904. break}}
  1905. 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)
  1906. nb_only=false
  1907. break}}}
  1908. 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)
  1909. nb_only=false
  1910. break}}}}}
  1911. if(nb_only){if(tp.f[2]==1)
  1912. return
  1913. set_font("tuplet")
  1914. xm=(s2.x+s1.x)/2
  1915. if(dir==C.SL_ABOVE)
  1916. ym=y_get(upstaff,1,xm-4,8)
  1917. else
  1918. ym=y_get(upstaff,0,xm-4,8)-
  1919. gene.curfont.size
  1920. if(s1.stem*s2.stem>0){if(s1.stem>0)
  1921. xm+=1.5
  1922. else
  1923. xm-=1.5}
  1924. if(tp.f[2]==0)
  1925. xy_str(xm,ym,tp.p.toString(),'c')
  1926. else
  1927. xy_str(xm,ym,tp.p+':'+tp.q,'c')
  1928. for(s3=s1;;s3=s3.next){if(s3.x>=xm)
  1929. break}
  1930. if(dir==C.SL_ABOVE){ym+=gene.curfont.size
  1931. if(s3.ymx<ym)
  1932. s3.ymx=ym;y_set(upstaff,true,xm-3,6,ym)}else{if(s3.ymn>ym)
  1933. s3.ymn=ym;y_set(upstaff,false,xm-3,6,ym)}
  1934. return}
  1935. x1=s1.x-4
  1936. if(s2.dur>s2.prev.dur){s3=s2.next
  1937. 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)
  1938. break}}
  1939. x2=s3?s3.x-s3.wl-5:realwidth-6}else{x2=s2.x+4
  1940. r=s2.stem>=0?0:s2.nhd
  1941. if(s2.notes[r].shhd>0)
  1942. x2+=s2.notes[r].shhd
  1943. if(s2.st==upstaff&&s2.stem>0)
  1944. x2+=3.5}
  1945. if(dir==C.SL_ABOVE){if(s1.st==s2.st){y1=y2=staff_tb[upstaff].topbar+2}else{y1=s1.ymx;y2=s2.ymx}
  1946. if(s1.st==upstaff){for(s3=s1;!s3.dur;s3=s3.next);ym=y_get(upstaff,1,s3.x-4,8)
  1947. if(ym>y1)
  1948. y1=ym
  1949. if(s1.stem>0)
  1950. x1+=3}
  1951. if(s2.st==upstaff){for(s3=s2;!s3.dur;s3=s3.prev);ym=y_get(upstaff,1,s3.x-4,8)
  1952. if(ym>y2)
  1953. y2=ym}
  1954. 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)
  1955. if(s0>0){if(a<0)
  1956. a=0
  1957. else if(a>s0)
  1958. a=s0}else{if(a>0)
  1959. a=0
  1960. else if(a<s0)
  1961. a=s0}
  1962. a=s1.fmt.beamslope*a/(s1.fmt.beamslope+Math.abs(a))
  1963. if(a*a<.1*.1)
  1964. a=0
  1965. dy=0
  1966. for(s3=s1;;s3=s3.next){if(!s3.dur||s3.st!=upstaff){if(s3==s2)
  1967. break
  1968. continue}
  1969. yy=ym+(s3.x-xm)*a;yx=y_get(upstaff,1,s3.x-4,8)+2
  1970. if(yx-yy>dy)
  1971. dy=yx-yy
  1972. if(s3==s2)
  1973. break}
  1974. ym+=dy;y1=ym+a*(x1-xm);y2=ym+a*(x2-xm);ym+=6
  1975. for(s3=s1;;s3=s3.next){if(s3.st==upstaff){yy=ym+(s3.x-xm)*a
  1976. if(s3.ymx<yy)
  1977. s3.ymx=yy
  1978. y_set(upstaff,true,s3.x-3,6,yy)}
  1979. if(s3==s2)
  1980. break}}else{if(s1.stem<0)
  1981. x1-=2
  1982. if(s1.st==upstaff){for(s3=s1;!s3.dur;s3=s3.next);y1=y_get(upstaff,0,s3.x-4,8)}else{y1=0}
  1983. if(s2.st==upstaff){for(s3=s2;!s3.dur;s3=s3.prev);y2=y_get(upstaff,0,s3.x-4,8)}else{y2=0}
  1984. 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)
  1985. if(s0>0){if(a<0)
  1986. a=0
  1987. else if(a>s0)
  1988. a=s0
  1989. if(a>.35)
  1990. a=.35}else{if(a>0)
  1991. a=0
  1992. else if(a<s0)
  1993. a=s0
  1994. if(a<-.35)
  1995. a=-.35}
  1996. if(a*a<.1*.1)
  1997. a=0
  1998. dy=0
  1999. for(s3=s1;;s3=s3.next){if(!s3.dur||s3.st!=upstaff){if(s3==s2)
  2000. break
  2001. continue}
  2002. yy=ym+(s3.x-xm)*a;yx=y_get(upstaff,0,s3.x-4,8)
  2003. if(yx-yy<dy)
  2004. dy=yx-yy
  2005. if(s3==s2)
  2006. break}
  2007. ym+=dy-8
  2008. y1=ym+a*(x1-xm);y2=ym+a*(x2-xm);ym-=2
  2009. for(s3=s1;;s3=s3.next){if(s3.st==upstaff){yy=ym+(s3.x-xm)*a
  2010. if(s3.ymn>yy)
  2011. s3.ymn=yy;y_set(upstaff,false,s3.x-3,6,yy)}
  2012. if(s3==s2)
  2013. break}}
  2014. if(tp.f[2]==1){out_tubr(x1,y1+4,x2-x1,y2-y1,dir==C.SL_ABOVE);return}
  2015. 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)
  2016. y_set(upstaff,true,xm-3,6,yy+2)
  2017. else
  2018. y_set(upstaff,false,xm-3,6,yy)}
  2019. 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
  2020. for(m=0;m<s1.nhd;m++)
  2021. if(s1.notes[m]==not1)
  2022. break
  2023. if(dir>0){if(m<s1.nhd&&p+1==s1.notes[m+1].pit)
  2024. if(s1.notes[m+1].shhd>sh)
  2025. sh=s1.notes[m+1].shhd}else{if(m>0&&p==s1.notes[m-1].pit+1)
  2026. if(s1.notes[m-1].shhd>sh)
  2027. sh=s1.notes[m-1].shhd}
  2028. x1=s1.x+sh
  2029. if(job!=2){for(m=0;m<s2.nhd;m++)
  2030. if(s2.notes[m]==not2)
  2031. break
  2032. sh=s2.notes[m].shhd
  2033. if(dir>0){if(m<s2.nhd&&p+1==s2.notes[m+1].pit)
  2034. if(s2.notes[m+1].shhd<sh)
  2035. sh=s2.notes[m+1].shhd}else{if(m>0&&p==s2.notes[m-1].pit+1)
  2036. if(s2.notes[m-1].shhd<sh)
  2037. sh=s2.notes[m-1].shhd}
  2038. x2+=sh}
  2039. switch(job){default:if(p<not2.pit||dir<0)
  2040. p=not1.pit
  2041. break
  2042. case 3:dir=-dir
  2043. case 1:x1=s2.prev?(s2.prev.x+s2.wr):s1.x
  2044. if(s1.st!=s2.st)
  2045. st=s2.st
  2046. x1+=(x2-x1)*.4
  2047. if(x1>x2-20)
  2048. x1=x2-20
  2049. break
  2050. case 2:x2=s1.next?s1.next.x:realwidth
  2051. if(x2!=realwidth)
  2052. x2-=(x2-x1)*.4
  2053. if(x2<x1+16)
  2054. x2=x1+16
  2055. break}
  2056. if(x2-x1>20){x1+=3.5
  2057. x2-=3.5}else{x1+=1.5
  2058. x2-=1.5}
  2059. if(s1.dots&&!(not1.pit&1)&&((dir>0&&!s1.dot_low)||(dir<0&&s1.dot_low)))
  2060. x1+=5
  2061. y=staff_tb[st].y+3*(p-18)+dir
  2062. h=(.03*(x2-x1)+16)*dir*s1.fmt.tieheight
  2063. slur_out(x1,y,x2,y,dir,h,not1.tie_ty&C.SL_DOTTED)}
  2064. function draw_all_ties(p_voice){var s,s1,s2,clef_chg,x,dx,m,not1,not2,tim2=0
  2065. s1=p_voice.sym
  2066. set_color(s1.color)
  2067. for(;s1;s1=s1.next){if(s1.ti2&&s1.time!=tim2){for(m=0;m<=s1.nhd;m++){not2=s1.notes[m]
  2068. not1=not2.tie_s
  2069. if(!not1||not1.s.v!=s1.v)
  2070. continue
  2071. draw_tie(not1,not2,1)}}
  2072. if(!s1.ti1)
  2073. continue
  2074. if(s1.type==C.GRACE){for(s=s1.extra;s;s=s.next){for(m=0;m<=s1.nhd;m++){not1=s.notes[m]
  2075. not2=not1.tie_e
  2076. if(!not2)
  2077. continue
  2078. draw_tie(not1,not2)
  2079. tim2=not2.s.time}}
  2080. continue}
  2081. for(m=0;m<=s1.nhd;m++){not1=s1.notes[m]
  2082. not2=not1.tie_e
  2083. if(!not2){if(not1.tie_ty)
  2084. draw_tie(not1,not1,2)
  2085. continue}
  2086. s2=not2.s
  2087. if(tsnext&&s2.time>=tsnext.time){draw_tie(not1,not2,2)
  2088. continue}
  2089. tim2=s2.time
  2090. for(s=s1.ts_next;s!=s2;s=s.ts_next){if(s.st!=s1.st)
  2091. continue
  2092. if(s.type==C.CLEF){clef_chg=true
  2093. break}}
  2094. if(clef_chg||s1.st!=s2.st){draw_tie(not1,not2,2)
  2095. draw_tie(not1,not2,3)
  2096. clef_chg=false}else{draw_tie(not1,not2)}}}}
  2097. 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]
  2098. k*=a
  2099. if(s1.stem>0){while(i<=j){y=k*i+b
  2100. if(p_st.top[i]<y)
  2101. p_st.top[i]=y
  2102. i++}}else{while(i<=j){y=k*i+b
  2103. if(p_st.bot[i]>y)
  2104. p_st.bot[i]=y
  2105. i++}}}
  2106. output=""
  2107. YSTEP=Math.ceil(realwidth/2)
  2108. for(st=0;st<=nstaff;st++){p_st=staff_tb[st]
  2109. p_st.top=new Float32Array(YSTEP)
  2110. p_st.bot=new Float32Array(YSTEP)
  2111. for(i=0;i<YSTEP;i++){p_st.top[i]=0
  2112. p_st.bot[i]=24}}
  2113. for(v=0;v<voice_tb.length;v++){var bm={},first_note=true;p_voice=voice_tb[v]
  2114. 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)
  2115. if(bm.s2)
  2116. set_yab(g,bm.s2)}}
  2117. if(!s.p_v.ckey.k_bagpipe&&s.fmt.graceslurs&&!s.gr_shift&&!s.sl1&&!s.ti1&&s.next&&s.next.type==C.NOTE)
  2118. grace_slur(s)
  2119. break}}
  2120. 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)
  2121. if(bm.s2)
  2122. set_yab(s,bm.s2)}
  2123. break}}}
  2124. set_tie_room();draw_deco_near()
  2125. for(s=tsfirst;s;s=s.ts_next){if(s.invis)
  2126. continue
  2127. 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)}
  2128. continue
  2129. case C.MREST:y_set(s.st,true,s.x+16,32,s.ymx+2)
  2130. continue
  2131. 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)
  2132. continue
  2133. case C.NOTE:break}
  2134. 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}
  2135. y_set(s.st,true,s.x+dx,w,s.ymx);ymn=s.ymn
  2136. if(s.notes[0].acc&&ymn>3*(s.notes[0].pit-18)-9)
  2137. ymn=3*(s.notes[0].pit-18)-9
  2138. 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}
  2139. dx+=s.notes[0].shhd;y_set(s.st,false,s.x+dx,w,s.ymn)}
  2140. if(s.notes[s.nhd].acc){y=3*(s.notes[s.nhd].pit-18)
  2141. +(s.notes[s.nhd].acc==-1?11:10)
  2142. y_set(s.st,true,s.x-10,10,y)}
  2143. if(s.notes[0].acc){y=3*(s.notes[0].pit-18)
  2144. -(s.notes[0].acc==-1?5:10)
  2145. y_set(s.st,false,s.x-10,10,y)}}
  2146. draw_deco_note()
  2147. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v];s=p_voice.sym
  2148. if(!s)
  2149. continue
  2150. set_color(s.color);st=p_voice.st;for(;s;s=s.next){if(s.play)
  2151. continue
  2152. if(s.tp)
  2153. draw_tuplet(s)
  2154. if(s.sls||s.sl1)
  2155. draw_slurs(s)}}
  2156. set_color()
  2157. for(st=0;st<=nstaff;st++){p_st=staff_tb[st];top=p_st.topbar+2;bot=p_st.botbar-2
  2158. for(i=0;i<YSTEP;i++){if(top>p_st.top[i])
  2159. p_st.top[i]=top
  2160. if(bot<p_st.bot[i])
  2161. p_st.bot[i]=bot}}
  2162. if(cfmt.measurenb>=0)
  2163. draw_measnb();set_dscale(-1)
  2164. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v]
  2165. if(p_voice.have_ly){draw_all_lyrics()
  2166. break}}
  2167. draw_deco_staff()
  2168. draw_partempo()
  2169. set_dscale(-1);output=output_sav}
  2170. function draw_vname(indent,stl){var p_voice,n,st,v,a_p,p,y,h,h2,staff_d=[]
  2171. for(st=stl.length;st>=0;st--){if(stl[st])
  2172. break}
  2173. if(st<0)
  2174. return
  2175. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v]
  2176. if(!cur_sy.voices[v])
  2177. continue
  2178. st=cur_sy.voices[v].st
  2179. if(!stl[st])
  2180. continue
  2181. if(!gene.vnt)
  2182. continue
  2183. p=gene.vnt==2?p_voice.nm:p_voice.snm
  2184. if(!p)
  2185. continue
  2186. delete p_voice.new_name
  2187. if(!staff_d[st])
  2188. staff_d[st]=p
  2189. else
  2190. staff_d[st]+="\n"+p}
  2191. if(!staff_d.length)
  2192. return
  2193. set_font("voice");h=gene.curfont.size
  2194. h2=h/2
  2195. indent=-indent*.5
  2196. for(st=0;st<staff_d.length;st++){if(!staff_d[st])
  2197. continue
  2198. a_p=staff_d[st].split("\n");y=staff_tb[st].y
  2199. +staff_tb[st].topbar*.5*staff_tb[st].staffscale
  2200. +h2*(a_p.length-2)
  2201. 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])
  2202. y-=(staff_tb[st].y-staff_tb[st+1].y)*.5
  2203. for(n=0;n<a_p.length;n++){p=a_p[n];xy_str(indent,y,p,"c");y-=h}}}
  2204. 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
  2205. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v]
  2206. if(p_voice.scale!=1)
  2207. p_voice.scale_str='transform="scale('+p_voice.scale.toFixed(2)+')"'}
  2208. for(st=0;st<=nstaff;st++){if(gene.st_print[st])
  2209. break}
  2210. y=0
  2211. if(st>nstaff){st--;p_staff=staff_tb[st]}
  2212. p_staff=staff_tb[st]
  2213. for(i=0;i<YSTEP;i++){val=p_staff.top[i]
  2214. if(y<val)
  2215. y=val}
  2216. y*=p_staff.staffscale;staffsep=fmt.staffsep*.5+
  2217. p_staff.topbar*p_staff.staffscale
  2218. if(y<staffsep)
  2219. y=staffsep
  2220. if(y<p_staff.ann_top)
  2221. y=p_staff.ann_top;p_staff.y=-y;for(prev_staff=0;prev_staff<st;prev_staff++)
  2222. staff_tb[prev_staff].y=-y
  2223. if(!gene.st_print[st])
  2224. return y
  2225. var sy_staff_prev=sy.staves[prev_staff]
  2226. for(st++;st<=nstaff;st++){if(!gene.st_print[st])
  2227. continue
  2228. p_staff=staff_tb[st]
  2229. staffsep=sy_staff_prev.sep||cfmt.sysstaffsep;maxsep=sy_staff_prev.maxsep||cfmt.maxsysstaffsep;dy=0
  2230. if(p_staff.staffscale==staff_tb[prev_staff].staffscale){for(i=0;i<YSTEP;i++){val=p_staff.top[i]-
  2231. staff_tb[prev_staff].bot[i]
  2232. if(dy<val)
  2233. dy=val}
  2234. dy*=p_staff.staffscale}else{for(i=0;i<YSTEP;i++){val=p_staff.top[i]*p_staff.staffscale
  2235. -staff_tb[prev_staff].bot[i]*staff_tb[prev_staff].staffscale
  2236. if(dy<val)
  2237. dy=val}}
  2238. staffsep+=p_staff.topbar*p_staff.staffscale
  2239. if(dy<staffsep)
  2240. dy=staffsep;maxsep+=p_staff.topbar*p_staff.staffscale
  2241. if(dy>maxsep)
  2242. dy=maxsep;y+=dy;p_staff.y=-y;while(!gene.st_print[++prev_staff])
  2243. staff_tb[prev_staff].y=-y
  2244. while(1){sy_staff_prev=sy.staves[prev_staff]
  2245. if(sy_staff_prev)
  2246. break
  2247. sy=sy.next}}
  2248. mbot=0
  2249. for(i=0;i<YSTEP;i++){val=staff_tb[prev_staff].bot[i]
  2250. if(mbot>val)
  2251. mbot=val}
  2252. if(mbot>p_staff.ann_bot)
  2253. mbot=p_staff.ann_bot;mbot*=staff_tb[prev_staff].staffscale
  2254. for(st=0;st<=nstaff;st++){p_staff=staff_tb[st];dy=p_staff.y
  2255. if(p_staff.staffscale!=1){p_staff.scale_str='transform="translate(0,'+
  2256. (posy-dy).toFixed(1)+') '+'scale('+p_staff.staffscale.toFixed(2)+')"'}}
  2257. if(mbot==0){for(st=nstaff;st>=0;st--){if(gene.st_print[st])
  2258. break}
  2259. if(st<0)
  2260. return y}
  2261. dy=-mbot;staffsep=fmt.staffsep*.5
  2262. if(dy<staffsep)
  2263. dy=staffsep;maxsep=fmt.maxstaffsep*.5
  2264. if(dy>maxsep)
  2265. dy=maxsep;return y+dy}
  2266. function draw_systems(indent){var s,s2,st,x,x2,res,sy,xstaff=[],stl=[],bar_bot=[],bar_height=[],ba=[],sb="",thb=""
  2267. function bar_set(){var st,staffscale,top,bot,dy=0
  2268. for(st=0;st<=cur_sy.nstaff;st++){if(xstaff[st]<0){bar_bot[st]=bar_height[st]=0
  2269. continue}
  2270. staffscale=staff_tb[st].staffscale;top=staff_tb[st].topbar*staffscale;bot=staff_tb[st].botbar*staffscale
  2271. if(dy==0)
  2272. 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]}}
  2273. 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
  2274. if(!/[\[|]/.test(stafflines))
  2275. return
  2276. w=x2-x1;set_sscale(-1)
  2277. 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)
  2278. return}
  2279. for(i=0;i<l;i++,y-=il){if(stafflines[i]=='.')
  2280. continue
  2281. dy=0
  2282. for(;i<l;i++,y-=il,dy-=il){switch(stafflines[i]){case'.':case'-':continue
  2283. case ty:ln+='m-'+w.toFixed(1)+' '+dy+'h'+w.toFixed(1);dy=0
  2284. continue}
  2285. if(ty!=undefined)
  2286. ln+='"/>\n';ty=stafflines[i]
  2287. ln+='<path class="'+
  2288. (ty=='['?'slthW':'slW')+'" d="m0 '+y+'h'+w.toFixed(1);dy=0}
  2289. ln+='"/>'}
  2290. y=staff_tb[st].y
  2291. if(!cache&&w>get_lwidth()-10&&staff_tb[st].staffscale==1){cache={st_l:stafflines,st_w:w|0}
  2292. i='stdef'+cfmt.fullsvg;if(ln.indexOf('<path',1)<0)
  2293. glyphs[i]=ln.replace('path','path id="'+i+'"')
  2294. else
  2295. glyphs[i]='<g id="'+i+'">\n'+ln+'\n</g>';xygl(x1,y,i)
  2296. return}
  2297. out_XYAB('<g transform="translate(X, Y)">\n'+ln+'\n</g>\n',x1,y)}
  2298. 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
  2299. if(st!=0&&s.ts_prev&&s.ts_prev.type!=C.BAR)
  2300. h=p_staff.topbar*p_staff.staffscale;s.ymx=s.ymn+h;set_sscale(-1)
  2301. anno_start(s)
  2302. if(s.color)
  2303. set_color(s.color);yb=p_staff.y+12;if(p_staff.stafflines!='|||||')
  2304. yb+=(p_staff.topbar+p_staff.botbar)/2-12
  2305. if(s.bar_mrep){set_sscale(st)
  2306. 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")
  2307. if(s.v==cur_sy.top_voice)
  2308. nrep_out(x,yb+p_staff.topbar,s.bar_mrep)}
  2309. set_sscale(-1)}
  2310. if(bar_type=='||:')
  2311. bar_type='[|:'
  2312. 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)
  2313. +' '+self.sy(bot).toFixed(1)
  2314. +'v-'+h.toFixed(1)}
  2315. break
  2316. default:x-=3;if(s.color)
  2317. out_XYAB('<path class="bthW" d="MX Yv-F"/>\n',x+1.5,bot,h)
  2318. else
  2319. thb+='M'+sx(x+1.5).toFixed(1)
  2320. +' '+self.sy(bot).toFixed(1)
  2321. +'v-'+h.toFixed(1)
  2322. break
  2323. case":":x-=2;set_sscale(st);xygl(x+1,yb-12,"rdots")
  2324. set_sscale(-1)
  2325. break}
  2326. x-=3}
  2327. set_color();anno_stop(s)}
  2328. function out_bars(){var i,b,bx,l=ba.length
  2329. set_font("annotation");bx=gene.curfont.box
  2330. if(bx)
  2331. gene.curfont.box=0
  2332. for(i=0;i<l;i++){b=ba[i];draw_bar(b[0],b[1],b[2])}
  2333. if(bx)
  2334. gene.curfont.box=bx
  2335. set_sscale(-1)
  2336. if(sb)
  2337. output+='<path class="bW" d="'
  2338. +sb
  2339. +'"/>\n'
  2340. if(thb)
  2341. output+='<path class="bthW" d="'
  2342. +thb
  2343. +'"/>\n'}
  2344. function hl_rest(s){var j,p_st=staff_tb[s.st],i=5-s.nflags,x=s.x,y=s.y
  2345. if(i<6)
  2346. return
  2347. if(i==7&&y==12&&p_st.stafflines.length<=2)
  2348. y-=6
  2349. j=y/6
  2350. switch(i){default:switch(p_st.stafflines[j+1]){case'|':case'[':break
  2351. default:set_hl(p_st,j+1,x,-7,7)
  2352. break}
  2353. if(i==9){y-=6
  2354. j--}
  2355. break
  2356. case 7:y+=6
  2357. j++
  2358. case 6:break}
  2359. switch(p_st.stafflines[j]){case'|':case'[':break
  2360. default:set_hl(p_st,j,x,-7,7)
  2361. break}}
  2362. function st1(st,s){var tim=s.time
  2363. do{s=s.ts_next}while(s.st!=st)
  2364. while(s.prev&&s.prev.time>=tim)
  2365. s=s.prev
  2366. if(s.bar_type)
  2367. return s.x
  2368. return s.x-s.wl}
  2369. for(st=0;st<=nstaff;st++){stl[st]=cur_sy.st_print[st]
  2370. xstaff[st]=!stl[st]?-1:0}
  2371. bar_set();draw_lstaff(0)
  2372. for(s=tsfirst;s;s=s.ts_next){switch(s.type){case C.STAVES:sy=s.sy
  2373. for(st=0;st<=nstaff;st++){x=xstaff[st]
  2374. if(x<0){if(sy.st_print[st]){xstaff[st]=st1(st,s)
  2375. stl[st]=true}
  2376. continue}
  2377. if(sy.st_print[st]&&cur_sy.staves[st]&&sy.staves[st].stafflines==cur_sy.staves[st].stafflines)
  2378. continue
  2379. if(s.ts_prev.bar_type){x2=s.ts_prev.x}else{x2=(s.ts_prev.x+s.x)/2
  2380. xstaff[st]=-1}
  2381. draw_staff(st,x,x2)
  2382. xstaff[st]=sy.st_print[st]?x2:-1}
  2383. cur_sy=sy;bar_set()
  2384. continue
  2385. case C.BAR:if(s.invis||!s.bar_type||!cur_sy.st_print[s.st])
  2386. break
  2387. if(s.second&&(!s.ts_prev||(s.ts_prev.type==C.BAR&&s.ts_prev.st==s.st)))
  2388. break
  2389. ba.push([s,bar_bot[s.st],bar_height[s.st]])
  2390. break
  2391. case C.STBRK:if(cur_sy.voices[s.v]&&cur_sy.voices[s.v].range==0){if(s.xmx>14){var nv=0
  2392. for(var i=0;i<voice_tb.length;i++){if(cur_sy.voices[i]&&cur_sy.voices[i].range>0)
  2393. nv++}
  2394. for(s2=s.ts_next;s2;s2=s2.ts_next){if(s2.type!=C.STBRK)
  2395. break
  2396. nv--}
  2397. if(nv==0)
  2398. draw_lstaff(s.x)}}
  2399. st=s.st;x=xstaff[st]
  2400. if(x>=0){s2=s.prev
  2401. if(!s2)
  2402. break
  2403. x2=s2.type==C.BAR?s2.x:s.x-s.xmx
  2404. if(x>=x2)
  2405. break
  2406. draw_staff(st,x,x2)
  2407. xstaff[st]=s.x}
  2408. break
  2409. case C.GRACE:for(s2=s.extra;s2;s2=s2.next)
  2410. self.draw_hl(s2)
  2411. break
  2412. case C.NOTE:if(!s.invis)
  2413. self.draw_hl(s)
  2414. break
  2415. case C.REST:if(s.fmr||(s.rep_nb&&s.rep_nb>=0))
  2416. center_rest(s)
  2417. if(!s.invis)
  2418. hl_rest(s)
  2419. break}}
  2420. for(st=0;st<=nstaff;st++){x=xstaff[st]
  2421. if(x<0||x>=realwidth)
  2422. continue
  2423. draw_staff(st,x,realwidth)}
  2424. draw_all_hl()
  2425. out_bars()
  2426. draw_vname(indent,stl)}
  2427. 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)
  2428. staff_tb[s.st].clef=s
  2429. continue
  2430. case C.KEY:p_voice.ckey=s
  2431. default:continue
  2432. case C.NOTE:break}}
  2433. st=s.st
  2434. x=s.x;set_color(s.color)
  2435. switch(s.type){case C.NOTE:set_scale(s)
  2436. if(s.beam_st&&!s.beam_end){if(self.calculate_beam(bm,s))
  2437. draw_beams(bm)}
  2438. if(!s.invis){anno_start(s);draw_note(s,!bm.s2);anno_a.push(s)}
  2439. if(s==bm.s2)
  2440. bm.s2=null
  2441. break
  2442. case C.REST:if(!gene.st_print[st])
  2443. break
  2444. draw_rest(s);break
  2445. case C.BAR:break
  2446. case C.CLEF:if(s.time>=staff_tb[st].clef.time)
  2447. staff_tb[st].clef=s
  2448. if(s.second||!staff_tb[st].topbar||!gene.st_print[st])
  2449. break
  2450. set_color();set_sscale(st);anno_start(s);y=staff_tb[st].y
  2451. if(s.clef_name)
  2452. xygl(x,y+s.y,s.clef_name)
  2453. else if(!s.clef_small)
  2454. xygl(x,y+s.y,s.clef_type+"clef")
  2455. else
  2456. xygl(x,y+s.y,"s"+s.clef_type+"clef")
  2457. if(s.clef_octave){if(s.clef_octave>0){y+=s.ymx-10
  2458. if(s.clef_small)
  2459. y-=1}else{y+=s.ymn+6
  2460. if(s.clef_small)
  2461. y+=1}
  2462. xygl(x-2,y,(s.clef_octave==7||s.clef_octave==-7)?"oct":"oct2")}
  2463. anno_a.push(s)
  2464. break
  2465. case C.METER:p_voice.meter=s
  2466. if(s.second||!staff_tb[s.st].topbar)
  2467. break
  2468. set_color();set_sscale(s.st);anno_start(s);draw_meter(s);anno_a.push(s)
  2469. break
  2470. case C.KEY:p_voice.ckey=s
  2471. if(s.second||!staff_tb[s.st].topbar)
  2472. break
  2473. set_color();set_sscale(s.st);anno_start(s);self.draw_keysig(x,s);anno_a.push(s)
  2474. break
  2475. case C.MREST:draw_mrest(s)
  2476. break
  2477. case C.GRACE:set_scale(s);draw_gracenotes(s)
  2478. break
  2479. case C.SPACE:case C.STBRK:break
  2480. case C.CUSTOS:set_scale(s);draw_note(s,0)
  2481. break
  2482. case C.BLOCK:case C.REMARK:case C.STAVES:case C.TEMPO:break
  2483. default:error(2,s,"draw_symbols - Cannot draw symbol "+s.type)
  2484. break}}
  2485. set_scale(p_voice.sym)}
  2486. function draw_all_sym(){var p_voice,v,n=voice_tb.length
  2487. function draw_sl2(){var i,a,d,dy,dy2,dy2o,dz,n,sl
  2488. while(1){sl=gene.a_sl.shift()
  2489. if(!sl)
  2490. break
  2491. i=sl[3].indexOf('d="M')+4
  2492. output+=sl[3].slice(0,i)
  2493. a=new Float32Array(sl[3].slice(i).match(/[\d.-]+/g))
  2494. a[1]-=staff_tb[sl[0].st].y
  2495. dy2o=sl[0].fmt.sysstaffsep+24
  2496. dy2=staff_tb[sl[1].st].y-staff_tb[sl[0].st].y
  2497. switch(sl[2]){case"//":case"\\\\":d=-(sl[1].prev.prev.y+staff_tb[sl[0].st].y
  2498. +sl[1].prev.next.y+staff_tb[sl[1].st].y)
  2499. -2*(a[1]-posy)
  2500. a[5]=d-a[5]
  2501. a[7]=d-a[7]
  2502. if(a.length>8){d=sl[2][0]=='/'?3:-3
  2503. a[8]=-a[8]
  2504. a[10]=-a[3]+d
  2505. a[12]=-a[5]+d
  2506. a[14]=-a[7]}
  2507. break
  2508. case"/\\":case"\\/":d=sl[2][0]=='/'?dy2-dy2o-10:dy2+dy2o+10
  2509. a[3]+=d
  2510. a[5]+=d
  2511. if(a.length>8){a[10]+=d
  2512. a[12]+=d}
  2513. break
  2514. default:d=sl[2][0]=='/'?dy2-dy2o:-dy2-dy2o
  2515. a[5]+=d
  2516. a[7]+=d
  2517. if(a.length>8){a[12]-=d
  2518. a[14]-=d}
  2519. break}
  2520. output+=a[0].toFixed(1)+' '+a[1].toFixed(1)
  2521. +'c'+a[2].toFixed(1)+' '+a[3].toFixed(1)
  2522. +' '+a[4].toFixed(1)+' '+a[5].toFixed(1)
  2523. +' '+a[6].toFixed(1)+' '+a[7].toFixed(1)
  2524. if(a.length>8)
  2525. output+='v'+a[8].toFixed(1)
  2526. +'c'+a[9].toFixed(1)
  2527. +' '+a[10].toFixed(1)
  2528. +' '+a[11].toFixed(1)
  2529. +' '+a[12].toFixed(1)
  2530. +' '+a[13].toFixed(1)
  2531. +' '+a[14].toFixed(1)
  2532. output+='"/>\n'}}
  2533. for(v=0;v<n;v++){p_voice=voice_tb[v]
  2534. if(p_voice.sym&&p_voice.sym.x!=undefined){self.draw_symbols(p_voice)
  2535. draw_all_ties(p_voice);set_color()}}
  2536. self.draw_all_deco()
  2537. glout()
  2538. anno_put()
  2539. set_sscale(-1)
  2540. if(gene.a_sl)
  2541. draw_sl2()}
  2542. function set_tie_dir(s){var i,ntie,dir,sec,pit,ty,s2
  2543. for(;s;s=s.next){if(!s.ti1)
  2544. continue
  2545. sec=ntie=0;pit=128
  2546. for(i=0;i<=s.nhd;i++){if(s.notes[i].tie_ty){ntie++
  2547. if(pit<128&&s.notes[i].pit<=pit+1)
  2548. sec++;pit=s.notes[i].pit
  2549. s2=s.notes[i].tie_e}}
  2550. if(s2&&s.stem*s2.stem<0)
  2551. dir=pit>=22?C.SL_ABOVE:C.SL_BELOW
  2552. else if(s.multi)
  2553. dir=s.multi>0?C.SL_ABOVE:C.SL_BELOW
  2554. else
  2555. dir=s.stem<0?C.SL_ABOVE:C.SL_BELOW
  2556. if(s.multi){for(i=0;i<=s.nhd;i++){ty=s.notes[i].tie_ty
  2557. if(!((ty&0x07)==C.SL_AUTO))
  2558. continue
  2559. s.notes[i].tie_ty=(ty&C.SL_DOTTED)|dir}
  2560. continue}
  2561. if(ntie<=1){for(i=0;i<=s.nhd;i++){ty=s.notes[i].tie_ty
  2562. if(ty){if((ty&0x07)==C.SL_AUTO)
  2563. s.notes[i].tie_ty=(ty&C.SL_DOTTED)|dir
  2564. break}}
  2565. continue}
  2566. if(!sec){if(ntie&1){ntie=(ntie-1)/2;dir=C.SL_BELOW
  2567. for(i=0;i<=s.nhd;i++){ty=s.notes[i].tie_ty
  2568. if(!ty)
  2569. continue
  2570. if(ntie==0){if(s.notes[i].pit>=22)
  2571. dir=C.SL_ABOVE}
  2572. if((ty&0x07)==C.SL_AUTO)
  2573. s.notes[i].tie_ty=(ty&C.SL_DOTTED)|dir
  2574. if(ntie--==0)
  2575. dir=C.SL_ABOVE}
  2576. continue}
  2577. ntie/=2;dir=C.SL_BELOW
  2578. for(i=0;i<=s.nhd;i++){ty=s.notes[i].tie_ty
  2579. if(!ty)
  2580. continue
  2581. if((ty&0x07)==C.SL_AUTO)
  2582. s.notes[i].tie_ty=(ty&C.SL_DOTTED)|dir
  2583. if(--ntie==0)
  2584. dir=C.SL_ABOVE}
  2585. continue}
  2586. pit=128
  2587. for(i=0;i<=s.nhd;i++){if(s.notes[i].tie_ty){if(pit<128&&s.notes[i].pit<=pit+1){ntie=i
  2588. break}
  2589. pit=s.notes[i].pit}}
  2590. dir=C.SL_BELOW
  2591. for(i=0;i<=s.nhd;i++){ty=s.notes[i].tie_ty
  2592. if(!ty)
  2593. continue
  2594. if(ntie==i)
  2595. dir=C.SL_ABOVE
  2596. if((ty&0x07)==C.SL_AUTO)
  2597. s.notes[i].tie_ty=(ty&C.SL_DOTTED)|dir}}}
  2598. function set_tie_room(){var p_voice,s,s2,v,dx,y,dy
  2599. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v];s=p_voice.sym
  2600. if(!s)
  2601. continue
  2602. s=s.next
  2603. if(!s)
  2604. continue
  2605. set_tie_dir(s)
  2606. for(;s;s=s.next){if(!s.ti1)
  2607. continue
  2608. 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
  2609. continue
  2610. s2=s.next
  2611. while(s2&&s2.type!=C.NOTE)
  2612. s2=s2.next
  2613. if(s2){if(s2.st!=s.st)
  2614. continue
  2615. dx=s2.x-s.x-10}else{dx=realwidth-s.x-10}
  2616. if(dx<100)
  2617. dy=9
  2618. else if(dx<300)
  2619. dy=12
  2620. else
  2621. dy=16
  2622. if(s.notes[s.nhd].pit>24){y=3*(s.notes[s.nhd].pit-18)+dy
  2623. if(s.ymx<y)
  2624. s.ymx=y
  2625. if(s2&&s2.ymx<y)
  2626. s2.ymx=y;y_set(s.st,true,s.x+5,dx,y)}
  2627. if(s.notes[0].pit<20){y=3*(s.notes[0].pit-18)-dy
  2628. if(s.ymn>y)
  2629. s.ymn=y
  2630. if(s2&&s2.ymn>y)
  2631. s2.ymn=y;y_set(s.st,false,s.x+5,dx,y)}}}}
  2632. var musicfont='url("data:application/octet-stream;base64,\
  2633. AAEAAAAOAIAAAwBgRkZUTZHVOuoAAFgMAAAAHEdERUYAFQAUAABX8AAAABxPUy8yWMFdCgAAAWgA\
  2634. AABWY21hcHlUuFMAAAQIAAAD5mN2dCAAIgKIAAAH8AAAAARnYXNw//8AAwAAV+gAAAAIZ2x5ZqUq\
  2635. QgUAAAkcAABF/GhlYWQVmDJzAAAA7AAAADZoaGVhCWn/GwAAASQAAAAkaG10eNm9+0EAAAHAAAAC\
  2636. SGxvY2HHqraAAAAH9AAAASZtYXhwANkBEgAAAUgAAAAgbmFtZeq7sB0AAE8YAAADFXBvc3SIfxKM\
  2637. AABSMAAABbUAAQAAAAEAANGbj/xfDzz1AAsEAAAAAADRlyIXAAAAAOBezej/OPzvBUsEiAAAAAgA\
  2638. AgAAAAAAAAABAAAEiPzvAFwEJf84/XQFSwABAAAAAAAAAAAAAAAAAAAAkgABAAAAkgDhAAUAAAAA\
  2639. AAIAAAABAAEAAABAAC4AAAAAAAEBgAGQAAUACAKZAswAAACPApkCzAAAAesAMwEJAAACAAUDAAAA\
  2640. AAAAAAAAARAAAAAAAAAAAAAAAFBmRWQAQAAA7LcDOP84AFwEiAMRAAAAAQAAAAAAAAF2ACIAAAAA\
  2641. AVUAAAGQAAACWAAAAFcAAAAjAAAAJQAAACT//wBkAAAEIwAABCUAAAHg/9wDugAAAwsAAALSAAAC\
  2642. v/+6AdYAAAMLAAADDgAAAyf/yADIAAABaAAAAa4AAAEiAAABkAAAAXwAAAGQAAABkAAAAYEAAAGQ\
  2643. AAABkAAAAYEAAAGZAAkBmAAJAfQAAAEEABQBBAAKAmsAJAISAAABwgAAAUIAAAFAAAABSv/+ASwA\
  2644. AAIwAAABSgAAAUoAAABkAAABQAAAAUAAAAFAAAABQAAAAGQAAAE2AAAA5gAAATYAAAE7AAABOwAA\
  2645. ATsAAAE7AAABOwAAATsAAAE7AAABOwAAATsAAAE7AAABDQAAAMgAAAD/AAABCwAUAW4AAACMAAAA\
  2646. jAAAAQ0AMgFu//UAqQAAAToAAAFA//0AUAAAAVQAAABkAAABGAAAAlgAAAC2AAABkAAFAIIAAACC\
  2647. AAABLAAAASwAAADuAAAA/wAAAUkAAAGPAAAB2AAAAdgAAAIz//ADIP/hAXv/tAG4/9sBFv9+ARP/\
  2648. 2wDcAAAA6P/kAr//tAIz/7QCv/+0Ayv/2wFf/9sCaf9+AV//fgJp/34BXwAAAf0ABQG1AAABtQAA\
  2649. AkQADQJEAA0BGAAAATYAAAEs//8BLAAAAPoAAADIAAABGP84APoAAADIAAAEDQAAAhwADAH0AAAB\
  2650. 9AAAAfQAAAH0AAAB9AAAAfQAAAB4AAAALQAAAhwAAAD6AAAA+v/oAcIAAAFIAAABQAAAAgoAAAIK\
  2651. AAAAZAAAAAAAAwAAAAMAAAAcAAEAAAAAAuAAAwABAAAAHAAEAsQAAABgAEAABQAgAAAAIOAA4DDg\
  2652. OeBI4FDgXOBi4GngjOCV4KTgqeCz4QHhu+Hn4gDiSeJk4mvig+Ss5MDk0eTq5QHlMeU55W3lguXQ\
  2653. 5eLmGOYk5jDmUOZV6RjpIOkl6V3qAuqk7Knst///AAAAAAAg4ADgMOA44EPgUOBc4GLgaeB64JTg\
  2654. oOCp4LPhAeG54efh8uJA4mDiauKA5KDkwOTO5OHlAOUg5TnlZuWC5dDl4uYQ5iTmMOZQ5lXpEOkg\
  2655. 6SXpXeoC6qTsouy3//8AA//kIAUf1gAAAAAfvh+zH64fqAAAAAAAAB+CH3kfLAAAHkkAAAAAAAAA\
  2656. AAAAAAAbkwAAAAAAAAAAGzcAABr0GqcalgAAGlkaThovGisAABdnF2MXLBaIFecAABPaAAEAAAAA\
  2657. AAAAAABYAFoAAAAAAAAAAABcAIAAggAAAAAAAACEAAAAhgCiALQAvAC+AMQAAADaAOAA8gD0AAAB\
  2658. FAAAAAAAAAEcAAAAAAAAAAABJAAAAAAAAAAAAAABKgAAAAAABwAIAAkAAAAKAAsADAANABIAEwAU\
  2659. ABUAFgAAABcAGAAZABoAGwAcAB0AHgAfACAAIQAiACMAJAAlACYAJwAoACkAKgAuAAAALwAxAAAA\
  2660. MgAAAAAAMwAAADQAAAAAADUAAAA2ADcAOAA5ADoAOwA8AD0APgA/AEAAQQBCAEMARABFAEYARwBI\
  2661. AEkASgBLAEwATQBOAAAATwAAAFAAAAAAAAAAUQAAAAAAAABSAFQAAAAAAFUAVgBXAFgAWQBaAFsA\
  2662. XABdAF4AXwBgAGEAYgBjAGQAZQBmAGcAAAAAAAAAaABpAGoAawBsAAAAbQBuAG8AcQByAAAAcwAA\
  2663. AAAAdAB1AHkAAAB6AAAAewAAAAAAAAB8AIEAggCDAAAAhACFAAAAAACGAIwAjQAAAI4AAACPAAAA\
  2664. kAAAAQYAAAMAAAAAAAAAAQIAAAACAAAAAAAAAAAAAAAAAAAAAQAABAAAAAAAAAAAAAAAAAAAAAAA\
  2665. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\
  2666. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AP9qAWwBsAAOABwAKwA6AAA3DgEd\
  2809. ATI3Njc2NTQnJiM3MhYVFAcGBwYjETMRNhcOAR0BMjc2NzY1NCcmIzcyFhUUBwYHDgEjETMRNk4R\
  2810. Hg4eHwwEChARGR0rCRgrNS8fGdERHRAeHQsGCxAPFh8qCxkoFjcWHht9AR4QxikrNA0ZHhQVJjkh\
  2811. EiA5NEACRv7BMiYBHRHGKS8wExMcFhUmNiQWHD4vGyUCRv7BMgAAAQAA/wYAjAD6AA4AADcVBhUU\
  2812. FxUuAzQ+AoxQUBolMhsbMiX6FEOjpkAUDx86WnBaOh8AAAEAAP8GAIwA+gAOAAA1HgMUDgIHNTY1\
  2813. NCcaJTIbGzIlGlBQ+g8fOlpwWjofDxRApqNDAAACADL/ZAENAbAACgAWAAA3IgYVFBcWFzU0Jicy\
  2814. FxEzESInJjU0NqsXIC4uGiozOiMjOlJPOXomGzBFQgPLEh4mNAFE/bRSUEUjMgAABP/1/2oBbAGw\
  2815. AA4AHQAsADsAADcjIgcGFRQXFhcWMzU0JicyFxEzESImJyYnJjU0NhcOAR0BMjc2NzY1NCcmIzcy\
  2816. FhUUBwYHDgEjETMRNlcBERAKBAwfHg4eKzAZHxY3FysYCSvpER0QHh0LBgsQDxYfKgsZKBY3Fh4b\
  2817. fRUUHhkNNCspxhAeJzIBP/26JRs0OSASITkmAR0RxikvMBMTHBYVJjYkFhw+LxslAkb+wTIAAAAA\
  2818. AQAA/sAAqQFAABMAABMzFTcVBxU3FQcVIzUHNTc1BzU3RB5HR0dHHkREREQBQKIOXA5/DloPqKIO\
  2819. XA5/DloPAAMAAP6YAToBaAAjACcAKwAANzUzFTcVBxU3FQcVIzUHFSM1DwEjNQc1NzUHNTc1MxU3\
  2820. NTMVAzUHFTcVNzXpHjMzMzMePR48AR4zMzMzHj0eHj1bPcCong9cD58PWg+1qhKspBCong9cD58P\
  2821. Wg+1qhKspP79nhGfuJ4RnwAB//0AAAE/APQAGAAANwYjIiY1ND8BNi8BJjU0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AABAAAAAAAEAAcCLAABAAAAAAAFAAgCRgABAAAAAAAGAAcCXwADAAEECQAAAQYA\
  2990. AAADAAEECQABAA4BjAADAAEECQACAA4BpAADAAEECQADAD4BvAADAAEECQAEAA4CHAADAAEECQAF\
  2991. ABACNAADAAEECQAGAA4CTwBDAG8AcAB5AHIAaQBnAGgAdAAgAFwAMgA1ADEAIAAyADAAMQA4AC0A\
  2992. MgAwADEAOQAgAEoAZQBhAG4ALQBGAHIAYQBuAGMAbwBpAHMAIABNAG8AaQBuAGUALgAgAFQAaABp\
  2993. AHMAIABmAG8AbgB0ACAAaQBzACAAbABpAGMAZQBuAHMAZQBkACAAdQBuAGQAZQByACAAdABoAGUA\
  2994. IABTAEkATAAgAE8AcABlAG4AIABGAG8AbgB0ACAATABpAGMAZQBuAHMAZQAgAFwAKABoAHQAdABw\
  2995. ADoALwAvAHMAYwByAGkAcAB0AHMALgBzAGkAbAAuAG8AcgBnAC8ATwBGAEwAXAApAC4AAENvcHly\
  2996. aWdodCBcMjUxIDIwMTgtMjAxOSBKZWFuLUZyYW5jb2lzIE1vaW5lLiBUaGlzIGZvbnQgaXMgbGlj\
  2997. ZW5zZWQgdW5kZXIgdGhlIFNJTCBPcGVuIEZvbnQgTGljZW5zZSBcKGh0dHA6Ly9zY3JpcHRzLnNp\
  2998. bC5vcmcvT0ZMXCkuAABhAGIAYwAyAHMAdgBnAABhYmMyc3ZnAABSAGUAZwB1AGwAYQByAABSZWd1\
  2999. bGFyAABGAG8AbgB0AEYAbwByAGcAZQAgADoAIABhAGIAYwAyAHMAdgBnACAAOgAgADEANAAtADQA\
  3000. LQAyADAAMgAzAABGb250Rm9yZ2UgOiBhYmMyc3ZnIDogMTQtNC0yMDIzAABhAGIAYwAyAHMAdgBn\
  3001. AABhYmMyc3ZnAABWAGUAcgBzAGkAbwBuACAAAFZlcnNpb24gAABhAGIAYwAyAHMAdgBnAABhYmMy\
  3002. c3ZnAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAA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VuaUVDQTkHdW5pRUNCNwAAAAAAAAH//wACAAEA\
  3028. AAAAAAAADAAUAAQAAAACAAAAAQAAAAEAAAAAAAEAAAAA399K6gAAAADRlyIXAAAAAOBezeg=\
  3029. ") format("truetype")'
  3030. 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={}
  3031. 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\
  3032. B "Book: "\n\
  3033. S "Source: "\n\
  3034. D "Discography: "\n\
  3035. N "Notes: "\n\
  3036. Z "Transcription: "\n\
  3037. 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"}
  3038. 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}
  3039. function get_bool(param){return!param||!/^(0|n|f)/i.test(param)}
  3040. function get_font_scale(param){var i,font,a=info_split(param)
  3041. if(a.length<=1)
  3042. return
  3043. var scale=+a[a.length-1]
  3044. if(isNaN(scale)||scale<=0.5){syntax(1,"Bad scale value in %%font")
  3045. return}
  3046. font_scale_tb[a[0]]=scale}
  3047. function set_font_fac(font){var scale=font_scale_tb[font.fname||font.name]
  3048. if(!scale)
  3049. scale=1.1;font.swfac=font.size*scale}
  3050. function param_set_font(xxxfont,p){var font,n,a,ft2,k
  3051. if(xxxfont[xxxfont.length-2]=='-'){n=xxxfont[xxxfont.length-1]
  3052. if(n<'1'||n>'9')
  3053. return
  3054. xxxfont="u"+n+"font"}
  3055. font={}
  3056. a=p.match(/\s+(no)?box(\s|$)/)
  3057. if(a){if(a[1]){font.box=false
  3058. font.pad=0}else{font.box=true
  3059. font.pad=2.5}
  3060. p=p.replace(a[0],a[2])}
  3061. a=p.match(/\s+padding=([\d.]+)(\s|$)/)
  3062. if(a){font.pad=a[1]?+a[1]:0
  3063. p=p.replace(a[0],a[2])}
  3064. a=p.match(/\s+class=(.*?)(\s|$)/)
  3065. if(a){font.class=a[1];p=p.replace(a[0],a[2])}
  3066. a=p.match(/\s+wadj=(.*?)(\s|$)/)
  3067. if(a){if(typeof document=="undefined")
  3068. switch(a[1]){case'none':font.wadj=''
  3069. break
  3070. case'space':font.wadj='spacing'
  3071. break
  3072. case'glyph':font.wadj='spacingAndGlyphs'
  3073. break
  3074. default:syntax(1,errs.bad_val,"%%"+xxxfont)
  3075. break}
  3076. p=p.replace(a[0],a[2])}
  3077. a=p.match(/\s+([0-9.]+|\*)$/)
  3078. if(a){if(a[1]!="*")
  3079. font.size=+a[1]
  3080. p=p.replace(a[0],"")}
  3081. if(p[0]=='u'&&p.slice(0,4)=="url("){n=p.indexOf(')',1)
  3082. if(n<0){syntax(1,"No end of url in font family")
  3083. return}
  3084. font.src=p.slice(0,n+1)
  3085. font.fid=abc2svg.font_tb.length
  3086. abc2svg.font_tb.push(font)
  3087. font.name='ft'+font.fid
  3088. p=p.replace(font.src,'')}
  3089. a=p.match(/[- ]?[nN]ormal/)
  3090. if(a){font.normal=true
  3091. p=p.replace(a[0],'')}
  3092. a=p.match(abc2svg.ft_re)
  3093. if(a){font.weight=abc2svg.ft_w[a[0].replace(/[ -]/,'').toLowerCase()]
  3094. p=p.replace(a[0],'')}
  3095. a=p.match(/[- ]?[iI]talic/)
  3096. if(a){font.style="italic"
  3097. p=p.replace(a[0],'')}
  3098. a=p.match(/[- ]?[oO]blique/)
  3099. if(a){font.style="oblique"
  3100. p=p.replace(a[0],'')}
  3101. if(!font.src){if(p[0]=='"'){n=p.indexOf('"',1)
  3102. if(n<0){syntax(1,"No end of string in font family")
  3103. return}
  3104. p=p.slice(1,n)}
  3105. p=p.trim()
  3106. switch(p){case"":case"*":p="";break
  3107. case"Times-Roman":case"Times":p="serif";break
  3108. case"Helvetica":p="sans-serif";break
  3109. case"Courier":p="monospace";break
  3110. case"music":p=cfmt.musicfont.name;break
  3111. default:if(p.indexOf("Fig")>0)
  3112. font.figb=true
  3113. break}}
  3114. if(p&&!font.name)
  3115. font.name=p
  3116. if(font.size)
  3117. set_font_fac(font)
  3118. if(!font.name||!font.size){ft2=cfmt[xxxfont]
  3119. for(k in ft2){if(!ft2.hasOwnProperty(k)||font[k]!=undefined)
  3120. continue
  3121. switch(k){case"fid":case"used":break
  3122. case"style":case"weight":if(font.normal)
  3123. break
  3124. default:font[k]=ft2[k]
  3125. break}}
  3126. if(!font.swfac)
  3127. set_font_fac(font)}
  3128. if(font.pad==undefined)
  3129. font.pad=0
  3130. font.fname=font.name
  3131. if(font.weight>=700)
  3132. font.fname+='Bold'
  3133. cfmt[xxxfont]=font}
  3134. function get_unit(param){var v=param.toLowerCase().match(/(-?[\d.]+)(.*)/)
  3135. if(!v)
  3136. return NaN
  3137. v[1]=+v[1]
  3138. switch(v[2]){case"cm":return v[1]*CM
  3139. case"in":return v[1]*IN
  3140. case"pt":return v[1]*.75
  3141. case"px":case"":return v[1]}
  3142. return NaN}
  3143. function set_infoname(param){var tmp=cfmt.infoname.split("\n"),letter=param[0]
  3144. for(var i=0;i<tmp.length;i++){var infoname=tmp[i]
  3145. if(infoname[0]!=letter)
  3146. continue
  3147. if(param.length==1)
  3148. tmp.splice(i,1)
  3149. else
  3150. tmp[i]=param
  3151. cfmt.infoname=tmp.join('\n')
  3152. return}
  3153. cfmt.infoname+="\n"+param}
  3154. 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'}
  3155. function get_textopt(v){var i=v.indexOf(' ')
  3156. if(i>0)
  3157. v=v.slice(0,i)
  3158. return textopt[v]}
  3159. 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}
  3160. function set_pos(k,v){k=k.slice(0,3)
  3161. if(k=="ste")
  3162. k="stm"
  3163. set_v_param("pos",'"'+k+' '+v+'"')}
  3164. function set_writefields(parm){var c,i,a=parm.split(/\s+/)
  3165. if(get_bool(a[1])){for(i=0;i<a[0].length;i++){c=a[0][i]
  3166. if(cfmt.writefields.indexOf(c)<0)
  3167. cfmt.writefields+=c}}else{for(i=0;i<a[0].length;i++){c=a[0][i]
  3168. if(cfmt.writefields.indexOf(c)>=0)
  3169. cfmt.writefields=cfmt.writefields.replace(c,'')}}}
  3170. function set_v_param(k,v){k=[k+'=',v]
  3171. if(parse.state<3)
  3172. memo_kv_parm(curvoice?curvoice.id:'*',k)
  3173. else if(curvoice)
  3174. set_kv_parm(k)
  3175. else
  3176. memo_kv_parm('*',k)}
  3177. function set_page(){if(!img.chg)
  3178. return
  3179. img.chg=false;img.lm=cfmt.leftmargin-cfmt.printmargin
  3180. if(img.lm<0)
  3181. img.lm=0;img.rm=cfmt.rightmargin-cfmt.printmargin
  3182. if(img.rm<0)
  3183. img.rm=0;img.width=cfmt.pagewidth-2*cfmt.printmargin
  3184. if(img.width-img.lm-img.rm<100){error(0,undefined,"Bad staff width");img.width=img.lm+img.rm+150}
  3185. img.lw=(img.width-img.lm-img.rm
  3186. -2)
  3187. / cfmt.scale
  3188. set_posx()}
  3189. Abc.prototype.set_format=function(cmd,param){var f,f2,v,i
  3190. if(/.+font(-[\d])?$/.test(cmd)){if(cmd=="soundfont")
  3191. cfmt.soundfont=param
  3192. else
  3193. param_set_font(cmd,param)
  3194. return}
  3195. if(sfmt[cmd]&&parse.ufmt)
  3196. cfmt=Object.create(cfmt)
  3197. switch(cmd){case"aligncomposer":case"barsperstaff":case"infoline":case"measurenb":case"rbmax":case"rbmin":case"measrepnb":case"shiftunison":v=parseInt(param)
  3198. if(isNaN(v)){syntax(1,"Bad integer value");break}
  3199. cfmt[cmd]=v
  3200. break
  3201. case"abc-version":case"bgcolor":case"fgcolor":case"propagate-accidentals":case"titleformat":case"writeout-accidentals":cfmt[cmd]=param
  3202. break
  3203. case"beamslope":case"breaklimit":case"lineskipfac":case"maxshrink":case"pagescale":case"parskipfac":case"scale":case"slurheight":case"stemheight":case"tieheight":f=+param
  3204. if(isNaN(f)||!param||f<0){syntax(1,errs.bad_val,'%%'+cmd)
  3205. break}
  3206. switch(cmd){case"scale":f/=.75
  3207. case"pagescale":if(f<.1)
  3208. f=.1
  3209. cmd="scale";img.chg=true
  3210. break}
  3211. cfmt[cmd]=f
  3212. break
  3213. case"annotationbox":case"gchordbox":case"measurebox":case"partsbox":param_set_font(cmd.replace("box","font"),"* * "+(get_bool(param)?"box":"nobox"))
  3214. break
  3215. 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)
  3216. break
  3217. case"dblrepbar":param=":: "+param
  3218. case"bardef":v=param.split(/\s+/)
  3219. if(v.length!=2){syntax(1,errs.bad_val,"%%bardef")}else{if(parse.ufmt)
  3220. cfmt.bardef=Object.create(cfmt.bardef)
  3221. cfmt.bardef[v[0]]=v[1]}
  3222. break
  3223. case"chordalias":v=param.split(/\s+/)
  3224. if(!v.length)
  3225. syntax(1,errs.bad_val,"%%chordalias")
  3226. else
  3227. abc2svg.ch_alias[v[0]]=v[1]||""
  3228. break
  3229. 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)
  3230. if(isNaN(f))
  3231. syntax(1,errs.bad_val,'%%'+cmd)
  3232. else
  3233. cfmt[cmd]=f
  3234. break
  3235. case"page-format":user.page_format=get_bool(param)
  3236. break
  3237. case"print-leftmargin":syntax(0,"$1 is deprecated - use %%printmargin instead",'%%'+cmd)
  3238. cmd="printmargin"
  3239. case"printmargin":case"leftmargin":case"pagewidth":case"rightmargin":f=get_unit(param)
  3240. if(isNaN(f)){syntax(1,errs.bad_val,'%%'+cmd)
  3241. break}
  3242. cfmt[cmd]=f;img.chg=true
  3243. break
  3244. case"concert-score":if(cfmt.sound!="play")
  3245. cfmt.sound="concert"
  3246. break
  3247. case"writefields":set_writefields(param)
  3248. break
  3249. case"volume":cmd="dynamic"
  3250. case"dynamic":case"gchord":case"gstemdir":case"ornament":case"stemdir":case"vocal":set_pos(cmd,param)
  3251. break
  3252. case"font":get_font_scale(param)
  3253. break
  3254. case"fullsvg":if(parse.state!=0){syntax(1,errs.not_in_tune,"%%fullsvg")
  3255. break}
  3256. cfmt[cmd]=param
  3257. break
  3258. case"gracespace":v=param.split(/\s+/)
  3259. for(i=0;i<3;i++)
  3260. if(isNaN(+v[i])){syntax(1,errs.bad_val,"%%gracespace")
  3261. break}
  3262. if(parse.ufmt)
  3263. cfmt[cmd]=new Float32Array(3)
  3264. for(i=0;i<3;i++)
  3265. cfmt[cmd][i]=+v[i]
  3266. break
  3267. case"tuplets":v=param.split(/\s+/)
  3268. f=v[3]
  3269. if(f)
  3270. f=posval[f]
  3271. if(f)
  3272. v[3]=f
  3273. if(curvoice)
  3274. curvoice.tup=v
  3275. else
  3276. cfmt[cmd]=v
  3277. break
  3278. case"infoname":set_infoname(param)
  3279. break
  3280. case"notespacingfactor":v=param.match(/([.\d]+)[,\s]*(\d+)?/)
  3281. if(v){f=+v[1]
  3282. if(isNaN(f)||f<1||f>2){f=0}else if(v[2]){f2=+v[2]
  3283. if(isNaN(f))
  3284. f=0}else{f2=cfmt.spatab[5]}}
  3285. if(!f){syntax(1,errs.bad_val,"%%"+cmd)
  3286. break}
  3287. cfmt[cmd]=param
  3288. cfmt.spatab=new Float32Array(10)
  3289. i=5;do{cfmt.spatab[i]=f2
  3290. f2/=f}while(--i>=0)
  3291. i=5;f2=cfmt.spatab[i]
  3292. for(;++i<cfmt.spatab.length;){f2*=f;cfmt.spatab[i]=f2}
  3293. break
  3294. case"play":cfmt.sound="play"
  3295. break
  3296. case"pos":cmd=param.match(/(\w*)\s+(.*)/)
  3297. if(!cmd||!cmd[2]){syntax(1,"Error in %%pos")
  3298. break}
  3299. if(cmd[1].slice(0,3)=='tup'&&curvoice){if(!curvoice.tup)
  3300. curvoice.tup=cfmt.tuplets
  3301. else
  3302. curvoice.tup=Object.create(curvoice.tup)
  3303. v=posval[cmd[2]]
  3304. switch(v){case C.SL_ABOVE:curvoice.tup[3]=1
  3305. break
  3306. case C.SL_BELOW:curvoice.tup[3]=2
  3307. break
  3308. case C.SL_HIDDEN:curvoice.tup[2]=1
  3309. break}
  3310. break}
  3311. if(cmd[1].slice(0,3)=="vol")
  3312. cmd[1]="dyn"
  3313. set_pos(cmd[1],cmd[2])
  3314. break
  3315. case"sounding-score":if(cfmt.sound!="play")
  3316. cfmt.sound="sounding"
  3317. break
  3318. case"staffwidth":v=get_unit(param)
  3319. if(isNaN(v)){syntax(1,errs.bad_val,'%%'+cmd)
  3320. break}
  3321. if(v<100){syntax(1,"%%staffwidth too small")
  3322. break}
  3323. v=cfmt.pagewidth-v-cfmt.leftmargin
  3324. if(v<2){syntax(1,"%%staffwidth too big")
  3325. break}
  3326. cfmt.rightmargin=v;img.chg=true
  3327. break
  3328. case"textoption":cfmt[cmd]=get_textopt(param)
  3329. break
  3330. case"dynalign":case"singleline":case"stretchlast":case"titletrim":v=+param
  3331. if(isNaN(v))
  3332. v=get_bool(param)?0:1
  3333. if(cmd[1]=='t'){if(v<0||v>1){syntax(1,errs.bad_val,'%%'+cmd)
  3334. break}}
  3335. cfmt[cmd]=v
  3336. break
  3337. case"combinevoices":syntax(1,"%%combinevoices is deprecated - use %%voicecombine instead")
  3338. break
  3339. case"voicemap":set_v_param("map",param)
  3340. break
  3341. case"voicescale":set_v_param("scale",param)
  3342. break
  3343. case"rbdbstop":v=get_bool(param)
  3344. if(v&&cfmt["abc-version"]>="2.2")
  3345. cfmt["abc-version"]="1"
  3346. else if(!v&&cfmt["abc-version"]<"2.2")
  3347. cfmt["abc-version"]="2.2"
  3348. break
  3349. default:if(!parse.state)
  3350. cfmt[cmd]=param
  3351. break}
  3352. if(sfmt[cmd]&&parse.ufmt){parse.ufmt=false}}
  3353. function st_font(font){var n=font.name,r=""
  3354. if(font.weight)
  3355. r+=font.weight+" "
  3356. if(font.style)
  3357. r+=font.style+" "
  3358. if(n.indexOf('"')<0&&n.indexOf(' ')>0)
  3359. n='"'+n+'"'
  3360. return r+font.size.toFixed(1)+'px '+n}
  3361. function style_font(font){return'font:'+st_font(font)}
  3362. Abc.prototype.style_font=style_font
  3363. function font_class(font){var f='f'+font.fid+cfmt.fullsvg
  3364. if(font.class)
  3365. f+=' '+font.class
  3366. if(font.box)
  3367. f+=' '+'box'
  3368. return f}
  3369. function use_font(font){if(!font.used){font.used=true;if(font.fid==undefined){font.fid=abc2svg.font_tb.length
  3370. abc2svg.font_tb.push(font)
  3371. if(!font.swfac)
  3372. set_font_fac(font)
  3373. if(!font.pad)
  3374. font.pad=0}
  3375. add_fstyle(".f"+font.fid+
  3376. (cfmt.fullsvg||"")+"{"+style_font(font)+"}")
  3377. if(font.src)
  3378. add_fstyle("@font-face{\n\
  3379. font-family:"+font.name+";\n\
  3380. src:"+font.src+"}")
  3381. if(font==cfmt.musicfont)
  3382. add_fstyle(".f"+font.fid
  3383. +(cfmt.fullsvg||"")
  3384. +' text,tspan{white-space:pre}')}}
  3385. function get_font(fn){var font,font2,fid,st
  3386. fn+="font"
  3387. font=cfmt[fn]
  3388. if(!font){syntax(1,"Unknown font $1",fn)
  3389. return gene.curfont}
  3390. if(!font.name||!font.size){font2=Object.create(gene.deffont)
  3391. if(font.name)
  3392. font2.name=font.name
  3393. if(font.normal){if(font2.weight)
  3394. font2.weight=null
  3395. if(font2.style)
  3396. font2.style=null}else{if(font.weight)
  3397. font2.weight=font.weight
  3398. if(font.style)
  3399. font2.style=font.style}
  3400. if(font.src)
  3401. font2.src=font.src
  3402. if(font.size)
  3403. font2.size=font.size
  3404. st=st_font(font2)
  3405. if(font.class){font2.class=font.class
  3406. st+=' '+font.class}
  3407. fid=abc2svg.font_st[st]
  3408. if(fid!=undefined)
  3409. return abc2svg.font_tb[fid]
  3410. abc2svg.font_st[st]=abc2svg.font_tb.length
  3411. font2.fid=font2.used=undefined
  3412. font=font2}
  3413. use_font(font)
  3414. return font}
  3415. var sav={},mac={},maci={},modone={}
  3416. 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":"þ"}
  3417. var oct_acc={"1":"\u266f","2":"\u266d","3":"\u266e","4":"&#x1d12a;","5":"&#x1d12b;"}
  3418. function cnv_escape(src,flag){var c,c2,dst="",i,j=0
  3419. while(1){i=src.indexOf('\\',j)
  3420. if(i<0)
  3421. break
  3422. dst+=src.slice(j,i);c=src[++i]
  3423. if(!c)
  3424. return dst+'\\'
  3425. switch(c){case'0':case'2':if(src[i+1]!='0')
  3426. break
  3427. c2=oct_acc[src[i+2]]
  3428. if(c2){dst+=c2;j=i+3
  3429. continue}
  3430. break
  3431. case'u':j=Number("0x"+src.slice(i+1,i+5));if(isNaN(j)||j<0x20){dst+=src[++i]+"\u0306"
  3432. j=i+1
  3433. continue}
  3434. c=String.fromCharCode(j)
  3435. if(c=='\\'){i+=4
  3436. break}
  3437. dst+=c
  3438. j=i+5
  3439. continue
  3440. case't':dst+='\t';j=i+1
  3441. continue
  3442. case'n':dst+='\n';j=i+1
  3443. continue
  3444. default:c2=abc_utf[src.slice(i,i+2)]
  3445. if(c2){dst+=c2;j=i+2
  3446. continue}
  3447. c2=src[i+1]
  3448. if(!c2)
  3449. break
  3450. if(!/[A-Za-z]/.test(c2))
  3451. break
  3452. switch(c){case'`':dst+=c2+"\u0300"
  3453. j=i+2
  3454. continue
  3455. case"'":dst+=c2+"\u0301"
  3456. j=i+2
  3457. continue
  3458. case'^':dst+=c2+"\u0302"
  3459. j=i+2
  3460. continue
  3461. case'~':dst+=c2+"\u0303"
  3462. j=i+2
  3463. continue
  3464. case'=':dst+=c2+"\u0304"
  3465. j=i+2
  3466. continue
  3467. case'_':dst+=c2+"\u0305"
  3468. j=i+2
  3469. continue
  3470. case'.':dst+=c2+"\u0307"
  3471. j=i+2
  3472. continue
  3473. case'"':dst+=c2+"\u0308"
  3474. j=i+2
  3475. continue
  3476. case'o':dst+=c2+"\u030a"
  3477. j=i+2
  3478. continue
  3479. case'H':dst+=c2+"\u030b"
  3480. j=i+2
  3481. continue
  3482. case'v':dst+=c2+"\u030c"
  3483. j=i+2
  3484. continue
  3485. case'c':dst+=c2+"\u0327"
  3486. j=i+2
  3487. continue
  3488. case';':dst+=c2+"\u0328"
  3489. j=i+2
  3490. continue}
  3491. break}
  3492. if(flag=='w')
  3493. dst+='\\'
  3494. dst+=c
  3495. j=i+1}
  3496. return dst+src.slice(j)}
  3497. var include=0
  3498. function do_include(fn){var file,parse_sav
  3499. if(!user.read_file){syntax(1,"No read_file support")
  3500. return}
  3501. if(include>2){syntax(1,"Too many include levels")
  3502. return}
  3503. file=user.read_file(fn)
  3504. if(!file){syntax(1,"Cannot read file '$1'",fn)
  3505. return}
  3506. include++;parse_sav=clone(parse);tosvg(fn,file);parse_sav.state=parse.state;parse=parse_sav;include--}
  3507. 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'
  3508. function tune_selected(){var re,res,i=file.indexOf('K:',bol)
  3509. if(i<0){return false}
  3510. i=file.indexOf('\n',i)
  3511. if(parse.select.test(file.slice(parse.bol,i)))
  3512. return true
  3513. re=/\n\w*\n/;re.lastIndex=i;res=re.exec(file)
  3514. if(res)
  3515. eol=re.lastIndex
  3516. else
  3517. eol=eof
  3518. return false}
  3519. function uncomment(src,flag){if(!src)
  3520. return src
  3521. var i=src.indexOf('%')
  3522. if(i==0)
  3523. return''
  3524. if(i>0)
  3525. src=src.replace(/([^\\])%.*/,'$1').replace(/\\%/g,'%');src=src.replace(/\s+$/,'')
  3526. if(flag&&src.indexOf('\\')>=0)
  3527. return cnv_escape(src,flag)
  3528. return src}
  3529. function end_tune(){generate()
  3530. 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
  3531. delete parse.ctrl
  3532. init_tune()
  3533. img.chg=true;set_page()}
  3534. function do_voice(select,in_tune){var opt,bol
  3535. if(select=="end")
  3536. return
  3537. if(in_tune){if(!parse.tune_v_opts)
  3538. parse.tune_v_opts={};opt=parse.tune_v_opts}else{if(!parse.voice_opts)
  3539. parse.voice_opts={};opt=parse.voice_opts}
  3540. opt[select]=[]
  3541. while(1){bol=++eol
  3542. if(file[bol]!='%')
  3543. break
  3544. eol=file.indexOf('\n',eol);if(file[bol+1]!=line1)
  3545. continue
  3546. bol+=2
  3547. if(eol<0)
  3548. text=file.slice(bol)
  3549. else
  3550. text=file.slice(bol,eol);a=text.match(/\S+/)
  3551. switch(a[0]){default:opt[select].push(uncomment(text,true))
  3552. continue
  3553. case"score":case"staves":case"tune":case"voice":bol-=2
  3554. break}
  3555. break}
  3556. eol=parse.eol=bol-1}
  3557. function tune_filter(){var o,opts,j,pc,h,i=file.indexOf('K:',bol)
  3558. i=file.indexOf('\n',i);h=file.slice(parse.bol,i)
  3559. for(i in parse.tune_opts){if(!parse.tune_opts.hasOwnProperty(i))
  3560. continue
  3561. if(!(new RegExp(i)).test(h))
  3562. continue
  3563. opts=parse.tune_opts[i]
  3564. for(j=0;j<opts.t_opts.length;j++){pc=opts.t_opts[j]
  3565. switch(pc.match(/\S+/)[0]){case"score":case"staves":if(!parse.scores)
  3566. parse.scores=[];parse.scores.push(pc)
  3567. break
  3568. default:self.do_pscom(pc)
  3569. break}}
  3570. opts=opts.v_opts
  3571. if(!opts)
  3572. continue
  3573. for(j in opts){if(!opts.hasOwnProperty(j))
  3574. continue
  3575. if(!parse.tune_v_opts)
  3576. parse.tune_v_opts={};if(!parse.tune_v_opts[j])
  3577. parse.tune_v_opts[j]=opts[j]
  3578. else
  3579. parse.tune_v_opts[j]=parse.tune_v_opts[j].concat(opts[j])}}}
  3580. if(abc2svg.mhooks){for(i in abc2svg.mhooks){if(!modone[i]){modone[i]=1
  3581. abc2svg.mhooks[i](self)}}}
  3582. parse.file=file;parse.fname=in_fname
  3583. if(bol==undefined)
  3584. bol=0
  3585. if(!eof)
  3586. eof=file.length
  3587. if(file.slice(bol,bol+5)=="%abc-")
  3588. cfmt["abc-version"]=/[1-9.]+/.exec(file.slice(bol+5,bol+10))
  3589. for(;bol<eof;bol=parse.eol+1){eol=file.indexOf('\n',bol)
  3590. if(eol<0||eol>eof)
  3591. eol=eof;parse.eol=eol
  3592. while(1){eol--
  3593. switch(file[eol]){case' ':case'\t':continue}
  3594. break}
  3595. eol++
  3596. 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()
  3597. parse.state=0
  3598. if(parse.select){eol=file.indexOf('\nX:',parse.eol)
  3599. if(eol<0)
  3600. eol=eof
  3601. parse.eol=eol}}
  3602. continue}
  3603. parse.istart=parse.bol=bol;parse.iend=eol;parse.line.index=0;line0=file[bol];line1=file[bol+1]
  3604. if((line0=='I'&&line1==':')||line0=='%'){if(line0=='%'&&parse.prefix.indexOf(line1)<0)
  3605. continue
  3606. 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}}
  3607. if(pscom){pscom=false;bol+=2
  3608. text=file.slice(bol,eol)
  3609. a=text.match(/([^\s]+)\s*(.*)/)
  3610. if(!a||a[1][0]=='%')
  3611. continue
  3612. switch(a[1]){case"abcm2ps":case"ss-pref":parse.prefix=a[2]
  3613. continue
  3614. case"abc-include":do_include(uncomment(a[2]))
  3615. continue}
  3616. if(a[1].slice(0,5)=='begin'){b=a[1].substr(5);end='\n'+line0+line1+"end"+b;i=file.indexOf(end,eol)
  3617. if(i<0){syntax(1,"No $1 after %%$2",end.slice(1),a[1]);parse.eol=eof
  3618. continue}
  3619. self.do_begin_end(b,uncomment(a[2]),file.slice(eol+1,i).replace(/\n%[^%].*$/gm,'').replace(/^%%/gm,''))
  3620. parse.eol=file.indexOf('\n',i+6)
  3621. if(parse.eol<0)
  3622. parse.eol=eof
  3623. continue}
  3624. switch(a[1]){case"select":if(parse.state!=0){syntax(1,errs.not_in_tune,"%%select")
  3625. continue}
  3626. select=uncomment(text.slice(7))
  3627. if(select[0]=='"')
  3628. select=select.slice(1,-1);if(!select){delete parse.select
  3629. continue}
  3630. select=select.replace(/\(/g,'\\(');select=select.replace(/\)/g,'\\)');parse.select=new RegExp(select,'m')
  3631. continue
  3632. case"tune":if(parse.state!=0){syntax(1,errs.not_in_tune,"%%tune")
  3633. continue}
  3634. select=uncomment(a[2])
  3635. if(!select){parse.tune_opts={}
  3636. continue}
  3637. if(select=="end")
  3638. continue
  3639. if(!parse.tune_opts)
  3640. parse.tune_opts={};parse.tune_opts[select]=opt={t_opts:[]};while(1){bol=++eol
  3641. if(file[bol]!='%')
  3642. break
  3643. eol=file.indexOf('\n',eol);if(file[bol+1]!=line1)
  3644. continue
  3645. bol+=2
  3646. if(eol<0)
  3647. text=file.slice(bol)
  3648. else
  3649. text=file.slice(bol,eol);a=text.match(/([^\s]+)\s*(.*)/)
  3650. switch(a[1]){case"tune":break
  3651. case"voice":do_voice(uncomment(a[2],true),true)
  3652. continue
  3653. default:opt.t_opts.push(uncomment(text,true))
  3654. continue}
  3655. break}
  3656. if(parse.tune_v_opts){opt.v_opts=parse.tune_v_opts;parse.tune_v_opts=null}
  3657. parse.eol=bol-1
  3658. continue
  3659. case"voice":if(parse.state!=0){syntax(1,errs.not_in_tune,"%%voice")
  3660. continue}
  3661. select=uncomment(a[2])
  3662. if(!select){parse.voice_opts=null
  3663. continue}
  3664. do_voice(select)
  3665. continue}
  3666. self.do_pscom(uncomment(text,true))
  3667. continue}
  3668. if(line1!=':'||!/[A-Za-z+]/.test(line0)){last_info=undefined;if(parse.state<2)
  3669. continue
  3670. parse.line.buffer=uncomment(file.slice(bol,eol))
  3671. if(parse.line.buffer)
  3672. parse_music_line()
  3673. continue}
  3674. bol+=2
  3675. while(1){switch(file[bol]){case' ':case'\t':bol++
  3676. continue}
  3677. break}
  3678. if(line0=='+'){if(!last_info){syntax(1,"+: without previous info field")
  3679. continue}
  3680. txt_add=' ';line0=last_info}
  3681. text=uncomment(file.slice(bol,eol),line0)
  3682. switch(line0){case'X':if(parse.state!=0){syntax(1,errs.ignored,line0)
  3683. continue}
  3684. if(parse.select&&!tune_selected()){eol=file.indexOf('\nX:',parse.eol)
  3685. if(eol<0)
  3686. eol=eof;parse.eol=eol
  3687. continue}
  3688. sav.cfmt=clone(cfmt);sav.info=clone(info,2)
  3689. 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
  3690. if(user.page_format&&blkdiv<1)
  3691. blkdiv=1
  3692. if(parse.tune_opts)
  3693. tune_filter()
  3694. continue
  3695. case'T':switch(parse.state){case 0:continue
  3696. case 1:case 2:if(info.T==undefined)
  3697. info.T=text
  3698. else
  3699. info.T+="\n"+text
  3700. continue}
  3701. s=new_block("title");s.text=text
  3702. continue
  3703. case'K':switch(parse.state){case 0:continue
  3704. case 1:info.K=text
  3705. break}
  3706. do_info(line0,text)
  3707. continue
  3708. case'W':if(parse.state==0||cfmt.writefields.indexOf(line0)<0)
  3709. break
  3710. if(info.W==undefined)
  3711. info.W=text
  3712. else
  3713. info.W+=txt_add+text
  3714. break
  3715. case'm':if(parse.state>=2){syntax(1,errs.ignored,line0)
  3716. continue}
  3717. a=text.match(/(.*?)[= ]+(.*)/)
  3718. if(!a||!a[2]){syntax(1,errs.bad_val,"m:")
  3719. continue}
  3720. mac[a[1]]=a[2];maci[a[1][0]]=true
  3721. break
  3722. case's':if(parse.state!=3||cfmt.writefields.indexOf(line0)<0)
  3723. break
  3724. get_sym(text,txt_add==' ')
  3725. break
  3726. case'w':if(parse.state!=3||cfmt.writefields.indexOf(line0)<0)
  3727. break
  3728. get_lyrics(text,txt_add==' ')
  3729. break
  3730. case'|':if(parse.state<2)
  3731. continue
  3732. parse.line.buffer=text
  3733. parse_music_line()
  3734. continue
  3735. default:if("ABCDFGHNOSZ".indexOf(line0)>=0){if(parse.state>=2){syntax(1,errs.ignored,line0)
  3736. continue}
  3737. if(!info[line0])
  3738. info[line0]=text
  3739. else
  3740. info[line0]+=txt_add+text
  3741. break}
  3742. do_info(line0,text)
  3743. continue}
  3744. txt_add='\n';last_info=line0}
  3745. if(include)
  3746. return
  3747. if(parse.state>=2)
  3748. end_tune();parse.state=0}
  3749. Abc.prototype.tosvg=tosvg
  3750. var gene,staff_tb,nstaff,tsnext,realwidth,insert_meter,spf_last,smallest_duration
  3751. var dx_tb=new Float32Array([10,10,11,13,15])
  3752. var hw_tb=new Float32Array([4.7,5,6,7.2,7.5])
  3753. var w_note=new Float32Array([3.5,3.7,5,6,7])
  3754. function identify_note(s,dur_o){var head,flags,dots=0,dur=dur_o
  3755. if(dur%12!=0)
  3756. error(1,s,"Invalid note duration $1",dur);dur/=12
  3757. if(!dur)
  3758. error(1,s,"Note too short")
  3759. for(flags=5;dur;dur>>=1,flags--){if(dur&1)
  3760. break}
  3761. dur>>=1
  3762. if((dur+1)&dur){if(s.type!=C.REST||dur_o!=s.p_v.wmeasure)
  3763. error(0,s,"Non standard note duration $1",dur_o)}
  3764. while(dur>>dots>0)
  3765. dots++
  3766. flags-=dots
  3767. if(flags>=0){head=C.FULL}else switch(flags){default:error(1,s,"Note too long")
  3768. flags=-4
  3769. case-4:head=C.SQUARE
  3770. break
  3771. case-3:head=s.fmt.squarebreve?C.SQUARE:C.OVALBARS
  3772. break
  3773. case-2:head=C.OVAL
  3774. break
  3775. case-1:head=C.EMPTY
  3776. break}
  3777. return[head,dots,flags]}
  3778. function set_head_shift(s){var i,i1,i2,d,ps,dx,dx_head=dx_tb[s.head],dir=s.stem,n=s.nhd
  3779. if(!n)
  3780. return
  3781. dx=dx_head*.74
  3782. if(s.grace)
  3783. dx*=.6
  3784. 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}
  3785. var shift=false,dx_max=0
  3786. for(i=i1;i!=i2;i+=dir){d=s.notes[i].pit-ps;ps=s.notes[i].pit
  3787. if(!d){if(shift){var new_dx=s.notes[i].shhd=s.notes[i-dir].shhd+dx
  3788. if(dx_max<new_dx)
  3789. dx_max=new_dx
  3790. continue}
  3791. if(i+dir!=i2&&ps+dir==s.notes[i+dir].pit){s.notes[i].shhd=-dx
  3792. if(dx_max<-dx)
  3793. dx_max=-dx
  3794. continue}}
  3795. if(d<0)
  3796. d=-d
  3797. if(d>3||(d>=2&&s.head!=C.SQUARE)){shift=false}else{shift=!shift
  3798. if(shift){s.notes[i].shhd=dx
  3799. if(dx_max<dx)
  3800. dx_max=dx}}}
  3801. s.xmx=dx_max}
  3802. function acc_shift(notes,dx_head){var i,i1,i2,dx,dx1,dx2,ps,p1,acc,n=notes.length
  3803. for(i=n-1;--i>=0;){dx=notes[i].shhd
  3804. if(!dx||dx>0)
  3805. continue
  3806. dx=dx_head-dx;ps=notes[i].pit
  3807. for(i1=n;--i1>=0;){if(!notes[i1].acc)
  3808. continue
  3809. p1=notes[i1].pit
  3810. if(p1<ps-3)
  3811. break
  3812. if(p1>ps+3)
  3813. continue
  3814. if(notes[i1].shac<dx)
  3815. notes[i1].shac=dx}}
  3816. for(i1=n;--i1>=0;){if(notes[i1].acc){p1=notes[i1].pit
  3817. dx1=notes[i1].shac
  3818. if(!dx1){dx1=notes[i1].shhd
  3819. if(dx1<0)
  3820. dx1=dx_head-dx1
  3821. else
  3822. dx1=dx_head}
  3823. break}}
  3824. if(i1<0)
  3825. return
  3826. for(i2=0;i2<i1;i2++){if(notes[i2].acc){ps=notes[i2].pit
  3827. dx2=notes[i2].shac
  3828. if(!dx2){dx2=notes[i2].shhd
  3829. if(dx2<0)
  3830. dx2=dx_head-dx2
  3831. else
  3832. dx2=dx_head}
  3833. break}}
  3834. if(i1==i2){notes[i1].shac=dx1
  3835. return}
  3836. if(p1>ps+4){if(dx1>dx2)
  3837. dx2=dx1
  3838. notes[i1].shac=notes[i2].shac=dx2}else{notes[i1].shac=dx1
  3839. if(notes[i1].pit!=notes[i2].pit)
  3840. dx1+=7
  3841. notes[i2].shac=dx2=dx1}
  3842. dx2+=7
  3843. for(i=i1;--i>i2;){acc=notes[i].acc
  3844. if(!acc)
  3845. continue
  3846. dx=notes[i].shac
  3847. if(dx<dx2)
  3848. dx=dx2
  3849. ps=notes[i].pit
  3850. for(i1=n;--i1>i;){if(!notes[i1].acc)
  3851. continue
  3852. p1=notes[i1].pit
  3853. if(p1>=ps+4){if(p1>ps+4||acc<0||notes[i1].acc<0)
  3854. continue}
  3855. if(dx>notes[i1].shac-6){dx1=notes[i1].shac+7
  3856. if(dx1>dx)
  3857. dx=dx1}}
  3858. notes[i].shac=dx}}
  3859. function set_acc_shft(){var s,s2,st,i,acc,st,t,dx_head,notes
  3860. s=tsfirst
  3861. while(s){if(s.type!=C.NOTE||s.invis){s=s.ts_next
  3862. continue}
  3863. st=s.st;t=s.time;acc=false
  3864. for(s2=s;s2;s2=s2.ts_next){if(s2.time!=t||s2.type!=C.NOTE||s2.st!=st)
  3865. break
  3866. if(acc)
  3867. continue
  3868. for(i=0;i<=s2.nhd;i++){if(s2.notes[i].acc){acc=true
  3869. break}}}
  3870. if(!acc){s=s2
  3871. continue}
  3872. dx_head=dx_tb[s.head]
  3873. notes=[]
  3874. for(;s!=s2;s=s.ts_next){if(!s.invis)
  3875. Array.prototype.push.apply(notes,s.notes)}
  3876. notes.sort(abc2svg.pitcmp)
  3877. acc_shift(notes,dx_head)}}
  3878. function lkvsym(s,next){s.next=next;s.prev=next.prev
  3879. if(s.prev)
  3880. s.prev.next=s
  3881. else
  3882. s.p_v.sym=s;next.prev=s}
  3883. function lktsym(s,next){var old_wl
  3884. s.ts_next=next
  3885. if(next){s.ts_prev=next.ts_prev
  3886. if(s.ts_prev)
  3887. s.ts_prev.ts_next=s;next.ts_prev=s}else{error(2,s,"Bad linkage")
  3888. s.ts_prev=null}
  3889. 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])
  3890. if(!next||next.seqst)
  3891. return
  3892. next.seqst=next.time!=s.time||(w_tb[s.type]!=w_tb[next.type]&&!!w_tb[s.type])
  3893. if(next.seqst){old_wl=next.wl
  3894. self.set_width(next)
  3895. if(next.a_ly)
  3896. ly_set(next)
  3897. if(!next.shrink){next.shrink=next.wl
  3898. if(next.prev)
  3899. next.shrink+=next.prev.wr}else{next.shrink+=next.wl-old_wl}
  3900. next.space=0}}
  3901. function unlksym(s){if(s.next)
  3902. s.next.prev=s.prev
  3903. if(s.prev)
  3904. s.prev.next=s.next
  3905. else
  3906. s.p_v.sym=s.next
  3907. 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
  3908. s.shrink=s.ts_next.shrink
  3909. s.space=s.ts_next.space}}
  3910. s.ts_next.ts_prev=s.ts_prev}
  3911. if(s.ts_prev)
  3912. s.ts_prev.ts_next=s.ts_next
  3913. if(tsfirst==s)
  3914. tsfirst=s.ts_next
  3915. if(tsnext==s)
  3916. tsnext=s.ts_next}
  3917. function insert_clef(s,clef_type,clef_line){var p_voice=s.p_v,new_s,st=s.st
  3918. if(s.type==C.BAR&&s.prev&&s.prev.type==C.BAR&&s.prev.bar_type[0]!=':')
  3919. s=s.prev;p_voice.last_sym=s.prev
  3920. if(!p_voice.last_sym)
  3921. 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
  3922. delete new_s.second;new_s.notes=[]
  3923. new_s.notes[0]={pit:s.notes[0].pit}
  3924. new_s.nhd=0;while(!s.seqst)
  3925. s=s.ts_prev;lktsym(new_s,s)
  3926. if(s.soln){new_s.soln=true
  3927. delete s.soln}
  3928. return new_s}
  3929. function set_float(){var p_voice,st,staff_chg,v,s,s1,up,down
  3930. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v]
  3931. staff_chg=false;st=p_voice.st
  3932. for(s=p_voice.sym;s;s=s.next){if(!s.floating){while(s&&!s.floating)
  3933. s=s.next
  3934. if(!s)
  3935. break
  3936. staff_chg=false}
  3937. if(!s.dur){if(staff_chg)
  3938. s.st++
  3939. continue}
  3940. if(s.notes[0].pit>=19){staff_chg=false
  3941. continue}
  3942. if(s.notes[s.nhd].pit<=12){staff_chg=true
  3943. s.st++
  3944. continue}
  3945. up=127
  3946. for(s1=s.ts_prev;s1;s1=s1.ts_prev){if(s1.st!=st||s1.v==s.v)
  3947. break
  3948. if(s1.type==C.NOTE)
  3949. if(s1.notes[0].pit<up)
  3950. up=s1.notes[0].pit}
  3951. if(up==127){if(staff_chg)
  3952. s.st++
  3953. continue}
  3954. if(s.notes[s.nhd].pit>up-3){staff_chg=false
  3955. continue}
  3956. down=-127
  3957. for(s1=s.ts_next;s1;s1=s1.ts_next){if(s1.st!=st+1||s1.v==s.v)
  3958. break
  3959. if(s1.type==C.NOTE)
  3960. if(s1.notes[s1.nhd].pit>down)
  3961. down=s1.notes[s1.nhd].pit}
  3962. if(down==-127){if(staff_chg)
  3963. s.st++
  3964. continue}
  3965. if(s.notes[0].pit<down+3){staff_chg=true
  3966. s.st++
  3967. continue}
  3968. up-=s.notes[s.nhd].pit
  3969. down=s.notes[0].pit-down
  3970. if(!staff_chg){if(up<down+3)
  3971. continue
  3972. staff_chg=true}else{if(up<down-3){staff_chg=false
  3973. continue}}
  3974. s.st++}}}
  3975. 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)
  3976. gspleft-=3;x=gspleft;g.beam_st=true
  3977. for(;;g=g.next){set_head_shift(g)
  3978. acc_shift(g.notes,6.5)
  3979. dx=0
  3980. for(m=g.nhd;m>=0;m--){if(g.notes[m].shac-2>dx)
  3981. dx=g.notes[m].shac-2}
  3982. x+=dx;g.x=x
  3983. if(g.nflags<=0)
  3984. g.beam_st=g.beam_end=true
  3985. next=g.next
  3986. if(!next){g.beam_end=true
  3987. break}
  3988. if(next.nflags<=0)
  3989. g.beam_end=true
  3990. if(g.beam_end){next.beam_st=true;x+=gspinside/4}
  3991. if(g.nflags<=0)
  3992. x+=gspinside/4
  3993. if(g.y>next.y+8)
  3994. x-=1.5
  3995. x+=gspinside}
  3996. next=s.next
  3997. if(next&&next.type==C.NOTE){if(g.y>=3*(next.notes[next.nhd].pit-18))
  3998. gspright-=1
  3999. else if(g.beam_st&&g.y<3*(next.notes[next.nhd].pit-18)-4)
  4000. gspright+=2}
  4001. x+=gspright;return x}
  4002. function set_w_chs(s){var i,ch,w0,s0,dw,x=0,n=0
  4003. set_font("vocal")
  4004. for(;s;s=s.ts_next){if(s.shrink){x+=s.shrink;n++}
  4005. if(s.a_ly)
  4006. ly_set(s)
  4007. if(!s.a_gch)
  4008. continue
  4009. for(i=0;i<s.a_gch.length;i++){ch=s.a_gch[i]
  4010. if(ch.type!='g'||ch.y<0)
  4011. continue
  4012. if(w0){if(w0>x+ch.x){if(s.prev&&s.prev.seqst&&s.prev.type==C.BAR)
  4013. n--
  4014. dw=(w0-x-ch.x)/n
  4015. while(1){s0=s0.ts_next
  4016. if(s0.shrink)
  4017. s0.shrink+=dw
  4018. if(s0==s||s0.type==C.BAR)
  4019. break}}}
  4020. s0=s;w0=ch.text.wh[0];n=0;x=0
  4021. break}}}
  4022. function gchord_width(s,wlnote,wlw){var gch,w,ix,arspc=0
  4023. for(ix=0;ix<s.a_gch.length;ix++){gch=s.a_gch[ix]
  4024. switch(gch.type){case'<':w=gch.text.wh[0]+wlnote
  4025. if(w>wlw)
  4026. wlw=w
  4027. break
  4028. case'>':w=gch.text.wh[0]+s.wr
  4029. if(w>arspc)
  4030. arspc=w
  4031. break}}
  4032. if(s.wr<arspc)
  4033. s.wr=arspc
  4034. return wlw}
  4035. 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
  4036. if(s.play){s.wl=s.wr=0
  4037. return}
  4038. switch(s.type){case C.NOTE:case C.REST:s.wr=wlnote=s.invis?0:hw_tb[s.head]
  4039. if(s.xmx>0)
  4040. s.wr+=s.xmx+4;for(s2=s.prev;s2;s2=s2.prev){if(w_tb[s2.type])
  4041. break}
  4042. if(s2){switch(s2.type){case C.BAR:case C.CLEF:case C.KEY:case C.METER:wlnote+=3
  4043. break
  4044. case C.STBRK:wlnote+=8
  4045. break}}
  4046. for(m=0;m<=s.nhd;m++){nt=s.notes[m]
  4047. xx=nt.shhd
  4048. if(xx<0){if(wlnote<-xx+5)
  4049. wlnote=-xx+5}
  4050. acc=nt.acc
  4051. if(acc){tmp=nt.shac+
  4052. (typeof acc=="object"?5.5:3.5)
  4053. if(wlnote<tmp)
  4054. wlnote=tmp}
  4055. if(nt.a_dd)
  4056. wlnote+=deco_wch(nt)}
  4057. if(s2){switch(s2.type){case C.BAR:case C.CLEF:case C.KEY:case C.METER:wlnote-=3
  4058. break}}
  4059. if(s.a_dd)
  4060. wlnote=deco_width(s,wlnote)
  4061. if(s.beam_st&&s.beam_end&&s.stem>0&&s.nflags>0){if(s.wr<s.xmx+9)
  4062. s.wr=s.xmx+9}
  4063. if(s.dots){if(s.wl==undefined)
  4064. switch(s.head){case C.SQUARE:case C.OVALBARS:s.xmx+=3
  4065. break
  4066. case C.OVAL:s.xmx+=1
  4067. break}
  4068. if(s.wr<s.xmx+8)
  4069. s.wr=s.xmx+8
  4070. if(s.dots>=2)
  4071. s.wr+=3.5*(s.dots-1)}
  4072. if(s.trem2&&s.beam_end&&wlnote<20)
  4073. wlnote=20
  4074. wlw=wlnote
  4075. if(s2){switch(s2.type){case C.NOTE:if(s2.stem>0&&s.stem<0){if(wlw<7)
  4076. wlw=7}
  4077. if((s.y>27&&s2.y>27)||(s.y<-3&&s2.y<-3)){if(wlw<6)
  4078. wlw=6}
  4079. if(s2.tie){if(wlw<14)
  4080. wlw=14}
  4081. break
  4082. case C.CLEF:if(s2.second||s2.clef_small)
  4083. break
  4084. case C.KEY:if(s.a_gch)
  4085. wlw+=4
  4086. case C.METER:wlw+=3
  4087. break}}
  4088. if(s.a_gch)
  4089. wlw=gchord_width(s,wlnote,wlw)
  4090. if(s.prev&&s.prev.type==C.GRACE){s.prev.wl+=wlnote-4.5
  4091. s.wl=s.prev.wl}else{s.wl=wlw}
  4092. return
  4093. case C.SPACE:xx=s.width/2;s.wr=xx
  4094. if(s.a_gch)
  4095. xx=gchord_width(s,xx,xx)
  4096. if(s.a_dd)
  4097. xx=deco_width(s,xx)
  4098. s.wl=xx
  4099. return
  4100. case C.BAR:bar_type=s.bar_type
  4101. switch(bar_type){case"|":w=5
  4102. break
  4103. case"[":w=0
  4104. break
  4105. default:w=2+2.8*bar_type.length
  4106. for(i=0;i<bar_type.length;i++){switch(bar_type[i]){case"[":case"]":w+=1
  4107. case":":w+=2
  4108. break}}
  4109. break}
  4110. s.wl=w
  4111. if(s.next&&s.next.type!=C.METER)
  4112. s.wr=7
  4113. else
  4114. s.wr=5
  4115. if(s.invis)
  4116. s.wl=s.wr=2
  4117. s2=s.prev
  4118. if(s2&&s2.type==C.GRACE)
  4119. s.wl-=6
  4120. for(;s2;s2=s2.prev){if(w_tb[s2.type]){if(s2.type==C.STBRK)
  4121. s.wl-=12
  4122. break}}
  4123. if(s.a_dd)
  4124. s.wl=deco_width(s,s.wl)
  4125. if(s.text&&s.text.length<4&&s.next&&s.next.a_gch){set_font("repeat");s.wr+=strwh(s.text)[0]+2
  4126. if(cfmt.measurenb>0&s.bar_num&&s.bar_num%cfmt.measurenb)
  4127. s.wr+=4}
  4128. return
  4129. case C.CLEF:if(s.invis){s.wl=s.wr=1
  4130. return}
  4131. if(s.prev&&s.prev.type==C.STBRK){s.wl=6
  4132. s.wr=13
  4133. delete s.clef_small
  4134. return}
  4135. s.wl=s.clef_small?11:12
  4136. s.wr=s.clef_small?8:13
  4137. return
  4138. case C.KEY:if(s.invis){s.wl=s.wr=0
  4139. return}
  4140. s.wl=0
  4141. esp=3
  4142. n1=s.k_sf
  4143. if(s.k_old_sf&&(s.fmt.cancelkey||n1==0))
  4144. n2=s.k_old_sf
  4145. else
  4146. n2=0
  4147. if(n1*n2>=0){if(n1<0)
  4148. n1=-n1
  4149. if(n2<0)
  4150. n2=-n2
  4151. if(n2>n1)
  4152. n1=n2}else{n1-=n2
  4153. if(n1<0)
  4154. n1=-n1;esp+=3}
  4155. if(s.k_bagpipe=='p')
  4156. n1++
  4157. if(s.k_a_acc){n2=s.k_a_acc.length
  4158. if(s.exp)
  4159. n1=n2
  4160. else
  4161. n1+=n2
  4162. if(n2)
  4163. last_acc=s.k_a_acc[0].acc
  4164. for(i=1;i<n2;i++){acc=s.k_a_acc[i]
  4165. if(acc.pit>s.k_a_acc[i-1].pit+6||acc.pit<s.k_a_acc[i-1].pit-6)
  4166. n1--
  4167. else if(acc.acc!=last_acc)
  4168. esp+=3;last_acc=acc.acc}}
  4169. if(!n1)
  4170. break
  4171. s.wr=5.5*n1+esp
  4172. if(s.prev&&!s.prev.bar_type)
  4173. s.wl+=2
  4174. return
  4175. case C.METER:s.x_meter=[]
  4176. if(!s.a_meter.length)
  4177. break
  4178. wlw=0
  4179. for(i=0;i<s.a_meter.length;i++){meter=s.a_meter[i]
  4180. switch(meter.top[0]){case'C':case'c':case'o':s.x_meter[i]=wlw+6;wlw+=12
  4181. break
  4182. case'.':case'|':s.x_meter[i]=s.x_meter[i-1]
  4183. break
  4184. default:w=0
  4185. if(!meter.bot||meter.top.length>meter.bot.length)
  4186. meter=meter.top
  4187. else
  4188. meter=meter.bot;for(m=0;m<meter.length;m++){switch(meter[m]){case'(':wlw+=4
  4189. case')':case'1':w+=4
  4190. break
  4191. default:w+=12
  4192. break}}
  4193. s.x_meter[i]=wlw+w/2
  4194. wlw+=w}}
  4195. s.wl=1
  4196. s.wr=wlw+7
  4197. return
  4198. case C.MREST:s.wl=6;s.wr=66
  4199. return
  4200. case C.GRACE:if(s.invis)
  4201. break
  4202. s.wl=set_graceoffs(s);s.wr=0
  4203. if(s.a_ly)
  4204. ly_set(s)
  4205. return
  4206. case C.STBRK:s.wl=s.xmx
  4207. s.wr=8
  4208. return
  4209. case C.CUSTOS:s.wl=s.wr=4
  4210. return
  4211. case C.TEMPO:tempo_build(s)
  4212. break
  4213. case C.BLOCK:case C.REMARK:case C.STAVES:break
  4214. default:error(2,s,"set_width - Cannot set width for symbol $1",s.type)
  4215. break}
  4216. s.wl=s.wr=0}
  4217. function time2space(s,len){var i,l,space
  4218. if(smallest_duration>=C.BLEN/2){if(smallest_duration>=C.BLEN)
  4219. len/=4
  4220. else
  4221. len/=2}else if(!s.next&&len>=C.BLEN){len/=2}
  4222. if(len>=C.BLEN/4){if(len<C.BLEN/2)
  4223. i=5
  4224. else if(len<C.BLEN)
  4225. i=6
  4226. else if(len<C.BLEN*2)
  4227. i=7
  4228. else if(len<C.BLEN*4)
  4229. i=8
  4230. else
  4231. i=9}else{if(len>=C.BLEN/8)
  4232. i=4
  4233. else if(len>=C.BLEN/16)
  4234. i=3
  4235. else if(len>=C.BLEN/32)
  4236. i=2
  4237. else if(len>=C.BLEN/64)
  4238. i=1
  4239. else
  4240. i=0}
  4241. l=len-((C.BLEN/16/8)<<i)
  4242. space=cfmt.spatab[i]
  4243. if(l){if(l<0){space=cfmt.spatab[0]*len/(C.BLEN/16/8)}else{if(i>=9)
  4244. i=8
  4245. space+=(cfmt.spatab[i+1]-cfmt.spatab[i])*l/((C.BLEN/16/8)<<i)}}
  4246. return space}
  4247. function set_space(s,ptime){var space,len,s2,stemdir
  4248. len=s.time-ptime
  4249. if(!len){switch(s.type){case C.MREST:return s.wl}
  4250. return 0}
  4251. if(s.ts_prev.type==C.MREST)
  4252. return 71
  4253. space=time2space(s,len)
  4254. while(!s.dur){switch(s.type){case C.BAR:if(!s.next)
  4255. space*=.9
  4256. return space*.9-3
  4257. case C.CLEF:return space-s.wl-s.wr
  4258. case C.BLOCK:case C.REMARK:case C.STAVES:case C.TEMPO:s=s.ts_next
  4259. if(!s)
  4260. return space
  4261. continue}
  4262. break}
  4263. if(s.dur&&len<=C.BLEN/4){s2=s
  4264. while(s2){if(!s2.beam_st){space*=.9
  4265. break}
  4266. s2=s2.ts_next
  4267. if(!s2||s2.seqst)
  4268. break}}
  4269. if(s.type==C.NOTE&&s.nflags>=-1&&s.stem>0){stemdir=true
  4270. 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
  4271. break}}
  4272. 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
  4273. break}}
  4274. if(stemdir)
  4275. space*=.9}}
  4276. return space}
  4277. function set_sp_tup(s,s_et){var tim=s.time,ttim=s_et.time-tim,sp=time2space(s,ttim),s2=s,wsp=0
  4278. while(1){s2=s2.ts_next
  4279. if(s2.seqst){wsp+=s2.space
  4280. if(s2.bar_type)
  4281. wsp+=10}
  4282. if(s2==s_et)
  4283. break}
  4284. sp=(sp+wsp)/2/ttim
  4285. while(1){s=s.ts_next
  4286. if(s.seqst){s.space=sp*(s.time-tim)
  4287. tim=s.time}
  4288. if(s==s_et)
  4289. break}}
  4290. 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}}
  4291. function add_end_bar(s){var b=_bar(s),sn=s.ts_next
  4292. b.wl=0
  4293. b.wr=0
  4294. b.ts_prev=s
  4295. b.next=s.next
  4296. b.ts_next=s.ts_next
  4297. b.shrink=s.type==C.STBRK?0:(s.wr+3)
  4298. if(s.next)
  4299. s.next.prev=b
  4300. s.ts_next.ts_prev=b
  4301. s.next=s.ts_next=b
  4302. b.space=sn.space*.9-3
  4303. return b}
  4304. function set_allsymwidth(first){var val,st,s_chs,stup,itup,s=tsfirst,s2=s,xa=0,xl=[],wr=[],maxx=xa,tim=s.time
  4305. while(1){itup=0
  4306. do{if((s.a_gch||s.a_ly)&&!s_chs)
  4307. s_chs=s;self.set_width(s);st=s.st
  4308. if(xl[st]==undefined)
  4309. xl[st]=0
  4310. if(wr[st]==undefined)
  4311. wr[st]=0;val=xl[st]+wr[st]+s.wl
  4312. if(val>maxx)
  4313. maxx=val
  4314. if(s.dur&&s.dur!=s.notes[0].dur&&first)
  4315. itup=1
  4316. s=s.ts_next}while(s&&!s.seqst);s2.shrink=maxx-xa
  4317. s2.space=s2.ts_prev?set_space(s2,tim):0
  4318. if(s2.space==0&&s2.ts_prev&&s2.ts_prev.type==C.SPACE&&s2.ts_prev.seqst)
  4319. s2.space=s2.ts_prev.space/=2
  4320. if(itup){if(!stup)
  4321. stup=s2}else if(stup&&stup.v==s2.v){set_sp_tup(stup,s2)
  4322. stup=null}
  4323. if(!s2.shrink){if(s2.type==C.CLEF&&!s2.ts_prev.bar_type){delete s2.seqst;s2.time=tim}else{s2.shrink=10}}
  4324. tim=s2.time
  4325. if(!s)
  4326. break
  4327. s=s2
  4328. do{wr[s.st]=0
  4329. s=s.ts_next}while(!s.seqst)
  4330. xa=maxx
  4331. do{st=s2.st;xl[st]=xa
  4332. if(s2.wr>wr[st])
  4333. wr[st]=s2.wr
  4334. s2=s2.ts_next}while(!s2.seqst)}
  4335. if(stup)
  4336. set_sp_tup(stup,s2)
  4337. if(first&&s_chs)
  4338. set_w_chs(s_chs)}
  4339. function to_rest(so){var s=clone(so)
  4340. s.prev.next=so.ts_prev=so.prev=s.ts_prev.ts_next=s
  4341. s.next=s.ts_next=so
  4342. so.seqst=false
  4343. so.invis=so.play=true
  4344. s.type=C.REST
  4345. delete s.in_tuplet
  4346. delete s.tp
  4347. delete s.a_dd
  4348. delete s.a_gch
  4349. delete s.sls
  4350. return s}
  4351. function set_repeat(s){var s2,s3,i,j,dur,n=s.repeat_n,k=s.repeat_k,st=s.st,v=s.v
  4352. s.repeat_n=0
  4353. if(n<0){n=-n;i=n
  4354. for(s3=s.prev;s3;s3=s3.prev){if(!s3.dur){if(s3.type==C.BAR){error(1,s3,"Bar in repeat sequence")
  4355. return}
  4356. continue}
  4357. if(--i<=0)
  4358. break}
  4359. if(!s3){error(1,s,errs.not_enough_n)
  4360. return}
  4361. dur=s.time-s3.time;i=k*n
  4362. for(s2=s;s2;s2=s2.next){if(!s2.dur){if(s2.type==C.BAR){error(1,s2,"Bar in repeat sequence")
  4363. return}
  4364. continue}
  4365. if(--i<=0)
  4366. break}
  4367. if(!s2||!s2.next){error(1,s,errs.not_enough_n)
  4368. return}
  4369. for(s2=s.prev;s2!=s3;s2=s2.prev){if(s2.type==C.NOTE){s2.beam_end=true
  4370. break}}
  4371. for(j=k;--j>=0;){i=n
  4372. if(s.dur)
  4373. i--;s2=s.ts_next
  4374. while(i>0){if(s2.st==st){s2.invis=s2.play=true
  4375. if(s2.seqst&&s2.ts_next.seqst)
  4376. s2.seqst=false
  4377. if(s2.v==v&&s2.dur)
  4378. i--}
  4379. s2=s2.ts_next}
  4380. s=to_rest(s)
  4381. s.dur=s.notes[0].dur=dur;s.rep_nb=-1;s.beam_st=true;self.set_width(s)
  4382. s.head=C.SQUARE;for(s=s2;s;s=s.ts_next){if(s.st==st&&s.v==v&&s.dur)
  4383. break}}
  4384. return}
  4385. i=n
  4386. for(s2=s.prev.prev;s2;s2=s2.prev){if(s2.type==C.BAR||s2.time==tsfirst.time){if(--i<=0)
  4387. break}}
  4388. if(!s2){error(1,s,errs.not_enough_m)
  4389. return}
  4390. dur=s.time-s2.time
  4391. if(n==1)
  4392. i=k
  4393. else
  4394. i=n
  4395. for(s2=s;s2;s2=s2.next){if(s2.type==C.BAR){if(--i<=0)
  4396. break}}
  4397. if(!s2){error(1,s,errs.not_enough_m)
  4398. return}
  4399. i=k
  4400. if(n==2&&i>1){s2=s2.next
  4401. if(!s2){error(1,s,errs.not_enough_m)
  4402. return}
  4403. s2.repeat_n=n;s2.repeat_k=--i}
  4404. dur/=n
  4405. if(n==2){s3=s
  4406. for(s2=s.ts_next;;s2=s2.ts_next){if(s2.st!=st)
  4407. continue
  4408. if(s2.type==C.BAR){if(s2.v==v)
  4409. break
  4410. continue}
  4411. s2.invis=s2.play=true
  4412. if(s2.seqst&&s2.ts_next.seqst)
  4413. s2.seqst=false}
  4414. s3=to_rest(s3)
  4415. s3.dur=s3.notes[0].dur=dur;s3.invis=true
  4416. s2.bar_mrep=2
  4417. s3=s2.next;for(s2=s3.ts_next;;s2=s2.ts_next){if(s2.st!=st)
  4418. continue
  4419. if(s2.type==C.BAR){if(s2.v==v)
  4420. break
  4421. continue}
  4422. if(!s2.dur)
  4423. continue
  4424. s2.invis=s2.play=true
  4425. if(s2.seqst&&s2.ts_next.seqst)
  4426. s2.seqst=false}
  4427. s3=to_rest(s3)
  4428. s3.dur=s3.notes[0].dur=dur;s3.invis=true;self.set_width(s3)
  4429. return}
  4430. s3=s
  4431. for(j=k;--j>=0;){for(s2=s3.ts_next;;s2=s2.ts_next){if(s2.st!=st)
  4432. continue
  4433. if(s2.type==C.BAR){if(s2.v==v)
  4434. break
  4435. continue}
  4436. if(!s2.dur)
  4437. continue
  4438. s2.invis=s2.play=true
  4439. if(s2.seqst&&s2.ts_next.seqst)
  4440. s2.seqst=false}
  4441. s3=to_rest(s3)
  4442. s3.dur=s3.notes[0].dur=dur;s3.beam_st=true
  4443. if(k==1){s3.rep_nb=1
  4444. break}
  4445. s3.rep_nb=k-j+1;s3=s2.next}}
  4446. function custos_add(s){var p_voice,new_s,i,s2=s
  4447. while(1){if(s2.type==C.NOTE)
  4448. break
  4449. s2=s2.next
  4450. if(!s2)
  4451. return}
  4452. 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
  4453. new_s.wr=4
  4454. lktsym(new_s,s);new_s.shrink=s.shrink
  4455. if(new_s.shrink<8+4)
  4456. new_s.shrink=8+4;new_s.space=s2.space;new_s.head=C.FULL
  4457. new_s.stem=s2.stem
  4458. new_s.nhd=s2.nhd;new_s.notes=[]
  4459. for(i=0;i<s2.notes.length;i++){new_s.notes[i]={pit:s2.notes[i].pit,shhd:0,dur:C.BLEN/4}}
  4460. new_s.stemless=true}
  4461. function set_nl(s){var p_voice,done,tim,ptyp
  4462. function bardiv(so){var s,s1,s2,t1,t2,i
  4463. function new_type(s){var t=s.bar_type.match(/(:*)([^:]*)(:*)/)
  4464. if(!t[3]){t1=t[1]+t[2]
  4465. t2='['}else if(!t[1]){t1='||'
  4466. t2='[|'+t[3]}else{i=(t[2].length/2)|0
  4467. t1=t[1]+'|'+t[2].slice(0,i)
  4468. t2=t[2].slice(i)+'|'+t[3]}}
  4469. function eol_bar(s,so,sst){var s1,s2,s3
  4470. for(s1=so.ts_prev;s1.time==s.time;s1=s1.ts_prev){if(s1.v!=s.v)
  4471. continue
  4472. if(s1.bar_type){if(s1.bar_type!='|')
  4473. return
  4474. s2=s1
  4475. break}
  4476. if(!s3)
  4477. s3=s1.next}
  4478. if(!s2){s2=clone(s)
  4479. if(!s3)
  4480. s3=s
  4481. s2.next=s3
  4482. s2.prev=s3.prev
  4483. if(s2.prev)
  4484. s2.prev.next=s2
  4485. s3.prev=s2
  4486. s2.ts_prev=so.ts_prev
  4487. s2.ts_prev.ts_next=s2
  4488. s2.ts_next=so
  4489. so.ts_prev=s2
  4490. if(s==sst)
  4491. s2.seqst=1
  4492. if(s2.seqst){for(s=s2.ts_next;!s.seqst;s=s.ts_next);s2.shrink=s.shrink
  4493. s.shrink=s2.wr+s.wl
  4494. s2.space=s.space
  4495. s.space=0}
  4496. delete s2.part}
  4497. s2.bar_type="||"}
  4498. s=so
  4499. while(s&&s.time==so.time){if(s.bar_type&&s.bar_type.slice(-1)==':'){s2=s
  4500. break}
  4501. s=s.ts_next}
  4502. if(s2){s=s2
  4503. while(1){eol_bar(s2,so,s)
  4504. s2=s2.ts_next
  4505. if(!s2||s2.seqst)
  4506. break}
  4507. return so}
  4508. s=so
  4509. while(s.ts_prev&&s.ts_prev.time==so.time){s=s.ts_prev
  4510. if(s.bar_type)
  4511. s1=s
  4512. else if(!s1&&s.type==C.GRACE&&s.seqst)
  4513. so=s}
  4514. if(!s1||!s1.bar_type||(s1.bar_type.slice(-1)!=':'&&!s1.text))
  4515. return so
  4516. 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}
  4517. break}
  4518. s=s1
  4519. while(1){new_type(s1)
  4520. s2=clone(s1)
  4521. s2.bar_type=t1
  4522. s1.bar_type=t2
  4523. s2.ts_prev=so.ts_prev
  4524. s2.ts_prev.ts_next=s2
  4525. s2.ts_next=so
  4526. so.ts_prev=s2
  4527. if(s1==s)
  4528. s2.seqst=1
  4529. s2.next=s1
  4530. if(s2.prev)
  4531. s2.prev.next=s2
  4532. s1.prev=s2
  4533. if(s1.rbstop)
  4534. s2.rbstop=s1.rbstop
  4535. if(s1.text){s1.invis=1
  4536. delete s1.xsh
  4537. delete s2.text
  4538. delete s2.rbstart}
  4539. delete s2.part
  4540. delete s1.a_dd
  4541. do{s1=s1.ts_next}while(!s1.seqst&&!s1.bar_type)
  4542. if(s1.seqst)
  4543. break}
  4544. return so}
  4545. function set_eol(s){if(cfmt.custos&&voice_tb.length==1)
  4546. custos_add(s)
  4547. s.nl=true
  4548. s=s.ts_prev
  4549. if(s.type!=C.BAR)
  4550. add_end_bar(s)}
  4551. function do_warn(s){var s1,s2,s3,s4,w
  4552. for(s2=s;s2&&s2.time==s.time;s2=s2.ts_next){switch(s2.type){case C.KEY:if(!s.fmt.keywarn||s2.invis)
  4553. continue
  4554. for(s1=s.ts_prev;s1;s1=s1.ts_prev){if(s1.type!=C.METER)
  4555. break}
  4556. case C.METER:if(s2.type==C.METER){if(!s.fmt.timewarn)
  4557. continue
  4558. s1=s.ts_prev}
  4559. case C.CLEF:if(!s2.prev)
  4560. continue
  4561. if(s2.type==C.CLEF){if(s2.invis)
  4562. break
  4563. for(s1=s.ts_prev;s1;s1=s1.ts_prev){switch(s1.type){case C.BAR:if(s1.bar_type[0]==':')
  4564. break
  4565. case C.KEY:case C.METER:continue}
  4566. break}}
  4567. s3=clone(s2)
  4568. lktsym(s3,s1.ts_next)
  4569. s1=s3
  4570. while(1){s1=s1.ts_next
  4571. if(s1.v==s2.v)
  4572. break}
  4573. lkvsym(s3,s1)
  4574. if(s3.seqst){self.set_width(s3)
  4575. s3.shrink=s3.wl
  4576. s4=s3.ts_prev
  4577. w=0
  4578. while(1){if(s4.wr>w)
  4579. w=s4.wr
  4580. if(s4.seqst)
  4581. break
  4582. s4=s4.ts_prev}
  4583. s3.shrink+=w
  4584. s3.space=0
  4585. s4=s3
  4586. while(1){if(s4.ts_next.seqst)
  4587. break
  4588. s4=s4.ts_next}
  4589. w=0
  4590. while(1){if(s4.wl>w)
  4591. w=s4.wl
  4592. s4=s4.ts_next
  4593. if(s4.seqst)
  4594. break}
  4595. s4.shrink=s3.wr+w}
  4596. delete s3.part
  4597. continue}
  4598. if(w_tb[s2.type])
  4599. break}}
  4600. s=bardiv(s)
  4601. do_warn(s)
  4602. if(s.ts_prev.type!=C.STAVES){set_eol(s)
  4603. return s}
  4604. for(s=s.ts_prev;s;s=s.ts_prev){if(s.seqst&&s.type!=C.CLEF)
  4605. break}
  4606. done=0
  4607. ptyp=s.type
  4608. for(;;s=s.ts_next){if(!s)
  4609. return s
  4610. if(s.type==ptyp)
  4611. continue
  4612. ptyp=s.type
  4613. if(done<0)
  4614. break
  4615. switch(s.type){case C.STAVES:if(!s.ts_prev)
  4616. return
  4617. if(s.ts_prev.type==C.BAR)
  4618. break
  4619. while(s.ts_next){if(w_tb[s.ts_next.type]&&s.ts_next.type!=C.CLEF)
  4620. break
  4621. s=s.ts_next}
  4622. if(!s.ts_next||s.ts_next.type!=C.BAR)
  4623. continue
  4624. s=s.ts_next
  4625. case C.BAR:if(done)
  4626. break
  4627. done=1;continue
  4628. case C.STBRK:if(!s.stbrk_forced)
  4629. unlksym(s)
  4630. else
  4631. done=-1
  4632. continue
  4633. case C.CLEF:if(done)
  4634. break
  4635. continue
  4636. default:if(!done||(s.prev&&s.prev.type==C.GRACE))
  4637. continue
  4638. break}
  4639. break}
  4640. set_eol(s)
  4641. return s}
  4642. function get_ck_width(){var r0,r1,p_voice=voice_tb[0]
  4643. self.set_width(p_voice.clef);self.set_width(p_voice.ckey);self.set_width(p_voice.meter)
  4644. return[p_voice.clef.wl+p_voice.clef.wr+
  4645. p_voice.ckey.wl+p_voice.ckey.wr,p_voice.meter.wl+p_voice.meter.wr]}
  4646. function get_width(s,next){var shrink,space,w=0,wmx=0,sp_fac=(1-s.fmt.maxshrink)
  4647. while(s!=next){if(s.seqst){shrink=s.shrink
  4648. wmx+=shrink
  4649. if((space=s.space)<shrink)
  4650. w+=shrink
  4651. else
  4652. w+=shrink*s.fmt.maxshrink
  4653. +space*sp_fac
  4654. s.x=w}
  4655. s=s.ts_next}
  4656. if(next)
  4657. wmx+=next.wr
  4658. return[w,wmx]}
  4659. 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)
  4660. if(s.fmt.keywarn&&next&&next.type==C.KEY&&!last.dur){ws[0]+=next.wr
  4661. ws[1]+=next.wr}
  4662. if(ws[0]+indent<lwidth){if(next)
  4663. next=set_nl(next)
  4664. return next||last}
  4665. wwidth=ws[0]+indent
  4666. while(1){nlines=Math.ceil(wwidth/lwidth)
  4667. if(nlines<=1){if(next)
  4668. next=set_nl(next)
  4669. return next||last}
  4670. 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)
  4671. continue
  4672. if(s.type==C.BAR)
  4673. s2=s
  4674. if(s.x>=xmin)
  4675. break}
  4676. s4=s
  4677. if(s==next){if(s)
  4678. s=set_nl(s)
  4679. return s}
  4680. s3=null
  4681. for(;s!=next;s=s.ts_next){x=s.x
  4682. if(!x)
  4683. continue
  4684. if(x>xmax)
  4685. break
  4686. if(s.type!=C.BAR)
  4687. continue
  4688. if(x<xmid){s3=s
  4689. continue}
  4690. if(!s3||x-xmid<xmid-s3.x)
  4691. s3=s
  4692. break}
  4693. if(!s3){s=s4
  4694. var beam=0,bar_time=s2.time
  4695. xmax-=8;s5=s
  4696. for(;s!=next;s=s.ts_next){if(s.seqst){x=s.x
  4697. if(x+s.wr>=xmax)
  4698. break
  4699. if(!beam&&!s.in_tuplet&&(xmid-s5.x>x-xmid||(s.time-bar_time)%(C.BLEN/4)==0))
  4700. s3=s}
  4701. if(s.beam_st)
  4702. beam|=1<<s.v
  4703. if(s.beam_end)
  4704. beam&=~(1<<s.v)
  4705. s5=s}
  4706. if(s3){do{s3=s3.ts_prev}while(!s3.seqst)}}
  4707. if(!s3){s3=s=s4
  4708. for(;s!=next;s=s.ts_next){x=s.x
  4709. if(!x)
  4710. continue
  4711. if(x+s.wr>=xmax)
  4712. break
  4713. if(s3&&x>=xmid){if(xmid-s3.x>x-xmid)
  4714. s3=s
  4715. break}
  4716. s3=s}}
  4717. s=s3
  4718. while(s.ts_next){s=s.ts_next
  4719. if(s.seqst)
  4720. break}
  4721. if(s.nl){error(0,s,"Line split problem - adjust maxshrink and/or breaklimit");nlines=2
  4722. for(s=s.ts_next;s!=next;s=s.ts_next){if(!s.x)
  4723. continue
  4724. if(--nlines<=0)
  4725. break}}
  4726. s=set_nl(s)
  4727. if(!s||(next&&s.time>=next.time))
  4728. break
  4729. wwidth-=s.x-first.x;indent=0}
  4730. return s}
  4731. 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
  4732. lwidth-=lsh[1]
  4733. if(cfmt.indent&&cfmt.indent>lsh[0])
  4734. indent+=cfmt.indent
  4735. lwidth-=ckw[0]
  4736. indent+=ckw[1]
  4737. if(cfmt.custos&&voice_tb.length==1)
  4738. lwidth-=12
  4739. i=s.fmt.barsperstaff
  4740. if(i){for(s2=s;s2;s2=s2.ts_next){if(s2.type!=C.BAR||!s2.bar_num||--i>0)
  4741. continue
  4742. while(s2.ts_next&&s2.ts_next.type==C.BAR)
  4743. s2=s2.ts_next
  4744. if(s2.ts_next)
  4745. s2.ts_next.soln=true
  4746. i=s.fmt.barsperstaff}}
  4747. s2=s
  4748. 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)
  4749. self.set_format(s.subtype,s.param)
  4750. break
  4751. case"mc_start":mc={lm:cfmt.leftmargin,rm:cfmt.rightmargin}
  4752. break
  4753. case"mc_new":case"mc_end":if(!mc)
  4754. break
  4755. cfmt.leftmargin=mc.lm
  4756. cfmt.rightmargin=mc.rm
  4757. img.chg=1
  4758. break}}
  4759. if(!s.ts_next){s=null}else if(!s.soln){continue}else{s.soln=false
  4760. if(s.time==s2.time)
  4761. continue
  4762. while(!s.seqst)
  4763. s=s.ts_prev}
  4764. set_page()
  4765. lwidth=get_lwidth()-lsh[1]-ckw[0]
  4766. s2=set_lines(s2,s,lwidth,indent)
  4767. if(!s2)
  4768. break
  4769. s=s2.type==C.BLOCK?s2.ts_prev:s
  4770. indent=0}
  4771. cfmt.leftmargin=pg_sav.leftmargin
  4772. cfmt.rightmargin=pg_sav.rightmargin
  4773. cfmt.pagewidth=pg_sav.pagewidth
  4774. cfmt.scale=pg_sav.scale
  4775. img.chg=1
  4776. set_page()}
  4777. function set_yval(s){switch(s.type){case C.CLEF:if(s.second||s.invis){s.ymx=s.ymn=12
  4778. break}
  4779. s.y=(s.clef_line-1)*6
  4780. switch(s.clef_type){default:s.ymx=s.y+28
  4781. s.ymn=s.y-14
  4782. break
  4783. case"c":s.ymx=s.y+13
  4784. s.ymn=s.y-11
  4785. break
  4786. case"b":s.ymx=s.y+7
  4787. s.ymn=s.y-12
  4788. break}
  4789. if(s.clef_small){s.ymx-=2;s.ymn+=2}
  4790. if(s.ymx<26)
  4791. s.ymx=26
  4792. if(s.ymn>-1)
  4793. s.ymn=-1
  4794. if(s.clef_octave){if(s.clef_octave>0)
  4795. s.ymx+=12
  4796. else
  4797. s.ymn-=12}
  4798. break
  4799. case C.KEY:if(s.k_sf>2)
  4800. s.ymx=24+10
  4801. else if(s.k_sf>0)
  4802. s.ymx=24+6
  4803. else
  4804. s.ymx=24+2;s.ymn=-2
  4805. break
  4806. default:s.ymx=24;s.ymn=0
  4807. break}}
  4808. function set_ottava(){var s,s1,st,o,d,m=nstaff+1,staff_d=new Int8Array(m)
  4809. function sym_ott(s,d){var g,m,note
  4810. switch(s.type){case C.REST:if(voice_tb.length==1)
  4811. break
  4812. case C.NOTE:if(!s.p_v.ckey.k_drum){for(m=s.nhd;m>=0;m--){note=s.notes[m];if(!note.opit)
  4813. note.opit=note.pit;note.pit+=d}}
  4814. break
  4815. 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]
  4816. if(!note.opit)
  4817. note.opit=note.pit
  4818. note.pit+=d}}}
  4819. break}}
  4820. function deco_rm(s){for(var i=s.a_dd.length;--i>=0;){if(s.a_dd[i].name.match(/1?[85][vm][ab]/))
  4821. s.a_dd.splice(i,1)}}
  4822. for(s=tsfirst;s;s=s.ts_next){st=s.st
  4823. o=s.ottava
  4824. if(o){if(o[0]){if(staff_d[st]&&!o[1]){sym_ott(s,staff_d[st])
  4825. deco_rm(s)
  4826. continue}}else if(!staff_d[st]){deco_rm(s)
  4827. continue}
  4828. s1=s
  4829. while(s1&&!s1.seqst)
  4830. s1=s1.ts_prev
  4831. if(s1){while(s1!=s){if(s1.st==st){if(o[1])
  4832. sym_ott(s1,-staff_d[st])
  4833. if(o[0])
  4834. sym_ott(s1,-o[0]*7)}
  4835. s1=s1.ts_next}}
  4836. if(o[0]){staff_d[st]=-o[0]*7}else{staff_d[st]=0}}
  4837. if(staff_d[st])
  4838. sym_ott(s,staff_d[st])}}
  4839. function mrest_expand(){var s,s2
  4840. function mexp(s){var bar,s3,s4,tim,nbar,nb=s.nmes,dur=s.dur/nb,s2=s.next
  4841. while(!s2.bar_type)
  4842. s2=s2.next
  4843. bar=s2
  4844. while(!s2.bar_num)
  4845. s2=s2.ts_prev
  4846. nbar=s2.bar_num-s.nmes
  4847. s.type=C.REST
  4848. s.notes[0].dur=s.dur=s.dur_orig=dur
  4849. s.nflags=-2
  4850. s.head=C.FULL
  4851. s.fmr=1
  4852. tim=s.time+dur
  4853. s3=s
  4854. while(--nb>0){s2=clone(bar)
  4855. delete s2.soln
  4856. delete s2.a_gch
  4857. delete s2.a_dd
  4858. delete s2.text
  4859. delete s2.rbstart
  4860. delete s2.rbstop
  4861. lkvsym(s2,s.next)
  4862. s2.time=tim
  4863. while(s3.time<tim)
  4864. s3=s3.ts_next
  4865. while(s3&&s3.v<s.v&&s3.type==C.BAR)
  4866. s3=s3.ts_next
  4867. if(s3){if(s3.bar_type)
  4868. s3.seqst=0
  4869. lktsym(s2,s3)
  4870. if(s3.type==C.BAR)
  4871. delete s3.bar_num}else{s3=s
  4872. while(s3.ts_next)
  4873. s3=s3.ts_next
  4874. s3.ts_next=s2
  4875. s2.ts_prev=s3
  4876. s2.ts_next=null}
  4877. nbar++
  4878. if(s2.seqst){s2.bar_num=nbar
  4879. s4=s2.ts_next}else{delete s2.bar_num
  4880. s4=s2.ts_prev}
  4881. s2.bar_type=s4.bar_type||"|"
  4882. if(s4.bar_num&&!s4.seqst)
  4883. delete s4.bar_num
  4884. s4=clone(s)
  4885. delete s4.a_dd
  4886. delete s4.soln
  4887. delete s4.a_gch
  4888. delete s4.part
  4889. if(s2.next){s4.next=s2.next
  4890. s4.next.prev=s4}else{s4.next=null}
  4891. s2.next=s4
  4892. s4.prev=s2
  4893. s4.time=tim
  4894. while(s3&&!s3.dur&&s3.time==tim)
  4895. s3=s3.ts_next
  4896. while(s3&&s3.v<s.v){s3=s3.ts_next
  4897. if(s3&&s3.seqst)
  4898. break}
  4899. if(s3){if(s3.dur)
  4900. s3.seqst=0
  4901. lktsym(s4,s3)}else{s3=s
  4902. while(s3.ts_next)
  4903. s3=s3.ts_next
  4904. s3.ts_next=s4
  4905. s4.ts_prev=s3
  4906. s4.ts_next=null}
  4907. tim+=dur
  4908. s=s3=s4}}
  4909. for(s=tsfirst;s;s=s.ts_next){if(s.type!=C.MREST)
  4910. continue
  4911. if(!s.seqst&&w_tb[s.ts_prev.type]){s2=s}else{s2=s.ts_next
  4912. while(!s2.seqst){if(s2.type!=C.MREST||s2.nmes!=s.nmes)
  4913. break
  4914. s2=s2.ts_next}}
  4915. if(!s2.seqst){while(s.type==C.MREST){mexp(s)
  4916. s=s.ts_next}}else{s=s2.ts_prev}}}
  4917. function set_auto_clef(st,s_start,clef_type_start){var s,time,s2,s3,max=12,min=20
  4918. for(s=s_start;s;s=s.ts_next){if(s.type==C.STAVES&&s!=s_start)
  4919. break
  4920. if(s.st!=st)
  4921. continue
  4922. if(s.type!=C.NOTE){if(s.type==C.CLEF){if(s.clef_type!='a')
  4923. break
  4924. unlksym(s)}
  4925. continue}
  4926. if(s.notes[0].pit<min)
  4927. min=s.notes[0].pit
  4928. if(s.notes[s.nhd].pit>max)
  4929. max=s.notes[s.nhd].pit}
  4930. if(min>=19||(min>=13&&clef_type_start!='b'))
  4931. return't'
  4932. if(max<=13||(max<=19&&clef_type_start!='t'))
  4933. return'b'
  4934. if(clef_type_start=='a'){if((max+min)/2>=16)
  4935. clef_type_start='t'
  4936. else
  4937. clef_type_start='b'}
  4938. var clef_type=clef_type_start,s_last=s,s_last_chg=null
  4939. for(s=s_start;s!=s_last;s=s.ts_next){if(s.type==C.STAVES&&s!=s_start)
  4940. break
  4941. if(s.st!=st||s.type!=C.NOTE)
  4942. continue
  4943. time=s.time
  4944. if(clef_type=='t'){if(s.notes[0].pit>12||s.notes[s.nhd].pit>20){if(s.notes[0].pit>20)
  4945. s_last_chg=s
  4946. continue}
  4947. s2=s.ts_prev
  4948. if(s2&&s2.time==time&&s2.st==st&&s2.type==C.NOTE&&s2.notes[0].pit>=19)
  4949. continue
  4950. s2=s.ts_next
  4951. if(s2&&s2.st==st&&s2.time==time&&s2.type==C.NOTE&&s2.notes[0].pit>=19)
  4952. continue}else{if(s.notes[0].pit<=12||s.notes[s.nhd].pit<20){if(s.notes[s.nhd].pit<=12)
  4953. s_last_chg=s
  4954. continue}
  4955. s2=s.ts_prev
  4956. if(s2&&s2.time==time&&s2.st==st&&s2.type==C.NOTE&&s2.notes[0].pit<=13)
  4957. continue
  4958. s2=s.ts_next
  4959. if(s2&&s2.st==st&&s2.time==time&&s2.type==C.NOTE&&s2.notes[0].pit<=13)
  4960. continue}
  4961. if(!s_last_chg){clef_type=clef_type_start=clef_type=='t'?'b':'t';s_last_chg=s
  4962. continue}
  4963. s3=s
  4964. for(s2=s.ts_prev;s2!=s_last_chg;s2=s2.ts_prev){if(s2.st!=st)
  4965. continue
  4966. if(s2.type==C.BAR){s3=s2.bar_type[0]!=':'?s2:s2.next
  4967. break}
  4968. if(s2.type!=C.NOTE)
  4969. continue
  4970. if(s2.beam_st&&!s2.p_v.second)
  4971. s3=s2}
  4972. if(s3.time==s_last_chg.time){s_last_chg=s
  4973. continue}
  4974. 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}
  4975. return clef_type_start}
  4976. 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=[]
  4977. staff_tb=new Array(nstaff+1)
  4978. for(st=0;st<=nstaff;st++){staff_clef[st]={autoclef:true}
  4979. staff_tb[st]={output:"",sc_out:""}}
  4980. for(st=0;st<=sy.nstaff;st++)
  4981. mid[st]=(sy.staves[st].stafflines.length-1)*3
  4982. for(s=tsfirst;s;s=s.ts_next){if(s.repeat_n)
  4983. set_repeat(s)
  4984. switch(s.type){case C.STAVES:sy=s.sy
  4985. for(st=0;st<=nstaff;st++)
  4986. staff_clef[st].autoclef=true
  4987. for(v=0;v<voice_tb.length;v++){if(!sy.voices[v])
  4988. continue
  4989. p_voice=voice_tb[v];st=sy.voices[v].st
  4990. if(!sy.voices[v].second){sy.staves[st].staffnonote=p_voice.staffnonote
  4991. if(p_voice.staffscale)
  4992. sy.staves[st].staffscale=p_voice.staffscale
  4993. if(sy.voices[v].sep)
  4994. sy.staves[st].sep=sy.voices[v].sep
  4995. if(sy.voices[v].maxsep)
  4996. sy.staves[st].maxsep=sy.voices[v].maxsep}
  4997. s2=p_voice.clef
  4998. if(!s2.clef_auto)
  4999. staff_clef[st].autoclef=false}
  5000. for(st=0;st<=sy.nstaff;st++)
  5001. mid[st]=(sy.staves[st].stafflines.length-1)*3
  5002. for(v=0;v<voice_tb.length;v++){if(!sy.voices[v]||sy.voices[v].second)
  5003. continue
  5004. p_voice=voice_tb[v];st=sy.voices[v].st;s2=p_voice.clef
  5005. 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}
  5006. if(!staff_clef[st].clef){if(s2.clef_auto){if(s2.clef_type!='a')
  5007. p_voice.clef=clone(p_voice.clef);p_voice.clef.clef_type=new_type;p_voice.clef.clef_line=new_line}
  5008. staff_tb[st].clef=staff_clef[st].clef=p_voice.clef
  5009. continue}
  5010. if(new_type==staff_clef[st].clef.clef_type&&new_line==staff_clef[st].clef.clef_line)
  5011. continue
  5012. g=s.ts_prev
  5013. while(g&&g.time==s.time&&(g.v!=v||g.st!=st))
  5014. g=g.ts_prev
  5015. if(!g||g.time!=s.time){g=s.ts_next
  5016. while(g&&(g.v!=v||g.st!=st))
  5017. g=g.ts_next
  5018. if(!g||g.time!=s.time)
  5019. g=s}
  5020. if(g.type!=C.CLEF){g=insert_clef(g,new_type,new_line)
  5021. if(s2.clef_auto)
  5022. g.clef_auto=true}
  5023. staff_clef[st].clef=p_voice.clef=g}
  5024. continue
  5025. default:s.mid=mid[s.st]
  5026. continue
  5027. case C.CLEF:break}
  5028. 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}
  5029. p_voice=s.p_v;p_voice.clef=s
  5030. if(s.second){unlksym(s)
  5031. continue}
  5032. st=s.st
  5033. 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}
  5034. staff_clef[st].clef=s}
  5035. sy=cur_sy
  5036. for(v=0;v<voice_tb.length;v++){if(!sy.voices[v])
  5037. continue
  5038. s2=voice_tb[v].sym
  5039. if(!s2||s2.notes[0].pit!=127)
  5040. continue
  5041. st=sy.voices[v].st
  5042. switch(staff_tb[st].clef.clef_type){default:pit=22
  5043. break
  5044. case"c":pit=16
  5045. break
  5046. case"b":pit=10
  5047. break}
  5048. for(s=s2;s;s=s.next)
  5049. s.notes[0].pit=pit}}
  5050. var delta_tb={t:0-2*2,c:6-3*2,b:12-4*2,p:0-3*2}
  5051. var rest_sp=[[18,18],[12,18],[12,12],[6,12],[6,8],[10,10],[6,4],[10,0],[10,4],[10,10]]
  5052. 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(m*2),sy=cur_sy
  5053. for(st=0;st<=nstaff;st++){s=staff_tb[st].clef;staff_delta[st]=delta_tb[s.clef_type]+s.clef_line*2
  5054. if(s.clefpit)
  5055. staff_delta[st]+=s.clefpit
  5056. if(cfmt.sound){if(s.clef_octave&&!s.clef_oct_transp)
  5057. staff_delta[st]+=s.clef_octave}else{if(s.clef_oct_transp)
  5058. staff_delta[st]-=s.clef_octave}}
  5059. for(s=tsfirst;s!=last_s;s=s.ts_next){st=s.st
  5060. switch(s.type){case C.CLEF:staff_delta[st]=delta_tb[s.clef_type]+
  5061. s.clef_line*2
  5062. if(s.clefpit)
  5063. staff_delta[st]+=s.clefpit
  5064. if(cfmt.sound){if(s.clef_octave&&!s.clef_oct_transp)
  5065. staff_delta[st]+=s.clef_octave}else{if(s.clef_oct_transp)
  5066. staff_delta[st]-=s.clef_octave}
  5067. set_yval(s)
  5068. break
  5069. case C.GRACE:for(g=s.extra;g;g=g.next){delta=staff_delta[g.st]
  5070. if(delta&&!s.p_v.ckey.k_drum){for(m=0;m<=g.nhd;m++){note=g.notes[m];note.opit=note.pit
  5071. note.pit+=delta}}
  5072. g.ymn=3*(g.notes[0].pit-18)-2;g.ymx=3*(g.notes[g.nhd].pit-18)+2}
  5073. set_yval(s)
  5074. break
  5075. case C.KEY:s.k_y_clef=staff_delta[st]
  5076. default:set_yval(s)
  5077. break
  5078. case C.MREST:if(s.invis)
  5079. break
  5080. s.y=12;s.ymx=24+15;s.ymn=-2
  5081. break
  5082. case C.REST:if(s.rep_nb>1||s.bar_mrep){s.y=12
  5083. s.ymx=38
  5084. s.ymn=0
  5085. break}
  5086. if(voice_tb.length==1){s.y=12;s.ymx=24;s.ymn=0
  5087. break}
  5088. case C.NOTE:delta=staff_delta[st]
  5089. if(delta&&!s.p_v.ckey.k_drum){for(m=s.nhd;m>=0;m--){note=s.notes[m]
  5090. note.opit=note.pit
  5091. note.pit+=delta}}
  5092. 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]}
  5093. if(s.dur<dur)
  5094. dur=s.dur
  5095. break}}
  5096. if(!last_s)
  5097. smallest_duration=dur}
  5098. 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
  5099. while(s){for(st=0;st<=nst;st++)
  5100. st_v_tb[st]=[]
  5101. v_st_tb=[]
  5102. for(u=s;u;u=u.ts_next){if(u.type==C.BAR)
  5103. break;if(u.type==C.STAVES){if(u!=s)
  5104. break
  5105. sy=s.sy
  5106. for(st=nst;st<=sy.nstaff;st++)
  5107. st_v_tb[st]=[]
  5108. nst=sy.nstaff
  5109. continue}
  5110. if((u.type!=C.NOTE&&u.type!=C.REST)||u.invis)
  5111. continue
  5112. 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)}
  5113. v=u.v;v_st=v_st_tb[v]
  5114. if(!v_st){v_st={st1:-1,st2:-1}
  5115. v_st_tb[v]=v_st}
  5116. 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)
  5117. v_st.st2=st}else{if(v_st.st1>v_st.st2)
  5118. v_st.st2=v_st.st1;v_st.st1=st}}
  5119. st_v=st_v_tb[st];rvoice=sy.voices[v].range;for(i=st_v.length;--i>=0;){vobj=st_v[i]
  5120. if(vobj.v==rvoice)
  5121. break}
  5122. if(i<0){vobj={v:rvoice,ymx:0,ymn:24}
  5123. for(i=0;i<st_v.length;i++){if(rvoice<st_v[i].v){st_v.splice(i,0,vobj)
  5124. break}}
  5125. if(i==st_v.length)
  5126. st_v.push(vobj)}
  5127. if(u.type!=C.NOTE)
  5128. continue
  5129. if(u.ymx>vobj.ymx)
  5130. vobj.ymx=u.ymx
  5131. if(u.ymn<vobj.ymn)
  5132. vobj.ymn=u.ymn
  5133. 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}}}
  5134. for(;s!=u;s=s.ts_next){if(s.multi)
  5135. continue
  5136. switch(s.type){default:continue
  5137. 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)
  5138. break
  5139. if(s.ts_next.a_dd)
  5140. s.a_dd=s.ts_next.a_dd
  5141. if(s.ts_next.a_gch)
  5142. s.a_gch=s.ts_next.a_gch
  5143. unlksym(s.ts_next)
  5144. break
  5145. case C.NOTE:case C.GRACE:break}
  5146. st=s.st;v=s.v;v_st=v_st_tb[v];st_v=st_v_tb[st]
  5147. if(v_st&&v_st.st2>=0){if(st==v_st.st1)
  5148. s.multi=-1
  5149. else if(st==v_st.st2)
  5150. s.multi=1
  5151. continue}
  5152. if(st_v.length<=1){if(s.floating)
  5153. s.multi=st==voice_tb[v].st?-1:1
  5154. continue}
  5155. rvoice=sy.voices[v].range
  5156. for(i=st_v.length;--i>=0;){if(st_v[i].v==rvoice)
  5157. break}
  5158. if(i<0)
  5159. continue
  5160. if(i==st_v.length-1){s.multi=-1}else{s.multi=1
  5161. if(i&&i+2==st_v.length){if(st_v[i].ymn-s.fmt.stemheight>=st_v[i+1].ymx)
  5162. s.multi=-1;t=s.ts_next
  5163. 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))
  5164. s.multi=-1}}}
  5165. while(s&&s.type==C.BAR)
  5166. s=s.ts_next}}
  5167. 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
  5168. for(s=tsfirst;s;s=s.ts_next){if(s.invis)
  5169. continue
  5170. if(s.type==C.STAVES)
  5171. sy=s.sy
  5172. if(!s.dur)
  5173. continue
  5174. v_s=v_s_tb[s.v]
  5175. if(!v_s){v_s={}
  5176. v_s_tb[s.v]=v_s}
  5177. v_s.s=s;v_s.st=s.st;v_s.end_time=s.time+s.dur
  5178. if(s.type!=C.REST)
  5179. continue
  5180. ymin=-127;ymax=127;not_alone=dots=false
  5181. for(v=0;v<=v_s_tb.length;v++){v_s=v_s_tb[v]
  5182. if(!v_s||!v_s.s||v_s.st!=s.st||v==s.v)
  5183. continue
  5184. if(v_s.end_time<=s.time)
  5185. continue
  5186. not_alone=true;s2=v_s.s
  5187. if(sy.voices[v].range<sy.voices[s.v].range){if(s2.time==s.time){if(s2.ymn<ymax){ymax=s2.ymn
  5188. if(s2.dots)
  5189. dots=true}}else{if(s2.y<ymax)
  5190. ymax=s2.y}}else{if(s2.time==s.time){if(s2.ymx>ymin){ymin=s2.ymx
  5191. if(s2.dots)
  5192. dots=true}}else{if(s2.y>ymin)
  5193. ymin=s2.y}}}
  5194. end_time=s.time+s.dur
  5195. for(s2=s.ts_next;s2;s2=s2.ts_next){if(s2.time>=end_time)
  5196. break
  5197. if(s2.st!=s.st||!s2.dur||s2.invis)
  5198. continue
  5199. not_alone=true
  5200. if(sy.voices[s2.v].range<sy.voices[s.v].range){if(s2.time==s.time){if(s2.ymn<ymax){ymax=s2.ymn
  5201. if(s2.dots)
  5202. dots=true}}else{if(s2.y<ymax)
  5203. ymax=s2.y}}else{if(s2.time==s.time){if(s2.ymx>ymin){ymin=s2.ymx
  5204. if(s2.dots)
  5205. dots=true}}else{if(s2.y>ymin)
  5206. ymin=s2.y}}}
  5207. if(!not_alone){s.y=12;s.ymx=24;s.ymn=0
  5208. continue}
  5209. if(ymax==127&&s.y<12){shift=12-s.y
  5210. s.y+=shift;s.ymx+=shift;s.ymn+=shift}
  5211. if(ymin==-127&&s.y>12){shift=s.y-12
  5212. s.y-=shift;s.ymx-=shift;s.ymn-=shift}
  5213. shift=ymax-s.ymx
  5214. if(shift<0){shift=Math.ceil(-shift/6)*6
  5215. if(s.ymn-shift>=ymin){s.y-=shift;s.ymx-=shift;s.ymn-=shift
  5216. continue}
  5217. dx=dots?15:10;s.notes[0].shhd=dx;s.xmx=dx
  5218. continue}
  5219. shift=ymin-s.ymn
  5220. if(shift>0){shift=Math.ceil(shift/6)*6
  5221. if(s.ymx+shift<=ymax){s.y+=shift;s.ymx+=shift;s.ymn+=shift
  5222. continue}
  5223. dx=dots?15:10;s.notes[0].shhd=dx;s.xmx=dx
  5224. continue}}}
  5225. function new_sym(s,p_v,last_s){s.p_v=p_v
  5226. s.v=p_v.v
  5227. s.st=p_v.st
  5228. s.time=last_s.time
  5229. if(p_v.last_sym){s.next=p_v.last_sym.next
  5230. if(s.next)
  5231. s.next.prev=s;p_v.last_sym.next=s;s.prev=p_v.last_sym}
  5232. p_v.last_sym=s;lktsym(s,last_s)}
  5233. 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
  5234. for(v=0;v<nv;v++){if(!cur_sy.voices[v])
  5235. continue
  5236. p_voice=voice_tb[v];p_voice.st=cur_sy.voices[v].st
  5237. 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
  5238. break
  5239. case C.KEY:s.p_v.ckey=s
  5240. break
  5241. case C.METER:s.p_v.meter=s
  5242. insert_meter=cfmt.writefields.indexOf('M')>=0&&s.a_meter.length
  5243. break}
  5244. if(s.part)
  5245. s.next.part=s.part
  5246. unlksym(s)
  5247. case C.TEMPO:case C.BLOCK:case C.REMARK:continue}
  5248. break}}
  5249. last_s=tsfirst
  5250. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  5251. if(!cur_sy.voices[v]||(cur_sy.voices[v].second&&!p_voice.bar_start))
  5252. continue
  5253. st=cur_sy.voices[v].st
  5254. if(!staff_tb[st]||!staff_tb[st].clef)
  5255. continue
  5256. 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
  5257. if(s.next)
  5258. s.next.prev=s;p_voice.sym=p_voice.last_sym=s
  5259. s.ts_next=last_s;if(last_s)
  5260. s.ts_prev=last_s.ts_prev
  5261. else
  5262. s.ts_prev=null
  5263. if(!s.ts_prev){tsfirst=s}else{s.ts_prev.ts_next=s
  5264. delete s.seqst}
  5265. if(last_s)
  5266. last_s.ts_prev=s
  5267. delete s.clef_small;delete s.part
  5268. s.second=cur_sy.voices[v].second
  5269. if(!cur_sy.st_print[st])
  5270. s.invis=true
  5271. else
  5272. delete s.invis
  5273. s.fmt=fmt}
  5274. 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])
  5275. continue
  5276. p_voice=voice_tb[v]
  5277. s2=p_voice.ckey
  5278. if(s2.k_sf||s2.k_a_acc){s=clone(s2)
  5279. new_sym(s,p_voice,last_s)
  5280. delete s.invis
  5281. delete s.part
  5282. s.k_old_sf=s2.k_sf
  5283. s.fmt=fmt}}
  5284. if(insert_meter){for(v=0;v<nv;v++){p_voice=voice_tb[v];s2=p_voice.meter
  5285. if(!cur_sy.voices[v]||cur_sy.voices[v].second||!cur_sy.st_print[cur_sy.voices[v].st])
  5286. continue
  5287. s=clone(s2)
  5288. new_sym(s,p_voice,last_s)
  5289. delete s.part
  5290. s.fmt=fmt}
  5291. insert_meter=false}
  5292. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  5293. 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}
  5294. new_sym(s,p_voice,last_s)
  5295. p_voice.sls=[]}}
  5296. for(v=0;v<nv;v++){p_voice=voice_tb[v];s2=p_voice.bar_start;p_voice.bar_start=null
  5297. for(s=last_s;s&&s.time==last_s.time;s=s.ts_next){if(s.rbstop){s2=null
  5298. break}}
  5299. if(!s2)
  5300. continue
  5301. if(!cur_sy.voices[v]||!cur_sy.st_print[cur_sy.voices[v].st])
  5302. continue
  5303. if(p_voice.last_sym.type==C.BAR){if(!p_voice.last_sym.rbstop)
  5304. p_voice.last_sym.rbstart=1}else{new_sym(s2,p_voice,last_s)
  5305. s2.fmt=fmt}}
  5306. self.set_pitch(last_s);s=tsfirst
  5307. s.seqst=true
  5308. 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)
  5309. for(s=s.ts_next;s.ts_next&&!s.ts_next.seqst;s=s.ts_next);s2=s.ts_next
  5310. s.ts_next=null
  5311. set_allsymwidth()
  5312. s.ts_next=s2}
  5313. function check_end_bar(){var s2,s=tsfirst
  5314. while(s.ts_next)
  5315. s=s.ts_next
  5316. if(s.type!=C.BAR){s2=_bar(s)
  5317. s2.ts_prev=s
  5318. s.next=s.ts_next=s2}}
  5319. function set_words(p_voice){var s,s2,nflags,lastnote,res,start_flag=true,pitch=127
  5320. function trem_adj(s){s.prev.trem2=true
  5321. s.prev.head=++s.head
  5322. if(--s.nflags>0){s.nflags+=s.ntrem}else{if(s.nflags<=-2){s.stemless=true
  5323. s.prev.stemless=true}
  5324. s.nflags=s.ntrem}
  5325. s.prev.nflags=s.nflags}
  5326. for(s=p_voice.sym;s;s=s.next){if(s.type==C.NOTE){pitch=s.notes[0].pit
  5327. break}}
  5328. for(s=p_voice.sym;s;s=s.next){if(s.a_gch)
  5329. self.gch_build(s)
  5330. switch(s.type){case C.MREST:start_flag=true
  5331. break
  5332. case C.BAR:res=s.fmt.bardef[s.bar_type]
  5333. if(res)
  5334. s.bar_type=res
  5335. if(!s.beam_on)
  5336. start_flag=true
  5337. if(!s.next&&s.prev&&!s.invis&&s.prev.head==C.OVALBARS)
  5338. s.prev.head=C.SQUARE
  5339. break
  5340. case C.GRACE:for(s2=s.extra;s2;s2=s2.next){s2.notes.sort(abc2svg.pitcmp)
  5341. res=identify_note(s2,s2.dur_orig)
  5342. s2.head=res[0]
  5343. s2.dots=res[1]
  5344. s2.nflags=res[2]
  5345. if(s2.trem2&&(!s2.next||s2.next.trem2))
  5346. trem_adj(s2)}
  5347. break
  5348. 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]
  5349. if(s.nflags<=-2)
  5350. s.stemless=true
  5351. if(s.xstem)
  5352. s.nflags=0
  5353. if(s.trem1){if(s.nflags>0)
  5354. s.nflags+=s.ntrem
  5355. else
  5356. s.nflags=s.ntrem}
  5357. if(s.next&&s.next.trem2)
  5358. break
  5359. if(s.trem2){trem_adj(s)
  5360. break}
  5361. nflags=s.nflags
  5362. if(s.ntrem)
  5363. nflags+=s.ntrem
  5364. if(s.type==C.REST&&s.beam_end&&!s.beam_on){start_flag=true}
  5365. if(start_flag||nflags<=0){if(lastnote){lastnote.beam_end=true;lastnote=null}
  5366. 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}}
  5367. if(s.beam_end)
  5368. start_flag=true
  5369. if(s.type==C.NOTE||s.beam_on)
  5370. lastnote=s
  5371. break}
  5372. if(s.type==C.NOTE){if(s.nhd)
  5373. s.notes.sort(abc2svg.pitcmp)
  5374. pitch=s.notes[0].pit
  5375. for(s2=s.prev;s2;s2=s2.prev){if(s2.type!=C.REST)
  5376. break
  5377. s2.notes[0].pit=pitch}}else{if(!s.notes){s.notes=[]
  5378. s.notes[0]={}
  5379. s.nhd=0}
  5380. s.notes[0].pit=pitch}}
  5381. if(lastnote)
  5382. lastnote.beam_end=true}
  5383. function set_rb(p_voice){var s2,n,s=p_voice.sym
  5384. while(s){if(s.type!=C.BAR||!s.rbstart||s.norepbra){s=s.next
  5385. continue}
  5386. n=0;s2=null
  5387. for(s=s.next;s;s=s.next){if(s.type!=C.BAR)
  5388. continue
  5389. if(s.rbstop)
  5390. break
  5391. if(!s.next){s.rbstop=2
  5392. break}
  5393. n++
  5394. if(n==s.fmt.rbmin)
  5395. s2=s
  5396. if(n==s.fmt.rbmax){if(s2)
  5397. s=s2;s.rbstop=1
  5398. break}}}}
  5399. var delpit=[0,-7,-14,0]
  5400. function set_global(){var p_voice,v,nv=voice_tb.length,sy=cur_sy,st=sy.nstaff
  5401. insert_meter=cfmt.writefields.indexOf('M')>=0
  5402. while(1){sy=sy.next
  5403. if(!sy)
  5404. break
  5405. if(sy.nstaff>st)
  5406. st=sy.nstaff}
  5407. nstaff=st;check_end_bar()
  5408. for(v=0;v<nv;v++){p_voice=voice_tb[v];set_words(p_voice)
  5409. p_voice.ckey=p_voice.key
  5410. set_rb(p_voice)}
  5411. if(nv>1){set_float()
  5412. if(glovar.mrest_p)
  5413. mrest_expand()}
  5414. if(glovar.ottava&&cfmt.sound!="play")
  5415. set_ottava();set_clefs();self.set_pitch(null)}
  5416. function get_lshift(){var st,v,p_v,p1,po,fnt,w,sy=cur_sy,lsh1=0,lsho=0,nv=voice_tb.length
  5417. function get_wx(p,wx){var w,j,i=0
  5418. p+='\n'
  5419. while(1){j=p.indexOf("\n",i)
  5420. if(j<0)
  5421. break
  5422. w=strwh(p.slice(i,j))[0]+12
  5423. if(w>wx)
  5424. wx=w
  5425. if(j<0)
  5426. break
  5427. i=j+1}
  5428. return wx}
  5429. for(v=0;v<nv;v++){p_v=voice_tb[v]
  5430. p1=p_v.nm
  5431. po=p_v.snm
  5432. if((p1||po)&&!fnt){set_font("voice")
  5433. fnt=gene.deffont}
  5434. if(p1){w=get_wx(p1,lsh1)
  5435. if(w>lsh1)
  5436. lsh1=w}
  5437. if(po){w=get_wx(po,lsho)
  5438. if(w>lsho)
  5439. lsho=w}}
  5440. w=0
  5441. while(sy){for(st=0;st<=sy.nstaff;st++){if(sy.staves[st].flags&(OPEN_BRACE2|OPEN_BRACKET2)){w=12
  5442. break}
  5443. if(sy.staves[st].flags&(OPEN_BRACE|OPEN_BRACKET))
  5444. w=6}
  5445. if(w==12)
  5446. break
  5447. sy=sy.next}
  5448. lsh1+=w
  5449. lsho+=w
  5450. return[lsh1,lsho]}
  5451. function set_indent(lsh){var st,v,w,p_voice,p,i,j,font,vnt=0,nv=voice_tb.length
  5452. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  5453. if(!cur_sy.voices[v]||!gene.st_print[p_voice.st])
  5454. continue
  5455. if(p_voice.new_name){vnt=2
  5456. break}
  5457. if(p_voice.snm)
  5458. vnt=1}
  5459. gene.vnt=vnt
  5460. return vnt==2?lsh[0]:lsh[1]}
  5461. function set_beams(sym){var s,t,g,beam,s_opp,n,m,mid_p,pu,pd,laststem=-1
  5462. for(s=sym;s;s=s.next){if(s.type!=C.NOTE){if(s.type!=C.GRACE)
  5463. continue
  5464. g=s.extra
  5465. if(g.stem==2){s_opp=s
  5466. continue}
  5467. if(!s.stem)
  5468. s.stem=s.multi||1
  5469. for(;g;g=g.next){g.stem=s.stem;g.multi=s.multi}
  5470. continue}
  5471. if(!s.stem&&s.multi)
  5472. s.stem=s.multi
  5473. if(!s.stem){mid_p=s.mid/3+18
  5474. 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
  5475. for(g=s.next;g;g=g.next){if(g.type!=C.NOTE)
  5476. continue
  5477. if(g.stem||g.multi)
  5478. s.stem=g.stem||g.multi
  5479. if(g.notes[g.nhd].pit>pu)
  5480. pu=g.notes[g.nhd].pit
  5481. if(g.notes[0].pit<pd)
  5482. pd=g.notes[0].pit
  5483. if(g.beam_end)
  5484. break}
  5485. 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)
  5486. s.stem=-1}}
  5487. if(!s.stem)
  5488. s.stem=laststem}else{n=(s.notes[s.nhd].pit+s.notes[0].pit)/2
  5489. if(n==mid_p&&s.nhd>1){for(m=0;m<s.nhd;m++){if(s.notes[m].pit>=mid_p)
  5490. break}
  5491. n=m*2<s.nhd?mid_p-1:mid_p+1}
  5492. if(n<mid_p)
  5493. s.stem=1
  5494. else if(n>mid_p||s.fmt.bstemdown)
  5495. s.stem=-1
  5496. else
  5497. s.stem=laststem}}else{if(s.beam_st&&!s.beam_end)
  5498. beam=true}
  5499. if(s.beam_end)
  5500. beam=false;laststem=s.stem;if(s_opp){for(g=s_opp.extra;g;g=g.next)
  5501. g.stem=-laststem;s_opp.stem=-laststem;s_opp=null}}}
  5502. function same_head(s1,s2){var i1,i2,l1,l2,head,i11,i12,i21,i22,sh1,sh2,shu=s1.fmt.shiftunison||0
  5503. if(shu>=3)
  5504. return false
  5505. if((l1=s1.dur)>=C.BLEN)
  5506. return false
  5507. if((l2=s2.dur)>=C.BLEN)
  5508. return false
  5509. if(s1.stemless&&s2.stemless)
  5510. return false
  5511. if(s1.dots!=s2.dots){if(shu&1||s1.dots*s2.dots!=0)
  5512. return false}
  5513. if(s1.stem*s2.stem>0)
  5514. return false
  5515. i1=i2=0
  5516. if(s1.notes[0].pit>s2.notes[0].pit){if(s1.stem<0)
  5517. return false
  5518. while(s2.notes[i2].pit!=s1.notes[0].pit){if(++i2>s2.nhd)
  5519. return false}}else if(s1.notes[0].pit<s2.notes[0].pit){if(s2.stem<0)
  5520. return false
  5521. while(s2.notes[0].pit!=s1.notes[i1].pit){if(++i1>s1.nhd)
  5522. return false}}
  5523. if(s2.notes[i2].acc!=s1.notes[i1].acc)
  5524. return false;i11=i1;i21=i2;sh1=s1.notes[i1].shhd;sh2=s2.notes[i2].shhd
  5525. do{i1++;i2++
  5526. if(i1>s1.nhd){break}
  5527. if(i2>s2.nhd){break}
  5528. if(s2.notes[i2].acc!=s1.notes[i1].acc)
  5529. return false
  5530. if(sh1<s1.notes[i1].shhd)
  5531. sh1=s1.notes[i1].shhd
  5532. if(sh2<s2.notes[i2].shhd)
  5533. sh2=s2.notes[i2].shhd}while(s2.notes[i2].pit==s1.notes[i1].pit)
  5534. if(i1<=s1.nhd){if(i2<=s2.nhd)
  5535. return false
  5536. if(s2.stem>0)
  5537. return false}else if(i2<=s2.nhd){if(s1.stem>0)
  5538. return false}
  5539. i12=i1;i22=i2;head=0
  5540. if(l1!=l2){if(l1<l2){l1=l2;l2=s1.dur}
  5541. if(l1<C.BLEN/2){if(s2.dots)
  5542. head=2
  5543. else if(s1.dots)
  5544. head=1}else if(l2<C.BLEN/4){if(shu&2)
  5545. return false
  5546. head=s2.dur>=C.BLEN/2?2:1}else{return false}}
  5547. if(!head)
  5548. head=s1.p_v.scale<s2.p_v.scale?2:1
  5549. if(head==1){for(i2=i21;i2<i22;i2++){s2.notes[i2].invis=true
  5550. delete s2.notes[i2].acc}
  5551. for(i2=0;i2<=s2.nhd;i2++)
  5552. s2.notes[i2].shhd+=sh1}else{for(i1=i11;i1<i12;i1++){s1.notes[i1].invis=true
  5553. delete s1.notes[i1].acc}
  5554. for(i1=0;i1<=s1.nhd;i1++)
  5555. s1.notes[i1].shhd+=sh2}
  5556. return true}
  5557. function unison_acc(s1,s2,i1,i2){var m,d,acc
  5558. acc=s2.notes[i2].acc
  5559. if(!acc){d=w_note[s2.head]*2+s2.xmx+s1.notes[i1].shac+2
  5560. acc=s1.notes[i1].acc
  5561. if(typeof acc=="object")
  5562. d+=2
  5563. if(s2.dots)
  5564. d+=6
  5565. for(m=0;m<=s1.nhd;m++){s1.notes[m].shhd+=d;s1.notes[m].shac-=d}
  5566. s1.xmx+=d}else{d=w_note[s1.head]*2+s1.xmx+s2.notes[i2].shac+2
  5567. if(typeof acc=="object")
  5568. d+=2
  5569. if(s1.dots)
  5570. d+=6
  5571. for(m=0;m<=s2.nhd;m++){s2.notes[m].shhd+=d;s2.notes[m].shac-=d}
  5572. s2.xmx+=d}}
  5573. var MAXPIT=48*2
  5574. function set_left(s){var m,i,j,shift,w_base=w_note[s.head],w=w_base,left=[]
  5575. for(i=0;i<MAXPIT;i++)
  5576. left.push(-100)
  5577. 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}
  5578. if(i<0)
  5579. i=0
  5580. if(j>=MAXPIT)
  5581. j=MAXPIT-1
  5582. while(i<=j)
  5583. left[i++]=w}
  5584. 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
  5585. if(i<0)
  5586. i=0
  5587. else if(i>=MAXPIT-1)
  5588. i=MAXPIT-2
  5589. if(w>left[i])
  5590. left[i]=w
  5591. if(s.head!=C.SQUARE)
  5592. w-=1
  5593. if(w>left[i-1])
  5594. left[i-1]=w
  5595. if(w>left[i+1])
  5596. left[i+1]=w}
  5597. return left}
  5598. 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=[]
  5599. for(i=0;i<MAXPIT;i++)
  5600. right.push(-100)
  5601. 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}
  5602. if(i<0)
  5603. i=0
  5604. if(j>MAXPIT)
  5605. j=MAXPIT
  5606. while(i<j)
  5607. right[i++]=w}
  5608. if(flags){if(s.stem>0){if(s.xmx==0)
  5609. i=s.notes[s.nhd].pit*2
  5610. else
  5611. i=s.notes[0].pit*2;i+=4
  5612. if(i<0)
  5613. i=0
  5614. for(;i<MAXPIT&&i<=j-4;i++)
  5615. right[i]=11}else{i=k
  5616. if(i<0)
  5617. i=0
  5618. for(;i<MAXPIT&&i<=s.notes[0].pit*2-4;i++)
  5619. right[i]=3.5}}
  5620. shift=s.notes[s.stem>0?0:s.nhd].shhd
  5621. for(m=0;m<=s.nhd;m++){w=s.notes[m].shhd+w_base-shift;i=s.notes[m].pit*2
  5622. if(i<0)
  5623. i=0
  5624. else if(i>=MAXPIT-1)
  5625. i=MAXPIT-2
  5626. if(w>right[i])
  5627. right[i]=w
  5628. if(s.head!=C.SQUARE)
  5629. w-=1
  5630. if(w>right[i-1])
  5631. right[i-1]=w
  5632. if(w>right[i+1])
  5633. right[i+1]=w}
  5634. return right}
  5635. 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
  5636. function v_invert(){s1=s2;s2=s;d=d2;pl=left1;pr=right1;dr2=dr}
  5637. for(s=tsfirst;s;s=s.ts_next){if(s.type!=C.NOTE||s.invis){if(s.type==C.STAVES)
  5638. sy=s.sy
  5639. continue}
  5640. 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}}
  5641. s2=s
  5642. while(1){s2=s2.ts_next
  5643. if(!s2)
  5644. break
  5645. if(s2.time!=s.time){s2=null
  5646. break}
  5647. if(s2.type==C.NOTE&&!s2.invis&&s2.st==s.st)
  5648. break}
  5649. if(!s2)
  5650. continue
  5651. s1=s
  5652. if(sy.voices[s1.v].range<sy.voices[s2.v].range)
  5653. s2.dot_low=true
  5654. else
  5655. s1.dot_low=true
  5656. if(s1.ymn>s2.ymx||s1.ymx<s2.ymn)
  5657. continue
  5658. if(same_head(s1,s2))
  5659. continue
  5660. if(!s1.dots&&!s2.dots)
  5661. 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}
  5662. d=s1.notes[0].shhd+7
  5663. for(m=0;m<=s2.nhd;m++)
  5664. s2.notes[m].shhd+=d
  5665. s2.xmx+=d
  5666. s1.xmx=s2.xmx
  5667. continue}
  5668. right1=set_right(s1);left2=set_left(s2);s3=s1.ts_prev
  5669. if(s3&&s3.time==s1.time&&s3.st==s1.st&&s3.type==C.NOTE&&!s3.invis){right3=set_right(s3)
  5670. for(i=0;i<MAXPIT;i++){if(right3[i]>right1[i])
  5671. right1[i]=right3[i]}}else{s3=null}
  5672. d=-10
  5673. for(i=0;i<MAXPIT;i++){if(left2[i]+right1[i]>d)
  5674. d=left2[i]+right1[i]}
  5675. 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))))
  5676. continue
  5677. right2=set_right(s2);left1=set_left(s1)
  5678. if(s3){right3=set_left(s3)
  5679. for(i=0;i<MAXPIT;i++){if(right3[i]>left1[i])
  5680. left1[i]=right3[i]}}
  5681. d2=dr=dr2=-100
  5682. for(i=0;i<MAXPIT;i++){if(left1[i]+right2[i]>d2)
  5683. d2=left1[i]+right2[i]
  5684. if(right2[i]>dr2)
  5685. dr2=right2[i]
  5686. if(right1[i]>dr)
  5687. dr=right1[i]}
  5688. t=0;i1=s1.nhd;i2=s2.nhd
  5689. while(1){dp=s1.notes[i1].pit-s2.notes[i2].pit
  5690. switch(dp){case 2:if(!(s1.notes[i1].pit&1))
  5691. s1.dot_low=false
  5692. break
  5693. case 1:if(s1.notes[i1].pit&1)
  5694. s2.dot_low=true
  5695. else
  5696. s1.dot_low=false
  5697. break
  5698. case 0:if(s1.notes[i1].acc!=s2.notes[i2].acc){t=-1
  5699. break}
  5700. if(s2.notes[i2].acc){if(!s1.notes[i1].acc)
  5701. s1.notes[i1].acc=s2.notes[i2].acc
  5702. s2.notes[i2].acc=0}
  5703. if(s1.dots&&s2.dots&&(s1.notes[i1].pit&1))
  5704. t=1
  5705. break
  5706. case-1:if(s1.notes[i1].pit&1)
  5707. s2.dot_low=false
  5708. else
  5709. s1.dot_low=true
  5710. break
  5711. case-2:if(!(s1.notes[i1].pit&1))
  5712. s2.dot_low=false
  5713. break}
  5714. if(t<0)
  5715. break
  5716. if(dp>=0){if(--i1<0)
  5717. break}
  5718. if(dp<=0){if(--i2<0)
  5719. break}}
  5720. if(t<0){unison_acc(s1,s2,i1,i2)
  5721. continue}
  5722. sd=0;if(s1.dots){if(s2.dots){if(!t)
  5723. sd=1}else{v_invert()}}else if(s2.dots){if(d2+dr<d+dr2)
  5724. sd=1}
  5725. pl=left2;pr=right2
  5726. if(!s3&&d2+dr<d+dr2)
  5727. v_invert()
  5728. d+=3
  5729. if(d<0)
  5730. 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
  5731. if(s1.dots){dx=7.7+s1.xmx+
  5732. 3.5*s1.dots-3.5+
  5733. 3;if(!sd){d2=-100;for(i1=0;i1<=s1.nhd;i1++){i=s1.notes[i1].pit
  5734. if(!(i&1)){if(!s1.dot_low)
  5735. i++
  5736. else
  5737. i--}
  5738. i*=2
  5739. if(i<1)
  5740. i=1
  5741. else if(i>=MAXPIT-1)
  5742. i=MAXPIT-2
  5743. if(pl[i]>d2)
  5744. d2=pl[i]
  5745. if(pl[i-1]+1>d2)
  5746. d2=pl[i-1]+1
  5747. if(pl[i+1]+1>d2)
  5748. d2=pl[i+1]+1}
  5749. if(dx+d2+2>d)
  5750. d=dx+d2+2}else{if(dx<d+dr2+s2.xmx){d2=0
  5751. for(i1=0;i1<=s1.nhd;i1++){i=s1.notes[i1].pit
  5752. if(!(i&1)){if(!s1.dot_low)
  5753. i++
  5754. else
  5755. i--}
  5756. i*=2
  5757. if(i<1)
  5758. i=1
  5759. else if(i>=MAXPIT-1)
  5760. i=MAXPIT-2
  5761. if(pr[i]>d2)
  5762. d2=pr[i]
  5763. if(pr[i-1]+1>d2)
  5764. d2=pr[i-1]=1
  5765. if(pr[i+1]+1>d2)
  5766. d2=pr[i+1]+1}
  5767. if(d2>4.5&&7.7+s1.xmx+2<d+d2+s2.xmx)
  5768. s2.xmx=d2+3-7.7}}}
  5769. for(m=s2.nhd;m>=0;m--){s2.notes[m].shhd+=d}
  5770. s2.xmx+=d
  5771. if(sd)
  5772. s1.xmx=s2.xmx}}
  5773. Abc.prototype.set_stems=function(){var s,s2,g,slen,scale,ymn,ymx,nflags,ymin,ymax
  5774. for(s=tsfirst;s;s=s.ts_next){if(s.type!=C.NOTE){if(s.type!=C.GRACE)
  5775. continue
  5776. ymin=ymax=s.mid
  5777. for(g=s.extra;g;g=g.next){slen=GSTEM
  5778. if(g.nflags>1)
  5779. slen+=1.2*(g.nflags-1);ymn=3*(g.notes[0].pit-18);ymx=3*(g.notes[g.nhd].pit-18)
  5780. 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)}
  5781. ymx+=4
  5782. ymn-=4
  5783. if(ymn<ymin)
  5784. ymin=ymn
  5785. else if(ymx>ymax)
  5786. ymax=ymx;g.ymx=ymx;g.ymn=ymn}
  5787. s.ymx=ymax;s.ymn=ymin
  5788. continue}
  5789. set_head_shift(s);nflags=s.nflags
  5790. if(s.beam_st&&!s.beam_end){if(s.feathered_beam)
  5791. nflags=++s.nflags
  5792. for(s2=s.next;;s2=s2.next){if(s2.type==C.NOTE){if(s.feathered_beam)
  5793. s2.nflags++
  5794. if(s2.beam_end)
  5795. break}}
  5796. if(s2.nflags>nflags)
  5797. nflags=s2.nflags}else if(!s.beam_st&&s.beam_end){for(s2=s.prev;;s2=s2.prev){if(s2.beam_st)
  5798. break}
  5799. if(s2.nflags>nflags)
  5800. nflags=s2.nflags}
  5801. slen=s.fmt.stemheight
  5802. switch(nflags){case 2:slen+=0;break
  5803. case 3:slen+=4;break
  5804. case 4:slen+=8;break
  5805. case 5:slen+=12;break}
  5806. if((scale=s.p_v.scale)!=1)
  5807. slen*=(scale+1)*.5;ymn=3*(s.notes[0].pit-18)
  5808. if(s.nhd>0){slen-=2;ymx=3*(s.notes[s.nhd].pit-18)}else{ymx=ymn}
  5809. if(s.ntrem)
  5810. slen+=2*s.ntrem
  5811. if(s.stemless){if(s.stem>=0){s.y=ymn;s.ys=ymx}else{s.ys=ymn;s.y=ymx}
  5812. 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
  5813. if(s.notes[s.nhd].pit>28)
  5814. slen-=2}
  5815. s.y=ymn
  5816. if(s.notes[0].tie)
  5817. ymn-=3;s.ymn=ymn-4;s.ys=ymx+slen
  5818. if(s.ys<s.mid)
  5819. 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
  5820. if(s.notes[0].pit<16)
  5821. slen-=2}
  5822. s.ys=ymn-slen
  5823. if(s.ys>s.mid)
  5824. s.ys=s.mid;s.ymn=(s.ys-2.5)|0;s.y=ymx
  5825. if(s.notes[s.nhd].tie)
  5826. ymx+=3;s.ymx=ymx+4}}}
  5827. var blocks=[]
  5828. 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)
  5829. break
  5830. case"mc_start":if(multicol){error(1,s,"No end of the previous %%multicol")
  5831. break}
  5832. multicol={posy:posy,maxy:posy,lm:cfmt.leftmargin,rm:cfmt.rightmargin,w:cfmt.pagewidth,sc:cfmt.scale}
  5833. break
  5834. case"mc_new":if(!multicol){error(1,s,"%%multicol new without start")
  5835. break}
  5836. if(posy>multicol.maxy)
  5837. multicol.maxy=posy
  5838. cfmt.leftmargin=multicol.lm
  5839. cfmt.rightmargin=multicol.rm
  5840. cfmt.pagewidth=multicol.w
  5841. cfmt.scale=multicol.sc
  5842. posy=multicol.posy
  5843. img.chg=1
  5844. break
  5845. case"mc_end":if(!multicol){error(1,s,"%%multicol end without start")
  5846. break}
  5847. if(posy<multicol.maxy)
  5848. posy=multicol.maxy
  5849. cfmt.leftmargin=multicol.lm
  5850. cfmt.rightmargin=multicol.rm
  5851. cfmt.pagewidth=multicol.w
  5852. cfmt.scale=multicol.sc
  5853. multicol=undefined
  5854. blk_flush()
  5855. img.chg=1
  5856. break
  5857. case"ml":blk_flush()
  5858. user.img_out(s.text)
  5859. break
  5860. case"newpage":if(!user.page_format)
  5861. break
  5862. blk_flush()
  5863. if(blkdiv<0)
  5864. user.img_out('</div>')
  5865. blkdiv=2
  5866. break
  5867. case"sep":set_page();vskip(s.sk1);output+='<path class="stroke"\n\td="M';out_sxsy((img.width-s.l)/2-img.lm,' ',0)
  5868. output+='h'+s.l.toFixed(1)+'"/>\n';vskip(s.sk2);break
  5869. case"text":set_font(s.font)
  5870. use_font(s.font)
  5871. write_text(s.text,s.opt)
  5872. break
  5873. case"title":write_title(s.text,true)
  5874. break
  5875. case"vskip":vskip(s.sk);break}}
  5876. function sym_staff_move(st){for(var s=tsfirst;s;s=s.ts_next){if(s.nl)
  5877. break
  5878. if(s.st==st&&s.type!=C.CLEF){s.st++
  5879. if(s.type!=C.TEMPO)
  5880. s.invis=true}}}
  5881. function set_piece(){var s,last,p_voice,st,v,nv,tmp,non_empty=[],non_empty_gl=[],sy=cur_sy
  5882. function reset_staff(st){var p_staff=staff_tb[st],sy_staff=sy.staves[st]
  5883. if(!p_staff)
  5884. p_staff=staff_tb[st]={}
  5885. 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}
  5886. function set_brace(){var st,i,empty_fl,n=sy.staves.length
  5887. for(st=0;st<n;st++){if(!(sy.staves[st].flags&(OPEN_BRACE|OPEN_BRACE2)))
  5888. continue
  5889. empty_fl=0;i=st
  5890. while(st<n){empty_fl|=non_empty[st]?1:2
  5891. if(sy.staves[st].flags&(CLOSE_BRACE|CLOSE_BRACE2))
  5892. break
  5893. st++}
  5894. if(empty_fl==3){while(i<=st){non_empty[i]=true;non_empty_gl[i++]=true}}}}
  5895. function set_top_bot(){var st,p_staff,i,j,l
  5896. for(st=0;st<=nstaff;st++){p_staff=staff_tb[st]
  5897. p_staff.hlu=[]
  5898. p_staff.hld=[]
  5899. l=p_staff.stafflines.length;p_staff.topbar=6*(l-1)
  5900. for(i=0;i<l-1;i++){switch(p_staff.stafflines[i]){case'.':case'-':continue}
  5901. break}
  5902. p_staff.botline=p_staff.botbar=i*6
  5903. 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
  5904. continue}}
  5905. if(!non_empty_gl[st])
  5906. continue
  5907. p_staff.hll=17+i*2
  5908. p_staff.hlmap=new Int8Array((l-i+1)*2
  5909. +2)
  5910. 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
  5911. break}}}}
  5912. if(tsfirst.type==C.STAVES){s=tsfirst
  5913. tsfirst=tsfirst.ts_next
  5914. tsfirst.ts_prev=null
  5915. if(s.seqst)
  5916. tsfirst.seqst=true
  5917. s.p_v.sym=s.next
  5918. if(s.next)
  5919. s.next.prev=null}
  5920. nstaff=sy.nstaff
  5921. for(st=0;st<=nstaff;st++)
  5922. reset_staff(st);for(s=tsfirst;s;s=s.ts_next){if(s.nl)
  5923. break
  5924. switch(s.type){case C.STAVES:set_brace();sy.st_print=new Uint8Array(non_empty);sy=s.sy;while(nstaff<sy.nstaff)
  5925. reset_staff(++nstaff)
  5926. non_empty=[]
  5927. continue
  5928. case C.BLOCK:if(!s.play){blocks.push(s)
  5929. unlksym(s)}else if(s.ts_next&&s.ts_next.shrink)
  5930. s.ts_next.shrink=0
  5931. continue}
  5932. st=s.st
  5933. if(st>nstaff){switch(s.type){case C.CLEF:staff_tb[st].clef=s
  5934. break
  5935. case C.KEY:s.p_v.ckey=s
  5936. break
  5937. case C.METER:s.p_v.meter=s
  5938. break}
  5939. unlksym(s)
  5940. continue}
  5941. if(non_empty[st])
  5942. continue
  5943. switch(s.type){default:continue
  5944. case C.BAR:if(s.bar_mrep||sy.staves[st].staffnonote>1)
  5945. break
  5946. continue
  5947. case C.GRACE:break
  5948. case C.NOTE:case C.REST:case C.SPACE:case C.MREST:if(sy.staves[st].staffnonote>1)
  5949. break
  5950. if(s.invis)
  5951. continue
  5952. if(sy.staves[st].staffnonote||s.type==C.NOTE)
  5953. break
  5954. continue}
  5955. non_empty_gl[st]=non_empty[st]=true}
  5956. tsnext=s;set_brace()
  5957. sy.st_print=new Uint8Array(non_empty);set_top_bot()
  5958. for(st=0;st<nstaff;st++){if(!non_empty_gl[st])
  5959. sym_staff_move(st)}
  5960. if(!non_empty_gl[nstaff])
  5961. staff_tb[nstaff].topbar=0
  5962. if(tsnext){s=tsnext;delete s.nl;last=s.ts_prev;last.ts_next=null;nv=voice_tb.length
  5963. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  5964. if(p_voice.sym&&p_voice.sym.time<=tsnext.time){for(s=last;s;s=s.ts_prev){if(s.v==v){p_voice.s_next=s.next;s.next=null;break}}
  5965. if(s)
  5966. continue}
  5967. p_voice.s_next=p_voice.sym;p_voice.sym=null}}
  5968. init_music_line()
  5969. gene.st_print=new Uint8Array(non_empty_gl)}
  5970. Abc.prototype.set_sym_glue=function(width){var s,g,ll,x,some_grace,spf,xmin=0,xx=0,xs=0,xse=0
  5971. for(s=tsfirst;s;s=s.ts_next){if(s.type==C.GRACE&&!some_grace)
  5972. some_grace=s
  5973. if(s.seqst){xmin+=s.shrink
  5974. if(xmin>width){error(1,s,"Line too much shrunk $1 $2 $3",xmin.toFixed(1),xx.toFixed(1),width.toFixed(1))
  5975. break}
  5976. if(s.space){if(s.space<s.shrink){xse+=s.shrink;xx+=s.shrink}else{xx+=s.space}}else{xs+=s.shrink}}}
  5977. if(!xx){realwidth=0
  5978. return}
  5979. ll=!tsnext||(tsnext.type==C.BLOCK&&!tsnext.play)||blocks.length
  5980. s=tsfirst
  5981. if(xmin>=width){x=0
  5982. for(;s;s=s.ts_next){if(s.seqst)
  5983. x+=s.shrink;s.x=x}
  5984. spf_last=0}else if((ll&&xx+xs>width*(1-s.fmt.stretchlast))||(!ll&&(xx+xs>width||s.fmt.stretchstaff))){if(xx==xse)
  5985. xx+=5
  5986. for(var cnt=4;--cnt>=0;){spf=(width-xs-xse)/(xx-xse);xx=0;xse=0;x=0
  5987. 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}}
  5988. s.x=x}
  5989. if(Math.abs(x-width)<0.1)
  5990. break}
  5991. spf_last=spf}else{spf=1-s.fmt.maxshrink
  5992. if(spf_last&&xx*spf_last+xs<width)
  5993. spf=spf_last
  5994. x=0
  5995. for(;s;s=s.ts_next){if(s.seqst)
  5996. x+=s.space<=s.shrink?s.shrink:s.shrink*(1-spf)+s.space*spf
  5997. s.x=x}}
  5998. realwidth=x
  5999. for(s=some_grace;s;s=s.ts_next){if(s.type!=C.GRACE)
  6000. continue
  6001. if(s.gr_shift)
  6002. x=s.prev.x+s.prev.wr
  6003. else
  6004. x=s.x-s.wl
  6005. for(g=s.extra;g;g=g.next)
  6006. g.x+=x}}
  6007. function set_sym_line(){var p_v,s,v=voice_tb.length
  6008. while(--v>=0){p_v=voice_tb[v]
  6009. if(p_v.sym&&p_v.s_prev){p_v.sym.prev=p_v.s_prev
  6010. p_v.s_prev.next=p_v.sym}
  6011. s=p_v.s_next
  6012. p_v.s_next=null
  6013. p_v.sym=s
  6014. if(s){if(s.prev)
  6015. s.prev.next=s
  6016. p_v.s_prev=s.prev
  6017. s.prev=null}else{p_v.s_prev=null}}}
  6018. function set_posx(){posx=img.lm/cfmt.scale}
  6019. function gen_init(){var s=tsfirst,tim=s.time
  6020. for(;s;s=s.ts_next){if(s.time!=tim){set_page()
  6021. return}
  6022. switch(s.type){case C.NOTE:case C.REST:case C.MREST:case C.SPACE:set_page()
  6023. return
  6024. default:continue
  6025. case C.STAVES:cur_sy=s.sy
  6026. continue
  6027. case C.BLOCK:if(s.play)
  6028. continue
  6029. self.block_gen(s)
  6030. break}
  6031. unlksym(s)
  6032. if(s.p_v.s_next==s)
  6033. s.p_v.s_next=s.next}
  6034. tsfirst=null}
  6035. Abc.prototype.output_music=function(){var v,lwidth,indent,lsh,line_height,ts1st,tslast,p_v,nv=voice_tb.length
  6036. set_global()
  6037. if(nv>1)
  6038. self.set_stem_dir()
  6039. for(v=0;v<nv;v++)
  6040. set_beams(voice_tb[v].sym);self.set_stems()
  6041. set_acc_shft()
  6042. if(nv>1){set_rest_offset();set_overlap()}
  6043. set_allsymwidth(1)
  6044. lsh=get_lshift()
  6045. if(cfmt.singleline){v=get_ck_width();lwidth=lsh[0]+v[0]+v[1]+get_width(tsfirst,null)[0]
  6046. v=cfmt.singleline==2?get_lwidth():lwidth
  6047. if(v>lwidth)
  6048. lwidth=v
  6049. else
  6050. img.width=lwidth*cfmt.scale+img.lm+img.rm+2}else{lwidth=get_lwidth();cut_tune(lwidth,lsh)}
  6051. gen_init()
  6052. if(!tsfirst)
  6053. return
  6054. ts1st=tsfirst
  6055. v=nv
  6056. while(--v>=0)
  6057. voice_tb[v].osym=voice_tb[v].sym
  6058. spf_last=0
  6059. while(1){set_piece();indent=set_indent(lsh)
  6060. if(!line_height&&cfmt.indent&&indent<cfmt.indent)
  6061. indent=cfmt.indent
  6062. self.set_sym_glue(lwidth-indent)
  6063. if(realwidth){if(indent)
  6064. posx+=indent;draw_sym_near();line_height=set_staff();draw_systems(indent);draw_all_sym();delayed_update();if(output)
  6065. vskip(line_height)
  6066. if(indent)
  6067. posx-=indent}
  6068. blk_flush()
  6069. while(blocks.length)
  6070. self.block_gen(blocks.shift())
  6071. if(tslast)
  6072. tslast.ts_next.ts_prev=tslast
  6073. if(!tsnext)
  6074. break
  6075. tsnext.ts_prev.ts_next=tsfirst=tsnext
  6076. gen_init()
  6077. if(!tsfirst)
  6078. break
  6079. tslast=tsfirst.ts_prev
  6080. tsfirst.ts_prev=null;set_sym_line();lwidth=get_lwidth()}
  6081. tsfirst=ts1st
  6082. v=nv
  6083. while(--v>=0){p_v=voice_tb[v]
  6084. if(p_v.sym&&p_v.s_prev)
  6085. p_v.sym.prev=p_v.s_prev
  6086. p_v.sym=p_v.osym}}
  6087. var a_gch,a_dcn=[],multicol,maps={}
  6088. var qplet_tb=new Int8Array([0,1,3,2,3,0,2,0,3,0]),ntb="CDEFGABcdefgab"
  6089. function set_ref(s){s.fname=parse.fname;s.istart=parse.istart;s.iend=parse.iend}
  6090. 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
  6091. set_ref(s)
  6092. switch(clef_def[0]){case'"':i=clef_def.indexOf('"',1);s.clef_name=clef_def.slice(1,i);i++
  6093. break
  6094. case'a':if(clef_def[1]=='u'){s.clef_type="a";s.clef_auto=true;i=4
  6095. break}
  6096. i=4
  6097. case'C':s.clef_type="c";s.clef_line=3
  6098. break
  6099. case'b':i=4
  6100. case'F':s.clef_type="b";s.clef_line=4
  6101. break
  6102. case'n':i=4
  6103. s.invis=true
  6104. break
  6105. case't':if(clef_def[1]=='e'){s.clef_type="c";s.clef_line=4
  6106. break}
  6107. i=6
  6108. case'G':break
  6109. case'p':i=4
  6110. case'P':s.clef_type="p";s.clef_line=3;break
  6111. default:syntax(1,"Unknown clef '$1'",clef_def)
  6112. return}
  6113. if(clef_def[i]>='1'&&clef_def[i]<='9'){s.clef_line=+clef_def[i]
  6114. i++}
  6115. delete curvoice.snd_oct
  6116. if(clef_def[i+1]!='8'&&clef_def[i+1]!='1')
  6117. return s
  6118. switch(clef_def[i]){case'^':s.clef_oct_transp=true
  6119. case'+':s.clef_octave=clef_def[i+1]=='8'?7:14
  6120. if(!s.clef_oct_transp)
  6121. curvoice.snd_oct=clef_def[i+1]==8?12:24
  6122. break
  6123. case'_':s.clef_oct_transp=true
  6124. case'-':s.clef_octave=clef_def[i+1]=='8'?-7:-14
  6125. if(!s.clef_oct_transp)
  6126. curvoice.snd_oct=clef_def[i+1]==8?-12:-24
  6127. break}
  6128. return s}
  6129. function get_interval(param,score){var i,val,tmp,note,pit
  6130. tmp=new scanBuf;tmp.buffer=param
  6131. pit=[]
  6132. for(i=0;i<2;i++){note=tmp.buffer[tmp.index]?parse_acc_pit(tmp):null
  6133. if(!note){if(i!=1||!score){syntax(1,errs.bad_transp)
  6134. return}
  6135. pit[i]=242}else{if(typeof note.acc=="object"){syntax(1,errs.bad_transp)
  6136. return}
  6137. pit[i]=abc2svg.pab40(note.pit,note.acc)}}
  6138. return pit[1]-pit[0]}
  6139. function nt_trans(nt,a){var ak,an,d,b40,n
  6140. if(typeof a=="object"){n=a[0]
  6141. d=a[1]
  6142. a=n>0?1:-1}
  6143. b40=abc2svg.pab40(nt.pit,a)
  6144. +curvoice.tr_sco
  6145. nt.pit=abc2svg.b40p(b40)
  6146. an=abc2svg.b40a(b40)
  6147. if(!d){if(an==-3)
  6148. return an
  6149. a=an
  6150. if(nt.acc){if(!a)
  6151. a=3}else{if(!curvoice.ckey.k_none)
  6152. a=0}
  6153. nt.acc=a
  6154. return an}
  6155. switch(an){case-2:if(n>0)
  6156. n-=d*2
  6157. else
  6158. n-=d
  6159. break
  6160. case-1:if(n>0)
  6161. n-=d
  6162. break
  6163. case 0:case 3:if(n>0)
  6164. n-=d
  6165. else
  6166. n+=d
  6167. break
  6168. case 1:if(n<0)
  6169. n+=d
  6170. break
  6171. case 2:if(n<0)
  6172. n+=d*2
  6173. else
  6174. n+=d
  6175. break}
  6176. nt.acc=[n,d]
  6177. return an}
  6178. function set_linebreak(param){var i,item
  6179. for(i=0;i<128;i++){if(char_tb[i]=="\n")
  6180. char_tb[i]=nil}
  6181. param=param.split(/\s+/)
  6182. for(i=0;i<param.length;i++){item=param[i]
  6183. switch(item){case'!':case'$':case'*':case';':case'?':case'@':break
  6184. case"<none>":continue
  6185. case"<EOL>":item='\n'
  6186. break
  6187. default:syntax(1,"Bad value '$1' in %%linebreak - ignored",item)
  6188. continue}
  6189. char_tb[item.charCodeAt(0)]='\n'}}
  6190. function set_user(parm){var k,c,v,a=parm.match(/(.)[=\s]*(\[I:.+\]|".+"|!.+!)$/)
  6191. if(!a){syntax(1,'Lack of starting [, ! or " in U: / %%user')
  6192. return}
  6193. c=a[1];v=a[2]
  6194. if(c[0]=='\\'){if(c[1]=='t')
  6195. c='\t'
  6196. else if(!c[1])
  6197. c=' '}
  6198. k=c.charCodeAt(0)
  6199. if(k>=128){syntax(1,errs.not_ascii)
  6200. return}
  6201. switch(char_tb[k][0]){case'0':case'd':case'i':case' ':break
  6202. case'"':case'!':case'[':if(char_tb[k].length>1)
  6203. break
  6204. default:syntax(1,"Bad user character '$1'",c)
  6205. return}
  6206. switch(v){case"!beambreak!":v=" "
  6207. break
  6208. case"!ignore!":v="i"
  6209. break
  6210. case"!nil!":case"!none!":v="d"
  6211. break}
  6212. char_tb[k]=v}
  6213. function get_st_lines(param){if(!param)
  6214. return
  6215. if(/^[\]\[|.-]+$/.test(param))
  6216. return param.replace(/\]/g,'[')
  6217. var n=+param
  6218. switch(n){case 0:return"..."
  6219. case 1:return"..|"
  6220. case 2:return".||"
  6221. case 3:return".|||"}
  6222. if(isNaN(n)||n<0||n>16)
  6223. return
  6224. return"||||||||||||||||".slice(0,n)}
  6225. function new_block(subtype){var c_v,s={type:C.BLOCK,subtype:subtype,dur:0}
  6226. c_v=curvoice
  6227. if(subtype.slice(0,4)!="midi")
  6228. curvoice=voice_tb[0]
  6229. sym_link(s)
  6230. if(c_v)
  6231. curvoice=c_v
  6232. return s}
  6233. Abc.prototype.set_vp=function(a){var s,item,pos,val,clefpit,tr_p=0
  6234. while(1){item=a.shift()
  6235. if(!item)
  6236. break
  6237. if(item.slice(-1)=='='&&!a.length){syntax(1,errs.bad_val,item)
  6238. break}
  6239. switch(item){case"clef=":s=a.shift()
  6240. break
  6241. case"clefpitch=":item=a.shift()
  6242. if(item){val=ntb.indexOf(item[0])
  6243. if(val>=0){switch(item[1]){case"'":val+=7
  6244. break
  6245. case',':val-=7
  6246. if(item[2]==',')
  6247. val-=7
  6248. break}
  6249. clefpit=4-val
  6250. break}}
  6251. syntax(1,errs.bad_val,item)
  6252. break
  6253. case"octave=":val=+a.shift()
  6254. if(isNaN(val))
  6255. syntax(1,errs.bad_val,item)
  6256. else
  6257. curvoice.octave=val
  6258. break
  6259. case"cue=":curvoice.scale=a.shift()=='on'?.7:1
  6260. break
  6261. case"instrument=":item=a.shift()
  6262. val=item.indexOf('/')
  6263. if(val<0){val=get_interval('c'+item)
  6264. if(val==undefined)
  6265. break
  6266. curvoice.sound=val
  6267. tr_p|=2
  6268. val=0}else{val=get_interval('c'+item.slice(val+1))
  6269. if(val==undefined)
  6270. break
  6271. curvoice.sound=val
  6272. tr_p|=2
  6273. val=get_interval(item.replace('/',''))
  6274. if(val==undefined)
  6275. break}
  6276. curvoice.score=cfmt.sound?curvoice.sound:val
  6277. tr_p|=1
  6278. break
  6279. case"map=":curvoice.map=a.shift()
  6280. break
  6281. case"name=":case"nm=":curvoice.nm=a.shift()
  6282. if(curvoice.nm[0]=='"')
  6283. curvoice.nm=cnv_escape(curvoice.nm.slice(1,-1))
  6284. curvoice.new_name=true
  6285. break
  6286. case"stem=":case"pos=":if(item=="pos=")
  6287. item=a.shift().slice(1,-1).split(' ')
  6288. else
  6289. item=["stm",a.shift()];val=posval[item[1]]
  6290. if(val==undefined){syntax(1,errs.bad_val,"%%pos")
  6291. break}
  6292. switch(item[2]){case"align":val|=C.SL_ALIGN;break
  6293. case"center":val|=C.SL_CENTER;break
  6294. case"close":val|=C.SL_CLOSE;break}
  6295. if(!pos)
  6296. pos={}
  6297. pos[item[0]]=val
  6298. break
  6299. case"scale=":val=+a.shift()
  6300. if(isNaN(val)||val<.5||val>2)
  6301. syntax(1,errs.bad_val,"%%voicescale")
  6302. else
  6303. curvoice.scale=val
  6304. break
  6305. case"score=":if(cfmt.nedo){syntax(1,errs.notransp)
  6306. break}
  6307. item=a.shift()
  6308. if(cfmt.sound)
  6309. break
  6310. val=get_interval(item,true)
  6311. if(val!=undefined){curvoice.score=val
  6312. tr_p|=1}
  6313. break
  6314. case"shift=":if(cfmt.nedo){syntax(1,errs.notransp)
  6315. break}
  6316. val=get_interval(a.shift())
  6317. if(val!=undefined){curvoice.shift=val
  6318. tr_p=3}
  6319. break
  6320. case"sound=":if(cfmt.nedo){syntax(1,errs.notransp)
  6321. break}
  6322. val=get_interval(a.shift())
  6323. if(val==undefined)
  6324. break
  6325. curvoice.sound=val
  6326. if(cfmt.sound)
  6327. curvoice.score=val
  6328. tr_p|=2
  6329. break
  6330. case"subname=":case"sname=":case"snm=":curvoice.snm=a.shift()
  6331. if(curvoice.snm[0]=='"')
  6332. curvoice.snm=curvoice.snm.slice(1,-1);break
  6333. case"stafflines=":val=get_st_lines(a.shift())
  6334. if(val==undefined)
  6335. syntax(1,"Bad %%stafflines value")
  6336. else if(curvoice.st!=undefined)
  6337. par_sy.staves[curvoice.st].stafflines=val
  6338. else
  6339. curvoice.stafflines=val
  6340. break
  6341. case"staffnonote=":val=+a.shift()
  6342. if(isNaN(val))
  6343. syntax(1,"Bad %%staffnonote value")
  6344. else
  6345. curvoice.staffnonote=val
  6346. break
  6347. case"staffscale=":val=+a.shift()
  6348. if(isNaN(val)||val<.3||val>2)
  6349. syntax(1,"Bad %%staffscale value")
  6350. else
  6351. curvoice.staffscale=val
  6352. break
  6353. case"tacet=":val=a.shift()
  6354. curvoice.tacet=val||undefined
  6355. break
  6356. case"transpose=":if(cfmt.nedo){syntax(1,errs.notransp)
  6357. break}
  6358. val=get_transp(a.shift())
  6359. if(val==undefined){syntax(1,errs.bad_transp)}else{curvoice.sound=val
  6360. if(cfmt.sound)
  6361. curvoice.score=val
  6362. tr_p=2}
  6363. break
  6364. default:switch(item.slice(0,4)){case"treb":case"bass":case"alto":case"teno":case"perc":s=item
  6365. break
  6366. default:if("GFC".indexOf(item[0])>=0)
  6367. s=item
  6368. else if(item.slice(-1)=='=')
  6369. a.shift()
  6370. break}
  6371. break}}
  6372. if(pos){curvoice.pos=clone(curvoice.pos)
  6373. for(item in pos)
  6374. if(pos.hasOwnProperty(item))
  6375. curvoice.pos[item]=pos[item]}
  6376. if(s){s=new_clef(s)
  6377. if(s){if(clefpit)
  6378. s.clefpit=clefpit
  6379. get_clef(s)}}
  6380. if(tr_p&2){tr_p=(curvoice.sound|0)+(curvoice.shift|0)
  6381. if(tr_p)
  6382. curvoice.tr_snd=abc2svg.b40m(tr_p+122)-36
  6383. else if(curvoice.tr_snd)
  6384. curvoice.tr_snd=0}}
  6385. function set_kv_parm(a){if(!curvoice.init){curvoice.init=true
  6386. if(info.V){if(info.V[curvoice.id])
  6387. a=info.V[curvoice.id].concat(a)
  6388. if(info.V['*'])
  6389. a=info.V['*'].concat(a)}}
  6390. if(a.length)
  6391. self.set_vp(a)}
  6392. function memo_kv_parm(vid,a){if(!a.length)
  6393. return
  6394. if(!info.V)
  6395. info.V={}
  6396. if(info.V[vid])
  6397. Array.prototype.push.apply(info.V[vid],a)
  6398. else
  6399. info.V[vid]=a}
  6400. 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}
  6401. set_ref(s);i=1
  6402. if(sf<-1){switch(param[0]){case'H':key_end=true
  6403. if(param[1].toLowerCase()!='p'){syntax(1,"Unknown bagpipe-like key")
  6404. break}
  6405. s.k_bagpipe=param[1];sf=param[1]=='P'?0:2;i++
  6406. if(!cfmt.temper)
  6407. 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])
  6408. break
  6409. case'P':syntax(1,"K:P is deprecated");sf=0;s.k_drum=true;key_end=true
  6410. break
  6411. case'n':if(param.indexOf("none")==0){sf=0;s.k_none=true;i=4
  6412. break}
  6413. default:s.k_map=[]
  6414. s.k_mode=0
  6415. return[s,info_split(param)]}}
  6416. if(!key_end){switch(param[i]){case'#':sf+=7;i++;break
  6417. case'b':sf-=7;i++;break}
  6418. param=param.slice(i).trim()
  6419. switch(param.slice(0,3).toLowerCase()){default:if(param[0]!='m'||(param[1]!=' '&&param[1]!='\t'&&param[1]!='\n')){key_end=true
  6420. break}
  6421. case"aeo":case"m":case"min":sf-=3;mode=5
  6422. break
  6423. case"dor":sf-=2;mode=1
  6424. break
  6425. case"ion":case"maj":break
  6426. case"loc":sf-=5;mode=6
  6427. break
  6428. case"lyd":sf+=1;mode=3
  6429. break
  6430. case"mix":sf-=1;mode=4
  6431. break
  6432. case"phr":sf-=4;mode=2
  6433. break}
  6434. if(!key_end)
  6435. param=param.replace(/\w+\s*/,'')
  6436. if(param.indexOf("exp ")==0){param=param.replace(/\w+\s*/,'')
  6437. if(!param)
  6438. syntax(1,"No accidental after 'exp'");s.exp=1}
  6439. c=param[0]
  6440. if(c=='^'||c=='_'||c=='='){s.k_a_acc=[];tmp=new scanBuf;tmp.buffer=param
  6441. do{note=parse_acc_pit(tmp)
  6442. if(!note)
  6443. break
  6444. s.k_a_acc.push(note);c=param[tmp.index]
  6445. while(c==' ')
  6446. c=param[++tmp.index]}while(c=='^'||c=='_'||c=='=');param=param.slice(tmp.index)}else if(s.exp&&param.indexOf("none")==0){sf=0
  6447. param=param.replace(/\w+\s*/,'')}}
  6448. if(sf<-7||sf>7){syntax(1,"Key with double sharps/flats")
  6449. if(sf>7)
  6450. sf-=12
  6451. else
  6452. sf+=12}
  6453. s.k_sf=sf;s.k_map=s.k_bagpipe&&!sf?abc2svg.keys[9]:abc2svg.keys[sf+7]
  6454. if(s.k_a_acc){s.k_map=new Int8Array(s.k_map)
  6455. i=s.k_a_acc.length
  6456. while(--i>=0){note=s.k_a_acc[i]
  6457. s.k_map[(note.pit+19)%7]=note.acc}}
  6458. s.k_mode=mode
  6459. s.k_b40=[1,24,7,30,13,36,19,2,25,8,31,14,37,20,3][sf+7]
  6460. return[s,info_split(param)]}
  6461. 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)
  6462. if(p.indexOf("none")==0){i=4;wmeasure=1}else{wmeasure=0
  6463. while(i<p.length){if(p[i]=='=')
  6464. break
  6465. switch(p[i]){case'C':meter.top=p[i++]
  6466. if(!m1){m1=4;m2=4}
  6467. break
  6468. case'c':case'o':meter.top=p[i++]
  6469. if(!m1){if(p[i-1]=='c'){m1=2;m2=4}else{m1=3;m2=4}
  6470. switch(p[i]){case'|':m2/=2
  6471. break
  6472. case'.':m1*=3;m2*=2
  6473. break}}
  6474. break
  6475. case'.':case'|':m1=0;meter.top=p[i++]
  6476. break
  6477. case'(':if(p[i+1]=='('){in_parenth=true;meter.top=p[i++];s.a_meter.push(meter);meter={}}
  6478. j=i+1
  6479. while(j<p.length){if(p[j]==')'||p[j]=='/')
  6480. break
  6481. j++}
  6482. if(p[j]==')'&&p[j+1]=='/'){i++
  6483. continue}
  6484. case')':in_parenth=p[i]=='(';meter.top=p[i++];s.a_meter.push(meter);meter={}
  6485. continue
  6486. default:if(p[i]<='0'||p[i]>'9'){syntax(1,"Bad char '$1' in M:",p[i])
  6487. return}
  6488. m2=2;meter.top=p[i++]
  6489. for(;;){while(p[i]>='0'&&p[i]<='9')
  6490. meter.top+=p[i++]
  6491. if(p[i]==')'){if(p[i+1]!='/')
  6492. break
  6493. i++}
  6494. if(p[i]=='/'){i++;if(p[i]<='0'||p[i]>'9'){syntax(1,"Bad char '$1' in M:",p[i])
  6495. return}
  6496. meter.bot=p[i++]
  6497. while(p[i]>='0'&&p[i]<='9')
  6498. meter.bot+=p[i++]
  6499. break}
  6500. if(p[i]!=' '&&p[i]!='+')
  6501. break
  6502. if(i>=p.length||p[i+1]=='(')
  6503. break
  6504. meter.top+=p[i++]}
  6505. m1=+meter.top
  6506. break}
  6507. if(!in_parenth){if(meter.bot)
  6508. m2=+meter.bot
  6509. wmeasure+=m1*C.BLEN/m2}
  6510. s.a_meter.push(meter);meter={}
  6511. while(p[i]==' ')
  6512. i++
  6513. if(p[i]=='+'){meter.top=p[i++];s.a_meter.push(meter);meter={}}}}
  6514. if(p[i]=='='){val=p.substring(++i).match(/^(\d+)\/(\d+)$/)
  6515. if(!val){syntax(1,"Bad duration '$1' in M:",p.substring(i))
  6516. return}
  6517. wmeasure=C.BLEN*val[1]/val[2]}
  6518. if(!wmeasure){syntax(1,errs.bad_val,'M:')
  6519. return}
  6520. s.wmeasure=wmeasure
  6521. if(cfmt.writefields.indexOf('M')<0)
  6522. s.a_meter=[]
  6523. if(parse.state!=3){info.M=p;glovar.meter=s
  6524. if(parse.state){if(!glovar.ulen){if(wmeasure<=1||wmeasure>=C.BLEN*3/4)
  6525. glovar.ulen=C.BLEN/8
  6526. else
  6527. glovar.ulen=C.BLEN/16}
  6528. for(v=0;v<voice_tb.length;v++){voice_tb[v].meter=s;voice_tb[v].wmeasure=wmeasure}}}else{curvoice.wmeasure=wmeasure
  6529. if(is_voice_sig())
  6530. curvoice.meter=s
  6531. else
  6532. sym_link(s)
  6533. for(p_v=curvoice.voice_down;p_v;p_v=p_v.voice_down)
  6534. p_v.wmeasure=wmeasure}}
  6535. function new_tempo(text){var i,c,d,nd,txt=text,s={type:C.TEMPO,dur:0}
  6536. function get_nd(p){var n,d,nd=p.match(/(\d+)\/(\d+)/)
  6537. if(nd){d=+nd[2]
  6538. if(d&&!isNaN(d)&&!(d&(d-1))){n=+nd[1]
  6539. if(!isNaN(n))
  6540. return C.BLEN*n/d}}
  6541. syntax(1,"Invalid note duration $1",c)}
  6542. set_ref(s)
  6543. if(cfmt.writefields.indexOf('Q')<0)
  6544. s.invis=true
  6545. if(text[0]=='"'){c=text.match(/"([^"]*)"/)
  6546. if(!c){syntax(1,"Unterminated string in Q:")
  6547. return}
  6548. s.tempo_str1=c[1]
  6549. text=text.slice(c[0].length).replace(/^\s+/,'')}
  6550. if(text.slice(-1)=='"'){i=text.indexOf('"')
  6551. s.tempo_str2=text.slice(i+1,-1)
  6552. text=text.slice(0,i).replace(/\s+$/,'')}
  6553. i=text.indexOf('=')
  6554. if(i>0){d=text.slice(0,i).split(/\s+/)
  6555. text=text.slice(i+1).replace(/^\s+/,'')
  6556. while(1){c=d.shift()
  6557. if(!c)
  6558. break
  6559. nd=get_nd(c)
  6560. if(!nd)
  6561. return
  6562. if(!s.tempo_notes)
  6563. s.tempo_notes=[]
  6564. s.tempo_notes.push(nd)}
  6565. if(text.slice(0,4)=="ca. "){s.tempo_ca='ca. '
  6566. text=text.slice(4)}
  6567. i=text.indexOf('/')
  6568. if(i>0){nd=get_nd(text)
  6569. if(!nd)
  6570. return
  6571. s.new_beat=nd}else{s.tempo=+text
  6572. if(!s.tempo||isNaN(s.tempo)){syntax(1,"Bad tempo value")
  6573. return}}}
  6574. if(parse.state<2||(!curvoice.time&&!glovar.tempo)){info.Q=txt
  6575. glovar.tempo=s
  6576. return}
  6577. if(!glovar.tempo)
  6578. syntax(0,"No previous tempo")
  6579. if(new_ctrl(s))
  6580. sym_link(s)}
  6581. function do_info(info_type,text){var s,d1,d2,a,vid,tim,v,p_v
  6582. if(curvoice&&curvoice.ignore){switch(info_type){default:return
  6583. case'P':case'Q':case'V':break}}
  6584. switch(info_type){case'I':self.do_pscom(text)
  6585. break
  6586. case'L':a=text.match(/^1\/(\d+)(=(\d+)\/(\d+))?$/)
  6587. if(a){d1=+a[1]
  6588. if(!d1||(d1&(d1-1))!=0)
  6589. break
  6590. d1=C.BLEN/d1
  6591. if(a[2]){d2=+a[4]
  6592. d2=d2?+a[3]/d2*C.BLEN:0}else{d2=d1}}else if(text=="auto"){d1=d2=-1}
  6593. if(!d2){syntax(1,"Bad L: value")
  6594. break}
  6595. if(parse.state<=1){glovar.ulen=d1}else{curvoice.ulen=d1;curvoice.dur_fact=d2/d1}
  6596. break
  6597. case'M':new_meter(text)
  6598. break
  6599. case'U':set_user(text)
  6600. break
  6601. case'P':if(!parse.state)
  6602. break
  6603. if(parse.state==1){info.P=text
  6604. break}
  6605. s={type:C.PART,text:text,time:tim}
  6606. if(!new_ctrl(s))
  6607. break
  6608. sym_link(s)
  6609. if(cfmt.writefields.indexOf(info_type)<0)
  6610. s.invis=true
  6611. break
  6612. case'Q':if(!parse.state)
  6613. break
  6614. new_tempo(text)
  6615. break
  6616. case'V':get_voice(text)
  6617. if(parse.state==3)
  6618. curvoice.ignore=!par_sy.voices[curvoice.v]
  6619. break
  6620. case'K':if(!parse.state)
  6621. break
  6622. get_key(text)
  6623. break
  6624. case'N':case'R':if(!info[info_type])
  6625. info[info_type]=text
  6626. else
  6627. info[info_type]+='\n'+text
  6628. break
  6629. case'r':if(!user.keep_remark||parse.state!=3)
  6630. break
  6631. s={type:C.REMARK,text:text,dur:0}
  6632. sym_link(s)
  6633. break
  6634. default:syntax(0,"'$1:' line ignored",info_type)
  6635. break}}
  6636. function adjust_dur(s){var s2,time,auto_time,i,fac;s2=curvoice.last_sym
  6637. if(!s2)
  6638. return;if(s2.type==C.MREST||s2.type==C.BAR)
  6639. return
  6640. while(s2.type!=C.BAR&&s2.prev)
  6641. s2=s2.prev;time=s2.time;auto_time=curvoice.time-time
  6642. fac=curvoice.wmeasure/auto_time
  6643. if(fac==1)
  6644. return
  6645. for(;s2;s2=s2.next){s2.time=time
  6646. if(!s2.dur||s2.grace)
  6647. continue
  6648. s2.dur*=fac;s2.dur_orig*=fac;time+=s2.dur
  6649. if(s2.type!=C.NOTE&&s2.type!=C.REST)
  6650. continue
  6651. for(i=0;i<=s2.nhd;i++)
  6652. s2.notes[i].dur*=fac}
  6653. curvoice.time=s.time=time}
  6654. 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}
  6655. if(vover&&vover.bar)
  6656. get_vover('|')
  6657. if(glovar.new_nbar){s.bar_num=glovar.new_nbar;glovar.new_nbar=0}
  6658. bar_type=line.char()
  6659. while(1){c=line.next_char()
  6660. switch(c){case'|':case'[':case']':case':':bar_type+=c
  6661. continue}
  6662. break}
  6663. if(bar_type[0]==':'){if(bar_type==':'){bar_type='|';s.bar_dotted=true}else{s.rbstop=2}}
  6664. if(a_gch)
  6665. csan_add(s)
  6666. if(a_dcn.length)
  6667. deco_cnv(s)
  6668. if(bar_type.slice(-1)=='['&&!(/[0-9" ]/.test(c))){bar_type=bar_type.slice(0,-1);line.index--;c='['}
  6669. if(c>'0'&&c<='9'){s.text=c
  6670. while(1){c=line.next_char()
  6671. if("0123456789,.-".indexOf(c)<0)
  6672. break
  6673. s.text+=c}}else if(c=='"'&&bar_type.slice(-1)=='['){s.text=""
  6674. while(1){c=line.next_char()
  6675. if(!c){syntax(1,"No end of repeat string")
  6676. return}
  6677. if(c=='"'){line.index++
  6678. break}
  6679. s.text+=c}}
  6680. if(bar_type[0]==']'){s.rbstop=2
  6681. if(bar_type.length!=1)
  6682. bar_type=bar_type.slice(1)
  6683. else
  6684. s.invis=true}
  6685. s.iend=parse.bol+line.index
  6686. if(s.text&&bar_type.slice(-1)=='['&&bar_type!='[')
  6687. bar_type=bar_type.slice(0,-1)
  6688. if(bar_type.slice(-1)==':'){s.rbstop=1
  6689. if(s.text){syntax(1,"Variant ending on a left repeat bar")
  6690. delete s.text}
  6691. curvoice.tie_s_rep=null}
  6692. if(s.text){s.rbstart=s.rbstop=2
  6693. if(s.text[0]=='1'){curvoice.tie_s_rep=curvoice.tie_s
  6694. if(curvoice.acc_tie)
  6695. curvoice.acc_tie_rep=curvoice.acc_tie.slice()
  6696. else if(curvoice.acc_tie_rep)
  6697. curvoice.acc_tie_rep=null}else{curvoice.tie_s=curvoice.tie_s_rep
  6698. if(curvoice.acc_tie_rep)
  6699. curvoice.acc_tie=curvoice.acc_tie_rep.slice()}
  6700. if(curvoice.norepbra&&!curvoice.second)
  6701. s.norepbra=1}
  6702. if(curvoice.ulen<0)
  6703. adjust_dur(s);if((bar_type=="["||bar_type=="|:")&&!curvoice.eoln&&!s.a_gch&&!s.invis){s2=curvoice.last_sym
  6704. if(s2&&s2.type==C.BAR){if((bar_type=="["&&!s2.text)||s.norepbra){if(s.text){s2.text=s.text
  6705. if(curvoice.st&&!s.norepbra&&!(par_sy.staves[curvoice.st-1].flags&STOP_BAR))
  6706. s2.xsh=4}
  6707. if(s.norepbra)
  6708. s2.norepbra=1
  6709. if(s.rbstart)
  6710. s2.rbstart=s.rbstart
  6711. if(s.rbstop)
  6712. s2.rbstop=s.rbstop
  6713. return}
  6714. if(bar_type=="|:"){switch(s2.bar_type){case":|":s2.bar_type="::";s2.rbstop=2
  6715. return}}}}
  6716. switch(bar_type){case"[":case"[]":case"[|]":s.invis=true;bar_type=s.rbstart?"[":"[]"
  6717. break
  6718. case":|:":case":||:":bar_type="::"
  6719. break
  6720. case"||":if(cfmt["abc-version"]>="2.2")
  6721. break
  6722. case"[|":case"|]":s.rbstop=2
  6723. break}
  6724. s.bar_type=bar_type
  6725. if(!curvoice.lyric_restart)
  6726. curvoice.lyric_restart=s
  6727. if(!curvoice.sym_restart)
  6728. curvoice.sym_restart=s
  6729. sym_link(s);s.st=curvoice.st
  6730. if(s.text&&s.st>0&&!s.norepbra&&!(par_sy.staves[s.st-1].flags&STOP_BAR)&&bar_type!='[')
  6731. s.xsh=4
  6732. if(!s.bar_dotted&&!s.invis)
  6733. curvoice.acc=[]}
  6734. 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)
  6735. if(!a){syntax(1,errs.bad_val,"%%score")
  6736. return}
  6737. while(1){e=a.shift()
  6738. if(!e)
  6739. break
  6740. switch(e){case'[':if(parenth||brace+bracket>=2){syntax(1,errs.misplaced,'[');err=true
  6741. break}
  6742. flags|=brace+bracket==0?OPEN_BRACKET:OPEN_BRACKET2;bracket++;flags_st<<=8;flags_st|=OPEN_BRACKET
  6743. break
  6744. case'{':if(parenth||brace||bracket>=2){syntax(1,errs.misplaced,'{');err=true
  6745. break}
  6746. flags|=!bracket?OPEN_BRACE:OPEN_BRACE2;brace++;flags_st<<=8;flags_st|=OPEN_BRACE
  6747. break
  6748. case'(':if(parenth){syntax(1,errs.misplaced,'(');err=true
  6749. break}
  6750. flags|=OPEN_PARENTH;parenth++;flags_st<<=8;flags_st|=OPEN_PARENTH
  6751. break
  6752. case'*':if(brace&&!parenth&&!(flags&(OPEN_BRACE|OPEN_BRACE2)))
  6753. flags|=FL_VOICE
  6754. break
  6755. case'+':flags|=MASTER_VOICE
  6756. break
  6757. case']':case'}':case')':syntax(1,"Bad voice ID in %%score");err=true
  6758. break
  6759. default:vid=e
  6760. while(1){e=a.shift()
  6761. if(!e)
  6762. break
  6763. switch(e){case']':if(!(flags_st&OPEN_BRACKET)){syntax(1,errs.misplaced,']');err=true
  6764. break}
  6765. bracket--;flags|=brace+bracket==0?CLOSE_BRACKET:CLOSE_BRACKET2;flags_st>>=8
  6766. continue
  6767. case'}':if(!(flags_st&OPEN_BRACE)){syntax(1,errs.misplaced,'}');err=true
  6768. break}
  6769. brace--;flags|=!bracket?CLOSE_BRACE:CLOSE_BRACE2;flags&=~FL_VOICE;flags_st>>=8
  6770. continue
  6771. case')':if(!(flags_st&OPEN_PARENTH)){syntax(1,errs.misplaced,')');err=true
  6772. break}
  6773. parenth--;flags|=CLOSE_PARENTH;flags_st>>=8
  6774. continue
  6775. case'|':flags|=STOP_BAR
  6776. continue}
  6777. break}
  6778. if(vids[vid]){syntax(1,"Double voice in %%score")
  6779. err=true}else{vids[vid]=true
  6780. a_vf.push([vid,flags])}
  6781. flags=0
  6782. if(!e)
  6783. break
  6784. a.unshift(e)
  6785. break}}
  6786. if(flags_st!=0){syntax(1,"'}', ')' or ']' missing in %%score");err=true}
  6787. if(err||!a_vf.length)
  6788. return
  6789. return a_vf}
  6790. function info_split(text){if(!text)
  6791. return[]
  6792. var a=text.match(/[^\s"=]+=?|"[^"]*"/g)
  6793. if(!a){syntax(1,"Unterminated string")
  6794. return[]}
  6795. return a}
  6796. var reg_dur=/(\d*)(\/*)(\d*)/g
  6797. function parse_dur(line){var res,num,den;reg_dur.lastIndex=line.index;res=reg_dur.exec(line.buffer)
  6798. if(!res[0])
  6799. return[1,1];num=res[1]||1;den=res[3]||1
  6800. if(!res[3])
  6801. den*=1<<res[2].length;line.index=reg_dur.lastIndex
  6802. return[+num,+den]}
  6803. function parse_acc_pit(line){var note,acc,pit,d,nd,c=line.char()
  6804. switch(c){case'^':c=line.next_char()
  6805. if(c=='^'){acc=2;c=line.next_char()}else{acc=1}
  6806. break
  6807. case'=':acc=3;c=line.next_char()
  6808. break
  6809. case'_':c=line.next_char()
  6810. if(c=='_'){acc=-2;c=line.next_char()}else{acc=-1}
  6811. break}
  6812. if(acc==1||acc==-1){if((c>='1'&&c<='9')||c=='/'){nd=parse_dur(line);if(acc<0)
  6813. nd[0]=-nd[0]
  6814. if(cfmt.nedo&&nd[1]==1){nd[0]*=12
  6815. nd[1]*=cfmt.nedo}
  6816. acc=nd
  6817. c=line.char()}}
  6818. pit=ntb.indexOf(c)+16;c=line.next_char()
  6819. if(pit<16){syntax(1,"'$1' is not a note",line.buffer[line.index-1])
  6820. return}
  6821. while(c=="'"){pit+=7;c=line.next_char()}
  6822. while(c==','){pit-=7;c=line.next_char()}
  6823. note={pit:pit,shhd:0,shac:0}
  6824. if(acc)
  6825. note.acc=acc
  6826. return note}
  6827. function set_map(note,acc){var pit=note.pit,nn=not2abc(pit,acc),map=maps[curvoice.map]
  6828. if(!map[nn]){nn='o'+nn.replace(/[',]+/,'')
  6829. if(!map[nn]){nn='k'+ntb[(pit+75-
  6830. curvoice.ckey.k_sf*11)%7]
  6831. if(!map[nn]){nn='all'
  6832. if(!map[nn])
  6833. return}}}
  6834. note.map=map=map[nn]
  6835. if(map[1]){note.pit=pit=map[1].pit
  6836. note.acc=map[1].acc
  6837. if(map[1].notrp){note.notrp=1
  6838. note.noplay=1}}
  6839. if(map[2])
  6840. note.color=map[2]
  6841. nn=map[3]
  6842. if(nn)
  6843. note.midi=pit2mid(nn.pit+19,nn.acc)}
  6844. function parse_basic_note(line,ulen){var nd,note=parse_acc_pit(line)
  6845. if(!note)
  6846. return
  6847. if(line.char()=='0'){parse.stemless=true;line.index++}
  6848. nd=parse_dur(line);note.dur=ulen*nd[0]/nd[1]
  6849. return note}
  6850. function parse_vpos(){var line=parse.line,ty=0
  6851. if(a_dcn.length&&a_dcn[a_dcn.length-1]=="dot"){ty=C.SL_DOTTED
  6852. a_dcn.pop()}
  6853. switch(line.next_char()){case"'":line.index++
  6854. return ty+C.SL_ABOVE
  6855. case",":line.index++
  6856. return ty+C.SL_BELOW
  6857. case'?':line.index++
  6858. return ty+C.SL_CENTER}
  6859. return ty+C.SL_AUTO}
  6860. function slur_add(s,nt){var i,s2,sl
  6861. for(i=curvoice.sls.length;--i>=0;){sl=curvoice.sls[i]
  6862. if(sl.ss==s)
  6863. continue
  6864. curvoice.sls.splice(i,1)
  6865. sl.se=s
  6866. if(nt)
  6867. sl.nte=nt
  6868. s2=sl.ss
  6869. if(!s2.sls)
  6870. s2.sls=[]
  6871. s2.sls.push(sl)
  6872. if(sl.grace)
  6873. sl.grace.sl1=true
  6874. return}
  6875. for(s2=s.prev;s2;s2=s2.prev){if(s2.type==C.BAR&&s2.bar_type[0]==':'&&s2.text){if(!s2.sls)
  6876. s2.sls=[];s2.sls.push({ty:C.SL_AUTO,ss:s2,se:s})
  6877. if(nt)
  6878. s2.sls[s2.sls.length-1].nte=nt
  6879. return}}
  6880. if(!s.sls)
  6881. s.sls=[];s.sls.push({ty:C.SL_AUTO,se:s,loc:'i'})
  6882. if(nt)
  6883. s.sls[s.sls.length-1].nte=nt}
  6884. function pit2mid(pit,acc){var p=[0,2,4,5,7,9,11][pit%7],o=((pit/7)|0)*12,p0,p1,s,b40
  6885. if(curvoice.snd_oct)
  6886. o+=curvoice.snd_oct
  6887. if(acc==3)
  6888. acc=0
  6889. if(acc){if(typeof acc=="object"){s=acc[0]/acc[1]
  6890. if(acc[1]==100)
  6891. return p+o+s}else{s=acc}}else{if(cfmt.temper)
  6892. return cfmt.temper[abc2svg.p_b40[pit%7]]+o
  6893. return p+o}
  6894. if(!cfmt.nedo){if(!cfmt.temper){p+=o+s
  6895. return p}}else{if(typeof acc!="object"){b40=abc2svg.p_b40[pit%7]+acc
  6896. return cfmt.temper[b40]+o}
  6897. if(acc[1]==cfmt.nedo){b40=abc2svg.p_b40[pit%7]
  6898. return cfmt.temper[b40]+o+s}}
  6899. p0=cfmt.temper[abc2svg.p_b40[pit%7]]
  6900. if(s>0){p1=cfmt.temper[(abc2svg.p_b40[pit%7]+1)%40]
  6901. if(p1<p0)
  6902. p1+=12}else{p1=cfmt.temper[(abc2svg.p_b40[pit%7]+39)%40]
  6903. if(p1>p0)
  6904. p1-=12
  6905. s=-s}
  6906. return p0+o+(p1-p0)*s}
  6907. function do_ties(s,tie_s){var i,m,not1,not2,mid,g,nt=0,se=(tie_s.time+tie_s.dur)==curvoice.time
  6908. for(m=0;m<=s.nhd;m++){not2=s.notes[m]
  6909. mid=not2.midi
  6910. if(tie_s.type!=C.GRACE){for(i=0;i<=tie_s.nhd;i++){not1=tie_s.notes[i]
  6911. if(!not1.tie_ty)
  6912. continue
  6913. if(not1.midi==mid&&(!se||!not1.tie_e)){not2.tie_s=not1
  6914. not2.s=s
  6915. if(se){not1.tie_e=not2
  6916. not1.s=tie_s}
  6917. nt++
  6918. break}}}else{for(g=tie_s.extra;g;g=g.next){not1=g.notes[0]
  6919. if(!not1.tie_ty)
  6920. continue
  6921. if(not1.midi==mid){g.ti1=true
  6922. not2.tie_s=not1
  6923. not2.s=s
  6924. not1.tie_e=not2
  6925. not1.s=g
  6926. nt++
  6927. break}}}}
  6928. if(!nt)
  6929. error(1,tie_s,"Bad tie")
  6930. else
  6931. s.ti2=true}
  6932. 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
  6933. a_dcn=[]
  6934. parse.stemless=false;s={type:C.NOTE,fname:parse.fname,stem:0,multi:0,nhd:0,xmx:0}
  6935. s.istart=parse.bol+line.index
  6936. if(curvoice.color)
  6937. s.color=curvoice.color
  6938. if(grace){s.grace=true}else{if(curvoice.tie_s){tie_s=curvoice.tie_s
  6939. curvoice.tie_s=null}
  6940. if(a_gch)
  6941. csan_add(s)
  6942. if(parse.repeat_n){s.repeat_n=parse.repeat_n;s.repeat_k=parse.repeat_k;parse.repeat_n=0}}
  6943. c=line.char()
  6944. switch(c){case'X':s.invis=true
  6945. case'Z':s.type=C.MREST;c=line.next_char()
  6946. s.nmes=(c>'0'&&c<='9')?line.get_int():1;if(curvoice.wmeasure==1){error(1,s,"multi-measure rest, but no measure!")
  6947. return}
  6948. s.dur=curvoice.wmeasure*s.nmes
  6949. if(curvoice.second){delete curvoice.eoln
  6950. curvoice.time+=s.dur
  6951. return}
  6952. if(s.nmes==1){s.type=C.REST;s.dur_orig=s.dur;s.fmr=1
  6953. s.notes=[{pit:18,dur:s.dur}]}else{glovar.mrest_p=true
  6954. if(par_sy.voices.length==1){s.tacet=curvoice.tacet
  6955. delete s.invis}}
  6956. break
  6957. case'y':s.type=C.SPACE;s.invis=true;s.dur=0;c=line.next_char()
  6958. if(c>='0'&&c<='9')
  6959. s.width=line.get_int()
  6960. else
  6961. s.width=10
  6962. if(tie_s){curvoice.tie_s=tie_s
  6963. tie_s=null}
  6964. break
  6965. case'x':s.invis=true
  6966. 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)
  6967. s.fmr=1
  6968. s.notes=[{pit:18,dur:s.dur_orig}]
  6969. break
  6970. case'[':in_chord=true;c=line.next_char()
  6971. default:if(curvoice.acc_tie){acc_tie=curvoice.acc_tie
  6972. curvoice.acc_tie=null}
  6973. s.notes=[]
  6974. while(1){if(in_chord){while(1){if(!c)
  6975. break
  6976. i=c.charCodeAt(0);if(i>=128){syntax(1,errs.not_ascii)
  6977. return}
  6978. type=char_tb[i]
  6979. switch(type[0]){case'(':sl1.push(parse_vpos());c=line.char()
  6980. continue
  6981. case'!':if(type.length>1)
  6982. a_dcn.push(type.slice(1,-1))
  6983. else
  6984. get_deco()
  6985. c=line.next_char()
  6986. continue}
  6987. break}}
  6988. note=parse_basic_note(line,s.grace?C.BLEN/4:curvoice.ulen<0?C.BLEN:curvoice.ulen)
  6989. if(!note)
  6990. return
  6991. if(curvoice.octave)
  6992. note.pit+=curvoice.octave*7
  6993. apit=note.pit+19
  6994. i=note.acc
  6995. if(!i){if(cfmt["propagate-accidentals"][0]=='p')
  6996. i=curvoice.acc[apit%7]
  6997. else
  6998. i=curvoice.acc[apit]
  6999. if(!i)
  7000. i=curvoice.ckey.k_map[apit%7]||0}
  7001. if(i){if(cfmt["propagate-accidentals"][0]=='p')
  7002. curvoice.acc[apit%7]=i
  7003. else if(cfmt["propagate-accidentals"][0]!='n')
  7004. curvoice.acc[apit]=i}
  7005. if(acc_tie&&acc_tie[apit])
  7006. i=acc_tie[apit]
  7007. if(curvoice.map&&maps[curvoice.map])
  7008. set_map(note,i)
  7009. if(!note.midi)
  7010. note.midi=pit2mid(apit,i)
  7011. if(curvoice.tr_sco&&!note.notrp){i=nt_trans(note,i)
  7012. if(i==-3){error(1,s,"triple sharp/flat")
  7013. i=note.acc>0?1:-1
  7014. note.pit+=i
  7015. note.acc=i}
  7016. dpit=note.pit+19-apit}
  7017. if(curvoice.tr_snd)
  7018. note.midi+=curvoice.tr_snd
  7019. if(i){switch(cfmt["writeout-accidentals"][1]){case'd':s2=curvoice.ckey
  7020. if(!s2.k_a_acc)
  7021. break
  7022. for(n=0;n<s2.k_a_acc.length;n++){if((s2.k_a_acc[n].pit-note.pit)%7==0){note.acc=i
  7023. break}}
  7024. break
  7025. case'l':note.acc=i
  7026. break}}
  7027. if(sl1.length){while(1){i=sl1.shift()
  7028. if(!i)
  7029. break
  7030. curvoice.sls.push({ty:i,ss:s,nts:note})}}
  7031. if(a_dcn.length){s.time=curvoice.time
  7032. dh_cnv(s,note)}
  7033. s.notes.push(note)
  7034. if(!in_chord)
  7035. break
  7036. c=line.char()
  7037. while(1){switch(c){case')':slur_add(s,note)
  7038. c=line.next_char()
  7039. continue
  7040. case'-':note.tie_ty=parse_vpos()
  7041. note.s=s
  7042. curvoice.tie_s=s
  7043. s.ti1=true
  7044. if(curvoice.acc[apit]||(acc_tie&&acc_tie[apit])){if(!curvoice.acc_tie)
  7045. curvoice.acc_tie=[]
  7046. i=curvoice.acc[apit]
  7047. if(acc_tie&&acc_tie[apit])
  7048. i=acc_tie[apit]
  7049. curvoice.acc_tie[apit]=i}
  7050. c=line.char()
  7051. continue
  7052. case'.':c=line.next_char()
  7053. switch(c){case'-':case'(':a_dcn.push("dot")
  7054. continue}
  7055. syntax(1,"Misplaced dot")
  7056. break}
  7057. break}
  7058. if(c==']'){line.index++;nd=parse_dur(line);s.nhd=s.notes.length-1
  7059. for(i=0;i<=s.nhd;i++){note=s.notes[i];note.dur=note.dur*nd[0]/nd[1]}
  7060. break}}
  7061. if(sls.length){while(1){i=sls.shift()
  7062. if(!i)
  7063. break
  7064. curvoice.sls.push({ty:i,ss:s})
  7065. if(grace)
  7066. curvoice.sls[curvoice.sls.length-1].grace=grace}}
  7067. s.dur_orig=s.notes[0].dur;s.dur=s.notes[0].dur*curvoice.dur_fact
  7068. break}
  7069. if(s.grace&&s.type!=C.NOTE){syntax(1,errs.bad_grace)
  7070. return}
  7071. if(s.notes){if(!grace){switch(curvoice.pos.stm&0x07){case C.SL_ABOVE:s.stem=1;break
  7072. case C.SL_BELOW:s.stem=-1;break
  7073. case C.SL_HIDDEN:s.stemless=true;break}
  7074. num=curvoice.brk_rhythm
  7075. if(num){curvoice.brk_rhythm=0;s2=curvoice.last_note
  7076. if(num>0){n=num*2-1;s.dur=s.dur*n/num;s.dur_orig=s.dur_orig*n/num
  7077. for(i=0;i<=s.nhd;i++)
  7078. s.notes[i].dur=s.notes[i].dur*n/num;s2.dur/=num;s2.dur_orig/=num
  7079. for(i=0;i<=s2.nhd;i++)
  7080. s2.notes[i].dur/=num}else{num=-num;n=num*2-1;s.dur/=num;s.dur_orig/=num
  7081. for(i=0;i<=s.nhd;i++)
  7082. s.notes[i].dur/=num;s2.dur=s2.dur*n/num;s2.dur_orig=s2.dur_orig*n/num
  7083. for(i=0;i<=s2.nhd;i++)
  7084. s2.notes[i].dur=s2.notes[i].dur*n/num}
  7085. curvoice.time=s2.time+s2.dur;for(s2=s2.next;s2;s2=s2.next)
  7086. s2.time=curvoice.time}}else{div=curvoice.ckey.k_bagpipe?8:4
  7087. for(i=0;i<=s.nhd;i++)
  7088. s.notes[i].dur/=div;s.dur/=div;s.dur_orig/=div
  7089. if(grace.stem)
  7090. s.stem=grace.stem}
  7091. curvoice.last_note=s
  7092. c=line.char()
  7093. while(1){switch(c){case'.':if(line.buffer[line.index+1]!='-')
  7094. break
  7095. a_dcn.push("dot")
  7096. line.index++
  7097. case'-':ty=parse_vpos()
  7098. for(i=0;i<=s.nhd;i++){s.notes[i].tie_ty=ty
  7099. s.notes[i].s=s}
  7100. curvoice.tie_s=grace||s
  7101. curvoice.tie_s.ti1=true
  7102. for(i=0;i<=s.nhd;i++){note=s.notes[i]
  7103. apit=note.pit+19
  7104. -dpit
  7105. if(curvoice.acc[apit]||(acc_tie&&acc_tie[apit])){if(!curvoice.acc_tie)
  7106. curvoice.acc_tie=[]
  7107. n=curvoice.acc[apit]
  7108. if(acc_tie&&acc_tie[apit])
  7109. n=acc_tie[apit]
  7110. curvoice.acc_tie[apit]=n}}
  7111. c=line.char()
  7112. continue}
  7113. break}
  7114. if(tie_s)
  7115. do_ties(s,tie_s)}
  7116. sym_link(s)
  7117. if(!grace){if(!curvoice.lyric_restart)
  7118. curvoice.lyric_restart=s
  7119. if(!curvoice.sym_restart)
  7120. curvoice.sym_restart=s}
  7121. if(a_dcn_sav.length){a_dcn=a_dcn_sav
  7122. deco_cnv(s,s.prev)}
  7123. if(grace&&s.ottava)
  7124. grace.ottava=s.ottava
  7125. if(parse.stemless)
  7126. s.stemless=true
  7127. s.iend=parse.bol+line.index
  7128. return s}
  7129. function tp_adj(s,fact){var d,tim=s.time,to=curvoice.time-tim,tt=to*fact
  7130. curvoice.time=tim+tt
  7131. while(1){s.in_tuplet=true
  7132. if(!s.grace){s.time=tim
  7133. if(s.dur){d=Math.round(s.dur*tt/to)
  7134. to-=s.dur
  7135. s.dur=d
  7136. tt-=s.dur
  7137. tim+=s.dur}}
  7138. if(!s.next){if(s.tpe)
  7139. s.tpe++
  7140. else
  7141. s.tpe=1
  7142. break}
  7143. s=s.next}}
  7144. function get_deco(){var c,line=parse.line,i=line.index,dcn=""
  7145. while(1){c=line.next_char()
  7146. if(!c){line.index=i
  7147. syntax(1,"No end of decoration")
  7148. return}
  7149. if(c=='!')
  7150. break
  7151. dcn+=c}
  7152. a_dcn.push(dcn)}
  7153. 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,]
  7154. function parse_music_line(){var grace,last_note_sav,a_dcn_sav,no_eol,s,tps,tp=[],tpn=-1,sls=[],line=parse.line
  7155. function check_mac(m){var i,j,b
  7156. for(i=1,j=line.index+1;i<m.length;i++,j++){if(m[i]==line.buffer[j])
  7157. continue
  7158. if(m[i]!='n')
  7159. return
  7160. b=ntb.indexOf(line.buffer[j])
  7161. if(b<0)
  7162. return
  7163. while(line.buffer[j+1]=="'"){b+=7;j++}
  7164. while(line.buffer[j+1]==','){b-=7;j++}}
  7165. line.index=j
  7166. return b}
  7167. function n2n(n){var c=''
  7168. while(n<0){n+=7;c+=','}
  7169. while(n>=14){n-=7;c+="'"}
  7170. return ntb[n]+c}
  7171. function expand(m,b){if(b==undefined)
  7172. return m
  7173. var c,i,r="",n=m.length
  7174. for(i=0;i<n;i++){c=m[i]
  7175. if(c>='h'&&c<='z'){r+=n2n(b+c.charCodeAt(0)-'n'.charCodeAt(0))}else{r+=c}}
  7176. return r}
  7177. 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))
  7178. s=curvoice.last_sym
  7179. ti=curvoice.time
  7180. parse_seq(true)
  7181. if(!s)
  7182. s=curvoice.sym
  7183. for(s=s.next;s;s=s.next)
  7184. s.noplay=true
  7185. te=curvoice.time
  7186. curv=curvoice
  7187. curvoice=clone_voice(curv.id+'-p')
  7188. if(!par_sy.voices[curvoice.v]){curvoice.second=true
  7189. par_sy.voices[curvoice.v]={st:curv.st,second:true,range:curvoice.v}}
  7190. curvoice.time=ti
  7191. s=curvoice.last_sym
  7192. parse.line=line=new scanBuf
  7193. parse.istart+=line_sav.index
  7194. line.buffer=expand(m,b)
  7195. parse_seq(true)
  7196. if(curvoice.time!=te)
  7197. syntax(1,"Bad length of the macro sequence")
  7198. if(!s)
  7199. s=curvoice.sym
  7200. for(;s;s=s.next)
  7201. s.invis=s.play=true
  7202. curvoice=curv}else{line.buffer=expand(m,b)
  7203. parse_seq(true)}
  7204. parse.line=line=line_sav
  7205. parse.istart=istart_sav}
  7206. function parse_seq(in_mac){var c,idx,type,k,s,dcn,i,n,text,note
  7207. while(1){c=line.char()
  7208. if(!c)
  7209. break
  7210. if(!in_mac&&maci[c]){n=undefined
  7211. for(k in mac){if(!mac.hasOwnProperty(k)||k[0]!=c)
  7212. continue
  7213. if(k.indexOf('n')<0){if(line.buffer.indexOf(k,line.index)
  7214. !=line.index)
  7215. continue
  7216. line.index+=k.length}else{n=check_mac(k)
  7217. if(n==undefined)
  7218. continue}
  7219. parse_mac(k,mac[k],n)
  7220. n=1
  7221. break}
  7222. if(n)
  7223. continue}
  7224. idx=c.charCodeAt(0)
  7225. if(idx>=128){syntax(1,errs.not_ascii)
  7226. line.index++
  7227. break}
  7228. type=char_tb[idx]
  7229. switch(type[0]){case' ':s=curvoice.last_note
  7230. if(s){s.beam_end=true
  7231. if(grace)
  7232. grace.gr_shift=true}
  7233. break
  7234. case'\n':if(cfmt.barsperstaff)
  7235. break
  7236. curvoice.eoln=true
  7237. break
  7238. case'&':if(grace){syntax(1,errs.bad_grace)
  7239. break}
  7240. c=line.next_char()
  7241. if(c==')'){get_vover(c)
  7242. break}
  7243. get_vover('&')
  7244. continue
  7245. case'(':c=line.next_char()
  7246. if(c>'0'&&c<='9'){if(grace){syntax(1,errs.bad_grace)
  7247. break}
  7248. var pplet=line.get_int(),qplet=qplet_tb[pplet],rplet=pplet
  7249. c=line.char()
  7250. if(c==':'){c=line.next_char()
  7251. if(c>'0'&&c<='9'){qplet=line.get_int();c=line.char()}
  7252. if(c==':'){c=line.next_char()
  7253. if(c>'0'&&c<='9'){rplet=line.get_int();c=line.char()}else{syntax(1,"Invalid 'r' in tuplet")
  7254. continue}}}
  7255. if(qplet==0||qplet==undefined)
  7256. qplet=(curvoice.wmeasure%9)==0?3:2;if(tpn<0)
  7257. tpn=tp.length
  7258. tp.push({p:pplet,q:qplet,r:rplet,ro:rplet,f:curvoice.tup||cfmt.tuplets})
  7259. continue}
  7260. if(c=='&'){if(grace){syntax(1,errs.bad_grace)
  7261. break}
  7262. get_vover('(')
  7263. break}
  7264. line.index--;sls.push(parse_vpos())
  7265. continue
  7266. case')':s=curvoice.last_sym
  7267. if(s){switch(s.type){case C.SPACE:if(!s.notes){s.notes=[]
  7268. s.notes[0]={}}
  7269. case C.NOTE:case C.REST:break
  7270. case C.GRACE:for(s=s.extra;s.next;s=s.next);break
  7271. default:s=null
  7272. break}}
  7273. if(!s){syntax(1,errs.bad_char,c)
  7274. break}
  7275. slur_add(s)
  7276. break
  7277. case'!':if(type.length>1)
  7278. a_dcn.push(type.slice(1,-1))
  7279. else
  7280. get_deco()
  7281. break
  7282. case'"':if(grace){syntax(1,errs.bad_grace)
  7283. break}
  7284. parse_gchord(type)
  7285. break
  7286. case'[':if(type.length>1){self.do_pscom(type.slice(3,-1))
  7287. break}
  7288. var c_next=line.buffer[line.index+1]
  7289. if('|[]: "'.indexOf(c_next)>=0||(c_next>='1'&&c_next<='9')){if(grace){syntax(1,errs.bar_grace)
  7290. break}
  7291. new_bar()
  7292. continue}
  7293. if(line.buffer[line.index+2]==':'){if(grace){syntax(1,errs.bad_grace)
  7294. break}
  7295. i=line.buffer.indexOf(']',line.index+1)
  7296. if(i<0){syntax(1,"Lack of ']'")
  7297. break}
  7298. text=line.buffer.slice(line.index+3,i).trim()
  7299. parse.istart=parse.bol+line.index;parse.iend=parse.bol+ ++i;line.index=0;do_info(c_next,text);line.index=i
  7300. continue}
  7301. case'n':s=self.new_note(grace,sls)
  7302. if(!s)
  7303. continue
  7304. if(grace||!s.notes)
  7305. continue
  7306. if(tpn>=0){s.tp=tp.slice(tpn)
  7307. tpn=-1
  7308. if(tps)
  7309. s.tp[0].s=tps
  7310. tps=s}else if(!tps){continue}
  7311. k=tp[tp.length-1]
  7312. if(--k.r>0)
  7313. continue
  7314. while(1){tp_adj(tps,k.q/k.p)
  7315. i=k.ro
  7316. if(k.s)
  7317. tps=k.s
  7318. tp.pop()
  7319. if(!tp.length){tps=null
  7320. break}
  7321. k=tp[tp.length-1]
  7322. k.r-=i
  7323. if(k.r>0)
  7324. break}
  7325. continue
  7326. case'<':if(!curvoice.last_note){syntax(1,"No note before '<'")
  7327. break}
  7328. if(grace){syntax(1,"Cannot have a broken rhythm in grace notes")
  7329. break}
  7330. n=c=='<'?1:-1
  7331. while(c=='<'||c=='>'){n*=2;c=line.next_char()}
  7332. curvoice.brk_rhythm=n
  7333. continue
  7334. case'i':break
  7335. case'{':if(grace){syntax(1,"'{' in grace note")
  7336. break}
  7337. last_note_sav=curvoice.last_note;curvoice.last_note=null;a_dcn_sav=a_dcn;a_dcn=[]
  7338. grace={type:C.GRACE,fname:parse.fname,istart:parse.bol+line.index,dur:0,multi:0}
  7339. if(curvoice.color)
  7340. grace.color=curvoice.color
  7341. switch(curvoice.pos.gst&0x07){case C.SL_ABOVE:grace.stem=1;break
  7342. case C.SL_BELOW:grace.stem=-1;break
  7343. case C.SL_HIDDEN:grace.stem=2;break}
  7344. sym_link(grace);c=line.next_char()
  7345. if(c=='/'){grace.sappo=true
  7346. break}
  7347. continue
  7348. case'|':if(grace){syntax(1,errs.bar_grace)
  7349. break}
  7350. new_bar()
  7351. continue
  7352. case'}':if(curvoice.ignore){grace=null
  7353. break}
  7354. s=curvoice.last_note
  7355. if(!grace||!s){syntax(1,errs.bad_char,c)
  7356. break}
  7357. if(a_dcn.length)
  7358. syntax(1,"Decoration ignored");grace.extra=grace.next;grace.extra.prev=null;grace.next=null;curvoice.last_sym=grace;grace=null
  7359. if(!s.prev&&!curvoice.ckey.k_bagpipe){for(i=0;i<=s.nhd;i++)
  7360. s.notes[i].dur*=2;s.dur*=2;s.dur_orig*=2}
  7361. curvoice.last_note=last_note_sav;a_dcn=a_dcn_sav
  7362. break
  7363. case"\\":if(!line.buffer[line.index+1]){no_eol=true
  7364. break}
  7365. default:syntax(1,errs.bad_char,c)
  7366. break}
  7367. line.index++}}
  7368. if(parse.state!=3)
  7369. return
  7370. if(parse.tp){tp=parse.tp
  7371. tpn=parse.tpn
  7372. tps=parse.tps
  7373. parse.tp=null}
  7374. parse_seq()
  7375. if(tp.length){parse.tp=tp
  7376. parse.tps=tps
  7377. parse.tpn=tpn}
  7378. if(sls.length)
  7379. syntax(1,"Start of slur without note")
  7380. if(grace){syntax(1,"No end of grace note sequence");curvoice.last_sym=grace.prev;curvoice.last_note=last_note_sav
  7381. if(grace.prev)
  7382. grace.prev.next=null}
  7383. if(!no_eol&&!cfmt.barsperstaff&&!vover&&char_tb['\n'.charCodeAt(0)]=='\n')
  7384. curvoice.eoln=true
  7385. if(curvoice.eoln&&cfmt.breakoneoln&&curvoice.last_note)
  7386. curvoice.last_note.beam_end=true}
  7387. var sheet
  7388. var add_fstyle=typeof document!="undefined"?function(s){var e
  7389. if(cfmt.fullsvg)
  7390. font_style+="\n"+s
  7391. if(!sheet){if(abc2svg.sheet){sheet=abc2svg.sheet
  7392. e=sheet.cssRules.length
  7393. while(--e>=0)
  7394. sheet.deleteRule(e)}else{e=document.createElement('style')
  7395. document.head.appendChild(e)
  7396. abc2svg.sheet=sheet=e.sheet}}
  7397. s=s.match(/[^{]+{[^}]+}/g)
  7398. while(1){e=s.shift()
  7399. if(!e)
  7400. break
  7401. sheet.insertRule(e,sheet.cssRules.length)}}:function(s){font_style+="\n"+s}
  7402. var
  7403. 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
  7404. function cwid(c){var i=c.charCodeAt(0)
  7405. if(i>=0x80){if(i>=0x300&&i<0x370)
  7406. return 0;i=0x61}
  7407. return cw_tb[i]}
  7408. function cwidf(c){return cwid(c)*gene.curfont.swfac}
  7409. var strwh
  7410. (function(){if(typeof document!="undefined"){var el
  7411. strwh=function(str){if(str.wh)
  7412. return str.wh
  7413. if(!el){el=document.createElement('text')
  7414. el.style.position='absolute'
  7415. el.style.top='-1000px'
  7416. el.style.padding='0'
  7417. document.body.appendChild(el)}
  7418. var c,font=gene.curfont,h=font.size,w=0,n=str.length,i0=0,i=0
  7419. el.className=font_class(font)
  7420. el.style.lineHeight=1
  7421. if(typeof str=="object"){el.innerHTML=str
  7422. str.wh=[el.clientWidth,el.clientHeight]
  7423. return str.wh}
  7424. str=str.replace(/<|>|&[^&\s]*?;|&/g,function(c){switch(c){case'<':return"&lt;"
  7425. case'>':return"&gt;"
  7426. case'&':return"&amp;"}
  7427. return c})
  7428. while(1){i=str.indexOf('$',i)
  7429. if(i>=0){c=str[i+1]
  7430. if(c=='0'){font=gene.deffont}else if(c>='1'&&c<='9'){font=get_font("u"+c)}else{i++
  7431. continue}}
  7432. el.innerHTML=str.slice(i0,i>=0?i:undefined)
  7433. w+=el.clientWidth
  7434. if(el.clientHeight>h)
  7435. h=el.clientHeight
  7436. if(i<0)
  7437. break
  7438. el.style.font=style_font(font).slice(5);i+=2;i0=i}
  7439. 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
  7440. for(i=0;i<n;i++){c=str[i]
  7441. switch(c){case'$':c=str[i+1]
  7442. if(c=='0'){font=gene.deffont}else if(c>='1'&&c<='9'){font=get_font("u"+c)}else{c='$'
  7443. break}
  7444. i++;swfac=font.swfac
  7445. if(font.size>h)
  7446. h=font.size
  7447. continue
  7448. case'&':if(str[i+1]==' ')
  7449. break
  7450. j=str.indexOf(';',i)
  7451. if(j>0&&j-i<10){i=j;c='a'}
  7452. break}
  7453. w+=cwid(c)*swfac}
  7454. return[w,h]}}})()
  7455. function str2svg(str){if(typeof str=="object")
  7456. return str
  7457. var n_font,wh,o_font=gene.deffont,c_font=gene.curfont,o=""
  7458. function tspan(nf,of){var cl
  7459. if(nf.class&&nf.name==of.name&&nf.size==of.size&&nf.weight==of.weight&&nf.style==of.style)
  7460. cl=nf.class
  7461. else
  7462. cl=font_class(nf)
  7463. return'<tspan\n\tclass="'+cl+'">'}
  7464. if(c_font!=o_font)
  7465. o=tspan(c_font,o_font)
  7466. o+=str.replace(/<|>|&[^&\s]*?;|&|\$./g,function(c){switch(c){case'<':return"&lt;"
  7467. case'>':return"&gt;"
  7468. case'&':return"&amp;"
  7469. default:if(c[0]!='$')
  7470. break
  7471. if(c[1]=='0')
  7472. n_font=gene.deffont
  7473. else if(c[1]>='1'&&c[1]<='9')
  7474. n_font=get_font("u"+c[1])
  7475. else
  7476. break
  7477. c=''
  7478. if(n_font==c_font)
  7479. return c
  7480. if(c_font!=o_font)
  7481. c="</tspan>"
  7482. c_font=n_font
  7483. if(c_font==o_font)
  7484. return c
  7485. return c+tspan(c_font,o_font)}
  7486. return c})
  7487. if(c_font!=o_font)
  7488. o+="</tspan>"
  7489. o=new String(o)
  7490. if(typeof document!="undefined")
  7491. strwh(o)
  7492. else
  7493. o.wh=strwh(str)
  7494. gene.curfont=c_font
  7495. return o}
  7496. function set_font(xxx){if(typeof xxx=="string")
  7497. xxx=get_font(xxx)
  7498. cw_tb=xxx.name.slice(0,4)=='sans'?ssw_tb:sw_tb
  7499. gene.curfont=gene.deffont=xxx}
  7500. function out_str(str){output+=str2svg(str)}
  7501. function xy_str(x,y,str,action,w,wh){if(!wh)
  7502. wh=str.wh||strwh(str)
  7503. output+='<text class="'+font_class(gene.deffont)
  7504. if(action!='j'&&str.length>5&&gene.deffont.wadj)
  7505. output+='" lengthAdjust="'+gene.deffont.wadj+'" textLength="'+wh[0].toFixed(1);output+='" x="';out_sxsy(x,'" y="',y)
  7506. switch(action){case'c':output+='" text-anchor="middle">'
  7507. break
  7508. case'j':output+='" textLength="'+w.toFixed(1)+'">'
  7509. break
  7510. case'r':output+='" text-anchor="end">'
  7511. break
  7512. default:output+='">'
  7513. break}
  7514. out_str(str);output+="</text>\n"}
  7515. function trim_title(title,is_subtitle){var i
  7516. if(cfmt.titletrim){i=title.lastIndexOf(", ")
  7517. 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)
  7518. i=0}else{if(i<title.length-cfmt.titletrim-2)
  7519. i=0}
  7520. if(i)
  7521. title=title.slice(i+2).trim()+' '+title.slice(0,i)}
  7522. if(!is_subtitle&&cfmt.writefields.indexOf('X')>=0)
  7523. title=info.X+'. '+title
  7524. if(cfmt.titlecaps)
  7525. return title.toUpperCase()
  7526. return title}
  7527. function get_lwidth(){if(img.chg)
  7528. set_page()
  7529. return img.lw}
  7530. function write_title(title,is_subtitle){var h,wh
  7531. if(!title)
  7532. return
  7533. set_page();title=trim_title(title,is_subtitle)
  7534. if(is_subtitle){set_font("subtitle");h=cfmt.subtitlespace}else{set_font("title");h=cfmt.titlespace}
  7535. wh=strwh(title)
  7536. wh[1]+=gene.curfont.pad*2
  7537. vskip(wh[1]+h+gene.curfont.pad)
  7538. h=gene.curfont.pad+wh[1]*.22
  7539. if(cfmt.titleleft)
  7540. xy_str(0,h,title,null,null,wh)
  7541. else
  7542. xy_str(get_lwidth()/2,h,title,"c",null,wh)}
  7543. function put_inf2r(x,y,str1,str2,action){if(!str1){if(!str2)
  7544. return
  7545. str1=str2;str2=null}
  7546. if(!str2)
  7547. xy_str(x,y,str1,action)
  7548. else
  7549. xy_str(x,y,str1+' ('+str2+')',action)}
  7550. function write_text(text,action){if(action=='s')
  7551. return
  7552. 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
  7553. switch(action){case'c':x=strlw/2;break
  7554. case'r':x=strlw-font.pad;break
  7555. default:x=font.pad;break}
  7556. j=0
  7557. while(1){i=text.indexOf('\n',j)
  7558. if(i==j){vskip(parskip);blk_flush()
  7559. use_font(gene.curfont)
  7560. while(text[i+1]=='\n'){vskip(lineskip);i++}
  7561. if(i==text.length)
  7562. break}else{if(i<0)
  7563. str=text.slice(j)
  7564. else
  7565. str=text.slice(j,i)
  7566. ww=strwh(str)
  7567. vskip(ww[1]*cfmt.lineskipfac
  7568. +font.pad*2)
  7569. xy_str(x,font.pad+ww[1]*.2,str,action)
  7570. if(i<0)
  7571. break}
  7572. j=i+1}
  7573. vskip(parskip);blk_flush()
  7574. break
  7575. case'f':case'j':j=0
  7576. while(1){i=text.indexOf('\n\n',j)
  7577. if(i<0)
  7578. words=text.slice(j)
  7579. else
  7580. words=text.slice(j,i);words=words.split(/\s+/);w=k=wh=0
  7581. for(j=0;j<words.length;j++){ww=strwh(words[j]+'Â ')
  7582. w+=ww[0]
  7583. if(w>=strlw){vskip(wh*cfmt.lineskipfac)
  7584. xy_str(0,ww[1]*.2,words.slice(k,j).join(' '),action,strlw)
  7585. k=j;w=ww[0]
  7586. wh=0}
  7587. if(ww[1]>wh)
  7588. wh=ww[1]}
  7589. if(w!=0){vskip(wh*cfmt.lineskipfac)
  7590. xy_str(0,ww[1]*.2,words.slice(k).join(' '))}
  7591. vskip(parskip);blk_flush()
  7592. if(i<0)
  7593. break
  7594. while(text[i+2]=='\n'){vskip(lineskip);i++}
  7595. if(i==text.length)
  7596. break
  7597. use_font(gene.curfont);j=i+2}
  7598. break}}
  7599. function put_words(words){var p,i,j,nw,w,lw,x1,x2,i1,i2,do_flush,maxn=0,n=1
  7600. function put_wline(p,x){var i=0,k=0
  7601. if(p[0]=='$'&&p[1]>='0'&&p[1]<='9'){gene.curfont=p[1]=='0'?gene.deffont:get_font("u"+p[1])
  7602. p=p.slice(2)}
  7603. if((p[i]>='0'&&p[i]<='9')||p[i+1]=='.'){while(i<p.length){i++
  7604. if(p[i]==' '||p[i-1]==':'||p[i-1]=='.')
  7605. break}
  7606. k=i
  7607. while(p[i]==' ')
  7608. i++}
  7609. var y=gene.curfont.size*.22
  7610. if(k!=0)
  7611. xy_str(x,y,p.slice(0,k),'r')
  7612. if(i<p.length)
  7613. xy_str(x+5,y,p.slice(i),'l')}
  7614. set_font("words")
  7615. vskip(cfmt.wordsspace)
  7616. svg_flush()
  7617. words=words.split('\n')
  7618. nw=words.length
  7619. for(i=0;i<nw;i++){p=words[i]
  7620. if(!p){while(i+1<nw&&!words[i+1])
  7621. i++
  7622. n++}else if(p.length>maxn){maxn=p.length
  7623. i1=i}}
  7624. w=get_lwidth()/2
  7625. lw=strwh(words[i1])[0]
  7626. i1=i2=0
  7627. if(lw<w){j=n>>1
  7628. for(i=0;i<nw;i++){p=words[i]
  7629. if(!p){if(--j<=0)
  7630. i1=i
  7631. while(i+1<nw&&!words[i+1])
  7632. i++
  7633. if(j<=0){i2=i+1
  7634. break}}}
  7635. n>>=1}
  7636. if(i2){x1=(w-lw)/2+10
  7637. x2=x1+w}else{x2=w-lw/2+10}
  7638. do_flush=true
  7639. for(i=0;i<i1||i2<nw;i++,i2++){vskip(cfmt.lineskipfac*gene.curfont.size)
  7640. if(i<i1){p=words[i]
  7641. if(p)
  7642. put_wline(p,x1)
  7643. else
  7644. use_font(gene.curfont)}
  7645. if(i2<nw){p=words[i2]
  7646. if(p){put_wline(p,x2)}else{if(--n==0){if(i<i1){n++}else if(i2<nw-1){x2=w-lw/2+10
  7647. svg_flush()}}}}
  7648. if(!words[i+1]&&!words[i2+1]){if(do_flush){svg_flush()
  7649. do_flush=false}}else{do_flush=true}}}
  7650. function put_history(){var i,j,c,str,font,h,w,wh,head,names=cfmt.infoname.split("\n"),n=names.length
  7651. for(i=0;i<n;i++){c=names[i][0]
  7652. if(cfmt.writefields.indexOf(c)<0)
  7653. continue
  7654. str=info[c]
  7655. if(!str)
  7656. continue
  7657. if(!font){font=true;set_font("history");vskip(cfmt.textspace);h=gene.curfont.size*cfmt.lineskipfac}
  7658. head=names[i].slice(2)
  7659. if(head[0]=='"')
  7660. 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])
  7661. for(j=1;j<str.length;j++){if(!str[j]){vskip(gene.curfont.size*cfmt.parskipfac)
  7662. continue}
  7663. vskip(h);xy_str(w,wh[1]*.22,str[j])}
  7664. vskip(h*cfmt.parskipfac)
  7665. use_font(gene.curfont)}}
  7666. var info_font_init={A:"info",C:"composer",O:"composer",P:"parts",Q:"tempo",R:"info",T:"title",X:"title"}
  7667. 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={}
  7668. var fmt="",p=cfmt.titleformat,j=0,i=0
  7669. while(1){while(p[i]==' ')
  7670. i++
  7671. c=p[i++]
  7672. if(!c)
  7673. break
  7674. if(c<'A'||c>'Z'){switch(c){case'+':align='+'
  7675. c=p[i++]
  7676. break
  7677. case',':fmt+='\n'
  7678. default:continue
  7679. case'<':align='l'
  7680. c=p[i++]
  7681. break
  7682. case'>':align='r'
  7683. c=p[i++]
  7684. break}}else{switch(p[i]){case'-':align='l'
  7685. i++
  7686. break
  7687. case'1':align='r'
  7688. i++
  7689. break
  7690. case'0':i++
  7691. default:align='c'
  7692. break}}
  7693. if(!info_val[c]){if(!info[c])
  7694. continue
  7695. info_val[c]=info[c].split('\n');info_nb[c]=1}else{info_nb[c]++}
  7696. fmt+=align+c}
  7697. fmt+='\n'
  7698. 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
  7699. while(1){yb.l=yb.c=yb.r=y=0;j=i
  7700. while(1){align=p[j++]
  7701. if(align=='\n')
  7702. break
  7703. c=p[j++]
  7704. if(align=='+'||yb[align])
  7705. continue
  7706. str=info_val[c]
  7707. if(!str)
  7708. continue
  7709. font_name=info_font[c]
  7710. if(!font_name)
  7711. font_name="history";font=get_font(font_name);sz=font.size*1.1
  7712. if(info_sz[c])
  7713. sz+=info_sz[c]
  7714. if(y<sz)
  7715. y=sz;yb[align]=sz}
  7716. ya.l+=y-yb.l;ya.c+=y-yb.c;ya.r+=y-yb.r
  7717. while(1){align=p[i++]
  7718. if(align=='\n')
  7719. break
  7720. c=p[i++]
  7721. if(!info_val[c].length)
  7722. continue
  7723. str=info_val[c].shift()
  7724. if(p[i]=='+'){info_nb[c]--;i++
  7725. c=p[i++];if(info_val[c].length){if(str)
  7726. str+=' '+info_val[c].shift()
  7727. else
  7728. str=' '+info_val[c].shift()}}
  7729. font_name=info_font[c]
  7730. if(!font_name)
  7731. font_name="history";font=get_font(font_name);sz=font.size*1.1
  7732. if(info_sz[c])
  7733. sz+=info_sz[c];set_font(font);x=xa[align];y=ya[align]+sz
  7734. if(c=='Q'){self.set_width(glovar.tempo)
  7735. if(!glovar.tempo.invis){if(align!='l'){tempo_build(glovar.tempo)
  7736. w=glovar.tempo.tempo_wh[0]
  7737. if(align=='c')
  7738. w*=.5;x-=w}
  7739. writempo(glovar.tempo,x,-y)}}else if(str){if(c=='T')
  7740. str=trim_title(str,info_font.T[0]=='s')
  7741. xy_str(x,-y,str,align)}
  7742. if(c=='T'){font_name=info_font.T="subtitle";info_sz.T=cfmt.subtitlespace}
  7743. if(info_nb[c]<=1){if(c=='T'){font=get_font(font_name);sz=font.size*1.1
  7744. if(info_sz[c])
  7745. sz+=info_sz[c];set_font(font)}
  7746. while(info_val[c].length>0){y+=sz;str=info_val[c].shift();xy_str(x,-y,str,align)}}
  7747. info_nb[c]--;ya[align]=y}
  7748. if(ya.c>ya.l)
  7749. ya.l=ya.c
  7750. if(ya.r>ya.l)
  7751. ya.l=ya.r
  7752. if(i>=p.length)
  7753. break
  7754. ya.c=ya.r=ya.l}
  7755. vskip(ya.l)}
  7756. function write_heading(){var i,j,area,composer,origin,rhythm,down1,down2,lwidth=get_lwidth()
  7757. vskip(cfmt.topspace)
  7758. if(cfmt.titleformat){write_headform(lwidth);vskip(cfmt.musicspace)
  7759. return}
  7760. if(info.T&&cfmt.writefields.indexOf('T')>=0){i=0
  7761. while(1){j=info.T.indexOf("\n",i)
  7762. if(j<0){write_title(info.T.substring(i),i!=0)
  7763. break}
  7764. write_title(info.T.slice(i,j),i!=0);i=j+1}}
  7765. down1=down2=0
  7766. if(parse.ckey.k_bagpipe&&!cfmt.infoline&&cfmt.writefields.indexOf('R')>=0)
  7767. rhythm=info.R
  7768. if(rhythm){set_font("composer");down1=cfmt.composerspace+gene.curfont.size+2
  7769. xy_str(0,-down1+gene.curfont.size*.22,rhythm)}
  7770. area=info.A
  7771. if(cfmt.writefields.indexOf('C')>=0)
  7772. composer=info.C
  7773. if(cfmt.writefields.indexOf('O')>=0)
  7774. origin=info.O
  7775. 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'}
  7776. if(composer||origin){down2=cfmt.composerspace+2
  7777. i=0
  7778. while(1){down2+=gene.curfont.size
  7779. if(composer)
  7780. j=composer.indexOf("\n",i)
  7781. else
  7782. j=-1
  7783. if(j<0){put_inf2r(xcomp,-down2+gene.curfont.size*.22,composer?composer.substring(i):null,origin,align)
  7784. break}
  7785. xy_str(xcomp,-down2+gene.curfont.size*.22,composer.slice(i,j),align);i=j+1}}
  7786. rhythm=rhythm?null:info.R
  7787. if((rhythm||area)&&cfmt.infoline){set_font("info");down2+=cfmt.infospace+gene.curfont.size
  7788. put_inf2r(lwidth,-down2+gene.curfont.size*.22,rhythm,area,'r')}}
  7789. if(info.P&&cfmt.writefields.indexOf('P')>=0){set_font("parts");i=cfmt.partsspace+gene.curfont.size+gene.curfont.pad
  7790. if(down1+i>down2)
  7791. down2=down1+i
  7792. else
  7793. down2+=i
  7794. xy_str(0,-down2+gene.curfont.size*.22,info.P)
  7795. down2+=gene.curfont.pad}else if(down1>down2){down2=down1}
  7796. vskip(down2+cfmt.musicspace)}
  7797. var output="",style='\
  7798. \n.stroke{stroke:currentColor;fill:none}\
  7799. \n.bW{stroke:currentColor;fill:none;stroke-width:1}\
  7800. \n.bthW{stroke:currentColor;fill:none;stroke-width:3}\
  7801. \n.slW{stroke:currentColor;fill:none;stroke-width:.7}\
  7802. \n.slthW{stroke:currentColor;fill:none;stroke-width:1.5}\
  7803. \n.sW{stroke:currentColor;fill:none;stroke-width:.7}\
  7804. \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
  7805. 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"}}
  7806. var glyphs={}
  7807. function m_gl(s){return s.replace(/[Cco]\||[co]\.|./g,function(e){var m=tgls["mtr"+e]
  7808. return m?m.c:0})}
  7809. function def_use(gl){var i,j,g
  7810. if(defined_glyph[gl])
  7811. return
  7812. defined_glyph[gl]=true;g=glyphs[gl]
  7813. if(!g){error(1,null,"Unknown glyph: '$1'",gl)
  7814. return}
  7815. j=0
  7816. while(1){i=g.indexOf('xlink:href="#',j)
  7817. if(i<0)
  7818. break
  7819. i+=13;j=g.indexOf('"',i);def_use(g.slice(i,j))}
  7820. defs+='\n'+g}
  7821. function defs_add(text){var i,j,gl,tag,is,ie=0
  7822. text=text.replace(/<!--.*?-->/g,'')
  7823. while(1){is=text.indexOf('<',ie);if(is<0)
  7824. break
  7825. i=text.indexOf('id="',is)
  7826. if(i<0)
  7827. break
  7828. i+=4;j=text.indexOf('"',i);if(j<0)
  7829. break
  7830. gl=text.slice(i,j);ie=text.indexOf('>',j);if(ie<0)
  7831. break
  7832. if(text[ie-1]=='/'){ie++}else{i=text.indexOf(' ',is);if(i<0)
  7833. break
  7834. tag=text.slice(is+1,i);ie=text.indexOf('</'+tag+'>',ie)
  7835. if(ie<0)
  7836. break
  7837. ie+=3+tag.length}
  7838. if(text.substr(is,7)=='<filter')
  7839. fulldefs+=text.slice(is,ie)+'\n'
  7840. else
  7841. glyphs[gl]=text.slice(is,ie)}}
  7842. function set_g(){if(stv_g.started){stv_g.started=false;glout()
  7843. output+="</g>\n"}
  7844. if(stv_g.scale==1&&!stv_g.color)
  7845. return
  7846. glout()
  7847. output+='<g '
  7848. if(stv_g.scale!=1){if(stv_g.st<0)
  7849. output+=voice_tb[stv_g.v].scale_str
  7850. else if(stv_g.v<0)
  7851. output+=staff_tb[stv_g.st].scale_str
  7852. else
  7853. output+='transform="translate(0,'+
  7854. (posy-stv_g.dy).toFixed(1)+') scale('+stv_g.scale.toFixed(2)+')"'}
  7855. if(stv_g.color){if(stv_g.scale!=1)
  7856. output+=' ';output+='color="'+stv_g.color+'"'}
  7857. output+=">\n";stv_g.started=true}
  7858. function set_color(color){if(color==stv_g.color)
  7859. return undefined
  7860. var old_color=stv_g.color;stv_g.color=color;set_g()
  7861. return old_color}
  7862. function set_sscale(st){var new_scale,dy
  7863. if(st!=stv_g.st&&stv_g.scale!=1)
  7864. stv_g.scale=0;new_scale=st>=0?staff_tb[st].staffscale:1
  7865. if(st>=0&&new_scale!=1)
  7866. dy=staff_tb[st].y
  7867. else
  7868. dy=posy
  7869. if(new_scale==stv_g.scale&&dy==stv_g.dy)
  7870. return
  7871. stv_g.scale=new_scale;stv_g.dy=dy;stv_g.st=st;stv_g.v=-1;set_g()}
  7872. function set_scale(s){var new_dy,new_scale=s.p_v.scale
  7873. if(new_scale==1){set_sscale(s.st)
  7874. return}
  7875. new_dy=posy
  7876. if(staff_tb[s.st].staffscale!=1){new_scale*=staff_tb[s.st].staffscale;new_dy=staff_tb[s.st].y}
  7877. if(new_scale==stv_g.scale&&stv_g.dy==posy)
  7878. return
  7879. 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()}
  7880. function set_dscale(st,no_scale){if(output){if(stv_g.started){stv_g.started=false
  7881. glout()
  7882. output+="</g>\n"}
  7883. 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}
  7884. output=""}
  7885. if(st<0)
  7886. stv_g.scale=1
  7887. else
  7888. stv_g.scale=no_scale?1:staff_tb[st].staffscale;stv_g.st=st;stv_g.dy=0}
  7889. function delayed_update(){var st,new_out,text
  7890. for(st=0;st<=nstaff;st++){if(staff_tb[st].sc_out){output+='<g '+staff_tb[st].scale_str+'>\n'+
  7891. staff_tb[st].sc_out+'</g>\n';staff_tb[st].sc_out=""}
  7892. if(!staff_tb[st].output)
  7893. continue
  7894. output+='<g transform="translate(0,'+
  7895. (-staff_tb[st].y).toFixed(1)+')">\n'+
  7896. staff_tb[st].output+'</g>\n';staff_tb[st].output=""}}
  7897. function anno_out(s,t,f){if(s.istart==undefined)
  7898. return
  7899. var type=s.type,h=s.ymx-s.ymn+4,wl=s.wl||2,wr=s.wr||2
  7900. if(s.grace)
  7901. type=C.GRACE
  7902. 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)}
  7903. function a_start(s,t){anno_out(s,t,user.anno_start)}
  7904. function a_stop(s,t){anno_out(s,t,user.anno_stop)}
  7905. function empty_function(){}
  7906. var anno_start=empty_function,anno_stop=empty_function
  7907. function anno_put(){var s
  7908. while(1){s=anno_a.shift()
  7909. if(!s)
  7910. break
  7911. 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)
  7912. break}
  7913. case C.GRACE:case C.NOTE:case C.MREST:set_scale(s)
  7914. break}
  7915. anno_stop(s)}}
  7916. 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)
  7917. case'Y':return y.toFixed(1)
  7918. case'A':return a
  7919. case'B':return b
  7920. case'F':return a.toFixed(1)
  7921. default:return b.toFixed(1)}})}
  7922. function g_open(x,y,rot,sx,sy){glout()
  7923. out_XYAB('<g transform="translate(X,Y',x,y);if(rot)
  7924. output+=') rotate('+rot.toFixed(2)
  7925. if(sx){if(sy)
  7926. output+=') scale('+sx.toFixed(2)+', '+sy.toFixed(2)
  7927. else
  7928. output+=') scale('+sx.toFixed(2)}
  7929. output+=')">\n';stv_g.g++}
  7930. function g_close(){glout()
  7931. stv_g.g--;output+='</g>\n'}
  7932. Abc.prototype.out_svg=function(str){output+=str}
  7933. function sx(x){if(stv_g.g)
  7934. return x
  7935. return(x+posx)/stv_g.scale}
  7936. Abc.prototype.sx=sx
  7937. function sy(y){if(stv_g.g)
  7938. return-y
  7939. if(stv_g.scale==1)
  7940. return posy-y
  7941. if(stv_g.v>=0)
  7942. return(stv_g.dy-y)/voice_tb[stv_g.v].scale
  7943. return stv_g.dy-y}
  7944. Abc.prototype.sy=sy;Abc.prototype.sh=function(h){if(stv_g.st<0)
  7945. return h/stv_g.scale
  7946. return h}
  7947. Abc.prototype.ax=function(x){return x+posx}
  7948. Abc.prototype.ay=function(y){if(stv_g.st<0)
  7949. return posy-y
  7950. return posy+(stv_g.dy-y)*stv_g.scale-stv_g.dy}
  7951. Abc.prototype.ah=function(h){if(stv_g.st<0)
  7952. return h
  7953. return h*stv_g.scale}
  7954. function out_sxsy(x,sep,y){x=sx(x);y=sy(y);output+=x.toFixed(1)+sep+y.toFixed(1)}
  7955. Abc.prototype.out_sxsy=out_sxsy
  7956. function xypath(x,y,fill){if(fill)
  7957. out_XYAB('<path d="mX Y',x,y)
  7958. else
  7959. out_XYAB('<path class="stroke" d="mX Y',x,y)}
  7960. Abc.prototype.xypath=xypath
  7961. function draw_all_hl(){var st,p_st
  7962. function hlud(hla,d){var hl,hll,i,xp,dx2,x2,n=hla.length
  7963. if(!n)
  7964. return
  7965. for(i=0;i<n;i++){hll=hla[i]
  7966. if(!hll||!hll.length)
  7967. continue
  7968. xp=sx(hll[0][0])
  7969. output+='<path class="stroke" stroke-width="1" d="M'+
  7970. xp.toFixed(1)+' '+
  7971. sy(p_st.y+d*i).toFixed(1)
  7972. dx2=0
  7973. while(1){hl=hll.shift()
  7974. if(!hl)
  7975. break
  7976. x2=sx(hl[0])
  7977. output+='m'+
  7978. (x2-xp+hl[1]-dx2).toFixed(2)+' 0h'+(-hl[1]+hl[2]).toFixed(2)
  7979. xp=x2
  7980. dx2=hl[2]}
  7981. output+='"/>\n'}}
  7982. for(st=0;st<=nstaff;st++){p_st=staff_tb[st]
  7983. if(!p_st.hlu)
  7984. continue
  7985. set_sscale(st)
  7986. hlud(p_st.hlu,6)
  7987. hlud(p_st.hld,-6)}}
  7988. var gla=[[],[],"",[],[],[]]
  7989. function glout(){var e,v=[]
  7990. if(gla[0].length){while(1){e=gla[0].shift()
  7991. if(e==undefined)
  7992. break
  7993. v.push(e.toFixed(1))}
  7994. output+='<text x="'+v.join(',')
  7995. v=[]
  7996. while(1){e=gla[1].shift()
  7997. if(e==undefined)
  7998. break
  7999. v.push(e.toFixed(1))}
  8000. output+='"\ny="'+v.join(',')
  8001. output+='"\n>'+gla[2]+'</text>\n'
  8002. gla[2]=""}
  8003. if(!gla[3].length)
  8004. return
  8005. output+='<path class="sW" d="'
  8006. while(1){e=gla[3].shift()
  8007. if(e==undefined)
  8008. break
  8009. output+='M'+e.toFixed(1)+' '+gla[3].shift().toFixed(1)+'v'+gla[3].shift().toFixed(1)}
  8010. output+='"/>\n'}
  8011. function xygl(x,y,gl){if(glyphs[gl]){def_use(gl)
  8012. out_XYAB('<use x="X" y="Y" xlink:href="#A"/>\n',x,y,gl)}else{var tgl=tgls[gl]
  8013. if(tgl){x+=tgl.x*stv_g.scale;y-=tgl.y
  8014. 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))
  8015. gla[1].push(sy(y))
  8016. gla[2]+=tgl.c}}else{error(1,null,'no definition of $1',gl)}}}
  8017. function out_acciac(x,y,dx,dy,up){if(up){x-=1;y+=4}else{x-=5;y-=4}
  8018. out_XYAB('<path class="stroke" d="mX YlF G"/>\n',x,y,dx,-dy)}
  8019. function out_brace(x,y,h){x+=posx-6;y=posy-y;h/=24;output+='<text transform="translate('+
  8020. x.toFixed(1)+','+y.toFixed(1)+') scale(2.5,'+h.toFixed(2)+')">'+tgls.brace.c+'</text>\n'}
  8021. 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\
  8022. c10.5 1 12 -4.5 12 -3.5c0 1 -3.5 5.5 -8.5 5.5\n\
  8023. v'+h.toFixed(1)+'\n\
  8024. c5 0 8.5 4.5 8.5 5.5c0 1 -1.5 -4.5 -12 -3.5"/>\n'}
  8025. function out_hyph(x,y,w){var n,a_y,d=25+((w/20)|0)*3
  8026. if(w>15.)
  8027. n=((w-15)/d)|0
  8028. else
  8029. n=0;x+=(w-d*n-5)/2;out_XYAB('<path class="stroke" stroke-width="1.2"\n\
  8030. stroke-dasharray="5,A"\n\
  8031. d="mX YhB"/>\n',x,y+4,Math.round((d-5)/stv_g.scale),d*n+5)}
  8032. function out_stem(x,y,h,grace,nflags,straight){var dx=grace?GSTEM_XOFF:3.5,slen=-h
  8033. if(h<0)
  8034. dx=-dx;x+=dx*stv_g.scale
  8035. if(stv_g.v>=0)
  8036. slen/=voice_tb[stv_g.v].scale;gla[3].push(sx(x))
  8037. gla[3].push(sy(y))
  8038. gla[3].push(slen)
  8039. if(!nflags)
  8040. return
  8041. y+=h
  8042. if(h>0){if(!straight){if(!grace){xygl(x,y,"flu"+nflags)
  8043. return}else{output+='<path d="'
  8044. if(nflags==1){out_XYAB('MX Yc0.6 3.4 5.6 3.8 3 10\n\
  8045. 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\
  8046. 1.4 -4.8 -2.4 -5.4 -3.2 -5.2\n',x,y);y-=3.5}}}}else{output+='<path d="'
  8047. 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)
  8048. return}else{output+='<path d="'
  8049. if(nflags==1){out_XYAB('MX Yc0.6 -3.4 5.6 -3.8 3 -10\n\
  8050. 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\
  8051. 1.4 4.8 -2.4 5.4 -3.2 5.2\n',x,y);y+=3.5}}}}else{output+='<path d="'
  8052. if(!grace){while(--nflags>=0){out_XYAB('MX Yl7 -3.2 0 -3.2 -7 3.2z\n',x,y);y+=5.4}}}}
  8053. output+='"/>\n'}
  8054. function out_trem(x,y,ntrem){out_XYAB('<path d="mX Y\n\t',x-4.5,y)
  8055. while(1){output+='l9 -3v3l-9 3z'
  8056. if(--ntrem<=0)
  8057. break
  8058. output+='m0 5.4'}
  8059. output+='"/>\n'}
  8060. 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'}
  8061. function out_tubrn(x,y,dx,dy,up,str){var dxx,sw=str.length*10,h=up?-3:3;set_font("tuplet")
  8062. xy_str(x+dx/2,y+dy/2-gene.curfont.size*.1,str,'c')
  8063. dx/=stv_g.scale
  8064. if(!up)
  8065. y+=6;output+='<path class="stroke" d="m';out_sxsy(x,' ',y);dxx=dx-sw+1
  8066. if(dy>0)
  8067. sw+=dy/8
  8068. else
  8069. sw-=dy/8
  8070. output+='v'+h.toFixed(1)+'m'+dx.toFixed(1)+' '+(-dy).toFixed(1)+'v'+(-h).toFixed(1)+'"/>\n'+'<path class="stroke" stroke-dasharray="'+
  8071. (dxx/2).toFixed(1)+' '+sw.toFixed(1)+'" d="m';out_sxsy(x,' ',y-h);output+='l'+dx.toFixed(1)+' '+(-dy).toFixed(1)+'"/>\n'}
  8072. function out_wln(x,y,w){out_XYAB('<path class="stroke" stroke-width="0.8" d="mX YhF"/>\n',x,y+1,w)}
  8073. 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'}}
  8074. function out_deco_str(x,y,name,str){if(name=='fng'){out_XYAB('\
  8075. <text x="X" y="Y" style="font-size:14px">A</text>\n',x-2,y,m_gl(str))
  8076. return}
  8077. var f,a_deco=deco_str_style[name]
  8078. if(!a_deco){xygl(x,y,name)
  8079. return}
  8080. x+=a_deco.dx;y+=a_deco.dy;if(!a_deco.def){style+="\n."+name+" {"+a_deco.style+"}";a_deco.def=true}
  8081. 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'}
  8082. function out_arp(x,y,val){g_open(x,y,270);x=0;val=Math.ceil(val/6)
  8083. while(--val>=0){xygl(x,6,"ltr");x+=6}
  8084. g_close()}
  8085. function out_cresc(x,y,val,defl){x+=val*stv_g.scale
  8086. val=-val;out_XYAB('<path class="stroke"\n\
  8087. d="mX YlF ',x,y,val)
  8088. if(defl.nost)
  8089. output+='-2.2m0 -3.6l'+(-val).toFixed(1)+' -2.2"/>\n'
  8090. else
  8091. output+='-4l'+(-val).toFixed(1)+' -4"/>\n'}
  8092. function out_dim(x,y,val,defl){out_XYAB('<path class="stroke"\n\
  8093. d="mX YlF ',x,y,val)
  8094. if(defl.noen)
  8095. output+='-2.2m0 -3.6l'+(-val).toFixed(1)+' -2.2"/>\n'
  8096. else
  8097. output+='-4l'+(-val).toFixed(1)+' -4"/>\n'}
  8098. function out_ltr(x,y,val){y+=4;val=Math.ceil(val/6)
  8099. while(--val>=0){xygl(x,y,"ltr");x+=6}}
  8100. Abc.prototype.out_lped=function(x,y,val,defl){if(!defl.nost)
  8101. xygl(x,y,"ped");if(!defl.noen)
  8102. xygl(x+val+6,y,"pedoff")}
  8103. function out_8va(x,y,val,defl){if(val<18){val=18
  8104. x-=4}
  8105. if(!defl.nost){out_XYAB('<text x="X" y="Y" \
  8106. style="font:italic bold 12px text,serif">8\
  8107. <tspan dy="-4" style="font-size:10px">va</tspan></text>\n',x-8,y);x+=12;val-=12}
  8108. y+=6;out_XYAB('<path class="stroke" stroke-dasharray="6,6" d="mX YhF"/>\n',x,y,val)
  8109. if(!defl.noen)
  8110. out_XYAB('<path class="stroke" d="mX Yv6"/>\n',x+val,y)}
  8111. function out_8vb(x,y,val,defl){if(val<18){val=18
  8112. x-=4}
  8113. if(!defl.nost){out_XYAB('<text x="X" y="Y" \
  8114. style="font:italic bold 12px text,serif">8\
  8115. <tspan dy=".5" style="font-size:10px">vb</tspan></text>\n',x-8,y);x+=10
  8116. val-=10}
  8117. out_XYAB('<path class="stroke" stroke-dasharray="6,6" d="mX YhF"/>\n',x,y,val)
  8118. if(!defl.noen)
  8119. out_XYAB('<path class="stroke" d="mX Yv-6"/>\n',x+val,y)}
  8120. function out_15ma(x,y,val,defl){if(val<25){val=25
  8121. x-=6}
  8122. if(!defl.nost){out_XYAB('<text x="X" y="Y" \
  8123. style="font:italic bold 12px text,serif">15\
  8124. <tspan dy="-4" style="font-size:10px">ma</tspan></text>\n',x-10,y);x+=20;val-=20}
  8125. y+=6;out_XYAB('<path class="stroke" stroke-dasharray="6,6" d="mX YhF"/>\n',x,y,val)
  8126. if(!defl.noen)
  8127. out_XYAB('<path class="stroke" d="mX Yv6"/>\n',x+val,y)}
  8128. function out_15mb(x,y,val,defl){if(val<24){val=24
  8129. x-=5}
  8130. if(!defl.nost){out_XYAB('<text x="X" y="Y" \
  8131. style="font:italic bold 12px text,serif">15\
  8132. <tspan dy=".5" style="font-size:10px">mb</tspan></text>\n',x-10,y);x+=18
  8133. val-=18}
  8134. out_XYAB('<path class="stroke" stroke-dasharray="6,6" d="mX YhF"/>\n',x,y,val)
  8135. if(!defl.noen)
  8136. out_XYAB('<path class="stroke" d="mX Yv-6"/>\n',x+val,y)}
  8137. 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}
  8138. function out_deco_val(x,y,name,val,defl){if(deco_val_tb[name])
  8139. deco_val_tb[name](x,y,val,defl)
  8140. else
  8141. error(1,null,"No function for decoration '$1'",name)}
  8142. 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)
  8143. if(!stv_g.g)
  8144. dx/=stv_g.scale
  8145. ar=Math.atan2(dy,dx)
  8146. a=ar/Math.PI*180
  8147. len=(dx-(de1.s.dots?13+de1.s.xmx:8)
  8148. -8-(de.s.notes[0].shac||0))
  8149. / Math.cos(ar)
  8150. g_open(x1,y1,a);x1=de1.s.dots?13+de1.s.xmx:8;len=len/6|0
  8151. if(len<1)
  8152. len=1
  8153. while(--len>=0){xygl(x1,0,"ltr");x1+=6}
  8154. g_close()}
  8155. 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)
  8156. if(!stv_g.g)
  8157. dx/=stv_g.scale
  8158. ar=Math.atan2(dy,dx)
  8159. a=ar/Math.PI*180
  8160. len=(dx-(de1.s.dots?13+de1.s.xmx:8)
  8161. -8-(de.s.notes[0].shac||0))
  8162. / Math.cos(ar)
  8163. g_open(x1,y1,a);xypath(de1.s.dots?13+de1.s.xmx:8,0)
  8164. output+='h'+len.toFixed(1)+'" stroke-width="1"/>\n';g_close()}
  8165. var deco_l_tb={glisq:out_glisq,gliss:out_gliss}
  8166. function out_deco_long(x,y,de){var s,p_v,m,nt,i,name=de.dd.glyph,de1=de.start
  8167. if(!deco_l_tb[name]){error(1,null,"No function for decoration '$1'",name)
  8168. return}
  8169. p_v=de.s.p_v
  8170. if(de.defl.noen){s=p_v.s_next
  8171. while(s&&!s.dur)
  8172. s=s.next
  8173. if(s){for(m=0;m<=s.nhd;m++){nt=s.notes[m]
  8174. if(!nt.a_dd)
  8175. continue
  8176. for(i=0;i<nt.a_dd.length;i++){if(nt.a_dd[i].name==de.dd.name){y=3*(nt.pit-18)
  8177. +staff_tb[de.s.st].y
  8178. break}}}}
  8179. x+=8}else if(de.defl.nost){s=p_v.s_prev
  8180. while(s&&!s.dur)
  8181. s=s.prev
  8182. if(s){for(m=0;m<=s.nhd;m++){nt=s.notes[m]
  8183. if(!nt.a_dd)
  8184. continue
  8185. for(i=0;i<nt.a_dd.length;i++){if(nt.a_dd[i].name==de1.dd.name){de1.y=3*(nt.pit-18)
  8186. break}}}}
  8187. de1.x-=8}
  8188. deco_l_tb[name](x,y,de)}
  8189. function tempo_note(s,dur){var p,elts=identify_note(s,dur)
  8190. switch(elts[0]){case C.OVAL:p="\ueca2"
  8191. break
  8192. case C.EMPTY:p="\ueca3"
  8193. break
  8194. default:switch(elts[2]){case 2:p="\ueca9"
  8195. break
  8196. case 1:p="\ueca7"
  8197. break
  8198. default:p="\ueca5"
  8199. break}
  8200. break}
  8201. if(elts[1])
  8202. p+='<tspan dx=".1em">\uecb7</tspan>'
  8203. return p}
  8204. function tempo_build(s){var i,j,bx,p,wh,dy,w=0,str=[]
  8205. if(s.tempo_str)
  8206. return
  8207. if(!cfmt.musicfont.used)
  8208. get_font("music")
  8209. set_font("tempo")
  8210. if(s.tempo_str1){str.push(s.tempo_str1)
  8211. w+=strwh(s.tempo_str1)[0]}
  8212. if(s.tempo_notes){dy=' dy="-1"'
  8213. for(i=0;i<s.tempo_notes.length;i++){p=tempo_note(s,s.tempo_notes[i])
  8214. str.push('<tspan\nclass="'+
  8215. font_class(cfmt.musicfont)+'" style="font-size:'+
  8216. (gene.curfont.size*1.3).toFixed(1)+'px"'+
  8217. dy+'>'+
  8218. p+'</tspan>')
  8219. j=p.length>1?2:1
  8220. w+=j*gene.curfont.swfac
  8221. dy=''}
  8222. str.push('<tspan dy="1">=</tspan>')
  8223. w+=cwidf('=')
  8224. if(s.tempo_ca){str.push(s.tempo_ca)
  8225. w+=strwh(s.tempo_ca)[0]
  8226. j=s.tempo_ca.length+1}
  8227. if(s.tempo){str.push(s.tempo)
  8228. w+=strwh(s.tempo.toString())[0]}else{p=tempo_note(s,s.new_beat)
  8229. str.push('<tspan\nclass="'+
  8230. font_class(cfmt.musicfont)+'" style="font-size:'+
  8231. (gene.curfont.size*1.3).toFixed(1)+'px" dy="-1">'+
  8232. p+'</tspan>')
  8233. j=p.length>1?2:1
  8234. w+=j*gene.curfont.swfac
  8235. dy='y'}}
  8236. if(s.tempo_str2){if(dy)
  8237. str.push('<tspan\n\tdy="1">'+
  8238. s.tempo_str2+'</tspan>')
  8239. else
  8240. str.push(s.tempo_str2)
  8241. w+=strwh(s.tempo_str2)[0]}
  8242. s.tempo_str=str.join(' ')
  8243. w+=cwidf(' ')*(str.length-1)
  8244. s.tempo_wh=[w,13.0]}
  8245. function writempo(s,x,y){var bh
  8246. set_font("tempo")
  8247. if(gene.curfont.box){gene.curfont.box=false
  8248. bh=gene.curfont.size+4}
  8249. output+='<text class="'+font_class(gene.curfont)+'" x="'
  8250. out_sxsy(x,'" y="',y+gene.curfont.size*.22)
  8251. output+='">'+s.tempo_str+'</text>\n'
  8252. if(bh){gene.curfont.box=true
  8253. output+='<rect class="stroke" x="'
  8254. out_sxsy(x-2,'" y="',y+bh-1)
  8255. output+='" width="'+(s.tempo_wh[0]+4).toFixed(1)+'" height="'+bh.toFixed(1)+'"/>\n'}
  8256. s.invis=true}
  8257. function vskip(h){posy+=h}
  8258. function svg_flush(){if(multicol||!output||!user.img_out||posy==0)
  8259. return
  8260. var i,font,head='<svg xmlns="http://www.w3.org/2000/svg" version="1.1"\n\
  8261. xmlns:xlink="http://www.w3.org/1999/xlink"\n\
  8262. fill="currentColor" stroke-width=".7"',g=''
  8263. glout()
  8264. font=get_font("music")
  8265. head+=' class="'+font_class(font)+' tune'+tunes.length+'"\n'
  8266. posy*=cfmt.scale
  8267. if(user.imagesize!=undefined)
  8268. head+=user.imagesize
  8269. else
  8270. head+=' width="'+img.width.toFixed(0)
  8271. +'px" height="'+posy.toFixed(0)+'px"'
  8272. head+=' viewBox="0 0 '+img.width.toFixed(0)+' '
  8273. +posy.toFixed(0)+'">\n'
  8274. +fulldefs
  8275. if(style||font_style){head+='<style>'+font_style
  8276. if(cfmt.fgcolor||cfmt.bgcolor){head+='\n.f'+font.fid+(cfmt.fullsvg||'')
  8277. +'{'
  8278. +(cfmt.fgcolor?('color:'+cfmt.fgcolor+';'):'')
  8279. +(cfmt.bgcolor?('background-color:'+cfmt.bgcolor):'')
  8280. +'}'}
  8281. head+=style+'\n</style>\n'}
  8282. if(defs)
  8283. head+='<defs>'+defs+'\n</defs>\n'
  8284. if(cfmt.scale!=1){head+='<g class="g" transform="scale('+
  8285. cfmt.scale.toFixed(2)+')">\n';g='</g>\n'}
  8286. if(psvg)
  8287. psvg.ps_flush(true);if(blkdiv>0){user.img_out(blkdiv==1?'<div class="nobrk">':'<div class="nobrk newpage">')
  8288. blkdiv=-1}
  8289. user.img_out(head+output+g+"</svg>");output=""
  8290. font_style=''
  8291. if(cfmt.fullsvg){defined_glyph={}
  8292. for(i=0;i<abc2svg.font_tb.length;i++)
  8293. abc2svg.font_tb[i].used=false}else{style='';fulldefs=''}
  8294. defs='';posy=0}
  8295. function blk_flush(){svg_flush()
  8296. if(blkdiv<0&&(!parse.state||cfmt.splittune)){user.img_out('</div>')
  8297. blkdiv=0}}
  8298. Abc.prototype.blk_flush=blk_flush
  8299. var par_sy,cur_sy,voice_tb,curvoice,staves_found,vover,tsfirst
  8300. function voice_filter(){var opt
  8301. function vfilt(opts,opt){var i,sel=new RegExp(opt)
  8302. if(sel.test(curvoice.id)||sel.test(curvoice.nm)){for(i=0;i<opts.length;i++)
  8303. self.do_pscom(opts[i])}}
  8304. if(parse.voice_opts)
  8305. for(opt in parse.voice_opts){if(parse.voice_opts.hasOwnProperty(opt))
  8306. vfilt(parse.voice_opts[opt],opt)}
  8307. if(parse.tune_v_opts)
  8308. for(opt in parse.tune_v_opts){if(parse.tune_v_opts.hasOwnProperty(opt))
  8309. vfilt(parse.tune_v_opts[opt],opt)}}
  8310. function sym_link(s){var tim=curvoice.time
  8311. if(!s.fname)
  8312. set_ref(s)
  8313. if(!curvoice.ignore){s.prev=curvoice.last_sym
  8314. if(curvoice.last_sym)
  8315. curvoice.last_sym.next=s
  8316. else
  8317. curvoice.sym=s}
  8318. curvoice.last_sym=s
  8319. s.v=curvoice.v;s.p_v=curvoice;s.st=curvoice.cst;s.time=tim
  8320. if(s.dur&&!s.grace)
  8321. curvoice.time+=s.dur;parse.ufmt=true
  8322. s.fmt=cfmt
  8323. s.pos=curvoice.pos
  8324. if(curvoice.second)
  8325. s.second=true
  8326. if(curvoice.floating)
  8327. s.floating=true
  8328. if(curvoice.eoln){s.soln=true
  8329. curvoice.eoln=false}}
  8330. 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
  8331. if(!s2)
  8332. s2=s.next
  8333. if(s2){s.fname=s2.fname;s.istart=s2.istart;s.iend=s2.iend}
  8334. return s}
  8335. var w_tb=new Uint8Array([6,2,8,6,0,3,4,9,9,0,9,5,0,1,0,0,0,0])
  8336. 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
  8337. function b_chk(){var bt,s,s2,v,t,ir=0
  8338. while(1){v=vn[ir++]
  8339. if(v==undefined)
  8340. break
  8341. s=vtb[v]
  8342. if(!s||!s.bar_type||s.invis||s.time!=time)
  8343. continue
  8344. if(!bt){bt=s.bar_type
  8345. if(s.text&&bt=='|')
  8346. t=s.text
  8347. continue}
  8348. if(s.bar_type!=bt)
  8349. break
  8350. if(s.text&&!t&&bt=='|'){t=s.text
  8351. break}}
  8352. if(!fl){while(prev.type==C.GRACE&&vtb[prev.v]&&!vtb[prev.v].bar_type){vtb[prev.v]=prev
  8353. prev=prev.ts_prev
  8354. fl=1}}
  8355. if(v==undefined)
  8356. return
  8357. if(bt=="::"||bt==":|"||t){ir=0
  8358. bt=t?'|':"::"
  8359. while(1){v=vn[ir++]
  8360. if(v==undefined)
  8361. break
  8362. s=vtb[v]
  8363. if(!s||s.invis||s.bar_type!=bt||(bt=='|'&&!s.text))
  8364. continue
  8365. s2=clone(s)
  8366. if(bt=="::"){s.bar_type=":|"
  8367. s2.bar_type="|:"}else{delete s.text
  8368. delete s.rbstart
  8369. s2.bar_type='['
  8370. s2.invis=1
  8371. s2.xsh=0}
  8372. s2.next=s.next
  8373. if(s2.next)
  8374. s2.next.prev=s2
  8375. s2.prev=s
  8376. s.next=s2}}else{error(1,s,"Different bars $1 and $2",(bt+(t||'')),(s.bar_type+(s.text||'')))}}
  8377. for(v=0;v<nv;v++){s=voice_tb[v].sym
  8378. vtb[v]=s
  8379. if(sy.voices[v]){vn[sy.voices[v].range]=v
  8380. if(!prev&&s){fmt=s.fmt
  8381. p_voice=voice_tb[v]
  8382. 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}}}}
  8383. if(!prev)
  8384. return
  8385. p_voice.sym=tsfirst=s=prev
  8386. if(s.next)
  8387. s.next.prev=s
  8388. else
  8389. p_voice.last_sym=s
  8390. s=glovar.tempo
  8391. if(s){s.v=v=p_voice.v
  8392. s.p_v=p_voice
  8393. s.st=0
  8394. s.time=0
  8395. s.prev=prev
  8396. s.next=prev.next
  8397. if(s.next)
  8398. s.next.prev=s
  8399. else
  8400. p_voice.last_sym=s
  8401. s.prev.next=s
  8402. s.fmt=fmt
  8403. glovar.tempo=null
  8404. vtb[v]=s}
  8405. if(nv==1){s=tsfirst
  8406. s.ts_next=s.next
  8407. while(1){s=s.next
  8408. if(!s)
  8409. return
  8410. if(s.time!=s.prev.time||w_tb[s.prev.type]||s.type==C.GRACE&&s.prev.type==C.GRACE)
  8411. s.seqst=1
  8412. if(s.type==C.PART){s.prev.next=s.prev.ts_next=s.next
  8413. if(s.next){s.next.part=s
  8414. s.next.prev=s.prev
  8415. if(s.soln)
  8416. s.next.soln=1
  8417. if(s.seqst)
  8418. s.next.seqst=1}
  8419. continue}
  8420. s.ts_prev=s.prev
  8421. s.ts_next=s.next}}
  8422. while(1){if(new_sy){sy=new_sy;new_sy=null;vn.length=0
  8423. for(v=0;v<nv;v++){if(!sy.voices[v])
  8424. continue
  8425. vn[sy.voices[v].range]=v}}
  8426. wmin=time=10000000
  8427. ir=0
  8428. while(1){v=vn[ir++]
  8429. if(v==undefined)
  8430. break
  8431. s=vtb[v]
  8432. if(!s||s.time>time)
  8433. continue
  8434. w=w_tb[s.type]
  8435. if(s.type==C.GRACE&&s.next&&s.next.type==C.GRACE)
  8436. w--
  8437. if(s.time<time){time=s.time;wmin=w}else if(w<wmin){wmin=w}}
  8438. if(wmin>127)
  8439. break
  8440. if(wmin==6)
  8441. b_chk()
  8442. ir=0
  8443. while(1){v=vn[ir++]
  8444. if(v==undefined)
  8445. break
  8446. s=vtb[v]
  8447. if(!s||s.time!=time)
  8448. continue
  8449. w=w_tb[s.type]
  8450. if(!w&&s.type==C.GRACE&&s.next&&s.next.type==C.GRACE)
  8451. w--
  8452. if(w!=wmin)
  8453. continue
  8454. if(!w&&s.type==C.PART){if(s.prev)
  8455. s.prev.next=s.next
  8456. vtb[v]=s.next
  8457. if(s.next){s.next.part=s
  8458. s.next.prev=s.prev
  8459. if(s.soln)
  8460. s.next.soln=1}
  8461. continue}
  8462. if(s.type==C.STAVES)
  8463. new_sy=s.sy
  8464. if(fl){fl=0;s.seqst=true}
  8465. s.ts_prev=prev
  8466. prev.ts_next=s
  8467. prev=s
  8468. vtb[v]=s.next}
  8469. if(wmin)
  8470. fl=1}}
  8471. function voice_adj(sys_chg){var p_voice,s,s2,v,sl
  8472. function set_feathered_beam(s1){var s,s2,t,d,b,i,a,d=s1.dur,n=1
  8473. for(s=s1;s;s=s.next){if(s.beam_end||!s.next)
  8474. break
  8475. n++}
  8476. if(n<=1){delete s1.feathered_beam
  8477. return}
  8478. s2=s;b=d/2;a=d/(n-1);t=s1.time
  8479. 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}}
  8480. s.dur=s.time+s.dur-t;s.time=t}
  8481. if(curvoice&&curvoice.clone){parse.istart=parse.eol
  8482. do_cloning()}
  8483. if(par_sy.one_v)
  8484. fill_mr_ba(voice_tb[par_sy.top_voice])
  8485. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v]
  8486. if(!sys_chg){delete p_voice.eoln
  8487. while(1){sl=p_voice.sls.shift()
  8488. if(!sl)
  8489. break
  8490. s=sl.ss
  8491. if(!s.sls)
  8492. s.sls=[]
  8493. sl.loc='o'
  8494. s.sls.push(sl)}}
  8495. for(s=p_voice.sym;s;s=s.next){if(s.time>=staves_found)
  8496. break}
  8497. 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}
  8498. if(s.prev)
  8499. s.prev.next=s2
  8500. else
  8501. voice_tb[s.v].sym=s2
  8502. s.prev=s2}
  8503. switch(s.type){case C.GRACE:if(!cfmt.graceword)
  8504. continue
  8505. for(s2=s.next;s2;s2=s2.next){switch(s2.type){case C.SPACE:continue
  8506. case C.NOTE:if(!s2.a_ly)
  8507. break
  8508. s.a_ly=s2.a_ly;s2.a_ly=null
  8509. break}
  8510. break}
  8511. continue}
  8512. if(s.feathered_beam)
  8513. set_feathered_beam(s)}}}
  8514. function new_syst(init){var st,v,sy_staff,p_voice,sy_new={voices:[],staves:[],top_voice:0}
  8515. if(init){cur_sy=par_sy=sy_new
  8516. return}
  8517. for(v=0;v<voice_tb.length;v++){if(par_sy.voices[v]){st=par_sy.voices[v].st
  8518. sy_staff=par_sy.staves[st]
  8519. p_voice=voice_tb[v]
  8520. sy_staff.staffnonote=p_voice.staffnonote
  8521. if(p_voice.staffscale)
  8522. sy_staff.staffscale=p_voice.staffscale}}
  8523. for(st=0;st<par_sy.staves.length;st++){sy_new.staves[st]=clone(par_sy.staves[st]);sy_new.staves[st].flags=0}
  8524. par_sy.next=sy_new;par_sy=sy_new}
  8525. 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
  8526. function check_meas(){var s3
  8527. if(tim>ptim+wmeasure&&s.prev.type!=C.MREST)
  8528. return 1
  8529. 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}
  8530. for(s=tsfirst;;s=s.ts_next){if(!s)
  8531. return
  8532. switch(s.type){case C.METER:wmeasure=s.wmeasure
  8533. case C.CLEF:case C.KEY:case C.STBRK:continue
  8534. case C.BAR:if(s.bar_num)
  8535. bar_num=s.bar_num
  8536. break}
  8537. break}
  8538. for(s2=s.ts_next;s2;s2=s2.ts_next){if(s2.type==C.BAR&&s2.time){if(s2.time<wmeasure){s=s2
  8539. bar_tim=s.time}
  8540. break}}
  8541. for(;s;s=s.ts_next){switch(s.type){case C.METER:if(s.time==bar_tim)
  8542. break
  8543. if(wmeasure!=1)
  8544. bar_num+=(s.time-bar_tim)/wmeasure
  8545. bar_tim=s.time
  8546. wmeasure=s.wmeasure
  8547. break
  8548. case C.BAR:if(s.time<=tim)
  8549. break
  8550. tim=s.time
  8551. nu=1
  8552. txt=""
  8553. for(s2=s;s2;s2=s2.next){if(s2.time>tim||s2.dur)
  8554. break
  8555. if(!s2.bar_type)
  8556. continue
  8557. if(s2.bar_type!='[')
  8558. nu=0
  8559. if(s2.text)
  8560. txt=s2.text}
  8561. if(s.bar_num){bar_num=s.bar_num
  8562. ptim=bar_tim=tim
  8563. continue}
  8564. if(wmeasure==1){if(s.bar_dotted)
  8565. continue
  8566. if(txt){if(!cfmt.contbarnb){if(txt[0]=='1')
  8567. rep_tim=bar_num
  8568. else
  8569. bar_num=rep_tim}}
  8570. if(!nu)
  8571. s.bar_num=++bar_num
  8572. continue}
  8573. n=bar_num+(tim-bar_tim)/wmeasure
  8574. k=n-(n|0)
  8575. if(cfmt.checkbars&&k&&check_meas())
  8576. error(0,s,"Bad measure duration")
  8577. if(tim>ptim+wmeasure){n|=0
  8578. k=0
  8579. bar_tim=tim
  8580. bar_num=n}
  8581. if(txt){if(txt[0]=='1'){if(!cfmt.contbarnb)
  8582. rep_tim=tim-bar_tim
  8583. if(!nu)
  8584. s.bar_num=n}else{if(!cfmt.contbarnb)
  8585. bar_tim=tim-rep_tim
  8586. n=bar_num+(tim-bar_tim)/wmeasure
  8587. if(n==(n|0))
  8588. s.bar_num=n}}else{n|=0
  8589. s.bar_num=n}
  8590. if(!k)
  8591. ptim=tim
  8592. break}}}
  8593. function not2abc(pit,acc){var i,nn=''
  8594. if(acc&&acc!=3){if(typeof acc!="object"){nn=['__','_','','^','^^'][acc+2]}else{i=acc[0]
  8595. if(i>0){nn+='^'}else{nn+='_'
  8596. i=-i}
  8597. nn+=i+'/'+acc[1]}}
  8598. nn+=ntb[(pit+75)%7]
  8599. for(i=pit;i>=23;i-=7)
  8600. nn+="'"
  8601. for(i=pit;i<16;i+=7)
  8602. nn+=","
  8603. return nn}
  8604. function get_map(text){if(!text)
  8605. return
  8606. var i,note,notes,map,tmp,ns,ty='',a=text.split(/\s+/)
  8607. if(a.length<3){syntax(1,not_enough_p)
  8608. return}
  8609. ns=a[1]
  8610. if(ns[0]=='*'||ns.indexOf("all")==0){ns='all'}else{if(ns.indexOf("octave,")==0||ns.indexOf("key,")==0){ty=ns[0]
  8611. ns=ns.split(',')[1]
  8612. ns=ns.replace(/[,']+/,'').toUpperCase()
  8613. if(ns.indexOf("key,")==0)
  8614. ns=ns.replace(/[=^_]+/,'')}
  8615. tmp=new scanBuf
  8616. tmp.buffer=ns
  8617. note=parse_acc_pit(tmp)
  8618. if(!note){syntax(1,"Bad note in %%map")
  8619. return}
  8620. ns=ty+not2abc(note.pit,note.acc)}
  8621. notes=maps[a[0]]
  8622. if(!notes)
  8623. maps[a[0]]=notes={}
  8624. map=notes[ns]
  8625. if(!map)
  8626. notes[ns]=map=[]
  8627. a.shift()
  8628. a.shift()
  8629. if(!a.length)
  8630. return
  8631. a=info_split(a.join(' '))
  8632. i=0
  8633. if(a[0].indexOf('=')<0){if(a[0][0]!='*'){tmp=new scanBuf;tmp.buffer=a[0];map[1]=parse_acc_pit(tmp)}
  8634. if(!a[1])
  8635. return
  8636. i++
  8637. if(a[1].indexOf('=')<0){map[0]=a[1].split(',')
  8638. i++}}
  8639. for(;i<a.length;i++){switch(a[i]){case"heads=":if(!a[++i]){syntax(1,not_enough_p)
  8640. break}
  8641. map[0]=a[i].split(',')
  8642. break
  8643. case"print=":case"play=":case"print_notrp=":if(!a[++i]){syntax(1,not_enough_p)
  8644. break}
  8645. tmp=new scanBuf;tmp.buffer=a[i];note=parse_acc_pit(tmp)
  8646. if(a[i-1][5]=='_')
  8647. note.notrp=1
  8648. if(a[i-1][1]=='r')
  8649. map[1]=note
  8650. else
  8651. map[3]=note
  8652. break
  8653. case"color=":if(!a[++i]){syntax(1,not_enough_p)
  8654. break}
  8655. map[2]=a[i]
  8656. break}}}
  8657. function new_ctrl(s){var a,ty=(s.type+curvoice.time).toString()
  8658. if(!parse.ctrl)
  8659. parse.ctrl={}
  8660. a=parse.ctrl[ty]
  8661. if(a){if(a&1<<curvoice.v)
  8662. return 1
  8663. parse.ctrl[ty]=a|1<<curvoice.v
  8664. return}
  8665. parse.ctrl[ty]=1<<curvoice.v
  8666. return 1}
  8667. function get_transp(param){if(param[0]=='0')
  8668. return 0
  8669. if("123456789-+".indexOf(param[0])>=0){var val=parseInt(param)
  8670. if(isNaN(val)||val<-36||val>36){syntax(1,errs.bad_transp)
  8671. return}
  8672. val+=36
  8673. val=((val/12|0)-3)*40+abc2svg.isb40[val%12]
  8674. if(param.slice(-1)=='b')
  8675. val+=4
  8676. return val}}
  8677. Abc.prototype.do_pscom=function(text){var h1,val,s,cmd,param,n,k,b
  8678. cmd=text.match(/[^\s]+/)
  8679. if(!cmd)
  8680. return
  8681. cmd=cmd[0];if(curvoice&&curvoice.ignore){switch(cmd){case"staves":case"score":break
  8682. default:return}}
  8683. param=text.replace(cmd,'').trim()
  8684. if(param.slice(-5)==' lock'){fmt_lock[cmd]=true;param=param.slice(0,-5).trim()}else if(fmt_lock[cmd]){return}
  8685. switch(cmd){case"clef":if(parse.state>=2){s=new_clef(param)
  8686. if(s)
  8687. get_clef(s)}
  8688. return
  8689. case"deco":deco_add(param)
  8690. return
  8691. case"linebreak":set_linebreak(param)
  8692. return
  8693. case"map":get_map(param)
  8694. return
  8695. case"maxsysstaffsep":case"sysstaffsep":if(parse.state==3){val=get_unit(param)
  8696. if(isNaN(val)){syntax(1,errs.bad_val,"%%"+cmd)
  8697. return}
  8698. par_sy.voices[curvoice.v][cmd[0]=='m'?"maxsep":"sep"]=val
  8699. return}
  8700. break
  8701. case"multicol":switch(param){case"start":case"new":case"end":break
  8702. default:syntax(1,"Unknown keyword '$1' in %%multicol",param)
  8703. return}
  8704. s={type:C.BLOCK,subtype:"mc_"+param,dur:0}
  8705. if(parse.state>=2){curvoice=voice_tb[0]
  8706. curvoice.eoln=1
  8707. sym_link(s)
  8708. return}
  8709. set_ref(s)
  8710. self.block_gen(s)
  8711. return
  8712. case"ottava":if(parse.state!=3)
  8713. return
  8714. n=parseInt(param)
  8715. if(isNaN(n)||n<-2||n>2||(!n&&!curvoice.ottava)){syntax(1,errs.bad_val,"%%ottava")
  8716. return}
  8717. k=n
  8718. if(n){curvoice.ottava=n}else{n=curvoice.ottava
  8719. curvoice.ottava=0}
  8720. a_dcn.push(["15mb","8vb","","8va","15ma"][n+2]
  8721. +(k?'(':')'))
  8722. return
  8723. case"repbra":if(curvoice)
  8724. curvoice.norepbra=!get_bool(param)
  8725. return
  8726. case"repeat":if(parse.state!=3)
  8727. return
  8728. if(!curvoice.last_sym){syntax(1,"%%repeat cannot start a tune")
  8729. return}
  8730. if(!param.length){n=1;k=1}else{b=param.split(/\s+/);n=parseInt(b[0]);k=parseInt(b[1])
  8731. if(isNaN(n)||n<1||(curvoice.last_sym.type==C.BAR&&n>2)){syntax(1,"Incorrect 1st value in %%repeat")
  8732. return}
  8733. if(isNaN(k)){k=1}else{if(k<1){syntax(1,"Incorrect 2nd value in %%repeat")
  8734. return}}}
  8735. parse.repeat_n=curvoice.last_sym.type==C.BAR?n:-n;parse.repeat_k=k
  8736. return
  8737. case"sep":var h2,len,values,lwidth;set_page();lwidth=img.width-img.lm-img.rm;h1=h2=len=0
  8738. if(param){values=param.split(/\s+/);h1=get_unit(values[0])
  8739. if(values[1]){h2=get_unit(values[1])
  8740. if(values[2])
  8741. len=get_unit(values[2])}
  8742. if(isNaN(h1)||isNaN(h2)||isNaN(len)){syntax(1,errs.bad_val,"%%sep")
  8743. return}}
  8744. if(h1<1)
  8745. h1=14
  8746. if(h2<1)
  8747. h2=h1
  8748. if(len<1)
  8749. len=90
  8750. 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
  8751. return}
  8752. 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()
  8753. return
  8754. case"setbarnb":val=parseInt(param)
  8755. if(isNaN(val)||val<1){syntax(1,"Bad %%setbarnb value")
  8756. break}
  8757. glovar.new_nbar=val
  8758. return
  8759. case"staff":if(parse.state!=3)
  8760. return
  8761. val=parseInt(param)
  8762. if(isNaN(val)){syntax(1,"Bad %%staff value '$1'",param)
  8763. return}
  8764. var st
  8765. if(param[0]=='+'||param[0]=='-')
  8766. st=curvoice.cst+val
  8767. else
  8768. st=val-1
  8769. if(st<0||st>nstaff){syntax(1,"Bad %%staff number $1 (cur $2, max $3)",st,curvoice.cst,nstaff)
  8770. return}
  8771. delete curvoice.floating;curvoice.cst=st
  8772. return
  8773. case"staffbreak":if(parse.state!=3)
  8774. return
  8775. s={type:C.STBRK,dur:0}
  8776. if(param.slice(-1)=='f'){s.stbrk_forced=true
  8777. param=param.replace(/\sf$/,'')}
  8778. if(param){val=get_unit(param)
  8779. if(isNaN(val)){syntax(1,errs.bad_val,"%%staffbreak")
  8780. return}
  8781. s.xmx=val}else{s.xmx=14}
  8782. sym_link(s)
  8783. return
  8784. case"tacet":if(param[0]=='"')
  8785. param=param.slice(1,-1)
  8786. case"stafflines":case"staffscale":case"staffnonote":set_v_param(cmd,param)
  8787. return
  8788. case"staves":case"score":if(!parse.state)
  8789. return
  8790. if(parse.scores&&parse.scores.length>0){text=parse.scores.shift();cmd=text.match(/([^\s]+)\s*(.*)/);param=cmd[2]
  8791. cmd=cmd[1]}
  8792. get_staves(cmd,param)
  8793. return
  8794. case"center":case"text":k=cmd[0]=='c'?'c':cfmt.textoption
  8795. set_font("text")
  8796. if(parse.state>=2){s=new_block("text")
  8797. s.text=param
  8798. s.opt=k
  8799. s.font=cfmt.textfont
  8800. return}
  8801. write_text(param,k)
  8802. return
  8803. case"transpose":if(cfmt.sound)
  8804. return
  8805. val=get_transp(param)
  8806. if(val==undefined){val=get_interval(param)
  8807. if(val==undefined)
  8808. return}
  8809. switch(parse.state){case 0:cfmt.transp=0
  8810. case 1:cfmt.transp=(cfmt.transp||0)+val
  8811. return}
  8812. cfmt.transp=(cfmt.transp||0)+val
  8813. key_trans()
  8814. return
  8815. case"tune":return
  8816. case"user":set_user(param)
  8817. return
  8818. case"voicecolor":if(curvoice)
  8819. curvoice.color=param
  8820. return
  8821. case"vskip":val=get_unit(param)
  8822. if(isNaN(val)){syntax(1,errs.bad_val,"%%vskip")
  8823. return}
  8824. if(val<0){syntax(1,"%%vskip cannot be negative")
  8825. return}
  8826. if(parse.state>=2){s=new_block(cmd);s.sk=val
  8827. return}
  8828. vskip(val);return
  8829. 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
  8830. return}
  8831. if(cmd=="newpage"){blk_flush()
  8832. if(user.page_format)
  8833. blkdiv=2
  8834. return}
  8835. break}
  8836. self.set_format(cmd,param)}
  8837. Abc.prototype.do_begin_end=function(type,opt,text){var i,j,action,s
  8838. switch(type){case"js":js_inject(text)
  8839. break
  8840. case"ml":if(cfmt.pageheight){syntax(1,"Cannot have %%beginml with %%pageheight")
  8841. break}
  8842. if(parse.state>=2){s=new_block(type);s.text=text}else{blk_flush()
  8843. if(user.img_out)
  8844. user.img_out(text)}
  8845. break
  8846. case"svg":j=0
  8847. while(1){i=text.indexOf('<style',j)
  8848. if(i<0)
  8849. break
  8850. i=text.indexOf('>',i)
  8851. j=text.indexOf('</style>',i)
  8852. if(j<0){syntax(1,"No </style> in %%beginsvg sequence")
  8853. break}
  8854. style+=text.slice(i+1,j).replace(/\s+$/,'')}
  8855. j=0
  8856. while(1){i=text.indexOf('<defs>\n',j)
  8857. if(i<0)
  8858. break
  8859. j=text.indexOf('</defs>',i)
  8860. if(j<0){syntax(1,"No </defs> in %%beginsvg sequence")
  8861. break}
  8862. defs_add(text.slice(i+6,j))}
  8863. break
  8864. case"text":action=get_textopt(opt);if(!action)
  8865. action=cfmt.textoption
  8866. set_font("text")
  8867. if(text.indexOf('\\')>=0)
  8868. text=cnv_escape(text)
  8869. if(parse.state>1){s=new_block(type);s.text=text
  8870. s.opt=action
  8871. s.font=cfmt.textfont
  8872. break}
  8873. write_text(text,action)
  8874. break}}
  8875. function generate(){var s,v,p_voice;if(a_dcn.length){syntax(1,"Decoration without symbol")
  8876. a_dcn=[]}
  8877. if(parse.tp){syntax(1,"No end of tuplet")
  8878. s=parse.tps
  8879. if(s)
  8880. delete s.tp
  8881. delete parse.tp}
  8882. if(vover){syntax(1,"No end of voice overlay");get_vover(vover.bar?'|':')')}
  8883. voice_adj();sort_all()
  8884. if(tsfirst){for(v=0;v<voice_tb.length;v++){if(!voice_tb[v].key)
  8885. voice_tb[v].key=parse.ckey}
  8886. if(user.anno_start)
  8887. anno_start=a_start
  8888. if(user.anno_stop)
  8889. anno_stop=a_stop
  8890. self.set_bar_num()
  8891. if(info.P)
  8892. tsfirst.parts=info.P
  8893. if(user.get_abcmodel)
  8894. user.get_abcmodel(tsfirst,voice_tb,abc2svg.sym_name,info)
  8895. if(user.img_out)
  8896. self.output_music()}
  8897. set_page()
  8898. if(info.W)
  8899. put_words(info.W)
  8900. put_history()
  8901. parse.state=0
  8902. blk_flush()
  8903. if(tsfirst){tunes.push([tsfirst,voice_tb,info,cfmt])
  8904. tsfirst=null}}
  8905. function key_trans(){var i,n,a_acc,b40,s=curvoice.ckey,ti=s.time||0
  8906. if(s.k_bagpipe||s.k_drum)
  8907. return
  8908. n=(curvoice.score|0)
  8909. +(curvoice.shift|0)
  8910. +(cfmt.transp|0)
  8911. if((curvoice.tr_sco|0)==n)
  8912. return
  8913. if(is_voice_sig()){curvoice.key=s}else if(curvoice.time!=ti){s=clone(s.orig||s)
  8914. if(!curvoice.new)
  8915. s.k_old_sf=curvoice.ckey.k_sf
  8916. sym_link(s)}
  8917. curvoice.ckey=s
  8918. if(cfmt.transp&&curvoice.shift)
  8919. syntax(0,"Mix of old and new transposition syntaxes");curvoice.tr_sco=n
  8920. b40=(s.k_b40+200+n)%40
  8921. i=abc2svg.b40k[b40]-b40
  8922. if(i){curvoice.tr_sco+=i
  8923. b40+=i}
  8924. s.orig=clone(s)
  8925. s.k_b40=b40
  8926. if(!s.k_none)
  8927. s.k_sf=abc2svg.b40sf[b40]
  8928. if(!s.k_a_acc)
  8929. return
  8930. a_acc=[]
  8931. 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
  8932. a_acc[i]={pit:abc2svg.b40p(b40),acc:abc2svg.b40a(b40)||3}}
  8933. s.k_a_acc=a_acc}
  8934. function fill_mr_ba(p_v){var v,p_v2,mxt=0
  8935. for(v=0;v<voice_tb.length;v++){if(voice_tb[v].time>mxt){p_v2=voice_tb[v]
  8936. mxt=p_v2.time}}
  8937. if(p_v.time>=mxt)
  8938. return
  8939. 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}
  8940. if(p_v2.last_sym.bar_type)
  8941. s2.bar_type=p_v2.last_sym.bar_type
  8942. glovar.mrest_p=1
  8943. curvoice=p_v
  8944. sym_link(s)
  8945. sym_link(s2)
  8946. curvoice=p_v_sav}
  8947. 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
  8948. if(parm){a_vf=parse_staves(parm)
  8949. if(!a_vf)
  8950. return}else if(staves_found<0){syntax(1,errs.bad_val,'%%'+cmd)
  8951. return}
  8952. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  8953. if(p_voice.time>maxtime)
  8954. maxtime=p_voice.time}
  8955. if(!maxtime){par_sy.staves=[]
  8956. par_sy.voices=[]}else{voice_adj(true)
  8957. for(v=0;v<par_sy.voices.length;v++){if(par_sy.voices[v]){curvoice=voice_tb[v]
  8958. break}}
  8959. curvoice.time=maxtime;s={type:C.STAVES,dur:0}
  8960. sym_link(s);par_sy.nstaff=nstaff;if(!parm){s.sy=clone(par_sy,1)
  8961. par_sy.next=s.sy
  8962. par_sy=s.sy
  8963. staves_found=maxtime
  8964. for(v=0;v<nv;v++)
  8965. voice_tb[v].time=maxtime
  8966. curvoice=voice_tb[par_sy.top_voice]
  8967. return}
  8968. new_syst();s.sy=par_sy}
  8969. staves_found=maxtime
  8970. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  8971. delete p_voice.second
  8972. delete p_voice.floating
  8973. if(p_voice.ignore){p_voice.ignore=0
  8974. s=p_voice.sym
  8975. if(s){while(s.next)
  8976. s=s.next}
  8977. p_voice.last_sym=s}}
  8978. range=0
  8979. 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
  8980. a_vf[i][0]=p_voice;while(1){par_sy.voices[v]={range:range++}
  8981. p_voice=p_voice.voice_down
  8982. if(!p_voice)
  8983. break
  8984. v=p_voice.v}}
  8985. par_sy.top_voice=a_vf[0][0].v
  8986. if(a_vf.length==1)
  8987. par_sy.one_v=1
  8988. if(cmd[1]=='t'){for(i=0;i<a_vf.length;i++){flags=a_vf[i][1]
  8989. if(!(flags&(OPEN_BRACE|OPEN_BRACE2)))
  8990. continue
  8991. if((flags&(OPEN_BRACE|CLOSE_BRACE))==(OPEN_BRACE|CLOSE_BRACE)||(flags&(OPEN_BRACE2|CLOSE_BRACE2))==(OPEN_BRACE2|CLOSE_BRACE2))
  8992. continue
  8993. if(a_vf[i+1][1]!=0)
  8994. continue
  8995. if((flags&OPEN_PARENTH)||(a_vf[i+2][1]&OPEN_PARENTH))
  8996. continue
  8997. 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}}}
  8998. st=-1
  8999. for(i=0;i<a_vf.length;i++){flags=a_vf[i][1]
  9000. if((flags&(OPEN_PARENTH|CLOSE_PARENTH))==(OPEN_PARENTH|CLOSE_PARENTH)){flags&=~(OPEN_PARENTH|CLOSE_PARENTH);a_vf[i][1]=flags}
  9001. p_voice=a_vf[i][0]
  9002. 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}}
  9003. par_sy.staves[st].flags=0}
  9004. v=p_voice.v;p_voice.st=p_voice.cst=par_sy.voices[v].st=st;par_sy.staves[st].flags|=flags
  9005. if(flags&OPEN_PARENTH){p_voice2=p_voice
  9006. while(i<a_vf.length-1){p_voice=a_vf[++i][0];v=p_voice.v
  9007. if(a_vf[i][1]&MASTER_VOICE){p_voice2.second=true
  9008. p_voice2=p_voice}else{p_voice.second=true}
  9009. p_voice.st=p_voice.cst=par_sy.voices[v].st=st
  9010. if(a_vf[i][1]&CLOSE_PARENTH)
  9011. break}
  9012. par_sy.staves[st].flags|=a_vf[i][1]}}
  9013. if(st<0)
  9014. st=0
  9015. par_sy.nstaff=nstaff=st
  9016. if(cmd[1]=='c'){for(st=0;st<nstaff;st++)
  9017. par_sy.staves[st].flags^=STOP_BAR}
  9018. nv=voice_tb.length
  9019. st=0
  9020. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  9021. if(par_sy.voices[v])
  9022. st=p_voice.st
  9023. else
  9024. p_voice.st=st
  9025. if(!maxtime){for(s=p_voice.sym;s;s=s.next)
  9026. s.st=st}
  9027. if(!par_sy.voices[v])
  9028. continue
  9029. p_voice2=p_voice.voice_down
  9030. while(p_voice2){i=p_voice2.v
  9031. p_voice2.st=p_voice2.cst=par_sy.voices[i].st=st
  9032. p_voice2=p_voice2.voice_down}
  9033. par_sy.voices[v].second=p_voice.second;st=p_voice.st
  9034. if(st>0&&p_voice.norepbra==undefined&&!(par_sy.staves[st-1].flags&STOP_BAR))
  9035. p_voice.norepbra=true}
  9036. curvoice=parse.state>=2?voice_tb[par_sy.top_voice]:null}
  9037. function clone_voice(id){var v,p_voice
  9038. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v]
  9039. if(p_voice.id==id)
  9040. return p_voice}
  9041. 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)
  9042. p_voice.sls=[]
  9043. delete p_voice.nm
  9044. delete p_voice.snm
  9045. delete p_voice.new_name
  9046. delete p_voice.lyric_restart
  9047. delete p_voice.lyric_cont
  9048. delete p_voice.sym_restart
  9049. delete p_voice.sym_cont
  9050. delete p_voice.have_ly
  9051. delete p_voice.tie_s
  9052. voice_tb.push(p_voice)
  9053. return p_voice}
  9054. function get_vover(type){var p_voice2,p_voice3,range,s,time,v,v2,v3,s2
  9055. if(type=='|'||type==')'){if(!curvoice.last_note){syntax(1,errs.nonote_vo)
  9056. if(vover){curvoice=vover.p_voice
  9057. vover=null}
  9058. return}
  9059. curvoice.last_note.beam_end=true
  9060. if(!vover){syntax(1,"Erroneous end of voice overlay")
  9061. return}
  9062. if(curvoice.time!=vover.p_voice.time){if(!curvoice.ignore)
  9063. syntax(1,"Wrong duration in voice overlay");if(curvoice.time>vover.p_voice.time)
  9064. vover.p_voice.time=curvoice.time}
  9065. curvoice.acc=[]
  9066. p_voice2=vover.p_voice
  9067. s=curvoice.last_sym
  9068. if(s.type==C.SPACE&&p_voice2.last_sym.type!=C.SPACE){s.p_v=p_voice2
  9069. s.v=s.p_v.v
  9070. while(s.prev.type==C.SPACE){s=s.prev
  9071. s.p_v=p_voice2
  9072. s.v=s.p_v.v}
  9073. s2=s.prev
  9074. s2.next=null
  9075. s.prev=p_voice2.last_sym
  9076. s.prev.next=s
  9077. p_voice2.last_sym=curvoice.last_sym
  9078. curvoice.last_sym=s2}
  9079. curvoice=p_voice2
  9080. vover=null
  9081. return}
  9082. if(type=='('){if(vover){syntax(1,"Voice overlay already started")
  9083. return}
  9084. vover={p_voice:curvoice,time:curvoice.time}
  9085. return}
  9086. if(!curvoice.last_note){syntax(1,errs.nonote_vo)
  9087. return}
  9088. curvoice.last_note.beam_end=true;p_voice2=curvoice.voice_down
  9089. 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
  9090. v2=p_voice2.v;if(par_sy.voices[curvoice.v]){par_sy.voices[v2]={st:curvoice.st,second:true}
  9091. range=par_sy.voices[curvoice.v].range
  9092. for(v=0;v<par_sy.voices.length;v++){if(par_sy.voices[v]&&par_sy.voices[v].range>range)
  9093. par_sy.voices[v].range++}
  9094. par_sy.voices[v2].range=range+1}}
  9095. p_voice2.ulen=curvoice.ulen
  9096. p_voice2.dur_fact=curvoice.dur_fact
  9097. p_voice2.acc=[]
  9098. if(!vover){time=p_voice2.time
  9099. if(curvoice.ignore)
  9100. s=null
  9101. else
  9102. for(s=curvoice.last_sym;;s=s.prev){if(s.type==C.BAR||s.time<=time)
  9103. break}
  9104. 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")
  9105. if(curvoice.time>vover.p_voice.time)
  9106. vover.p_voice.time=curvoice.time}}
  9107. p_voice2.time=vover.time;curvoice=p_voice2}
  9108. function is_voice_sig(){var s
  9109. if(curvoice.time)
  9110. return false
  9111. if(!curvoice.last_sym)
  9112. return true
  9113. for(s=curvoice.last_sym;s;s=s.prev)
  9114. if(w_tb[s.type])
  9115. return false
  9116. return true}
  9117. function get_clef(s){var s2,s3
  9118. if(s.clef_type=='p'){s2=curvoice.ckey
  9119. s2.k_drum=1
  9120. s2.k_sf=0
  9121. s2.k_b40=2
  9122. s2.k_map=abc2svg.keys[7]
  9123. if(!curvoice.key)
  9124. curvoice.key=s2}
  9125. if(!curvoice.time&&is_voice_sig()){curvoice.clef=s
  9126. s.fmt=cfmt
  9127. return}
  9128. for(s2=curvoice.last_sym;s2&&s2.time==curvoice.time;s2=s2.prev){if(w_tb[s2.type])
  9129. break}
  9130. if(s2&&s2.time==curvoice.time&&s2.k_sf!=undefined){s3=s2
  9131. s2=s2.prev}
  9132. if(s2&&s2.time==curvoice.time&&s2.bar_type&&s2.bar_type[0]!=':')
  9133. s3=s2
  9134. if(s3){s2=curvoice.last_sym
  9135. curvoice.last_sym=s3.prev
  9136. sym_link(s)
  9137. s.next=s3
  9138. s3.prev=s
  9139. curvoice.last_sym=s2
  9140. if(s.soln){delete s.soln
  9141. curvoice.eoln=true}}else{sym_link(s)}
  9142. if(s.prev)
  9143. s.clef_small=1}
  9144. 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
  9145. a=a[1]
  9146. if(empty)
  9147. s.invis=1
  9148. if(parse.state==1){parse.ckey=s
  9149. if(empty){s_key.k_sf=0;s_key.k_none=true
  9150. s_key.k_map=abc2svg.keys[7]}
  9151. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v];p_voice.ckey=clone(s_key)}
  9152. if(a.length){memo_kv_parm('*',a)
  9153. a=[]}
  9154. if(!glovar.ulen)
  9155. glovar.ulen=C.BLEN/8;goto_tune()}else if(!empty){s.k_old_sf=curvoice.ckey.k_sf
  9156. curvoice.ckey=s
  9157. sym_link(s)
  9158. if(curvoice.tr_sco)
  9159. curvoice.tr_sco=0}
  9160. if(!curvoice){if(!voice_tb.length){curvoice=new_voice("1")
  9161. var def=1}else{curvoice=voice_tb[staves_found<0?0:par_sy.top_voice]}}
  9162. p_voice=curvoice.clone
  9163. if(p_voice)
  9164. curvoice.clone=null
  9165. get_voice(curvoice.id+' '+a.join(' '))
  9166. if(p_voice)
  9167. curvoice.clone=p_voice
  9168. if(def)
  9169. curvoice.default=1}
  9170. function new_voice(id){var v,p_v_sav,p_voice=voice_tb[0],n=voice_tb.length
  9171. if(n==1&&p_voice.default){delete p_voice.default
  9172. if(!p_voice.time){p_voice.id=id
  9173. return p_voice}}
  9174. for(v=0;v<n;v++){p_voice=voice_tb[v]
  9175. if(p_voice.id==id)
  9176. return p_voice}
  9177. 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}
  9178. voice_tb.push(p_voice);if(parse.state==3){p_voice.ckey=clone(parse.ckey)
  9179. if(p_voice.ckey.k_bagpipe&&!p_voice.pos.stm){p_voice.pos=clone(p_voice.pos)
  9180. p_voice.pos.stm&=~0x07
  9181. p_voice.pos.stm|=C.SL_BELOW}}
  9182. return p_voice}
  9183. function init_tune(){nstaff=-1;voice_tb=[];curvoice=null;new_syst(true);staves_found=-1;gene={}
  9184. a_de=[]
  9185. cross={}}
  9186. 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
  9187. delete curvoice.clone
  9188. if(file[eol-1]=='[')
  9189. eol--
  9190. include++;for(i=0;i<vs.length;i++){parse=Object.create(parse_sav)
  9191. parse.line=Object.create(parse_sav.line)
  9192. get_voice(vs[i]+' '+a.join(' '))
  9193. tosvg(parse.fname,file,bol,eol)}
  9194. include--
  9195. parse=parse_sav}
  9196. function get_voice(parm){var v,vs,a=info_split(parm),vid=a.shift()
  9197. if(!vid)
  9198. return
  9199. if(curvoice&&curvoice.clone)
  9200. do_cloning()
  9201. if(vid.indexOf(',')>0)
  9202. vs=vid.split(',')
  9203. else
  9204. vs=[vid]
  9205. if(parse.state<2){while(1){vid=vs.shift()
  9206. if(!vid)
  9207. break
  9208. if(a.length)
  9209. memo_kv_parm(vid,a)
  9210. if(vid!='*'&&parse.state==1)
  9211. curvoice=new_voice(vid)}
  9212. return}
  9213. if(vid=='*'){syntax(1,"Cannot have V:* in tune body")
  9214. return}
  9215. curvoice=new_voice(vs[0])
  9216. if(vs.length>1){vs.shift()
  9217. curvoice.clone={vs:vs,a:a,bol:parse.iend}
  9218. if(parse.file[curvoice.clone.bol-1]!=']')
  9219. curvoice.clone.bol++}
  9220. set_kv_parm(a)
  9221. key_trans()
  9222. v=curvoice.v
  9223. if(curvoice.new){delete curvoice.new
  9224. if(staves_found<0){curvoice.st=curvoice.cst=++nstaff;par_sy.nstaff=nstaff;par_sy.voices[v]={st:nstaff,range:v}
  9225. par_sy.staves[nstaff]={stafflines:curvoice.stafflines||"|||||",staffscale:1}}else if(!par_sy.voices[v]){curvoice.ignore=1
  9226. return}}
  9227. if(!curvoice.filtered&&par_sy.voices[v]&&(parse.voice_opts||parse.tune_v_opts)){curvoice.filtered=true;voice_filter()}}
  9228. function goto_tune(){var v,p_voice
  9229. set_page();write_heading();if(glovar.new_nbar){gene.nbar=glovar.new_nbar
  9230. glovar.new_nbar=0}else{gene.nbar=1}
  9231. parse.state=3
  9232. for(v=0;v<voice_tb.length;v++){p_voice=voice_tb[v];p_voice.ulen=glovar.ulen
  9233. if(parse.ckey.k_bagpipe&&!p_voice.pos.stm){p_voice.pos=clone(p_voice.pos)
  9234. p_voice.pos.stm&=~0x07
  9235. p_voice.pos.stm|=C.SL_BELOW}}
  9236. if(staves_found<0){v=voice_tb.length
  9237. par_sy.nstaff=nstaff=v-1
  9238. 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}
  9239. par_sy.staves[v]={stafflines:p_voice.stafflines||"|||||",staffscale:1}}}}
  9240. function get_sym(p,cont){var s,c,i,j,d
  9241. if(curvoice.ignore)
  9242. return
  9243. if(cont){s=curvoice.sym_cont
  9244. if(!s){syntax(1,"+: symbol line without music")
  9245. return}}else{if(curvoice.sym_restart){curvoice.sym_start=curvoice.sym_restart;curvoice.sym_restart=null}
  9246. s=curvoice.sym_start
  9247. if(!s)
  9248. s=curvoice.sym
  9249. if(!s){syntax(1,"s: without music")
  9250. return}}
  9251. i=0
  9252. while(1){while(p[i]==' '||p[i]=='\t')
  9253. i++;c=p[i]
  9254. if(!c)
  9255. break
  9256. switch(c){case'|':while(s&&s.type!=C.BAR)
  9257. s=s.next
  9258. if(!s){syntax(1,"Not enough measure bars for symbol line")
  9259. return}
  9260. s=s.next;i++
  9261. continue
  9262. case'!':case'"':j=++i
  9263. i=p.indexOf(c,j)
  9264. if(i<0){syntax(1,c=='!'?"No end of decoration":"No end of chord symbol/annotation");i=p.length
  9265. continue}
  9266. d=p.slice(j-1,i+1)
  9267. break
  9268. case'*':break
  9269. default:d=c.charCodeAt(0)
  9270. if(d<128){d=char_tb[d]
  9271. if(d.length>1&&(d[0]=='!'||d[0]=='"')){c=d[0]
  9272. break}}
  9273. syntax(1,errs.bad_char,c)
  9274. break}
  9275. while(s&&s.type!=C.NOTE)
  9276. s=s.next
  9277. if(!s){syntax(1,"Too many elements in symbol line")
  9278. return}
  9279. switch(c){default:break
  9280. case'!':a_dcn.push(d.slice(1,-1))
  9281. deco_cnv(s,s.prev)
  9282. break
  9283. case'"':parse_gchord(d)
  9284. if(a_gch)
  9285. csan_add(s)
  9286. break}
  9287. s=s.next;i++}
  9288. curvoice.sym_cont=s}
  9289. function get_lyrics(text,cont){var s,word,p,i,j,ly,dfnt,ln,c,cf
  9290. if(curvoice.ignore)
  9291. return
  9292. if((curvoice.pos.voc&0x07)!=C.SL_HIDDEN)
  9293. curvoice.have_ly=true
  9294. if(cont){s=curvoice.lyric_cont
  9295. if(!s){syntax(1,"+: lyric without music")
  9296. return}
  9297. dfnt=get_font("vocal")
  9298. if(gene.deffont!=dfnt){if(gene.curfont==gene.deffont)
  9299. gene.curfont=dfnt
  9300. gene.deffont=dfnt}}else{set_font("vocal")
  9301. 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}
  9302. if(!s)
  9303. s=curvoice.sym
  9304. if(!s){syntax(1,"w: without music")
  9305. return}}
  9306. p=text;i=0
  9307. cf=gene.curfont
  9308. while(1){while(p[i]==' '||p[i]=='\t')
  9309. i++
  9310. if(!p[i])
  9311. break
  9312. ln=0
  9313. j=parse.istart+i+2
  9314. switch(p[i]){case'|':while(s&&s.type!=C.BAR)
  9315. s=s.next
  9316. if(!s){syntax(1,"Not enough measure bars for lyric line")
  9317. return}
  9318. s=s.next;i++
  9319. continue
  9320. case'-':case'_':word=p[i]
  9321. ln=p[i]=='-'?2:3
  9322. break
  9323. case'*':word=""
  9324. break
  9325. default:word="";while(1){if(!p[i])
  9326. break
  9327. switch(p[i]){case'_':case'*':case'|':i--
  9328. case' ':case'\t':break
  9329. case'~':word+=' '
  9330. i++
  9331. continue
  9332. case'-':ln=1
  9333. break
  9334. case'\\':if(!p[++i])
  9335. continue
  9336. word+=p[i++]
  9337. continue
  9338. case'$':word+=p[i++]
  9339. c=p[i]
  9340. if(c=='0')
  9341. gene.curfont=gene.deffont
  9342. else if(c>='1'&&c<='9')
  9343. gene.curfont=get_font("u"+c)
  9344. default:word+=p[i++]
  9345. continue}
  9346. break}
  9347. break}
  9348. while(s&&s.type!=C.NOTE)
  9349. s=s.next
  9350. if(!s){syntax(1,"Too many words in lyric line")
  9351. return}
  9352. if(word&&(s.pos.voc&0x07)!=C.SL_HIDDEN){ly={t:word,font:cf,istart:j,iend:j+word.length}
  9353. if(ln)
  9354. ly.ln=ln
  9355. if(!s.a_ly)
  9356. s.a_ly=[]
  9357. s.a_ly[curvoice.lyric_line]=ly
  9358. cf=gene.curfont}
  9359. s=s.next;i++}
  9360. curvoice.lyric_cont=s}
  9361. 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
  9362. for(s2=s.ts_next;s2;s2=s2.ts_next){if(s2.shrink){dx+=s2.shrink
  9363. n++}
  9364. if(s2.bar_type){dx+=3
  9365. break}
  9366. if(!s2.a_ly)
  9367. continue
  9368. i=s2.a_ly.length
  9369. while(--i>=0){ly=s2.a_ly[i]
  9370. if(!ly)
  9371. continue
  9372. if(!ly.ln||ly.ln<2)
  9373. break}
  9374. if(i>=0)
  9375. break}
  9376. for(i=0;i<a_ly.length;i++){ly=a_ly[i]
  9377. if(!ly)
  9378. continue
  9379. gene.curfont=ly.font
  9380. ly.t=p=str2svg(ly.t)
  9381. if(ly.ln>=2){ly.shift=0
  9382. continue}
  9383. spw=cwid(' ')*ly.font.swfac
  9384. w=p.wh[0]+spw*1.5
  9385. 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(' ')
  9386. set_font(ly.font)
  9387. if(j>0)
  9388. sz=strwh(p.slice(0,j))[0]
  9389. else
  9390. sz=w*.2}
  9391. shift=(w-sz)*.4
  9392. if(shift>14)
  9393. shift=14
  9394. shift+=sz
  9395. if(p[0]>='0'&&p[0]<='9'){if(shift>align)
  9396. align=shift}}else{shift=w*.4
  9397. if(shift>14)
  9398. shift=14}
  9399. ly.shift=shift
  9400. if(shift>wl)
  9401. wl=shift
  9402. w-=shift
  9403. if(w>wx)
  9404. wx=w}
  9405. while(!s3.seqst)
  9406. s3=s3.ts_prev
  9407. if(s3.ts_prev&&s3.ts_prev.bar_type)
  9408. wl-=4
  9409. if(s3.wl<wl){s3.shrink+=wl-s3.wl
  9410. s3.wl=wl}
  9411. dx-=6
  9412. if(dx<wx){dx=(wx-dx)/n
  9413. s1=s.ts_next
  9414. while(1){if(s1.shrink){s1.shrink+=dx
  9415. s3.wr+=dx
  9416. s3=s1}
  9417. if(s1==s2)
  9418. break
  9419. s1=s1.ts_next}}
  9420. if(align>0){for(i=0;i<a_ly.length;i++){ly=a_ly[i]
  9421. if(ly&&ly.t[0]>='0'&&ly.t[0]<='9')
  9422. ly.shift=align}}}
  9423. function draw_lyric_line(p_voice,j,y){var p,lastx,w,s,s2,ly,lyl,ln,hyflag,lflag,x0,shift
  9424. if(p_voice.hy_st&(1<<j)){hyflag=true;p_voice.hy_st&=~(1<<j)}
  9425. for(s=p_voice.sym;;s=s.next)
  9426. if(s.type!=C.CLEF&&s.type!=C.KEY&&s.type!=C.METER)
  9427. break
  9428. lastx=s.prev?s.prev.x:tsfirst.x;x0=0
  9429. for(;s;s=s.next){if(s.a_ly)
  9430. ly=s.a_ly[j]
  9431. else
  9432. ly=null
  9433. 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}}
  9434. continue}
  9435. if(ly.font!=gene.curfont)
  9436. gene.curfont=ly.font
  9437. p=ly.t;ln=ly.ln||0
  9438. w=p.wh[0]
  9439. shift=ly.shift
  9440. 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}}
  9441. if(lflag&&ln!=3){out_wln(lastx+3,y,x0-lastx+3);lflag=false;lastx=s.x+s.wr}
  9442. if(ln>=2){if(x0==0&&lastx>s.x-18)
  9443. lastx=s.x-18
  9444. if(ln==2)
  9445. hyflag=true
  9446. else
  9447. lflag=true;x0=s.x-shift
  9448. continue}
  9449. x0=s.x-shift;if(ln)
  9450. hyflag=true
  9451. 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}
  9452. anno_start(s2,'lyrics')}
  9453. xy_str(x0,y,p)
  9454. anno_stop(s2,'lyrics')
  9455. lastx=x0+w}
  9456. if(hyflag){hyflag=false;x0=realwidth-10
  9457. if(x0<lastx+10)
  9458. x0=lastx+10;out_hyph(lastx,y,x0-lastx)
  9459. if(p_voice.s_next&&p_voice.s_next.fmt.hyphencont)
  9460. p_voice.hy_st|=(1<<j)}
  9461. for(p_voice.s_next;s;s=s.next){if(s.type==C.NOTE){if(!s.a_ly)
  9462. break
  9463. ly=s.a_ly[j]
  9464. if(ly&&ly.ln==3){lflag=true;x0=realwidth-15
  9465. if(x0<lastx+12)
  9466. x0=lastx+12}
  9467. break}}
  9468. if(lflag){out_wln(lastx+3,y,x0-lastx+3);lflag=false}}
  9469. function draw_lyrics(p_voice,nly,a_h,y,incr){var j,top,sc=staff_tb[p_voice.st].staffscale;set_font("vocal")
  9470. if(incr>0){if(y>-tsfirst.fmt.vocalspace)
  9471. y=-tsfirst.fmt.vocalspace;y*=sc
  9472. for(j=0;j<nly;j++){y-=a_h[j]*1.1;draw_lyric_line(p_voice,j,y+a_h[j]*.22)}
  9473. return y/sc}
  9474. top=staff_tb[p_voice.st].topbar+tsfirst.fmt.vocalspace
  9475. if(y<top)
  9476. y=top;y*=sc
  9477. for(j=nly;--j>=0;){draw_lyric_line(p_voice,j,y+a_h[j]*.22)
  9478. y+=a_h[j]*1.1}
  9479. return y/sc}
  9480. 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
  9481. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  9482. if(!p_voice.sym)
  9483. continue
  9484. if(p_voice.st!=st){top=0;bot=0;st=p_voice.st}
  9485. nly=0
  9486. if(p_voice.have_ly){if(!h_tb[v])
  9487. h_tb[v]=[]
  9488. for(s=p_voice.sym;s;s=s.next){a_ly=s.a_ly
  9489. if(!a_ly)
  9490. continue
  9491. x=s.x;w=10
  9492. for(i=0;i<a_ly.length;i++){ly=a_ly[i]
  9493. if(ly){x-=ly.shift;w=ly.t.wh[0]
  9494. break}}
  9495. y=y_get(p_voice.st,1,x,w)
  9496. if(top<y)
  9497. top=y;y=y_get(p_voice.st,0,x,w)
  9498. if(bot>y)
  9499. bot=y
  9500. while(nly<a_ly.length)
  9501. h_tb[v][nly++]=0
  9502. for(i=0;i<a_ly.length;i++){ly=a_ly[i]
  9503. if(!ly)
  9504. continue
  9505. if(!h_tb[v][i]||ly.t.wh[1]>h_tb[v][i])
  9506. h_tb[v][i]=ly.t.wh[1]}}}else{y=y_get(p_voice.st,1,0,realwidth)
  9507. if(top<y)
  9508. top=y;y=y_get(p_voice.st,0,0,realwidth)
  9509. if(bot>y)
  9510. bot=y}
  9511. if(!lyst_tb[st])
  9512. lyst_tb[st]={}
  9513. lyst_tb[st].top=top;lyst_tb[st].bot=bot;nly_tb[v]=nly
  9514. if(nly==0)
  9515. continue
  9516. if(p_voice.pos.voc)
  9517. above_tb[v]=(p_voice.pos.voc&0x07)==C.SL_ABOVE
  9518. else if(voice_tb[v+1]&&voice_tb[v+1].st==st&&voice_tb[v+1].have_ly)
  9519. above_tb[v]=true
  9520. else
  9521. above_tb[v]=false
  9522. if(above_tb[v])
  9523. lyst_tb[st].a=true
  9524. else
  9525. lyst_tb[st].b=true}
  9526. i=0
  9527. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  9528. if(!p_voice.sym)
  9529. continue
  9530. if(!p_voice.have_ly)
  9531. continue
  9532. if(above_tb[v]){rv_tb[i++]=v
  9533. continue}
  9534. st=p_voice.st;set_dscale(st,true)
  9535. if(nly_tb[v]>0)
  9536. lyst_tb[st].bot=draw_lyrics(p_voice,nly_tb[v],h_tb[v],lyst_tb[st].bot,1)}
  9537. 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)}
  9538. for(v=0;v<nv;v++){p_voice=voice_tb[v]
  9539. if(!p_voice.sym)
  9540. continue
  9541. st=p_voice.st;if(lyst_tb[st].a){top=lyst_tb[st].top+2
  9542. for(s=p_voice.sym;s;s=s.next){if(s.a_ly){y_set(st,1,s.x-2,10,top)}}}
  9543. if(lyst_tb[st].b){bot=lyst_tb[st].bot-2
  9544. 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)}}}}
  9545. 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
  9546. function get_float(){var txt=''
  9547. while(1){c=text[i++]
  9548. if("1234567890.-".indexOf(c)<0)
  9549. return parseFloat(txt)
  9550. txt+=c}}
  9551. istart=parse.bol+line.index
  9552. if(type.length>1){text=type.slice(1,-1);iend=istart+1}else{i=++line.index
  9553. while(1){j=line.buffer.indexOf('"',i)
  9554. if(j<0){syntax(1,"No end of chord symbol/annotation")
  9555. return}
  9556. if(line.buffer[j-1]!='\\'||line.buffer[j-2]=='\\')
  9557. break
  9558. i=j+1}
  9559. text=cnv_escape(line.buffer.slice(line.index,j))
  9560. line.index=j
  9561. iend=parse.bol+line.index+1}
  9562. if(ann_font.pad)
  9563. h_ann+=ann_font.pad
  9564. i=0;type='g'
  9565. while(1){c=text[i]
  9566. if(!c)
  9567. break
  9568. gch={text:"",istart:istart,iend:iend,font:ann_font}
  9569. switch(c){case'@':type=c;i++;x_abs=get_float()
  9570. if(c!=','){syntax(1,"',' lacking in annotation '@x,y'");y_abs=0}else{y_abs=get_float()
  9571. if(c!=' ')
  9572. i--}
  9573. gch.x=x_abs;gch.y=y_abs
  9574. break
  9575. case'^':gch.pos=C.SL_ABOVE
  9576. case'_':if(c=='_')
  9577. gch.pos=C.SL_BELOW
  9578. case'<':case'>':i++;type=c
  9579. break
  9580. default:switch(type){case'g':gch.font=get_font("gchord")
  9581. gch.pos=curvoice.pos.gch||C.SL_ABOVE
  9582. break
  9583. case'^':gch.pos=C.SL_ABOVE
  9584. break
  9585. case'_':gch.pos=C.SL_BELOW
  9586. break
  9587. case'@':gch.x=x_abs;y_abs-=h_ann;gch.y=y_abs
  9588. break}
  9589. break}
  9590. gch.type=type
  9591. while(1){c=text[i]
  9592. if(!c)
  9593. break
  9594. switch(c){case'\\':c=text[++i]
  9595. if(c=='n')
  9596. break
  9597. gch.text+='\\'
  9598. if(!c)
  9599. break
  9600. default:gch.text+=c;i++
  9601. continue
  9602. case'&':while(1){gch.text+=c;c=text[++i]
  9603. switch(c){default:continue
  9604. case';':case undefined:case'\\':break}
  9605. break}
  9606. if(c==';'){i++;gch.text+=c
  9607. continue}
  9608. break
  9609. case';':break}
  9610. i++
  9611. break}
  9612. gch.otext=gch.text
  9613. if(!a_gch)
  9614. a_gch=[]
  9615. a_gch.push(gch)}}
  9616. var note_names="CDEFGAB",acc_name=["bb","b","","#","##"]
  9617. function gch_tr1(p,tr){var i,o,n,a,ip,b40,csa=p.split('/')
  9618. for(i=0;i<csa.length;i++){p=csa[i];o=p.search(/[A-G]/)
  9619. if(o<0)
  9620. continue
  9621. ip=o+1
  9622. a=0
  9623. while(p[ip]=='#'||p[ip]=='\u266f'){a++;ip++}
  9624. while(p[ip]=='b'||p[ip]=='\u266d'){a--;ip++}
  9625. n=note_names.indexOf(p[o])+16
  9626. b40=(abc2svg.pab40(n,a)+tr+200)%40
  9627. b40=abc2svg.b40k[b40]
  9628. csa[i]=p.slice(0,o)+
  9629. note_names[abc2svg.b40_p[b40]]+
  9630. acc_name[abc2svg.b40_a[b40]+2]+
  9631. p.slice(ip)}
  9632. return csa.join('/')}
  9633. function csan_add(s){var i,gch
  9634. 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")
  9635. a_gch.splice(i)}}}
  9636. if(curvoice.tr_sco){for(i=0;i<a_gch.length;i++){gch=a_gch[i]
  9637. if(gch.type=='g')
  9638. gch.text=gch_tr1(gch.text,curvoice.tr_sco)}}
  9639. if(s.a_gch)
  9640. s.a_gch=s.a_gch.concat(a_gch)
  9641. else
  9642. s.a_gch=a_gch
  9643. a_gch=null}
  9644. 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]
  9645. if(gch.type=='g'){gch.text=gch.text.replace(/##|#|=|bb|b/g,function(x){switch(x){case'##':return"&#x1d12a;"
  9646. case'#':return"\u266f"
  9647. case'=':return"\u266e"
  9648. case'b':return"\u266d"}
  9649. return"&#x1d12b;"})}else{if(gch.type=='@'&&!user.anno_start&&!user.anno_stop){set_font(gch.font)
  9650. gch.text=str2svg(gch.text)
  9651. continue}}
  9652. set_font(gch.font);gch.text=str2svg(gch.text)
  9653. wh=gch.text.wh
  9654. switch(gch.type){case'@':break
  9655. default:xspc=wh[0]*GCHPRE
  9656. if(xspc>8)
  9657. xspc=8;gch.x=-xspc;break
  9658. case'<':gch.x=-(wh[0]+6);y_left-=wh[1];gch.y=y_left+wh[1]/2
  9659. break
  9660. case'>':gch.x=6;y_right-=wh[1];gch.y=y_right+wh[1]/2
  9661. break}}
  9662. y_left/=2;y_right/=2
  9663. for(ix=0;ix<s.a_gch.length;ix++){gch=s.a_gch[ix]
  9664. switch(gch.type){case'<':gch.y-=y_left
  9665. break
  9666. case'>':gch.y-=y_right
  9667. break}}}
  9668. Abc.prototype.draw_gchord=function(i,s,x,y){if(s.invis&&s.play)
  9669. return
  9670. 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
  9671. if(an.font.figb){h*=2.4
  9672. dy+=an.font.size*1.3}
  9673. switch(an.type){case'_':y-=h+pad
  9674. break
  9675. case'^':y+=pad
  9676. break
  9677. case'<':case'>':if(an.type=='<'){if(s.notes[0].acc)
  9678. x-=s.notes[0].shac
  9679. x-=pad}else{if(s.xmx)
  9680. x+=s.xmx
  9681. if(s.dots)
  9682. x+=1.5+3.5*s.dots
  9683. x+=pad}
  9684. y+=(s.type==C.NOTE?(((s.notes[s.nhd].pit+s.notes[0].pit)>>1)-
  9685. 18)*3:12)
  9686. -h/2
  9687. break
  9688. default:if(y>=0)
  9689. y+=pad
  9690. else
  9691. y-=h+pad
  9692. break
  9693. case'@':y+=(s.type==C.NOTE?(((s.notes[s.nhd].pit+s.notes[0].pit)>>1)-
  9694. 18)*3:12)
  9695. -h/2
  9696. if(y>0){y2=y+h+pad+2
  9697. if(y2>staff_tb[s.st].ann_top)
  9698. staff_tb[s.st].ann_top=y2}else{y2=y-2
  9699. if(y2<staff_tb[s.st].ann_bot)
  9700. staff_tb[s.st].ann_bot=y2}
  9701. break}
  9702. if(an.type!='@'){if(y>=0)
  9703. y_set(s.st,1,x,w,y+h+pad+2)
  9704. else
  9705. y_set(s.st,0,x,w,y-pad)}
  9706. use_font(an.font)
  9707. set_font(an.font)
  9708. set_dscale(s.st)
  9709. if(user.anno_start)
  9710. user.anno_start("annot",an.istart,an.iend,x-2,y+h+2,w+4,h+4,s)
  9711. xy_str(x,y+dy,an.text)
  9712. if(user.anno_stop)
  9713. user.anno_stop("annot",an.istart,an.iend,x-2,y+h+2,w+4,h+4,s)}
  9714. function draw_all_chsy(){var s,san1,an,i,x,y,w,n_an=0,minmax=new Array(nstaff+1)
  9715. function set_an_yu(j){var an,i,s,x,y,w
  9716. for(s=san1;s;s=s.ts_next){an=s.a_gch
  9717. if(!an)
  9718. continue
  9719. i=an.length-j-1
  9720. an=an[i]
  9721. if(!an)
  9722. continue
  9723. if(an.pos==C.SL_ABOVE){x=s.x+an.x
  9724. w=an.text.wh[0]
  9725. if(w&&x+w>realwidth)
  9726. x=realwidth-w
  9727. y=y_get(s.st,1,x,w)+2
  9728. if(an.type=='g'&&y<minmax[s.st].yup)
  9729. y=minmax[s.st].yup}else if(an.pos==C.SL_BELOW||an.pos==C.SL_HIDDEN){continue}else{x=s.x+an.x
  9730. y=an.y}
  9731. self.draw_gchord(i,s,x,y)}}
  9732. function set_an_yl(i){var an,x,y,w
  9733. for(var s=san1;s;s=s.ts_next){an=s.a_gch
  9734. if(!an)
  9735. continue
  9736. an=an[i]
  9737. if(!an||an.pos!=C.SL_BELOW)
  9738. continue
  9739. x=s.x+an.x
  9740. w=an.text.wh[0]
  9741. if(w&&x+w>realwidth)
  9742. x=realwidth-w
  9743. y=y_get(s.st,0,x,w)-2
  9744. if(an.type=='g'&&y>minmax[s.st].ydn)
  9745. y=minmax[s.st].ydn
  9746. self.draw_gchord(i,s,x,y)}}
  9747. for(i=0;i<=nstaff;i++)
  9748. minmax[i]={ydn:staff_tb[i].botbar-3,yup:staff_tb[i].topbar+4}
  9749. for(s=tsfirst;s;s=s.ts_next){an=s.a_gch
  9750. if(!an)
  9751. continue
  9752. if(!san1)
  9753. san1=s
  9754. i=an.length
  9755. if(i>n_an)
  9756. n_an=i
  9757. while(--i>=0){if(an[i].type=='g'){an=an[i]
  9758. x=s.x+an.x
  9759. w=an.text.wh[0]
  9760. if(w&&x+w>realwidth)
  9761. x=realwidth-w
  9762. if(an.pos==C.SL_ABOVE){y=y_get(s.st,true,x,w)+2
  9763. if(y>minmax[s.st].yup)
  9764. minmax[s.st].yup=y}else if(an.pos==C.SL_BELOW){y=y_get(s.st,false,x,w)-2
  9765. if(y<minmax[s.st].ydn)
  9766. minmax[s.st].ydn=y}
  9767. break}}}
  9768. if(!san1)
  9769. return
  9770. set_dscale(-1)
  9771. for(i=0;i<n_an;i++){set_an_yu(i)
  9772. set_an_yl(i)}}
  9773. init_tune()
  9774. Abc.prototype.a_de=function(){return a_de}
  9775. 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)
  9776. deco_cnv(s)}
  9777. Abc.prototype.defs_add=defs_add
  9778. Abc.prototype.dh_put=function(nm,s,nt){a_dcn.push(nm)
  9779. dh_cnv(s,nt)}
  9780. Abc.prototype.draw_meter=draw_meter
  9781. 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}
  9782. 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
  9783. 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)}
  9784. Abc.prototype.set_hl=set_hl
  9785. Abc.prototype.set_page=set_page
  9786. Abc.prototype.set_pagef=function(){blkdiv=1}
  9787. Abc.prototype.set_realwidth=function(v){realwidth=v}
  9788. Abc.prototype.set_scale=set_scale;Abc.prototype.set_sscale=set_sscale
  9789. 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
  9790. Abc.prototype.unlksym=unlksym;Abc.prototype.use_font=use_font;Abc.prototype.vskip=vskip
  9791. Abc.prototype.xy_str=xy_str;Abc.prototype.xygl=xygl}
  9792. var Abc=abc2svg.Abc
  9793. if(typeof module=='object'&&typeof exports=='object'){exports.abc2svg=abc2svg;exports.Abc=Abc}
  9794. if(!abc2svg.loadjs){abc2svg.loadjs=function(fn,onsuccess,onerror){if(onerror)
  9795. onerror(fn)}}
  9796. 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)
  9797. return user.errmsg
  9798. if(typeof abc2svg.printErr=='function')
  9799. return abc2svg.printErr
  9800. if(typeof alert=='function')
  9801. return function(m){alert(m)}
  9802. if(typeof console=='object')
  9803. return console.log
  9804. return function(){}}
  9805. function load_end(){if(--abc2svg.modules.nreq==0)
  9806. abc2svg.modules.cbf()}
  9807. var m,i,fn,nreq_i=this.nreq,ls=file.match(/(^|\n)(%%|I:).+?\b/g)
  9808. if(!ls)
  9809. return true
  9810. this.cbf=relay||function(){}
  9811. this.errmsg=errmsg||get_errmsg()
  9812. for(i=0;i<ls.length;i++){fn=ls[i].replace(/\n?(%%|I:)/,'')
  9813. m=abc2svg.modules[fn]
  9814. if(!m||m.loaded)
  9815. continue
  9816. m.loaded=true
  9817. if(m.fn)
  9818. fn=m.fn
  9819. this.nreq++
  9820. abc2svg.loadjs(fn+"-1.js",load_end,function(){abc2svg.modules.errmsg('Error loading the module '+fn)
  9821. load_end()})}
  9822. return this.nreq==nreq_i}}
  9823. abc2svg.version="v1.22.9-23-02f440d127";abc2svg.vdate="2023-08-30"