lilypond-devel
[Top][All Lists]
Advanced

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

Re: First attempt at new accidentals in git


From: Rune Zedeler
Subject: Re: First attempt at new accidentals in git
Date: Sun, 18 Nov 2007 00:05:13 +0100
User-agent: Thunderbird 2.0.0.6 (X11/20071022)

Han-Wen Nienhuys skrev:
+  SCM virtual_smobbed_copy () { // AAARGH!
+    return smobbed_copy ();
+  }

for this, we usually have a clone() method, see the
VIRTUAL_COPY_CONSTRUCTOR method; so I suggest to use a smobbed_clone()
function.

   DECLARE_SIMPLE_SMOBS (Pitch);
This looks bad. You have to remove Pitch as a smobtype, and then
create an unsmob_pitch, which does

  dynamic_cast<Pitch*> (unsmob_pitchclass (obj))
That won't work with simple smobs.

Why? It should work if have virtual methods.

I feel a bit stupid now, sorry, but IMPLEMENT_SIMPLE_SMOBS does

  SCM CL::smobbed_copy () const
  {
    CL *ptr = new CL (*this);
    SCM s;
    s = scm_cons (SCM_PACK (CL::smob_tag_), SCM_PACK (ptr));
scm_gc_register_collectable_memory ((CL *)this, sizeof (CL), #CL " smob");
    return s;
  }

So it is hardcoded that the normal non-virtual copy-constructor is used to generate the smob. And it is hardcoded that the SCM should only use memory at the sizeof Pitchclass. If I stuff a Pitch in there won't we get severe trouble because it takes up more heap space than what the SCM memory management thinks?

Sorry for me being stupid.

Suppose you have x,
which is a pitch smob.  Then you have function f which takes a
pitchclass. From the scheme side of things, it's not clear that f can
be applied to x, since x has a different type.

Hmm, so what you say is that we should not allow scheme functions that work on both pitch and pitchclass? I don't like this - the whole idea of the pitchclass-pitch-thing is that the key signature contains both pitches and pitchclasses. The scheme programmer should be supplied with high-level-functions that compares pitches and pitchclasses in the right way - no matter whether they are pitches or pitchclassses. This will be ruined if he is not allowed to stuff pitches and pitchclasses into the same function.

For instance we have

LY_DEFINE (ly_pitch_octave, "ly:pitch-octave",
           1, 0, 0, (SCM pp),
           "Extract the octave from address@hidden@var{pp}.")
{
  Pitch *p = unsmob_pitch (pp);
  if(p==NULL)
    {
      LY_ASSERT_SMOB (Pitchclass, pp, 1);
      return SCM_BOOL_F;
    }
  int q = p->get_octave ();
  return scm_from_int (q);
}

The scheme function that returns the octave from a pitch, or #f from a pitchclass.

-Rune




reply via email to

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