Page 5 of 5
Re: it is about time...
Posted: Wed Jan 25, 2017 12:53 am
by 110
i dont get the manual about the scheduler.
the scheduler of the main thread runs only at 10 ms, but when you turn audio on, it runs at samplingrate?
both is hard to believe. i expected something like 0.5 or 1.0 milliseconds (think music sequencing)
Re: it is about time...
Posted: Wed Jan 25, 2017 6:02 am
by KG_is_back
110 wrote:so i´ve ben readin up on comparisons for an hour but i dont get it.
is there no simple method to compare two values and have it return a value?
i am writing small expressions using conditoinal statements like 300 * (a>0) + 500 * (a<=0) all the time, it is far more straight forward than splitting it up into 4 processes and use some kind of if type of statement... but 300 really wants to be multiplicated with 0 and 1 and doesnt really want to connect with "true".
There are several ways to handle this. You can for example modify the TrueClass and FalseClass to be convertible to int.
Code: Select all
class FalseClass; def to_i; 0 end end
class TrueClass; def to_i; 1 end end
with this you simply add .to_i every time you want the boolean to behave like a 0/1. for example in your formula:
300 * (a>0).to_i + 500 * (a<=0).to_i
Or even better, you can add coerce method into them. coerce method is used in ruby to convert numbers into common type (i.e when you multiply integer with float, it converts the int to float).
Code: Select all
#coerce method receives the second number "num and returns array of [num,self] both converted to common type
class FalseClass; def coerce(num); [num,0] end end
class TrueClass; def coerce(num); [num,1] end end
However, this makes it depends on the order of operands.
Code: Select all
9*(1>0) #returns 9. because multiply method is called upon 9 and within that method coerce is called, which does the conversion.
(1>0)*9 #raises error, because "*" method is not defined for TrueClass.
In both cases make sure the modification to the classes are made earier than they are used when schematic loads. For more info on how to do this and why, read page 231 in the manual (chapter "Declaration Order").
Re: it is about time...
Posted: Wed Jan 25, 2017 7:32 pm
by 110
okay, in my case i usually wrote the condition behind the statement, so that would work out.
but it is getting probematic if there is more than one condition, or if the rest of the calculation also aready contains comparison operators, right?
what do you think about my hack 5 * (1>0)?1:0