Beginner Questions - controlling the bus 1 & 2 with one slider

Discussion in 'KONTAKT: Sampling, Programming & Scripting' started by William Palmer, May 16, 2019.

  1. William Palmer

    William Palmer Member

    94
    55
    Aug 7, 2018
    London
    Hi all!

    I'm new to making stuff in Kontakt...

    I have an instrument with two sample groups, 'Close' (containing close mic samples) and 'Far' (containing ambient mic samples). 'Close' is sending to bus 1. 'Far' is sending to bus 2.

    I'd like to control the volume of bus 1 and bus 2 with a single slider in the GUI (scaling 0-127), in order to cross fade from 'Close' to 'Far'.

    Do let me know of any scripts or tutorials that I should check out please!


    EDIT:
    I should add, I tried this technique: .

    He automates cc1 to control the amp.
    For whatever reason, I found this technique interrupted the playback of the my samples. The instrument I've made is a series of one shots - with a 2 second release on each sample.
     
  2. P.N.

    P.N. Active Member

    479
    172
    Aug 14, 2015
    Hi.
    CC or other mod shaper methods are only meant for group crossfading.

    For busses, use an array that simultaneously increases the volume of bus A while decreasing the volume of bus B.

    For simplicity, it would be better if your crossfade slider range is 0-1000, as most arrays i've seen contain 1001 elements. (I think i only have an equal power array for this, need to check that.)
    Anyway, keeping the slider range in line with the array will result in simpler, more direct code.

    Assuming a 1001 array size and a 0-1000 slider range, the code would look something like:

    Code:
    on ui_control($your_mix_slider)
        set_engine_par($ENGINE_PAR_VOLUME, %your_mix_array[$your_mix_slider], -1, -1, $NI_BUS_OFFSET + 0)
        set_engine_par($ENGINE_PAR_VOLUME, %your_mix_array[1000 - $your_mix_slider], -1, -1, $NI_BUS_OFFSET + 1)
    end on
    You would need to get the array (sorry, i'm not at my pc atm), and you might need to inverse the busses (replace "+ 0" with "+ 1" and vice versa), depending on how you'd like the crossfade to behave relative to the busses.

    Cheers.
     
    Last edited: May 16, 2019
    William Palmer likes this.
  3. OP
    OP
    William Palmer

    William Palmer Member

    94
    55
    Aug 7, 2018
    London
    Thank you!
    I'll see how I get on with that...
     
  4. EvgenyEmelyanov

    EvgenyEmelyanov Composer | Programmer

    IMHO, you do not need to declare a huge array for this. Let's say you have a slider from 0 to constant:

    Code:
    on init
      declare const $constant := 600000        {any integer from 0 to 1000000}
      declare ui_slider $your_mix_slider(0, $constant)
    end on
    
    Let's start with linear function:

    Code:
    on ui_control($your_mix_slider)
       set_engine_par($ENGINE_PAR_VOLUME, $your_mix_slider, -1, -1, $NI_BUS_OFFSET + 0)
       set_engine_par($ENGINE_PAR_VOLUME, $constant - $your_mix_slider, -1, -1, $NI_BUS_OFFSET + 1)
    end on
    
    Obviously, a linear function will not work great. Especially, in the middle between BUS 1 and BUS 2. Because the dB scale is not linear but logarithmic scale.

    So, here we can use COS, POW or LOG functions. Use some simple math to plot F(X), where X is $your_mix_slider and then use it in the code above. It allows you to not declare a huge array. Do you need help to create this function?
     
  5. EvilDragon

    EvilDragon KSP Wizard

    6,107
    3,978
    May 25, 2010
    Croatia
    Using a lookup array will make it a nice equal-power crossfade. But you have to know the scaling of $ENGINE_PAR_VOLUME before you do that. So rather than piling on more math at the problem, it ends up being more efficient just to have that array there.

    Here's the array:

    Code:
    declare vol_ep[1001] := ( 0, 0, 0, 0, 29240, 29240, 29240, 29240, 36840, 36840, 42172, 42172, 46416, 46416, 50000, 53133, 55934, 55934, 58480, 60822, 62996, 65030, 66943, 68753, 70473, 73681, 75185, 76631, 79370, 80671, 81932, 84343, 86624, 87721, 89835, 90856, 92832, 94727, 96549, 98305, 100000, 101640, 103228, 104769, 106266, 107722, 109139, 111199, 112531, 113832, 115729, 116961, 118760, 119931, 121644, 123311, 124397, 125992, 127548, 129066, 130550, 132001, 133420, 134810, 136172, 137507, 138817, 140525, 141780, 143013, 144625, 145810, 147361, 148504, 150000, 151103, 152549, 153968, 155362, 156391, 157742, 159070, 160377, 161662, 162928, 164174, 165706, 166911, 168099, 169270, 170712, 171848, 173248, 174351, 175711, 176784, 178108, 179412, 180441, 181712, 182965, 184201, 185422, 186626, 187814, 188988, 190148, 191293, 192425, 193766, 194869, 195961, 197254, 198319, 199582, 200623, 201858, 202875, 204083, 205276, 206260, 207429, 208585, 209727, 210858, 211977, 213084, 214179, 215264, 216337, 217577, 218628, 219669, 220700, 221891, 222902, 224070, 225062, 226208, 227180, 228305, 229419, 230522, 231459, 232543, 233616, 234680, 235735, 236780, 237816, 238843, 239861, 241014, 242014, 243006, 243990, 245105, 246072, 247168, 248119, 249197, 250133, 251194, 252246, 253160, 254196, 255223, 256243, 257254, 258258, 259129, 260241, 261222, 262195, 263162, 264121, 265073, 266136, 267074, 268005, 269046, 269963, 270989, 271893, 272904, 273796, 274793, 275673, 276657, 277633, 278603, 279566, 280522, 281367, 282415, 283249, 284284, 285209, 286128, 287041, 287948, 288850, 289845, 290735, 291620, 292597, 293470, 294434, 295297, 296250, 297196, 298043, 298978, 299907, 300739, 301658, 302570, 303478, 304380, 305277, 306169, 307055, 307936, 308813, 309684, 310551, 311498, 312355, 313206, 314054, 314980, 315818, 316651, 317563, 318387, 319289, 320185, 320996, 321883, 322766, 323564, 324437, 325305, 326169, 327029, 327884, 328657, 329580, 330422, 331259, 332093, 332922, 333747, 334568, 335384, 336271, 337080, 337885, 338758, 339555, 340420, 341210, 342066, 342848, 343697, 344471, 345312, 346079, 346912, 347741, 348566, 349318, 350136, 350950, 351760, 352566, 353369, 354168, 354963, 355755, 356543, 357329, 358110, 358953, 359727, 360498, 361266, 362094, 362855, 363613, 364431, 365182, 365993, 366738, 367542, 368280, 369077, 369810, 370600, 371387, 372111, 372892, 373669, 374444, 375156, 375924, 376689, 377451, 378209, 378965, 379718, 380468, 381215, 381959, 382700, 383438, 384174, 384906, 385692, 386419, 387143, 387865, 388639, 389355, 390068, 390833, 391541, 392301, 393003, 393703, 394455, 395203, 395896, 396639, 397326, 398063, 398798, 399479, 400208, 400935, 401660, 402330, 403049, 403767, 404481, 405193, 405902, 406558, 407263, 407965, 408665, 409362, 410057, 410750, 411440, 412178, 412863, 413546, 414227, 414906, 415583, 416306, 416978, 417648, 418315, 419028, 419692, 420353, 421059, 421716, 422371, 423071, 423722, 424417, 425063, 425754, 426397, 427083, 427722, 428404, 429084, 429717, 430393, 431066, 431693, 432363, 433031, 433652, 434316, 434977, 435637, 436251, 436907, 437560, 438212, 438862, 439510, 440114, 440758, 441400, 442041, 442680, 443317, 443952, 444585, 445217, 445847, 446475, 447101, 447725, 448348, 448969, 449629, 450247, 450862, 451477, 452089, 452700, 453309, 453916, 454563, 455167, 455769, 456370, 457009, 457607, 458203, 458838, 459431, 460022, 460651, 461239, 461826, 462451, 463034, 463617, 464236, 464815, 465432, 466008, 466583, 467195, 467767, 468375, 468944, 469550, 470116, 470719, 471282, 471882, 472442, 473039, 473597, 474191, 474746, 475337, 475889, 476477, 477027, 477613, 478160, 478742, 479323, 479867, 480445, 481022, 481562, 482136, 482673, 483245, 483815, 484348, 484916, 485482, 486012, 486576, 487139, 487665, 488225, 488749, 489306, 489862, 490417, 490937, 491489, 492040, 492556, 493105, 493653, 494165, 494711, 495255, 495798, 496306, 496847, 497386, 497891, 498428, 498965, 499466, 500000, 500533, 501031, 501562, 502091, 502587, 503114, 503640, 504132, 504656, 505179, 505701, 506190, 506710, 507228, 507714, 508230, 508746, 509229, 509742, 510255, 510766, 511245, 511755, 512232, 512739, 513246, 513720, 514225, 514728, 515200, 515702, 516203, 516671, 517170, 517637, 518134, 518631, 519095, 519589, 520083, 520544, 521036, 521496, 521986, 522444, 522932, 523389, 523875, 524330, 524815, 525268, 525751, 526203, 526684, 527134, 527614, 528062, 528540, 528987, 529463, 529908, 530353, 530827, 531270, 531742, 532184, 532625, 533094, 533534, 533973, 534440, 534877, 535314, 535779, 536214, 536648, 537111, 537544, 537976, 538407, 538867, 539297, 539727, 540155, 540583, 541011, 541438, 541864, 542317, 542742, 543166, 543589, 544012, 544434, 544856, 545276, 545696, 546116, 546535, 546953, 547370, 547787, 548203, 548591, 549006, 549421, 549835, 550248, 550660, 551045, 551456, 551867, 552277, 552659, 553068, 553477, 553857, 554264, 554671, 555050, 555455, 555860, 556237, 556641, 557018, 557420, 557795, 558197, 558571, 558971, 559344, 559717, 560116, 560488, 560859, 561256, 561626, 561996, 562365, 562759, 563128, 563495, 563863, 564229, 564595, 564987, 565353, 565717, 566082, 566445, 566809, 567172, 567534, 567870, 568232, 568593, 568954, 569314, 569673, 570007, 570366, 570724, 571082, 571414, 571771, 572128, 572459, 572815, 573145, 573499, 573854, 574183, 574511, 574864, 575192, 575544, 575871, 576198, 576549, 576875, 577200, 577525, 577875, 578199, 578523, 578846, 579169, 579492, 579815, 580137, 580459, 580780, 581101, 581421, 581742, 582062, 582357, 582676, 582995, 583313, 583607, 583925, 584243, 584535, 584852, 585144, 585461, 585752, 586068, 586359, 586674, 586964, 587254, 587568, 587858, 588147, 588436, 588749, 589037, 589325, 589613, 589900, 590188, 590474, 590761, 591048, 591334, 591620, 591905, 592167, 592452, 592737, 593021, 593282, 593565, 593826, 594109, 594369, 594652, 594911, 595193, 595452, 595734, 595992, 596250, 596531, 596788, 597046, 597303, 597559, 597816, 598072, 598329, 598608, 598840, 599096, 599351, 599606, 599861, 600116, 600347, 600601, 600855, 601086, 601340, 601593, 601823, 602076, 602306, 602536, 602788, 603017, 603246, 603475, 603727, 603955, 604184, 604412, 604640, 604868, 605095, 605323, 605550, 605778, 606004, 606231, 606435, 606662, 606888, 607092, 607318, 607544, 607747, 607972, 608175, 608400, 608603, 608805, 609030, 609232, 609434, 609636, 609838, 610039, 610263, 610442, 610666, 610844, 611045, 611246, 611447, 611647, 611848, 612026, 612226, 612404, 612604, 612781, 612981, 613158, 613358, 613535, 613712, 613911, 614088, 614265, 614441, 614618, 614794, 614993, 615147, 615323, 615499, 615675, 615851, 616026, 616180, 616356, 616531, 616685, 616860, 617013, 617188, 617341, 617516, 617669, 617822, 617975, 618149, 618302, 618454, 618607, 618759, 618912, 619064, 619216, 619368, 619498, 619650, 619802, 619954, 620084, 620236, 620366, 620517, 620647, 620798, 620928, 621058, 621187, 621339, 621468, 621597, 621727, 621856, 621985, 622115, 622244, 622373, 622502, 622610, 622738, 622867, 622975, 623104, 623211, 623340, 623447, 623575, 623683, 623790, 623918, 624025, 624132, 624239, 624346, 624453, 624560, 624666, 624773, 624880, 624987, 625072, 625179, 625285, 625370, 625477, 625562, 625668, 625754, 625860, 625945, 626030, 626115, 626222, 626307, 626392, 626476, 626561, 626646, 626731, 626795, 626880, 626965, 627049, 627113, 627198, 627261, 627346, 627409, 627494, 627558, 627621, 627706, 627769, 627832, 627896, 627959, 628023, 628086, 628149, 628213, 628276, 628339, 628382, 628445, 628508, 628550, 628614, 628656, 628719, 628761, 628803, 628867, 628909, 628951, 628993, 629035, 629077, 629119, 629162, 629204, 629246, 629288, 629330, 629351, 629393, 629414, 629456, 629498, 629519, 629540, 629582, 629603, 629624, 629666, 629687, 629708, 629729, 629750, 629771, 629792, 629814, 629814, 629834, 629856, 629876, 629876, 629897, 629897, 629919, 629919, 629940, 629940, 629940, 629940, 629961, 629961, 629961, 629961)
     
  6. EvgenyEmelyanov

    EvgenyEmelyanov Composer | Programmer

    For me it looks like simple math for 12-years girls. Just a power function.

    But honestly, I don't know what's better for script performance - working with real functions (like power or log) or working with big arrays. Seems like I should compare them.
     
    P.N. likes this.
  7. EvilDragon

    EvilDragon KSP Wizard

    6,107
    3,978
    May 25, 2010
    Croatia
    Memory access is a faster operation than calculating a bunch of math functions, in case of KSP (and very often in other programming languages, too).
     
  8. EvgenyEmelyanov

    EvgenyEmelyanov Composer | Programmer

    You know, I think you are right - memory access is a faster operation.

    Right now I see only one advantage of math functions: you can easily control the curve of power functions using KSP :) Let's use the x^n function. All you need - changing n parameter.
     
  9. P.N.

    P.N. Active Member

    479
    172
    Aug 14, 2015
    IMHO, that's something a 13 year old would say. :D

    But seriously, if Breaking Bad taught me anything, is that we should try to stay away from math whenever possible.
     
    EvgenyEmelyanov and polypx like this.
  10. OP
    OP
    William Palmer

    William Palmer Member

    94
    55
    Aug 7, 2018
    London
    Hi All, I managed to get this part of the instrument working! Thanks for the help :)
     

Share This Page