{ Initialize "() { AddToPluginsMenu('Convert Score to Lilypond','Run'); }" Run "() { //Sibelius.MessageBox('sib2ly - This could take a while...'); // sib2ly.plg - A Sibelius to Lilypond converter plugin // by Matthew Scott - http://mjs-svc.com - 2009 // Jeroen van Veldhuizen // This code is licensed under a Creative Commons 3.0 License: // (CC) -BY- // The license is available at the following URL: // http://creativecommons.org/licenses/by/3.0/ // Done: pitches, durations, time signatures, keys, clefs // barlines, most text, most lines, progress bar, basic tuplets // basic grouping // Todo: nested tuplets, repeat barlines, text, lyrics, some lines, symbols // voices, percussion staves, staff grouping/brackets/braces // To install, follow the directions at the following URL: // http://www.sibelius.com/download/plugins/index.html?help=install score = Sibelius.ActiveScore; _lyFile = score.FileName & '.ly'; // Set some stuff first... _lyDurations = CreateHash(); _lyDurations[Long] = '\\longa'; _lyDurations[Breve] = '\\breve'; _lyDurations[DottedBreve] = '\\breve.'; _lyDurations[Whole] = '1'; _lyDurations[DottedWhole] = '1.'; _lyDurations[DottedWhole+Quarter] = '1..'; _lyDurations[Half] = '2'; _lyDurations[DottedHalf] = '2.'; _lyDurations[DottedHalf+Eighth] = '2..'; _lyDurations[Quarter] = '4'; _lyDurations[DottedQuarter] = '4.'; _lyDurations[DottedQuarter+Sixteenth] = '4..'; _lyDurations[Eighth] = '8'; _lyDurations[DottedEighth] = '8.'; _lyDurations[DottedEighth+ThirtySecond] = '8..'; _lyDurations[Sixteenth] = '16'; _lyDurations[DottedSixteenth] = '16.'; _lyDurations[DottedSixteenth+SixtyFourth] = '16..'; _lyDurations[ThirtySecond] = '32'; _lyDurations[DottedThirtySecond] = '32.'; _lyDurations[SixtyFourth] = '64'; _lyDurations[DottedSixtyFourth] = '64.'; _lyDurations[OneHundredTwentyEighth] = '128'; _lyDurations[DottedOneHundredTwentyEighth] = '128.'; _lyBarlines = CreateArray(); _lyBarlines[SpecialBarlineStartRepeat] = '|:'; _lyBarlines[SpecialBarlineEndRepeat] = ':|'; _lyBarlines[SpecialBarlineDashed] = ':'; _lyBarlines[SpecialBarlineDouble] = '||'; _lyBarlines[SpecialBarlineFinal] = '|.'; _lyDynamics = CreateHash(); _lyDynamics['ppppp']='x'; _lyDynamics['pppp']='x'; _lyDynamics['ppp']='true'; _lyDynamics['pp']='true'; _lyDynamics['p']='true'; _lyDynamics['mp']='true'; _lyDynamics['mf']='true'; _lyDynamics['f']='true'; _lyDynamics['ff']='true'; _lyDynamics['fff']='true'; _lyDynamics['ffff']='true'; _lyDynamics['sf']='true'; _lyDynamics['fp']='true'; _lyDynamics['sff']='true'; _lyDynamics['sp']='true'; _lyDynamics['spp']='true'; _lyDynamics['sfz']='true'; _lyDynamics['rfz']='true'; _lyNrOfTuplets = 0; _lyProgress = 0; Sibelius.CreateTextFile(_lyFile); //Sibelius.ShowDialog(TemplateSelect, Self); // if there is more than one staff, select grouping if (not score.IsDynamicPart) { //Sibelius.ShowDialog(GroupingSelect, Self); _lyGenerateParts = Sibelius.YesNoMessageBox('Generate parts?'); } else { _lyGenerateParts = False; } //Trace('generate parts: ' & _lyGenerateParts); lyScore(score); Sibelius.MessageBox('Done!');}" lyDuration "(note) { //Trace('last duration: ' & _lyLastDuration); duration = note.Duration; voice = note.VoiceNumber; if (duration = _lyLastDuration[voice]) { return ''; } else { _lyLastDuration[voice] = duration; return _lyDurations[duration]; }}" lyPitch "(note,checkOctave) { // Begin with the note name staff = note.ParentBar.ParentStaff; if (utils.Pos('unpitched', note.ParentBar.ParentStaff.InitialStyleId) >=0 and not ( utils.Pos('1line', staff.InitialStyleId) > 0 or staff.InitialStyleId = 'instrument.unpitched.drums.snare' or staff.InitialStyleId = 'instrument.unpitched.tambourine' or staff.InitialStyleId = 'instrument.unpitched.drums.cymbal' )) { return lyPercussionPitch(note); } toReturn = utils.LowerCase(Substring(note.Name, 0, 1)); // Add accidental suffixes switch (note.Accidental) { case (Sharp) { toReturn = toReturn & 'is'; } case (DoubleSharp) { toReturn = toReturn & 'isis'; } case (Flat) { switch (toReturn) { case 'e' {toReturn = toReturn & 's'; } case 'a' {toReturn = toReturn & 's'; } default {toReturn = toReturn & 'es'; } } } case (DoubleFlat) { switch (toReturn) { case 'e' {toReturn = toReturn & 'ses'; } case 'a' {toReturn = toReturn & 'ses'; } default {toReturn = toReturn & 'eses'; } } } } // Check to see if we need to add a leap modifier voice = note.VoiceNumber; diff = utils.AbsoluteValue(_lyLastPitch[voice] - note.DiatonicPitch); if (diff > 3) { leap = ''; //Trace('diff: ' & diff & ' leap size: ' & RoundDown((diff - 4) / 7)); // subtract 4 because with a fourth, we do not jump. then ranges of octaves start switch (RoundDown((diff - 4) / 7)) { // Seriously? Yeesh... case (0) { if (_lyLastPitch[voice] > note.DiatonicPitch) { leap = ','; } else { leap = Chr(39); } } case (1) { if (_lyLastPitch[voice] > note.DiatonicPitch) { leap = ',,'; } else { leap = Chr(39) & Chr(39); } } case (2) { if (_lyLastPitch[voice] > note.DiatonicPitch) { leap = ',,,'; } else { leap = Chr(39) & Chr(39) & Chr(39); } } case (3) { if (_lyLastPitch[voice] > note.DiatonicPitch) { leap = ',,,,'; } else { leap = Chr(39) & Chr(39) & Chr(39) & Chr(39); } } case (4) { if (_lyLastPitch[voice] > note.DiatonicPitch) { leap = ',,,,,'; } else { leap = Chr(39) & Chr(39) & Chr(39) & Chr(39) & Chr(39); } } } toReturn = toReturn & leap; } // Set _lyLastPitch for the next time around _lyLastPitch[voice] = note.DiatonicPitch; if (checkOctave = 'true') { // extract the exact octave toReturn = toReturn & '=' ; octaveNum = RoundDown(note.DiatonicPitch/7); //Trace('doing octavecheck in octave: ' & octaveNum); switch(octaveNum) { case (0) { toReturn = toReturn & ',,,,'; } case (1) { toReturn = toReturn & ',,,'; } case (2) { toReturn = toReturn & ',,'; } case (3) { toReturn = toReturn & ','; } case (4) { toReturn = toReturn & ''; } case (5) { toReturn = toReturn & Chr(39); } case (6) { toReturn = toReturn & Chr(39)& Chr(39); } case (7) { toReturn = toReturn & Chr(39)& Chr(39)& Chr(39); } case (8) { toReturn = toReturn & Chr(39)& Chr(39)& Chr(39)& Chr(39); } case (9) { toReturn = toReturn & Chr(39)& Chr(39)& Chr(39)& Chr(39)& Chr(39); } case (10) { toReturn = toReturn & Chr(39)& Chr(39)& Chr(39)& Chr(39)& Chr(39)& Chr(39); } } //Trace('toReturn is now: ' & toReturn); } // Return return toReturn;}" _lyLastPitch "35" { "45" "42" "38" "35" "35" } lyNoteRest "(n, vars) { toReturn = ''; tuplet = n.ParentTupletIfAny; doCheck = vars.checkOctave; //if (doCheck) { Trace('octave check on'); } // close tuplet tupletOn = vars.tupletInVoice[n.VoiceNumber]; if (tupletOn = true and tuplet = null) { //Trace('tuplet count close: ' & _lyNrOfTuplets); vars.tupletInVoice[n.VoiceNumber] = null; toReturn = toReturn & '}'; } switch (n.NoteCount) { case (0) { //Trace('duration rest: ' & n.Duration); expr = 'r'; if (n.Hidden) {expr = 's'; } toReturn = toReturn & expr & lyDuration(n) & lyArticulations(n) & lyHandleLines(n,vars) & lyHandleMarkup(vars); } case (1) { if (n.GraceNote) { if (vars.graceOn = false) { toReturn = toReturn & lyGrace(n); vars.graceOn = true; } } else { if (vars.graceOn) { toReturn = toReturn & ']}'; vars.graceOn = false; vars.graceBracketOn = false; // check } } if (n.CueSize) { toReturn = toReturn & '\\once\\override NoteHead #'&Chr(39)&'font-size = #-4 '; } //Trace('duration single note: ' & n.Duration); // check notehead if (not vars.percussion and n.Lowest.NoteStyle != NormalNoteStyle) { toReturn = toReturn & lyNotehead(n.Lowest.NoteStyle); } toReturn = toReturn & lyPitch(n[0], doCheck) & lyDuration(n) & lyArticulations(n) & lyHandleLines(n,vars) & lyHandleMarkup(vars); if (n[0].Tied) { toReturn = toReturn & '~'; } if (n.GraceNote and not vars.graceBracketOn) { toReturn = toReturn & '['; vars.graceBracketOn = true; } } default { //Trace('duration chord: ' & n.Duration); if (n.GraceNote) { //Trace('grace. writing start: ' & vars.graceOn); if (vars.graceOn = false) { toReturn = toReturn & lyGrace(n); vars.graceOn = true; } } else { if (vars.graceOn) { toReturn = toReturn & ']}'; vars.graceOn = false; vars.graceBracketOn = false; } } if (n.CueSize) { toReturn = toReturn & '\\once\\override NoteHead #'&Chr(39)&'font-size = #-4 '; } toReturn = toReturn & '<'; firstNoteOfChord = true; pitchOfFirstNote = 0; for each note in n { if (firstNoteOfChord = true) { // and not note.GraceNote) { pitchOfFirstNote = note.DiatonicPitch; firstNoteOfChord = false; } // notehead cannot be altered in chord // do check on harmonics //if (not vars.percussion and note.NoteStyle != NormalNoteStyle) { // toReturn = toReturn & lyNotehead(note.NoteStyle); //} toReturn = toReturn & ' ' & lyPitch(note, doCheck); // check on harmonics if (note.NoteStyle = DiamondNoteStyle) { toReturn = toReturn & '\\harmonic '; } if (note.Tied) { toReturn = toReturn & '~'; } } toReturn = toReturn & '>' & lyDuration(n) & lyArticulations(n) & lyHandleLines(n,vars) & lyHandleMarkup(vars); if (n.GraceNote and not vars.graceBracketOn) { toReturn = toReturn & '['; vars.graceBracketOn = true; } _lyLastPitch[n.VoiceNumber] = pitchOfFirstNote; } } // close tuplet tupletOn = vars.tupletInVoice[n.VoiceNumber]; if (tupletOn = true) { // check tuplet duration tupletFilled = vars.tupletInVoiceFilled[n.VoiceNumber]; tupletFilled = tupletFilled - n.Duration; vars.tupletInVoiceFilled[n.VoiceNumber] = tupletFilled; //_lyTupletFilled = _lyTupletFilled - n.Duration; //Trace('checking tuplet closure. Time remaining: ' & _lyTupletFilled); if (tupletFilled <=0) { //Trace('closing tuplet'); vars.tupletInVoice[n.VoiceNumber] = null; //_lyNrOfTuplets = _lyNrOfTuplets - 1; toReturn = toReturn & '}'; } //Trace('tuplet count close: ' & _lyNrOfTuplets); } if (n.NoteCount > 0 and doCheck = 'true') { vars.checkOctave='false'; } return toReturn & ' ';}" _lyLastDuration "0" { "256" "512" "256" "0" "0" } _lyDurations { "128" "128." "64" "64." "32" "32." "16" "16." "16.." "8" "8." "8.." "4" "4." "4.." "2" "2." "2.." "1" "1." "1.." "\breve" "\breve." "\longa" } lyScore "(score, file) { writeln('\\version ' & Chr(34) & '2.14.2' & Chr(34)); writeln(''); score.TransposingScore = True; // open progress window numbars = score.StaffCount * score.SystemStaff.BarCount; Sibelius.CreateProgressDialog('Converting score to Lilypond...', 0, numbars); staves = CreateSparseArray(); i = 0; lyrics = CreateSparseArray(); lyrics._property:new = null; if (score.IsDynamicPart) { // Trace('processing one part'); for each staff in score { if (i<26) { staves[i] = 'staff' & Chr(i + 65); } else { staves[i] = 'staffA' & Chr(i - 26 + 65); } lyStaff(staves[i], staff, lyrics); if (lyrics.new != null) { lyrics = lyrics.Concat(lyrics.new); Trace('found lyrics: ' & lyrics.Join()); } i = i + 1; } } else { // Trace('Processing full score'); fullScore = null; //loop through staves and get the dynamic part for each partstaff in score { lyrics._property:new = null; rightPart = null; //Trace('checking staff: ' & partstaff.InstrumentName); j=0; for each part in score.DynamicParts { //Trace('checking against part: ' & j); //Trace('checking staff: ' & partstaff.InstrumentName); if (not part.IsFullScore) { for each checkstaff in part { if (checkstaff.InstrumentName = partstaff.InstrumentName) { //Trace('found!'); rightPart = part; } } } j=j+1; } // we have found the right part, now go on score.CurrentDynamicPart = rightPart; //Sibelius.ShowDynamicPart(rightPart); for each staff in Sibelius.ActiveScore { if (i<26) { staves[i] = 'staff' & Chr(i + 65); } else { staves[i] = 'staffA' & Chr(i - 26 + 65); } lyStaff(staves[i], staff, lyrics); if (lyrics.new != null) { lyrics = lyrics.Concat(lyrics.new); Trace('found lyrics: ' & lyrics.Join()); } i = i + 1; } } // return to full score //Sibelius.Close(); //Trace('closed part'); score.CurrentDynamicPart = score.DynamicParts[0]; Sibelius.ActiveScore = score.DynamicParts[0]; //score = fullScore.ParentScore; //Sibelius.ShowDynamicPart(score.DynamicParts[0]); } //Trace('lyrics: ' & lyrics.Join()); writeScore(score, staves, lyrics); if (_lyGenerateParts and not score.IsDynamicPart) { generateParts(score, staves, lyrics); } Sibelius.DestroyProgressDialog();}" _lyFile "/Users/jeroen/Documents/Barneveld/Maart 2012/Boos.sib.ly" writeln "(text) { // somehow unicode does not work correctly Sibelius.AppendLineToFile(_lyFile, text, True); }" write "(text) { // somehow unicode does not work correctly Sibelius.AppendTextFile(_lyFile, text, True); }" lyStaff "(name, staff, lyrics) { _lyLastPitch[1] = '35'; _lyLastPitch[2] = '35'; _lyLastPitch[3] = '35'; _lyLastPitch[4] = '35'; _lyLastDuration[1] = '0'; _lyLastDuration[2] = '0'; _lyLastDuration[3] = '0'; _lyLastDuration[4] = '0'; _lyNrOfTuplets = '0'; instrument = staff.InitialInstrumentType; percussion = false; write(name & ' = ' & lyTransposition(instrument, null)); if (utils.Pos('unpitched', staff.InitialStyleId) >= 0) { if (utils.Pos('1line', staff.InitialStyleId) > 0 or staff.InitialStyleId = 'instrument.unpitched.drums.snare' or staff.InitialStyleId = 'instrument.unpitched.tambourine' or staff.InitialStyleId = 'instrument.unpitched.drums.cymbal') { writeln(' \\relative c' & Chr(39) & ' {'); writeln(' \\override MultiMeasureRest #' & Chr(39) & 'staff-position = #0.01'); } else { write(' \\context DrumVoice = '&Chr(34)& '4' &Chr(34)&' {'); write(' \\context DrumVoice = '&Chr(34)& '3' &Chr(34)&' {'); write(' \\context DrumVoice = '&Chr(34)& '2' &Chr(34)&' {'); write(' \\context DrumVoice = '&Chr(34)& '1' &Chr(34)&' {'); writeln(' \\drummode {'); percussion = true; } } else { writeln(' \\relative c' & Chr(39) & ' {'); } writeln(' \\override MultiMeasureRest #'& Chr(39) &'expand-limit = 1'); writeln(' \\set Staff.instrumentName = \\markup{' & lyProcessText(null,staff.FullInstrumentNameWithFormatting) & '}'); writeln(' \\set Staff.shortInstrumentName = \\markup{' & lyProcessText(null,staff.ShortInstrumentNameWithFormatting)& '}'); writeln(' \\compressFullBarRests'); writeln(' \\set countPercentRepeats = ##t'); writeln(' \\set repeatCountVisibility = #(every-nth-repeat-count-visible 4)'); writeln(' #(set-accidental-style ' & Chr(39) & 'modern-cautionary)'); writeln(' \\override Hairpin #' & Chr(39) & 'minimum-length = #5'); //writeln(lyTransposition(instrument)); switch (staff.InitialClefStyleId) { case('clef.treble') { writeln(' \\clef treble'); } case('clef.bass') { writeln(' \\clef bass'); } case('clef.percussion') { writeln(' \\clef percussion'); } default { Trace('unknown clef style: ' & staff.InitialClefStyleId); } } writeln(' ' & lyTimeSignature(Sibelius.ActiveScore.SystemStaff.CurrentTimeSignature(1))); vars = staff; vars._property:lines = CreateSparseArray(); vars._property:lineStarted = CreateSparseArray(); vars._property:textItems = CreateSparseArray(); vars._property:systemBarItems = CreateSparseArray(); vars._property:tupletInVoice = CreateSparseArray(); vars._property:tupletInVoiceFilled = CreateSparseArray(); vars._property:lastSystemItemsPos = 0; vars._property:systemTextItemsHandled = false; vars._property:multiRestCount = 0; vars._property:percussion = percussion; vars._property:graceOn = false; vars._property:graceBracketOn = false; vars._property:checkOctave = 'false'; vars._property:barRepeatOn = false; vars._property:closeBarRepeatOnBar = 0; vars._property:containsLyrics = false; vars._property:lyricVerses = CreateSparseArray(); vars._property:staffName = name; vars._property:lyricBlockClosed = false; _lyInstrumentChangeInPart = 'false'; if (not percussion) { writeln(' ' & lyKeySignature(staff.InitialKeySignature, vars)); } for each bar in staff { write(' '); vars.systemTextItemsHandled = false; lyBar(bar, vars); _lyProgress = _lyProgress + 1; result = Sibelius.UpdateProgressDialog(_lyProgress, 'staff: ' & staff.InstrumentName & ' bar: ' & bar.BarNumber); if (result = false) { StopPlugin('Lilypond conversion cancelled'); } }; if (percussion) { write('}}}}'); } if (_lyInstrumentChangeInPart = 'true') { write('}'); _lyInstrumentChangeInPart = 'false'; } if (vars.lyricVerses.Length > 0 and not vars.lyricBlockClosed) { //for i = 0 to vars.lyricVerses.Length { write('}'); //} } writeln('}'); writeln(''); if (vars.containsLyrics) { thislyrics = processLyrics(staff, name, vars); //Trace('in staff: lyrics: ' & thislyrics.Join()); lyrics.new = lyrics.Concat(thislyrics); //Trace('lyrics is now: ' & lyrics.Join()); } else { lyrics.new = null; }}" lyBar "(bar, vars) { systemStaff = bar.ParentStaff.ParentScore.SystemStaff; // reset durations _lyLastDuration[1] = '0'; _lyLastDuration[2] = '0'; _lyLastDuration[3] = '0'; _lyLastDuration[4] = '0'; // reset system items vars.systemBarItems = CreateSparseArray(); vars.lastSystemItemsPos = 0; // check start repeats etc systemBar = systemStaff.NthBar(bar.BarNumber); for each SpecialBarline barline in systemBar { if (barline.Position = 0) { //Trace('barline. type: ' & barline.Type & ' position: ' & barline.Position); write(lyBarline(barline, vars)); } } //Trace('bar: ' & bar.BarNumber & ' breaktype: ' & bar.BreakType & ' sb: ' & systemBar.BreakType); for each SystemSymbolItem item in systemBar { // check start of codasystem e.d. if (item.Index = CodaSymbol) { //Trace('start of coda found, bar: ' & bar.BarNumber); lyWriteCoda(bar); } } // check RepeatTimeLines for each RepeatTimeLine object in systemBar { //Trace('repeat line: ' & object.Type); write(lyRepeatTimeLine(object)); } // check time signature timesig = systemStaff.CurrentTimeSignature(bar.BarNumber); if (bar.BarNumber = 1) { _lyLastTimeSignature = timesig.Text; } if (timesig.Text != _lyLastTimeSignature and bar.BarNumber > 1) { _lyLastTimeSignature = timesig.Text; write(lyTimeSignature(timesig)); } // system markup write(lyHandleSystemMarkup(bar, vars, 0)); voiceArray = CreateSparseArray(); //Trace('bar: ' & bar.ExternalBarNumber); voiceobj=CreateArray(); // check bar repeats checkBarRepeats(bar, vars); // handle all items in a bar // including system items on position? eigenlijk moeten die worden samengevoegd. // completeBar = lyMergeBarObjects(bar); oldPos = 0; for each obj in bar{ // check system items, put them on voice 1 if (obj.Type = 'NoteRest' and oldPos > 0) { voiceArray[1] = voiceArray[1] & lyHandleSystemMarkup(bar, vars, oldPos); } //Trace('object: ' & obj.Type); func = 'ly' & obj.Type; // stack in voice // if there are more than one voice filled, render correctly if (voiceobj[obj.VoiceNumber] != 'true' and obj.Type = 'NoteRest') { voiceobj[obj.VoiceNumber] = 'true'; vars._property:checkOctave = 'true'; //} else { // vars._property:checkOctave = 'false'; } result = @func(obj,vars); // check voice // voice 0 things are put in voice 1 if (obj.VoiceNumber = 0) { //Trace(result); voiceArray[1] = voiceArray[1] & result; } else { // if first note in voice, then do an octave check voiceArray[obj.VoiceNumber] = voiceArray[obj.VoiceNumber] & result; } result = ''; oldPos = obj.Position; } // check remaining system items voiceArray[1] = voiceArray[1] & lyHandleSystemMarkup(bar, vars, 99999); // now write out the voices //Trace('bar: ' & bar.BarNumber & ' array length: ' & voiceArray.Length); if (voiceArray.Length <= 2) { if (voiceArray.Length = 2) { // single voice, no polyphony //Trace('Writing single voice: ' & voiceArray[1]); // remove [ ] brackets voiceArray[1] = utils.Replace(voiceArray[1], '[ ]', '', True); write(voiceArray[1]); voiceArray[1]=null; } } else { write(' <<'); for i=1 to 4 { // remove [ ] brackets voiceArray[i] = utils.Replace(voiceArray[i], '[ ]', '', True); if (voiceArray[i] != null) { write('{' & voiceArray[i] & '}'); } if (voiceArray[i+1] != null) { write(' \\\\ '); } voiceArray[i]=null; } write(' >> \\oneVoice '); // also reset duration, because it gets confused //Trace('resetting duration for voicing'); //_lyLastDuration = 0; } // check end of tuplets while (_lyNrOfTuplets > 0) { write('}'); _lyNrOfTuplets = _lyNrOfTuplets - 1; } // check end of endings if (_lyCloseEnding = 'true') { write(' }} ' ); _lyCloseEnding = 'false'; } // check barline barlineCount = 0; for each SpecialBarline barline in systemBar { if (barline.Position > 0) { //Trace('barline. type: ' & barline.Type & ' position: ' & barline.Position); write(lyBarline(barline, vars) & Chr(37) & bar.ExternalBarNumberString); barlineCount = barlineCount + 1; } } // when this is the start/middle of a multi-measure rest, do not print anything if (bar.InMultirest = NoMultirest or bar.InMultirest = EndsMultirest) { if (barlineCount = 0) {write(' | ' & Chr(37) & bar.ExternalBarNumberString);} writeln(''); } }" lyClef "(obj) { switch (obj.StyleId) { case ('clef.treble') { return '\\clef treble '; } case ('clef.tenor') { return '\\clef tenor '; } case ('clef.bass') { return '\\clef bass '; } case ('clef.percussion') { return '\\clef percussion '; } default { Trace ('unknown clef: ' & obj.StyleId); } }}" lySpecialBarline "(obj) { barlines = CreateArray(); barlines[SpecialBarlineStartRepeat] = '|:'; barlines[SpecialBarlinesEndRepeat] = ':|'; barlines[SpecialBarlinesDashed] = ':'; barlines[SpecialBarlinesDouble] = '||'; barlines[SpecialBarlinesFinal] = '|.'; return '\\bar ' & Chr(34) & barlines[obj.BarlineInternalType] & Chr(34) & ' ';}" lyTimeSignature "(obj) { //Sibelius.MessageBox('time signature change to ' & obj.Numerator & '/' & obj.Denominator); return '\\time ' & obj.Numerator & '/' & obj.Denominator & ' ';}" lyKeySignature "(obj, vars) { returnValue = '' ; if (vars.percussion) { return returnValue; } if (obj.Major) { majors = CreateHash(); majors['-7'] = 'ces'; majors['-6'] = 'ges'; majors['-5'] = 'des'; majors['-4'] = 'as'; majors['-3'] = 'es'; majors['-2'] = 'bes'; majors['-1'] = 'f'; majors['0'] = 'c'; majors['1'] = 'g'; majors['2'] = 'd'; majors['3'] = 'a'; majors['4'] = 'e'; majors['5'] = 'b'; majors['6'] = 'fis'; majors['7'] = 'cis'; returnValue = '\\key ' & majors[obj.Sharps] & ' \\major '; } else { minors = CreateHash(); minors['-7'] = 'as'; minors['-6'] = 'es'; minors['-5'] = 'bes'; minors['-4'] = 'f'; minors['-3'] = 'c'; minors['-2'] = 'g'; minors['-1'] = 'd'; minors['0'] = 'a'; minors['1'] = 'e'; minors['2'] = 'b'; minors['3'] = 'fis'; minors['4'] = 'cis'; minors['5'] = 'gis'; minors['6'] = 'dis'; minors['7'] = 'ais'; returnValue = '\\key ' & minors[obj.Sharps] & ' \\minor '; } //Trace(returnValue); return returnValue;}" lyLine "(obj, vars) { //Trace('line type: ' & obj.Type & ' bar: ' & obj.ParentBar.BarNumber); if (obj.Duration > 0) { vars.lines.Push(obj); vars.lineStarted.Push(obj); } return '';}" lyArpeggioLine "(obj) { if (obj.Duration > 0) { vars.lines.Push(obj); vars.lineStarted.Push(obj); } return '';}" lyCrescendoLine "(obj, vars) { if (obj.Duration > 0) { vars.lines.Push(obj); vars.lineStarted.Push(obj); } return '';}" lyDiminuendoLine "(obj, vars) { if (obj.Duration > 0) { vars.lines.Push(obj); vars.lineStarted.Push(obj); } return '';}" lyGlissandoLine "(obj, vars) { //vars.lines.Push(obj); //Trace('GlissandoLine not implemented'); // put down immediately return '\\glissando ';}" lyOctavaLine "(obj, vars) { toReturn = ''; if (obj.Duration > 0) { vars.lines.Push(obj); //vars.lineStarted.Push(obj); // put down immediately toReturn = '\\ottava #1 '; currentClef = obj.ParentBar.GetClefAt(0); if (currentClef.StyleId = 'clef.treble') { toReturn = toReturn & '\\set Staff.middleCPosition = #-6 '; } if (currentClef.StyleId = 'clef.bass') { toReturn = toReturn & '\\set Staff.middleCPosition = #6 '; } } return toReturn;}" lyPedalLine "(obj, vars) { // write sustain style if necessary toReturn = ''; if (vars._property:sustainWritten != true) { toReturn = '\\set Staff.pedalSustainStyle = #' & Chr(39) & 'mixed '; vars._property:sustainWritten = true; } if (obj.Duration > 0) { vars.lines.Push(obj); vars.lineStarted.Push(obj); } return toReturn;}" lyRepeatTimeLine "(obj) { returnValue = ''; //Trace('Linestyle: ' & obj.StyleId); switch(obj.StyleId) { case ('line.system.repeat.1st') { returnValue = '} \\alternative {{'; } case ('line.system.repeat.2nd') { returnValue = '{'; _lyCloseEnding = 'true'; } default { Trace('Repeat timeline not implemented: ' & obj.StyleId); } } return returnValue;}" lySlur "(obj, vars) { if (obj.Duration > 0) { vars.lines.Push(obj); vars.lineStarted.Push(obj); } return '';}" lyTrill "(obj, vars) { //if (obj.Duration > 0) { vars.lines.Push(obj); vars.lineStarted.Push(obj); //} return '';}" lyBox "(obj) { return '';}" lyTuplet "(obj, vars) { // close old tuplet, nesting not yet supported toReturn = ''; tupletOn = vars.tupletInVoice[obj.VoiceNumber]; if (tupletOn = true) { toReturn = '} '; } toReturn = toReturn & '\\times ' & obj.Right & '/' & obj.Left & ' { '; vars.tupletInVoice[obj.VoiceNumber] = true; vars.tupletInVoiceFilled[obj.VoiceNumber] = obj.PlayedDuration * obj.Left / obj.Right; return toReturn;}" lyRitardLine "(obj, bar) { Trace('RitardLine not implemented'); return '';}" lyLyricItem "(obj, vars) { //Trace('bar: ' & obj.ParentBar.BarNumber & ' lyric: ' & obj.Text); vars.containsLyrics = true; toReturn = ''; voiceName = ''; verse = utils.Replace(obj.StyleId,'text.staff.space.hypen.lyrics.', '', true); switch(verse) { case ('verse1') { if (vars.lyricVerses[1] != true) { vars.lyricVerses[1] = true; //voiceName = vars.staffName & 'Lyrics' & Chr(65); voiceName = vars.staffName & 'Lyrics'; } } case ('verse2') { if (vars.lyricVerses[2] != true) { vars.lyricVerses[2] = true; //voiceName = vars.staffName & 'Lyrics' & Chr(66); } } case ('verse3') { if (vars.lyricVerses[3] != true) { vars.lyricVerses[3] = true; //voiceName = vars.staffName & 'Lyrics' & Chr(67); } } case ('verse4') { if (vars.lyricVerses[4] != true) { vars.lyricVerses[4] = true; //voiceName = vars.staffName & 'Lyrics' & Chr(68); } } case ('verse5') { if (vars.lyricVerses[5] != true) { vars.lyricVerses[5] = true; //voiceName = vars.staffName & 'Lyrics' & Chr(69); } } case ('above') { if (vars.lyricVerses[6] != true) { vars.lyricVerses[6] = true; //voiceName = vars.staffName & 'LyricsAbove'; } } case ('chorus') { if (vars.lyricVerses[7] != true) { vars.lyricVerses[7] = true; //voiceName = vars.staffName & 'LyricsChorus'; } } } if (voiceName != '') { toReturn = '\\new Voice = ' & Chr(34) & voiceName & Chr(34) & ' {'; } return toReturn;}" lyText "(obj, bar) { toReturn = '' ; switch (obj.StyleId) { case 'text.staff.timesig.onestaffonly' { timesig = obj.Text; // split on newline timesigParts = SplitString(timesig); Trace('independent time signature not supported'); } default { // text with tilde is for playback, do not print if (obj.Hidden = False and obj.Text != '' and Substring(obj.Text,0,1) != '~') { bar.textItems.Push(obj); } } } return toReturn;}" lyGuitarFrame "(obj) { return '';}" lyTransposition "(instr, oldinstr) { //toReturn = ' \\transposition '; toReturn = ' \\transpose '; diff = 0; if (oldinstr = null) { diff = instr.DiatonicTransposition; } else { diff = instr.DiatonicTransposition - oldinstr.DiatonicTransposition; } switch (diff) { case(-1) { toReturn = toReturn & 'bes c' & Chr(39); } case(-4) { toReturn = toReturn & 'f c' & Chr(39); } case(-5) { toReturn = toReturn & 'es c' & Chr(39); } case(-7) { toReturn = toReturn & 'c c' & Chr(39); } case(-8) { toReturn = toReturn & 'bes, c' & Chr(39); } case(-12) { toReturn = toReturn & 'es, c' & Chr(39); } case(-15) { toReturn = toReturn & 'bes,, c' & Chr(39); } case(0) { toReturn = ''; } case(2) { toReturn = toReturn & 'es' & Chr(39) & ' c' & Chr(39); } case(7) { toReturn = toReturn & 'c' & Chr(39) & Chr(39) & ' c' & Chr(39); } case(14) { toReturn = toReturn & 'c' & Chr(39) & Chr(39) & Chr(39) & ' c' & Chr(39); } default { Trace('unhandled transposition: ' & instr.DiatonicTransposition); } } //Sibelius.MessageBox(toReturn); return toReturn;}" lyInstrumentChange "(obj, vars) { toReturn = ''; //Trace('instrument change: bar: ' & obj.ParentBar.BarNumber & ' to: ' & obj.StyleId); // look up instrument instrChange = null; for each instr in obj.ParentBar.ParentStaff.ParentScore.InstrumentTypes { //Trace(instr.StyleId); if (instr.StyleId = obj.StyleId) { instrChange = instr; } } if (_lyInstrumentChangeInPart = 'true') { toReturn = '} '; } oldinstr = obj.ParentBar.ParentStaff.InitialInstrumentType; toReturn = toReturn & lyTransposition(instrChange, oldinstr) & ' \\relative c' & Chr(39) & ' {'; _lyInstrumentChangeInPart = 'true'; // turn on octave check for next note vars.checkOctave = 'true'; vars.textItems.Push(obj); return toReturn;}" lyBarRest "(obj, vars) { toReturn = ''; if (obj.RestType = WholeBarRest) { //restDuration = lyDuration(obj.ParentBar.Length); restDuration = 1; // construct length based on time sig switch (obj.ParentBar.Length) { case(1024) { // 4/4 restDuration = '1'; } case(1920) { // 15/8 restDuration = '1*15/8'; } case(1280) { // 5/4 restDuration = '1*5/4'; } case(1152) { // 9/8 restDuration = '1*9/8'; } case(768) { // 3/4, 6/8 restDuration = '2.'; } case(512) { // 2/4 restDuration = '2'; } default { Trace('Unsupported full bar rest of length: ' & obj.ParentBar.Length); } } restMark = ' R'; if (obj.Hidden) { restMark = ' s'; } toReturn = toReturn & restMark & restDuration; //& lyHandleLines(obj,vars) //& lyHandleMarkup(vars); } // check multiRest switch (obj.ParentBar.InMultirest) { case (StartsMultirest) { vars.multiRestCount = 1; toReturn = ''; } case (MidMultirest) { vars.multiRestCount = vars.multiRestCount + 1; toReturn = ''; } case (EndsMultirest) { vars.multiRestCount = vars.multiRestCount + 1; toReturn = toReturn & '*' & vars.multiRestCount; vars.multiRestCount = 0; toReturn = toReturn & lyHandleLines(obj,vars) & lyHandleMarkup(vars); } case (NoMultirest) { toReturn = toReturn & lyHandleLines(obj,vars) & lyHandleMarkup(vars); } } if ( not obj.ParentBar.InMultirest) { toReturn = toReturn & lyHandleLines(obj,vars); } // check if barrest part of barrepeat if (obj.ParentBar.BarNumber > 1) { previousBar = obj.ParentBar.ParentStaff[obj.ParentBar.BarNumber - 1]; for each BarRest br in previousBar { if (br.RestType = TwoBarRepeat) { toReturn = ''; } } } _lyLastDuration[1] = '0'; _lyLastDuration[2] = '0'; _lyLastDuration[3] = '0'; _lyLastDuration[4] = '0'; return toReturn;}" lyGraphic "(obj) { return '';}" lyBarline "(obj, vars) { // check for repeat starts and ends returnValue = '' ; //Trace(obj.BarlineInternalType); switch (obj.BarlineInternalType) { case (SpecialBarlineStartRepeat) { returnValue = '\\repeat volta 2 { ' ; _lyVoltaStarted = 'true'; } case (SpecialBarlineEndRepeat) { if (_lyVoltaStarted = 'true') { returnValue = ' } ' ; _lyVoltaStarted = 'false'; if (vars.lyricVerses.Length > 0 and not vars.lyricBlockClosed) { returnValue = returnValue & '}'; vars.lyricBlockClosed = true; } } else { returnValue = '\\bar ' & Chr(34) & _lyBarlines[obj.BarlineInternalType] & Chr(34) & ' '; } } default { returnValue = '\\bar ' & Chr(34) & _lyBarlines[obj.BarlineInternalType] & Chr(34) & ' '; } } return returnValue;}" TemplateSelect "Dialog" { Controls { RadioButton { Title "Choir" X "30" Y "37" Width "67" Height "15" StartGroup "0" Value "_lyChoirTly" Method SetFocus "0" } RadioButton { Title "Piano" X "30" Y "54" Width "66" Height "16" StartGroup "0" Value "_lyPianoTly" Method SetFocus "0" } Button { Title "Use this template" X "29" Y "76" Width "66" Height "16" DefaultButton "0" Value Method SetFocus "0" EndDialog "1" } RadioButton { Title "None" X "30" Y "20" Width "67" Height "14" StartGroup "1" Value "_lyNoTly" Method SetFocus "0" } } Title "Select Template..." X "363" Y "249" Width "127" Height "115" } _lyChoirTly "false" _lyPianoTly "false" _lyNoTly "true" lyGrace "(note) { toReturn = ''; if (note.IsAcciaccatura) { toReturn = ' \\acciaccatura { '; } else { if (note.IsAppoggiatura) { toReturn = ' \\appoggiatura { '; } else { toReturn = ' \\grace { '; }} return toReturn; }" _lyNrOfTuplets "0" _lyTupletFilled "0" _lyLastTimeSignature "4\n\4" _lyBarlines { "|:" ":|" ":" "||" "|." } lyArticulations "(note) { toReturn = ''; if (note.NoteCount = 0) { if (note.GetArticulation(SquarePauseArtic)) {toReturn = toReturn & '\\longfermata';} if (note.GetArticulation(PauseArtic)) {toReturn = toReturn & '\\fermata';} if (note.GetArticulation(TriPauseArtic)) {toReturn = toReturn & '\\shortfermata';} } else { if (note.GetArticulation(Custom1Artic)) {toReturn = toReturn & '';} if (note.GetArticulation(StaccatoArtic)) {toReturn = toReturn & '-.';} if (note.GetArticulation(StaccatissimoArtic)) {toReturn = toReturn & '-|';} if (note.GetArticulation(WedgeArtic)) {toReturn = toReturn & '';} if (note.GetArticulation(TenutoArtic)) {toReturn = toReturn & '--';} if (note.GetArticulation(AccentArtic)) {toReturn = toReturn & '->';} if (note.GetArticulation(MarcatoArtic)) {toReturn = toReturn & '-^';} if (note.GetArticulation(HarmonicArtic)) {toReturn = toReturn & '\\flageolet';} if (note.GetArticulation(PlusArtic)) {toReturn = toReturn & '\\stopped';} if (note.GetArticulation(UpBowArtic)) {toReturn = toReturn & '\\upbow';} if (note.GetArticulation(DownBowArtic)) {toReturn = toReturn & '\\downbow';} if (note.GetArticulation(SquarePauseArtic)) {toReturn = toReturn & '\\longfermata';} if (note.GetArticulation(PauseArtic)) {toReturn = toReturn & '\\fermata';} if (note.GetArticulation(TriPauseArtic)) {toReturn = toReturn & '\\shortfermata';} if (note.GetArticulation(Custom3Artic)) {toReturn = toReturn & '';} if (note.ArpeggioType != ArpeggioTypeNone) {toReturn = toReturn & '\\arpeggio'; } if (note.SingleTremolos != 0) { if (note.Duration >= Quarter) { switch(note.SingleTremolos) { case(1) { toReturn = toReturn & ':8';} case(2) { toReturn = toReturn & ':16';} case(3) { toReturn = toReturn & ':32';} case(4) { toReturn = toReturn & ':64';} case(5) { toReturn = toReturn & ':128';} case(6) { toReturn = toReturn & ':256';} //case(0) {toReturn = toReturn & '';} default { Trace('Unhandled nr of tremolos: ' & note.SingleTremolos); } }} if (note.Duration >= Eighth and note.Duration < Quarter) { switch(note.SingleTremolos) { case(1) { toReturn = toReturn & ':16';} case(2) { toReturn = toReturn & ':32';} case(3) { toReturn = toReturn & ':64';} case(4) { toReturn = toReturn & ':128';} case(5) { toReturn = toReturn & ':256';} //case(6) { toReturn = toReturn & ':256';} //case(0) {toReturn = toReturn & '';} default { Trace('Unhandled nr of tremolos: ' & note.SingleTremolos); } }} if (note.Duration >= Sixteenth and note.Duration < Eighth) { switch(note.SingleTremolos) { case(1) { toReturn = toReturn & ':32';} case(2) { toReturn = toReturn & ':64';} case(3) { toReturn = toReturn & ':128';} case(4) { toReturn = toReturn & ':256';} //case(5) { toReturn = toReturn & ':256';} //case(6) { toReturn = toReturn & ':256';} //case(0) {toReturn = toReturn & '';} default { Trace('Unhandled nr of tremolos: ' & note.SingleTremolos); } } } } } return toReturn;}" lyHandleMarkup "(vars) { // check if there are markups (text items) to handle toReturn = ''; while (vars.textItems.Length > 0) { textItem = vars.textItems.Pop(); if (textItem.Type = 'SymbolItem') { switch (textItem.Index) { case (225) { // staccato below toReturn = toReturn & '_.'; } case (233) { // upbow below toReturn = toReturn & '_\\upbow '; } case (234) { // downbow below toReturn = toReturn & '_\\downbow '; } } } else { if (textItem.Type != 'InstrumentChange' and textItem.Text != '' and textItem.Hidden = False) { switch (textItem.StyleId) { case 'text.staff.expression' { //Sibelius.MessageBox(textItem.Text & ' in array: ' & _lyDynamics[textItem.Text]); if (textItem.Text = 'ffff' or textItem.Text = 'fff' or textItem.Text = 'ff' or textItem.Text = 'f' or textItem.Text = 'mf' or textItem.Text = 'mp' or textItem.Text = 'p' or textItem.Text = 'pp' or textItem.Text = 'ppp' or textItem.Text = 'pppp' or textItem.Text = 'ppppp' or textItem.Text = 'fp' or textItem.Text = 'sf' or textItem.Text = 'sff' or textItem.Text = 'sp' or textItem.Text = 'spp' or textItem.Text = 'sfz' or textItem.Text = 'rfz') { toReturn = toReturn & '\\' & textItem.Text; } else { toReturn = toReturn & '_\\markup\\italic{' & lyProcessText(textItem)&'}'; } } case('text.staff.space.fingering') { // if longer than 1, then it contains special things if (textItem.Hidden = False) { if (Length(textItem.Text) > 1) { toReturn = toReturn & '^\\markup\\finger{ ' & textItem.Text & '}'; } else { toReturn = toReturn & '-' & textItem.TextWithFormattingAsString; }} } default { if (textItem.Hidden = False) { toReturn = toReturn & '^\\markup{' & lyProcessText(textItem) & '}'; } } }}} if (textItem.Type='InstrumentChange') { toReturn = toReturn & '^\\markup{' & lyProcessText(null, textItem.TextLabel) & '}'; } } return toReturn;}" lyHandleSystemMarkup "(bar, vars, pos) { toReturn = ''; markText = ''; containsSymbols = false; // collect all markups if (pos = 0) { systemBar = bar.ParentStaff.ParentScore.SystemStaff[bar.BarNumber]; for each SystemTextItem textItem in systemBar { vars.systemBarItems.Push(textItem); } for each SystemSymbolItem symItem in systemBar { vars.systemBarItems.Push(symItem); } for each RitardLine symLine in systemBar { toReturn = toReturn & '\\override TextSpanner #' &Chr(39) & '(bound-details left text) = ' &Chr(34) & symLine.StyleAsText & Chr(34) & ' ' ; //Trace('voice: ' & symLine.VoiceNumber); vars.lines.Push(symLine); vars.lineStarted.Push(symLine); } vars.lastSystemItemPos=0; } // handle items for pos for each i in vars.systemBarItems.ValidIndices { obj = vars.systemBarItems[i]; //Trace('bar: ' & bar.BarNumber & ' obj type: ' & obj.Type & ' pos: ' & obj.Position & ' checkpos: ' & pos); if (obj.Position <= pos) { if (not obj.Hidden) { if (obj.Type = 'SystemTextItem') { //Trace('handling systemtext'); textItem = obj; if (textItem.Text != '') { text = lyProcessText(textItem); if (utils.Pos('glyph', text) >= 0) { containsSymbols = true; } switch (textItem.StyleId) { case 'text.system.tempo' { toReturn = toReturn & '\\tempo\\markup {' & text & '} '; } case 'text.system.repeat' { // codas, segnos etc markText = markText & text & ' '; //Trace('repeat found: ' & textItem.Text); } default { //Trace('unhandled markup type: ' & textItem.StyleId); toReturn = toReturn; } } } } if (obj.Type = 'SystemSymbolItem') { //Trace('handling system symbol'); containsSymbols = true; symItem = obj; switch(symItem.Index) { case SegnoSymbol { //toReturn = toReturn & '\\once \\override Score.RehearsalMark #'&Chr(39)&'self-alignment-X = #right '; markText = markText & '\\musicglyph #' & Chr(34) & 'scripts.segno' & Chr(34) & ' '; } case CodaSymbol { //toReturn = toReturn & '\\once \\override Score.RehearsalMark #'&Chr(39)&'self-alignment-X = #right '; markText = markText & '\\musicglyph #' & Chr(34) & 'scripts.coda' & Chr(34) & ' '; } default { Trace('systemsymbolitem found, index: ' + symItem.index); } } } } // item has now been handled, so remove from array vars.systemBarItems[i] = null; } } // check for rehearsal marks if (pos = 0) { for each RehearsalMark mark in systemBar { markText = markText & '\\box\\bold ' & Chr(34) & mark.MarkAsText & Chr(34) & ' '; } } if (markText != '') { align = '\\once \\override Score.RehearsalMark #'&Chr(39)&'self-alignment-X = #'; if (pos = 0 or containsSymbols = true) { align = align & 'center '; } else { align = align & 'right '; } toReturn = align&'\\mark\\markup\\column\\center-align{' & markText & '} ' & toReturn; } return toReturn;}" lyHandleLines "(note, vars) { // check end of lines toReturn = ''; toReturn = toReturn & lyHandleLineStop(note,vars,true); // check start of lines wrongLines = CreateSparseArray(); while (vars.lineStarted.Length > 0) { obj = vars.lineStarted.Pop(); //Trace('Starting: ' & obj.Type & ' in voice: ' & obj.VoiceNumber); // check voice of line if (obj.VoiceNumber != note.VoiceNumber and obj.VoiceNumber > 0) { wrongLines.Push(obj); } else { switch (obj.Type) { case 'CrescendoLine' { toReturn = toReturn & '\\<'; } case 'DiminuendoLine' { toReturn = toReturn & '\\>'; } case 'RitardLine' { toReturn = toReturn & '\\startTextSpan'; } case 'Slur' { if (obj.VoiceNumber = 1) { toReturn = toReturn & '\\('; } else { toReturn = toReturn & '('; } } case 'Trill' { if (obj.Duration > 0) { toReturn = toReturn & '\\startTrillSpan '; } else { toReturn = toReturn & '\\trill '; } } case 'PedalLine' { toReturn = toReturn & '\\sustainOn '; } case 'ArpeggioLine' { toReturn = toReturn & '\\arpeggio '; } case 'GlissandoLine' { toReturn = toReturn & '\\glissando '; } case 'SymbolItem' { //Trace('handling symbolitem as line'); if (obj.Index = TrillSymbol) { //Trace('handling trill symbol'); toReturn = toReturn & '\\trill '; } } case 'OctavaLine' { // how many octaves up or down? // mark already put down toReturn = toReturn; } default { //Trace('unhandled line: ' & obj.Type); toReturn = toReturn & '\\override TextSpanner #' &Chr(39) & '(bound-details left text) = ' &Chr(34) & Chr(34) & ' ' ; toReturn = toReturn & '\\startTextSpan '; } }} } vars.lineStarted = wrongLines; // in case this is a one-note line, it needs to be stopped also and // removed from the other array toReturn = toReturn & lyHandleLineStop(note,vars,false); //if (toReturn != '') { // Trace('line result: ' & toReturn); //} return toReturn;}" lyHandleLineStop "(note,vars,noteStart) { toReturn = ''; // check end of lines // get list of active line items //if (vars.lines.Length > 0) { // Trace('checking line stops for start=' & noteStart); //} for i=0 to vars.lines.Length { obj = vars.lines[i]; // check if this object has been started. If not, it will // be done in the second pass (after object starts) // for now, only check the last started object lastObj = null; if (noteStart = true and vars.lineStarted.Length > 0) { lastObj = vars.lineStarted.Pop(); //Trace('executed pop to check'); } if (obj != null and (note.VoiceNumber = obj.VoiceNumber or (note.VoiceNumber = 1 and obj.VoiceNumber = 0)) and (lastObj = null or (not(lastObj.Type = obj.Type and lastObj.ParentBar.BarNumber = obj.ParentBar.BarNumber and lastObj.Position = obj.Position and lastObj.Duration = obj.Duration)))) { measure = note.ParentBar.BarNumber; //position = note.Position + note.Duration; position = note.Position; //Trace('checking on measure/pos: ' & measure & ':' & position & ' object: ' & obj.Type & ' endmeasure: ' & obj.EndBarNumber & ' endpos: ' & obj.EndPosition); if (measure > obj.EndBarNumber or (measure = obj.EndBarNumber and position >= obj.EndPosition)) { // this is the end of a line item //Trace('Stopping: ' & obj.Type); // some items may only be stopped on a noteStart, such as ottava keep = False; switch (obj.Type) { case 'CrescendoLine' { toReturn = toReturn & '\\!'; } case 'DiminuendoLine' { toReturn = toReturn & '\\!'; } case 'RitardLine' { toReturn = toReturn & '\\stopTextSpan'; } case 'Slur' { if (obj.VoiceNumber = 1) { toReturn = toReturn & '\\)'; } else { toReturn = toReturn & ')'; } } case 'Trill' { if (obj.Duration > 0) {toReturn = toReturn & '\\stopTrillSpan ';} } case 'PedalLine' { toReturn = toReturn & '\\sustainOff '; } case 'OctavaLine' { if (noteStart = False) { toReturn = toReturn & ' \\ottava #0 '; } else { keep = True; } } default { //Trace('stopping unhandled line: ' & obj.Type); toReturn = toReturn & ' \\stopTextSpan '; } } // clear from array if (not keep) { vars.lines[i] = null; } } // end length check // } else { // Trace('skipping object, not started yet'); } // end skip if (lastObj != null) { vars.lineStarted.Push(lastObj); //Trace('executed push'); } } return toReturn;}" lySymbolItem "(obj, vars) { toReturn = ''; switch (obj.Index) { case (CommaSymbol) { toReturn = '\\breathe '; } case (TrillSymbol) { //vars.lines.Push(obj); vars.lineStarted.Push(obj); //Trace('trill pushed'); //toReturn = '\\trill '; } case (225) { // staccato below //toReturn = '_.'; vars.textItems.Push(obj); } case (233) { // upbow below //toReturn = '_\\upbow '; vars.textItems.Push(obj); } case (234) { // downbow below //toReturn = '_\\downbow '; vars.textItems.Push(obj); } default { Trace('symbolitem found, index: ' & obj.Index & ' bar: ' & obj.ParentBar.BarNumber); } } return toReturn;}" GroupingSelect "Dialog" { Title "Select grouping" X "579" Y "297" Width "122" Height "125" Controls { Text { Title "Select grouping:" X "11" Y "2" Width "66" Height "15" RightAlign "0" Value Method SetFocus "0" } RadioButton { Title "None" X "13" Y "18" Width "67" Height "13" StartGroup "1" Value "_lyGroupingNone" Method SetFocus "0" } RadioButton { Title "All" X "13" Y "31" Width "67" Height "12" StartGroup "0" Value "_lyGroupingAll" Method SetFocus "0" } RadioButton { Title "Band style" X "13" Y "43" Width "67" Height "12" StartGroup "0" Value "_lyGroupingBand" Method SetFocus "0" } CheckBox { Title "Generate parts" X "65" Y "18" Width "67" Height "12" StartGroup "0" Value "_lyGenerateParts" Method SetFocus "0" } Button { Title "OK" X "20" Y "68" Width "67" Height "12" DefaultButton "0" Value Method SetFocus "0" EndDialog "1" } } } _lyGroupingNone "false" _lyGroupingAll "false" _lyGroupingBand "true" lyScoreBand "(score,staves) { // check if a staff family exists, create families // groupings: // 1) flutes & double reed // 2) clarinets // 3) saxes // 4) trumpets/cornets/flugels // 5) horns // 6) trombones // 7) euphonium/basses/strings // 8) piano // 9) timpani // 10) percussion // create an array with group starts. // If an instrument belongs to a new group, then add the number. // Some groups can be joined if they contain only one staff. // If a group contains one staff and cannot be joined, then // no grouping is needed. groupStarts = CreateSparseArray(); // for i = 0 to staves.NumChildren { staff = score[i]; instrument = staff.InitialStyleId; if (i=0) { groupStarts.Push(i); } else { // check agains previous and next staff familyThis = lyScoreInstrumentBandFamily(instrument); familyPrevious = lyScoreInstrumentBandFamily(score[i-1].InitialStyleId); if (familyThis != familyPrevious) { //Trace('start of new family: ' & familyThis); groupStarts.Push(i); } } } // evaluate starters groupCounter = 0; writeln(' <<'); writeln(' \\set Score.markFormatter = #format-mark-box-letters'); writeln(' \\set Score.skipBars = ##t'); for i = 0 to staves.NumChildren { // check start of new group if (i = groupStarts[groupCounter]) { // write end of group if (groupCounter > 0) { writeln(' >>'); } writeln(' \\new StaffGroup << '); groupCounter = groupCounter + 1; } writeln(' \\new ' & lyStaffType(score[i],false) & ' \\' & staves[i]); } if (groupStarts.Length > 1) { writeln(' >>'); } writeln(' >>'); }" lyScoreInstrumentBandFamily "(instr) { toReturn = ''; instrParts = SplitString(instr, '.'); //Trace('checking part: ' & instrParts[2]); instrName = instrParts[2]; switch (instrName) { case 'piccolo' { toReturn = 'flutedoublereed'; } case 'flute' { toReturn = 'flutedoublereed'; } case 'oboe' { toReturn = 'flutedoublereed'; } case 'coranglais' { toReturn = 'flutedoublereed'; } case 'englishhorn' { toReturn = 'flutedoublereed'; } case 'bassoon' { toReturn = 'flutedoublereed'; } case 'clarinet' { toReturn = 'clarinet'; } case 'saxophone' { toReturn = 'saxophone'; } case 'trumpet' { toReturn = 'trumpet'; } //case 'flugelhorn' { toReturn = 'trumpet'; } case 'horn' { toReturn = 'horn'; } case 'trombone' { toReturn = 'trombone'; } case 'euphonium' { toReturn = 'euphonium'; } case 'drums' { toReturn = 'drums'; } default { if (instrParts[1] = 'pitchedpercussion') { toReturn = 'pitchedpercussion'; } else { Trace('unknown instrument, gets own family: ' & instr); toReturn = instrName; } } } return toReturn;}" lyStaffType "(staff, forparts) { toReturn = ''; instrument = staff.InitialStyleId; instrParts = SplitString(instrument, '.'); pitching = instrParts[1]; pageTurner = ''; if (forparts) { pageTurner = '\\consists '&Chr(34)&'Page_turn_engraver'&Chr(34); } instrumentWriter = ''; if (forparts) { instrumentWriter = ' \\remove '&Chr(34)&'Instrument_name_engraver'&Chr(34); } switch (pitching) { case 'unpitched' { if (utils.Pos('1line', staff.InitialStyleId) > 0 or staff.InitialStyleId = 'instrument.unpitched.drums.snare' or staff.InitialStyleId = 'instrument.unpitched.tambourine' or staff.InitialStyleId = 'instrument.unpitched.drums.cymbal') { toReturn = 'RhythmicStaff \\with {'; //toReturn = toReturn & ' \\override StaffSymbol #'&Chr(39)&'line-count = #1 '; //toReturn = toReturn & ' \\override BarLine #'&Chr(39)&'bar-size = #2 '; toReturn = toReturn & ' drumStyleTable = #percussion-style '; } else { toReturn = 'DrumStaff \\with {'; toReturn = toReturn & ' drumStyleTable = #drums-style '; } toReturn = toReturn & pageTurner & instrumentWriter; toReturn = toReturn & '}'; } default { toReturn = 'Staff \\with { ' & pageTurner & instrumentWriter & '}' ; } } return toReturn;}" _lyCloseEnding "false" lyOctaveCheck "(note) { returnValue = '\\octave '; // extract note&pitch // Begin with the note name toReturn = utils.LowerCase(Substring(note.Name, 0, 1)); // Add accidental suffixes switch (note.Accidental) { case (Sharp) { toReturn = toReturn & 'is'; } case (DoubleSharp) { toReturn = toReturn & 'isis'; } case (Flat) { switch (toReturn) { case 'e' {toReturn = toReturn & 's'; } case 'a' {toReturn = toReturn & 's'; } default {toReturn = toReturn & 'es'; } } } case (DoubleFlat) { switch (toReturn) { case 'e' {toReturn = toReturn & 'ses'; } case 'a' {toReturn = toReturn & 'ses'; } default {toReturn = toReturn & 'eses'; } } } } // Check to see if we need to add a leap modifier voice = note.VoiceNumber; diff = utils.AbsoluteValue(_lyLastPitch[voice] - note.DiatonicPitch); if (diff > 3) { leap = ''; //Trace('diff: ' & diff & ' leap size: ' & RoundDown((diff - 3) / 7)); // subtract 4 because with a fourth, we do not jump. then ranges of octaves start switch (RoundDown((diff - 4) / 7)) { // Seriously? Yeesh... case (0) { if (_lyLastPitch > note.DiatonicPitch) { leap = ','; } else { leap = Chr(39); } } case (1) { if (_lyLastPitch > note.DiatonicPitch) { leap = ',,'; } else { leap = Chr(39) & Chr(39); } } case (2) { if (_lyLastPitch > note.DiatonicPitch) { leap = ',,,'; } else { leap = Chr(39) & Chr(39) & Chr(39); } } case (3) { if (_lyLastPitch > note.DiatonicPitch) { leap = ',,,,'; } else { leap = Chr(39) & Chr(39) & Chr(39) & Chr(39); } } case (4) { if (_lyLastPitch > note.DiatonicPitch) { leap = ',,,,,'; } else { leap = Chr(39) & Chr(39) & Chr(39) & Chr(39) & Chr(39); } } } toReturn = toReturn & leap; } // Set _lyLastPitch for the next time around _lyLastPitch[voice] = note.DiatonicPitch; // Return return toReturn; return returnValue;}" _lyVoltaStarted "false" lyNotehead "(notehead) { toReturn = ''; helper = '\\once \\override NoteHead #' & Chr(39) & 'style = #' & Chr(39) ; switch(notehead) { case(CrossNoteStyle) { toReturn = helper & 'cross ' ; } case(DiamondNoteStyle) { toReturn = helper & 'harmonic ' ; } default { Trace('unimplemented notehead: ' & notehead); } } return toReturn;}" lyProcessText "(textitem, textContents) { toReturn = ''; if (textitem != null) { items = textitem.TextWithFormatting; } else { items = CreateSparseArray(); //Trace(textContents); pos = utils.Pos('\\', textContents); rest = textContents; i=0; while (pos >= 0) { //Trace('rest: ' & rest); part = Substring(rest, 0, pos); if (pos = 0) { // start of format format = Substring(rest, 1); pos = utils.Pos('\\', format); items[i] = '\\' & Substring(format, 0, pos) & '\\'; rest = Substring(format, pos+1); } else { items[i] = part; rest = Substring(rest, pos); } //Trace('part: ' & items[i]); i=i+1; pos = utils.Pos('\\', rest); } // handle remainder items[i] = rest; //Trace(items[i]); } closeCount = 0; symbolOn = false; //Trace(textitem.TextWithFormattingAsString); i=0; item = items[i]; while (item != '') { //Trace('processing: ' & item); // if item starts with a slash it is formatting, else it is normal text if (utils.Pos('\\', item) < 0) { if (symbolOn = false) { //Trace('adding: ' & Chr(34) & item & Chr(34)); toReturn = toReturn & Chr(34) & item & Chr(34); } else { //Trace('symbolitem asc: ' & Asc(item)); switch(item) { case('b') { toReturn=toReturn & '\\teeny\\flat ' ; } case('e') { toReturn=toReturn & '\\teeny\\note #' & Chr(34) & '8' & Chr(34) & ' #1 ' ; } case('q.') { toReturn=toReturn & '\\teeny\\note #' & Chr(34) & '4.' & Chr(34) & ' #1 ' ; } case('q') { toReturn=toReturn & '\\teeny\\note #' & Chr(34) & '4' & Chr(34) & ' #1 ' ; } case('h') { toReturn=toReturn & '\\teeny\\note #' & Chr(34) & '2' & Chr(34) & ' #1 ' ; } case('$') { toReturn=toReturn & '\\musicglyph #' & Chr(34) & 'scripts.segno' & Chr(34) & ' '; } case('ø') { toReturn=toReturn & '\\musicglyph #' & Chr(34) & 'scripts.coda' & Chr(34) & ' '; } case(Chr(216)) { toReturn=toReturn & '\\musicglyph #' & Chr(34) & 'scripts.coda' & Chr(34) & ' '; } case('sfz') { toReturn=toReturn & '\\dynamic ' & item & ' '; } case('ppp') { toReturn=toReturn & '\\dynamic ' & item & ' '; } case('pp') { toReturn=toReturn & '\\dynamic ' & item & ' '; } case('p') { toReturn=toReturn & '\\dynamic ' & item & ' '; } case('mp') { toReturn=toReturn & '\\dynamic ' & item & ' '; } case('mf') { toReturn=toReturn & '\\dynamic ' & item & ' '; } case('f') { toReturn=toReturn & '\\dynamic ' & item & ' '; } case('ff') { toReturn=toReturn & '\\dynamic ' & item & ' '; } case('fff') { toReturn=toReturn & '\\dynamic ' & item & ' '; } case('rfz') { toReturn=toReturn & '\\dynamic ' & item & ' '; } case('sf') { toReturn=toReturn & '\\dynamic ' & item & ' '; } default { if (textitem != null) { Trace('unimplemented symbol, trying dynamic: ' & item & ' - ascii: - ' & Asc(item) & ' - bar: ' & textitem.ParentBar.BarNumber); } else { Trace('unimplemented symbol, trying dynamic: ' & item & ' - ascii: - ' & Asc(item)); } toReturn=toReturn & '\\dynamic ' & item & ' '; } } } } else { format = utils.Replace(item,'\\','',true); switch (format) { case('I') { toReturn = toReturn & '\\italic{' ; closeCount = closeCount + 1; } case('i') { if (closeCount > 0) { toReturn = toReturn & '}' ; closeCount = closeCount - 1; } } case('B') { toReturn = toReturn & '\\bold{' ; closeCount = closeCount + 1; } case('b') { if (closeCount > 0) { toReturn = toReturn & '}' ; closeCount = closeCount - 1; } } case('fOpus Text') { symbolOn = true; } case('fHelsinki Text') { symbolOn = true; } case('s') { //ignoring font size toReturn = toReturn; } case('f_') { symbolOn = false; } case('$') { // ignoring templates such as title, arranger etc toReturn = toReturn; } case('n') { // ignoring page number toReturn = toReturn; } default { Trace('unimplemented format: ' & format); } } } i = i + 1; item = items[i]; //Trace('closecount: ' & closeCount); } // close any leftover braces if (closeCount > 0) { for i = 0 to closeCount { toReturn = toReturn & '}'; } } //Trace('returning: ' & toReturn); return toReturn & ' ' ;}" lyPercussionPitch "(note) { toReturn = ''; // translate pitch to percussion notation pitch = note.DiatonicPitch; head = note.NoteStyle; switch(pitch) { case(37) { toReturn = 'bd'; } case(38) { toReturn = 'bd'; } case(39) { toReturn = 'tomfl'; } case(40) { toReturn = 'tomfh'; } case(41) { toReturn = 'tamb'; } case(42) { toReturn = 'sn'; } case(43) { toReturn = 'tomml'; } case(44) { toReturn = 'tommh'; } case(45) { if (head = CrossNoteStyle) { toReturn = 'cymr'; } else { toReturn = 'tomh'; } } case(46) { if (head = DiamondNoteStyle) { toReturn = 'hho'; } else { toReturn = 'hh'; } } case(47) { if (head = ShapedNote1NoteStyle) { toReturn = 'tri'; } else { toReturn = 'cymc'; } } default { Trace('unimplemented percussion pitch: ' & pitch) ; } } return toReturn;}" lyWriteCoda "(bar) { // if in part, then do a line break and skip. // if in score, only break up writeln('% coda'); writeln(' \\cadenzaOn \\stopStaff s1*3 \\startStaff \\cadenzaOff'); writeln(' \\cadenzaOn s8 \\bar '& Chr(34) & Chr(34) & ' \\cadenzaOff '); writeln(' \\once \\override Staff.KeySignature #'&Chr(39)&'break-visibility = #end-of-line-invisible'); writeln(' \\once \\override Staff.Clef #'&Chr(39)&'break-visibility = #end-of-line-invisible'); write(' ');}" _lyInstrumentChangeInPart "false" _lyGenerateParts "false" generateParts "(score, staves, lyrics) { // loop over the dynamic parts and create a score for them //Trace('generating parts. num of staves: ' & staves.Length); //writeln('\\book {'); for i=0 to staves.Length { writeln('\\book {'); // find correct part rightPart = null; for each part in score.DynamicParts { if (not part.IsFullScore) { for each checkstaff in part { if (checkstaff.InstrumentName = score[i].InstrumentName) { rightPart = part; } } } } score.CurrentDynamicPart = rightPart; partname = utils.Replace(score.PartName, '^b', '\\flat', true); partname = utils.Replace(partname, '\\n\\', ', ', true); writeln(' \\bookOutputSuffix ' & Chr(34) & partname & Chr(34)); if (i=0) { writePaper(Sibelius.ActiveScore); //writeHeader(Sibelius.ActiveScore); } //writeln('\\bookpart {'); writeHeader(Sibelius.ActiveScore); score.CurrentDynamicPart = score.DynamicParts[0]; // write the music writeln(' \\score { '); writeln(' <<'); writeln(' \\set Score.markFormatter = #format-mark-box-letters'); writeln(' \\set Score.skipBars = ##t'); writeln(' \\new ' & lyStaffType(score[i],true) & ' \\' & staves[i]); // check for lyric staves for each index in lyrics.ValidIndices { // check blockName = lyrics[index]; //Trace('found lyricblock: ' & blockName); if (utils.Pos(staves[i], blockName) >= 0) { // found a correct block writeln(' \\new Lyrics \\lyricsto ' & Chr(34) & staves[i] & 'Lyrics' & Chr(34) & ' \\' & blockName ); } } writeln(' >>'); writeln(' } % end score'); // writeln(' \\paper {'); // writeln(' #(define page-breaking ly:page-turn-breaking)'); // writeln(' noindent=##t'); // writeln(' indent=0\\mm'); // writeln(' } % end paper'); // writeln('} % end bookpart'); writeln('} % end book'); writeln(''); } //writeln('} % end book'); }" writeScore "(score, staves, lyrics) { // write out score using staff groupings brackets = score.BracketsAndBraces; if (not score.IsDynamicPart) { writeln('#(set-global-staff-size ' & RoundDown(score.StaffHeight / 0.3526667) & ')'); } else { writeln('#(set-global-staff-size 19)'); } writeln(''); writeln('\\book {'); writePaper(score); writeHeader(score); writeln('\\score { '); writeln(' <<'); // per bracket or per staff? for i=0 to staves.Length { // check if there is a start of a stave for each bracket in brackets { if (bracket.TopStaveNum-1 = i) { // start a new bracket if (bracket.BracketType = BracketBrace) { writeln(' \\new GrandStaff { <<'); } else { writeln(' \\new StaffGroup { <<'); if (bracket.BracketType = BracketSub) { writeln(' \\set StaffGroup.systemStartDelimiter = #' & Chr(39) & 'SystemStartSquare'); } } } } // write out this stave writeln(' \\new ' & lyStaffType(score[i],score.IsDynamicPart) & ' \\' & staves[i]); // check for lyric staves for each index in lyrics.ValidIndices { // check blockName = lyrics[index]; //Trace('found lyricblock: ' & blockName); if (utils.Pos(staves[i], blockName) >= 0) { // found a correct block //Trace('matched block: ' & blockName & ' against staff: ' & staves[i]); writeln(' \\new Lyrics \\lyricsto ' & Chr(34) & staves[i] & 'Lyrics' & Chr(34) & ' \\' & blockName ); lyrics[index] = null; } } for each bracket in brackets { if (bracket.BottomStaveNum-1 = i) { // end this bracket writeln(' >> } % end bracket'); } } // if there is a staff, check if it must be ended } writeln(' >>'); // for score we need a layout block here writeln(' \\layout {'); writeln(' indent = 2 \\cm'); writeln(' short-indent = 1 \\cm'); writeln(' }'); writeln('} % end score'); writeln('} % end book'); writeln(''); }" writeHeader "(score) { partname = utils.Replace(score.PartName, '^b', '\\flat', true); partname = utils.Replace(partname, '\\n\\', ', ', true); composer = utils.Replace(score.Composer, '\\n\\', '} \\line { ', true); writeln('\\header {'); writeln(' title = ' & Chr(34) & score.Title & Chr(34)); writeln(' subtitle = ' & Chr(34) & score.Subtitle & Chr(34)); writeln(' composer = \\markup\\bold\\large\\column\\right-align{\\line{' & composer & '}}'); if (score.Arranger != '') { writeln(' arranger = ' & Chr(34) & 'arr. ' & score.Arranger & Chr(34)); } writeln(' instrument = \\markup{' & partname & '}'); writeln(' copyright = ' & Chr(34) & score.Copyright & Chr(34)); writeln('}'); writeln(''); }" writePaper "(score) { // check some common paper sizes paper = score.ScoreHeight & 'x' & score.ScoreWidth; papersize = ''; switch (paper) { case '297x210' { papersize=Chr(34)&'a4'&Chr(34); } case '420x297' { papersize=Chr(34)&'a3'&Chr(34); } case '210x297' { papersize=Chr(34)&'a4'&Chr(34)&' '&Chr(39)&'landscape'; } case '297x420' { papersize=Chr(34)&'a3'&Chr(34)&' '&Chr(39)&'landscape'; } default { Trace('unimplemented paper size: ' & paper); } } //writeln('#(set-default-paper-size ' & papersize & ')'); writeln('\\paper {'); writeln(' #(set-paper-size ' & papersize & ')'); if (not score.IsDynamicPart) { // adjust left margin (default 10mm) for instr names writeln(' ragged-last-bottom=##f'); writeln(' system-separator-markup = \\slashSeparator'); writeln(' myStaffSize = #' & RoundDown(score.StaffHeight / 0.3526667)); } else { writeln(' #(define page-breaking ly:page-turn-breaking)'); writeln(' noindent=##t'); writeln(' indent=0\\mm'); // headermarkup niet meer nodig: iedere part zijn eigen file //writeln(' oddHeaderMarkup = \\markup \\fill-line { ' & Chr(34) & ' ' & Chr(34) & ' } '); //writeln(' evenHeaderMarkup = \\markup \\fill-line { ' & Chr(34) & ' ' & Chr(34) & ' } '); writeln(' myStaffSize = #19'); } writeln(' #(define fonts'); writeln(' (make-pango-font-tree ' & Chr(34) & 'Georgia' & Chr(34)); writeln(' ' & Chr(34) & 'Verdana' & Chr(34)); writeln(' ' & Chr(34) & 'Lucida Typewriter' & Chr(34)); writeln(' (/ myStaffSize 20)))'); writeln('}'); writeln(''); }" _lyProgress "558" checkBarRepeats "(bar, vars) { // check if next bar, or bar after that, is a repeat repeatOn = vars.barRepeatOn; lastBarnum = bar.ParentStaff.BarCount; //Trace('checking bar: ' & bar.BarNumber& ' barcount: ' & bar.ParentStaff.BarCount); if (bar.BarNumber+1 = bar.ParentStaff.BarCount) {return ''; } foundrepeat = false; count = 0; if (bar.BarNumber < (lastBarnum -1)) { nextBar = bar.ParentStaff[bar.BarNumber + 1]; for each BarRest br in nextBar { if (br.RestType = OneBarRepeat) { foundrepeat = true; // look for end of repeat (repeat count) count = 2; repeatOn = true; while (repeatOn = true) { //Trace('checking bar: ' & (bar.BarNumber + count)); checkBar = bar.ParentStaff[bar.BarNumber + count]; vars.closeBarRepeatOnBar = checkBar.BarNumber - 1; repeatOn = false; for each BarRest br in checkBar { if (br.RestType = OneBarRepeat) { count = count + 1; repeatOn = true; } } //Trace('repeatOn = ' & repeatOn); } } }} if (bar.BarNumber < (lastBarnum -2)) { next2Bar = bar.ParentStaff[bar.BarNumber + 2]; for each BarRest br in next2Bar { if (br.RestType = TwoBarRepeat) { foundrepeat = true; // look for end of repeat (repeat count) count = 2; repeatOn = true; while (repeatOn = true) { //Trace('checking bar: ' & (bar.BarNumber + (count*2) )); checkBar = bar.ParentStaff[bar.BarNumber + (count*2) ]; vars.closeBarRepeatOnBar = checkBar.BarNumber - 1; repeatOn = false; for each BarRest br in checkBar { if (br.RestType = TwoBarRepeat) { count = count + 1; repeatOn = true; } } //Trace('repeatOn = ' & repeatOn); } } }} if (bar.BarNumber < (lastBarnum -4)) { next4Bar = bar.ParentStaff[bar.BarNumber + 4]; for each BarRest br in next4Bar { if (br.RestType = FourBarRepeat) { foundrepeat = true; } }} if (foundrepeat and not vars.barRepeatOn) { writeln(' \\repeat ' & Chr(34) & 'percent' & Chr(34) & ' ' & count & ' {'); vars._property:barRepeatOn = True; //vars.barRepeatStarted = False; } // check if a barrest has passed. close on last barrest if (vars.barRepeatOn = True and bar.BarNumber = vars.closeBarRepeatOnBar) { writeln(' }'); vars.barRepeatOn = False; return ''; } return '';}" processLyrics "(staff, staffname, vars) { //Trace('processing lyrics'); toReturn = CreateSparseArray(); for i = 1 to 8 { if (vars.lyricVerses[i] = true) { checkverse = ''; blockname = staffname & 'Lyrics'; if (i<6){ checkverse = 'verse' & i; blockname = blockname & Chr(i+64); } if (i=6) { checkverse = 'above'; blockname = blockname & 'Above'; } if (i=7) { checkverse = 'chorus'; blockname = blockname & 'Chorus'; } toReturn.Push(blockname); writeln(blockname &' = \\lyricmode {'); for each bar in staff { linefound = false; for each LyricItem lyric in bar { verse = utils.Replace(lyric.StyleId, 'text.staff.space.hypen.lyrics.', '', true); if (verse = checkverse) { //Trace('lyrics styleID: ' & lyric.StyleId); write(lyric.Text & ' ' ) ; if (lyric.SyllableType = MiddleOfWord) { write('-- ');} linefound = true; // check lyric length: look for corresponding noterest if (lyric.NumNotes > 1) { Trace('long lyric: ' & lyric.Text & ' numnotes: ' & lyric.NumNotes); } if (lyric.NumNotes > 1) { nextNote = lyric.NextItem(lyric.VoiceNumber, 'NoteRest'); if (nextNote[0].Tied = true) { if (lyric.NumNotes > 2 and nextNote.NextItem(lyric.VoiceNumber, 'NoteRest')[0].Tied = True) { start = 3; } else { start = 2; } } else { start = 1; } for j = start to lyric.NumNotes { write('_ '); } } } } if (linefound) {writeln('');} } writeln('}'); } } //} //Trace('returning from lyrics: ' & toReturn.Join()); return toReturn;}" lyBend "(note, vars) { toReturn = ''; }" }