Re: initializing classes

[email protected]
Newsgroups gmane.comp.audio.supercollider.user
Message-ID <CAFniQ7U_nJAzMvGc9yx9enTZzz2HRajR+cmkCV1pEdZ3eweXoA@mail.gmail.com>
On Tue, Mar 23, 2021 at 3:24 AM <[email protected]> wrote:
> This way it works, but then I have to initialize ALL variables, otherwise they are nil
>
> MyClass : MySuperClass{
> var <>midinote = #[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
> var <>dur = 1;
> var <>legato=#[1, 0.1, 1];
>
> *new { |midinote, dur, legato|
> ^super.newCopyArgs(midinote,dur, legato)
> }
> }

Many classes do this by providing defaults to the *new arguments:

    *new { |midinote = #[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], dur =
1, legato = #[1, 0.1, 1]|
        ^super.newCopyArgs(midinote,dur, legato)
    }

hjh

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.