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
Newbie Q: Sporking and Global Arrays
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [5 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
vze26m98



Joined: Jun 12, 2011
Posts: 6
Location: GWB

PostPosted: Fri Jun 17, 2011 11:30 am    Post subject: Newbie Q: Sporking and Global Arrays Reply with quote  Mark this post and the followings unread

Hi all-

I thought I knew how to do this earlier in the week, but either I'm wrong or have forgotten the incantation.

In file "one.ck" I have a global array:

Code:
[6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96] @=> int freqs[];


...along with the code to feed this to a Ugen and on to the dac.

I have another file, "two.ck" that has only a reference to the Array "freqs" with different data from the above.

At the terminal, I want to "chuck -l one.ck" in one window, and want to "chuck + two.ck" in another, expecting the array of frequencies to change value.

I get either a sporked shred that does nothing or syntax errors.

Any idea what I'm doing wrong? Pointers on the best way to accomplish this?

Many thanks, Charles
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Fri Jun 17, 2011 12:37 pm    Post subject: Reply with quote  Mark this post and the followings unread

Only thing I know is that, in order to make things visible across chuck source files like this, you need to put them as static members of a class, like:

Code:
class MyGlobalStuff {
      [6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96] @=>static int freqs[];
}


Now you can do <<< "freq 1 iz: ", MyGlobalStuff.freqs[1] >>> etc.

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
vze26m98



Joined: Jun 12, 2011
Posts: 6
Location: GWB

PostPosted: Fri Jun 17, 2011 1:04 pm    Post subject: Reply with quote  Mark this post and the followings unread

Thanks Stefan-

I was heading in that direction. It seems you can't initalize an array inside a class, so this is the way to do it:

Code:
class Foo {
  static int freqs[];
}

[100, 150] @=> Foo.freqs;

<<<Foo>>>;


(Wow, strange Forum bug screws up ChucK code. Here's what it should be:

Posted Image, might have been reduced in size. Click Image to view fullscreen.

More later when I actually get my problem solved.

Best wishes, Charles


bug.png
 Description:
 Filesize:  19.89 KB
 Viewed:  5681 Time(s)

bug.png


Back to top
View user's profile Send private message
vze26m98



Joined: Jun 12, 2011
Posts: 6
Location: GWB

PostPosted: Fri Jun 17, 2011 1:09 pm    Post subject: Reply with quote  Mark this post and the followings unread

It has to be declared a "public" class to be visible from another shred:

Code:
public class X {
  static int freqs[];
}
Back to top
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 4145
Location: Sweden
Audio files: 371
G2 patch files: 100

PostPosted: Fri Jun 17, 2011 2:17 pm    Post subject: Reply with quote  Mark this post and the followings unread

Yeah public class and no initializer - check. This is one of those things that are poorly documented indeed.

Regarding weird code in your posts - you usually need to turn off HTML and smilies in the post when you include ChucK code - it's two of the five little checkboxes under the text area where you write your post. You need to keep BBCode on to make the code box work.

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
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 [5 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