Chord-name-engraver plus capo

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Chord-name-engraver plus capo

Wols Lists
 anthony@ashdown ~/gitstuff/music/Hymnal/Choruses $
~/gitstuff/lilypond/out/bin/lilypond HeGaveMeBeautyForAshes.ly | tee chords
GNU LilyPond 2.13.30
Processing `HeGaveMeBeautyForAshes.ly'
Parsing...
Interpreting music...
warning: cannot find property type-check for `capoFret'
(translation-type?).  perhaps a typing error?
warning: doing assignment anyway
/home/anthony/gitstuff/lilypond/out/share/lilypond/current/scm/chord-ignatzek-names.scm:216:16:
In procedure car in expression (car in-pitches):
/home/anthony/gitstuff/lilypond/out/share/lilypond/current/scm/chord-ignatzek-names.scm:216:16:
Wrong type (expecting pair): ()


Learning a bit at a time ... how do I add properties? I've used "\set
ChordNames.capoFret = #3", but it's a new property, and it's objecting,
as you can see. I've added it to the "read" section of the
ADD_TRANSLATOR macro of chord-name-engraver.cc, but I'm guessing that
tells the engraver to use it, it doesn't tell lily that the property
exists ...

(the other stuff I know what's triggering it, I'll investigate the cause
later ...)

Cheers,
Wol

---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: Chord-name-engraver plus capo

Trevor D-2

Wols Lists wrote Thursday, August 26, 2010 2:19 PM

>
> Learning a bit at a time ... how do I add properties? I've used
> "\set
> ChordNames.capoFret = #3", but it's a new property, and it's
> objecting,
> as you can see. I've added it to the "read" section of the
> ADD_TRANSLATOR macro of chord-name-engraver.cc, but I'm guessing
> that
> tells the engraver to use it, it doesn't tell lily that the
> property
> exists ...

Have a look at scm/define-grob-properties.scm and
scm/define-context-properties.scm.  These define and
document all properties.  I think that's what you need;
I'm sure someone else will chime in if not.

Trevor



---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: Chord-name-engraver plus capo

Wols Lists
 On 26/08/10 20:00, Trevor Daniels wrote:

>
> Wols Lists wrote Thursday, August 26, 2010 2:19 PM
>>
>> Learning a bit at a time ... how do I add properties? I've used "\set
>> ChordNames.capoFret = #3", but it's a new property, and it's objecting,
>> as you can see. I've added it to the "read" section of the
>> ADD_TRANSLATOR macro of chord-name-engraver.cc, but I'm guessing that
>> tells the engraver to use it, it doesn't tell lily that the property
>> exists ...
>
> Have a look at scm/define-grob-properties.scm and
> scm/define-context-properties.scm.  These define and
> document all properties.  I think that's what you need;
> I'm sure someone else will chime in if not.
>
> Trevor
>
Thanks. Spot on.

Cheers,
Wol

---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: Chord-name-engraver plus capo - pitches

Wols Lists
 Next glitch - I'm trying to actually do the transpose ... and I don't
understand this Rational stuff :-(

The code is below:

      if (capo) {
        Pitch *p = unsmob_pitch (n->get_property ("pitch"));
        Pitch orig = p->transposed (Pitch (0, 0, -capo));
        capo_pitches = scm_cons ( orig.smobbed_copy (), capo_pitches);
      }

In my code, capo happens to be set to 3 at the moment. In other words, I
want to transpose down by three semitones. I've already discovered that
the first argument to Pitch( 0, 0, 0) takes it down three octaves. The
second takes it down three notenames. So I'm guessing that I need to
pass something in the third argument. The only problem is, what? capo is
an int and the above code simply bombs. I've found rational.hh, but my
C++fu isn't up to understanding what on earth is going on.

So, simply put, how do I describe 3 semitones as a rational, so I can
get my transposition to work?

Cheers,
Wol

---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: Chord-name-engraver plus capo - pitches

Trevor D-2

Wols Lists wrote Friday, August 27, 2010 12:42 AM


> Next glitch - I'm trying to actually do the transpose ... and I
> don't
> understand this Rational stuff :-(
>
> The code is below:
>
>      if (capo) {
>        Pitch *p = unsmob_pitch (n->get_property ("pitch"));
>        Pitch orig = p->transposed (Pitch (0, 0, -capo));
>        capo_pitches = scm_cons ( orig.smobbed_copy (),
> capo_pitches);
>      }
>
> In my code, capo happens to be set to 3 at the moment. In other
> words, I
> want to transpose down by three semitones. I've already discovered
> that
> the first argument to Pitch( 0, 0, 0) takes it down three octaves.
> The
> second takes it down three notenames. So I'm guessing that I need
> to
> pass something in the third argument. The only problem is, what?
> capo is
> an int and the above code simply bombs. I've found rational.hh,
> but my
> C++fu isn't up to understanding what on earth is going on.
>
> So, simply put, how do I describe 3 semitones as a rational, so I
> can
> get my transposition to work?

Good files to study:

lily/pitch.cc
lily/include/pitch.hh
flower/rational.cc
flower/include/rational.hh

You'll see Pitch::transpose (Pitch delta) is a private
method of the Pitch class, called by Pitch::transposed(d).
Like you, I think this is what you need.

The delta is a pitch, and the alteration is a rational
specified in tones (normally used for sharps and flats)
so I'd guess you'd use

transposedPitch = originalPitch->transposed (Pitch (0, 0, Rational
(-capo/2)));

Caveat: untried and remember I'm also a novice at this.

Trevor



---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: Chord-name-engraver plus capo - pitches

Wols Lists
 On 27/08/10 09:54, Trevor Daniels wrote:

>
> Wols Lists wrote Friday, August 27, 2010 12:42 AM
>
>
>> Next glitch - I'm trying to actually do the transpose ... and I don't
>> understand this Rational stuff :-(
>>
>> The code is below:
>>
>>      if (capo) {
>>        Pitch *p = unsmob_pitch (n->get_property ("pitch"));
>>        Pitch orig = p->transposed (Pitch (0, 0, -capo));
>>        capo_pitches = scm_cons ( orig.smobbed_copy (), capo_pitches);
>>      }
>>
>> In my code, capo happens to be set to 3 at the moment. In other words, I
>> want to transpose down by three semitones. I've already discovered that
>> the first argument to Pitch( 0, 0, 0) takes it down three octaves. The
>> second takes it down three notenames. So I'm guessing that I need to
>> pass something in the third argument. The only problem is, what? capo is
>> an int and the above code simply bombs. I've found rational.hh, but my
>> C++fu isn't up to understanding what on earth is going on.
>>
>> So, simply put, how do I describe 3 semitones as a rational, so I can
>> get my transposition to work?
>
> Good files to study:
>
> lily/pitch.cc
> lily/include/pitch.hh
> flower/rational.cc
> flower/include/rational.hh
>
> You'll see Pitch::transpose (Pitch delta) is a private
> method of the Pitch class, called by Pitch::transposed(d).
> Like you, I think this is what you need.
>
> The delta is a pitch, and the alteration is a rational
> specified in tones (normally used for sharps and flats)
> so I'd guess you'd use
>
> transposedPitch = originalPitch->transposed (Pitch (0, 0, Rational
> (-capo/2)));
>
> Caveat: untried and remember I'm also a novice at this.
>
> Trevor
>
I think I tried something like that ... I found those files, having had
a brainwave in bed last night. I still haven't sussed Rational, but I've
created an array of Pitch's, which seems to work fine. eg fret 3 selects
array[2] which is "a pitch and a flat". The problem to me is "pitch"
seems to be note name, so I'm going to have to play with it, but it
seems to me that "1" takes it down a semitone to B, "2" takes it down 1
1/2 tones to A, etc etc.

(Bear in mind, with your suggestion, "capo" is an int. So it's a bit
more complicated than that ... and I don't think you can pass floating
points to Rational)

Anyways, I now have it seeming to work. I've got my markup printing
either the original chords, or the transposed chords. I now have to find
out how to parenthesise the transposed chord, and stick the two
together, but I'm nearly there ...

But once I've got this engraver (and the capo_indicator_engraver?) done,
I'll dig into this and document it. If I'm going to write my
brass_fingering_engraver I need to work in semitones, not pitches!

---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: Chord-name-engraver plus capo - pitches

Trevor D-2

Wols Lists wrote Friday, August 27, 2010 1:15 PM

>
> On 27/08/10 09:54, Trevor Daniels wrote:
>>
>> transposedPitch = originalPitch->transposed (Pitch (0, 0,
>> Rational
>> (-capo/2)));
>>
> I think I tried something like that ... I found those files,
> having had
>
> (Bear in mind, with your suggestion, "capo" is an int. So it's a
> bit
> more complicated than that ... and I don't think you can pass
> floating
> points to Rational)

No, you're right, you can't.  I didn't intend to, but I
did get it wrong.  It should be Rational (-capo, 2) I think.
This should instantiate a Rational with value -capo/2.

(Sorry, I'm not set up to try this at the moment, so it
might still bomb.)

Trevor.



---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: Chord-name-engraver plus capo - pitches

Neil Puttock
On 27 August 2010 15:15, Trevor Daniels <[hidden email]> wrote:

> No, you're right, you can't.  I didn't intend to, but I
> did get it wrong.  It should be Rational (-capo, 2) I think.
> This should instantiate a Rational with value -capo/2.

You didn't get it wrong.  It's perfectly possible to use a double
here, though less efficient; see line 266 in rational.cc.

The only thing to be aware of when transposing pitches is the
limitation on alteration size: pitches can't have alterations larger
than a double, so Pitch (0, 0, Rational (-3/2)) isn't wise; it would
require normalizing (which would produce a B double flat).

Cheers,
Neil

---
----
Join the Frogs!

Reply | Threaded
Open this post in threaded view
|

Re: Chord-name-engraver plus capo - pitches

Wols Lists
In reply to this post by Trevor D-2
 On 27/08/10 15:15, Trevor Daniels wrote:

>
> Wols Lists wrote Friday, August 27, 2010 1:15 PM
>>
>> On 27/08/10 09:54, Trevor Daniels wrote:
>>>
>>> transposedPitch = originalPitch->transposed (Pitch (0, 0, Rational
>>> (-capo/2)));
>>>
>> I think I tried something like that ... I found those files, having had
>>
>> (Bear in mind, with your suggestion, "capo" is an int. So it's a bit
>> more complicated than that ... and I don't think you can pass floating
>> points to Rational)
>
> No, you're right, you can't.  I didn't intend to, but I
> did get it wrong.  It should be Rational (-capo, 2) I think.
> This should instantiate a Rational with value -capo/2.
>
> (Sorry, I'm not set up to try this at the moment, so it
> might still bomb.)
As I say, I've got that working. I strongly don't think it's that simple
:-( because Pitch seems to work on the tonal scale. Rational is used
purely for adjustments, not for thinking in semitones :-( because it
needs to deal with quarter tones and other such stuff.

I'm just going to submit the working code, and wait for a "hey, you
shouldn't do it that way!" :-)

Cheers,
Wol

---
----
Join the Frogs!