]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/midi.scm
Run `make grand-replace'.
[lilypond.git] / scm / midi.scm
index 46cb81c803e412000f430a46c454a2ff53356c24..9a7bcb5e68492f981dea1e01046ae77b178bd0e4 100644 (file)
@@ -1,38 +1,44 @@
-;;; midi.scm -- scm midi variables and functions
-;;;
-;;;  source file of the GNU LilyPond music typesetter
-;;; 
-;;; (c) 2000--2001 Jan Nieuwenhuizen <janneke@gnu.org>
+;;;; midi.scm -- scm midi variables and functions
+;;;;
+;;;;  source file of the GNU LilyPond music typesetter
+;;;; 
+;;;; (c) 2000--2008 Jan Nieuwenhuizen <janneke@gnu.org>
 
 
+
+;;;;;;;;;;;;;;;;;;
+;;; TODO:
+
+;; this is broken: we should not ever export variables from Scheme.
+
 ;; define factor of total volume per dynamic marking
-(define absolute-volume-alist '())
+(define-public absolute-volume-alist '())
 (set! absolute-volume-alist
       (append 
       '(
        ("sf" . 1.00)
        ("fffff" . 0.95)
-       ("ffff" . 0.91)
-       ("fff" . 0.81)
-       ("ff" . 0.71)
-       ("f" . 0.61)
-       ("mf" . 0.50)
-       ("mp" . 0.40)
-       ("p" . 0.30)
-       ("pp" . 0.20)
-       ("ppp" . 0.10)
-       ("pppp" . 0.08)
-       ("ppppp" . 0.05)
+       ("ffff" . 0.92)
+       ("fff" . 0.85)
+       ("ff" . 0.80)
+       ("f" . 0.75)
+       ("mf" . 0.68)
+       ("mp" . 0.61)
+       ("p" . 0.55)
+       ("pp" . 0.49)
+       ("ppp" . 0.42)
+       ("pppp" . 0.34)
+       ("ppppp" . 0.25)
        )
       absolute-volume-alist))
 
-(define (default-dynamic-absolute-volume s)
+(define-public (default-dynamic-absolute-volume s)
   (let ((entry (assoc s absolute-volume-alist)))
     (if entry
        (cdr entry))))
 
 ;; define factors of total volume of minimum and maximum volume
-(define instrument-equalizer-alist '())
+(define-public instrument-equalizer-alist '())
 (set! instrument-equalizer-alist
       (append 
        '(
         )
        instrument-equalizer-alist))
 
-;; (name . program+32768*(channel10 ? 1 : 0) )
+(define-public (default-instrument-equalizer s)
+  (let ((entry (assoc s instrument-equalizer-alist)))
+    (if entry
+       (cdr entry))))
+
+;; (name . program+32768*(channel10 ? 1 : 0))
 (define instrument-names-alist '())
 (set! instrument-names-alist
       (append
          ("recorder" . ,(- 75 1))
          ("pan flute" . ,(- 76 1))
          ("blown bottle" . ,(- 77 1))
-         ("skakuhachi" . ,(- 78 1))
+         ("shakuhachi" . ,(- 78 1))
          ("whistle" . ,(- 79 1))
          ("ocarina" . ,(- 80 1))
 
          ("mt-32 drums" .      ,(+ 32768 127))
          ("cm-64 kit" .        ,(+ 32768 127))
          ("cm-64 drums" .      ,(+ 32768 127))
-       )
-        instrument-names-alist
-      )
-)
-
+         )
+       instrument-names-alist))
 
-(define (default-instrument-equalizer s)
-  (let ((entry (assoc s instrument-equalizer-alist)))
-    (if entry
-       (cdr entry))))
-
-;; returns whether the instrument should use midi channel 9
-(define (percussion-p instrument)
+(define-public (percussion? instrument)
+  "
+returns whether the instrument should use midi channel 9
+"
   (let* ((inst  (symbol->string instrument))
-         (entry (assoc inst instrument-names-alist))
-       )
-     (and entry (>= (cdr entry) 32768))
-  )
-)
+         (entry (assoc inst instrument-names-alist)))
+     (and entry (>= (cdr entry) 32768))))
 
-;; returns the program of the instrument
-(define (midi-program instrument)
+(define-public (midi-program instrument)
+"
+returns the program of the instrument
+"
   (let* ((inst  (symbol->string instrument))
-         (entry (assoc inst instrument-names-alist))
-       )
-    (if entry (modulo (cdr entry) 32768) #f )
-  )
-)
+         (entry (assoc inst instrument-names-alist)))
+    (if entry (modulo (cdr entry) 32768) #f)))
 
 ;; 90 == 90/127 == 0.71 is supposed to be the default value
 ;; urg: we should set this at start of track
-(define dynamic-default-volume 0.71)
+(define-public dynamic-default-volume 0.71)
+
+(define-public (alterations-in-key pitch-list)
+  "Count number of sharps minus number of flats"
+  
+  (* (apply + (map cdr pitch-list)) 2))
+
+
 
-;; Count number of sharps minus number of flats
-(define (accidentals-in-key pitch-list)
-  (apply + (map cdr pitch-list)))
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
 
-;; Characterise the key as major if the alteration of the 
-;; third scale note is the same as that of the main note
-;; Note: MIDI cannot handle other tonalities than major/minor.
-(define (major-key pitch-list)
-  (eq? (cdr (list-ref pitch-list 4)) (cdr (list-ref pitch-list 6))))
+(define-public (write-performances-midis performances basename . rest)
+  (let ((midi-ext (ly:get-option 'midi-extension)))
+    (let
+       loop
+      ((perfs performances)
+       (count (if (null? rest) 0 (car rest))))
+      (if (pair?  perfs)
+         (begin
+           (ly:performance-write
+            (car perfs)
+            (if (> count 0)
+                (format #f "~a-~a.~a" basename count midi-ext)
+                (format #f "~a.~a" basename midi-ext)))
+           (loop (cdr perfs) (1+ count)))))))