diff --git a/Music/LilyPond/Light.hs b/Music/LilyPond/Light.hs
--- a/Music/LilyPond/Light.hs
+++ b/Music/LilyPond/Light.hs
@@ -1,639 +1,8 @@
-module Music.LilyPond.Light (module Music.LilyPond.Light
-                            ,module L) where
+module Music.LilyPond.Light (module L) where
 
-import Data.List
-import Data.Monoid
-import Data.Ratio
+import Music.LilyPond.Light.Annotation as L
 import Music.LilyPond.Light.Constant as L
-import Music.LilyPond.Light.Constant.NoteName as L
+import Music.LilyPond.Light.Measure as L
 import Music.LilyPond.Light.Model as L
+import Music.LilyPond.Light.Notation as L
 import Music.LilyPond.Light.Output.LilyPond as L
-import Music.Theory.Duration as L
-import Music.Theory.Duration.Name as L
-import Music.Theory.Key as L
-import Music.Theory.Pitch as L
-import Music.Theory.Pitch.Spelling
-
--- * Music category predicates
-
-is_music_c :: Music_C -> Music -> Bool
-is_music_c c = (==) c . music_c
-
-is_note :: Music -> Bool
-is_note = is_music_c Note_C
-
-is_chord :: Music -> Bool
-is_chord = is_music_c Chord_C
-
-is_rest :: Music -> Bool
-is_rest = is_music_c Rest_C
-
-is_mm_rest :: Music -> Bool
-is_mm_rest = is_music_c MMRest_C
-
-is_grace :: Music -> Bool
-is_grace = is_music_c Grace_C
-
-is_after_grace :: Music -> Bool
-is_after_grace = is_music_c AfterGrace_C
-
--- | These are required to avoid issues in lilypond (see manual)
-is_grace_skip :: Music -> Bool
-is_grace_skip m =
-    case m of
-      Grace (Skip _) -> True
-      _ -> False
-
-is_clef :: Music -> Bool
-is_clef = is_music_c Clef_C
-
-is_time :: Music -> Bool
-is_time = is_music_c Time_C
-
-is_tempo :: Music -> Bool
-is_tempo = is_music_c Tempo_C
-
-is_barlinecheck :: Music -> Bool
-is_barlinecheck m =
-    case m of
-      Command BarlineCheck -> True
-      _ -> False
-
-is_tied :: Music -> Bool
-is_tied m =
-    case m of
-      Note _ _ xs -> Begin_Tie `elem` xs
-      Chord _ _ xs -> Begin_Tie `elem` xs
-      _ -> False
-
-is_tuplet :: Music -> Bool
-is_tuplet = is_music_c Tuplet_C
-
--- * Pitch
-
--- | Add reminder accidental to note.
-r_acc :: Music -> Music
-r_acc x = x &rAcc
-
--- | Add cautionary accidental to note.
-c_acc :: Music -> Music
-c_acc x = x &cAcc
-
--- | Remove any reminder or cautionary accidentals at note or chord.
-clr_acc :: Music -> Music
-clr_acc m =
-    let rl = [rAcc,cAcc]
-    in case m of
-         Note x d a -> Note x d (a \\ rl)
-         Chord xs d a -> Chord (map clr_acc xs) d a
-         _ -> error ("clr_acc at non-note/chord: " ++ ly_music_elem m)
-
-octpc_to_note :: (Octave, PitchClass) -> Music
-octpc_to_note x = Note (octpc_to_pitch pc_spell_ks x) Nothing []
-
--- * Rests
-
--- | Construct rests.
-r :: Duration -> Music
-r x = Rest x []
-
--- | Multi-measure variant of 'r'.
-r' :: TimeSignature -> Music
-r' x = MMRest 1 x []
-
--- | Create an empty measure for the specified time signature.
-empty_measure :: Integer -> Integer -> Music
-empty_measure n d = mconcat [MMRest 1 (n,d) [], l]
-
--- | Like 'empty_measure', but with an invisible rest.
-null_measure :: Integer -> Integer -> Music
-null_measure n d =
-    let x = Duration d 0 1
-    in mconcat (map Skip (genericReplicate n x) ++ [l])
-
--- | Like 'empty_measure' but write time signature.
-measure_rest :: Integer -> Integer -> Music
-measure_rest n d = mconcat [time_signature (n,d), empty_measure n d]
-
--- | Like 'measure_rest' but write time signature.
-measure_null :: Integer -> Integer -> Music
-measure_null n d = mconcat [time_signature (n,d), null_measure n d]
-
--- * Measures
-
-type M_Annotation = Music
-data Measure = Measure [M_Annotation] [Music]
-
-m_annotate :: M_Annotation -> Measure -> Measure
-m_annotate a (Measure as xs) = Measure (as++[a]) xs
-
-m_annotate' :: [M_Annotation] -> Measure -> Measure
-m_annotate' as' (Measure as xs) = Measure (as++as') xs
-
-m_annotate_first' :: [M_Annotation] -> [Measure] -> [Measure]
-m_annotate_first' as xs =
-    case xs of
-      (x:xs') -> m_annotate' as x : xs'
-      [] -> error "m_annotate_first'"
-
-m_annotate_last' :: [M_Annotation] -> [Measure] -> [Measure]
-m_annotate_last' as xs =
-    case xs of
-      [] -> []
-      [x] -> [m_annotate' as x]
-      (x:xs') -> x : m_annotate_last' as xs'
-
-m_append :: [Music] -> Measure -> Measure
-m_append c (Measure as xs) = Measure as (xs++c)
-
-m_elements :: Measure -> [Music]
-m_elements (Measure as xs) = as ++ xs
-
-mm_elements :: [Measure] -> [Music]
-mm_elements = concat . map m_elements
-
--- * Tuplets
-
--- | Apply a 'Duration' function to a 'Music' node, if it has a duration.
-edit_dur :: (Duration -> Duration) -> Music -> Music
-edit_dur fn x =
-    case x of
-      Note _ Nothing _ -> x
-      Note n (Just d) a -> Note n (Just (fn d)) a
-      Chord n d a -> Chord n (fn d) a
-      Rest d a -> Rest (fn d) a
-      Skip d -> Skip (fn d)
-      _ -> x
-
--- | Temporal scaling of music (tuplets).
-tuplet :: Tuplet_T -> [Music] -> Music
-tuplet (d,n) =
-    let fn x = x { multiplier = n%d }
-    in Tuplet Normal_Tuplet (n,d) . mconcat . map (edit_dur fn)
-
--- | Tuplet variants that set location, and then restore to neutral.
-tuplet_above,tuplet_below :: Tuplet_T -> [Music] -> Music
-tuplet_above n xs = mconcat [tuplet_up, tuplet n xs, tuplet_neutral]
-tuplet_below n xs = mconcat [tuplet_down, tuplet n xs, tuplet_neutral]
-
--- | Like tuplet but does not annotate music, see also
---   'ts_set_fraction'.
-scale_durations :: Tuplet_T -> [Music] -> Music
-scale_durations (n,d) =
-    let fn x = x { multiplier = d%n }
-    in Tuplet Scale_Durations (n,d) . mconcat . map (edit_dur fn)
-
--- * Time signatures
-
--- | Construct time signature.
-time_signature :: TimeSignature -> Music
-time_signature = Time
-
--- | Allow proper auto-indenting of multiple measures with the same
---   time signature.
-with_time_signature :: TimeSignature -> [Music] -> Music
-with_time_signature ts xs = mconcat (time_signature ts : xs)
-
-{-
--- | Make a duration to fill a whole measure.
-ts_dur :: TimeSignature -> Duration
-ts_dur (n,d) = Duration d 0 (fromIntegral n)
--}
-
--- | Tied, non-multiplied durations to fill a whole measure.
-ts_whole_note :: TimeSignature -> [Duration]
-ts_whole_note t =
-    case t of
-      (1,2) -> [half_note]
-      (2,16) -> [eighth_note]
-      (2,8) -> [quarter_note]
-      (2,4) -> [half_note]
-      (2,2) -> [whole_note]
-      (3,16) -> [dotted_eighth_note]
-      (3,8) -> [dotted_quarter_note]
-      (3,4) -> [dotted_half_note]
-      (3,2) -> [dotted_whole_note]
-      (4,16) -> [quarter_note]
-      (4,8) -> [half_note]
-      (4,4) -> [whole_note]
-      (4,2) -> [breve]
-      (5,16) -> [quarter_note,sixteenth_note]
-      (5,8) -> [half_note,eighth_note]
-      (5,4) -> [whole_note,quarter_note]
-      (6,2) -> [dotted_breve]
-      _ -> error ("ts_whole_note: " ++ show t)
-
--- | Command to request that @4\/4@ and @2\/2@ etc. are typeset as
--- fractions.
-ts_use_fractions :: Music
-ts_use_fractions =
-    let x = "\\override Staff.TimeSignature #'style = #'()"
-    in Command (User x)
-
--- | Set the printed time-signature fraction.
-ts_set_fraction :: Integer -> Integer -> Music
-ts_set_fraction n d =
-    let x = "#'(" ++ show n ++ " . " ++ show d ++ ")"
-        y = "\\set Staff.timeSignatureFraction = " ++ x
-    in Command (User y)
-
-numeric_time_signature :: Music
-numeric_time_signature = Command (User "\\numericTimeSignature")
-
-ts_parentheses :: Music
-ts_parentheses =
-    let x = "\\override Staff.TimeSignature #'stencil = #(lambda (grob) (bracketify-stencil (ly:time-signature::print grob) Y 0.1 0.2 0.1))"
-    in Command (User x)
-
--- * Key signatures
-
--- | Construct key signature.
-key :: Music -> Mode_T -> Music
-key (Note (Pitch n a _) _ _) md = Key n (Just a) md
-key _ _ = error "key"
-
--- * Repetition
-
--- | Construct standard (two times) repeat.
-std_repeat :: Integer -> [Music] -> Music
-std_repeat n = Repeat n . mconcat
-
--- * Annotations
-
--- | Can a 'Music' element be annotated?
-allows_annotations :: Music -> Bool
-allows_annotations m =
-    is_note m ||
-    is_chord m ||
-    is_rest m ||
-    is_mm_rest m
-
--- | Attempt to add an 'Annotation' to a 'Music' element.
-add_annotation :: Annotation -> Music -> Maybe Music
-add_annotation a m =
-    case m of
-      Note n d as -> Just (Note n d (as ++ [a]))
-      Chord n d as -> Just (Chord n d (as ++ [a]))
-      Rest d as -> Just (Rest d (as ++ [a]))
-      MMRest i j as -> Just (MMRest i j (as ++ [a]))
-      _ -> Nothing
-
--- | Add an 'Annotation' to a 'Music' element or 'error'.
-add_annotation_err :: Annotation -> Music -> Music
-add_annotation_err a m =
-    case add_annotation a m of
-      Just m' -> m'
-      Nothing -> error ("add_annotation failed: " ++ show (a,ly_music_elem m))
-
--- | Infix form of 'add_annotation_err'.
-(&) :: Music -> Annotation -> Music
-m & a = add_annotation_err a m
-
--- | Add an 'Annotation' to a 'Pitch'.
-(&#) :: Pitch -> Annotation -> Music
-x &# y = Note x Nothing [y]
-
--- | Add an 'Annotation' to a 'Music' element.
-perhaps_annotate :: Annotation -> Music -> Music
-perhaps_annotate a m = maybe m id (add_annotation a m)
-
-bracket_annotation_fn :: (Annotation -> Music -> Music) ->
-                         (Annotation,Annotation) -> [Music] -> [Music]
-bracket_annotation_fn fn (begin, end) xs =
-    let x0 = head xs
-        xn = last xs
-        xs' = drop 1 (reverse (drop 1 (reverse xs)))
-        xs_e = show (map ly_music_elem xs)
-    in if length xs >= 2
-       then [fn begin x0] ++ xs' ++ [fn end xn]
-       else error ("bracket_annotation failed: " ++ xs_e)
-
-bracket_annotation :: (Annotation,Annotation) -> [Music] -> [Music]
-bracket_annotation = bracket_annotation_fn add_annotation_err
-
-bracket_annotation' :: (Annotation,Annotation) -> [Music] -> [Music]
-bracket_annotation' a x =
-    case x of
-      (_:_:_) -> bracket_annotation_fn perhaps_annotate a x
-      _ -> x
-
-beam' :: [Music] -> [Music]
-beam' = bracket_annotation (begin_beam, end_beam)
-
--- | Manual beaming.
-beam :: [Music] -> Music
-beam = mconcat . beam'
-
-slur' :: [Music] -> [Music]
-slur' = bracket_annotation (begin_slur, end_slur)
-
-slur :: [Music] -> Music
-slur = mconcat . slur'
-
-phrasing_slur' :: [Music] -> [Music]
-phrasing_slur' =
-    let a = (begin_phrasing_slur, end_phrasing_slur)
-    in bracket_annotation a
-
-phrasing_slur :: [Music] -> Music
-phrasing_slur = mconcat . phrasing_slur'
-
-text_above,text_below :: String -> Annotation
-text_above x = CompositeAnnotation [Above, Text x]
-text_below x = CompositeAnnotation [Below, Text x]
-
-arco,pizz :: Annotation
-arco = text_above "arco"
-pizz = text_above "pizz."
-
-stem_tremolo :: Integer -> Annotation
-stem_tremolo = Articulation . StemTremolo
-
-place_above,place_below :: Annotation -> Annotation
-place_above x = CompositeAnnotation [Above, x]
-place_below x = CompositeAnnotation [Below, x]
-
--- | Add an 'Annotation' to a @Note@ 'Music' element, else identity.
-note_annotate :: Annotation -> Music -> Music
-note_annotate a m =
-    case m of
-      Note n d xs -> Note n d (xs++[a])
-      _ -> m
-
--- | Annotate the first note/chord element.
-initial_note_chord_annotate :: Annotation -> [Music] -> [Music]
-initial_note_chord_annotate a m =
-    case m of
-      [] -> []
-      (x:xs) -> if is_note x || is_chord x
-                then x & a : xs
-                else x : initial_note_chord_annotate a xs
-
--- * Indirect annotations
-
-allows_indirect_annotation :: Music -> Bool
-allows_indirect_annotation m =
-    case m of
-      Grace x -> allows_indirect_annotation x
-      AfterGrace x _ -> allows_indirect_annotation x
-      Tuplet _ _ x -> allows_indirect_annotation x
-      Join (x:_) -> allows_indirect_annotation x
-      _ -> allows_annotations m
-
-indirect_annotation :: Annotation -> Music -> Music
-indirect_annotation a m =
-    case m of
-      Grace x -> Grace (indirect_annotation a x)
-      AfterGrace x1 x2 -> AfterGrace (indirect_annotation a x1) x2
-      Tuplet tm tt x -> Tuplet tm tt (indirect_annotation a x)
-      Join (x:xs) -> Join (indirect_annotation a x : xs)
-      _ -> m & a
-
-attach_indirect_annotation :: Annotation -> [Music] -> [Music]
-attach_indirect_annotation _ [] = error "attach_indirect_annotation"
-attach_indirect_annotation a (x:xs) =
-    if allows_indirect_annotation x
-    then indirect_annotation a x : xs
-    else x : attach_indirect_annotation a xs
-
--- * Octave
-
--- | Shift the octave of a note element, else identity.
-note_edit_octave :: (Integer -> Integer) -> Music -> Music
-note_edit_octave fn m =
-    case m of
-      Note (Pitch n a o) d xs -> Note (Pitch n a (fn o)) d xs
-      _ -> m
-
--- | Shift the octave of a note element, else identity.
-note_shift_octave :: Integer -> Music -> Music
-note_shift_octave i = note_edit_octave (+ i)
-
--- * Beaming
-
--- | Predicate combinators.
-p_or, p_and :: (t -> Bool) -> (t -> Bool) -> t -> Bool
-p_or p1 p2 = \x -> p1 x || p2 x
-p_and p1 p2 = \x -> p1 x && p2 x
-
--- | Variant of 'span' that further spans the reverse of the right
--- hand side.
---
---  > span_r (< 0) [-1,-2,1,2,3,-3,-4] == ([-1,-2],[1,2,3],[-3,-4])
-span_r :: (a -> Bool) -> [a] -> ([a], [a], [a])
-span_r fn xs =
-    let (o1,o2) = span fn xs
-        (o3,o4) = span fn (reverse o2)
-    in (o1,reverse o4, reverse o3)
-
--- | Beam if at least two elements.
-perhaps_beam :: [Music] -> [Music]
-perhaps_beam xs =
-    case xs of
-      [] -> []
-      [x] -> [x]
-      _ -> beam' xs
-
--- | Beam interior notes/chords (ie. skip exterior
---   non-note/non-chords).
-beam_notes :: [Music] -> Music
-beam_notes xs =
-    let (x1,x2,x3) = span_r (not . p_or is_note is_chord) xs
-    in mconcat (x1 ++ perhaps_beam x2 ++ x3)
-
--- 2.13.29 (Issue #1083)
-set_subdivide_beams :: Integer -> Music
-set_subdivide_beams i =
-    let x0 = "\\set subdivideBeams = ##t"
-        x1 = "\\set baseMoment = #(ly:make-moment 1 " ++ show i ++ ")"
-    in mconcat [Command (User x0), Command (User x1)]
-
--- * Duration
-
--- | Add 'Duration' to 'Pitch' to make a @Note@ 'Music' element.
-(##) :: Pitch -> Duration -> Music
-x ## d = Note x (Just d) []
-
--- | Add 'Duration' to either a @Note@ or @Chord@ 'Music' element.
-(#) :: Music -> Duration -> Music
-x # d =
-    case x of
-      Note n _ a -> Note n (Just d) a
-      Chord n _ a -> Chord n d a
-      _ -> error ("##: " ++ show x)
-
--- * Chords
-
--- | Construct chord.
-chd_p :: [Pitch] -> Duration -> Music
-chd_p [] _ = error "chd_p: null elements"
-chd_p xs d = Chord (map (\x -> Note x Nothing []) xs) d []
-
-chd :: [Music] -> Duration -> Music
-chd [] _ = error "chd: null elements"
-chd xs d =
-    let fn x =
-            let err msg = error (msg ++ ": " ++ show x)
-            in case x of
-              Note _ (Just _) _ -> err "chd: note has duration"
-              Note _ Nothing _ -> x
-              _ -> err "chd: non note element"
-    in Chord (map fn xs) d []
-
--- * Commands
-
--- | Construct bar number check command.
-bar_number_check :: Integer -> Music
-bar_number_check = Command . BarNumberCheck
-
--- | Change staff.
-change :: String -> Music
-change x = Command (Change x)
-
--- | Indicate initial partial measure.
-partial :: Duration -> Music
-partial = Command . Partial
-
--- | Set or unset the @circled-tip@ hairpin attribute.
-hairpin_circled_tip :: Bool -> Music
-hairpin_circled_tip x =
-    let c = if x
-            then "\\override Hairpin #'circled-tip = ##t"
-            else "\\revert Hairpin #'circled-tip"
-    in Command (User c)
-
--- | Set or unset the @to-barline@ hairpin attribute.
-hairpin_to_barline :: Bool -> Music
-hairpin_to_barline x =
-    let c = if x
-            then "\\revert Hairpin #'to-barline"
-            else "\\override Hairpin #'to-barline = ##f"
-    in Command (User c)
-
--- * Staff and Parts
-
-name_to_id :: Staff_Name -> Staff_ID
-name_to_id (x,_) =
-    case x of
-      "" -> "no_id"
-      _ -> "id_" ++ x
-
--- | Construct staff.
-staff :: Staff_Name -> [Music] -> Staff
-staff nm =
-    let st = Staff_Settings Normal_Staff (name_to_id nm) 0
-    in Staff st nm . Part Nothing
-
--- | Construct rhythmic staff.
-rhythmic_staff :: Staff_Name -> [Music] -> Staff
-rhythmic_staff nm =
-    let st = Staff_Settings Rhythmic_Staff (name_to_id nm) 0
-    in Staff st nm . Part Nothing
-
--- | Construct staff with text underlay.
-text_staff :: Staff_Name -> String -> [Music] -> Staff
-text_staff nm txt =
-    let st = Staff_Settings Normal_Staff (name_to_id nm) 0
-    in Staff st nm . Part (Just txt)
-
--- | Construct piano staff.  For two staff piano music the staffs have
---   identifiers rh and lh.
-piano_staff :: Staff_Name -> [[Music]] -> Staff
-piano_staff nm [rh,lh] =
-    let st x = Staff_Settings Normal_Staff x 0
-    in Staff_Set
-       PianoStaff
-       nm
-       [Staff (st "rh") ("","") (Part Nothing rh)
-       ,Staff (st "lh") ("","") (Part Nothing lh)]
-piano_staff nm xs =
-    Staff_Set PianoStaff nm (map (staff ("","")) xs)
-
-grand_staff :: Staff_Name -> [[Music]] -> Staff
-grand_staff nm = Staff_Set GrandStaff nm . map (staff ("",""))
-
-staff_group :: Staff_Name -> [[Music]] -> Staff
-staff_group nm = Staff_Set StaffGroup nm . map (staff ("",""))
-
-rhythmic_grand_staff :: Staff_Name -> [[Music]] -> Staff
-rhythmic_grand_staff nm = Staff_Set GrandStaff nm . map (rhythmic_staff ("",""))
-
--- | Variant with names for each staff.
-grand_staff' :: Staff_Name -> [Staff_Name] -> [[Music]] -> Staff
-grand_staff' nm xs ys = Staff_Set GrandStaff nm (zipWith staff xs ys)
-
-staff_group' :: Staff_Name -> [Staff_Name] -> [[Music]] -> Staff
-staff_group' nm xs ys = Staff_Set StaffGroup nm (zipWith staff xs ys)
-
-two_part_staff :: Staff_Name -> ([Music], [Music]) -> Staff
-two_part_staff nm (p0, p1) =
-    let st = Staff_Settings Normal_Staff (name_to_id nm) 0
-    in Staff st nm (MultipleParts [voice_one:p0
-                                  ,voice_two:p1])
-
-instr_name :: Staff_Name -> Staff -> Staff
-instr_name nm pt =
-    case pt of
-      Staff st _ x -> Staff st nm x
-      Staff_Set ty _ xs -> Staff_Set ty nm xs
-
-resize_staff :: Int -> Staff -> Staff
-resize_staff n st =
-    case st of
-      Staff (Staff_Settings ty i sc) nm pt ->
-          Staff (Staff_Settings ty i (sc + n)) nm pt
-      Staff_Set ty nm xs ->
-          Staff_Set ty nm (map (resize_staff n) xs)
-
-score :: [Staff] -> Score
-score = Score default_score_settings
-
--- * Aliases
-
-tempo :: Duration -> Integer -> Music
-tempo = Tempo
-
-after_grace :: Music -> Music -> Music
-after_grace = AfterGrace
-
-grace :: Music -> Music
-grace = Grace
-
-tremolo :: (Music, Music) -> Integer -> Music
-tremolo = Tremolo
-
--- | Interior polyphony.  For two part music on one staff see
---   'two_part_staff'.
-polyphony :: Music -> Music -> Music
-polyphony = Polyphony
-
-polyphony' :: [Music] -> [Music] -> Music
-polyphony' x y = polyphony (mconcat x) (mconcat y)
-
--- * Noteheads
-
--- | Request cross note-heads.
-cross_noteheads :: Music
-cross_noteheads =
-    Command (User "\\override NoteHead #'style = #'cross")
-
--- | Revert to standard note-heads.
-revert_noteheads :: Music
-revert_noteheads =
-    Command (User "\\revert NoteHead #'style")
-
--- * Rests
-
--- | Joins directly adjacent rest elements.
-join_rests :: [Music] -> [Music]
-join_rests =
-    let fn recur xs =
-            case xs of
-              [] -> []
-              Rest d a : Rest d' a' : ys ->
-                  case sum_dur d d' of
-                    Nothing -> let zs = Rest d a : join_rests (Rest d' a' : ys)
-                               in if recur then fn False zs else zs
-                    Just d'' -> join_rests (Rest d'' (a ++ a') : ys)
-              y:ys -> y : join_rests ys
-    in fn True
diff --git a/Music/LilyPond/Light/Analysis.hs b/Music/LilyPond/Light/Analysis.hs
--- a/Music/LilyPond/Light/Analysis.hs
+++ b/Music/LilyPond/Light/Analysis.hs
@@ -8,11 +8,11 @@
 import Data.Ratio
 import qualified Music.LilyPond.Light as L
 import Music.LilyPond.Light.Model
-import Music.Theory.Duration
+import Music.Theory.Duration {- hmt -}
 import Music.Theory.Pitch
 import qualified Music.Theory.Pitch.Spelling as T
-
-type R = Double
+import Music.Theory.Tempo_Marking
+import Music.Theory.Time_Signature
 
 -- * Basic traversal
 
@@ -55,7 +55,7 @@
     case m of
       (Note x _ _) -> [x]
       (Chord xs _ _) -> concatMap collect_pitches xs
-      (Skip _) -> []
+      (Skip _ _) -> []
       (Join xs) -> concatMap collect_pitches xs
       _ -> error ("collect_pitches_no_grace: " ++ L.ly_music_elem m)
 
@@ -81,41 +81,11 @@
 freq_anal :: (Ord a) => [a] -> [(Int,a)]
 freq_anal = freq_anal_by compare
 
--- * Durations
-
-type TempoMarking = (Duration,Integer)
-
--- | Apply `d' dots to the rational pulse count `n'.
-apply_dots :: Rational -> Integer -> Rational
-apply_dots n d =
-    let m = map (\x -> n * (1 / fromInteger (2 ^ x))) [1..d]
-    in n + sum m
-
--- | Convert a duration to a pulse count in relation to the indicated
---   time signature.
-dur_pulses :: TimeSignature -> Duration -> Rational
-dur_pulses (_, b) (Duration dv dt ml) =
-    let n = b % dv
-    in apply_dots n dt * ml
-
--- | The duration, in seconds, of a pulse at the indicated time
---   signaure and tempo marking.
-pulse_duration :: TimeSignature -> TempoMarking -> R
-pulse_duration t (x,i) =
-    let j = recip (dur_pulses t x)
-        s = 60 / fromIntegral i
-    in fromRational j * s
-
--- | The duration, in seconds, of a measure at the indicated time
---   signaure and tempo marking.
-measure_duration :: TimeSignature -> TempoMarking -> R
-measure_duration (n,d) t = pulse_duration (n,d) t * fromIntegral n
-
 -- * Temporal map
 
-type TimeSignature_Map = [(Measure,TimeSignature)]
-type TempoMarking_Map = [(Measure,TempoMarking)]
-type Temporal_Map = (TimeSignature_Map,TempoMarking_Map)
+type Time_Signature_Map = [(Measure,Time_Signature)]
+type Tempo_Marking_Map = [(Measure,Tempo_Marking)]
+type Temporal_Map = (Time_Signature_Map,Tempo_Marking_Map)
 
 temporal_map :: [Music] -> Temporal_Map
 temporal_map xs =
@@ -124,7 +94,7 @@
     in (ts_m,tm_m)
 
 -- | Return duration (in seconds) and pulse counts for n measures.
-mm_durations :: Temporal_Map -> Integer -> [(R,Integer)]
+mm_durations :: Temporal_Map -> Integer -> [(Rational,Integer)]
 mm_durations (ts_m,tm_m) n =
     let get = map_lookup
         fn xs i = if i == n
@@ -142,17 +112,17 @@
 
 -- | Return start time and duration (in seconds) and pulse counts for
 --   i measures.
-mm_start_times :: Temporal_Map -> Integer -> [(R,R,Integer)]
+mm_start_times :: Temporal_Map -> Integer -> [(Rational,Rational,Integer)]
 mm_start_times tm i =
     let (x,y) = unzip (mm_durations tm i)
     in zip3 (0 : integrate x) x y
 
-location_to_rt :: [(R,R,Integer)] -> Location -> R
+location_to_rt :: [(Rational,Rational,Integer)] -> Location -> Rational
 location_to_rt mm l =
     let (x,y,z) = mm `genericIndex` measure l
     in x + ((fromRational (pulse l) / fromIntegral z) * y)
 
-locate_rt :: [Music] -> [(R,Music)]
+locate_rt :: [Music] -> [(Rational,Music)]
 locate_rt xs =
     let l = locate' xs
         m = temporal_map xs
@@ -178,7 +148,7 @@
                 deriving (Show, Eq, Ord)
 
 -- | Convert a location to normal form under given time signature.
-location_nf :: TimeSignature -> Location -> Location
+location_nf :: Time_Signature -> Location -> Location
 location_nf ts l =
     let (Location b p v m) = l
         (n, _) = ts
@@ -188,7 +158,7 @@
        else l
 
 -- | Type to thread state through location calculations.
-type Locate_ST = (TimeSignature, Location)
+type Locate_ST = (Time_Signature, Location)
 
 -- | Update state part number.
 st_set_part :: Locate_ST -> Part_ID -> Locate_ST
@@ -207,7 +177,7 @@
 location_step st d =
     let (ts, l) = st
         (Location b p v m) = l
-        p' = p + dur_pulses ts d
+        p' = p + ts_duration_pulses ts d
         l' = location_nf ts (Location b p' v m)
     in (ts, l')
 
@@ -225,13 +195,13 @@
         this = (l,m)
     in case m of
          Note _ (Just d) _ -> (location_step st d, [this])
-         Note _ _ _ -> error "locate_st: note without duration"
+         Note {} -> error "locate_st: note without duration"
          Chord _ d _ -> (location_step st d, [this])
          Tremolo _ _ -> error "locate_st: Tremolo"
          Rest d _ -> (location_step st d, [this])
          MMRest i (j,k) _ -> let d = Duration k 0 ((i * j) % 1)
                              in (location_step st d, [this])
-         Skip d -> (location_step st d, [this])
+         Skip d _ -> (location_step st d, [this])
          Repeat _ x -> locate_st st x
          Tuplet _ _ x ->
              let st' = (ts, l { mode = LM_In_Tuplet })
@@ -244,11 +214,11 @@
          Join xs ->
              let (st', r) = mapAccumL locate_st st xs
              in (st', concat r)
-         Clef _ _ -> (st, [this])
+         Clef _ -> (st, [this])
          Time ts' -> ((ts', l), [this])
-         Key _ _ _ -> (st, [this])
+         Key {} -> (st, [this])
          Tempo _ _ -> (st, [this])
-         Command _ -> (st, [this])
+         Command _ _ -> (st, [this])
          Polyphony x0 x1 ->
               let (Location _ _ v _) = l
                   st' = map (st_set_part st) [v ..]
@@ -330,39 +300,20 @@
 
 -- * Time-signature structure analysis.
 
--- | Rewrite time signature to indicated denominator.
-ts_rewrite :: Integer -> TimeSignature -> TimeSignature
-ts_rewrite d' =
-    let dv i j = let (x,y) = i `divMod` j
-                 in if y == 0 then x else error "ts_rewrite"
-        go (n,d) = case compare d d' of
-                     EQ -> (n,d)
-                     GT -> go (n `dv` 2, d `dv` 2)
-                     LT -> go (n * 2, d * 2)
-    in go
-
--- | Sum time signatures (ie. 3/16 and 1/2 sum to 11/16).
-ts_sum :: [TimeSignature] -> TimeSignature
-ts_sum xs =
-    let i = maximum (map snd xs)
-        xs' = map (ts_rewrite i) xs
-        j = sum (map fst xs')
-    in (j,i)
-
 measure_diff :: Location -> Location -> Integer
 measure_diff l1 l2 = measure l2 - measure l1
 
 lv_last_measure :: [LV a] -> Measure
 lv_last_measure =
     let fn = compare `on` measure
-    in measure . last . sortBy fn . map fst
+    in measure . maximumBy fn . map fst
 
-time_unpack :: Music -> TimeSignature
+time_unpack :: Music -> Time_Signature
 time_unpack (Time t) = t
 time_unpack _ = error "time_unpack"
 
 -- | Time signature structure of music.
-ts_structure :: Music -> [[(TimeSignature, Integer)]]
+ts_structure :: Music -> [[(Time_Signature, Integer)]]
 ts_structure m =
     let m' = locate m
         ts = filter (L.is_time . snd) m'
@@ -373,7 +324,7 @@
         f (l1, t1) (l2, _) = (t1, measure_diff l1 l2)
     in map (\ys -> zipWith f ys (tail ys) ++ [e ys]) ps
 
-ts_structure' :: [Music] -> [[(TimeSignature, Integer)]]
+ts_structure' :: [Music] -> [[(Time_Signature, Integer)]]
 ts_structure' = ts_structure . mconcat
 
 structure_unfold' :: (Integral i) => [(a,i)] -> [a]
@@ -386,12 +337,12 @@
     let repl = genericReplicate
     in concatMap (\(x,n) -> Just x : repl (n - 1) Nothing)
 
-lm_ts_map :: [LM] -> TimeSignature_Map
+lm_ts_map :: [LM] -> Time_Signature_Map
 lm_ts_map xs =
     let xs' = filter (L.is_time . snd) xs
     in map (measure *** time_unpack) xs'
 
-ts_map :: [Music] -> TimeSignature_Map
+ts_map :: [Music] -> Time_Signature_Map
 ts_map = lm_ts_map . locate'
 
 -- | Keys are in ascending order, the value retrieved is the that with
@@ -406,22 +357,22 @@
          [(j,x)] -> if i >= j then x else error "map_lookup"
          _ -> fn (error "map_lookup") mp
 
-ts_lookup :: [(Measure,TimeSignature)] -> Measure -> TimeSignature
+ts_lookup :: [(Measure,Time_Signature)] -> Measure -> Time_Signature
 ts_lookup = map_lookup
 
 -- * Tempo
 
-lm_tempo_map :: [LM] -> [(Measure,(Duration,Integer))]
+lm_tempo_map :: [LM] -> [(Measure,Tempo_Marking)]
 lm_tempo_map =
     let f (t,i) = case i of
                     Tempo d x -> Just (measure t,(d,x))
                     _ -> Nothing
     in mapMaybe f
 
-tempo_map :: [Music] -> [(Measure,(Duration,Integer))]
+tempo_map :: [Music] -> [(Measure,Tempo_Marking)]
 tempo_map = lm_tempo_map . locate'
 
-tempo_lookup :: [(Measure,(Duration,Integer))] -> Measure -> (Duration,Integer)
+tempo_lookup :: [(Measure,Tempo_Marking)] -> Measure -> Tempo_Marking
 tempo_lookup = map_lookup
 
 -- * Key/value utilties
@@ -569,9 +520,9 @@
     let fn keep ns =
             case ns of
               (x:xs) -> let i = if keep then [x] else []
-                        in if i_pr x || (not keep && f_pr x)
-                           then i ++ fn False xs
-                           else i ++ fn True xs
+                        in i ++ if i_pr x || (not keep && f_pr x)
+                                then fn False xs
+                                else fn True xs
               _ -> ns
     in fn True
 
@@ -623,4 +574,3 @@
       Chord [] _ _ -> ["empty chord"]
       Chord xs _ _ -> mapMaybe v_chord_note_valid xs
       _ -> []
-
diff --git a/Music/LilyPond/Light/Annotation.hs b/Music/LilyPond/Light/Annotation.hs
new file mode 100644
--- /dev/null
+++ b/Music/LilyPond/Light/Annotation.hs
@@ -0,0 +1,215 @@
+module Music.LilyPond.Light.Annotation where
+
+import Data.Maybe
+import Data.Monoid
+import Music.LilyPond.Light.Constant
+import Music.LilyPond.Light.Model
+import Music.LilyPond.Light.Notation
+import Music.LilyPond.Light.Output.LilyPond
+import Music.Theory.Pitch {- hmt -}
+
+-- | Can a 'Music' element be annotated?  'Skip' and 'Command' do not
+-- ordinarily allow annotations, though there are some cases...
+allows_annotations :: Music -> Bool
+allows_annotations m =
+    is_note m ||
+    is_chord m ||
+    is_rest m ||
+    is_mm_rest m
+ -- is_skip m ||
+ -- is_command m ||
+
+-- | Attempt to add an 'Annotation' to a 'Music' element.
+add_annotation :: Annotation -> Music -> Maybe Music
+add_annotation a m =
+    case m of
+      Note n d as -> Just (Note n d (as ++ [a]))
+      Chord n d as -> Just (Chord n d (as ++ [a]))
+      Rest d as -> Just (Rest d (as ++ [a]))
+      Skip d as -> Just (Skip d (as ++ [a]))
+      MMRest i j as -> Just (MMRest i j (as ++ [a]))
+      Command c as -> Just (Command c (as ++ [a]))
+      _ -> Nothing
+
+-- | Add an 'Annotation' to a 'Music' element or 'error'.
+add_annotation_err :: Annotation -> Music -> Music
+add_annotation_err a m =
+    let err = error ("add_annotation: " ++ show (a,ly_music_elem m))
+    in fromMaybe err (add_annotation a m)
+
+-- | Infix form of 'add_annotation_err'.
+(&) :: Music -> Annotation -> Music
+m & a = add_annotation_err a m
+
+-- | Add an 'Annotation' to a 'Pitch'.
+(&#) :: Pitch -> Annotation -> Music
+x &# y = Note x Nothing [y]
+
+-- | Add an 'Annotation' to a 'Music' element.
+perhaps_annotate :: Annotation -> Music -> Music
+perhaps_annotate a m = fromMaybe m (add_annotation a m)
+
+bracket_annotation_fn :: (Annotation -> Music -> Music) ->
+                         (Annotation,Annotation) -> [Music] -> [Music]
+bracket_annotation_fn fn (begin, end) xs =
+    let x0 = head xs
+        xn = last xs
+        xs' = drop 1 (reverse (drop 1 (reverse xs)))
+        xs_e = show (map ly_music_elem xs)
+    in if length xs >= 2
+       then [fn begin x0] ++ xs' ++ [fn end xn]
+       else error ("bracket_annotation failed: " ++ xs_e)
+
+bracket_annotation :: (Annotation,Annotation) -> [Music] -> [Music]
+bracket_annotation = bracket_annotation_fn add_annotation_err
+
+bracket_annotation' :: (Annotation,Annotation) -> [Music] -> [Music]
+bracket_annotation' a x =
+    case x of
+      (_:_:_) -> bracket_annotation_fn perhaps_annotate a x
+      _ -> x
+
+beam' :: [Music] -> [Music]
+beam' = bracket_annotation (begin_beam, end_beam)
+
+-- | Manual beaming.
+beam :: [Music] -> Music
+beam = mconcat . beam'
+
+slur' :: [Music] -> [Music]
+slur' = bracket_annotation (begin_slur, end_slur)
+
+slur :: [Music] -> Music
+slur = mconcat . slur'
+
+phrasing_slur' :: [Music] -> [Music]
+phrasing_slur' =
+    let a = (begin_phrasing_slur, end_phrasing_slur)
+    in bracket_annotation a
+
+phrasing_slur :: [Music] -> Music
+phrasing_slur = mconcat . phrasing_slur'
+
+text_above,text_below,text_mark :: String -> Annotation
+text_above x = CompositeAnnotation [Place_Above, Text Text_Plain x]
+text_below x = CompositeAnnotation [Place_Below, Text Text_Plain x]
+text_mark x = CompositeAnnotation [Text_Mark, Text Text_Plain x]
+
+text_above_fmt,text_below_fmt,text_mark_fmt :: String -> Annotation
+text_above_fmt x = CompositeAnnotation [Place_Above,Text Text_Markup x]
+text_below_fmt x = CompositeAnnotation [Place_Below,Text Text_Markup x]
+text_mark_fmt x = CompositeAnnotation [Text_Mark, Text Text_Markup x]
+
+arco,pizz :: Annotation
+arco = text_above "arco"
+pizz = text_above "pizz."
+
+place_above,place_below :: Annotation -> Annotation
+place_above x = CompositeAnnotation [Place_Above, x]
+place_below x = CompositeAnnotation [Place_Below, x]
+
+-- | Add an 'Annotation' to a @Note@ 'Music' element, else identity.
+note_annotate :: Annotation -> Music -> Music
+note_annotate a m =
+    case m of
+      Note n d xs -> Note n d (xs++[a])
+      _ -> m
+
+-- | Annotate the first note/chord element.
+initial_note_chord_annotate :: Annotation -> [Music] -> [Music]
+initial_note_chord_annotate a m =
+    case m of
+      [] -> []
+      (x:xs) -> if is_note x || is_chord x
+                then x & a : xs
+                else x : initial_note_chord_annotate a xs
+
+-- * Indirect annotations
+
+allows_indirect_annotation :: Music -> Bool
+allows_indirect_annotation m =
+    case m of
+      Grace x -> allows_indirect_annotation x
+      AfterGrace x _ -> allows_indirect_annotation x
+      Tuplet _ _ x -> allows_indirect_annotation x
+      Join (x:_) -> allows_indirect_annotation x
+      _ -> allows_annotations m
+
+indirect_annotation :: Annotation -> Music -> Music
+indirect_annotation a m =
+    case m of
+      Grace x -> Grace (indirect_annotation a x)
+      AfterGrace x1 x2 -> AfterGrace (indirect_annotation a x1) x2
+      Tuplet tm tt x -> Tuplet tm tt (indirect_annotation a x)
+      Join (x:xs) -> Join (indirect_annotation a x : xs)
+      _ -> m & a
+
+attach_indirect_annotation :: Annotation -> [Music] -> [Music]
+attach_indirect_annotation a m =
+    case m of
+      [] -> error "attach_indirect_annotation"
+      x:xs -> if allows_indirect_annotation x
+              then indirect_annotation a x : xs
+              else x : attach_indirect_annotation a xs
+
+-- * Pitch
+
+-- | Add reminder accidental to note.
+r_acc :: Music -> Music
+r_acc x = x &rAcc
+
+-- | Add cautionary accidental to note.
+c_acc :: Music -> Music
+c_acc x = x &cAcc
+
+-- * Beaming
+
+-- * Beaming
+
+-- | Predicate composition.
+p_cmp :: (t1 -> t2 -> t) -> (t3 -> t1) -> (t3 -> t2) -> t3 -> t
+p_cmp fn p1 p2 x = p1 x `fn` p2 x
+
+-- | Predicate composition (or).
+--
+-- > p_or even odd 1 == True
+p_or :: (t -> Bool) -> (t -> Bool) -> t -> Bool
+p_or = p_cmp (||)
+
+-- | Predicate composition (and).
+--
+-- > p_and even odd 1 == False
+p_and :: (t -> Bool) -> (t -> Bool) -> t -> Bool
+p_and = p_cmp (&&)
+
+-- | Variant of 'span' that further spans the reverse of the right
+-- hand side.
+--
+--  > span_r (< 0) [-1,-2,1,2,3,-3,-4] == ([-1,-2],[1,2,3],[-3,-4])
+span_r :: (a -> Bool) -> [a] -> ([a], [a], [a])
+span_r fn xs =
+    let (o1,o2) = span fn xs
+        (o3,o4) = span fn (reverse o2)
+    in (o1,reverse o4, reverse o3)
+
+-- | Beam if at least two elements.
+perhaps_beam :: [Music] -> [Music]
+perhaps_beam xs =
+    case xs of
+      [] -> []
+      [x] -> [x]
+      _ -> beam' xs
+
+-- | Beam interior notes/chords (ie. skip exterior
+--   non-note/non-chords).
+beam_notes :: [Music] -> Music
+beam_notes xs =
+    let (x1,x2,x3) = span_r (not . p_or is_note is_chord) xs
+    in mconcat (x1 ++ perhaps_beam x2 ++ x3)
+
+-- 2.13.29 (Issue #1083)
+set_subdivide_beams :: Integer -> Music
+set_subdivide_beams i =
+    let x0 = "\\set subdivideBeams = ##t"
+        x1 = "\\set baseMoment = #(ly:make-moment 1 " ++ show i ++ ")"
+    in mconcat [Command (User x0) [], Command (User x1) []]
diff --git a/Music/LilyPond/Light/Constant.hs b/Music/LilyPond/Light/Constant.hs
--- a/Music/LilyPond/Light/Constant.hs
+++ b/Music/LilyPond/Light/Constant.hs
@@ -1,30 +1,12 @@
+-- | Notation related constants.
 module Music.LilyPond.Light.Constant where
 
 import Music.LilyPond.Light.Model
+import qualified Music.Theory.Clef as C {- hmt -}
+import Music.Theory.Duration
 
 -- * Annotations
 
-pppp,ppp,pp,p,mp,mf,f,ff,fff,ffff,fp,sfz :: Annotation
-pppp = Dynamic PPPP
-ppp = Dynamic PPP
-pp = Dynamic Pianissimo
-p = Dynamic Piano
-mp = Dynamic MezzoPiano
-mf = Dynamic MezzoForte
-f = Dynamic Forte
-ff = Dynamic Fortissimo
-fff = Dynamic FFF
-ffff = Dynamic FFFF
-fp = Dynamic FP
-sfz = Dynamic SFZ
-
-cresc,decr,end_cresc,end_decr,espressivo ::Annotation
-cresc = Dynamic Begin_Crescendo
-decr = Dynamic Begin_Decrescendo
-end_cresc = Dynamic End_Dynamic
-end_decr = Dynamic End_Dynamic
-espressivo = Dynamic Espressivo
-
 arpeggio,fermata,flageolet,harmonic,laissezVibrer,glissando :: Annotation
 arpeggio = Articulation Arpeggio
 fermata = Articulation Fermata
@@ -39,63 +21,66 @@
 tenuto = Articulation Tenuto
 accent = Articulation Accent
 
+stem_tremolo :: Integer -> Annotation
+stem_tremolo = Articulation . StemTremolo
+
 -- * Clefs
 
 bass_clef,tenor_clef,alto_clef,treble_clef,percussion_clef :: Music
-bass_clef = Clef Bass 0
-tenor_clef = Clef Tenor 0
-alto_clef = Clef Alto 0
-treble_clef = Clef Treble 0
-percussion_clef = Clef Percussion 0
+bass_clef = Clef (C.Clef C.Bass 0)
+tenor_clef = Clef (C.Clef C.Tenor 0)
+alto_clef = Clef (C.Clef C.Alto 0)
+treble_clef = Clef (C.Clef C.Treble 0)
+percussion_clef = Clef (C.Clef C.Percussion 0)
 
 bass_8vb_clef,treble_8va_clef,treble_8vb_clef,treble_15ma_clef :: Music
-bass_8vb_clef = Clef Bass (-1)
-treble_8va_clef = Clef Treble 1
-treble_8vb_clef = Clef Treble (-1)
-treble_15ma_clef = Clef Treble 2
+bass_8vb_clef = Clef (C.Clef C.Bass (-1))
+treble_8va_clef = Clef (C.Clef C.Treble 1)
+treble_8vb_clef = Clef (C.Clef C.Treble (-1))
+treble_15ma_clef = Clef (C.Clef C.Treble 2)
 
 -- * Commands
 
-l :: Music
-l = Command BarlineCheck
+bar_line_check :: Music
+bar_line_check = Command BarlineCheck []
 
 double_barline,final_barline :: Music
-double_barline = Command (Bar DoubleBarline)
-final_barline = Command (Bar FinalBarline)
+double_barline = Command (Bar DoubleBarline) []
+final_barline = Command (Bar FinalBarline) []
 
 system_break,no_system_break :: Music
-system_break = Command Break
-no_system_break = Command NoBreak
+system_break = Command Break []
+no_system_break = Command NoBreak []
 
 page_break,no_page_break :: Music
-page_break = Command PageBreak
-no_page_break = Command NoPageBreak
+page_break = Command PageBreak []
+no_page_break = Command NoPageBreak []
 
 auto_beam_off :: Music
-auto_beam_off = Command AutoBeamOff
+auto_beam_off = Command AutoBeamOff []
 
 tuplet_down,tuplet_neutral,tuplet_up :: Music
-tuplet_down = Command TupletDown
-tuplet_neutral = Command TupletNeutral
-tuplet_up = Command TupletUp
+tuplet_down = Command TupletDown []
+tuplet_neutral = Command TupletNeutral []
+tuplet_up = Command TupletUp []
 
 voice_one,voice_two :: Music
-voice_one = Command VoiceOne
-voice_two = Command VoiceTwo
+voice_one = Command VoiceOne []
+voice_two = Command VoiceTwo []
 
 stem_down,stem_neutral,stem_up :: Music
-stem_down = Command StemDown
-stem_neutral = Command StemNeutral
-stem_up = Command StemUp
+stem_down = Command StemDown []
+stem_neutral = Command StemNeutral []
+stem_up = Command StemUp []
 
 dynamic_down,dynamic_neutral,dynamic_up :: Music
-dynamic_down = Command DynamicDown
-dynamic_neutral = Command DynamicNeutral
-dynamic_up = Command DynamicUp
+dynamic_down = Command DynamicDown []
+dynamic_neutral = Command DynamicNeutral []
+dynamic_up = Command DynamicUp []
 
 begin_8va,end_8va :: Music
-begin_8va = Command (Octavation 1)
-end_8va = Command (Octavation 0)
+begin_8va = Command (Octavation 1) []
+end_8va = Command (Octavation 0) []
 
 -- * Annotations
 
@@ -117,9 +102,9 @@
 end_slur = Phrasing End_Slur
 
 slur_down,slur_neutral,slur_up :: Music
-slur_down = Command (User "\\slurDown")
-slur_neutral = Command (User "\\slurNeutral")
-slur_up = Command (User "\\slurUp")
+slur_down = Command (User "\\slurDown") []
+slur_neutral = Command (User "\\slurNeutral") []
+slur_up = Command (User "\\slurUp") []
 
 -- | Phrasing slur annotations.
 begin_phrasing_slur,end_phrasing_slur :: Annotation
@@ -135,18 +120,48 @@
 set_accidental_style_dodecaphonic :: Music
 set_accidental_style_dodecaphonic =
     let x = "#(set-accidental-style 'dodecaphonic)"
-    in Command (User x)
+    in Command (User x) []
 
 set_accidental_style_neo_modern :: Music
 set_accidental_style_neo_modern =
     let x = "#(set-accidental-style 'neo-modern)"
-    in Command (User x)
+    in Command (User x) []
 
 set_accidental_style_modern :: Music
 set_accidental_style_modern =
     let x = "#(set-accidental-style 'modern)"
-    in Command (User x)
+    in Command (User x) []
 
+-- * Noteheads
+
+-- | Request particular note-heads.
+set_noteheads :: String -> Music
+set_noteheads x =
+    let u = "\\override NoteHead #'style = #'" ++ x
+    in Command (User u) []
+
+-- | Request specific note-heads.
+cross_noteheads :: Music
+cross_noteheads = set_noteheads "cross"
+
+baroque_noteheads :: Music
+baroque_noteheads = set_noteheads "baroque"
+
+neomensural_noteheads,mensural_noteheads,petrucci_noteheads :: Music
+neomensural_noteheads = set_noteheads "neomensural"
+mensural_noteheads = set_noteheads "mensural"
+petrucci_noteheads = set_noteheads "petrucci"
+
+harmonic_noteheads,harmonic_mixed_noteheads,diamond_noteheads :: Music
+harmonic_noteheads = set_noteheads "harmonic"
+harmonic_mixed_noteheads = set_noteheads "harmonic-mixed"
+diamond_noteheads = set_noteheads "diamond"
+
+-- | Revert to standard note-heads.
+revert_noteheads :: Music
+revert_noteheads =
+    Command (User "\\revert NoteHead #'style") []
+
 -- * Paper
 
 a4_paper :: Paper
@@ -161,10 +176,12 @@
           ,paper_height = Length 297 MM
           ,ragged_last = False
           ,ragged_last_bottom = True
+          ,ragged_right = False
           ,right_margin = Length 10 MM
           ,systems_per_page = Nothing
           ,top_margin = Length 5 MM
-          ,two_sided = False}
+          ,two_sided = False
+          ,print_page_number = True}
 
 length_scale :: Double -> Length -> Length
 length_scale n (Length x u) = Length (n * x) u
@@ -187,18 +204,35 @@
         ht = paper_height x
     in x {paper_width = ht, paper_height = wd}
 
--- * Settings
+mk_fragment_paper :: Double -> Double -> Paper
+mk_fragment_paper w h =
+    Paper {binding_offset = Length 0 MM
+          ,bottom_margin = Length 0 MM
+          ,indent = Length 0 MM
+          ,inner_margin = Length 0 MM
+          ,left_margin = Length 0 MM
+          ,outer_margin = Length 0 MM
+          ,paper_width = Length w MM
+          ,paper_height = Length h MM
+          ,ragged_last = True
+          ,ragged_last_bottom = True
+          ,ragged_right = True
+          ,right_margin = Length 0 MM
+          ,systems_per_page = Nothing
+          ,top_margin = Length 0 MM
+          ,two_sided = False
+          ,print_page_number = False}
 
-default_score_settings :: Score_Settings
-default_score_settings =
-    Score_Settings {independent_time_signatures = False}
+-- * Aliases
 
--- * Header
+tempo :: Duration -> Integer -> Music
+tempo d = Tempo d . fromIntegral
 
-default_header :: Header
-default_header =
-    Header {dedication = ""
-           ,title = ""
-           ,subtitle = ""
-           ,composer = ""
-           ,tagline = ""}
+after_grace :: Music -> Music -> Music
+after_grace = AfterGrace
+
+grace :: Music -> Music
+grace = Grace
+
+tremolo :: (Music, Music) -> Integer -> Music
+tremolo = Tremolo
diff --git a/Music/LilyPond/Light/Constant/Dynamic.hs b/Music/LilyPond/Light/Constant/Dynamic.hs
new file mode 100644
--- /dev/null
+++ b/Music/LilyPond/Light/Constant/Dynamic.hs
@@ -0,0 +1,26 @@
+-- | Dynamic constants.
+module Music.LilyPond.Light.Constant.Dynamic where
+
+import Music.LilyPond.Light.Model
+import Music.Theory.Dynamic_Mark {- hmt -}
+
+pppp,ppp,pp,p,mp,mf,f,ff,fff,ffff,fp,sfz :: Annotation
+pppp = Dynamic (Dynamic_Mark PPPP)
+ppp = Dynamic (Dynamic_Mark PPP)
+pp = Dynamic (Dynamic_Mark PP)
+p = Dynamic (Dynamic_Mark P)
+mp = Dynamic (Dynamic_Mark MP)
+mf = Dynamic (Dynamic_Mark MF)
+f = Dynamic (Dynamic_Mark F)
+ff = Dynamic (Dynamic_Mark FF)
+fff = Dynamic (Dynamic_Mark FFF)
+ffff = Dynamic (Dynamic_Mark FFFF)
+fp = Dynamic (Dynamic_Mark FP)
+sfz = Dynamic (Dynamic_Mark SFZ)
+
+cresc,decr,end_cresc,end_decr,espressivo :: Annotation
+cresc = Dynamic (Hairpin Crescendo)
+decr = Dynamic (Hairpin Diminuendo)
+end_cresc = Dynamic (Hairpin End_Hairpin)
+end_decr = Dynamic (Hairpin End_Hairpin)
+espressivo = Dynamic Espressivo
diff --git a/Music/LilyPond/Light/Constant/Note.hs b/Music/LilyPond/Light/Constant/Note.hs
new file mode 100644
--- /dev/null
+++ b/Music/LilyPond/Light/Constant/Note.hs
@@ -0,0 +1,398 @@
+-- | 'Pitch' names lifted to 'Music' values.
+module Music.LilyPond.Light.Constant.Note where
+
+import Music.LilyPond.Light.Model
+import Music.Theory.Pitch {- hmt -}
+import qualified Music.Theory.Pitch.Name as P
+
+-- * Notes
+
+pitch_to_music :: Pitch -> Music
+pitch_to_music p = Note p Nothing []
+
+c1,d1,e1,f1,g1,a1,b1 :: Music
+c1 = pitch_to_music P.c1
+d1 = pitch_to_music P.d1
+e1 = pitch_to_music P.e1
+f1 = pitch_to_music P.f1
+g1 = pitch_to_music P.g1
+a1 = pitch_to_music P.a1
+b1 = pitch_to_music P.b1
+
+ces1,des1,ees1,fes1,ges1,aes1,bes1 :: Music
+ces1 = pitch_to_music P.ces1
+des1 = pitch_to_music P.des1
+ees1 = pitch_to_music P.ees1
+fes1 = pitch_to_music P.fes1
+ges1 = pitch_to_music P.ges1
+aes1 = pitch_to_music P.aes1
+bes1 = pitch_to_music P.bes1
+
+cis1,dis1,eis1,fis1,gis1,ais1,bis1 :: Music
+cis1 = pitch_to_music P.cis1
+dis1 = pitch_to_music P.dis1
+eis1 = pitch_to_music P.eis1
+fis1 = pitch_to_music P.fis1
+gis1 = pitch_to_music P.gis1
+ais1 = pitch_to_music P.ais1
+bis1 = pitch_to_music P.bis1
+
+c2,d2,e2,f2,g2,a2,b2 :: Music
+c2 = pitch_to_music P.c2
+d2 = pitch_to_music P.d2
+e2 = pitch_to_music P.e2
+f2 = pitch_to_music P.f2
+g2 = pitch_to_music P.g2
+a2 = pitch_to_music P.a2
+b2 = pitch_to_music P.b2
+
+ces2,des2,ees2,fes2,ges2,aes2,bes2 :: Music
+ces2 = pitch_to_music P.ces2
+des2 = pitch_to_music P.des2
+ees2 = pitch_to_music P.ees2
+fes2 = pitch_to_music P.fes2
+ges2 = pitch_to_music P.ges2
+aes2 = pitch_to_music P.aes2
+bes2 = pitch_to_music P.bes2
+
+cis2,dis2,eis2,fis2,gis2,ais2,bis2 :: Music
+cis2 = pitch_to_music P.cis2
+dis2 = pitch_to_music P.dis2
+eis2 = pitch_to_music P.eis2
+fis2 = pitch_to_music P.fis2
+gis2 = pitch_to_music P.gis2
+ais2 = pitch_to_music P.ais2
+bis2 = pitch_to_music P.bis2
+
+cisis2,disis2,eisis2,fisis2,gisis2,aisis2,bisis2 :: Music
+cisis2 = pitch_to_music P.cisis2
+disis2 = pitch_to_music P.disis2
+eisis2 = pitch_to_music P.eisis2
+fisis2 = pitch_to_music P.fisis2
+gisis2 = pitch_to_music P.gisis2
+aisis2 = pitch_to_music P.aisis2
+bisis2 = pitch_to_music P.bisis2
+
+c3,d3,e3,f3,g3,a3,b3 :: Music
+c3 = pitch_to_music P.c3
+d3 = pitch_to_music P.d3
+e3 = pitch_to_music P.e3
+f3 = pitch_to_music P.f3
+g3 = pitch_to_music P.g3
+a3 = pitch_to_music P.a3
+b3 = pitch_to_music P.b3
+
+ces3,des3,ees3,fes3,ges3,aes3,bes3 :: Music
+ces3 = pitch_to_music P.ces3
+des3 = pitch_to_music P.des3
+ees3 = pitch_to_music P.ees3
+fes3 = pitch_to_music P.fes3
+ges3 = pitch_to_music P.ges3
+aes3 = pitch_to_music P.aes3
+bes3 = pitch_to_music P.bes3
+
+cis3,dis3,eis3,fis3,gis3,ais3,bis3 :: Music
+cis3 = pitch_to_music P.cis3
+dis3 = pitch_to_music P.dis3
+eis3 = pitch_to_music P.eis3
+fis3 = pitch_to_music P.fis3
+gis3 = pitch_to_music P.gis3
+ais3 = pitch_to_music P.ais3
+bis3 = pitch_to_music P.bis3
+
+cisis3,disis3,eisis3,fisis3,gisis3,aisis3,bisis3 :: Music
+cisis3 = pitch_to_music P.cisis3
+disis3 = pitch_to_music P.disis3
+eisis3 = pitch_to_music P.eisis3
+fisis3 = pitch_to_music P.fisis3
+gisis3 = pitch_to_music P.gisis3
+aisis3 = pitch_to_music P.aisis3
+bisis3 = pitch_to_music P.bisis3
+
+ceseh3,deseh3,eeseh3,feseh3,geseh3,aeseh3,beseh3 :: Music
+ceseh3 = pitch_to_music P.ceseh3
+deseh3 = pitch_to_music P.deseh3
+eeseh3 = pitch_to_music P.eeseh3
+feseh3 = pitch_to_music P.feseh3
+geseh3 = pitch_to_music P.geseh3
+aeseh3 = pitch_to_music P.aeseh3
+beseh3 = pitch_to_music P.beseh3
+
+ceh3,deh3,eeh3,feh3,geh3,aeh3,beh3 :: Music
+ceh3 = pitch_to_music P.ceh3
+deh3 = pitch_to_music P.deh3
+eeh3 = pitch_to_music P.eeh3
+feh3 = pitch_to_music P.feh3
+geh3 = pitch_to_music P.geh3
+aeh3 = pitch_to_music P.aeh3
+beh3 = pitch_to_music P.beh3
+
+cih3,dih3,eih3,fih3,gih3,aih3,bih3 :: Music
+cih3 = pitch_to_music P.cih3
+dih3 = pitch_to_music P.dih3
+eih3 = pitch_to_music P.eih3
+fih3 = pitch_to_music P.fih3
+gih3 = pitch_to_music P.gih3
+aih3 = pitch_to_music P.aih3
+bih3 = pitch_to_music P.bih3
+
+cisih3,disih3,eisih3,fisih3,gisih3,aisih3,bisih3 :: Music
+cisih3 = pitch_to_music P.cisih3
+disih3 = pitch_to_music P.disih3
+eisih3 = pitch_to_music P.eisih3
+fisih3 = pitch_to_music P.fisih3
+gisih3 = pitch_to_music P.gisih3
+aisih3 = pitch_to_music P.aisih3
+bisih3 = pitch_to_music P.bisih3
+
+c4,d4,e4,f4,g4,a4,b4 :: Music
+c4 = pitch_to_music P.c4
+d4 = pitch_to_music P.d4
+e4 = pitch_to_music P.e4
+f4 = pitch_to_music P.f4
+g4 = pitch_to_music P.g4
+a4 = pitch_to_music P.a4
+b4 = pitch_to_music P.b4
+
+ces4,des4,ees4,fes4,ges4,aes4,bes4 :: Music
+ces4 = pitch_to_music P.ces4
+des4 = pitch_to_music P.des4
+ees4 = pitch_to_music P.ees4
+fes4 = pitch_to_music P.fes4
+ges4 = pitch_to_music P.ges4
+aes4 = pitch_to_music P.aes4
+bes4 = pitch_to_music P.bes4
+
+cis4,dis4,eis4,fis4,gis4,ais4,bis4 :: Music
+cis4 = pitch_to_music P.cis4
+dis4 = pitch_to_music P.dis4
+eis4 = pitch_to_music P.eis4
+fis4 = pitch_to_music P.fis4
+gis4 = pitch_to_music P.gis4
+ais4 = pitch_to_music P.ais4
+bis4 = pitch_to_music P.bis4
+
+ceses4,deses4,eeses4,feses4,geses4,aeses4,beses4 :: Music
+ceses4 = pitch_to_music P.ceses4
+deses4 = pitch_to_music P.deses4
+eeses4 = pitch_to_music P.eeses4
+feses4 = pitch_to_music P.feses4
+geses4 = pitch_to_music P.geses4
+aeses4 = pitch_to_music P.aeses4
+beses4 = pitch_to_music P.beses4
+
+cisis4,disis4,eisis4,fisis4,gisis4,aisis4,bisis4 :: Music
+cisis4 = pitch_to_music P.cisis4
+disis4 = pitch_to_music P.disis4
+eisis4 = pitch_to_music P.eisis4
+fisis4 = pitch_to_music P.fisis4
+gisis4 = pitch_to_music P.gisis4
+aisis4 = pitch_to_music P.aisis4
+bisis4 = pitch_to_music P.bisis4
+
+ceseh4,deseh4,eeseh4,feseh4,geseh4,aeseh4,beseh4 :: Music
+ceseh4 = pitch_to_music P.ceseh4
+deseh4 = pitch_to_music P.deseh4
+eeseh4 = pitch_to_music P.eeseh4
+feseh4 = pitch_to_music P.feseh4
+geseh4 = pitch_to_music P.geseh4
+aeseh4 = pitch_to_music P.aeseh4
+beseh4 = pitch_to_music P.beseh4
+
+ceh4,deh4,eeh4,feh4,geh4,aeh4,beh4 :: Music
+ceh4 = pitch_to_music P.ceh4
+deh4 = pitch_to_music P.deh4
+eeh4 = pitch_to_music P.eeh4
+feh4 = pitch_to_music P.feh4
+geh4 = pitch_to_music P.geh4
+aeh4 = pitch_to_music P.aeh4
+beh4 = pitch_to_music P.beh4
+
+cih4,dih4,eih4,fih4,gih4,aih4,bih4 :: Music
+cih4 = pitch_to_music P.cih4
+dih4 = pitch_to_music P.dih4
+eih4 = pitch_to_music P.eih4
+fih4 = pitch_to_music P.fih4
+gih4 = pitch_to_music P.gih4
+aih4 = pitch_to_music P.aih4
+bih4 = pitch_to_music P.bih4
+
+cisih4,disih4,eisih4,fisih4,gisih4,aisih4,bisih4 :: Music
+cisih4 = pitch_to_music P.cisih4
+disih4 = pitch_to_music P.disih4
+eisih4 = pitch_to_music P.eisih4
+fisih4 = pitch_to_music P.fisih4
+gisih4 = pitch_to_music P.gisih4
+aisih4 = pitch_to_music P.aisih4
+bisih4 = pitch_to_music P.bisih4
+
+c5,d5,e5,f5,g5,a5,b5 :: Music
+c5 = pitch_to_music P.c5
+d5 = pitch_to_music P.d5
+e5 = pitch_to_music P.e5
+f5 = pitch_to_music P.f5
+g5 = pitch_to_music P.g5
+a5 = pitch_to_music P.a5
+b5 = pitch_to_music P.b5
+
+ces5,des5,ees5,fes5,ges5,aes5,bes5 :: Music
+ces5 = pitch_to_music P.ces5
+des5 = pitch_to_music P.des5
+ees5 = pitch_to_music P.ees5
+fes5 = pitch_to_music P.fes5
+ges5 = pitch_to_music P.ges5
+aes5 = pitch_to_music P.aes5
+bes5 = pitch_to_music P.bes5
+
+cis5,dis5,eis5,fis5,gis5,ais5,bis5 :: Music
+cis5 = pitch_to_music P.cis5
+dis5 = pitch_to_music P.dis5
+eis5 = pitch_to_music P.eis5
+fis5 = pitch_to_music P.fis5
+gis5 = pitch_to_music P.gis5
+ais5 = pitch_to_music P.ais5
+bis5 = pitch_to_music P.bis5
+
+ceses5,deses5,eeses5,feses5,geses5,aeses5,beses5 :: Music
+ceses5 = pitch_to_music P.ceses5
+deses5 = pitch_to_music P.deses5
+eeses5 = pitch_to_music P.eeses5
+feses5 = pitch_to_music P.feses5
+geses5 = pitch_to_music P.geses5
+aeses5 = pitch_to_music P.aeses5
+beses5 = pitch_to_music P.beses5
+
+cisis5,disis5,eisis5,fisis5,gisis5,aisis5,bisis5 :: Music
+cisis5 = pitch_to_music P.cisis5
+disis5 = pitch_to_music P.disis5
+eisis5 = pitch_to_music P.eisis5
+fisis5 = pitch_to_music P.fisis5
+gisis5 = pitch_to_music P.gisis5
+aisis5 = pitch_to_music P.aisis5
+bisis5 = pitch_to_music P.bisis5
+
+ceseh5,deseh5,eeseh5,feseh5,geseh5,aeseh5,beseh5 :: Music
+ceseh5 = pitch_to_music P.ceseh5
+deseh5 = pitch_to_music P.deseh5
+eeseh5 = pitch_to_music P.eeseh5
+feseh5 = pitch_to_music P.feseh5
+geseh5 = pitch_to_music P.geseh5
+aeseh5 = pitch_to_music P.aeseh5
+beseh5 = pitch_to_music P.beseh5
+
+ceh5,deh5,eeh5,feh5,geh5,aeh5,beh5 :: Music
+ceh5 = pitch_to_music P.ceh5
+deh5 = pitch_to_music P.deh5
+eeh5 = pitch_to_music P.eeh5
+feh5 = pitch_to_music P.feh5
+geh5 = pitch_to_music P.geh5
+aeh5 = pitch_to_music P.aeh5
+beh5 = pitch_to_music P.beh5
+
+cih5,dih5,eih5,fih5,gih5,aih5,bih5 :: Music
+cih5 = pitch_to_music P.cih5
+dih5 = pitch_to_music P.dih5
+eih5 = pitch_to_music P.eih5
+fih5 = pitch_to_music P.fih5
+gih5 = pitch_to_music P.gih5
+aih5 = pitch_to_music P.aih5
+bih5 = pitch_to_music P.bih5
+
+cisih5,disih5,eisih5,fisih5,gisih5,aisih5,bisih5 :: Music
+cisih5 = pitch_to_music P.cisih5
+disih5 = pitch_to_music P.disih5
+eisih5 = pitch_to_music P.eisih5
+fisih5 = pitch_to_music P.fisih5
+gisih5 = pitch_to_music P.gisih5
+aisih5 = pitch_to_music P.aisih5
+bisih5 = pitch_to_music P.bisih5
+
+c6,d6,e6,f6,g6,a6,b6 :: Music
+c6 = pitch_to_music P.c6
+d6 = pitch_to_music P.d6
+e6 = pitch_to_music P.e6
+f6 = pitch_to_music P.f6
+g6 = pitch_to_music P.g6
+a6 = pitch_to_music P.a6
+b6 = pitch_to_music P.b6
+
+ces6,des6,ees6,fes6,ges6,aes6,bes6 :: Music
+ces6 = pitch_to_music P.ces6
+des6 = pitch_to_music P.des6
+ees6 = pitch_to_music P.ees6
+fes6 = pitch_to_music P.fes6
+ges6 = pitch_to_music P.ges6
+aes6 = pitch_to_music P.aes6
+bes6 = pitch_to_music P.bes6
+
+cis6,dis6,eis6,fis6,gis6,ais6,bis6 :: Music
+cis6 = pitch_to_music P.cis6
+dis6 = pitch_to_music P.dis6
+eis6 = pitch_to_music P.eis6
+fis6 = pitch_to_music P.fis6
+gis6 = pitch_to_music P.gis6
+ais6 = pitch_to_music P.ais6
+bis6 = pitch_to_music P.bis6
+
+ceseh6,deseh6,eeseh6,feseh6,geseh6,aeseh6,beseh6 :: Music
+ceseh6 = pitch_to_music P.ceseh6
+deseh6 = pitch_to_music P.deseh6
+eeseh6 = pitch_to_music P.eeseh6
+feseh6 = pitch_to_music P.feseh6
+geseh6 = pitch_to_music P.geseh6
+aeseh6 = pitch_to_music P.aeseh6
+beseh6 = pitch_to_music P.beseh6
+
+ceh6,deh6,eeh6,feh6,geh6,aeh6,beh6 :: Music
+ceh6 = pitch_to_music P.ceh6
+deh6 = pitch_to_music P.deh6
+eeh6 = pitch_to_music P.eeh6
+feh6 = pitch_to_music P.feh6
+geh6 = pitch_to_music P.geh6
+aeh6 = pitch_to_music P.aeh6
+beh6 = pitch_to_music P.beh6
+
+cih6,dih6,eih6,fih6,gih6,aih6,bih6 :: Music
+cih6 = pitch_to_music P.cih6
+dih6 = pitch_to_music P.dih6
+eih6 = pitch_to_music P.eih6
+fih6 = pitch_to_music P.fih6
+gih6 = pitch_to_music P.gih6
+aih6 = pitch_to_music P.aih6
+bih6 = pitch_to_music P.bih6
+
+cisih6,disih6,eisih6,fisih6,gisih6,aisih6,bisih6 :: Music
+cisih6 = pitch_to_music P.cisih6
+disih6 = pitch_to_music P.disih6
+eisih6 = pitch_to_music P.eisih6
+fisih6 = pitch_to_music P.fisih6
+gisih6 = pitch_to_music P.gisih6
+aisih6 = pitch_to_music P.aisih6
+bisih6 = pitch_to_music P.bisih6
+
+c7,d7,e7,f7,g7,a7,b7 :: Music
+c7 = pitch_to_music P.c7
+d7 = pitch_to_music P.d7
+e7 = pitch_to_music P.e7
+f7 = pitch_to_music P.f7
+g7 = pitch_to_music P.g7
+a7 = pitch_to_music P.a7
+b7 = pitch_to_music P.b7
+
+ces7,des7,ees7,fes7,ges7,aes7,bes7 :: Music
+ces7 = pitch_to_music P.ces7
+des7 = pitch_to_music P.des7
+ees7 = pitch_to_music P.ees7
+fes7 = pitch_to_music P.fes7
+ges7 = pitch_to_music P.ges7
+aes7 = pitch_to_music P.aes7
+bes7 = pitch_to_music P.bes7
+
+cis7,dis7,eis7,fis7,gis7,ais7,bis7 :: Music
+cis7 = pitch_to_music P.cis7
+dis7 = pitch_to_music P.dis7
+eis7 = pitch_to_music P.eis7
+fis7 = pitch_to_music P.fis7
+gis7 = pitch_to_music P.gis7
+ais7 = pitch_to_music P.ais7
+bis7 = pitch_to_music P.bis7
diff --git a/Music/LilyPond/Light/Constant/NoteName.hs b/Music/LilyPond/Light/Constant/NoteName.hs
deleted file mode 100644
--- a/Music/LilyPond/Light/Constant/NoteName.hs
+++ /dev/null
@@ -1,396 +0,0 @@
-module Music.LilyPond.Light.Constant.NoteName where
-
-import Music.LilyPond.Light.Model
-import Music.Theory.Pitch
-
--- * Notes
-
-mk_note :: Note_T -> Alteration_T -> Octave -> Music
-mk_note n a o = Note (Pitch n a o) Nothing []
-
-c1,d1,e1,f1,g1,a1,b1 :: Music
-c1 = mk_note C Natural 1
-d1 = mk_note D Natural 1
-e1 = mk_note E Natural 1
-f1 = mk_note F Natural 1
-g1 = mk_note G Natural 1
-a1 = mk_note A Natural 1
-b1 = mk_note B Natural 1
-
-ces1,des1,ees1,fes1,ges1,aes1,bes1 :: Music
-ces1 = mk_note C Flat 1
-des1 = mk_note D Flat 1
-ees1 = mk_note E Flat 1
-fes1 = mk_note F Flat 1
-ges1 = mk_note G Flat 1
-aes1 = mk_note A Flat 1
-bes1 = mk_note B Flat 1
-
-cis1,dis1,eis1,fis1,gis1,ais1,bis1 :: Music
-cis1 = mk_note C Sharp 1
-dis1 = mk_note D Sharp 1
-eis1 = mk_note E Sharp 1
-fis1 = mk_note F Sharp 1
-gis1 = mk_note G Sharp 1
-ais1 = mk_note A Sharp 1
-bis1 = mk_note B Sharp 1
-
-c2,d2,e2,f2,g2,a2,b2 :: Music
-c2 = mk_note C Natural 2
-d2 = mk_note D Natural 2
-e2 = mk_note E Natural 2
-f2 = mk_note F Natural 2
-g2 = mk_note G Natural 2
-a2 = mk_note A Natural 2
-b2 = mk_note B Natural 2
-
-ces2,des2,ees2,fes2,ges2,aes2,bes2 :: Music
-ces2 = mk_note C Flat 2
-des2 = mk_note D Flat 2
-ees2 = mk_note E Flat 2
-fes2 = mk_note F Flat 2
-ges2 = mk_note G Flat 2
-aes2 = mk_note A Flat 2
-bes2 = mk_note B Flat 2
-
-cis2,dis2,eis2,fis2,gis2,ais2,bis2 :: Music
-cis2 = mk_note C Sharp 2
-dis2 = mk_note D Sharp 2
-eis2 = mk_note E Sharp 2
-fis2 = mk_note F Sharp 2
-gis2 = mk_note G Sharp 2
-ais2 = mk_note A Sharp 2
-bis2 = mk_note B Sharp 2
-
-cisis2,disis2,eisis2,fisis2,gisis2,aisis2,bisis2 :: Music
-cisis2 = mk_note C DoubleSharp 2
-disis2 = mk_note D DoubleSharp 2
-eisis2 = mk_note E DoubleSharp 2
-fisis2 = mk_note F DoubleSharp 2
-gisis2 = mk_note G DoubleSharp 2
-aisis2 = mk_note A DoubleSharp 2
-bisis2 = mk_note B DoubleSharp 2
-
-c3,d3,e3,f3,g3,a3,b3 :: Music
-c3 = mk_note C Natural 3
-d3 = mk_note D Natural 3
-e3 = mk_note E Natural 3
-f3 = mk_note F Natural 3
-g3 = mk_note G Natural 3
-a3 = mk_note A Natural 3
-b3 = mk_note B Natural 3
-
-ces3,des3,ees3,fes3,ges3,aes3,bes3 :: Music
-ces3 = mk_note C Flat 3
-des3 = mk_note D Flat 3
-ees3 = mk_note E Flat 3
-fes3 = mk_note F Flat 3
-ges3 = mk_note G Flat 3
-aes3 = mk_note A Flat 3
-bes3 = mk_note B Flat 3
-
-cis3,dis3,eis3,fis3,gis3,ais3,bis3 :: Music
-cis3 = mk_note C Sharp 3
-dis3 = mk_note D Sharp 3
-eis3 = mk_note E Sharp 3
-fis3 = mk_note F Sharp 3
-gis3 = mk_note G Sharp 3
-ais3 = mk_note A Sharp 3
-bis3 = mk_note B Sharp 3
-
-cisis3,disis3,eisis3,fisis3,gisis3,aisis3,bisis3 :: Music
-cisis3 = mk_note C DoubleSharp 3
-disis3 = mk_note D DoubleSharp 3
-eisis3 = mk_note E DoubleSharp 3
-fisis3 = mk_note F DoubleSharp 3
-gisis3 = mk_note G DoubleSharp 3
-aisis3 = mk_note A DoubleSharp 3
-bisis3 = mk_note B DoubleSharp 3
-
-ceseh3,deseh3,eeseh3,feseh3,geseh3,aeseh3,beseh3 :: Music
-ceseh3 = mk_note C ThreeQuarterToneFlat 3
-deseh3 = mk_note D ThreeQuarterToneFlat 3
-eeseh3 = mk_note E ThreeQuarterToneFlat 3
-feseh3 = mk_note F ThreeQuarterToneFlat 3
-geseh3 = mk_note G ThreeQuarterToneFlat 3
-aeseh3 = mk_note A ThreeQuarterToneFlat 3
-beseh3 = mk_note B ThreeQuarterToneFlat 3
-
-ceh3,deh3,eeh3,feh3,geh3,aeh3,beh3 :: Music
-ceh3 = mk_note C QuarterToneFlat 3
-deh3 = mk_note D QuarterToneFlat 3
-eeh3 = mk_note E QuarterToneFlat 3
-feh3 = mk_note F QuarterToneFlat 3
-geh3 = mk_note G QuarterToneFlat 3
-aeh3 = mk_note A QuarterToneFlat 3
-beh3 = mk_note B QuarterToneFlat 3
-
-cih3,dih3,eih3,fih3,gih3,aih3,bih3 :: Music
-cih3 = mk_note C QuarterToneSharp 3
-dih3 = mk_note D QuarterToneSharp 3
-eih3 = mk_note E QuarterToneSharp 3
-fih3 = mk_note F QuarterToneSharp 3
-gih3 = mk_note G QuarterToneSharp 3
-aih3 = mk_note A QuarterToneSharp 3
-bih3 = mk_note B QuarterToneSharp 3
-
-cisih3,disih3,eisih3,fisih3,gisih3,aisih3,bisih3 :: Music
-cisih3 = mk_note C ThreeQuarterToneSharp 3
-disih3 = mk_note D ThreeQuarterToneSharp 3
-eisih3 = mk_note E ThreeQuarterToneSharp 3
-fisih3 = mk_note F ThreeQuarterToneSharp 3
-gisih3 = mk_note G ThreeQuarterToneSharp 3
-aisih3 = mk_note A ThreeQuarterToneSharp 3
-bisih3 = mk_note B ThreeQuarterToneSharp 3
-
-c4,d4,e4,f4,g4,a4,b4 :: Music
-c4 = mk_note C Natural 4
-d4 = mk_note D Natural 4
-e4 = mk_note E Natural 4
-f4 = mk_note F Natural 4
-g4 = mk_note G Natural 4
-a4 = mk_note A Natural 4
-b4 = mk_note B Natural 4
-
-ces4,des4,ees4,fes4,ges4,aes4,bes4 :: Music
-ces4 = mk_note C Flat 4
-des4 = mk_note D Flat 4
-ees4 = mk_note E Flat 4
-fes4 = mk_note F Flat 4
-ges4 = mk_note G Flat 4
-aes4 = mk_note A Flat 4
-bes4 = mk_note B Flat 4
-
-cis4,dis4,eis4,fis4,gis4,ais4,bis4 :: Music
-cis4 = mk_note C Sharp 4
-dis4 = mk_note D Sharp 4
-eis4 = mk_note E Sharp 4
-fis4 = mk_note F Sharp 4
-gis4 = mk_note G Sharp 4
-ais4 = mk_note A Sharp 4
-bis4 = mk_note B Sharp 4
-
-ceses4,deses4,eeses4,feses4,geses4,aeses4,beses4 :: Music
-ceses4 = mk_note C DoubleFlat 4
-deses4 = mk_note D DoubleFlat 4
-eeses4 = mk_note E DoubleFlat 4
-feses4 = mk_note F DoubleFlat 4
-geses4 = mk_note G DoubleFlat 4
-aeses4 = mk_note A DoubleFlat 4
-beses4 = mk_note B DoubleFlat 4
-
-cisis4,disis4,eisis4,fisis4,gisis4,aisis4,bisis4 :: Music
-cisis4 = mk_note C DoubleSharp 4
-disis4 = mk_note D DoubleSharp 4
-eisis4 = mk_note E DoubleSharp 4
-fisis4 = mk_note F DoubleSharp 4
-gisis4 = mk_note G DoubleSharp 4
-aisis4 = mk_note A DoubleSharp 4
-bisis4 = mk_note B DoubleSharp 4
-
-ceseh4,deseh4,eeseh4,feseh4,geseh4,aeseh4,beseh4 :: Music
-ceseh4 = mk_note C ThreeQuarterToneFlat 4
-deseh4 = mk_note D ThreeQuarterToneFlat 4
-eeseh4 = mk_note E ThreeQuarterToneFlat 4
-feseh4 = mk_note F ThreeQuarterToneFlat 4
-geseh4 = mk_note G ThreeQuarterToneFlat 4
-aeseh4 = mk_note A ThreeQuarterToneFlat 4
-beseh4 = mk_note B ThreeQuarterToneFlat 4
-
-ceh4,deh4,eeh4,feh4,geh4,aeh4,beh4 :: Music
-ceh4 = mk_note C QuarterToneFlat 4
-deh4 = mk_note D QuarterToneFlat 4
-eeh4 = mk_note E QuarterToneFlat 4
-feh4 = mk_note F QuarterToneFlat 4
-geh4 = mk_note G QuarterToneFlat 4
-aeh4 = mk_note A QuarterToneFlat 4
-beh4 = mk_note B QuarterToneFlat 4
-
-cih4,dih4,eih4,fih4,gih4,aih4,bih4 :: Music
-cih4 = mk_note C QuarterToneSharp 4
-dih4 = mk_note D QuarterToneSharp 4
-eih4 = mk_note E QuarterToneSharp 4
-fih4 = mk_note F QuarterToneSharp 4
-gih4 = mk_note G QuarterToneSharp 4
-aih4 = mk_note A QuarterToneSharp 4
-bih4 = mk_note B QuarterToneSharp 4
-
-cisih4,disih4,eisih4,fisih4,gisih4,aisih4,bisih4 :: Music
-cisih4 = mk_note C ThreeQuarterToneSharp 4
-disih4 = mk_note D ThreeQuarterToneSharp 4
-eisih4 = mk_note E ThreeQuarterToneSharp 4
-fisih4 = mk_note F ThreeQuarterToneSharp 4
-gisih4 = mk_note G ThreeQuarterToneSharp 4
-aisih4 = mk_note A ThreeQuarterToneSharp 4
-bisih4 = mk_note B ThreeQuarterToneSharp 4
-
-c5,d5,e5,f5,g5,a5,b5 :: Music
-c5 = mk_note C Natural 5
-d5 = mk_note D Natural 5
-e5 = mk_note E Natural 5
-f5 = mk_note F Natural 5
-g5 = mk_note G Natural 5
-a5 = mk_note A Natural 5
-b5 = mk_note B Natural 5
-
-ces5,des5,ees5,fes5,ges5,aes5,bes5 :: Music
-ces5 = mk_note C Flat 5
-des5 = mk_note D Flat 5
-ees5 = mk_note E Flat 5
-fes5 = mk_note F Flat 5
-ges5 = mk_note G Flat 5
-aes5 = mk_note A Flat 5
-bes5 = mk_note B Flat 5
-
-cis5,dis5,eis5,fis5,gis5,ais5,bis5 :: Music
-cis5 = mk_note C Sharp 5
-dis5 = mk_note D Sharp 5
-eis5 = mk_note E Sharp 5
-fis5 = mk_note F Sharp 5
-gis5 = mk_note G Sharp 5
-ais5 = mk_note A Sharp 5
-bis5 = mk_note B Sharp 5
-
-ceses5,deses5,eeses5,feses5,geses5,aeses5,beses5 :: Music
-ceses5 = mk_note C DoubleFlat 5
-deses5 = mk_note D DoubleFlat 5
-eeses5 = mk_note E DoubleFlat 5
-feses5 = mk_note F DoubleFlat 5
-geses5 = mk_note G DoubleFlat 5
-aeses5 = mk_note A DoubleFlat 5
-beses5 = mk_note B DoubleFlat 5
-
-cisis5,disis5,eisis5,fisis5,gisis5,aisis5,bisis5 :: Music
-cisis5 = mk_note C DoubleSharp 5
-disis5 = mk_note D DoubleSharp 5
-eisis5 = mk_note E DoubleSharp 5
-fisis5 = mk_note F DoubleSharp 5
-gisis5 = mk_note G DoubleSharp 5
-aisis5 = mk_note A DoubleSharp 5
-bisis5 = mk_note B DoubleSharp 5
-
-ceseh5,deseh5,eeseh5,feseh5,geseh5,aeseh5,beseh5 :: Music
-ceseh5 = mk_note C ThreeQuarterToneFlat 5
-deseh5 = mk_note D ThreeQuarterToneFlat 5
-eeseh5 = mk_note E ThreeQuarterToneFlat 5
-feseh5 = mk_note F ThreeQuarterToneFlat 5
-geseh5 = mk_note G ThreeQuarterToneFlat 5
-aeseh5 = mk_note A ThreeQuarterToneFlat 5
-beseh5 = mk_note B ThreeQuarterToneFlat 5
-
-ceh5,deh5,eeh5,feh5,geh5,aeh5,beh5 :: Music
-ceh5 = mk_note C QuarterToneFlat 5
-deh5 = mk_note D QuarterToneFlat 5
-eeh5 = mk_note E QuarterToneFlat 5
-feh5 = mk_note F QuarterToneFlat 5
-geh5 = mk_note G QuarterToneFlat 5
-aeh5 = mk_note A QuarterToneFlat 5
-beh5 = mk_note B QuarterToneFlat 5
-
-cih5,dih5,eih5,fih5,gih5,aih5,bih5 :: Music
-cih5 = mk_note C QuarterToneSharp 5
-dih5 = mk_note D QuarterToneSharp 5
-eih5 = mk_note E QuarterToneSharp 5
-fih5 = mk_note F QuarterToneSharp 5
-gih5 = mk_note G QuarterToneSharp 5
-aih5 = mk_note A QuarterToneSharp 5
-bih5 = mk_note B QuarterToneSharp 5
-
-cisih5,disih5,eisih5,fisih5,gisih5,aisih5,bisih5 :: Music
-cisih5 = mk_note C ThreeQuarterToneSharp 5
-disih5 = mk_note D ThreeQuarterToneSharp 5
-eisih5 = mk_note E ThreeQuarterToneSharp 5
-fisih5 = mk_note F ThreeQuarterToneSharp 5
-gisih5 = mk_note G ThreeQuarterToneSharp 5
-aisih5 = mk_note A ThreeQuarterToneSharp 5
-bisih5 = mk_note B ThreeQuarterToneSharp 5
-
-c6,d6,e6,f6,g6,a6,b6 :: Music
-c6 = mk_note C Natural 6
-d6 = mk_note D Natural 6
-e6 = mk_note E Natural 6
-f6 = mk_note F Natural 6
-g6 = mk_note G Natural 6
-a6 = mk_note A Natural 6
-b6 = mk_note B Natural 6
-
-ces6,des6,ees6,fes6,ges6,aes6,bes6 :: Music
-ces6 = mk_note C Flat 6
-des6 = mk_note D Flat 6
-ees6 = mk_note E Flat 6
-fes6 = mk_note F Flat 6
-ges6 = mk_note G Flat 6
-aes6 = mk_note A Flat 6
-bes6 = mk_note B Flat 6
-
-cis6,dis6,eis6,fis6,gis6,ais6,bis6 :: Music
-cis6 = mk_note C Sharp 6
-dis6 = mk_note D Sharp 6
-eis6 = mk_note E Sharp 6
-fis6 = mk_note F Sharp 6
-gis6 = mk_note G Sharp 6
-ais6 = mk_note A Sharp 6
-bis6 = mk_note B Sharp 6
-
-ceseh6,deseh6,eeseh6,feseh6,geseh6,aeseh6,beseh6 :: Music
-ceseh6 = mk_note C ThreeQuarterToneFlat 6
-deseh6 = mk_note D ThreeQuarterToneFlat 6
-eeseh6 = mk_note E ThreeQuarterToneFlat 6
-feseh6 = mk_note F ThreeQuarterToneFlat 6
-geseh6 = mk_note G ThreeQuarterToneFlat 6
-aeseh6 = mk_note A ThreeQuarterToneFlat 6
-beseh6 = mk_note B ThreeQuarterToneFlat 6
-
-ceh6,deh6,eeh6,feh6,geh6,aeh6,beh6 :: Music
-ceh6 = mk_note C QuarterToneFlat 6
-deh6 = mk_note D QuarterToneFlat 6
-eeh6 = mk_note E QuarterToneFlat 6
-feh6 = mk_note F QuarterToneFlat 6
-geh6 = mk_note G QuarterToneFlat 6
-aeh6 = mk_note A QuarterToneFlat 6
-beh6 = mk_note B QuarterToneFlat 6
-
-cih6,dih6,eih6,fih6,gih6,aih6,bih6 :: Music
-cih6 = mk_note C QuarterToneSharp 6
-dih6 = mk_note D QuarterToneSharp 6
-eih6 = mk_note E QuarterToneSharp 6
-fih6 = mk_note F QuarterToneSharp 6
-gih6 = mk_note G QuarterToneSharp 6
-aih6 = mk_note A QuarterToneSharp 6
-bih6 = mk_note B QuarterToneSharp 6
-
-cisih6,disih6,eisih6,fisih6,gisih6,aisih6,bisih6 :: Music
-cisih6 = mk_note C ThreeQuarterToneSharp 6
-disih6 = mk_note D ThreeQuarterToneSharp 6
-eisih6 = mk_note E ThreeQuarterToneSharp 6
-fisih6 = mk_note F ThreeQuarterToneSharp 6
-gisih6 = mk_note G ThreeQuarterToneSharp 6
-aisih6 = mk_note A ThreeQuarterToneSharp 6
-bisih6 = mk_note B ThreeQuarterToneSharp 6
-
-c7,d7,e7,f7,g7,a7,b7 :: Music
-c7 = mk_note C Natural 7
-d7 = mk_note D Natural 7
-e7 = mk_note E Natural 7
-f7 = mk_note F Natural 7
-g7 = mk_note G Natural 7
-a7 = mk_note A Natural 7
-b7 = mk_note B Natural 7
-
-ces7,des7,ees7,fes7,ges7,aes7,bes7 :: Music
-ces7 = mk_note C Flat 7
-des7 = mk_note D Flat 7
-ees7 = mk_note E Flat 7
-fes7 = mk_note F Flat 7
-ges7 = mk_note G Flat 7
-aes7 = mk_note A Flat 7
-bes7 = mk_note B Flat 7
-
-cis7,dis7,eis7,fis7,gis7,ais7,bis7 :: Music
-cis7 = mk_note C Sharp 7
-dis7 = mk_note D Sharp 7
-eis7 = mk_note E Sharp 7
-fis7 = mk_note F Sharp 7
-gis7 = mk_note G Sharp 7
-ais7 = mk_note A Sharp 7
-bis7 = mk_note B Sharp 7
diff --git a/Music/LilyPond/Light/Literal.hs b/Music/LilyPond/Light/Literal.hs
new file mode 100644
--- /dev/null
+++ b/Music/LilyPond/Light/Literal.hs
@@ -0,0 +1,18 @@
+module Music.LilyPond.Light.Literal (l,r,r',module L) where
+
+import Music.LilyPond.Light.Constant
+import Music.LilyPond.Light.Constant.Dynamic as L
+import Music.LilyPond.Light.Constant.Note as L
+import Music.LilyPond.Light.Model
+import Music.LilyPond.Light.Notation
+import Music.Theory.Duration {- hmt -}
+import Music.Theory.Time_Signature
+
+l :: Music
+l = bar_line_check
+
+r :: Duration -> Music
+r = rest
+
+r' :: Time_Signature -> Music
+r' = mm_rest
diff --git a/Music/LilyPond/Light/Measure.hs b/Music/LilyPond/Light/Measure.hs
new file mode 100644
--- /dev/null
+++ b/Music/LilyPond/Light/Measure.hs
@@ -0,0 +1,34 @@
+module Music.LilyPond.Light.Measure where
+
+import Music.LilyPond.Light.Model
+
+type M_Annotation = Music
+data Measure = Measure [M_Annotation] [Music] deriving (Eq,Show)
+
+m_annotate :: M_Annotation -> Measure -> Measure
+m_annotate a (Measure as xs) = Measure (as++[a]) xs
+
+m_annotate' :: [M_Annotation] -> Measure -> Measure
+m_annotate' as' (Measure as xs) = Measure (as++as') xs
+
+m_annotate_first' :: [M_Annotation] -> [Measure] -> [Measure]
+m_annotate_first' as xs =
+    case xs of
+      (x:xs') -> m_annotate' as x : xs'
+      [] -> error "m_annotate_first'"
+
+m_annotate_last' :: [M_Annotation] -> [Measure] -> [Measure]
+m_annotate_last' as xs =
+    case xs of
+      [] -> []
+      [x] -> [m_annotate' as x]
+      (x:xs') -> x : m_annotate_last' as xs'
+
+m_append :: [Music] -> Measure -> Measure
+m_append c (Measure as xs) = Measure as (xs++c)
+
+m_elements :: Measure -> [Music]
+m_elements (Measure as xs) = as ++ xs
+
+mm_elements :: [Measure] -> [Music]
+mm_elements = concatMap m_elements
diff --git a/Music/LilyPond/Light/Model.hs b/Music/LilyPond/Light/Model.hs
--- a/Music/LilyPond/Light/Model.hs
+++ b/Music/LilyPond/Light/Model.hs
@@ -1,9 +1,12 @@
 module Music.LilyPond.Light.Model where
 
 import Data.Monoid
+import qualified Music.Theory.Clef as C {- hmt -}
 import Music.Theory.Pitch
 import Music.Theory.Duration
+import Music.Theory.Dynamic_Mark
 import Music.Theory.Key
+import Music.Theory.Time_Signature
 
 data Version = Version String
                deriving (Eq, Show)
@@ -24,10 +27,12 @@
                    , paper_height :: Length
                    , ragged_last :: Bool
                    , ragged_last_bottom :: Bool
+                   , ragged_right :: Bool
                    , right_margin :: Length
                    , systems_per_page :: Maybe Integer
                    , top_margin :: Length
-                   , two_sided :: Bool }
+                   , two_sided :: Bool
+                   , print_page_number :: Bool }
              deriving (Eq, Show)
 
 data Header = Header { dedication :: String
@@ -37,9 +42,6 @@
                      , tagline :: String }
               deriving (Eq, Show)
 
-data Clef_T = Bass | Tenor | Alto | Treble | Percussion
-              deriving (Eq, Ord, Show)
-
 data Articulation_T = Accent
                     | Arpeggio
                     | ArpeggioDown
@@ -62,13 +64,9 @@
                     | UpBow
                       deriving (Eq, Show)
 
-data Dynamic_T = PPPP | PPP | Pianissimo | Piano | MezzoPiano
-               | MezzoForte | Forte | Fortissimo | FFF | FFFF
-               | FP | SFZ
+data Dynamic_T = Dynamic_Mark Dynamic_Mark_T
+               | Hairpin Hairpin_T
                | Espressivo
-               | Begin_Crescendo
-               | Begin_Decrescendo
-               | End_Dynamic
                  deriving (Eq, Show)
 
 data Phrasing_T = Begin_Slur
@@ -81,12 +79,15 @@
                 | SustainOff
                   deriving (Eq, Show)
 
+data Text_T = Text_Plain | Text_Markup
+              deriving (Eq, Show)
+
 data Annotation = Articulation Articulation_T
                 | Dynamic Dynamic_T
                 | Phrasing Phrasing_T
                 | Begin_Tie
-                | Above | Below
-                | Text String
+                | Place_Above | Place_Below
+                | Text_Mark | Text Text_T String
                 | ReminderAccidental | CautionaryAccidental
                 | CompositeAnnotation [Annotation]
                   deriving (Eq, Show)
@@ -125,8 +126,6 @@
                | VoiceFour
                  deriving (Eq, Show)
 
-type TimeSignature = (Integer, Integer)
-
 type Tuplet_T = (Integer, Integer)
 
 data Tuplet_Mode = Normal_Tuplet
@@ -155,22 +154,22 @@
 music_c :: Music -> Music_C
 music_c m =
     case m of
-      Note _ _ _ -> Note_C
-      Chord _ _ _ -> Chord_C
+      Note {} -> Note_C
+      Chord {} -> Chord_C
       Tremolo _ _ -> Tremolo_C
       Rest _ _ -> Rest_C
-      MMRest _ _ _ -> MMRest_C
-      Skip _ -> Skip_C
+      MMRest {} -> MMRest_C
+      Skip _ _ -> Skip_C
       Repeat _ _ -> Repeat_C
-      Tuplet _ _ _ -> Tuplet_C
+      Tuplet {} -> Tuplet_C
       Grace _ -> Grace_C
       AfterGrace _ _ -> AfterGrace_C
       Join _ -> Join_C
-      Clef _ _ -> Clef_C
+      Clef _ -> Clef_C
       Time _ -> Time_C
-      Key _ _ _ -> Key_C
+      Key {} -> Key_C
       Tempo _ _ -> Tempo_C
-      Command _ -> Command_C
+      Command _ _ -> Command_C
       Polyphony _ _ -> Polyphony_C
       Empty -> Empty_C
 
@@ -182,18 +181,18 @@
                    , chord_annotations :: [Annotation] }
            | Tremolo (Music,Music) Integer
            | Rest Duration [Annotation]
-           | MMRest Integer TimeSignature [Annotation]
-           | Skip Duration
+           | MMRest Integer Time_Signature [Annotation]
+           | Skip Duration [Annotation]
            | Repeat Integer Music
            | Tuplet Tuplet_Mode Tuplet_T Music
            | Grace Music
            | AfterGrace Music Music
            | Join [Music]
-           | Clef Clef_T Int
-           | Time TimeSignature
+           | Clef (C.Clef Int)
+           | Time Time_Signature
            | Key Note_T (Maybe Alteration_T) Mode_T
-           | Tempo Duration Integer
-           | Command Command_T
+           | Tempo Duration Rational
+           | Command Command_T [Annotation]
            | Polyphony Music Music
            | Empty
              deriving (Eq, Show)
@@ -232,8 +231,9 @@
              deriving (Eq, Show)
 
 data Score_Settings =
-    Score_Settings { independent_time_signatures :: Bool
-                   }
+    Score_Settings {independent_time_signatures :: Bool
+                   ,remove_empty_staves :: Bool
+                   ,remove_empty_staves_first_system :: Bool}
     deriving (Eq, Show)
 
 data Score = Score Score_Settings [Staff]
@@ -244,3 +244,36 @@
                  , work_header :: Header
                  , work_score :: Score }
             deriving (Eq, Show)
+
+data Fragment = Fragment { fragment_version :: Version
+                         , fragment_paper :: Paper
+                         , fragment_music :: Music }
+                deriving (Eq, Show)
+
+data Format = PDF | PS | PNG
+              deriving (Enum,Eq,Show)
+
+
+-- * Default values
+
+default_version :: Version
+default_version = Version "2.14.2"
+
+default_header :: Header
+default_header =
+    Header {dedication = ""
+           ,title = ""
+           ,subtitle = ""
+           ,composer = ""
+           ,tagline = ""}
+
+default_score_settings :: Score_Settings
+default_score_settings =
+    Score_Settings {independent_time_signatures = False
+                   ,remove_empty_staves = False
+                   ,remove_empty_staves_first_system = False}
+
+-- * Translation
+
+ly_bool :: Bool -> String
+ly_bool c = if c then "##t" else "##f"
diff --git a/Music/LilyPond/Light/Notation.hs b/Music/LilyPond/Light/Notation.hs
new file mode 100644
--- /dev/null
+++ b/Music/LilyPond/Light/Notation.hs
@@ -0,0 +1,534 @@
+module Music.LilyPond.Light.Notation where
+
+import Data.List
+import Data.Maybe
+import Data.Monoid
+import Data.Ratio
+import Music.LilyPond.Light.Constant
+import Music.LilyPond.Light.Measure
+import Music.LilyPond.Light.Model
+import Music.LilyPond.Light.Output.LilyPond
+import Music.Theory.Duration {- hmt -}
+import Music.Theory.Duration.Annotation
+import Music.Theory.Key
+import Music.Theory.Pitch
+import Music.Theory.Pitch.Spelling
+import Music.Theory.Time_Signature
+import Text.Printf
+
+-- * Music category predicates
+
+is_music_c :: Music_C -> Music -> Bool
+is_music_c c = (==) c . music_c
+
+is_note :: Music -> Bool
+is_note = is_music_c Note_C
+
+is_chord :: Music -> Bool
+is_chord = is_music_c Chord_C
+
+is_rest :: Music -> Bool
+is_rest = is_music_c Rest_C
+
+is_skip :: Music -> Bool
+is_skip = is_music_c Skip_C
+
+is_mm_rest :: Music -> Bool
+is_mm_rest = is_music_c MMRest_C
+
+is_grace :: Music -> Bool
+is_grace = is_music_c Grace_C
+
+is_after_grace :: Music -> Bool
+is_after_grace = is_music_c AfterGrace_C
+
+-- | These are required to avoid issues in lilypond (see manual)
+is_grace_skip :: Music -> Bool
+is_grace_skip m =
+    case m of
+      Grace (Skip _ _) -> True
+      _ -> False
+
+is_clef :: Music -> Bool
+is_clef = is_music_c Clef_C
+
+is_time :: Music -> Bool
+is_time = is_music_c Time_C
+
+is_tempo :: Music -> Bool
+is_tempo = is_music_c Tempo_C
+
+is_command :: Music -> Bool
+is_command = is_music_c Command_C
+
+is_barlinecheck :: Music -> Bool
+is_barlinecheck m =
+    case m of
+      Command BarlineCheck _ -> True
+      _ -> False
+
+is_tied :: Music -> Bool
+is_tied m =
+    case m of
+      Note _ _ xs -> Begin_Tie `elem` xs
+      Chord _ _ xs -> Begin_Tie `elem` xs
+      _ -> False
+
+is_tuplet :: Music -> Bool
+is_tuplet = is_music_c Tuplet_C
+
+-- * Pitch
+
+-- | Remove any reminder or cautionary accidentals at note or chord.
+clr_acc :: Music -> Music
+clr_acc m =
+    let rl = [rAcc,cAcc]
+    in case m of
+         Note x d a -> Note x d (a \\ rl)
+         Chord xs d a -> Chord (map clr_acc xs) d a
+         _ -> error ("clr_acc at non-note/chord: " ++ ly_music_elem m)
+
+octpc_to_note :: (Octave, PitchClass) -> Music
+octpc_to_note x = Note (octpc_to_pitch pc_spell_ks x) Nothing []
+
+-- * Rests
+
+-- | Construct rests.
+rest :: Duration -> Music
+rest x = Rest x []
+
+-- | Multi-measure variant of 'r'.
+mm_rest :: Time_Signature -> Music
+mm_rest x = MMRest 1 x []
+
+-- | Non-printing variant of 'rest'.
+skip :: Duration -> Music
+skip x = Skip x []
+
+-- | Create an empty measure for the specified time signature.
+empty_measure :: Integer -> Integer -> Music
+empty_measure n d = mconcat [MMRest 1 (n,d) [], bar_line_check]
+
+-- | Like 'empty_measure', but with an invisible rest.
+null_measure :: Integer -> Integer -> Music
+null_measure n d =
+    let x = Duration d 0 1
+        l = [bar_line_check]
+    in mconcat (map (\i -> Skip i []) (genericReplicate n x) ++ l)
+
+-- | Like 'empty_measure' but write time signature.
+measure_rest :: Integer -> Integer -> Music
+measure_rest n d = mconcat [time_signature (n,d), empty_measure n d]
+
+-- | Like 'measure_rest' but write time signature.
+measure_null :: Integer -> Integer -> Music
+measure_null n d = mconcat [time_signature (n,d), null_measure n d]
+
+-- * Tuplets
+
+-- | Apply a 'Duration' function to a 'Music' node, if it has a duration.
+edit_dur :: (Duration -> Duration) -> Music -> Music
+edit_dur fn x =
+    case x of
+      Note _ Nothing _ -> x
+      Note n (Just d) a -> Note n (Just (fn d)) a
+      Chord n d a -> Chord n (fn d) a
+      Rest d a -> Rest (fn d) a
+      Skip d a -> Skip (fn d) a
+      _ -> x
+
+-- | Temporal scaling of music (tuplets).
+tuplet :: Tuplet_T -> [Music] -> Music
+tuplet (d,n) =
+    let fn x = x { multiplier = n%d }
+    in Tuplet Normal_Tuplet (n,d) . mconcat . map (edit_dur fn)
+
+-- | Tuplet variants that set location, and then restore to neutral.
+tuplet_above,tuplet_below :: Tuplet_T -> [Music] -> Music
+tuplet_above n xs = mconcat [tuplet_up, tuplet n xs, tuplet_neutral]
+tuplet_below n xs = mconcat [tuplet_down, tuplet n xs, tuplet_neutral]
+
+-- | Like tuplet but does not annotate music, see also
+--   'ts_set_fraction'.
+scale_durations :: Tuplet_T -> [Music] -> Music
+scale_durations (n,d) =
+    let fn x = x { multiplier = d%n }
+    in Tuplet Scale_Durations (n,d) . mconcat . map (edit_dur fn)
+
+-- * Time signatures
+
+-- | Construct time signature.
+time_signature :: Time_Signature -> Music
+time_signature = Time
+
+-- | Allow proper auto-indenting of multiple measures with the same
+--   time signature.
+with_time_signature :: Time_Signature -> [Music] -> Music
+with_time_signature ts xs = mconcat (time_signature ts : xs)
+
+{-
+-- | Make a duration to fill a whole measure.
+ts_dur :: Time_Signature -> Duration
+ts_dur (n,d) = Duration d 0 (fromIntegral n)
+-}
+
+-- | Command to request that @4\/4@ and @2\/2@ etc. are typeset as
+-- fractions.
+ts_use_fractions :: Music
+ts_use_fractions =
+    let x = "\\override Staff.TimeSignature #'style = #'()"
+    in Command (User x) []
+
+-- | Set the printed time-signature fraction.
+ts_set_fraction :: Integer -> Integer -> Music
+ts_set_fraction n d =
+    let x = "#'(" ++ show n ++ " . " ++ show d ++ ")"
+        y = "\\set Staff.timeSignatureFraction = " ++ x
+    in Command (User y) []
+
+numeric_time_signature :: Music
+numeric_time_signature = Command (User "\\numericTimeSignature") []
+
+ts_parentheses :: Music
+ts_parentheses =
+    let x = "\\override Staff.TimeSignature #'stencil = #(lambda (grob) (bracketify-stencil (ly:time-signature::print grob) Y 0.1 0.2 0.1))"
+    in Command (User x) []
+
+ts_stencil :: Bool -> Music
+ts_stencil x =
+    let c = "\\override Staff.TimeSignature #'stencil = " ++ ly_bool x
+    in Command (User c) []
+
+ts_transparent :: Bool -> Music
+ts_transparent x =
+    let c = "\\override Staff.TimeSignature #'transparent = " ++ ly_bool x
+    in Command (User c) []
+
+ts_all_invisible :: Music
+ts_all_invisible =
+    let c = "\\override Staff.TimeSignature #'break-visibility = #all-invisible"
+    in Command (User c) []
+
+-- * Key signatures
+
+-- | Construct key signature.
+key :: Music -> Mode_T -> Music
+key m md =
+    case m of
+      (Note (Pitch n a _) _ _) -> Key n (Just a) md
+      _ -> error "key"
+
+-- * Repetition
+
+-- | Construct standard (two times) repeat.
+std_repeat :: Integer -> [Music] -> Music
+std_repeat n = Repeat n . mconcat
+
+-- * Octave
+
+-- | Shift the octave of a note element, else identity.
+note_edit_octave :: (Integer -> Integer) -> Music -> Music
+note_edit_octave fn m =
+    case m of
+      Note (Pitch n a o) d xs -> Note (Pitch n a (fn o)) d xs
+      _ -> m
+
+-- | Shift the octave of a note element, else identity.
+note_shift_octave :: Integer -> Music -> Music
+note_shift_octave i = note_edit_octave (+ i)
+
+-- * Duration
+
+-- > tie_r_ann [Tie_Right] == [Begin_Tie]
+tie_r_ann :: [D_Annotation] -> [Annotation]
+tie_r_ann a = if any (== Tie_Right) a then [Begin_Tie] else []
+
+-- | Rest of  'Duration_A'.
+da_rest :: Duration_A -> Music
+da_rest (d,_) = Rest d []
+
+-- | Add 'Duration_A' to 'Pitch' to make a @Note@ 'Music' element.
+(##@) :: Pitch -> Duration_A -> Music
+x ##@ (d,a) = Note x (Just d) (tie_r_ann a)
+
+-- | Add 'Duration' to 'Pitch' to make a @Note@ 'Music' element.
+(##) :: Pitch -> Duration -> Music
+x ## d = x ##@ (d,[])
+
+-- | Add 'Duration_A' to either a @Note@ or @Chord@ 'Music' element.
+(#@) :: Music -> Duration_A -> Music
+x #@ (d,a) =
+    case x of
+      Note n _ a' -> Note n (Just d) (tie_r_ann a ++ a')
+      Chord n _ a' -> Chord n d (tie_r_ann a ++ a')
+      _ -> error ("###: " ++ show x)
+
+-- | Add 'Duration' to either a @Note@ or @Chord@ 'Music' element.
+(#) :: Music -> Duration -> Music
+x # d = x #@ (d,[])
+
+-- * Chords
+
+-- | Construct chord.
+chd_p :: [Pitch] -> Duration -> Music
+chd_p xs d =
+    case xs of
+      [] -> error "chd_p: null elements"
+      _ -> Chord (map (\x -> Note x Nothing []) xs) d []
+
+chd :: [Music] -> Duration -> Music
+chd xs d =
+    case xs of
+      [] -> error "chd: null elements"
+      _ -> let fn x = let err msg = error (msg ++ ": " ++ show x)
+                      in case x of
+                           Note _ (Just _) _ -> err "chd: note has duration"
+                           Note _ Nothing _ -> x
+                           _ -> err "chd: non note element"
+           in Chord (map fn xs) d []
+
+-- * Commands
+
+-- | Construct bar number check command.
+bar_number_check :: Integer -> Music
+bar_number_check n = Command (BarNumberCheck n) []
+
+-- | Switch bar numbering visibility.
+bar_numbering :: Bool -> Music
+bar_numbering x =
+    let r = if x then "#(#t #t #t)" else "#(#f #f #f)"
+        s = "\\override Score.BarNumber #'break-visibility = #'" ++ r
+    in Command (User s) []
+
+-- | Change staff.
+change :: String -> Music
+change x = Command (Change x) []
+
+-- | Indicate initial partial measure.
+partial :: Duration -> Music
+partial d = Command (Partial d) []
+
+-- | Set or unset the @circled-tip@ hairpin attribute.
+hairpin_circled_tip :: Bool -> Music
+hairpin_circled_tip x =
+    let c = if x
+            then "\\override Hairpin #'circled-tip = ##t"
+            else "\\revert Hairpin #'circled-tip"
+    in Command (User c) []
+
+-- | Set or unset the @to-barline@ hairpin attribute.
+hairpin_to_barline :: Bool -> Music
+hairpin_to_barline x =
+    let c = if x
+            then "\\revert Hairpin #'to-barline"
+            else "\\override Hairpin #'to-barline = ##f"
+    in Command (User c) []
+
+-- | Set or unset the @minimum-length@ hairpin attribute.
+hairpin_minimum_length :: Maybe Int -> Music
+hairpin_minimum_length x =
+    let c = case x of
+              Nothing -> "\\revert Hairpin #'minimum-length"
+              Just n -> "\\override Hairpin #'minimum-length = #" ++ show n
+    in Command (User c) []
+
+-- * Staff and Parts
+
+set_8va_notation :: Music
+set_8va_notation = Command (User "\\set Staff.ottavation = #\"8\"") []
+
+name_to_id :: Staff_Name -> Staff_ID
+name_to_id (x,_) =
+    case x of
+      "" -> "no_id"
+      _ -> "id_" ++ x
+
+-- | Construct staff.
+staff :: Staff_Name -> [Music] -> Staff
+staff nm =
+    let st = Staff_Settings Normal_Staff (name_to_id nm) 0
+    in Staff st nm . Part Nothing
+
+-- | Construct rhythmic staff.
+rhythmic_staff :: Staff_Name -> [Music] -> Staff
+rhythmic_staff nm =
+    let st = Staff_Settings Rhythmic_Staff (name_to_id nm) 0
+    in Staff st nm . Part Nothing
+
+-- | Construct staff with text underlay.
+text_staff :: Staff_Name -> String -> [Music] -> Staff
+text_staff nm txt =
+    let st = Staff_Settings Normal_Staff (name_to_id nm) 0
+    in Staff st nm . Part (Just txt)
+
+-- | Construct piano staff.  For two staff piano music the staffs have
+--   identifiers rh and lh.
+piano_staff :: Staff_Name -> [[Music]] -> Staff
+piano_staff nm xs =
+    case xs of
+      [rh,lh] ->
+          let st x = Staff_Settings Normal_Staff x 0
+          in Staff_Set
+             PianoStaff
+             nm
+             [Staff (st "rh") ("","") (Part Nothing rh)
+             ,Staff (st "lh") ("","") (Part Nothing lh)]
+      _ -> Staff_Set PianoStaff nm (map (staff ("","")) xs)
+
+grand_staff :: Staff_Name -> [[Music]] -> Staff
+grand_staff nm = Staff_Set GrandStaff nm . map (staff ("",""))
+
+staff_group :: Staff_Name -> [[Music]] -> Staff
+staff_group nm = Staff_Set StaffGroup nm . map (staff ("",""))
+
+rhythmic_grand_staff :: Staff_Name -> [[Music]] -> Staff
+rhythmic_grand_staff nm = Staff_Set GrandStaff nm . map (rhythmic_staff ("",""))
+
+-- | Variant with names for each staff.
+grand_staff' :: Staff_Name -> [Staff_Name] -> [[Music]] -> Staff
+grand_staff' nm xs ys = Staff_Set GrandStaff nm (zipWith staff xs ys)
+
+staff_group' :: Staff_Name -> [Staff_Name] -> [[Music]] -> Staff
+staff_group' nm xs ys = Staff_Set StaffGroup nm (zipWith staff xs ys)
+
+two_part_staff :: Staff_Name -> ([Music], [Music]) -> Staff
+two_part_staff nm (p0, p1) =
+    let st = Staff_Settings Normal_Staff (name_to_id nm) 0
+    in Staff st nm (MultipleParts [voice_one:p0
+                                  ,voice_two:p1])
+
+instr_name :: Staff_Name -> Staff -> Staff
+instr_name nm pt =
+    case pt of
+      Staff st _ x -> Staff st nm x
+      Staff_Set ty _ xs -> Staff_Set ty nm xs
+
+resize_staff :: Int -> Staff -> Staff
+resize_staff n st =
+    case st of
+      Staff (Staff_Settings ty i sc) nm pt ->
+          Staff (Staff_Settings ty i (sc + n)) nm pt
+      Staff_Set ty nm xs ->
+          Staff_Set ty nm (map (resize_staff n) xs)
+
+score :: [Staff] -> Score
+score = Score default_score_settings
+
+-- | Interior polyphony.  For two part music on one staff see
+--   'two_part_staff'.
+polyphony :: Music -> Music -> Music
+polyphony = Polyphony
+
+polyphony' :: [Music] -> [Music] -> Music
+polyphony' x y = polyphony (mconcat x) (mconcat y)
+
+-- * Rests
+
+-- | Joins directly adjacent rest elements.
+join_rests :: [Music] -> [Music]
+join_rests =
+    let fn recur xs =
+            case xs of
+              [] -> []
+              Rest d a : Rest d' a' : ys ->
+                  case sum_dur d d' of
+                    Nothing -> let zs = Rest d a : join_rests (Rest d' a' : ys)
+                               in if recur then fn False zs else zs
+                    Just d'' -> join_rests (Rest d'' (a ++ a') : ys)
+              y:ys -> y : join_rests ys
+    in fn True
+
+-- * 'Duration_A' functions
+
+-- | Transform ascribed 'Duration_A' value to 'Music'.
+type DA_F x = (Duration_A,x) -> Music
+
+-- | Given 'DA_F' transform, transform set of ascribed 'Duration_A'
+-- values to 'Music'.
+--
+-- > import Music.Theory.Duration.Sequence.Notate
+-- > import Music.Theory.Duration.RQ.Tied
+-- > import Music.Theory.Pitch.Name
+-- > import Music.LilyPond.Light.Output.LilyPond
+--
+-- > let {Just d = m_notate True [[(2/3,_f),(1/3,_t)],[(1,_t)],[(1,_f)]]
+-- >     ;jn (i,j) = j ##@ i
+-- >     ;n = ascribe d [c4,d4]
+-- >     ;r = "\\times 2/3 { c' 4 d' 8 ~ } d' 4 ~ d' 4"}
+-- > in ly_music_elem (Join (da_to_music jn n)) == r
+da_to_music :: DA_F t -> [(Duration_A,t)] -> [Music]
+da_to_music fn x =
+    let g = da_group_tuplets_nn (map fst x)
+        g' = nn_reshape (,) g (map snd x)
+        tr el = case el of
+                 Left i -> fn i
+                 Right y -> let (y0,_):_ = y
+                                (n,d,_) = fromJust (da_begin_tuplet y0)
+                            in Tuplet Normal_Tuplet (d,n) (Join (map fn y))
+    in map tr g'
+
+-- | Variant of 'da_to_music' that operates on sets of measures.
+da_to_measures :: DA_F x -> Maybe [Time_Signature] -> [[(Duration_A,x)]] -> [Measure]
+da_to_measures fn m_t x =
+    let m = map (da_to_music fn) x
+        jn i = Measure [i]
+    in case m_t of
+         Just t -> zipWith jn (map Time t) m
+         Nothing -> map (Measure []) m
+
+-- * Fragment
+
+-- | Make a fragment from a list of 'Music' elements.  Width and
+-- height are in millimeters.
+mk_fragment :: (Double, Double) -> [Music] -> Fragment
+mk_fragment (w,h) m =
+    let pr = mk_fragment_paper w h
+    in Fragment default_version pr (Join m)
+
+-- | 'Measure' variant of 'mk_fragment'.
+mk_fragment_mm :: (Double, Double) -> [Measure] -> Fragment
+mk_fragment_mm d = mk_fragment d . mm_elements
+
+-- * Stem
+
+stem_transparent :: Bool -> Music
+stem_transparent x =
+    let c = "\\override Stem #'transparent = " ++ ly_bool x
+    in Command (User c) []
+
+-- * Text
+
+text_length_on :: Music
+text_length_on = Command (User "\\textLengthOn") []
+
+text_outside_staff_priority :: Maybe Double -> Music
+text_outside_staff_priority x =
+    let pr = case x of
+              Nothing -> ly_bool False
+              Just n -> '#' : show n
+        s = "\\override TextScript #'outside-staff-priority = " ++ pr
+    in Command (User s) []
+
+text_extra_spacing_width :: (Double,Double) -> Music
+text_extra_spacing_width (i,j) =
+    let t = "\\override TextScript #'extra-spacing-width = #'(%f . %f)"
+        s = printf t i j
+    in Command (User s) []
+
+-- * Measure operations
+
+-- | Delete redundant (repeated) time signatures.
+--
+-- > let mm = [Measure [Time (3,4)] [],Measure [Time (3,4)] []]
+-- > in mm_delete_redundant_ts mm == [Measure [Time (3,4)] [],Measure [] []]
+mm_delete_redundant_ts :: [Measure] -> [Measure]
+mm_delete_redundant_ts =
+    let f st m = let Measure a n = m
+                     ts = find is_time a
+                 in case (st,ts) of
+                      (Just p,Just q) -> if p == q
+                                         then (st,Measure (delete q a) n)
+                                         else (ts,m)
+                      (_,Just _) -> (ts,m)
+                      _ -> (st,m)
+    in snd . mapAccumL f Nothing
diff --git a/Music/LilyPond/Light/Output/LilyPond.hs b/Music/LilyPond/Light/Output/LilyPond.hs
--- a/Music/LilyPond/Light/Output/LilyPond.hs
+++ b/Music/LilyPond/Light/Output/LilyPond.hs
@@ -1,10 +1,21 @@
-module Music.LilyPond.Light.Output.LilyPond (ly_work
-                                            ,ly_music_elem) where
+module Music.LilyPond.Light.Output.LilyPond
+    (ly_work
+    ,ly_fragment
+    ,ly_music_elem
+    ,ly_process,ly_process_cwd
+    ,Lilypond(..)) where
 
+import Data.Char
 import Music.LilyPond.Light.Model
+import qualified Music.Theory.Clef as C {- hmt -}
 import Music.Theory.Pitch
 import Music.Theory.Duration
+import Music.Theory.Dynamic_Mark
 import Music.Theory.Key
+import System.Directory {- directory -}
+import System.Exit
+import System.FilePath {- filepath -}
+import System.Process {- process -}
 import Text.Printf
 
 with_brackets :: (String,String) -> [String] -> [String]
@@ -22,10 +33,6 @@
 ly_assign :: (String -> String) -> (String,String) -> [String]
 ly_assign fn (key,value) = [key,"=",fn value]
 
-ly_bool :: Bool -> String
-ly_bool True = "##t"
-ly_bool False = "##f"
-
 ly_units :: Units -> String
 ly_units x =
     case x of
@@ -53,9 +60,11 @@
              ,("paper-height", ly_length (paper_height p))
              ,("ragged-last", ly_bool (ragged_last p))
              ,("ragged-last-bottom", ly_bool (ragged_last_bottom p))
+             ,("ragged-right", ly_bool (ragged_right p))
              ,("systems-per-page", maybe "" show (systems_per_page p))
              ,("top-margin", ly_length (top_margin p))
-             ,("two-sided", ly_bool tw)]
+             ,("two-sided", ly_bool tw)
+             ,("print-page-number", ly_bool (print_page_number p))]
         ys = ly_delete_nil_values (xs ++ mg)
     in "\\paper" : with_braces (concatMap (ly_assign id) ys)
 
@@ -68,17 +77,17 @@
              ,("tagline", tagline hdr)]
     in "\\header" : with_braces (concatMap (ly_assign ly_str) xs)
 
-ly_clef_t :: Clef_T -> String
+ly_clef_t :: C.Clef_T -> String
 ly_clef_t c =
     case c of
-      Treble -> "treble"
-      Alto -> "alto"
-      Tenor -> "tenor"
-      Bass -> "bass"
-      Percussion -> "percussion"
+      C.Treble -> "treble"
+      C.Alto -> "alto"
+      C.Tenor -> "tenor"
+      C.Bass -> "bass"
+      C.Percussion -> "percussion"
 
-ly_clef :: Clef_T -> Int -> String
-ly_clef c o =
+ly_clef :: C.Clef Int -> String
+ly_clef (C.Clef c o) =
     let o' = case o of
                (-2) -> "_15"
                (-1) -> "_8"
@@ -90,31 +99,10 @@
        else concat ["\"", ly_clef_t c, o', "\""]
 
 ly_note :: Note_T -> String
-ly_note n =
-    case n of
-      C -> "c"
-      D -> "d"
-      E -> "e"
-      F -> "f"
-      G -> "g"
-      A -> "a"
-      B -> "b"
-
-ly_alteration :: Alteration_T -> String
-ly_alteration a =
-    case a of
-      DoubleFlat -> "eses"
-      ThreeQuarterToneFlat -> "eseh"
-      Flat -> "es"
-      QuarterToneFlat -> "eh"
-      Natural -> ""
-      QuarterToneSharp -> "ih"
-      Sharp -> "is"
-      ThreeQuarterToneSharp -> "isih"
-      DoubleSharp -> "isis"
+ly_note = map toLower . show
 
 ly_alteration' :: Maybe Alteration_T -> String
-ly_alteration' = maybe "" ly_alteration
+ly_alteration' = maybe "" alteration_ly_name
 
 ly_alteration_rule :: [Annotation] -> String
 ly_alteration_rule xs
@@ -140,7 +128,7 @@
 ly_pitch :: [Annotation] -> Pitch -> String
 ly_pitch xs (Pitch n a o) =
     ly_note n ++
-    ly_alteration a ++
+    alteration_ly_name a ++
     ly_octave o ++
     ly_alteration_rule xs
 
@@ -168,24 +156,18 @@
       Trill -> "\\trill"
       UpBow -> "\\upbow"
 
+ly_hairpin_t :: Hairpin_T -> String
+ly_hairpin_t h =
+    case h of
+      Crescendo -> "\\<"
+      Diminuendo -> "\\>"
+      End_Hairpin -> "\\!"
+
 ly_dynamic :: Dynamic_T -> String
 ly_dynamic d =
     case d of
-      PPPP -> "\\pppp"
-      PPP -> "\\ppp"
-      Pianissimo -> "\\pp"
-      Piano -> "\\p"
-      MezzoPiano -> "\\mp"
-      MezzoForte -> "\\mf"
-      Forte -> "\\f"
-      Fortissimo -> "\\ff"
-      FFF -> "\\fff"
-      FFFF -> "\\ffff"
-      FP -> "\\fp"
-      SFZ -> "\\sfz"
-      Begin_Crescendo -> "\\<"
-      Begin_Decrescendo -> "\\>"
-      End_Dynamic -> "\\!"
+      Dynamic_Mark m -> '\\' : map toLower (show m)
+      Hairpin h -> ly_hairpin_t h
       Espressivo -> "\\espressivo"
 
 ly_fraction :: (Integer,Integer) -> String
@@ -217,9 +199,11 @@
       Dynamic x -> ly_dynamic x
       Phrasing x -> ly_phrasing x
       Begin_Tie -> "~"
-      Above -> "^"
-      Below -> "_"
-      Text x -> ly_str x
+      Place_Above -> "^"
+      Place_Below -> "_"
+      Text_Mark -> "\\mark"
+      Text Text_Plain x -> ly_str x
+      Text Text_Markup x -> "\\markup {" ++ x ++ "}"
       CompositeAnnotation xs -> unwords (map ly_annotation xs)
       ReminderAccidental -> "" -- see ly_pitch
       CautionaryAccidental -> "" -- see ly_pitch
@@ -284,7 +268,7 @@
       Rest d aa -> ["r", ly_duration d] ++ map ly_annotation aa
       MMRest i (j,k) aa -> let d = printf "R %d*%d " k (i*j)
                            in d : map ly_annotation aa
-      Skip d -> ["\\skip", ly_duration d]
+      Skip d aa -> ["\\skip", ly_duration d] ++ map ly_annotation aa
       Repeat n x -> ["\\repeat", "volta", show n] ++ with_braces (ly_music x)
       Tuplet o n x ->
           let (o',n') =
@@ -294,13 +278,15 @@
           in [o', n'] ++ with_braces (ly_music x)
       Grace x -> "\\grace" : with_braces (ly_music x)
       AfterGrace x0 x1 -> "\\afterGrace" : concatMap ly_music [x0, x1]
-      Clef c o -> ["\\clef", ly_clef c o]
+      Clef c -> ["\\clef", ly_clef c]
       Time n -> ["\\time", ly_fraction n]
       Key n a md -> ["\\key"
                     ,ly_note n ++ ly_alteration' a
                     ,ly_key_mode md]
-      Tempo d r -> ["\\tempo", ly_duration d, "=", show r]
-      Command x -> [ly_command x]
+      Tempo d r ->
+          let r' = floor r :: Integer
+          in ["\\tempo", ly_duration d, "=", show r']
+      Command x aa -> ly_command x : map ly_annotation aa
       Join xs -> concatMap ly_music xs
       Polyphony x1 x2 -> ["\\simultaneous", "{"] ++
                          with_braces (ly_music x1) ++
@@ -383,6 +369,15 @@
     ,"    \\consists \"Default_bar_line_engraver\""
     ,"  }"]
 
+ly_remove_empty_staves :: Bool -> [String]
+ly_remove_empty_staves g =
+    ["\\context {"
+    ,"  \\Staff \\RemoveEmptyStaves"
+    ,if g
+     then "   \\override VerticalAxisGroup #'remove-first = ##t"
+     else ""
+    ,"}"]
+
 ly_layout :: Score_Settings -> [String]
 ly_layout x =
     let mk_i = printf "\\context { \\%s \\consists \"Instrument_name_engraver\"}"
@@ -391,6 +386,9 @@
        ,if independent_time_signatures x
         then unlines ly_independent_time_signatures
         else ""
+       ,if remove_empty_staves x
+        then unlines (ly_remove_empty_staves (remove_empty_staves_first_system x))
+        else ""
        ,is
        ,"}"]
 
@@ -400,6 +398,7 @@
         xs'' = with_braces ("\\simultaneous" : xs' ++ ly_layout pr)
     in "\\score" : xs''
 
+-- | Translate 'Work' to lilypond source code.
 ly_work :: Work -> String
 ly_work (Work v p hdr sc) =
     let xs = ly_version v ++
@@ -408,5 +407,39 @@
              ly_score sc
     in unwords xs
 
+-- | Translate 'Music' element to lilypond source code.
+--
+-- > import Music.LilyPond.Light
+-- > import Music.Theory.Duration.Name.Abbreviation
+-- > ly_music_elem (Join [c4#q',e4#h]) == "c' 4. e' 2"
 ly_music_elem :: Music -> String
 ly_music_elem = unwords . ly_music
+
+ly_fragment :: Fragment -> String
+ly_fragment (Fragment v p m) =
+    unlines (ly_version v ++
+             ly_paper p ++
+             ly_header default_header ++
+             with_braces [ly_music_elem m])
+
+class Lilypond a where ly_notate :: a -> String
+instance Lilypond Score where ly_notate = unlines . ly_score
+instance Lilypond Work where ly_notate = ly_work
+instance Lilypond Fragment where ly_notate = ly_fragment
+
+-- | Notate 'Lilypond' value, write to file, and run @lilypond@ to
+-- generate output in 'Format'.
+ly_process :: Lilypond a => FilePath -> Format -> String -> a -> IO ExitCode
+ly_process dir fmt nm ly = do
+  let fmt' = map toLower (show fmt)
+      o_fn = dir </> nm
+      ly_fn = o_fn <.> "ly"
+      cmd = printf "lilypond --%s -o %s %s" fmt' o_fn ly_fn
+  writeFile ly_fn (ly_notate ly)
+  system cmd
+
+-- | Variant of 'ly_process' using current working directory.
+ly_process_cwd :: Lilypond a => Format -> String -> a -> IO ExitCode
+ly_process_cwd fmt nm ly = do
+  d <- getCurrentDirectory
+  ly_process d fmt nm ly
diff --git a/README b/README
--- a/README
+++ b/README
@@ -1,11 +1,12 @@
 hly - minimalist haskell lilypond
+---------------------------------
 
-A very lightweight embedding of the lilypond
-typesetting model in haskell
+A very lightweight embedding of the [lilypond][ly]
+typesetting model in [haskell][hs].
 
-  http://slavepianos.org/rd/?t=hly
-  http://haskell.org/
-  http://lilypond.org/
+© [rohan drape][rd], 2010-2012, [gpl]
 
-(c) rohan drape, 2010-2011
-    gpl, http://gnu.org/copyleft/
+[ly]: http://lilypond.org/
+[hs]: http://haskell.org/
+[rd]: http://rd.slavepianos.org/
+[gpl]: http://gnu.org/copyleft/
diff --git a/help/hly.help.lhs b/help/hly.help.lhs
new file mode 100644
--- /dev/null
+++ b/help/hly.help.lhs
@@ -0,0 +1,17 @@
+> import Music.Theory.Duration.Sequence.Notate
+> import Music.Theory.Duration.Annotation
+> import Music.Theory.Duration.RQ.Tied
+> import Music.LilyPond.Light
+
+![hly-00](hly-00.png)
+
+> let {ts = [(3,4),(2,4),(3,4)]
+>     ;rq = [2/3,7/3,1,3/5,2/5+1/3,2/3,3/2,1/2]
+>     ;ps = [c4,d4,e4,f4,g4,a4,b4,c5]
+>     ;sr = default_rule []
+>     ;Just n = notate sr ts rq
+>     ;a = mm_ascribe n ps
+>     ;jn (i,j) = j #@ i
+>     ;m = da_to_measures jn ts a
+>     ;fr = mk_fragment_mm (105,20) m}
+> in ly_process_cwd PNG "hly-00" fr
diff --git a/hly.cabal b/hly.cabal
--- a/hly.cabal
+++ b/hly.cabal
@@ -1,31 +1,40 @@
 Name:              hly
-Version:           0.11
+Version:           0.12
 Synopsis:          Haskell LilyPond
 Description:       A very lightweight embedding of the lilypond
                    typesetting model in haskell
 License:           GPL
 Category:          Music
-Copyright:         (c) Rohan Drape, 2010-2011
+Copyright:         (c) Rohan Drape, 2010-2012
 Author:            Rohan Drape
 Maintainer:        rd@slavepianos.org
 Stability:         Experimental
-Homepage:          http://slavepianos.org/rd/?t=hly
-Tested-With:       GHC == 7.2.2
+Homepage:          http://rd.slavepianos.org/?t=hly
+Tested-With:       GHC == 7.6.1
 Build-Type:        Simple
 Cabal-Version:     >= 1.8
 Data-Files:        README
+                   help/*.help.lhs
 
 Library
   Build-Depends:   base==4.*,
-                   hmt==0.11.*
+                   directory,
+                   filepath,
+                   hmt==0.12.*,
+                   process
   GHC-Options:     -Wall -fwarn-tabs
   Exposed-modules: Music.LilyPond.Light
                    Music.LilyPond.Light.Analysis
+                   Music.LilyPond.Light.Annotation
                    Music.LilyPond.Light.Constant
-                   Music.LilyPond.Light.Constant.NoteName
+                   Music.LilyPond.Light.Constant.Dynamic
+                   Music.LilyPond.Light.Constant.Note
+                   Music.LilyPond.Light.Literal
+                   Music.LilyPond.Light.Measure
                    Music.LilyPond.Light.Model
+                   Music.LilyPond.Light.Notation
                    Music.LilyPond.Light.Output.LilyPond
 
 Source-Repository  head
   Type:            darcs
-  Location:        http://slavepianos.org/rd/sw/hly
+  Location:        http://rd.slavepianos.org/sw/hly
