Re: [frogs] Chord-name-engraver plus capo - pitches

[ Thread Index | Date Index | More lilynet.net/frogs Archives ]


 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!


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/