From 7461c479c7a2e448b2d1da9759246b0cc1c9257a Mon Sep 17 00:00:00 2001 From: Carl Sorensen Date: Fri, 7 Aug 2009 07:37:57 -0600 Subject: [PATCH] Create general facility for changing styles of note heads styledNoteHeads music function allows the changing of note heads both inside and outside of chord construct with the same syntax. Redo deadNotes and palmMute for tablature to use the styledNoteHeads infrastructure. --- input/regression/palm-mute.ly | 8 +++-- ly/music-functions-init.ly | 6 ++++ ly/property-init.ly | 59 ++++++++++------------------------- scm/c++.scm | 6 ++++ scm/music-functions.scm | 37 +++++++++++++++++++++- 5 files changed, 70 insertions(+), 46 deletions(-) diff --git a/input/regression/palm-mute.ly b/input/regression/palm-mute.ly index 33123f3f8e..ac730f1fac 100644 --- a/input/regression/palm-mute.ly +++ b/input/regression/palm-mute.ly @@ -1,8 +1,10 @@ \version "2.13.4" -\header{ texidoc = "The palm mute technique for stringed instruments - is supported by triangle-shaped note heads." - } +\header{ + texidoc = +"The palm mute technique for stringed instruments +is supported by triangle-shaped note heads." +} palmmute = \relative c, { \time 4/4 diff --git a/ly/music-functions-init.ly b/ly/music-functions-init.ly index 3f3bdca54d..26f0e68fe4 100644 --- a/ly/music-functions-init.ly +++ b/ly/music-functions-init.ly @@ -731,6 +731,12 @@ the `parameters' assoc list.") (cons 'system-Y-extent (cdr (assoc 'system-Y-extent parameters)))) #}) +styledNoteHeads = +#(define-music-function + (parser location style heads music) + (symbol? list-or-symbol? ly:music?) + (_i "Set @var{heads} in @var{music} to @var{style}.") + (style-note-heads heads style music)) rightHandFinger = #(define-music-function (parser location finger) (number-or-string?) diff --git a/ly/property-init.ly b/ly/property-init.ly index f91c4b8d85..8759c7dad7 100644 --- a/ly/property-init.ly +++ b/ly/property-init.ly @@ -3,7 +3,7 @@ \version "2.12.0" stemUp = \override Stem #'direction = #UP -stemDown = \override Stem #'direction = #DOWN +stemDown = \override Stem #'direction = #DOWN stemNeutral = \revert Stem #'direction slurUp = \override Slur #'direction = #UP @@ -16,7 +16,7 @@ slurNeutral = \revert Slur #'direction slurDashed = { \override Slur #'dash-definition = #'((0 1 0.4 0.75)) } -slurDashPattern = +slurDashPattern = #(define-music-function (parser location dash-fraction dash-period) (number? number?) #{ @@ -46,7 +46,7 @@ phrasingSlurNeutral = \revert PhrasingSlur #'direction phrasingSlurDashed = { \override PhrasingSlur #'dash-definition = #'((0 1 0.4 0.75)) } -phrasingSlurDashPattern = +phrasingSlurDashPattern = #(define-music-function (parser location dash-fraction dash-period) (number? number?) #{ @@ -94,7 +94,7 @@ tieNeutral = \revert Tie #'direction tieDashed = { \override Tie #'dash-definition = #'((0 1 0.4 0.75)) } -tieDashPattern = +tieDashPattern = #(define-music-function (parser location dash-fraction dash-period) (number? number?) #{ @@ -164,7 +164,7 @@ cadenzaOff = { \set Timing.measurePosition = #ZERO-MOMENT } -% dynamic ly:dir? text script, articulation script ly:dir? +% dynamic ly:dir? text script, articulation script ly:dir? oneVoice = #(context-spec-music (make-voice-props-revert) 'Voice) voiceOne = #(context-spec-music (make-voice-props-set 0) 'Voice) voiceTwo = #(context-spec-music (make-voice-props-set 1) 'Voice) @@ -279,9 +279,9 @@ defaultTimeSignature = { % For drawing vertical chord brackets with \arpeggio -% This is a shorthand for the value of the print-function property -% of either Staff.Arpeggio or PianoStaff.Arpeggio, depending whether -% cross-staff brackets are desired. +% This is a shorthand for the value of the print-function property +% of either Staff.Arpeggio or PianoStaff.Arpeggio, depending whether +% cross-staff brackets are desired. arpeggio = #(make-music 'ArpeggioEvent) @@ -320,7 +320,7 @@ arpeggioParenthesisDashed = { glissando = #(make-music 'GlissandoEvent) -fermataMarkup = \markup { \musicglyph #"scripts.ufermata" } +fermataMarkup = \markup { \musicglyph #"scripts.ufermata" } hideNotes = { % hide notes, accidentals, etc. @@ -405,7 +405,7 @@ bassFigureStaffAlignmentNeutral = { \revert Staff.BassFigureAlignmentPositioning #'direction } -predefinedFretboardsOff = { +predefinedFretboardsOff = { \set FretBoards.predefinedDiagramTable = ##f } @@ -422,53 +422,28 @@ pointAndClickOn = #(define-music-function (parser location) () (make-music 'SequentialMusic 'void #t)) palmMuteOn = { - \override NoteHead #'style = #'do + #(override-head-style 'NoteHead 'do) } palmMuteOff = { - \revert NoteHead #'style + #(revert-head-style 'NoteHead) } palmMute = #(define-music-function (parser location note) (ly:music?) - ;; are we inside a <...>? - (if (eq? (ly:music-property note 'name) 'NoteEvent) - ;; yes -> add a tweak - (begin (set! (ly:music-property note 'tweaks) - (acons 'style 'do (ly:music-property note 'tweaks))) - note) - ;; no -> use predefined commands to switch to triangle-shaped note heads - #{ - \palmMuteOn - $note - \palmMuteOff - #})) + (style-note-heads 'NoteHead 'do note)) deadNotesOn = { - \override TabNoteHead #'style = #'cross - \override NoteHead #'style = #'cross + #(override-head-style '(TabNoteHead NoteHead) 'cross) } deadNotesOff = { - \revert TabNoteHead #'style - \revert NoteHead #'style + #(revert-head-style '(TabNoteHead NoteHead)) } deadNote = #(define-music-function (parser location note) (ly:music?) - ;; are we inside a <...>? - (if (eq? (ly:music-property note 'name) 'NoteEvent) - ;; yes -> add a tweak - (begin (set! (ly:music-property note 'tweaks) - (acons 'style 'cross (ly:music-property note 'tweaks))) - note) - ;; no -> use predefined commmands for changing - ;; note head and tablature fret signs - #{ - \deadNotesOn - $note - \deadNotesOff - #})) + (style-note-heads '(TabNoteHead NoteHead) 'cross note)) tabFullNotation = { % time signature @@ -481,7 +456,7 @@ tabFullNotation = { \revert TabVoice.Tie #'stencil \revert TabVoice.Tie #'after-line-breaking \revert TabVoice.RepeatTie #'stencil - \revert TabVoice.RepeatTie #'after-line-braking + \revert TabVoice.RepeatTie #'after-line-breaking \revert TabVoice.LaissezVibrerTie #'stencil \revert TabVoice.Slur #'stencil \revert PhrasingSlur #'stencil diff --git a/scm/c++.scm b/scm/c++.scm index 8db8bb96c0..3381a9e898 100644 --- a/scm/c++.scm +++ b/scm/c++.scm @@ -36,6 +36,12 @@ (define-public (string-or-pair? x) (or (string? x) (pair? x))) +(define-public (cheap-list? x) + (or (pair? x) (null? x))) + +(define-public (list-or-symbol? x) + (or (cheap-list? x) (symbol? x))) + (define-public (scheme? x) #t) diff --git a/scm/music-functions.scm b/scm/music-functions.scm index b5dd3bb392..b3d58db60a 100644 --- a/scm/music-functions.scm +++ b/scm/music-functions.scm @@ -563,7 +563,42 @@ included in .ly file." (make-music type 'span-direction span-dir)) -(define-public (set-mus-properties! m alist) +(define-public (override-head-style heads style) + "Override style for @var{heads} to @var{style}." + (make-sequential-music + (if (pair? heads) + (map (lambda (h) + (make-grob-property-override h 'style style)) + heads) + (list (make-grob-property-override heads 'style style))))) + +(define-public (revert-head-style heads) + "Revert style for @var{heads}." + (make-sequential-music + (if (pair? heads) + (map (lambda (h) + (make-grob-property-revert h 'style)) + heads) + (list (make-grob-property-revert heads 'style))))) + +(define-public (style-note-heads heads style music) + "Set @var{style} for all @var{heads} in @var{music}. Works both +inside of and outside of chord construct." + ;; are we inside a <...>? + (if (eq? (ly:music-property music 'name) 'NoteEvent) + ;; yes -> use a tweak + (begin + (set! (ly:music-property music 'tweaks) + (acons 'style style (ly:music-property music 'tweaks))) + music) + ;; not in <...>, so use overrides + (make-sequential-music + (list + (override-head-style heads style) + music + (revert-head-style heads))))) + + (define-public (set-mus-properties! m alist) "Set all of ALIST as properties of M." (if (pair? alist) (begin -- 2.39.2