After capo handler comes capo key

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

After capo handler comes capo key

Wols Lists
This is mostly saying "where do I start", so hints and clues are fine
... but what I want to do is have syntax along the lines of

\key C \major
\capokey A

ie capokey comes after key (and relies on being able to find out that
information).

The problem I've got is that I guess I don't want to do a markup if I
can avoid it (I want this to print the relevant text, and it goes above
all the clef/timesig/keysig clutter at the start of the piece).

And I want it to calculate and set capopitch at the same time, but
that's probably trivial compared to getting it to print the text.

So basically, it's do I need to return the text as a markup? If not,
what? If yes, what do I attach it to, and how?

I'm guessing it's best written in scheme, so also there's which
directory (and what file) should I put the code in, and how do I get
lilypond to autoload it?

Anyways, I'll try and write some draft code in the next day or two, and
if you've got any advice I'll take it on board before I post a first
attempt.

Cheers, and tia
Wol

---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: After capo handler comes capo key

Carl Sorensen
On 7/31/11 3:32 PM, "Wols Lists" <[hidden email]> wrote:

> This is mostly saying "where do I start", so hints and clues are fine
> ... but what I want to do is have syntax along the lines of
>
> \key C \major
> \capokey A
>
> ie capokey comes after key (and relies on being able to find out that
> information).
>
> The problem I've got is that I guess I don't want to do a markup if I
> can avoid it (I want this to print the relevant text, and it goes above
> all the clef/timesig/keysig clutter at the start of the piece).
>
> And I want it to calculate and set capopitch at the same time, but
> that's probably trivial compared to getting it to print the text.
>
> So basically, it's do I need to return the text as a markup? If not,
> what? If yes, what do I attach it to, and how?

There are two fundamentally different ways to approach this.

The first is to return the text as a markup.  You could attach it to nothing
if it were a top-level markup.  But I don't know if that's feasible or not.
If you want to do it this way, you would probably define \capoKey as a music
function.

The second is to create a capo_engraver that will create a Capo grob.

I think the second is the best way to do it, but it will be more complex.

If I were doing it, I'd probably start with the music function.

>
> I'm guessing it's best written in scheme, so also there's which
> directory (and what file) should I put the code in, and how do I get
> lilypond to autoload it?

Probably written in scheme, but in a .ly file, using define-music-function.
Most likely ly/music-functions-init.ly.

Any helper functions that are pure scheme would probably be in
scm/chord-names.scm.   They're already autoloaded.

scm/lily.scm handles the autoloading of the .scm files.  See line 400.

HTH,

Carl


---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: After capo handler comes capo key

Wols Lists
On 31/07/11 23:50, Carl Sorensen wrote:

> Probably written in scheme, but in a .ly file, using define-music-function.
> Most likely ly/music-functions-init.ly.
>
> Any helper functions that are pure scheme would probably be in
> scm/chord-names.scm.   They're already autoloaded.
>
> scm/lily.scm handles the autoloading of the .scm files.  See line 400.
>
> HTH,
>
Okay. That's helped a fair bit - I've got my first draft. Although
there's a fair few issues with it :-)

I've done it as a .scm file despite make-music-function only working as
a .ly - because kate does colour-formatting etc, and it's easier to work
that way :-)

The main thing is I've commented everything I think is dodgy, so if you
can cast an eye over it and point me in the right direction ... I was
hoping to get some hints from the code that implemented \key and \major
/ \minor, but I couldn't find it. Not least because I need to know if
I'm in minor mode to print the capo key correctly :-)

When all this is done, I'll try to write it up as "diary of a tadpole" -
a few articles like that on the website might not be bad :-) And if I do
my two engraver projects, that'll be useful too :-)

Cheers,
Wol


capokey.scm (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: After capo handler comes capo key

Jan Warchol
2011/8/2 Wols Lists <[hidden email]>:

> On 31/07/11 23:50, Carl Sorensen wrote:
>> Probably written in scheme, but in a .ly file, using define-music-function.
>> Most likely ly/music-functions-init.ly.
>>
>> Any helper functions that are pure scheme would probably be in
>> scm/chord-names.scm.   They're already autoloaded.
>>
>> scm/lily.scm handles the autoloading of the .scm files.  See line 400.
>>
>> HTH,
>>
> Okay. That's helped a fair bit - I've got my first draft. Although
> there's a fair few issues with it :-)
>
> I've done it as a .scm file despite make-music-function only working as
> a .ly - because kate does colour-formatting etc, and it's easier to work
> that way :-)

Do you want it uploaded to Rietveld?  If so, where in the source
should i paste it?  Anywhere in scm/chord-names.scm will do?

> When all this is done, I'll try to write it up as "diary of a tadpole" -
> a few articles like that on the website might not be bad :-) And if I do
> my two engraver projects, that'll be useful too :-)

Looking forward to reading it!

cheers,
Janek

---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: After capo handler comes capo key

Wols Lists
On 02/08/11 21:16, Jan Warchoł wrote:
>> I've done it as a .scm file despite make-music-function only working as
>> > a .ly - because kate does colour-formatting etc, and it's easier to work
>> > that way :-)
> Do you want it uploaded to Rietveld?  If so, where in the source
> should i paste it?  Anywhere in scm/chord-names.scm will do?
>
Does it really belong on Rietveld at the moment?

I know you said Scheme was not your strong point :-) but this code
doesn't belong in a .scm file (it should be in a .ly), and I haven't
attempted to compile it because I'm pretty certain it'll crash and burn
spectacularly :-)

If it should go on Rietveld, great, but I was hoping a frog-master would
help me get it into a rather better state before it was subjected to the
ridicule of the wider community :-)

Cheers,
Wol

---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: After capo handler comes capo key

Jan Warchol
2011/8/2 Wols Lists <[hidden email]>:
> On 02/08/11 21:16, Jan Warchoł wrote:
>>> I've done it as a .scm file despite make-music-function only working as
>>> > a .ly - because kate does colour-formatting etc, and it's easier to work
>>> > that way :-)
>> Do you want it uploaded to Rietveld?  If so, where in the source
>> should i paste it?  Anywhere in scm/chord-names.scm will do?
>>
> Does it really belong on Rietveld at the moment?

Perhaps not, then :)

> I know you said Scheme was not your strong point :-) but this code
> doesn't belong in a .scm file (it should be in a .ly), and I haven't
> attempted to compile it because I'm pretty certain it'll crash and burn
> spectacularly :-)

:)

> If it should go on Rietveld, great, but I was hoping a frog-master would
> help me get it into a rather better state before it was subjected to the
> ridicule of the wider community :-)

Then it's good that i resisted the temptation to cc this thread to devel :P
Somehow i very rarely post anything not on devel...

cheers,
Janek

---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: After capo handler comes capo key

Neil Puttock
In reply to this post by Wols Lists
On 1 August 2011 23:19, Wols Lists <[hidden email]> wrote:

> The main thing is I've commented everything I think is dodgy, so if you
> can cast an eye over it and point me in the right direction ... I was
> hoping to get some hints from the code that implemented \key and \major
> / \minor, but I couldn't find it. Not least because I need to know if
> I'm in minor mode to print the capo key correctly :-)

There's no flag which will tell you the mode of a key since all the
modes are just lists containing (scale-degree . alteration) pairs.
When a \key command is parsed, the list is tranposed; that tells the
engraver which alterations to typeset.

#(display minor)

-> ((0 . 0) (1 . 0) (2 . -1/2) (3 . 0) (4 . 0) (5 . -1/2) (6 . -1/2))

Here are a few comments on the music function:

> (let* (key-pitch (ly:make-pitch (ly:context-property context 'keySignature '())))

To read context properties inside a music function requires
\applyContext (in scheme form: (make-apply-context ...) or (make-music
'ApplyContext ...) ):

applyTest =
#(define-music-function (parser location) ()
   (define (look-at-key ctx)
     (newline)
     ;; not keySignature since that's the list of alterations
     (display (ly:context-property ctx 'tonic)))
   (context-spec-music
    (make-apply-context look-at-key)
    'Staff))

\relative c' {
  \key a \major
  \applyTest
  a1
}

Assuming the capo key appears above a stave, you'll have to set
capoPitch at Score level for ChordNames to see it.

> (capo-pitch (ly:make-pitch 0 capokey )) ;; set capo-pitch to the passed in notename ;; need to convert notename to "note alter"

You can pass pitches directly to the music function if you use the
predicate ly:pitch?

> (pitch-diff (cc:pitch::pitch-interval key-pitch capo-pitch))  ;; how do I call a c++ function

See the list of exported scheme functions here:

http://lilypond.org/doc/v2.15/Documentation/internals/scheme-functions

>    (if (capo-fret >= 0)
>      (make-line-markup (list "Capo " (abs (minus capo-fret 12)) (make-hspace-markup 1) (make-parenthesize-markup capokey)))  ;; do I need a make-markup function
>      (make-line-markup (list "Capo " (abs capo-fret) (make-hspace-markup 1) (make-parenthesize-markup capokey))))))

You can't return a markup from a music function (it must return music).

If the capo key markup is to be aligned somewhere over prefatory
material (such as the key signature), your best bet would be to create
a new break-aligned grob (similar to a rehearsal mark or bar number).

Cheers,
Neil

---
----
Join the Frogs!

Loading...