[chuck-users] late binding

Robert Poor rdpoor at gmail.com
Wed Feb 10 19:00:40 EST 2010


Hi Beinan:

Your code is close; the uber-overloaded ChucK operator is your source  
of grief.

Overlooking a couple of typos (i.e. "Class MyInstrument" should be  
"public class MyInstrument", "Public void Play" should be "fun void  
Play"), the real problem is lurking in line2 of my_chuck.ck:

	Mandolin man => dummy.m_whatever;

To the compiler, it appears that you're making a UGen link, when what  
you really mean to be doing is assigning a *reference* of 'man' to  
dummy's m_whatever instance variable.   And for that, you want the @=>  
operator instead:

	Mandolin man @=> dummy.m_whatever;

Amended code follows.  Hope this helps.

- Rob

// ===== File: instr.ck
public class MyInstrument {

     StkInstrument @ m_whatever;

     fun void Play(dur duration) {
         m_whatever.noteOn(1);
         duration => now;
         m_whatever.noteOff(1);
     }
}
// ===== EOF =====
// =====- File: my_chuck.ck
MyInstrument dummy;
Mandolin man @=> dummy.m_whatever;
dummy.m_whatever => dac;

1::second => dur d;
dummy.Play(d);
// ===== EOF =====

On 10 Feb 2010, at 15:40, Beinan Li 2 wrote:

>
> Hi Chuckists,
>
> I’d like to dynamically switch instrument as in my small code (chuck  
> instr.ck my_chuck.ck)
>
> // instr.ck
> Class MyInstrument
> {
>                 StkInstrument@ m_whatever;
>
>                 Public void Play(dur duration)
> {
>                 m_whatever.noteOn(1);
> duration => now;
> m_whatever.noteOff(1);
> }
> }
>
> // my_chuck.ck
> MyInstrument dummy;
> Mandolin man => dummy.m_whatever;
> Dummy.m_whatever  => dac;
>
> 1::second => dur d;
> dummy.Play(d);
>
> Then I got this error:
> [chuck](VM): NullPointerException: (UGen link) in  
> shred[id=5:my_chuck.ck], PC=[46]
>
>
> Where am I wrong with this late binding?
>
> Thanks,
> Beinan
> _______________________________________________
> chuck-users mailing list
> chuck-users at lists.cs.princeton.edu
> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users

--:
Robert Poor
e:	robert.poor at nbt-ventures.com
p:	+1 617 818 5115
b:	http://blog.nbt-ventures.com
--:
This message and the information it contains are the proprietary and  
confidential property of NBT Ventures and may be privileged. If you  
are not the intended recipient, please do not read, copy, disclose or  
distribute its contents to any party, and notify the sender immediately.
--:

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20100210/e0af7464/attachment.html>


More information about the chuck-users mailing list