Author |
Message |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Mon Jan 07, 2008 5:06 pm Post subject:
Events and the Public Class |
 |
|
Is it possible to have an Event in the public class that could then be used to trigger things outside of that class in different shreds?
For example in pseudo/naff code
Code: |
public class Class
{
Event e;
//Code in here to send out the event to all shreds that have e=>now
}
Class c;
while(true)
{
c.e => now; // Wait on the event being triggered in the public class
<<<"Event Signal">>>;
}
|
I hope that aint too confusing but I havent the first idea on how to write it down properly, hence I'm falling on the mercy of you guys.
Thanks for your time,
Rhys |
|
Back to top
|
|
 |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Tue Jan 08, 2008 7:47 am Post subject:
|
 |
|
Also, is it possible to spork and shred within a Public Class?
I can Machine.add files it seems but the shred reference is always not found when it comes to removing shreds, so I've resorted to using me.exit(); in shreds before then added them again in the Public Class.
It's kind of a way of avoid stack overflow errors which Kassen mentioned in a previous thread but every now and then it crashes ChucK.
Code: |
public class X
{
static int Shred1;
public static int shredShred1(int value)
{
if (value == 1)
{
0 => value;
// What code could I put here to remove Shred1 should it be running?
// Rather than resorting to me.exit() in Shred1.ck? --or is that safe enough?
<<<"Shred1 Sporked">>>;
//Machine.add( "Shred1.ck" ) => Shred1;
}
}
}
X x;
Machine.add( "Shred1.ck" ) => int Shred1;
// Is there anyway to load this shred with a reference that is declared in the public class?
while (true)
{
10::minute => now;
}
|
Thanks again,
Rhys |
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Tue Jan 08, 2008 9:00 am Post subject:
|
 |
|
Rhys,
I'm going to have to think about this and do a little puzzling, just last night I was thinking about similar questions... There are several issues working together here and they all need to line up but I'm not yet sure how.....
I'll get back to you and please keep me/us up to date about any progress you might make as this is quite interesting and usefull. _________________ Kassen |
|
Back to top
|
|
 |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Tue Jan 08, 2008 9:04 am Post subject:
|
 |
|
It's an area that requires long hours of thinking for me too, plus a whole lot of banging my head against a brick wall.
I'll keep you posted.
Rhys |
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Tue Jan 08, 2008 9:14 am Post subject:
|
 |
|
Wait, I miss-read.
The event is fairly easy but needs to be instantiated outside of the class.
Code: | public class Foo
{
static Event eve;
}
Foo foo;
Event bar @=> Foo.eve; |
I think that's it. As it's a static event we can assign bar directly to the class, not to a instance, it's the same for all instances. That bottom line creates a event and assigns it to "eve", eve from there on will be the same across the whole VM, we need to do this because static data in public classes doesn't get instantiated properly which is a known issue.
As for your other question, wouldn't Machine.replace() in case you already have such a shred and Machine.add() in other cases do? Do mind that shreds sporked from other files as opposed to functions do not share the parent shred's namespace and aren't automatically removed if the sporking shred exists.
Does that help already or do I need more coffee? _________________ Kassen |
|
Back to top
|
|
 |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Tue Jan 08, 2008 12:39 pm Post subject:
|
 |
|
I think it does. It certainly seems clear enough, I'll let you know how I get on after I'm done with the arpeggiator and MIDI control section of my code which I've thrown myself into.
Thanks for your help again Kassen.
Rhys |
|
Back to top
|
|
 |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Tue Jan 08, 2008 1:11 pm Post subject:
|
 |
|
It's work brilliantly. I just had to change the line:
to
Code: |
static Event @ eve;
|
This should be perfect for syncing up my shreds via a public class and eliminating garbage! |
|
Back to top
|
|
 |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Tue Jan 08, 2008 2:10 pm Post subject:
|
 |
|
I've hit a wall with these shreds and sporks though...
Code: |
public class X
{
static int Shred1;
public static int shredShred1()
{
<<<"Shred1 Sporked">>>;
Machine.replace(Shred1,"Shred1.txt") => Shred1;
}
}
X x;
int Shred1 @=> x.Shred1;
Machine.add( "Shred1.txt" ) => Shred1; // If I use this then I get error replace shred: no shred with id
Machine.add( "Shred1.txt" ) @=> x.Shred1; // If I use this then I get shreduler ERROR replacing shred
while (true)
{
10::minute => now;
}
|
Can't understand what is going on here?!
Rhys |
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Tue Jan 08, 2008 6:40 pm Post subject:
|
 |
|
First of all; primitives like integers don't need to be instantiated outside of the class. Int is fune, so is float, and dur, string is a borderline case, arrays and events give issues and need to be instantiated outside. This is a bug, but it's not *that* bad.
Next; I strongly suspect you mean to add "fun" to indicate you are defining a function. I can't correct this, then check what happens as the computer I'm on ATM doesn't have ChucK.
Third, I don't care if you call stuff foo, bar or I_like_candy, but please don't all call it the same name. I went "what?!!!!"three times reading this. Please?
 _________________ Kassen |
|
Back to top
|
|
 |
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Wed Jan 09, 2008 9:19 am Post subject:
|
 |
|
I am confused by the use of @ with x.Shred1 - could be that I don't know this part of ChucK.
What is
Code: | int Shred1 @=> x.Shred1; |
supposed to do? There is no value assigned to either Shred1 or x.Shred1 in this statement.
Code: | Machine.add( "Shred1.txt" ) @=> x.Shred1; |
x.Shred1 is a plain int, if I understand correctly. Surely you're not supposed to assign stuff to it using "@=>"?
/Stefan _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
 |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Thu Jan 10, 2008 9:56 am Post subject:
|
 |
|
Here's a sensibly named version of what I'm trying to do:
The Machine.replace command just throws up shreduler errors and the shred never gets replaced....why?
PUBLICCLASS.txt
Code: |
public class X
{
static int Shred1;
public static int addshred()
{
Machine.add("Shred1.txt") => Shred1;
}
public static int replaceshred()
{
Machine.replace(Shred1,"Shred1.txt"); //removed typo
<<<"Shred1 Replaced">>>;
}
}
X x;
while (true)
{
x.addshred();
10::minute => now;
}
|
SHRED1.txt
Code: |
X x;
<<<"Shred1 Running For 2 Seconds">>>;
2::second => now;
me.yield();
x.replaceshred();
//1::samp => now;
|
If anyone has any ideas as to why I'm getting this error, please let me know.
Thanks in advance,
Rhys Last edited by Dr. Spankenstein on Thu Jan 10, 2008 5:00 pm; edited 1 time in total |
|
Back to top
|
|
 |
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Thu Jan 10, 2008 1:04 pm Post subject:
|
 |
|
Checking the manual:
Code: |
// add
Machine.add( "boo.ck" ) => id
// replace shred with "bar.ck"
Machine.replace( id, "bar.ck" ); |
I don't think you're supposed to assign the return value from Machine.replace to anything. It will simply reuse that ID for a different shred. Try this instead:
Code: | Machine.replace(Shred1,"Shred1.txt"); |
/Stefan _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
 |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Thu Jan 10, 2008 5:02 pm Post subject:
|
 |
|
Sorry that was a typo error on my behalf. Even without the typo and written the way it is stated in the manual, this still doesnt work.
I just don't understand why?
Rhys |
|
Back to top
|
|
 |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Fri Jan 11, 2008 6:02 am Post subject:
|
 |
|
I think this might have something to do with my problems:
Code: |
int x;
int Shred1;
while (true)
{
if (x == 1)
{
Machine.add("1.txt") => Shred1;
// I can also use => int Shred1 but that doesnt work neither?
}
if (x == 2)
{
Machine.replace( Shred1 , "1.txt" );
}
x++;
2::second => now;
}
|
1.txt
Maybe I'm just being stupid, and if so, feel free to point it out but why when I have declared an integer does Machine.replace not see it as such?
In other words I get a "cannot replace shred/no shred with ID error" when the ID has already been declared as an int and therefore surely everything can see it? |
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Fri Jan 11, 2008 6:34 am Post subject:
|
 |
|
Just a guess;
Here "Shred" is the name of your integer but "Shred" is also the (reserved) name of a build in class. I'm surprised this is legal at all. That could be one issue? Not on a ChucKing computer ATM. _________________ Kassen |
|
Back to top
|
|
 |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Fri Jan 11, 2008 7:33 am Post subject:
|
 |
|
Unfortunately not, it can be named anything
Thanks for the help mind, but if you aint near a ChucKing computer dont sweat it. I'll keep trying various methods until I get somewhere.
Rhys |
|
Back to top
|
|
 |
Antimon
Joined: Jan 18, 2005 Posts: 4145 Location: Sweden
Audio files: 371
G2 patch files: 100
|
Posted: Fri Jan 11, 2008 9:30 am Post subject:
|
 |
|
I think I found it! There is no problem with ChucK. 1.txt finishes right after it starts, so when you run Machine.replace() on it there is actually nothing to replace - no running shred. Try adding an endless loop at the end of 1.txt:
Code: | <<<"Hello">>>;
while (true) {
1::second => now;
}
|
That will make the error message go away.
/Stefan _________________ Antimon's Window
@soundcloud @Flattr home - you can't explain music |
|
Back to top
|
|
 |
Dr. Spankenstein
Joined: Mar 03, 2007 Posts: 136 Location: Cambridge
Audio files: 1
|
Posted: Fri Jan 11, 2008 1:28 pm Post subject:
|
 |
|
Well done sir!
The problem is, when placed into my code it causes ChucK to crash when replacing the shred, but only on certain occasions (around the fourth or fifth time of replacing)
I'm just gonna have to live with stack overflow errors I think, unless I can find a way to replace it within a public class.
Rhys |
|
Back to top
|
|
 |
|