electro-music.org   Dedicated to experimental electro-acoustic
and electronic music
 
 Front Page  |  Radio  |  Forum  |  Media  |  Playlists  |  Wiki
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 
 Forum index » DIY Hardware and Software » ChucK programming language
Loop
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [2 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
Hayden



Joined: Jul 12, 2010
Posts: 2
Location: Wellington, NZ

PostPosted: Tue Jul 13, 2010 5:14 am    Post subject: Loop
Subject description: how do you set the dur of a loop
Reply with quote  Mark this post and the followings unread

Hi
I have just started learning to use chucK, today, and im playing around and i came across this loop, and i was wondering what i need to write if i wanted the loop to only play for, say 5 seconds

here is the code so far

___________________


SqrOsc s => dac;


while( true )
{
150::ms => now;
Std.rand2f(150.0, 600.0) => s.freq;
}

______________________

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



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

PostPosted: Tue Jul 13, 2010 6:40 am    Post subject: Reply with quote  Mark this post and the followings unread

One way is to put the loop in a shred.
Code:

SqrOsc s => dac;

true => int playing;

fun void player() {
   while( playing )
   {
   150::ms => now;
   Std.rand2f(150.0, 600.0) => s.freq;
   }
}

spork ~ player();
5::second => now;
false => playing;


This will start player() as a kind of parallell process, called a shred. Using the boolean variable "playing" in this way will cause the shred to end gracefully once "playing" is set to false. There is also a command for killing a shred in a more brutal way I think, but I prefer this way as it matches the recommended way of ending threads in e.g. Java. Shreds are not the same as threads (do a search here on the forum if you want to know more), but you can often apply the same programming practices on them.

_________________
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 [2 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
Log in
Username:     Password:      Log me on automatically each visit    


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2026 by electro-music.org