From a1b71e02edde596f80881ebc8c10a5f7ec030598 Mon Sep 17 00:00:00 2001
From: Reinhold Kainhofer <reinhold@kainhofer.com>
Date: Thu, 6 Mar 2008 18:38:41 +0100
Subject: [PATCH] Implement *MidiInstrument setting for a staff

---
 Documentation/examples/orchestrallily.ly |  2 +-
 orchestrallily.ly                        | 33 ++++++++++++++----------
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/Documentation/examples/orchestrallily.ly b/Documentation/examples/orchestrallily.ly
index f7c199c..411a71d 120000
--- a/Documentation/examples/orchestrallily.ly
+++ b/Documentation/examples/orchestrallily.ly
@@ -1 +1 @@
-../orchestrallily.ly
\ No newline at end of file
+../../orchestrallily.ly
\ No newline at end of file
diff --git a/orchestrallily.ly b/orchestrallily.ly
index 32b9ebd..c40cbc7 100644
--- a/orchestrallily.ly
+++ b/orchestrallily.ly
@@ -260,28 +260,35 @@ orchestralScoreStructure = #(define-music-function (parser location structure) (
   )
 )
 
+% Given a property name and the extensions, either generate the pair to set 
+% the property or an empty list, if no pre-defined variable could be found
+#(define (oly:generate_property_pair prop piece instr type)
+  (let* ((val (namedPieceInstrObject piece instr type)))
+    (if (not-null? val) (list 'assign prop val) '())
+  )
+)
 % Generate the properties for the staff for piece and instr. Typically, these
 % are the instrument name and the short instrument name (if defined).
 % return a (possibly empty) list of all assignments.
 #(define (oly:make_staff_properties piece instr)
   (let* (
-         (instrName (namedPieceInstrObject piece instr "InstrumentName"))
-         (shortInstrName (namedPieceInstrObject piece instr "ShortInstrumentName"))
-         (props '())
+         (mapping '( 
+              (instrumentName . "InstrumentName") 
+              (shortInstrumentName . "ShortInstrumentName")
+              (midiInstrument . "MidiInstrument")
+            ))
+         (assignments (map 
+             (lambda (pr) 
+                 (oly:generate_property_pair (car pr) piece instr (cdr pr))
+             )
+             mapping))
+         (props (filter not-null? assignments))
         )
-    (if (not-null? instrName)
-        (set! props (append props (list (list 'assign 'instrumentName instrName)))))
-    (if (not-null? shortInstrName)
-        (set! props (append props (list (list 'assign 'shortInstrumentName shortInstrName)))))
+    (display props)
     props
   )
 )
-#(define (oly:settings_pair setting value)
-  (if (not-null? value)
-    (list setting value)
-    '()
-  )
-)  
+
 #(define (oly:make_staff_group parser piece instr stafftype instruments)
   (let* (
          (staves     (oly:make_parallel_staves parser piece instr instruments))
-- 
GitLab