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
float to int?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [4 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Robot



Joined: Aug 18, 2007
Posts: 2
Location: Brooklyn

PostPosted: Mon Sep 10, 2007 5:48 pm    Post subject:  float to int? Reply with quote  Mark this post and the followings unread

wAZ UP ChucKers?

1st off, Im lovin me some chuck. It so good for makin justly tuned scales. It also so good for makin joystick instruments. It just so good.


But I am stuck on one thing which I think should be easy.

How can I turn a float into an integer? either rounding or truncating, I don't care?

Basically, my joystick axis gives me a float range of -1.0 through 1.0. I want to use it's postion to index an array of frequencies to use as my instrument frequency. ie, I want it to convert -1.0 - 1.0 into 0-7

I have this formula that gives me 0.0-7.0 rounded, which as it turns out is not good enough.

Math.round(((e.Throttle + 1.0)/2.0 * 7.0)) => float note;

and then doing this:

scale[note] => m.freq;

gets me a big phat:
array index 1 must be of type 'int' or 'string', not 'float'



I have tried doing stuff I thought would work like using integer math like:
((e.Throttle+1.0)*7)/2

but to no avail.

What is the obvious thing I am missing here?

Thanks for all the rad chuck'n, and Ill post some stuff I have been makin at some point.
Back to top
View user's profile Send private message
moudi



Joined: Oct 07, 2006
Posts: 63
Location: Bern Switzerland

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

Hi Robot and welcome in the world of chuck.

It seems that you're looking for a possibility to cast float to int.
Chuck automatically (implicit) casts int to float, but since
you lose information casting from float to int you need an
explicit cast:

Code:
4.8 $ int => int foo;


enjoy chucking
/moudi
Back to top
View user's profile Send private message Visit poster's website
Robot



Joined: Aug 18, 2007
Posts: 2
Location: Brooklyn

PostPosted: Tue Sep 11, 2007 4:32 am    Post subject: Reply with quote  Mark this post and the followings unread

Heck yea, that works! That is the 1st I have heard of explicit type casting in ChucK. THanks so much.

Now I can use the throttle axis of my joystick to set a pitch in a seven note scale, brilliant!
Back to top
View user's profile Send private message
robin746



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

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

Robot wrote:
Now I can use the throttle axis of my joystick to set a pitch in a seven note scale, brilliant!


That's the sort of sentence I like to read.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [4 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