Hi Mike,

I can post my envelope class with some examples of how I use it and I intend also to write a similar class using CurveTable. But this will be after a couple of weeks because I'm extremely busy these days and have no time, I'll keep you posted.

I agree, what is best always depends on the application, sometimes short, fast and application-specific code is needed and sometimes reusable and generic code is a necessity. And some things are also a matter of preference.

I started using the -1 .op status when using the physical models like clarinet which are quite expensive and it really helped me to save a lot of cpu. Envelopes are not that expensive but I use a lot of them all the time but it's better to make sure they're not running when not needed rather than trying to find out where the cpu is wasted after having trouble, I think.

Dimitris

--- Στις Κυρ., 23/08/09, ο/η mike clemow <gelfmuse@gmail.com> έγραψε:
Dimitris,

I see your point about the -1 .op status.  I'm going to re-work my
code to use that and will let you know what kind of CPU efficiency I
see.  I like the "secure" code you posted, however, for the most part,
I'm building one-off instruments that I use to perform and find that I
generally get more use out of smaller, simpler blocks of code.
Perhaps we could combine your secure style with the CurveEnvelope
method of envelope and create a SecureCurveEnvelope class (with a
shorter name, of course).  This might--at least in the short
term--satisfy our need for more flexible envelopes.

-Mike

2009/8/22 mike clemow <gelfmuse@gmail.com>:
> Hey Dimirtris,
>
> This code looks like a better way of doing things.  Thanks for
> posting.  Do you have any example/usage code you could post?
>
> -Mike
>
> 2009/8/14 Bozelos Dimitris <dbozelos@yahoo.gr>:
>> Hi,
>>
>> thanks everyone for the replies. Gen[n] and CurveTable are useful I will
>> give them a try. If i'm not mistaken the curves generated this way pass
>> through the intermediate points, so I was thinking of bezier curves because
>> they pass in between the intermediate points and meet only the edges and
>> they are smoother.
>>
>> Thanks for the code Mike! I looked at your technique and I have a couple of
>> observations/questions. I guess you disconnect the envelope to save cpu when
>> not needed. But you have the phasor in ( .op() == 0 ) - probably for the
>> same reason - which I haven't verified it but according to the manual should
>> still be active but giving output of 0 - so it wastes cpu, no?  And
>> shouldn't be needed to block the input since you use the multiplier's gain
>> for it, no? I usually use the passthru status ( .op() == -1 ) which
>> shouldn't use any cpu. I post part of my envelope class in case anybody
>> would be interested in this way. Maybe too much for just an envelope but in
>> long complicated code I find it really time saving to use this kind of
>> 'secure' code:
>>
>> public class XEnvelope
>> {
>>     Envelope envelope;
>>
>>     UGen @ inputRef;
>>     UGen @ outputRef;
>>
>>     // default status: passthru
>>     -1 => envelope.op;
>>
>>     int isChucked;  // 1 if connected both ways (left-right)
>>     int isOn;       // 1 if envelope.op() == 1
>>     int isRunning;  // 1 while envelope is running
>>
>>     5 => int isBlocked; // if( isBlocked == 5 ) it is not blocked
>>                         // otherwise it indicates the op status before
>> blocked
>>
>>     // connect input
>>     // if already connected, disconnect and connect the new one
>>     fun void leftChuck( UGen input )
>>     {
>>         if( inputRef != NULL )
>>         {
>>             leftUnchuck();
>>         }
>>
>>         input  => envelope;
>>         input @=> inputRef;
>>
>>         if( outputRef != NULL )
>>         {
>>             1 => isChucked;
>>         }
>>     }
>>
>>     // connect to output
>>     // if already connected, disconnect and connect the new one
>>     fun void rightChuck( UGen output )
>>     {
>>         if( outputRef != NULL )
>>         {
>>             rightUnchuck();
>>         }
>>
>>         envelope  => output;
>>         output   @=> outputRef;
>>
>>         if( inputRef != NULL )
>>         {
>>             1 => isChucked;
>>         }
>>     }
>>
>>     // disconnect input
>>     fun void leftUnchuck()
>>     {
>>         if( inputRef != NULL )
>>         {
>>             inputRef  =< envelope;
>>             NULL     @=> inputRef;
>>
>>             0 => isChucked;
>>         }
>>     }
>>
>>     // disconnect output
>>     fun void rightUnchuck()
>>     {
>>         if( outputRef != NULL )
>>         {
>>             envelope  =< outputRef;
>>             NULL     @=> outputRef;
>>
>>             0 => isChucked;
>>         }
>>     }
>>
>>     // when blocking the envelope be careful not to change envelope.op
>>     // elsewhere. security will be enhanced in the future
>>     fun void block()
>>     {
>>         if( isBlocked == 5 )
>>         {
>>             envelope.op() => isBlocked;
>>             0             => envelope.op;
>>         }
>>     }
>>
>>     fun void unblock()
>>     {
>>         if( isBlocked != 5 )
>>         {
>>             isBlocked => envelope.op;
>>             5         => isBlocked;
>>         }
>>     }
>>
>>     // being OFF, turn on, run and hold
>>     // needs to be turned off in the end with 'off'
>>     fun void on( float start, float target, int milliseconds )
>>     {
>>         if( isChucked && !isOn )
>>         {
>>             1 => isRunning => isOn => envelope.op;
>>
>>             milliseconds::ms => envelope.duration;
>>             start            => envelope.value;
>>             target           => envelope.target;
>>
>>             milliseconds::ms => now;
>>
>>             0 => isRunning;
>>         }
>>         else if( !isChucked )
>>         {
>>             <<< "ERROR: can't turn the envelope on - not connected" >>>;
>>         }
>>         else if( isOn )
>>         {
>>             <<< "ERROR: can't turn the envelope on - already on" >>>;
>>         }
>>     }
>>
>>     // being OFF, turn on, run and hold
>>     // needs to be turned off in the end with 'off'
>>     fun void on( float start, float target, int milliseconds )
>>     {
>>         if( isChucked && !isOn )
>>         {
>>             1 => isRunning => isOn => envelope.op;
>>
>>             milliseconds::ms => envelope.duration;
>>             start            => envelope.value;
>>             target           => envelope.target;
>>
>>             milliseconds::ms => now;
>>
>>             0 => isRunning;
>>         }
>>         else if( !isChucked )
>>         {
>>             <<< "ERROR: can't turn the envelope on - not connected" >>>;
>>         }
>>         else if( isOn )
>>         {
>>             <<< "ERROR: can't turn the envelope on - already on" >>>;
>>         }
>>     }
>>
>>     // being ON, run to target and turn off
>>     fun void off( float target, int milliseconds )
>>     {
>>         if( isOn && !isRunning )
>>         {
>>             1 => isRunning;
>>
>>             milliseconds::ms => envelope.duration;
>>             target           => envelope.target;
>>
>>             milliseconds::ms => now;
>>
>>              0 => isRunning;
>>             -1 => envelope.op;
>>              0 => isOn;
>>         }
>>         else if( !isOn )
>>         {
>>             <<< "ERROR: can't turn the envelope off - already off" >>>;
>>         }
>>         else if( isRunning )
>>         {
>>             <<< "ERROR: can't turn the envelope off - running" >>>;
>>         }
>>     }
>>
>>     // being ON, move to next target
>>     fun void to( float target, int milliseconds )
>>     {
>>         if( isOn && !isRunning )
>>         {
>>             1 => isRunning;
>>
>>             milliseconds::ms => envelope.duration;
>>             target           => envelope.target;
>>
>>             milliseconds::ms => now;
>>
>>             0 => isRunning;
>>         }
>>         else if( !isOn )
>>         {
>>             <<< "ERROR: can't move the envelope - envelope off" >>>;
>>         }
>>         else if( isRunning )
>>         {
>>             <<< "ERROR: can't move the envelope - running" >>>;
>>         }
>>     }
>>
>>     // being OFF, turn on, run and turn off
>>     fun void onOff( float start, float target, int milliseconds )
>>     {
>>         if( isChucked && !isOn )
>>         {
>>             1 => isRunning => isOn => envelope.op;
>>
>>             milliseconds::ms => envelope.duration;
>>             start            => envelope.value;
>>             target           => envelope.target;
>>
>>             milliseconds::ms => now;
>>
>>             -1 => envelope.op;
>>              0 => isOn;
>>              0 => isRunning;
>>         }
>>         else if( !isChucked )
>>         {
>>             <<< "ERROR: can't turn the envelope on/off - not connected" >>>;
>>         }
>>         else if( isOn )
>>         {
>>             <<< "ERROR: can't turn the envelope on/off - already on" >>>;
>>         }
>>     }
>> }
>>
>> ________________________________
>> Χρησιμοποιείτε Yahoo!
>> Βαρεθήκατε τα ενοχλητικά μηνύ ματα (spam); Το Yahoo! Mail διαθέτει την
>> καλύτερη δυνατή προστασία κατά των ενοχλητικών μηνυμάτων
>> http://login.yahoo.com/config/mail?.intl=gr
>> _______________________________________________
>> chuck-users mailing list
>> chuck-users@lists.cs.princeton.edu
>> https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
>>
>>
>
>
>
> --
> http://michaelclemow.com
> http://semiotech.org
>



--
http://michaelclemow.com
http://semiotech.org
_______________________________________________
chuck-users mailing list
chuck-users@lists.cs.princeton.edu
https://lists.cs.princeton.edu/mailman/listinfo/chuck-users


Χρησιμοποιείτε Yahoo!
Βαρεθήκατε τα ενοχλητικά μηνύ ματα (spam); Το Yahoo! Mail διαθέτει την καλύτερη δυνατή προστασία κατά των ενοχλητικών μηνυμάτων
http://login.yahoo.com/config/mail?.intl=gr