electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
go to the radio page Live at electro-music.com radio 1 Please visit the chat
poster
 Forum index » DIY Hardware and Software » ChucK programming language
Upcasting of classes?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [11 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
djdaphalgan



Joined: Jul 19, 2007
Posts: 20
Location: Belgium

PostPosted: Fri Sep 07, 2007 3:03 am    Post subject: Upcasting of classes? Reply with quote  Mark this post and the followings unread

Hi, is upcasting/downcasting of classes possible? Example: I make an array of Instruments, and I put a Moog, a Flute, ect. in there. Chuck will see an Instrument if I get an element out of this array, so I can only use the methods (functions) of Instrument. If I would like to use other methods (like the once of Moog), that I have to upcast my Instrument to a Moog object (don't know for sure if upcast/dawoncast is the correct term). Is this possible in chuck?
Back to top
View user's profile Send private message
spencer



Joined: Aug 16, 2006
Posts: 53
Location: northern california

PostPosted: Thu Sep 13, 2007 12:08 am    Post subject: Reply with quote  Mark this post and the followings unread

Hi djdaphalgan,
Yep--the $ cast operator works on objects as well as primitive types. E.g.
Code:
UGen ugens[10];

new SinOsc @=> ugens[0];

440 => ( ugens[0] $ SinOsc ).freq;

ugens[0] => dac;

1::day => now;
will do the right thing. But, uh, casting to an class that is not the object's class hierarchy can crash chuck.

spencer
Back to top
View user's profile Send private message
djdaphalgan



Joined: Jul 19, 2007
Posts: 20
Location: Belgium

PostPosted: Thu Sep 13, 2007 12:26 am    Post subject: Reply with quote  Mark this post and the followings unread

I did'nt not know the cast $ operator.
thanx for the info.
Back to top
View user's profile Send private message
robin746



Joined: Sep 02, 2007
Posts: 26
Location: Eire

PostPosted: Wed Sep 19, 2007 4:58 am    Post subject: Reply with quote  Mark this post and the followings unread

Can you explain, for us newbies, what that code is supposed to do that couldn't be done without the cast?
Back to top
View user's profile Send private message Visit poster's website
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Wed Sep 19, 2007 5:06 am    Post subject: Reply with quote  Mark this post and the followings unread

This is something I haven't done before also..
but it's just cool.

I once tried putting different instances of UGens in an array of UGen,
i couldn't access each UGen's individual functions and value
(because it's refered to as only a UGen, not a particular kind of UGen)

so casting like this is just the right way to work out the problem.
thanks! .. I didn't think about this at all hahah ^_^
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
robin746



Joined: Sep 02, 2007
Posts: 26
Location: Eire

PostPosted: Wed Sep 19, 2007 5:15 am    Post subject: Reply with quote  Mark this post and the followings unread

OK, I think I follow that. In my dabbling I had a similar problem. Unfortunately this method still doesn't solve it because different Ugens have different methods that need to be used to, say, play a note.

If I could subclass Ugens then I could create my own PlayNote method for each, which does different things depending on the parent class. Then all I would need to do, no matter which Ugen, is say PlayNote.

This seems like obvious functionality to someone from Python, but I don't think it can be done at all in ChucK.
Back to top
View user's profile Send private message Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Wed Sep 19, 2007 6:55 am    Post subject: Reply with quote  Mark this post and the followings unread

No, it would be good to be able to write our own proper Ugens (or extend existing ones) and it *is* obvious functionality.

ChucK isn't "finished" yet. Personally I hope it never will be, aside from the usefulness the development itself is exciting to me.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
robin746



Joined: Sep 02, 2007
Posts: 26
Location: Eire

PostPosted: Wed Sep 19, 2007 6:59 am    Post subject: Reply with quote  Mark this post and the followings unread

I am glad that "no" means we agree. Smile

I still think maybe I'm missing things since I am so completely new to ChucK. I don't mean to be hammering on about things that are missing!
Back to top
View user's profile Send private message Visit poster's website
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Wed Sep 19, 2007 7:15 am    Post subject: Reply with quote  Mark this post and the followings unread

Or maybe you can use another int array to store "UGen types" in the ugen array..
and use if statement to select the proper casting and note-playing method for each UGen in the UGen array.

I haven't tried this yet, but i'll work it out as one homework and post it,
if i've got more time this week ^_^
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
robin746



Joined: Sep 02, 2007
Posts: 26
Location: Eire

PostPosted: Wed Sep 19, 2007 7:33 am    Post subject: Reply with quote  Mark this post and the followings unread

kijjaz wrote:
Or maybe you can use another int array to store "UGen types" in the ugen array..
and use if statement to select the proper casting and note-playing method for each UGen in the UGen array.


That gets messy since there is no case statement or equivalent. (Unless I've missed that too!)
Back to top
View user's profile Send private message Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Wed Sep 19, 2007 7:40 am    Post subject: Reply with quote  Mark this post and the followings unread

robin746 wrote:
I am glad that "no" means we agree. Smile

I still think maybe I'm missing things since I am so completely new to ChucK. I don't mean to be hammering on about things that are missing!


Well, your statement was in a negative form so I thought that was the right way to agree. Maybe this was just me applying Dutch syntax to English, this happens.

The fun thing with a occasionally buggy and incomplete language is that hammering on things you are missing is often very constructive; I do it a lot too but only because Ge inexplicitly asked for it many times. I don't think anybody said "ChucK can be buggy and is incomplete" more times then Ge did.

As long as it's friendly hammering nobody will mind, hammering is cool, constructive hammering will build one a nice house.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [11 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use