electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks GalleryGallery 
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
How do I refresh a shred, keeping a value without crashing?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [1 Post]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Dr. Spankenstein



Joined: Mar 03, 2007
Posts: 136
Location: Cambridge
Audio files: 1

PostPosted: Mon Jan 21, 2008 5:33 am    Post subject: How do I refresh a shred, keeping a value without crashing? Reply with quote  Mark this post and the followings unread

I've simplified the process as much as I can to demonstrate what I'm aiming for.

The idea is that I have to refresh a shred every so often as to avoid garbage errors.

Whilst this method works fine, it no longer works when I try to introduce a function that gets the last known value of a variable when the shred is refreshed (e.g. machine.removed then sporked)

Class.txt

Code:


public class Hello
{
   static int ValueRefresh;
   public static int setValueRefresh(int input)
   {
      input => ValueRefresh;
   }
   public static int getValueRefresh()
   {
      return ValueRefresh;
   }
}

Hello hello;
Machine.add( "Refresh.txt" ) => int refresh;

while(true)
{
   10::minute => now;
}



Refresh.txt

Code:


Hello hello;
hello.getValueRefresh() => int x;
x + 10 => int y;

spork ~ refreshing() @=> Shred @ refreshingDestroy;
printx();

fun void printx()
{
   while(x < y)
   {
      <<<x>>>;
      1::second => now;
   }
   Machine.add( "refresh.txt" ) => int refresh;
   me.exit();   
}

fun void refreshing()
{
   while(true)
   {
      x++;
      hello.setValueRefresh(x);
      0.1::second => now;
   }
}



This method will always crash ChucK and I'm not sure how to prevent that other than syncing the two times together (e.g. both printx() and refreshing() use 1::second => now)?! This isnt ideal.

Any ideas anyone?

Thanks,

Rhys

PS. On a side note, how can I parse a string as an integer. In other words cast a string "23" to an integer of value 23?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [1 Post]
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
Top Selling Products! CLICK HERE!

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003, 2004, 2005, 2006 and 2007 by electro-music.com