//!Mup-Arkkra
// lpd's definitions used by many different mup score files, 2nd iteration.

// $Id: lpddefs2.mup,v 1.48 2014-01-22 00:51:09 lpd Exp $

// Copyright (c) 2011, 2014 L Peter Deutsch.  All rights reserved.

ifndef LPDDEFS2_INCLUDED		// suppress multiple inclusion
define LPDDEFS2_INCLUDED @

// Defaults for specific composer
ifndef COMPOSER_  define COMPOSER_ "L Peter Deutsch"            @  endif
ifndef CONTACT_   define CONTACT_  "http://www.major2nd.com/ae" @  endif
// Break up the e-mail to mitigate harvesting from the Web.
ifndef EMAIL1_    define EMAIL1_   "aemusic"                    @  endif
ifndef EMAIL2_    define EMAIL2_   "major2nd.com"               @  endif
ifndef CP_YEAR_   define CP_YEAR_  "2014"                       @  endif

// ****** MANY DEFOCTS NOT INSERTED YET ******
// ****** CHECK SAX DEFOCTS ******
// ****** SOME TL_ NOT INSERTED YET ******

// Command line options:
//   -D ANON for an anonymous score (no author name).
//   -D BINDING for a score that will be bound (wider margins -- eventually,
//	 on the left on odd-numbered pages, right on even-numbered).
//   -D CLEAN for a clean score (no analysis).
//   -D FIRSTPAGE=<pagenum> (for scores divided into multiple files).
//   -D NOX (no analysis).
//   -D PART=I_<instr> for a single instrument part.  (PART= takes precedence
//	over ALL_PARTS and CONCERT.)
//   -D PART_VOICE=1 or 2 for a single instrument part out of two on a staff.
//   -D PART_LABEL='"<label>"' to label a part differently.  (Both sets of
//	 quotes are required, unfortunately.)
//   -D ALL_PARTS for an orchestral score (all parts) at written 
//	(transposed) pitch.
//   -D CONCERT for an orchestral score (all parts) at concert pitch.
//   -D NOREPEATS to ignore repeats.
//   -D APART to force every part onto a separate staff (not implemented here,
//     a convention for use by score files).
//   -D NOHEADER to suppress header (e.g. for music examples).
//   -D NOFOOTER to suppress footer (ibid.)
//   -D NOLABELS to suppress staff and group labels (ibid.)
// Layout parameters:
//   -D SMALL for a smaller score.
//   -D PAD=<pad> to specify the 'pad' value.
//   -D SCALE=<scale> to specify the 'scale' value.
//   -D SCOREPAD=<scorepad> to specify the 'scorepad' value.
//   -D PARAMS='<param>=value; ...' to specify other parameter values.
//   -D DYNFONT=<font> to specify the font for dynamics, normally boldital
//      (can include a font name, e.g. bookman boldital).
//   -D DYNSIZE=<size> to specify the size adjustment for dynamics, normally
//      "+2" but can also be an absolute size.  The enclosing quotes are
//      required.
// Performance parameters:
//   -D RELNORM=<release> to specify the normal MIDI 'release' value
//   -D RELLEG=<release> to specify the legato MIDI 'release' value

// Scores may be written using either concert pitches or transposed pitches.
// Concert pitch is the default: if the file uses conventional written
// (transposed) pitches, it must define TRANSPOSED before including this file.
// Similarly, concert pitch is the default for printed output: a
// written-pitch score required -D ALL_PARTS.
// 
// Regardless of which way the file is written, -D ALL_PARTS always produces
// a transposed full score, and -D CONCERT always produces a concert-pitch
// full score.  (Parts are always produced transposed in the printed output
// and at concert pitch in MIDI files.)

// Each score should include this file at the beginning, before any other
//   definitions (except for definitions affecting the operation of this file,
//   as listed above.)
// The score should:
//	Define HEADER[2] and FOOTER[2] if desired.
//	Define COMPOSER, COMPOSER_CONTACT[2], COMPOSER_EMAIL{12},
//	  COPYRIGHT_STRING if desired.  (They default to the values COMPOSER_
//        etc. defined above.)
//	For all the instruments to be handled automatically (i.e.,
//        automatic generation of staff, clef, labels, and MIDI programs):
//	    define INSTRUMENTS\
//	    IS(<staff>,I_<name>)\ -- for one instrument on a staff
//	    ISV2(<staff>,I_<name>)\ -- for one instrument on a staff with
//	      two voices (e.g. string double stops)
//	    ISD(<staff>,I_<name>)\ -- for double instruments (1,2) on a staff
//	    IS2(<staff>,I_<name>,I_<name>)\ -- for two instruments on a staff
//	    @
//	  (The backslashes at the end of each line are necessary.)
//	  Staff numbers should be in ascending order.
//	  ISV2 is equivalent to IS with vscheme = 2f and vcombine = shareone.
//	  ISD is equivalent to ISV2 with a slightly different label.
//	    Note that for ISV2/ISD/IS2, both instruments or voices are
//	    mapped to MIDI channel <staff>.
//	For instruments *not* to be handled automatically:
//	    Use LABEL(lbl) or LABEL2(lbl,lbl2) (in staff context) for the
//	      staff labels.  (These are suppressed when generating parts.)
//	If desired, define INIT_MIDI or FIRST_MIDI as initial MIDI settings.
//	  Defining INIT_MIDI suppresses the automatic definition of MIDI
//	  program settings for defined instruments: to include both custom
//	  and automatic MIDI settings, define FIRST_MIDI instead.
//	If desired, define BEFORE_STAFFS to be executed before any settings
//	  that depend on the staffs being defined (e.g., to define the staffs
//	  if this can't be done at the beginning).
//	If desired, define BEFORE_MUSIC to be executed after the instruments
//	  are defined but before the first use of music context (e.g., to
//	  change default octaves or set score layout parameters).

// If the score is divided into multiple files, each file should include
// this one, then have a time signature and then BEGINMUSIC().
// The file can detect whether it is the first one (e.g., if an additional
// dynamic marking is needed for a partial score) by testing whether FIRST
// is defined, but it must always actually include this file.

// A common naming convention for multi-file pieces is to put all the shared
// definitions in <piece>0.mup, the sections in <piece>a.mup, <piece>b.mup,
// etc., with <piece>.mup including all the sections.  Section <piece><x>.mup
// should end with 'bar reh "<x>"'.

// Notes for specific instruments:
//	Woodwinds:
//	  Clarinets are in Bb by default.  CLARINET and CLARINET_1,2,3
//	    are available, also CLARINET_A and E_FLAT_CLARINET.  Bass
//	    clarinet has _TREBLE and _BASS like the horn.
//	Horn:
//	  Define CLEF_HORN as HORN_TREBLE or HORN_BASS to set the initial
//	    clef for the horn on a full score.  (The part is always treble.)
//	  HORN and HORN_1,2,3,4 are available.
//	  Note that the effective range of the horn is written C0 to E1
//	    (concert F-1 to A0): lower notes tend to sound weak and muddy.
//	Brass:
//	  TRUMPET, TRUMPET_1,2 (in Bb) and TRUMPET_C, _1_C, _2_C are available.
//	Percussion:
//	  Define VSCHEME_PERCUSSION to override the default of 1.
//	  Define LABEL[2]_PERCUSSION to override the default staff label(s).
//	  Define STAFF_PERCUSSION to override the default of "stafflines=5n".
//	Piano:
//	  Note that piano parts (I_PIANO_RH/LH) do not generate labels.
//	  Define VSCHEME_RH or VSCHEME_LH to override the default of 2f.
//	  If using an alternate VSCHEME that is not 1, also define
//	    PIANO_VOICES_RH/LH for that staff (e.g. as 1 1 & 1 2 & 1 3).
//	  Piano or organ scores with more than two staffs are not currently
//	    supported.
//	Harp:
//	  See above re piano, using VSCHEME_HARP_{R,L}H and HARP_VOICES_{R,L}H.
//	  For harp, the default vscheme is 1, not 2f, and HARP_VOICES_{R,L}H
//	    is required if defining VSCHEME_HARP_{R,L}H.
//	Strings:
//	  Define CLEF_VIOLA as VIOLA_TREBLE or VIOLA_ALTO, or CLEF_CELLO as
//	    CELLO_TREBLE, CELLO_TENOR, or CELLO_BASS, to set the initial clef
//	    for the viola or cello (on both full score and part).
//	  VIOLIN, VIOLIN_I, and VIOLIN_II are available.
//	  Use the macros PIZZ[N], ARCO[N] for pizzicato/arco.
//	  (PIZZ2 and ARCO2 are obsolete synonyms for PIZZN and ARCON.)
//	  Cello notes above A0 are only recommended for professional players.
//	Voices:
//	  define DEFOCT_TENOR to override the default octave for tenor (3).

undef FIRST
define FIRST @				// first file (if multiple files)

define IF_FIRST(IFX) ifdef FIRST IFX endif @
define IF_NOTFIRST(IFX) ifndef FIRST IFX endif @

ifdef PART undef APART define APART @ endif
ifdef MIDI undef APART define APART @ endif

// ---------------- Score hygiene ---------------- //

// Shrink the score a bit (scale = 0.7); leave plenty of space for dynamics
// between parts and between systems (staffsep = 24, except for piano where
// staffsep = 10).

// Indent the first system 1/2" or so (newscore leftmargin = 0.75).

// Get rid of tonal analysis on circulated scores (-D NOX).

// Use 8th 4tr 8th rather than 8th 8th~8th 8th, except when crossing the
// middle of the bar.
// When appropriate, ibid. 4tr half 4tr rather than 4tr 4tr~4tr 4tr.

// Put all instrument dynamics under the staff, voice dynamics over, except:
//   - When >1 voice on a staff, put dynamics on proper side.
//   - General piano dynamics go between RH and LH, per-hand over/under staff.

// Don't let < > run into a bar line or each other.
// Always indicate the final dynamics at end of < >.
// Don't use < > in the piano to cover only 2 notes.

// When two piano voices on the same staff have the same-length rest,
// just print one rest.

// Only use cautionary accidentals if they are cancelling an accidental in
// the same part and octave in the previous measure, not any earlier measure.

// After rests, put new clef/dynamics right next to the first note, not at
// the beginning of the measure.

// ---------------- Miscellany ---------------- //

// Draw a "let vibrate" curve after a note.  (The note must be tagged.)
define LV_ABOVE(T_)\
  medium curve (T_.e,T_.n) to (T_.e+2,T_.n+1) to (T_.e+4,T_.n) @
define LV_BELOW(T_)\
  medium curve (T_.e,T_.s) to (T_.e+2,T_.s-1) to (T_.e+4,T_.s) @

// mup doesn't substitute macro definitions between backquotes, only macro
// parameters.  Because of this, we can't define MIDI channel numbers using
// macros.  We work around this with the following unfortunate hack.
// (This isn't a problem with MIDI program numbers, because those are *only*
// used quoted: channel numbers may be the same as staff numbers, which must
// defined without quotes.)  This only works for numbers 0-16!
define LITNUM(LNX_,LNM_)\
if (LNX_)>=8 then\
 if (LNX_)>=12 then\
  if (LNX_)==12 then LNM_(12) else if (LNX_)==13 then LNM_(13) else\
  if (LNX_)==14 then LNM_(14) else if (LNX_)==15 then LNM_(15) else\
  if (LNX_)==16 then LNM_(16) endif endif endif endif endif\
 else\
  if (LNX_)==8 then LNM_(8) else if (LNX_)==9 then LNM_(9) else\
  if (LNX_)==10 then LNM_(10) else LNM_(11) endif endif endif\
 endif\
else\
 if (LNX_)>=4 then\
  if (LNX_)==4 then LNM_(4) else if (LNX_)==5 then LNM_(5) else\
  if (LNX_)==6 then LNM_(6) else LNM_(7) endif endif endif\
 else\
  if (LNX_)==0 then LNM_(0) else if (LNX_)==1 then LNM_(1) else\
  if (LNX_)==2 then LNM_(2) else if (LNX_)==3 then LNM_(3)\
  endif endif endif endif\
 endif\
endif\
@
define QUOTE(QUOTEX_)`QUOTEX_`@
define QUOTENUM(QNX_)LITNUM(QNX_,QUOTE)@

// Fortuitously, we can use the same hack to do general arithmetic!
define AV_(VALUE_) VALUE_@
define ARITH(EXPR_) LITNUM(EXPR_, AV_)@

// ---------------- Instruments / parts ---------------- //

// -------- Instrument definitions -------- //

// The general form of an instrument definition is:
//	define U_<name> 0xjnnnnnnn @
//	define I_<name>(I_) I_(U_<name>,"midiname","label","label2",<clef>,<defoct>,MP_<name>,<transposition if any>)
// Because of a bug in mup's handling of 'if' statements, there must not be a
// line break (even escaped with \) between the prototype and the definition.
// The defoct is needed in case the instrument is combined onto a staff with
// another instrument with a different default clef.

// The "unique" identifier for each instrument is 0xjnnnnnnn, where j is the
// instance number (e.g., clarinet 1,2,3) if any and nnnnnnn are the lowest hex
// digit of the first 1-7 letters of the ASCII name, except that multi-word
// names abbreviate the first word to a single letter (e.g., TSAX, EHORN,
// CBASS, BCLARINET).
define U1_ +0x10000000 @
define U2_ +0x20000000 @
define U3_ +0x30000000 @
define U4_ +0x40000000 @
// Add a tag bit to indicate whether the instrument uses more than one staff
// (piano, organ, harp, ...).  In this case we use U2_ and U3_ to indicate
// the number of staffs.  For such instruments, the first 5 letters must be
// the same for all staffs, and the last 2 must be different.  (Yes, this is
// a hack.)
define UMS_ 0x80000000 @		// multi-staff
define MUNS_ 0x70000000 @		// number-of-staffs mask
define MUIN_ 0x0fffff00 @		// name of instrument
define MUSN_ 0x000000ff @		// name of staff
define U2S_ U2_+UMS_ @
//define U3S_ U3_+UMS_ @	// for organ someday

define IUN_(IUN,IMN,ILB,IL2,ICF,IDO,IMP,ITR)IUN@
define IMN_(IUN,IMN,ILB,IL2,ICF,IDO,IMP,ITR)IMN@
define ILB_(IUN,IMN,ILB,IL2,ICF,IDO,IMP,ITR)ILB@
define IL2_(IUN,IMN,ILB,IL2,ICF,IDO,IMP,ITR)IL2@
define ICF_(IUN,IMN,ILB,IL2,ICF,IDO,IMP,ITR)ICF@
define IDO_(IUN,IMN,ILB,IL2,ICF,IDO,IMP,ITR)IDO@
define IMP_(IUN,IMN,ILB,IL2,ICF,IDO,IMP,ITR)IMP@
define ITR_(IUN,IMN,ILB,IL2,ICF,IDO,IMP,ITR)ITR@

// Transposition (ITR) can be empty, TDOWN_(interval), or TUP_(interval).
// TDOWN_ and TUP_ are defined later depending on the status of score
// transposition.

// As noted above, INSTRUMENTS consists of a sequence of IS/ISD/IS2 calls.
// IN_, INV2_, IND_, and IN2_ are redefined for local purposes, so....

// uses IN_ free; defines ISN_, IVD_, IVN_.
define IS(ISN_,IJ_)\
undef IVD_ define IVD_ staff ISN_ \@   undef IVN_ define IVN_ ISN_ \@ \
IN_(QUOTENUM(ISN_\),IJ_) @

// uses INV2_ free; defines ISN_, IVD_, IVN_.
define ISV2(ISN_,IJ_)\
undef IVD_ define IVD_ staff ISN_ \@   undef IVN_ define IVN_ ISN_ \@ \
INV2_(QUOTENUM(ISN_\),IJ_) @

// uses IND_ free; defines ISN_, IVD_, IVN_.
define ISD(ISN_,IJ_)\
undef IVD_ define IVD_ staff ISN_ \@   undef IVN_ define IVN_ ISN_ \@ \
IND_(QUOTENUM(ISN_\),IJ_) @

// uses IN2_ free; defines ISN_; IN2_ args define IVD_, IVN_.
define IS2(ISN_,IJ1_,IJ2_)\
IN2_(QUOTENUM(ISN_\),\
 undef IVD_ define IVD_ voice ISN_ 1 \@ undef IVN_ define IVN_ ISN_ 1 \@,IJ1_,\
 undef IVD_ define IVD_ voice ISN_ 2 \@ undef IVN_ define IVN_ ISN_ 2 \@,IJ2_)@

// Determine the staff # for a part or instrument (specified by "unique" ID)
// by enumerating INSTRUMENTS -- needed because of limitations in mup's macro
// handling.  USTAFFX(uniqueID, expression) evaluates expression in a context
// where ISN_ is set to the staff number of the instrument with the given
// uniqueID.
define USTAFFX(USXUN_,USXX_) \
undef IN_ define IN_(ISS_,II_) if II_(IUN_)==USXUN_ then USXX_ endif \@ \
undef INV2_ define INV2_(ISS_,II_) if II_(IUN_)==USXUN_ then USXX_ endif \@ \
undef IND_ define IND_(ISS_,II_) if II_(IUN_)==USXUN_ then USXX_ endif \@ \
undef IN2_ define IN2_(IS2_, IX1_,II1_,IX2_,II2_) IN_(IS2_,II1_) IN_(IS2_,II2_) \@ \
INSTRUMENTS @
define USTAFF(USUN_) USTAFFX(USUN_,ISN_) @

// Add the transposed key to labels only if we are transposing.
define TL_(TLN_,TLK_,TLC_) ifdef TRANSPOSING_ TLK_+TLN_ else TLN_+TLC_ endif @
define TLCP_ "\n(concert pitch)" @
define TLCP2_ "\n(concert)" @
define TL1_(TL1N_) TL_(TL1N_,"",TLCP_) @
define TL2_(TL2N_) TL_(TL2N_,"",TLCP2_) @

// ---- Woodwinds ---- //

define MP_PICCOLO "72" @
define MP_FLUTE "73" @
define MP_OBOE "68" @
define MP_ENGLISH_HORN "69" @
define MP_CLARINET "71" @
define MP_BASS_CLARINET "71" @	    // if it goes low enough, or use bassoon
define MP_HORN "60" @
define MP_BASSOON "70" @
define MP_CONTRABASSOON "70" @	// if it goes low enough, or use double bass

define U_PICCOLO 0x00933fcf @
define I_PICCOLO(I_) I_(U_PICCOLO,"Piccolo",TL1_("Piccolo"\),TL2_("Picc."\),treble,4,MP_PICCOLO,TUP_(per 8\))@

define U_FLUTE 0x0004c545 @
define I_FLUTE(I_) I_(U_FLUTE,"Flute","Flute","Fl.",treble,4,MP_FLUTE,)@

define U_OBOE 0x0000f2f5 @
define I_OBOE(I_) I_(U_OBOE,"Oboe","Oboe","Ob.",treble,4,MP_OBOE,)@

define U_ENGLISH_HORN 0x00058f2e @
define I_ENGLISH_HORN(I_) I_(U_ENGLISH_HORN,"English Horn",TL1_("English horn"\),TL2_("Eng. horn"\),treble,4,MP_ENGLISH_HORN,TDOWN_(per 5\))@

// The clarinet labels depend on on whether we're transposing.
define L1_CL(CN_) TL_("Clarinet"+CN_, "B\\\(flat\) ", TLCP_) @
define L2_CL(CN_) TL_("Cl."+CN_, "", TLCP2_) @
define U_CLARINET 0x03c129e5 @
define I_CLARINET(I_) I_(U_CLARINET,"Clarinet",L1_CL(""\),L2_CL(""\),treble,4,MP_CLARINET,TDOWN_(maj 2\))@
define I_CLARINET_1(I_) I_(U_CLARINET U1_,"Clarinet",L1_CL(" 1"\),L2_CL(" 1"\),treble,4,MP_CLARINET,TDOWN_(maj 2\))@
define I_CLARINET_2(I_) I_(U_CLARINET U2_,"Clarinet",L1_CL(" 2"\),L2_CL(" 2"\),treble,4,MP_CLARINET,TDOWN_(maj 2\))@
define I_CLARINET_3(I_) I_(U_CLARINET U3_,"Clarinet",L1_CL(" 3"\),L2_CL(" 3"\),treble,4,MP_CLARINET,TDOWN_(maj 2\))@

define L1_CLA TL_("A Clarinet", "", TLCP_) @
define L2_CLA TL_("A Cl.", "", TLCP2_) @
define U_CLARINET_A 0x013c129e @	// ACLARIN
define I_CLARINET_A(I_) I_(U_CLARINET_,"Clarinet",L1_CLA,L2_CLA,treble,4,MP_CLARINET,TDOWN_(min 3\))@

define L1_CLEB TL_("E\\\(flat\) clarinet", "", TLCP_) @
define L2_CLEB TL_("E\\\(flat\) clar.", "", TLCP2_) @
define U_E_FLAT_CLARINET 0x0523c129 @
define I_E_FLAT_CLARINET(I_) I_(U_CLARINET_,"Clarinet",L1_CLEB,L2_CLEB,treble,4,MP_CLARINET,TUP_(min 3\))@

// The bass clarinet has clef issues like the horn.  See below.
define BASS_CLARINET_TREBLE \
  undef CLBC_ define CLBC_ treble \@ \
  undef DOBC_ define DOBC_ 4 \@ @
define BASS_CLARINET_BASS \
  undef CLBC_ \
  ifdef TRANSPOSING_ define CLBC_ treble \@ else define CLBC_ bass \@ endif \
  undef DOBC_ define DOBC_ 3 \@ @
ifndef CLEF_BASS_CLARINET
  define CLEF_BASS_CLARINET BASS_CLARINET_BASS @
endif
// SET_BASS_CLARINET(H, BASS_CLARINET_{TREBLE|BASS}) [as a command]
// CHANGE_BASS_CLARINET(BASS_CLARINET_{TREBLE|BASS}) [in-line]
// Note that this must not include any newlines, so it can be used in-line.
define SET_BASS_CLARINET(HS_,HTB_) HTB_ staff HS_ clef = CLBC_; defoct = DOBC_ @
define CHANGE_BASS_CLARINET(HTB_) << HTB_ staff clef = CLBC_; defoct = DOBC_ >> @
define U_BASS_CLARINET 0x023c129e @
define I_BASS_CLARINET(I_) I_(U_BASS_CLARINET,"Bass clarinet","Bass clarinet","B.Cl.",CLEF_BASS_CLARINET CLBC_,CLEF_BASS_CLARINET DOBC_,MP_BASS_CLARINET,TDOWN_(maj 9\))@

// The horn clefs and labels depend on whether we're transposing.
// Note that we need special macros for clef changes, because the horn parts
// should always use treble clef exclusively.
// Note that HORN_TREBLE and HORN_BASS must not include any newlines,
// so that they can be used for in-line clef changes.
define HORN_TREBLE \
  undef CLH_ define CLH_ treble \@ \
  undef DOH_ define DOH_ 4 \@ @
define HORN_BASS \
  undef CLH_ \
  ifdef TRANSPOSING_ define CLH_ treble \@ else define CLH_ bass \@ endif \
  undef DOH_ define DOH_ 3 \@ @
define L1_HORN(HN_)     TL_("F Horn"+HN_, "", TLCP_) @
define L2_HORN(HN_)     TL_("F Hn."+HN_, "", TLCP2_) @
define CH_ ifdef CLEF_HORN CLEF_HORN else HORN_BASS endif @
// SET_HORN(H, HORN_{TREBLE|BASS}) [as a command]
// CHANGE_HORN(HORN_{TREBLE|BASS}) [in-line]
// Note that this must not include any newlines, so it can be used in-line.
define SET_HORN(HS_,HTB_) HTB_ staff HS_ clef = CLH_; defoct = DOH_ @
define CHANGE_HORN(HTB_) << HTB_ staff clef = CLH_; defoct = DOH_ >> @
define U_HORN 0x00008f2e @
define I_HORN(I_) I_(U_HORN,"French Horn",L1_HORN(""\),L2_HORN(""\),CH_ CLH_,CH_ DOH_,MP_HORN,TDOWN_(per 5\))@
define I_HORN_1(I_) I_(U_HORN U1_,"French Horn",L1_HORN(" 1"\),L2_HORN(" 1"\),CH_ CLH_,CH_ DOH_,MP_HORN,TDOWN_(per 5\))@
define I_HORN_2(I_) I_(U_HORN U2_,"French Horn",L1_HORN(" 2"\),L2_HORN(" 2"\),CH_ CLH_,CH_ DOH_,MP_HORN,TDOWN_(per 5\))@
define I_HORN_3(I_) I_(U_HORN U3_,"French Horn",L1_HORN(" 3"\),L2_HORN(" 3"\),CH_ CLH_,CH_ DOH_,MP_HORN,TDOWN_(per 5\))@
define I_HORN_4(I_) I_(U_HORN U4_,"French Horn",L1_HORN(" 4"\),L2_HORN(" 4"\),CH_ CLH_,CH_ DOH_,MP_HORN,TDOWN_(per 5\))@

define U_BASSOON 0x02133ffe @
define I_BASSOON(I_) I_(U_BASSOON,"Bassoon","Bassoon","Bsn.",bass,3,MP_BASSOON,)@

define U_CONTRABASSOON 0x032133ff @
define I_CONTRABASSOON(I_) I_(U_CONTRABASSOON,"Contrabassoon",TL1_("Contrabassoon"\),TL2_("C.Bsn."\),bass,3,MP_CONTRABASSOON,TDOWN_(per 8\))@

// ---- Brass ---- //

define MP_TRUMPET "56" @
define MP_TROMBONE "57" @
define MP_TUBA "58" @
define MP_SOPRANO_SAX "64" @
define MP_ALTO_SAX "65" @
define MP_TENOR_SAX "66" @
define MP_BARITONE_SAX "67" @

// Trumpets can be in either Bb or C.  The default is Bb.
define L1_T(TN_) TL_("B\\\(flat\) Trumpet"+TN_, "", TLCP_) @
define L2_T(TN_) TL_("B\\\(flat\) Tpt."+TN_, "", TLCP2_) @
define U_TRUMPET 0x0425d054 @
define I_TRUMPET(I_) I_(U_TRUMPET,"Trumpet",L1_T(""\),L2_T(""\),treble,4,MP_TRUMPET,TDOWN_(maj 2\))@
define I_TRUMPET_1(I_) I_(U_TRUMPET U1_,"Trumpet",L1_T(" 1"\),L2_T(" 1"\),treble,4,MP_TRUMPET,TDOWN_(maj 2\))@
define I_TRUMPET_2(I_) I_(U_TRUMPET U2_,"Trumpet",L1_T(" 2"\),L2_T(" 2"\),treble,4,MP_TRUMPET,TDOWN_(maj 2\))@
// Trumpets in C (preferred by American orchestras).
undef L1_T define L1_T(TN_) TL_("C Trumpet"+TN_, "", TLCP_) @
undef L2_T define L2_T(TN_) TL_("C Tpt."+TN_, "", TLCP2_) @
define I_TRUMPET_C(I_) I_(U_TRUMPET,"Trumpet",L1_T(""\),L2_T(""\),treble,4,MP_TRUMPET,)@
define I_TRUMPET_1_C(I_) I_(U_TRUMPET U1_,"Trumpet",L1_T(" 1"\),L2_T(" 1"\),treble,4,MP_TRUMPET,)@
define I_TRUMPET_2_C(I_) I_(U_TRUMPET U2_,"Trumpet",L1_T(" 2"\),L2_T(" 2"\),treble,4,MP_TRUMPET,)@

define U_TROMBONE 0x042fd2fe @
define I_TROMBONE(I_) I_(U_TROMBONE,"Trombone","Tenor trombone","T.Tbn.",bass,3,MP_TROMBONE,)@

define U_BASS_TROMBONE 0x0242fd2f @
define I_BASS_TROMBONE(I_) I_(U_BASS_TROMBONE,"Trombone","Bass trombone","B.Tbn.",bass,3,MP_TROMBONE,)@

define U_TUBA 0x00004521 @
define I_TUBA(I_) I_(U_TUBA,"Tuba","Tuba","Tba.",bass,3,MP_TUBA,)@

// Some saxophone clefs depend on whether we're transposing.
define U_SOPRANO_SAX 0x00003318 @
define I_SOPRANO_SAX(I_) I_(U_SOPRANO_SAX,"Soprano Sax","Soprano sax","S. sax",treble,4,MP_SOPRANO_SAX,TDOWN_(maj 2\))@

define CLEF_ALTO_SAX treble @
define U_ALTO_SAX 0x00001318 @
define I_ALTO_SAX(I_) I_(U_ALTO_SAX,"Alto Sax","Alto sax","A. sax",CLEF_ALTO_SAX,4,MP_ALTO_SAX,TDOWN_(maj 6\))@

define CLEF_TENOR_SAX ifdef TRANSPOSING_ treble else treble8 endif @
define DEFOCT_TENOR_SAX ifdef TRANSPOSED 4 else 3 endif @
define U_TENOR_SAX 0x00004318 @
define I_TENOR_SAX(I_) I_(U_TENOR_SAX,"Tenor Sax","Tenor sax","T. sax",CLEF_TENOR_SAX,DEFOCT_TENOR_SAX,MP_TENOR_SAX,TDOWN_(maj 9\))@

define CLEF_BARITONE_SAX ifdef TRANSPOSING_ treble else bass endif @
define U_BARITONE_SAX 0x00002318 @
define I_BARITONE_SAX(I_) I_(U_BARITONE_SAX,"Baritone Sax","Baritone sax","T. sax",CLEF_BARITONE_SAX,3,MP_BARITONE_SAX,TDOWN_(maj 13\))@

// ---- Percussion, guitar ---- //

define MP_GUITAR "26" @			// one of several alternatives
define MP_BASS_GUITAR "26" @		// ??
define MP_PERCUSSION "115" @		// wood blocks, as good as any
define MP_TIMPANI "47" @

define CLEF_GUITAR ifdef TRANSPOSING_ treble else treble8 endif @
define U_GUITAR 0x00759412 @
define I_GUITAR(I_) I_(U_GUITAR,"Acoustic Guitar","Guitar","Gtr.",CLEF_GUITAR,MP_GUITAR,TDOWN_(per 8\))@

define U_BASS_GUITAR 0x02759412 @
define I_BASS_GUITAR(I_) I_(U_BASS_GUITAR,"Acoustic Bass","Bass guitar","B. gtr.",MP_BASS_GUITAR,TDOWN_(per 8\))@

define LBP_ ifdef LABEL_PERCUSSION LABEL_PERCUSSION else "Percussion" endif @
define LBP2_ ifdef LABEL2_PERCUSSION LABEL2_PERCUSSION else "Perc." endif @
define U_PERCUSSION 0x005235229 @
define I_PERCUSSION(I_) I_(U_PERCUSSION,"-Percussion-",LBP_,LBP2_,treble;ifdef STAFF_PERCUSSION STAFF_PERCUSSION else stafflines=5n endif; vscheme=ifdef VSCHEME_PERCUSSION VSCHEME_PERCUSSION else 1 endif,4,MP_PERCUSSION,)@

define U_TIMPANI 0x049d01e9 @
define I_TIMPANI(I_) I_(U_TIMPANI,"Timpani","Timpani","Timp.",bass,3,MP_TIMPANI,) @

// ---- Piano, harp ---- //

// The default for piano is two parts in each hand.  Don't label the parts.
define VSRH_ ifdef VSCHEME_RH VSCHEME_RH else 2f endif @
define VSLH_ ifdef VSCHEME_LH VSCHEME_LH else 2f endif @

define SRH_ USTAFF(U_PIANO_RH) @
define SLH_ USTAFF(U_PIANO_LH) @

define MP_PIANO "0" @

define U_PIANO_RH 0x0091ef28 @
define I_PIANO_RH(I_) I_(U_PIANO_RH,"Acoustic Grand Piano","","", treble;vscheme=VSRH_,4,MP_PIANO,)@
define U_PIANO_LH 0x0091efc8 @
define I_PIANO_LH(I_) I_(U_PIANO_LH,"Acoustic Grand Piano","","", bass;vscheme=VSLH_,3,MP_PIANO,)@
// Pseudo-instrument for PART=I_PIANO
define U_PIANO 0xa091ef00 @		// MUIN_ for setting PART
define I_PIANO(I_) I_(U_PIANO,"Acoustic Grand Piano","Piano","",none,none,MP_PIANO,)@

// The default for harp is one part in each hand.  Don't label the parts.
define VSRHH_ ifdef VSCHEME_HARP_RH VSCHEME_HARP_RH else 1 endif @
define VSLHH_ ifdef VSCHEME_HARP_LH VSCHEME_HARP_LH else 1 endif @

define SRHH_ USTAFF(U_HARP_RH) @
define SLHH_ USTAFF(U_HARP_LH) @

define MP_HARP "46" @

define U_HARP_RH 0x00812028 @
define I_HARP_RH(I_) I_(U_HARP_RH,"Harp","","", treble;vscheme=VSRHH_,4,MP_HARP,)@
define U_HARP_LH 0x008120c8 @
define I_HARP_LH(I_) I_(U_HARP_LH,"Harp","","", bass;vscheme=VSLHH_,3,MP_HARP,)@
// Pseudo-instrument for PART=I_HARP
define U_HARP 0xa0812000 @		// MUIN_ for setting PART
define I_HARP(I_) I_(U_HARP,"Harp","Harp","",none,none,MP_HARP,)@

// ---- Strings ---- //

define MP_VIOLIN "40" @
define MP_VIOLA "41" @
define MP_CELLO "42" @
// We prefer "double bass" to "contrabass", but both are used.
define MP_DOUBLE_BASS "43" @
define MP_CONTRABASS "43" @
define MP_PIZZICATO "45" @		// not a real instrument

define U_VIOLIN 0x0069fc9e @
define I_VIOLIN(I_) I_(U_VIOLIN,"Violin","Violin","Vln.",treble,4,MP_VIOLIN,)@
define I_VIOLIN_I(I_) I_(U_VIOLIN U1_,"Violin","Violin 1","Vln. 1",treble,4,MP_VIOLIN,)@
define I_VIOLIN_II(I_) I_(U_VIOLIN U2_,"Violin","Violin 2","Vln. 2",treble,4,MP_VIOLIN,)@

// See HORN_TREBLE et al above regarding alternate clefs for viola and cello.

define VIOLA_TREBLE undef CLVA_ define CLVA_ treble \@ @
define VIOLA_ALTO   undef CLVA_ define CLVA_ alto \@ @

define U_VIOLA 0x00069fc1 @
// Unfortunately, some older files define CLEF_VIOLA as simply 'treble' or
// 'alto'.  Work around this here.
define CVA_ \
  ifdef CLEF_VIOLA \
    undef CLVA_ CLEF_VIOLA ifdef CLVA_ CLVA_ endif \
  else alto endif @
define I_VIOLA(I_) I_(U_VIOLA,"Viola","Viola","Vla.",CVA_,4,MP_VIOLA,)@

define CELLO_TREBLE \
  undef CLVC_ define CLVC_ treble \@ \
  undef DOVC_ define DOVC_ 4 \@ @
define CELLO_TENOR \
  undef CLVC_ define CLVC_ tenor \@ \
  undef DOVC_ define DOVC_ 3 \@ @
define CELLO_BASS \
  undef CLVC_ define CLVC_ bass \@ \
  undef DOVC_ define DOVC_ 3 \@ @

define U_CELLO 0x00035ccf @
define CVC_ ifdef CLEF_CELLO CLEF_CELLO else CELLO_BASS endif @
define I_CELLO(I_) I_(U_CELLO,"Cello","Violoncello","Vlc.",CVC_ CLVC_,CVC_ DOVC_,MP_CELLO,)@

define U_DOUBLE_BASS 0x00042133 @
define I_DOUBLE_BASS(I_) I_(U_DOUBLE_BASS,"Contrabass",TL1_("Double Bass"\),TL2_("D.B."\),bass,3,MP_DOUBLE_BASS,TDOWN_(per 8\))@
define U_CONTRABASS 0x00032133 @
define I_CONTRABASS(I_) I_(U_CONTRABASS,"Contrabass",TL1_("Contrabass"\),TL2_("C.bass"\),bass,3,MP_CONTRABASS,TDOWN_(per 8\))@

// Pizzicato/arco

define PIZZN(ZN,ZP) ital above ZN: ZP "pizz.";
midi ZN: ZP "program="+MP_PIZZICATO @
define PIZZ(ZZN) PIZZN(ZZN,1) @

define ARCON(ZN,ZMP,ZP) ital above ZN: ZP "arco";
midi ZN: ZP "program="+ZMP @
define ARCO(ZZN,ZZMP) ARCON(ZZN,ZZMP,1) @

// Old, deprecated synonyms.
define PIZZ2(ZN2,ZP2) PIZZN(ZN2,ZP2) @
define ARCO2(ZN2,ZP2,ZMP2) ARCON(ZN2,ZMP2,ZP2) @ // note different order

// ---- Voice ---- //

define MP_SOPRANO MP_OBOE @
define MP_ALTO MP_CLARINET @
define MP_TENOR MP_CLARINET @
define MP_BARITONE MP_BASSOON @
define MP_BASS MP_BASSOON @

define U_SOPRANO 0x03f021ef @
define I_SOPRANO(I_) I_(U_SOPRANO,"Soprano Voice","Soprano","Sop.",treble,4,MP_SOPRANO,)@
define I_SOPRANO_1(I_) I_(U_SOPRANO U1_,"Soprano Voice","Soprano 1","Sop. 1",treble,4,MP_SOPRANO,)@
define I_SOPRANO_2(I_) I_(U_SOPRANO U2_,"Soprano Voice","Soprano 2","Sop. 2",treble,4,MP_SOPRANO,)@

define U_ALTO 0x00001c4f @
define I_ALTO(I_) I_(U_ALTO,"Alto Voice","Alto","Alt.",treble,4,MP_ALTO,)@
define I_ALTO_1(I_) I_(U_ALTO U1_,"Alto Voice","Alto 1","Alt. 1",treble,4,MP_ALTO,)@
define I_ALTO_2(I_) I_(U_ALTO U2_,"Alto Voice","Alto 2","Alt. 2",treble,4,MP_ALTO,)@

define DOT_ ifdef DEFOCT_TENOR DEFOCT_TENOR else 3 endif @
define U_TENOR 0x00045ef2 @
define I_TENOR(I_) I_(U_TENOR,"Tenor Voice","Tenor","Ten.",treble8,DOT_,MP_TENOR,)@
define I_TENOR_1(I_) I_(U_TENOR U1_,"Tenor Voice","Tenor 1","Ten. 1",treble8,DOT_,MP_TENOR,)@
define I_TENOR_2(I_) I_(U_TENOR U2_,"Tenor Voice","Tenor 2","Ten. 2",treble8,DOT_,MP_TENOR,)@
// Tenor line written in bass clef, for combining with bass on a single staff.
define I_TENOR_B(I_) I_(U_TENOR,"Tenor Voice","Tenor","Ten.",bass,DOT_,MP_TENOR,)@

define U_BARITONE 0x021294fe @
define I_BARITONE(I_) I_(U_BARITONE,"Baritone Voice","Baritone","Bar.",bass,3,MP_BARITONE,)@

define U_BASS 0x00002133 @
define I_BASS(I_) I_(U_BASS,"Bass Voice","Bass","Bass",bass,3,MP_BASS,)@

// -------- End of instrument definitions -------- //

// Handle transposition.  We define TRANSPOSING_ internally iff we are
// producing transposed output, but the only thing that affects is the staff
// labels.

// Note whether we're producing parts, and whether we're transposing.
ifdef PART				// Don't label each staff.
  define U_PART PART(IUN_) @
  define LABEL(L) @
  define LABEL2(L1,L2) @
  define TRANSPOSING_ @
  score visible = n		     // Only the selected parts are visible.
  restcombine = 2			// Combine rests (should be 1).
else					// Not producing parts, label staves.
  define U_PART (-1) @
  // If NOLABELS, we really want no label, not spaces.
  define LABEL(L) ifndef NOLABELS label = L; endif @
  define LABEL2(L1,L2) ifndef NOLABELS label = L1; label2 = L2; endif @
  ifdef ALL_PARTS define TRANSPOSING_ @ endif
endif
ifdef MIDI undef TRANSPOSING_ endif	// MIDI output at concert pitch!
// There are 4 cases depending on TRANSPOSED and TRANSPOSING_....
define TDOWN_(TI_) @
define TUP_(TI_) @

ifdef TRANSPOSED
  ifndef TRANSPOSING_			// do transposition
    undef TDOWN_ define TDOWN_(TI_) transpose=down TI_; @
    undef TUP_ define TUP_(TI_) transpose=up TI_; @
  endif
else					// not TRANSPOSED
 ifdef TRANSPOSING_			// undo transposition
    undef TDOWN_ define TDOWN_(TI_) transpose=up TI_; @
    undef TUP_ define TUP_(TI_) transpose=down TI_; @
  endif
endif

// Define MIDI information
define MIDI_PART(MVOICE,MCHANNEL,MPROGRAM)\
midi MVOICE: 0 "channel="+MCHANNEL; 0 "program="+MPROGRAM; @
define MIDI_INSTR(MIV,MNAME,MIC,MIP)\
MIDI_PART(MIV,MIC,MIP) 0 "instrument="+MNAME; @

// ---------------- Score/staff/page level ---------------- //

// Keep SCALE and PAD separate from actual parameters.
ifdef PAD define PAD_ PAD @ endif
ifdef SCALE define SCALE_ SCALE @ endif
ifdef SMALL
  ifndef SCALE_ define SCALE_ 0.7 @ endif
  ifndef PAD_ define PAD_ 2.5 @ endif
else
  ifndef SCALE_ define SCALE_ 0.85 @ endif
  ifndef PAD_ define PAD_ 2 @ endif
endif
	score scale = SCALE_; pad = PAD_
	// These are our defaults:
	measnum = y; cancelkey = y
	ifdef BINDING
	  // We should adjust the margins for even/odd pages, but we can't.
	  // Just make them both wider.
	  leftmargin = 0.75
	  rightmargin = 0.75
	endif
	ifdef SCOREPAD scorepad = SCOREPAD endif
	// Set parameters from the command line.
	ifdef PARAMS PARAMS endif
	ifdef RELNORM release = RELNORM endif

define MUSIC score @			// not ready for music yet

ifdef ANON
undef COMPOSER
define COMPOSER "by the composer" @
else
ifndef COMPOSER  define COMPOSER COMPOSER_ @  endif
ifndef COMPOSER_CONTACT  define COMPOSER_CONTACT CONTACT_ @  endif
ifndef COMPOSER_EMAIL1  define COMPOSER_EMAIL1 EMAIL1_ @  endif
ifndef COMPOSER_EMAIL2  define COMPOSER_EMAIL2 EMAIL2_ @  endif
endif					// ANON

ifndef COPYRIGHT_YEAR  define COPYRIGHT_YEAR CP_YEAR_ @  endif

define COMPOSER_COPYRIGHT_STRING "Copyright \(copyright) " + COPYRIGHT_YEAR + " " + COMPOSER + ". All rights reserved." @

ifndef COPYRIGHT_STRING
define COPYRIGHT_STRING COMPOSER_COPYRIGHT_STRING  @
endif

// Define headers, including a page number.
// The page number should alternate between left and right sides,
// but there's currently no way to make it do that.
ifndef NOHEADER

ifdef PART
  ifndef HEADER  define HEADER @  endif
endif					// ifdef PART
ifdef FIRSTPAGE
  firstpage = FIRSTPAGE
  ifndef HEADER  define HEADER @  endif
endif					// ifdef FIRSTPAGE
ifdef HEADER
header
ifdef FIRSTPAGE				// number the first page
	right "\s(18)\%  "
endif					// ifdef FIRSTPAGE
ifdef PART
	title (24) ifdef PART_LABEL PART_LABEL else PART(ILB_) endif ""
endif					// ifdef PART
	HEADER
endif					// ifdef HEADER

header2
ifdef HEADER2
	HEADER2
else
	right "\s(18)\%  "
endif					// if(n)def HEADER2

endif					// ifndef NOHEADER

ifndef NOFOOTER

// Define footers with a time stamp.
define PSSTAMP "
	save
	/show2 { exch show dup 10 lt { (0) show } if 2 string cvs show } def
	(%Calendar%) currentdevparams begin
	Year 4 string cvs show
	(/) Month show2 (/) Day show2
	( ) Hour show2 (:) Minute show2 (:) Second show2
	end restore
" @

define FOOTSTAMP
	postscript PSSTAMP
@

footer
ifdef FOOTER
	FOOTER
	title ""			// leave a blank line
endif					// ifdef FOOTER
	left nl COPYRIGHT_STRING
ifdef COMPOSER_CONTACT
	left nl "      " + COMPOSER_CONTACT
endif					// ifdef COMPOSER_CONTACT
// Break up the composer e-mail to avoid harvesting from the Web.
ifdef COMPOSER_EMAIL1
	print "; " + COMPOSER_EMAIL1
	print "@"
	print COMPOSER_EMAIL2
endif					// ifdef COMPOSER_EMAIL1
ifdef COMPOSER_CONTACT2
	left nl "      " + COMPOSER_CONTACT2
endif					// ifdef COMPOSER_EMAIL2
	left nl "Printed "
FOOTSTAMP

footer2
ifdef FOOTER2
	FOOTER2
	title ""			// leave a blank line
endif					// ifdef FOOTER2
	left nl "Printed "
FOOTSTAMP

endif					// ifndef NOFOOTER

// Define staff visibility.  An individual score may choose to have
// all staffs initially visible, or not.
define VIS(SN) staff SN visible = y; MUSIC @
define INVIS(SN) staff SN visible = n; MUSIC @
define UVIS(SN) staff SN visible = whereused; MUSIC @

// ---------------- File level ---------------- //

// No comments on clean scores.
ifdef CLEAN
ifndef NOX define NOX @ endif
endif

// Define a placeholder for missing sections.
define OMITTED(SSTR)
MUSIC
1: mr;
bar reh SSTR
@

// Define tempo settings.
define SET_TEMPO_AT3(TP3, TS3, MTP3, MTS3, TF3) \
midi all: MTP3 "tempo=" + MTS3;
TF3 above all: TP3 TS3 ; @
define SET_TEMPO_AT2(TP2,TS2,MTP2,MTS2) SET_TEMPO_AT3(TP2,TS2,MTP2,MTS2,rom) @
define SET_TEMPO_AT(TP1,TS1,MTS1) SET_TEMPO_AT2(TP1,TS1,TP1,MTS1) @
define SET_TEMPO(TSTR,MTSTR) SET_TEMPO_AT2(1,TSTR,0,MTSTR) @
define CHANGE_TEMPO_AT(TP1,TS1,MTS1) SET_TEMPO_AT3(TP1,TS1,TP1,MTS1,ital) @
define CHANGE_TEMPO(TSTR,MTSTR) CHANGE_TEMPO_AT(1,TSTR,MTSTR) @

// Define staff visibility, a little tricky for multi-staff instruments.
define SVIS_ defined(ALL_PARTS) || !((U_PART ^ II_(IUN_)) & (U_PART & UMS_ ? MUIN_ : -1)) @
// Define staff parameters.
define STARTSTAFFS
ifndef STAFFSTARTED
define STAFFSTARTED \@			// only do once
ifdef BEFORE_STAFFS
BEFORE_STAFFS
endif
undef IN_ define IN_(ISS_, II_)\
  staff ISN_ clef = II_(ICF_); defoct = II_(IDO_); LABEL2(II_(ILB_\), II_(IL2_\)) II_(ITR_)
  if SVIS_ then
    staff ISN_ visible = y
  endif \@
undef INV2_ define INV2_(ISS_, II_)\
  staff ISN_ clef = II_(ICF_); defoct = II_(IDO_); LABEL2(II_(ILB_\), II_(IL2_\)) vscheme = 2f; vcombine = 1-2 shareone; II_(ITR_)
  if SVIS_ then
    staff ISN_ visible = y
  endif \@
undef IND_ define IND_(ISS_, II_)\
  staff ISN_ clef = II_(ICF_); defoct = II_(IDO_); LABEL2(II_(ILB_\)+" 1\,2", II_(IL2_\)+" 1\,2") vscheme = 2f; vcombine = 1-2 shareone; II_(ITR_)
  if SVIS_ then
    staff ISN_ visible = y
    ifdef PART
	// When producing parts, the voice must be specified.
      voice ISN_ 1 visible = n
      voice ISN_ 2 visible = n
      voice ISN_ PART_VOICE visible = y
    endif
  endif \@
undef IN2_ define IN2_(IS2_, IX1_,II1_,IX2_,II2_)\
  ifdef PART
    IX1_ IN_(II1_) IX2_ IN_(II2_)	// only one part
  else
    // Which clef do we use?  Right now we just use that of voice 1,
    // but we make sure that each voice has the correct defoct.
    staff ISN_ clef = II1_(ICF_); vscheme = 2o; label = II1_(ILB_) + "\n" + II2_(ILB_); label2 = II1_(IL2_) + "\n" + II2_(IL2_); II1_(ITR_)
    voice ISN_ 1 defoct = II1_(IDO_)
    voice ISN_ 2 defoct = II2_(IDO_)
    ifdef ALL_PARTS staff ISN_ visible = y endif // no transposition
  endif \@
INSTRUMENTS
endif
@

// Define the start of actual music (see above), or of a section.
define BEGINMUSIC()
ifndef STARTED
define STARTED \@			// only do once
STARTSTAFFS
ifdef BEFORE_MUSIC BEFORE_MUSIC endif
undef MUSIC
define MUSIC music \@
MUSIC
midi all: 0 "copyright=" + COPYRIGHT_STRING;
ifdef INIT_MIDI
INIT_MIDI
else					// !INIT_MIDI
undef IN_
define IN_(ISS_, II_) MIDI_INSTR(IVN_, II_(IMN_\), ISS_, II_(IMP_\))
\@
undef INV2_
define INV2_(ISS_, II_) MIDI_INSTR(IVN_ 1, II_(IMN_\), ISS_, II_(IMP_\))
MIDI_INSTR(IVN_ 2, II_(IMN_\), ISS_, II_(IMP_\))
\@
undef IND_
define IND_(ISS_, II_) MIDI_INSTR(IVN_ 1, II_(IMN_\), ISS_, II_(IMP_\))
MIDI_INSTR(IVN_ 2, II_(IMN_\), ISS_, II_(IMP_\))
\@
undef IN2_
define IN2_(IS2_, IX1_,II1_,IX2_,II2_) IX1_ IN_(IS2_, II1_) IX2_ IN_(IS2_, II2_) \@
INSTRUMENTS
ifdef FIRST_MIDI FIRST_MIDI endif
endif					// INIT_MIDI
endif					// STARTED
MUSIC
ifdef TEMPO TEMPO undef TEMPO endif
@

// ---------------- Bar level ---------------- //

// Define bar lengths and beam styles.

define NOBEAM
	score beamstyle = ; MUSIC
@
define SCORETIME_ undef DOBEAM_
	score time = @

// Turn beaming on and off.
define DONT_BEAM
  undef DOBEAM
  define DOBEAM NOBEAM \@
@
define DO_BEAM
  undef DOBEAM
  define DOBEAM
    score beamstyle = DOBEAM_ ; MUSIC
  \@
@
DO_BEAM

define BEAM1_2 2 @
define TIME1_2 SCORETIME_ 1/2 define DOBEAM_ BEAM1_2 \@ DOBEAM @

define BEAM1_4 4 @
define TIME1_4 SCORETIME_ 1/4 define DOBEAM_ BEAM1_4 \@ DOBEAM @

define BEAM2_2 2,2 @
define SETBEAM2_2 define DOBEAM_ BEAM2_2 \@ DOBEAM @
define TIME2_2 SCORETIME_ 2/2 SETBEAM2_2 @
define TIMECUT SCORETIME_ cut SETBEAM2_2 @

define BEAM2_4 4,4 @
define TIME2_4 SCORETIME_ 2/4 define DOBEAM_ BEAM2_4 \@ DOBEAM @

define BEAM3_2 2,2,2 @
define TIME3_2 SCORETIME_ 3/2 define DOBEAM_ BEAM3_2 \@ DOBEAM @
define BEAM3_4 4,4,4 @
define TIME3_4 SCORETIME_ 3/4 define DOBEAM_ BEAM3_4 \@ DOBEAM @
define BEAM3_8 4. @
define TIME3_8 SCORETIME_ 3/8 define DOBEAM_ BEAM3_8 \@ DOBEAM @
define BEAM3_16 8. @
define TIME3_16 SCORETIME_ 3/16 define DOBEAM_ BEAM3_16 \@ DOBEAM @

define BEAM4_4 4,4,4,4 @
define SETBEAM4_4 define DOBEAM_ BEAM4_4 \@ DOBEAM @
define TIME4_4 SCORETIME_ 4/4 SETBEAM4_4 @
define TIMECOMMON SCORETIME_ common SETBEAM4_4 @

define BEAM4_8 4,4 @
define TIME4_8 SCORETIME_ 4/8 define DOBEAM_ BEAM4_8 \@ DOBEAM @

define BEAM5_4 4,4,4,4,4 @
define TIME5_4 SCORETIME_ 5/4 define DOBEAM_ BEAM5_4 \@ DOBEAM @
define BEAM5_8 4,4. @			// arbitrary
define TIME5_8 SCORETIME_ 5/8 define DOBEAM_ BEAM5_8 \@ DOBEAM @
define BEAM5_16 8,8. @			// arbitrary
define TIME5_16 SCORETIME_ 5/16 define DOBEAM_ BEAM5_16 \@ DOBEAM @

define BEAM6_4 4,4,4,4,4,4 @
define TIME6_4 SCORETIME_ 6/4 define DOBEAM_ BEAM6_4 \@ DOBEAM @
define BEAM6_8 4.,4. @
define TIME6_8 SCORETIME_ 6/8 define DOBEAM_ BEAM6_8 \@ DOBEAM @

define BEAM7_4 4,4,4,4,4,4,4 @
define TIME7_4 SCORETIME_ 7/4 define DOBEAM_ BEAM7_4 \@ DOBEAM @
define BEAM7_8 4.,4,4 @			// arbitrary
define TIME7_8 SCORETIME_ 7/8 define DOBEAM_ BEAM7_8 \@ DOBEAM @
define BEAM7_16 8.,8,8 @		// arbitrary
define TIME7_16 SCORETIME_ 7/16 define DOBEAM_ BEAM7_16 \@ DOBEAM @

define BEAM8_4 4,4,4,4,4,4,4,4 @
define TIME8_4 SCORETIME_ 8/4 define DOBEAM_ BEAM8_4 \@ DOBEAM @
define BEAM8_8 4,4,4,4 @
define TIME8_8 SCORETIME_ 8/8 define DOBEAM_ BEAM8_8 \@ DOBEAM @
define BEAM8_16 4,4 @
define TIME8_16 SCORETIME_ 8/16 define DOBEAM_ BEAM8_16 \@ DOBEAM @

define BEAM9_4 4,4,4,4,4,4,4,4,4 @
define TIME9_4 SCORETIME_ 9/4 define DOBEAM_ BEAM9_4 \@ DOBEAM @
define BEAM9_8 4.,4.,4. @
define TIME9_8 SCORETIME_ 9/8 define DOBEAM_ BEAM9_8 \@ DOBEAM @
define BEAM9_16 8.,8.,8. @
define TIME9_16 SCORETIME_ 9/16 define DOBEAM_ BEAM9_16 \@ DOBEAM @

define BEAM10_8 4.,4,4.,4 @
define TIME10_8 SCORETIME_ 10/8 define DOBEAM_ BEAM10_8 \@ DOBEAM @

define BEAM12_8 4.,4.,4.,4. @
define TIME12_8 SCORETIME_ 12/8 define DOBEAM_ BEAM12_8 \@ DOBEAM @

define BEAM17_8 4.,2,4.,2,4. @		// arbitrary
define TIME17_8 SCORETIME_ 17/8 define DOBEAM_ BEAM17_8 \@ DOBEAM @

define BEAM18_8 2,2,4.,2,4. @		// arbitrary
define TIME18_8 SCORETIME_ 18/8 define DOBEAM_ BEAM18_8 \@ DOBEAM @

// Define analysis strings.
ifdef NOX				// no analysis
define X_AT(XATLOC, XATSTR) @
else					// not NOX
define X_AT(XATLOC, XATSTR) helvetica rom (10) analysis XATLOC : XATSTR ; @
endif					// (not) NOX
define X(XSTR) X_AT(below all, XSTR) @

// Define lead sheet chord strings.
define Y_AT(YATLOC, YATSTR) helvetica bold (14) analysis YATLOC : YATSTR ; @
define Y(YSTR) Y_AT(above all, YSTR) @

// Conditionally enable repeats.
ifdef NOREPEATS
define ENDENDING @
define ENDING(N) @
define REPEATSTART dblbar @
define REPEATBOTH dblbar @
define REPEATEND dblbar @
else					// not NOREPEATS
define ENDENDING endending @
define ENDING(N) ending N @
define REPEATSTART repeatstart @
define REPEATBOTH repeatboth @
define REPEATEND repeatend @
endif					// (not) NOREPEATS

// ---------------- Note level ---------------- //

// Define articulation and other symbols.
define DOT [with .] @
define ACCENT [with >] @
define DASH [with -] @
define FERMATA [with "\(ferm)"] @
// The following are only for strings.
define RING [with "\(dim)"] @		// string harmonics
// 'with' places symbols opposite the stem, but bowing indications should
// always go above the note.  Currently there is no way to force mup to
// do this, so we use separate statements instead.  (We've requested a mup
// feature to accomplish this.)
//define UPBOW [with "\(upbow)" above] @
//define DNBOW [with "\(dnbow)" above] @
define BOWUP(BSN_,BPOS_) mussym above BSN_: BPOS_ "upbow"; @
define BOWDN(BSN_,BPOS_) mussym above BSN_: BPOS_ "dnbow"; @

// Define breath marks.
define BREATHE(SN, POS) rom SN: POS "\s(35)," @

// Define MIDI articulations.
define MR_(REL_) <<voice release=REL_>> @
define MRN_STAC 250 @
define MR_STAC MR_(MRN_STAC) @
// The normal release value is more articulated than the mup default.
define MRN_NORM ifdef RELNORM RELNORM else 60 endif @
define MR_NORM MR_(MRN_NORM) @
// Classical and later default string articulation is almost legato.
// Offer this as an option, but don't preset it.
define MRN_SNORM 10 @
define MR_SNORM MR_(MRN_SNORM) @
// Even legato playing needs a tiny bit of articulation.
define MRN_LEG ifdef RELLEG RELLEG else 5 endif @ // not 0
define MR_LEG MR_(MRN_LEG) @
// Mup adjusts the release value automatically for staccatos.
//define MDOT MR_STAC DOT @
define MDOT DOT @
define MNODOT MR_NORM @
define MPHRASE MR_LEG @
  define MBP MPHRASE @			// begin phrase
  define MBD MBP DASH @
define MNOPHRASE MR_NORM @
  define MEP MNOPHRASE @		// end phrase
  define MED MEP DASH @
// For mup versions >= 5.7, we can use ph/eph.
// Unfortunately, mup gives us no way to determine the version.
// Also unfortunately, the syntax must be different, because << >> must
// precede the duration and pitch but ph/eph must follow them;
// also, using ph and bm together requires a comma.
// Note that while MEPH can be used with MDOT, MPH cannot be used with MNORM:
// use MNPH instead.
  define MPH(DURP_) MPHRASE DURP_ ph @
  define MPB(DURP_) MPHRASE DURP_ ph,bm @
  define MNPH(DURP_) MPHRASE DURP_ ph @	// MPHRASE overrides MNORM
  define MEPH(DURP_) MNOPHRASE DURP_ eph @
  define MEPB(DURP_) MNOPHRASE DURP_ eph,ebm @
  define MEPDOT(DURP_) MDOT DURP_ eph @
define MNORM MR_NORM @
define MSNORM MR_SNORM @
define MDASH MR_NORM DASH @

// ---------------- Dynamics ---------------- //

// Placement of dynamics is messy.  There are 7 cases:
//	above	vocal line alone on a staff
//	below	instrumental line alone on a staff
//	above	keyboard RH
//	below	keyboard LH
//	between	keyboard both hands
//	above 1st, below 2nd
//		non-keyboard line with two voices on a staff
// Ideally, we would like to have a single set of DYN macros that would
// choose placement according to the part, voice, and setting of APART,
// but we don't see how to do this within mup's limitations.
// Therefore, we define the following sets of macros:
//	V(ocal)DYN[N][2] - for single vocal lines
//	I(nstrumental)DYN[N][2] - for single instrumental lines
//	P[2]{R,L,}DYN[N] - for piano {left,right,both} hand(s) with
//	  1 or 2 voices
//	DYN[N]2 - for two-voice lines (including lines that might be on a
//	  two-voice staff if APART isn't defined)
// The argument lists are:
//	xDYN(D_xx, staff)
//	xDYN2(D_xx, staff, midi)
//	xDYNN(D_xx, staff, position)
//	xDYNN2(D_xx, staff, midi, position)
// In fact, the DYN* macros don't really work if there are really two
// independent lines on a staff, because they don't include above/below
// information for producing separate parts.  So when there are two
// instrumental lines on a staff, use:
//	I2DYN[N][2](D_xx, staff, voice[, midi][, position])
// if both voices play at some point in the measure (so the dynamics for
// voice 1 need to go above the staff in the full score), or:
//	I2DYN[N][2]1(D_xx, staff, voice[, midi][, position])
// if only one voice plays anywhere in the measure.
// (We don't bother with this for vocal lines, because we never produce
// separate parts from multi-voice-per-staff music.  If this changes in
// the future, the V2DYN* macros are easy enough to add.)
// Because mup associates < and > with staffs rather than voices, we also
// need to use macros for these when there are two lines on a staff and
// we are going to produce parts:
//	I2CRESC[1](staff, voice, xx til xx)
//	I2DIM[1](staff, voice, xx til xx)
//
// ******************************** NOTE ********************************
// The V, I, P, and plain DYN macros *require a terminating semicolon*.
// The I2 macros *do not use a terminating semicolon*.
// (We blew it -- none of the macros should have required a semicolon --
// but we can't define the I2 macros so as to allow one.)

// Define names for expressive dynamics.
define DT_(D_M,D_T) D_T @		// text
// MIDI provides three different ways to specify volume: parameter 7 (Main
// Volume), parameter 11 (Expression Controller), and the "on velocity" of
// individual notes.  Mup can't handle "on velocity" with "midi all", and
// parameter 11 is clearly better than parameter 7 semantically.
define DM_(D_M,D_T) "parameter=11,"+D_M @ // MIDI
// The original numbers were: (10), 23, 36, 49, 62, 75, 88, 101, 114, (127),
// drawn from some application.  This is much too linear.
//pppp
define MD_PPP "16" @
define D_PPP(DQ) DQ(MD_PPP, "ppp") @
define MD_PP "23" @
define D_PP(DQ) DQ(MD_PP, "pp") @
define MD_P "32" @
define D_P(DQ) DQ(MD_P, "p") @
define MD_MP "45" @
define D_MP(DQ) DQ(MD_MP, "mp") @
define MD_MF "64" @
define D_MF(DQ) DQ(MD_MF, "mf") @
define MD_F "80" @
define D_F(DQ) DQ(MD_F, "f") @
define MD_FF "101" @
define D_FF(DQ) DQ(MD_FF, "ff") @
define MD_FFF "127" @
define D_FFF(DQ) DQ(MD_FFF, "fff") @
//ffff

// Define macros for setting dynamics.
// PV vs. MV is needed because MIDI needs each voice separately.

// MIDI-only dynamics
define XMDYN(MD_XX, MDX, MMV, MPOS) midi MMV: MPOS MD_XX(MDX) @
define MDYN(MD_XX0, MMV0, MPOS0) XMDYN(MD_XX0, DM_, MMV0, MPOS0) @
define PMDYN(MD_XX0, MMV0, MPOS0) XMDYN(MD_XX0, DP_, MMV0, MPOS0) @

// Score + MIDI dynamics
ifndef DYNFONT define DYNFONT boldital @ endif
ifndef DYNSIZE define DYNSIZE "+2" @ endif
define DYNSIZESTR "\s(" + DYNSIZE + ")" @
define XDYNN2(DN2_XX, DXX, DPV, DMV, DPOS)
XMDYN(DN2_XX, DXX, DMV, DPOS);
DYNFONT dyn DPV: DPOS DYNSIZESTR + DN2_XX(DT_) @
define DYNN2(DN2_XX, DPV_, DMV_, DPOS_) XDYNN2(DN2_XX, DM_, DPV_, DMV_, DPOS_)@
define DYN2(DN_XX, DPX_, DMX_) DYNN2(DN_XX, DPX_, DMX_, 1) @
// Vocal
define VDYNN2(VD_XX, VN_, VM_, VP_) DYNN2(VD_XX, above VN_, VM_, VP_) @
define VDYNN(VD_XX, VN_, VP_)       DYNN2(VD_XX, above VN_, VN_, VP_) @
define VDYN2(VD_XX, VN_, VM_)       DYN2(VD_XX, above VN_, VM_) @
define VDYN(VD_XX, VN_)             DYN2(VD_XX, above VN_, VN_) @
// Instrumental
define IDYNN2(ID_XX, VN_, VM_, VP_) DYNN2(ID_XX, below VN_, VM_, VP_) @
define IDYNN(ID_XX, VN_, VP_)       DYNN2(ID_XX, below VN_, VN_, VP_) @
define IDYN2(ID_XX, VN_, VM_)       DYN2(ID_XX, below VN_, VM_) @
define IDYN(ID_XX, VN_)             DYN2(ID_XX, below VN_, VN_) @

// Piano dynamics are extra messy.  By default, they go between two staves
// and affect all piano voices.
define BSRLH_ between SRH_ & SLH_ @
define VRH_ \
  ifdef PIANO_VOICES_RH PIANO_VOICES_RH else \
    ifdef VSCHEME_RH SRH_ else SRH_ 1 & SRH_ 2 endif endif @
define VLH_ \
  ifdef PIANO_VOICES_LH PIANO_VOICES_LH else \
    ifdef VSCHEME_LH SLH_ else SLH_ 1 & SLH_ 2 endif endif @

define PDYNN(PDN_XX, PDPOS)\
XDYNN2(PDN_XX, DM_, BSRLH_, VRH_ & VLH_, PDPOS) @
define PDYN(PD_XX) PDYNN(PD_XX, 1) @

define PLDYNN(PDN_XX, PDPOS)\
XDYNN2(PDN_XX, DM_, below SLH_, VLH_, PDPOS) @ // ****** WRONG ******
define PLDYN(PD_XX) PLDYNN(PD_XX, 1) @

define PRDYNN(PDN_XX, PDPOS)\
XDYNN2(PDN_XX, DM_, above SRH_, VRH_, PDPOS) @ // ****** WRONG ******
define PRDYN(PD_XX) PRDYNN(PD_XX, 1) @

// Piano crescendo/diminuendo
define PCRESC(WHERE) < BSRLH_: WHERE @
define PDIM(WHERE)   > BSRLH_: WHERE @

// Everything just said about the piano also applies to the harp.
define BSRLHH_ between SRHH_ & SLHH_ @
define VRHH_ ifdef HARP_VOICES_RH HARP_VOICES_RH else SRHH_ endif @
define VLHH_ ifdef HARP_VOICES_LH HARP_VOICES_LH else SLHH_ endif @

define HDYNN(HDN_XX, HDPOS)\
XDYNN2(HDN_XX, DM_, BSRLHH_, VRHH_ & VLHH_, HDPOS) @
define HDYN(HD_XX) HDYNN(HD_XX, 1) @

define HLDYNN(HDN_XX, HDPOS)\
XDYNN2(HDN_XX, DM_, below SLHH_, VLHH_, HDPOS) @ // ****** WRONG ******
define HLDYN(HD_XX) PLDYNN(HD_XX, 1) @

define HRDYNN(HDN_XX, HDPOS)\
XDYNN2(HDN_XX, DM_, above SRHH_, VRHH_, HDPOS) @ // ****** WRONG ******
define HRDYN(HD_XX) PRDYNN(HD_XX, 1) @

// Harp crescendo/diminuendo
define HCRESC(WHERE) < BSRLHH_: WHERE @
define HDIM(WHERE)   > BSRLHH_: WHERE @

// Two-instrument dynamics
define I2DX_(I2S_,I2SN_) \
  if I2S_ == I2SN_ then IDYNN2(I2DXX, V2N_, V2M_, V2P_); endif @
define I2AB_(I2ABVN_) if I2ABVN_ == 1 then above else below endif @
define I2D_(I2D_XX, V2N_, V2V_, V2ABV_, V2M_, V2P_) \
  ifdef PART \
    if PART_VOICE == V2V_ then USTAFFX(PART(IUN_\), I2DX_(ISN_\, V2N_\)) endif \
  else \
    DYNN2(I2D_XX, I2AB_(V2ABV_\) V2N_, V2M_, V2P_); \
  endif \
@
define I2DYNN2(ID_XX, VN_, VV_, VM_, VP_)\
  I2D_(ID_XX, VN_, VV_, VV_, VM_, VP_) @
define I2DYNN(ID_XX, VN_, VV_, VP_)\
  I2D_(ID_XX, VN_, VV_, VV_, VN_,VP_) @
define I2DYN2(ID_XX, VN_, VV_, VM_)\
  I2D_(ID_XX, VN_, VV_, VV_, VM_, 1) @
define I2DYN(ID_XX, VN_, VV_)\
  I2D_(ID_XX, VN_, VV_, VV_, VN_, 1) @
define I2DYNN21(ID_XX, VN_, VV_, VM_, VP_)\
  I2D_(ID_XX, VN_, VV_, 0, VM_, VP_) @
define I2DYNN1(ID_XX, VN_, VV_, VP_)\
  I2D_(ID_XX, VN_, VV_, 0, VN_,VP_) @
define I2DYN21(ID_XX, VN_, VV_, VM_)\
  I2D_(ID_XX, VN_, VV_, 0, VM_, 1) @
define I2DYN1(ID_XX, VN_, VV_)\
  I2D_(ID_XX, VN_, VV_, 0, VN_, 1) @

// Two-instrument crescendo/diminuendo
define I2CDX_(I2S_,I2SN_,I2BODY_) if I2S_ == I2SN_ then I2BODY_ endif @
define I2CD_(ICDX_,ICDSN_,ICDVN_,ICDABN_,ICDTIL_)\
  ifdef PART \
    if PART_VOICE == ICDVN_ then USTAFFX(PART(IUN_\), I2CDX_(ISN_\, ICDSN_\, ICDX_ below ICDSN_: ICDTIL_;\)) endif \
  else \
    ICDX_ I2AB_(ICDABN_) ICDSN_: ICDTIL_;\
  endif \
@
define I2CRESC(I2SN_,I2VN_,I2TIL_) I2CD_(<,I2SN_,I2VN_,I2VN_,I2TIL_) @
define I2DIM(I2SN_,I2VN_,I2TIL_)   I2CD_(>,I2SN_,I2VN_,I2VN_,I2TIL_) @
define I2CRESC1(I2SN_,I2VN_,I2TIL_)I2CD_(<,I2SN_,I2VN_,0,I2TIL_) @
define I2DIM1(I2SN_,I2VN_,I2TIL_)  I2CD_(>,I2SN_,I2VN_,0,I2TIL_) @

else					// LPDDEFS2_INCLUDED

undef FIRST

endif					// LPDDEFS2_INCLUDED
