Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(99)

Delta Between Two Patch Sets: scm/music-functions.scm

Issue 320820043: Add a \voicify command (Closed)
Left Patch Set: Fix documentation problems (and some formatting) Created 7 years, 9 months ago
Right Patch Set: Fix stupid blunder/omission Created 7 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « ly/music-functions-init.ly ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 ;;;; This file is part of LilyPond, the GNU music typesetter. 1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;; 2 ;;;;
3 ;;;; Copyright (C) 1998--2015 Jan Nieuwenhuizen <janneke@gnu.org> 3 ;;;; Copyright (C) 1998--2015 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl> 4 ;;;; Han-Wen Nienhuys <hanwen@xs4all.nl>
5 ;;;; 5 ;;;;
6 ;;;; LilyPond is free software: you can redistribute it and/or modify 6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by 7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or 8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version. 9 ;;;; (at your option) any later version.
10 ;;;; 10 ;;;;
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 'elements 929 'elements
930 (ly:music-property m 'articulations) 930 (ly:music-property m 'articulations)
931 'origin 931 'origin
932 (ly:music-property m 'origin)) 932 (ly:music-property m 'origin))
933 (ly:music-property m 'duration) 933 (ly:music-property m 'duration)
934 '(rhythmic-event))))) 934 '(rhythmic-event)))))
935 (else #f))) 935 (else #f)))
936 music))) 936 music)))
937 937
938 ;;; splitting chords into voices. 938 ;;; splitting chords into voices.
939 (define (voicify-list lst id) 939 (define (voicify-list locs lst id)
940 "Make a list of Musics. 940 "Make a list of Musics.
941 941
942 voicify-list :: [ [Music ] ] -> id -> [Music] 942 voicify-list :: [ [Music ] ] -> id -> [Music]
943 LST is a list music-lists. 943 LST is a list music-lists.
944 944
945 id is 1-based, i.e., Voice=1 (upstems) has number 1. 945 id is 1-based, i.e., Voice=1 (upstems) has number 1.
946 946
947 id may be a symbol or string giving a specific voice id: in this 947 id may be a symbol or string giving a specific voice id: in this
948 case, no \voiceXXX style is selected, merely the context given. 948 case, no \voiceXXX style is selected, merely the context given.
949
950 locs is a list of music expressions suitable for giving
951 error locations (enclosing expression for the first element,
952 preceding \\\\ separator for the others)
949 " 953 "
950 (define (voicify-item music id) 954 (define (voicify-sublist loc sublist id)
951 (cond ((string? id) 955 (cond ((string? id)
952 (context-spec-music 956 (context-spec-music
953 (make-simultaneous-music music) 957 (make-simultaneous-music sublist)
954 'Bottom id)) 958 'Bottom id))
955 ((symbol? id) 959 ((symbol? id)
956 (voicify-item music (symbol->string id))) 960 (voicify-sublist loc sublist (symbol->string id)))
957 ((and (integer? id) (exact? id) (positive? id)) 961 ((and (integer? id) (exact? id) (positive? id))
958 (context-spec-music 962 (context-spec-music
959 (make-sequential-music 963 (make-sequential-music
960 (list (make-voice-props-set (1- id)) 964 (list (make-voice-props-set (1- id))
961 (make-simultaneous-music music))) 965 (make-simultaneous-music sublist)))
962 'Bottom (number->string id))) 966 'Bottom (number->string id)))
963 (else 967 (else
964 (ly:music-warning music 968 (ly:music-warning loc (_ "Bad voice id: ~a") id)
965 (_ ("Bad voicification id: ~a")) 969 (context-spec-music (make-simultaneous-music sublist) 'Bottom))))
966 id)
967 (context-spec-music (make-simultaneous-music music) 'Bottom))))
968 970
thomasmorley651 2017/04/08 12:02:45 Why not throw an error if lengths of `lst' and `id
thomasmorley651 2017/04/08 12:26:14 Other possibility would be to extend the id-list w
969 (cond ((null? lst) '()) 971 (cond ((null? lst) '())
970 ((number? id) 972 ((number? id)
971 (cons (voicify-item (car lst) id) 973 (cons (voicify-sublist (car locs) (car lst) id)
972 (voicify-list (cdr lst) (1+ id)))) 974 (voicify-list (cdr locs) (cdr lst) (1+ id))))
973 ((pair? id) 975 ((pair? id)
974 (cons (voicify-item (car lst) (car id)) 976 (cons (voicify-sublist (car locs) (car lst) (car id))
975 (voicify-list (cdr lst) (cdr id)))) 977 (voicify-list (cdr locs) (cdr lst) (cdr id))))
976 ((null? id) 978 ((null? id)
977 (ly:music-warning (car lst) 979 (ly:music-warning (car locs) (_ "\\voices needs more ids"))
978 (_ ("No more voicification ids"))) 980 (voicify-list locs lst 1))))
979 (voicify-list lst 1))))
980 981
981 (define (voicify-chord ch id) 982 (define (voicify-chord ch id)
982 "Split the parts of a chord into different Voices using separator" 983 "Split the parts of a chord into different Voices using separator"
983 (let ((es (ly:music-property ch 'elements))) 984 (let ((es (ly:music-property ch 'elements)))
984 (set! (ly:music-property ch 'elements) 985 (set! (ly:music-property ch 'elements)
985 (voicify-list (split-list-by-separator es music-separator?) id)) 986 (voicify-list (cons ch (filter music-separator? es))
987 (split-list-by-separator es music-separator?)
988 id))
986 ch)) 989 ch))
987 990
988 (define*-public (voicify-music m #:optional (id 1)) 991 (define*-public (voicify-music m #:optional (id 1))
989 "Recursively split chords that are separated with @code{\\\\}. 992 "Recursively split chords that are separated with @code{\\\\}.
990 Optional @var{id} can be a list of context ids to use. If numeric, 993 Optional @var{id} can be a list of context ids to use. If numeric,
991 they also indicate a voice type override. If @var{id} is just a single 994 they also indicate a voice type override. If @var{id} is just a single
992 number, that's where numbering starts." 995 number, that's where numbering starts."
993 (let loop ((m m)) 996 (let loop ((m m))
994 (if (not (ly:music? m)) 997 (if (not (ly:music? m))
995 (ly:error (_ "music expected: ~S") m)) 998 (ly:error (_ "music expected: ~S") m))
(...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after
2730 (memq tags music-tags) 2733 (memq tags music-tags)
2731 (not (any (lambda (t) (eq? (tag-group-get t) group)) music-tags)))) )) 2734 (not (any (lambda (t) (eq? (tag-group-get t) group)) music-tags)))) ))
2732 (let ((groups (delete-duplicates (map tag-group-get tags) eq?))) 2735 (let ((groups (delete-duplicates (map tag-group-get tags) eq?)))
2733 (lambda (m) 2736 (lambda (m)
2734 (let ((music-tags (ly:music-property m 'tags))) 2737 (let ((music-tags (ly:music-property m 'tags)))
2735 (or 2738 (or
2736 (null? music-tags) ; redundant but very frequent 2739 (null? music-tags) ; redundant but very frequent
2737 (any (lambda (t) (memq t tags)) music-tags) 2740 (any (lambda (t) (memq t tags)) music-tags)
2738 ;; if no tag matches, no tag group should match either 2741 ;; if no tag matches, no tag group should match either
2739 (not (any (lambda (t) (memq (tag-group-get t) groups)) music-tags)) )))))) 2742 (not (any (lambda (t) (memq (tag-group-get t) groups)) music-tags)) ))))))
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b