• Register
  • Help
Page 15 of 15 FirstFirst ... 512131415
Results 141 to 149 of 149

Topic: K2 portamento/glide script

Share/Bookmark
  1. #141
    Senior Member
    Join Date
    Apr 2004
    Location
    Seattle, WA
    Posts
    611

    Re: K2 portamento/glide script

    Quote Originally Posted by alx
    Hi Bob, thanks for the heads up.

    Actually, I have a bit of a newbie question for ya. I'm trying to work out a way of rounding up a number with decimal places to a whole number. Is there a way to do this at all in the K2 scripting engine?

    for eg, I have a formula that goes:
    $variable1 := ($interval / 12 * 10000 + 20000)

    $interval is always a value between 1 and 12. If I enter in 7, this formula should return a value of 25833.33... and K2 seems to ignore this, and all I end up with is a value of 20000 (it obviously just either ignores the first part or converts it to 0). Do you know of a way around this?
    Kontakt script is integer-only. The closest you'll get is:
    $variable1 := ($interval * 10000 / 12 + 20000)

    ...which will result in a value of 25833 in your example. You'll always get a truncation of the decimal places. A trick is possible to get it to round, if you need that kind of accuracy.
    $variable1 := ($interval * 100000 / 12 + 200005) / 10

    fizbin

  2. #142

    Re: K2 portamento/glide script

    Quote Originally Posted by fizbin
    Kontakt script is integer-only. The closest you'll get is:
    $variable1 := ($interval * 10000 / 12 + 20000)

    ...which will result in a value of 25833 in your example. You'll always get a truncation of the decimal places. A trick is possible to get it to round, if you need that kind of accuracy.
    $variable1 := ($interval * 100000 / 12 + 200005) / 10

    fizbin
    Thanks sbkp,

    and thank you very much Fizbin .

    Works perfectly.

    I stopped doing maths in year 10 of highschool, and I haven't done an inkling of it for 8 years. My maths brain is so rusty it's ridiculous, there's no chance I would ever have come up with that, so thanks again.


    EDIT: hmm for interests sake, I'm still not sure how that first one you posted works yet not mine, given that when I perform those operations on a calculator I still get 25833.33... but for some reason kontakt accepts it when it's that way round?!

  3. #143
    Senior Member
    Join Date
    Apr 2004
    Location
    Seattle, WA
    Posts
    611

    Re: K2 portamento/glide script

    Quote Originally Posted by alx
    Thanks sbkp,

    and thank you very much Fizbin .

    Works perfectly.

    I stopped doing maths in year 10 of highschool, and I haven't done an inkling of it for 8 years. My maths brain is so rusty it's ridiculous, there's no chance I would ever have come up with that, so thanks again.


    EDIT: hmm for interests sake, I'm still not sure how that first one you posted works yet not mine, given that when I perform those operations on a calculator I still get 25833.33... but for some reason kontakt accepts it when it's that way round?!
    The calculator does not do integer math. In integer math 7 divided by 12 is 0.

  4. #144

    Re: K2 portamento/glide script

    ah yes, thanks - I see now.

  5. #145
    Senior Member Big Bob's Avatar
    Join Date
    Jun 2005
    Location
    Apple Valley, California
    Posts
    323

    Re: K2 portamento/glide script

    Hi Alex,

    I didn't see your question until now, but I see that fizbin has already done a good job of helping you. To clarify a little I would only emphasize a few points. As fiz has said, in integer math 7/12 = 0. So, in order to not lose precision in a series of chained calculations, you should generally do as many of the multiplications as you can before doing any divisions. Thus while 7/12*10000 = 0, 7*10000/12 = 5833. What you have to watch out for when doing a long string of multiplies is that you don't exceed the limit for a 32-bit signed integer
    (which is from -2147483648 to +2147483647, ie -2**31 to +2**31 - 1).

    The rounding trick that fizbin illustrated is called 'half-adjusting'. The idea is that if your last step involves a division by some even number, you first add half of that divisor to the dividend. For example (using floating point values) if we divide 17 by 2, we expect an answer of 8.5 but if we restrict our answer to just one digit (which we would have to with only integer arithmetic), we would say the answer is 9. We usually think of doing this at the end by promoting the 0.5 to 1.0. However, we could also do it before the division by adding half of the divisor (2) first, ie (17 + 1)/2 = 9.

    So for your example, if you you were evaluating: $variable1 / 12 *10000 and $variable1 were say 5, your calculator would show 4166.67 which you would round to 4167. You can do the same in integer arithmetic by using the following operations: ($variable1 * 10000 + 6) / 12 = 4167.

    There is however a gotcha connected with half-adjusting. If $variable1 was -5 instead of +5, you would have to subtract 6 instead of adding it. In general, if signed variables are involved, the situation is more complex. Something like the following will give the right answer regardless of whether $variable1 is positive or negative.

    ($variable1 * 10000 + 6 * $variable1/abs($variable1))/12
    Big Bob (aka Wonderful Bob)

  6. #146

    Re: K2 portamento/glide script

    Big Bob,
    would it be theoretically possible to do either:
    A) tempo syncing instead of the glide time
    or
    B) Assigning a CCcontroller to adjust the length of the gliss?

    What if a piece needs different gliss lengths in the same piece? Load a different patch for each length?

    I love what you've done by the way... Great for solo female wordless vocals, for that "cantabile" feel.
    http://hopkins.composerarts.com

  7. #147
    Senior Member Big Bob's Avatar
    Join Date
    Jun 2005
    Location
    Apple Valley, California
    Posts
    323

    Re: K2 portamento/glide script

    "would it be theoretically possible to do either:
    A) tempo syncing instead of the glide time
    or
    B) Assigning a CCcontroller to adjust the length of the gliss?"

    Hi Jesse,
    Quite probably, but, remember the current implementation of the script is only the Pitch Control Engine, PCE, with a quick and dirty human interface. Before I ran into the stone wall with the change_vol noise problem, it was intended that we would all kick around ideas until we settled on the best and most useful form of the HI. That part of the project is still pending until (and if) NI gets rid of the current set of problems with the KSP and K2.

    Until then, we wait and wait and wait and wait ..........

    BTW has something happened to the quote function? doesn't seem to work as it did before?
    Big Bob (aka Wonderful Bob)

  8. #148

    Re: K2 portamento/glide script

    I think there is something with the quote function.

    Hey Bob. Even though there is the noise problem (which I don't even notice much) could we still try to do a tempo sync/cc controlled version?

    The knob would say

    "Gliss Duration"
    0-960 (240 is a quarter note 960 is a whole note)

    "Control with cc#: ___"
    http://hopkins.composerarts.com

  9. #149
    Senior Member Big Bob's Avatar
    Join Date
    Jun 2005
    Location
    Apple Valley, California
    Posts
    323

    Re: K2 portamento/glide script

    "I think there is something with the quote function."

    I am definitely having a quote problem, but, it seems just to be me because many others seem to be able to use it without a problem.

    "Hey Bob. Even though there is the noise problem (which I don't even notice much) could we still try to do a tempo sync/cc controlled version?

    The knob would say

    "Gliss Duration"
    0-960 (240 is a quarter note 960 is a whole note)

    "Control with cc#: ___"

    We could probably do something like that but I hate to just tack things onto a temporary Human Interface. I think it would be much better if we designed the HI in a unified way. Also, right now I'm kind of 'up to my eyeballs' with things to do. But, since I have already made all the source code and design charts available (I assume you have downloaded the complete package from Theo's website?), if you or someone you know is into scripting, feel free to modify or embellish the code in any way that you wish.

    However, if NI ever gets this thing working right, then I'll start a new thread to call for ideas of how to best design the HI and that will be your opportunity to chime in with your ideas and wishlist.
    Big Bob (aka Wonderful Bob)

Go Back to forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •