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
Up and Down
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [13 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
conexionismo



Joined: Dec 29, 2007
Posts: 11
Location: spain

PostPosted: Sat Dec 29, 2007 10:18 pm    Post subject: Up and Down Reply with quote  Mark this post and the followings unread

Hello.

I am new in this great language.

I have one simple thing:

A loop counter counts from 0 to 100, to 99 to 0, from 0 to 100, etc.

Surely it is very easy, but not achievement.

for? while?

Excuse my ignorance and my spanish english.

Thanks
Back to top
View user's profile Send private message Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Sun Dec 30, 2007 4:12 am    Post subject: Reply with quote  Mark this post and the followings unread

Hi, conexionismo! Welcome!

Your English is better then my Spanish but we can speak ChucK together.
See if you can understand this;

Code:
1 => int direction;
 int counter;

100 => int max;
0 => int min;

while (true)
  {
  <<<counter>>>;
  //your code goes here

  0.25::second => now;

  if (counter >= max) -1 => direction;
  else if (counter <= min) 1 => direction;
  direction +=> counter;
  }


The trick is that every time we loop we add 1 or -1 to the counter and we switch the direction if we hit the minimum or the maximum.

TIP; if you don't know what kind of loop to use take "while", you can always write any loop as a while loop.

Happy ChucKing!

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Sun Dec 30, 2007 1:04 pm    Post subject: Reply with quote  Mark this post and the followings unread

Yes. Kassen's method is really easy to understand. Thanks. Very Happy
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Sun Dec 30, 2007 1:41 pm    Post subject: Reply with quote  Mark this post and the followings unread

ahhh i did tried to do that in a shorter expression..
I thought I should use "if" for doing that
but after playing around with the idea,
I come up with this nasty expression..
I'm not sure if I can simplify it more
but it works now:

Code:
100 => int max;
int i, j;
while(true)
{
    <<< j + 1 >>>;
    i++;   
    1 - 2 * (i % (max * 2) - i % max) / max +=> j;
    40::ms => now;
}


the expression's quite a mess now hahahha -_-
- - -
update: after I let my brain float around for a while..
I came up with a simplified one.. with only one variable! oh yay..
Code:

100 => int max;
int i;
while(true)
{
    <<< max - Std.abs(i % (2 * max) - max) >>>;
    i++;   
   
    40::ms => now;
}
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
conexionismo



Joined: Dec 29, 2007
Posts: 11
Location: spain

PostPosted: Sun Dec 30, 2007 3:22 pm    Post subject: great! Reply with quote  Mark this post and the followings unread

Thanks!

The kassen and the kijjaz code works fine.

I thought not in 'else if' and >=.

Knew that I had to be an expression like that of kijjaz, but my knowledge is limited.

Chuck is powerful and a new and exciting world!!
Back to top
View user's profile Send private message Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Mon Dec 31, 2007 11:13 am    Post subject: Reply with quote  Mark this post and the followings unread

kijjaz wrote:
ahhh i did tried to do that in a shorter expression..
Code:

100 => int max;
int i;
while(true)
{
    <<< max - Std.abs(i % (2 * max) - max) >>>;
    i++;   
   
    40::ms => now;
}


I love it!

How about;

Code:

100 => int max;
int i;
while(true)
{
    <<< max - Std.abs(i++ % (2 * max) - max) >>>;
   
    40::ms => now;
}


Yet smaller! Yet more perverse! ;¬)

I think it's harder on the cpu though and I think it will run into issues once "i" gets larger then the largest integer we can use (that's very large but that number does exist).

I think defining a minimal value is useful too but with your version you could simply define that as a offset.

Not a very friendly expression but lots of fun, cool!

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Mon Dec 31, 2007 11:16 am    Post subject: Re: great! Reply with quote  Mark this post and the followings unread

conexionismo wrote:

Chuck is powerful and a new and exciting world!!


Yes, it is! Isn't it fun?

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Mon Dec 31, 2007 12:10 pm    Post subject: Reply with quote  Mark this post and the followings unread

hmm yes.. i can grow into a very very large int
to stop that, i might use (i + 1) % (2 * max) => i; instead of i++;

hmm -_- this is kinda fun after all those somewhat chaotic sound synthesis i've been doing. -_-"
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Mon Dec 31, 2007 1:16 pm    Post subject: Reply with quote  Mark this post and the followings unread

Yeah for sequencing I use this all the time;

++i%16 => i;

it's compact, clear and doesn't overflow. I like it.

You can set stuff like this loose on the STK pianos (using Std.mtof) as well, I bet you could do great arpeggios in very little code. There's at least as much space for math in music as there is in sound.

_________________
Kassen
Back to top
View user's profile Send private message Send e-mail Visit poster's website
conexionismo



Joined: Dec 29, 2007
Posts: 11
Location: spain

PostPosted: Mon Dec 31, 2007 5:16 pm    Post subject: Chuck it's fun! Reply with quote  Mark this post and the followings unread

Yes, Chuck it's fun.

The computer is a good musical instrument, but until now it was only to make sounds, helped by midi controllers who used to be copies of the traditional instruments.

The livecode is a good tool to ensure that the computer is, moreover, a good interface for controlling musical events. Instant is lost, but wins a immersive experience where they control many parameters at once.

Yes, Chuck it's fun.
Back to top
View user's profile Send private message Visit poster's website
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Thu Jan 03, 2008 8:20 am    Post subject: Reply with quote  Mark this post and the followings unread

While playing around with more simple algorithm, i've found this:

Code:
chuck %> { int a, b;
a++ => b++;
}

chuck %> [chuck](VM): sporking incoming shred: 1 (chuck_file.JHxIXL)...

Segmentation fault (core dumped)

hahhaha -_-
maybe that expression's too out for ChucK. -_-"
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Frostburn



Joined: Dec 12, 2007
Posts: 255
Location: Finland
Audio files: 9

PostPosted: Thu Jan 03, 2008 1:35 pm    Post subject: Reply with quote  Mark this post and the followings unread

Kassen wrote:

How about;

Code:

100 => int max;
int i;
while(true)
{
    <<< max - Std.abs(i++ % (2 * max) - max) >>>;
   
    40::ms => now;
}


Yet smaller! Yet more perverse! ;¬)


Nice. :)

What about just;
Code:

100 => int max;
-max => int i;
while(i <= max)
{
    <<< max - Std.abs(i++) >>>;
   
    40::ms => now;
}

_________________
To boldly go where no man has bothered to go before.
Back to top
View user's profile Send private message
kijjaz



Joined: Sep 20, 2004
Posts: 765
Location: bangkok, thailand
Audio files: 4

PostPosted: Thu Jan 03, 2008 8:53 pm    Post subject: Reply with quote  Mark this post and the followings unread

Frostburn: wow, that's neat for up and down. ^_^
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [13 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