Stupid problem

Jan 11, 2010 at 2:55pm

Stupid problem

Hi.
I’m realy sorry to post that problem because I know that’s very simple but I don’t see my mistake.
This script is just to stop a constant seeding of value to a changement of statut.

Here it is :
//entrée et sortie
inlets = 1;
outlets = 1;
//initation variable
var sortie = 0;
//démarrage de la convertion
if (inlets == 1) {
if (sortie == 0) {
sortie = 1;
}
}
else if (sortie == 1) {
sortie = 0;
}
post (sortie);

#47709
Jan 11, 2010 at 3:06pm

I’m not entirely sure what you’re trying to achieve. It looks like you’re just trying to swap the value of the sortie variable between 0 and 1 each time this code is called. What are you expecting to be printed to the max window each time and what values are you actually receiving?

A more efficient way to switch sortie each time would be:

sortie = 1-sortie;

lh

#171592
Jan 11, 2010 at 3:12pm

or

sortie = !sortie;


//start js
sortie = 0;
function bang(){
sortie = !sortie;
post(sortie);
}
//end js

#171593
Jan 11, 2010 at 4:58pm

First off, you probably need to define some function(s). The global code is only read once when the js object is instantiated. Then you might consider using the !- 1 (or == 0) object ;-)

#171594
Jan 11, 2010 at 6:55pm

Well i’m going to explain what i’m doing.

I do a trigger audio (with a mic input, the user put a threshold like fore a noise gate. When it goes over threshold, a sample choose by the user is playing) in Ableton Live for my final work at school.
For now, I have a noise gate who gives information about the statut (0=no sound and & 1=sound passed thrue the gate).

But it gives EVERYTIME statut but I just want to have the “impulsion” of the changement value. “One” will be the moment to play the sample.

I was sure that will be more easer in JS with a variable who will only change when the entrance value is different of him value.

Correct me if I’m wrong of course, I’m here to finish my school project of course :)

#171595
Jan 11, 2010 at 8:14pm

You might be looking for the change object. Here’s a simple example (you might want to add a few more things to smooth the signal).

– Pasted Max Patch, click to expand. –
#171596
Jan 11, 2010 at 9:06pm

Thanks man !!!
It do exactly the thing that I want !

#171597

You must be logged in to reply to this topic.