% Utilities for conventional input with scordablature output. % reset the output scale (may be needed with lilypond-book) majorScale = #'#(0 1 2 5/2 7/2 9/2 11/2) #(ly:set-default-scale (ly:make-scale majorScale)) % The magic function that converts a standard pitch % to a scordablature pitch. % Number of steps to the octave = ET. % Middle C is set to MIDI pitch midc #(define (scorda-pitch ET midc p) (let* ((reg (ly:pitch-octave p)) (semitones (+ (* 12 reg) (* 2 (+ (vector-ref majorScale (modulo (ly:pitch-steps p) 7)) (ly:pitch-alteration p))))) (diatonic-degree (ly:pitch-steps p)) (scorda-steps (+ (- midc 60) (* semitones (semitone-size ET)) (* diatonic-degree (diesis-size ET)))) (scorda-reg (inexact->exact (floor (/ scorda-steps 12)))) (scorda-semis (- scorda-steps (* 12 scorda-reg))) (defaultDiatonicDegrees '#(0 0 1 2 2 3 3 4 4 5 6 6)) (scorda-degree (vector-ref defaultDiatonicDegrees (round scorda-semis))) (alteration (- (/ scorda-semis 2) (vector-ref majorScale scorda-degree))) ) (ly:make-pitch scorda-reg scorda-degree alteration))) % Finds the best size of fifth in the equal temperement with % the given number of fifths to the octave. % Note: different to the function in regular.ly as it returns the size % of tempered scale steps #(define (best-fifth ET) (inexact->exact (round (* ET 0.5849625007)))) % Finds the size of chromatic semitones for the given equal temperament #(define (semitone-size ET) (- (* 7 (best-fifth ET)) (* 4 ET))) % Finds the size of enharmonic dieses for the given equal temperament #(define (diesis-size ET) (- (* 7 ET) (* 12 (best-fifth ET)))) % Convert all notes. % This is copied from "Transposing music with minimum accidentals" % In the "Pitches" snippets in the documentation. % Transposed so middle C comes out as pitch midc #(define (scordablarize ET midc music) (let* ((es (ly:music-property music 'elements)) (e (ly:music-property music 'element)) (p (ly:music-property music 'pitch))) (if (pair? es) (ly:music-set-property! music 'elements (map (lambda (x) (scordablarize ET midc x)) es))) (if (ly:music? e) (ly:music-set-property! music 'element (scordablarize ET midc e))) (if (ly:pitch? p) (begin (set! p (scorda-pitch ET midc p)) (ly:music-set-property! music 'pitch p))) music)) absoluteRetune = #(define-music-function (parser location ET m) (integer? ly:music?) (scordablarize ET 70 m)) % Music expression to give middle C without note names defined: midc = #(make-music 'EventChord 'elements (list (make-music 'NoteEvent 'duration (ly:make-duration 1 0) 'pitch (ly:make-pitch 0 0 0)))) % Apply scordablature so that middle C becomes MIDI pitch midc retune = #(define-music-function (parser location ET midc m) (integer? integer? ly:music?) (scordablarize ET midc m))