lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to include a file/definition temporarily?


From: Patrick Schmidt
Subject: Re: How to include a file/definition temporarily?
Date: Mon, 20 Sep 2010 11:52:38 +0200

Hi Carl and David
Am 20.09.2010 um 11:29 schrieb Carl Sorensen:




On 9/20/10 1:19 AM, "David Kastrup" <address@hidden> wrote:

Patrick Schmidt <address@hidden> writes:

Hi all,

I have several files with definitions of guitar fret diagrams for
various chord shapes (e.g. c-shape.ly, a-shape.ly, g-shape.ly, e-
shape.ly and d-shape.ly). I can't include all of these files at the
same time in the main file as quite a few chord alternatives start on
the same pitch. How can I use those definitions only temporarily? I
tried this:

cShape = { \include "c-shape.ly" }
aShape = { \include "a-shape.ly"  }

music = \chordmode {
  \cShape
  c1
  \aShape
  c1
}

Maybe something like

stdfretboard = #(copy-list fretboard-table)
\include "c-shape.ly"
cshapefretboard = #(copy-list fretboard-table)
#(set! fretboard-table stdfretboard)
\include "a-shape.ly"
ashapefretboard = #(copy-list fretboard-table)
cShape = #(define-music-function ... (set! fretboard-table
           cshapefretboard)
aShape = #(define-music-funciton ...

or similar.  If c-shape/a-shape just add items to the front of
fretboard-table, you will not even need to copy stuff.  If it is
something other than a list, you'll need some other copying mechanism.

This is a good thought as a temporary workaround. However, it won't work
as-is, because fretboard-table is a hash table.  We'd need to define a
hash-table copy function:

(define (hash-table-copy my-table)
  (let ((new-hash-table (make-hash-table 100)))
    (hash-for-each (lambda (key value)
                     (hash-set! new-hash-table key value))
                   my-table)
     new-hash-table))

then replace copy-list above with hash-table-copy.

cShape and aShape would then be defined as void music functions, which is
not shown in David's code above.

Thanks for the idea, David.

Note: the code above is *not* tested. I hope to get it tested in the next
day or two.

This is still only a temporary workaround, I think, because we should avoid
the hard-coded fretboard-table.

Carl

Thanks for your hints! I will play around with it. I understand the general idea of the code but at the moment I'm still struggling to differentiate between scheme functions and self-defined functions. For example I couldn't find "copy-list" anywhere in the manuals so I guess it is a self-defined function or a scheme function I haven't found, yet. (In Carl's code I can see the definition of »hash-table- copy«.) I'm also unsure about what should follow after "define-music- function" instead of the three dots. But I will continue to study the "Extending"-manual.

Thanks,
patrick




reply via email to

[Prev in Thread] Current Thread [Next in Thread]