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: Han-Wen Nienhuys
Subject: Re: First attempt at new accidentals in git
Date: Sat, 16 Feb 2008 20:16:05 -0200

2007/11/17, Rune Zedeler <address@hidden>:
> >>>>    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.

we can change this to use the clone() method.

> 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?

no, not really - it might do a little too much GC or too little, but
disasters are unlikely.

> > 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?

No, I'm just saying that I want to have the base class be the smob
type (in this case: pitchclass), and that each function argument only
takes one type of smob.  The function itself may apply further logic
to enforce that the argument is a pitch rather than a pitchclass.

>
  > For instance we have
>

so this

> LY_DEFINE (ly_pitch_octave, "ly:pitch-octave",

will be:

{
   Pitchclass *pc = unsmob_pitchclass(arg);
   SCM_ASSERT_TYPE(pc, ... , "pitch class")
   if (Pitch *p = dynamic_cast<Pitch*> (pc))  //optionally: use unsmob_pitch()
     return scm_to_int(p->octave());
   else
     return SCM_BOOL_F;
   }

>            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.



-- 
Han-Wen Nienhuys - address@hidden - http://www.xs4all.nl/~hanwen




reply via email to

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